Merge lp:~oif-team/ginn/subscribe-necessary into lp:ginn

Proposed by Chase Douglas
Status: Merged
Merged at revision: 89
Proposed branch: lp:~oif-team/ginn/subscribe-necessary
Merge into: lp:ginn
Diff against target: 158 lines (+131/-10)
1 file modified
src/ginn.c (+131/-10)
To merge this branch: bzr merge lp:~oif-team/ginn/subscribe-necessary
Reviewer Review Type Date Requested Status
Chase Douglas (community) Needs Fixing
Josh Fee (community) Approve
Review via email: mp+71268@code.launchpad.net

Description of the change

Patch from Josh Fee to subscribe only to gestures that are requested in the wishes file.

To post a comment you must log in.
Revision history for this message
Josh Fee (joshfee) :
review: Approve
Revision history for this message
Chase Douglas (chasedouglas) wrote :

First, thanks Josh for the patch! The major change here is good, there's just a small list of things that need to be cleaned up:

* The comment at the top is great! Please remove the "Edits made by joshfee Aug 7 2011" line. When we merge the branch back to the tree I'll make sure to list you as the author of the commit.

* Please use 4 spaces for indentation so it fits with the rest of the source code.

* There's a multi-line comment that uses "///" at the beginning of each line. I would prefer if it had the same multi-line comment format as your comment at the top. Also, use "//" instead of "///" for single line comments.

* Please put the "int finished = 0" declaration with the other variable declarations at the top of the scope before the comments.

* Use plain printf(...) instead of fprintf(stdout, ...)

* Normally we want people to use the macros for gesture subscription, like GESTURE_TYPE_DRAG_1. However, that would cause an explosion of switch statements in the code if we enforced that here. I am ok with letting this slide.

Again, great code! Thanks for submitting it!

review: Needs Fixing
Revision history for this message
Josh Fee (joshfee) wrote :

The fprintf(...) statement is only there for debugging. Should this be left alone, or should I remove/comment it?

90. By Josh Fee

Fixed comments and indentation to adhere to convention.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ginn.c'
2--- src/ginn.c 2011-03-16 16:23:21 +0000
3+++ src/ginn.c 2011-08-12 15:44:34 +0000
4@@ -365,16 +365,6 @@
5 GeisInstance instance;
6 struct ginn_config cfg;
7
8- const char *sub_gestures_list[] = {
9- GEIS_GESTURE_TYPE_DRAG2, GEIS_GESTURE_TYPE_DRAG3,
10- GEIS_GESTURE_TYPE_DRAG4, GEIS_GESTURE_TYPE_DRAG5,
11- GEIS_GESTURE_TYPE_PINCH2, GEIS_GESTURE_TYPE_PINCH3,
12- GEIS_GESTURE_TYPE_PINCH4, GEIS_GESTURE_TYPE_PINCH5,
13- GEIS_GESTURE_TYPE_ROTATE2, GEIS_GESTURE_TYPE_ROTATE3,
14- GEIS_GESTURE_TYPE_ROTATE4, GEIS_GESTURE_TYPE_ROTATE5,
15- GEIS_GESTURE_TYPE_TAP2, GEIS_GESTURE_TYPE_TAP3,
16- GEIS_GESTURE_TYPE_TAP4, GEIS_GESTURE_TYPE_TAP5, NULL
17- };
18 {
19 char *config_file_name = NULL;
20 if (argc < 2) {
21@@ -418,6 +408,137 @@
22 config_attr[pos].valMax);
23 pos++;
24 }
25+
26+ /**
27+ * Check the loaded wishes to see which gestures are used
28+ * and add these gestures to a NULL terminated list "sub_gestures_list"
29+ *
30+ * This list is used to subscribe only the necessary gestures
31+ * to GEIS. This will avoid issues with 2 finger scrolls and other gestues
32+ * being dropped when not accounted for in the wishes file.
33+ **/
34+
35+ apps * appPtr = ap;
36+ wish * wishPtr;
37+ char * sub_gestures_list[17] = {NULL};
38+ int finished = 0;
39+
40+ /**
41+ * Loop through each wish inside ap
42+ * After all of the wishes in ap are accounted for
43+ * add global wishes
44+ **/
45+
46+ while(finished != 1)
47+ {
48+ // Check if we are finished with the application wishes
49+ if(appPtr == NULL)
50+ {
51+ wishPtr = wp;
52+ finished = 1;
53+ }else{
54+ wishPtr = appPtr->wp;
55+ }
56+
57+ // Loop through each wish
58+ while(wishPtr)
59+ {
60+ int i;
61+ for(i = 0; i < 25; i ++)
62+ {
63+
64+ char *sub_gesture = malloc(sizeof(char[16]));
65+ int pos = 0;
66+
67+ // Check for Drag gesture
68+ if(strcmp(wishPtr->config_attr[i].attrName, "delta x") == 0 ||
69+ strcmp(wishPtr->config_attr[i].attrName, "delta y") == 0 ||
70+ strcmp(wishPtr->config_attr[i].attrName, "velocity x") == 0 ||
71+ strcmp(wishPtr->config_attr[i].attrName, "velocity y") == 0
72+ )
73+ {
74+ sprintf(sub_gesture, "Drag,touch=%i", (int)wishPtr->config_attr[1].val);
75+ }
76+
77+ // Check for Rotate gesture
78+ else if(strcmp(wishPtr->config_attr[i].attrName, "angle delta") == 0 ||
79+ strcmp(wishPtr->config_attr[i].attrName, "angular velocity") == 0 ||
80+ strcmp(wishPtr->config_attr[i].attrName, "angle") == 0
81+ )
82+ {
83+ sprintf(sub_gesture, "Rotate,touch=%i", (int)wishPtr->config_attr[1].val);
84+ }
85+
86+ // Check for Pinch gesture
87+ else if(strcmp(wishPtr->config_attr[i].attrName, "radius delta") == 0 ||
88+ strcmp(wishPtr->config_attr[i].attrName, "radial velocity") == 0 ||
89+ strcmp(wishPtr->config_attr[i].attrName, "radius") == 0
90+ )
91+ {
92+ sprintf(sub_gesture, "Pinch,touch=%i", (int)wishPtr->config_attr[1].val);
93+ }
94+
95+ // Check for Tap gesture
96+ else if(strcmp(wishPtr->config_attr[i].attrName, "tap time") == 0)
97+ {
98+ sprintf(sub_gesture, "Tap,touch=%i", (int)wishPtr->config_attr[1].val);
99+ }
100+
101+ // Deallocate sub_gesture if no gesture was found
102+ else
103+ {
104+ free(sub_gesture);
105+ sub_gesture = NULL;
106+ continue;
107+ }
108+
109+ /** Check the current gesture list
110+ * Only add if the gesture is not already in the list
111+ * Store in index of the first NULL found
112+ **/
113+
114+ while(pos < 17)
115+ {
116+ if(sub_gestures_list[pos] == NULL)
117+ {
118+ sub_gestures_list[pos] = sub_gesture;
119+ break;
120+ }else if(strcmp(sub_gestures_list[pos], sub_gesture) == 0)
121+ {
122+ break;
123+ }
124+ pos ++;
125+ }
126+
127+
128+ }
129+ // Iterate to the next wish
130+ wishPtr = wishPtr->next;
131+ }
132+
133+ // If there are more applications, iterate to the next
134+
135+ if(finished != 1)
136+ {
137+ appPtr = appPtr->next;
138+ }
139+ }
140+
141+ // Show which gestures were subscribed
142+ printf("Gestures subscribed:\n");
143+
144+ pos = 0;
145+ while(pos < 17)
146+ {
147+ if(sub_gestures_list[pos] != NULL)
148+ {
149+ printf("%s\n", sub_gestures_list[pos]);
150+ }
151+
152+ pos ++;
153+ }
154+
155+ // End sub gesture list creation
156
157 status = geis_init(&win_info, &instance);
158 if (status != GEIS_STATUS_SUCCESS) {