From 43881077bf0ba1546538cc736cbcf7213422c4e2 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Fri, 10 Oct 2025 07:01:23 +0800 Subject: [PATCH] opt: first version that need to check layout switch --- src/mango.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/src/mango.c b/src/mango.c index aada3a9..104a5ba 100644 --- a/src/mango.c +++ b/src/mango.c @@ -3874,7 +3874,24 @@ void motionabsolute(struct wl_listener *listener, void *data) { } void resize_tile_client(Client *grabc) { - Client *tc; + Client *tc = NULL; + float delta_x, delta_y; + Client *next = NULL; + Client *prev = NULL; + // 查找 grabc 在链表中的前一个和后一个客户端 + wl_list_for_each(tc, &clients, link) { + if (tc == grabc) { + // 找到当前客户端,下一个节点就是 next + if (tc->link.next != &clients) { + next = wl_container_of(tc->link.next, next, link); + } + // 前一个节点就是 prev + if (tc->link.prev != &clients) { + prev = wl_container_of(tc->link.prev, prev, link); + } + break; + } + } if (!start_drag_window) { begin_cursorx = cursor->x; @@ -3891,18 +3908,52 @@ void resize_tile_client(Client *grabc) { grabc->begin_geom = grabc->geom; } else { // 计算相对于屏幕尺寸的比例变化 - float delta_x = (float)(cursor->x - begin_cursorx) * - (1 - grabc->old_master_width_per) / - grabc->begin_geom.width; - float delta_y = (float)(cursor->y - begin_cursory) * - (grabc->old_slave_height_per) / - grabc->begin_geom.height; + if(grabc->ismaster) { + delta_x = (float)(cursor->x - begin_cursorx) * + (grabc->old_master_width_per) / + grabc->begin_geom.width; + delta_y = (float)(cursor->y - begin_cursory) * + (grabc->old_master_height_per) / + grabc->begin_geom.height; + } else { + delta_x = (float)(cursor->x - begin_cursorx) * + (1 - grabc->old_master_width_per) / + grabc->begin_geom.width; + delta_y = (float)(cursor->y - begin_cursory) * + (grabc->old_slave_height_per) / + grabc->begin_geom.height; + } bool moving_up = cursor->y < begin_cursory; bool moving_down = cursor->y > begin_cursory; - if ((grabc->cursor_in_upper_half && moving_up) || + + if(grabc->ismaster && !prev) { + if(moving_up) { + delta_y = -fabsf(delta_y); + } else { + delta_y = fabsf(delta_y); + } + } else if(grabc->ismaster && !next->ismaster) { + if(moving_up) { + delta_y = fabsf(delta_y); + } else { + delta_y = -fabsf(delta_y); + } + } else if(!grabc->ismaster && prev->ismaster) { + if(moving_up) { + delta_y = -fabsf(delta_y); + } else { + delta_y = fabsf(delta_y); + } + } else if(!grabc->ismaster && !next) { + if(moving_up) { + delta_y = fabsf(delta_y); + } else { + delta_y = -fabsf(delta_y); + } + } else if ((grabc->cursor_in_upper_half && moving_up) || (!grabc->cursor_in_upper_half && moving_down)) { // 光标在窗口上方且向上移动,或在窗口下方且向下移动 → 增加高度 delta_y = fabsf(delta_y);