-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremap.c
32 lines (30 loc) · 971 Bytes
/
remap.c
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
#include "remap.h"
XKeyEvent
makeKeyEvent(Display *display, Window win, Window winRoot, Bool press, KeyCode keycode, int modifiers) {
XKeyEvent event = {
.display = display,
.window = win,
.root = winRoot,
.subwindow = None,
.time = CurrentTime,
.x = 1,
.y = 1,
.x_root = 1,
.y_root = 1,
.same_screen = True,
.keycode = keycode,
.state = modifiers,
.type = press ? KeyPress : KeyRelease
};
return event;
}
void
sendKey(KeyCode keycode, int modifiers) {
if (!selmon || !selmon->sel || !selmon->sel->win)
return ;
XKeyEvent kep = makeKeyEvent(dpy, selmon->sel->win, root, True, keycode, modifiers);
XSendEvent(dpy, selmon->sel->win, True, KeyPressMask, (XEvent*)&kep);
XKeyEvent ker = makeKeyEvent(dpy, selmon->sel->win, root, False, keycode, modifiers);
XSendEvent(dpy, selmon->sel->win, True, KeyPressMask, (XEvent*)&ker);
XUngrabKeyboard(dpy, CurrentTime);
}