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

Proposed by Sam Spilsbury
Status: Merged
Approved by: Daniel van Vugt
Approved revision: 3399
Merged at revision: 3416
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1053280
Merge into: lp:compiz/0.9.9
Diff against target: 1133 lines (+843/-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 (+507/-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 Approve
Daniel van Vugt Approve
Sam Spilsbury Pending
Review via email: mp+129085@code.launchpad.net

This proposal supersedes 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.
(LP: #1053280)

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

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

> 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.

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
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

clang++ says:

In file included from /home/dan/bzr/compiz/tmp.280/src/event.cpp:44:
/home/dan/bzr/compiz/tmp.280/src/eventmanagement.h:30:1: error: class
      'CompScreenEdge' was previously declared as a struct
      [-Werror,-Wmismatched-tags]
class CompScreenEdge;
^
/home/dan/bzr/compiz/tmp.280/src/privatescreen.h:120:8: note: previous use is
      here
struct CompScreenEdge {
       ^
/home/dan/bzr/compiz/tmp.280/src/eventmanagement.h:30:1: note: did you mean
      struct here?
class CompScreenEdge;
^~~~~
struct
/home/dan/bzr/compiz/tmp.280/src/eventmanagement.h:37:1: error: struct
      'GrabList' was previously declared as a class [-Werror,-Wmismatched-tags]
struct GrabList;
^
/home/dan/bzr/compiz/tmp.280/src/privatescreen.h:281:7: note: previous use is
      here
class GrabList
      ^
/home/dan/bzr/compiz/tmp.280/src/eventmanagement.h:37:1: note: did you mean
      class here?
struct GrabList;
^~~~~~
class
2 errors generated.

review: Needs Fixing
3397. By Sam Spilsbury

Forward declare correctly

3398. By Sam Spilsbury

Merge lp:compiz

Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

clang now says:

/home/dan/bzr/compiz/tmp.280/src/privatescreen/tests/test-privatescreen.cpp:1040:1: error:
      unused function 'GetTerminateForMock' [-Werror,-Wunused-function]
GetTerminateForMock (MockTriggerableAction &triggerableAction)
^
1 error generated.

review: Needs Fixing
3399. By Daniel van Vugt

Fix build error/warning: Remove unused function.

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

The 5 nested if statements in ce::activateButtonPressOnEdgeBindingOption could be a single statement. If nicely formatted and aligned that would make it easier to read too.

But I can't find any real problems any more. Approved.

review: Approve
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)

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-15 05:24:18 +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-10-02 16:28:52 +0000
+++ include/core/action.h 2012-10-15 05:24:18 +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
@@ -172,7 +180,12 @@
172180
173 bool active ();181 bool active ();
174182
175 friend class CompScreenImpl;183 /* CompAction should be a pure virtual class so
184 * that we can pass the interface required to for setActionActiveState
185 * directly rather than using friends
186 */
187 friend void compiz::actions::setActionActiveState (const CompAction &action,
188 bool active);
176189
177 private:190 private:
178 PrivateAction *priv;191 PrivateAction *priv;
179192
=== modified file 'include/core/option.h'
--- include/core/option.h 2012-05-30 09:24:15 +0000
+++ include/core/option.h 2012-10-15 05:24:18 +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-15 05:24:18 +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-15 05:24:18 +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-15 05:24:18 +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
30struct CompScreenEdge;
31class CompOption;
32
33namespace compiz
34{
35namespace private_screen
36{
37class 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-15 05:24:18 +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-15 05:24:18 +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-15 05:24:18 +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-15 05:24:18 +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,504 @@
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
1039}
1040
1041bool operator== (const CompOption &lhs,
1042 const CompOption &rhs)
1043{
1044 if (lhs.type () != rhs.type ())
1045 return false;
1046
1047 return lhs.value () == rhs.value ();
1048}
1049
1050TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnUnboundAction)
1051{
1052 CompAction action;
1053 CompOption option ("button", CompOption::TypeButton);
1054 CompOption::Value value (action);
1055 cps::EventManager eventManager;
1056 MockTriggerableAction triggerableAction;
1057 ce::EventArguments arguments;
1058
1059 option.set (value);
1060
1061 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1062 GetMatchEventStateFuncForMock (triggerableAction);
1063
1064 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1065 testingButtonNumber,
1066 testingButtonState,
1067 eventManager,
1068 matchEventState,
1069 arguments));
1070}
1071
1072TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnUnboundInactiveAction)
1073{
1074 CompAction action;
1075 MockTriggerableAction triggerableAction;
1076 int edgeMask = 1 << SCREEN_EDGE_TOP;
1077
1078 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1079 GetMatchEventStateFuncForMock (triggerableAction);
1080 const CompAction::CallBack &initiate =
1081 GetInitiateForMock (triggerableAction);
1082
1083 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1084 testingButtonState));
1085 action.setEdgeMask (edgeMask);
1086
1087
1088 CompOption option ("button", CompOption::TypeButton);
1089 CompOption::Value value (action);
1090 cps::EventManager eventManager;
1091 ce::EventArguments arguments;
1092
1093 option.set (value);
1094 option.value ().action ().setInitiate (initiate);
1095 option.value ().action ().setState (CompAction::StateInitButton);
1096 ca::setActionActiveState (option.value ().action (), false);
1097
1098 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1099 testingButtonNumber,
1100 testingButtonState,
1101 edgeMask,
1102 eventManager,
1103 matchEventState,
1104 arguments));
1105}
1106
1107TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnMismatchedButtonNumber)
1108{
1109 CompAction action;
1110 MockTriggerableAction triggerableAction;
1111
1112 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1113 GetMatchEventStateFuncForMock (triggerableAction);
1114 const CompAction::CallBack &initiate =
1115 GetInitiateForMock (triggerableAction);
1116
1117 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1118 testingButtonState));
1119
1120 CompOption option ("button", CompOption::TypeButton);
1121 CompOption::Value value (action);
1122 cps::EventManager eventManager;
1123 ce::EventArguments arguments;
1124
1125 option.set (value);
1126 option.value ().action ().setInitiate (initiate);
1127 option.value ().action ().setState (CompAction::StateInitButton);
1128 ca::setActionActiveState (option.value ().action (), true);
1129
1130 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1131 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1132 0,
1133 testingButtonState,
1134 eventManager,
1135 matchEventState,
1136 arguments));
1137}
1138
1139TEST (privatescreen_ButtonPressEventManagementTest, NoTriggerOnMismatchedButtonState)
1140{
1141 CompAction action;
1142 MockTriggerableAction triggerableAction;
1143
1144 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1145 GetMatchEventStateFuncForMock (triggerableAction);
1146 const CompAction::CallBack &initiate =
1147 GetInitiateForMock (triggerableAction);
1148
1149 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1150 testingButtonState));
1151
1152 CompOption option ("button", CompOption::TypeButton);
1153 CompOption::Value value (action);
1154 cps::EventManager eventManager;
1155 ce::EventArguments arguments;
1156
1157 option.set (value);
1158 option.value ().action ().setInitiate (initiate);
1159 option.value ().action ().setState (CompAction::StateInitButton);
1160 ca::setActionActiveState (option.value ().action (), true);
1161
1162 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, 0))
1163 .WillOnce (Return (false));
1164 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1165 EXPECT_FALSE (ce::activateButtonPressOnWindowBindingOption (option,
1166 testingButtonNumber,
1167 0,
1168 eventManager,
1169 matchEventState,
1170 arguments));
1171}
1172
1173TEST (privatescreen_ButtonPressEventManagementTest, TriggerWhenStateAndButtonMatch)
1174{
1175 CompAction action;
1176 MockTriggerableAction triggerableAction;
1177
1178 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1179 GetMatchEventStateFuncForMock (triggerableAction);
1180 const CompAction::CallBack &initiate =
1181 GetInitiateForMock (triggerableAction);
1182
1183 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1184 testingButtonState));
1185
1186 CompOption option ("button", CompOption::TypeButton);
1187 CompOption::Value value (action);
1188 cps::EventManager eventManager;
1189 ce::EventArguments arguments;
1190
1191 option.set (value);
1192 option.value ().action ().setInitiate (initiate);
1193 option.value ().action ().setState (CompAction::StateInitButton);
1194 ca::setActionActiveState (option.value ().action (), true);
1195
1196 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, testingButtonState))
1197 .WillOnce (Return (true));
1198 EXPECT_CALL (triggerableAction, initiate (&option.value ().action (),
1199 CompAction::StateInitButton,
1200 arguments)).WillOnce (Return (true));
1201 EXPECT_TRUE (ce::activateButtonPressOnWindowBindingOption (option,
1202 testingButtonNumber,
1203 testingButtonState,
1204 eventManager,
1205 matchEventState,
1206 arguments));
1207}
1208
1209TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnInvalidEdge)
1210{
1211 CompAction action;
1212 CompOption option ("button", CompOption::TypeButton);
1213 CompOption::Value value (action);
1214 cps::EventManager eventManager;
1215 MockTriggerableAction triggerableAction;
1216 ce::EventArguments arguments;
1217 int edgeMask = -1;
1218
1219 option.set (value);
1220
1221 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1222 GetMatchEventStateFuncForMock (triggerableAction);
1223
1224 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1225 testingButtonNumber,
1226 testingButtonState,
1227 edgeMask,
1228 eventManager,
1229 matchEventState,
1230 arguments));
1231}
1232
1233TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnUnboundAction)
1234{
1235 CompAction action;
1236 CompOption option ("button", CompOption::TypeButton);
1237 CompOption::Value value (action);
1238 cps::EventManager eventManager;
1239 MockTriggerableAction triggerableAction;
1240 ce::EventArguments arguments;
1241 int edgeMask = 1 << SCREEN_EDGE_TOP;
1242
1243 option.set (value);
1244
1245 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1246 GetMatchEventStateFuncForMock (triggerableAction);
1247
1248 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1249 testingButtonNumber,
1250 testingButtonState,
1251 edgeMask,
1252 eventManager,
1253 matchEventState,
1254 arguments));
1255}
1256
1257TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedEdgeMask)
1258{
1259 CompAction action;
1260 MockTriggerableAction triggerableAction;
1261 int edgeMask = 1 << SCREEN_EDGE_TOP;
1262
1263 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1264 GetMatchEventStateFuncForMock (triggerableAction);
1265 const CompAction::CallBack &initiate =
1266 GetInitiateForMock (triggerableAction);
1267
1268 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1269 testingButtonState));
1270 action.setEdgeMask (edgeMask);
1271
1272 CompOption option ("button", CompOption::TypeButton);
1273 CompOption::Value value (action);
1274 cps::EventManager eventManager;
1275 ce::EventArguments arguments;
1276
1277
1278 option.set (value);
1279 option.value ().action ().setInitiate (initiate);
1280 option.value ().action ().setState (CompAction::StateInitButton);
1281 ca::setActionActiveState (option.value ().action (), true);
1282
1283 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1284 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1285 testingButtonNumber,
1286 testingButtonState,
1287 0,
1288 eventManager,
1289 matchEventState,
1290 arguments));
1291}
1292
1293TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedButtonNumber)
1294{
1295 CompAction action;
1296 MockTriggerableAction triggerableAction;
1297 int edgeMask = 1 << SCREEN_EDGE_TOP;
1298
1299 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1300 GetMatchEventStateFuncForMock (triggerableAction);
1301 const CompAction::CallBack &initiate =
1302 GetInitiateForMock (triggerableAction);
1303
1304 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1305 testingButtonState));
1306 action.setEdgeMask (edgeMask);
1307
1308 CompOption option ("button", CompOption::TypeButton);
1309 CompOption::Value value (action);
1310 cps::EventManager eventManager;
1311 ce::EventArguments arguments;
1312
1313
1314 option.set (value);
1315 option.value ().action ().setInitiate (initiate);
1316 option.value ().action ().setState (CompAction::StateInitButton);
1317 ca::setActionActiveState (option.value ().action (), true);
1318
1319 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1320 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1321 0,
1322 testingButtonState,
1323 edgeMask,
1324 eventManager,
1325 matchEventState,
1326 arguments));
1327}
1328
1329TEST (privatescreen_ButtonPressEdgeEventManagementTest, NoTriggerOnMismatchedButtonState)
1330{
1331 CompAction action;
1332 MockTriggerableAction triggerableAction;
1333 int edgeMask = 1 << SCREEN_EDGE_TOP;
1334
1335 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1336 GetMatchEventStateFuncForMock (triggerableAction);
1337 const CompAction::CallBack &initiate =
1338 GetInitiateForMock (triggerableAction);
1339
1340 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1341 testingButtonState));
1342 action.setEdgeMask (edgeMask);
1343
1344
1345 CompOption option ("button", CompOption::TypeButton);
1346 CompOption::Value value (action);
1347 cps::EventManager eventManager;
1348 ce::EventArguments arguments;
1349
1350 option.set (value);
1351 option.value ().action ().setInitiate (initiate);
1352 option.value ().action ().setState (CompAction::StateInitButton);
1353 ca::setActionActiveState (option.value ().action (), true);
1354
1355 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, 0))
1356 .WillOnce (Return (false));
1357 EXPECT_CALL (triggerableAction, initiate (_, _, _)).Times (0);
1358 EXPECT_FALSE (ce::activateButtonPressOnEdgeBindingOption (option,
1359 testingButtonNumber,
1360 0,
1361 edgeMask,
1362 eventManager,
1363 matchEventState,
1364 arguments));
1365}
1366
1367TEST (privatescreen_ButtonPressEdgeEventManagementTest, TriggerWhenStateButtonAndEdgeMaskMatch)
1368{
1369 CompAction action;
1370 MockTriggerableAction triggerableAction;
1371 int edgeMask = 1 << SCREEN_EDGE_TOP;
1372
1373 const ce::ActionModsMatchesEventStateFunc &matchEventState =
1374 GetMatchEventStateFuncForMock (triggerableAction);
1375 const CompAction::CallBack &initiate =
1376 GetInitiateForMock (triggerableAction);
1377
1378 action.setButton (CompAction::ButtonBinding (testingButtonNumber,
1379 testingButtonState));
1380 action.setEdgeMask (edgeMask);
1381
1382 CompOption option ("button", CompOption::TypeButton);
1383 CompOption::Value value (action);
1384 cps::EventManager eventManager;
1385 ce::EventArguments arguments;
1386
1387 option.set (value);
1388 option.value ().action ().setInitiate (initiate);
1389 option.value ().action ().setState (CompAction::StateInitButton |
1390 CompAction::StateInitEdge);
1391 ca::setActionActiveState (option.value ().action (), true);
1392
1393 EXPECT_CALL (triggerableAction, matchEventState (testingButtonState, testingButtonState))
1394 .WillOnce (Return (true));
1395 EXPECT_CALL (triggerableAction, initiate (&option.value ().action (),
1396 CompAction::StateInitButton |
1397 CompAction::StateInitEdge,
1398 arguments)).WillOnce (Return (true));
1399 EXPECT_TRUE (ce::activateButtonPressOnEdgeBindingOption (option,
1400 testingButtonNumber,
1401 testingButtonState,
1402 edgeMask,
1403 eventManager,
1404 matchEventState,
1405 arguments));
1406}
1407
1408TEST (privatescreen_ActionActiveTest, TestMakeActionActive)
1409{
1410 CompAction action;
1411
1412 ASSERT_EQ (action.active (), false);
1413 ca::setActionActiveState (action, true);
1414 ASSERT_EQ (action.active (), true);
1415 ca::setActionActiveState (action, false);
1416 ASSERT_EQ (action.active (), false);
1417}
9121418
=== modified file 'src/screen.cpp'
--- src/screen.cpp 2012-10-02 16:28:52 +0000
+++ src/screen.cpp 2012-10-15 05:24:18 +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
@@ -3576,7 +3577,7 @@
3576 privateScreen.enableEdge (i);3577 privateScreen.enableEdge (i);
3577 }3578 }
35783579
3579 action->priv->active = true;3580 ca::setActionActiveState (*action, true);
35803581
3581 return true;3582 return true;
3582}3583}
@@ -3607,7 +3608,7 @@
3607 privateScreen.disableEdge (i);3608 privateScreen.disableEdge (i);
3608 }3609 }
36093610
3610 action->priv->active = false;3611 ca::setActionActiveState (*action, false);
3611}3612}
36123613
3613CompRect3614CompRect

Subscribers

People subscribed via source and target branches