Merge lp:~jpakkane/libgrip/deduplicate into lp:libgrip

Proposed by Jussi Pakkanen
Status: Merged
Merged at revision: 42
Proposed branch: lp:~jpakkane/libgrip/deduplicate
Merge into: lp:libgrip
Diff against target: 488 lines (+124/-333)
1 file modified
src/gripgesturemanager.c (+124/-333)
To merge this branch: bzr merge lp:~jpakkane/libgrip/deduplicate
Reviewer Review Type Date Requested Status
Chase Douglas (community) Approve
Review via email: mp+64676@code.launchpad.net

Description of the change

Gesture_start, gesture_update and gesture_end are identical except for one parameter. This branch deduplicates these into one common function.

To post a comment you must log in.
Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Whoops, theres an extra thingy there. I'll push a fixed version.

lp:~jpakkane/libgrip/deduplicate updated
42. By Jussi Pakkanen

Removed useless duplication with a common function.

43. By Jussi Pakkanen

Put braces according to coding standards.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Fixed.

Revision history for this message
Chase Douglas (chasedouglas) wrote :

/me loves code simplification :).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/gripgesturemanager.c'
2--- src/gripgesturemanager.c 2011-05-19 11:11:35 +0000
3+++ src/gripgesturemanager.c 2011-06-15 12:53:25 +0000
4@@ -489,6 +489,127 @@
5 return (x >= ax && x < ax + alloc.width && y >= ay && y < ay + alloc.height);
6 }
7
8+
9+static void process_gesture (void *cookie,
10+ GeisGestureType type,
11+ GeisGestureId id,
12+ GeisSize attr_count,
13+ GeisGestureAttr *attrs,
14+ GripTimeType time_type)
15+{
16+ GripGestureRegistration *reg = (GripGestureRegistration *)cookie;
17+ GList *l = NULL;
18+
19+ for (l = reg->bindings; l != NULL; l = l->next)
20+ {
21+ GripGestureBinding *binding = (GripGestureBinding *)l->data;
22+
23+ if (binding->type == type)
24+ {
25+ GripGestureEvent *event = grip_gesture_event_new (type);
26+
27+ if (type == GRIP_GESTURE_DRAG)
28+ {
29+ GripEventGestureDrag *drag = (GripEventGestureDrag *)event;
30+
31+ drag->type = type;
32+ drag->id = id;
33+ drag->fingers = drag_gesture_handle_properties (drag,
34+ attr_count,
35+ attrs);
36+
37+ if (drag->fingers == binding->touches)
38+ {
39+ if (matches_widget (binding->widget,
40+ gtk_widget_get_window(GTK_WIDGET (reg->window)),
41+ (gint)drag->focus_x,
42+ (gint)drag->focus_y))
43+ {
44+ binding->callback (binding->widget,
45+ time_type,
46+ event,
47+ binding->data);
48+ }
49+ }
50+ }
51+ else if (type == GRIP_GESTURE_PINCH)
52+ {
53+ GripEventGesturePinch *pinch = (GripEventGesturePinch *)event;
54+
55+ pinch->type = type;
56+ pinch->id = id;
57+ pinch->fingers = pinch_gesture_handle_properties (pinch,
58+ attr_count,
59+ attrs);
60+
61+ if (pinch->fingers == binding->touches)
62+ {
63+ if (matches_widget (binding->widget,
64+ gtk_widget_get_window(GTK_WIDGET(reg->window)),
65+ (gint)pinch->focus_x,
66+ (gint)pinch->focus_y))
67+ {
68+ binding->callback (binding->widget,
69+ time_type,
70+ event,
71+ binding->data);
72+ }
73+ }
74+ }
75+ else if (type == GRIP_GESTURE_ROTATE)
76+ {
77+ GripEventGestureRotate *rotate = (GripEventGestureRotate *)event;
78+
79+ rotate->type = type;
80+ rotate->id = id;
81+ rotate->fingers = rotate_gesture_handle_properties (rotate,
82+ attr_count,
83+ attrs);
84+
85+ if (rotate->fingers == binding->touches)
86+ {
87+ if (matches_widget (binding->widget,
88+ gtk_widget_get_window(GTK_WIDGET (reg->window)),
89+ (gint)rotate->focus_x,
90+ (gint)rotate->focus_y))
91+ {
92+ binding->callback (binding->widget,
93+ time_type,
94+ event,
95+ binding->data);
96+ }
97+ }
98+ }
99+ else if (type == GRIP_GESTURE_TAP)
100+ {
101+ GripEventGestureTap *tap = (GripEventGestureTap *)event;
102+
103+ tap->type = type;
104+ tap->id = id;
105+ tap->fingers = tap_gesture_handle_properties (tap,
106+ attr_count,
107+ attrs);
108+
109+ if (tap->fingers == binding->touches)
110+ {
111+ if (matches_widget (binding->widget,
112+ gtk_widget_get_window(GTK_WIDGET (reg->window)),
113+ (gint)tap->focus_x,
114+ (gint)tap->focus_y))
115+ {
116+ binding->callback (binding->widget,
117+ time_type,
118+ event,
119+ binding->data);
120+ }
121+ }
122+ }
123+
124+ grip_gesture_event_free (event);
125+ }
126+ }
127+}
128+
129 static void
130 gesture_start (void *cookie,
131 GeisGestureType type,
132@@ -496,117 +617,7 @@
133 GeisSize attr_count,
134 GeisGestureAttr *attrs)
135 {
136- GripGestureRegistration *reg = (GripGestureRegistration *)cookie;
137- GList *l = NULL;
138-
139- for (l = reg->bindings; l != NULL; l = l->next)
140- {
141- GripGestureBinding *binding = (GripGestureBinding *)l->data;
142-
143- if (binding->type == type)
144- {
145- GripGestureEvent *event = grip_gesture_event_new (type);
146-
147- if (type == GRIP_GESTURE_DRAG)
148- {
149- GripEventGestureDrag *drag = (GripEventGestureDrag *)event;
150-
151- drag->type = type;
152- drag->id = id;
153- drag->fingers = drag_gesture_handle_properties (drag,
154- attr_count,
155- attrs);
156-
157- if (drag->fingers == binding->touches)
158- {
159- if (matches_widget (binding->widget,
160- gtk_widget_get_window(GTK_WIDGET (reg->window)),
161- (gint)drag->focus_x,
162- (gint)drag->focus_y))
163- {
164- binding->callback (binding->widget,
165- GRIP_TIME_START,
166- event,
167- binding->data);
168- }
169- }
170- }
171- else if (type == GRIP_GESTURE_PINCH)
172- {
173- GripEventGesturePinch *pinch = (GripEventGesturePinch *)event;
174-
175- pinch->type = type;
176- pinch->id = id;
177- pinch->fingers = pinch_gesture_handle_properties (pinch,
178- attr_count,
179- attrs);
180-
181- if (pinch->fingers == binding->touches)
182- {
183- if (matches_widget (binding->widget,
184- gtk_widget_get_window(GTK_WIDGET(reg->window)),
185- (gint)pinch->focus_x,
186- (gint)pinch->focus_y))
187- {
188- binding->callback (binding->widget,
189- GRIP_TIME_START,
190- event,
191- binding->data);
192- }
193- }
194- }
195- else if (type == GRIP_GESTURE_ROTATE)
196- {
197- GripEventGestureRotate *rotate = (GripEventGestureRotate *)event;
198-
199- rotate->type = type;
200- rotate->id = id;
201- rotate->fingers = rotate_gesture_handle_properties (rotate,
202- attr_count,
203- attrs);
204-
205- if (rotate->fingers == binding->touches)
206- {
207- if (matches_widget (binding->widget,
208- gtk_widget_get_window(GTK_WIDGET (reg->window)),
209- (gint)rotate->focus_x,
210- (gint)rotate->focus_y))
211- {
212- binding->callback (binding->widget,
213- GRIP_TIME_START,
214- event,
215- binding->data);
216- }
217- }
218- }
219- else if (type == GRIP_GESTURE_TAP)
220- {
221- GripEventGestureTap *tap = (GripEventGestureTap *)event;
222-
223- tap->type = type;
224- tap->id = id;
225- tap->fingers = tap_gesture_handle_properties (tap,
226- attr_count,
227- attrs);
228-
229- if (tap->fingers == binding->touches)
230- {
231- if (matches_widget (binding->widget,
232- gtk_widget_get_window(GTK_WIDGET (reg->window)),
233- (gint)tap->focus_x,
234- (gint)tap->focus_y))
235- {
236- binding->callback (binding->widget,
237- GRIP_TIME_START,
238- event,
239- binding->data);
240- }
241- }
242- }
243-
244- grip_gesture_event_free (event);
245- }
246- }
247+ process_gesture(cookie, type, id, attr_count, attrs, GRIP_TIME_START);
248 }
249
250 static void
251@@ -616,117 +627,7 @@
252 GeisSize attr_count,
253 GeisGestureAttr *attrs)
254 {
255- GripGestureRegistration *reg = (GripGestureRegistration *)cookie;
256- GList *l = NULL;
257-
258- for (l = reg->bindings; l != NULL; l = l->next)
259- {
260- GripGestureBinding *binding = (GripGestureBinding *)l->data;
261-
262- if (binding->type == type)
263- {
264- GripGestureEvent *event = grip_gesture_event_new (type);
265-
266- if (type == GRIP_GESTURE_DRAG)
267- {
268- GripEventGestureDrag *drag = (GripEventGestureDrag *)event;
269-
270- drag->type = type;
271- drag->id = id;
272- drag->fingers = drag_gesture_handle_properties (drag,
273- attr_count,
274- attrs);
275-
276- if (drag->fingers == binding->touches)
277- {
278- if (matches_widget (binding->widget,
279- gtk_widget_get_window(GTK_WIDGET (reg->window)),
280- (gint)drag->focus_x,
281- (gint)drag->focus_y))
282- {
283- binding->callback (binding->widget,
284- GRIP_TIME_UPDATE,
285- event,
286- binding->data);
287- }
288- }
289- }
290- else if (type == GRIP_GESTURE_PINCH)
291- {
292- GripEventGesturePinch *pinch = (GripEventGesturePinch *)event;
293-
294- pinch->type = type;
295- pinch->id = id;
296- pinch->fingers = pinch_gesture_handle_properties (pinch,
297- attr_count,
298- attrs);
299-
300- if (pinch->fingers == binding->touches)
301- {
302- if (matches_widget (binding->widget,
303- gtk_widget_get_window(GTK_WIDGET (reg->window)),
304- (gint)pinch->focus_x,
305- (gint)pinch->focus_y))
306- {
307- binding->callback (binding->widget,
308- GRIP_TIME_UPDATE,
309- event,
310- binding->data);
311- }
312- }
313- }
314- else if (type == GRIP_GESTURE_ROTATE)
315- {
316- GripEventGestureRotate *rotate = (GripEventGestureRotate *)event;
317-
318- rotate->type = type;
319- rotate->id = id;
320- rotate->fingers = rotate_gesture_handle_properties (rotate,
321- attr_count,
322- attrs);
323-
324- if (rotate->fingers == binding->touches)
325- {
326- if (matches_widget (binding->widget,
327- gtk_widget_get_window(GTK_WIDGET (reg->window)),
328- (gint)rotate->focus_x,
329- (gint)rotate->focus_y))
330- {
331- binding->callback (binding->widget,
332- GRIP_TIME_UPDATE,
333- event,
334- binding->data);
335- }
336- }
337- }
338- else if (type == GRIP_GESTURE_TAP)
339- {
340- GripEventGestureTap *tap = (GripEventGestureTap *)event;
341-
342- tap->type = type;
343- tap->id = id;
344- tap->fingers = tap_gesture_handle_properties (tap,
345- attr_count,
346- attrs);
347-
348- if (tap->fingers == binding->touches)
349- {
350- if (matches_widget (binding->widget,
351- gtk_widget_get_window(GTK_WIDGET (reg->window)),
352- (gint)tap->focus_x,
353- (gint)tap->focus_y))
354- {
355- binding->callback (binding->widget,
356- GRIP_TIME_UPDATE,
357- event,
358- binding->data);
359- }
360- }
361- }
362-
363- grip_gesture_event_free (event);
364- }
365- }
366+ process_gesture(cookie, type, id, attr_count, attrs, GRIP_TIME_UPDATE);
367 }
368
369 static void
370@@ -736,117 +637,7 @@
371 GeisSize attr_count,
372 GeisGestureAttr *attrs)
373 {
374- GripGestureRegistration *reg = (GripGestureRegistration *)cookie;
375- GList *l = NULL;
376-
377- for (l = reg->bindings; l != NULL; l = l->next)
378- {
379- GripGestureBinding *binding = (GripGestureBinding *)l->data;
380-
381- if (binding->type == type)
382- {
383- GripGestureEvent *event = grip_gesture_event_new (type);
384-
385- if (type == GRIP_GESTURE_DRAG)
386- {
387- GripEventGestureDrag *drag = (GripEventGestureDrag *)event;
388-
389- drag->type = type;
390- drag->id = id;
391- drag->fingers = drag_gesture_handle_properties (drag,
392- attr_count,
393- attrs);
394-
395- if (drag->fingers == binding->touches)
396- {
397- if (matches_widget (binding->widget,
398- gtk_widget_get_window(GTK_WIDGET (reg->window)),
399- (gint)drag->focus_x,
400- (gint)drag->focus_y))
401- {
402- binding->callback (binding->widget,
403- GRIP_TIME_END,
404- event,
405- binding->data);
406- }
407- }
408- }
409- else if (type == GRIP_GESTURE_PINCH)
410- {
411- GripEventGesturePinch *pinch = (GripEventGesturePinch *)event;
412-
413- pinch->type = type;
414- pinch->id = id;
415- pinch->fingers = pinch_gesture_handle_properties (pinch,
416- attr_count,
417- attrs);
418-
419- if (pinch->fingers == binding->touches)
420- {
421- if (matches_widget (binding->widget,
422- gtk_widget_get_window(GTK_WIDGET (reg->window)),
423- (gint)pinch->focus_x,
424- (gint)pinch->focus_y))
425- {
426- binding->callback (binding->widget,
427- GRIP_TIME_END,
428- event,
429- binding->data);
430- }
431- }
432- }
433- else if (type == GRIP_GESTURE_ROTATE)
434- {
435- GripEventGestureRotate *rotate = (GripEventGestureRotate *)event;
436-
437- rotate->type = type;
438- rotate->id = id;
439- rotate->fingers = rotate_gesture_handle_properties (rotate,
440- attr_count,
441- attrs);
442-
443- if (rotate->fingers == binding->touches)
444- {
445- if (matches_widget (binding->widget,
446- gtk_widget_get_window(GTK_WIDGET (reg->window)),
447- (gint)rotate->focus_x,
448- (gint)rotate->focus_y))
449- {
450- binding->callback (binding->widget,
451- GRIP_TIME_END,
452- event,
453- binding->data);
454- }
455- }
456- }
457- else if (type == GRIP_GESTURE_TAP)
458- {
459- GripEventGestureTap *tap = (GripEventGestureTap *)event;
460-
461- tap->type = type;
462- tap->id = id;
463- tap->fingers = tap_gesture_handle_properties (tap,
464- attr_count,
465- attrs);
466-
467- if (tap->fingers == binding->touches)
468- {
469- if (matches_widget (binding->widget,
470- gtk_widget_get_window(GTK_WIDGET (reg->window)),
471- (gint)tap->focus_x,
472- (gint)tap->focus_y))
473- {
474- binding->callback (binding->widget,
475- GRIP_TIME_END,
476- event,
477- binding->data);
478- }
479- }
480- }
481-
482- grip_gesture_event_free (event);
483- }
484- }
485+ process_gesture(cookie, type, id, attr_count, attrs, GRIP_TIME_END);
486 }
487
488 static void

Subscribers

People subscribed via source and target branches