Fixed regression when placing windows.
authorIain Patterson <wm@iain.cx>
Fri, 16 Nov 2012 22:43:52 +0000 (16 14:43 -0800)
committerCarlos R. Mafra <crmafra@gmail.com>
Sat, 17 Nov 2012 10:49:28 +0000 (17 11:49 +0100)
The initial fix for the bug reported by Paul Seelig whereby windows
would drift on restart introduced two regressions.

New windows would place higher on the screen than intended, possibly
obscuring the bottoms of other windows with their titlebars, and all
windows would jump vertically at shutdown because we weren't restoring
them to where they were before they had a titlebar and border.

src/client.c
src/placement.c
src/window.c

index 3287306..10f2571 100644 (file)
@@ -81,6 +81,13 @@ void wClientRestore(WWindow * wwin)
        if (gy > 0)
                wwin->frame_y += (wwin->frame->top_width + wwin->frame->bottom_width);
 #endif
+       /* account for titlebar and border */
+       wwin->frame_y += wwin->frame->top_width;
+       if (HAS_BORDER(wwin)) {
+               wwin->frame_x += FRAME_BORDER_WIDTH;
+               wwin->frame_y += FRAME_BORDER_WIDTH;
+       }
+
        XSetWindowBorderWidth(dpy, wwin->client_win, wwin->old_border_width);
        XReparentWindow(dpy, wwin->client_win, wwin->screen_ptr->root_win, wwin->frame_x, wwin->frame_y);
 
index b30e0af..3d219d6 100644 (file)
@@ -523,6 +523,7 @@ void PlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, unsigned width, unsigned
        WScreen *scr = wwin->screen_ptr;
        int h = WMFontHeight(scr->title_font)
                + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
+       int border_width;
 
        if (h > wPreferences.window_title_max_height)
                h = wPreferences.window_title_max_height;
@@ -577,13 +578,14 @@ void PlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, unsigned width, unsigned
         * this will also take dock/clip etc.. into account
         * aswell as being xinerama friendly
         */
-       if (*x_ret + width > usableArea.x2)
-               *x_ret = usableArea.x2 - width;
+       border_width = (HAS_BORDER(wwin)) ? 2 * FRAME_BORDER_WIDTH : 0;
+       if (*x_ret + border_width + width > usableArea.x2)
+               *x_ret = usableArea.x2 - border_width - width;
        if (*x_ret < usableArea.x1)
                *x_ret = usableArea.x1;
 
-       if (*y_ret + height > usableArea.y2)
-               *y_ret = usableArea.y2 - height;
+       if (*y_ret + border_width + height > usableArea.y2)
+               *y_ret = usableArea.y2 - border_width - height;
        if (*y_ret < usableArea.y1)
                *y_ret = usableArea.y1;
 }
index b07d9d4..7f0a1fe 100644 (file)
@@ -591,6 +591,7 @@ WWindow *wManageWindow(WScreen *scr, Window window)
        char *title;
        Bool withdraw = False;
        Bool raise = False;
+       Bool frame_adjustment = True;
 
        /* mutex. */
        XGrabServer(dpy);
@@ -994,6 +995,7 @@ WWindow *wManageWindow(WScreen *scr, Window window)
 
                        } else {
                                PlaceWindow(wwin, &x, &y, width, height);
+                               frame_adjustment = False;
                        }
                        if (wPreferences.window_placement == WPM_MANUAL) {
                                dontBring = True;
@@ -1144,7 +1146,7 @@ WWindow *wManageWindow(WScreen *scr, Window window)
                        y -= wwin->frame->top_width + wwin->frame->bottom_width;
        }
 
-       {
+       if (frame_adjustment) {
                WMRect rect;
                WArea usableArea;
                int head;
@@ -1161,7 +1163,6 @@ WWindow *wManageWindow(WScreen *scr, Window window)
                 * when placing so the window would be shifted without
                 * the adjustment below
                 */
-
                if (y >= usableArea.y1 + wwin->frame->top_width)
                        y -= wwin->frame->top_width;