aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-01-20 23:11:00 +0100
committerdec05eba <dec05eba@protonmail.com>2025-01-20 23:11:00 +0100
commit47ada4d79844d9a98d9689d0de0c92864e0fc372 (patch)
tree1325fd3061e78a194b3db0be848a06928fdacce9 /include
parent92401d8bc8fa3cbc8017936eb1d18280199942e0 (diff)
Add option to save replay with controller (double-click share button), allow prime-run on wayland
Diffstat (limited to 'include')
-rw-r--r--include/Config.hpp1
-rw-r--r--include/GlobalHotkeysJoystick.hpp53
-rw-r--r--include/Hotplug.hpp33
-rw-r--r--include/Overlay.hpp3
-rw-r--r--include/gui/GlobalSettingsPage.hpp13
5 files changed, 98 insertions, 5 deletions
diff --git a/include/Config.hpp b/include/Config.hpp
index 6f81c1c..e7b629f 100644
--- a/include/Config.hpp
+++ b/include/Config.hpp
@@ -44,6 +44,7 @@ namespace gsr {
int32_t config_file_version = 0;
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;
};
diff --git a/include/GlobalHotkeysJoystick.hpp b/include/GlobalHotkeysJoystick.hpp
new file mode 100644
index 0000000..367de18
--- /dev/null
+++ b/include/GlobalHotkeysJoystick.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "GlobalHotkeys.hpp"
+#include "Hotplug.hpp"
+#include <unordered_map>
+#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;
+ int num_times_clicked = 0;
+ bool save_replay = false;
+ int hotplug_poll_index = -1;
+ Hotplug hotplug;
+ };
+} \ No newline at end of file
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 9f1a5ae..2ccfb02 100644
--- a/include/Overlay.hpp
+++ b/include/Overlay.hpp
@@ -61,6 +61,9 @@ namespace gsr {
void exit();
const Config& get_config() const;
+
+ std::function<void(const char *hotkey_option)> on_keyboard_hotkey_changed;
+ std::function<void(const char *hotkey_option)> on_joystick_hotkey_changed;
private:
void xi_setup();
void handle_xi_events();
diff --git a/include/gui/GlobalSettingsPage.hpp b/include/gui/GlobalSettingsPage.hpp
index 06098f0..1066bb5 100644
--- a/include/gui/GlobalSettingsPage.hpp
+++ b/include/gui/GlobalSettingsPage.hpp
@@ -24,13 +24,15 @@ 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;
+ 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:
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<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();
@@ -44,6 +46,7 @@ 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;
};
} \ No newline at end of file