Merge lp:~alan-griffiths/compiz-core/private_screen-GrabList into lp:compiz-core

Proposed by Alan Griffiths
Status: Merged
Merged at revision: 3049
Proposed branch: lp:~alan-griffiths/compiz-core/private_screen-GrabList
Merge into: lp:compiz-core
Diff against target: 254 lines (+66/-34)
4 files modified
include/core/screen.h (+5/-1)
src/event.cpp (+6/-6)
src/privatescreen.h (+25/-6)
src/screen.cpp (+30/-21)
To merge this branch: bzr merge lp:~alan-griffiths/compiz-core/private_screen-GrabList
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Review via email: mp+96628@code.launchpad.net

Description of the change

Encapsulate grabs - the list of Grab*

To post a comment you must log in.
Revision history for this message
Daniel van Vugt (vanvugt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/core/screen.h'
--- include/core/screen.h 2012-03-05 09:04:16 +0000
+++ include/core/screen.h 2012-03-08 17:50:24 +0000
@@ -141,6 +141,10 @@
141141
142};142};
143143
144namespace compiz { namespace private_screen {
145 class Grab;
146}}
147
144class CompScreen :148class CompScreen :
145 public WrapableHandler<ScreenInterface, 18>,149 public WrapableHandler<ScreenInterface, 18>,
146 public PluginClassStorage, // TODO should be an interface here150 public PluginClassStorage, // TODO should be an interface here
@@ -148,7 +152,7 @@
148 public CompOption::Class // TODO should be an interface here152 public CompOption::Class // TODO should be an interface here
149{153{
150public:154public:
151 typedef void* GrabHandle;155 typedef compiz::private_screen::Grab* GrabHandle;
152156
153 WRAPABLE_HND (0, ScreenInterface, void, fileWatchAdded, CompFileWatch *)157 WRAPABLE_HND (0, ScreenInterface, void, fileWatchAdded, CompFileWatch *)
154 WRAPABLE_HND (1, ScreenInterface, void, fileWatchRemoved, CompFileWatch *)158 WRAPABLE_HND (1, ScreenInterface, void, fileWatchRemoved, CompFileWatch *)
155159
=== modified file 'src/event.cpp'
--- src/event.cpp 2012-03-08 08:06:02 +0000
+++ src/event.cpp 2012-03-08 17:50:24 +0000
@@ -141,7 +141,7 @@
141{141{
142 bool actionEventHandled = false;142 bool actionEventHandled = false;
143143
144 if (state == CompAction::StateInitKey && grabs.empty ())144 if (state == CompAction::StateInitKey && grabsEmpty ())
145 {145 {
146 if (grabbed)146 if (grabbed)
147 {147 {
@@ -219,7 +219,7 @@
219219
220 if (event->window != edgeWindow)220 if (event->window != edgeWindow)
221 {221 {
222 if (grabs.empty () || event->window != root)222 if (grabsEmpty () || event->window != root)
223 return false;223 return false;
224 }224 }
225225
@@ -1079,7 +1079,7 @@
1079 XAllowEvents (priv->dpy, mode, event->xkey.time);1079 XAllowEvents (priv->dpy, mode, event->xkey.time);
1080 }1080 }
10811081
1082 if (priv->grabs.empty () && event->type == KeyPress)1082 if (priv->grabsEmpty () && event->type == KeyPress)
1083 {1083 {
1084 XUngrabKeyboard (priv->dpy, event->xkey.time);1084 XUngrabKeyboard (priv->dpy, event->xkey.time);
1085 }1085 }
@@ -1120,7 +1120,7 @@
1120 priv->eventHandled = priv->handleActionEvent (event);1120 priv->eventHandled = priv->handleActionEvent (event);
1121 if (priv->eventHandled)1121 if (priv->eventHandled)
1122 {1122 {
1123 if (priv->grabs.empty ())1123 if (priv->grabsEmpty ())
1124 XAllowEvents (priv->dpy, AsyncPointer, event->xbutton.time);1124 XAllowEvents (priv->dpy, AsyncPointer, event->xbutton.time);
1125 return;1125 return;
1126 }1126 }
@@ -1407,7 +1407,7 @@
1407 }1407 }
1408 }1408 }
14091409
1410 if (priv->grabs.empty ())1410 if (priv->grabsEmpty ())
1411 XAllowEvents (priv->dpy, ReplayPointer, event->xbutton.time);1411 XAllowEvents (priv->dpy, ReplayPointer, event->xbutton.time);
14121412
1413 break;1413 break;
@@ -2102,7 +2102,7 @@
2102 priv->below = w->id ();2102 priv->below = w->id ();
21032103
2104 if (!priv->optionGetClickToFocus () &&2104 if (!priv->optionGetClickToFocus () &&
2105 priv->grabs.empty () &&2105 priv->grabsEmpty () &&
2106 event->xcrossing.mode != NotifyGrab &&2106 event->xcrossing.mode != NotifyGrab &&
2107 event->xcrossing.detail != NotifyInferior)2107 event->xcrossing.detail != NotifyInferior)
2108 {2108 {
21092109
=== modified file 'src/privatescreen.h'
--- src/privatescreen.h 2012-03-07 15:25:23 +0000
+++ src/privatescreen.h 2012-03-08 17:50:24 +0000
@@ -577,9 +577,32 @@
577 Time tapStart;577 Time tapStart;
578};578};
579579
580class GrabList
581{
582 // TODO: std::list<Grab *> is almost certainly the wrong data
583 // structure. Probably better as std::vector<Grab> - many fewer
584 // memory allocations and releases.
585 typedef std::list<Grab *> GrabPtrList;
586
587public:
588 typedef GrabPtrList::iterator GrabIterator;
589
590 bool grabsEmpty() const { return grabs.empty(); }
591 void grabsPush(Grab* grab) { grabs.push_back (grab); }
592 GrabIterator grabsBegin() { return grabs.begin(); }
593 GrabIterator grabsEnd() { return grabs.end(); }
594 void grabsRemove(Grab* grab);
595 bool grabExist (const char *grab);
596 Grab* grabsBack() { return grabs.back (); }
597
598private:
599 GrabPtrList grabs;
600};
601
580class EventManager :602class EventManager :
581 public PluginManager,603 public PluginManager,
582 public ValueHolder,604 public ValueHolder,
605 public GrabList,
583 public virtual ScreenUser606 public virtual ScreenUser
584{607{
585public:608public:
@@ -641,11 +664,8 @@
641 int count;664 int count;
642};665};
643666
644class Grab {667struct Grab {
645 public:668 Grab(Cursor cursor, const char *name) : cursor(cursor), name(name) {}
646
647 friend class ::CompScreenImpl;
648 private:
649 Cursor cursor;669 Cursor cursor;
650 const char *name;670 const char *name;
651};671};
@@ -659,7 +679,6 @@
659 Window edgeWindow;679 Window edgeWindow;
660 Window xdndWindow;680 Window xdndWindow;
661 bool eventHandled;681 bool eventHandled;
662 std::list<Grab *> grabs;
663 bool grabbed; /* true once we recieve a GrabNotify682 bool grabbed; /* true once we recieve a GrabNotify
664 on FocusOut and false on683 on FocusOut and false on
665 UngrabNotify from FocusIn */684 UngrabNotify from FocusIn */
666685
=== modified file 'src/screen.cpp'
--- src/screen.cpp 2012-03-08 10:37:58 +0000
+++ src/screen.cpp 2012-03-08 17:50:24 +0000
@@ -2490,7 +2490,7 @@
24902490
2491bool CompScreenImpl::grabsEmpty() const2491bool CompScreenImpl::grabsEmpty() const
2492{2492{
2493 return priv->grabs.empty();2493 return priv->grabsEmpty();
2494}2494}
24952495
2496void2496void
@@ -2929,7 +2929,7 @@
2929CompScreenImpl::GrabHandle2929CompScreenImpl::GrabHandle
2930CompScreenImpl::pushGrab (Cursor cursor, const char *name)2930CompScreenImpl::pushGrab (Cursor cursor, const char *name)
2931{2931{
2932 if (priv->grabs.empty ())2932 if (priv->grabsEmpty ())
2933 {2933 {
2934 int status;2934 int status;
29352935
@@ -2960,11 +2960,8 @@
2960 cursor, CurrentTime);2960 cursor, CurrentTime);
2961 }2961 }
29622962
2963 cps::Grab *grab = new cps::Grab ();2963 cps::Grab *grab = new cps::Grab (cursor, name);
2964 grab->cursor = cursor;2964 priv->grabsPush (grab);
2965 grab->name = name;
2966
2967 priv->grabs.push_back (grab);
29682965
2969 return grab;2966 return grab;
2970}2967}
@@ -2988,20 +2985,13 @@
2988 if (!handle)2985 if (!handle)
2989 return;2986 return;
29902987
2991 std::list<cps::Grab *>::iterator it;2988 priv-> grabsRemove(handle);
29922989
2993 it = std::find (priv->grabs.begin (), priv->grabs.end (), handle);2990 if (!priv->grabsEmpty ())
2994
2995 if (it != priv->grabs.end ())
2996 {
2997 priv->grabs.erase (it);
2998 delete (static_cast<cps::Grab *> (handle));
2999 }
3000 if (!priv->grabs.empty ())
3001 {2991 {
3002 XChangeActivePointerGrab (priv->dpy,2992 XChangeActivePointerGrab (priv->dpy,
3003 POINTER_GRAB_MASK,2993 POINTER_GRAB_MASK,
3004 priv->grabs.back ()->cursor,2994 priv->grabsBack ()->cursor,
3005 CurrentTime);2995 CurrentTime);
3006 }2996 }
3007 else2997 else
@@ -3015,6 +3005,20 @@
3015 }3005 }
3016}3006}
30173007
3008void
3009cps::GrabList::grabsRemove(Grab* handle)
3010{
3011 PrivateScreen::GrabIterator it;
3012
3013 it = std::find (grabsBegin (), grabsEnd (), handle);
3014
3015 if (it != grabsEnd ())
3016 {
3017 grabs.erase (it);
3018 delete (handle);
3019 }
3020}
3021
3018/* otherScreenGrabExist takes a series of strings terminated by a NULL.3022/* otherScreenGrabExist takes a series of strings terminated by a NULL.
3019 It returns true if a grab exists but it is NOT held by one of the3023 It returns true if a grab exists but it is NOT held by one of the
3020 plugins listed, returns false otherwise. */3024 plugins listed, returns false otherwise. */
@@ -3027,7 +3031,7 @@
30273031
3028 std::list<cps::Grab *>::iterator it;3032 std::list<cps::Grab *>::iterator it;
30293033
3030 for (it = priv->grabs.begin (); it != priv->grabs.end (); it++)3034 for (it = priv->grabsBegin (); it != priv->grabsEnd (); it++)
3031 {3035 {
3032 va_start (ap, first);3036 va_start (ap, first);
30333037
@@ -3052,7 +3056,13 @@
3052bool3056bool
3053CompScreenImpl::grabExist (const char *grab)3057CompScreenImpl::grabExist (const char *grab)
3054{3058{
3055 foreach (cps::Grab* g, priv->grabs)3059 return priv->grabExist (grab);
3060}
3061
3062bool
3063cps::GrabList::grabExist (const char *grab)
3064{
3065 foreach (cps::Grab* g, grabs)
3056 {3066 {
3057 if (strcmp (g->name, grab) == 0)3067 if (strcmp (g->name, grab) == 0)
3058 return true;3068 return true;
@@ -5060,7 +5070,6 @@
5060 edgeWindow (None),5070 edgeWindow (None),
5061 xdndWindow (None),5071 xdndWindow (None),
5062 eventHandled (false),5072 eventHandled (false),
5063 grabs (),
5064 grabbed (false)5073 grabbed (false)
5065{5074{
5066}5075}

Subscribers

People subscribed via source and target branches