ratpoison-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RP] xgrabkeyboard race/fail patch


From: twb
Subject: [RP] xgrabkeyboard race/fail patch
Date: Sat Nov 22 18:53:03 2003

I noticed that since RP started using XGrabKeyboard for various things
(2003-08-30), there's been a race condition calling interactive RP
commands from my kluge'd keybinder (epist).

It would XGrabKeyboard, fork, XUngrabKeyboard.  RP tries to `Grab
before epist `Ungrabs, and so RP just sits around waiting for input it
can't receive.

This patch lets RP handle failure to XGrabKeyboard.

-trent
-- 
<atticus> My parents think I'm nuts. I sit on my computer most evenings 
laughing at the monitor.
<atticus> Then I turn it on and come here.

harpo:/foo/pkg/cvs/ratpoison/ratpoison$ cvs -z9 diff
cvs server: Diffing .
cvs server: Diffing contrib
cvs server: Diffing debian
cvs server: Diffing doc
cvs server: Diffing src
Index: src/actions.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/actions.c,v
retrieving revision 1.185
diff -r1.185 actions.c
1694c1694,1705
<       XGrabKeyboard (dpy, s->key_window, False, GrabModeSync, GrabModeAsync, 
CurrentTime);
---
>       int XGrabKeyboardError=0;
>       int XGrabKeyboardLoop=0;
>       while (XGrabKeyboardError = XGrabKeyboard (dpy, s->key_window, False, 
> GrabModeSync, GrabModeAsync, CurrentTime)
>            && XGrabKeyboardLoop < 10) {
>       PRINT_DEBUG(("Couldn't grab the keyboard!  Retry in 0.01 seconds.\n"));
>       ++XGrabKeyboardLoop;
>       usleep(10000);
>       }
>       if (XGrabKeyboardError) {
>       message (MESSAGE_XGRABKEYBOARD_ERROR);
>       return NULL;
>       }
1844c1855,1870
<   XGrabKeyboard (dpy, s->help_window, False, GrabModeSync, GrabModeAsync, 
CurrentTime);
---
>   int XGrabKeyboardError=0;
>   int XGrabKeyboardLoop=0;
>   while (XGrabKeyboardError = XGrabKeyboard (dpy, s->help_window, False, 
> GrabModeSync, GrabModeAsync, CurrentTime)
>        && XGrabKeyboardLoop < 10) {
>     PRINT_DEBUG(("Couldn't grab the keyboard!  Retry in 0.01 seconds.\n"));
>     ++XGrabKeyboardLoop;
>     usleep(10000);
>   }
>   if (XGrabKeyboardError) {
>     XUnmapWindow (dpy, s->help_window);
>     /* The help window overlaps the bar, so redraw it. */
>     if (current_screen()->bar_is_raised)
>       show_last_message();
>     message (MESSAGE_XGRABKEYBOARD_ERROR);
>     return NULL;
>   }
1918c1944,1959
<       XGrabKeyboard (dpy, s->help_window, False, GrabModeSync, GrabModeAsync, 
CurrentTime);
---
>       int XGrabKeyboardError=0;
>       int XGrabKeyboardLoop=0;
>       while (XGrabKeyboardError = XGrabKeyboard (dpy, s->help_window, False, 
> GrabModeSync, GrabModeAsync, CurrentTime)
>            && XGrabKeyboardLoop < 10) {
>       PRINT_DEBUG(("Couldn't grab the keyboard!  Retry in 0.01 seconds.\n"));
>       ++XGrabKeyboardLoop;
>       usleep(10000);
>       }
>       if (XGrabKeyboardError) {
>       XUnmapWindow (dpy, s->help_window);
>       /* The help window overlaps the bar, so redraw it. */
>       if (current_screen()->bar_is_raised)
>         show_last_message();
>       message (MESSAGE_XGRABKEYBOARD_ERROR);
>       return NULL;
>       }
3335c3376,3387
<       XGrabKeyboard (dpy, s->key_window, False, GrabModeSync, GrabModeAsync, 
CurrentTime);
---
>       int XGrabKeyboardError=0;
>       int XGrabKeyboardLoop=0;
>       while (XGrabKeyboardError = XGrabKeyboard (dpy, s->key_window, False, 
> GrabModeSync, GrabModeAsync, CurrentTime)
>            && XGrabKeyboardLoop < 10) {
>       PRINT_DEBUG(("Couldn't grab the keyboard!  Retry in 0.01 seconds.\n"));
>       ++XGrabKeyboardLoop;
>       usleep(10000);
>       }
>       if (XGrabKeyboardError) {
>       message (MESSAGE_XGRABKEYBOARD_ERROR);
>       return NULL;
>       }
3982c4034,4046
<   XGrabKeyboard (dpy, current_screen()->key_window, False, GrabModeSync, 
GrabModeAsync, CurrentTime);
---
>   
>   int XGrabKeyboardError=0;
>   int XGrabKeyboardLoop=0;
>   while (XGrabKeyboardError = XGrabKeyboard (dpy, 
> current_screen()->key_window, False, GrabModeSync, GrabModeAsync, CurrentTime)
>        && XGrabKeyboardLoop < 10) {
>     PRINT_DEBUG(("Couldn't grab the keyboard!  Retry in 0.01 seconds.\n"));
>     ++XGrabKeyboardLoop;
>     usleep(10000);
>   }
>   if (XGrabKeyboardError) {
>     message (MESSAGE_XGRABKEYBOARD_ERROR);
>     return NULL;
>   }
Index: src/input.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/input.c,v
retrieving revision 1.38
diff -r1.38 input.c
403c403,416
<   XGrabKeyboard (dpy, s->input_window, False, GrabModeSync, GrabModeAsync, 
CurrentTime);
---
>   int XGrabKeyboardError=0;
>   int XGrabKeyboardLoop=0;
>   while (XGrabKeyboardError = XGrabKeyboard (dpy, s->input_window, False, 
> GrabModeSync, GrabModeAsync, CurrentTime)
>        && XGrabKeyboardLoop < 10) {
>     PRINT_DEBUG(("Couldn't grab the keyboard!  Retry in 0.01 seconds.\n"));
>     ++XGrabKeyboardLoop;
>     usleep(10000);
>   }
>   if (XGrabKeyboardError) {
>     input_line_free (line);
>     XUnmapWindow (dpy, s->input_window);
>     message (MESSAGE_XGRABKEYBOARD_ERROR);
>     return NULL;
>   }
Index: src/messages.h
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/messages.h,v
retrieving revision 1.13
diff -r1.13 messages.h
48a49,50
> #define MESSAGE_XGRABKEYBOARD_ERROR " Could not grab keyboard (synchronously) 
> "
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]