aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-12-29 14:29:03 +0100
committerdec05eba <dec05eba@protonmail.com>2024-12-29 14:29:03 +0100
commit050e8773ccd887d4f0fb57b512a2c70556e3a932 (patch)
treec0ff11e8f25cb9e1bca1d0da25205ae1984994e1
parent3c3e165eb76c4f472212c0fe7215b7ea9cb70a45 (diff)
Add option to launch the program and show the UI immediately, with 'gsr-ui launch-show'
-rw-r--r--src/Overlay.cpp2
-rw-r--r--src/main.cpp38
2 files changed, 36 insertions, 4 deletions
diff --git a/src/Overlay.cpp b/src/Overlay.cpp
index ec6421c..11808c6 100644
--- a/src/Overlay.cpp
+++ b/src/Overlay.cpp
@@ -985,7 +985,7 @@ namespace gsr {
if(exit_status == 127) {
if(enable)
- show_notification("Failed to add GPU Screen Recorder to system startup.\nThis option only works on systems that use systemd.\nYou have to manually add gsr-ui to system startup on systems that uses another init system.", 10.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
+ show_notification("Failed to add GPU Screen Recorder to system startup.\nThis option only works on systems that use systemd.\nYou have to manually add \"gsr-ui\" to system startup on systems that uses another init system.", 10.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
} else {
if(enable)
show_notification("Failed to add GPU Screen Recorder to system startup", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
diff --git a/src/main.cpp b/src/main.cpp
index c210033..4bd7a84 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,5 @@
#include "../include/GsrInfo.hpp"
#include "../include/Theme.hpp"
-#include "../include/window_texture.h"
#include "../include/Overlay.hpp"
#include "../include/GlobalHotkeysX11.hpp"
#include "../include/GlobalHotkeysLinux.hpp"
@@ -9,6 +8,7 @@
#include <unistd.h>
#include <signal.h>
#include <thread>
+#include <string.h>
#include <X11/keysym.h>
#include <mglpp/mglpp.hpp>
@@ -132,7 +132,21 @@ static std::unique_ptr<gsr::GlobalHotkeysLinux> register_linux_hotkeys(gsr::Over
return global_hotkeys;
}
-int main(void) {
+static void usage() {
+ printf("usage: gsr-ui [action]\n");
+ printf("OPTIONS:\n");
+ printf(" action The launch action. Should be either \"launch-show\" or \"launch-hide\". Optional, defaults to \"launch-hide\".\n");
+ printf(" If \"launch-show\" is used then the program starts and the UI is immediately opened and can be shown/hidden with Alt+Z.\n");
+ printf(" If \"launch-hide\" is used then the program starts but the UI is not opened until Alt+Z is pressed.\n");
+ exit(1);
+}
+
+enum class LaunchAction {
+ LAUNCH_SHOW,
+ LAUNCH_HIDE
+};
+
+int main(int argc, char **argv) {
setlocale(LC_ALL, "C"); // Sigh... stupid C
if(geteuid() == 0) {
@@ -140,6 +154,22 @@ int main(void) {
return 1;
}
+ LaunchAction launch_action = LaunchAction::LAUNCH_HIDE;
+ if(argc == 1) {
+ launch_action = LaunchAction::LAUNCH_HIDE;
+ } else if(argc == 2) {
+ if(strcmp(argv[1], "launch-show") == 0) {
+ launch_action = LaunchAction::LAUNCH_SHOW;
+ } else if(strcmp(argv[1], "launch-hide") == 0) {
+ launch_action = LaunchAction::LAUNCH_HIDE;
+ } else {
+ printf("error: invalid action \"%s\", expected \"launch-show\" or \"launch-hide\".\n", argv[1]);
+ usage();
+ }
+ } else {
+ usage();
+ }
+
// Cant get window texture when prime-run is used
disable_prime_run();
@@ -201,7 +231,6 @@ int main(void) {
fprintf(stderr, "Info: gsr ui is now ready, waiting for inputs. Press alt+z to show/hide the overlay\n");
auto overlay = std::make_unique<gsr::Overlay>(resources_path, std::move(gsr_info), std::move(capture_options), egl_funcs);
- //overlay.show();
// std::unique_ptr<gsr::GlobalHotkeys> global_hotkeys = nullptr;
// if(display_server == gsr::DisplayServer::X11) {
@@ -215,6 +244,9 @@ int main(void) {
// }
std::unique_ptr<gsr::GlobalHotkeys> global_hotkeys = register_linux_hotkeys(overlay.get());
+ if(launch_action == LaunchAction::LAUNCH_SHOW)
+ overlay->show();
+
// 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.
mgl::Clock frame_delta_clock;