aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-03-18 01:02:45 +0100
committerdec05eba <dec05eba@protonmail.com>2025-03-18 01:02:45 +0100
commit44e7f57d21680de28a5ccd7b6556697666061fe7 (patch)
treee3c76ae8c4455401cb6b4bbe57d3c32c4bad4a2e
parent9b461edd0c0eaad31114c3b13b83a08a59543077 (diff)
Change joystick hotkeys to not conflict with steam
-rw-r--r--include/GlobalHotkeysJoystick.hpp4
-rw-r--r--src/GlobalHotkeysJoystick.cpp37
-rw-r--r--src/gui/GlobalSettingsPage.cpp8
3 files changed, 31 insertions, 18 deletions
diff --git a/include/GlobalHotkeysJoystick.hpp b/include/GlobalHotkeysJoystick.hpp
index 7dbb272..1effe3c 100644
--- a/include/GlobalHotkeysJoystick.hpp
+++ b/include/GlobalHotkeysJoystick.hpp
@@ -49,6 +49,10 @@ namespace gsr {
int event_index = -1;
bool playstation_button_pressed = false;
+ bool up_pressed = false;
+ bool down_pressed = false;
+ bool left_pressed = false;
+ bool right_pressed = false;
bool save_replay = false;
bool take_screenshot = false;
diff --git a/src/GlobalHotkeysJoystick.cpp b/src/GlobalHotkeysJoystick.cpp
index 2a33738..066c8c9 100644
--- a/src/GlobalHotkeysJoystick.cpp
+++ b/src/GlobalHotkeysJoystick.cpp
@@ -8,10 +8,8 @@
namespace gsr {
static constexpr int button_pressed = 1;
static constexpr int playstation_button = 10;
- static constexpr int x_button = 0;
- static constexpr int circle_button = 1;
- static constexpr int triangle_button = 2;
- static constexpr int square_button = 3;
+ static constexpr int axis_up_down = 7;
+ static constexpr int axis_left_right = 6;
// Returns -1 on error
static int get_js_dev_input_id_from_filepath(const char *dev_input_filepath) {
@@ -179,19 +177,30 @@ namespace gsr {
if(read(fd, &event, sizeof(event)) != sizeof(event))
return;
- if((event.type & JS_EVENT_BUTTON) == 0)
- return;
+ if((event.type & JS_EVENT_BUTTON) == JS_EVENT_BUTTON) {
+ if(event.number == playstation_button)
+ playstation_button_pressed = event.value == button_pressed;
+ } else if((event.type & JS_EVENT_AXIS) == JS_EVENT_AXIS && playstation_button_pressed) {
+ const int trigger_threshold = 16383;
+ const bool prev_up_pressed = up_pressed;
+ const bool prev_down_pressed = down_pressed;
+ const bool prev_left_pressed = left_pressed;
+ const bool prev_right_pressed = right_pressed;
+ if(event.number == axis_up_down) {
+ up_pressed = event.value <= -trigger_threshold;
+ down_pressed = event.value >= trigger_threshold;
+ } else if(event.number == axis_left_right) {
+ left_pressed = event.value <= -trigger_threshold;
+ right_pressed = event.value >= trigger_threshold;
+ }
- if(event.number == playstation_button) {
- playstation_button_pressed = event.value == button_pressed;
- } else if(playstation_button_pressed && event.value == button_pressed) {
- if(event.number == circle_button)
- save_replay = true;
- else if(event.number == triangle_button)
+ if(up_pressed && !prev_up_pressed)
take_screenshot = true;
- else if(event.number == square_button)
+ else if(down_pressed && !prev_down_pressed)
+ save_replay = true;
+ else if(left_pressed && !prev_left_pressed)
toggle_record = true;
- else if(event.number == x_button)
+ else if(right_pressed && !prev_right_pressed)
toggle_replay = true;
}
}
diff --git a/src/gui/GlobalSettingsPage.cpp b/src/gui/GlobalSettingsPage.cpp
index 82baa86..44c5a1c 100644
--- a/src/gui/GlobalSettingsPage.cpp
+++ b/src/gui/GlobalSettingsPage.cpp
@@ -340,10 +340,10 @@ namespace gsr {
list_ptr->add_widget(create_record_hotkey_options());
list_ptr->add_widget(create_stream_hotkey_options());
list_ptr->add_widget(create_screenshot_hotkey_options());
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and square to start/stop recording", get_color_theme().text_color));
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and X to start/stop replay", get_color_theme().text_color));
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and circle to save a replay", get_color_theme().text_color));
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and triangle to take a screenshot", get_color_theme().text_color));
+ list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and d-pad up to take a screenshot", get_color_theme().text_color));
+ list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and d-pad down to save a replay", get_color_theme().text_color));
+ list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and d-pad left to start/stop recording", get_color_theme().text_color));
+ list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and d-pad right to start/stop replay", get_color_theme().text_color));
list_ptr->add_widget(create_hotkey_control_buttons());
return subsection;
}