diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Config.hpp | 21 | ||||
-rw-r--r-- | include/GlobalHotkeys.hpp | 15 | ||||
-rw-r--r-- | include/GlobalHotkeysJoystick.hpp | 54 | ||||
-rw-r--r-- | include/GlobalHotkeysLinux.hpp | 6 | ||||
-rw-r--r-- | include/GsrInfo.hpp | 17 | ||||
-rw-r--r-- | include/Hotplug.hpp | 33 | ||||
-rw-r--r-- | include/Overlay.hpp | 24 | ||||
-rw-r--r-- | include/WindowUtils.hpp | 7 | ||||
-rw-r--r-- | include/gui/GlobalSettingsPage.hpp | 60 | ||||
-rw-r--r-- | include/gui/SettingsPage.hpp | 2 |
10 files changed, 217 insertions, 22 deletions
diff --git a/include/Config.hpp b/include/Config.hpp index 6f81c1c..34c2010 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -6,12 +6,14 @@ #include <vector> #include <optional> +#define GSR_CONFIG_FILE_VERSION 1 + namespace gsr { struct SupportedCaptureOptions; struct ConfigHotkey { - int64_t keysym = 0; - uint32_t modifiers = 0; + int64_t key = 0; // Mgl key + uint32_t modifiers = 0; // HotkeyModifier bool operator==(const ConfigHotkey &other) const; bool operator!=(const ConfigHotkey &other) const; @@ -41,10 +43,12 @@ namespace gsr { }; struct MainConfig { - int32_t config_file_version = 0; + int32_t config_file_version = GSR_CONFIG_FILE_VERSION; bool software_encoding_warning_shown = false; std::string hotkeys_enable_option = "enable_hotkeys"; + std::string joystick_hotkeys_enable_option = "disable_hotkeys"; std::string tint_color; + ConfigHotkey show_hide_hotkey; }; struct YoutubeStreamConfig { @@ -68,7 +72,7 @@ namespace gsr { YoutubeStreamConfig youtube; TwitchStreamConfig twitch; CustomStreamConfig custom; - ConfigHotkey start_stop_recording_hotkey; + ConfigHotkey start_stop_hotkey; }; struct RecordConfig { @@ -78,22 +82,23 @@ namespace gsr { bool show_video_saved_notifications = true; std::string save_directory; std::string container = "mp4"; - ConfigHotkey start_stop_recording_hotkey; - ConfigHotkey pause_unpause_recording_hotkey; + ConfigHotkey start_stop_hotkey; + ConfigHotkey pause_unpause_hotkey; }; struct ReplayConfig { RecordOptions record_options; std::string turn_on_replay_automatically_mode = "dont_turn_on_automatically"; bool save_video_in_game_folder = false; + bool restart_replay_on_save = false; bool show_replay_started_notifications = true; bool show_replay_stopped_notifications = true; bool show_replay_saved_notifications = true; std::string save_directory; std::string container = "mp4"; int32_t replay_time = 60; - ConfigHotkey start_stop_recording_hotkey; - ConfigHotkey save_recording_hotkey; + ConfigHotkey start_stop_hotkey; + ConfigHotkey save_hotkey; }; struct Config { diff --git a/include/GlobalHotkeys.hpp b/include/GlobalHotkeys.hpp index 27fca07..2927fa7 100644 --- a/include/GlobalHotkeys.hpp +++ b/include/GlobalHotkeys.hpp @@ -9,9 +9,20 @@ namespace mgl { } namespace gsr { + enum HotkeyModifier : uint32_t { + HOTKEY_MOD_LSHIFT = 1 << 0, + HOTKEY_MOD_RSHIFT = 1 << 1, + HOTKEY_MOD_LCTRL = 1 << 2, + HOTKEY_MOD_RCTRL = 1 << 3, + HOTKEY_MOD_LALT = 1 << 4, + HOTKEY_MOD_RALT = 1 << 5, + HOTKEY_MOD_LSUPER = 1 << 6, + HOTKEY_MOD_RSUPER = 1 << 7 + }; + struct Hotkey { - uint64_t key = 0; - uint32_t modifiers = 0; + uint32_t key = 0; // X11 keysym + uint32_t modifiers = 0; // HotkeyModifier }; using GlobalHotkeyCallback = std::function<void(const std::string &id)>; diff --git a/include/GlobalHotkeysJoystick.hpp b/include/GlobalHotkeysJoystick.hpp new file mode 100644 index 0000000..69f66df --- /dev/null +++ b/include/GlobalHotkeysJoystick.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include "GlobalHotkeys.hpp" +#include "Hotplug.hpp" +#include <unordered_map> +#include <optional> +#include <thread> +#include <poll.h> +#include <mglpp/system/Clock.hpp> +#include <linux/joystick.h> + +namespace gsr { + static constexpr int max_js_poll_fd = 16; + + class GlobalHotkeysJoystick : public GlobalHotkeys { + class GlobalHotkeysJoystickHotplugDelegate; + public: + GlobalHotkeysJoystick() = default; + GlobalHotkeysJoystick(const GlobalHotkeysJoystick&) = delete; + GlobalHotkeysJoystick& operator=(const GlobalHotkeysJoystick&) = delete; + ~GlobalHotkeysJoystick() override; + + bool start(); + bool bind_action(const std::string &id, GlobalHotkeyCallback callback) override; + void poll_events() override; + private: + void read_events(); + void process_js_event(int fd, js_event &event); + bool add_device(const char *dev_input_filepath, bool print_error = true); + bool remove_device(const char *dev_input_filepath); + bool remove_poll_fd(int index); + // Returns -1 if not found + int get_poll_fd_index_by_dev_input_id(int dev_input_id) const; + private: + struct ExtraData { + int dev_input_id = 0; + }; + + std::unordered_map<std::string, GlobalHotkeyCallback> bound_actions_by_id; + std::thread read_thread; + + pollfd poll_fd[max_js_poll_fd]; + ExtraData extra_data[max_js_poll_fd]; + int num_poll_fd = 0; + int event_fd = -1; + int event_index = -1; + + mgl::Clock double_click_clock; + std::optional<double> prev_time_clicked; + bool save_replay = false; + int hotplug_poll_index = -1; + Hotplug hotplug; + }; +}
\ No newline at end of file diff --git a/include/GlobalHotkeysLinux.hpp b/include/GlobalHotkeysLinux.hpp index addb849..c9428de 100644 --- a/include/GlobalHotkeysLinux.hpp +++ b/include/GlobalHotkeysLinux.hpp @@ -18,11 +18,13 @@ namespace gsr { ~GlobalHotkeysLinux() override; bool start(); - bool bind_action(const std::string &id, GlobalHotkeyCallback callback) override; + bool bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) override; + void unbind_all_keys() override; void poll_events() override; private: pid_t process_id = 0; - int pipes[2]; + int read_pipes[2]; + int write_pipes[2]; FILE *read_file = nullptr; std::unordered_map<std::string, GlobalHotkeyCallback> bound_actions_by_id; GrabType grab_type; diff --git a/include/GsrInfo.hpp b/include/GsrInfo.hpp index 86df0b7..a8c0742 100644 --- a/include/GsrInfo.hpp +++ b/include/GsrInfo.hpp @@ -2,6 +2,7 @@ #include <string> #include <vector> +#include <stdint.h> #include <mglpp/system/vec.hpp> @@ -24,6 +25,21 @@ namespace gsr { mgl::vec2i size; }; + struct GsrVersion { + uint8_t major = 0; + uint8_t minor = 0; + uint8_t patch = 0; + + bool operator>(const GsrVersion &other) const; + bool operator>=(const GsrVersion &other) const; + bool operator<(const GsrVersion &other) const; + bool operator<=(const GsrVersion &other) const; + bool operator==(const GsrVersion &other) const; + bool operator!=(const GsrVersion &other) const; + + std::string to_string() const; + }; + struct SupportedCaptureOptions { bool window = false; bool focused = false; @@ -40,6 +56,7 @@ namespace gsr { struct SystemInfo { DisplayServer display_server = DisplayServer::UNKNOWN; bool supports_app_audio = false; + GsrVersion gsr_version; }; enum class GpuVendor { diff --git a/include/Hotplug.hpp b/include/Hotplug.hpp new file mode 100644 index 0000000..38fe25d --- /dev/null +++ b/include/Hotplug.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include <functional> + +namespace gsr { + enum class HotplugAction { + ADD, + REMOVE + }; + + using HotplugEventCallback = std::function<void(HotplugAction hotplug_action, const char *devname)>; + + class Hotplug { + public: + Hotplug() = default; + Hotplug(const Hotplug&) = delete; + Hotplug& operator=(const Hotplug&) = delete; + ~Hotplug(); + + bool start(); + int steal_fd(); + void process_event_data(int fd, const HotplugEventCallback &callback); + private: + void parse_netlink_data(const char *line, const HotplugEventCallback &callback); + private: + int fd = -1; + bool started = false; + bool event_is_add = false; + bool event_is_remove = false; + bool subsystem_is_input = false; + char event_data[1024]; + }; +}
\ No newline at end of file diff --git a/include/Overlay.hpp b/include/Overlay.hpp index e802cd0..a4e75dc 100644 --- a/include/Overlay.hpp +++ b/include/Overlay.hpp @@ -5,6 +5,9 @@ #include "GsrInfo.hpp" #include "Config.hpp" #include "window_texture.h" +#include "WindowUtils.hpp" +#include "GlobalHotkeysLinux.hpp" +#include "GlobalHotkeysJoystick.hpp" #include <mglpp/window/Window.hpp> #include <mglpp/window/Event.hpp> @@ -41,8 +44,7 @@ namespace gsr { Overlay& operator=(const Overlay&) = delete; ~Overlay(); - void handle_events(gsr::GlobalHotkeys *global_hotkeys); - void on_event(mgl::Event &event); + void handle_events(); // Returns false if not visible bool draw(); @@ -60,13 +62,19 @@ namespace gsr { void exit(); const Config& get_config() const; + + void unbind_all_keyboard_hotkeys(); + void rebind_all_keyboard_hotkeys(); private: + void handle_keyboard_mapping_event(); + void on_event(mgl::Event &event); + void xi_setup(); void handle_xi_events(); void process_key_bindings(mgl::Event &event); void grab_mouse_and_keyboard(); void xi_setup_fake_cursor(); - void xi_grab_all_devices(); + void xi_grab_all_mouse_devices(); void close_gpu_screen_recorder_output(); @@ -97,7 +105,7 @@ namespace gsr { void on_press_start_replay(bool disable_notification); void on_press_start_record(); void on_press_start_stream(); - bool update_compositor_texture(const mgl_monitor *monitor); + bool update_compositor_texture(const Monitor &monitor); void force_window_on_top(); private: @@ -169,5 +177,13 @@ namespace gsr { mgl::vec2i window_size = { 1280, 720 }; mgl::vec2i window_pos = { 0, 0 }; + + mgl::Clock show_overlay_clock; + double show_overlay_timeout_seconds = 0.0; + + std::unique_ptr<GlobalHotkeys> global_hotkeys = nullptr; + std::unique_ptr<GlobalHotkeysJoystick> global_hotkeys_js = nullptr; + Display *x11_mapping_display = nullptr; + XEvent x11_mapping_xev; }; }
\ No newline at end of file diff --git a/include/WindowUtils.hpp b/include/WindowUtils.hpp index d17c0fd..c8806df 100644 --- a/include/WindowUtils.hpp +++ b/include/WindowUtils.hpp @@ -2,6 +2,7 @@ #include <mglpp/system/vec.hpp> #include <string> +#include <vector> #include <X11/Xlib.h> namespace gsr { @@ -10,10 +11,16 @@ namespace gsr { CURSOR }; + struct Monitor { + mgl::vec2i position; + mgl::vec2i size; + }; + Window get_focused_window(Display *dpy, WindowCaptureType cap_type); std::string get_focused_window_name(Display *dpy, WindowCaptureType window_capture_type); mgl::vec2i get_cursor_position(Display *dpy, Window *window); mgl::vec2i create_window_get_center_position(Display *display); std::string get_window_manager_name(Display *display); bool is_compositor_running(Display *dpy, int screen); + std::vector<Monitor> get_monitors(Display *dpy); }
\ No newline at end of file diff --git a/include/gui/GlobalSettingsPage.hpp b/include/gui/GlobalSettingsPage.hpp index 06098f0..580e943 100644 --- a/include/gui/GlobalSettingsPage.hpp +++ b/include/gui/GlobalSettingsPage.hpp @@ -5,18 +5,32 @@ #include "../Config.hpp" #include <functional> +#include <mglpp/window/Event.hpp> namespace gsr { + class Overlay; class GsrPage; class PageStack; class ScrollablePage; class Subsection; class RadioButton; class Button; + class List; + class CustomRendererWidget; + + enum ConfigureHotkeyType { + NONE, + REPLAY_START_STOP, + REPLAY_SAVE, + RECORD_START_STOP, + RECORD_PAUSE_UNPAUSE, + STREAM_START_STOP, + SHOW_HIDE + }; class GlobalSettingsPage : public StaticPage { public: - GlobalSettingsPage(const GsrInfo *gsr_info, Config &config, PageStack *page_stack); + GlobalSettingsPage(Overlay *overlay, const GsrInfo *gsr_info, Config &config, PageStack *page_stack); GlobalSettingsPage(const GlobalSettingsPage&) = delete; GlobalSettingsPage& operator=(const GlobalSettingsPage&) = delete; @@ -24,19 +38,39 @@ namespace gsr { void save(); void on_navigate_away_from_page() override; - // Called with (enable, exit_status) - std::function<void(bool, int)> on_startup_changed; - // Called with (reason) - std::function<void(const char*)> on_click_exit_program_button; + bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; + + std::function<void(bool enable, int exit_status)> on_startup_changed; + std::function<void(const char *reason)> on_click_exit_program_button; + std::function<void(const char *hotkey_option)> on_keyboard_hotkey_changed; + std::function<void(const char *hotkey_option)> on_joystick_hotkey_changed; private: + void load_hotkeys(); + std::unique_ptr<Subsection> create_appearance_subsection(ScrollablePage *parent_page); std::unique_ptr<Subsection> create_startup_subsection(ScrollablePage *parent_page); + std::unique_ptr<RadioButton> create_enable_keyboard_hotkeys_button(); + std::unique_ptr<RadioButton> create_enable_joystick_hotkeys_button(); + std::unique_ptr<List> create_show_hide_hotkey_options(); + std::unique_ptr<List> create_replay_hotkey_options(); + std::unique_ptr<List> create_record_hotkey_options(); + std::unique_ptr<List> create_stream_hotkey_options(); + std::unique_ptr<List> create_hotkey_control_buttons(); std::unique_ptr<Subsection> create_hotkey_subsection(ScrollablePage *parent_page); std::unique_ptr<Button> create_exit_program_button(); std::unique_ptr<Button> create_go_back_to_old_ui_button(); std::unique_ptr<Subsection> create_application_options_subsection(ScrollablePage *parent_page); + std::unique_ptr<Subsection> create_application_info_subsection(ScrollablePage *parent_page); void add_widgets(); + + Button* configure_hotkey_get_button_by_active_type(); + ConfigHotkey* configure_hotkey_get_config_by_active_type(); + void for_each_config_hotkey(std::function<void(ConfigHotkey *config_hotkey)> callback); + void configure_hotkey_start(ConfigureHotkeyType hotkey_type); + void configure_hotkey_cancel(); + void configure_hotkey_stop_and_save(); private: + Overlay *overlay = nullptr; Config &config; const GsrInfo *gsr_info = nullptr; @@ -44,6 +78,20 @@ namespace gsr { PageStack *page_stack = nullptr; RadioButton *tint_color_radio_button_ptr = nullptr; RadioButton *startup_radio_button_ptr = nullptr; - RadioButton *enable_hotkeys_radio_button_ptr = nullptr; + RadioButton *enable_keyboard_hotkeys_radio_button_ptr = nullptr; + RadioButton *enable_joystick_hotkeys_radio_button_ptr = nullptr; + + Button *turn_replay_on_off_button_ptr = nullptr; + Button *save_replay_button_ptr = nullptr; + Button *start_stop_recording_button_ptr = nullptr; + Button *pause_unpause_recording_button_ptr = nullptr; + Button *start_stop_streaming_button_ptr = nullptr; + Button *show_hide_button_ptr = nullptr; + + ConfigHotkey configure_config_hotkey; + ConfigureHotkeyType configure_hotkey_type = ConfigureHotkeyType::NONE; + + CustomRendererWidget *hotkey_overlay_ptr = nullptr; + std::string hotkey_configure_action_name; }; }
\ No newline at end of file diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp index efa958e..8db3915 100644 --- a/include/gui/SettingsPage.hpp +++ b/include/gui/SettingsPage.hpp @@ -97,6 +97,7 @@ namespace gsr { std::unique_ptr<List> create_replay_time(); std::unique_ptr<RadioButton> create_start_replay_automatically(); std::unique_ptr<CheckBox> create_save_replay_in_game_folder(); + std::unique_ptr<CheckBox> create_restart_replay_on_save(); std::unique_ptr<Label> create_estimated_replay_file_size(); void update_estimated_replay_file_size(); std::unique_ptr<CheckBox> create_save_recording_in_game_folder(); @@ -170,6 +171,7 @@ namespace gsr { List *stream_url_list_ptr = nullptr; List *container_list_ptr = nullptr; CheckBox *save_replay_in_game_folder_ptr = nullptr; + CheckBox *restart_replay_on_save = nullptr; Label *estimated_file_size_ptr = nullptr; CheckBox *show_replay_started_notification_checkbox_ptr = nullptr; CheckBox *show_replay_stopped_notification_checkbox_ptr = nullptr; |