#include #include #include #include #include static void die(const char *s) { fprintf(stderr, "xlockkbd: %s\n", s); exit(1); } static bool grab_kbd(Display *d, int screen) { return (XGrabKeyboard(d, RootWindow(d, screen), True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess); } static void wait_for_key(Display *d) { XEvent ev; while (!XNextEvent(d, &ev)) { if (ev.type == KeyPress && XLookupKeysym(&ev.xkey, 0) == XK_Escape) break; } } int main() { Display *d = XOpenDisplay(NULL); if (!d) die("cannot open display"); for (int i = 0; i < ScreenCount(d); ++i) { if (!grab_kbd(d, i)) die("failed to grab keyboard"); } wait_for_key(d); return 0; }