From b5754f237f7d34b35b16085587f5bd700f021d27 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 3a08466..e50f3b5 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -997,6 +997,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 b7c464c..e9f1584 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -903,6 +903,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;