1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xutil.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define len(X) (sizeof X / sizeof X[0])
typedef struct {
char *command;
unsigned int mod;
KeySym key;
} Key;
static const Key hotkeys[] = {
//"Command MOD Key
{ "svte &", Mod1Mask, XK_g },
{ "svte -e mocp &", ShiftMask|ControlMask, XK_y }
};
int main() {
Display* dpy = XOpenDisplay(0);
Window root = DefaultRootWindow(dpy);
unsigned int i = 0;
for(i = 0; i < len(hotkeys); i++) {
XGrabKey(dpy, XKeysymToKeycode(dpy,hotkeys[i].key), hotkeys[i].mod, root, False, GrabModeAsync, GrabModeAsync);
}
XSelectInput(dpy, root, KeyPressMask );
while(true) {
XEvent ev;
XNextEvent(dpy, &ev);
if(ev.type == KeyPress) {
//ripped out of dwm
XKeyEvent *kev = &ev.xkey;
KeySym keysym = XKeycodeToKeysym(dpy, (KeyCode)kev->keycode, 0);
for(i = 0; i < len(hotkeys); i++) {
if(keysym == hotkeys[i].key && hotkeys[i].mod == kev->state) {
printf("executing '%s'\n", hotkeys[i].command);
system(hotkeys[i].command);
}
}
}
}
XCloseDisplay(dpy);
return 0;
}
|