Skip to content

Instantly share code, notes, and snippets.

@grawity
Last active January 10, 2020 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grawity/5f52f8ded53c7ffe17ed102aea226dbc to your computer and use it in GitHub Desktop.
Save grawity/5f52f8ded53c7ffe17ed102aea226dbc to your computer and use it in GitHub Desktop.
#if 0
src = $(MAKEFILE_LIST)
app = $(basename $(src))
$(app): LDLIBS = -lX11 -lXi
$(app): $(src)
define source
#endif
/* http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html */
#define _GNU_SOURCE
#include <X11/Xlib.h>
#include <X11/extensions/XInput2.h>
#include <err.h>
#include <stdlib.h>
int main(void) {
Display *d;
Window rw;
int xinput_op, foo;
unsigned char mask[2] = {0};
XIEventMask ximask;
XEvent ev;
XIHierarchyEvent *hev;
d = XOpenDisplay(NULL);
if (!d)
errx(1, "cannot open display");
if (!XQueryExtension(d, "XInputExtension", &xinput_op, &foo, &foo))
errx(1, "no XInput extension on display");
rw = RootWindow(d, DefaultScreen(d));
XISetMask(mask, XI_HierarchyChanged);
ximask.mask = mask;
ximask.mask_len = sizeof(mask);
ximask.deviceid = XIAllDevices;
XISelectEvents(d, rw, &ximask, 1);
XFlush(d);
for (;;) {
XNextEvent(d, &ev);
if (ev.type != GenericEvent)
continue;
/* XInput2 always uses extended events */
/* http://who-t.blogspot.com/2009/07/xi2-and-xlib-cookies.html */
if (ev.xcookie.extension != xinput_op)
continue;
if (ev.xcookie.evtype != XI_HierarchyChanged)
continue;
if (!XGetEventData(d, &ev.xcookie))
continue;
hev = ev.xcookie.data;
if (!(hev->flags & XIDeviceEnabled))
continue;
warnx("device enabled");
system("xmodmap ~/.Xmodmap");
XFreeEventData(d, &ev.xcookie);
}
}
#if 0
endef
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment