diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-12-29 15:31:28 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-12-29 15:31:28 +0100 |
commit | 78f44a9486bbc682ea723bb76a24091421c41d78 (patch) | |
tree | c5309c1eb65763b15c0b871bb474c2ccdea8c434 | |
parent | b96b877a1a5c96d3d8982e43637d4223fdf99c14 (diff) |
Detect multiple instances of gsr-ui by detecting virtual keyboard presence instead. This works in flatpak
-rw-r--r-- | src/main.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index 3abccd0..ae08bb8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -133,6 +133,24 @@ static std::unique_ptr<gsr::GlobalHotkeysLinux> register_linux_hotkeys(gsr::Over return global_hotkeys; } +static bool is_gsr_ui_virtual_keyboard_running() { + 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; +} + static void usage() { printf("usage: gsr-ui [action]\n"); printf("OPTIONS:\n"); @@ -171,12 +189,19 @@ int main(int argc, char **argv) { usage(); } - const pid_t gsr_ui_pid = gsr::pidof("gsr-ui"); - if(gsr_ui_pid != -1) { + // TODO: This is a shitty method to detect if multiple instances of gsr-ui is running but this will work properly even in flatpak + // that uses pid sandboxing. Replace this with a better method once we no longer rely on linux global hotkeys on some platform. + if(is_gsr_ui_virtual_keyboard_running()) { const char *args[] = { "gsr-notify", "--text", "Another instance of GPU Screen Recorder UI is already running", "--timeout", "5.0", "--icon-color", "ff0000", "--bg-color", "ff0000", nullptr }; gsr::exec_program_daemonized(args); return 1; } + // const pid_t gsr_ui_pid = gsr::pidof("gsr-ui"); + // if(gsr_ui_pid != -1) { + // const char *args[] = { "gsr-notify", "--text", "Another instance of GPU Screen Recorder UI is already running", "--timeout", "5.0", "--icon-color", "ff0000", "--bg-color", "ff0000", nullptr }; + // gsr::exec_program_daemonized(args); + // return 1; + // } // Cant get window texture when prime-run is used disable_prime_run(); |