aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsnyman <snyman@users.noreply.github.com>2018-03-20 22:59:54 -0400
committerJack Humbert <jack.humb@gmail.com>2018-03-20 22:59:54 -0400
commit7a5ce36f23624b29b548f9e8f8e3a0b165cdf2a4 (patch)
treeb3d9a72244a49f08b9ef12a1a8376fd05954c67b
parent4ec03111cc0dd8cb365aaa43a6aaf2c626d72a61 (diff)
downloadqmk_firmware-7a5ce36f23624b29b548f9e8f8e3a0b165cdf2a4.tar.gz
qmk_firmware-7a5ce36f23624b29b548f9e8f8e3a0b165cdf2a4.zip
Add macro for momentarily switching to a layer while some mods are active (#2460)
* Macro for a momentary layer switch with mods Passes through to the existing ACTION_LAYER_MODS macro, albeit with more limited options due to lack of space in the quantum_keycodes enum. * Add documentation for LM layer-mod macro * Clean up Tap Toggle documentation
-rw-r--r--docs/feature_advanced_keycodes.md3
-rw-r--r--docs/keycodes.md17
-rw-r--r--quantum/keymap_common.c5
-rw-r--r--quantum/quantum_keycodes.h5
4 files changed, 21 insertions, 9 deletions
diff --git a/docs/feature_advanced_keycodes.md b/docs/feature_advanced_keycodes.md
index ceee7fad1..f61d78d50 100644
--- a/docs/feature_advanced_keycodes.md
+++ b/docs/feature_advanced_keycodes.md
@@ -25,7 +25,8 @@ These functions allow you to activate layers in various ways.
25* `LT(layer, kc)` - momentary switch to *layer* when held, and *kc* when tapped. 25* `LT(layer, kc)` - momentary switch to *layer* when held, and *kc* when tapped.
26* `TG(layer)` - toggles a layer on or off. 26* `TG(layer)` - toggles a layer on or off.
27* `TO(layer)` - Goes to a layer. This code is special, because it lets you go either up or down the stack -- just goes directly to the layer you want. So while other codes only let you go _up_ the stack (from layer 0 to layer 3, for example), `TO(2)` is going to get you to layer 2, no matter where you activate it from -- even if you're currently on layer 5. This gets activated on keydown (as soon as the key is pressed). 27* `TO(layer)` - Goes to a layer. This code is special, because it lets you go either up or down the stack -- just goes directly to the layer you want. So while other codes only let you go _up_ the stack (from layer 0 to layer 3, for example), `TO(2)` is going to get you to layer 2, no matter where you activate it from -- even if you're currently on layer 5. This gets activated on keydown (as soon as the key is pressed).
28* `TT(layer)` - Layer Tap-Toggle. If you hold the key down, the layer becomes active, and then deactivates when you let go. And if you tap it, the layer simply becomes active (toggles on). It needs 5 taps by default, but you can set it by defining `TAPPING_TOGGLE`, for example, `#define TAPPING_TOGGLE 2` for just two taps. 28* `TT(layer)` - Layer Tap-Toggle. If you hold the key down, the layer becomes active, and then deactivates when you let go. And if you repeatedly tap it, the layer simply becomes active (toggles on). It needs 5 taps by default, but you can set it by defining `TAPPING_TOGGLE`, for example, `#define TAPPING_TOGGLE 2` for just two taps.
29* `LM(layer, mod)` - Momentary switch to *layer* (like MO), but with modifier(s) *mod* active. Only supports layers 0-15 and the left modifiers.
29 30
30# Working with Layers 31# Working with Layers
31 32
diff --git a/docs/keycodes.md b/docs/keycodes.md
index 0f7968e7d..dad645cf0 100644
--- a/docs/keycodes.md
+++ b/docs/keycodes.md
@@ -368,14 +368,15 @@ This is a reference only. Each group of keys links to the page documenting their
368 368
369## [Switching and Toggling Layers](feature_advanced_keycodes.md#switching-and-toggling-layers) 369## [Switching and Toggling Layers](feature_advanced_keycodes.md#switching-and-toggling-layers)
370 370
371|Key |Description | 371|Key |Description |
372|---------------|----------------------------------------------------------------------------------| 372|----------------|----------------------------------------------------------------------------------|
373|`LT(layer, kc)`|Turn on `layer` when held, `kc` when tapped | 373|`LT(layer, kc)` |Turn on `layer` when held, `kc` when tapped |
374|`TO(layer)` |Turn on `layer` when pressed | 374|`TO(layer)` |Turn on `layer` when pressed |
375|`MO(layer)` |Momentarily turn on `layer` when pressed (requires `KC_TRNS` on destination layer)| 375|`MO(layer)` |Momentarily turn on `layer` when pressed (requires `KC_TRNS` on destination layer)|
376|`DF(layer)` |Set the base (default) layer | 376|`DF(layer)` |Set the base (default) layer |
377|`TG(layer)` |Toggle `layer` on or off | 377|`TG(layer)` |Toggle `layer` on or off |
378|`TT(layer)` |Tap toggle? idk FIXME | 378|`TT(layer)` |Normally acts like MO unless it's tapped multiple times, which toggles `layer` on |
379|`LM(layer, mod)`|Momentarily turn on `layer` (like MO) with `mod` active as well. |
379 380
380## [One Shot Keys](quantum_keycodes.md#one-shot-keys) 381## [One Shot Keys](quantum_keycodes.md#one-shot-keys)
381 382
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 8b09f93fc..9a412b66a 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -122,6 +122,11 @@ action_t action_for_key(uint8_t layer, keypos_t key)
122 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: 122 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
123 action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF); 123 action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF);
124 break; 124 break;
125 case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
126 mod = keycode & 0xF;
127 action_layer = (keycode >> 4) & 0xF;
128 action.code = ACTION_LAYER_MODS(action_layer, mod);
129 break;
125 case QK_MOD_TAP ... QK_MOD_TAP_MAX: 130 case QK_MOD_TAP ... QK_MOD_TAP_MAX:
126 mod = mod_config((keycode >> 0x8) & 0x1F); 131 mod = mod_config((keycode >> 0x8) & 0x1F);
127 action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF); 132 action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF);
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 4a5681c7e..8122bfe73 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -71,6 +71,8 @@ enum quantum_keycodes {
71 QK_TAP_DANCE_MAX = 0x57FF, 71 QK_TAP_DANCE_MAX = 0x57FF,
72 QK_LAYER_TAP_TOGGLE = 0x5800, 72 QK_LAYER_TAP_TOGGLE = 0x5800,
73 QK_LAYER_TAP_TOGGLE_MAX = 0x58FF, 73 QK_LAYER_TAP_TOGGLE_MAX = 0x58FF,
74 QK_LAYER_MOD = 0x5900,
75 QK_LAYER_MOD_MAX = 0x59FF,
74#ifdef STENO_ENABLE 76#ifdef STENO_ENABLE
75 QK_STENO = 0x5A00, 77 QK_STENO = 0x5A00,
76 QK_STENO_BOLT = 0x5A30, 78 QK_STENO_BOLT = 0x5A30,
@@ -597,6 +599,9 @@ enum quantum_keycodes {
597// One-shot layer - 256 layer max 599// One-shot layer - 256 layer max
598#define OSL(layer) (layer | QK_ONE_SHOT_LAYER) 600#define OSL(layer) (layer | QK_ONE_SHOT_LAYER)
599 601
602// L-ayer M-od: Momentary switch layer with modifiers active - 16 layer max, left mods only
603#define LM(layer, mod) (QK_LAYER_MOD | (((layer) & 0xF) << 4) | ((mod) & 0xF))
604
600// One-shot mod 605// One-shot mod
601#define OSM(mod) ((mod) | QK_ONE_SHOT_MOD) 606#define OSM(mod) ((mod) | QK_ONE_SHOT_MOD)
602 607