From f295f9085beaff4ae68cb8a57e26ff011b5a8028 Mon Sep 17 00:00:00 2001 From: carpetoctopus Date: Thu, 30 Apr 2026 17:23:32 +0200 Subject: [PATCH] fix multikey modifier for floating_modifier Allows using key combinations as the modifier key used for floating_modifier. Example: floating_modifier Shift+Alt normal will work, whereas before it would throw an "Invalid modifier" error. --- sway/input/keyboard.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index d18237375..9ca839720 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -39,14 +39,28 @@ static struct modifier_key { }; uint32_t get_modifier_mask_by_name(const char *name) { - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if (strcasecmp(modifiers[i].name, name) == 0) { - return modifiers[i].mod; - } - } + uint32_t mod = 0; + const char *p = name; - return 0; + while (*p) { + const char *start = p; + const char *end = p; + + while (*end && *end != '+') end++; + + size_t len = (size_t)(end - start); + + for (int i = 0; i < (int)(sizeof(modifiers) / sizeof(modifiers[0])); ++i) { + if (strlen(modifiers[i].name) == len && + strncasecmp(modifiers[i].name, start, len) == 0 + ) { + mod |= modifiers[i].mod; + break; + } + } + p = (*end == '+') ? end + 1 : end; + } + return mod; } const char *get_modifier_name_by_mask(uint32_t modifier) {