From 940f7553fd895b03bcdb346ff57589c696021a30 Mon Sep 17 00:00:00 2001 From: Tony <45124675+sonninnos@users.noreply.github.com> Date: Fri, 31 Dec 2021 19:17:32 +0200 Subject: [PATCH] Add delay + acceleration to volume hotkeys (#13434) --- runloop.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/runloop.c b/runloop.c index bfff113a09..08f35ab9d5 100644 --- a/runloop.c +++ b/runloop.c @@ -6873,10 +6873,41 @@ static enum runloop_state_enum runloop_check_state( /* Check if we have pressed the AI Service toggle button */ HOTKEY_CHECK(RARCH_AI_SERVICE, CMD_EVENT_AI_SERVICE_TOGGLE, true, NULL); - if (BIT256_GET(current_bits, RARCH_VOLUME_UP)) - command_event(CMD_EVENT_VOLUME_UP, NULL); - else if (BIT256_GET(current_bits, RARCH_VOLUME_DOWN)) - command_event(CMD_EVENT_VOLUME_DOWN, NULL); + /* Volume stepping + acceleration */ + { + static unsigned volume_hotkey_delay = 0; + static unsigned volume_hotkey_delay_active = 0; + unsigned volume_hotkey_delay_default = 15; + if (BIT256_GET(current_bits, RARCH_VOLUME_UP)) + { + if (volume_hotkey_delay > 0) + volume_hotkey_delay--; + else + { + command_event(CMD_EVENT_VOLUME_UP, NULL); + if (volume_hotkey_delay_active > 0) + volume_hotkey_delay_active--; + volume_hotkey_delay = volume_hotkey_delay_active; + } + } + else if (BIT256_GET(current_bits, RARCH_VOLUME_DOWN)) + { + if (volume_hotkey_delay > 0) + volume_hotkey_delay--; + else + { + command_event(CMD_EVENT_VOLUME_DOWN, NULL); + if (volume_hotkey_delay_active > 0) + volume_hotkey_delay_active--; + volume_hotkey_delay = volume_hotkey_delay_active; + } + } + else + { + volume_hotkey_delay = 0; + volume_hotkey_delay_active = volume_hotkey_delay_default; + } + } #ifdef HAVE_NETWORKING /* Check Netplay */