From 9c41538e701824ae2e72268592add0373123705c Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 18 Apr 2008 11:43:12 -0600 Subject: [PATCH] Try three times to grab keyboard. I should probably make it try forever. Who knows. Maybe this is a bad idea. --- xkeygrab.c | 28 +++++++++++++++------------- xss.c | 16 +++++++++++++++- xsswin.c | 2 +- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/xkeygrab.c b/xkeygrab.c index 53a978e..9434711 100644 --- a/xkeygrab.c +++ b/xkeygrab.c @@ -40,22 +40,24 @@ main(int argc, char *argv[]) char obuf[4096]; int obuflen = 0; struct pollfd fds[2]; + int i; if (! (display = XOpenDisplay(NULL))) raise("cannot open display"); root = DefaultRootWindow(display); - (void)XUngrabPointer(display, CurrentTime); - if (GrabSuccess != XGrabPointer(display, root, - False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, - GrabModeAsync, GrabModeAsync, - None, None, CurrentTime)) { - raise("cannot grab pointer"); - } - (void)XUngrabKeyboard(display, CurrentTime); - if (GrabSuccess != XGrabKeyboard(display, root, - True, - GrabModeAsync, GrabModeAsync, - CurrentTime)) { - raise("cannot grab keyboard"); + for (i = 0; i < 3; ) { + if ((! (i & 1)) && (GrabSuccess == XGrabKeyboard(display, root, + True, + GrabModeAsync, GrabModeAsync, + CurrentTime))) { + i |= 1; + } + if ((! (i & 2)) && (GrabSuccess == XGrabPointer(display, root, + False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, + GrabModeAsync, GrabModeAsync, + None, None, CurrentTime))) { + i |= 2; + } + (void)poll(NULL, 0, 100); } fds[0].fd = STDOUT_FILENO; diff --git a/xss.c b/xss.c index 3a6ae9d..1499299 100644 --- a/xss.c +++ b/xss.c @@ -21,6 +21,7 @@ #include #include +#include #include #include "obj.h" @@ -47,18 +48,31 @@ main(int argc, char *argv[]) try { int ss_event, ss_error; + int screen; XEvent event; + Window root; if (! (display = XOpenDisplay(NULL))) raise("cannot open display"); + screen = DefaultScreen(display); if (! XScreenSaverQueryExtension(display, &ss_event, &ss_error)) { raise("X server does not support MIT-SCREEN-SAVER extension."); } - XScreenSaverSelectInput(display, DefaultRootWindow(display), ScreenSaverNotifyMask); + if (! XScreenSaverRegister(display, screen, (XID)getpid(), XA_INTEGER)) { + raise("cannot register screen saver, is another one already running?"); + } + root = RootWindow(display, screen); + XScreenSaverSelectInput(display, root, ScreenSaverNotifyMask); while (! XNextEvent(display, &event)) { if (ss_event == event.type) { XScreenSaverNotifyEvent *sevent = (XScreenSaverNotifyEvent *)&event; if (ScreenSaverOn == sevent->state) { +#if 0 + XScreenSaverInfo info; + if (XScreenSaverQueryInfo(display, (Drawable)root, &info)) { + XLowerWindow(display, info.window); + } +#endif if (! child) { child = fork(); if (0 == child) { diff --git a/xsswin.c b/xsswin.c index 6b556ac..e1be891 100644 --- a/xsswin.c +++ b/xsswin.c @@ -58,8 +58,8 @@ main(int argc, char * const argv[]) CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWBackPixel, &wa); - XAllocColor(display, DefaultColormap(display, screen), &black); pmap = XCreateBitmapFromData(display, w, "\0", 1, 1); + black.pixel = BlackPixel(display, screen); invisible = XCreatePixmapCursor(display, pmap, pmap, &black, &black, 0, 0); XDefineCursor(display, w, invisible); XMapRaised(display, w);