Merge lp:~renatofilho/compiz/compiz-lp1033531 into lp:compiz/0.9.8

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Daniel van Vugt
Approved revision: 3311
Merged at revision: 3307
Proposed branch: lp:~renatofilho/compiz/compiz-lp1033531
Merge into: lp:compiz/0.9.8
Diff against target: 296 lines (+221/-2)
8 files modified
plugins/expo/CMakeLists.txt (+5/-1)
plugins/expo/src/click_threshold/CMakeLists.txt (+33/-0)
plugins/expo/src/click_threshold/include/click-threshold.h (+38/-0)
plugins/expo/src/click_threshold/src/click-threshold.cpp (+39/-0)
plugins/expo/src/click_threshold/tests/CMakeLists.txt (+19/-0)
plugins/expo/src/click_threshold/tests/test-expo-click-threshold.cpp (+79/-0)
plugins/expo/src/expo.cpp (+7/-1)
plugins/expo/src/expo.h (+1/-0)
To merge this branch: bzr merge lp:~renatofilho/compiz/compiz-lp1033531
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Sam Spilsbury Approve
Review via email: mp+118973@code.launchpad.net

Commit message

Implemented single click exit from expo screen. (LP: #1033531)

Description of the change

Implemented single click exit from expo screen.

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Looks good, and as I thought, this was pretty simple anyways.

+#define DND_THRESHOLD 5

Can you make this a const unsigned int? eg const unsigned int DND_THRESHOLD 5 . Makes things more debuggable.

26 + ((abs (prevClickPoint.x () - event->xbutton.x) <= DND_THRESHOLD) &&
27 + (abs (prevClickPoint.y () - event->xbutton.y) <= DND_THRESHOLD)))

These need to be aligned with the initial bracked after the else, and not the else itself, eg,

else (foo () ||
      bar ())

not

else (foo () ||
bar ())

Major point:
This needs tests before it can go in. It should be fairly easy to get this code under test, since there's a single abstraction, eg

namespace compiz
{
namespace expo
{
bool clickMovementInThreshold (const CompPoint &previousPoint,
                               const CompPoint &currentPoint)
{
    CompPoint distance = currentPoint - previousPoint;
    distance.set (abs (distance.x ()), abs (distance.y ()));

    if (distance.x () < DND_THRESHOLD &&
        distance.y () < DND_THRESHOLD)
        return true;

    return false;
}
}
}

You can then put it in a different file and test it that way. There are examples around the codebase (eg, in decor, composite, wall) on how to do this. Testing == Awesome.

review: Needs Fixing
3308. By Renato Araujo Oliveira Filho

Declared DND_THRESHOLD as "static const unsigned int" instead of "define";

3309. By Renato Araujo Oliveira Filho

Created new file with ¨clickMovementInThreshold¨ function.
Created unit test for function ¨clickMovementInThreshold¨.

Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

@Sam Spilsbury (smspillaz)

All comments fixed.

Thanks

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

Looks great. Thanks!

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

Works well. Just a couple of small cleanups:

clickMovementInThreshold(const CompPoint &previousPoint, int x, int y)
^ This is inconsistent. It should either accept two CompPoints, or four ints. Not a mixture of both.

This:
    static const unsigned int DND_THRESHOLD = 5;
    if ((abs (previousPoint.x () - x) <= static_cast<int>(DND_THRESHOLD)
should just be:
    static const int DND_THRESHOLD = 5;
    if ((abs (previousPoint.x () - x) <= DND_THRESHOLD

Ideally CMakeLists should use lower case for reserved words like the docs do:
http://www.cmake.org/cmake/help/v2.8.8/cmake.html

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

Also, to get the alignment right in all environments, make sure you use spaces on line 138, to align with line 137. Then tabs when actually indenting a block.

Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

> Also, to get the alignment right in all environments, make sure you use spaces
> on line 138, to align with line 137. Then tabs when actually indenting a
> block.

I might be wrong but what I understand from this code style is that I should use 'tab' for 2 levels of indentation.

ref: http://wiki.compiz.org/Development/CodingStyle

Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

> > Also, to get the alignment right in all environments, make sure you use
> spaces
> > on line 138, to align with line 137. Then tabs when actually indenting a
> > block.
>
> I might be wrong but what I understand from this code style is that I should
> use 'tab' for 2 levels of indentation.
>
> ref: http://wiki.compiz.org/Development/CodingStyle

And this was done automatically by vim because of the flag "set cindent" which they recommend to use in the vimrc.

3310. By Renato Araujo Oliveira Filho

Used lower case for reserved words in cmake files.

3311. By Renato Araujo Oliveira Filho

Changed "clickMovementInThreshold" signature to use int instead of CompPoint.

Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

> Works well. Just a couple of small cleanups:
>
> clickMovementInThreshold(const CompPoint &previousPoint, int x, int y)
> ^ This is inconsistent. It should either accept two CompPoints, or four ints.
> Not a mixture of both.
>
> This:
> static const unsigned int DND_THRESHOLD = 5;
> if ((abs (previousPoint.x () - x) <= static_cast<int>(DND_THRESHOLD)
> should just be:
> static const int DND_THRESHOLD = 5;
> if ((abs (previousPoint.x () - x) <= DND_THRESHOLD

Fixed on revision 3311

>
> Ideally CMakeLists should use lower case for reserved words like the docs do:
> http://www.cmake.org/cmake/help/v2.8.8/cmake.html

Fixed on revision 3310

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

OK, thanks. Approved.

I noticed a bug with wobbly and using the "single click" sometimes got my windows stuck in a permanently deformed state. But I can't reproduce that bug now... !?

P.S. clickMovementInThreshold really should be a single line:
    return (abs (previousX - currentX) <= DND_THRESHOLD) &&
           (abs (previousY - currentY) <= DND_THRESHOLD);
And yes, that would mean libcompiz_expo_click_threshold.a would be a library containing only a single line function :)

P.P.S Namespaces should not be used repeatedly in a file:
    EXPECT_TRUE(compiz::expo::clickMovementInThreshold (10, 10, 13, 13));
    EXPECT_FALSE(compiz::expo::clickMovementInThreshold (10, 10, 1, 1));
Instead you should:
    using namespace compiz::expo;
    ...
    EXPECT_TRUE(clickMovementInThreshold (10, 10, 13, 13));
    EXPECT_FALSE(clickMovementInThreshold (10, 10, 1, 1));

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

P.P.P.S. If text needs to be aligned, you should always use the same number of tabs (if any) as the previous line. Because you can't always assumed the source code will be viewed in the same editor as yours with the same settings. So ensuring the tabs at the start of the lines are identical guarantees correctly aligned text in all environments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/expo/CMakeLists.txt'
2--- plugins/expo/CMakeLists.txt 2012-05-16 17:40:58 +0000
3+++ plugins/expo/CMakeLists.txt 2012-08-10 12:28:19 +0000
4@@ -3,5 +3,9 @@
5 include (CompizPlugin)
6
7 if (OPENGL_GLU_FOUND)
8- compiz_plugin (expo PLUGINDEPS composite opengl LIBRARIES ${OPENGL_glu_LIBRARY} INCDIRS ${OPENGL_INCLUDE_DIR})
9+ add_subdirectory (src/click_threshold)
10+ include_directories (src/click_threshold/include)
11+
12+ compiz_plugin (expo PLUGINDEPS composite opengl LIBRARIES ${OPENGL_glu_LIBRARY} compiz_expo_click_threshold INCDIRS ${OPENGL_INCLUDE_DIR})
13 endif (OPENGL_GLU_FOUND)
14+
15
16=== added directory 'plugins/expo/src/click_threshold'
17=== added file 'plugins/expo/src/click_threshold/CMakeLists.txt'
18--- plugins/expo/src/click_threshold/CMakeLists.txt 1970-01-01 00:00:00 +0000
19+++ plugins/expo/src/click_threshold/CMakeLists.txt 2012-08-10 12:28:19 +0000
20@@ -0,0 +1,33 @@
21+include_directories (
22+ ${CMAKE_CURRENT_SOURCE_DIR}/include
23+ ${CMAKE_CURRENT_SOURCE_DIR}/src
24+ ${Boost_INCLUDE_DIRS}
25+ ${GLIBMM_INCLUDE_DIRS}
26+)
27+
28+link_directories (${GLIBMM_LIBRARY_DIRS} ${COMPIZ_LIBRARY_DIRS})
29+
30+set (
31+ PRIVATE_HEADERS
32+ ${CMAKE_CURRENT_SOURCE_DIR}/include/click-threshold.h
33+)
34+
35+set (
36+ SRCS
37+ ${CMAKE_CURRENT_SOURCE_DIR}/src/click-threshold.cpp
38+)
39+
40+add_library (
41+ compiz_expo_click_threshold STATIC
42+ ${SRCS}
43+ ${PRIVATE_HEADERS}
44+)
45+
46+if (COMPIZ_BUILD_TESTING)
47+ add_subdirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/tests )
48+endif (COMPIZ_BUILD_TESTING)
49+
50+target_link_libraries (
51+ compiz_expo_click_threshold
52+ compiz_point
53+)
54
55=== added directory 'plugins/expo/src/click_threshold/include'
56=== added file 'plugins/expo/src/click_threshold/include/click-threshold.h'
57--- plugins/expo/src/click_threshold/include/click-threshold.h 1970-01-01 00:00:00 +0000
58+++ plugins/expo/src/click_threshold/include/click-threshold.h 2012-08-10 12:28:19 +0000
59@@ -0,0 +1,38 @@
60+/**
61+ *
62+ * Compiz Expo plugin
63+ *
64+ * click-threshold.h
65+ *
66+ * Copyright © 2012 Canonical Ltd.
67+ *
68+ * Authors:
69+ * Renato Araujo Oliviera Filho <renato@canonical.com>
70+ *
71+ * This program is free software; you can redistribute it and/or
72+ * modify it under the terms of the GNU General Public License
73+ * as published by the Free Software Foundation; either version 2
74+ * of the License, or (at your option) any later version.
75+ *
76+ * This program is distributed in the hope that it will be useful,
77+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
78+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79+ * GNU General Public License for more details.
80+ *
81+ **/
82+
83+#ifndef _COMPIZ_EXPO_CLICK_THRESHOLD_H
84+#define _COMPIZ_EXPO_CLICK_THRESHOLD_H
85+
86+#include <core/point.h>
87+
88+namespace compiz
89+{
90+ namespace expo
91+ {
92+ bool clickMovementInThreshold(int previousX, int previousY,
93+ int currentX, int currentY);
94+ }
95+}
96+
97+#endif
98
99=== added directory 'plugins/expo/src/click_threshold/src'
100=== added file 'plugins/expo/src/click_threshold/src/click-threshold.cpp'
101--- plugins/expo/src/click_threshold/src/click-threshold.cpp 1970-01-01 00:00:00 +0000
102+++ plugins/expo/src/click_threshold/src/click-threshold.cpp 2012-08-10 12:28:19 +0000
103@@ -0,0 +1,39 @@
104+/**
105+ *
106+ * Compiz Expo plugin
107+ *
108+ * click-threshold.cpp
109+ *
110+ * Copyright © 2012 Canonical Ltd.
111+ *
112+ * Authors:
113+ * Renato Araujo Oliviera Filho <renato@canonical.com>
114+ *
115+ * This program is free software; you can redistribute it and/or
116+ * modify it under the terms of the GNU General Public License
117+ * as published by the Free Software Foundation; either version 2
118+ * of the License, or (at your option) any later version.
119+ *
120+ * This program is distributed in the hope that it will be useful,
121+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
122+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
123+ * GNU General Public License for more details.
124+ *
125+ **/
126+
127+
128+#include "click-threshold.h"
129+#include <stdlib.h>
130+
131+static const int DND_THRESHOLD = 5;
132+
133+bool
134+compiz::expo::clickMovementInThreshold(int previousX, int previousY,
135+ int currentX, int currentY)
136+{
137+ if ((abs (previousX - currentX) <= DND_THRESHOLD) &&
138+ (abs (previousY - currentY) <= DND_THRESHOLD))
139+ return true;
140+ else
141+ return false;
142+}
143
144=== added directory 'plugins/expo/src/click_threshold/tests'
145=== added file 'plugins/expo/src/click_threshold/tests/CMakeLists.txt'
146--- plugins/expo/src/click_threshold/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
147+++ plugins/expo/src/click_threshold/tests/CMakeLists.txt 2012-08-10 12:28:19 +0000
148@@ -0,0 +1,19 @@
149+if (NOT GTEST_FOUND)
150+ message ("Google Test not found - cannot build tests!")
151+ set (COMPIZ_BUILD_TESTING OFF)
152+endif (NOT GTEST_FOUND)
153+
154+include_directories (${GTEST_INCLUDE_DIRS})
155+
156+link_directories (${COMPIZ_LIBRARY_DIRS})
157+
158+add_executable (compiz_test_expo_click_threshold
159+ ${CMAKE_CURRENT_SOURCE_DIR}/test-expo-click-threshold.cpp)
160+
161+target_link_libraries (compiz_test_expo_click_threshold
162+ compiz_expo_click_threshold
163+ ${GTEST_BOTH_LIBRARIES}
164+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
165+ )
166+
167+compiz_discover_tests (compiz_test_expo_click_threshold COVERAGE compiz_expo_click_threshold)
168
169=== added file 'plugins/expo/src/click_threshold/tests/test-expo-click-threshold.cpp'
170--- plugins/expo/src/click_threshold/tests/test-expo-click-threshold.cpp 1970-01-01 00:00:00 +0000
171+++ plugins/expo/src/click_threshold/tests/test-expo-click-threshold.cpp 2012-08-10 12:28:19 +0000
172@@ -0,0 +1,79 @@
173+/*
174+ * Copyright © 2012 Canonical Ltd.
175+ *
176+ * Permission to use, copy, modify, distribute, and sell this software
177+ * and its documentation for any purpose is hereby granted without
178+ * fee, provided that the above copyright notice appear in all copies
179+ * and that both that copyright notice and this permission notice
180+ * appear in supporting documentation, and that the name of
181+ * Canonical Ltd. not be used in advertising or publicity pertaining to
182+ * distribution of the software without specific, written prior permission.
183+ * Canonical Ltd. makes no representations about the suitability of this
184+ * software for any purpose. It is provided "as is" without express or
185+ * implied warranty.
186+ *
187+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
188+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
189+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
190+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
191+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
192+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
193+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
194+ *
195+ * Authored by: Renato Araujo Oliveira Filho <renato@canonical.com>
196+ */
197+
198+
199+#include <gtest/gtest.h>
200+
201+#include "click-threshold.h"
202+
203+class ExpoClickThresholdTest :
204+ public ::testing::Test
205+{
206+};
207+
208+TEST(ExpoClickThresholdTest, TestNotMove)
209+{
210+ EXPECT_TRUE(compiz::expo::clickMovementInThreshold (10, 10, 10, 10));
211+}
212+
213+TEST(ExpoClickThresholdTest, TestMoveNearLeft)
214+{
215+ EXPECT_TRUE(compiz::expo::clickMovementInThreshold (10, 10, 8, 8));
216+}
217+
218+TEST(ExpoClickThresholdTest, TestMoveNearRight)
219+{
220+ EXPECT_TRUE(compiz::expo::clickMovementInThreshold (10, 10, 13, 13));
221+}
222+
223+TEST(ExpoClickThresholdTest, TestMoveFarLeft)
224+{
225+ EXPECT_FALSE(compiz::expo::clickMovementInThreshold (10, 10, 1, 1));
226+}
227+
228+TEST(ExpoClickThresholdTest, TestMoveFarRight)
229+{
230+ EXPECT_FALSE(compiz::expo::clickMovementInThreshold (10, 10, 30, 30));
231+}
232+
233+TEST(ExpoClickThresholdTest, TestMoveNearX)
234+{
235+ EXPECT_TRUE(compiz::expo::clickMovementInThreshold (10, 10, 13, 10));
236+}
237+
238+TEST(ExpoClickThresholdTest, TestMoveNearY)
239+{
240+ EXPECT_TRUE(compiz::expo::clickMovementInThreshold (10, 10, 10, 13));
241+}
242+
243+TEST(ExpoClickThresholdTest, TestMoveFarX)
244+{
245+ EXPECT_FALSE(compiz::expo::clickMovementInThreshold (10, 10, 30, 10));
246+}
247+
248+TEST(ExpoClickThresholdTest, TestMoveFarY)
249+{
250+ EXPECT_FALSE(compiz::expo::clickMovementInThreshold (10, 10, 10, 30));
251+}
252
253=== modified file 'plugins/expo/src/expo.cpp'
254--- plugins/expo/src/expo.cpp 2012-05-28 06:08:02 +0000
255+++ plugins/expo/src/expo.cpp 2012-08-10 12:28:19 +0000
256@@ -24,6 +24,7 @@
257 **/
258
259 #include "expo.h"
260+#include "click-threshold.h"
261 #include <math.h>
262 #include <GL/glu.h>
263 #include <X11/cursorfont.h>
264@@ -354,6 +355,7 @@
265 doubleClick = false;
266 }
267 cScreen->damageScreen ();
268+ prevClickPoint = CompPoint(event->xbutton.x, event->xbutton.y);
269 }
270 break;
271
272@@ -367,7 +369,11 @@
273 clickTime = 0;
274 doubleClick = false;
275 }
276- else if (doubleClick)
277+ else if (doubleClick ||
278+ compiz::expo::clickMovementInThreshold(prevClickPoint.x (),
279+ prevClickPoint.y (),
280+ event->xbutton.x,
281+ event->xbutton.y))
282 {
283 CompAction& action = optionGetExpoKey ();
284
285
286=== modified file 'plugins/expo/src/expo.h'
287--- plugins/expo/src/expo.h 2012-05-28 05:35:38 +0000
288+++ plugins/expo/src/expo.h 2012-08-10 12:28:19 +0000
289@@ -86,6 +86,7 @@
290
291 CompPoint prevCursor;
292 CompPoint newCursor;
293+ CompPoint prevClickPoint;
294
295 CompPoint origVp;
296 CompPoint selectedVp;

Subscribers

People subscribed via source and target branches