diff --git a/src/actions.c b/src/actions.c index 881448f1..988e90a6 100644 --- a/src/actions.c +++ b/src/actions.c @@ -287,14 +287,20 @@ void wUnshadeWindow(WWindow *wwin) /* Set the old coordinates using the current values */ static void save_old_geometry(WWindow *wwin, int directions) { - if (directions & MAX_HORIZONTAL || ! wwin->old_geometry.width) { - wwin->old_geometry.width = wwin->client.width; + /* never been saved? */ + if (! wwin->old_geometry.width) + directions |= SAVE_GEOMETRY_X | SAVE_GEOMETRY_WIDTH; + if (! wwin->old_geometry.height) + directions |= SAVE_GEOMETRY_Y | SAVE_GEOMETRY_HEIGHT; + + if (directions & SAVE_GEOMETRY_X) wwin->old_geometry.x = wwin->frame_x; - } - if (directions & MAX_VERTICAL || ! wwin->old_geometry.height) { - wwin->old_geometry.height = wwin->client.height; + if (directions & SAVE_GEOMETRY_Y) wwin->old_geometry.y = wwin->frame_y; - } + if (directions & SAVE_GEOMETRY_WIDTH) + wwin->old_geometry.width = wwin->client.width; + if (directions & SAVE_GEOMETRY_HEIGHT) + wwin->old_geometry.height = wwin->client.height; } static void remember_geometry(WWindow *wwin, int *x, int *y, int *w, int *h) @@ -312,6 +318,27 @@ static void remember_geometry(WWindow *wwin, int *x, int *y, int *w, int *h) *h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height; } +/* Remember geometry for unmaximizing */ +void update_saved_geometry(WWindow *wwin) +{ + /* NOT if we aren't already maximized + * we'll save geometry when maximizing */ + if (!wwin->flags.maximized) + return; + + /* NOT if we are fully maximized */ + if ((wwin->flags.maximized & MAX_MAXIMUS) || + ((wwin->flags.maximized & MAX_HORIZONTAL) && + (wwin->flags.maximized & MAX_VERTICAL))) + return; + + /* save the co-ordinate in the axis in which we AREN'T maximized */ + if (wwin->flags.maximized & MAX_HORIZONTAL) + save_old_geometry(wwin, SAVE_GEOMETRY_Y); + if (wwin->flags.maximized & MAX_VERTICAL) + save_old_geometry(wwin, SAVE_GEOMETRY_X); +} + #define IS_MAX_HORIZONTALLY(directions) ((directions & MAX_HORIZONTAL) | (directions & MAX_LEFTHALF) | (directions & MAX_RIGHTHALF)) void wMaximizeWindow(WWindow *wwin, int directions) { @@ -336,17 +363,20 @@ void wMaximizeWindow(WWindow *wwin, int directions) adj_size = FRAME_BORDER_WIDTH * 2 * has_border; /* save old coordinates before we change the current values + * always if the window is not currently maximized at all * but never if the window has been Maximusized */ - if (!(wwin->flags.old_maximized & MAX_MAXIMUS)) { + if (!wwin->flags.maximized) + save_directions |= SAVE_GEOMETRY_ALL; + else if (!(wwin->flags.old_maximized & MAX_MAXIMUS)) { if ((directions & MAX_VERTICAL) && !(wwin->flags.maximized & MAX_VERTICAL)) - save_directions |= MAX_VERTICAL; + save_directions |= SAVE_GEOMETRY_Y | SAVE_GEOMETRY_HEIGHT; if (IS_MAX_HORIZONTALLY(directions) && !IS_MAX_HORIZONTALLY(wwin->flags.maximized)) - save_directions |= MAX_HORIZONTAL; + save_directions |= SAVE_GEOMETRY_X | SAVE_GEOMETRY_WIDTH; } if ((directions & MAX_MAXIMUS) && !wwin->flags.maximized) - save_directions |= MAX_VERTICAL | MAX_HORIZONTAL; + save_directions |= SAVE_GEOMETRY_ALL; save_old_geometry(wwin, save_directions); totalArea.x1 = 0; @@ -445,6 +475,8 @@ void wMaximizeWindow(WWindow *wwin, int directions) new_y -= wwin->frame->top_width; new_height += wwin->frame->top_width - 1; } + wwin->maximus_x = new_x; + wwin->maximus_y = new_y; wwin->flags.old_maximized |= MAX_MAXIMUS; } @@ -673,9 +705,16 @@ void wUnmaximizeWindow(WWindow *wwin) wwin->flags.skip_next_animation = 1; wUnshadeWindow(wwin); } + /* Use old coordinates if they are set, current values otherwise */ remember_geometry(wwin, &x, &y, &w, &h); + /* unMaximusize relative to original position */ + if (wwin->flags.maximized & MAX_MAXIMUS) { + x += wwin->frame_x - wwin->maximus_x; + y += wwin->frame_y - wwin->maximus_y; + } + wwin->flags.maximized = 0; wwin->flags.old_maximized = 0; wWindowConfigure(wwin, x, y, w, h); diff --git a/src/actions.h b/src/actions.h index 719df2e9..55de740b 100644 --- a/src/actions.h +++ b/src/actions.h @@ -31,6 +31,12 @@ #define MAX_IGNORE_XINERAMA (1 << 5) #define MAX_KEYBOARD (1 << 6) +#define SAVE_GEOMETRY_X (1 << 0) +#define SAVE_GEOMETRY_Y (1 << 1) +#define SAVE_GEOMETRY_WIDTH (1 << 2) +#define SAVE_GEOMETRY_HEIGHT (1 << 3) +#define SAVE_GEOMETRY_ALL SAVE_GEOMETRY_X | SAVE_GEOMETRY_Y | SAVE_GEOMETRY_WIDTH | SAVE_GEOMETRY_HEIGHT + void wSetFocusTo(WScreen *scr, WWindow *wwin); int wMouseMoveWindow(WWindow *wwin, XEvent *ev); @@ -71,6 +77,7 @@ void wFullscreenWindow(WWindow *wwin); void wUnfullscreenWindow(WWindow *wwin); void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh); +void update_saved_geometry(WWindow *wwin); #endif diff --git a/src/moveres.c b/src/moveres.c index 3d3ff7ed..59dd0d22 100644 --- a/src/moveres.c +++ b/src/moveres.c @@ -1535,6 +1535,8 @@ int wKeyboardMoveResizeWindow(WWindow * wwin) wArrangeIcons(scr, True); } + update_saved_geometry(wwin); + return 1; } } @@ -1796,6 +1798,10 @@ int wMouseMoveWindow(WWindow * wwin, XEvent * ev) head != wGetHeadForWindow(wwin)) { wArrangeIcons(scr, True); } + + if (started) + update_saved_geometry(wwin); + return started; } diff --git a/src/window.h b/src/window.h index 99e1c243..cdb5bc79 100644 --- a/src/window.h +++ b/src/window.h @@ -199,6 +199,9 @@ typedef struct WWindow { unsigned int width, height; /* original geometry of the window */ } bfs_geometry; /* (before fullscreen) */ + int maximus_x; /* size after Maximusizing */ + int maximus_y; + /* client window info */ short old_border_width; /* original border width of client_win*/ Window client_win; /* the window we're managing */