Merge lp:~mc-return/compiz/compiz.merge-fix1101446-and-1101618-and-other-improvements into lp:compiz/0.9.11

Proposed by MC Return
Status: Work in progress
Proposed branch: lp:~mc-return/compiz/compiz.merge-fix1101446-and-1101618-and-other-improvements
Merge into: lp:compiz/0.9.11
Diff against target: 583 lines (+135/-121)
3 files modified
plugins/grid/src/grabhandler/include/grabhandler.h (+2/-2)
plugins/grid/src/grid.cpp (+124/-117)
plugins/grid/src/grid.h (+9/-2)
To merge this branch: bzr merge lp:~mc-return/compiz/compiz.merge-fix1101446-and-1101618-and-other-improvements
Reviewer Review Type Date Requested Status
Compiz Maintainers Pending
Review via email: mp+176720@code.launchpad.net

Commit message

Grid:
Do not use xwc uninitialized (2x).
Declaration of variables outside of loops.
Initialization and assignment of variables in one line.
Improved GL_BLEND behaviour.
Merged if condition checks.
Removed redundant brackets.
Enhanced comments.
Indentation fixes.

(LP: #1101446, LP: #1101618)

Description of the change

Still WIP.

To post a comment you must log in.
3775. By MC Return

Reduced the .diff
Minor additional fixes

3776. By MC Return

Merged latest lp:compiz

Unmerged revisions

3776. By MC Return

Merged latest lp:compiz

3775. By MC Return

Reduced the .diff
Minor additional fixes

3774. By MC Return

Just disable GL_BLEND if it was disabled before

3773. By MC Return

Grid: Multiple improvements (please see main commit message for details)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/grid/src/grabhandler/include/grabhandler.h'
2--- plugins/grid/src/grabhandler/include/grabhandler.h 2012-09-25 08:28:11 +0000
3+++ plugins/grid/src/grabhandler/include/grabhandler.h 2013-07-24 17:30:37 +0000
4@@ -56,8 +56,8 @@
5
6 private:
7
8- unsigned int mMask;
9- GrabActiveFunc mGrabActive;
10+ unsigned int mMask;
11+ GrabActiveFunc mGrabActive;
12
13 };
14 }
15
16=== modified file 'plugins/grid/src/grid.cpp'
17--- plugins/grid/src/grid.cpp 2013-07-12 19:04:03 +0000
18+++ plugins/grid/src/grid.cpp 2013-07-24 17:30:37 +0000
19@@ -36,9 +36,9 @@
20 static int const CURVE_ANIMATION = 35;
21
22 void
23-GridScreen::handleCompizEvent(const char *plugin,
24- const char *event,
25- CompOption::Vector& o)
26+GridScreen::handleCompizEvent(const char *plugin,
27+ const char *event,
28+ CompOption::Vector &o)
29 {
30 if (strcmp(event, "start_viewport_switch") == 0)
31 mSwitchingVp = true;
32@@ -49,18 +49,18 @@
33 }
34
35 CompRect
36-GridScreen::slotToRect (CompWindow *w,
37- const CompRect& slot)
38+GridScreen::slotToRect (CompWindow *w,
39+ const CompRect &slot)
40 {
41 return CompRect (slot.x () + w->border ().left,
42 slot.y () + w->border ().top,
43- slot.width () - (w->border ().left + w->border ().right),
44- slot.height () - (w->border ().top + w->border ().bottom));
45+ slot.width () - (w->border ().left + w->border ().right),
46+ slot.height () - (w->border ().top + w->border ().bottom));
47 }
48
49 CompRect
50-GridScreen::constrainSize (CompWindow *w,
51- const CompRect& slot)
52+GridScreen::constrainSize (CompWindow *w,
53+ const CompRect &slot)
54 {
55 int cw, ch;
56 CompRect result = slotToRect (w, slot);
57@@ -73,6 +73,7 @@
58
59 if (dx > 0)
60 result.setX (result.x () - dx);
61+
62 if (dy > 0)
63 result.setY (result.y () - dy);
64
65@@ -93,7 +94,9 @@
66 }
67
68 int
69-applyProgress (int a, int b, float progress)
70+applyProgress (int a,
71+ int b,
72+ float progress)
73 {
74 return a < b ?
75 b - (ABS (a - b) * progress) :
76@@ -118,27 +121,26 @@
77 }
78
79 bool
80-GridScreen::initiateCommon (CompAction *action,
81- CompAction::State state,
82- CompOption::Vector &option,
83- unsigned int where,
84- bool resize,
85- bool key)
86+GridScreen::initiateCommon (CompAction *action,
87+ CompAction::State state,
88+ CompOption::Vector &option,
89+ unsigned int where,
90+ bool resize,
91+ bool key)
92 {
93- CompWindow *cw = 0;
94-
95- Window xid = CompOption::getIntOptionNamed (option, "window");
96- cw = screen->findWindow (xid);
97+ Window xid = CompOption::getIntOptionNamed (option, "window");
98+ CompWindow *cw = screen->findWindow (xid);
99
100 if (cw)
101 {
102- XWindowChanges xwc;
103- bool maximizeH = where & (GridBottom | GridTop | GridMaximize);
104- bool maximizeV = where & (GridLeft | GridRight | GridMaximize);
105-
106- bool horzMaximizedGridPosition = where & (GridTop | GridBottom);
107+ XWindowChanges xwc = XWINDOWCHANGES_INIT;
108+
109+ bool maximizeH = where & (GridBottom | GridTop | GridMaximize);
110+ bool maximizeV = where & (GridLeft | GridRight | GridMaximize);
111+
112+ bool horzMaximizedGridPosition = where & (GridTop | GridBottom);
113 bool vertMaximizedGridPosition = where & (GridLeft | GridRight);
114- bool anyMaximizedGridPosition = horzMaximizedGridPosition ||
115+ bool anyMaximizedGridPosition = horzMaximizedGridPosition ||
116 vertMaximizedGridPosition ||
117 where & GridMaximize;
118
119@@ -187,7 +189,7 @@
120 * have to worry about them. Don't mark the window as a
121 * gridded one.
122 */
123- gw->isGridResized = false;
124+ gw->isGridResized = false;
125 gw->isGridHorzMaximized = false;
126 gw->isGridVertMaximized = false;
127
128@@ -251,7 +253,7 @@
129 gw->lastTarget & where)
130 {
131 int slotWidth25 = workarea.width () / 4;
132- int slotWidth33 = (workarea.width () / 3) + cw->border ().left;
133+ int slotWidth33 = workarea.width () / 3 + cw->border ().left;
134 int slotWidth17 = slotWidth33 - slotWidth25;
135 int slotWidth66 = workarea.width () - slotWidth33;
136 int slotWidth75 = workarea.width () - slotWidth25;
137@@ -388,29 +390,29 @@
138 /* First restore the window to its original size */
139 XWindowChanges rwc;
140
141- rwc.x = gw->originalSize.x ();
142- rwc.y = gw->originalSize.y ();
143+ rwc.x = gw->originalSize.x ();
144+ rwc.y = gw->originalSize.y ();
145 rwc.width = gw->originalSize.width ();
146 rwc.height = gw->originalSize.height ();
147
148 cw->configureXWindow (CWX | CWY | CWWidth | CWHeight, &rwc);
149
150- /* GridLeft || GridRight */
151+ /* GridLeft || GridRight == isGridVertMaximized */
152 if (vertMaximizedGridPosition)
153 {
154 gw->isGridVertMaximized = true;
155 gw->isGridHorzMaximized = false;
156- gw->isGridResized = false;
157+ gw->isGridResized = false;
158
159 /* Semi-maximize the window vertically */
160 cw->maximize (CompWindowStateMaximizedVertMask);
161 }
162- /* GridTop || GridBottom */
163+ /* GridTop || GridBottom == isGridHorzMaximized */
164 else /* (horzMaximizedGridPosition) */
165 {
166 gw->isGridHorzMaximized = true;
167 gw->isGridVertMaximized = false;
168- gw->isGridResized = false;
169+ gw->isGridResized = false;
170
171 /* Semi-maximize the window horizontally */
172 cw->maximize (CompWindowStateMaximizedHorzMask);
173@@ -425,14 +427,14 @@
174 }
175 else /* GridCorners || GridCenter */
176 {
177- gw->isGridResized = true;
178+ gw->isGridResized = true;
179 gw->isGridHorzMaximized = false;
180 gw->isGridVertMaximized = false;
181 }
182 }
183 else /* if (optionGetCycleSizes ()) */
184 {
185- gw->isGridResized = true;
186+ gw->isGridResized = true;
187 gw->isGridHorzMaximized = false;
188 gw->isGridVertMaximized = false;
189 }
190@@ -445,7 +447,7 @@
191 (gw->window->border ().top +
192 gw->window->border ().bottom);
193
194- xwc.width += dw;
195+ xwc.width += dw;
196 xwc.height += dh;
197
198 /* Make window the size that we want */
199@@ -482,14 +484,13 @@
200 const GLMatrix &transform,
201 CompOutput *output)
202 {
203- CompRect rect;
204- GLMatrix sTransform (transform);
205- std::vector<Animation>::iterator iter;
206- GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
207- GLfloat vertexData[12];
208- GLushort colorData[4];
209- GLushort *color;
210- GLboolean isBlendingEnabled;
211+ CompRect rect;
212+ GLMatrix sTransform (transform);
213+ GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
214+ GLfloat vertexData[12];
215+ GLushort colorData[4];
216+ GLushort *color;
217+ float curve, alpha;
218
219 const float MaxUShortFloat = std::numeric_limits <unsigned short>::max ();
220
221@@ -500,15 +501,18 @@
222
223 sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
224
225- glGetBooleanv (GL_BLEND, &isBlendingEnabled);
226- glEnable (GL_BLEND);
227-
228- for (iter = animations.begin (); iter != animations.end () && animating; ++iter)
229+ GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
230+
231+ if (!glBlendEnabled)
232+ glEnable (GL_BLEND);
233+
234+ for (std::vector<Animation>::iterator iter = animations.begin ();
235+ iter != animations.end () && animating; ++iter)
236 {
237- Animation& anim = *iter;
238+ Animation &anim = *iter;
239
240- float curve = powf (CURVE_ANIMATION, -anim.progress);
241- float alpha = (optionGetFillColorAlpha () / MaxUShortFloat) * anim.opacity;
242+ curve = powf (CURVE_ANIMATION, -anim.progress);
243+ alpha = (optionGetFillColorAlpha () / MaxUShortFloat) * anim.opacity;
244 color = optionGetFillColor ();
245
246 colorData[0] = alpha * color[0];
247@@ -542,7 +546,7 @@
248 /* Set outline rect smaller to avoid damage issues */
249 anim.currentRect.setGeometry (anim.currentRect.x () + 1,
250 anim.currentRect.y () + 1,
251- anim.currentRect.width () - 2,
252+ anim.currentRect.width () - 2,
253 anim.currentRect.height () - 2);
254
255 /* draw outline */
256@@ -610,7 +614,7 @@
257 /* Set outline rect smaller to avoid damage issues */
258 rect.setGeometry (rect.x () + 1,
259 rect.y () + 1,
260- rect.width () - 2,
261+ rect.width () - 2,
262 rect.height () - 2);
263
264 /* draw outline */
265@@ -641,7 +645,7 @@
266 streamingBuffer->render (sTransform);
267 }
268
269- if (!isBlendingEnabled)
270+ if (!glBlendEnabled)
271 glDisable (GL_BLEND);
272 }
273
274@@ -672,7 +676,7 @@
275 }
276
277 unsigned int mask;
278- int type;
279+ int type;
280 };
281 }
282
283@@ -754,8 +758,6 @@
284 void
285 GridScreen::handleEvent (XEvent *event)
286 {
287- CompWindow *w;
288-
289 screen->handleEvent (event);
290
291 if (event->type != MotionNotify || !mGrabWindow)
292@@ -828,9 +830,8 @@
293
294 if (lastEdge != edge)
295 {
296- bool check = false;
297+ lastSlot = desiredSlot;
298 unsigned int target = typeToMask (edgeToGridType ());
299- lastSlot = desiredSlot;
300
301 if (edge == NoEdge || target == GridUnknown)
302 desiredSlot.setGeometry (0, 0, 0, 0);
303@@ -838,7 +839,7 @@
304 if (cScreen)
305 cScreen->damageRegion (desiredSlot);
306
307- check = initiateCommon (NULL, 0, o, target, false, false);
308+ bool check = initiateCommon (NULL, 0, o, target, false, false);
309
310 if (cScreen)
311 cScreen->damageRegion (desiredSlot);
312@@ -856,13 +857,13 @@
313 if (cw)
314 {
315 animations.push_back (Animation ());
316- int current = animations.size () - 1;
317- animations.at (current).fromRect = cw->serverBorderRect ();
318- animations.at (current).currentRect = cw->serverBorderRect ();
319- animations.at (current).duration = optionGetAnimationDuration ();
320- animations.at (current).timer = animations.at (current).duration;
321- animations.at (current).targetRect = desiredSlot;
322- animations.at (current).window = cw->id();
323+ int current = animations.size () - 1;
324+ animations.at (current).fromRect = cw->serverBorderRect ();
325+ animations.at (current).currentRect = cw->serverBorderRect ();
326+ animations.at (current).duration = optionGetAnimationDuration ();
327+ animations.at (current).timer = animations.at (current).duration;
328+ animations.at (current).targetRect = desiredSlot;
329+ animations.at (current).window = cw->id();
330
331 if (lastEdge == NoEdge || !animating)
332 {
333@@ -879,7 +880,7 @@
334 lastEdge = edge;
335 }
336
337- w = screen->findWindow (CompOption::getIntOptionNamed (o, "window"));
338+ CompWindow *w = screen->findWindow (CompOption::getIntOptionNamed (o, "window"));
339
340 if (w)
341 {
342@@ -898,18 +899,18 @@
343 }
344
345 void
346-GridWindow::validateResizeRequest (unsigned int &xwcm,
347+GridWindow::validateResizeRequest (unsigned int &xwcm,
348 XWindowChanges *xwc,
349- unsigned int source)
350+ unsigned int source)
351 {
352 window->validateResizeRequest (xwcm, xwc, source);
353
354 /* Don't allow non-pagers to change
355 * the size of the window, the user
356 * specified this size */
357- if (isGridHorzMaximized || isGridVertMaximized)
358- if (source != ClientTypePager)
359- xwcm = 0;
360+ if ((isGridHorzMaximized || isGridVertMaximized) &&
361+ source != ClientTypePager)
362+ xwcm = 0;
363 }
364
365 void
366@@ -963,13 +964,15 @@
367 }
368
369 gScreen->lastResizeEdge = gScreen->edge;
370- gScreen->edge = NoEdge;
371+ gScreen->edge = NoEdge;
372
373 window->ungrabNotify ();
374 }
375
376 void
377-GridWindow::moveNotify (int dx, int dy, bool immediate)
378+GridWindow::moveNotify (int dx,
379+ int dy,
380+ bool immediate)
381 {
382 window->moveNotify (dx, dy, immediate);
383
384@@ -1015,15 +1018,15 @@
385 {
386 if (isGridHorzMaximized)
387 {
388- window->saveMask () |= CWY | CWHeight;
389- window->saveWc ().y = originalSize.y ();
390- window->saveWc ().height = originalSize.height ();
391+ window->saveMask () |= CWY | CWHeight;
392+ window->saveWc ().y = originalSize.y ();
393+ window->saveWc ().height = originalSize.height ();
394 }
395 else if (isGridVertMaximized)
396 {
397- window->saveMask () |= CWX | CWWidth;
398- window->saveWc ().x = originalSize.x ();
399- window->saveWc ().width = originalSize.width ();
400+ window->saveMask () |= CWX | CWWidth;
401+ window->saveWc ().x = originalSize.x ();
402+ window->saveWc ().width = originalSize.width ();
403 }
404 }
405
406@@ -1055,8 +1058,6 @@
407 CompAction::State state,
408 CompOption::Vector &option)
409 {
410- XWindowChanges xwc;
411- int xwcm = 0;
412 CompWindow *cw = screen->findWindow (screen->activeWindow ());
413
414 if (!cw)
415@@ -1064,6 +1065,9 @@
416
417 GRID_WINDOW (cw);
418
419+ XWindowChanges xwc = XWINDOWCHANGES_INIT;
420+ int xwcm = 0;
421+
422 /* We have nothing to do here */
423 if (!gw->isGridResized &&
424 !gw->isGridVertMaximized &&
425@@ -1109,11 +1113,16 @@
426 {
427 /* The windows x-center is different in this case. */
428 if (optionGetSnapbackWindows ())
429- xwc.x = pointerX - (gw->originalSize.width () / 2);
430+ {
431+ xwc.x = pointerX - gw->originalSize.width () / 2;
432+ xwc.y = pointerY + cw->border ().top / 2;
433+ }
434 else /* the user does not want the original size back */
435- xwc.x = pointerX - gw->currentSize.width () / 2;
436-
437- xwc.y = pointerY + cw->border ().top / 2;
438+ {
439+ /* this one is quite tricky to get right */
440+ xwc.x = pointerX - gw->pointerBufDx - gw->currentSize.width () / 2;
441+ xwc.y = pointerY - gw->pointerBufDy + cw->border ().top / 2;
442+ }
443 }
444 else if (cw->grabbed () && screen->grabExist ("expo"))
445 {
446@@ -1158,9 +1167,9 @@
447
448 cw->configureXWindow (xwcm, &xwc);
449
450- gw->currentSize = CompRect ();
451- gw->pointerBufDx = 0;
452- gw->pointerBufDy = 0;
453+ gw->currentSize = CompRect ();
454+ gw->pointerBufDx = 0;
455+ gw->pointerBufDy = 0;
456
457 if (cw->state () & MAXIMIZE_STATE)
458 cw->maximize(0);
459@@ -1174,9 +1183,8 @@
460 void
461 GridScreen::preparePaint (int msSinceLastPaint)
462 {
463- std::vector<Animation>::iterator iter;
464-
465- for (iter = animations.begin (); iter != animations.end (); ++iter)
466+ for (std::vector<Animation>::iterator iter = animations.begin ();
467+ iter != animations.end (); ++iter)
468 {
469 Animation& anim = *iter;
470 anim.timer -= msSinceLastPaint;
471@@ -1216,9 +1224,8 @@
472 void
473 GridScreen::donePaint ()
474 {
475- std::vector<Animation>::iterator iter;
476-
477- for (iter = animations.begin (); iter != animations.end ();)
478+ for (std::vector<Animation>::iterator iter = animations.begin ();
479+ iter != animations.end ();)
480 {
481 Animation& anim = *iter;
482
483@@ -1255,16 +1262,16 @@
484
485 Animation::Animation ()
486 {
487- progress = 0.0f;
488- fromRect = CompRect (0, 0, 0, 0);
489- targetRect = CompRect (0, 0, 0, 0);
490+ progress = 0.0f;
491+ fromRect = CompRect (0, 0, 0, 0);
492+ targetRect = CompRect (0, 0, 0, 0);
493 currentRect = CompRect (0, 0, 0, 0);
494- opacity = 0.0f;
495- timer = 0.0f;
496- duration = 0;
497- complete = false;
498- fadingOut = false;
499- window = 0;
500+ opacity = 0.0f;
501+ timer = 0.0f;
502+ duration = 0;
503+ complete = false;
504+ fadingOut = false;
505+ window = 0;
506 }
507
508 GridScreen::GridScreen (CompScreen *screen) :
509@@ -1353,23 +1360,23 @@
510 }
511
512 bool
513-GridWindow::glPaint (const GLWindowPaintAttrib& attrib, const GLMatrix& matrix,
514- const CompRegion& region, const unsigned int mask)
515+GridWindow::glPaint (const GLWindowPaintAttrib &attrib,
516+ const GLMatrix &matrix,
517+ const CompRegion &region,
518+ const unsigned int mask)
519 {
520 bool status = gWindow->glPaint (attrib, matrix, region, mask);
521
522- std::vector<Animation>::iterator iter;
523-
524- for (iter = gScreen->animations.begin ();
525+ for (std::vector<Animation>::iterator iter = gScreen->animations.begin ();
526 iter != gScreen->animations.end () && gScreen->animating; ++iter)
527 {
528- Animation& anim = *iter;
529+ Animation &anim = *iter;
530
531 if (anim.timer > 0.0f && anim.window == window->id())
532 {
533- GLWindowPaintAttrib wAttrib(attrib);
534- GLMatrix wTransform (matrix);
535- unsigned int wMask(mask);
536+ GLWindowPaintAttrib wAttrib (attrib);
537+ GLMatrix wTransform (matrix);
538+ unsigned int wMask (mask);
539
540 float curve = powf (CURVE_ANIMATION, -anim.progress);
541 wAttrib.opacity *= curve;
542@@ -1408,8 +1415,8 @@
543 bool
544 GridPluginVTable::init ()
545 {
546- if (CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) &&
547- CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) &&
548+ if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) &&
549+ CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) &&
550 CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
551 return true;
552
553
554=== modified file 'plugins/grid/src/grid.h'
555--- plugins/grid/src/grid.h 2013-04-30 00:18:41 +0000
556+++ plugins/grid/src/grid.h 2013-07-24 17:30:37 +0000
557@@ -30,6 +30,8 @@
558
559 #include "grid_options.h"
560
561+#define XWINDOWCHANGES_INIT {0, 0, 0, 0, 0, None, 0}
562+
563 namespace GridWindowType
564 {
565 static const unsigned int GridUnknown = (1 << 0);
566@@ -224,11 +226,16 @@
567 const CompRegion &,
568 unsigned int );
569
570- void grabNotify (int, int, unsigned int, unsigned int);
571+ void grabNotify (int ,
572+ int ,
573+ unsigned int ,
574+ unsigned int );
575
576 void ungrabNotify ();
577
578- void moveNotify (int, int, bool);
579+ void moveNotify (int ,
580+ int ,
581+ bool );
582
583 void stateChangeNotify (unsigned int);
584

Subscribers

People subscribed via source and target branches

to all changes: