diff --git a/src/keyboard.c b/src/keyboard.c index 2a0264a..564796c 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -200,6 +200,7 @@ void kbd_reset(struct keyboard *kbd) static void lookup_descriptor(struct keyboard *kbd, uint8_t code, uint8_t *layer_mods, struct descriptor *d) { + size_t max; size_t i; uint8_t active[MAX_LAYERS]; struct layer_table *lt = &kbd->layer_table; @@ -223,6 +224,7 @@ static void lookup_descriptor(struct keyboard *kbd, uint8_t code, uint8_t *layer } } + max = 0; /* Scan for any composite matches (which take precedence). */ for (i = 0; i < lt->nr; i++) { struct layer *layer = <->layers[i]; @@ -239,9 +241,11 @@ static void lookup_descriptor(struct keyboard *kbd, uint8_t code, uint8_t *layer match = 0; } - if (match && layer->keymap[code].op) { + if (match && layer->keymap[code].op && (layer->nr_layers > max)) { *layer_mods = mods; *d = layer->keymap[code]; + + max = layer->nr_layers; } } } diff --git a/t/composite.t b/t/composite.t new file mode 100644 index 0000000..952c177 --- /dev/null +++ b/t/composite.t @@ -0,0 +1,21 @@ +control down +alt down +h down +h up +control up +alt up + +control down +alt down +alt up +control up +shift down +h down +h up +shift up +control down +alt down +control up +control down +alt up +control up diff --git a/t/composite2.t b/t/composite2.t new file mode 100644 index 0000000..6edc1d8 --- /dev/null +++ b/t/composite2.t @@ -0,0 +1,25 @@ +control down +shift down +alt down +h down +h up +control up +shift up +alt up + +control down +shift down +alt down +alt up +control up +shift up +left down +left up +control down +shift down +alt down +control up +shift up +control down +alt up +control up diff --git a/t/test.conf b/t/test.conf index 321c043..83d730a 100644 --- a/t/test.conf +++ b/t/test.conf @@ -73,6 +73,14 @@ s = swap(swapped1) 1 = swap(tablayer, tab) 2 = swap(tablayer2, tab) +[myalt+control+shift] + +h = left + +[myalt+control] + +h = H + [swapped1] a = b