Merge lp:~compiz-team/compiz/compiz.fix_1053280 into lp:compiz/0.9.9

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1053280
Merge into: lp:compiz/0.9.9
Diff against target: 1140 lines (+850/-75)
11 files modified
include/core/abiversion.h (+1/-1)
include/core/action.h (+14/-1)
include/core/option.h (+4/-3)
src/action.cpp (+15/-0)
src/event.cpp (+149/-62)
src/eventmanagement.h (+80/-0)
src/option.cpp (+16/-4)
src/option/tests/option.cpp (+31/-0)
src/privateaction.h (+23/-1)
src/privatescreen/tests/test-privatescreen.cpp (+514/-1)
src/screen.cpp (+3/-2)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1053280
Reviewer Review Type Date Requested Status
jenkins (community) continuous-integration Needs Fixing
Daniel van Vugt Needs Fixing
Sam Spilsbury Pending
Review via email: mp+126873@code.launchpad.net

This proposal supersedes a proposal from 2012-09-24.

This proposal has been superseded by a proposal from 2012-10-11.

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 : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Martin Mrazik (mrazik) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

Resubmit per the prereq branch.

review: Needs Resubmitting
Revision history for this message
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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
Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

Resubmitted with typo fixed and file added (sorry about that). Marking resubmit for now as requested, as this bug is no longer high priority.

review: Needs Resubmitting
Revision history for this message
jenkins (martin-mrazik+qa) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal

Resubmit... just so I don't keep forgetting and looking at this again.

review: Needs Resubmitting
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
3394. By Sam Spilsbury

Merge lp:compiz and handle some BCI stuff

3395. By Sam Spilsbury

Constify the API a bit

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

No obvious problems in testing. Just a few things:

1. These should be dropped now:
    Type type (); // BCI: drop this in 0.9.9
If you need to constify functions as part of this proposal then no problem. Otherwise constification and other general clean-ups should be done as separate proposals.

2. BCI, PV? Are those acronyms explained in the source files they're mentioned?

3. I would much prefer that the namespace depth did not affect the indentation of declarations. I would accept:
    namespace a { namespace b {
or
    namespace a {
    namespace b {
Because namespaces should be changeable without affecting the surrounding code. So if the depth changed then you shouldn't ever need to re-indent your code.

4. Two functions:
    PrivateAction::makeActive()
    PrivateAction::makeInactive()
should be one:
    PrivateAction::setActive(bool active)
Which will not only shrink the interface but is much more flexible for callers who want to change the setting based on a bool, like ca::setActionActiveState.

5. End-users of identifiers in namespaces like src/screen.cpp should use:
    using namespace compiz::actions;
    foo
    bar
instead of:
    namespace ca = compiz::actions;
    ca::foo
    ca::bar
It's cleaner to read, and again more flexible should namespaces ever change.

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

> No obvious problems in testing. Just a few things:
>
> 1. These should be dropped now:
> Type type (); // BCI: drop this in 0.9.9
> If you need to constify functions as part of this proposal then no problem.
> Otherwise constification and other general clean-ups should be done as
> separate proposals.

Done. Constification was necessary.

>
> 2. BCI, PV? Are those acronyms explained in the source files they're
> mentioned?

BCI == Binary Compat
PV == Pure Virtual

>
> 3. I would much prefer that the namespace depth did not affect the indentation
> of declarations. I would accept:
> namespace a { namespace b {
> or
> namespace a {
> namespace b {
> Because namespaces should be changeable without affecting the surrounding
> code. So if the depth changed then you shouldn't ever need to re-indent your
> code.

Debatable but okay.

>
> 4. Two functions:
> PrivateAction::makeActive()
> PrivateAction::makeInactive()
> should be one:
> PrivateAction::setActive(bool active)
> Which will not only shrink the interface but is much more flexible for callers
> who want to change the setting based on a bool, like ca::setActionActiveState.
>

Okay

> 5. End-users of identifiers in namespaces like src/screen.cpp should use:
> using namespace compiz::actions;
> foo
> bar
> instead of:
> namespace ca = compiz::actions;
> ca::foo
> ca::bar
> It's cleaner to read, and again more flexible should namespaces ever change.

using is bad because it just imports namespace conflicts and defeats the purpose of namespaces. namespace aliases are designed to fix that problem. Also considering that we have implementation and interface namespaces the conflicts are a very real problem.

3396. By Sam Spilsbury

Cleanup.

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

Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
3397. By Sam Spilsbury

Forward declare correctly

3398. By Sam Spilsbury

Merge lp:compiz

3399. By Daniel van Vugt

Fix build error/warning: Remove unused function.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/core/abiversion.h'
--- include/core/abiversion.h 2012-09-28 08:23:17 +0000
+++ include/core/abiversion.h 2012-10-03 06:22:21 +0000
@@ -5,6 +5,6 @@
5# error Conflicting definitions of CORE_ABIVERSION5# error Conflicting definitions of CORE_ABIVERSION
6#endif6#endif
77
8#define CORE_ABIVERSION 201209278#define CORE_ABIVERSION 20121002
99
10#endif // COMPIZ_ABIVERSION_H10#endif // COMPIZ_ABIVERSION_H
1111
=== modified file 'include/core/action.h'
--- include/core/action.h 2012-09-07 22:37:20 +0000
+++ include/core/action.h 2012-10-03 06:22:21 +0000
@@ -34,6 +34,14 @@
3434
35#include <X11/Xlib-xcb.h>35#include <X11/Xlib-xcb.h>
3636
37namespace compiz
38{
39namespace actions
40{
41void setActionActiveState (const CompAction &action,
42 bool active);
43}
44}
3745
38class PrivateAction;46class PrivateAction;
3947
@@ -171,7 +179,12 @@
171179
172 bool active ();180 bool active ();
173181
174 friend class CompScreenImpl;182 /* CompAction should be a pure virtual class so
183 * that we can pass the interface required to for setActionActiveState
184 * directly rather than using friends
185 */
186 friend void compiz::actions::setActionActiveState (const CompAction &action,
187 bool active);
175188
176 private:189 private:
177 PrivateAction *priv;190 PrivateAction *priv;
178191
=== modified file 'include/core/option.h'
--- include/core/option.h 2012-05-30 09:24:15 +0000
+++ include/core/option.h 2012-10-03 06:22:21 +0000
@@ -242,14 +242,15 @@
242242
243 void reset ();243 void reset ();
244244
245 CompString name ();245 const CompString & name () const;
246246
247 Type type ();247 Type type () const;
248 Value & value ();248 Value & value ();
249 const Value & value () const;
249 Restriction & rest ();250 Restriction & rest ();
250251
251 bool set (Value &val);252 bool set (Value &val);
252 bool isAction ();253 bool isAction () const;
253254
254 CompOption & operator= (const CompOption &option);255 CompOption & operator= (const CompOption &option);
255256
256257
=== modified file 'src/action.cpp'
--- src/action.cpp 2012-05-10 12:58:01 +0000
+++ src/action.cpp 2012-10-03 06:22:21 +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,19 @@
626 return priv->active;628 return priv->active;
627}629}
628630
631void
632PrivateAction::setActive (bool a)
633{
634 active = a;
635}
636
637void
638ca::setActionActiveState (const CompAction &action,
639 bool active)
640{
641 action.priv->setActive (active);
642}
643
629PrivateAction::PrivateAction () :644PrivateAction::PrivateAction () :
630 initiate (),645 initiate (),
631 terminate (),646 terminate (),
632647
=== modified file 'src/event.cpp'
--- src/event.cpp 2012-09-05 16:42:03 +0000
+++ src/event.cpp 2012-10-03 06:22:21 +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{
@@ -109,6 +111,9 @@
109 if (!(option.value ().action ().state () & state))111 if (!(option.value ().action ().state () & state))
110 return false;112 return false;
111113
114 if (!option.value ().action ().active ())
115 return false;
116
112 return true;117 return true;
113}118}
114119
@@ -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
=== added file 'src/eventmanagement.h'
--- src/eventmanagement.h 1970-01-01 00:00:00 +0000
+++ src/eventmanagement.h 2012-10-03 06:22:21 +0000
@@ -0,0 +1,80 @@
1/*
2 * Copyright © 2012 Canonical, Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Canonical, Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Canonical, Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * CANONICAL LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL Canonical, Ltd. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Author: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25#ifndef _COMPIZ_EVENT_MANAGEMENT_H
26#define _COMPIZ_EVENT_MANAGEMENT_H
27
28#include <boost/function.hpp>
29
30class CompScreenEdge;
31class CompOption;
32
33namespace compiz
34{
35namespace private_screen
36{
37struct GrabList;
38class EventManager;
39}
40
41namespace events
42{
43namespace cps = compiz::private_screen;
44typedef std::vector <CompOption> EventArguments;
45typedef boost::function <bool (unsigned int, unsigned int)> ActionModsMatchesEventStateFunc;
46
47int
48processButtonPressOnEdgeWindow (Window edgeWindow,
49 Window root,
50 Window eventWindow,
51 Window eventRoot,
52 cps::GrabList &grabList,
53 const CompScreenEdge *screenEdge);
54
55void
56setEventWindowInButtonPressArguments (EventArguments &arguments,
57 Window eventWindow);
58
59bool
60activateButtonPressOnWindowBindingOption (CompOption &option,
61 unsigned int eventButton,
62 unsigned int eventState,
63 cps::EventManager &eventManager,
64 const ActionModsMatchesEventStateFunc &matchEventState,
65 EventArguments &arguments);
66
67bool
68activateButtonPressOnEdgeBindingOption (CompOption &option,
69 unsigned int eventButton,
70 unsigned int eventState,
71 int edge,
72 cps::EventManager &eventManager,
73 const ActionModsMatchesEventStateFunc &matchEventState,
74 EventArguments &arguments);
75}
76}
77
78
79
80#endif
081
=== modified file 'src/option.cpp'
--- src/option.cpp 2012-06-24 09:00:27 +0000
+++ src/option.cpp 2012-10-03 06:22:21 +0000
@@ -450,14 +450,14 @@
450 priv->type = type;450 priv->type = type;
451}451}
452452
453CompString453const CompString &
454CompOption::name ()454CompOption::name () const
455{455{
456 return priv->name;456 return priv->name;
457}457}
458458
459CompOption::Type459CompOption::Type
460CompOption::type ()460CompOption::type () const
461{461{
462 return priv->type;462 return priv->type;
463}463}
@@ -468,6 +468,12 @@
468 return priv->value;468 return priv->value;
469}469}
470470
471const CompOption::Value &
472CompOption::value () const
473{
474 return priv->value;
475}
476
471CompOption::Restriction &477CompOption::Restriction &
472CompOption::rest ()478CompOption::rest ()
473{479{
@@ -477,6 +483,12 @@
477bool483bool
478CompOption::set (CompOption::Value &val)484CompOption::set (CompOption::Value &val)
479{485{
486 /* XXX: It is uncertain as to why this is done. The only
487 * logical reason would be that actions are stateful and
488 * we don't want to care about the old state from the
489 * action that we're setting this value to, so we're just
490 * clearing that state and starting over, however copyState
491 * does a lot more than that */
480 if (isAction () && priv->type != CompOption::TypeAction)492 if (isAction () && priv->type != CompOption::TypeAction)
481 val.action ().copyState (priv->value.action ());493 val.action ().copyState (priv->value.action ());
482494
@@ -550,7 +562,7 @@
550}562}
551563
552bool564bool
553CompOption::isAction ()565CompOption::isAction () const
554{566{
555 return checkIsAction (priv->type);567 return checkIsAction (priv->type);
556}568}
557569
=== 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-10-03 06:22:21 +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-10-03 06:22:21 +0000
@@ -28,11 +28,33 @@
28#ifndef _PRIVATEACTION_H28#ifndef _PRIVATEACTION_H
29#define _PRIVATEACTION_H29#define _PRIVATEACTION_H
3030
31class PrivateAction {31namespace compiz
32{
33namespace actions
34{
35class BoundAction
36{
37 public:
38
39 virtual ~BoundAction () {}
40
41 virtual void setActive (bool) = 0;
42};
43
44void setActionActiveState (const CompAction &action,
45 bool active);
46}
47}
48
49class PrivateAction :
50 public compiz::actions::BoundAction
51{
32 public:52 public:
33 PrivateAction ();53 PrivateAction ();
34 PrivateAction (const PrivateAction&);54 PrivateAction (const PrivateAction&);
3555
56 void setActive (bool);
57
36 CompAction::CallBack initiate;58 CompAction::CallBack initiate;
37 CompAction::CallBack terminate;59 CompAction::CallBack terminate;
3860
3961
=== 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-10-03 06:22:21 +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,8 @@
355} // (abstract) namespace358} // (abstract) namespace
356359
357namespace cps = compiz::private_screen;360namespace cps = compiz::private_screen;
361namespace ce = compiz::events;
362namespace ca = compiz::actions;
358363
359TEST(privatescreen_PluginManagerTest, create_and_destroy)364TEST(privatescreen_PluginManagerTest, create_and_destroy)
360{365{
@@ -909,3 +914,511 @@
909914
910 EXPECT_EQ (vp, CompPoint (0, 1));915 EXPECT_EQ (vp, CompPoint (0, 1));
911}916}
917
918namespace
919{
920const Window topLeftScreenEdge = 1;
921const Window topScreenEdge = 2;
922const Window topRightScreenEdge = 3;
923const Window rightScreenEdge = 4;
924const Window bottomRightScreenEdge = 5;
925const Window bottomScreenEdge = 6;
926const Window bottomLeftScreenEdge = 7;
927const Window leftScreenEdge = 8;
928
929const CompScreenEdge screenEdges[SCREEN_EDGE_NUM] =
930{
931 { leftScreenEdge, SCREEN_EDGE_LEFT },
932 { rightScreenEdge, SCREEN_EDGE_RIGHT },
933 { topScreenEdge, SCREEN_EDGE_TOP },
934 { bottomScreenEdge , SCREEN_EDGE_BOTTOM },
935 { topLeftScreenEdge, SCREEN_EDGE_TOPLEFT },
936 { topRightScreenEdge, SCREEN_EDGE_TOPRIGHT },
937 { bottomLeftScreenEdge, SCREEN_EDGE_BOTTOMLEFT },
938 { bottomRightScreenEdge, SCREEN_EDGE_BOTTOMRIGHT}
939};
940}
941
942TEST (privatescreen_ButtonPressEdgeEventManagementTest, IgnoreWhenEventAndRootWindowMismatch)
943{
944 const Window rootWindow = 1;
945 const Window edgeWindow = topScreenEdge;
946
947 cps::OrphanData orphanData;
948 cps::GrabList grabList;
949
950 EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
951 rootWindow,
952 0,
953 0,
954 grabList,
955 screenEdges), -1);
956}
957
958TEST (privatescreen_ButtonPressEdgeEventManagementTest, IgnoreWhenEventMismatchAndNoGrabs)
959{
960 const Window rootWindow = 1;
961 const Window edgeWindow = topScreenEdge;
962
963 cps::OrphanData orphanData;
964 cps::GrabList grabList;
965
966 EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
967 rootWindow,
968 0,
969 rootWindow,
970 grabList,
971 screenEdges), -1);
972}
973
974TEST (privatescreen_ButtonPressEdgeEventManagementTest, AllowWhenEventButNotRootWindowMismatchWhileGrabbed)
975{
976 const Window rootWindow = 1;
977 const Window edgeWindow = topScreenEdge;
978 unsigned int topEdgeMask = 1 << SCREEN_EDGE_TOP;
979
980 cps::OrphanData orphanData;
981 cps::GrabList grabList;
982
983 grabList.grabsPush (new cps::Grab (None, "Nil"));
984
985 EXPECT_EQ (ce::processButtonPressOnEdgeWindow (edgeWindow,
986 rootWindow,
987 0,
988 rootWindow,
989 grabList,
990 screenEdges), topEdgeMask);
991
992 grabList.grabsRemove (grabList.grabsBack ());
993}
994
995TEST (privatescreen_ButtonPressEventManagementTest, SetEventWindowArgument)
996{
997 const Window activeWindow = 1;
998
999 ce::EventArguments arguments (2);
1000 ce::setEventWindowInButtonPressArguments (arguments, activeWindow);
1001 EXPECT_EQ (arguments[1].value ().i (), activeWindow);
1002}
1003
1004namespace
1005{
1006class MockTriggerableAction
1007{
1008 public:
1009
1010 MOCK_METHOD2 (matchEventState, bool (unsigned int,
1011 unsigned int));
1012 MOCK_METHOD3 (initiate, bool (CompAction *,
1013 CompAction::State ,
1014 CompOption::Vector &));
1015 MOCK_METHOD3 (terminate, bool (CompAction *,
1016 CompAction::State ,
1017 CompOption::Vector &));
1018};
1019
1020const unsigned int testingButtonNumber = 1;
1021const unsigned int testingButtonState = (1 << 1);
1022
1023ce::ActionModsMatchesEventStateFunc
1024GetMatchEventStateFuncForMock (MockTriggerableAction &triggerableAction)
1025{
1026 return boost::bind (&MockTriggerableAction::matchEventState,
1027 &triggerableAction,
1028 _1, _2);
1029}
1030
1031CompAction::CallBack
1032GetInitiateForMock (MockTriggerableAction &triggerableAction)
1033{
1034 return boost::bind (&MockTriggerableAction::initiate,
1035 &triggerableAction,
1036 _1, _2, _3);
1037}
1038
1039CompAction::CallBack
1040GetTerminateForMock (MockTriggerableAction &triggerableAction)
1041{
1042 return boost::bind (&MockTriggerableAction::terminate,
1043 &triggerableAction,
1044 _1, _2, _3);
1045}
1046}
1047
1048bool operator== (const CompOption &lhs,
1049 const CompOption &rhs)
1050{
1051 if (lhs.type () != rhs.type ())
1052 return false;
1053
1054 return lhs.value () == rhs.value ();
1055}
1056
1057TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnUnboundAction)
1058{
1059 CompAction action;
1060 CompOption option ("button", CompOption::TypeButton);
1061 CompOption::Value value (action);
1062 cps::EventManager eventManager;
1063 MockTriggerableAction triggerableAction;
1064 ce::EventArguments arguments;
1065
1066 option.set (value);
1067
1068 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1069 GetMatchEventStateFuncForMock (triggerableAction);
1070
1071 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1072 testingButtonNumber,
1073 testingButtonState,
1074 eventManager,
1075 matchEventState,
1076 arguments));
1077}
1078
1079TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnUnboundInactiveAction)
1080{
1081 CompAction action;
1082 MockTriggerableAction triggerableAction;
1083 int edgeMask = 1 << SCREEN_EDGE_TOP;
1084
1085 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1086 GetMatchEventStateFuncForMock (triggerableAction);
1087 const CompAction::CallBack &initiate =
1088 GetInitiateForMock (triggerableAction);
1089
1090 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1091 testingButtonState));
1092 action.setEdgeMask (edgeMask);
1093
1094
1095 CompOption option ("button", CompOption::TypeButton);
1096 CompOption::Value value (action);
1097 cps::EventManager eventManager;
1098 ce::EventArguments arguments;
1099
1100 option.set (value);
1101 option.value ().action ().setInitiate (initiate);
1102 option.value ().action ().setState (CompAction::StateInitButton);
1103 ca::setActionActiveState (option.value ().action (), false);
1104
1105 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1106 testingButtonNumber,
1107 testingButtonState,
1108 edgeMask,
1109 eventManager,
1110 matchEventState,
1111 arguments));
1112}
1113
1114TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnMismatchedButtonNumber)
1115{
1116 CompAction action;
1117 MockTriggerableAction triggerableAction;
1118
1119 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1120 GetMatchEventStateFuncForMock (triggerableAction);
1121 const CompAction::CallBack &initiate =
1122 GetInitiateForMock (triggerableAction);
1123
1124 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1125 testingButtonState));
1126
1127 CompOption option ("button", CompOption::TypeButton);
1128 CompOption::Value value (action);
1129 cps::EventManager eventManager;
1130 ce::EventArguments arguments;
1131
1132 option.set (value);
1133 option.value ().action ().setInitiate (initiate);
1134 option.value ().action ().setState (CompAction::StateInitButton);
1135 ca::setActionActiveState (option.value ().action (), true);
1136
1137 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1138 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1139 0,
1140 testingButtonState,
1141 eventManager,
1142 matchEventState,
1143 arguments));
1144}
1145
1146TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnMismatchedButtonState)
1147{
1148 CompAction action;
1149 MockTriggerableAction triggerableAction;
1150
1151 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1152 GetMatchEventStateFuncForMock (triggerableAction);
1153 const CompAction::CallBack &initiate =
1154 GetInitiateForMock (triggerableAction);
1155
1156 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1157 testingButtonState));
1158
1159 CompOption option ("button", CompOption::TypeButton);
1160 CompOption::Value value (action);
1161 cps::EventManager eventManager;
1162 ce::EventArguments arguments;
1163
1164 option.set (value);
1165 option.value ().action ().setInitiate (initiate);
1166 option.value ().action ().setState (CompAction::StateInitButton);
1167 ca::setActionActiveState (option.value ().action (), true);
1168
1169 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, 0))
1170 .WillOnce (Return (false));
1171 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1172 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1173 testingButtonNumber,
1174 0,
1175 eventManager,
1176 matchEventState,
1177 arguments));
1178}
1179
1180TEST (privatescreen_ButtonPressEventManagementTest, TriggerWhenStateAndButtonMatch)
1181{
1182 CompAction action;
1183 MockTriggerableAction triggerableAction;
1184
1185 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1186 GetMatchEventStateFuncForMock (triggerableAction);
1187 const CompAction::CallBack &initiate =
1188 GetInitiateForMock (triggerableAction);
1189
1190 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1191 testingButtonState));
1192
1193 CompOption option ("button", CompOption::TypeButton);
1194 CompOption::Value value (action);
1195 cps::EventManager eventManager;
1196 ce::EventArguments arguments;
1197
1198 option.set (value);
1199 option.value ().action ().setInitiate (initiate);
1200 option.value ().action ().setState (CompAction::StateInitButton);
1201 ca::setActionActiveState (option.value ().action (), true);
1202
1203 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, testingButtonState))
1204 .WillOnce (Return (true));
1205 EXPECT_CALL (triggerableAction, initiate (&option.value ().action (),
1206 CompAction::StateInitButton,
1207 arguments)).WillOnce (Return (true));
1208 EXPECT_TRUE (ce::activateButtonPressOnWindowBindingOption (option,
1209 testingButtonNumber,
1210 testingButtonState,
1211 eventManager,
1212 matchEventState,
1213 arguments));
1214}
1215
1216TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnInvalidEdge)
1217{
1218 CompAction action;
1219 CompOption option ("button", CompOption::TypeButton);
1220 CompOption::Value value (action);
1221 cps::EventManager eventManager;
1222 MockTriggerableAction triggerableAction;
1223 ce::EventArguments arguments;
1224 int edgeMask = -1;
1225
1226 option.set (value);
1227
1228 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1229 GetMatchEventStateFuncForMock (triggerableAction);
1230
1231 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1232 testingButtonNumber,
1233 testingButtonState,
1234 edgeMask,
1235 eventManager,
1236 matchEventState,
1237 arguments));
1238}
1239
1240TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnUnboundAction)
1241{
1242 CompAction action;
1243 CompOption option ("button", CompOption::TypeButton);
1244 CompOption::Value value (action);
1245 cps::EventManager eventManager;
1246 MockTriggerableAction triggerableAction;
1247 ce::EventArguments arguments;
1248 int edgeMask = 1 << SCREEN_EDGE_TOP;
1249
1250 option.set (value);
1251
1252 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1253 GetMatchEventStateFuncForMock (triggerableAction);
1254
1255 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1256 testingButtonNumber,
1257 testingButtonState,
1258 edgeMask,
1259 eventManager,
1260 matchEventState,
1261 arguments));
1262}
1263
1264TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedEdgeMask)
1265{
1266 CompAction action;
1267 MockTriggerableAction triggerableAction;
1268 int edgeMask = 1 << SCREEN_EDGE_TOP;
1269
1270 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1271 GetMatchEventStateFuncForMock (triggerableAction);
1272 const CompAction::CallBack &initiate =
1273 GetInitiateForMock (triggerableAction);
1274
1275 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1276 testingButtonState));
1277 action.setEdgeMask (edgeMask);
1278
1279 CompOption option ("button", CompOption::TypeButton);
1280 CompOption::Value value (action);
1281 cps::EventManager eventManager;
1282 ce::EventArguments arguments;
1283
1284
1285 option.set (value);
1286 option.value ().action ().setInitiate (initiate);
1287 option.value ().action ().setState (CompAction::StateInitButton);
1288 ca::setActionActiveState (option.value ().action (), true);
1289
1290 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1291 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1292 testingButtonNumber,
1293 testingButtonState,
1294 0,
1295 eventManager,
1296 matchEventState,
1297 arguments));
1298}
1299
1300TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedButtonNumber)
1301{
1302 CompAction action;
1303 MockTriggerableAction triggerableAction;
1304 int edgeMask = 1 << SCREEN_EDGE_TOP;
1305
1306 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1307 GetMatchEventStateFuncForMock (triggerableAction);
1308 const CompAction::CallBack &initiate =
1309 GetInitiateForMock (triggerableAction);
1310
1311 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1312 testingButtonState));
1313 action.setEdgeMask (edgeMask);
1314
1315 CompOption option ("button", CompOption::TypeButton);
1316 CompOption::Value value (action);
1317 cps::EventManager eventManager;
1318 ce::EventArguments arguments;
1319
1320
1321 option.set (value);
1322 option.value ().action ().setInitiate (initiate);
1323 option.value ().action ().setState (CompAction::StateInitButton);
1324 ca::setActionActiveState (option.value ().action (), true);
1325
1326 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1327 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1328 0,
1329 testingButtonState,
1330 edgeMask,
1331 eventManager,
1332 matchEventState,
1333 arguments));
1334}
1335
1336TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedButtonState)
1337{
1338 CompAction action;
1339 MockTriggerableAction triggerableAction;
1340 int edgeMask = 1 << SCREEN_EDGE_TOP;
1341
1342 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1343 GetMatchEventStateFuncForMock (triggerableAction);
1344 const CompAction::CallBack &initiate =
1345 GetInitiateForMock (triggerableAction);
1346
1347 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1348 testingButtonState));
1349 action.setEdgeMask (edgeMask);
1350
1351
1352 CompOption option ("button", CompOption::TypeButton);
1353 CompOption::Value value (action);
1354 cps::EventManager eventManager;
1355 ce::EventArguments arguments;
1356
1357 option.set (value);
1358 option.value ().action ().setInitiate (initiate);
1359 option.value ().action ().setState (CompAction::StateInitButton);
1360 ca::setActionActiveState (option.value ().action (), true);
1361
1362 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, 0))
1363 .WillOnce (Return (false));
1364 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1365 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1366 testingButtonNumber,
1367 0,
1368 edgeMask,
1369 eventManager,
1370 matchEventState,
1371 arguments));
1372}
1373
1374TEST (privatescreen_ButtonPressEdgeEventManagementTest, TriggerWhenStateButtonAndEdgeMaskMatch)
1375{
1376 CompAction action;
1377 MockTriggerableAction triggerableAction;
1378 int edgeMask = 1 << SCREEN_EDGE_TOP;
1379
1380 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1381 GetMatchEventStateFuncForMock (triggerableAction);
1382 const CompAction::CallBack &initiate =
1383 GetInitiateForMock (triggerableAction);
1384
1385 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1386 testingButtonState));
1387 action.setEdgeMask (edgeMask);
1388
1389 CompOption option ("button", CompOption::TypeButton);
1390 CompOption::Value value (action);
1391 cps::EventManager eventManager;
1392 ce::EventArguments arguments;
1393
1394 option.set (value);
1395 option.value ().action ().setInitiate (initiate);
1396 option.value ().action ().setState (CompAction::StateInitButton |
1397 CompAction::StateInitEdge);
1398 ca::setActionActiveState (option.value ().action (), true);
1399
1400 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, testingButtonState))
1401 .WillOnce (Return (true));
1402 EXPECT_CALL (triggerableAction, initiate (&option.value ().action (),
1403 CompAction::StateInitButton |
1404 CompAction::StateInitEdge,
1405 arguments)).WillOnce (Return (true));
1406 EXPECT_TRUE (ce::activateButtonPressOnEdgeBindingOption (option,
1407 testingButtonNumber,
1408 testingButtonState,
1409 edgeMask,
1410 eventManager,
1411 matchEventState,
1412 arguments));
1413}
1414
1415TEST (privatescreen_ActionActiveTest, TestMakeActionActive)
1416{
1417 CompAction action;
1418
1419 ASSERT_EQ (action.active (), false);
1420 ca::setActionActiveState (action, true);
1421 ASSERT_EQ (action.active (), true);
1422 ca::setActionActiveState (action, false);
1423 ASSERT_EQ (action.active (), false);
1424}
9121425
=== modified file 'src/screen.cpp'
--- src/screen.cpp 2012-09-18 01:44:23 +0000
+++ src/screen.cpp 2012-10-03 06:22:21 +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