[client] app: delay showing the escape help for 250ms

This change prevents the help text being shown unless the escape key has
been held for a minimum of 250ms (reduced from 500ms).
This commit is contained in:
Geoffrey McRae 2021-02-26 10:21:56 +11:00
parent 521ac706c1
commit f3b46e6d4f
4 changed files with 27 additions and 6 deletions

View File

@ -54,6 +54,7 @@ void app_handleKeyRelease(int scancode);
void app_handleEnterEvent(bool entered); void app_handleEnterEvent(bool entered);
void app_handleFocusEvent(bool focused); void app_handleFocusEvent(bool focused);
void app_handleCloseEvent(void); void app_handleCloseEvent(void);
void app_handleRenderEvent(const uint64_t timeUs);
void app_setFullscreen(bool fs); void app_setFullscreen(bool fs);
bool app_getFullscreen(void); bool app_getFullscreen(void);

View File

@ -196,7 +196,6 @@ void app_handleKeyPress(int sc)
g_state.escapeActive = true; g_state.escapeActive = true;
g_state.escapeTime = microtime(); g_state.escapeTime = microtime();
g_state.escapeAction = -1; g_state.escapeAction = -1;
app_showHelp(true);
return; return;
} }
@ -234,7 +233,7 @@ void app_handleKeyRelease(int sc)
{ {
if (g_state.escapeAction == -1) if (g_state.escapeAction == -1)
{ {
if (microtime() - g_state.escapeTime < 500000 && g_params.useSpiceInput) if (!g_state.escapeHelp && g_params.useSpiceInput)
core_setGrab(!g_cursor.grab); core_setGrab(!g_cursor.grab);
} }
else else
@ -248,10 +247,7 @@ void app_handleKeyRelease(int sc)
} }
if (sc == g_params.escapeKey) if (sc == g_params.escapeKey)
{
g_state.escapeActive = false; g_state.escapeActive = false;
app_showHelp(false);
}
} }
if (!core_inputEnabled()) if (!core_inputEnabled())
@ -386,6 +382,26 @@ void app_handleCloseEvent(void)
g_state.state = APP_STATE_SHUTDOWN; g_state.state = APP_STATE_SHUTDOWN;
} }
void app_handleRenderEvent(const uint64_t timeUs)
{
if (!g_state.escapeActive)
{
if (g_state.escapeHelp)
{
g_state.escapeHelp = false;
app_showHelp(false);
}
}
else
{
if (!g_state.escapeHelp && timeUs - g_state.escapeTime > 200000)
{
g_state.escapeHelp = true;
app_showHelp(true);
}
}
}
void app_setFullscreen(bool fs) void app_setFullscreen(bool fs)
{ {
g_state.ds->setFullscreen(fs); g_state.ds->setFullscreen(fs);

View File

@ -157,7 +157,8 @@ static int renderThread(void * unused)
} }
} }
if (!g_state.resizeDone && g_state.resizeTimeout < microtime()) const uint64_t now = microtime();
if (!g_state.resizeDone && g_state.resizeTimeout < now)
{ {
g_state.ds->setWindowSize( g_state.ds->setWindowSize(
g_state.dstRect.w, g_state.dstRect.w,
@ -165,6 +166,8 @@ static int renderThread(void * unused)
); );
g_state.resizeDone = true; g_state.resizeDone = true;
} }
app_handleRenderEvent(now);
} }
g_state.state = APP_STATE_SHUTDOWN; g_state.state = APP_STATE_SHUTDOWN;

View File

@ -51,6 +51,7 @@ struct AppState
bool escapeActive; bool escapeActive;
uint64_t escapeTime; uint64_t escapeTime;
int escapeAction; int escapeAction;
bool escapeHelp;
KeybindHandle bindings[KEY_MAX]; KeybindHandle bindings[KEY_MAX];
const char * keyDescription[KEY_MAX]; const char * keyDescription[KEY_MAX];
bool keyDown[KEY_MAX]; bool keyDown[KEY_MAX];