From 521ac706c176d73ffb0cab94f9ed4fbcab1e1fee Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 25 Feb 2021 04:01:22 -0500 Subject: [PATCH] [client] app: do not toggle capture if escapeKey is held When users press escapeKey for a long time, they probably want to see the help text instead of actually toggling capture. Therefore, if the key is held down for more than 500 ms, we assume the user wants to look at the help text and do not toggle capture mode. 500 ms seems to be a decent compromise, allowing slow presses, but is not enough time for the user to have looked at the help text. --- client/src/app.c | 3 ++- client/src/main.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/app.c b/client/src/app.c index 79f640ce..3d540dee 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -194,6 +194,7 @@ void app_handleKeyPress(int sc) if (sc == g_params.escapeKey && !g_state.escapeActive) { g_state.escapeActive = true; + g_state.escapeTime = microtime(); g_state.escapeAction = -1; app_showHelp(true); return; @@ -233,7 +234,7 @@ void app_handleKeyRelease(int sc) { if (g_state.escapeAction == -1) { - if (g_params.useSpiceInput) + if (microtime() - g_state.escapeTime < 500000 && g_params.useSpiceInput) core_setGrab(!g_cursor.grab); } else diff --git a/client/src/main.h b/client/src/main.h index f427436f..382dc643 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -49,6 +49,7 @@ struct AppState bool ignoreInput; bool showFPS; bool escapeActive; + uint64_t escapeTime; int escapeAction; KeybindHandle bindings[KEY_MAX]; const char * keyDescription[KEY_MAX];