add 'grab_server' for grabbing .. the .. server!
authorDana Jansens <danakj@orodu.net>
Tue, 18 Mar 2003 20:00:44 +0000 (20:00 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 18 Mar 2003 20:00:44 +0000 (20:00 +0000)
openbox/client.c
openbox/grab.c
openbox/grab.h

index c8d33e8..790dba5 100644 (file)
@@ -5,6 +5,7 @@
 #include "frame.h"
 #include "engine.h"
 #include "event.h"
+#include "grab.h"
 #include "focus.h"
 #include "stacking.h"
 #include "dispatch.h"
@@ -120,9 +121,8 @@ void client_manage(Window window)
     XWindowAttributes attrib;
     XSetWindowAttributes attrib_set;
 /*    XWMHints *wmhint; */
-     
-    XGrabServer(ob_display);
-    XSync(ob_display, FALSE);
+
+    grab_server(TRUE);
 
     /* check if it has already been unmapped by the time we started mapping
        the grab does a sync so we don't have to here */
@@ -130,16 +130,14 @@ void client_manage(Window window)
        XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
        XPutBackEvent(ob_display, &e);
     
-       XUngrabServer(ob_display);
-       XFlush(ob_display);
+        grab_server(FALSE);
        return; /* don't manage it */
     }
 
     /* make sure it isn't an override-redirect window */
     if (!XGetWindowAttributes(ob_display, window, &attrib) ||
        attrib.override_redirect) {
-       XUngrabServer(ob_display);
-       XFlush(ob_display);
+        grab_server(FALSE);
        return; /* don't manage it */
     }
   
@@ -148,8 +146,7 @@ void client_manage(Window window)
        if ((wmhint->flags & StateHint) &&
            wmhint->initial_state == WithdrawnState) {
            /\* XXX: make dock apps work! *\/
-           XUngrabServer(ob_display);
-           XFlush(ob_display);
+            grab_server(FALSE);
            XFree(wmhint);
            return;
        }
@@ -184,8 +181,7 @@ void client_manage(Window window)
 
     client_apply_startup_state(client);
 
-    XUngrabServer(ob_display);
-    XFlush(ob_display);
+    grab_server(FALSE);
      
     client_list = g_slist_append(client_list, client);
     stacking_list = g_list_append(stacking_list, client);
index 3bba14b..c6beee7 100644 (file)
@@ -2,7 +2,7 @@
 #include <glib.h>
 #include <X11/Xlib.h>
 
-static guint kgrabs, pgrabs;
+static guint kgrabs, pgrabs, sgrabs;
 
 void grab_keyboard(gboolean grab)
 {
@@ -28,13 +28,29 @@ void grab_pointer(gboolean grab, Cursor cur)
     }
 }
 
+void grab_server(gboolean grab)
+{
+    if (grab) {
+        if (sgrabs++ == 0) {
+            XGrabServer(ob_display);
+            XSync(ob_display, FALSE);
+        }
+    } else if (sgrabs > 0) {
+        if (--sgrabs == 0) {
+            XUngrabServer(ob_display);
+            XFlush(ob_display);
+        }
+    }
+}
+
 void grab_startup()
 {
-    kgrabs = pgrabs = 0;
+    kgrabs = pgrabs = sgrabs = 0;
 }
 
 void grab_shutdown()
 {
     while (kgrabs) grab_keyboard(FALSE);
     while (pgrabs) grab_pointer(FALSE, None);
+    while (sgrabs) grab_server(FALSE);
 }
index 49c6a43..d6a1b78 100644 (file)
@@ -9,5 +9,6 @@ void grab_shutdown();
 
 void grab_keyboard(gboolean grab);
 void grab_pointer(gboolean grab, Cursor cur);
+void grab_server(gboolean grab);
 
 #endif