aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-04-11 21:51:38 +0200
committerdec05eba <dec05eba@protonmail.com>2025-04-11 21:51:38 +0200
commit38feee9f29c134d7734f76db8af196618380e8f5 (patch)
tree92f9072c8688bcea3d3dbb1b07079056f80e4f8f
parent90a1272a653f9ac7b00e902a343e22455dbb67b1 (diff)
Fix unable to change hotkey settings while recording
-rw-r--r--README.md2
-rw-r--r--include/GlobalHotkeysLinux.hpp2
-rw-r--r--src/GlobalHotkeysLinux.cpp35
-rw-r--r--src/Overlay.cpp24
-rw-r--r--tools/gsr-global-hotkeys/README.md6
-rw-r--r--tools/gsr-global-hotkeys/keyboard_event.c5
6 files changed, 51 insertions, 23 deletions
diff --git a/README.md b/README.md
index 7eafeae..8abb4a4 100644
--- a/README.md
+++ b/README.md
@@ -40,7 +40,7 @@ There are also additional dependencies needed at runtime:
## Program behavior notes
This program has to grab all keyboards and create a virtual keyboard (`gsr-ui virtual keyboard`) to make global hotkeys work on all Wayland compositors.\
This might cause issues for you if you use keyboard remapping software. To workaround this you can go into settings and select "Only grab virtual devices".\
-If you use keyboard remapping software such as keyd then make sure to make it ignore "gsr-ui virtual keyboard" (-dec0:5eba device id), otherwise your keyboard can get locked
+If you use keyboard remapping software such as keyd then make sure to make it ignore "gsr-ui virtual keyboard" (dec0:5eba device id), otherwise your keyboard can get locked
as gpu screen recorder tries to grab keys and keyd grabs gpu screen recorder, leading to a lock.\
If you are stuck in such a lock where you cant press and keyboard keys you can press (left) ctrl+shift+alt+esc to close gpu screen recorder and remove it from system startup.
diff --git a/include/GlobalHotkeysLinux.hpp b/include/GlobalHotkeysLinux.hpp
index c9428de..959d095 100644
--- a/include/GlobalHotkeysLinux.hpp
+++ b/include/GlobalHotkeysLinux.hpp
@@ -22,6 +22,8 @@ namespace gsr {
void unbind_all_keys() override;
void poll_events() override;
private:
+ void close_fds();
+ private:
pid_t process_id = 0;
int read_pipes[2];
int write_pipes[2];
diff --git a/src/GlobalHotkeysLinux.cpp b/src/GlobalHotkeysLinux.cpp
index fbba0ea..20b089f 100644
--- a/src/GlobalHotkeysLinux.cpp
+++ b/src/GlobalHotkeysLinux.cpp
@@ -1,5 +1,4 @@
#include "../include/GlobalHotkeysLinux.hpp"
-#include <signal.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <limits.h>
@@ -71,21 +70,39 @@ namespace gsr {
}
GlobalHotkeysLinux::~GlobalHotkeysLinux() {
+ if(write_pipes[PIPE_WRITE] > 0) {
+ char command[32];
+ const int command_size = snprintf(command, sizeof(command), "exit\n");
+ if(write(write_pipes[PIPE_WRITE], command, command_size) != command_size) {
+ fprintf(stderr, "Error: GlobalHotkeysLinux::~GlobalHotkeysLinux: failed to write command to gsr-global-hotkeys, error: %s\n", strerror(errno));
+ close_fds();
+ }
+ }
+
+ if(process_id > 0) {
+ int status;
+ waitpid(process_id, &status, 0);
+ }
+
+ close_fds();
+ }
+
+ void GlobalHotkeysLinux::close_fds() {
for(int i = 0; i < 2; ++i) {
- if(read_pipes[i] > 0)
+ if(read_pipes[i] > 0) {
close(read_pipes[i]);
+ read_pipes[i] = -1;
+ }
- if(write_pipes[i] > 0)
+ if(write_pipes[i] > 0) {
close(write_pipes[i]);
+ write_pipes[i] = -1;
+ }
}
- if(read_file)
+ if(read_file) {
fclose(read_file);
-
- if(process_id > 0) {
- kill(process_id, SIGKILL);
- int status;
- waitpid(process_id, &status, 0);
+ read_file = nullptr;
}
}
diff --git a/src/Overlay.cpp b/src/Overlay.cpp
index 2a4ca81..c342d37 100644
--- a/src/Overlay.cpp
+++ b/src/Overlay.cpp
@@ -1580,9 +1580,9 @@ namespace gsr {
return;
if(is_capture_target_monitor(recording_capture_target.c_str()))
- snprintf(msg, sizeof(msg), "Saved recording of this monitor to '%s'", filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a recording of this monitor to '%s'", filename.c_str());
else
- snprintf(msg, sizeof(msg), "Saved recording of %s to '%s'", recording_capture_target.c_str(), filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a recording of %s to '%s'", recording_capture_target.c_str(), filename.c_str());
capture_target = recording_capture_target.c_str();
break;
@@ -1592,9 +1592,9 @@ namespace gsr {
return;
if(is_capture_target_monitor(replay_capture_target.c_str()))
- snprintf(msg, sizeof(msg), "Saved replay of this monitor to '%s'", filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a replay of this monitor to '%s'", filename.c_str());
else
- snprintf(msg, sizeof(msg), "Saved replay of %s to '%s'", replay_capture_target.c_str(), filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a replay of %s to '%s'", replay_capture_target.c_str(), filename.c_str());
capture_target = replay_capture_target.c_str();
break;
@@ -1604,9 +1604,9 @@ namespace gsr {
return;
if(is_capture_target_monitor(screenshot_capture_target.c_str()))
- snprintf(msg, sizeof(msg), "Saved screenshot of this monitor to '%s'", filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a screenshot of this monitor to '%s'", filename.c_str());
else
- snprintf(msg, sizeof(msg), "Saved screenshot of %s to '%s'", screenshot_capture_target.c_str(), filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a screenshot of %s to '%s'", screenshot_capture_target.c_str(), filename.c_str());
capture_target = screenshot_capture_target.c_str();
break;
@@ -1626,9 +1626,9 @@ namespace gsr {
const std::string filename = filepath_get_filename(replay_saved_filepath);
char msg[512];
if(is_capture_target_monitor(replay_capture_target.c_str()))
- snprintf(msg, sizeof(msg), "Saved replay of this monitor to '%s'", filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a replay of this monitor to '%s'", filename.c_str());
else
- snprintf(msg, sizeof(msg), "Saved replay of %s to '%s'", replay_capture_target.c_str(), filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a replay of %s to '%s'", replay_capture_target.c_str(), filename.c_str());
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY, replay_capture_target.c_str());
}
}
@@ -1729,9 +1729,9 @@ namespace gsr {
const std::string filename = filepath_get_filename(screenshot_filepath.c_str());
char msg[512];
if(is_capture_target_monitor(screenshot_capture_target.c_str()))
- snprintf(msg, sizeof(msg), "Saved screenshot of this monitor to '%s'", filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a screenshot of this monitor to '%s'", filename.c_str());
else
- snprintf(msg, sizeof(msg), "Saved screenshot of %s to '%s'", screenshot_capture_target.c_str(), filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a screenshot of %s to '%s'", screenshot_capture_target.c_str(), filename.c_str());
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::SCREENSHOT, screenshot_capture_target.c_str());
}
} else {
@@ -1835,9 +1835,9 @@ namespace gsr {
const std::string filename = filepath_get_filename(record_filepath.c_str());
char msg[512];
if(is_capture_target_monitor(recording_capture_target.c_str()))
- snprintf(msg, sizeof(msg), "Saved recording of this monitor to '%s'", filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a recording of this monitor to '%s'", filename.c_str());
else
- snprintf(msg, sizeof(msg), "Saved recording of %s to '%s'", recording_capture_target.c_str(), filename.c_str());
+ snprintf(msg, sizeof(msg), "Saved a recording of %s to '%s'", recording_capture_target.c_str(), filename.c_str());
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD, recording_capture_target.c_str());
}
} else {
diff --git a/tools/gsr-global-hotkeys/README.md b/tools/gsr-global-hotkeys/README.md
index 8744107..38585c1 100644
--- a/tools/gsr-global-hotkeys/README.md
+++ b/tools/gsr-global-hotkeys/README.md
@@ -18,4 +18,10 @@ To unbind all keys send `unbind_all<newline>` to the programs stdin, for example
```
unbind_all
+```
+## Exit
+To close gsr-global-hotkeys send `exit<newline>` to the programs stdin, for example:
+```
+exit
+
``` \ No newline at end of file
diff --git a/tools/gsr-global-hotkeys/keyboard_event.c b/tools/gsr-global-hotkeys/keyboard_event.c
index e5221dc..bcfae6b 100644
--- a/tools/gsr-global-hotkeys/keyboard_event.c
+++ b/tools/gsr-global-hotkeys/keyboard_event.c
@@ -707,8 +707,11 @@ static void keyboard_event_parse_stdin_command(keyboard_event *self, const char
}
self->num_global_hotkeys = 0;
fprintf(stderr, "Info: unbinded all hotkeys\n");
+ } else if(strncmp(command, "exit", 4) == 0) {
+ self->stdin_failed = true;
+ fprintf(stderr, "Info: received exit command\n");
} else {
- fprintf(stderr, "Warning: got invalid command: \"%s\", expected command to start with either \"bind\" or \"unbind_all\"\n", command);
+ fprintf(stderr, "Warning: got invalid command: \"%s\", expected command to start with either \"bind\", \"unbind_all\" or \"exit\"\n", command);
}
}