This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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