]> Dogcows Code - chaz/openbox/commitdiff
only xungrabkeyboard when we actually have a passive grab on it
authorDana Jansens <danakj@orodu.net>
Tue, 12 Jun 2007 15:53:14 +0000 (15:53 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 12 Jun 2007 15:53:14 +0000 (15:53 +0000)
openbox/event.c
openbox/grab.c
openbox/grab.h
openbox/keyboard.c

index 9dd78c17934960dd6d4f3bce946b633445447b97..12ecdac0398bbc5d7b6ecf2f78c9e8ff19448a93 100644 (file)
@@ -1828,10 +1828,9 @@ static void event_handle_user_input(ObClient *client, XEvent *e)
                in the case where it is animating before disappearing */
             if (!client || !frame_iconify_animating(client->frame))
                 mouse_event(client, e);
-        } else if (e->type == KeyPress) {
+        } else
             keyboard_event((focus_cycle_target ? focus_cycle_target :
                             (client ? client : focus_client)), e);
-        }
     }
 }
 
@@ -1920,20 +1919,20 @@ static gboolean is_enter_focus_event_ignored(XEvent *e)
 
 void event_cancel_all_key_grabs()
 {
-    if (keyboard_interactively_grabbed())
+    if (keyboard_interactively_grabbed()) {
         keyboard_interactive_cancel();
-    else if (menu_frame_visible)
+        ob_debug("KILLED interactive event\n");
+    }
+    else if (menu_frame_visible) {
         menu_frame_hide_all();
-    else if (grab_on_keyboard())
+        ob_debug("KILLED open menus\n");
+    }
+    else if (grab_on_keyboard()) {
         ungrab_keyboard();
+        ob_debug("KILLED active grab on keyboard\n");
+    }
     else
-        /* If we don't have the keyboard grabbed, then ungrab it with
-           XUngrabKeyboard, so that there is not a passive grab left
-           on from the KeyPress. If the grab is left on, and focus
-           moves during that time, it will be NotifyWhileGrabbed, and
-           applications like to ignore those! */
-        XUngrabKeyboard(ob_display, CurrentTime);
-
+        ungrab_passive_key();
 }
 
 gboolean event_time_after(Time t1, Time t2)
index ac91a6bcdb692f442c5aa3b9f9b565b2949061ad..85027d5dceb02c2931ffbc0e4f67018e88272803 100644 (file)
@@ -39,6 +39,7 @@ static guint kgrabs = 0;
 static guint pgrabs = 0;
 /*! The time at which the last grab was made */
 static Time  grab_time = CurrentTime;
+static gint passive_count = 0;
 
 static Time ungrab_time()
 {
@@ -78,8 +79,10 @@ gboolean grab_keyboard_full(gboolean grab)
                                 event_curtime) == Success;
             if (!ret)
                 --kgrabs;
-            else
+            else {
+                passive_count = 0;
                 grab_time = event_curtime;
+            }
         } else
             ret = TRUE;
     } else if (kgrabs > 0) {
@@ -207,3 +210,20 @@ void ungrab_all_keys(Window win)
 {
     XUngrabKey(ob_display, AnyKey, AnyModifier, win);
 }
+
+void grab_key_passive_count(int change)
+{
+    if (grab_on_keyboard()) return;
+    passive_count += change;
+    if (passive_count < 0) passive_count = 0;
+}
+
+void ungrab_passive_key()
+{
+    ob_debug("ungrabbing %d passive grabs\n", passive_count);
+    if (passive_count) {
+        /* kill out passive grab */
+        XUngrabKeyboard(ob_display, event_curtime);
+        passive_count = 0;
+    }
+}
index 8a654c8b0caa1f436c895fad3c4490fabf623dd3..30c4b709b550ce7005e96fe28a2868812aeb8fb9 100644 (file)
@@ -49,4 +49,7 @@ void grab_key(guint keycode, guint state, Window win, gint keyboard_mode);
 
 void ungrab_all_keys(Window win);
 
+void grab_key_passive_count(int change);
+void ungrab_passive_key();
+
 #endif
index e62f5011292a21456533ce6777cb482a9af65d76..9fd38def9452a03d1534cb3cef0a0ab2cedbcc47 100644 (file)
@@ -276,7 +276,13 @@ void keyboard_event(ObClient *client, const XEvent *e)
 {
     KeyBindingTree *p;
 
+    if (e->type == KeyRelease) {
+        grab_key_passive_count(-1);
+        return;
+    }
+
     g_assert(e->type == KeyPress);
+    grab_key_passive_count(1);
 
     if (e->xkey.keycode == config_keyboard_reset_keycode &&
         e->xkey.state == config_keyboard_reset_state)
This page took 0.028989 seconds and 4 git commands to generate.