From 78f44a9486bbc682ea723bb76a24091421c41d78 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 29 Dec 2024 15:31:28 +0100 Subject: Detect multiple instances of gsr-ui by detecting virtual keyboard presence instead. This works in flatpak --- src/main.cpp | 29 +++++++++++++++++++++++++++-- 1 file 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 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(); -- cgit v1.2.3