[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RP] xgrabkeyboard race/fail patch
From: |
twb |
Subject: |
Re: [RP] xgrabkeyboard race/fail patch |
Date: |
Sat Nov 22 23:53:02 2003 |
Quoth Cameron Patrick <address@hidden> on or about Sun, 23 Nov 2003 11:07:16
+0800:
> On Sun, Nov 23, 2003 at 02:01:20PM +1100, twb wrote:
>
> | This patch lets RP handle failure to XGrabKeyboard.
>
> Eww. Could you extract your error-loopy bit out into a separate
> function and call that? Having several copies of essentially identical
> code strewn around the place is yucky.
>
> Cameron.
I know. It should be a cpp macro, but I haven't worked them out yet.
Also, I've only tried the one in input.c, because I don't use -i've
:fselect or :resize -- it was more an afterthought. Finally, I have
an irrational fear of cosmetic branching, because deep down where
normal people keep religion, it feels like I'm wasting processage on a
useless BRA.
Anyhow, how's this? I put the definition in global.h, which is
probably wrong. Should be in rp.h? Did the diff properly this time.
-trent
--
<darkaeon> How much money do you make now? I know it can't be much since you're
on irc.
<MadHatter>I'm not even on irc.
<darkaeon> I programmed some lego mindstorms to get on irc for me.
cvs server: Diffing .
Index: actions.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/actions.c,v
retrieving revision 1.185
diff -u -r1.185 actions.c
--- actions.c 18 Nov 2003 05:06:35 -0000 1.185
+++ actions.c 23 Nov 2003 07:44:35 -0000
@@ -1691,7 +1691,11 @@
scale. */
if (num_frames (s) < 2) return NULL;
- XGrabKeyboard (dpy, s->key_window, False, GrabModeSync, GrabModeAsync,
CurrentTime);
+ rp_xgrabkeyboard (dpy, s->key_window, False, GrabModeSync,
GrabModeAsync, CurrentTime)
+ {
+ message (MESSAGE_XGRABKEYBOARD_ERROR);
+ return NULL;
+ }
/* Save the frameset in case the user aborts. */
bk = screen_copy_frameset (s);
@@ -1841,7 +1845,15 @@
NULL};
XMapRaised (dpy, s->help_window);
- XGrabKeyboard (dpy, s->help_window, False, GrabModeSync, GrabModeAsync,
CurrentTime);
+ rp_xgrabkeyboard (dpy, s->help_window, False, GrabModeSync, GrabModeAsync,
CurrentTime)
+ {
+ 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;
+ }
/* Find the longest line. */
for(i=0; license_text[i]; i++)
@@ -1915,7 +1927,15 @@
char *keysym_name;
XMapRaised (dpy, s->help_window);
- XGrabKeyboard (dpy, s->help_window, False, GrabModeSync, GrabModeAsync,
CurrentTime);
+ rp_xgrabkeyboard (dpy, s->help_window, False, GrabModeSync,
GrabModeAsync, CurrentTime)
+ {
+ 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;
+ }
XDrawString (dpy, s->help_window, s->normal_gc,
10, y + defaults.font->max_bounds.ascent,
@@ -3332,7 +3352,11 @@
XSync (dpy, False);
/* Read a key. */
- XGrabKeyboard (dpy, s->key_window, False, GrabModeSync, GrabModeAsync,
CurrentTime);
+ rp_xgrabkeyboard (dpy, s->key_window, False, GrabModeSync,
GrabModeAsync, CurrentTime)
+ {
+ message (MESSAGE_XGRABKEYBOARD_ERROR);
+ return NULL;
+ }
read_key (&c, &mod, NULL, 0);
XUngrabKeyboard (dpy, CurrentTime);
@@ -3979,7 +4003,12 @@
return NULL;
}
- XGrabKeyboard (dpy, current_screen()->key_window, False, GrabModeSync,
GrabModeAsync, CurrentTime);
+
+ rp_xgrabkeyboard (dpy, current_screen()->key_window, False, GrabModeSync,
GrabModeAsync, CurrentTime)
+ {
+ message (MESSAGE_XGRABKEYBOARD_ERROR);
+ return NULL;
+ }
/* Change the mouse icon to indicate to the user we are waiting for
more keystrokes */
Index: globals.h
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/globals.h,v
retrieving revision 1.8
diff -u -r1.8 globals.h
--- globals.h 15 Oct 2003 22:26:19 -0000 1.8
+++ globals.h 23 Nov 2003 07:44:36 -0000
@@ -141,4 +141,18 @@
void set_rp_window_focus (rp_window *win);
void set_window_focus (Window window);
+#define XGRABKEYBOARD_LOOP_DEPTH 10
+#define XGRABKEYBOARD_UDELAY 10000
+#define rp_xgrabkeyboard(display, grab_window, owner_events, pointer_mode,
keyboard_mode, time) \
+ int XGrabKeyboardError=0; \
+ int XGrabKeyboardLoop=0; \
+ while (XGrabKeyboardError = XGrabKeyboard (display, grab_window,
owner_events, pointer_mode, keyboard_mode, time) \
+ && XGrabKeyboardLoop < XGRABKEYBOARD_LOOP_DEPTH) { \
+ PRINT_DEBUG(("Couldn't grab the keyboard! Retry in 0.01
seconds.\n")); \
+ ++XGrabKeyboardLoop; \
+ usleep(XGRABKEYBOARD_UDELAY); \
+ } \
+ if (XGrabKeyboardError)
+
+
#endif
Index: input.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/input.c,v
retrieving revision 1.38
diff -u -r1.38 input.c
--- input.c 2 Nov 2003 06:10:14 -0000 1.38
+++ input.c 23 Nov 2003 07:44:36 -0000
@@ -400,7 +400,13 @@
update_input_window (s, line);
- XGrabKeyboard (dpy, s->input_window, False, GrabModeSync, GrabModeAsync,
CurrentTime);
+ rp_xgrabkeyboard (dpy, s->input_window, False, GrabModeSync, GrabModeAsync,
CurrentTime)
+ {
+ input_line_free (line);
+ XUnmapWindow (dpy, s->input_window);
+ message (MESSAGE_XGRABKEYBOARD_ERROR);
+ return NULL;
+ }
for (;;)
{
Index: messages.h
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/messages.h,v
retrieving revision 1.13
diff -u -r1.13 messages.h
--- messages.h 25 May 2003 10:56:20 -0000 1.13
+++ messages.h 23 Nov 2003 07:44:36 -0000
@@ -46,4 +46,6 @@
#define MESSAGE_WELCOME " Welcome to ratpoison! Hit `%s %s' for help. "
#define MESSAGE_FRAME_STRING " Current Frame "
+#define MESSAGE_XGRABKEYBOARD_ERROR " Could not grab keyboard (asynchronously)
"
+
#endif /* ! _RATPOISON_MESSAGES_H */