Merge lp:~smspillaz/compiz-core/compiz-core.place-plugin-use-screen-size-change into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Merged
Merged at revision: 2942
Proposed branch: lp:~smspillaz/compiz-core/compiz-core.place-plugin-use-screen-size-change
Merge into: lp:compiz-core/0.9.5
Diff against target: 666 lines (+154/-299)
8 files modified
cmake/CompizPlugin.cmake (+1/-0)
include/core/screen.h (+2/-2)
plugins/place/src/place.cpp (+110/-285)
plugins/place/src/place.h (+26/-4)
plugins/place/src/screen-size-change/src/screen-size-change.cpp (+2/-2)
plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp (+2/-0)
src/CMakeLists.txt (+7/-2)
src/screen.cpp (+4/-4)
To merge this branch: bzr merge lp:~smspillaz/compiz-core/compiz-core.place-plugin-use-screen-size-change
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Review via email: mp+89550@code.launchpad.net

Description of the change

Actually use the screen size change handling codepath in the place plugin

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmake/CompizPlugin.cmake'
2--- cmake/CompizPlugin.cmake 2012-01-12 06:48:58 +0000
3+++ cmake/CompizPlugin.cmake 2012-01-21 17:25:26 +0000
4@@ -404,6 +404,7 @@
5 ${${_PLUGIN}_PKG_LIBRARIES}
6 ${${_PLUGIN}_LIBRARIES}
7 ${${_PLUGIN}_MOD_LIBRARIES}
8+ compiz_core
9 )
10
11 install (
12
13=== modified file 'include/core/screen.h'
14--- include/core/screen.h 2011-09-19 12:54:22 +0000
15+++ include/core/screen.h 2012-01-21 17:25:26 +0000
16@@ -330,9 +330,9 @@
17
18 int outputDeviceForGeometry (const CompWindow::Geometry& gm);
19
20- CompPoint vp ();
21+ const CompPoint & vp () const;
22
23- CompSize vpSize ();
24+ const CompSize & vpSize () const;
25
26 int desktopWindowCount ();
27 unsigned int activeNum () const;
28
29=== modified file 'plugins/place/src/place.cpp'
30--- plugins/place/src/place.cpp 2011-05-07 17:31:52 +0000
31+++ plugins/place/src/place.cpp 2012-01-21 17:25:26 +0000
32@@ -45,256 +45,92 @@
33 screen->updateSupportedWmHints ();
34 }
35
36+CompWindowList
37+compiz::place::collectStrutWindows (const CompWindowList &all)
38+{
39+ CompWindowList l;
40+
41+ foreach (CompWindow *w, all)
42+ {
43+ if (!w->managed () ||
44+ w->overrideRedirect ())
45+ continue;
46+
47+ if (w->struts ())
48+ l.push_back (w);
49+ }
50+
51+ return l;
52+}
53+
54+
55 void
56-PlaceScreen::doHandleScreenSizeChange (bool firstPass,
57- int newWidth,
58+PlaceScreen::doHandleScreenSizeChange (int newWidth,
59 int newHeight)
60 {
61- int vpX, vpY, shiftX, shiftY;
62- CompRect extents;
63- XWindowChanges xwc;
64- CompRect vpRelRect, winRect, workArea;
65- int pivotX, pivotY;
66- unsigned int mask;
67- int curVpOffsetX = screen->vp ().x () * screen->width ();
68- int curVpOffsetY = screen->vp ().y () * screen->height ();
69-
70- if (firstPass)
71- mStrutWindowCount = 0;
72- else
73- if (mResChangeFallbackHandle.active ())
74- {
75- mResChangeFallbackHandle.stop ();
76- }
77-
78 foreach (CompWindow *w, screen->windows ())
79 {
80 if (!w->managed ())
81 continue;
82
83- PLACE_WINDOW (w);
84-
85- if (firstPass)
86- {
87- /* count the windows that have struts */
88- if (w->struts ())
89- mStrutWindowCount++;
90-
91- /* for maximized/fullscreen windows, keep window coords before
92- * screen resize, as they are sometimes automaticall changed
93- * before the 2nd pass */
94-
95- if (w->type () & CompWindowTypeFullscreenMask ||
96- (w->state () & (CompWindowStateMaximizedVertMask |
97- CompWindowStateMaximizedHorzMask)))
98- {
99- pw->mPrevServer.set (w->serverX (), w->serverY ());
100- }
101- }
102-
103 if (w->wmType () & (CompWindowTypeDockMask |
104 CompWindowTypeDesktopMask))
105- {
106- continue;
107- }
108-
109- /* Also in the first pass, we save the rectangle of those windows that
110- * don't already have a saved one. So, skip those tat do. */
111-
112- if (firstPass && pw->mSavedOriginal)
113- continue;
114-
115- winRect = ((CompRect) w->serverGeometry ());
116-
117-
118- pivotX = winRect.x ();
119- pivotY = winRect.y ();
120-
121- if (w->type () & CompWindowTypeFullscreenMask ||
122- (w->state () & (CompWindowStateMaximizedVertMask |
123- CompWindowStateMaximizedHorzMask)))
124- {
125- if (w->saveMask () & CWX)
126- winRect.setX (w->saveWc ().x);
127-
128- if (w->saveMask () & CWY)
129- winRect.setY (w->saveWc ().y);
130-
131- if (w->saveMask () & CWWidth)
132- winRect.setWidth (w->saveWc ().width);
133-
134- if (w->saveMask () & CWHeight)
135- winRect.setHeight (w->saveWc ().height);
136-
137- pivotX = pw->mPrevServer.x ();
138- pivotY = pw->mPrevServer.y ();
139- }
140-
141- /* calculate target vp x, y index for window's pivot point */
142- vpX = pivotX / newWidth;
143- if (pivotX < 0)
144- vpX -= 1;
145- vpY = pivotY / newHeight;
146- if (pivotY < 0)
147- vpY -= 1;
148-
149- /* if window's target vp is to the left of the leftmost viewport on that
150- row, assign its target vp column as 0 (-s->x rel. to current vp) */
151- if (screen->vp ().x () + vpX < 0)
152- vpX = -screen->vp ().x ();
153-
154- /* if window's target vp is above the topmost viewport on that column,
155- assign its target vp row as 0 (-s->y rel. to current vp) */
156- if (screen->vp ().y () + vpY < 0)
157- vpY = -screen->vp ().y ();
158-
159- if (pw->mSavedOriginal)
160- {
161- /* set position/size to saved original rectangle */
162- vpRelRect = pw->mOrigVpRelRect;
163-
164- xwc.x = pw->mOrigVpRelRect.x () + vpX * screen->width ();
165- xwc.y = pw->mOrigVpRelRect.y () + vpY * screen->height ();
166- }
167- else
168- {
169- /* set position/size to window's current rectangle
170- (with position relative to target viewport) */
171- vpRelRect.setX (winRect.x () - vpX * mPrevSize.width ());
172- vpRelRect.setY (winRect.y () - vpY * mPrevSize.height ());
173- vpRelRect.setWidth (winRect.width ());
174- vpRelRect.setHeight (winRect.height ());
175-
176- xwc.x = winRect.x ();
177- xwc.y = winRect.y ();
178-
179- shiftX = vpX * (newWidth - screen->width ());
180- shiftY = vpY * (newWidth - screen->height ());
181-
182- /* if coords. relative to viewport are outside new viewport area,
183- shift window left/up so that it falls inside */
184- if (vpRelRect.x () >= screen->width ())
185- shiftX -= vpRelRect.x () - (screen->width () - 1);
186- if (vpRelRect.y () >= screen->height ())
187- shiftY -= vpRelRect.y () - (screen->height () - 1);
188-
189- if (shiftX)
190- xwc.x += shiftX;
191-
192- if (shiftY)
193- xwc.y += shiftY;
194- }
195-
196- mask = CWX | CWY | CWWidth | CWHeight;
197- xwc.width = vpRelRect.width ();
198- xwc.height = vpRelRect.height ();
199-
200- /* Handle non-(0,0) current viewport by shifting by curVpOffsetX,Y,
201- and bring window to (0,0) by shifting by minus its vp offset */
202-
203- xwc.x += curVpOffsetX - (screen->vp ().x () + vpX) * screen->width ();
204- xwc.y += curVpOffsetY - (screen->vp ().y () + vpY) * screen->height ();
205-
206- workArea =
207- pw->doValidateResizeRequest (mask, &xwc, FALSE, FALSE);
208-
209- xwc.x -= curVpOffsetX - (screen->vp ().x () + vpX) * screen->width ();
210- xwc.y -= curVpOffsetY - (screen->vp ().y () + vpY) * screen->height ();
211-
212- /* Check if the new coordinates are different than current position and
213- size. If not, we can clear the corresponding mask bits. */
214- if (xwc.x == winRect.x ())
215- mask &= ~CWX;
216-
217- if (xwc.y == winRect.y ())
218- mask &= ~CWY;
219-
220- if (xwc.width == winRect.width ())
221- mask &= ~CWWidth;
222-
223- if (xwc.height == winRect.height ())
224- mask &= ~CWHeight;
225-
226- if (!pw->mSavedOriginal)
227- {
228- if (mask)
229- {
230- /* save window geometry (relative to viewport) so that it
231- can be restored later */
232- pw->mSavedOriginal = TRUE;
233- pw->mOrigVpRelRect = vpRelRect;
234- }
235- }
236- else if (pw->mOrigVpRelRect.x () + vpX * newWidth == xwc.x &&
237- pw->mOrigVpRelRect.y () + vpY * newHeight == xwc.y &&
238- pw->mOrigVpRelRect.width () == xwc.width &&
239- pw->mOrigVpRelRect.height () == xwc.height)
240- {
241- /* if size and position is back to original, clear saved rect */
242- pw->mSavedOriginal = FALSE;
243- }
244-
245- if (firstPass) /* if first pass, don't actually move the window */
246- continue;
247-
248- /* for maximized/fullscreen windows, update saved pos/size */
249- if (w->type () & CompWindowTypeFullscreenMask ||
250- (w->state () & (CompWindowStateMaximizedVertMask |
251- CompWindowStateMaximizedHorzMask)))
252- {
253- if (mask & CWX)
254- {
255- w->saveWc ().x = xwc.x;
256- w->saveMask () |= CWX;
257- }
258- if (mask & CWY)
259- {
260- w->saveWc ().y = xwc.y;
261- w->saveMask () |= CWY;
262- }
263- if (mask & CWWidth)
264- {
265- w->saveWc ().width = xwc.width;
266- w->saveMask () |= CWWidth;
267- }
268- if (mask & CWHeight)
269- {
270- w->saveWc ().height = xwc.height;
271- w->saveMask () |= CWHeight;
272- }
273-
274- if (w->type () & CompWindowTypeFullscreenMask)
275- {
276- mask |= CWX | CWY | CWWidth | CWHeight;
277- xwc.x = vpX * screen->width ();
278- xwc.y = vpY * screen->height ();
279- xwc.width = screen->width ();
280- xwc.height = screen->height ();
281- }
282- else
283- {
284- if (w->state () & CompWindowStateMaximizedHorzMask)
285- {
286- mask |= CWX | CWWidth;
287- xwc.x = vpX * screen->width () + workArea.x () + w->border ().left;
288- xwc.width = workArea.width () -
289- (2 * w->serverGeometry ().border () +
290- w->border ().left + w->border ().right);
291- }
292- if (w->state () & CompWindowStateMaximizedVertMask)
293- {
294- mask |= CWY | CWHeight;
295- xwc.y = vpY * screen->height () + workArea.y () + w->border ().top;
296- xwc.height = workArea.height () -
297- (2 * w->serverGeometry ().border () +
298- w->border ().top + w->border ().bottom);
299- }
300- }
301- }
302- if (mask)
303- {
304- /* actually move/resize window in directions given by mask */
305- w->configureXWindow (mask, &xwc);
306+ continue;
307+
308+ PlaceWindow::get (w)->adjustForSize (mPrevSize, CompSize (newWidth, newHeight));
309+ }
310+}
311+
312+const compiz::window::Geometry &
313+PlaceWindow::getGeometry () const
314+{
315+ return window->serverGeometry ();
316+}
317+
318+const CompPoint &
319+PlaceWindow::getViewport () const
320+{
321+ return screen->vp ();
322+}
323+
324+const CompRect &
325+PlaceWindow::getWorkarea (const compiz::window::Geometry &g) const
326+{
327+ return screen->getWorkareaForOutput (screen->outputDeviceForGeometry (g));
328+}
329+
330+const compiz::window::extents::Extents &
331+PlaceWindow::getExtents () const
332+{
333+ return window->border ();
334+}
335+
336+void
337+PlaceWindow::applyGeometry (compiz::window::Geometry &ng,
338+ compiz::window::Geometry &og)
339+{
340+ CompRect workArea = screen->getWorkareaForOutput (
341+ screen->outputDeviceForGeometry (og));
342+
343+ XWindowChanges xwc;
344+ unsigned int mask = og.changeMask (ng);
345+
346+ xwc.x = ng.x ();
347+ xwc.y = ng.y ();
348+ xwc.width = ng.width ();
349+ xwc.height = ng.height ();
350+ xwc.border_width = ng.border ();
351+
352+ window->configureXWindow (mask, &xwc);
353+
354+ if ((window->actions () & MAXIMIZE_STATE) == MAXIMIZE_STATE &&
355+ (window->mwmDecor () & (MwmDecorAll | MwmDecorTitle)) &&
356+ !(window->state () & CompWindowStateFullscreenMask))
357+ {
358+ if (og.width () >= workArea.width () &&
359+ og.height () >= workArea.height ())
360+ {
361+ sendMaximizationRequest ();
362 }
363 }
364 }
365@@ -304,12 +140,12 @@
366 int height)
367 {
368 /* If countdown is not finished yet (i.e. at least one struct window didn't
369- * update its struts), reset the count down and do the 2nd pass here */
370+ * update its struts), reset the count down and move windows around here */
371
372 if (mStrutWindowCount > 0) /* no windows with struts found */
373 {
374 mStrutWindowCount = 0;
375- doHandleScreenSizeChange (false, width, height);
376+ doHandleScreenSizeChange (width, height);
377 }
378
379 return false;
380@@ -319,45 +155,44 @@
381 PlaceScreen::handleScreenSizeChange (int width,
382 int height)
383 {
384- CompRect extents;
385-
386- if (screen->width () == width && screen->height () == height)
387+ if (mPrevSize == CompSize (width, height))
388 return;
389
390- mPrevSize.setWidth (screen->width ());
391- mPrevSize.setHeight (screen->height ());
392-
393- if (mResChangeFallbackHandle.active ())
394- mResChangeFallbackHandle.stop ();
395-
396- doHandleScreenSizeChange (true, width, height);
397-
398- if (mStrutWindowCount == 0) /* no windows with struts found */
399- {
400- mResChangeFallbackHandle.stop ();
401- /* do the 2nd pass right here instead of handleEvent */
402-
403- doHandleScreenSizeChange (false, width, height);
404- }
405+ mResChangeFallbackHandle.stop ();
406+ mStrutWindows = compiz::place::collectStrutWindows (screen->windows ());
407+
408+ /* Don't wait for strut windows to update if there are none */
409+ if (mStrutWindows.empty ())
410+ doHandleScreenSizeChange (width, height);
411 else
412 {
413- mResChangeFallbackHandle.setCallback (
414- boost::bind (&PlaceScreen::handleScreenSizeChangeFallback,
415- this, width, height));
416+ /* Wait for windows with set struts to update their struts, but
417+ * if one of them isn't updating them, have a fallback to ignore them */
418+ mResChangeFallbackHandle.setCallback (
419+ boost::bind (&PlaceScreen::handleScreenSizeChangeFallback,
420+ this, width, height));
421 mResChangeFallbackHandle.start ();
422 }
423+
424 }
425
426 void
427 PlaceScreen::handleEvent (XEvent *event)
428 {
429+ if (event->type == ConfigureNotify &&
430+ event->xconfigure.window == screen->root ())
431+ {
432+ mPrevSize.setWidth (screen->width ());
433+ mPrevSize.setHeight (screen->height ());
434+ }
435+
436+ screen->handleEvent (event);
437+
438 switch (event->type)
439 {
440 case ConfigureNotify:
441 {
442-
443- if (event->type == ConfigureNotify &&
444- event->xconfigure.window == screen->root ())
445+ if (event->xconfigure.window == screen->root ())
446 {
447 handleScreenSizeChange (event->xconfigure.width,
448 event->xconfigure.height);
449@@ -373,23 +208,15 @@
450 w = screen->findWindow (event->xproperty.window);
451 if (w)
452 {
453+ mStrutWindows.remove (w);
454 /* Only do when handling screen size change.
455 ps->strutWindowCount is 0 at any other time */
456- if (mStrutWindowCount > 0 &&
457- w->updateStruts ())
458- {
459- mStrutWindowCount--;
460- screen->updateWorkarea ();
461-
462- /* if this was the last window with struts */
463- if (!mStrutWindowCount)
464- doHandleScreenSizeChange (false, screen->width (),
465- screen->height ()); /* 2nd pass */
466- }
467+ if (mStrutWindows.empty ())
468+ doHandleScreenSizeChange (screen->width (),
469+ screen->height ()); /* 2nd pass */
470 }
471 }
472 }
473- screen->handleEvent (event);
474 }
475
476 /* sort functions */
477@@ -441,7 +268,7 @@
478
479 PlaceWindow::PlaceWindow (CompWindow *w) :
480 PluginClassHandler<PlaceWindow, CompWindow> (w),
481- mSavedOriginal (false),
482+ compiz::place::ScreenSizeChangeObject (w->serverGeometry ()),
483 window (w),
484 ps (PlaceScreen::get (screen))
485 {
486@@ -1689,12 +1516,10 @@
487 unsigned int state,
488 unsigned int mask)
489 {
490- if (mSavedOriginal)
491- {
492- if (screen->grabExist ("move") ||
493- screen->grabExist ("resize"))
494- mSavedOriginal = false;
495- }
496+ /* Don't restore geometry if the user moved the window */
497+ if (screen->grabExist ("move") ||
498+ screen->grabExist ("resize"))
499+ unset ();
500
501 window->grabNotify (x, y, state, mask);
502 }
503
504=== modified file 'plugins/place/src/place.h'
505--- plugins/place/src/place.h 2012-01-18 16:26:45 +0000
506+++ plugins/place/src/place.h 2012-01-21 17:25:26 +0000
507@@ -30,6 +30,19 @@
508 #include <core/pluginclasshandler.h>
509
510 #include "place_options.h"
511+#include "screen-size-change.h"
512+
513+namespace compiz
514+{
515+
516+ namespace place
517+ {
518+
519+ CompWindowList collectStrutWindows (const CompWindowList &allWindows);
520+
521+ }
522+
523+}
524
525 class PlaceScreen :
526 public PluginClassHandler<PlaceScreen, CompScreen>,
527@@ -41,7 +54,7 @@
528 ~PlaceScreen ();
529
530 void handleEvent (XEvent *event);
531- void doHandleScreenSizeChange (bool, int, int);
532+ void doHandleScreenSizeChange (int, int);
533 bool handleScreenSizeChangeFallback (int width, int height);
534 void handleScreenSizeChange (int width, int height);
535 bool getPointerPosition (CompPoint &p);
536@@ -50,6 +63,7 @@
537 CompSize mPrevSize;
538 int mStrutWindowCount;
539 CompTimer mResChangeFallbackHandle;
540+ CompWindowList mStrutWindows;
541
542 Atom fullPlacementAtom;
543 };
544@@ -59,6 +73,7 @@
545
546 class PlaceWindow :
547 public PluginClassHandler<PlaceWindow, CompWindow>,
548+ public compiz::place::ScreenSizeChangeObject,
549 public WindowInterface
550 {
551 public:
552@@ -76,10 +91,17 @@
553 XWindowChanges *xwc,
554 unsigned int source);
555 void grabNotify (int, int, unsigned int, unsigned int);
556- bool mSavedOriginal;
557- CompRect mOrigVpRelRect;
558+
559 CompPoint mPrevServer;
560-
561+
562+ protected:
563+
564+ void applyGeometry (compiz::window::Geometry &ng,
565+ compiz::window::Geometry &og);
566+ const compiz::window::Geometry & getGeometry () const;
567+ const CompPoint & getViewport () const;
568+ const CompRect & getWorkarea (const compiz::window::Geometry &g) const;
569+ const compiz::window::extents::Extents & getExtents () const;
570
571 private:
572 typedef enum {
573
574=== modified file 'plugins/place/src/screen-size-change/src/screen-size-change.cpp'
575--- plugins/place/src/screen-size-change/src/screen-size-change.cpp 2012-01-20 06:27:10 +0000
576+++ plugins/place/src/screen-size-change/src/screen-size-change.cpp 2012-01-21 17:25:26 +0000
577@@ -21,6 +21,7 @@
578 */
579
580 #include "screen-size-change.h"
581+#include <stdio.h>
582
583
584 compiz::place::ScreenSizeChangeObject::ScreenSizeChangeObject (const compiz::window::Geometry &g) :
585@@ -43,6 +44,7 @@
586 int curVpOffsetY = getViewport ().y () * newSize.height ();
587
588 g = getGeometry ();
589+ compiz::window::Geometry og (g);
590
591 pivotX = g.x ();
592 pivotY = g.y ();
593@@ -117,8 +119,6 @@
594 g.setY (g.y () + curVpOffsetY - (getViewport ().y () + vpY) * newSize.height ());
595
596 unsigned int flags = 0;
597-
598- compiz::window::Geometry og (g);
599 const CompRect &workArea = getWorkarea (g);
600
601 compiz::place::clampGeometryToWorkArea (g, workArea, getExtents (), flags, newSize);
602
603=== modified file 'plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp'
604--- plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2012-01-20 06:27:10 +0000
605+++ plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2012-01-21 17:25:26 +0000
606@@ -89,6 +89,8 @@
607 MockScreenSizeChangeObject::applyGeometry (compiz::window::Geometry &n,
608 compiz::window::Geometry &o)
609 {
610+ EXPECT_EQ (mCurrentGeometry, o);
611+
612 std::cout << "DEBUG: new geometry : " << n.x () << " "
613 << n.y () << " "
614 << n.width () << " "
615
616=== modified file 'src/CMakeLists.txt'
617--- src/CMakeLists.txt 2012-01-20 15:42:52 +0000
618+++ src/CMakeLists.txt 2012-01-21 17:25:26 +0000
619@@ -77,6 +77,7 @@
620 link_directories (
621 ${COMPIZ_LINK_DIRS}
622 ${CORE_MOD_LIBRARY_DIRS}
623+ ${libdir}
624 )
625
626 add_library (compiz_core SHARED
627@@ -144,10 +145,14 @@
628
629 install (
630 TARGETS compiz_core
631+ LIBRARY DESTINATION ${COMPIZ_DESTDIR}${libdir}
632+)
633+
634+install (
635+ TARGETS compiz
636 RUNTIME DESTINATION ${COMPIZ_DESTDIR}${exec_prefix}
637- LIBRARY DESTINATION ${COMPIZ_DESTDIR}${libdir}
638- ARCHIVE DESTINATION ${COMPIZ_DESTDIR}${libdir}
639 )
640+
641 add_subdirectory(tests)
642
643 enable_coverage_report( TARGETS compiz )
644
645=== modified file 'src/screen.cpp'
646--- src/screen.cpp 2012-01-20 12:59:05 +0000
647+++ src/screen.cpp 2012-01-21 17:25:26 +0000
648@@ -4180,14 +4180,14 @@
649 return priv->screenNum;
650 }
651
652-CompPoint
653-CompScreen::vp ()
654+const CompPoint &
655+CompScreen::vp () const
656 {
657 return priv->vp;
658 }
659
660-CompSize
661-CompScreen::vpSize ()
662+const CompSize &
663+CompScreen::vpSize () const
664 {
665 return priv->vpSize;
666 }

Subscribers

People subscribed via source and target branches