Merge lp:~compiz-team/compiz/compiz.fix_1053820 into lp:compiz/0.9.8

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1053820
Merge into: lp:compiz/0.9.8
Diff against target: 1030 lines (+779/-69)
9 files modified
include/core/action.h (+12/-1)
include/core/option.h (+4/-2)
src/action.cpp (+24/-0)
src/event.cpp (+149/-62)
src/option.cpp (+18/-0)
src/option/tests/option.cpp (+31/-0)
src/privateaction.h (+25/-1)
src/privatescreen/tests/test-privatescreen.cpp (+513/-1)
src/screen.cpp (+3/-2)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1053820
Reviewer Review Type Date Requested Status
Daniel van Vugt Needs Fixing
jenkins (community) continuous-integration Needs Fixing
Review via email: mp+125836@code.launchpad.net

This proposal has been superseded by a proposal from 2012-09-24.

Commit message

Don't trigger actions unless they are actually marked active. It is possible that we may have a passive button grab for other reasons than actions being bound, so actions which haven't been added should be ignored.

Description of the change

Don't trigger actions unless they are actually marked active. It is possible that we may have a passive button grab for other reasons than actions being bound, so actions which haven't been added should be ignored.

Tests added for refactored code:

 Start 107: privatescreen_ButtonPressEdgeEventManagementTest.IgnoreWhenEventAndRootWindowMismatch
107/548 Test #107: privatescreen_ButtonPressEdgeEventManagementTest.IgnoreWhenEventAndRootWindowMismatch ....................................................................... Passed 0.01 sec
        Start 108: privatescreen_ButtonPressEdgeEventManagementTest.IgnoreWhenEventMismatchAndNoGrabs
108/548 Test #108: privatescreen_ButtonPressEdgeEventManagementTest.IgnoreWhenEventMismatchAndNoGrabs .......................................................................... Passed 0.01 sec
        Start 109: privatescreen_ButtonPressEdgeEventManagementTest.AllowWhenEventButNotRootWindowMismatchWhileGrabbed
109/548 Test #109: privatescreen_ButtonPressEdgeEventManagementTest.AllowWhenEventButNotRootWindowMismatchWhileGrabbed ......................................................... Passed 0.01 sec
        Start 110: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnInvalidEdge
110/548 Test #110: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnInvalidEdge ..................................................................................... Passed 0.01 sec
        Start 111: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnUnboundAction
111/548 Test #111: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnUnboundAction ................................................................................... Passed 0.01 sec
        Start 112: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnMismatchedEdgeMask
112/548 Test #112: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnMismatchedEdgeMask .............................................................................. Passed 0.01 sec
        Start 113: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnMismatchedButtonNumber
113/548 Test #113: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnMismatchedButtonNumber .......................................................................... Passed 0.01 sec
        Start 114: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnMismatchedButtonState
114/548 Test #114: privatescreen_ButtonPressEdgeEventManagementTest.NoTriggerOnMismatchedButtonState ........................................................................... Passed 0.01 sec
        Start 115: privatescreen_ButtonPressEdgeEventManagementTest.TriggerWhenStateButtonAndEdgeMaskMatch
115/548 Test #115: privatescreen_ButtonPressEdgeEventManagementTest.TriggerWhenStateButtonAndEdgeMaskMatch ..................................................................... Passed 0.01 sec
        Start 116: privatescreen_ButtonPressEventManagementTest.SetEventWindowArgument
116/548 Test #116: privatescreen_ButtonPressEventManagementTest.SetEventWindowArgument ......................................................................................... Passed 0.01 sec
        Start 117: privatescreen_ButtonPressEventManagementTest.NoTriggerOnUnboundAction
117/548 Test #117: privatescreen_ButtonPressEventManagementTest.NoTriggerOnUnboundAction ....................................................................................... Passed 0.01 sec
        Start 118: privatescreen_ButtonPressEventManagementTest.NoTriggerOnUnboundInactiveAction
118/548 Test #118: privatescreen_ButtonPressEventManagementTest.NoTriggerOnUnboundInactiveAction ............................................................................... Passed 0.01 sec
        Start 119: privatescreen_ButtonPressEventManagementTest.NoTriggerOnMismatchedButtonNumber
119/548 Test #119: privatescreen_ButtonPressEventManagementTest.NoTriggerOnMismatchedButtonNumber .............................................................................. Passed 0.01 sec
        Start 120: privatescreen_ButtonPressEventManagementTest.NoTriggerOnMismatchedButtonState
120/548 Test #120: privatescreen_ButtonPressEventManagementTest.NoTriggerOnMismatchedButtonState ............................................................................... Passed 0.01 sec
        Start 121: privatescreen_ButtonPressEventManagementTest.TriggerWhenStateAndButtonMatch
121/548 Test #121: privatescreen_ButtonPressEventManagementTest.TriggerWhenStateAndButtonMatch ................................................................................. Passed 0.01 sec

To post a comment you must log in.
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Martin Mrazik (mrazik) wrote :

This is the jenkins error:
[ 14%] Building CXX object src/CMakeFiles/compiz_core.dir/event.cpp.o
cd /tmp/buildd/compiz-0.9.8.2+bzr3377/obj-x86_64-linux-gnu/src && /usr/lib/ccache/c++ -Dcompiz_core_EXPORTS -DHAVE_SCANDIR_POSIX -DHAVE_SCANDIR_POSIX -DHAVE_SCANDIR_POSIX -DHAVE_CONFIG_H -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Wall -Wl,-zdefs -Wno-deprecated-declarations -Werror -fPIC -Wall -Wl,-zdefs -Wno-deprecated-declarations -Werror -fPIC -Wall -Wl,-zdefs -Wno-deprecated-declarations -Werror -O2 -g -fPIC -I/tmp/buildd/compiz-0.9.8.2+bzr3377/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/obj-x86_64-linux-gnu -I/tmp/buildd/compiz-0.9.8.2+bzr3377/obj-x86_64-linux-gnu/generated -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/glibmm-2.4 -I/usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I/usr/include/sigc++-2.0 -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I/usr/include/startup-notification-1.0 -I/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/string/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/string/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/logmessage/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/logmessage/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/timer/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/timer/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/pluginclasshandler/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/pluginclasshandler/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/point/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/point/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/rect/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/rect/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/servergrab/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/servergrab/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/region/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/region/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/window/geometry/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/window/geometry/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/window/geometry-saver/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/window/geometry-saver/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/window/extents/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/window/extents/src -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/window/constrainment/include -I/tmp/buildd/compiz-0.9.8.2+bzr3377/src/window/constrainment/src -DPLUGINDIR=\"/usr/lib/compiz\" -DSHAREDIR=\"/usr/share/compiz/\" -DMETADATADIR=\"/usr/share/compiz\" -o CMakeFiles/compiz_core.dir/event.cpp.o -c /tmp/buildd/compiz-0.9.8.2+bzr3377/src/event.cpp
/tmp/buildd/compiz-0.9.8.2+bzr3377/src/event.cpp:44:29: fatal error: eventmanagement.h: No such file or directory
compilation terminated.
make[3]: *** [src/CMakeFiles/compiz_core.dir/event.cpp.o] Error 1
make[3]: Leaving directory `/tmp/buildd/compiz-0.9.8.2+bzr3377/obj-x86_64-linux-gnu'

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

What's the real bug ID? I don't think it's bug 1053820.

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

And after that, please set to Resubmit. I think this is too large and dangerous to squeeze in 0.9.8.

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

Resubmit per the prereq branch.

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

Sorry, that comment doesn't belong here. Please fix as requested above.

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

Confirmed the same build failure as jenkins:
/home/dan/bzr/compiz/tmp.142/src/event.cpp:44:29: fatal error: eventmanagement.h: No such file or directory

Please also correct the bug links and branch name. Then leave it in progress or Resubmit state.

review: Needs Fixing
3391. By Sam Spilsbury

Add missing file

3392. By Sam Spilsbury

Merge lp:compiz

3393. By Sam Spilsbury

Move check to the right place

3394. By Sam Spilsbury

Merge lp:compiz and handle some BCI stuff

3395. By Sam Spilsbury

Constify the API a bit

3396. By Sam Spilsbury

Cleanup.

Unindent namespaces, simplify interface, add namespace alias where
appropriate.

Unmerged revisions

3396. By Sam Spilsbury

Cleanup.

Unindent namespaces, simplify interface, add namespace alias where
appropriate.

3395. By Sam Spilsbury

Constify the API a bit

3394. By Sam Spilsbury

Merge lp:compiz and handle some BCI stuff

3393. By Sam Spilsbury

Move check to the right place

3392. By Sam Spilsbury

Merge lp:compiz

3391. By Sam Spilsbury

Add missing file

3390. By Sam Spilsbury

Don't trigger actions unless they're actually added

3389. By Sam Spilsbury

Restrict access of private data in CompAction to a separate nonmember
function, add a test for its usage

3388. By Sam Spilsbury

Refactored out the rest of that function and tested it

3387. By Sam Spilsbury

Reworked the way actions are set up to be more in line with how
compiz expects it. Now the tests pass

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/core/action.h'
2--- include/core/action.h 2012-09-07 22:37:20 +0000
3+++ include/core/action.h 2012-09-22 03:07:19 +0000
4@@ -34,6 +34,14 @@
5
6 #include <X11/Xlib-xcb.h>
7
8+namespace compiz
9+{
10+ namespace actions
11+ {
12+ void setActionActiveState (const CompAction &action,
13+ bool active);
14+ }
15+}
16
17 class PrivateAction;
18
19@@ -171,7 +179,10 @@
20
21 bool active ();
22
23- friend class CompScreenImpl;
24+ /* BCI: Not optimal, CompAction should implement
25+ * BoundAction instead or be a PV class */
26+ friend void compiz::actions::setActionActiveState (const CompAction &action,
27+ bool active);
28
29 private:
30 PrivateAction *priv;
31
32=== modified file 'include/core/option.h'
33--- include/core/option.h 2012-05-30 09:24:15 +0000
34+++ include/core/option.h 2012-09-22 03:07:19 +0000
35@@ -244,8 +244,10 @@
36
37 CompString name ();
38
39- Type type ();
40- Value & value ();
41+ Type type () const;
42+ Type type (); // BCI: drop this in 0.9.9
43+ Value & value () const;
44+ Value & value (); // BCI: drop this in 0.9.9
45 Restriction & rest ();
46
47 bool set (Value &val);
48
49=== modified file 'src/action.cpp'
50--- src/action.cpp 2012-05-10 12:58:01 +0000
51+++ src/action.cpp 2012-09-22 03:07:19 +0000
52@@ -33,6 +33,8 @@
53 #include <core/screen.h>
54 #include "privateaction.h"
55
56+namespace ca = compiz::actions;
57+
58 struct _Modifier {
59 const char *name;
60 int modifier;
61@@ -626,6 +628,28 @@
62 return priv->active;
63 }
64
65+void
66+PrivateAction::makeActive ()
67+{
68+ active = true;
69+}
70+
71+void
72+PrivateAction::makeInactive ()
73+{
74+ active = false;
75+}
76+
77+void
78+ca::setActionActiveState (const CompAction &action,
79+ bool active)
80+{
81+ if (active)
82+ action.priv->makeActive ();
83+ else
84+ action.priv->makeInactive ();
85+}
86+
87 PrivateAction::PrivateAction () :
88 initiate (),
89 terminate (),
90
91=== modified file 'src/event.cpp'
92--- src/event.cpp 2012-09-05 16:42:03 +0000
93+++ src/event.cpp 2012-09-22 03:07:19 +0000
94@@ -41,8 +41,10 @@
95 #include "privatescreen.h"
96 #include "privatewindow.h"
97 #include "privatestackdebugger.h"
98+#include "eventmanagement.h"
99
100 namespace cps = compiz::private_screen;
101+namespace ce = compiz::events;
102
103 namespace
104 {
105@@ -124,6 +126,9 @@
106 if (option.value ().action ().initiate ().empty ())
107 return false;
108
109+ if (!option.value ().action ().active ())
110+ return false;
111+
112 *action = &option.value ().action ();
113
114 return true;
115@@ -189,78 +194,160 @@
116 return false;
117 }
118
119+int
120+ce::processButtonPressOnEdgeWindow (Window edgeWindow,
121+ Window root,
122+ Window eventWindow,
123+ Window eventRoot,
124+ cps::GrabList &grabList,
125+ const CompScreenEdge *screenEdge)
126+{
127+ int edge = -1;
128+
129+ if (eventRoot != root)
130+ return edge;
131+
132+ if (eventWindow != edgeWindow)
133+ {
134+ if (grabList.grabsEmpty () ||
135+ eventRoot != root)
136+ return edge;
137+ }
138+
139+ for (unsigned int i = 0; i < SCREEN_EDGE_NUM; i++)
140+ {
141+ if (edgeWindow == screenEdge[i].id)
142+ {
143+ edge = 1 << i;
144+ break;
145+ }
146+ }
147+
148+ return edge;
149+}
150+
151+void
152+ce::setEventWindowInButtonPressArguments (ce::EventArguments &arguments,
153+ Window eventWindow)
154+{
155+ arguments[1].value ().set ((int) eventWindow);
156+}
157+
158+namespace
159+{
160+ bool buttonActionModifiersMatchEventState (unsigned int actionModifiers,
161+ unsigned int eventState)
162+ {
163+ const unsigned int ignored = modHandler->ignoredModMask ();
164+ const unsigned int modMask = REAL_MOD_MASK & ~ignored;
165+ const unsigned int bindMods = modHandler->virtualToRealModMask (actionModifiers);
166+
167+ return (bindMods & modMask) == (eventState & modMask);
168+ }
169+}
170+
171+bool
172+ce::activateButtonPressOnWindowBindingOption (CompOption &option,
173+ unsigned int eventButton,
174+ unsigned int eventState,
175+ cps::EventManager &eventManager,
176+ const ActionModsMatchesEventStateFunc &matchEventState,
177+ ce::EventArguments &arguments)
178+{
179+ CompAction *action;
180+ const CompAction::State state = CompAction::StateInitButton;
181+
182+ if (isBound (option, CompAction::BindingTypeButton, state, &action))
183+ {
184+ if (action->button ().button () == (int) eventButton)
185+ {
186+ if (matchEventState (action->button ().modifiers (),
187+ eventState))
188+ {
189+ if (eventManager.triggerPress (action, state, arguments))
190+ return true;
191+ }
192+ }
193+ }
194+
195+ return false;
196+}
197+
198+bool
199+ce::activateButtonPressOnEdgeBindingOption (CompOption &option,
200+ unsigned int eventButton,
201+ unsigned int eventState,
202+ int edge,
203+ cps::EventManager &eventManager,
204+ const ActionModsMatchesEventStateFunc &matchEventState,
205+ ce::EventArguments &arguments)
206+{
207+ CompAction *action;
208+ const CompAction::State state = CompAction::StateInitButton |
209+ CompAction::StateInitEdge;
210+
211+ if (edge != -1)
212+ {
213+ if (isInitiateBinding (option, CompAction::BindingTypeEdgeButton,
214+ state, &action))
215+ {
216+ if ((action->button ().button () == (int) eventButton) &&
217+ (action->edgeMask () & edge))
218+ {
219+ if (matchEventState (action->button ().modifiers (),
220+ eventState))
221+ if (action->initiate () (action, state,
222+ arguments))
223+ return true;
224+ }
225+ }
226+ }
227+
228+ return false;
229+}
230+
231 bool
232 PrivateScreen::triggerButtonPressBindings (CompOption::Vector &options,
233 XButtonEvent *event,
234 CompOption::Vector &arguments)
235 {
236- CompAction::State state = CompAction::StateInitButton;
237- CompAction *action;
238- unsigned int ignored = modHandler->ignoredModMask ();
239- unsigned int modMask = REAL_MOD_MASK & ~ignored;
240- unsigned int bindMods;
241- unsigned int edge = 0;
242+ int edge = -1;
243+
244+ static const ce::ActionModsMatchesEventStateFunc matchEventState (
245+ boost::bind (buttonActionModifiersMatchEventState,
246+ _1, _2));
247
248 if (edgeWindow)
249- {
250- unsigned int i;
251-
252- if (event->root != screen->root())
253- return false;
254-
255- if (event->window != edgeWindow)
256- {
257- if (eventManager.grabsEmpty () || event->window != screen->root())
258- return false;
259- }
260-
261- for (i = 0; i < SCREEN_EDGE_NUM; i++)
262- {
263- if (edgeWindow == screenEdge[i].id)
264- {
265- edge = 1 << i;
266- arguments[1].value ().set ((int) orphanData.activeWindow);
267- break;
268- }
269- }
270- }
271+ edge = ce::processButtonPressOnEdgeWindow (edgeWindow,
272+ screen->root (),
273+ event->window,
274+ event->root,
275+ eventManager,
276+ screenEdge);
277+
278+ if (edge != -1)
279+ ce::setEventWindowInButtonPressArguments (arguments,
280+ orphanData.activeWindow);
281
282 foreach (CompOption &option, options)
283 {
284- if (isBound (option, CompAction::BindingTypeButton, state, &action))
285- {
286- if (action->button ().button () == (int) event->button)
287- {
288- bindMods = modHandler->virtualToRealModMask (
289- action->button ().modifiers ());
290-
291- if ((bindMods & modMask) == (event->state & modMask))
292- {
293- if (eventManager.triggerPress (action, state, arguments))
294- return true;
295- }
296- }
297- }
298-
299- if (edge)
300- {
301- if (isInitiateBinding (option, CompAction::BindingTypeEdgeButton,
302- state | CompAction::StateInitEdge, &action))
303- {
304- if ((action->button ().button () == (int) event->button) &&
305- (action->edgeMask () & edge))
306- {
307- bindMods = modHandler->virtualToRealModMask (
308- action->button ().modifiers ());
309-
310- if ((bindMods & modMask) == (event->state & modMask))
311- if (action->initiate () (action, state |
312- CompAction::StateInitEdge,
313- arguments))
314- return true;
315- }
316- }
317- }
318+ if (ce::activateButtonPressOnWindowBindingOption (option,
319+ event->button,
320+ event->state,
321+ eventManager,
322+ matchEventState,
323+ arguments))
324+ return true;
325+
326+ if (ce::activateButtonPressOnEdgeBindingOption (option,
327+ event->button,
328+ event->state,
329+ edge,
330+ eventManager,
331+ matchEventState,
332+ arguments))
333+ return true;
334+
335 }
336
337 return false;
338
339=== modified file 'src/option.cpp'
340--- src/option.cpp 2012-06-24 09:00:27 +0000
341+++ src/option.cpp 2012-09-22 03:07:19 +0000
342@@ -462,12 +462,24 @@
343 return priv->type;
344 }
345
346+CompOption::Type
347+CompOption::type () const
348+{
349+ return priv->type;
350+}
351+
352 CompOption::Value &
353 CompOption::value ()
354 {
355 return priv->value;
356 }
357
358+CompOption::Value &
359+CompOption::value () const
360+{
361+ return priv->value;
362+}
363+
364 CompOption::Restriction &
365 CompOption::rest ()
366 {
367@@ -477,6 +489,12 @@
368 bool
369 CompOption::set (CompOption::Value &val)
370 {
371+ /* XXX: It is uncertain as to why this is done. The only
372+ * logical reason would be that actions are stateful and
373+ * we don't want to care about the old state from the
374+ * action that we're setting this value to, so we're just
375+ * clearing that state and starting over, however copyState
376+ * does a lot more than that */
377 if (isAction () && priv->type != CompOption::TypeAction)
378 val.action ().copyState (priv->value.action ());
379
380
381=== modified file 'src/option/tests/option.cpp'
382--- src/option/tests/option.cpp 2012-05-27 03:27:57 +0000
383+++ src/option/tests/option.cpp 2012-09-22 03:07:19 +0000
384@@ -206,3 +206,34 @@
385 ASSERT_EQ(expectTwo, as_const.f());
386 }
387 }
388+
389+TEST (CompOption, AssignDefaultActionValueToUnsetTypeClearsOldStateKeepsInfo)
390+{
391+ /* Value is unset at this point */
392+ CompOption option ("testing", CompOption::TypeKey);
393+ CompAction action;
394+
395+ /* We need to set up the state here as
396+ * the CompOption::Value constructor makes
397+ * a copy of the action */
398+ action.setState (CompAction::StateInitKey);
399+ action.setButton (CompAction::ButtonBinding (1,
400+ 1 << 1));
401+
402+ CompOption::Value value (action);
403+
404+ ASSERT_EQ (value.action ().state (), CompAction::StateInitKey);
405+
406+ /* Actually set the action value, this will
407+ * overwrite the internal value */
408+ option.set (value);
409+
410+ /* We don't care about the old action's state, so get
411+ * rid of it */
412+ ASSERT_EQ (option.value ().action ().state (), 0);
413+
414+ /* We do want to keep the non-stateful data which is
415+ * pure info */
416+ ASSERT_EQ (option.value ().action ().button ().button (), 1);
417+ ASSERT_EQ (option.value ().action ().button ().modifiers (), 1 << 1);
418+}
419
420=== modified file 'src/privateaction.h'
421--- src/privateaction.h 2012-02-14 11:39:59 +0000
422+++ src/privateaction.h 2012-09-22 03:07:19 +0000
423@@ -28,11 +28,35 @@
424 #ifndef _PRIVATEACTION_H
425 #define _PRIVATEACTION_H
426
427-class PrivateAction {
428+namespace compiz
429+{
430+ namespace actions
431+ {
432+ class BoundAction
433+ {
434+ public:
435+
436+ virtual ~BoundAction () {}
437+
438+ virtual void makeActive () = 0;
439+ virtual void makeInactive () = 0;
440+ };
441+
442+ void setActionActiveState (const CompAction &action,
443+ bool active);
444+ }
445+}
446+
447+class PrivateAction :
448+ public compiz::actions::BoundAction
449+{
450 public:
451 PrivateAction ();
452 PrivateAction (const PrivateAction&);
453
454+ void makeActive ();
455+ void makeInactive ();
456+
457 CompAction::CallBack initiate;
458 CompAction::CallBack terminate;
459
460
461=== modified file 'src/privatescreen/tests/test-privatescreen.cpp'
462--- src/privatescreen/tests/test-privatescreen.cpp 2012-06-24 09:00:27 +0000
463+++ src/privatescreen/tests/test-privatescreen.cpp 2012-09-22 03:07:19 +0000
464@@ -1,5 +1,6 @@
465 #include "privatescreen.h"
466-
467+#include "privateaction.h"
468+#include "eventmanagement.h"
469
470 // Get rid of stupid macro from X.h
471 // Why, oh why, are we including X.h?
472@@ -16,6 +17,8 @@
473
474 namespace {
475
476+const unsigned long None = 0;
477+
478 class MockCompScreen : public CompScreen
479 {
480 public:
481@@ -355,6 +358,7 @@
482 } // (abstract) namespace
483
484 namespace cps = compiz::private_screen;
485+namespace ce = compiz::events;
486
487 TEST(privatescreen_PluginManagerTest, create_and_destroy)
488 {
489@@ -909,3 +913,511 @@
490
491 EXPECT_EQ (vp, CompPoint (0, 1));
492 }
493+
494+namespace
495+{
496+ const Window topLeftScreenEdge = 1;
497+ const Window topScreenEdge = 2;
498+ const Window topRightScreenEdge = 3;
499+ const Window rightScreenEdge = 4;
500+ const Window bottomRightScreenEdge = 5;
501+ const Window bottomScreenEdge = 6;
502+ const Window bottomLeftScreenEdge = 7;
503+ const Window leftScreenEdge = 8;
504+
505+ const CompScreenEdge screenEdges[SCREEN_EDGE_NUM] =
506+ {
507+ { leftScreenEdge, SCREEN_EDGE_LEFT },
508+ { rightScreenEdge, SCREEN_EDGE_RIGHT },
509+ { topScreenEdge, SCREEN_EDGE_TOP },
510+ { bottomScreenEdge , SCREEN_EDGE_BOTTOM },
511+ { topLeftScreenEdge, SCREEN_EDGE_TOPLEFT },
512+ { topRightScreenEdge, SCREEN_EDGE_TOPRIGHT },
513+ { bottomLeftScreenEdge, SCREEN_EDGE_BOTTOMLEFT },
514+ { bottomRightScreenEdge, SCREEN_EDGE_BOTTOMRIGHT}
515+ };
516+}
517+
518+TEST (privatescreen_ButtonPressEdgeEventManagementTest, IgnoreWhenEventAndRootWindowMismatch)
519+{
520+ const Window rootWindow = 1;
521+ const Window edgeWindow = topScreenEdge;
522+
523+ cps::OrphanData orphanData;
524+ cps::GrabList grabList;
525+
526+ EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
527+ rootWindow,
528+ 0,
529+ 0,
530+ grabList,
531+ screenEdges), -1);
532+}
533+
534+TEST (privatescreen_ButtonPressEdgeEventManagementTest, IgnoreWhenEventMismatchAndNoGrabs)
535+{
536+ const Window rootWindow = 1;
537+ const Window edgeWindow = topScreenEdge;
538+
539+ cps::OrphanData orphanData;
540+ cps::GrabList grabList;
541+
542+ EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
543+ rootWindow,
544+ 0,
545+ rootWindow,
546+ grabList,
547+ screenEdges), -1);
548+}
549+
550+TEST (privatescreen_ButtonPressEdgeEventManagementTest, AllowWhenEventButNotRootWindowMismatchWhileGrabbed)
551+{
552+ const Window rootWindow = 1;
553+ const Window edgeWindow = topScreenEdge;
554+ unsigned int topEdgeMask = 1 << SCREEN_EDGE_TOP;
555+
556+ cps::OrphanData orphanData;
557+ cps::GrabList grabList;
558+
559+ grabList.grabsPush (new cps::Grab (None, "Nil"));
560+
561+ EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
562+ rootWindow,
563+ 0,
564+ rootWindow,
565+ grabList,
566+ screenEdges), topEdgeMask);
567+
568+ grabList.grabsRemove (grabList.grabsBack ());
569+}
570+
571+TEST (privatescreen_ButtonPressEventManagementTest, SetEventWindowArgument)
572+{
573+ const Window activeWindow = 1;
574+
575+ ce::EventArguments arguments (2);
576+ ce::setEventWindowInButtonPressArguments (arguments, activeWindow);
577+ EXPECT_EQ (arguments[1].value ().i (), activeWindow);
578+}
579+
580+namespace
581+{
582+ class MockTriggerableAction
583+ {
584+ public:
585+
586+ MOCK_METHOD2 (matchEventState, bool (unsigned int,
587+ unsigned int));
588+ MOCK_METHOD3 (initiate, bool (CompAction *,
589+ CompAction::State ,
590+ CompOption::Vector &));
591+ MOCK_METHOD3 (terminate, bool (CompAction *,
592+ CompAction::State ,
593+ CompOption::Vector &));
594+ };
595+
596+ const unsigned int testingButtonNumber = 1;
597+ const unsigned int testingButtonState = (1 << 1);
598+
599+ ce::ActionModsMatchesEventStateFunc
600+ GetMatchEventStateFuncForMock (MockTriggerableAction &triggerableAction)
601+ {
602+ return boost::bind (&MockTriggerableAction::matchEventState,
603+ &triggerableAction,
604+ _1, _2);
605+ }
606+
607+ CompAction::CallBack
608+ GetInitiateForMock (MockTriggerableAction &triggerableAction)
609+ {
610+ return boost::bind (&MockTriggerableAction::initiate,
611+ &triggerableAction,
612+ _1, _2, _3);
613+ }
614+
615+ CompAction::CallBack
616+ GetTerminateForMock (MockTriggerableAction &triggerableAction)
617+ {
618+ return boost::bind (&MockTriggerableAction::terminate,
619+ &triggerableAction,
620+ _1, _2, _3);
621+ }
622+}
623+
624+bool operator== (const CompOption &lhs,
625+ const CompOption &rhs)
626+{
627+ if (lhs.type () != rhs.type ())
628+ return false;
629+
630+ return lhs.value () == rhs.value ();
631+}
632+
633+TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnUnboundAction)
634+{
635+ CompAction action;
636+ CompOption option ("button", CompOption::TypeButton);
637+ CompOption::Value value (action);
638+ cps::EventManager eventManager;
639+ MockTriggerableAction triggerableAction;
640+ ce::EventArguments arguments;
641+
642+ option.set (value);
643+
644+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
645+ GetMatchEventStateFuncForMock (triggerableAction);
646+
647+ EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
648+ testingButtonNumber,
649+ testingButtonState,
650+ eventManager,
651+ matchEventState,
652+ arguments));
653+}
654+
655+TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnUnboundInactiveAction)
656+{
657+ CompAction action;
658+ MockTriggerableAction triggerableAction;
659+ int edgeMask = 1 << SCREEN_EDGE_TOP;
660+
661+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
662+ GetMatchEventStateFuncForMock (triggerableAction);
663+ const CompAction::CallBack &initiate =
664+ GetInitiateForMock (triggerableAction);
665+
666+ action.setButton (CompAction::ButtonBinding (testingButtonNumber,
667+ testingButtonState));
668+ action.setEdgeMask (edgeMask);
669+
670+
671+ CompOption option ("button", CompOption::TypeButton);
672+ CompOption::Value value (action);
673+ cps::EventManager eventManager;
674+ ce::EventArguments arguments;
675+
676+ option.set (value);
677+ option.value ().action ().setInitiate (initiate);
678+ option.value ().action ().setState (CompAction::StateInitButton);
679+ compiz::actions::setActionActiveState (option.value ().action (), false);
680+
681+ EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
682+ testingButtonNumber,
683+ testingButtonState,
684+ edgeMask,
685+ eventManager,
686+ matchEventState,
687+ arguments));
688+}
689+
690+TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnMismatchedButtonNumber)
691+{
692+ CompAction action;
693+ MockTriggerableAction triggerableAction;
694+
695+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
696+ GetMatchEventStateFuncForMock (triggerableAction);
697+ const CompAction::CallBack &initiate =
698+ GetInitiateForMock (triggerableAction);
699+
700+ action.setButton (CompAction::ButtonBinding (testingButtonNumber,
701+ testingButtonState));
702+
703+ CompOption option ("button", CompOption::TypeButton);
704+ CompOption::Value value (action);
705+ cps::EventManager eventManager;
706+ ce::EventArguments arguments;
707+
708+ option.set (value);
709+ option.value ().action ().setInitiate (initiate);
710+ option.value ().action ().setState (CompAction::StateInitButton);
711+ compiz::actions::setActionActiveState (option.value ().action (), true);
712+
713+ EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
714+ EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
715+ 0,
716+ testingButtonState,
717+ eventManager,
718+ matchEventState,
719+ arguments));
720+}
721+
722+TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnMismatchedButtonState)
723+{
724+ CompAction action;
725+ MockTriggerableAction triggerableAction;
726+
727+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
728+ GetMatchEventStateFuncForMock (triggerableAction);
729+ const CompAction::CallBack &initiate =
730+ GetInitiateForMock (triggerableAction);
731+
732+ action.setButton (CompAction::ButtonBinding (testingButtonNumber,
733+ testingButtonState));
734+
735+ CompOption option ("button", CompOption::TypeButton);
736+ CompOption::Value value (action);
737+ cps::EventManager eventManager;
738+ ce::EventArguments arguments;
739+
740+ option.set (value);
741+ option.value ().action ().setInitiate (initiate);
742+ option.value ().action ().setState (CompAction::StateInitButton);
743+ compiz::actions::setActionActiveState (option.value ().action (), true);
744+
745+ EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, 0))
746+ .WillOnce (Return (false));
747+ EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
748+ EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
749+ testingButtonNumber,
750+ 0,
751+ eventManager,
752+ matchEventState,
753+ arguments));
754+}
755+
756+TEST (privatescreen_ButtonPressEventManagementTest, TriggerWhenStateAndButtonMatch)
757+{
758+ CompAction action;
759+ MockTriggerableAction triggerableAction;
760+
761+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
762+ GetMatchEventStateFuncForMock (triggerableAction);
763+ const CompAction::CallBack &initiate =
764+ GetInitiateForMock (triggerableAction);
765+
766+ action.setButton (CompAction::ButtonBinding (testingButtonNumber,
767+ testingButtonState));
768+
769+ CompOption option ("button", CompOption::TypeButton);
770+ CompOption::Value value (action);
771+ cps::EventManager eventManager;
772+ ce::EventArguments arguments;
773+
774+ option.set (value);
775+ option.value ().action ().setInitiate (initiate);
776+ option.value ().action ().setState (CompAction::StateInitButton);
777+ compiz::actions::setActionActiveState (option.value ().action (), true);
778+
779+ EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, testingButtonState))
780+ .WillOnce (Return (true));
781+ EXPECT_CALL (triggerableAction, initiate (&option.value ().action (),
782+ CompAction::StateInitButton,
783+ arguments)).WillOnce (Return (true));
784+ EXPECT_TRUE (ce::activateButtonPressOnWindowBindingOption (option,
785+ testingButtonNumber,
786+ testingButtonState,
787+ eventManager,
788+ matchEventState,
789+ arguments));
790+}
791+
792+TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnInvalidEdge)
793+{
794+ CompAction action;
795+ CompOption option ("button", CompOption::TypeButton);
796+ CompOption::Value value (action);
797+ cps::EventManager eventManager;
798+ MockTriggerableAction triggerableAction;
799+ ce::EventArguments arguments;
800+ int edgeMask = -1;
801+
802+ option.set (value);
803+
804+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
805+ GetMatchEventStateFuncForMock (triggerableAction);
806+
807+ EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
808+ testingButtonNumber,
809+ testingButtonState,
810+ edgeMask,
811+ eventManager,
812+ matchEventState,
813+ arguments));
814+}
815+
816+TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnUnboundAction)
817+{
818+ CompAction action;
819+ CompOption option ("button", CompOption::TypeButton);
820+ CompOption::Value value (action);
821+ cps::EventManager eventManager;
822+ MockTriggerableAction triggerableAction;
823+ ce::EventArguments arguments;
824+ int edgeMask = 1 << SCREEN_EDGE_TOP;
825+
826+ option.set (value);
827+
828+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
829+ GetMatchEventStateFuncForMock (triggerableAction);
830+
831+ EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
832+ testingButtonNumber,
833+ testingButtonState,
834+ edgeMask,
835+ eventManager,
836+ matchEventState,
837+ arguments));
838+}
839+
840+TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedEdgeMask)
841+{
842+ CompAction action;
843+ MockTriggerableAction triggerableAction;
844+ int edgeMask = 1 << SCREEN_EDGE_TOP;
845+
846+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
847+ GetMatchEventStateFuncForMock (triggerableAction);
848+ const CompAction::CallBack &initiate =
849+ GetInitiateForMock (triggerableAction);
850+
851+ action.setButton (CompAction::ButtonBinding (testingButtonNumber,
852+ testingButtonState));
853+ action.setEdgeMask (edgeMask);
854+
855+ CompOption option ("button", CompOption::TypeButton);
856+ CompOption::Value value (action);
857+ cps::EventManager eventManager;
858+ ce::EventArguments arguments;
859+
860+
861+ option.set (value);
862+ option.value ().action ().setInitiate (initiate);
863+ option.value ().action ().setState (CompAction::StateInitButton);
864+ compiz::actions::setActionActiveState (option.value ().action (), true);
865+
866+ EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
867+ EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
868+ testingButtonNumber,
869+ testingButtonState,
870+ 0,
871+ eventManager,
872+ matchEventState,
873+ arguments));
874+}
875+
876+TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedButtonNumber)
877+{
878+ CompAction action;
879+ MockTriggerableAction triggerableAction;
880+ int edgeMask = 1 << SCREEN_EDGE_TOP;
881+
882+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
883+ GetMatchEventStateFuncForMock (triggerableAction);
884+ const CompAction::CallBack &initiate =
885+ GetInitiateForMock (triggerableAction);
886+
887+ action.setButton (CompAction::ButtonBinding (testingButtonNumber,
888+ testingButtonState));
889+ action.setEdgeMask (edgeMask);
890+
891+ CompOption option ("button", CompOption::TypeButton);
892+ CompOption::Value value (action);
893+ cps::EventManager eventManager;
894+ ce::EventArguments arguments;
895+
896+
897+ option.set (value);
898+ option.value ().action ().setInitiate (initiate);
899+ option.value ().action ().setState (CompAction::StateInitButton);
900+ compiz::actions::setActionActiveState (option.value ().action (), true);
901+
902+ EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
903+ EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
904+ 0,
905+ testingButtonState,
906+ edgeMask,
907+ eventManager,
908+ matchEventState,
909+ arguments));
910+}
911+
912+TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedButtonState)
913+{
914+ CompAction action;
915+ MockTriggerableAction triggerableAction;
916+ int edgeMask = 1 << SCREEN_EDGE_TOP;
917+
918+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
919+ GetMatchEventStateFuncForMock (triggerableAction);
920+ const CompAction::CallBack &initiate =
921+ GetInitiateForMock (triggerableAction);
922+
923+ action.setButton (CompAction::ButtonBinding (testingButtonNumber,
924+ testingButtonState));
925+ action.setEdgeMask (edgeMask);
926+
927+
928+ CompOption option ("button", CompOption::TypeButton);
929+ CompOption::Value value (action);
930+ cps::EventManager eventManager;
931+ ce::EventArguments arguments;
932+
933+ option.set (value);
934+ option.value ().action ().setInitiate (initiate);
935+ option.value ().action ().setState (CompAction::StateInitButton);
936+ compiz::actions::setActionActiveState (option.value ().action (), true);
937+
938+ EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, 0))
939+ .WillOnce (Return (false));
940+ EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
941+ EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
942+ testingButtonNumber,
943+ 0,
944+ edgeMask,
945+ eventManager,
946+ matchEventState,
947+ arguments));
948+}
949+
950+TEST (privatescreen_ButtonPressEdgeEventManagementTest, TriggerWhenStateButtonAndEdgeMaskMatch)
951+{
952+ CompAction action;
953+ MockTriggerableAction triggerableAction;
954+ int edgeMask = 1 << SCREEN_EDGE_TOP;
955+
956+ const ce::ActionModsMatchesEventStateFunc &matchEventState =
957+ GetMatchEventStateFuncForMock (triggerableAction);
958+ const CompAction::CallBack &initiate =
959+ GetInitiateForMock (triggerableAction);
960+
961+ action.setButton (CompAction::ButtonBinding (testingButtonNumber,
962+ testingButtonState));
963+ action.setEdgeMask (edgeMask);
964+
965+ CompOption option ("button", CompOption::TypeButton);
966+ CompOption::Value value (action);
967+ cps::EventManager eventManager;
968+ ce::EventArguments arguments;
969+
970+ option.set (value);
971+ option.value ().action ().setInitiate (initiate);
972+ option.value ().action ().setState (CompAction::StateInitButton |
973+ CompAction::StateInitEdge);
974+ compiz::actions::setActionActiveState (option.value ().action (), true);
975+
976+ EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, testingButtonState))
977+ .WillOnce (Return (true));
978+ EXPECT_CALL (triggerableAction, initiate (&option.value ().action (),
979+ CompAction::StateInitButton |
980+ CompAction::StateInitEdge,
981+ arguments)).WillOnce (Return (true));
982+ EXPECT_TRUE (ce::activateButtonPressOnEdgeBindingOption (option,
983+ testingButtonNumber,
984+ testingButtonState,
985+ edgeMask,
986+ eventManager,
987+ matchEventState,
988+ arguments));
989+}
990+
991+TEST (privatescreen_ActionActiveTest, TestMakeActionActive)
992+{
993+ CompAction action;
994+
995+ ASSERT_EQ (action.active (), false);
996+ compiz::actions::setActionActiveState (action, true);
997+ ASSERT_EQ (action.active (), true);
998+ compiz::actions::setActionActiveState (action, false);
999+ ASSERT_EQ (action.active (), false);
1000+}
1001
1002=== modified file 'src/screen.cpp'
1003--- src/screen.cpp 2012-09-18 01:44:23 +0000
1004+++ src/screen.cpp 2012-09-22 03:07:19 +0000
1005@@ -89,6 +89,7 @@
1006 } MwmHints;
1007
1008 namespace cps = compiz::private_screen;
1009+namespace ca = compiz::actions;
1010
1011
1012
1013@@ -3565,7 +3566,7 @@
1014 privateScreen.enableEdge (i);
1015 }
1016
1017- action->priv->active = true;
1018+ ca::setActionActiveState (*action, true);
1019
1020 return true;
1021 }
1022@@ -3594,7 +3595,7 @@
1023 privateScreen.disableEdge (i);
1024 }
1025
1026- action->priv->active = false;
1027+ ca::setActionActiveState (*action, false);
1028 }
1029
1030 CompRect

Subscribers

People subscribed via source and target branches