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;