Merge lp:~gustavold/ginn/ginn.gustavo into lp:ginn

Proposed by Gustavo Luiz Duarte
Status: Merged
Merged at revision: 51
Proposed branch: lp:~gustavold/ginn/ginn.gustavo
Merge into: lp:ginn
Diff against target: 213 lines (+69/-24)
4 files modified
etc/wishes.xml (+16/-16)
src/config.c (+25/-0)
src/config.h (+9/-0)
src/ginn.c (+19/-8)
To merge this branch: bzr merge lp:~gustavold/ginn/ginn.gustavo
Reviewer Review Type Date Requested Status
Mohamed IKBEL Boulabiar (community) Approve
Review via email: mp+39339@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Mohamed IKBEL Boulabiar (boulabiar) wrote :

Thanks Gustavo !

review: Approve
lp:~gustavold/ginn/ginn.gustavo updated
51. By Mohamed IKBEL Boulabiar

Add some gestures wishes.
Merge Gustavo modifications and bugfixes:
  Gustavo Luiz Duarte 2010-10-26 Support for accumulated gesture values and state aware action configuration
    Gustavo Luiz Duarte 2010-10-26 Bugfix: Ginn was discarding the last configured trigger when there was more than one

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'etc/wishes.xml'
2--- etc/wishes.xml 2010-10-22 14:23:47 +0000
3+++ etc/wishes.xml 2010-10-26 05:24:47 +0000
4@@ -1,53 +1,53 @@
5 <ginn>
6 <global>
7 <wish gesture="Tap" fingers="4">
8- <action name="action1">
9+ <action name="action1" when="update">
10 <trigger prop="tap time" min="20" max="400"/>
11 <key modifier1="Super_L">E</key>
12 </action>
13 </wish>
14 <wish gesture="Pinch" fingers="2">
15- <action name="action1">
16+ <action name="action1" when="update">
17 <trigger prop="radius delta" min="20" max="200"/>
18 <trigger prop="radial velocity" min="-1" max="1000"/>
19 <key>KP_Add</key>
20 </action>
21 </wish>
22 <wish gesture="Pinch" fingers="2">
23- <action name="action2">
24+ <action name="action2" when="update">
25 <trigger prop="radius delta" min="-200" max="-20"/>
26 <key>KP_Subtract</key>
27 </action>
28 </wish>
29 <wish gesture="Drag" fingers="4">
30- <action name="action3">
31- <trigger prop="delta x" min="40" max="60"/>
32+ <action name="action3" when="finish">
33+ <trigger prop="delta x" min="40" max="600"/>
34 <key modifier1="Control_L" modifier2="Alt_L">Right</key>
35 </action>
36 </wish>
37 <wish gesture="Drag" fingers="4">
38- <action name="action4">
39- <trigger prop="delta x" min="-60" max="-40"/>
40+ <action name="action4" when="finish">
41+ <trigger prop="delta x" min="-600" max="-40"/>
42 <key modifier1="Control_L" modifier2="Alt_L">Left</key>
43 </action>
44 </wish>
45 <wish gesture="Drag" fingers="2">
46- <action name="action5">
47- <trigger prop="delta y" min="40" max="80"/>
48+ <action name="action5" when="update">
49+ <trigger prop="delta y" min="20" max="80"/>
50+ <key>Down</key>
51+ </action>
52+ </wish>
53+ <wish gesture="Drag" fingers="2">
54+ <action name="action6" when="update">
55+ <trigger prop="delta y" min="-80" max="-20"/>
56 <key>Up</key>
57 </action>
58 </wish>
59- <wish gesture="Drag" fingers="2">
60- <action name="action6">
61- <trigger prop="delta y" min="-80" max="-40"/>
62- <key>Down</key>
63- </action>
64- </wish>
65 </global>
66 <applications>
67 <application name="Inkscape">
68 <wish gesture="Pinch" fingers="3">
69- <action name="action2">
70+ <action name="action2" when="update">
71 <trigger prop="radius delta" min="30" max="1000"/>
72 <key>KP_Subtract</key>
73 </action>
74
75=== modified file 'src/config.c'
76--- src/config.c 2010-10-22 08:37:17 +0000
77+++ src/config.c 2010-10-26 05:24:47 +0000
78@@ -51,6 +51,23 @@
79 }
80 }
81
82+static int ginn_str2state(const char *str){
83+ if (str == NULL) return -1;
84+ if (strcmp(str, "start") == 0) return GINN_START;
85+ if (strcmp(str, "update") == 0) return GINN_UPDATE;
86+ if (strcmp(str, "finish") == 0) return GINN_FINISH;
87+ fprintf(stderr, "ERROR: Undefined state: %s\n", str);
88+ return -2;
89+}
90+
91+static int ginn_str2bool(const char *str){
92+ if (str == NULL) return -1;
93+ if (strcmp(str, "true") == 0) return 1;
94+ if (strcmp(str, "false") == 0) return 0;
95+ fprintf(stderr, "ERROR: Ivalid value for boolean attribute: %s\n", str);
96+ return -2;
97+}
98+
99 void parse_node(const xmlNode *root, int depth, struct wish *wp)
100 {
101 xmlNode *node, *tnode;
102@@ -76,10 +93,18 @@
103 wp->config_attr[1].val = atoi(xmlGetProp(node, "fingers"));
104 wp->config_attr[1].valMax = atoi(xmlGetProp(node, "fingers"));
105 }
106+ if (0==strcmp(node->name, "action")) {
107+ wp->when = ginn_str2state(xmlGetProp(node, "when"));
108+ if (wp->when < 0)
109+ fprintf(stderr, "ERROR: you must provide property 'when' to the action: %s\n", xmlGetProp(node, "name"));
110+ }
111 while (0==strcmp(node->name, "trigger")) {
112 wp->config_attr[position].attrName = xmlGetProp(node, "prop");
113 wp->config_attr[position].val = atoi(xmlGetProp(node, "min"));
114 wp->config_attr[position].valMax = atoi(xmlGetProp(node, "max"));
115+ int acc = ginn_str2bool(xmlGetProp(node, "accumulate"));
116+ wp->config_attr[position].accumulate = acc == -1 ? GINN_DEFAULT_ACCUMULATE : acc;
117+ wp->config_attr[position].accumVal = 0;
118 position++;
119 if (node->next)
120 node = (node->next);
121
122=== modified file 'src/config.h'
123--- src/config.h 2010-10-22 08:37:17 +0000
124+++ src/config.h 2010-10-26 05:24:47 +0000
125@@ -1,6 +1,12 @@
126 #include <libxml/tree.h>
127 #include <string.h>
128
129+#define GINN_START 0
130+#define GINN_UPDATE 1
131+#define GINN_FINISH 2
132+
133+#define GINN_DEFAULT_ACCUMULATE 1
134+
135 typedef struct ginn_config {
136 xmlDocPtr doc;
137 xmlNodePtr root;
138@@ -10,6 +16,8 @@
139 char * attrName ;
140 int val ;
141 int valMax;
142+ int accumulate;
143+ int accumVal;
144 } att;
145
146 typedef struct wish {
147@@ -17,4 +25,5 @@
148 char * key;
149 char * modifiers[4];
150 struct wish* next;
151+ int when;
152 } wish;
153
154=== modified file 'src/ginn.c'
155--- src/ginn.c 2010-10-22 14:23:47 +0000
156+++ src/ginn.c 2010-10-26 05:24:47 +0000
157@@ -32,10 +32,6 @@
158 #include <X11/Xlib.h>
159 #include <X11/keysym.h>
160
161-#define GINN_START 0
162-#define GINN_UPDATE 1
163-#define GINN_FINISH 2
164-
165 att config_attr[25] = { [0 ... 24] = {.attrName="", .val=0, .valMax=0 } };
166
167 wish w1 = { .config_attr = { [0 ... 24] = {.attrName="", .val=0, .valMax=0 } },
168@@ -62,6 +58,14 @@
169 }
170 }
171
172+static void clear_accum_attrs(att *attrs){
173+ int i = 0;
174+ while (strcmp(attrs[i].attrName, "") != 0){
175+ if (attrs[i].accumulate) attrs[i].accumVal = 0;
176+ i++;
177+ }
178+}
179+
180 static void
181 gesture_match( GeisGestureType gesture_type,
182 GeisGestureId gesture_id,
183@@ -85,13 +89,20 @@
184 printf("DEBUG -- comparing %s %s : ", attrs[attrsI].name, wp->config_attr[cAttrI].attrName);
185 printf("%d %d %d \n", (int)attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax);
186 printf("%i \n", inside((int)attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax));
187- valid = valid && inside((int)attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax);
188+ if (wp->config_attr[cAttrI].accumulate){
189+ wp->config_attr[cAttrI].accumVal += (int)attrs[attrsI].float_val;
190+ valid = valid && inside(wp->config_attr[cAttrI].accumVal, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax);
191+ }
192+ else valid = valid && inside((int)attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax);
193 attrsI++; cAttrI++;
194 } else attrsI++;
195- } while ( (0!=strcmp(wp->config_attr[cAttrI+1].attrName,"")) && attrsI<18 && valid );
196- if (valid)
197+ } while ( (0!=strcmp(wp->config_attr[cAttrI].attrName,"")) && attrsI<18 );
198+ if (valid && wp->when == state){
199 injKey(XStringToKeysym(wp->key), wp->modifiers);
200+ clear_accum_attrs(wp->config_attr);
201+ }
202 }
203+ if (state == GINN_FINISH) clear_accum_attrs(wp->config_attr);
204 wp=wp->next;
205 }
206 wp=topw;
207@@ -206,7 +217,7 @@
208 fprintf(stdout, "Gesture type %d finished\n", gesture_type);
209 for (i = 0; i < attr_count; ++i)
210 print_attr(&attrs[i]);
211- //gesture_match(gesture_type, gesture_id, attr_count, attrs, GINN_FINISH);
212+ gesture_match(gesture_type, gesture_id, attr_count, attrs, GINN_FINISH);
213 }
214
215