Fix controller double click not working sometimes

This commit is contained in:
dec05eba
2025-01-23 21:49:07 +01:00
parent 1d9d4d6398
commit 5b84d7421f
3 changed files with 16 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
#include "GlobalHotkeys.hpp" #include "GlobalHotkeys.hpp"
#include "Hotplug.hpp" #include "Hotplug.hpp"
#include <unordered_map> #include <unordered_map>
#include <optional>
#include <thread> #include <thread>
#include <poll.h> #include <poll.h>
#include <mglpp/system/Clock.hpp> #include <mglpp/system/Clock.hpp>
@@ -45,7 +46,7 @@ namespace gsr {
int event_index = -1; int event_index = -1;
mgl::Clock double_click_clock; mgl::Clock double_click_clock;
int num_times_clicked = 0; std::optional<double> prev_time_clicked;
bool save_replay = false; bool save_replay = false;
int hotplug_poll_index = -1; int hotplug_poll_index = -1;
Hotplug hotplug; Hotplug hotplug;

View File

@@ -52,7 +52,7 @@ datadir = get_option('datadir')
gsr_ui_resources_path = join_paths(prefix, datadir, 'gsr-ui') 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_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( executable(
meson.project_name(), meson.project_name(),

View File

@@ -155,15 +155,20 @@ namespace gsr {
return; return;
if(event.number == 8 && event.value == 1) { if(event.number == 8 && event.value == 1) {
++num_times_clicked; const double now = double_click_clock.get_elapsed_time_seconds();
if(num_times_clicked == 1) if(!prev_time_clicked.has_value()) {
double_click_clock.restart(); prev_time_clicked = now;
else if(num_times_clicked == 2 && double_click_clock.restart() >= double_click_timeout_seconds) return;
num_times_clicked = 0; }
if(num_times_clicked == 2) { if(prev_time_clicked.has_value()) {
save_replay = true; const bool double_clicked = (now - prev_time_clicked.value()) < double_click_timeout_seconds;
num_times_clicked = 0; if(double_clicked) {
save_replay = true;
prev_time_clicked.reset();
} else {
prev_time_clicked = now;
}
} }
} }
} }