Closed mmikeww closed 3 months ago
Sure thing, happy to clarify. The use case that Layer Lock has in mind is a layer that:
You usually want to activate "momentarily" by holding a MO
layer switch (or other switch that is held like an LT
, OSL
, or LM
),
Yet sometimes you want to stay in that layer without having to hold a layer switch continuously.
Such situations come up especially on navigation layers and numpad layers on smaller keyboards. A user might want both #1 and #2 with a navigation layer for instance, between brief or extended uses or the arrow keys, or on a numpad layer for typing a single digit vs. a typing something long like a date or telephone number.
If only #2 were needed, then certainly, that could be done with simply a TO
(or TG
) switch.
To do both #1 and #2, it's possible to have both an MO
and a TO
on the base layer. This has downsides, however:
TO
and get stuck in a situation where it is impossible to switch layers without rebooting the keyboard.To be clear, I'm not saying TO
is "wrong" to use. If it works for you, then use it! FWIW, I use TO
pretty heavily in my own keymap. But yes, there are reasons why users might not be entirely happy with TO
and want something else.
Layer Lock is an alternative without the downsides listed above: you can use one MO
(or LT
, etc.) on the base layer and place the Layer Lock key on the destination layer. The layer stays locked until the Layer Lock key or MO
is pressed again. By design, the lock is easily "broken" to avoid layers from getting stuck.
No no, i'm saying, we are on base layer 0. We then go to layer 1 by holding the key to MO(1)
. And then while on layer 1, we have another key or same key to use TO(1)
to stay locked on layer 1. Is that not possible?
Aha! Well, that's different. There is an elegance to what you describe and it could have been a nice way for MO
and TO
to work together, but no, I'm afraid that QMK doesn't work that way.
QMK's layer switches work in terms of setting or clearing bits in the current layer state:
TO(k)
sets the k
th bit and clears all other bits on press (here in QMK core as an "ON_PRESS", "OP_BIT_SET" action).
MO(k)
sets the k
th bit on press, and clears the k
th bit on release (here as an "OP_ON_OFF" action).
There is some further description about this in the Keymap and Layers documentation. It's all pretty low level and inherited from the older TMK firmware that QMK is based on.
Using MO
and TO
as you describe behaves in the following way:
MO(1)
is pressed. The bit for layer 1 is set, activating the layer.TO(1)
is released. This is a no-op.MO(1)
is released. The bit for layer 1 is cleared, deactivating the layer (!). All bits are now clear, and only layer 0 is active, rather than staying on layer 1.To be clear, this is working as intended, not a QMK bug.
ahhh thank you very much for the technical explanation. exactly what i was looking for. much appreciated
i'm reading the layer lock blog post, but when Layer2 is being held down, why couldn't the layer lock key simply be a built in
TO()
action to lock the same layer we're on?