aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-07-06 20:35:46 +0200
committerdec05eba <dec05eba@protonmail.com>2025-07-06 20:38:18 +0200
commita78cefc65b1de37b293b210e4dec1c9f39d914fb (patch)
tree8cc7e839bedbf72c9e8c8f12204fd87029ae3d08
parenta0d1de55d7c704d796e63e5b13e5d68fd4eb61ea (diff)
Add better single instance detection (use rpc fifo file existence with unlink to detect process instead of pidof gsr-ui)
-rw-r--r--TODO10
-rw-r--r--src/Rpc.cpp7
-rw-r--r--src/main.cpp32
3 files changed, 28 insertions, 21 deletions
diff --git a/TODO b/TODO
index 8f34501..59950f9 100644
--- a/TODO
+++ b/TODO
@@ -195,3 +195,13 @@ Add a window that shows a warning for wayland users, that wayland doesn't suppor
Add a window that shows a warning if gpu video encoding isn't supported.
Disable system notifications when recording. Does the notification dbus interface support pausing notifications?
+
+Automatically mark window region in window capture for screenshot on x11.
+
+Disable hotkeys if virtual keyboard is found (either at startup or after running), if grab type if not virtual. Show a notification if that happens that hotkeys have been disabled.
+ Detect if keyboard is locked by listening to gsr-ui virtual keyboard events and if no event is received after pressing a key (when writing to it after receiving input from another keyboard)
+ then remove the keyboard grab and show a message or something.
+ This can happen if the gsr-ui virtual keyboard is grabbed by some other software.
+ Maybe this can be fixed automatically by grabbing gsr-ui virtual keyboard and releasing it just before we write to it and then release it again.
+ But wont keyboard remapping software grab the keyboard first if they detect it quickly?
+ If we fail to grab it because some other software did then dont grab any keyboards nor gsr-ui virtual keyboards, just listen to them.
diff --git a/src/Rpc.cpp b/src/Rpc.cpp
index 3eec98d..803a4dc 100644
--- a/src/Rpc.cpp
+++ b/src/Rpc.cpp
@@ -32,7 +32,7 @@ namespace gsr {
fclose(file);
if(!fifo_filepath.empty())
- remove(fifo_filepath.c_str());
+ unlink(fifo_filepath.c_str());
}
bool Rpc::create(const char *name) {
@@ -44,15 +44,16 @@ namespace gsr {
char fifo_filepath_tmp[PATH_MAX];
get_runtime_filepath(fifo_filepath_tmp, sizeof(fifo_filepath_tmp), name);
fifo_filepath = fifo_filepath_tmp;
- remove(fifo_filepath.c_str());
+ unlink(fifo_filepath.c_str());
if(mkfifo(fifo_filepath.c_str(), 0600) != 0) {
fprintf(stderr, "Error: mkfifo failed, error: %s, %s\n", strerror(errno), fifo_filepath.c_str());
+ fifo_filepath.clear();
return false;
}
if(!open_filepath(fifo_filepath.c_str())) {
- remove(fifo_filepath.c_str());
+ unlink(fifo_filepath.c_str());
fifo_filepath.clear();
return false;
}
diff --git a/src/main.cpp b/src/main.cpp
index a68ff7d..dcd352b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,7 +14,6 @@
#include <mglpp/system/Clock.hpp>
// TODO: Make keyboard/controller controllable for steam deck (and other controllers).
-// TODO: Keep track of gpu screen recorder run by other programs to not allow recording at the same time, or something.
// TODO: Add systray by using org.kde.StatusNotifierWatcher/etc dbus directly.
// TODO: Make sure the overlay always stays on top. Test with starting the overlay and then opening youtube in fullscreen.
// This is done in Overlay::force_window_on_top, but it's not called right now. It cant be used because the overlay will be on top of
@@ -220,17 +219,17 @@ int main(int argc, char **argv) {
set_display_server_environment_variables();
- // 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.
- // TODO: This method doesn't work when disabling hotkeys and the method below with pidof gsr-ui doesn't work in flatpak.
- // What do? creating a pid file doesn't work in flatpak either.
- // TODO: This doesn't work in flatpak when disabling hotkeys.
- if(is_gsr_ui_virtual_keyboard_running() || gsr::pidof("gsr-ui", getpid()) != -1) {
+ auto rpc = std::make_unique<gsr::Rpc>();
+ const bool rpc_created = rpc->create("gsr-ui");
+ if(!rpc_created)
+ fprintf(stderr, "Error: Failed to create rpc\n");
+
+ if(is_gsr_ui_virtual_keyboard_running() || !rpc_created) {
if(launch_action == LaunchAction::LAUNCH_DAEMON)
return 1;
- gsr::Rpc rpc;
- if(rpc.open("gsr-ui") && rpc.write("show_ui\n", 8)) {
+ rpc = std::make_unique<gsr::Rpc>();
+ if(rpc->open("gsr-ui") && rpc->write("show_ui\n", 8)) {
fprintf(stderr, "Error: another instance of gsr-ui is already running, opening that one instead\n");
} else {
fprintf(stderr, "Error: failed to send command to running gsr-ui instance, user will have to open the UI manually with Alt+Z\n");
@@ -243,6 +242,12 @@ int main(int argc, char **argv) {
if(gsr::pidof("gpu-screen-recorder", getpid()) != -1) {
const char *args[] = { "gsr-notify", "--text", "GPU Screen Recorder is already running in another process.\nPlease close it before using GPU Screen Recorder UI.", "--timeout", "5.0", "--icon-color", "ff0000", "--bg-color", "ff0000", nullptr };
gsr::exec_program_daemonized(args);
+ return 1;
+ }
+
+ if(mgl_init(MGL_WINDOW_SYSTEM_X11) != 0) {
+ fprintf(stderr, "Error: failed to initialize mgl. Failed to either connect to the X11 server or setup opengl\n");
+ return 1;
}
if(is_flatpak())
@@ -288,11 +293,6 @@ int main(int argc, char **argv) {
disable_prime_run();
}
- if(mgl_init(MGL_WINDOW_SYSTEM_X11) != 0) {
- fprintf(stderr, "Error: failed to initialize mgl. Failed to either connect to the X11 server or setup opengl\n");
- exit(1);
- }
-
gsr::SupportedCaptureOptions capture_options = gsr::get_supported_capture_options(gsr_info);
std::string resources_path;
@@ -325,10 +325,6 @@ int main(int argc, char **argv) {
if(launch_action == LaunchAction::LAUNCH_SHOW)
overlay->show();
- auto rpc = std::make_unique<gsr::Rpc>();
- if(!rpc->create("gsr-ui"))
- fprintf(stderr, "Error: Failed to create rpc, commands won't be received\n");
-
rpc_add_commands(rpc.get(), overlay.get());
// TODO: Add hotkeys in Overlay when using x11 global hotkeys. The hotkeys in Overlay should duplicate each key that is used for x11 global hotkeys.