Merge lp:~jpakkane/libgrip/type_separation into lp:libgrip
- type_separation
- Merge into trunk
Proposed by
Jussi Pakkanen
Status: | Merged |
---|---|
Merged at revision: | 48 |
Proposed branch: | lp:~jpakkane/libgrip/type_separation |
Merge into: | lp:libgrip |
Diff against target: |
473 lines (+201/-113) 4 files modified
configure.ac (+1/-1) examples/rectangle-mover/gesture.c (+7/-4) libgrip.pc.in (+1/-1) src/gripgesturemanager.c (+192/-107) |
To merge this branch: | bzr merge lp:~jpakkane/libgrip/type_separation |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chase Douglas (community) | Approve | ||
Review via email: mp+66751@code.launchpad.net |
Commit message
Description of the change
This branch finalises the work for subscribing to events based on device type.
To post a comment you must log in.
- 58. By Jussi Pakkanen
-
Update Geis dependency info.
- 59. By Jussi Pakkanen
-
Drop libgrip element from pkg-config file.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'configure.ac' |
2 | --- configure.ac 2011-06-14 17:20:34 +0000 |
3 | +++ configure.ac 2011-07-08 08:28:31 +0000 |
4 | @@ -75,7 +75,7 @@ |
5 | AC_SUBST(GTK_CFLAGS) |
6 | AC_SUBST(GTK_LIBS) |
7 | |
8 | -PKG_CHECK_MODULES(GEIS, libutouch-geis >= 0.3) |
9 | +PKG_CHECK_MODULES(GEIS, libutouch-geis >= 2.1.1) |
10 | AC_SUBST(GEIS_CFLAGS) |
11 | AC_SUBST(GEIS_LIBS) |
12 | |
13 | |
14 | === modified file 'examples/rectangle-mover/gesture.c' |
15 | --- examples/rectangle-mover/gesture.c 2011-06-20 07:31:18 +0000 |
16 | +++ examples/rectangle-mover/gesture.c 2011-07-08 08:28:31 +0000 |
17 | @@ -109,6 +109,9 @@ |
18 | return (GtkTreeModel *)gtk_list_store_new (1, G_TYPE_STRING); |
19 | } |
20 | |
21 | +/* Change this to suit your needs. */ |
22 | +#define DEVICE_TYPE GRIP_DEVICE_ALL |
23 | + |
24 | static void |
25 | subscribe_gestures(GripGestureManager *manager, GtkWidget *window, |
26 | GtkWidget *da) |
27 | @@ -116,7 +119,7 @@ |
28 | grip_gesture_manager_register_window (manager, |
29 | da, |
30 | GRIP_GESTURE_PINCH, |
31 | - GRIP_DEVICE_ALL, |
32 | + DEVICE_TYPE, |
33 | 2, |
34 | gesture_callback, |
35 | NULL, NULL); |
36 | @@ -124,7 +127,7 @@ |
37 | grip_gesture_manager_register_window (manager, |
38 | da, |
39 | GRIP_GESTURE_ROTATE, |
40 | - GRIP_DEVICE_ALL, |
41 | + DEVICE_TYPE, |
42 | 2, |
43 | gesture_callback, |
44 | NULL, NULL); |
45 | @@ -132,7 +135,7 @@ |
46 | grip_gesture_manager_register_window (manager, |
47 | da, |
48 | GRIP_GESTURE_DRAG, |
49 | - GRIP_DEVICE_ALL, |
50 | + DEVICE_TYPE, |
51 | 2, |
52 | gesture_callback, |
53 | NULL, NULL); |
54 | @@ -140,7 +143,7 @@ |
55 | grip_gesture_manager_register_window (manager, |
56 | da, |
57 | GRIP_GESTURE_TAP, |
58 | - GRIP_DEVICE_ALL, |
59 | + DEVICE_TYPE, |
60 | 2, |
61 | gesture_callback, |
62 | NULL, NULL); |
63 | |
64 | === modified file 'libgrip.pc.in' |
65 | --- libgrip.pc.in 2011-06-14 17:39:10 +0000 |
66 | +++ libgrip.pc.in 2011-07-08 08:28:31 +0000 |
67 | @@ -7,5 +7,5 @@ |
68 | Description: Multitouch gesture library |
69 | Version: @VERSION@ |
70 | Libs: -L${libdir} -lgrip |
71 | -Cflags: -I${includedir}/libgrip |
72 | +Cflags: -I${includedir} |
73 | Requires: gtk+-3.0 |
74 | |
75 | === modified file 'src/gripgesturemanager.c' |
76 | --- src/gripgesturemanager.c 2011-06-17 11:37:17 +0000 |
77 | +++ src/gripgesturemanager.c 2011-07-08 08:28:31 +0000 |
78 | @@ -38,6 +38,12 @@ |
79 | GArray *independent; |
80 | } GripDevices; |
81 | |
82 | +struct Registrations { |
83 | + GripGestureRegistration *touchscreen; |
84 | + GripGestureRegistration *touchpad; |
85 | + GripGestureRegistration *independent; |
86 | +}; |
87 | + |
88 | struct _GripGestureManagerPrivate |
89 | { |
90 | GHashTable *registered_windows; |
91 | @@ -146,8 +152,8 @@ |
92 | { |
93 | GripDevices *devices = (GripDevices *) cookie; |
94 | GeisGestureAttr *a; |
95 | - gboolean direct; |
96 | - gboolean independent; |
97 | + gboolean direct = FALSE; |
98 | + gboolean independent = FALSE; |
99 | |
100 | for (a = attrs; a->name; a++) |
101 | { |
102 | @@ -225,6 +231,9 @@ |
103 | { |
104 | GList *tmp = NULL; |
105 | |
106 | + if (!reg) |
107 | + return; |
108 | + |
109 | geis_unsubscribe (reg->instance, |
110 | (GeisGestureType*)reg->gesture_list->pdata); |
111 | |
112 | @@ -246,8 +255,10 @@ |
113 | gpointer value, |
114 | gpointer user_data) |
115 | { |
116 | - GripGestureRegistration *reg = (GripGestureRegistration *)value; |
117 | - free_registration(reg); |
118 | + struct Registrations *regs = (struct Registrations *)value; |
119 | + free_registration(regs->touchscreen); |
120 | + free_registration(regs->touchpad); |
121 | + free_registration(regs->independent); |
122 | } |
123 | |
124 | static void |
125 | @@ -763,12 +774,8 @@ |
126 | } |
127 | |
128 | static void |
129 | -window_destroyed_cb (GtkWidget *object, |
130 | - gpointer user_data) |
131 | +destroy_registration(GripGestureRegistration *reg) |
132 | { |
133 | - GripGestureManager *manager = (GripGestureManager *)user_data; |
134 | - GripGestureManagerPrivate *priv = manager->priv; |
135 | - GripGestureRegistration *reg = g_hash_table_lookup (priv->registered_windows, object); |
136 | GList *list; |
137 | |
138 | for (list = reg->bindings; list != NULL; list = list->next) |
139 | @@ -786,10 +793,21 @@ |
140 | } |
141 | |
142 | g_list_free (reg->bindings); |
143 | - |
144 | g_io_channel_shutdown (reg->iochannel, TRUE, NULL); |
145 | - |
146 | geis_finish (reg->instance); |
147 | +} |
148 | + |
149 | +static void |
150 | +window_destroyed_cb (GtkWidget *object, |
151 | + gpointer user_data) |
152 | +{ |
153 | + GripGestureManager *manager = (GripGestureManager *)user_data; |
154 | + GripGestureManagerPrivate *priv = manager->priv; |
155 | + struct Registrations *reg = g_hash_table_lookup (priv->registered_windows, object); |
156 | + |
157 | + destroy_registration(reg->touchpad); |
158 | + destroy_registration(reg->touchscreen); |
159 | + destroy_registration(reg->independent); |
160 | |
161 | g_hash_table_remove (priv->registered_windows, object); |
162 | g_free (reg); |
163 | @@ -847,110 +865,107 @@ |
164 | } |
165 | } |
166 | |
167 | +static GripGestureRegistration* new_window_registration(GripGestureManager *manager, |
168 | + GtkWidget *toplevel) |
169 | +{ |
170 | + GripGestureRegistration *reg; |
171 | + GeisInstance instance; |
172 | + GIOChannel *iochannel; |
173 | + gint fd = -1; |
174 | + GeisXcbWinInfo xcb_win_info = { |
175 | + .display_name = NULL, |
176 | + .screenp = NULL, |
177 | + .window_id = GDK_WINDOW_XID (gtk_widget_get_window(toplevel)) |
178 | + }; |
179 | + GeisWinInfo win_info = { |
180 | + GEIS_XCB_FULL_WINDOW, |
181 | + &xcb_win_info |
182 | + }; |
183 | + |
184 | + if (geis_init (&win_info, &instance) != GEIS_STATUS_SUCCESS) |
185 | + { |
186 | + g_warning ("Failed to initialize gesture manager."); |
187 | + return NULL; |
188 | + } |
189 | + |
190 | + if (geis_configuration_supported (instance, |
191 | + GEIS_CONFIG_UNIX_FD) != GEIS_STATUS_SUCCESS) |
192 | + { |
193 | + g_warning ("Gesture manager does not support UNIX fd."); |
194 | + return NULL; |
195 | + } |
196 | + |
197 | + if (geis_configuration_get_value (instance, |
198 | + GEIS_CONFIG_UNIX_FD, |
199 | + &fd) != GEIS_STATUS_SUCCESS) |
200 | + { |
201 | + g_error ("Gesture manager failed to obtain UNIX fd."); |
202 | + return NULL; |
203 | + } |
204 | + |
205 | + reg = g_new0 (GripGestureRegistration, 1); |
206 | + |
207 | + reg->window = GTK_WINDOW (toplevel); |
208 | + reg->instance = instance; |
209 | + |
210 | + g_signal_connect (toplevel, |
211 | + "destroy", |
212 | + G_CALLBACK (window_destroyed_cb), |
213 | + manager); |
214 | + |
215 | + iochannel = g_io_channel_unix_new (fd); |
216 | + g_io_add_watch (iochannel, |
217 | + G_IO_IN, |
218 | + io_callback, |
219 | + reg); |
220 | + |
221 | + reg->iochannel = iochannel; |
222 | + |
223 | + reg->gesture_list = g_ptr_array_new (); |
224 | + |
225 | + return reg; |
226 | +} |
227 | + |
228 | static void |
229 | -register_internal (GripGestureManager *manager, |
230 | - GtkWidget *widget, |
231 | - GripGestureType gesture_type, |
232 | - GripDeviceType device_type, |
233 | - gint touch_points, |
234 | - GripGestureCallback callback, |
235 | - gpointer user_data, |
236 | - GDestroyNotify destroy) |
237 | +bind_registration(GripGestureManager *manager, |
238 | + GripGestureRegistration *reg, |
239 | + GtkWidget *widget, |
240 | + GripGestureType gesture_type, |
241 | + GripDeviceType device_type, |
242 | + gint touch_points, |
243 | + GripGestureCallback callback, |
244 | + gpointer user_data, |
245 | + GDestroyNotify destroy) |
246 | { |
247 | GripGestureManagerPrivate *priv; |
248 | - GripGestureRegistration *reg; |
249 | GripGestureBinding *binding; |
250 | - GtkWidget *toplevel; |
251 | GArray *devices; |
252 | |
253 | - g_return_if_fail (GRIP_IS_GESTURE_MANAGER (manager)); |
254 | - g_return_if_fail (GTK_IS_WIDGET (widget)); |
255 | - |
256 | - toplevel = gtk_widget_get_toplevel (widget); |
257 | - |
258 | - g_return_if_fail (GTK_IS_WINDOW (toplevel)); |
259 | - |
260 | priv = manager->priv; |
261 | |
262 | - if (!(reg = g_hash_table_lookup (priv->registered_windows, toplevel))) |
263 | - { |
264 | - GeisInstance instance; |
265 | - GIOChannel *iochannel; |
266 | - gint fd = -1; |
267 | - GeisXcbWinInfo xcb_win_info = { |
268 | - .display_name = NULL, |
269 | - .screenp = NULL, |
270 | - .window_id = GDK_WINDOW_XID (gtk_widget_get_window(toplevel)) |
271 | - }; |
272 | - GeisWinInfo win_info = { |
273 | - GEIS_XCB_FULL_WINDOW, |
274 | - &xcb_win_info |
275 | - }; |
276 | - |
277 | - if (geis_init (&win_info, &instance) != GEIS_STATUS_SUCCESS) |
278 | - { |
279 | - g_warning ("Failed to initialize gesture manager."); |
280 | - return; |
281 | - } |
282 | - |
283 | - if (geis_configuration_supported (instance, |
284 | - GEIS_CONFIG_UNIX_FD) != GEIS_STATUS_SUCCESS) |
285 | - { |
286 | - g_warning ("Gesture manager does not support UNIX fd."); |
287 | - return; |
288 | - } |
289 | - |
290 | - if (geis_configuration_get_value (instance, |
291 | - GEIS_CONFIG_UNIX_FD, |
292 | - &fd) != GEIS_STATUS_SUCCESS) |
293 | - { |
294 | - g_error ("Gesture manager failed to obtain UNIX fd."); |
295 | - return; |
296 | - } |
297 | - |
298 | - reg = g_new0 (GripGestureRegistration, 1); |
299 | - |
300 | - reg->window = GTK_WINDOW (toplevel); |
301 | - reg->instance = instance; |
302 | - |
303 | - g_signal_connect (toplevel, |
304 | - "destroy", |
305 | - G_CALLBACK (window_destroyed_cb), |
306 | - manager); |
307 | - |
308 | - iochannel = g_io_channel_unix_new (fd); |
309 | - g_io_add_watch (iochannel, |
310 | - G_IO_IN, |
311 | - io_callback, |
312 | - reg); |
313 | - |
314 | - reg->iochannel = iochannel; |
315 | - |
316 | - reg->gesture_list = g_ptr_array_new (); |
317 | - } |
318 | - else |
319 | - { |
320 | - geis_unsubscribe (reg->instance, |
321 | - (GeisGestureType*)reg->gesture_list->pdata); |
322 | - } |
323 | |
324 | if (reg->gesture_list->len) |
325 | g_ptr_array_remove_index (reg->gesture_list, |
326 | - reg->gesture_list->len - 1); |
327 | - |
328 | - g_ptr_array_add (reg->gesture_list, |
329 | - (gchar *)grip_type_to_geis_type (gesture_type, touch_points)); |
330 | - g_ptr_array_add (reg->gesture_list, |
331 | - NULL); |
332 | + reg->gesture_list->len - 1); |
333 | |
334 | devices = g_array_new (TRUE, FALSE, sizeof(GeisInputDeviceId)); |
335 | grip_devices_for_type(device_type, devices, &priv->devices); |
336 | + if (devices->len == 0) { |
337 | + g_array_free(devices, TRUE); |
338 | + return; |
339 | + } |
340 | + |
341 | + g_ptr_array_add (reg->gesture_list, |
342 | + (gchar *)grip_type_to_geis_type (gesture_type, touch_points)); |
343 | + g_ptr_array_add (reg->gesture_list, |
344 | + NULL); |
345 | + |
346 | |
347 | geis_subscribe (reg->instance, |
348 | - (GeisInputDeviceId *)devices->data, |
349 | - (const char**)reg->gesture_list->pdata, |
350 | - &gesture_funcs, |
351 | - reg); |
352 | + (GeisInputDeviceId *)devices->data, |
353 | + (const char**)reg->gesture_list->pdata, |
354 | + &gesture_funcs, |
355 | + reg); |
356 | |
357 | g_array_unref (devices); |
358 | |
359 | @@ -966,9 +981,69 @@ |
360 | |
361 | reg->bindings = g_list_append (reg->bindings, binding); |
362 | |
363 | +} |
364 | + |
365 | +static void |
366 | +register_internal (GripGestureManager *manager, |
367 | + GtkWidget *widget, |
368 | + GripGestureType gesture_type, |
369 | + GripDeviceType device_type, |
370 | + gint touch_points, |
371 | + GripGestureCallback callback, |
372 | + gpointer user_data, |
373 | + GDestroyNotify destroy) |
374 | +{ |
375 | + GripGestureManagerPrivate *priv; |
376 | + GtkWidget *toplevel; |
377 | + struct Registrations *registrations; |
378 | + |
379 | + g_return_if_fail (GRIP_IS_GESTURE_MANAGER (manager)); |
380 | + g_return_if_fail (GTK_IS_WIDGET (widget)); |
381 | + |
382 | + toplevel = gtk_widget_get_toplevel (widget); |
383 | + |
384 | + g_return_if_fail (GTK_IS_WINDOW (toplevel)); |
385 | + |
386 | + priv = manager->priv; |
387 | + |
388 | + if (!(registrations = g_hash_table_lookup (priv->registered_windows, toplevel))) |
389 | + { |
390 | + registrations = g_new(struct Registrations, 1); |
391 | + registrations->touchscreen = new_window_registration(manager, toplevel); |
392 | + registrations->touchpad = new_window_registration(manager, toplevel); |
393 | + registrations->independent = new_window_registration(manager, toplevel); |
394 | + |
395 | + if (registrations->touchscreen == NULL || |
396 | + registrations->touchpad == NULL || |
397 | + registrations->independent == NULL) |
398 | + return; |
399 | + } |
400 | + else |
401 | + { |
402 | + geis_unsubscribe (registrations->touchscreen->instance, |
403 | + (GeisGestureType*)registrations->touchscreen->gesture_list->pdata); |
404 | + geis_unsubscribe (registrations->touchpad->instance, |
405 | + (GeisGestureType*)registrations->touchpad->gesture_list->pdata); |
406 | + geis_unsubscribe (registrations->independent->instance, |
407 | + (GeisGestureType*)registrations->independent->gesture_list->pdata); |
408 | + } |
409 | + |
410 | + if (device_type & GRIP_DEVICE_TOUCHSCREEN) |
411 | + bind_registration(manager, |
412 | + registrations->touchscreen, widget, gesture_type, GRIP_DEVICE_TOUCHSCREEN, touch_points, |
413 | + callback, user_data, destroy); |
414 | + |
415 | + if (device_type & GRIP_DEVICE_TOUCHPAD) |
416 | + bind_registration(manager, |
417 | + registrations->touchpad, widget, gesture_type, GRIP_DEVICE_TOUCHPAD, touch_points, |
418 | + callback, user_data, destroy); |
419 | + if (device_type & GRIP_DEVICE_INDEPENDENT) |
420 | + bind_registration(manager, |
421 | + registrations->independent, widget, gesture_type, GRIP_DEVICE_INDEPENDENT, touch_points, |
422 | + callback, user_data, destroy); |
423 | g_hash_table_insert (priv->registered_windows, |
424 | toplevel, |
425 | - reg); |
426 | + registrations); |
427 | } |
428 | |
429 | static void |
430 | @@ -1185,26 +1260,36 @@ |
431 | } |
432 | } |
433 | |
434 | +static void |
435 | +shutdown_registration(GripGestureRegistration *reg) |
436 | +{ |
437 | + free_registration(reg); |
438 | + geis_finish(reg->instance); |
439 | + reg->instance = NULL; |
440 | + g_free(reg); |
441 | +} |
442 | + |
443 | void |
444 | grip_gesture_manager_unregister_window (GripGestureManager *manager, |
445 | GtkWidget *toplevel) |
446 | { |
447 | GripGestureManagerPrivate *priv = manager->priv; |
448 | - GripGestureRegistration *reg; |
449 | + struct Registrations *registrations; |
450 | |
451 | g_return_if_fail (GRIP_IS_GESTURE_MANAGER (manager)); |
452 | g_return_if_fail (GTK_IS_WINDOW (toplevel)); |
453 | |
454 | /* Currently only allow unsubscribing after the window has been shown. */ |
455 | g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (toplevel))); |
456 | - reg = g_hash_table_lookup (priv->registered_windows, toplevel); |
457 | - if (!reg) { |
458 | + registrations = g_hash_table_lookup (priv->registered_windows, toplevel); |
459 | + if (!registrations) { |
460 | return; |
461 | } |
462 | - free_registration(reg); |
463 | - geis_finish(reg->instance); |
464 | - reg->instance = NULL; |
465 | - g_free(reg); |
466 | + |
467 | + shutdown_registration(registrations->touchscreen); |
468 | + shutdown_registration(registrations->touchpad); |
469 | + shutdown_registration(registrations->independent); |
470 | + g_free(registrations); |
471 | g_hash_table_remove(priv->registered_windows, toplevel); |
472 | |
473 | } |
At a high level everything looks good! I tested it out with a few tweaks to eog to test, and the results were good.
Lets merge this in and release!