aboutsummaryrefslogtreecommitdiff
path: root/tools/gsr-global-hotkeys/keyboard_event.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gsr-global-hotkeys/keyboard_event.c')
-rw-r--r--tools/gsr-global-hotkeys/keyboard_event.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/tools/gsr-global-hotkeys/keyboard_event.c b/tools/gsr-global-hotkeys/keyboard_event.c
index 74332ba..d69bbec 100644
--- a/tools/gsr-global-hotkeys/keyboard_event.c
+++ b/tools/gsr-global-hotkeys/keyboard_event.c
@@ -13,10 +13,13 @@
#include <dirent.h>
#include <sys/poll.h>
-/* LINUX */
+/* Linux */
#include <linux/input.h>
#include <linux/uinput.h>
+/* System */
+#include <X11/keysym.h>
+
#define GSR_UI_VIRTUAL_KEYBOARD_NAME "gsr-ui virtual keyboard"
#define KEY_RELEASE 0
@@ -27,22 +30,6 @@
#define KEYCODE_TO_XKB_KEYCODE(key) ((key) + 8)
-#define XK_Shift_L 0xffe1 /* Left shift */
-#define XK_Shift_R 0xffe2 /* Right shift */
-#define XK_Control_L 0xffe3 /* Left control */
-#define XK_Control_R 0xffe4 /* Right control */
-#define XK_Alt_L 0xffe9 /* Left alt */
-#define XK_Alt_R 0xffea /* Right alt */
-#define XK_Super_L 0xffeb /* Left super */
-#define XK_Super_R 0xffec /* Right super */
-
-#define XK_z 0x007a
-#define XK_F7 0xffc4
-#define XK_F8 0xffc5
-#define XK_F9 0xffc6
-#define XK_F10 0xffc7
-#define XK_F11 0xffc8
-
static inline int count_num_bits_set(unsigned char c) {
int n = 0;
n += (c & 1);
@@ -137,8 +124,8 @@ static void keyboard_event_process_key_state_change(keyboard_event *self, struct
static uint32_t keycode_to_keysym(keyboard_event *self, uint16_t keycode) {
const unsigned long xkb_keycode = KEYCODE_TO_XKB_KEYCODE(keycode);
- if(self->x_context.display && self->x_context.XKeycodeToKeysym && xkb_keycode <= 255)
- return self->x_context.XKeycodeToKeysym(self->x_context.display, xkb_keycode, 0);
+ if(self->display && xkb_keycode <= 255)
+ return XKeycodeToKeysym(self->display, xkb_keycode, 0);
else
return 0;
}
@@ -459,12 +446,12 @@ static int setup_virtual_keyboard_input(const char *name) {
return fd;
}
-bool keyboard_event_init(keyboard_event *self, bool poll_stdout_error, bool exclusive_grab, keyboard_grab_type grab_type, x11_context x_context) {
+bool keyboard_event_init(keyboard_event *self, bool poll_stdout_error, bool exclusive_grab, keyboard_grab_type grab_type, Display *display) {
memset(self, 0, sizeof(*self));
self->stdout_event_index = -1;
self->hotplug_event_index = -1;
self->grab_type = grab_type;
- self->x_context = x_context;
+ self->display = display;
if(exclusive_grab) {
self->uinput_fd = setup_virtual_keyboard_input(GSR_UI_VIRTUAL_KEYBOARD_NAME);
@@ -544,18 +531,16 @@ static void on_device_added_callback(const char *devname, void *userdata) {
keyboard_event_try_add_device_if_keyboard(keyboard_ev, dev_input_filepath);
}
-#define MappingNotify 34
-
static void keyboard_event_poll_x11_events(keyboard_event *self) {
- if(!self->x_context.display || !self->x_context.XPending || !self->x_context.XNextEvent || !self->x_context.XRefreshKeyboardMapping)
+ if(!self->display)
return;
XEvent xev;
- while(self->x_context.XPending(self->x_context.display)) {
+ while(XPending(self->display)) {
xev.type = 0;
- self->x_context.XNextEvent(self->x_context.display, &xev);
+ XNextEvent(self->display, &xev);
if(xev.type == MappingNotify)
- self->x_context.XRefreshKeyboardMapping(xev.data);
+ XRefreshKeyboardMapping(&xev.xmapping);
}
}