From a10b504cda0660c261f4437f35f4e4128b5afee4 Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Fri, 15 Jul 2022 21:44:53 +0200 Subject: [PATCH] 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) --- keyboard.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/keyboard.c b/keyboard.c index 5a1d708..33f0a73 100644 --- a/keyboard.c +++ b/keyboard.c @@ -245,8 +245,8 @@ 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)) { + if ((kb->compose == 1) && (k->type != Compose) && (k->type != Mod) && + (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: