Add option to save replay with controller (double-click share button), allow prime-run on wayland

This commit is contained in:
dec05eba
2025-01-20 23:11:00 +01:00
parent 92401d8bc8
commit 47ada4d798
17 changed files with 607 additions and 107 deletions

View File

@@ -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;
};

View File

@@ -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;
};
}

33
include/Hotplug.hpp Normal file
View File

@@ -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];
};
}

View File

@@ -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();

View File

@@ -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;
};
}