Merge lp:~3v1n0/compiz/push-grab-types into lp:compiz/0.9.12

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 3935
Merged at revision: 3983
Proposed branch: lp:~3v1n0/compiz/push-grab-types
Merge into: lp:compiz/0.9.12
Diff against target: 467 lines (+189/-73)
5 files modified
include/core/abiversion.h (+1/-1)
include/core/screen.h (+2/-0)
src/privatescreen.h (+31/-15)
src/privatescreen/tests/test-privatescreen.cpp (+2/-0)
src/screen.cpp (+153/-57)
To merge this branch: bzr merge lp:~3v1n0/compiz/push-grab-types
Reviewer Review Type Date Requested Status
MC Return Approve
Andrea Azzarone Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+271585@code.launchpad.net

Commit message

Screen: add pushKeyboardGrab and pushPointerGrab methods to add different kinds of grabs

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/compiz/push-grab-types updated
3932. By Marco Trevisan (Treviño)

debian/patches/ubuntu_super_p.patch: refresh to fix merging

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/compiz/push-grab-types updated
3933. By Marco Trevisan (Treviño)

Screen: use GrabType when calling removing or updating a Grab

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/compiz/push-grab-types updated
3934. By Marco Trevisan (Treviño)

Screen: add missing space

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~3v1n0/compiz/push-grab-types updated
3935. By Marco Trevisan (Treviño)

Screen: properly ungrab / change grab owners depending on the grab types

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~3v1n0/compiz/push-grab-types updated
3936. By Marco Trevisan (Treviño)

PrivateScreen: fix typo in GrabType definition

Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM

review: Approve
lp:~3v1n0/compiz/push-grab-types updated
3937. By Marco Trevisan (Treviño)

Merging with trunk

Revision history for this message
MC Return (mc-return) wrote :

I'm late to the party, but wanted to express a:
Great job on that one, Marco. +1

Very useful separation indeed. Top Job.

review: Approve

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 2015-02-17 14:57:27 +0000
+++ include/core/abiversion.h 2015-10-26 17:12:40 +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 201502178#define CORE_ABIVERSION 20150918
99
10#endif // COMPIZ_ABIVERSION_H10#endif // COMPIZ_ABIVERSION_H
1111
=== modified file 'include/core/screen.h'
--- include/core/screen.h 2012-12-03 10:36:42 +0000
+++ include/core/screen.h 2015-10-26 17:12:40 +0000
@@ -364,6 +364,8 @@
364 virtual CompIcon *defaultIcon () const = 0;364 virtual CompIcon *defaultIcon () const = 0;
365 virtual bool otherGrabExist (const char *, ...) = 0;365 virtual bool otherGrabExist (const char *, ...) = 0;
366 virtual GrabHandle pushGrab (Cursor cursor, const char *name) = 0;366 virtual GrabHandle pushGrab (Cursor cursor, const char *name) = 0;
367 virtual GrabHandle pushPointerGrab (Cursor cursor, const char *name) = 0;
368 virtual GrabHandle pushKeyboardGrab (const char *name) = 0;
367 virtual void removeGrab (GrabHandle handle, CompPoint *restorePointer) = 0;369 virtual void removeGrab (GrabHandle handle, CompPoint *restorePointer) = 0;
368 virtual bool writeImageToFile (CompString &path,370 virtual bool writeImageToFile (CompString &path,
369 const char *format,371 const char *format,
370372
=== modified file 'src/privatescreen.h'
--- src/privatescreen.h 2014-12-02 19:37:10 +0000
+++ src/privatescreen.h 2015-10-26 17:12:40 +0000
@@ -239,6 +239,20 @@
239 CompStringSet blacklist;239 CompStringSet blacklist;
240};240};
241241
242enum GrabType {
243 POINTER = 1 << 0,
244 KEYBOARD = 1 << 1,
245 ALL = POINTER|KEYBOARD
246};
247
248struct Grab {
249 Grab (GrabType type, Cursor cursor, const char *name) : type(type), cursor(cursor), name(name) {}
250 Grab (Cursor cursor, const char *name) : Grab(GrabType::ALL, cursor, name) {}
251 GrabType type;
252 Cursor cursor;
253 const char *name;
254};
255
242class GrabList256class GrabList
243{257{
244 // TODO: std::list<Grab *> is almost certainly the wrong data258 // TODO: std::list<Grab *> is almost certainly the wrong data
@@ -249,13 +263,14 @@
249public:263public:
250 typedef GrabPtrList::iterator GrabIterator;264 typedef GrabPtrList::iterator GrabIterator;
251265
252 bool grabsEmpty() const { return grabs.empty(); }266 bool grabsEmpty () const { return grabs.empty (); }
253 void grabsPush(Grab* grab) { grabs.push_back (grab); }267 void grabsPush (Grab* grab) { grabs.push_back (grab); }
254 GrabIterator grabsBegin() { return grabs.begin(); }268 GrabIterator grabsBegin () { return begin (grabs); }
255 GrabIterator grabsEnd() { return grabs.end(); }269 GrabIterator grabsEnd () { return end (grabs); }
256 void grabsRemove(Grab* grab);270 void grabsRemove (Grab* grab);
257 bool grabExist (const char *grab);271 bool grabExist (const char *grab);
258 Grab* grabsBack() { return grabs.back (); }272 Grab* topGrab (GrabType t) { auto it = std::find_if (begin (grabs), end (grabs), [t] (Grab *g) { return (g->type & t); }); return (it != end (grabs)) ? *it : NULL; }
273 Grab* grabsBack () { return grabs.back (); }
259274
260private:275private:
261 GrabPtrList grabs;276 GrabPtrList grabs;
@@ -349,12 +364,6 @@
349 int count;364 int count;
350};365};
351366
352struct Grab {
353 Grab(Cursor cursor, const char *name) : cursor(cursor), name(name) {}
354 Cursor cursor;
355 const char *name;
356};
357
358// data members that don't belong (these probably belong367// data members that don't belong (these probably belong
359// in CompScreenImpl as PrivateScreen doesn't use them)368// in CompScreenImpl as PrivateScreen doesn't use them)
360struct OrphanData : boost::noncopyable369struct OrphanData : boost::noncopyable
@@ -571,9 +580,6 @@
571 Display* const& dpy;580 Display* const& dpy;
572};581};
573582
574
575
576
577unsigned int windowStateMask (Atom state);583unsigned int windowStateMask (Atom state);
578584
579}} // namespace compiz::private_screen585}} // namespace compiz::private_screen
@@ -703,6 +709,10 @@
703 static void compScreenSnEvent (SnMonitorEvent *event,709 static void compScreenSnEvent (SnMonitorEvent *event,
704 void *userData);710 void *userData);
705711
712 CompScreen::GrabHandle pushGrabGeneric (::compiz::private_screen::GrabType type,
713 Cursor cursor,
714 const char *name);
715
706 int getXkbEvent() const { return xkbEvent.get(); }716 int getXkbEvent() const { return xkbEvent.get(); }
707 std::vector<XineramaScreenInfo>& getScreenInfo () { return screenInfo; }717 std::vector<XineramaScreenInfo>& getScreenInfo () { return screenInfo; }
708 SnDisplay* getSnDisplay () const { return snDisplay; }718 SnDisplay* getSnDisplay () const { return snDisplay; }
@@ -963,6 +973,12 @@
963 * be grabbed once and the actual grab refcounted */973 * be grabbed once and the actual grab refcounted */
964 GrabHandle pushGrab (Cursor cursor, const char *name);974 GrabHandle pushGrab (Cursor cursor, const char *name);
965975
976 /* Adds an X Pointer grab to the stack. */
977 GrabHandle pushPointerGrab (Cursor cursor, const char *name);
978
979 /* Adds an X Keyboard grab to the stack. */
980 GrabHandle pushKeyboardGrab (const char *name);
981
966 /* Allows you to change the pointer of your grab */982 /* Allows you to change the pointer of your grab */
967 void updateGrab (GrabHandle handle, Cursor cursor);983 void updateGrab (GrabHandle handle, Cursor cursor);
968984
969985
=== modified file 'src/privatescreen/tests/test-privatescreen.cpp'
--- src/privatescreen/tests/test-privatescreen.cpp 2015-09-23 23:17:54 +0000
+++ src/privatescreen/tests/test-privatescreen.cpp 2015-10-26 17:12:40 +0000
@@ -148,6 +148,8 @@
148 MOCK_CONST_METHOD0(defaultIcon, CompIcon *());148 MOCK_CONST_METHOD0(defaultIcon, CompIcon *());
149 virtual bool otherGrabExist (const char *, ...) { return false; } // TODO How to mock?149 virtual bool otherGrabExist (const char *, ...) { return false; } // TODO How to mock?
150 MOCK_METHOD2(pushGrab, GrabHandle (Cursor cursor, const char *name));150 MOCK_METHOD2(pushGrab, GrabHandle (Cursor cursor, const char *name));
151 MOCK_METHOD2(pushPointerGrab, GrabHandle (Cursor cursor, const char *name));
152 MOCK_METHOD1(pushKeyboardGrab, GrabHandle (const char *name));
151 MOCK_METHOD2(removeGrab, void (GrabHandle handle, CompPoint *restorePointer));153 MOCK_METHOD2(removeGrab, void (GrabHandle handle, CompPoint *restorePointer));
152 MOCK_METHOD4(writeImageToFile, bool (CompString &path,154 MOCK_METHOD4(writeImageToFile, bool (CompString &path,
153 const char *format,155 const char *format,
154156
=== modified file 'src/screen.cpp'
--- src/screen.cpp 2014-12-02 19:37:10 +0000
+++ src/screen.cpp 2015-10-26 17:12:40 +0000
@@ -104,7 +104,7 @@
104void CompScreenImpl::sizePluginClasses(unsigned int size)104void CompScreenImpl::sizePluginClasses(unsigned int size)
105{105{
106 if(size != pluginClasses.size ())106 if(size != pluginClasses.size ())
107 pluginClasses.resize (size);107 pluginClasses.resize (size);
108}108}
109109
110void CompScreenImpl::setWindowState (unsigned int state, Window id)110void CompScreenImpl::setWindowState (unsigned int state, Window id)
@@ -712,7 +712,7 @@
712 return false;712 return false;
713713
714 if (!CompOption::findOption (getOptions (), name, &index))714 if (!CompOption::findOption (getOptions (), name, &index))
715 return false;715 return false;
716716
717 switch (index) {717 switch (index) {
718 case CoreOptions::ActivePlugins:718 case CoreOptions::ActivePlugins:
@@ -870,7 +870,7 @@
870 break;870 break;
871 default:871 default:
872 break;872 break;
873 }873 }
874874
875 sn_display_process_event (snDisplay, &event);875 sn_display_process_event (snDisplay, &event);
876876
@@ -1584,8 +1584,8 @@
15841584
1585 i = compiz::window::fillStateData (state, data);1585 i = compiz::window::fillStateData (state, data);
1586 XChangeProperty (dpy, id, Atoms::winState,1586 XChangeProperty (dpy, id, Atoms::winState,
1587 XA_ATOM, 32, PropModeReplace,1587 XA_ATOM, 32, PropModeReplace,
1588 (unsigned char *) data, i);1588 (unsigned char *) data, i);
1589}1589}
15901590
1591unsigned int1591unsigned int
@@ -2760,10 +2760,10 @@
2760 }2760 }
2761 else2761 else
2762 {2762 {
2763 CompWindow::Map::const_iterator it = windowsMap.find (id);2763 CompWindow::Map::const_iterator it = windowsMap.find (id);
27642764
2765 if (it != windowsMap.end ())2765 if (it != windowsMap.end ())
2766 return (lastFoundWindow = it->second);2766 return (lastFoundWindow = it->second);
2767 }2767 }
27682768
2769 return 0;2769 return 0;
@@ -2933,7 +2933,7 @@
2933cps::WindowManager::eraseWindowFromMap (Window id)2933cps::WindowManager::eraseWindowFromMap (Window id)
2934{2934{
2935 if (id != 1)2935 if (id != 1)
2936 windowsMap.erase (id);2936 windowsMap.erase (id);
2937}2937}
29382938
2939void2939void
@@ -3024,73 +3024,166 @@
3024#define POINTER_GRAB_MASK (ButtonReleaseMask | \3024#define POINTER_GRAB_MASK (ButtonReleaseMask | \
3025 ButtonPressMask | \3025 ButtonPressMask | \
3026 PointerMotionMask)3026 PointerMotionMask)
3027CompScreenImpl::GrabHandle3027
3028CompScreenImpl::pushGrab (Cursor cursor, const char *name)3028CompScreen::GrabHandle
3029PrivateScreen::pushGrabGeneric (cps::GrabType type,
3030 Cursor cursor,
3031 const char *name)
3029{3032{
3030 if (privateScreen.eventManager.grabsEmpty ())3033 int status = GrabSuccess;
3034
3035 if (eventManager.grabsEmpty ())
3031 {3036 {
3032 int status;3037 if (type & cps::GrabType::POINTER)
30333038 {
3034 status = XGrabPointer (privateScreen.dpy, privateScreen.eventManager.getGrabWindow(), true,3039 status = XGrabPointer (dpy, eventManager.getGrabWindow (), true,
3035 POINTER_GRAB_MASK,3040 POINTER_GRAB_MASK,
3036 GrabModeAsync, GrabModeAsync,3041 GrabModeAsync, GrabModeAsync,
3037 privateScreen.rootWindow(), cursor,3042 root, cursor,
3038 CurrentTime);3043 CurrentTime);
3044 }
30393045
3040 if (status == GrabSuccess)3046 if (status == GrabSuccess)
3041 {3047 {
3042 status = XGrabKeyboard (privateScreen.dpy,3048 if (type & cps::GrabType::KEYBOARD)
3043 privateScreen.eventManager.getGrabWindow(), true,3049 {
3050 status = XGrabKeyboard (dpy,
3051 eventManager.getGrabWindow (), true,
3052 GrabModeAsync, GrabModeAsync,
3053 CurrentTime);
3054 if (status != GrabSuccess)
3055 {
3056 if (type & cps::GrabType::POINTER)
3057 XUngrabPointer (dpy, CurrentTime);
3058
3059 return NULL;
3060 }
3061 }
3062 }
3063 else
3064 return NULL;
3065 }
3066 else
3067 {
3068 if (type & cps::GrabType::POINTER)
3069 {
3070 if (eventManager.topGrab (cps::GrabType::POINTER))
3071 {
3072 XChangeActivePointerGrab (dpy, POINTER_GRAB_MASK,
3073 cursor, CurrentTime);
3074 }
3075 else
3076 {
3077 status = XGrabPointer (dpy, eventManager.getGrabWindow (), true,
3078 POINTER_GRAB_MASK,
3079 GrabModeAsync, GrabModeAsync,
3080 root, cursor,
3081 CurrentTime);
3082
3083 if (status != GrabSuccess)
3084 return NULL;
3085 }
3086 }
3087
3088 if ((type & cps::GrabType::KEYBOARD) &&
3089 !eventManager.topGrab (cps::GrabType::KEYBOARD))
3090 {
3091 status = XGrabKeyboard (dpy,
3092 eventManager.getGrabWindow (), true,
3044 GrabModeAsync, GrabModeAsync,3093 GrabModeAsync, GrabModeAsync,
3045 CurrentTime);3094 CurrentTime);
3095
3046 if (status != GrabSuccess)3096 if (status != GrabSuccess)
3047 {3097 {
3048 XUngrabPointer (privateScreen.dpy, CurrentTime);3098 if (type & cps::GrabType::POINTER)
3099 {
3100 if (cps::Grab *lastPtrGrab = eventManager.topGrab (cps::GrabType::POINTER))
3101 {
3102 XChangeActivePointerGrab (dpy, POINTER_GRAB_MASK,
3103 lastPtrGrab->cursor, CurrentTime);
3104 }
3105 else
3106 {
3107 XUngrabPointer (dpy, CurrentTime);
3108 }
3109 }
3110
3049 return NULL;3111 return NULL;
3050 }3112 }
3051 }3113 }
3052 else
3053 return NULL;
3054 }3114 }
3055 else3115
3116 cps::Grab *grab = new cps::Grab (type, cursor, name);
3117 eventManager.grabsPush (grab);
3118
3119 return grab;
3120}
3121
3122CompScreenImpl::GrabHandle
3123CompScreenImpl::pushGrab (Cursor cursor, const char *name)
3124{
3125 return privateScreen.pushGrabGeneric(cps::GrabType::ALL, cursor, name);
3126}
3127
3128CompScreenImpl::GrabHandle
3129CompScreenImpl::pushPointerGrab (Cursor cursor, const char *name)
3130{
3131 return privateScreen.pushGrabGeneric(cps::GrabType::POINTER, cursor, name);
3132}
3133
3134CompScreenImpl::GrabHandle
3135CompScreenImpl::pushKeyboardGrab (const char *name)
3136{
3137 return privateScreen.pushGrabGeneric(cps::GrabType::KEYBOARD, XC_X_cursor, name);
3138}
3139
3140void
3141CompScreenImpl::updateGrab (CompScreen::GrabHandle handle, Cursor cursor)
3142{
3143 if (!handle || !(handle->type & cps::GrabType::POINTER))
3144 return;
3145
3146 if (privateScreen.eventManager.topGrab (cps::GrabType::POINTER) == handle)
3056 {3147 {
3057 XChangeActivePointerGrab (privateScreen.dpy, POINTER_GRAB_MASK,3148 XChangeActivePointerGrab (privateScreen.dpy, POINTER_GRAB_MASK,
3058 cursor, CurrentTime);3149 cursor, CurrentTime);
3059 }3150 }
30603151
3061 cps::Grab *grab = new cps::Grab (cursor, name);
3062 privateScreen.eventManager.grabsPush (grab);
3063
3064 return grab;
3065}
3066
3067void
3068CompScreenImpl::updateGrab (CompScreen::GrabHandle handle, Cursor cursor)
3069{
3070 if (!handle)
3071 return;
3072
3073 XChangeActivePointerGrab (privateScreen.dpy, POINTER_GRAB_MASK,
3074 cursor, CurrentTime);
3075
3076 handle->cursor = cursor;3152 handle->cursor = cursor;
3077}3153}
30783154
3079void3155void
3080CompScreenImpl::removeGrab (CompScreen::GrabHandle handle,3156CompScreenImpl::removeGrab (CompScreen::GrabHandle handle,
3081 CompPoint *restorePointer)3157 CompPoint *restorePointer)
3082{3158{
3083 if (!handle)3159 if (!handle)
3084 return;3160 return;
30853161
3162 cps::GrabType removedType = handle->type;
3086 privateScreen.eventManager.grabsRemove(handle);3163 privateScreen.eventManager.grabsRemove(handle);
30873164
3088 if (!privateScreen.eventManager.grabsEmpty ())3165 if (!privateScreen.eventManager.grabsEmpty ())
3089 {3166 {
3090 XChangeActivePointerGrab (privateScreen.dpy,3167 if (removedType & cps::GrabType::POINTER)
3091 POINTER_GRAB_MASK,3168 {
3092 privateScreen.eventManager.grabsBack ()->cursor,3169 if (CompScreen::GrabHandle topPtrGrab = privateScreen.eventManager.topGrab (cps::GrabType::POINTER))
3093 CurrentTime);3170 {
3171 XChangeActivePointerGrab (privateScreen.dpy,
3172 POINTER_GRAB_MASK,
3173 topPtrGrab->cursor,
3174 CurrentTime);
3175 }
3176 else
3177 {
3178 XUngrabPointer (privateScreen.dpy, CurrentTime);
3179 }
3180 }
3181
3182 if (removedType & cps::GrabType::KEYBOARD)
3183 {
3184 if (!privateScreen.eventManager.topGrab (cps::GrabType::KEYBOARD))
3185 XUngrabKeyboard (privateScreen.dpy, CurrentTime);
3186 }
3094 }3187 }
3095 else3188 else
3096 {3189 {
@@ -3098,8 +3191,11 @@
3098 warpPointer (restorePointer->x () - pointerX,3191 warpPointer (restorePointer->x () - pointerX,
3099 restorePointer->y () - pointerY);3192 restorePointer->y () - pointerY);
31003193
3101 XUngrabPointer (privateScreen.dpy, CurrentTime);3194 if (removedType & cps::GrabType::POINTER)
3102 XUngrabKeyboard (privateScreen.dpy, CurrentTime);3195 XUngrabPointer (privateScreen.dpy, CurrentTime);
3196
3197 if (removedType & cps::GrabType::KEYBOARD)
3198 XUngrabKeyboard (privateScreen.dpy, CurrentTime);
3103 }3199 }
3104}3200}
31053201
@@ -3265,12 +3361,12 @@
3265 * keys, and know to cancel the tap if <modifier>+k is pressed.3361 * keys, and know to cancel the tap if <modifier>+k is pressed.
3266 */3362 */
3267 if (!(currentState & CompAction::StateIgnoreTap))3363 if (!(currentState & CompAction::StateIgnoreTap))
3268 {3364 {
3269 int minCode, maxCode;3365 int minCode, maxCode;
3270 XDisplayKeycodes (screen->dpy(), &minCode, &maxCode);3366 XDisplayKeycodes (screen->dpy(), &minCode, &maxCode);
3271 for (k = minCode; k <= maxCode; k++)3367 for (k = minCode; k <= maxCode; k++)
3272 grabUngrabOneKey (modifiers | modifierForKeycode | ignore, k, grab);3368 grabUngrabOneKey (modifiers | modifierForKeycode | ignore, k, grab);
3273 }3369 }
3274 }3370 }
32753371
3276 if (CompScreen::checkForError (screen->dpy()))3372 if (CompScreen::checkForError (screen->dpy()))
@@ -3517,7 +3613,7 @@
3517CompScreenImpl::removeAction (CompAction *action)3613CompScreenImpl::removeAction (CompAction *action)
3518{3614{
3519 if (!privateScreen.initialized ||3615 if (!privateScreen.initialized ||
3520 !action->active ())3616 !action->active ())
3521 return;3617 return;
35223618
3523 grabManager.setCurrentState(action->state());3619 grabManager.setCurrentState(action->state());
@@ -3746,7 +3842,7 @@
3746 pos = env.find (':');3842 pos = env.find (':');
3747 if (pos != std::string::npos)3843 if (pos != std::string::npos)
3748 {3844 {
3749 size_t pointPos = env.find ('.', pos);3845 size_t pointPos = env.find ('.', pos);
37503846
3751 if (pointPos != std::string::npos)3847 if (pointPos != std::string::npos)
3752 {3848 {
@@ -3754,7 +3850,7 @@
3754 }3850 }
3755 else3851 else
3756 {3852 {
3757 unsigned int displayNum = atoi (env.substr (pos + 1).c_str ());3853 unsigned int displayNum = atoi (env.substr (pos + 1).c_str ());
3758 env.erase (pos);3854 env.erase (pos);
3759 env.append (compPrintf (":%i", displayNum));3855 env.append (compPrintf (":%i", displayNum));
3760 }3856 }
@@ -5160,7 +5256,7 @@
5160 privateScreen.startupSequence.removeAllSequences ();5256 privateScreen.startupSequence.removeAllSequences ();
51615257
5162 while (!windowManager.getWindows().empty ())5258 while (!windowManager.getWindows().empty ())
5163 delete windowManager.getWindows().front ();5259 delete windowManager.getWindows().front ();
51645260
5165 while (CompPlugin* p = CompPlugin::pop ())5261 while (CompPlugin* p = CompPlugin::pop ())
5166 CompPlugin::unload (p);5262 CompPlugin::unload (p);

Subscribers

People subscribed via source and target branches