meep

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 6ba476dc2ba557ce39ca1242b33b01f1b7b56312
Author: Samdal <samdal@protonmail.com>
Date:   Sat,  6 Jan 2024 00:13:14 +0100

meep

Diffstat:
AMakefile | 9+++++++++
Ameep.c | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,9 @@ +all: meep + +meep: meep.c Makefile + gcc `pkg-config --cflags libnotify x11 xi` meep.c `pkg-config --libs libnotify x11 xi` -o meep + +clean: + rm meep + +.phony: all clean diff --git a/meep.c b/meep.c @@ -0,0 +1,64 @@ +#include <libnotify/notify.h> + +#include <X11/XKBlib.h> +#include <X11/extensions/XInput2.h> + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> + +int main(int argc, char * argv[]) { + int xiOpcode, queryEvent, queryError; + + notify_init("mehehe meep"); + + Display * disp = XOpenDisplay(":0"); + Window root = DefaultRootWindow(disp); + if (!XQueryExtension(disp, "XInputExtension", &xiOpcode, &queryEvent, &queryError)) return 2; + + { + XIEventMask m; + m.deviceid = XIAllMasterDevices; + m.mask_len = XIMaskLen(XI_LASTEVENT); + m.mask = calloc(m.mask_len, sizeof(char)); + XISetMask(m.mask, XI_RawKeyPress); + XISelectEvents(disp, root, &m, 1); + XSync(disp, false); + free(m.mask); + } + + XkbSelectEventDetails(disp, XkbUseCoreKbd, XkbStateNotify, XkbGroupStateMask, XkbGroupStateMask); + + char* matches[] = {"mehehe", "meep", "goop"}; + int states[sizeof(matches) / sizeof(*matches)] = {0}; + + for (;;) { + XEvent event; + XGenericEventCookie *cookie = (XGenericEventCookie*)&event.xcookie; + XNextEvent(disp, &event); + + if (XGetEventData(disp, cookie)) { + if (cookie->extension == xiOpcode && cookie->evtype == XI_RawKeyPress) { + XIRawEvent *ev = cookie->data; + KeySym s = XkbKeycodeToKeysym(disp, ev->detail, 0, 0); + char *str = XKeysymToString(s); + if (NULL == str) continue; + + for (int i = 0; i < sizeof(matches) / sizeof(*matches); i++) { + if (*str == matches[i][states[i]]) { + states[i]++; + if (matches[i][states[i]] == 0) { + NotifyNotification* notif = notify_notification_new(matches[i], matches[i], NULL); + notify_notification_show(notif, NULL); + states[i] = 0; + } + } else { + states[i] = 0; + } + } + } + XFreeEventData(disp, cookie); + } + } +}