Merge pull request #203 from UltimateHackingKeyboard/sticky-modifiers
Adjust the behavior of sticky modifiers
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
uint8_t timestamp;
|
uint8_t timestamp;
|
||||||
bool previous : 1;
|
bool previous : 1;
|
||||||
bool current : 1;
|
bool current : 1;
|
||||||
bool suppressed : 1;
|
|
||||||
bool debouncing : 1;
|
bool debouncing : 1;
|
||||||
} key_state_t;
|
} key_state_t;
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -15,7 +15,7 @@ void updateLayerStates(void)
|
|||||||
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
||||||
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
||||||
key_state_t *keyState = &KeyStates[slotId][keyId];
|
key_state_t *keyState = &KeyStates[slotId][keyId];
|
||||||
if (keyState->current && !keyState->suppressed) {
|
if (keyState->current) {
|
||||||
key_action_t action = CurrentKeymap[LayerId_Base][slotId][keyId];
|
key_action_t action = CurrentKeymap[LayerId_Base][slotId][keyId];
|
||||||
if (action.type == KeyActionType_SwitchLayer) {
|
if (action.type == KeyActionType_SwitchLayer) {
|
||||||
if (action.switchLayer.mode != SwitchLayerMode_Toggle) {
|
if (action.switchLayer.mode != SwitchLayerMode_Toggle) {
|
||||||
@@ -70,3 +70,14 @@ layer_id_t GetActiveLayer()
|
|||||||
|
|
||||||
return heldLayer;
|
return heldLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsLayerHeld(void)
|
||||||
|
{
|
||||||
|
for (layer_id_t layerId = LayerId_Mod; layerId <= LayerId_Mouse; layerId++) {
|
||||||
|
if (heldLayers[layerId]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
+2
-1
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
layer_id_t GetActiveLayer();
|
layer_id_t GetActiveLayer(void);
|
||||||
|
bool IsLayerHeld(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -237,18 +237,15 @@ static void handleSwitchLayerAction(key_state_t *keyState, key_action_t *action)
|
|||||||
static uint8_t basicScancodeIndex = 0;
|
static uint8_t basicScancodeIndex = 0;
|
||||||
static uint8_t mediaScancodeIndex = 0;
|
static uint8_t mediaScancodeIndex = 0;
|
||||||
static uint8_t systemScancodeIndex = 0;
|
static uint8_t systemScancodeIndex = 0;
|
||||||
static uint8_t stickyModifiers;
|
static uint8_t stickyModifiers, stickySlotId, stickyKeyId;
|
||||||
static uint8_t secondaryRoleState = SecondaryRoleState_Released;
|
static uint8_t secondaryRoleState = SecondaryRoleState_Released;
|
||||||
static uint8_t secondaryRoleSlotId;
|
static uint8_t secondaryRoleSlotId;
|
||||||
static uint8_t secondaryRoleKeyId;
|
static uint8_t secondaryRoleKeyId;
|
||||||
static secondary_role_t secondaryRole;
|
static secondary_role_t secondaryRole;
|
||||||
|
|
||||||
static void applyKeyAction(key_state_t *keyState, key_action_t *action)
|
static void applyKeyAction(key_state_t *keyState, key_action_t *action, uint8_t slotId, uint8_t keyId)
|
||||||
{
|
{
|
||||||
if (keyState->suppressed) {
|
if (keyState->current) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSwitchLayerAction(keyState, action);
|
handleSwitchLayerAction(keyState, action);
|
||||||
|
|
||||||
switch (action->type) {
|
switch (action->type) {
|
||||||
@@ -256,6 +253,8 @@ static void applyKeyAction(key_state_t *keyState, key_action_t *action)
|
|||||||
if (action->keystroke.scancode) {
|
if (action->keystroke.scancode) {
|
||||||
if (!keyState->previous) {
|
if (!keyState->previous) {
|
||||||
stickyModifiers = action->keystroke.modifiers;
|
stickyModifiers = action->keystroke.modifiers;
|
||||||
|
stickySlotId = slotId;
|
||||||
|
stickyKeyId = keyId;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ActiveUsbBasicKeyboardReport->modifiers |= action->keystroke.modifiers;
|
ActiveUsbBasicKeyboardReport->modifiers |= action->keystroke.modifiers;
|
||||||
@@ -304,6 +303,19 @@ static void applyKeyAction(key_state_t *keyState, key_action_t *action)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
switch (action->type) {
|
||||||
|
case KeyActionType_Keystroke:
|
||||||
|
if (keyState->previous) {
|
||||||
|
if (slotId == stickySlotId && keyId == stickyKeyId) {
|
||||||
|
if (!IsLayerHeld() && !(secondaryRoleState == SecondaryRoleState_Triggered && IS_SECONDARY_ROLE_LAYER_SWITCHER(secondaryRole))) {
|
||||||
|
stickyModifiers = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateActiveUsbReports(void)
|
static void updateActiveUsbReports(void)
|
||||||
@@ -394,22 +406,22 @@ static void updateActiveUsbReports(void)
|
|||||||
secondaryRoleSlotId = slotId;
|
secondaryRoleSlotId = slotId;
|
||||||
secondaryRoleKeyId = keyId;
|
secondaryRoleKeyId = keyId;
|
||||||
secondaryRole = action->keystroke.secondaryRole;
|
secondaryRole = action->keystroke.secondaryRole;
|
||||||
keyState->suppressed = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
applyKeyAction(keyState, action);
|
applyKeyAction(keyState, action, slotId, keyId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
keyState->suppressed = false;
|
|
||||||
|
|
||||||
// Release secondary role key.
|
// Release secondary role key.
|
||||||
if (keyState->previous && secondaryRoleSlotId == slotId && secondaryRoleKeyId == keyId) {
|
if (keyState->previous && secondaryRoleSlotId == slotId && secondaryRoleKeyId == keyId && secondaryRoleState != SecondaryRoleState_Released) {
|
||||||
// Trigger primary role.
|
// Trigger primary role.
|
||||||
if (secondaryRoleState == SecondaryRoleState_Pressed) {
|
if (secondaryRoleState == SecondaryRoleState_Pressed) {
|
||||||
keyState->previous = false;
|
keyState->previous = false;
|
||||||
applyKeyAction(keyState, action);
|
keyState->current = true;
|
||||||
|
applyKeyAction(keyState, action, slotId, keyId);
|
||||||
}
|
}
|
||||||
secondaryRoleState = SecondaryRoleState_Released;
|
secondaryRoleState = SecondaryRoleState_Released;
|
||||||
|
} else {
|
||||||
|
applyKeyAction(keyState, action, slotId, keyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user