From 3d0993998c9afa7fb0e6c80fff94a51c8abb9c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Sun, 26 Nov 2017 01:05:36 +0100 Subject: [PATCH] Add double tap switch layer timeout. --- right/src/usb_report_updater.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index 3b1f15c..d68e249 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -19,6 +19,8 @@ uint32_t UsbReportUpdateTime = 0; static uint32_t elapsedTime; +static uint16_t doubleTapSwitchLayerTimeout = 300; + static float mouseMoveInitialSpeed = 1; static float mouseMoveBaseAcceleration = 3; static float mouseMoveBaseSpeed = 5; @@ -137,6 +139,7 @@ static uint8_t basicScancodeIndex = 0; static uint8_t mediaScancodeIndex = 0; static uint8_t systemScancodeIndex = 0; key_state_t *doubleTapSwitchLayerKey; +uint32_t doubleTapSwitchLayerStartTime; void applyKeyAction(key_state_t *keyState, key_action_t *action) { @@ -179,10 +182,13 @@ void applyKeyAction(key_state_t *keyState, key_action_t *action) case KeyActionType_SwitchLayer: if (!keyState->previous && previousLayer == LayerId_Base && action->switchLayer.mode == SwitchLayerMode_HoldAndDoubleTapToggle) { if (doubleTapSwitchLayerKey) { - ToggledLayer = action->switchLayer.layer; + if (Timer_GetElapsedTime(&doubleTapSwitchLayerStartTime) < doubleTapSwitchLayerTimeout) { + ToggledLayer = action->switchLayer.layer; + } doubleTapSwitchLayerKey = NULL; } else { doubleTapSwitchLayerKey = keyState; + doubleTapSwitchLayerStartTime = CurrentTime; } } break;