diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2024-03-04 03:41:46 -0800 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2024-03-04 03:41:46 -0800 |
commit | 33163fb30686fdac5891ec860c19996ebec7683a (patch) | |
tree | 6b78f0523e9c5fc5ccba3ab3b0910d4cda37c1de | |
download | xkbdlock-33163fb30686fdac5891ec860c19996ebec7683a.tar.gz xkbdlock-33163fb30686fdac5891ec860c19996ebec7683a.tar.xz |
initial import
-rw-r--r-- | COPYING | 19 | ||||
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | xlockkbd.c | 43 |
3 files changed, 78 insertions, 0 deletions
@@ -0,0 +1,19 @@ +Copyright 2024 David Vazgenovich Shakaryan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..066d2ac --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +CFLAGS += -O2 -Wall -Wextra -Wpedantic +LDFLAGS += -lX11 + +TARGET := xlockkbd + +SRC := $(wildcard *.c) +OBJ := $(SRC:.c=.o) + +all: $(TARGET) + +$(TARGET): $(OBJ) + +clean: + rm -f $(TARGET) $(OBJ) + +.PHONY: all clean diff --git a/xlockkbd.c b/xlockkbd.c new file mode 100644 index 0000000..fd9e659 --- /dev/null +++ b/xlockkbd.c @@ -0,0 +1,43 @@ +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> + +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; +} |