diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-01-20 23:11:00 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-01-20 23:11:00 +0100 |
commit | 47ada4d79844d9a98d9689d0de0c92864e0fc372 (patch) | |
tree | 1325fd3061e78a194b3db0be848a06928fdacce9 /include/GlobalHotkeysJoystick.hpp | |
parent | 92401d8bc8fa3cbc8017936eb1d18280199942e0 (diff) |
Add option to save replay with controller (double-click share button), allow prime-run on wayland
Diffstat (limited to 'include/GlobalHotkeysJoystick.hpp')
-rw-r--r-- | include/GlobalHotkeysJoystick.hpp | 53 |
1 files changed, 53 insertions, 0 deletions
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 |