On Mon 31.Aug'09 at 21:28:31 +0200, Martin Dietze wrote:
> Still one problem: you do a tiled maximise. The
> window takes the workspace's full height but not width. Now you
> do something which increases the height (e.g. if you use a
> gnome-terminal, press Ctrl-Shift-T to add a second tab, the
> height consumed by the tabs at the top will be added to the
> window's overall height). Now I press the shortcut for vertical
> maximisation expecting the window to be resized to fit the 
> workspace's height again. But instead the window is now
> maximised to the full workspace thus covering other windows,
> i.e. the tiled maximisation's effect is gone.

This is strange. After using the tiled maximization the
vertical maximization acts like a full maximize?
I tried to understand that in the code, but decided to
clean up that whole mess with trying to shrink back
to original sizes from inside wMaximizeWindow() instead.

That function should not try to do what is effectively
a un-maximize, and it was doing that in a complicated
way, IMHO.

So my idea is to remove the un-maximize code from
wMaximizeWindow(), try to do it cleanly from the
calling sites of it and fix the fallout.

So here is my first humble attempt. I don't know
if it will solve your problem and I expect that
it will create other problems for the time being.

But that won't stop me from trying to make it cleaner.

>From 901aed7b2ae521a123747b30a95ff67b58ba98dd Mon Sep 17 00:00:00 2001
From: Carlos R. Mafra <[email protected]>
Date: Tue, 1 Sep 2009 03:22:57 +0200
Subject: [PATCH] First attempt to clean up maximization state memory

Let's remove the code which tried to keep track of which
maximizations already occurred from the function wMaximizeWindow(),
as that is not the place to shrink back to the original sizes.

The idea is to check for the maximization state in the calling places,
and use wUnmaximizeWindow() when appropriate.
---
 src/actions.c |   48 ++++++++++++++----------------------------------
 src/event.c   |   57 +++++++++++++++++++++++++++------------------------------
 2 files changed, 41 insertions(+), 64 deletions(-)

diff --git a/src/actions.c b/src/actions.c
index d214a88..7d34fa6 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -291,11 +291,19 @@ void wUnshadeWindow(WWindow *wwin)
        WMPostNotificationName(WMNChangedState, wwin, "shade");
 }
 
+/* Set the old coordinates using the current values */
+void set_old_geometry(WWindow *wwin)
+{
+       wwin->old_geometry.width = wwin->client.width;
+       wwin->old_geometry.height = wwin->client.height;
+       wwin->old_geometry.x = wwin->frame_x;
+       wwin->old_geometry.y = wwin->frame_y;
+}
+
 void wMaximizeWindow(WWindow * wwin, int directions)
 {
        int new_x, new_y;
        unsigned int new_width, new_height, half_scr_width;
-       int changed_h, changed_v, shrink_h, shrink_v;
        WArea usableArea, totalArea;
 
        if (!IS_RESIZABLE(wwin))
@@ -320,6 +328,9 @@ void wMaximizeWindow(WWindow * wwin, int directions)
                usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
        }
 
+       /* Only save directions, not kbd or xinerama hints */
+       directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | 
MAX_RIGHTHALF | MAX_MAXIMUS);
+
        if (WFLAGP(wwin, full_maximize)) {
                usableArea = totalArea;
        }
@@ -328,33 +339,6 @@ void wMaximizeWindow(WWindow * wwin, int directions)
                wwin->flags.skip_next_animation = 1;
                wUnshadeWindow(wwin);
        }
-       /* Only save directions, not kbd or xinerama hints */
-       directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | 
MAX_RIGHTHALF | MAX_MAXIMUS);
-
-       changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL);
-       changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL);
-       shrink_h = (changed_h && (directions & MAX_HORIZONTAL) == 0);
-       shrink_v = (changed_v && (directions & MAX_VERTICAL) == 0);
-
-       if (wwin->flags.maximized) {
-               /* if already maximized in some direction, we only update the
-                * appropriate old x, old y coordinates. This is necessary to
-                * allow succesive maximizations in different directions without
-                * the need to first do an un-maximize (to avoid flicker).
-                */
-               if (!(wwin->flags.maximized & 
(MAX_HORIZONTAL|MAX_LEFTHALF|MAX_RIGHTHALF))) {
-                       wwin->old_geometry.x = wwin->frame_x;
-               }
-               if (!(wwin->flags.maximized & MAX_VERTICAL)) {
-                       wwin->old_geometry.y = wwin->frame_y;
-               }
-       } else {
-               wwin->old_geometry.width = wwin->client.width;
-               wwin->old_geometry.height = wwin->client.height;
-               wwin->old_geometry.x = wwin->frame_x;
-               wwin->old_geometry.y = wwin->frame_y;
-       }
-       wwin->flags.maximized = directions;
 
        if (directions & MAX_HORIZONTAL) {
                new_width = usableArea.x2 - usableArea.x1;
@@ -371,9 +355,6 @@ void wMaximizeWindow(WWindow * wwin, int directions)
                if (HAS_BORDER(wwin))
                        new_width -= FRAME_BORDER_WIDTH * 2;
                new_x = usableArea.x1 + half_scr_width;
-       } else if (shrink_h) {
-               new_x = wwin->old_geometry.x;
-               new_width = wwin->old_geometry.width;
        } else {
                new_x = wwin->frame_x;
                new_width = wwin->frame->core->width;
@@ -388,9 +369,6 @@ void wMaximizeWindow(WWindow * wwin, int directions)
                        new_y -= wwin->frame->top_width;
                        new_height += wwin->frame->bottom_width - 1;
                }
-       } else if (shrink_v) {
-               new_y = wwin->old_geometry.y;
-               new_height = wwin->old_geometry.height;
        } else {
                new_y = wwin->frame_y;
                new_height = wwin->frame->core->height;
@@ -413,6 +391,8 @@ void wMaximizeWindow(WWindow * wwin, int directions)
        WMPostNotificationName(WMNChangedState, wwin, "maximize");
 
        wSoundPlay(WSOUND_MAXIMIZE);
+       /* set maximization state */
+       wwin->flags.maximized = directions;
 }
 
 /*
diff --git a/src/event.c b/src/event.c
index 70b8a1e..ee7233f 100644
--- a/src/event.c
+++ b/src/event.c
@@ -99,6 +99,8 @@ extern int wXkbEventBase;
 /* special flags */
 /*extern char WDelayedActionSet;*/
 
+extern void set_old_geometry(WWindow *wwin);
+
 /************ Local stuff ***********/
 
 static void saveTimestamp(XEvent *event);
@@ -1434,79 +1436,74 @@ static void handleKeyPress(XEvent * event)
                break;
        case WKBD_MAXIMIZE:
                if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
-                       int newdir = (MAX_VERTICAL | MAX_HORIZONTAL);
-
                        CloseWindowMenu(scr);
 
-                       if (wwin->flags.maximized == newdir) {
+                       if (wwin->flags.maximized == (MAX_VERTICAL | 
MAX_HORIZONTAL))
                                wUnmaximizeWindow(wwin);
-                       } else {
-                               wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
+                       else {
+                               set_old_geometry(wwin);
+                               wMaximizeWindow(wwin, MAX_VERTICAL | 
MAX_HORIZONTAL | MAX_KEYBOARD);
                        }
                }
                break;
        case WKBD_VMAXIMIZE:
                if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
-                       int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
-
                        CloseWindowMenu(scr);
 
-                       if (newdir) {
-                               wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
-                       } else {
+                       if (wwin->flags.maximized == MAX_VERTICAL) {
+                               //TODO: consider also HORIZONTAL
                                wUnmaximizeWindow(wwin);
+                       } else {
+                               set_old_geometry(wwin);
+                               wMaximizeWindow(wwin, MAX_VERTICAL | 
MAX_KEYBOARD);
                        }
                }
                break;
        case WKBD_HMAXIMIZE:
                if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
-                       int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
-
                        CloseWindowMenu(scr);
 
-                       if (newdir) {
-                               wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
-                       } else {
+                       if (wwin->flags.maximized == MAX_HORIZONTAL)
                                wUnmaximizeWindow(wwin);
+                       else {
+                               set_old_geometry(wwin);
+                               wMaximizeWindow(wwin, MAX_HORIZONTAL | 
MAX_KEYBOARD);
                        }
                }
                break;
        case WKBD_LHMAXIMIZE:
                if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
-                       int newdir = (MAX_VERTICAL|MAX_LEFTHALF);
-
                        CloseWindowMenu(scr);
 
-                       if (wwin->flags.maximized == newdir) {
+                       if (wwin->flags.maximized == MAX_VERTICAL | 
MAX_LEFTHALF)
                                wUnmaximizeWindow(wwin);
-                       } else {
-                               wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
+                       else {
+                               set_old_geometry(wwin);
+                               wMaximizeWindow(wwin, MAX_VERTICAL | 
MAX_LEFTHALF | MAX_KEYBOARD);
                        }
                }
                break;
        case WKBD_RHMAXIMIZE:
                if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
-                       int newdir = (MAX_VERTICAL|MAX_RIGHTHALF);
-
                        CloseWindowMenu(scr);
 
-                       if (wwin->flags.maximized == newdir) {
+                       if (wwin->flags.maximized == MAX_VERTICAL | 
MAX_RIGHTHALF)
                                wUnmaximizeWindow(wwin);
-                       } else {
-                               wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
+                       else {
+                               set_old_geometry(wwin);
+                               wMaximizeWindow(wwin, MAX_VERTICAL | 
MAX_RIGHTHALF | MAX_KEYBOARD);
                        }
                }
                break;
        case WKBD_MAXIMUS:
                if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
-                       int newdir = MAX_MAXIMUS;
-
                        CloseWindowMenu(scr);
 
-                       if (wwin->flags.maximized == newdir) {
+                       if (wwin->flags.maximized == MAX_MAXIMUS)
                                wUnmaximizeWindow(wwin);
-                       } else {
-                               wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
+                       else {
+                               set_old_geometry(wwin);
+                               wMaximizeWindow(wwin, MAX_MAXIMUS | 
MAX_KEYBOARD);
                        }
                }
                break;
-- 
1.6.4.2.236.gf324c


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

Reply via email to