Merge lp:~bratsche/libgrope/single-callback into lp:libgrope
- single-callback
- Merge into trunk
Proposed by
Cody Russell
Status: | Merged |
---|---|
Merged at revision: | 7 |
Proposed branch: | lp:~bratsche/libgrope/single-callback |
Merge into: | lp:libgrope |
Diff against target: |
432 lines (+163/-107) 5 files modified
example/gesture.c (+46/-61) example/python/example.py (+48/-0) example/python/pygrope-gestures.xml (+16/-0) src/gropegesturemanager.c (+45/-43) src/gropegesturemanager.h (+8/-3) |
To merge this branch: | bzr merge lp:~bratsche/libgrope/single-callback |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stephen M. Webb (community) | Approve | ||
Review via email: mp+41006@code.launchpad.net |
Commit message
Description of the change
The Python binding stuff doesn't seem to like having multiple callback functions register in one place, for some reason. So this branch switches to having a single callback function.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'example/gesture.c' |
2 | --- example/gesture.c 2010-11-09 21:59:17 +0000 |
3 | +++ example/gesture.c 2010-11-16 20:23:13 +0000 |
4 | @@ -61,58 +61,49 @@ |
5 | } |
6 | |
7 | static void |
8 | -gesture_start (GtkWindow *window, |
9 | - GropeGestureEvent *event, |
10 | - gpointer user_data) |
11 | -{ |
12 | - in_touch++; |
13 | - |
14 | - gtk_widget_queue_draw (GTK_WIDGET (window)); |
15 | -} |
16 | - |
17 | -static void |
18 | -gesture_end (GtkWindow *window, |
19 | - GropeGestureEvent *event, |
20 | - gpointer user_data) |
21 | -{ |
22 | - in_touch--; |
23 | - |
24 | - gtk_widget_queue_draw (GTK_WIDGET (window)); |
25 | -} |
26 | - |
27 | -static void |
28 | -rotate_update (GtkWindow *window, |
29 | - GropeGestureEvent *event, |
30 | - gpointer user_data) |
31 | -{ |
32 | - GropeEventGestureRotate *e = (GropeEventGestureRotate *)event; |
33 | - |
34 | - rotate += e->angle_delta * 100; |
35 | - |
36 | - gtk_widget_queue_draw (GTK_WIDGET (window)); |
37 | -} |
38 | - |
39 | -static void |
40 | -pinch_update (GtkWindow *window, |
41 | - GropeGestureEvent *event, |
42 | - gpointer user_data) |
43 | -{ |
44 | - GropeEventGesturePinch *e = (GropeEventGesturePinch *)event; |
45 | - |
46 | - scale += e->radius_delta / 100; |
47 | - |
48 | - gtk_widget_queue_draw (GTK_WIDGET (window)); |
49 | -} |
50 | - |
51 | -static void |
52 | -drag_update (GtkWindow *window, |
53 | - GropeGestureEvent *event, |
54 | - gpointer user_data) |
55 | -{ |
56 | - GropeEventGestureDrag *e = (GropeEventGestureDrag *)event; |
57 | - |
58 | - translate[0] += e->delta_x; |
59 | - translate[1] += e->delta_y; |
60 | +gesture_callback (GtkWindow *window, |
61 | + GropeTimeType time_type, |
62 | + GropeGestureEvent *event, |
63 | + gpointer user_data) |
64 | +{ |
65 | + if (time_type == GROPE_TIME_START) |
66 | + { |
67 | + in_touch++; |
68 | + } |
69 | + else if (time_type == GROPE_TIME_END) |
70 | + { |
71 | + in_touch--; |
72 | + } |
73 | + else |
74 | + { |
75 | + switch (event->type) |
76 | + { |
77 | + case GROPE_GESTURE_DRAG: |
78 | + { |
79 | + GropeEventGestureDrag *e = (GropeEventGestureDrag *)event; |
80 | + |
81 | + translate[0] += e->delta_x; |
82 | + translate[1] += e->delta_y; |
83 | + } |
84 | + break; |
85 | + |
86 | + case GROPE_GESTURE_PINCH: |
87 | + { |
88 | + GropeEventGesturePinch *e = (GropeEventGesturePinch *)event; |
89 | + |
90 | + scale += e->radius_delta / 100; |
91 | + } |
92 | + break; |
93 | + |
94 | + case GROPE_GESTURE_ROTATE: |
95 | + { |
96 | + GropeEventGestureRotate *e = (GropeEventGestureRotate *)event; |
97 | + |
98 | + rotate += e->angle_delta * 100; |
99 | + } |
100 | + break; |
101 | + } |
102 | + } |
103 | |
104 | gtk_widget_queue_draw (GTK_WIDGET (window)); |
105 | } |
106 | @@ -127,27 +118,21 @@ |
107 | window, |
108 | GROPE_GESTURE_PINCH, |
109 | 2, |
110 | - gesture_start, |
111 | - pinch_update, |
112 | - gesture_end, |
113 | + gesture_callback, |
114 | NULL, NULL); |
115 | |
116 | grope_gesture_manager_register_window (manager, |
117 | window, |
118 | GROPE_GESTURE_ROTATE, |
119 | 2, |
120 | - gesture_start, |
121 | - rotate_update, |
122 | - gesture_end, |
123 | + gesture_callback, |
124 | NULL, NULL); |
125 | |
126 | grope_gesture_manager_register_window (manager, |
127 | window, |
128 | GROPE_GESTURE_DRAG, |
129 | 2, |
130 | - gesture_start, |
131 | - drag_update, |
132 | - gesture_end, |
133 | + gesture_callback, |
134 | NULL, NULL); |
135 | } |
136 | |
137 | |
138 | === added directory 'example/python' |
139 | === added file 'example/python/example.py' |
140 | --- example/python/example.py 1970-01-01 00:00:00 +0000 |
141 | +++ example/python/example.py 2010-11-16 20:23:13 +0000 |
142 | @@ -0,0 +1,48 @@ |
143 | +import pygtk |
144 | +from gi.repository import Gtk |
145 | +from gi.repository import Grope |
146 | + |
147 | +# XXX For now, we'll use Grope directly. Once we have a good sense of what's |
148 | +# going to be needed in general for general Python code using Grope, we might |
149 | +# want to put that stuff in a wrapper grope module, and import everything from |
150 | +# there instead. |
151 | + |
152 | + |
153 | +class GestureTester(object): |
154 | + |
155 | + def __init__(self): |
156 | + builder = Gtk.Builder() |
157 | + builder.add_from_file("pygrope-gestures.xml") |
158 | + builder.connect_signals(self) |
159 | + self.window = builder.get_object("window1") |
160 | + self.window.show() |
161 | + |
162 | + def window_mapped(self, widget, data=None): |
163 | + # The gesture manager is only going to be needed for GTK2, since GTK3 |
164 | + # will have the gesture API natively. Conversely, pygrope will only be |
165 | + # for GTK2, since PyGTK3 will having the bindings. |
166 | + gesture_manager = Grope.GestureManager() |
167 | + # For the purpose of this example, we are registering all gestures; we |
168 | + # could limit this by choosing a different pygrope.GROPE_GESTURE_* |
169 | + # mask. Similarly, we're using one set of callbacks for all the |
170 | + # gestures; we could have different callbacks for different registered |
171 | + # gestures. |
172 | + # XXX the comment above is for the new API; the example below has been |
173 | + # reverted to the older API until the new one is merged to trunk. |
174 | + finger_count = 2 |
175 | + gesture_manager.register_window(self.window, |
176 | + Grope.GestureType.PINCH, |
177 | + finger_count, |
178 | + self.callback, |
179 | + None, None) |
180 | + |
181 | + def callback(self, window, time_type, gesture_type, gesture_event): |
182 | + print "received gesture" |
183 | + |
184 | + def quit(self, widget, data=None): |
185 | + Gtk.main_quit() |
186 | + |
187 | + |
188 | +if __name__ == "__main__": |
189 | + app = GestureTester() |
190 | + Gtk.main() |
191 | |
192 | === added file 'example/python/pygrope-gestures.xml' |
193 | --- example/python/pygrope-gestures.xml 1970-01-01 00:00:00 +0000 |
194 | +++ example/python/pygrope-gestures.xml 2010-11-16 20:23:13 +0000 |
195 | @@ -0,0 +1,16 @@ |
196 | +<?xml version="1.0"?> |
197 | +<interface> |
198 | + <requires lib="gtk+" version="2.16"/> |
199 | + <!-- interface-naming-policy project-wide --> |
200 | + <object class="GtkWindow" id="window1"> |
201 | + <property name="width_request">0</property> |
202 | + <property name="height_request">0</property> |
203 | + <property name="default_width">1400</property> |
204 | + <property name="default_height">800</property> |
205 | + <signal name="map_event" handler="window_mapped"/> |
206 | + <signal name="delete_event" handler="quit"/> |
207 | + <child> |
208 | + <placeholder/> |
209 | + </child> |
210 | + </object> |
211 | +</interface> |
212 | |
213 | === modified file 'src/gropegesturemanager.c' |
214 | --- src/gropegesturemanager.c 2010-11-10 19:56:11 +0000 |
215 | +++ src/gropegesturemanager.c 2010-11-16 20:23:13 +0000 |
216 | @@ -40,9 +40,7 @@ |
217 | { |
218 | GropeGestureType type; |
219 | gint touches; |
220 | - GropeGestureCallback start; |
221 | - GropeGestureCallback update; |
222 | - GropeGestureCallback end; |
223 | + GropeGestureCallback callback; |
224 | gpointer data; |
225 | GDestroyNotify destroy; |
226 | }; |
227 | @@ -367,9 +365,10 @@ |
228 | |
229 | if (drag.fingers == binding->touches) |
230 | { |
231 | - binding->start (reg->window, |
232 | - ((GropeGestureEvent*)&drag), |
233 | - binding->data); |
234 | + binding->callback (reg->window, |
235 | + GROPE_TIME_START, |
236 | + ((GropeGestureEvent*)&drag), |
237 | + binding->data); |
238 | } |
239 | } |
240 | else if (type == GROPE_GESTURE_PINCH) |
241 | @@ -384,9 +383,10 @@ |
242 | |
243 | if (pinch.fingers == binding->touches) |
244 | { |
245 | - binding->start (reg->window, |
246 | - ((GropeGestureEvent*)&pinch), |
247 | - binding->data); |
248 | + binding->callback (reg->window, |
249 | + GROPE_TIME_START, |
250 | + ((GropeGestureEvent*)&pinch), |
251 | + binding->data); |
252 | } |
253 | } |
254 | else if (type == GROPE_GESTURE_ROTATE) |
255 | @@ -401,9 +401,10 @@ |
256 | |
257 | if (rotate.fingers == binding->touches) |
258 | { |
259 | - binding->start (reg->window, |
260 | - ((GropeGestureEvent*)&rotate), |
261 | - binding->data); |
262 | + binding->callback (reg->window, |
263 | + GROPE_TIME_START, |
264 | + ((GropeGestureEvent*)&rotate), |
265 | + binding->data); |
266 | } |
267 | } |
268 | |
269 | @@ -440,9 +441,10 @@ |
270 | |
271 | if (drag.fingers == binding->touches) |
272 | { |
273 | - binding->update (reg->window, |
274 | - ((GropeGestureEvent*)&drag), |
275 | - binding->data); |
276 | + binding->callback (reg->window, |
277 | + GROPE_TIME_UPDATE, |
278 | + ((GropeGestureEvent*)&drag), |
279 | + binding->data); |
280 | } |
281 | } |
282 | else if (type == GROPE_GESTURE_PINCH) |
283 | @@ -457,9 +459,10 @@ |
284 | |
285 | if (pinch.fingers == binding->touches) |
286 | { |
287 | - binding->update (reg->window, |
288 | - ((GropeGestureEvent*)&pinch), |
289 | - binding->data); |
290 | + binding->callback (reg->window, |
291 | + GROPE_TIME_UPDATE, |
292 | + ((GropeGestureEvent*)&pinch), |
293 | + binding->data); |
294 | } |
295 | } |
296 | else if (type == GROPE_GESTURE_ROTATE) |
297 | @@ -474,9 +477,10 @@ |
298 | |
299 | if (rotate.fingers == binding->touches) |
300 | { |
301 | - binding->update (reg->window, |
302 | - ((GropeGestureEvent*)&rotate), |
303 | - binding->data); |
304 | + binding->callback (reg->window, |
305 | + GROPE_TIME_UPDATE, |
306 | + ((GropeGestureEvent*)&rotate), |
307 | + binding->data); |
308 | } |
309 | } |
310 | } |
311 | @@ -511,9 +515,10 @@ |
312 | |
313 | if (drag.fingers == binding->touches) |
314 | { |
315 | - binding->end (reg->window, |
316 | - ((GropeGestureEvent*)&drag), |
317 | - binding->data); |
318 | + binding->callback (reg->window, |
319 | + GROPE_TIME_END, |
320 | + ((GropeGestureEvent*)&drag), |
321 | + binding->data); |
322 | } |
323 | } |
324 | else if (type == GROPE_GESTURE_PINCH) |
325 | @@ -528,9 +533,10 @@ |
326 | |
327 | if (pinch.fingers == binding->touches) |
328 | { |
329 | - binding->end (reg->window, |
330 | - ((GropeGestureEvent*)&pinch), |
331 | - binding->data); |
332 | + binding->callback (reg->window, |
333 | + GROPE_TIME_END, |
334 | + ((GropeGestureEvent*)&pinch), |
335 | + binding->data); |
336 | } |
337 | } |
338 | else if (type == GROPE_GESTURE_ROTATE) |
339 | @@ -545,9 +551,10 @@ |
340 | |
341 | if (rotate.fingers == binding->touches) |
342 | { |
343 | - binding->end (reg->window, |
344 | - ((GropeGestureEvent*)&rotate), |
345 | - binding->data); |
346 | + binding->callback (reg->window, |
347 | + GROPE_TIME_END, |
348 | + ((GropeGestureEvent*)&rotate), |
349 | + binding->data); |
350 | } |
351 | } |
352 | } |
353 | @@ -619,12 +626,11 @@ |
354 | |
355 | /** |
356 | * grope_gesture_manager_register_window: |
357 | + * @manager: A #GropeGestureManager instance. |
358 | * @window: A #GtkWindow to register the gesture event for. |
359 | * @gesture_type: The type of gesture event to register. |
360 | * @touch_points: Number of touch points for this gesture. |
361 | - * @start: Called when a user initiates a gesture. |
362 | - * @update: Called each time the user updates the gesture. |
363 | - * @end: Called when the user ends the gesture. |
364 | + * @callback: Called when a gesture starts, updates, or ends. |
365 | * @user_data: User data |
366 | * @destroy: Destroy callback for user data. |
367 | * |
368 | @@ -638,9 +644,7 @@ |
369 | GtkWindow *window, |
370 | GropeGestureType gesture_type, |
371 | gint touch_points, |
372 | - GropeGestureCallback start, |
373 | - GropeGestureCallback update, |
374 | - GropeGestureCallback end, |
375 | + GropeGestureCallback callback, |
376 | gpointer user_data, |
377 | GDestroyNotify destroy) |
378 | { |
379 | @@ -718,13 +722,11 @@ |
380 | /* XXX - check for duplicates in reg->bindings first */ |
381 | binding = g_new0 (GropeGestureBinding, 1); |
382 | |
383 | - binding->type = gesture_type; |
384 | - binding->touches = touch_points; |
385 | - binding->start = start; |
386 | - binding->update = update; |
387 | - binding->end = end; |
388 | - binding->data = user_data; |
389 | - binding->destroy = destroy; |
390 | + binding->type = gesture_type; |
391 | + binding->touches = touch_points; |
392 | + binding->callback = callback; |
393 | + binding->data = user_data; |
394 | + binding->destroy = destroy; |
395 | |
396 | reg->bindings = g_list_append (reg->bindings, binding); |
397 | |
398 | |
399 | === modified file 'src/gropegesturemanager.h' |
400 | --- src/gropegesturemanager.h 2010-11-10 19:56:11 +0000 |
401 | +++ src/gropegesturemanager.h 2010-11-16 20:23:13 +0000 |
402 | @@ -52,6 +52,12 @@ |
403 | GROPE_GESTURE_ROTATE |
404 | } GropeGestureType; |
405 | |
406 | +typedef enum { |
407 | + GROPE_TIME_START, |
408 | + GROPE_TIME_UPDATE, |
409 | + GROPE_TIME_END |
410 | +} GropeTimeType; |
411 | + |
412 | struct _GropeEventGestureDrag |
413 | { |
414 | GropeGestureType type; |
415 | @@ -136,6 +142,7 @@ |
416 | }; |
417 | |
418 | typedef void (* GropeGestureCallback) (GtkWindow *window, |
419 | + GropeTimeType time, |
420 | GropeGestureEvent *gesture, |
421 | gpointer user_data); |
422 | |
423 | @@ -145,9 +152,7 @@ |
424 | GtkWindow *window, |
425 | GropeGestureType gesture_type, |
426 | gint touch_points, |
427 | - GropeGestureCallback start, |
428 | - GropeGestureCallback update, |
429 | - GropeGestureCallback end, |
430 | + GropeGestureCallback callback, |
431 | gpointer user_data, |
432 | GDestroyNotify destroy); |
433 |
Look OK to me.