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 --- README.md | 2 +- include/Config.hpp | 2 +- include/GlobalHotkeysLinux.hpp | 8 +++++++- src/Config.cpp | 2 +- src/GlobalHotkeysLinux.cpp | 15 +++++++++++--- src/gui/GlobalSettingsPage.cpp | 26 ++++++++++++------------ src/main.cpp | 10 ++++++---- tools/gsr-global-hotkeys/keyboard_event.c | 33 ++++++++++++++++++++++++++++++- tools/gsr-global-hotkeys/keyboard_event.h | 8 +++++++- tools/gsr-global-hotkeys/main.c | 30 ++++++++++++++++++++++++++-- 10 files changed, 108 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index a7aa20c..e5ee4ea 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ There are also additional dependencies needed at runtime: At the moment different keyboard layouts are not supported. The physical layout of keys are used for global hotkeys. If your Z and Y keys are swapped for example then you need to press Alt+Y instead of Alt+Z to open/hide the UI.\ If you experience this issue then please email dec05eba@protonmail.com to get it fixed.\ 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 input remapping software. To workaround this you can go into settings and disable hotkeys and use the included `gsr-ui-cli` tool to control the UI remotely. You can combine `gsr-ui-cli` commands to hotkeys in your desktop environments hotkey settings. +This might cause issues for you if you use input remapping software. To workaround this you can go into settings and select "Only grab virtual devices" # License This software is licensed under GPL3.0-only. Files under `fonts/` directory belong to the Noto Sans Google fonts project and they are licensed under `SIL Open Font License`. diff --git a/include/Config.hpp b/include/Config.hpp index dcfdee1..6f81c1c 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -43,7 +43,7 @@ namespace gsr { struct MainConfig { int32_t config_file_version = 0; bool software_encoding_warning_shown = false; - bool enable_hotkeys = true; + std::string hotkeys_enable_option = "enable_hotkeys"; std::string tint_color; }; diff --git a/include/GlobalHotkeysLinux.hpp b/include/GlobalHotkeysLinux.hpp index 62da74e..addb849 100644 --- a/include/GlobalHotkeysLinux.hpp +++ b/include/GlobalHotkeysLinux.hpp @@ -7,7 +7,12 @@ namespace gsr { class GlobalHotkeysLinux : public GlobalHotkeys { public: - GlobalHotkeysLinux(); + enum class GrabType { + ALL, + VIRTUAL + }; + + GlobalHotkeysLinux(GrabType grab_type); GlobalHotkeysLinux(const GlobalHotkeysLinux&) = delete; GlobalHotkeysLinux& operator=(const GlobalHotkeysLinux&) = delete; ~GlobalHotkeysLinux() override; @@ -20,5 +25,6 @@ namespace gsr { int pipes[2]; FILE *read_file = nullptr; std::unordered_map bound_actions_by_id; + GrabType grab_type; }; } \ No newline at end of file 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