From 050e8773ccd887d4f0fb57b512a2c70556e3a932 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 29 Dec 2024 14:29:03 +0100 Subject: Add option to launch the program and show the UI immediately, with 'gsr-ui launch-show' --- src/Overlay.cpp | 2 +- src/main.cpp | 38 +++++++++++++++++++++++++++++++++++--- 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 #include #include +#include #include #include @@ -132,7 +132,21 @@ static std::unique_ptr 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(resources_path, std::move(gsr_info), std::move(capture_options), egl_funcs); - //overlay.show(); // std::unique_ptr global_hotkeys = nullptr; // if(display_server == gsr::DisplayServer::X11) { @@ -215,6 +244,9 @@ int main(void) { // } std::unique_ptr 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; -- cgit v1.2.3