Merge lp:~bratsche/libgrope/callback-user-data into lp:libgrope
- callback-user-data
- Merge into trunk
Proposed by
Cody Russell
Status: | Merged |
---|---|
Merged at revision: | 3 |
Proposed branch: | lp:~bratsche/libgrope/callback-user-data |
Merge into: | lp:libgrope |
Diff against target: |
274 lines (+62/-31) 4 files modified
example/gesture.c (+16/-8) src/grope.h (+1/-3) src/gropegesturemanager.c (+37/-15) src/gropegesturemanager.h (+8/-5) |
To merge this branch: | bzr merge lp:~bratsche/libgrope/callback-user-data |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Duncan McGreggor (community) | Approve | ||
Open Input Framework Team | Pending | ||
Review via email: mp+40479@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 3. By Cody Russell
-
Add data to binding.
Revision history for this message
Cody Russell (bratsche) wrote : | # |
Oops, I put that up for review earlier than intended. The next revision finishes off what I wanted to do.
When you register a window to receive gesture events, you can pass some arbitrary data that will be stored in the registration and sent to the callback functions.
Revision history for this message
Duncan McGreggor (oubiwann) wrote : | # |
Cool, thanks for the extra info :-)
review:
Approve
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-10-12 15:42:04 +0000 | |||
3 | +++ example/gesture.c 2010-11-09 22:01:46 +0000 | |||
4 | @@ -62,7 +62,8 @@ | |||
5 | 62 | 62 | ||
6 | 63 | static void | 63 | static void |
7 | 64 | gesture_start (GtkWindow *window, | 64 | gesture_start (GtkWindow *window, |
9 | 65 | GropeGestureEvent *event) | 65 | GropeGestureEvent *event, |
10 | 66 | gpointer user_data) | ||
11 | 66 | { | 67 | { |
12 | 67 | in_touch++; | 68 | in_touch++; |
13 | 68 | 69 | ||
14 | @@ -71,7 +72,8 @@ | |||
15 | 71 | 72 | ||
16 | 72 | static void | 73 | static void |
17 | 73 | gesture_end (GtkWindow *window, | 74 | gesture_end (GtkWindow *window, |
19 | 74 | GropeGestureEvent *event) | 75 | GropeGestureEvent *event, |
20 | 76 | gpointer user_data) | ||
21 | 75 | { | 77 | { |
22 | 76 | in_touch--; | 78 | in_touch--; |
23 | 77 | 79 | ||
24 | @@ -80,7 +82,8 @@ | |||
25 | 80 | 82 | ||
26 | 81 | static void | 83 | static void |
27 | 82 | rotate_update (GtkWindow *window, | 84 | rotate_update (GtkWindow *window, |
29 | 83 | GropeGestureEvent *event) | 85 | GropeGestureEvent *event, |
30 | 86 | gpointer user_data) | ||
31 | 84 | { | 87 | { |
32 | 85 | GropeEventGestureRotate *e = (GropeEventGestureRotate *)event; | 88 | GropeEventGestureRotate *e = (GropeEventGestureRotate *)event; |
33 | 86 | 89 | ||
34 | @@ -91,7 +94,8 @@ | |||
35 | 91 | 94 | ||
36 | 92 | static void | 95 | static void |
37 | 93 | pinch_update (GtkWindow *window, | 96 | pinch_update (GtkWindow *window, |
39 | 94 | GropeGestureEvent *event) | 97 | GropeGestureEvent *event, |
40 | 98 | gpointer user_data) | ||
41 | 95 | { | 99 | { |
42 | 96 | GropeEventGesturePinch *e = (GropeEventGesturePinch *)event; | 100 | GropeEventGesturePinch *e = (GropeEventGesturePinch *)event; |
43 | 97 | 101 | ||
44 | @@ -102,7 +106,8 @@ | |||
45 | 102 | 106 | ||
46 | 103 | static void | 107 | static void |
47 | 104 | drag_update (GtkWindow *window, | 108 | drag_update (GtkWindow *window, |
49 | 105 | GropeGestureEvent *event) | 109 | GropeGestureEvent *event, |
50 | 110 | gpointer user_data) | ||
51 | 106 | { | 111 | { |
52 | 107 | GropeEventGestureDrag *e = (GropeEventGestureDrag *)event; | 112 | GropeEventGestureDrag *e = (GropeEventGestureDrag *)event; |
53 | 108 | 113 | ||
54 | @@ -124,7 +129,8 @@ | |||
55 | 124 | 2, | 129 | 2, |
56 | 125 | gesture_start, | 130 | gesture_start, |
57 | 126 | pinch_update, | 131 | pinch_update, |
59 | 127 | gesture_end); | 132 | gesture_end, |
60 | 133 | NULL, NULL); | ||
61 | 128 | 134 | ||
62 | 129 | grope_gesture_manager_register_window (manager, | 135 | grope_gesture_manager_register_window (manager, |
63 | 130 | window, | 136 | window, |
64 | @@ -132,7 +138,8 @@ | |||
65 | 132 | 2, | 138 | 2, |
66 | 133 | gesture_start, | 139 | gesture_start, |
67 | 134 | rotate_update, | 140 | rotate_update, |
69 | 135 | gesture_end); | 141 | gesture_end, |
70 | 142 | NULL, NULL); | ||
71 | 136 | 143 | ||
72 | 137 | grope_gesture_manager_register_window (manager, | 144 | grope_gesture_manager_register_window (manager, |
73 | 138 | window, | 145 | window, |
74 | @@ -140,7 +147,8 @@ | |||
75 | 140 | 2, | 147 | 2, |
76 | 141 | gesture_start, | 148 | gesture_start, |
77 | 142 | drag_update, | 149 | drag_update, |
79 | 143 | gesture_end); | 150 | gesture_end, |
80 | 151 | NULL, NULL); | ||
81 | 144 | } | 152 | } |
82 | 145 | 153 | ||
83 | 146 | static void | 154 | static void |
84 | 147 | 155 | ||
85 | === modified file 'src/grope.h' | |||
86 | --- src/grope.h 2010-10-12 15:42:04 +0000 | |||
87 | +++ src/grope.h 2010-11-09 22:01:46 +0000 | |||
88 | @@ -26,8 +26,6 @@ | |||
89 | 26 | #ifndef __GROPE_H__ | 26 | #ifndef __GROPE_H__ |
90 | 27 | #define __GROPE_H__ | 27 | #define __GROPE_H__ |
91 | 28 | 28 | ||
95 | 29 | #include <libgrope/gropescalemenuitem.h> | 29 | #include <libgrope/gropegesturemanager.h> |
93 | 30 | #include <libgrope/gropeentrymenuitem.h> | ||
94 | 31 | #include <libgrope/gropemessagedialog.h> | ||
96 | 32 | 30 | ||
97 | 33 | #endif /* __GROPE_H__ */ | 31 | #endif /* __GROPE_H__ */ |
98 | 34 | 32 | ||
99 | === modified file 'src/gropegesturemanager.c' | |||
100 | --- src/gropegesturemanager.c 2010-10-12 15:42:04 +0000 | |||
101 | +++ src/gropegesturemanager.c 2010-11-09 22:01:46 +0000 | |||
102 | @@ -38,11 +38,13 @@ | |||
103 | 38 | 38 | ||
104 | 39 | struct _GropeGestureBinding | 39 | struct _GropeGestureBinding |
105 | 40 | { | 40 | { |
111 | 41 | GropeGestureType type; | 41 | GropeGestureType type; |
112 | 42 | gint touches; | 42 | gint touches; |
113 | 43 | GropeGestureCallback start; | 43 | GropeGestureCallback start; |
114 | 44 | GropeGestureCallback update; | 44 | GropeGestureCallback update; |
115 | 45 | GropeGestureCallback end; | 45 | GropeGestureCallback end; |
116 | 46 | gpointer data; | ||
117 | 47 | GDestroyNotify destroy; | ||
118 | 46 | }; | 48 | }; |
119 | 47 | 49 | ||
120 | 48 | struct _GropeGestureRegistration | 50 | struct _GropeGestureRegistration |
121 | @@ -366,7 +368,8 @@ | |||
122 | 366 | if (drag.fingers == binding->touches) | 368 | if (drag.fingers == binding->touches) |
123 | 367 | { | 369 | { |
124 | 368 | binding->start (reg->window, | 370 | binding->start (reg->window, |
126 | 369 | ((GropeGestureEvent*)&drag)); | 371 | ((GropeGestureEvent*)&drag), |
127 | 372 | binding->data); | ||
128 | 370 | } | 373 | } |
129 | 371 | } | 374 | } |
130 | 372 | else if (type == GROPE_GESTURE_PINCH) | 375 | else if (type == GROPE_GESTURE_PINCH) |
131 | @@ -382,7 +385,8 @@ | |||
132 | 382 | if (pinch.fingers == binding->touches) | 385 | if (pinch.fingers == binding->touches) |
133 | 383 | { | 386 | { |
134 | 384 | binding->start (reg->window, | 387 | binding->start (reg->window, |
136 | 385 | ((GropeGestureEvent*)&pinch)); | 388 | ((GropeGestureEvent*)&pinch), |
137 | 389 | binding->data); | ||
138 | 386 | } | 390 | } |
139 | 387 | } | 391 | } |
140 | 388 | else if (type == GROPE_GESTURE_ROTATE) | 392 | else if (type == GROPE_GESTURE_ROTATE) |
141 | @@ -398,7 +402,8 @@ | |||
142 | 398 | if (rotate.fingers == binding->touches) | 402 | if (rotate.fingers == binding->touches) |
143 | 399 | { | 403 | { |
144 | 400 | binding->start (reg->window, | 404 | binding->start (reg->window, |
146 | 401 | ((GropeGestureEvent*)&rotate)); | 405 | ((GropeGestureEvent*)&rotate), |
147 | 406 | binding->data); | ||
148 | 402 | } | 407 | } |
149 | 403 | } | 408 | } |
150 | 404 | 409 | ||
151 | @@ -436,7 +441,8 @@ | |||
152 | 436 | if (drag.fingers == binding->touches) | 441 | if (drag.fingers == binding->touches) |
153 | 437 | { | 442 | { |
154 | 438 | binding->update (reg->window, | 443 | binding->update (reg->window, |
156 | 439 | ((GropeGestureEvent*)&drag)); | 444 | ((GropeGestureEvent*)&drag), |
157 | 445 | binding->data); | ||
158 | 440 | } | 446 | } |
159 | 441 | } | 447 | } |
160 | 442 | else if (type == GROPE_GESTURE_PINCH) | 448 | else if (type == GROPE_GESTURE_PINCH) |
161 | @@ -452,7 +458,8 @@ | |||
162 | 452 | if (pinch.fingers == binding->touches) | 458 | if (pinch.fingers == binding->touches) |
163 | 453 | { | 459 | { |
164 | 454 | binding->update (reg->window, | 460 | binding->update (reg->window, |
166 | 455 | ((GropeGestureEvent*)&pinch)); | 461 | ((GropeGestureEvent*)&pinch), |
167 | 462 | binding->data); | ||
168 | 456 | } | 463 | } |
169 | 457 | } | 464 | } |
170 | 458 | else if (type == GROPE_GESTURE_ROTATE) | 465 | else if (type == GROPE_GESTURE_ROTATE) |
171 | @@ -468,7 +475,8 @@ | |||
172 | 468 | if (rotate.fingers == binding->touches) | 475 | if (rotate.fingers == binding->touches) |
173 | 469 | { | 476 | { |
174 | 470 | binding->update (reg->window, | 477 | binding->update (reg->window, |
176 | 471 | ((GropeGestureEvent*)&rotate)); | 478 | ((GropeGestureEvent*)&rotate), |
177 | 479 | binding->data); | ||
178 | 472 | } | 480 | } |
179 | 473 | } | 481 | } |
180 | 474 | } | 482 | } |
181 | @@ -504,7 +512,8 @@ | |||
182 | 504 | if (drag.fingers == binding->touches) | 512 | if (drag.fingers == binding->touches) |
183 | 505 | { | 513 | { |
184 | 506 | binding->end (reg->window, | 514 | binding->end (reg->window, |
186 | 507 | ((GropeGestureEvent*)&drag)); | 515 | ((GropeGestureEvent*)&drag), |
187 | 516 | binding->data); | ||
188 | 508 | } | 517 | } |
189 | 509 | } | 518 | } |
190 | 510 | else if (type == GROPE_GESTURE_PINCH) | 519 | else if (type == GROPE_GESTURE_PINCH) |
191 | @@ -520,7 +529,8 @@ | |||
192 | 520 | if (pinch.fingers == binding->touches) | 529 | if (pinch.fingers == binding->touches) |
193 | 521 | { | 530 | { |
194 | 522 | binding->end (reg->window, | 531 | binding->end (reg->window, |
196 | 523 | ((GropeGestureEvent*)&pinch)); | 532 | ((GropeGestureEvent*)&pinch), |
197 | 533 | binding->data); | ||
198 | 524 | } | 534 | } |
199 | 525 | } | 535 | } |
200 | 526 | else if (type == GROPE_GESTURE_ROTATE) | 536 | else if (type == GROPE_GESTURE_ROTATE) |
201 | @@ -536,7 +546,8 @@ | |||
202 | 536 | if (rotate.fingers == binding->touches) | 546 | if (rotate.fingers == binding->touches) |
203 | 537 | { | 547 | { |
204 | 538 | binding->end (reg->window, | 548 | binding->end (reg->window, |
206 | 539 | ((GropeGestureEvent*)&rotate)); | 549 | ((GropeGestureEvent*)&rotate), |
207 | 550 | binding->data); | ||
208 | 540 | } | 551 | } |
209 | 541 | } | 552 | } |
210 | 542 | } | 553 | } |
211 | @@ -578,6 +589,13 @@ | |||
212 | 578 | { | 589 | { |
213 | 579 | GropeGestureBinding *binding = (GropeGestureBinding *)list->data; | 590 | GropeGestureBinding *binding = (GropeGestureBinding *)list->data; |
214 | 580 | 591 | ||
215 | 592 | if (binding->destroy) | ||
216 | 593 | { | ||
217 | 594 | GDestroyNotify d = binding->destroy; | ||
218 | 595 | |||
219 | 596 | d (binding->data); | ||
220 | 597 | } | ||
221 | 598 | |||
222 | 581 | g_free (binding); | 599 | g_free (binding); |
223 | 582 | } | 600 | } |
224 | 583 | 601 | ||
225 | @@ -620,7 +638,9 @@ | |||
226 | 620 | gint touch_points, | 638 | gint touch_points, |
227 | 621 | GropeGestureCallback start, | 639 | GropeGestureCallback start, |
228 | 622 | GropeGestureCallback update, | 640 | GropeGestureCallback update, |
230 | 623 | GropeGestureCallback end) | 641 | GropeGestureCallback end, |
231 | 642 | gpointer user_data, | ||
232 | 643 | GDestroyNotify destroy) | ||
233 | 624 | { | 644 | { |
234 | 625 | GropeGestureManagerPrivate *priv; | 645 | GropeGestureManagerPrivate *priv; |
235 | 626 | GropeGestureRegistration *reg; | 646 | GropeGestureRegistration *reg; |
236 | @@ -701,6 +721,8 @@ | |||
237 | 701 | binding->start = start; | 721 | binding->start = start; |
238 | 702 | binding->update = update; | 722 | binding->update = update; |
239 | 703 | binding->end = end; | 723 | binding->end = end; |
240 | 724 | binding->data = user_data; | ||
241 | 725 | binding->destroy = destroy; | ||
242 | 704 | 726 | ||
243 | 705 | reg->bindings = g_list_append (reg->bindings, binding); | 727 | reg->bindings = g_list_append (reg->bindings, binding); |
244 | 706 | 728 | ||
245 | 707 | 729 | ||
246 | === modified file 'src/gropegesturemanager.h' | |||
247 | --- src/gropegesturemanager.h 2010-10-12 15:42:04 +0000 | |||
248 | +++ src/gropegesturemanager.h 2010-11-09 22:01:46 +0000 | |||
249 | @@ -123,18 +123,21 @@ | |||
250 | 123 | GObjectClass parent_class; | 123 | GObjectClass parent_class; |
251 | 124 | }; | 124 | }; |
252 | 125 | 125 | ||
255 | 126 | typedef void (* GropeGestureCallback) (GtkWindow *window, | 126 | typedef void (* GropeGestureCallback) (GtkWindow *window, |
256 | 127 | GropeGestureEvent *gesture); | 127 | GropeGestureEvent *gesture, |
257 | 128 | gpointer user_data); | ||
258 | 128 | 129 | ||
259 | 129 | GType grope_gesture_manager_get_type (void) G_GNUC_CONST; | 130 | GType grope_gesture_manager_get_type (void) G_GNUC_CONST; |
260 | 130 | GropeGestureManager *grope_gesture_manager_get (void); | 131 | GropeGestureManager *grope_gesture_manager_get (void); |
261 | 131 | void grope_gesture_manager_register_window (GropeGestureManager *manager, | 132 | void grope_gesture_manager_register_window (GropeGestureManager *manager, |
263 | 132 | GtkWindow *window, | 133 | GtkWindow *window, |
264 | 133 | GropeGestureType gesture_type, | 134 | GropeGestureType gesture_type, |
266 | 134 | gint touch_points, | 135 | gint touch_points, |
267 | 135 | GropeGestureCallback start, | 136 | GropeGestureCallback start, |
268 | 136 | GropeGestureCallback update, | 137 | GropeGestureCallback update, |
270 | 137 | GropeGestureCallback end); | 138 | GropeGestureCallback end, |
271 | 139 | gpointer user_data, | ||
272 | 140 | GDestroyNotify destroy); | ||
273 | 138 | 141 | ||
274 | 139 | G_END_DECLS | 142 | G_END_DECLS |
275 | 140 | 143 |
I'm +1 for this change, as long as I understand it :-) Can you explain (briefly; no need for a disertation) the reason you're adding the gpointer?