This commit is contained in:
Eslam Mohamed 2026-03-22 22:42:58 +00:00 committed by GitHub
commit 3bea272ae8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 10 deletions

View file

@ -183,7 +183,8 @@ bind=ALT,e,set_proportion,1.0
bind=ALT,x,switch_proportion_preset,
# switch layout
bind=SUPER,n,switch_layout
bind=SUPER,n,next_layout
bind=SUPER+SHIFT,n,previous_layout
# tag switch
bind=SUPER,Left,viewtoleft,0

View file

@ -1042,6 +1042,10 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
} else if (strcmp(func_name, "setlayout") == 0) {
func = setlayout;
(*arg).v = strdup(arg_value);
} else if (strcmp(func_name, "next_layout") == 0) {
func = next_layout;
} else if (strcmp(func_name, "previous_layout") == 0) {
func = previous_layout;
} else if (strcmp(func_name, "switch_layout") == 0) {
func = switch_layout;
} else if (strcmp(func_name, "togglefloating") == 0) {

View file

@ -26,6 +26,8 @@ int32_t spawn_on_empty(const Arg *arg);
int32_t setkeymode(const Arg *arg);
int32_t switch_keyboard_layout(const Arg *arg);
int32_t setlayout(const Arg *arg);
int32_t next_layout(const Arg *arg);
int32_t previous_layout(const Arg *arg);
int32_t switch_layout(const Arg *arg);
int32_t setmfact(const Arg *arg);
int32_t quit(const Arg *arg);

View file

@ -975,8 +975,8 @@ int32_t switch_keyboard_layout(const Arg *arg) {
return 0;
}
int32_t switch_layout(const Arg *arg) {
// Internal helper: direction > 0 means next, direction < 0 means previous
static int32_t _switch_layout_dir(int direction) {
int32_t jk, ji;
char *target_layout_name = NULL;
uint32_t len;
@ -986,7 +986,6 @@ int32_t switch_layout(const Arg *arg) {
if (config.circle_layout_count != 0) {
for (jk = 0; jk < config.circle_layout_count; jk++) {
len = MAX(
strlen(config.circle_layout[jk]),
strlen(selmon->pertag->ltidxs[selmon->pertag->curtag]->name));
@ -994,9 +993,19 @@ int32_t switch_layout(const Arg *arg) {
if (strncmp(config.circle_layout[jk],
selmon->pertag->ltidxs[selmon->pertag->curtag]->name,
len) == 0) {
target_layout_name = jk == config.circle_layout_count - 1
? config.circle_layout[0]
: config.circle_layout[jk + 1];
if (direction > 0) {
// next: wrap forward
target_layout_name = (jk == config.circle_layout_count - 1)
? config.circle_layout[0]
: config.circle_layout[jk + 1];
} else {
// previous: wrap backward
target_layout_name =
(jk == 0)
? config
.circle_layout[config.circle_layout_count - 1]
: config.circle_layout[jk - 1];
}
break;
}
}
@ -1009,7 +1018,6 @@ int32_t switch_layout(const Arg *arg) {
len = MAX(strlen(layouts[ji].name), strlen(target_layout_name));
if (strncmp(layouts[ji].name, target_layout_name, len) == 0) {
selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[ji];
break;
}
}
@ -1019,11 +1027,21 @@ int32_t switch_layout(const Arg *arg) {
return 0;
}
// Fallback: iterate through global layouts[]
for (jk = 0; jk < LENGTH(layouts); jk++) {
if (strcmp(layouts[jk].name,
selmon->pertag->ltidxs[selmon->pertag->curtag]->name) == 0) {
selmon->pertag->ltidxs[selmon->pertag->curtag] =
jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1];
if (direction > 0) {
// next: wrap forward
selmon->pertag->ltidxs[selmon->pertag->curtag] =
(jk == LENGTH(layouts) - 1) ? &layouts[0]
: &layouts[jk + 1];
} else {
// previous: wrap backward
selmon->pertag->ltidxs[selmon->pertag->curtag] =
(jk == 0) ? &layouts[LENGTH(layouts) - 1]
: &layouts[jk - 1];
}
clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false, false);
printstatus();
@ -1033,6 +1051,12 @@ int32_t switch_layout(const Arg *arg) {
return 0;
}
int32_t next_layout(const Arg *arg) { return _switch_layout_dir(1); }
int32_t previous_layout(const Arg *arg) { return _switch_layout_dir(-1); }
int32_t switch_layout(const Arg *arg) { return next_layout(arg); }
int32_t switch_proportion_preset(const Arg *arg) {
float target_proportion = 0;
if (!selmon)