Change joystick hotkeys to not conflict with steam

This commit is contained in:
dec05eba
2025-03-18 01:02:45 +01:00
parent 9b461edd0c
commit 44e7f57d21
3 changed files with 31 additions and 18 deletions

View File

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

View File

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

View File

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