Merge lp:~smspillaz/compiz-plugins-main/compiz-plugins-main.fix_939228 into lp:compiz-plugins-main

Proposed by Sam Spilsbury
Status: Rejected
Rejected by: Sam Spilsbury
Proposed branch: lp:~smspillaz/compiz-plugins-main/compiz-plugins-main.fix_939228
Merge into: lp:compiz-plugins-main
Diff against target: 455 lines (+336/-45)
8 files modified
wall/CMakeLists.txt (+4/-1)
wall/src/offset_movement/CMakeLists.txt (+57/-0)
wall/src/offset_movement/include/offset-movement.h (+41/-0)
wall/src/offset_movement/src/offset-movement.cpp (+62/-0)
wall/src/offset_movement/tests/CMakeLists.txt (+50/-0)
wall/src/offset_movement/tests/test-wall-offset-movement.cpp (+97/-0)
wall/src/wall.cpp (+22/-43)
wall/src/wall.h (+3/-1)
To merge this branch: bzr merge lp:~smspillaz/compiz-plugins-main/compiz-plugins-main.fix_939228
Reviewer Review Type Date Requested Status
Compiz Maintainers Pending
Review via email: mp+103268@code.launchpad.net

Description of the change

== Problem ==

Another arm of bug 939228 : if a window spanned two monitors it would shift around on viewport changes

== Solution ==

Take all workareas into account when calculating window shift

== test ==

included.

To post a comment you must log in.
32. By Sam Spilsbury

checkin missing files

Revision history for this message
micove (micove) wrote :

This removes "LIBRARIES dl" from commit 28 in wall/CMakeLists.txt.

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

thanks, re-adding

33. By Sam Spilsbury

Add dl

Unmerged revisions

33. By Sam Spilsbury

Add dl

32. By Sam Spilsbury

checkin missing files

31. By Sam Spilsbury

Multimonitor aware window displacement algorithm LP#939228

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'wall/CMakeLists.txt'
2--- wall/CMakeLists.txt 2012-04-24 10:17:49 +0000
3+++ wall/CMakeLists.txt 2012-04-24 14:46:31 +0000
4@@ -2,4 +2,7 @@
5
6 include (CompizPlugin)
7
8-compiz_plugin (wall PLUGINDEPS composite opengl mousepoll PKGDEPS cairo cairo-xlib-xrender LIBRARIES dl)
9+add_subdirectory (src/offset_movement)
10+include_directories (src/offset_movement/include)
11+
12+compiz_plugin (wall PLUGINDEPS composite opengl mousepoll PKGDEPS cairo cairo-xlib-xrender LIBRARIES compiz_wall_offset_movement dl)
13
14=== added directory 'wall/src/offset_movement'
15=== added file 'wall/src/offset_movement/CMakeLists.txt'
16--- wall/src/offset_movement/CMakeLists.txt 1970-01-01 00:00:00 +0000
17+++ wall/src/offset_movement/CMakeLists.txt 2012-04-24 14:46:31 +0000
18@@ -0,0 +1,57 @@
19+pkg_check_modules (
20+ GLIBMM
21+ REQUIRED
22+ glibmm-2.4 glib-2.0 compiz
23+)
24+
25+INCLUDE_DIRECTORIES (
26+ ${CMAKE_CURRENT_SOURCE_DIR}/include
27+ ${CMAKE_CURRENT_SOURCE_DIR}/src
28+
29+ ${CMAKE_SOURCE_DIR}/include
30+
31+ ${Boost_INCLUDE_DIRS}
32+
33+ ${GLIBMM_INCLUDE_DIRS}
34+)
35+
36+LINK_DIRECTORIES (${GLIBMM_LIBRARY_DIRS})
37+
38+SET (
39+ PUBLIC_HEADERS
40+)
41+
42+SET (
43+ PRIVATE_HEADERS
44+ ${CMAKE_CURRENT_SOURCE_DIR}/include/offset-movement.h
45+)
46+
47+SET(
48+ SRCS
49+ ${CMAKE_CURRENT_SOURCE_DIR}/src/offset-movement.cpp
50+)
51+
52+ADD_LIBRARY(
53+ compiz_wall_offset_movement STATIC
54+
55+ ${SRCS}
56+
57+ ${PUBLIC_HEADERS}
58+ ${PRIVATE_HEADERS}
59+)
60+
61+if (COMPIZ_BUILD_TESTING)
62+ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests )
63+endif (COMPIZ_BUILD_TESTING)
64+
65+SET_TARGET_PROPERTIES(
66+ compiz_wall_offset_movement PROPERTIES
67+ PUBLIC_HEADER "${PUBLIC_HEADERS}"
68+)
69+
70+TARGET_LINK_LIBRARIES(
71+ compiz_wall_offset_movement
72+
73+ compiz_core
74+ ${GLIBMM_LIBRARIES}
75+)
76
77=== added directory 'wall/src/offset_movement/include'
78=== added file 'wall/src/offset_movement/include/offset-movement.h'
79--- wall/src/offset_movement/include/offset-movement.h 1970-01-01 00:00:00 +0000
80+++ wall/src/offset_movement/include/offset-movement.h 2012-04-24 14:46:31 +0000
81@@ -0,0 +1,41 @@
82+/**
83+ *
84+ * Compiz wall plugin
85+ *
86+ * offset-movement.h
87+ *
88+ * Copyright (c) 2006 Robert Carr <racarr@beryl-project.org>
89+ *
90+ * Authors:
91+ * Robert Carr <racarr@beryl-project.org>
92+ * Dennis Kasprzyk <onestone@opencompositing.org>
93+ *
94+ * This program is free software; you can redistribute it and/or
95+ * modify it under the terms of the GNU General Public License
96+ * as published by the Free Software Foundation; either version 2
97+ * of the License, or (at your option) any later version.
98+ *
99+ * This program is distributed in the hope that it will be useful,
100+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
101+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102+ * GNU General Public License for more details.
103+ *
104+ **/
105+
106+#ifndef _COMPIZ_WALL_OFFSET_MOVEMENT_H
107+#define _COMPIZ_WALL_OFFSET_MOVEMENT_H
108+
109+#include <core/region.h>
110+#include <core/rect.h>
111+#include <core/point.h>
112+
113+namespace compiz
114+{
115+ namespace wall
116+ {
117+ CompPoint movementWindowOnScreen (const CompRect &serverBorderRect,
118+ const CompRegion &screenRegion);
119+ }
120+}
121+
122+#endif
123
124=== added directory 'wall/src/offset_movement/src'
125=== added file 'wall/src/offset_movement/src/offset-movement.cpp'
126--- wall/src/offset_movement/src/offset-movement.cpp 1970-01-01 00:00:00 +0000
127+++ wall/src/offset_movement/src/offset-movement.cpp 2012-04-24 14:46:31 +0000
128@@ -0,0 +1,62 @@
129+/**
130+ *
131+ * Compiz wall plugin
132+ *
133+ * offset-movement.c
134+ *
135+ * Copyright (c) 2006 Robert Carr <racarr@beryl-project.org>
136+ *
137+ * Authors:
138+ * Robert Carr <racarr@beryl-project.org>
139+ * Dennis Kasprzyk <onestone@opencompositing.org>
140+ *
141+ * This program is free software; you can redistribute it and/or
142+ * modify it under the terms of the GNU General Public License
143+ * as published by the Free Software Foundation; either version 2
144+ * of the License, or (at your option) any later version.
145+ *
146+ * This program is distributed in the hope that it will be useful,
147+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
148+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
149+ * GNU General Public License for more details.
150+ *
151+ **/
152+
153+#include "offset-movement.h"
154+
155+CompPoint
156+compiz::wall::movementWindowOnScreen (const CompRect &serverBorderRect,
157+ const CompRegion &screenRegion)
158+{
159+ CompRegion sbrRegion (static_cast <const CompRect &> (serverBorderRect));
160+
161+ /* If the window would be partially offscreen
162+ * after it was moved then we should move it back
163+ * so that it is completely onscreen, since we moved
164+ * from mostly offscreen on B to mostly onscreen on A,
165+ * the user should be able to see their selected window */
166+ CompRegion inter = sbrRegion.intersected (screenRegion);
167+ CompRegion rem = sbrRegion - screenRegion;
168+
169+ int dx = 0;
170+ int dy = 0;
171+
172+ for (std::vector <CompRect>::const_iterator it = rem.rects ().begin ();
173+ it != rem.rects ().end ();
174+ it++)
175+ {
176+ const CompRect &r = *it;
177+
178+ if (r.x1 () >= inter.boundingRect ().x2 ())
179+ dx -= r.width ();
180+ else if (r.x2 () <= inter.boundingRect ().x1 ())
181+ dx += r.width ();
182+
183+ if (r.y1 () >= inter.boundingRect ().y2 ())
184+ dy -= r.height ();
185+ else if (r.y2 () <= inter.boundingRect ().y1 ())
186+ dy += r.height ();
187+ }
188+
189+ return CompPoint (dx, dy);
190+}
191
192=== added directory 'wall/src/offset_movement/tests'
193=== added file 'wall/src/offset_movement/tests/CMakeLists.txt'
194--- wall/src/offset_movement/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
195+++ wall/src/offset_movement/tests/CMakeLists.txt 2012-04-24 14:46:31 +0000
196@@ -0,0 +1,50 @@
197+# Build Google Test and make its headers known
198+find_package (GTest)
199+
200+if (NOT GTEST_FOUND)
201+
202+ # Check for google test and build it locally
203+ set (GTEST_ROOT_DIR
204+ "/usr/src/gtest" # Default value, adjustable by user with e.g., ccmake
205+ CACHE
206+ PATH
207+ "Path to Google test srcs"
208+ )
209+
210+ find_path (GTEST_INCLUDE_DIR gtest/gtest.h)
211+
212+ if (GTEST_INCLUDE_DIR)
213+ #FIXME - hardcoded is bad!
214+ add_subdirectory (${GTEST_ROOT_DIR}
215+ gtest)
216+ endif(GTEST_INCLUDE_DIR)
217+
218+ set (GTEST_BOTH_LIBRARIES gtest gtest_main)
219+ set (GTEST_FOUND TRUE)
220+
221+endif (NOT GTEST_FOUND)
222+
223+find_library (GMOCK_LIBRARY gmock)
224+find_library (GMOCK_MAIN_LIBRARY gmock_main)
225+
226+if (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY OR NOT GTEST_FOUND)
227+ message ("Google Mock and Google Test not found - cannot build tests!")
228+ set (COMPIZ_BUILD_TESTING OFF)
229+endif (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY OR NOT GTEST_FOUND)
230+
231+include_directories (${GTEST_INCLUDE_DIRS})
232+
233+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
234+
235+add_executable (compiz_test_wall_offset_movement
236+ ${CMAKE_CURRENT_SOURCE_DIR}/test-wall-offset-movement.cpp)
237+
238+target_link_libraries (compiz_test_wall_offset_movement
239+ compiz_wall_offset_movement
240+ ${GTEST_BOTH_LIBRARIES}
241+ ${GMOCK_LIBRARY}
242+ ${GMOCK_MAIN_LIBRARY}
243+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
244+ )
245+
246+gtest_add_tests (compiz_test_wall_offset_movement "" ${CMAKE_CURRENT_SOURCE_DIR}/test-wall-offset-movement.cpp)
247
248=== added file 'wall/src/offset_movement/tests/test-wall-offset-movement.cpp'
249--- wall/src/offset_movement/tests/test-wall-offset-movement.cpp 1970-01-01 00:00:00 +0000
250+++ wall/src/offset_movement/tests/test-wall-offset-movement.cpp 2012-04-24 14:46:31 +0000
251@@ -0,0 +1,97 @@
252+#include <gtest/gtest.h>
253+#include <gmock/gmock.h>
254+
255+#include "offset-movement.h"
256+
257+class WallOffsetMovementTest :
258+ public ::testing::Test
259+{
260+};
261+
262+TEST(WallOffsetMovementTest, TestOffsetRight)
263+{
264+ CompRect sbr (750, 0, 500, 500);
265+ CompRegion sr (0, 0, 1000, 1000);
266+
267+ CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr);
268+
269+ EXPECT_EQ (offset, CompPoint (-250, 0));
270+}
271+
272+TEST(WallOffsetMovementTest, TestOffsetLeft)
273+{
274+ CompRect sbr (-250, 0, 500, 500);
275+ CompRegion sr (0, 0, 1000, 1000);
276+
277+ CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr);
278+
279+ EXPECT_EQ (offset, CompPoint (250, 0));
280+}
281+
282+TEST(WallOffsetMovementTest, TestOffsetTop)
283+{
284+ CompRect sbr (0, -250, 500, 500);
285+ CompRegion sr (0, 0, 1000, 1000);
286+
287+ CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr);
288+
289+ EXPECT_EQ (offset, CompPoint (0, 250));
290+}
291+
292+TEST(WallOffsetMovementTest, TestOffsetBottom)
293+{
294+ CompRect sbr (0, 750, 500, 500);
295+ CompRegion sr (0, 0, 1000, 1000);
296+
297+ CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr);
298+
299+ EXPECT_EQ (offset, CompPoint (0, -250));
300+}
301+
302+TEST(WallOffsetMovementTest, TestOffsetRightMMSlice)
303+{
304+ CompRect sbr (750, 0, 500, 500);
305+ CompRegion sr (0, 0, 1000, 1000);
306+
307+ sr -= CompRegion (400, 0, 200, 0);
308+
309+ CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr);
310+
311+ EXPECT_EQ (offset, CompPoint (-250, 0));
312+}
313+
314+TEST(WallOffsetMovementTest, TestOffsetLeftMMSlice)
315+{
316+ CompRect sbr (-250, 0, 500, 500);
317+ CompRegion sr (0, 0, 1000, 1000);
318+
319+ sr -= CompRegion (400, 0, 200, 0);
320+
321+ CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr);
322+
323+ EXPECT_EQ (offset, CompPoint (250, 0));
324+}
325+
326+TEST(WallOffsetMovementTest, TestOffsetTopMMSlice)
327+{
328+ CompRect sbr (0, -250, 500, 500);
329+ CompRegion sr (0, 0, 1000, 1000);
330+
331+ sr -= CompRegion (400, 0, 200, 0);
332+
333+ CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr);
334+
335+ EXPECT_EQ (offset, CompPoint (0, 250));
336+}
337+
338+TEST(WallOffsetMovementTest, TestOffsetBottomMMSlice)
339+{
340+ CompRect sbr (0, 750, 500, 500);
341+ CompRegion sr (0, 0, 1000, 1000);
342+
343+ sr -= CompRegion (400, 0, 200, 0);
344+
345+ CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr);
346+
347+ EXPECT_EQ (offset, CompPoint (0, -250));
348+}
349
350=== modified file 'wall/src/wall.cpp'
351--- wall/src/wall.cpp 2012-01-23 10:29:36 +0000
352+++ wall/src/wall.cpp 2012-04-24 14:46:31 +0000
353@@ -620,50 +620,29 @@
354 XWindowChanges xwc;
355 unsigned int mask = 0;
356
357- ws->moveViewport (-dx, -dy, false);
358+ /* If changing viewports fails we should not
359+ * move the client window */
360+ if (!ws->moveViewport (-dx, -dy, false))
361+ {
362+ window->activate ();
363+ return;
364+ }
365+
366 ws->focusDefault = false;
367
368- CompWindow::Geometry sbr (window->serverBorderRect ().x (),
369- window->serverBorderRect ().y (),
370- window->serverBorderRect ().width (),
371- window->serverBorderRect ().height (),
372- 0);
373- CompRegion sbrRegion (sbr);
374- int output = screen->outputDeviceForGeometry (sbr);
375- CompRegion outputRegion (screen->outputDevs ()[output].workArea ());
376-
377- /* If the window would be partially offscreen
378- * after it was moved then we should move it back
379- * so that it is completely onscreen, since we moved
380- * from mostly offscreen on B to mostly onscreen on A,
381- * the user should be able to see their selected window */
382- CompRegion inter = sbrRegion.intersected (outputRegion);
383- CompRegion rem = sbrRegion - outputRegion;
384-
385- foreach (const CompRect &r, rem.rects ())
386- {
387- if (r.x1 () >= inter.boundingRect ().x2 ())
388- {
389- xwc.x = window->serverGeometry ().x () - r.width ();
390- mask |= CWX;
391- }
392- else if (r.x2 () <= inter.boundingRect ().x1 ())
393- {
394- xwc.x = window->serverGeometry ().x () + r.width ();
395- mask |= CWX;
396- }
397-
398- if (r.y1 () >= inter.boundingRect ().y2 ())
399- {
400- xwc.y = window->serverGeometry ().y () - r.height ();
401- mask |= CWY;
402- }
403- else if (r.y2 () <= inter.boundingRect ().y1 ())
404- {
405- xwc.y = window->serverGeometry ().y () + r.height ();
406- mask |= CWY;
407- }
408- }
409+ CompRegion screenRegion;
410+
411+ foreach (const CompOutput &o, screen->outputDevs ())
412+ screenRegion += o.workArea ();
413+
414+ CompPoint d = compiz::wall::movementWindowOnScreen (window->serverBorderRect (),
415+ screenRegion);
416+
417+ mask |= d.x () !=0 ? CWX : 0;
418+ mask |= d.y () !=0 ? CWY : 0;
419+
420+ xwc.x = window->serverGeometry ().x () + dx;
421+ xwc.y = window->serverGeometry ().y () + dy;
422
423 window->configureXWindow (mask, &xwc);
424 }
425@@ -1515,7 +1494,7 @@
426
427 if (!moving && !showPreview && grabIndex)
428 {
429- screen->removeGrab (grabIndex, NULL);
430+ screen->removeGrab (static_cast <CompScreen::GrabHandle> (grabIndex), NULL);
431 grabIndex = 0;
432 }
433
434
435=== modified file 'wall/src/wall.h'
436--- wall/src/wall.h 2012-03-09 10:11:24 +0000
437+++ wall/src/wall.h 2012-04-24 14:46:31 +0000
438@@ -31,6 +31,8 @@
439 #include <cairo-xlib-xrender.h>
440 #include <cairo.h>
441
442+#include "offset-movement.h"
443+
444 #include "wall_options.h"
445
446
447@@ -139,7 +141,7 @@
448
449 int boxTimeout;
450 unsigned int boxOutputDevice;
451- CompScreen::GrabHandle grabIndex;
452+ void *grabIndex;
453 int timer;
454
455 Window moveWindow;

Subscribers

People subscribed via source and target branches