allow modifiers with next layer button to switch to first/previous layer

- shift (or capslock) switch to the previous layer in the defined order
- control, alt or compose resets the view to the first layer

related fix: compose key resets on layer switch (doesn't stick now)
This commit is contained in:
Maarten van Gompel 2022-07-15 21:44:53 +02:00
parent 14f0f0824b
commit a10b504cda

View File

@ -246,7 +246,7 @@ kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
void
kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
if ((kb->compose == 1) && (k->type != Compose) && (k->type != Mod) &&
(k->layout)) {
(k->type != NextLayer) && (k->layout)) {
kb->compose++;
if (kb->debug)
fprintf(stderr, "showing compose %d\n", kb->compose);
@ -308,8 +308,30 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
}
break;
case NextLayer:
// switch to the next layout in the layer sequence
kb->layer_index++;
if ((kb->mods & Ctrl) || (kb->mods & Alt) || (kb->mods & AltGr) || ((bool)kb->compose)) {
// with modifiers: switch to the first layer
kb->layer_index = 0;
kb->mods = 0;
} else if ((kb->mods & Shift) || (kb->mods & CapsLock)) {
// with modifiers: switch to the previous layout in the layer sequence
if (kb->layer_index > 0) {
kb->layer_index--;
} else {
size_t layercount = 0;
for (size_t i = 0; layercount == 0; i++) {
if (kb->landscape) {
if (kb->landscape_layers[i] == NumLayouts) layercount = i;
} else {
if (kb->layers[i] == NumLayouts) layercount = i;
}
}
kb->layer_index = layercount - 1;
}
kb->mods = 0;
} else {
// normal behaviour: switch to the next layout in the layer sequence
kb->layer_index++;
}
enum layout_id layer;
if (kb->landscape) {
layer = kb->landscape_layers[kb->layer_index];
@ -324,6 +346,10 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
layer = kb->layers[kb->layer_index];
}
}
if ((bool)kb->compose) {
kb->compose = 0;
kbd_draw_key(kb, k, Unpress);
}
kbd_switch_layout(kb, &kb->layouts[layer]);
break;
case BackLayer: