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

Proposed by Alan Griffiths on 2012-03-08
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 2012-03-08 Approve on 2012-03-09
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.
Daniel van Vugt (vanvugt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/core/screen.h'
2--- include/core/screen.h 2012-03-05 09:04:16 +0000
3+++ include/core/screen.h 2012-03-08 17:50:24 +0000
4@@ -141,6 +141,10 @@
5
6 };
7
8+namespace compiz { namespace private_screen {
9+ class Grab;
10+}}
11+
12 class CompScreen :
13 public WrapableHandler<ScreenInterface, 18>,
14 public PluginClassStorage, // TODO should be an interface here
15@@ -148,7 +152,7 @@
16 public CompOption::Class // TODO should be an interface here
17 {
18 public:
19- typedef void* GrabHandle;
20+ typedef compiz::private_screen::Grab* GrabHandle;
21
22 WRAPABLE_HND (0, ScreenInterface, void, fileWatchAdded, CompFileWatch *)
23 WRAPABLE_HND (1, ScreenInterface, void, fileWatchRemoved, CompFileWatch *)
24
25=== modified file 'src/event.cpp'
26--- src/event.cpp 2012-03-08 08:06:02 +0000
27+++ src/event.cpp 2012-03-08 17:50:24 +0000
28@@ -141,7 +141,7 @@
29 {
30 bool actionEventHandled = false;
31
32- if (state == CompAction::StateInitKey && grabs.empty ())
33+ if (state == CompAction::StateInitKey && grabsEmpty ())
34 {
35 if (grabbed)
36 {
37@@ -219,7 +219,7 @@
38
39 if (event->window != edgeWindow)
40 {
41- if (grabs.empty () || event->window != root)
42+ if (grabsEmpty () || event->window != root)
43 return false;
44 }
45
46@@ -1079,7 +1079,7 @@
47 XAllowEvents (priv->dpy, mode, event->xkey.time);
48 }
49
50- if (priv->grabs.empty () && event->type == KeyPress)
51+ if (priv->grabsEmpty () && event->type == KeyPress)
52 {
53 XUngrabKeyboard (priv->dpy, event->xkey.time);
54 }
55@@ -1120,7 +1120,7 @@
56 priv->eventHandled = priv->handleActionEvent (event);
57 if (priv->eventHandled)
58 {
59- if (priv->grabs.empty ())
60+ if (priv->grabsEmpty ())
61 XAllowEvents (priv->dpy, AsyncPointer, event->xbutton.time);
62 return;
63 }
64@@ -1407,7 +1407,7 @@
65 }
66 }
67
68- if (priv->grabs.empty ())
69+ if (priv->grabsEmpty ())
70 XAllowEvents (priv->dpy, ReplayPointer, event->xbutton.time);
71
72 break;
73@@ -2102,7 +2102,7 @@
74 priv->below = w->id ();
75
76 if (!priv->optionGetClickToFocus () &&
77- priv->grabs.empty () &&
78+ priv->grabsEmpty () &&
79 event->xcrossing.mode != NotifyGrab &&
80 event->xcrossing.detail != NotifyInferior)
81 {
82
83=== modified file 'src/privatescreen.h'
84--- src/privatescreen.h 2012-03-07 15:25:23 +0000
85+++ src/privatescreen.h 2012-03-08 17:50:24 +0000
86@@ -577,9 +577,32 @@
87 Time tapStart;
88 };
89
90+class GrabList
91+{
92+ // TODO: std::list<Grab *> is almost certainly the wrong data
93+ // structure. Probably better as std::vector<Grab> - many fewer
94+ // memory allocations and releases.
95+ typedef std::list<Grab *> GrabPtrList;
96+
97+public:
98+ typedef GrabPtrList::iterator GrabIterator;
99+
100+ bool grabsEmpty() const { return grabs.empty(); }
101+ void grabsPush(Grab* grab) { grabs.push_back (grab); }
102+ GrabIterator grabsBegin() { return grabs.begin(); }
103+ GrabIterator grabsEnd() { return grabs.end(); }
104+ void grabsRemove(Grab* grab);
105+ bool grabExist (const char *grab);
106+ Grab* grabsBack() { return grabs.back (); }
107+
108+private:
109+ GrabPtrList grabs;
110+};
111+
112 class EventManager :
113 public PluginManager,
114 public ValueHolder,
115+ public GrabList,
116 public virtual ScreenUser
117 {
118 public:
119@@ -641,11 +664,8 @@
120 int count;
121 };
122
123-class Grab {
124- public:
125-
126- friend class ::CompScreenImpl;
127- private:
128+struct Grab {
129+ Grab(Cursor cursor, const char *name) : cursor(cursor), name(name) {}
130 Cursor cursor;
131 const char *name;
132 };
133@@ -659,7 +679,6 @@
134 Window edgeWindow;
135 Window xdndWindow;
136 bool eventHandled;
137- std::list<Grab *> grabs;
138 bool grabbed; /* true once we recieve a GrabNotify
139 on FocusOut and false on
140 UngrabNotify from FocusIn */
141
142=== modified file 'src/screen.cpp'
143--- src/screen.cpp 2012-03-08 10:37:58 +0000
144+++ src/screen.cpp 2012-03-08 17:50:24 +0000
145@@ -2490,7 +2490,7 @@
146
147 bool CompScreenImpl::grabsEmpty() const
148 {
149- return priv->grabs.empty();
150+ return priv->grabsEmpty();
151 }
152
153 void
154@@ -2929,7 +2929,7 @@
155 CompScreenImpl::GrabHandle
156 CompScreenImpl::pushGrab (Cursor cursor, const char *name)
157 {
158- if (priv->grabs.empty ())
159+ if (priv->grabsEmpty ())
160 {
161 int status;
162
163@@ -2960,11 +2960,8 @@
164 cursor, CurrentTime);
165 }
166
167- cps::Grab *grab = new cps::Grab ();
168- grab->cursor = cursor;
169- grab->name = name;
170-
171- priv->grabs.push_back (grab);
172+ cps::Grab *grab = new cps::Grab (cursor, name);
173+ priv->grabsPush (grab);
174
175 return grab;
176 }
177@@ -2988,20 +2985,13 @@
178 if (!handle)
179 return;
180
181- std::list<cps::Grab *>::iterator it;
182-
183- it = std::find (priv->grabs.begin (), priv->grabs.end (), handle);
184-
185- if (it != priv->grabs.end ())
186- {
187- priv->grabs.erase (it);
188- delete (static_cast<cps::Grab *> (handle));
189- }
190- if (!priv->grabs.empty ())
191+ priv-> grabsRemove(handle);
192+
193+ if (!priv->grabsEmpty ())
194 {
195 XChangeActivePointerGrab (priv->dpy,
196 POINTER_GRAB_MASK,
197- priv->grabs.back ()->cursor,
198+ priv->grabsBack ()->cursor,
199 CurrentTime);
200 }
201 else
202@@ -3015,6 +3005,20 @@
203 }
204 }
205
206+void
207+cps::GrabList::grabsRemove(Grab* handle)
208+{
209+ PrivateScreen::GrabIterator it;
210+
211+ it = std::find (grabsBegin (), grabsEnd (), handle);
212+
213+ if (it != grabsEnd ())
214+ {
215+ grabs.erase (it);
216+ delete (handle);
217+ }
218+}
219+
220 /* otherScreenGrabExist takes a series of strings terminated by a NULL.
221 It returns true if a grab exists but it is NOT held by one of the
222 plugins listed, returns false otherwise. */
223@@ -3027,7 +3031,7 @@
224
225 std::list<cps::Grab *>::iterator it;
226
227- for (it = priv->grabs.begin (); it != priv->grabs.end (); it++)
228+ for (it = priv->grabsBegin (); it != priv->grabsEnd (); it++)
229 {
230 va_start (ap, first);
231
232@@ -3052,7 +3056,13 @@
233 bool
234 CompScreenImpl::grabExist (const char *grab)
235 {
236- foreach (cps::Grab* g, priv->grabs)
237+ return priv->grabExist (grab);
238+}
239+
240+bool
241+cps::GrabList::grabExist (const char *grab)
242+{
243+ foreach (cps::Grab* g, grabs)
244 {
245 if (strcmp (g->name, grab) == 0)
246 return true;
247@@ -5060,7 +5070,6 @@
248 edgeWindow (None),
249 xdndWindow (None),
250 eventHandled (false),
251- grabs (),
252 grabbed (false)
253 {
254 }

Subscribers

People subscribed via source and target branches