| 1 | #define _GNU_SOURCE
|
|---|
| 2 | #include <dlfcn.h>
|
|---|
| 3 | #include <X11/Xlib.h>
|
|---|
| 4 |
|
|---|
| 5 | #define LIBRARY "libX11.so"
|
|---|
| 6 | #define FROM 0x84
|
|---|
| 7 | #define TO 0x80
|
|---|
| 8 |
|
|---|
| 9 | int (*real_function)(Display* display, XEvent* event);
|
|---|
| 10 |
|
|---|
| 11 | void modify_event(XEvent* event)
|
|---|
| 12 | {
|
|---|
| 13 | if(event == 0)
|
|---|
| 14 | return;
|
|---|
| 15 | switch(event->type)
|
|---|
| 16 | {
|
|---|
| 17 | case KeyPress:
|
|---|
| 18 | case KeyRelease:
|
|---|
| 19 | if((event->xkey.state & FROM) == FROM)
|
|---|
| 20 | event->xkey.state = (event->xkey.state & ~FROM) | TO;
|
|---|
| 21 | break;
|
|---|
| 22 | }
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | int XNextEvent(Display* display, XEvent* event)
|
|---|
| 26 | {
|
|---|
| 27 | if(real_function == NULL)
|
|---|
| 28 | {
|
|---|
| 29 | void* handle = dlopen(LIBRARY, RTLD_LAZY);
|
|---|
| 30 | real_function = dlsym(handle, "XNextEvent");
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | int ret = real_function(display, event);
|
|---|
| 34 | modify_event(event);
|
|---|
| 35 | return ret;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|