static void screensaver_disable_x11 (ScreenSaver * screensaver) { #ifdef HAVE_XTEST if (screensaver->have_xtest) { XLockDisplay (screensaver->display); XGetScreenSaver (screensaver->display, &screensaver->timeout, &screensaver->interval, &screensaver->prefer_blanking, &screensaver->allow_exposures); XUnlockDisplay (screensaver->display); if (screensaver->timeout != 0) { g_timeout_add_seconds (screensaver->timeout / 2, (GSourceFunc) fake_event, screensaver); } else { g_timeout_add_seconds (XSCREENSAVER_MIN_TIMEOUT / 2, (GSourceFunc) fake_event, screensaver); } return; } #endif XLockDisplay (screensaver->display); XGetScreenSaver (screensaver->display, &screensaver->timeout, &screensaver->interval, &screensaver->prefer_blanking, &screensaver->allow_exposures); XSetScreenSaver (screensaver->display, 0, 0, DontPreferBlanking, DontAllowExposures); XUnlockDisplay (screensaver->display); }
void wsScreenSaverOn(Display *mDisplay) { int nothing; #ifdef CONFIG_XDPMS if (dpms_disabled) { if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) { if (!DPMSEnable(mDisplay)) mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_WS_DpmsUnavailable); // restoring power saving settings else { // DPMS does not seem to be enabled unless we call DPMSInfo BOOL onoff; CARD16 state; DPMSInfo(mDisplay, &state, &onoff); if (onoff) mp_msg(MSGT_GPLAYER, MSGL_V, "Successfully enabled DPMS.\n"); else mp_msg(MSGT_GPLAYER, MSGL_STATUS, MSGTR_WS_DpmsNotEnabled); } } } #endif if (timeout_save) { int dummy, interval, prefer_blank, allow_exp; XGetScreenSaver(mDisplay, &dummy, &interval, &prefer_blank, &allow_exp); XSetScreenSaver(mDisplay, timeout_save, interval, prefer_blank, allow_exp); XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp); } }
void wsScreenSaverOff(Display *mDisplay) { int interval, prefer_blank, allow_exp, nothing; #ifdef CONFIG_XDPMS if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) { BOOL onoff; CARD16 state; DPMSInfo(mDisplay, &state, &onoff); if (onoff) { Status stat; mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "Disabling DPMS.\n"); dpms_disabled = 1; stat = DPMSDisable(mDisplay); // monitor powersave off mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "stat: %d.\n", stat); } } #endif XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp); if (timeout_save) XSetScreenSaver(mDisplay, 0, interval, prefer_blank, allow_exp); // turning off screensaver }
void XDisplay::disableScreenSaver() { int timeout, interval, blanking, exposure; XGetScreenSaver( this->connection, &timeout, &interval, &blanking, &exposure); XSetScreenSaver( this->connection, 0 /* Timeout */, 0 /* Interval */, blanking, exposure); }
void XDisplay::enableScreenSaver() { int timeout, interval, blanking, exposure; XGetScreenSaver( this->connection, &timeout, &interval, &blanking, &exposure); XSetScreenSaver( this->connection, DEFAULT_TIMEOUT, SERVER_DEFAULT, blanking, exposure ); }
/* This timer goes off every few minutes, whether the user is idle or not, to try and clean up anything that has gone wrong. It calls disable_builtin_screensaver() so that if xset has been used, or some other program (like xlock) has messed with the XSetScreenSaver() settings, they will be set back to sensible values (if a server extension is in use, messing with xlock can cause the screensaver to never get a wakeup event, and could cause monitor power-saving to occur, and all manner of heinousness.) This code was originally part of gnome-screensaver, see http://git.gnome.org/browse/gnome-screensaver/tree/src/gs-watcher-x11.c?id=fec00b12ec46c86334cfd36b37771cc4632f0d4d#n530 */ static gboolean disable_builtin_screensaver (gpointer unused) { int current_server_timeout, current_server_interval; int current_prefer_blank, current_allow_exp; int desired_server_timeout, desired_server_interval; int desired_prefer_blank, desired_allow_exp; XGetScreenSaver (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), ¤t_server_timeout, ¤t_server_interval, ¤t_prefer_blank, ¤t_allow_exp); desired_server_timeout = current_server_timeout; desired_server_interval = current_server_interval; desired_prefer_blank = current_prefer_blank; desired_allow_exp = current_allow_exp; desired_server_interval = 0; /* I suspect (but am not sure) that DontAllowExposures might have something to do with powering off the monitor as well, at least on some systems that don't support XDPMS? Who know... */ desired_allow_exp = AllowExposures; /* When we're not using an extension, set the server-side timeout to 0, so that the server never gets involved with screen blanking, and we do it all ourselves. (However, when we *are* using an extension, we tell the server when to notify us, and rather than blanking the screen, the server will send us an X event telling us to blank.) */ desired_server_timeout = 0; if (desired_server_timeout != current_server_timeout || desired_server_interval != current_server_interval || desired_prefer_blank != current_prefer_blank || desired_allow_exp != current_allow_exp) { g_debug ("disabling server builtin screensaver:" " (xset s %d %d; xset s %s; xset s %s)", desired_server_timeout, desired_server_interval, (desired_prefer_blank ? "blank" : "noblank"), (desired_allow_exp ? "expose" : "noexpose")); XSetScreenSaver (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), desired_server_timeout, desired_server_interval, desired_prefer_blank, desired_allow_exp); XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE); } return TRUE; }
EAPI void ecore_x_screensaver_blank_set(int blank) { int pto, pint, pblank, pexpo; LOGFN(__FILE__, __LINE__, __FUNCTION__); XGetScreenSaver(_ecore_x_disp, &pto, &pint, &pblank, &pexpo); XSetScreenSaver(_ecore_x_disp, pto, pint, blank, pexpo); }
EAPI int ecore_x_screensaver_timeout_get(void) { int pto, pint, pblank, pexpo; LOGFN(__FILE__, __LINE__, __FUNCTION__); XGetScreenSaver(_ecore_x_disp, &pto, &pint, &pblank, &pexpo); return pto; }
EAPI void ecore_x_screensaver_timeout_set(int timeout) { int pto, pint, pblank, pexpo; LOGFN(__FILE__, __LINE__, __FUNCTION__); XGetScreenSaver(_ecore_x_disp, &pto, &pint, &pblank, &pexpo); XSetScreenSaver(_ecore_x_disp, timeout, pint, pblank, pexpo); } /* ecore_x_screensaver_timeout_set */
EAPI void ecore_x_screensaver_interval_set(int interval) { int pto, pint, pblank, pexpo; LOGFN(__FILE__, __LINE__, __FUNCTION__); XGetScreenSaver(_ecore_x_disp, &pto, &pint, &pblank, &pexpo); XSetScreenSaver(_ecore_x_disp, pto, interval, pblank, pexpo); } /* ecore_x_screensaver_interval_set */
void SaveScreenSaver() { if (!m_state.saved) { XGetScreenSaver(qt_xdisplay(), &m_state.timeout, &m_state.interval, &m_state.preferblank, &m_state.allowexposure); m_state.saved = true; } }
/** * Actually this is a big mess. By default the libSDL disables the screen * saver during the SDL_InitSubSystem() call and restores the saved settings * during the SDL_QuitSubSystem() call. This mechanism can be disabled by * setting the environment variable SDL_VIDEO_ALLOW_SCREENSAVER to 1. However, * there is a known bug in the Debian libSDL: If this environment variable is * set, the screen saver is still disabled but the old state is not restored * during SDL_QuitSubSystem()! So the only solution to overcome this problem * is to save and restore the state prior and after each of these function * calls. */ void X11ScreenSaverSettingsSave() { int dummy; CARD16 dummy2; Display *display = QX11Info::display(); XGetScreenSaver(display, &gX11ScreenSaverTimeout, &dummy, &dummy, &dummy); if (gX11ScreenSaverDpmsAvailable) DPMSInfo(display, &dummy2, &gX11DpmsState); }
void SaveScreenSaver(void) { if (!m_state.saved && m_display) { XGetScreenSaver(m_display->GetDisplay(), &m_state.timeout, &m_state.interval, &m_state.preferblank, &m_state.allowexposure); m_state.saved = true; } }
// =================================== // setsaver... // ----------------------------------- void setsaver(Display *dpy, int value) { int timeout; int interval; int prefer_blank; int allow_exp; XGetScreenSaver(dpy,&timeout,&interval,&prefer_blank,&allow_exp); timeout = value; XSetScreenSaver(dpy,timeout,interval,prefer_blank,allow_exp); return; }
/** * Restore previously saved screen saver settings. */ void X11ScreenSaverSettingsRestore() { int timeout, interval, preferBlank, allowExp; Display *display = QX11Info::display(); XGetScreenSaver(display, &timeout, &interval, &preferBlank, &allowExp); timeout = gX11ScreenSaverTimeout; XSetScreenSaver(display, timeout, interval, preferBlank, allowExp); if (gX11DpmsState && gX11ScreenSaverDpmsAvailable) DPMSEnable(display); }
static void X11_XScreenSaverState(XWindow *xwin, Bool turn_on) { return; if (turn_on) { if (!xwin->ss_t) return; XSetScreenSaver(xwin->display, xwin->ss_t, xwin->ss_i, xwin->ss_b, xwin->ss_e); } else { /* Save state information */ XGetScreenSaver(xwin->display, &xwin->ss_t, &xwin->ss_i, &xwin->ss_b, &xwin->ss_e); if (xwin->ss_t) XSetScreenSaver(xwin->display, 0, xwin->ss_i, xwin->ss_b, xwin->ss_e); } }
void CXWindowsScreenSaver::disable() { // for xscreensaver m_disabled = true; updateDisableJob(); // use built-in X screen saver XGetScreenSaver(m_display, &m_timeout, &m_interval, &m_preferBlanking, &m_allowExposures); XSetScreenSaver(m_display, 0, m_interval, m_preferBlanking, m_allowExposures); // FIXME -- now deactivate? }
void X11ScreenSaverSettingsSave() { /* Actually this is a big mess. By default the libSDL disables the screen saver * during the SDL_InitSubSystem() call and restores the saved settings during * the SDL_QuitSubSystem() call. This mechanism can be disabled by setting the * environment variable SDL_VIDEO_ALLOW_SCREENSAVER to 1. However, there is a * known bug in the Debian libSDL: If this environment variable is set, the * screen saver is still disabled but the old state is not restored during * SDL_QuitSubSystem()! So the only solution to overcome this problem is to * save and restore the state prior and after each of these function calls. */ int dummy; CARD16 dummy2; Display *display = QX11Info::display(); XGetScreenSaver(display, &gX11ScreenSaverTimeout, &dummy, &dummy, &dummy); if (gX11ScreenSaverDpmsAvailable) DPMSInfo(display, &dummy2, &gX11DpmsState); }
static void screenSaverSetXScreenSaver( CompDisplay *d, Bool enable ) { SCREENSAVER_DISPLAY(d); if( enable && !sd->XSScontext.init ) { int dummy; if( !XScreenSaverQueryExtension(d->display, &sd->XSScontext.first_event, &dummy ) ) { compLogMessage ("screensaver", CompLogLevelWarn, "XScreenSaver Extension not available"); return; } sd->XSScontext.init = True; XGetScreenSaver( d->display, &sd->XSScontext.timeout, &sd->XSScontext.interval, \ &sd->XSScontext.prefer_blanking, &sd->XSScontext.allow_exposures); XSetScreenSaver( d->display, (int)(screensaverGetAfter(d)*60.0), sd->XSScontext.interval, 0, AllowExposures); Window root = DefaultRootWindow (d->display); XSetWindowAttributes attr; int mask = 0; XScreenSaverSetAttributes( d->display,root, -100,-100,1,1,0 ,CopyFromParent,CopyFromParent,CopyFromParent,mask,&attr); XScreenSaverSelectInput( d->display, root, ScreenSaverNotifyMask ); } if( !enable && sd->XSScontext.init ) { sd->XSScontext.init = False; XSetScreenSaver( d->display, sd->XSScontext.timeout, sd->XSScontext.interval, \ sd->XSScontext.prefer_blanking, sd->XSScontext.allow_exposures); Window root = DefaultRootWindow (d->display); XScreenSaverSelectInput( d->display, root, 0 ); XScreenSaverUnsetAttributes( d->display, root ); } }
static void enterFullscreenMode(_GLFWwindow* window) { XEvent event; if (!_glfwLibrary.X11.saver.changed) { // Remember old screen saver settings XGetScreenSaver(_glfwLibrary.X11.display, &_glfwLibrary.X11.saver.timeout, &_glfwLibrary.X11.saver.interval, &_glfwLibrary.X11.saver.blanking, &_glfwLibrary.X11.saver.exposure); // Disable screen saver XSetScreenSaver(_glfwLibrary.X11.display, 0, 0, DontPreferBlanking, DefaultExposures); _glfwLibrary.X11.saver.changed = GL_TRUE; } _glfwSetVideoMode(&window->width, &window->height, &window->refreshRate); if (_glfwLibrary.X11.hasEWMH && _glfwLibrary.X11.wmState != None && _glfwLibrary.X11.wmStateFullscreen != None) { if (_glfwLibrary.X11.wmActiveWindow != None) { // Ask the window manager to raise and focus the GLFW window // Only focused windows with the _NET_WM_STATE_FULLSCREEN state end // up on top of all other windows ("Stacking order" in EWMH spec) XEvent event; memset(&event, 0, sizeof(event)); event.type = ClientMessage; event.xclient.window = window->X11.handle; event.xclient.format = 32; // Data is 32-bit longs event.xclient.message_type = _glfwLibrary.X11.wmActiveWindow; event.xclient.data.l[0] = 1; // Sender is a normal application event.xclient.data.l[1] = 0; // We don't really know the timestamp XSendEvent(_glfwLibrary.X11.display, _glfwLibrary.X11.root, False, SubstructureNotifyMask | SubstructureRedirectMask, &event); } // Ask the window manager to make the GLFW window a fullscreen window // Fullscreen windows are undecorated and, when focused, are kept // on top of all other windows memset(&event, 0, sizeof(event)); event.type = ClientMessage; event.xclient.window = window->X11.handle; event.xclient.format = 32; // Data is 32-bit longs event.xclient.message_type = _glfwLibrary.X11.wmState; event.xclient.data.l[0] = _NET_WM_STATE_ADD; event.xclient.data.l[1] = _glfwLibrary.X11.wmStateFullscreen; event.xclient.data.l[2] = 0; // No secondary property event.xclient.data.l[3] = 1; // Sender is a normal application XSendEvent(_glfwLibrary.X11.display, _glfwLibrary.X11.root, False, SubstructureNotifyMask | SubstructureRedirectMask, &event); } else if (window->X11.overrideRedirect) { // In override-redirect mode we have divorced ourselves from the // window manager, so we need to do everything manually XRaiseWindow(_glfwLibrary.X11.display, window->X11.handle); XSetInputFocus(_glfwLibrary.X11.display, window->X11.handle, RevertToParent, CurrentTime); XMoveWindow(_glfwLibrary.X11.display, window->X11.handle, 0, 0); XResizeWindow(_glfwLibrary.X11.display, window->X11.handle, window->width, window->height); } // HACK: Try to get window inside viewport (for virtual displays) by moving // the cursor to the upper left corner (and then to the center) // This hack should be harmless on saner systems as well XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, 0,0); XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, window->width / 2, window->height / 2); }
// Enter fullscreen mode // static void enterFullscreenMode(_GLFWwindow* window) { if (!_glfw.x11.saver.changed) { // Remember old screen saver settings XGetScreenSaver(_glfw.x11.display, &_glfw.x11.saver.timeout, &_glfw.x11.saver.interval, &_glfw.x11.saver.blanking, &_glfw.x11.saver.exposure); // Disable screen saver XSetScreenSaver(_glfw.x11.display, 0, 0, DontPreferBlanking, DefaultExposures); _glfw.x11.saver.changed = GL_TRUE; } _glfwSetVideoMode(window->monitor, &window->videoMode); if (_glfw.x11.hasEWMH && _glfw.x11.NET_WM_STATE != None && _glfw.x11.NET_WM_STATE_FULLSCREEN != None) { if (_glfw.x11.NET_ACTIVE_WINDOW != None) { // Ask the window manager to raise and focus the GLFW window // Only focused windows with the _NET_WM_STATE_FULLSCREEN state end // up on top of all other windows ("Stacking order" in EWMH spec) XEvent event; memset(&event, 0, sizeof(event)); event.type = ClientMessage; event.xclient.window = window->x11.handle; event.xclient.format = 32; // Data is 32-bit longs event.xclient.message_type = _glfw.x11.NET_ACTIVE_WINDOW; event.xclient.data.l[0] = 1; // Sender is a normal application event.xclient.data.l[1] = 0; // We don't really know the timestamp XSendEvent(_glfw.x11.display, _glfw.x11.root, False, SubstructureNotifyMask | SubstructureRedirectMask, &event); } // Ask the window manager to make the GLFW window a fullscreen window // Fullscreen windows are undecorated and, when focused, are kept // on top of all other windows XEvent event; memset(&event, 0, sizeof(event)); event.type = ClientMessage; event.xclient.window = window->x11.handle; event.xclient.format = 32; // Data is 32-bit longs event.xclient.message_type = _glfw.x11.NET_WM_STATE; event.xclient.data.l[0] = _NET_WM_STATE_ADD; event.xclient.data.l[1] = _glfw.x11.NET_WM_STATE_FULLSCREEN; event.xclient.data.l[2] = 0; // No secondary property event.xclient.data.l[3] = 1; // Sender is a normal application XSendEvent(_glfw.x11.display, _glfw.x11.root, False, SubstructureNotifyMask | SubstructureRedirectMask, &event); } else if (window->x11.overrideRedirect) { // In override-redirect mode we have divorced ourselves from the // window manager, so we need to do everything manually GLFWvidmode mode; _glfwPlatformGetVideoMode(window->monitor, &mode); XRaiseWindow(_glfw.x11.display, window->x11.handle); XSetInputFocus(_glfw.x11.display, window->x11.handle, RevertToParent, CurrentTime); XMoveWindow(_glfw.x11.display, window->x11.handle, 0, 0); XResizeWindow(_glfw.x11.display, window->x11.handle, mode.width, mode.height); } }
void getSleep() { XGetScreenSaver(dpy, &timeout, &interval, &prefer_blank, &allow_exp); }
main() { Window w2; Display *dpy = XOpenDisplay(NIL); assert(dpy); Screen *scr = DefaultScreenOfDisplay(dpy); // CreateWindow Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XDestroyWindow(dpy, w); // CreateWindow with arguments XSetWindowAttributes swa; swa.background_pixel = WhitePixelOfScreen(scr); swa.bit_gravity = NorthWestGravity; swa.border_pixel = BlackPixelOfScreen(scr); swa.colormap = DefaultColormapOfScreen(scr); swa.cursor = None; swa.win_gravity = NorthGravity; w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, &swa); // CreateWindow with other arguments XDestroyWindow(dpy, w); Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr)); assert(pixmap); swa.background_pixmap = pixmap; swa.border_pixmap = pixmap; w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixmap | CWBorderPixmap, &swa); // ChangeWindowAttributes swa.backing_planes = 0x1; swa.backing_pixel = WhitePixelOfScreen(scr); swa.save_under = True; swa.event_mask = KeyPressMask | KeyReleaseMask; swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask; swa.override_redirect = False; XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask | CWDontPropagate | CWOverrideRedirect, &swa); // GetWindowAttributes XWindowAttributes wa; Status success = XGetWindowAttributes(dpy, w, &wa); // DestroyWindow (done) // DestroySubwindows w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XDestroySubwindows(dpy, w); // ChangeSaveSet // Display *dpy2 = XOpenDisplay(NIL); // assert(dpy2); // XAddToSaveSet(dpy2, w); // XCloseDisplay(dpy2); // ReparentWindow w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XReparentWindow(dpy, w2, w, 10, 5); // MapWindow XMapWindow(dpy, w); // MapSubwindows XMapSubwindows(dpy, w); // UnmapWindow XUnmapWindow(dpy, w); // UnmapSubwindows XMapWindow(dpy, w); XUnmapSubwindows(dpy, w2); XMapSubwindows(dpy, w); // ConfigureWindow Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XMapWindow(dpy, w3); XWindowChanges wc; wc.x = -5; wc.y = -10; wc.width = 50; wc.height = 40; wc.border_width = 7; wc.sibling = w2; wc.stack_mode = Opposite; XConfigureWindow(dpy, w3, CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, &wc); // CirculateWindow XCirculateSubwindows(dpy, w, RaiseLowest); // GetGeometry Window root; int x, y; unsigned width, height, border_width, depth; XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth); // QueryTree Window parent; Window *children; unsigned nchildren; success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren); XFree(children); // InternAtom Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True); // GetAtomName char *string = XGetAtomName(dpy, XA_PRIMARY); XFree(string); // ChangeProperty XStoreName(dpy, w, "test window"); // DeleteProperty XDeleteProperty(dpy, w, XA_WM_NAME); // GetProperty // TODO // ListProperties int num_prop; Atom *list = XListProperties(dpy, w, &num_prop); XFree(list); // SetSelectionOwner XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000); XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime); // GetSelectionOwner Window wx = XGetSelectionOwner(dpy, XA_PRIMARY); // ConvertSelection XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime); // SendEvent // GrabPointer std::cerr << "Grabbing" << std::endl; int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask, GrabModeSync, GrabModeAsync, w, None, CurrentTime); XSync(dpy, False); // sleep(5); // UngrabPointer std::cerr << "Ungrabbing" << std::endl; XUngrabPointer(dpy, CurrentTime); // GrabButton XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, GrabModeAsync, GrabModeSync, None, None); XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, GrabModeAsync, GrabModeSync, None, None); // UngrabButton XUngrabButton(dpy, 2, LockMask, w); // ChangeActivePointerGrab XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime); // GrabKeyboard XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000); // UngrabKeyboard XUngrabKeyboard(dpy, 13000); // GrabKey XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync, GrabModeSync); // UngrabKey XUngrabKey(dpy, AnyKey, AnyModifier, w); // AllowEvents XAllowEvents(dpy, AsyncPointer, 14000); // GrabServer XGrabServer(dpy); // UngrabServer XUngrabServer(dpy); // QueryPointer Window child; int root_x, root_y, win_x, win_y; unsigned mask; Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); // GetMotionEvents int nevents; XGetMotionEvents(dpy, w, 15000, 16000, &nevents); // TranslateCoordinates int dest_x, dest_y; XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child); // WarpPointer XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30); // SetInputFocus XSetInputFocus(dpy,w, RevertToPointerRoot, 17000); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000); // GetInputFocus Window focus; int revert_to; XGetInputFocus(dpy, &focus, &revert_to); // QueryKeymap char keys_return[32]; XQueryKeymap(dpy, keys_return); // OpenFont Font fid = XLoadFont(dpy, "cursor"); // CloseFont XUnloadFont(dpy, fid); // QueryFont XFontStruct *fs = XLoadQueryFont(dpy, "cursor"); assert(fs); // QueryTextExtents int direction, font_ascent, font_descent; XCharStruct overall; XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall); XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall); XChar2b c2bs; c2bs.byte1 = '$'; c2bs.byte2 = 'B'; XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall); XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, &font_descent, &overall); // ListFonts int actual_count; char **fontList = XListFonts(dpy, "*", 100, &actual_count); XFree((char *)fontList); // ListFontsWithInfo int count; XFontStruct *info; char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info); XFreeFontInfo(names, info, count); // SetFontPath // GetFontPath int npaths; char **charList = XGetFontPath(dpy, &npaths); char **charList2 = new char *[npaths + 1]; memcpy(charList2, charList, npaths * sizeof(char *)); charList2[npaths] = charList2[0]; XSetFontPath(dpy, charList2, npaths + 1); XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value XFreeFontPath(charList); delete [] charList2; // CreatePixmap Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr)); // FreePixmap XFreePixmap(dpy, pix2); // CreateGC Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4); XGCValues gcv; gcv.function = GXand; gcv.plane_mask = 0x1; gcv.foreground = WhitePixelOfScreen(scr); gcv.background = BlackPixelOfScreen(scr); gcv.line_width = 2; gcv.line_style = LineDoubleDash; gcv.cap_style = CapProjecting; gcv.join_style = JoinRound; gcv.fill_style = FillStippled; gcv.fill_rule = EvenOddRule; gcv.arc_mode = ArcPieSlice; gcv.tile = pixmap; gcv.stipple = bitmap; gcv.ts_x_origin = 3; gcv.ts_y_origin = 4; gcv.font = fs -> fid; gcv.subwindow_mode = ClipByChildren; gcv.graphics_exposures = True; gcv.clip_x_origin = 5; gcv.clip_y_origin = 6; gcv.clip_mask = bitmap; gcv.dash_offset = 1; gcv.dashes = 0xc2; GC gc = XCreateGC(dpy, w, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode | GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset | GCDashList | GCArcMode, &gcv); // ChangeGC gcv.function = GXandReverse; // Only a few of these should appear, since the values are cached on the client side by the Xlib. XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv); // CopyGC GC gc2 = XCreateGC(dpy, w, 0, NIL); XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2); // SetDashes XSetDashes(dpy, gc, 3, "\001\377\001", 3); // SetClipRectangles XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } }; XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted); // FreeGC // done already // ClearArea XClearArea(dpy, w, 30, 10, 10, 100, False); // CopyArea XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10); // CopyPlane // This won't work if the Screen doesn't have at least 3 planes XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4); // PolyPoint XDrawPoint(dpy, w, gc, 1, 2); XPoint points[] = { { 3, 4 }, { 5, 6 } }; XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin); // PolyLine XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious); // PolySegment XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } }; XDrawSegments(dpy, w, gc, segments, SIZEOF(segments)); // PolyRectangle XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles)); // PolyArc XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, { 10, 20, 30, 40, 50, -30 } }; XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs)); // FillPoly XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious); // PolyFillRectangle XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles)); // PolyFillArc XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs)); // PutImage // GetImage XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap); XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30); XSync(dpy, False); // Make the next request starts at the beginning of a packet // PolyText8 XTextItem textItems[3]; textItems[0].chars = "toto"; textItems[0].nchars = strlen(textItems[0].chars); textItems[0].delta = -3; textItems[0].font = fs->fid; textItems[1].chars = "titi"; textItems[1].nchars = strlen(textItems[1].chars); textItems[1].delta = 3; textItems[1].font = None; textItems[2].chars = "tutu"; textItems[2].nchars = strlen(textItems[2].chars); textItems[2].delta = 0; textItems[2].font = fs->fid; XDrawText(dpy, w, gc, 10, 10, textItems, 3); XTextItem textItems2[3]; textItems2[0].chars = "totox"; textItems2[0].nchars = strlen(textItems2[0].chars); textItems2[0].delta = -3; textItems2[0].font = fs->fid; textItems2[1].chars = "titi"; textItems2[1].nchars = strlen(textItems2[1].chars); textItems2[1].delta = 3; textItems2[1].font = None; textItems2[2].chars = "tutu"; textItems2[2].nchars = strlen(textItems2[2].chars); textItems2[2].delta = 0; textItems2[2].font = fs->fid; XDrawText(dpy, w, gc, 10, 10, textItems2, 3); // PolyText16 XChar2b c2b2[] = { 0, 't', 0, 'x' }; XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } }; XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16)); // ImageText8 XDrawImageString(dpy, w, gc, 10, 10, "toto", 4); // ImageText16 XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1); XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2); // CreateColormap // Don't forget to tell the kids how it was when we had only 8 bits per pixel. Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None); // FreeColormap XFreeColormap(dpy, colormap); colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None); // CopyColormapAndFree Colormap colormap2 = XCopyColormapAndFree(dpy, colormap); // InstallColormap XInstallColormap(dpy, colormap2); // UninstallColormap XUninstallColormap(dpy, colormap2); // ListInstalledColormaps int num; Colormap *colormapList = XListInstalledColormaps(dpy, w, &num); // AllocColor XColor screen; screen.red = 0; screen.green = 32767; screen.blue = 65535; screen.flags = DoRed | DoGreen | DoBlue; success = XAllocColor(dpy, colormap, &screen); // AllocNamedColor XColor screen2, exact; success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact); // AllocColorCells unsigned long plane_masks, pixels; success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1); // AllocColorPlanes unsigned long rmask, gmask, bmask; success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask); // FreeColors unsigned long pixels2[2] = { screen.pixel, screen2.pixel }; XFreeColors(dpy, colormap, pixels2, 2, 0); // StoreColors success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2); // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells // I want my requests to be sent, however. if (!success) { XSetErrorHandler(errorHandler); } XColor colors[2]; colors[0] = screen; colors[0].pixel = pixels2[0]; colors[1] = screen2; colors[1].pixel = pixels2[1]; XStoreColors(dpy, colormap, colors, 2); // StoreNamedColor XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue); XSync(dpy, False); XSetErrorHandler(NIL); // Restore the default handler // QueryColors screen2.pixel = WhitePixelOfScreen(scr); XQueryColor(dpy, colormap, &screen2); // LookupColor success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen); // CreateCursor Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10); // CreateGlyphCursor Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors); // FreeCursor XFreeCursor(dpy, cursor2); // RecolorCursor XRecolorCursor(dpy, cursor, colors, &exact); // QueryBestSize success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height); // QueryExtension int major_opcode, first_event, first_error; XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error); // ListExtensions int nextensions; char **extensionList = XListExtensions(dpy, &nextensions); for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl; XFree(extensionList); // ChangeKeyboardMapping // GetKeyboardMapping int min_keycodes, max_keycodes; XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes); int keysyms_per_keycode; KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1, &keysyms_per_keycode); XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, max_keycodes - min_keycodes + 1); // ChangeKeyboardControl // GetKeyboardControl XKeyboardState keyboardState; XGetKeyboardControl(dpy, &keyboardState); XKeyboardControl keyboardValues; keyboardValues.key_click_percent = keyboardState.key_click_percent; keyboardValues.bell_percent = keyboardState.bell_percent; keyboardValues.bell_pitch = keyboardState.bell_pitch; keyboardValues.bell_duration = keyboardState.bell_duration; keyboardValues.led = 1; keyboardValues.led_mode = LedModeOn; keyboardValues.key = min_keycodes; keyboardValues.auto_repeat_mode = AutoRepeatModeDefault; XChangeKeyboardControl(dpy, KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration | KBLed | KBLedMode | KBKey | KBAutoRepeatMode, &keyboardValues); // Bell XBell(dpy, 90); // ChangePointerControl // GetPointerControl int accel_numerator, accel_denominator, threshold; XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold); XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold); // SetScreenSaver // GetScreenSaver int timeout, interval, prefer_blanking, allow_exposures; XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures); XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures); // ChangeHosts // ListHosts int nhosts; Bool state; XHostAddress *hostList = XListHosts(dpy, &nhosts, &state); XHostAddress host; host.family = FamilyInternet; host.length = 4; host.address = "\001\002\003\004"; XAddHost(dpy, &host); // SetAccessControl XSetAccessControl(dpy, EnableAccess); // SetCloseDownMode XSetCloseDownMode(dpy, RetainTemporary); // KillClient XKillClient(dpy, AllTemporary); // RotateProperties Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), XInternAtom(dpy, "CUT_BUFFER1", False), XInternAtom(dpy, "CUT_BUFFER2", False) }; XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1); // ForceScreenSaver XForceScreenSaver(dpy, ScreenSaverReset); // SetPointerMapping // GetPointerMapping unsigned char map[64]; int map_length = XGetPointerMapping(dpy, map, 64); XSetPointerMapping(dpy, map, map_length); // SetModifierMapping // GetModifierMapping XModifierKeymap *modmap = XGetModifierMapping(dpy); XSetModifierMapping(dpy, modmap); // NoOperation XNoOp(dpy); for(;;) { XEvent e; XNextEvent(dpy, &e); std::cout << "Got an event of type " << e.type << std::endl; } }
CXWindowsScreenSaver::CXWindowsScreenSaver( CXWindowsScreen* screen, Display* display) : m_screen(screen), m_display(display), m_notify(None), m_xscreensaver(None), m_xscreensaverActive(false), m_disabled(false), m_suppressDisable(false), m_disableJobInstalled(false) { // screen saver disable callback m_disableJob = new TMethodJob<CXWindowsScreenSaver>(this, &CXWindowsScreenSaver::disableCallback); // get atoms m_atomScreenSaver = XInternAtom(m_display, "SCREENSAVER", False); m_atomScreenSaverVersion = XInternAtom(m_display, "_SCREENSAVER_VERSION", False); m_atomScreenSaverActivate = XInternAtom(m_display, "ACTIVATE", False); m_atomScreenSaverDeactivate = XInternAtom(m_display, "DEACTIVATE", False); m_atomSynergyScreenSaver = XInternAtom(m_display, "SYNERGY_SCREENSAVER", False); // create dummy window to receive xscreensaver responses. this // shouldn't be necessary (we should be able to send responses // to None) but it doesn't hurt. XSetWindowAttributes attr; attr.event_mask = 0;//PropertyChangeMask; attr.do_not_propagate_mask = 0; attr.override_redirect = True; m_xscreensaverSink = XCreateWindow(m_display, DefaultRootWindow(m_display), 0, 0, 1, 1, 0, 0, InputOnly, CopyFromParent, CWDontPropagate | CWEventMask | CWOverrideRedirect, &attr); LOG((CLOG_DEBUG "xscreensaver sink window is 0x%08x", m_xscreensaverSink)); // watch top-level windows for changes { bool error = false; CXWindowsUtil::CErrorLock lock(m_display, &error); Window root = DefaultRootWindow(m_display); XWindowAttributes attr; XGetWindowAttributes(m_display, root, &attr); m_rootEventMask = attr.your_event_mask; XSelectInput(m_display, root, m_rootEventMask | SubstructureNotifyMask); if (error) { LOG((CLOG_DEBUG "didn't set root event mask")); m_rootEventMask = 0; } } // get the xscreensaver window, if any if (!findXScreenSaver()) { setXScreenSaver(None); } // get the built-in settings XGetScreenSaver(m_display, &m_timeout, &m_interval, &m_preferBlanking, &m_allowExposures); }
CXWindowsScreenSaver::CXWindowsScreenSaver( Display* display, Window window, void* eventTarget, IEventQueue* events) : m_display(display), m_xscreensaverSink(window), m_eventTarget(eventTarget), m_xscreensaver(None), m_xscreensaverActive(false), m_dpms(false), m_disabled(false), m_suppressDisable(false), m_disableTimer(NULL), m_disablePos(0), m_events(events) { // get atoms m_atomScreenSaver = XInternAtom(m_display, "SCREENSAVER", False); m_atomScreenSaverVersion = XInternAtom(m_display, "_SCREENSAVER_VERSION", False); m_atomScreenSaverActivate = XInternAtom(m_display, "ACTIVATE", False); m_atomScreenSaverDeactivate = XInternAtom(m_display, "DEACTIVATE", False); // check for DPMS extension. this is an alternative screen saver // that powers down the display. #if HAVE_X11_EXTENSIONS_DPMS_H int eventBase, errorBase; if (DPMSQueryExtension(m_display, &eventBase, &errorBase)) { if (DPMSCapable(m_display)) { // we have DPMS m_dpms = true; } } #endif // watch top-level windows for changes bool error = false; { CXWindowsUtil::CErrorLock lock(m_display, &error); Window root = DefaultRootWindow(m_display); XWindowAttributes attr; XGetWindowAttributes(m_display, root, &attr); m_rootEventMask = attr.your_event_mask; XSelectInput(m_display, root, m_rootEventMask | SubstructureNotifyMask); } if (error) { LOG((CLOG_DEBUG "didn't set root event mask")); m_rootEventMask = 0; } // get the built-in settings XGetScreenSaver(m_display, &m_timeout, &m_interval, &m_preferBlanking, &m_allowExposures); // get the DPMS settings m_dpmsEnabled = isDPMSEnabled(); // get the xscreensaver window, if any if (!findXScreenSaver()) { setXScreenSaver(None); } // install disable timer event handler m_events->adoptHandler(CEvent::kTimer, this, new TMethodEventJob<CXWindowsScreenSaver>(this, &CXWindowsScreenSaver::handleDisableTimer)); }