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. 19
      docs/keyd.scdoc
  4. 50
      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.

@ -66,7 +66,7 @@ the form _[section_name]_ followed by a set of _bindings_. Lines beginning
with a hash are ignored.
Config files are stored in _/etc/keyd/_ and loaded upon initialization.
The reload command can be used to update the working set of config
The reload command can be used to update the working set of config
files (e.g sudo keyd reload).
A valid config file has the extension _.conf_ and *must* begin with an _[ids]_
@ -253,7 +253,7 @@ the full config actually looks something like this:
j = down
```
If multiple bindings for the same key are present, the most recent one takes precedence.
If multiple bindings for the same key are present, the most recent one takes precedence.
A layer heading may also appear multiple times, in which case the layer will
contain the sum of all bindings. Note that the layer type may not be reassigned.
@ -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,28 +709,44 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code,
size_t i;
struct cache_entry *ce = NULL;
for (i = 0; i < CACHE_SIZE; i++) {
uint8_t code = kbd->cache[i].code;
int layer = kbd->cache[i].layer;
int type = kbd->config.layers[layer].type;
if (code && layer == dl && type == LT_NORMAL && layer != 0) {
ce = &kbd->cache[i];
break;
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;
int type = kbd->config.layers[layer].type;
if (code && layer == dl && type == LT_NORMAL && layer != 0) {
ce = &kbd->cache[i];
break;
}
}
}
if (ce) {
ce->d.op = OP_LAYER;
ce->d.args[0].idx = idx;
if (ce) {
ce->d.op = OP_LAYER;
ce->d.args[0].idx = idx;
deactivate_layer(kbd, dl);
activate_layer(kbd, ce->code, idx);
deactivate_layer(kbd, dl);
activate_layer(kbd, ce->code, idx);
if (macro)
execute_macro(kbd, dl, macro);
if (macro)
execute_macro(kbd, dl, macro);
update_mods(kbd, -1, 0);
update_mods(kbd, -1, 0);
}
}
} else {
if (macro &&

@ -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