aboutsummaryrefslogtreecommitdiff
path: root/tools/gsr-global-hotkeys/main.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-12-16 21:48:35 +0100
committerdec05eba <dec05eba@protonmail.com>2024-12-16 21:48:35 +0100
commit14b0d376a8191a8873b1f866a3cfe777bbe091ce (patch)
tree6fc370efbb84ea2585cf867da4137c9a39561472 /tools/gsr-global-hotkeys/main.c
parenteb3660a4d81ede493943c13cba959ea061f2d536 (diff)
Prevent focused application from receiving global hotkey keys on wayland as well (massive hack)
Diffstat (limited to 'tools/gsr-global-hotkeys/main.c')
-rw-r--r--tools/gsr-global-hotkeys/main.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/tools/gsr-global-hotkeys/main.c b/tools/gsr-global-hotkeys/main.c
index 1b2dc4a..62d34cc 100644
--- a/tools/gsr-global-hotkeys/main.c
+++ b/tools/gsr-global-hotkeys/main.c
@@ -23,43 +23,46 @@ static global_hotkey global_hotkeys[NUM_GLOBAL_HOTKEYS] = {
{ .key = KEY_F10, .modifiers = KEYBOARD_MODKEY_ALT, .action = "replay_save" }
};
-static void on_key_callback(uint32_t key, uint32_t modifiers, int press_status, void *userdata) {
+static bool on_key_callback(uint32_t key, uint32_t modifiers, int press_status, void *userdata) {
(void)userdata;
if(press_status != 1) /* 1 == Pressed */
- return;
+ return true;
for(int i = 0; i < NUM_GLOBAL_HOTKEYS; ++i) {
if(key == global_hotkeys[i].key && modifiers == global_hotkeys[i].modifiers) {
puts(global_hotkeys[i].action);
fflush(stdout);
+ return false;
}
}
+
+ return true;
}
int main(void) {
const uid_t user_id = getuid();
if(geteuid() != 0) {
if(setuid(0) == -1) {
- fprintf(stderr, "error: failed to change user to root\n");
+ fprintf(stderr, "Error: failed to change user to root\n");
return 1;
}
}
keyboard_event keyboard_ev;
- if(!keyboard_event_init(&keyboard_ev, true)) {
+ if(!keyboard_event_init(&keyboard_ev, true, true)) {
fprintf(stderr, "Error: failed to setup hotplugging and no keyboard input devices were found\n");
setuid(user_id);
return 1;
}
+ fprintf(stderr, "Info: global hotkeys setup, waiting for hotkeys to be pressed\n");
+
for(;;) {
keyboard_event_poll_events(&keyboard_ev, -1, on_key_callback, NULL);
if(keyboard_event_stdout_has_failed(&keyboard_ev)) {
fprintf(stderr, "Info: stdout closed (parent process likely closed this process), exiting...\n");
break;
}
-
-
}
keyboard_event_deinit(&keyboard_ev);