From 52ce22ae22670b11c2bc5fac0583e1a4aa4e19f0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 4 Jan 2025 05:39:16 +0100 Subject: Add option to only grab virtual devices, to support input remapping software --- src/Config.cpp | 2 +- src/GlobalHotkeysLinux.cpp | 15 ++++++++++++--- src/gui/GlobalSettingsPage.cpp | 26 +++++++++++++------------- src/main.cpp | 10 ++++++---- 4 files changed, 32 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index 88ba11a..4ad1107 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -58,7 +58,7 @@ namespace gsr { return { {"main.config_file_version", &config.main_config.config_file_version}, {"main.software_encoding_warning_shown", &config.main_config.software_encoding_warning_shown}, - {"main.enable_hotkeys", &config.main_config.enable_hotkeys}, + {"main.hotkeys_enable_option", &config.main_config.hotkeys_enable_option}, {"main.tint_color", &config.main_config.tint_color}, {"streaming.record_options.record_area_option", &config.streaming_config.record_options.record_area_option}, diff --git a/src/GlobalHotkeysLinux.cpp b/src/GlobalHotkeysLinux.cpp index b1f59b1..3d1813d 100644 --- a/src/GlobalHotkeysLinux.cpp +++ b/src/GlobalHotkeysLinux.cpp @@ -9,7 +9,15 @@ #define PIPE_WRITE 1 namespace gsr { - GlobalHotkeysLinux::GlobalHotkeysLinux() { + static const char* grab_type_to_arg(GlobalHotkeysLinux::GrabType grab_type) { + switch(grab_type) { + case GlobalHotkeysLinux::GrabType::ALL: return "--all"; + case GlobalHotkeysLinux::GrabType::VIRTUAL: return "--virtual"; + } + return "--all"; + } + + GlobalHotkeysLinux::GlobalHotkeysLinux(GrabType grab_type) : grab_type(grab_type) { for(int i = 0; i < 2; ++i) { pipes[i] = -1; } @@ -32,6 +40,7 @@ namespace gsr { } bool GlobalHotkeysLinux::start() { + const char *grab_type_arg = grab_type_to_arg(grab_type); const bool inside_flatpak = getenv("FLATPAK_ID") != NULL; const char *user_homepath = getenv("HOME"); if(!user_homepath) @@ -61,10 +70,10 @@ namespace gsr { } if(inside_flatpak) { - const char *args[] = { "flatpak-spawn", "--host", "--", gsr_global_hotkeys_flatpak, NULL }; + const char *args[] = { "flatpak-spawn", "--host", "--", gsr_global_hotkeys_flatpak, grab_type_arg, nullptr }; execvp(args[0], (char* const*)args); } else { - const char *args[] = { "gsr-global-hotkeys", NULL }; + const char *args[] = { "gsr-global-hotkeys", grab_type_arg, nullptr }; execvp(args[0], (char* const*)args); } diff --git a/src/gui/GlobalSettingsPage.cpp b/src/gui/GlobalSettingsPage.cpp index 7b7bea5..d3d440d 100644 --- a/src/gui/GlobalSettingsPage.cpp +++ b/src/gui/GlobalSettingsPage.cpp @@ -89,11 +89,14 @@ namespace gsr { } std::unique_ptr GlobalSettingsPage::create_hotkey_subsection(ScrollablePage *parent_page) { - auto list = std::make_unique(List::Orientation::VERTICAL); - auto enable_hotkeys_radio_button = std::make_unique(&get_theme().body_font, RadioButton::Orientation::HORIZONTAL); + const bool inside_flatpak = getenv("FLATPAK_ID") != NULL; + + auto enable_hotkeys_radio_button = std::make_unique(&get_theme().body_font, RadioButton::Orientation::VERTICAL); enable_hotkeys_radio_button_ptr = enable_hotkeys_radio_button.get(); - enable_hotkeys_radio_button->add_item("Enable hotkeys and restart", "enable_hotkeys"); - enable_hotkeys_radio_button->add_item("Disable hotkeys and restart", "disable_hotkeys"); + enable_hotkeys_radio_button->add_item("Enable hotkeys", "enable_hotkeys"); + if(!inside_flatpak) + enable_hotkeys_radio_button->add_item("Disable hotkeys", "disable_hotkeys"); + enable_hotkeys_radio_button->add_item("Only grab virtual devices (supports input remapping software)", "enable_hotkeys_virtual_devices"); enable_hotkeys_radio_button->on_selection_changed = [&](const std::string&, const std::string &id) { if(!on_click_exit_program_button) return true; @@ -102,11 +105,12 @@ namespace gsr { on_click_exit_program_button("restart"); else if(id == "disable_hotkeys") on_click_exit_program_button("restart"); + else if(id == "enable_hotkeys_virtual_devices") + on_click_exit_program_button("restart"); return true; }; - list->add_widget(std::move(enable_hotkeys_radio_button)); - return std::make_unique("Hotkeys", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f)); + return std::make_unique("Hotkeys", std::move(enable_hotkeys_radio_button), mgl::vec2f(parent_page->get_inner_size().x, 0.0f)); } std::unique_ptr