From d98379ff4c05e155b8257a6afa095db563204649 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Thu, 19 Feb 2026 09:59:58 +0800 Subject: [PATCH] feat: support index arg in switch_keyboard_layout --- src/config/parse_config.h | 1 + src/dispatch/bind_define.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 64afd88..830d22b 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -1017,6 +1017,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, (*arg).v = strdup(arg_value); } else if (strcmp(func_name, "switch_keyboard_layout") == 0) { func = switch_keyboard_layout; + (*arg).i = CLAMP_INT(atoi(arg_value), 0, 100); } else if (strcmp(func_name, "setlayout") == 0) { func = setlayout; (*arg).v = strdup(arg_value); diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 0bfab15..7923ef6 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -902,6 +902,10 @@ int32_t switch_keyboard_layout(const Arg *arg) { } xkb_layout_index_t next = (current + 1) % num_layouts; + if (arg->i > 0 && arg->i <= num_layouts) { + next = arg->i - 1; + } + // 6. 应用新 keymap uint32_t depressed = keyboard->modifiers.depressed; uint32_t latched = keyboard->modifiers.latched;