summaryrefslogtreecommitdiffstats
path: root/tmk_core/common/action.c
diff options
context:
space:
mode:
authorWojciech Siewierski <wojciech.siewierski@onet.pl>2016-03-05 14:42:17 +0100
committerWojciech Siewierski <wojciech.siewierski@onet.pl>2016-03-05 14:42:17 +0100
commitc2480884aa1321ec4a0364f773476f0e7f7d3069 (patch)
treefbda4c0b773e48c78378485ab746bf84e2b74739 /tmk_core/common/action.c
parent4e4250063ed3f9fcaa3448715d28f7a815f7cc7e (diff)
downloadqmk_firmware-c2480884aa1321ec4a0364f773476f0e7f7d3069.tar.gz
qmk_firmware-c2480884aa1321ec4a0364f773476f0e7f7d3069.tar.xz
Fix the layer-dependent modifiers handling
Closes #181.
Diffstat (limited to 'tmk_core/common/action.c')
-rw-r--r--tmk_core/common/action.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 77ea39e94..be06e12aa 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -53,6 +53,26 @@ void action_exec(keyevent_t event)
#endif
}
+/*
+ * Make sure the action triggered when the key is released is the same
+ * one as the one triggered on press. It's important for the mod keys
+ * when the layer is switched after the down event but before the up
+ * event as they may get stuck otherwise.
+ */
+action_t store_or_get_action(bool pressed, keypos_t key)
+{
+#ifndef NO_ACTION_LAYER
+ static action_t pressed_actions[MATRIX_ROWS][MATRIX_COLS];
+
+ if (pressed) {
+ pressed_actions[key.row][key.col] = layer_switch_get_action(key);
+ }
+ return pressed_actions[key.row][key.col];
+#else
+ return layer_switch_get_action(key);
+#endif
+}
+
void process_action(keyrecord_t *record)
{
keyevent_t event = record->event;
@@ -62,7 +82,7 @@ void process_action(keyrecord_t *record)
if (IS_NOEVENT(event)) { return; }
- action_t action = layer_switch_get_action(event.key);
+ action_t action = store_or_get_action(event.pressed, event.key);
dprint("ACTION: "); debug_action(action);
#ifndef NO_ACTION_LAYER
dprint(" layer_state: "); layer_debug();