swap: Add support for swapping toggled layers (#410)

Sometimes it is desirable to transition directly from one
toggled layer to another.

This commit extends swap() to work not just with keys bound to layer(),
but also toggle() and oneshot(). For swaps which occur one layer
deep (the anticipated use case), this is rougly equivalent of a
clear() followed by toggle(<target>).
master
Raheman Vaiya 3 years ago
parent 685bbec982
commit 5166081c69
  1. BIN
      data/keyd-application-mapper.1.gz
  2. BIN
      data/keyd.1.gz
  3. 15
      docs/keyd.scdoc
  4. 16
      src/keyboard.c
  5. 10
      t/swap-oneshot.t
  6. 15
      t/swap-toggle.t
  7. 7
      t/test.conf

Binary file not shown.

Binary file not shown.

@ -620,9 +620,11 @@ A key may optionally be bound to an _action_ which accepts zero or more argument
If tapped, activate the supplied layer for the duration of the next keypress.
*swap(<layer>)*
Swap the currently active layer with the supplied one. The
supplied layer is active for the duration of the depression of the
current layer's activation key.
Swap the currently active layer with the supplied one. If the current
layer is toggled, it is deactivated and the supplied layer is toggled
instead. Otherwise, the active layer is deactivated and the supplied
layer remains active for the duration of the depression of the
activating key.
```
[control]
@ -635,6 +637,13 @@ A key may optionally be bound to an _action_ which accepts zero or more argument
b = S-insert
```
NOTE:
You probably don't need to use this unless you are trying to do something quite
involved. Think hard about whether or not what you are trying to achieve
can be done by other means, as it is easy to end up in states which
are impossible to exit.
*setlayout(<layout>)*
Set the current layout.

@ -709,6 +709,21 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code,
size_t i;
struct cache_entry *ce = NULL;
if (kbd->layer_state[dl].toggled) {
deactivate_layer(kbd, dl);
kbd->layer_state[dl].toggled = 0;
activate_layer(kbd, 0, idx);
kbd->layer_state[idx].toggled = 1;
update_mods(kbd, -1, 0);
} else if (kbd->layer_state[dl].oneshot) {
deactivate_layer(kbd, dl);
kbd->layer_state[dl].oneshot = 0;
activate_layer(kbd, 0, idx);
kbd->layer_state[idx].oneshot = 1;
update_mods(kbd, -1, 0);
} else {
for (i = 0; i < CACHE_SIZE; i++) {
uint8_t code = kbd->cache[i].code;
int layer = kbd->cache[i].layer;
@ -732,6 +747,7 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code,
update_mods(kbd, -1, 0);
}
}
} else {
if (macro &&
macro->sz == 1 &&

@ -0,0 +1,10 @@
1 down
2 down
300ms
1 up
2 up
a down
a up
b down
b up

@ -0,0 +1,15 @@
4 down
4 up
s down
s up
s down
s up
x down
x up
s down
s up
a down
a up
shift down
shift up

@ -31,6 +31,7 @@ p = layerm(shift, macro(on))
7 = overload(meta, oneshot(control))
8 = timeout(overload(control, a), 1, b)
9 = M-C-S-x
1+2 = oneshot(test)
l = layer(test)
m = macro(C-h one)
c = oneshot(control)
@ -69,11 +70,17 @@ b = macro(leftcontrol+n)
c = macro(leftcontrol n)
x = overload(meta, swap(shift))
[test2]
s = a
x = toggle(test2)
[test]
o = oneshot(o)
a = b
b = toggle(test)
s = swap(test2)
c = clear()
[o:C]

Loading…
Cancel
Save