Try three times to grab keyboard.

I should probably make it try forever.  Who knows.  Maybe this is a bad idea.
This commit is contained in:
Neale Pickett 2008-04-18 11:43:12 -06:00
parent 1d7330dce4
commit 9c41538e70
3 changed files with 31 additions and 15 deletions

View File

@ -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,
for (i = 0; i < 3; ) {
if ((! (i & 1)) && (GrabSuccess == XGrabKeyboard(display, root,
True,
GrabModeAsync, GrabModeAsync,
CurrentTime)) {
raise("cannot grab keyboard");
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;

16
xss.c
View File

@ -21,6 +21,7 @@
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/extensions/scrnsaver.h>
#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) {

View File

@ -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);