Merge lp:~sjakthol/compiz/fix-878516 into lp:compiz/0.9.9

Proposed by Sami Jaktholm
Status: Merged
Approved by: Daniel van Vugt
Approved revision: 3573
Merged at revision: 3578
Proposed branch: lp:~sjakthol/compiz/fix-878516
Merge into: lp:compiz/0.9.9
Diff against target: 203 lines (+65/-31)
2 files modified
plugins/grid/src/grid.cpp (+64/-30)
plugins/grid/src/grid.h (+1/-1)
To merge this branch: bzr merge lp:~sjakthol/compiz/fix-878516
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
MC Return Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+144020@code.launchpad.net

Commit message

Grid: Correctly restore semi-maximized windows.

Changes include:
1) Remove the special status of fully maximized windows - it just adds
   complexity to the restoration process. Core can handle the
   restoration of maximized windows perfectly well.
2) Catch un-maximation of a gridded semi-maximized window in
   stateChangeNotify and call restoreWindow to revert the changes.
3) Refactor restoreWindow to work with semi-maximized windows.

This fixes LP: #878516 and also LP: #925867 as a side effect.

Description of the change

NOTE: These fixes cause bug 1102024 to also manifest itself with semi-maximized terminal windows. Previously isGridMaximized wasn't unset once a semi-maximized window was restored as the restoration code was never called. Consequently validateResizeRequest blocked the size from being changed by the client. With this branch gnome-terminal fails to restore its geometry but other applications get their old geometries back.

I'm not sure whether it's worth fixing an annoying bug 878516 affecting every application by introducing another annoying bug that only affects one application. But anyways I'm putting my work up here if someone wants to take a shot at fixing the regression because I'm out of ideas...

To post a comment you must log in.
Revision history for this message
MC Return (mc-return) wrote :

Top job !
Works like expected and announced.
Makes those nasty mouse-resized grid windows much more usable.
Strange thing with the terminal windows though, but still a huge improvement of grid.

review: Approve
Revision history for this message
Sam Spilsbury (smspillaz) wrote :
Download full text (5.2 KiB)

Most of this makes a lot of sense, I only have a few comments which might
be worth considering (diff inline).

sampo555 has proposed merging lp:~sampo555/compiz/fix-878516 into lp:compiz.

Commit message:
Grid: Correctly restore semi-maximized windows.

Changes include:
1) Remove the special status of fully maximized windows - it just adds
   complexity to the restoration process. Core can handle the
   restoration of maximized windows perfectly well.
2) Catch un-maximation of a gridded semi-maximized window in
   stateChangeNotify and call restoreWindow to revert the changes.
3) Refactor restoreWindow to work with semi-maximized windows
=== modified file 'plugins/grid/src/grid.cpp'
--- plugins/grid/src/grid.cpp 2013-01-18 18:10:07 +0000
+++ plugins/grid/src/grid.cpp 2013-01-20 12:47:23 +0000
@@ -198,8 +198,8 @@
                cw->configureXWindow (CWX | CWY, &xwc);
            }
            cw->maximize (MAXIMIZE_STATE);
- gw->isGridResized = true;
- gw->isGridMaximized = true;
+ gw->isGridResized = false;
+ gw->isGridMaximized = false;

Once I had read the whole diff, this change made sense, though it was a bit
confusing in isolation, especially because we maximize the window and then
set isGridMaximized to false.

Some things that might be worth doing about this:
1) Rename isGridMaximed to isGridSemiMaximized
2) Stick a comment there about how we're letting core handle the
fully-maximized case.

                for (unsigned int i = 0; i < animations.size (); i++)
                        animations.at (i).fadingOut = true;
            return true;
@@ -926,7 +926,11 @@
 {
     if (lastState & MAXIMIZE_STATE &&
        !(window->state () & MAXIMIZE_STATE))
+ {
        lastTarget = GridUnknown;
+ if (isGridMaximized)
+ gScreen->restoreWindow(0, 0, gScreen->o);
+ }

I don't think this will be a problem, although I think it should be clear
that the condition should only ever be entered if the window went from
being semi-maximized to not-maximized at all (and guarded against further
change which would enter this condition if the window went from
semi-maximized to maximized)

     else if (!(lastState & MAXIMIZE_STATE) &&
             window->state () & MAXIMIZE_STATE)
     {
@@ -952,6 +956,7 @@
                           CompOption::Vector &option)
 {
     XWindowChanges xwc;
+ int xwcm = 0;
     CompWindow *cw = screen->findWindow (screen->activeWindow ());

     if (!cw)
@@ -959,35 +964,59 @@

     GRID_WINDOW (cw);

- if (!gw->isGridResized)
- return false;
-
- if (gw->isGridMaximized & !(cw->state () & MAXIMIZE_STATE))
- {
- gw->window->sizeHints ().flags |= gw->sizeHintsFlags;
- gw->isGridMaximized = false;
- }
- else
- {
- if (cw == mGrabWindow)
- {
- xwc.x = pointerX - (gw->originalSize.width () >> 1);
- xwc.y = pointerY + (cw->border ().top >> 1);
- }
- else
- {
- xwc.x = gw->originalSize.x ();
- xwc.y = gw->originalSize.y ();
- }
- xwc.width = gw->originalSize.width ();
- xwc.height = gw->originalSize.height ();
- cw->maximize (0);
- ...

Read more...

lp:~sjakthol/compiz/fix-878516 updated
3571. By Sami Jaktholm

isGridMaximized changed to isGridSemiMaximized and comment added about core handling fully maximized windows. Added assert to the else clause in restoreWindow, changed shifts to divide by 2 and added check for xwcm before calling sendSyncRequest. Also added an extra check so that we only call restoreWindow from stateChangeNotify if lastState was CompWindowStateMaximizedVertMask (e.g. not a fully maximized window incorrectly marked as isGridSemiMaximized).

Revision history for this message
Sami Jaktholm (sjakthol) wrote :

Changed the things you pointed out. About the extra check in stateChangeNotify, I hope you meant to check that we call restoreWindow only if the window was only vertically maximized. The other case (semi-maximized->maximized) should'n be possible as the previous if checks that the window is not maximized at all.

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Ah okay.

I'm that case you want to check for CompWindowStateMaximizeVertMask.
On 21/01/2013 11:27 PM, "sampo555" <email address hidden> wrote:

> Changed the things you pointed out. About the extra check in
> stateChangeNotify, I hope you meant to check that we call restoreWindow
> only if the window was only vertically maximized. The other case
> (semi-maximized->maximized) should'n be possible as the previous if checks
> that the window is not maximized at all.
> --
> https://code.launchpad.net/~sampo555/compiz/fix-878516/+merge/144020
> Your team Compiz Maintainers is requested to review the proposed merge of
> lp:~sampo555/compiz/fix-878516 into lp:compiz.
>

Revision history for this message
MC Return (mc-return) wrote :

Just a note:
The latest version fails to restore horizontal size of left/right mousegridded == semi-maximized windows...
Hope this gets corrected again as the first version was doing that correctly ?

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Testing both bugs, neither appear fixed. I can still reproduce both with this branch.

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

All -

Please remember to test proposals manually and not just read the code.

lp:~sjakthol/compiz/fix-878516 updated
3572. By Sami Jaktholm

Filter non-maximation related states from lastState before comparing it to VertMask.

Revision history for this message
Sami Jaktholm (sjakthol) wrote :

Of course I forgot that lastState in stateChangeNotify contains everything about window state - not just the bits related to maximization. This should now be fixed.

Revision history for this message
MC Return (mc-return) wrote :

Great !!! \o/

With r3572 in place everything seems to work as announced.
I cannot even reproduce the striking gnome-terminal issue anymore :)
This is another very important Grid fix and a important step in the right direction.
Well done, sampo555 !

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Nice. At first the bugs appear completely fixed, which is excellent. But then I noticed a slight regression similar to bug 878516 but with the height. If I repeatedly place a small terminal window to the side with grid and unsnap it, it will eventually stop restoring the original window height and will stay tall. This does not happen to the height with trunk (but it does happen with the width on trunk, obviously).

Also minor cleanup: In C++, <assert.h> should be <cassert>

And concerning hack:
    gw->window->sizeHints ().flags |= gw->sizeHintsFlags;
I was really hoping we could remove the sizeHints hacking. It's devious and evil. But I guess if you don't need to change it to resolve the bugs here then it's a job for another day.

review: Needs Fixing
lp:~sjakthol/compiz/fix-878516 updated
3573. By Sami Jaktholm

Change assert.h to cassert

Revision history for this message
Sami Jaktholm (sjakthol) wrote :

About the terminal height problem, that's what I was trying to say in the merge message. It has really nothing to do with grid as it also happens with the maximize/unmaximize keybindings. Prior to this branch terminals would keep their heights only because grid was not clearing isGridMaximized flags when the windows were restored (as the restoration code was not called at all). And thus validateResizeRequest was blocking these changes to the terminal windows. I was hoping someone could take a look at it (bug 1102024) before this goes in...

The sizeHints are there to resolve a bug where an empty space is left around left and right gridded terminal windows. To fix that without sizeHints modification core would have to allow plugins to force the size of the window without taking sizeHints into consideration. But that's a job for another day...

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Ok.

Yeah I know removing sizeHints would create space. And I would argue that's more correct, technically. But it's too contentious to argue in this little text box right now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/grid/src/grid.cpp'
2--- plugins/grid/src/grid.cpp 2013-01-18 18:10:07 +0000
3+++ plugins/grid/src/grid.cpp 2013-01-23 06:20:25 +0000
4@@ -24,6 +24,7 @@
5
6 #include <boost/bind.hpp>
7 #include <cmath>
8+#include <cassert>
9 #include "grid.h"
10 #include "grabhandler.h"
11
12@@ -198,8 +199,12 @@
13 cw->configureXWindow (CWX | CWY, &xwc);
14 }
15 cw->maximize (MAXIMIZE_STATE);
16- gw->isGridResized = true;
17- gw->isGridMaximized = true;
18+ /* Core can handle fully maximized windows so we don't
19+ * have to worry about them. Don't mark the window as a
20+ * gridded one.
21+ */
22+ gw->isGridResized = false;
23+ gw->isGridSemiMaximized = false;
24 for (unsigned int i = 0; i < animations.size (); i++)
25 animations.at (i).fadingOut = true;
26 return true;
27@@ -368,7 +373,7 @@
28
29 cw->configureXWindow (CWX | CWY | CWWidth | CWHeight, &rwc);
30
31- gw->isGridMaximized = true;
32+ gw->isGridSemiMaximized = true;
33 gw->isGridResized = false;
34
35 /* Maximize the window */
36@@ -384,7 +389,7 @@
37 else
38 {
39 gw->isGridResized = true;
40- gw->isGridMaximized = false;
41+ gw->isGridSemiMaximized = false;
42 }
43
44 int dw = (lastBorder.left + lastBorder.right) -
45@@ -839,7 +844,7 @@
46 /* Don't allow non-pagers to change
47 * the size of the window, the user
48 * specified this size, thank-you */
49- if (isGridMaximized)
50+ if (isGridSemiMaximized)
51 if (source != ClientTypePager)
52 xwcm = 0;
53 }
54@@ -863,7 +868,7 @@
55 pointerBufDx = pointerBufDy = 0;
56 grabMask = mask;
57
58- if (!isGridResized && !isGridMaximized && gScreen->optionGetSnapbackWindows ())
59+ if (!isGridResized && !isGridSemiMaximized && gScreen->optionGetSnapbackWindows ())
60 /* Store size not including borders when grabbing with cursor */
61 originalSize = gScreen->slotToRect(window,
62 window->serverBorderRect ());
63@@ -904,7 +909,7 @@
64 {
65 window->moveNotify (dx, dy, immediate);
66
67- if (isGridResized && !isGridMaximized && !GridScreen::get (screen)->mSwitchingVp)
68+ if (isGridResized && !isGridSemiMaximized && !GridScreen::get (screen)->mSwitchingVp)
69 {
70 if (window->grabbed () && (grabMask & CompWindowGrabMoveMask))
71 {
72@@ -926,7 +931,11 @@
73 {
74 if (lastState & MAXIMIZE_STATE &&
75 !(window->state () & MAXIMIZE_STATE))
76+ {
77 lastTarget = GridUnknown;
78+ if (isGridSemiMaximized && (lastState & MAXIMIZE_STATE) == CompWindowStateMaximizedVertMask)
79+ gScreen->restoreWindow(0, 0, gScreen->o);
80+ }
81 else if (!(lastState & MAXIMIZE_STATE) &&
82 window->state () & MAXIMIZE_STATE)
83 {
84@@ -952,6 +961,7 @@
85 CompOption::Vector &option)
86 {
87 XWindowChanges xwc;
88+ int xwcm = 0;
89 CompWindow *cw = screen->findWindow (screen->activeWindow ());
90
91 if (!cw)
92@@ -959,35 +969,59 @@
93
94 GRID_WINDOW (cw);
95
96- if (!gw->isGridResized)
97+ if (!gw->isGridResized && !gw->isGridSemiMaximized)
98+ {
99+ /* Grid hasn't touched this window or has maximized it. If it's
100+ * maximized, unmaximize it and get out. */
101+ if (cw->state () & MAXIMIZE_STATE)
102+ cw->maximize(0);
103+ return true;
104+ }
105+
106+ else if (!gw->isGridResized && gw->isGridSemiMaximized)
107+ {
108+ /* Window has been vertically maximized by grid. We only need
109+ * to restore the X and width - core handles Y and height. */
110+ if (gw->sizeHintsFlags)
111+ gw->window->sizeHints ().flags |= gw->sizeHintsFlags;
112+ xwcm |= CWX | CWWidth;
113+ }
114+
115+ else if (gw->isGridResized && !gw->isGridSemiMaximized)
116+ /* Window is just gridded (top, bottom, center, corners). We
117+ * need to handle everything. */
118+ xwcm |= CWX | CWY | CWWidth | CWHeight;
119+ else
120+ {
121+ /* This should never happen. But if it does, just bail out
122+ * gracefully. */
123+ assert (gw->isGridResized && gw->isGridSemiMaximized);
124 return false;
125+ }
126
127- if (gw->isGridMaximized & !(cw->state () & MAXIMIZE_STATE))
128+ if (cw == mGrabWindow)
129 {
130- gw->window->sizeHints ().flags |= gw->sizeHintsFlags;
131- gw->isGridMaximized = false;
132+ xwc.x = pointerX - (gw->originalSize.width () / 2);
133+ xwc.y = pointerY + (cw->border ().top / 2);
134 }
135 else
136 {
137- if (cw == mGrabWindow)
138- {
139- xwc.x = pointerX - (gw->originalSize.width () >> 1);
140- xwc.y = pointerY + (cw->border ().top >> 1);
141- }
142- else
143- {
144- xwc.x = gw->originalSize.x ();
145- xwc.y = gw->originalSize.y ();
146- }
147- xwc.width = gw->originalSize.width ();
148- xwc.height = gw->originalSize.height ();
149- cw->maximize (0);
150- gw->currentSize = CompRect ();
151- cw->configureXWindow (CWX | CWY | CWWidth | CWHeight, &xwc);
152- gw->pointerBufDx = 0;
153- gw->pointerBufDy = 0;
154+ xwc.x = gw->originalSize.x ();
155+ xwc.y = gw->originalSize.y ();
156 }
157+ xwc.width = gw->originalSize.width ();
158+ xwc.height = gw->originalSize.height ();
159+
160+ if (cw->mapNum() && xwcm)
161+ cw->sendSyncRequest();
162+ cw->configureXWindow (xwcm, &xwc);
163+ gw->currentSize = CompRect ();
164+ gw->pointerBufDx = 0;
165+ gw->pointerBufDy = 0;
166+ gw->isGridSemiMaximized = false;
167 gw->isGridResized = false;
168+ if (cw->state () & MAXIMIZE_STATE)
169+ cw->maximize(0);
170 gw->resizeCount = 0;
171 gw->lastTarget = GridUnknown;
172
173@@ -1001,7 +1035,7 @@
174 GRID_WINDOW (screen->findWindow
175 (CompOption::getIntOptionNamed (o, "window")));
176 gw->isGridResized = false;
177- gw->isGridMaximized = false;
178+ gw->isGridSemiMaximized = false;
179 gw->resizeCount = 0;
180 }
181
182@@ -1164,7 +1198,7 @@
183 gWindow (GLWindow::get(window)),
184 gScreen (GridScreen::get (screen)),
185 isGridResized (false),
186- isGridMaximized (false),
187+ isGridSemiMaximized (false),
188 grabMask (0),
189 pointerBufDx (0),
190 pointerBufDy (0),
191
192=== modified file 'plugins/grid/src/grid.h'
193--- plugins/grid/src/grid.h 2013-01-18 18:10:07 +0000
194+++ plugins/grid/src/grid.h 2013-01-23 06:20:25 +0000
195@@ -182,7 +182,7 @@
196 GridScreen *gScreen;
197
198 bool isGridResized;
199- bool isGridMaximized;
200+ bool isGridSemiMaximized;
201 unsigned int grabMask;
202 int pointerBufDx;
203 int pointerBufDy;

Subscribers

People subscribed via source and target branches