-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeys.cc
90 lines (72 loc) · 1.62 KB
/
keys.cc
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "keys.h"
#include "events.h"
#include "threewm.h"
#include <stdlib.h>
#include <string.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <vector>
using namespace std;
#define SHIFT (1 << 24)
#define CTRL (1 << 25)
#define ALT (1 << 26)
class key_entry {
public:
int code;
key_entry(int key_code, void (*key_ev)(const string&), const string key_arg):
code {key_code}, event_fn {key_ev}, arg {key_arg} {};
void exe();
private:
void (*event_fn)(const string&);
const string arg;
};
#define KEY(c, e, a) key_entry(c, e, a),
static vector<class key_entry> keys = {
#include "config_key.def"
};
#undef KEY
void key_entry::exe()
{
event_fn(arg);
}
static int keys_run_impl(int code)
{
for (auto &k: keys) {
if (k.code == code) {
k.exe();
return 0;
}
}
return -1;
}
int keys_run(XKeyEvent* e)
{
int k = XKeycodeToKeysym(dpy, e->keycode, 0);
if (e->state & ShiftMask)
k |= SHIFT;
if (!(KEY_EVENT_MODIFIERS & ControlMask) && e->state & ControlMask)
k |= CTRL;
if (!(KEY_EVENT_MODIFIERS & Mod1Mask) && e->state & Mod1Mask)
k |= ALT;
return keys_run_impl(k);
}
void keys_run_button(XButtonEvent* be) {
int k = 0;
if (be->button == Button1)
k = XK_Pointer_Button1;
else if (be->button == Button2)
k = XK_Pointer_Button2;
else if (be->button == Button3)
k = XK_Pointer_Button3;
else if (be->button == Button4)
k = XK_Pointer_Button4;
else if (be->button == Button5)
k = XK_Pointer_Button5;
if (be->state & ShiftMask)
k |= SHIFT;
if (be->state & ControlMask)
k |= CTRL;
if (be->state & Mod1Mask)
k |= ALT;
keys_run_impl(k);
}