From 0718297e9ac0d10a2a8b73d75a103fde0a20eee3 Mon Sep 17 00:00:00 2001 From: "Torrance, Douglas" Date: Fri, 20 Jan 2023 11:30:52 +0000 Subject: [PATCH] Correctly draw window snapping hints on multi-head systems Previously, the transparent frames that were drawn prior to snapping a window assumed that there was only one head, i.e., that the new position and dimensions of the window would be based on the dimensions of the entire screen. However, this is not the case on multi-head systems, and so we now base the transparent frame's position and dimensions on the current head of the window. We also refactor the code so that the new dimensions are computed in the switch statement and finish with one final call to drawTransparentFrame. --- src/moveres.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/moveres.c b/src/moveres.c index 4e0d7deb..685f3fc6 100644 --- a/src/moveres.c +++ b/src/moveres.c @@ -1199,46 +1199,65 @@ updateWindowPosition(WWindow * wwin, MoveData * data, Bool doResistance, static void draw_snap_frame(WWindow *wwin, int direction) { WScreen *scr; + int head, x, y; + unsigned int width, height; + WMRect rect; scr = wwin->screen_ptr; + head = wGetHeadForWindow(wwin); + rect = wGetRectForHead(scr, head); + + x = rect.pos.x; + y = rect.pos.y; + width = rect.size.width; + height = rect.size.height; switch (direction) { case SNAP_LEFT: - drawTransparentFrame(wwin, 0, 0, scr->scr_width/2, scr->scr_height); + width /= 2; break; case SNAP_RIGHT: - drawTransparentFrame(wwin, scr->scr_width/2, 0, scr->scr_width/2, scr->scr_height); + width /= 2; + x += width; break; case SNAP_TOP: - if (wPreferences.snap_to_top_maximizes_fullscreen) - drawTransparentFrame(wwin, 0, 0, scr->scr_width, scr->scr_height); - else - drawTransparentFrame(wwin, 0, 0, scr->scr_width, scr->scr_height/2); + if (!wPreferences.snap_to_top_maximizes_fullscreen) + height /= 2; break; case SNAP_BOTTOM: - drawTransparentFrame(wwin, 0, scr->scr_height/2, scr->scr_width, scr->scr_height/2); + height /= 2; + y += height; break; case SNAP_TOPLEFT: - drawTransparentFrame(wwin, 0, 0, scr->scr_width/2, scr->scr_height/2); + width /= 2; + height /= 2; break; case SNAP_TOPRIGHT: - drawTransparentFrame(wwin, scr->scr_width/2, 0, scr->scr_width/2, scr->scr_height/2); + width /= 2; + height /= 2; + x += width; break; case SNAP_BOTTOMLEFT: - drawTransparentFrame(wwin, 0, scr->scr_height/2, scr->scr_width/2, scr->scr_height/2); + width /= 2; + height /= 2; + y += height; break; case SNAP_BOTTOMRIGHT: - drawTransparentFrame(wwin, scr->scr_width/2, scr->scr_height/2, - scr->scr_width/2, scr->scr_height/2); + width /= 2; + height /= 2; + x += width; + y += height; break; } + + drawTransparentFrame(wwin, x, y, width, height); } static int get_snap_direction(WScreen *scr, int x, int y)