feat: support index arg in switch_keyboard_layout

This commit is contained in:
DreamMaoMao 2026-02-19 09:59:58 +08:00
parent 23d7b11e27
commit 68075c0044
2 changed files with 8 additions and 1 deletions

View file

@ -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);

View file

@ -900,7 +900,13 @@ int32_t switch_keyboard_layout(const Arg *arg) {
wlr_log(WLR_INFO, "Only one layout available");
return 0;
}
xkb_layout_index_t next = (current + 1) % num_layouts;
xkb_layout_index_t next = 0;
if (arg->i > 0 && arg->i <= num_layouts) {
next = arg->i - 1;
} else {
next = (current + 1) % num_layouts;
}
// 6. 应用新 keymap
uint32_t depressed = keyboard->modifiers.depressed;