]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Add macro for momentarily switching to a layer while some mods are active (#2460)
authorsnyman <snyman@users.noreply.github.com>
Wed, 21 Mar 2018 02:59:54 +0000 (22:59 -0400)
committerJack Humbert <jack.humb@gmail.com>
Wed, 21 Mar 2018 02:59:54 +0000 (22:59 -0400)
* 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

docs/feature_advanced_keycodes.md
docs/keycodes.md
quantum/keymap_common.c
quantum/quantum_keycodes.h

index ceee7fad183683a6cb3b99450e4a5a91ab7ebf29..f61d78d501f49ed2cbe33a4fd1f11a673c769a76 100644 (file)
@@ -25,7 +25,8 @@ These functions allow you to activate layers in various ways.
 * `LT(layer, kc)` - momentary switch to *layer* when held, and *kc* when tapped.
 * `TG(layer)` - toggles a layer on or off.
 * `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).
-* `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.
+* `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.
+* `LM(layer, mod)` - Momentary switch to *layer* (like MO), but with modifier(s) *mod* active. Only supports layers 0-15 and the left modifiers.
 
 # Working with Layers
 
index 0f7968e7d719509c35dd2c829f3f65e47f312f73..dad645cf085ec2c71d72c4df22ccd54fffe506da 100644 (file)
@@ -368,14 +368,15 @@ This is a reference only. Each group of keys links to the page documenting their
 
 ## [Switching and Toggling Layers](feature_advanced_keycodes.md#switching-and-toggling-layers)
 
-|Key            |Description                                                                       |
-|---------------|----------------------------------------------------------------------------------|
-|`LT(layer, kc)`|Turn on `layer` when held, `kc` when tapped                                       |
-|`TO(layer)`    |Turn on `layer` when pressed                                                      |
-|`MO(layer)`    |Momentarily turn on `layer` when pressed (requires `KC_TRNS` on destination layer)|
-|`DF(layer)`    |Set the base (default) layer                                                      |
-|`TG(layer)`    |Toggle `layer` on or off                                                          |
-|`TT(layer)`    |Tap toggle? idk FIXME                                                             |
+|Key             |Description                                                                       |
+|----------------|----------------------------------------------------------------------------------|
+|`LT(layer, kc)` |Turn on `layer` when held, `kc` when tapped                                       |
+|`TO(layer)`     |Turn on `layer` when pressed                                                      |
+|`MO(layer)`     |Momentarily turn on `layer` when pressed (requires `KC_TRNS` on destination layer)|
+|`DF(layer)`     |Set the base (default) layer                                                      |
+|`TG(layer)`     |Toggle `layer` on or off                                                          |
+|`TT(layer)`     |Normally acts like MO unless it's tapped multiple times, which toggles `layer` on |
+|`LM(layer, mod)`|Momentarily turn on `layer` (like MO) with `mod` active as well.                  |
 
 ## [One Shot Keys](quantum_keycodes.md#one-shot-keys)
 
index 8b09f93fced6815f6ca4107535022ed92f2f2665..9a412b66ade7f78280d58ac0aab295c9aeac15d2 100644 (file)
@@ -122,6 +122,11 @@ action_t action_for_key(uint8_t layer, keypos_t key)
         case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
             action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF);
             break;
+        case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
+            mod = keycode & 0xF;
+            action_layer = (keycode >> 4) & 0xF;
+            action.code = ACTION_LAYER_MODS(action_layer, mod);
+            break;
         case QK_MOD_TAP ... QK_MOD_TAP_MAX:
             mod = mod_config((keycode >> 0x8) & 0x1F);
             action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF);
index 4a5681c7e66a72a5734994ecd34363992f47aee7..8122bfe7397d0b38b1e3d3ab66f9b54289655dd4 100644 (file)
@@ -71,6 +71,8 @@ enum quantum_keycodes {
     QK_TAP_DANCE_MAX      = 0x57FF,
     QK_LAYER_TAP_TOGGLE   = 0x5800,
     QK_LAYER_TAP_TOGGLE_MAX = 0x58FF,
+    QK_LAYER_MOD          = 0x5900,
+    QK_LAYER_MOD_MAX      = 0x59FF,
 #ifdef STENO_ENABLE
     QK_STENO              = 0x5A00,
     QK_STENO_BOLT         = 0x5A30,
@@ -597,6 +599,9 @@ enum quantum_keycodes {
 // One-shot layer - 256 layer max
 #define OSL(layer) (layer | QK_ONE_SHOT_LAYER)
 
+// L-ayer M-od: Momentary switch layer with modifiers active - 16 layer max, left mods only
+#define LM(layer, mod) (QK_LAYER_MOD | (((layer) & 0xF) << 4) | ((mod) & 0xF))
+
 // One-shot mod
 #define OSM(mod) ((mod) | QK_ONE_SHOT_MOD)