From 5b84d7421f44c8bc00999071f2b3d46d238a9946 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 23 Jan 2025 21:49:07 +0100 Subject: Fix controller double click not working sometimes --- include/GlobalHotkeysJoystick.hpp | 3 ++- meson.build | 2 +- src/GlobalHotkeysJoystick.cpp | 23 ++++++++++++++--------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/GlobalHotkeysJoystick.hpp b/include/GlobalHotkeysJoystick.hpp index 367de18..69f66df 100644 --- a/include/GlobalHotkeysJoystick.hpp +++ b/include/GlobalHotkeysJoystick.hpp @@ -3,6 +3,7 @@ #include "GlobalHotkeys.hpp" #include "Hotplug.hpp" #include +#include #include #include #include @@ -45,7 +46,7 @@ namespace gsr { int event_index = -1; mgl::Clock double_click_clock; - int num_times_clicked = 0; + std::optional prev_time_clicked; bool save_replay = false; int hotplug_poll_index = -1; Hotplug hotplug; diff --git a/meson.build b/meson.build index a16933d..333ad48 100644 --- a/meson.build +++ b/meson.build @@ -52,7 +52,7 @@ datadir = get_option('datadir') gsr_ui_resources_path = join_paths(prefix, datadir, 'gsr-ui') add_project_arguments('-DGSR_UI_VERSION="' + meson.project_version() + '"', language: ['c', 'cpp']) -add_project_arguments('-DGSR_FLATPAK_VERSION="5.0.10"', language: ['c', 'cpp']) +add_project_arguments('-DGSR_FLATPAK_VERSION="5.1.0"', language: ['c', 'cpp']) executable( meson.project_name(), diff --git a/src/GlobalHotkeysJoystick.cpp b/src/GlobalHotkeysJoystick.cpp index 55c6e43..b79e799 100644 --- a/src/GlobalHotkeysJoystick.cpp +++ b/src/GlobalHotkeysJoystick.cpp @@ -155,15 +155,20 @@ namespace gsr { return; if(event.number == 8 && event.value == 1) { - ++num_times_clicked; - if(num_times_clicked == 1) - double_click_clock.restart(); - else if(num_times_clicked == 2 && double_click_clock.restart() >= double_click_timeout_seconds) - num_times_clicked = 0; - - if(num_times_clicked == 2) { - save_replay = true; - num_times_clicked = 0; + const double now = double_click_clock.get_elapsed_time_seconds(); + if(!prev_time_clicked.has_value()) { + prev_time_clicked = now; + return; + } + + if(prev_time_clicked.has_value()) { + const bool double_clicked = (now - prev_time_clicked.value()) < double_click_timeout_seconds; + if(double_clicked) { + save_replay = true; + prev_time_clicked.reset(); + } else { + prev_time_clicked = now; + } } } } -- cgit v1.2.3