feat: support scroll maximize and fullscreen window

This commit is contained in:
DreamMaoMao
2025-11-15 00:08:57 +08:00
parent fce47b37d9
commit cdcc64ab5f
7 changed files with 228 additions and 90 deletions

View File

@@ -80,8 +80,12 @@ int defaultgaps(const Arg *arg) {
int exchange_client(const Arg *arg) {
Client *c = selmon->sel;
if (!c || c->isfloating || c->isfullscreen || c->ismaximizescreen)
if (!c || c->isfloating)
return 0;
if ((c->isfullscreen || c->ismaximizescreen) && !is_scroller_layout(c->mon))
return 0;
exchange_two_client(c, direction_select(arg));
return 0;
}
@@ -497,7 +501,7 @@ int setlayout(const Arg *arg) {
for (jk = 0; jk < LENGTH(layouts); jk++) {
if (strcmp(layouts[jk].name, arg->v) == 0) {
selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk];
clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false);
printstatus();
return 0;
@@ -901,7 +905,7 @@ int switch_layout(const Arg *arg) {
break;
}
}
clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false);
printstatus();
return 0;
@@ -912,6 +916,7 @@ int switch_layout(const Arg *arg) {
selmon->pertag->ltidxs[selmon->pertag->curtag]->name) == 0) {
selmon->pertag->ltidxs[selmon->pertag->curtag] =
jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1];
clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false);
printstatus();
return 0;

View File

@@ -258,6 +258,7 @@ void dwl_ipc_output_set_layout(struct wl_client *client,
index = 0;
monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index];
clear_fullscreen_and_maximized_state(monitor);
arrange(monitor, false);
printstatus();
}

View File

@@ -142,7 +142,7 @@ Client *center_tiled_select(Monitor *m) {
return target_c;
}
Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
bool align) {
bool ignore_align) {
Client *c = NULL;
Client **tempClients = NULL; // 初始化为 NULL
int last = -1;
@@ -185,6 +185,7 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
switch (arg->i) {
case UP:
if (!ignore_align) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.y < sel_y &&
tempClients[_i]->geom.x == sel_x &&
@@ -199,7 +200,8 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
}
}
}
if (!tempFocusClients && !align) {
}
if (!tempFocusClients) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.y < sel_y) {
int dis_x = tempClients[_i]->geom.x - sel_x;
@@ -215,6 +217,7 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
}
break;
case DOWN:
if (!ignore_align) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.y > sel_y &&
tempClients[_i]->geom.x == sel_x &&
@@ -229,7 +232,8 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
}
}
}
if (!tempFocusClients && !align) {
}
if (!tempFocusClients) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.y > sel_y) {
int dis_x = tempClients[_i]->geom.x - sel_x;
@@ -245,6 +249,7 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
}
break;
case LEFT:
if (!ignore_align) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.x < sel_x &&
tempClients[_i]->geom.y == sel_y &&
@@ -259,7 +264,8 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
}
}
}
if (!tempFocusClients && !align) {
}
if (!tempFocusClients) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.x < sel_x) {
int dis_x = tempClients[_i]->geom.x - sel_x;
@@ -275,6 +281,7 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
}
break;
case RIGHT:
if (!ignore_align) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.x > sel_x &&
tempClients[_i]->geom.y == sel_y &&
@@ -289,7 +296,8 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating,
}
}
}
if (!tempFocusClients && !align) {
}
if (!tempFocusClients) {
for (int _i = 0; _i <= last; _i++) {
if (tempClients[_i]->geom.x > sel_x) {
int dis_x = tempClients[_i]->geom.x - sel_x;
@@ -317,12 +325,13 @@ Client *direction_select(const Arg *arg) {
if (!tc)
return NULL;
if (tc && (tc->isfullscreen || tc->ismaximizescreen)) {
// 不支持全屏窗口的焦点切换
if (tc && (tc->isfullscreen || tc->ismaximizescreen) &&
(!is_scroller_layout(selmon) || tc->isfloating)) {
return NULL;
}
return find_client_by_direction(tc, arg, true, false);
return find_client_by_direction(
tc, arg, true, is_scroller_layout(selmon) && !selmon->isoverview);
}
/* We probably should change the name of this, it sounds like

View File

@@ -599,6 +599,7 @@ arrange(Monitor *m, bool want_animation) {
return;
m->visible_clients = 0;
m->visible_tiling_clients = 0;
m->visible_scroll_tiling_clients = 0;
m->has_visible_fullscreen_client = false;
wl_list_for_each(c, &clients, link) {
@@ -619,6 +620,10 @@ arrange(Monitor *m, bool want_animation) {
if (ISTILED(c)) {
m->visible_tiling_clients++;
}
if (ISSCROLLTILED(c)) {
m->visible_scroll_tiling_clients++;
}
}
}

View File

@@ -189,6 +189,38 @@ void deck(Monitor *m) {
}
}
void horizontal_scroll_adjust_fullandmax(Client *c,
struct wlr_box *target_geom) {
Monitor *m = c->mon;
unsigned int cur_gappih = enablegaps ? m->gappih : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
cur_gappih =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappih;
cur_gappoh =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappoh;
cur_gappov =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappov;
if (c->isfullscreen) {
target_geom->height = m->m.height;
target_geom->width = m->m.width;
target_geom->y = m->m.y;
return;
}
if (c->ismaximizescreen) {
target_geom->height = m->w.height - 2 * cur_gappov;
target_geom->width = m->w.width - 2 * cur_gappoh;
target_geom->y = m->w.y + cur_gappov;
return;
}
target_geom->height = m->w.height - 2 * cur_gappov;
target_geom->y = m->w.y + (m->w.height - target_geom->height) / 2;
}
// 滚动布局
void scroller(Monitor *m) {
unsigned int i, n, j;
@@ -203,14 +235,17 @@ void scroller(Monitor *m) {
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
cur_gappih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappih;
cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov;
cur_gappih =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappih;
cur_gappoh =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappoh;
cur_gappov =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappov;
unsigned int max_client_width =
m->w.width - 2 * scroller_structs - cur_gappih;
n = m->visible_tiling_clients;
n = m->visible_scroll_tiling_clients;
if (n == 0) {
return; // 没有需要处理的客户端,直接返回
@@ -226,13 +261,14 @@ void scroller(Monitor *m) {
// 第二次遍历,填充 tempClients
j = 0;
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, m) && ISTILED(c)) {
if (VISIBLEON(c, m) && ISSCROLLTILED(c)) {
tempClients[j] = c;
j++;
}
}
if (n == 1 && !scroller_ignore_proportion_single) {
if (n == 1 && !scroller_ignore_proportion_single &&
!tempClients[0]->isfullscreen && !tempClients[0]->ismaximizescreen) {
c = tempClients[0];
single_proportion = c->scroller_proportion_single > 0.0f
@@ -248,11 +284,10 @@ void scroller(Monitor *m) {
return;
}
if (m->sel && !client_is_unmanaged(m->sel) && !m->sel->isfloating &&
!m->sel->ismaximizescreen && !m->sel->isfullscreen) {
if (m->sel && !client_is_unmanaged(m->sel) && !m->sel->isfloating) {
root_client = m->sel;
} else if (m->prevsel && ISTILED(m->prevsel) && VISIBLEON(m->prevsel, m) &&
!client_is_unmanaged(m->prevsel)) {
} else if (m->prevsel && ISSCROLLTILED(m->prevsel) &&
VISIBLEON(m->prevsel, m) && !client_is_unmanaged(m->prevsel)) {
root_client = m->prevsel;
} else {
root_client = center_tiled_select(m);
@@ -289,11 +324,18 @@ void scroller(Monitor *m) {
target_geom.height = m->w.height - 2 * cur_gappov;
target_geom.width = max_client_width * c->scroller_proportion;
target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2;
if (need_scroller) {
horizontal_scroll_adjust_fullandmax(tempClients[focus_client_index],
&target_geom);
if (tempClients[focus_client_index]->isfullscreen) {
target_geom.x = m->m.x;
resize(tempClients[focus_client_index], target_geom, 0);
} else if (tempClients[focus_client_index]->ismaximizescreen) {
target_geom.x = m->w.x + cur_gappoh;
resize(tempClients[focus_client_index], target_geom, 0);
} else if (need_scroller) {
if (scroller_focus_center ||
((!m->prevsel ||
(ISTILED(m->prevsel) &&
(ISSCROLLTILED(m->prevsel) &&
(m->prevsel->scroller_proportion * max_client_width) +
(root_client->scroller_proportion * max_client_width) >
m->w.width - 2 * scroller_structs - cur_gappih)) &&
@@ -316,14 +358,17 @@ void scroller(Monitor *m) {
for (i = 1; i <= focus_client_index; i++) {
c = tempClients[focus_client_index - i];
target_geom.width = max_client_width * c->scroller_proportion;
horizontal_scroll_adjust_fullandmax(c, &target_geom);
target_geom.x = tempClients[focus_client_index - i + 1]->geom.x -
cur_gappih - target_geom.width;
resize(c, target_geom, 0);
}
for (i = 1; i < n - focus_client_index; i++) {
c = tempClients[focus_client_index + i];
target_geom.width = max_client_width * c->scroller_proportion;
horizontal_scroll_adjust_fullandmax(c, &target_geom);
target_geom.x = tempClients[focus_client_index + i - 1]->geom.x +
cur_gappih +
tempClients[focus_client_index + i - 1]->geom.width;

View File

@@ -155,6 +155,38 @@ void vertical_deck(Monitor *m) {
}
}
void vertical_scroll_adjust_fullandmax(Client *c, struct wlr_box *target_geom) {
Monitor *m = c->mon;
unsigned int cur_gappiv = enablegaps ? m->gappiv : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
cur_gappiv =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappiv;
cur_gappov =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappov;
cur_gappoh =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappoh;
if (c->isfullscreen) {
target_geom->width = m->m.width;
target_geom->height = m->m.height;
target_geom->x = m->m.x;
return;
}
if (c->ismaximizescreen) {
target_geom->width = m->w.width - 2 * cur_gappoh;
target_geom->height = m->w.height - 2 * cur_gappov;
target_geom->x = m->w.x + cur_gappoh;
return;
}
target_geom->width = m->w.width - 2 * cur_gappoh;
target_geom->x = m->w.x + (m->w.width - target_geom->width) / 2;
}
// 竖屏滚动布局
void vertical_scroller(Monitor *m) {
unsigned int i, n, j;
float single_proportion = 1.0;
@@ -168,14 +200,17 @@ void vertical_scroller(Monitor *m) {
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv;
cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov;
cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh;
cur_gappiv =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappiv;
cur_gappov =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappov;
cur_gappoh =
smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappoh;
unsigned int max_client_height =
m->w.height - 2 * scroller_structs - cur_gappiv;
n = m->visible_tiling_clients;
n = m->visible_scroll_tiling_clients;
if (n == 0) {
return;
@@ -188,13 +223,14 @@ void vertical_scroller(Monitor *m) {
j = 0;
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, m) && ISTILED(c)) {
if (VISIBLEON(c, m) && ISSCROLLTILED(c)) {
tempClients[j] = c;
j++;
}
}
if (n == 1 && !scroller_ignore_proportion_single) {
if (n == 1 && !scroller_ignore_proportion_single &&
!tempClients[0]->isfullscreen && !tempClients[0]->ismaximizescreen) {
c = tempClients[0];
single_proportion = c->scroller_proportion_single > 0.0f
@@ -203,18 +239,17 @@ void vertical_scroller(Monitor *m) {
target_geom.width = m->w.width - 2 * cur_gappoh;
target_geom.height = (m->w.height - 2 * cur_gappov) * single_proportion;
target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2;
target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2;
target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2;
resize(c, target_geom, 0);
free(tempClients);
return;
}
if (m->sel && !client_is_unmanaged(m->sel) && !m->sel->isfloating &&
!m->sel->ismaximizescreen && !m->sel->isfullscreen) {
if (m->sel && !client_is_unmanaged(m->sel) && !m->sel->isfloating) {
root_client = m->sel;
} else if (m->prevsel && ISTILED(m->prevsel) && VISIBLEON(m->prevsel, m) &&
!client_is_unmanaged(m->prevsel)) {
} else if (m->prevsel && ISSCROLLTILED(m->prevsel) &&
VISIBLEON(m->prevsel, m) && !client_is_unmanaged(m->prevsel)) {
root_client = m->prevsel;
} else {
root_client = center_tiled_select(m);
@@ -251,11 +286,19 @@ void vertical_scroller(Monitor *m) {
target_geom.width = m->w.width - 2 * cur_gappoh;
target_geom.height = max_client_height * c->scroller_proportion;
target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2;
vertical_scroll_adjust_fullandmax(tempClients[focus_client_index],
&target_geom);
if (need_scroller) {
if (tempClients[focus_client_index]->isfullscreen) {
target_geom.y = m->m.y;
resize(tempClients[focus_client_index], target_geom, 0);
} else if (tempClients[focus_client_index]->ismaximizescreen) {
target_geom.y = m->w.y + cur_gappov;
resize(tempClients[focus_client_index], target_geom, 0);
} else if (need_scroller) {
if (scroller_focus_center ||
((!m->prevsel ||
(ISTILED(m->prevsel) &&
(ISSCROLLTILED(m->prevsel) &&
(m->prevsel->scroller_proportion * max_client_height) +
(root_client->scroller_proportion * max_client_height) >
m->w.height - 2 * scroller_structs - cur_gappiv)) &&
@@ -278,14 +321,17 @@ void vertical_scroller(Monitor *m) {
for (i = 1; i <= focus_client_index; i++) {
c = tempClients[focus_client_index - i];
target_geom.height = max_client_height * c->scroller_proportion;
vertical_scroll_adjust_fullandmax(c, &target_geom);
target_geom.y = tempClients[focus_client_index - i + 1]->geom.y -
cur_gappiv - target_geom.height;
resize(c, target_geom, 0);
}
for (i = 1; i < n - focus_client_index; i++) {
c = tempClients[focus_client_index + i];
target_geom.height = max_client_height * c->scroller_proportion;
vertical_scroll_adjust_fullandmax(c, &target_geom);
target_geom.y = tempClients[focus_client_index + i - 1]->geom.y +
cur_gappiv +
tempClients[focus_client_index + i - 1]->geom.height;

View File

@@ -104,6 +104,9 @@
#define ISTILED(A) \
(A && !(A)->isfloating && !(A)->isminied && !(A)->iskilling && \
!(A)->ismaximizescreen && !(A)->isfullscreen && !(A)->isunglobal)
#define ISSCROLLTILED(A) \
(A && !(A)->isfloating && !(A)->isminied && !(A)->iskilling && \
!(A)->isunglobal)
#define VISIBLEON(C, M) \
((C) && (M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
@@ -479,6 +482,7 @@ struct Monitor {
int asleep;
unsigned int visible_clients;
unsigned int visible_tiling_clients;
unsigned int visible_scroll_tiling_clients;
bool has_visible_fullscreen_client;
struct wlr_scene_optimized_blur *blur;
char last_surface_ws_name[256];
@@ -733,6 +737,7 @@ static void refresh_monitors_workspaces_status(Monitor *m);
static void init_client_properties(Client *c);
static float *get_border_color(Client *c);
static void request_fresh_all_monitors(void);
static void clear_fullscreen_and_maximized_state(Monitor *m);
#include "data/static_keymap.h"
#include "dispatch/bind_declare.h"
@@ -930,8 +935,26 @@ void applybounds(Client *c, struct wlr_box *bbox) {
c->geom.y = bbox->y;
}
void clear_fullscreen_and_maximized_state(Monitor *m) {
Client *fc = NULL;
wl_list_for_each(fc, &clients, link) {
if (fc && VISIBLEON(fc, m) && ISFULLSCREEN(fc)) {
clear_fullscreen_flag(fc);
}
}
}
/*清除全屏标志,还原全屏时清0的border*/
void clear_fullscreen_flag(Client *c) {
if ((c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id ==
SCROLLER ||
c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id ==
VERTICAL_SCROLLER) &&
!c->isfloating) {
return;
}
if (c->isfullscreen) {
setfullscreen(c, false);
}
@@ -3149,7 +3172,6 @@ void focusclient(Client *c, int lift) {
if (c && selmon->prevsel &&
(selmon->prevsel->tags & selmon->tagset[selmon->seltags]) &&
(c->tags & selmon->tagset[selmon->seltags]) && !c->isfloating &&
!c->isfullscreen && !c->ismaximizescreen &&
is_scroller_layout(selmon)) {
arrange(selmon, false);
}
@@ -3702,9 +3724,9 @@ mapnotify(struct wl_listener *listener, void *data) {
// tile at the top
wl_list_insert(&clients, &c->link); // 新窗口是master,头部入栈
else if (selmon && is_scroller_layout(selmon) &&
selmon->visible_tiling_clients > 0) {
selmon->visible_scroll_tiling_clients > 0) {
if (selmon->sel && ISTILED(selmon->sel) &&
if (selmon->sel && ISSCROLLTILED(selmon->sel) &&
VISIBLEON(selmon->sel, selmon)) {
at_client = selmon->sel;
} else {
@@ -4536,6 +4558,7 @@ void setmaximizescreen(Client *c, int maximizescreen) {
maximizescreen_box.width = c->mon->w.width - 2 * gappoh;
maximizescreen_box.height = c->mon->w.height - 2 * gappov;
wlr_scene_node_raise_to_top(&c->scene->node); // 将视图提升到顶层
if (!is_scroller_layout(c->mon) || c->isfloating)
resize(c, maximizescreen_box, 0);
c->ismaximizescreen = 1;
} else {
@@ -4545,9 +4568,8 @@ void setmaximizescreen(Client *c, int maximizescreen) {
setfloating(c, 1);
}
wlr_scene_node_reparent(&c->scene->node, layers[maximizescreen ? LyrTile
: c->isfloating ? LyrTop
: LyrTile]);
wlr_scene_node_reparent(&c->scene->node,
layers[c->isfloating ? LyrTop : LyrTile]);
if (!c->ismaximizescreen) {
set_size_per(c->mon, c);
}
@@ -4593,6 +4615,7 @@ void setfullscreen(Client *c, int fullscreen) // 用自定义全屏代理自带
c->bw = 0;
wlr_scene_node_raise_to_top(&c->scene->node); // 将视图提升到顶层
if (!is_scroller_layout(c->mon) || c->isfloating)
resize(c, c->mon->m, 1);
c->isfullscreen = 1;
} else {
@@ -5168,7 +5191,11 @@ unsigned int want_restore_fullscreen(Client *target_client) {
Client *c = NULL;
wl_list_for_each(c, &clients, link) {
if (c && c != target_client && c->tags == target_client->tags &&
c == selmon->sel) {
c == selmon->sel &&
c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id !=
SCROLLER &&
c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id !=
VERTICAL_SCROLLER) {
return 0;
}
}