This patch does not break anything obvious here, and it seems to
fix the handling of the titlebar during a maximuzation if fullscreen
is set.

And I also tried to clean up the order in which we check things,
so I moved common checks to the very end. It looks like this is
the right thing to do, but I fear that some xinerama stuff might
give me a regression nightmare. I would like to try nevertheless,
at least to show that some simplification can at least be tried
there. But the code gets smaller by a larger amount which was
increased by the Mac OS-X patch, so I like it :-)

Paul, note that this patch is not meant to solve the "wide" bug,
as I still don't understand it. This is only supposed to fix the
titlebar thing.

The issue with the +- 1 pixel is still on my TODO list, but
my time is running out now, really.

--8<--
>From b06620fed5f683bba3e49d178ecbde49488fcb70 Mon Sep 17 00:00:00 2001
From: Carlos R. Mafra <[email protected]>
Date: Wed, 16 Sep 2009 17:37:07 +0200
Subject: [PATCH] Simplify the handling of window attributes during maximization

It is cleaner to handle the geometry adjustments inside the
function which really cares, ie wWindowMaximize(), and move
them out of find_Maximus_geometry().

That way we can unify those adjustments in the final part
of wWindowMaximize(), treating everything together.

While at it, move the repeated checks for HAS_BORDER out
of every single maximization state possibility, and put them
at the very end. As a bonus it shaves off 320 bytes of code,
making it 2% smaller :-)

[ma...@pilar:wmaker.git]$ size src/actions.o.*
   text    data     bss     dec     hex filename
  16441       0       8   16449    4041 src/actions.o.new
  16761       0       8   16769    4181 src/actions.o.old
---
 src/actions.c |   48 ++++++++++++++----------------------------------
 1 files changed, 14 insertions(+), 34 deletions(-)

diff --git a/src/actions.c b/src/actions.c
index 85412e8..93f6cd2 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -343,18 +343,12 @@ void wMaximizeWindow(WWindow * wwin, int directions)
 
        if (directions & MAX_HORIZONTAL) {
                new_width = usableArea.x2 - usableArea.x1;
-               if (HAS_BORDER(wwin))
-                       new_width -= FRAME_BORDER_WIDTH * 2;
                new_x = usableArea.x1;
        } else if (directions & MAX_LEFTHALF) {
                new_width = half_scr_width;
-               if (HAS_BORDER(wwin))
-                       new_width -= FRAME_BORDER_WIDTH * 2;
                new_x = usableArea.x1;
        } else if (directions & MAX_RIGHTHALF) {
                new_width = half_scr_width;
-               if (HAS_BORDER(wwin))
-                       new_width -= FRAME_BORDER_WIDTH * 2;
                new_x = usableArea.x1 + half_scr_width;
        } else {
                new_x = wwin->frame_x;
@@ -363,24 +357,25 @@ void wMaximizeWindow(WWindow * wwin, int directions)
 
        if (directions & MAX_VERTICAL) {
                new_height = usableArea.y2 - usableArea.y1;
-               if (HAS_BORDER(wwin))
-                       new_height -= FRAME_BORDER_WIDTH * 2;
                new_y = usableArea.y1;
-               if (WFLAGP(wwin, full_maximize)) {
-                       new_y -= wwin->frame->top_width;
-                       new_height += wwin->frame->bottom_width - 1;
-               }
+       } else if (directions & MAX_MAXIMUS) {
+               find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, 
&new_width, &new_height);
        } else {
                new_y = wwin->frame_y;
                new_height = wwin->frame->core->height;
        }
 
-       if (!WFLAGP(wwin, full_maximize)) {
-               new_height -= wwin->frame->top_width + 
wwin->frame->bottom_width;
+       /* Take into account the window attributes */
+       if (directions && HAS_BORDER(wwin))
+                       new_height -= FRAME_BORDER_WIDTH * 2;
+
+       if ((directions & (MAX_VERTICAL | MAX_MAXIMUS)) && WFLAGP(wwin, 
full_maximize)) {
+                       new_y -= wwin->frame->top_width;
+                       new_height += wwin->frame->bottom_width - 1;
        }
 
-       if (directions & MAX_MAXIMUS)
-               find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, 
&new_width, &new_height);
+       if (!WFLAGP(wwin, full_maximize))
+               new_height -= wwin->frame->top_width + 
wwin->frame->bottom_width;
 
        wWindowConstrainSize(wwin, &new_width, &new_height);
 
@@ -415,9 +410,6 @@ static void find_Maximus_geometry(WWindow *wwin, WArea 
usableArea, int *new_x, i
        int new_x_0, new_y_0, new_botton_0, new_right_border_0, new_height_0;
        int x_j,  y_j, width_j, height_j, botton_j, top_j, right_border_j;
        int x_intsect, y_intsect;
-       /* Assume that the window w_0 has titlebar etc */
-       int has_titlebar = 1, has_resizebar = 1, has_border = 1;
-       int adjust_height, adjust_width;
 
        /* Try to fully maximize first, then readjust later */
        new_x_0            = usableArea.x1;
@@ -425,18 +417,6 @@ static void find_Maximus_geometry(WWindow *wwin, WArea 
usableArea, int *new_x, i
        new_botton_0       = usableArea.y2;
        new_right_border_0 = usableArea.x2;
 
-       if (!HAS_TITLEBAR(wwin))
-               has_titlebar = 0;
-       if (!HAS_RESIZEBAR(wwin))
-               has_resizebar = 0;
-       if (!HAS_BORDER(wwin))
-               has_border = 0;
-
-       /* the lengths to be subtracted if w_0 has titlebar, etc */
-       adjust_height = TITLEBAR_HEIGHT * has_titlebar
-               + 2 * FRAME_BORDER_WIDTH * has_border + RESIZEBAR_HEIGHT * 
has_resizebar;
-       adjust_width = 2 * FRAME_BORDER_WIDTH * has_border;
-
        tmp = wwin;
        /* TODO: Is the focused window always the last in the list? */
        while (tmp->prev) {
@@ -475,7 +455,7 @@ static void find_Maximus_geometry(WWindow *wwin, WArea 
usableArea, int *new_x, i
                 * the possibility that the new value of y_0 will have different
                 * intersections with w_j
                 */
-               new_height_0 = new_botton_0 - new_y_0 - adjust_height;
+               new_height_0 = new_botton_0 - new_y_0;
                y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, 
height_j);
                if (y_intsect != 0) {
                        if (right_border_j < x_0 && right_border_j > new_x_0) {
@@ -489,11 +469,11 @@ static void find_Maximus_geometry(WWindow *wwin, WArea 
usableArea, int *new_x, i
                }
        }
 
-       new_height_0 = new_botton_0 - new_y_0 - adjust_height;
+       new_height_0 = new_botton_0 - new_y_0;
        *new_x = new_x_0;
        *new_y = new_y_0;
        *new_height = new_height_0;
-       *new_width = new_right_border_0 - new_x_0 - adjust_width;
+       *new_width = new_right_border_0 - new_x_0;
 }
 
 void wUnmaximizeWindow(WWindow * wwin)
-- 
1.6.5.rc1


-- 
To unsubscribe, send mail to [email protected].

Reply via email to