Skip to content

Commit 68075c0

Browse files
committed
feat: support index arg in switch_keyboard_layout
1 parent 23d7b11 commit 68075c0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/config/parse_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
10171017
(*arg).v = strdup(arg_value);
10181018
} else if (strcmp(func_name, "switch_keyboard_layout") == 0) {
10191019
func = switch_keyboard_layout;
1020+
(*arg).i = CLAMP_INT(atoi(arg_value), 0, 100);
10201021
} else if (strcmp(func_name, "setlayout") == 0) {
10211022
func = setlayout;
10221023
(*arg).v = strdup(arg_value);

src/dispatch/bind_define.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,13 @@ int32_t switch_keyboard_layout(const Arg *arg) {
900900
wlr_log(WLR_INFO, "Only one layout available");
901901
return 0;
902902
}
903-
xkb_layout_index_t next = (current + 1) % num_layouts;
903+
904+
xkb_layout_index_t next = 0;
905+
if (arg->i > 0 && arg->i <= num_layouts) {
906+
next = arg->i - 1;
907+
} else {
908+
next = (current + 1) % num_layouts;
909+
}
904910

905911
// 6. 应用新 keymap
906912
uint32_t depressed = keyboard->modifiers.depressed;

0 commit comments

Comments
 (0)