+/* try to grab pointer, we may have to wait for another process to ungrab */
+static void
+grabpointer(void)
+{
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 };
+ int i;
+
+ for (i = 0; i < 1000; i++) {
+ if (XGrabPointer(dpy, rootwin, True, ButtonPressMask,
+ GrabModeAsync, GrabModeAsync, None,
+ None, CurrentTime) == GrabSuccess)
+ return;
+ nanosleep(&ts, NULL);
+ }
+ errx(1, "cannot grab keyboard");
+}
+
+/* try to grab keyboard, we may have to wait for another process to ungrab */
+static void
+grabkeyboard(void)
+{
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 };
+ int i;
+
+ for (i = 0; i < 1000; i++) {
+ if (XGrabKeyboard(dpy, rootwin, True, GrabModeAsync,
+ GrabModeAsync, CurrentTime) == GrabSuccess)
+ return;
+ nanosleep(&ts, NULL);
+ }
+ errx(1, "cannot grab keyboard");
+}
+