]> Dogcows Code - chaz/openbox/commitdiff
provide functions for grabbing and ungrabbing the keyboard and pointer
authorDana Jansens <danakj@orodu.net>
Tue, 18 Mar 2003 19:51:56 +0000 (19:51 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 18 Mar 2003 19:51:56 +0000 (19:51 +0000)
openbox/Makefile.am
openbox/grab.c [new file with mode: 0644]
openbox/grab.h [new file with mode: 0644]
openbox/openbox.c

index 0958c83bd73048cdaf810c0a0d93c27c8e48a863..827758557ecb574ccd0b06562c7b41302dc44d29 100644 (file)
@@ -20,11 +20,11 @@ ob3_LDADD=@LIBINTL@ ../render/librender.a
 ob3_LDFLAGS=-export-dynamic
 ob3_SOURCES=client.c event.c extensions.c focus.c frame.c openbox.c prop.c \
        screen.c stacking.c xerror.c themerc.c timer.c dispatch.c \
-       engine.c plugin.c action.c
+       engine.c plugin.c action.c grab.c
 
 noinst_HEADERS=client.h event.h extensions.h focus.h frame.h geom.h gettext.h \
        openbox.h prop.h screen.h stacking.h xerror.h themerc.h dispatch.h \
-       timer.h engine.h plugin.h action.h
+       timer.h engine.h plugin.h action.h grab.h
 
 MAINTAINERCLEANFILES= Makefile.in
 
diff --git a/openbox/grab.c b/openbox/grab.c
new file mode 100644 (file)
index 0000000..3bba14b
--- /dev/null
@@ -0,0 +1,40 @@
+#include "openbox.h"
+#include <glib.h>
+#include <X11/Xlib.h>
+
+static guint kgrabs, pgrabs;
+
+void grab_keyboard(gboolean grab)
+{
+    if (grab) {
+        if (kgrabs++ == 0)
+            XGrabKeyboard(ob_display, ob_root, 0, GrabModeAsync, GrabModeSync,
+                          CurrentTime);
+    } else if (kgrabs > 0) {
+        if (--kgrabs == 0)
+            XUngrabKeyboard(ob_display, CurrentTime);
+    }
+}
+
+void grab_pointer(gboolean grab, Cursor cur)
+{
+    if (grab) {
+        if (pgrabs++ == 0)
+            XGrabPointer(ob_display, ob_root, False, 0, GrabModeAsync,
+                         GrabModeSync, FALSE, cur, CurrentTime);
+    } else if (pgrabs > 0) {
+        if (--pgrabs == 0)
+            XUngrabPointer(ob_display, CurrentTime);
+    }
+}
+
+void grab_startup()
+{
+    kgrabs = pgrabs = 0;
+}
+
+void grab_shutdown()
+{
+    while (kgrabs) grab_keyboard(FALSE);
+    while (pgrabs) grab_pointer(FALSE, None);
+}
diff --git a/openbox/grab.h b/openbox/grab.h
new file mode 100644 (file)
index 0000000..49c6a43
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __grab_h
+#define __grab_h
+
+#include <glib.h>
+#include <X11/Xlib.h>
+
+void grab_startup();
+void grab_shutdown();
+
+void grab_keyboard(gboolean grab);
+void grab_pointer(gboolean grab, Cursor cur);
+
+#endif
index bf8913bc1bcab5c70424f6299ea8c46007df4370..fd4973da4514dbb17a6245a10d6a142a4f3a91b6 100644 (file)
@@ -8,6 +8,7 @@
 #include "focus.h"
 #include "extensions.h"
 #include "gettext.h"
+#include "grab.h"
 #include "engine.h"
 #include "themerc.h"
 #include "plugin.h"
@@ -137,11 +138,13 @@ int main(int argc, char **argv)
        screen_startup();
        focus_startup();
        client_startup();
+        grab_startup();
         plugin_startup();
 
         /* XXX load all plugins!! */
         plugin_open("focus");
         plugin_open("keyboard");
+        plugin_open("mouse");
 
        /* get all the existing windows */
        client_manage_all();
@@ -154,7 +157,8 @@ int main(int argc, char **argv)
 
        client_unmanage_all();
 
-        plugin_shutdown();
+        plugin_shutdown(); /* calls all the plugins' shutdown functions */
+        grab_shutdown();
        client_shutdown();
        screen_shutdown();
        event_shutdown();
This page took 0.030759 seconds and 4 git commands to generate.