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
=== modified file 'include/core/action.h'
--- include/core/action.h 2012-09-07 22:37:20 +0000
+++ include/core/action.h 2012-09-22 03:07:19 +0000
@@ -34,6 +34,14 @@
3434
35#include <X11/Xlib-xcb.h>35#include <X11/Xlib-xcb.h>
3636
37namespace compiz
38{
39 namespace actions
40 {
41 void setActionActiveState (const CompAction &action,
42 bool active);
43 }
44}
3745
38class PrivateAction;46class PrivateAction;
3947
@@ -171,7 +179,10 @@
171179
172 bool active ();180 bool active ();
173181
174 friend class CompScreenImpl;182 /* BCI: Not optimal, CompAction should implement
183 * BoundAction instead or be a PV class */
184 friend void compiz::actions::setActionActiveState (const CompAction &action,
185 bool active);
175186
176 private:187 private:
177 PrivateAction *priv;188 PrivateAction *priv;
178189
=== modified file 'include/core/option.h'
--- include/core/option.h 2012-05-30 09:24:15 +0000
+++ include/core/option.h 2012-09-22 03:07:19 +0000
@@ -244,8 +244,10 @@
244244
245 CompString name ();245 CompString name ();
246246
247 Type type ();247 Type type () const;
248 Value & value ();248 Type type (); // BCI: drop this in 0.9.9
249 Value & value () const;
250 Value & value (); // BCI: drop this in 0.9.9
249 Restriction & rest ();251 Restriction & rest ();
250252
251 bool set (Value &val);253 bool set (Value &val);
252254
=== modified file 'src/action.cpp'
--- src/action.cpp 2012-05-10 12:58:01 +0000
+++ src/action.cpp 2012-09-22 03:07:19 +0000
@@ -33,6 +33,8 @@
33#include <core/screen.h>33#include <core/screen.h>
34#include "privateaction.h"34#include "privateaction.h"
3535
36namespace ca = compiz::actions;
37
36struct _Modifier {38struct _Modifier {
37 const char *name;39 const char *name;
38 int modifier;40 int modifier;
@@ -626,6 +628,28 @@
626 return priv->active;628 return priv->active;
627}629}
628630
631void
632PrivateAction::makeActive ()
633{
634 active = true;
635}
636
637void
638PrivateAction::makeInactive ()
639{
640 active = false;
641}
642
643void
644ca::setActionActiveState (const CompAction &action,
645 bool active)
646{
647 if (active)
648 action.priv->makeActive ();
649 else
650 action.priv->makeInactive ();
651}
652
629PrivateAction::PrivateAction () :653PrivateAction::PrivateAction () :
630 initiate (),654 initiate (),
631 terminate (),655 terminate (),
632656
=== modified file 'src/event.cpp'
--- src/event.cpp 2012-09-05 16:42:03 +0000
+++ src/event.cpp 2012-09-22 03:07:19 +0000
@@ -41,8 +41,10 @@
41#include "privatescreen.h"41#include "privatescreen.h"
42#include "privatewindow.h"42#include "privatewindow.h"
43#include "privatestackdebugger.h"43#include "privatestackdebugger.h"
44#include "eventmanagement.h"
4445
45namespace cps = compiz::private_screen;46namespace cps = compiz::private_screen;
47namespace ce = compiz::events;
4648
47namespace49namespace
48{50{
@@ -124,6 +126,9 @@
124 if (option.value ().action ().initiate ().empty ())126 if (option.value ().action ().initiate ().empty ())
125 return false;127 return false;
126128
129 if (!option.value ().action ().active ())
130 return false;
131
127 *action = &option.value ().action ();132 *action = &option.value ().action ();
128133
129 return true;134 return true;
@@ -189,78 +194,160 @@
189 return false;194 return false;
190}195}
191196
197int
198ce::processButtonPressOnEdgeWindow (Window edgeWindow,
199 Window root,
200 Window eventWindow,
201 Window eventRoot,
202 cps::GrabList &grabList,
203 const CompScreenEdge *screenEdge)
204{
205 int edge = -1;
206
207 if (eventRoot != root)
208 return edge;
209
210 if (eventWindow != edgeWindow)
211 {
212 if (grabList.grabsEmpty () ||
213 eventRoot != root)
214 return edge;
215 }
216
217 for (unsigned int i = 0; i < SCREEN_EDGE_NUM; i++)
218 {
219 if (edgeWindow == screenEdge[i].id)
220 {
221 edge = 1 << i;
222 break;
223 }
224 }
225
226 return edge;
227}
228
229void
230ce::setEventWindowInButtonPressArguments (ce::EventArguments &arguments,
231 Window eventWindow)
232{
233 arguments[1].value ().set ((int) eventWindow);
234}
235
236namespace
237{
238 bool buttonActionModifiersMatchEventState (unsigned int actionModifiers,
239 unsigned int eventState)
240 {
241 const unsigned int ignored = modHandler->ignoredModMask ();
242 const unsigned int modMask = REAL_MOD_MASK & ~ignored;
243 const unsigned int bindMods = modHandler->virtualToRealModMask (actionModifiers);
244
245 return (bindMods & modMask) == (eventState & modMask);
246 }
247}
248
249bool
250ce::activateButtonPressOnWindowBindingOption (CompOption &option,
251 unsigned int eventButton,
252 unsigned int eventState,
253 cps::EventManager &eventManager,
254 const ActionModsMatchesEventStateFunc &matchEventState,
255 ce::EventArguments &arguments)
256{
257 CompAction *action;
258 const CompAction::State state = CompAction::StateInitButton;
259
260 if (isBound (option, CompAction::BindingTypeButton, state, &action))
261 {
262 if (action->button ().button () == (int) eventButton)
263 {
264 if (matchEventState (action->button ().modifiers (),
265 eventState))
266 {
267 if (eventManager.triggerPress (action, state, arguments))
268 return true;
269 }
270 }
271 }
272
273 return false;
274}
275
276bool
277ce::activateButtonPressOnEdgeBindingOption (CompOption &option,
278 unsigned int eventButton,
279 unsigned int eventState,
280 int edge,
281 cps::EventManager &eventManager,
282 const ActionModsMatchesEventStateFunc &matchEventState,
283 ce::EventArguments &arguments)
284{
285 CompAction *action;
286 const CompAction::State state = CompAction::StateInitButton |
287 CompAction::StateInitEdge;
288
289 if (edge != -1)
290 {
291 if (isInitiateBinding (option, CompAction::BindingTypeEdgeButton,
292 state, &action))
293 {
294 if ((action->button ().button () == (int) eventButton) &&
295 (action->edgeMask () & edge))
296 {
297 if (matchEventState (action->button ().modifiers (),
298 eventState))
299 if (action->initiate () (action, state,
300 arguments))
301 return true;
302 }
303 }
304 }
305
306 return false;
307}
308
192bool309bool
193PrivateScreen::triggerButtonPressBindings (CompOption::Vector &options,310PrivateScreen::triggerButtonPressBindings (CompOption::Vector &options,
194 XButtonEvent *event,311 XButtonEvent *event,
195 CompOption::Vector &arguments)312 CompOption::Vector &arguments)
196{313{
197 CompAction::State state = CompAction::StateInitButton;314 int edge = -1;
198 CompAction *action;315
199 unsigned int ignored = modHandler->ignoredModMask ();316 static const ce::ActionModsMatchesEventStateFunc matchEventState (
200 unsigned int modMask = REAL_MOD_MASK & ~ignored;317 boost::bind (buttonActionModifiersMatchEventState,
201 unsigned int bindMods;318 _1, _2));
202 unsigned int edge = 0;
203319
204 if (edgeWindow)320 if (edgeWindow)
205 {321 edge = ce::processButtonPressOnEdgeWindow (edgeWindow,
206 unsigned int i;322 screen->root (),
207323 event->window,
208 if (event->root != screen->root())324 event->root,
209 return false;325 eventManager,
210326 screenEdge);
211 if (event->window != edgeWindow)327
212 {328 if (edge != -1)
213 if (eventManager.grabsEmpty () || event->window != screen->root())329 ce::setEventWindowInButtonPressArguments (arguments,
214 return false;330 orphanData.activeWindow);
215 }
216
217 for (i = 0; i < SCREEN_EDGE_NUM; i++)
218 {
219 if (edgeWindow == screenEdge[i].id)
220 {
221 edge = 1 << i;
222 arguments[1].value ().set ((int) orphanData.activeWindow);
223 break;
224 }
225 }
226 }
227331
228 foreach (CompOption &option, options)332 foreach (CompOption &option, options)
229 {333 {
230 if (isBound (option, CompAction::BindingTypeButton, state, &action))334 if (ce::activateButtonPressOnWindowBindingOption (option,
231 {335 event->button,
232 if (action->button ().button () == (int) event->button)336 event->state,
233 {337 eventManager,
234 bindMods = modHandler->virtualToRealModMask (338 matchEventState,
235 action->button ().modifiers ());339 arguments))
236340 return true;
237 if ((bindMods & modMask) == (event->state & modMask))341
238 {342 if (ce::activateButtonPressOnEdgeBindingOption (option,
239 if (eventManager.triggerPress (action, state, arguments))343 event->button,
240 return true;344 event->state,
241 }345 edge,
242 }346 eventManager,
243 }347 matchEventState,
244348 arguments))
245 if (edge)349 return true;
246 {350
247 if (isInitiateBinding (option, CompAction::BindingTypeEdgeButton,
248 state | CompAction::StateInitEdge, &action))
249 {
250 if ((action->button ().button () == (int) event->button) &&
251 (action->edgeMask () & edge))
252 {
253 bindMods = modHandler->virtualToRealModMask (
254 action->button ().modifiers ());
255
256 if ((bindMods & modMask) == (event->state & modMask))
257 if (action->initiate () (action, state |
258 CompAction::StateInitEdge,
259 arguments))
260 return true;
261 }
262 }
263 }
264 }351 }
265352
266 return false;353 return false;
267354
=== modified file 'src/option.cpp'
--- src/option.cpp 2012-06-24 09:00:27 +0000
+++ src/option.cpp 2012-09-22 03:07:19 +0000
@@ -462,12 +462,24 @@
462 return priv->type;462 return priv->type;
463}463}
464464
465CompOption::Type
466CompOption::type () const
467{
468 return priv->type;
469}
470
465CompOption::Value &471CompOption::Value &
466CompOption::value ()472CompOption::value ()
467{473{
468 return priv->value;474 return priv->value;
469}475}
470476
477CompOption::Value &
478CompOption::value () const
479{
480 return priv->value;
481}
482
471CompOption::Restriction &483CompOption::Restriction &
472CompOption::rest ()484CompOption::rest ()
473{485{
@@ -477,6 +489,12 @@
477bool489bool
478CompOption::set (CompOption::Value &val)490CompOption::set (CompOption::Value &val)
479{491{
492 /* XXX: It is uncertain as to why this is done. The only
493 * logical reason would be that actions are stateful and
494 * we don't want to care about the old state from the
495 * action that we're setting this value to, so we're just
496 * clearing that state and starting over, however copyState
497 * does a lot more than that */
480 if (isAction () && priv->type != CompOption::TypeAction)498 if (isAction () && priv->type != CompOption::TypeAction)
481 val.action ().copyState (priv->value.action ());499 val.action ().copyState (priv->value.action ());
482500
483501
=== modified file 'src/option/tests/option.cpp'
--- src/option/tests/option.cpp 2012-05-27 03:27:57 +0000
+++ src/option/tests/option.cpp 2012-09-22 03:07:19 +0000
@@ -206,3 +206,34 @@
206 ASSERT_EQ(expectTwo, as_const.f());206 ASSERT_EQ(expectTwo, as_const.f());
207 }207 }
208}208}
209
210TEST (CompOption, AssignDefaultActionValueToUnsetTypeClearsOldStateKeepsInfo)
211{
212 /* Value is unset at this point */
213 CompOption option ("testing", CompOption::TypeKey);
214 CompAction action;
215
216 /* We need to set up the state here as
217 * the CompOption::Value constructor makes
218 * a copy of the action */
219 action.setState (CompAction::StateInitKey);
220 action.setButton (CompAction::ButtonBinding (1,
221 1 << 1));
222
223 CompOption::Value value (action);
224
225 ASSERT_EQ (value.action ().state (), CompAction::StateInitKey);
226
227 /* Actually set the action value, this will
228 * overwrite the internal value */
229 option.set (value);
230
231 /* We don't care about the old action's state, so get
232 * rid of it */
233 ASSERT_EQ (option.value ().action ().state (), 0);
234
235 /* We do want to keep the non-stateful data which is
236 * pure info */
237 ASSERT_EQ (option.value ().action ().button ().button (), 1);
238 ASSERT_EQ (option.value ().action ().button ().modifiers (), 1 << 1);
239}
209240
=== modified file 'src/privateaction.h'
--- src/privateaction.h 2012-02-14 11:39:59 +0000
+++ src/privateaction.h 2012-09-22 03:07:19 +0000
@@ -28,11 +28,35 @@
28#ifndef _PRIVATEACTION_H28#ifndef _PRIVATEACTION_H
29#define _PRIVATEACTION_H29#define _PRIVATEACTION_H
3030
31class PrivateAction {31namespace compiz
32{
33 namespace actions
34 {
35 class BoundAction
36 {
37 public:
38
39 virtual ~BoundAction () {}
40
41 virtual void makeActive () = 0;
42 virtual void makeInactive () = 0;
43 };
44
45 void setActionActiveState (const CompAction &action,
46 bool active);
47 }
48}
49
50class PrivateAction :
51 public compiz::actions::BoundAction
52{
32 public:53 public:
33 PrivateAction ();54 PrivateAction ();
34 PrivateAction (const PrivateAction&);55 PrivateAction (const PrivateAction&);
3556
57 void makeActive ();
58 void makeInactive ();
59
36 CompAction::CallBack initiate;60 CompAction::CallBack initiate;
37 CompAction::CallBack terminate;61 CompAction::CallBack terminate;
3862
3963
=== modified file 'src/privatescreen/tests/test-privatescreen.cpp'
--- src/privatescreen/tests/test-privatescreen.cpp 2012-06-24 09:00:27 +0000
+++ src/privatescreen/tests/test-privatescreen.cpp 2012-09-22 03:07:19 +0000
@@ -1,5 +1,6 @@
1#include "privatescreen.h"1#include "privatescreen.h"
22#include "privateaction.h"
3#include "eventmanagement.h"
34
4// Get rid of stupid macro from X.h5// Get rid of stupid macro from X.h
5// Why, oh why, are we including X.h?6// Why, oh why, are we including X.h?
@@ -16,6 +17,8 @@
1617
17namespace {18namespace {
1819
20const unsigned long None = 0;
21
19class MockCompScreen : public CompScreen22class MockCompScreen : public CompScreen
20{23{
21public:24public:
@@ -355,6 +358,7 @@
355} // (abstract) namespace358} // (abstract) namespace
356359
357namespace cps = compiz::private_screen;360namespace cps = compiz::private_screen;
361namespace ce = compiz::events;
358362
359TEST(privatescreen_PluginManagerTest, create_and_destroy)363TEST(privatescreen_PluginManagerTest, create_and_destroy)
360{364{
@@ -909,3 +913,511 @@
909913
910 EXPECT_EQ (vp, CompPoint (0, 1));914 EXPECT_EQ (vp, CompPoint (0, 1));
911}915}
916
917namespace
918{
919 const Window topLeftScreenEdge = 1;
920 const Window topScreenEdge = 2;
921 const Window topRightScreenEdge = 3;
922 const Window rightScreenEdge = 4;
923 const Window bottomRightScreenEdge = 5;
924 const Window bottomScreenEdge = 6;
925 const Window bottomLeftScreenEdge = 7;
926 const Window leftScreenEdge = 8;
927
928 const CompScreenEdge screenEdges[SCREEN_EDGE_NUM] =
929 {
930 { leftScreenEdge, SCREEN_EDGE_LEFT },
931 { rightScreenEdge, SCREEN_EDGE_RIGHT },
932 { topScreenEdge, SCREEN_EDGE_TOP },
933 { bottomScreenEdge , SCREEN_EDGE_BOTTOM },
934 { topLeftScreenEdge, SCREEN_EDGE_TOPLEFT },
935 { topRightScreenEdge, SCREEN_EDGE_TOPRIGHT },
936 { bottomLeftScreenEdge, SCREEN_EDGE_BOTTOMLEFT },
937 { bottomRightScreenEdge, SCREEN_EDGE_BOTTOMRIGHT}
938 };
939}
940
941TEST (privatescreen_ButtonPressEdgeEventManagementTest, IgnoreWhenEventAndRootWindowMismatch)
942{
943 const Window rootWindow = 1;
944 const Window edgeWindow = topScreenEdge;
945
946 cps::OrphanData orphanData;
947 cps::GrabList grabList;
948
949 EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
950 rootWindow,
951 0,
952 0,
953 grabList,
954 screenEdges), -1);
955}
956
957TEST (privatescreen_ButtonPressEdgeEventManagementTest, IgnoreWhenEventMismatchAndNoGrabs)
958{
959 const Window rootWindow = 1;
960 const Window edgeWindow = topScreenEdge;
961
962 cps::OrphanData orphanData;
963 cps::GrabList grabList;
964
965 EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
966 rootWindow,
967 0,
968 rootWindow,
969 grabList,
970 screenEdges), -1);
971}
972
973TEST (privatescreen_ButtonPressEdgeEventManagementTest, AllowWhenEventButNotRootWindowMismatchWhileGrabbed)
974{
975 const Window rootWindow = 1;
976 const Window edgeWindow = topScreenEdge;
977 unsigned int topEdgeMask = 1 << SCREEN_EDGE_TOP;
978
979 cps::OrphanData orphanData;
980 cps::GrabList grabList;
981
982 grabList.grabsPush (new cps::Grab (None, "Nil"));
983
984 EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
985 rootWindow,
986 0,
987 rootWindow,
988 grabList,
989 screenEdges), topEdgeMask);
990
991 grabList.grabsRemove (grabList.grabsBack ());
992}
993
994TEST (privatescreen_ButtonPressEventManagementTest, SetEventWindowArgument)
995{
996 const Window activeWindow = 1;
997
998 ce::EventArguments arguments (2);
999 ce::setEventWindowInButtonPressArguments (arguments, activeWindow);
1000 EXPECT_EQ (arguments[1].value ().i (), activeWindow);
1001}
1002
1003namespace
1004{
1005 class MockTriggerableAction
1006 {
1007 public:
1008
1009 MOCK_METHOD2 (matchEventState, bool (unsigned int,
1010 unsigned int));
1011 MOCK_METHOD3 (initiate, bool (CompAction *,
1012 CompAction::State ,
1013 CompOption::Vector &));
1014 MOCK_METHOD3 (terminate, bool (CompAction *,
1015 CompAction::State ,
1016 CompOption::Vector &));
1017 };
1018
1019 const unsigned int testingButtonNumber = 1;
1020 const unsigned int testingButtonState = (1 << 1);
1021
1022 ce::ActionModsMatchesEventStateFunc
1023 GetMatchEventStateFuncForMock (MockTriggerableAction &triggerableAction)
1024 {
1025 return boost::bind (&MockTriggerableAction::matchEventState,
1026 &triggerableAction,
1027 _1, _2);
1028 }
1029
1030 CompAction::CallBack
1031 GetInitiateForMock (MockTriggerableAction &triggerableAction)
1032 {
1033 return boost::bind (&MockTriggerableAction::initiate,
1034 &triggerableAction,
1035 _1, _2, _3);
1036 }
1037
1038 CompAction::CallBack
1039 GetTerminateForMock (MockTriggerableAction &triggerableAction)
1040 {
1041 return boost::bind (&MockTriggerableAction::terminate,
1042 &triggerableAction,
1043 _1, _2, _3);
1044 }
1045}
1046
1047bool operator== (const CompOption &lhs,
1048 const CompOption &rhs)
1049{
1050 if (lhs.type () != rhs.type ())
1051 return false;
1052
1053 return lhs.value () == rhs.value ();
1054}
1055
1056TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnUnboundAction)
1057{
1058 CompAction action;
1059 CompOption option ("button", CompOption::TypeButton);
1060 CompOption::Value value (action);
1061 cps::EventManager eventManager;
1062 MockTriggerableAction triggerableAction;
1063 ce::EventArguments arguments;
1064
1065 option.set (value);
1066
1067 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1068 GetMatchEventStateFuncForMock (triggerableAction);
1069
1070 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1071 testingButtonNumber,
1072 testingButtonState,
1073 eventManager,
1074 matchEventState,
1075 arguments));
1076}
1077
1078TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnUnboundInactiveAction)
1079{
1080 CompAction action;
1081 MockTriggerableAction triggerableAction;
1082 int edgeMask = 1 << SCREEN_EDGE_TOP;
1083
1084 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1085 GetMatchEventStateFuncForMock (triggerableAction);
1086 const CompAction::CallBack &initiate =
1087 GetInitiateForMock (triggerableAction);
1088
1089 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1090 testingButtonState));
1091 action.setEdgeMask (edgeMask);
1092
1093
1094 CompOption option ("button", CompOption::TypeButton);
1095 CompOption::Value value (action);
1096 cps::EventManager eventManager;
1097 ce::EventArguments arguments;
1098
1099 option.set (value);
1100 option.value ().action ().setInitiate (initiate);
1101 option.value ().action ().setState (CompAction::StateInitButton);
1102 compiz::actions::setActionActiveState (option.value ().action (), false);
1103
1104 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1105 testingButtonNumber,
1106 testingButtonState,
1107 edgeMask,
1108 eventManager,
1109 matchEventState,
1110 arguments));
1111}
1112
1113TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnMismatchedButtonNumber)
1114{
1115 CompAction action;
1116 MockTriggerableAction triggerableAction;
1117
1118 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1119 GetMatchEventStateFuncForMock (triggerableAction);
1120 const CompAction::CallBack &initiate =
1121 GetInitiateForMock (triggerableAction);
1122
1123 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1124 testingButtonState));
1125
1126 CompOption option ("button", CompOption::TypeButton);
1127 CompOption::Value value (action);
1128 cps::EventManager eventManager;
1129 ce::EventArguments arguments;
1130
1131 option.set (value);
1132 option.value ().action ().setInitiate (initiate);
1133 option.value ().action ().setState (CompAction::StateInitButton);
1134 compiz::actions::setActionActiveState (option.value ().action (), true);
1135
1136 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1137 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1138 0,
1139 testingButtonState,
1140 eventManager,
1141 matchEventState,
1142 arguments));
1143}
1144
1145TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnMismatchedButtonState)
1146{
1147 CompAction action;
1148 MockTriggerableAction triggerableAction;
1149
1150 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1151 GetMatchEventStateFuncForMock (triggerableAction);
1152 const CompAction::CallBack &initiate =
1153 GetInitiateForMock (triggerableAction);
1154
1155 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1156 testingButtonState));
1157
1158 CompOption option ("button", CompOption::TypeButton);
1159 CompOption::Value value (action);
1160 cps::EventManager eventManager;
1161 ce::EventArguments arguments;
1162
1163 option.set (value);
1164 option.value ().action ().setInitiate (initiate);
1165 option.value ().action ().setState (CompAction::StateInitButton);
1166 compiz::actions::setActionActiveState (option.value ().action (), true);
1167
1168 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, 0))
1169 .WillOnce (Return (false));
1170 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1171 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1172 testingButtonNumber,
1173 0,
1174 eventManager,
1175 matchEventState,
1176 arguments));
1177}
1178
1179TEST (privatescreen_ButtonPressEventManagementTest, TriggerWhenStateAndButtonMatch)
1180{
1181 CompAction action;
1182 MockTriggerableAction triggerableAction;
1183
1184 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1185 GetMatchEventStateFuncForMock (triggerableAction);
1186 const CompAction::CallBack &initiate =
1187 GetInitiateForMock (triggerableAction);
1188
1189 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1190 testingButtonState));
1191
1192 CompOption option ("button", CompOption::TypeButton);
1193 CompOption::Value value (action);
1194 cps::EventManager eventManager;
1195 ce::EventArguments arguments;
1196
1197 option.set (value);
1198 option.value ().action ().setInitiate (initiate);
1199 option.value ().action ().setState (CompAction::StateInitButton);
1200 compiz::actions::setActionActiveState (option.value ().action (), true);
1201
1202 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, testingButtonState))
1203 .WillOnce (Return (true));
1204 EXPECT_CALL (triggerableAction, initiate (&option.value ().action (),
1205 CompAction::StateInitButton,
1206 arguments)).WillOnce (Return (true));
1207 EXPECT_TRUE (ce::activateButtonPressOnWindowBindingOption (option,
1208 testingButtonNumber,
1209 testingButtonState,
1210 eventManager,
1211 matchEventState,
1212 arguments));
1213}
1214
1215TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnInvalidEdge)
1216{
1217 CompAction action;
1218 CompOption option ("button", CompOption::TypeButton);
1219 CompOption::Value value (action);
1220 cps::EventManager eventManager;
1221 MockTriggerableAction triggerableAction;
1222 ce::EventArguments arguments;
1223 int edgeMask = -1;
1224
1225 option.set (value);
1226
1227 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1228 GetMatchEventStateFuncForMock (triggerableAction);
1229
1230 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1231 testingButtonNumber,
1232 testingButtonState,
1233 edgeMask,
1234 eventManager,
1235 matchEventState,
1236 arguments));
1237}
1238
1239TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnUnboundAction)
1240{
1241 CompAction action;
1242 CompOption option ("button", CompOption::TypeButton);
1243 CompOption::Value value (action);
1244 cps::EventManager eventManager;
1245 MockTriggerableAction triggerableAction;
1246 ce::EventArguments arguments;
1247 int edgeMask = 1 << SCREEN_EDGE_TOP;
1248
1249 option.set (value);
1250
1251 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1252 GetMatchEventStateFuncForMock (triggerableAction);
1253
1254 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1255 testingButtonNumber,
1256 testingButtonState,
1257 edgeMask,
1258 eventManager,
1259 matchEventState,
1260 arguments));
1261}
1262
1263TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedEdgeMask)
1264{
1265 CompAction action;
1266 MockTriggerableAction triggerableAction;
1267 int edgeMask = 1 << SCREEN_EDGE_TOP;
1268
1269 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1270 GetMatchEventStateFuncForMock (triggerableAction);
1271 const CompAction::CallBack &initiate =
1272 GetInitiateForMock (triggerableAction);
1273
1274 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1275 testingButtonState));
1276 action.setEdgeMask (edgeMask);
1277
1278 CompOption option ("button", CompOption::TypeButton);
1279 CompOption::Value value (action);
1280 cps::EventManager eventManager;
1281 ce::EventArguments arguments;
1282
1283
1284 option.set (value);
1285 option.value ().action ().setInitiate (initiate);
1286 option.value ().action ().setState (CompAction::StateInitButton);
1287 compiz::actions::setActionActiveState (option.value ().action (), true);
1288
1289 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1290 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1291 testingButtonNumber,
1292 testingButtonState,
1293 0,
1294 eventManager,
1295 matchEventState,
1296 arguments));
1297}
1298
1299TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedButtonNumber)
1300{
1301 CompAction action;
1302 MockTriggerableAction triggerableAction;
1303 int edgeMask = 1 << SCREEN_EDGE_TOP;
1304
1305 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1306 GetMatchEventStateFuncForMock (triggerableAction);
1307 const CompAction::CallBack &initiate =
1308 GetInitiateForMock (triggerableAction);
1309
1310 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1311 testingButtonState));
1312 action.setEdgeMask (edgeMask);
1313
1314 CompOption option ("button", CompOption::TypeButton);
1315 CompOption::Value value (action);
1316 cps::EventManager eventManager;
1317 ce::EventArguments arguments;
1318
1319
1320 option.set (value);
1321 option.value ().action ().setInitiate (initiate);
1322 option.value ().action ().setState (CompAction::StateInitButton);
1323 compiz::actions::setActionActiveState (option.value ().action (), true);
1324
1325 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1326 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1327 0,
1328 testingButtonState,
1329 edgeMask,
1330 eventManager,
1331 matchEventState,
1332 arguments));
1333}
1334
1335TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedButtonState)
1336{
1337 CompAction action;
1338 MockTriggerableAction triggerableAction;
1339 int edgeMask = 1 << SCREEN_EDGE_TOP;
1340
1341 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1342 GetMatchEventStateFuncForMock (triggerableAction);
1343 const CompAction::CallBack &initiate =
1344 GetInitiateForMock (triggerableAction);
1345
1346 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1347 testingButtonState));
1348 action.setEdgeMask (edgeMask);
1349
1350
1351 CompOption option ("button", CompOption::TypeButton);
1352 CompOption::Value value (action);
1353 cps::EventManager eventManager;
1354 ce::EventArguments arguments;
1355
1356 option.set (value);
1357 option.value ().action ().setInitiate (initiate);
1358 option.value ().action ().setState (CompAction::StateInitButton);
1359 compiz::actions::setActionActiveState (option.value ().action (), true);
1360
1361 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, 0))
1362 .WillOnce (Return (false));
1363 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1364 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1365 testingButtonNumber,
1366 0,
1367 edgeMask,
1368 eventManager,
1369 matchEventState,
1370 arguments));
1371}
1372
1373TEST (privatescreen_ButtonPressEdgeEventManagementTest, TriggerWhenStateButtonAndEdgeMaskMatch)
1374{
1375 CompAction action;
1376 MockTriggerableAction triggerableAction;
1377 int edgeMask = 1 << SCREEN_EDGE_TOP;
1378
1379 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1380 GetMatchEventStateFuncForMock (triggerableAction);
1381 const CompAction::CallBack &initiate =
1382 GetInitiateForMock (triggerableAction);
1383
1384 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1385 testingButtonState));
1386 action.setEdgeMask (edgeMask);
1387
1388 CompOption option ("button", CompOption::TypeButton);
1389 CompOption::Value value (action);
1390 cps::EventManager eventManager;
1391 ce::EventArguments arguments;
1392
1393 option.set (value);
1394 option.value ().action ().setInitiate (initiate);
1395 option.value ().action ().setState (CompAction::StateInitButton |
1396 CompAction::StateInitEdge);
1397 compiz::actions::setActionActiveState (option.value ().action (), true);
1398
1399 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, testingButtonState))
1400 .WillOnce (Return (true));
1401 EXPECT_CALL (triggerableAction, initiate (&option.value ().action (),
1402 CompAction::StateInitButton |
1403 CompAction::StateInitEdge,
1404 arguments)).WillOnce (Return (true));
1405 EXPECT_TRUE (ce::activateButtonPressOnEdgeBindingOption (option,
1406 testingButtonNumber,
1407 testingButtonState,
1408 edgeMask,
1409 eventManager,
1410 matchEventState,
1411 arguments));
1412}
1413
1414TEST (privatescreen_ActionActiveTest, TestMakeActionActive)
1415{
1416 CompAction action;
1417
1418 ASSERT_EQ (action.active (), false);
1419 compiz::actions::setActionActiveState (action, true);
1420 ASSERT_EQ (action.active (), true);
1421 compiz::actions::setActionActiveState (action, false);
1422 ASSERT_EQ (action.active (), false);
1423}
9121424
=== modified file 'src/screen.cpp'
--- src/screen.cpp 2012-09-18 01:44:23 +0000
+++ src/screen.cpp 2012-09-22 03:07:19 +0000
@@ -89,6 +89,7 @@
89} MwmHints;89} MwmHints;
9090
91namespace cps = compiz::private_screen;91namespace cps = compiz::private_screen;
92namespace ca = compiz::actions;
9293
9394
9495
@@ -3565,7 +3566,7 @@
3565 privateScreen.enableEdge (i);3566 privateScreen.enableEdge (i);
3566 }3567 }
35673568
3568 action->priv->active = true;3569 ca::setActionActiveState (*action, true);
35693570
3570 return true;3571 return true;
3571}3572}
@@ -3594,7 +3595,7 @@
3594 privateScreen.disableEdge (i);3595 privateScreen.disableEdge (i);
3595 }3596 }
35963597
3597 action->priv->active = false;3598 ca::setActionActiveState (*action, false);
3598}3599}
35993600
3600CompRect3601CompRect

Subscribers

People subscribed via source and target branches