diff options
Diffstat (limited to 'tools/gsr-global-hotkeys')
-rw-r--r-- | tools/gsr-global-hotkeys/hotplug.c | 8 | ||||
-rw-r--r-- | tools/gsr-global-hotkeys/main.c | 23 |
2 files changed, 28 insertions, 3 deletions
diff --git a/tools/gsr-global-hotkeys/hotplug.c b/tools/gsr-global-hotkeys/hotplug.c index ba3ef9c..5ea2978 100644 --- a/tools/gsr-global-hotkeys/hotplug.c +++ b/tools/gsr-global-hotkeys/hotplug.c @@ -22,7 +22,7 @@ bool hotplug_event_init(hotplug_event *self) { const int fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); if(fd == -1) - return false; /* Not root user */ + return false; if(bind(fd, (void*)&nls, sizeof(struct sockaddr_nl))) { close(fd); @@ -56,19 +56,21 @@ static void hotplug_event_parse_netlink_data(hotplug_event *self, const char *li if(strcmp(line, "SUBSYSTEM=input") == 0) self->subsystem_is_input = true; - if(self->subsystem_is_input && strncmp(line, "DEVNAME=", 8) == 0) + if(self->subsystem_is_input && strncmp(line, "DEVNAME=", 8) == 0) { callback(line+8, userdata); + self->event_is_add = false; + } } } /* Netlink uevent structure is documented here: https://web.archive.org/web/20160127215232/https://www.kernel.org/doc/pending/hotplug.txt */ void hotplug_event_process_event_data(hotplug_event *self, int fd, hotplug_device_added_callback callback, void *userdata) { const int bytes_read = read(fd, self->event_data, sizeof(self->event_data)); - int data_index = 0; if(bytes_read <= 0) return; /* Hotplug data ends with a newline and a null terminator */ + int data_index = 0; while(data_index < bytes_read) { hotplug_event_parse_netlink_data(self, self->event_data + data_index, callback, userdata); data_index += strlen(self->event_data + data_index) + 1; /* Skip null terminator as well */ diff --git a/tools/gsr-global-hotkeys/main.c b/tools/gsr-global-hotkeys/main.c index b64d60f..d05ca5f 100644 --- a/tools/gsr-global-hotkeys/main.c +++ b/tools/gsr-global-hotkeys/main.c @@ -116,6 +116,24 @@ static x11_context setup_x11_context(void) { return x_context; } +static bool is_gsr_global_hotkeys_already_running(void) { + FILE *f = fopen("/proc/bus/input/devices", "rb"); + if(!f) + return false; + + bool virtual_keyboard_running = false; + char line[1024]; + while(fgets(line, sizeof(line), f)) { + if(strstr(line, "gsr-ui virtual keyboard")) { + virtual_keyboard_running = true; + break; + } + } + + fclose(f); + return virtual_keyboard_running; +} + int main(int argc, char **argv) { keyboard_grab_type grab_type = KEYBOARD_GRAB_TYPE_ALL; if(argc == 2) { @@ -135,6 +153,11 @@ int main(int argc, char **argv) { return 1; } + if(is_gsr_global_hotkeys_already_running()) { + fprintf(stderr, "Error: gsr-global-hotkeys is already running\n"); + return 1; + } + x11_context x_context = setup_x11_context(); const uid_t user_id = getuid(); |