From 79b052fca7f0f026593d3d9ddd6107100c945ee1 Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Tue, 31 Jul 2018 16:12:22 -0700 Subject: [PATCH 1/4] Remove redundant conditions --- right/src/usb_report_updater.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index e555863..7d99023 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -366,7 +366,7 @@ static void updateActiveUsbReports(void) if (action->type == KeyActionType_Keystroke && action->keystroke.secondaryRole) { // Press released secondary role key. - if (!keyState->previous && action->type == KeyActionType_Keystroke && action->keystroke.secondaryRole && secondaryRoleState == SecondaryRoleState_Released) { + if (!keyState->previous && secondaryRoleState == SecondaryRoleState_Released) { secondaryRoleState = SecondaryRoleState_Pressed; secondaryRoleSlotId = slotId; secondaryRoleKeyId = keyId; From 1e9b5833eb03ee83e1a90de85905ae3069cd7fb9 Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Wed, 1 Aug 2018 15:53:55 -0700 Subject: [PATCH 2/4] Correctly handle keypresses which triggers a secondary role --- right/src/usb_report_updater.c | 1 + 1 file changed, 1 insertion(+) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index 7d99023..d69a173 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -377,6 +377,7 @@ static void updateActiveUsbReports(void) // Trigger secondary role. if (!keyState->previous && secondaryRoleState == SecondaryRoleState_Pressed) { secondaryRoleState = SecondaryRoleState_Triggered; + keyState->current = false; } else { applyKeyAction(keyState, action); } From e4a99a9400fe35261462d7452ae41c91fd401b90 Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Wed, 1 Aug 2018 16:36:29 -0700 Subject: [PATCH 3/4] Make sticky modifiers work consistently --- right/src/usb_report_updater.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index d69a173..c829935 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -236,6 +236,7 @@ static void handleSwitchLayerAction(key_state_t *keyState, key_action_t *action) static uint8_t basicScancodeIndex = 0; static uint8_t mediaScancodeIndex = 0; static uint8_t systemScancodeIndex = 0; +static uint8_t stickyModifiers; static void applyKeyAction(key_state_t *keyState, key_action_t *action) { @@ -245,10 +246,19 @@ static void applyKeyAction(key_state_t *keyState, key_action_t *action) handleSwitchLayerAction(keyState, action); + if (!keyState->previous) { + stickyModifiers = 0; + } + switch (action->type) { case KeyActionType_Keystroke: - ActiveUsbBasicKeyboardReport->modifiers |= action->keystroke.modifiers; - + if (action->keystroke.scancode) { + if (!keyState->previous) { + stickyModifiers = action->keystroke.modifiers; + } + } else { + ActiveUsbBasicKeyboardReport->modifiers |= action->keystroke.modifiers; + } switch (action->keystroke.keystrokeType) { case KeystrokeType_Basic: if (basicScancodeIndex >= USB_BASIC_KEYBOARD_MAX_KEYS || action->keystroke.scancode == 0) { @@ -296,8 +306,6 @@ static secondary_role_t secondaryRole; static void updateActiveUsbReports(void) { - static uint8_t previousModifiers = 0; - if (MacroPlaying) { Macros_ContinueMacro(); memcpy(ActiveUsbMouseReport, &MacroMouseReport, sizeof MacroMouseReport); @@ -320,7 +328,11 @@ static void updateActiveUsbReports(void) if (activeLayer == LayerId_Base) { activeLayer = GetActiveLayer(); } - bool layerGotReleased = previousLayer != LayerId_Base && activeLayer == LayerId_Base; + bool layerChanged = previousLayer != activeLayer; + if (layerChanged) { + stickyModifiers = 0; + } + bool layerGotReleased = layerChanged && activeLayer == LayerId_Base; LedDisplay_SetLayer(activeLayer); if (TestUsbStack) { @@ -406,15 +418,12 @@ static void updateActiveUsbReports(void) // When a layer switcher key gets pressed along with another key that produces some modifiers // and the accomanying key gets released then keep the related modifiers active a long as the // layer switcher key stays pressed. Useful for Alt+Tab keymappings and the like. - if (activeLayer != LayerId_Base && activeLayer == PreviousHeldLayer && basicScancodeIndex == 0) { - ActiveUsbBasicKeyboardReport->modifiers |= previousModifiers; - } + ActiveUsbBasicKeyboardReport->modifiers |= stickyModifiers; if (secondaryRoleState == SecondaryRoleState_Triggered && IS_SECONDARY_ROLE_MODIFIER(secondaryRole)) { ActiveUsbBasicKeyboardReport->modifiers |= SECONDARY_ROLE_MODIFIER_TO_HID_MODIFIER(secondaryRole); } - previousModifiers = ActiveUsbBasicKeyboardReport->modifiers; previousLayer = activeLayer; } From 0bf205c5d2d3a7214e1622b5b26d3d1095904b95 Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Wed, 1 Aug 2018 18:12:12 -0700 Subject: [PATCH 4/4] Keep sticky modifiers active when modifier-only keys are pressed --- right/src/usb_report_updater.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index c829935..156db1a 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -246,10 +246,6 @@ static void applyKeyAction(key_state_t *keyState, key_action_t *action) handleSwitchLayerAction(keyState, action); - if (!keyState->previous) { - stickyModifiers = 0; - } - switch (action->type) { case KeyActionType_Keystroke: if (action->keystroke.scancode) { @@ -281,6 +277,9 @@ static void applyKeyAction(key_state_t *keyState, key_action_t *action) } break; case KeyActionType_Mouse: + if (!keyState->previous) { + stickyModifiers = 0; + } activeMouseStates[action->mouseAction] = true; break; case KeyActionType_SwitchLayer: @@ -288,11 +287,13 @@ static void applyKeyAction(key_state_t *keyState, key_action_t *action) break; case KeyActionType_SwitchKeymap: if (!keyState->previous) { + stickyModifiers = 0; SwitchKeymapById(action->switchKeymap.keymapId); } break; case KeyActionType_PlayMacro: if (!keyState->previous) { + stickyModifiers = 0; Macros_StartMacro(action->playMacro.macroId); } break;