Merge lp:~oif-team/ginn/scroll-pointer-fixes into lp:ginn
- scroll-pointer-fixes
- Merge into trunk
Proposed by
Chase Douglas
Status: | Merged |
---|---|
Merged at revision: | 84 |
Proposed branch: | lp:~oif-team/ginn/scroll-pointer-fixes |
Merge into: | lp:ginn |
Diff against target: |
1451 lines (+695/-639) 6 files modified
etc/wishes.xml (+2/-2) src/bamf.c (+27/-30) src/config.c (+162/-137) src/config.h (+17/-17) src/ginn.c (+409/-402) src/xt.c (+78/-51) |
To merge this branch: | bzr merge lp:~oif-team/ginn/scroll-pointer-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mohamed IKBEL Boulabiar (community) | Approve | ||
Review via email: mp+53649@code.launchpad.net |
Commit message
Description of the change
* Use pointer buttons for scrolling
* Reindent source code for uniformity
* Move the cursor to the location of the gesture
You probably will want to review the commits individually due to the reindentation. I can split the merge request up into individual requests if that's preferred.
To post a comment you must log in.
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-12-21 17:56:26 +0000 | |||
3 | +++ etc/wishes.xml 2011-03-16 16:26:15 +0000 | |||
4 | @@ -4,13 +4,13 @@ | |||
5 | 4 | <wish gesture="Drag" fingers="2"> | 4 | <wish gesture="Drag" fingers="2"> |
6 | 5 | <action name="action5" when="update"> | 5 | <action name="action5" when="update"> |
7 | 6 | <trigger prop="delta y" min="20" max="80"/> | 6 | <trigger prop="delta y" min="20" max="80"/> |
9 | 7 | <key>Down</key> | 7 | <button>4</button> |
10 | 8 | </action> | 8 | </action> |
11 | 9 | </wish> | 9 | </wish> |
12 | 10 | <wish gesture="Drag" fingers="2"> | 10 | <wish gesture="Drag" fingers="2"> |
13 | 11 | <action name="action6" when="update"> | 11 | <action name="action6" when="update"> |
14 | 12 | <trigger prop="delta y" min="-80" max="-20"/> | 12 | <trigger prop="delta y" min="-80" max="-20"/> |
16 | 13 | <key>Up</key> | 13 | <button>5</button> |
17 | 14 | </action> | 14 | </action> |
18 | 15 | </wish> | 15 | </wish> |
19 | 16 | 16 | ||
20 | 17 | 17 | ||
21 | === modified file 'src/bamf.c' | |||
22 | --- src/bamf.c 2011-02-03 09:59:19 +0000 | |||
23 | +++ src/bamf.c 2011-03-16 16:26:15 +0000 | |||
24 | @@ -19,33 +19,30 @@ | |||
25 | 19 | #include <libbamf/bamf-matcher.h> | 19 | #include <libbamf/bamf-matcher.h> |
26 | 20 | #include <string.h> | 20 | #include <string.h> |
27 | 21 | 21 | ||
58 | 22 | char * | 22 | char *getName(char *deskfile) |
59 | 23 | getName(char * deskfile) | 23 | { |
60 | 24 | { | 24 | char *temp; |
61 | 25 | char *temp; | 25 | temp = strdup(strrchr(deskfile, '/')); |
62 | 26 | temp = strdup(strrchr(deskfile, '/')); | 26 | return strndup(temp + 1, strlen(temp) - 9); |
63 | 27 | return strndup(temp+1, strlen(temp)-9); | 27 | } |
64 | 28 | } | 28 | |
65 | 29 | 29 | char *getCurrentApp() | |
66 | 30 | char * | 30 | { |
67 | 31 | getCurrentApp() | 31 | g_type_init(); |
68 | 32 | { | 32 | char *deskfile, *appName; |
69 | 33 | g_type_init(); | 33 | char *temp; |
70 | 34 | char *deskfile, *appName; | 34 | |
71 | 35 | char* temp; | 35 | BamfApplication *app = |
72 | 36 | 36 | bamf_matcher_get_active_application(bamf_matcher_get_default()); | |
73 | 37 | BamfApplication * app = bamf_matcher_get_active_application(bamf_matcher_get_default()); | 37 | if (app) { |
74 | 38 | if (app) { | 38 | appName = (char *) bamf_view_get_name(BAMF_VIEW(app)); |
75 | 39 | appName = (char*)bamf_view_get_name(BAMF_VIEW(app)); | 39 | temp = bamf_application_get_desktop_file(app); |
76 | 40 | temp = bamf_application_get_desktop_file(app); | 40 | |
77 | 41 | 41 | if (strchr(appName, ' ') && temp) | |
78 | 42 | if (strchr(appName,' ') && temp) | 42 | return getName((char *) temp); |
79 | 43 | return getName((char*)temp); | 43 | else |
80 | 44 | else | 44 | return appName; |
81 | 45 | return appName; | 45 | } else |
82 | 46 | } | 46 | return ""; |
83 | 47 | else | 47 | |
84 | 48 | return ""; | 48 | } |
55 | 49 | |||
56 | 50 | } | ||
57 | 51 | |||
85 | 52 | 49 | ||
86 | === modified file 'src/config.c' | |||
87 | --- src/config.c 2010-12-02 12:37:14 +0000 | |||
88 | +++ src/config.c 2011-03-16 16:26:15 +0000 | |||
89 | @@ -19,157 +19,182 @@ | |||
90 | 19 | #include "config.h" | 19 | #include "config.h" |
91 | 20 | #include <libxml/parser.h> | 20 | #include <libxml/parser.h> |
92 | 21 | 21 | ||
99 | 22 | void | 22 | void debugOut(struct wish *wp) |
100 | 23 | debugOut(struct wish * wp) { | 23 | { |
101 | 24 | int i; | 24 | int i; |
102 | 25 | printf("\n key : %s ", wp->key); | 25 | printf("\n key : %s ", wp->key); |
103 | 26 | printf("\n button : %d ", wp->button); | 26 | printf("\n button : %d ", wp->button); |
104 | 27 | for(i=0 ; i<4 ; i++) | 27 | for (i = 0; i < 4; i++) |
105 | 28 | printf("\t mod%d : %s ", i, wp->modifiers[i]); | 28 | printf("\t mod%d : %s ", i, wp->modifiers[i]); |
107 | 29 | for(i=0 ; i<4 ; i++ ) { | 29 | for (i = 0; i < 4; i++) { |
108 | 30 | printf("\n attrName : %s ", wp->config_attr[i].attrName); | 30 | printf("\n attrName : %s ", wp->config_attr[i].attrName); |
109 | 31 | printf("\t val : %.2f ", wp->config_attr[i].val); | 31 | printf("\t val : %.2f ", wp->config_attr[i].val); |
110 | 32 | printf("\t valMax : %.2f", wp->config_attr[i].valMax); | 32 | printf("\t valMax : %.2f", wp->config_attr[i].valMax); |
114 | 33 | } | 33 | } |
115 | 34 | printf("\n pMe : %x pNext : %x ", wp, wp->next); | 34 | printf("\n pMe : %x pNext : %x ", wp, wp->next); |
116 | 35 | printf("\n==================================================="); | 35 | printf("\n==================================================="); |
117 | 36 | } | 36 | } |
118 | 37 | 37 | ||
119 | 38 | int ginn_config_open(struct ginn_config *cfg, const char *path) | 38 | int ginn_config_open(struct ginn_config *cfg, const char *path) |
120 | 39 | { | 39 | { |
128 | 40 | memset(cfg, 0, sizeof(*cfg)); | 40 | memset(cfg, 0, sizeof(*cfg)); |
129 | 41 | cfg->doc = xmlReadFile(path, NULL, 0); | 41 | cfg->doc = xmlReadFile(path, NULL, 0); |
130 | 42 | if (cfg->doc == NULL) { | 42 | if (cfg->doc == NULL) { |
131 | 43 | fprintf(stderr, "Failed to parse %s\n", path); | 43 | fprintf(stderr, "Failed to parse %s\n", path); |
132 | 44 | return -1; | 44 | return -1; |
133 | 45 | } | 45 | } |
134 | 46 | return 0; | 46 | return 0; |
135 | 47 | } | 47 | } |
136 | 48 | 48 | ||
137 | 49 | void ginn_config_close(struct ginn_config *cfg) | 49 | void ginn_config_close(struct ginn_config *cfg) |
138 | 50 | { | 50 | { |
256 | 51 | xmlFreeDoc(cfg->doc); | 51 | xmlFreeDoc(cfg->doc); |
257 | 52 | } | 52 | } |
258 | 53 | 53 | ||
259 | 54 | 54 | static void print_node(const xmlNode * root, int depth) | |
260 | 55 | static void print_node(const xmlNode *root, int depth) | 55 | { |
261 | 56 | { | 56 | xmlNode *node; |
262 | 57 | xmlNode *node; | 57 | for (node = root; node; node = node->next) { |
263 | 58 | for (node = root; node; node = node->next) { | 58 | int i; |
264 | 59 | int i; | 59 | if (node->type != XML_ELEMENT_NODE) |
265 | 60 | if (node->type != XML_ELEMENT_NODE) | 60 | continue; |
266 | 61 | continue; | 61 | for (i = 0; i < depth; i++) |
267 | 62 | for (i = 0; i < depth; i++) | 62 | printf(" "); |
268 | 63 | printf(" "); | 63 | printf("%s\n", node->name); |
269 | 64 | printf("%s\n", node->name); | 64 | print_node(node->children, depth + 1); |
270 | 65 | print_node(node->children, depth + 1); | 65 | } |
271 | 66 | } | 66 | } |
272 | 67 | } | 67 | |
273 | 68 | 68 | static int ginn_str2state(const char *str) | |
274 | 69 | static int ginn_str2state(const char *str){ | 69 | { |
275 | 70 | if (str == NULL) return -1; | 70 | if (str == NULL) |
276 | 71 | if (strcmp(str, "start") == 0) return GINN_START; | 71 | return -1; |
277 | 72 | if (strcmp(str, "update") == 0) return GINN_UPDATE; | 72 | if (strcmp(str, "start") == 0) |
278 | 73 | if (strcmp(str, "finish") == 0) return GINN_FINISH; | 73 | return GINN_START; |
279 | 74 | fprintf(stderr, "ERROR: Undefined state: %s\n", str); | 74 | if (strcmp(str, "update") == 0) |
280 | 75 | return -2; | 75 | return GINN_UPDATE; |
281 | 76 | } | 76 | if (strcmp(str, "finish") == 0) |
282 | 77 | 77 | return GINN_FINISH; | |
283 | 78 | static int ginn_str2bool(const char *str){ | 78 | fprintf(stderr, "ERROR: Undefined state: %s\n", str); |
284 | 79 | if (str == NULL) return -1; | 79 | return -2; |
285 | 80 | if (strcmp(str, "true") == 0) return 1; | 80 | } |
286 | 81 | if (strcmp(str, "false") == 0) return 0; | 81 | |
287 | 82 | fprintf(stderr, "ERROR: Invalid value for boolean attribute: %s\n", str); | 82 | static int ginn_str2bool(const char *str) |
288 | 83 | return -2; | 83 | { |
289 | 84 | } | 84 | if (str == NULL) |
290 | 85 | 85 | return -1; | |
291 | 86 | void store_1config(xmlNode *node, struct wish *wp, int *position) | 86 | if (strcmp(str, "true") == 0) |
292 | 87 | { | 87 | return 1; |
293 | 88 | if (0==strcmp(node->name, "wish")) { | 88 | if (strcmp(str, "false") == 0) |
294 | 89 | // printf(" gesture %s fingers %s ",(xmlGetProp(node, "gesture")),(xmlGetProp(node, "fingers"))); | 89 | return 0; |
295 | 90 | wp->config_attr[0].attrName = "gesture name"; | 90 | fprintf(stderr, "ERROR: Invalid value for boolean attribute: %s\n", |
296 | 91 | switch (xmlGetProp(node, "gesture")[0]) { | 91 | str); |
297 | 92 | case 'D': wp->config_attr[0].val=wp->config_attr[0].valMax= 0; break; | 92 | return -2; |
298 | 93 | case 'P': wp->config_attr[0].val=wp->config_attr[0].valMax= 1; break; | 93 | } |
299 | 94 | case 'R': wp->config_attr[0].val=wp->config_attr[0].valMax= 2; break; | 94 | |
300 | 95 | case 'T': wp->config_attr[0].val=wp->config_attr[0].valMax=15; break; | 95 | void store_1config(xmlNode * node, struct wish *wp, int *position) |
301 | 96 | } | 96 | { |
302 | 97 | wp->config_attr[1].attrName = "touches"; | 97 | if (0 == strcmp(node->name, "wish")) { |
303 | 98 | wp->config_attr[1].val = atoi(xmlGetProp(node, "fingers")); | 98 | // printf(" gesture %s fingers %s ",(xmlGetProp(node, "gesture")),(xmlGetProp(node, "fingers"))); |
304 | 99 | wp->config_attr[1].valMax = atoi(xmlGetProp(node, "fingers")); | 99 | wp->config_attr[0].attrName = "gesture name"; |
305 | 100 | } | 100 | switch (xmlGetProp(node, "gesture")[0]) { |
306 | 101 | if (0==strcmp(node->name, "action")) { | 101 | case 'D': |
307 | 102 | wp->when = ginn_str2state(xmlGetProp(node, "when")); | 102 | wp->config_attr[0].val = wp->config_attr[0].valMax = 0; |
308 | 103 | if (wp->when < 0) | 103 | break; |
309 | 104 | fprintf(stderr, "ERROR: you must provide property 'when' to the action: %s\n", xmlGetProp(node, "name")); | 104 | case 'P': |
310 | 105 | } | 105 | wp->config_attr[0].val = wp->config_attr[0].valMax = 1; |
311 | 106 | if (0==strcmp(node->name, "trigger")) { | 106 | break; |
312 | 107 | wp->config_attr[*position].attrName = xmlGetProp(node, "prop"); | 107 | case 'R': |
313 | 108 | wp->config_attr[*position].val = atof(xmlGetProp(node, "min")); | 108 | wp->config_attr[0].val = wp->config_attr[0].valMax = 2; |
314 | 109 | wp->config_attr[*position].valMax = atof(xmlGetProp(node, "max")); | 109 | break; |
315 | 110 | int acc = ginn_str2bool(xmlGetProp(node, "accumulate")); | 110 | case 'T': |
316 | 111 | wp->config_attr[*position].accumulate = acc == -1 ? GINN_DEFAULT_ACCUMULATE : acc; | 111 | wp->config_attr[0].val = wp->config_attr[0].valMax = 15; |
317 | 112 | wp->config_attr[*position].accumVal = 0; | 112 | break; |
318 | 113 | (*position)++; | 113 | } |
319 | 114 | } | 114 | wp->config_attr[1].attrName = "touches"; |
320 | 115 | if (0==strcmp(node->name, "key") || 0==strcmp(node->name, "button")) { | 115 | wp->config_attr[1].val = atoi(xmlGetProp(node, "fingers")); |
321 | 116 | if (xmlGetProp(node, "modifier1")) | 116 | wp->config_attr[1].valMax = atoi(xmlGetProp(node, "fingers")); |
322 | 117 | wp->modifiers[0] = xmlGetProp(node, "modifier1"); | 117 | } |
323 | 118 | if (xmlGetProp(node, "modifier2")) | 118 | if (0 == strcmp(node->name, "action")) { |
324 | 119 | wp->modifiers[1] = xmlGetProp(node, "modifier2"); | 119 | wp->when = ginn_str2state(xmlGetProp(node, "when")); |
325 | 120 | if (xmlGetProp(node, "modifier3")) | 120 | if (wp->when < 0) |
326 | 121 | wp->modifiers[2] = xmlGetProp(node, "modifier3"); | 121 | fprintf(stderr, |
327 | 122 | if (xmlGetProp(node, "modifier4")) | 122 | "ERROR: you must provide property 'when' to the action: %s\n", |
328 | 123 | wp->modifiers[3] = xmlGetProp(node, "modifier4"); | 123 | xmlGetProp(node, "name")); |
329 | 124 | } | 124 | } |
330 | 125 | if (0==strcmp(node->name, "key")) | 125 | if (0 == strcmp(node->name, "trigger")) { |
331 | 126 | wp->key = xmlNodeGetContent(node); | 126 | wp->config_attr[*position].attrName = xmlGetProp(node, "prop"); |
332 | 127 | if (0==strcmp(node->name, "button")) | 127 | wp->config_attr[*position].val = atof(xmlGetProp(node, "min")); |
333 | 128 | wp->button = atoi(xmlNodeGetContent(node)); | 128 | wp->config_attr[*position].valMax = atof(xmlGetProp(node, "max")); |
334 | 129 | if (0==strcmp(node->name, "button")) | 129 | int acc = ginn_str2bool(xmlGetProp(node, "accumulate")); |
335 | 130 | printf("Button : %d ", wp->button); | 130 | wp->config_attr[*position].accumulate = |
336 | 131 | } | 131 | acc == -1 ? GINN_DEFAULT_ACCUMULATE : acc; |
337 | 132 | 132 | wp->config_attr[*position].accumVal = 0; | |
338 | 133 | void parse_node(const xmlNode *root, int depth, struct wish *wp, struct apps *ap) | 133 | (*position)++; |
339 | 134 | { | 134 | } |
340 | 135 | xmlNode *node; | 135 | if (0 == strcmp(node->name, "key") |
341 | 136 | int position=2; | 136 | || 0 == strcmp(node->name, "button")) { |
342 | 137 | for (node = root; node; node = node->next) { | 137 | if (xmlGetProp(node, "modifier1")) |
343 | 138 | if (node->type != XML_ELEMENT_NODE) | 138 | wp->modifiers[0] = xmlGetProp(node, "modifier1"); |
344 | 139 | continue; | 139 | if (xmlGetProp(node, "modifier2")) |
345 | 140 | 140 | wp->modifiers[1] = xmlGetProp(node, "modifier2"); | |
346 | 141 | if ( (0==strcmp(node->name, "application")) ) { | 141 | if (xmlGetProp(node, "modifier3")) |
347 | 142 | if (0!=strcmp(ap->appName, "")) { | 142 | wp->modifiers[2] = xmlGetProp(node, "modifier3"); |
348 | 143 | ap = ap->next = (struct apps *) malloc(sizeof(struct apps)); | 143 | if (xmlGetProp(node, "modifier4")) |
349 | 144 | inita(ap); | 144 | wp->modifiers[3] = xmlGetProp(node, "modifier4"); |
350 | 145 | } | 145 | } |
351 | 146 | ap->appName=xmlGetProp(node, "name"); | 146 | if (0 == strcmp(node->name, "key")) |
352 | 147 | wp = ap->wp = (struct wish *) malloc(sizeof(struct wish)); | 147 | wp->key = xmlNodeGetContent(node); |
353 | 148 | initw(wp); | 148 | if (0 == strcmp(node->name, "button")) |
354 | 149 | } | 149 | wp->button = atoi(xmlNodeGetContent(node)); |
355 | 150 | if ( (0==strcmp(node->name, "wish")) && (0==strcmp(wp->config_attr[0].attrName, "gesture name")) ) { | 150 | if (0 == strcmp(node->name, "button")) |
356 | 151 | if (!(wp->next)) { | 151 | printf("Button : %d ", wp->button); |
357 | 152 | wp->next = (struct wish *) malloc(sizeof(struct wish)); | 152 | } |
358 | 153 | initw(wp->next); | 153 | |
359 | 154 | } | 154 | void |
360 | 155 | wp = wp->next; | 155 | parse_node(const xmlNode * root, int depth, struct wish *wp, |
361 | 156 | position=2; | 156 | struct apps *ap) |
362 | 157 | } | 157 | { |
363 | 158 | store_1config(node, wp, &position); | 158 | xmlNode *node; |
364 | 159 | parse_node(node->children, depth + 1, wp, ap); | 159 | int position = 2; |
365 | 160 | } | 160 | for (node = root; node; node = node->next) { |
366 | 161 | } | 161 | if (node->type != XML_ELEMENT_NODE) |
367 | 162 | 162 | continue; | |
368 | 163 | 163 | ||
369 | 164 | void ginn_config_store(const struct ginn_config *cfg, struct wish *w, struct apps *a) | 164 | if ((0 == strcmp(node->name, "application"))) { |
370 | 165 | { | 165 | if (0 != strcmp(ap->appName, "")) { |
371 | 166 | const xmlNode *root = xmlDocGetRootElement(cfg->doc); | 166 | ap = ap->next = |
372 | 167 | parse_node(root, 0, w, a); | 167 | (struct apps *) malloc(sizeof(struct apps)); |
373 | 168 | inita(ap); | ||
374 | 169 | } | ||
375 | 170 | ap->appName = xmlGetProp(node, "name"); | ||
376 | 171 | wp = ap->wp = (struct wish *) malloc(sizeof(struct wish)); | ||
377 | 172 | initw(wp); | ||
378 | 173 | } | ||
379 | 174 | if ((0 == strcmp(node->name, "wish")) | ||
380 | 175 | && (0 == strcmp(wp->config_attr[0].attrName, "gesture name"))) { | ||
381 | 176 | if (!(wp->next)) { | ||
382 | 177 | wp->next = (struct wish *) malloc(sizeof(struct wish)); | ||
383 | 178 | initw(wp->next); | ||
384 | 179 | } | ||
385 | 180 | wp = wp->next; | ||
386 | 181 | position = 2; | ||
387 | 182 | } | ||
388 | 183 | store_1config(node, wp, &position); | ||
389 | 184 | parse_node(node->children, depth + 1, wp, ap); | ||
390 | 185 | } | ||
391 | 186 | } | ||
392 | 187 | |||
393 | 188 | void | ||
394 | 189 | ginn_config_store(const struct ginn_config *cfg, struct wish *w, | ||
395 | 190 | struct apps *a) | ||
396 | 191 | { | ||
397 | 192 | const xmlNode *root = xmlDocGetRootElement(cfg->doc); | ||
398 | 193 | parse_node(root, 0, w, a); | ||
399 | 168 | } | 194 | } |
400 | 169 | 195 | ||
401 | 170 | void ginn_config_print(const struct ginn_config *cfg) | 196 | void ginn_config_print(const struct ginn_config *cfg) |
402 | 171 | { | 197 | { |
405 | 172 | const xmlNode *root = xmlDocGetRootElement(cfg->doc); | 198 | const xmlNode *root = xmlDocGetRootElement(cfg->doc); |
406 | 173 | print_node(root, 0); | 199 | print_node(root, 0); |
407 | 174 | } | 200 | } |
408 | 175 | |||
409 | 176 | 201 | ||
410 | === modified file 'src/config.h' | |||
411 | --- src/config.h 2011-02-04 13:35:41 +0000 | |||
412 | +++ src/config.h 2011-03-16 16:26:15 +0000 | |||
413 | @@ -28,31 +28,31 @@ | |||
414 | 28 | #define GINN_DEFAULT_ACCUMULATE 1 | 28 | #define GINN_DEFAULT_ACCUMULATE 1 |
415 | 29 | 29 | ||
416 | 30 | typedef struct ginn_config { | 30 | typedef struct ginn_config { |
419 | 31 | xmlDocPtr doc; | 31 | xmlDocPtr doc; |
420 | 32 | xmlNodePtr root; | 32 | xmlNodePtr root; |
421 | 33 | } cfg; | 33 | } cfg; |
422 | 34 | 34 | ||
423 | 35 | typedef struct att { | 35 | typedef struct att { |
429 | 36 | char *attrName ; | 36 | char *attrName; |
430 | 37 | float val ; | 37 | float val; |
431 | 38 | float valMax; | 38 | float valMax; |
432 | 39 | int accumulate; | 39 | int accumulate; |
433 | 40 | float accumVal; | 40 | float accumVal; |
434 | 41 | } att; | 41 | } att; |
435 | 42 | 42 | ||
436 | 43 | typedef struct wish { | 43 | typedef struct wish { |
443 | 44 | att config_attr[25]; | 44 | att config_attr[25]; |
444 | 45 | char *key; | 45 | char *key; |
445 | 46 | int button; | 46 | int button; |
446 | 47 | char *modifiers[4]; | 47 | char *modifiers[4]; |
447 | 48 | struct wish* next; | 48 | struct wish *next; |
448 | 49 | int when; | 49 | int when; |
449 | 50 | } wish; | 50 | } wish; |
450 | 51 | 51 | ||
451 | 52 | typedef struct apps { | 52 | typedef struct apps { |
455 | 53 | char *appName; | 53 | char *appName; |
456 | 54 | struct wish *wp; | 54 | struct wish *wp; |
457 | 55 | struct apps *next; | 55 | struct apps *next; |
458 | 56 | } apps; | 56 | } apps; |
459 | 57 | 57 | ||
461 | 58 | #endif /* GINN_CONFIG_H */ | 58 | #endif /* GINN_CONFIG_H */ |
462 | 59 | 59 | ||
463 | === modified file 'src/ginn.c' | |||
464 | --- src/ginn.c 2011-02-04 16:04:30 +0000 | |||
465 | +++ src/ginn.c 2011-03-16 16:26:15 +0000 | |||
466 | @@ -33,432 +33,439 @@ | |||
467 | 33 | #include <X11/Xlib.h> | 33 | #include <X11/Xlib.h> |
468 | 34 | #include <X11/keysym.h> | 34 | #include <X11/keysym.h> |
469 | 35 | 35 | ||
471 | 36 | att config_attr[25] = { [0 ... 24] = {.attrName="", .val=0, .valMax=0 } }; | 36 | att config_attr[25] = {[0 ... 24] = {.attrName = "",.val = 0,.valMax = 0} |
472 | 37 | }; | ||
473 | 37 | 38 | ||
477 | 38 | wish w1 = { .config_attr = { [0 ... 24] = {.attrName="", .val=0, .valMax=0 } }, | 39 | wish w1 = {.config_attr = {[0 ... 24] = |
478 | 39 | .key ="", | 40 | {.attrName = "",.val = 0,.valMax = 0} |
479 | 40 | .next=NULL }; | 41 | } |
480 | 42 | , | ||
481 | 43 | .key = "", | ||
482 | 44 | .next = NULL | ||
483 | 45 | }; | ||
484 | 41 | 46 | ||
485 | 42 | wish *wp, *wpEnd; | 47 | wish *wp, *wpEnd; |
486 | 43 | apps *ap; | 48 | apps *ap; |
487 | 44 | 49 | ||
593 | 45 | static int | 50 | static int inside(float x, float a, float b) |
594 | 46 | inside (float x, float a, float b){ | 51 | { |
595 | 47 | return ((x<=b) && (x>=a)); | 52 | return ((x <= b) && (x >= a)); |
596 | 48 | } | 53 | } |
597 | 49 | 54 | ||
598 | 50 | void | 55 | void initw(struct wish *wp) |
599 | 51 | initw(struct wish *wp) { | 56 | { |
600 | 52 | int i; | 57 | int i; |
601 | 53 | wp->button=0; | 58 | wp->button = 0; |
602 | 54 | wp->key=""; | 59 | wp->key = ""; |
603 | 55 | wp->next=NULL; | 60 | wp->next = NULL; |
604 | 56 | for(i=0 ; i<4 ; i++) | 61 | for (i = 0; i < 4; i++) |
605 | 57 | wp->modifiers[i]=""; | 62 | wp->modifiers[i] = ""; |
606 | 58 | for(i=0 ; i<25 ; i++ ) { | 63 | for (i = 0; i < 25; i++) { |
607 | 59 | wp->config_attr[i].attrName=""; | 64 | wp->config_attr[i].attrName = ""; |
608 | 60 | wp->config_attr[i].val=0; | 65 | wp->config_attr[i].val = 0; |
609 | 61 | wp->config_attr[i].valMax=0; | 66 | wp->config_attr[i].valMax = 0; |
610 | 62 | } | 67 | } |
611 | 63 | } | 68 | } |
612 | 64 | 69 | ||
613 | 65 | void | 70 | void inita(struct apps *ap) |
614 | 66 | inita(struct apps *ap) { | 71 | { |
615 | 67 | ap->next=NULL; | 72 | ap->next = NULL; |
616 | 68 | ap->wp =NULL; | 73 | ap->wp = NULL; |
617 | 69 | ap->appName=""; | 74 | ap->appName = ""; |
618 | 70 | } | 75 | } |
619 | 71 | 76 | ||
620 | 72 | static void clear_accum_attrs(att *attrs){ | 77 | static void clear_accum_attrs(att * attrs) |
621 | 73 | int i = 0; | 78 | { |
622 | 74 | while (strcmp(attrs[i].attrName, "") != 0){ | 79 | int i = 0; |
623 | 75 | if (attrs[i].accumulate) attrs[i].accumVal = 0; | 80 | while (strcmp(attrs[i].attrName, "") != 0) { |
624 | 76 | i++; | 81 | if (attrs[i].accumulate) |
625 | 77 | } | 82 | attrs[i].accumVal = 0; |
626 | 78 | } | 83 | i++; |
627 | 79 | 84 | } | |
628 | 80 | static void | 85 | } |
629 | 81 | update_wishes() | 86 | |
630 | 82 | { | 87 | static void update_wishes() |
631 | 83 | char *activeApp; | 88 | { |
632 | 84 | apps* tmpAp = ap; | 89 | char *activeApp; |
633 | 85 | int diff=0; | 90 | apps *tmpAp = ap; |
634 | 86 | 91 | int diff = 0; | |
635 | 87 | activeApp = (char*)getCurrentApp(); | 92 | |
636 | 88 | printf(" --ActiveApp %s\n",activeApp); | 93 | activeApp = (char *) getCurrentApp(); |
637 | 89 | if (activeApp) | 94 | printf(" --ActiveApp %s\n", activeApp); |
638 | 90 | diff = strcmp(activeApp,ap->appName); | 95 | if (activeApp) |
639 | 91 | 96 | diff = strcmp(activeApp, ap->appName); | |
640 | 92 | while ( diff && ap->next ) { | 97 | |
641 | 93 | ap = ap->next; | 98 | while (diff && ap->next) { |
642 | 94 | diff = strcmp(activeApp,ap->appName); | 99 | ap = ap->next; |
643 | 95 | } | 100 | diff = strcmp(activeApp, ap->appName); |
644 | 96 | 101 | } | |
645 | 97 | if (!diff) | 102 | |
646 | 98 | wpEnd->next = ap->wp; | 103 | if (!diff) |
647 | 99 | else | 104 | wpEnd->next = ap->wp; |
648 | 100 | wpEnd->next = NULL; | 105 | else |
649 | 101 | 106 | wpEnd->next = NULL; | |
650 | 102 | ap = tmpAp; | 107 | |
651 | 103 | } | 108 | ap = tmpAp; |
652 | 104 | 109 | } | |
653 | 105 | static void | 110 | |
654 | 106 | gesture_match( GeisGestureType gesture_type, | 111 | static void |
655 | 107 | GeisGestureId gesture_id, | 112 | gesture_match(GeisGestureType gesture_type, |
656 | 108 | GeisSize attr_count, | 113 | GeisGestureId gesture_id, |
657 | 109 | GeisGestureAttr *attrs, | 114 | GeisSize attr_count, GeisGestureAttr * attrs, int state) |
658 | 110 | int state) | 115 | { |
659 | 111 | { | 116 | struct wish *topw; |
660 | 112 | struct wish *topw; | 117 | topw = wp; |
661 | 113 | topw=wp; | 118 | update_wishes(); |
662 | 114 | update_wishes(); | 119 | while (wp && (0 != strcmp(wp->key, "") || wp->button)) { |
663 | 115 | while (wp && ( 0!=strcmp(wp->key,"") || wp->button )) { | 120 | int valid = 1; |
664 | 116 | int valid=1; | 121 | if (gesture_type == wp->config_attr[0].val |
665 | 117 | if (gesture_type==wp->config_attr[0].val && attrs[8].integer_val==wp->config_attr[1].val) { | 122 | && attrs[8].integer_val == wp->config_attr[1].val) { |
666 | 118 | int attrsI=9, cAttrI=2; | 123 | int attrsI = 9, cAttrI = 2; |
667 | 119 | do { | 124 | do { |
668 | 120 | if (0==strcmp(attrs[attrsI].name, wp->config_attr[cAttrI].attrName)){ | 125 | if (0 == |
669 | 121 | printf("DEBUG -- comparing %s %s : ", attrs[attrsI].name, wp->config_attr[cAttrI].attrName); | 126 | strcmp(attrs[attrsI].name, |
670 | 122 | printf("%.2f %.2f %.2f \n", attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax); | 127 | wp->config_attr[cAttrI].attrName)) { |
671 | 123 | printf("%i \n", inside(attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax)); | 128 | printf("DEBUG -- comparing %s %s : ", |
672 | 124 | if (wp->config_attr[cAttrI].accumulate){ | 129 | attrs[attrsI].name, |
673 | 125 | wp->config_attr[cAttrI].accumVal += attrs[attrsI].float_val; | 130 | wp->config_attr[cAttrI].attrName); |
674 | 126 | valid= valid && inside(wp->config_attr[cAttrI].accumVal, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax); | 131 | printf("%.2f %.2f %.2f \n", |
675 | 127 | } | 132 | attrs[attrsI].float_val, |
676 | 128 | else valid = valid && inside(attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax); | 133 | wp->config_attr[cAttrI].val, |
677 | 129 | attrsI++; cAttrI++; | 134 | wp->config_attr[cAttrI].valMax); |
678 | 130 | } else attrsI++; | 135 | printf("%i \n", |
679 | 131 | } while ( (0!=strcmp(wp->config_attr[cAttrI].attrName,"")) && attrsI<18 ); | 136 | inside(attrs[attrsI].float_val, |
680 | 132 | if (valid && wp->when == state){ | 137 | wp->config_attr[cAttrI].val, |
681 | 133 | if ((0!=wp->button) && (0 != strcmp(wp->key, ""))) | 138 | wp->config_attr[cAttrI].valMax)); |
682 | 134 | { injMixBtnKey(XStringToKeysym(wp->key), wp->button, wp->modifiers); | 139 | if (wp->config_attr[cAttrI].accumulate) { |
683 | 135 | printf("MIX -- MIX"); | 140 | wp->config_attr[cAttrI].accumVal += |
684 | 136 | } | 141 | attrs[attrsI].float_val; |
685 | 137 | else { | 142 | valid = valid |
686 | 138 | if (0!=wp->button) | 143 | && inside(wp->config_attr |
687 | 139 | injButton(wp->button, wp->modifiers); | 144 | [cAttrI].accumVal, |
688 | 140 | if (0 != strcmp(wp->key, "")) | 145 | wp->config_attr |
689 | 141 | injKey(XStringToKeysym(wp->key), wp->modifiers); | 146 | [cAttrI].val, |
690 | 142 | } | 147 | wp->config_attr[cAttrI].valMax); |
691 | 143 | clear_accum_attrs(wp->config_attr); | 148 | } else |
692 | 144 | } | 149 | valid = valid |
693 | 145 | } | 150 | && inside(attrs[attrsI].float_val, |
694 | 146 | if (state == GINN_FINISH) clear_accum_attrs(wp->config_attr); | 151 | wp->config_attr |
695 | 147 | wp=wp->next; | 152 | [cAttrI].val, |
696 | 148 | } | 153 | wp->config_attr[cAttrI].valMax); |
697 | 149 | wp=topw; | 154 | attrsI++; |
698 | 155 | cAttrI++; | ||
699 | 156 | } else | ||
700 | 157 | attrsI++; | ||
701 | 158 | } while ((0 != strcmp(wp->config_attr[cAttrI].attrName, "")) | ||
702 | 159 | && attrsI < 18); | ||
703 | 160 | if (valid && wp->when == state) { | ||
704 | 161 | if ((0 != wp->button) | ||
705 | 162 | && (0 != strcmp(wp->key, ""))) { | ||
706 | 163 | injMixBtnKey(XStringToKeysym(wp->key), | ||
707 | 164 | wp->button, wp->modifiers); | ||
708 | 165 | printf("MIX -- MIX"); | ||
709 | 166 | } else { | ||
710 | 167 | if (0 != wp->button) | ||
711 | 168 | injButton(wp->button, wp->modifiers); | ||
712 | 169 | if (0 != strcmp(wp->key, "")) | ||
713 | 170 | injKey(XStringToKeysym(wp->key), wp->modifiers); | ||
714 | 171 | } | ||
715 | 172 | clear_accum_attrs(wp->config_attr); | ||
716 | 173 | } | ||
717 | 174 | } | ||
718 | 175 | if (state == GINN_FINISH) | ||
719 | 176 | clear_accum_attrs(wp->config_attr); | ||
720 | 177 | wp = wp->next; | ||
721 | 178 | } | ||
722 | 179 | wp = topw; | ||
723 | 150 | } | 180 | } |
724 | 151 | 181 | ||
725 | 152 | static Window getRootWindow() | 182 | static Window getRootWindow() |
726 | 153 | { | 183 | { |
742 | 154 | Display *display = NULL; | 184 | Display *display = NULL; |
743 | 155 | Window window = 0; | 185 | Window window = 0; |
744 | 156 | 186 | ||
745 | 157 | display = XOpenDisplay(NULL); | 187 | display = XOpenDisplay(NULL); |
746 | 158 | if (!display) | 188 | if (!display) { |
747 | 159 | { | 189 | fprintf(stderr, "error opening X11 display.\n"); |
748 | 160 | fprintf(stderr, "error opening X11 display.\n"); | 190 | exit(1); |
749 | 161 | exit(1); | 191 | } |
750 | 162 | } | 192 | |
751 | 163 | 193 | window = DefaultRootWindow(display); | |
752 | 164 | window = DefaultRootWindow(display); | 194 | |
753 | 165 | 195 | XCloseDisplay(display); | |
754 | 166 | XCloseDisplay(display); | 196 | |
755 | 167 | 197 | return window; | |
741 | 168 | return window; | ||
756 | 169 | } | 198 | } |
757 | 170 | 199 | ||
760 | 171 | static void | 200 | static void print_attr(GeisGestureAttr * attr) |
759 | 172 | print_attr(GeisGestureAttr *attr) | ||
761 | 173 | { | 201 | { |
765 | 174 | fprintf(stdout, "\tattr %s=", attr->name); | 202 | fprintf(stdout, "\tattr %s=", attr->name); |
766 | 175 | switch (attr->type) | 203 | switch (attr->type) { |
764 | 176 | { | ||
767 | 177 | case GEIS_ATTR_TYPE_BOOLEAN: | 204 | case GEIS_ATTR_TYPE_BOOLEAN: |
770 | 178 | fprintf(stdout, "%s\n", attr->boolean_val ? "true" : "false"); | 205 | fprintf(stdout, "%s\n", attr->boolean_val ? "true" : "false"); |
771 | 179 | break; | 206 | break; |
772 | 180 | case GEIS_ATTR_TYPE_FLOAT: | 207 | case GEIS_ATTR_TYPE_FLOAT: |
775 | 181 | fprintf(stdout, "%f\n", attr->float_val); | 208 | fprintf(stdout, "%f\n", attr->float_val); |
776 | 182 | break; | 209 | break; |
777 | 183 | case GEIS_ATTR_TYPE_INTEGER: | 210 | case GEIS_ATTR_TYPE_INTEGER: |
780 | 184 | fprintf(stdout, "%d\n", attr->integer_val); | 211 | fprintf(stdout, "%d\n", attr->integer_val); |
781 | 185 | break; | 212 | break; |
782 | 186 | case GEIS_ATTR_TYPE_STRING: | 213 | case GEIS_ATTR_TYPE_STRING: |
785 | 187 | fprintf(stdout, "\"%s\"\n", attr->string_val); | 214 | fprintf(stdout, "\"%s\"\n", attr->string_val); |
786 | 188 | break; | 215 | break; |
787 | 189 | default: | 216 | default: |
860 | 190 | fprintf(stdout, "<unknown>\n"); | 217 | fprintf(stdout, "<unknown>\n"); |
861 | 191 | break; | 218 | break; |
862 | 192 | } | 219 | } |
863 | 193 | } | 220 | } |
864 | 194 | 221 | ||
865 | 195 | static void | 222 | static void |
866 | 196 | gesture_added(void *cookie, | 223 | gesture_added(void *cookie, |
867 | 197 | GeisGestureType gesture_type, | 224 | GeisGestureType gesture_type, |
868 | 198 | GeisGestureId gesture_id, | 225 | GeisGestureId gesture_id, |
869 | 199 | GeisSize attr_count, | 226 | GeisSize attr_count, GeisGestureAttr * attrs) |
870 | 200 | GeisGestureAttr *attrs) | 227 | { |
871 | 201 | { | 228 | int i = 0; |
872 | 202 | int i = 0; | 229 | fprintf(stdout, "Gesture type %d added\n", gesture_type); |
873 | 203 | fprintf(stdout, "Gesture type %d added\n", gesture_type); | 230 | for (i = 0; i < attr_count; ++i) |
874 | 204 | for (i = 0; i < attr_count; ++i) | 231 | print_attr(&attrs[i]); |
875 | 205 | print_attr(&attrs[i]); | 232 | } |
876 | 206 | } | 233 | |
877 | 207 | 234 | static void | |
878 | 208 | static void | 235 | gesture_removed(void *cookie, |
879 | 209 | gesture_removed(void *cookie, | 236 | GeisGestureType gesture_type, |
880 | 210 | GeisGestureType gesture_type, | 237 | GeisGestureId gesture_id, |
881 | 211 | GeisGestureId gesture_id, | 238 | GeisSize attr_count, GeisGestureAttr * attrs) |
882 | 212 | GeisSize attr_count, | 239 | { |
883 | 213 | GeisGestureAttr *attrs) | 240 | int i = 0; |
884 | 214 | { | 241 | fprintf(stdout, "Gesture type %d removed\n", gesture_type); |
885 | 215 | int i = 0; | 242 | for (i = 0; i < attr_count; ++i) |
886 | 216 | fprintf(stdout, "Gesture type %d removed\n", gesture_type); | 243 | print_attr(&attrs[i]); |
887 | 217 | for (i = 0; i < attr_count; ++i) | 244 | } |
888 | 218 | print_attr(&attrs[i]); | 245 | |
889 | 219 | } | 246 | static void |
890 | 220 | 247 | gesture_start(void *cookie, | |
891 | 221 | static void | 248 | GeisGestureType gesture_type, |
892 | 222 | gesture_start(void *cookie, | 249 | GeisGestureId gesture_id, |
893 | 223 | GeisGestureType gesture_type, | 250 | GeisSize attr_count, GeisGestureAttr * attrs) |
894 | 224 | GeisGestureId gesture_id, | 251 | { |
895 | 225 | GeisSize attr_count, | 252 | int i = 0; |
896 | 226 | GeisGestureAttr *attrs) | 253 | fprintf(stdout, "Gesture type %d started\n", gesture_type); |
897 | 227 | { | 254 | for (i = 0; i < attr_count; ++i) |
898 | 228 | int i = 0; | 255 | print_attr(&attrs[i]); |
899 | 229 | fprintf(stdout, "Gesture type %d started\n", gesture_type); | 256 | |
900 | 230 | for (i = 0; i < attr_count; ++i) | 257 | // In GEIS v1, we know that the focus coords are in attrs 5 and 6 |
901 | 231 | print_attr(&attrs[i]); | 258 | movePointer((int)attrs[5].float_val, (int)attrs[6].float_val); |
902 | 232 | } | 259 | } |
903 | 233 | 260 | ||
904 | 234 | static void | 261 | static void |
905 | 235 | gesture_update(void *cookie, | 262 | gesture_update(void *cookie, |
906 | 236 | GeisGestureType gesture_type, | 263 | GeisGestureType gesture_type, |
907 | 237 | GeisGestureId gesture_id, | 264 | GeisGestureId gesture_id, |
908 | 238 | GeisSize attr_count, | 265 | GeisSize attr_count, GeisGestureAttr * attrs) |
909 | 239 | GeisGestureAttr *attrs) | 266 | { |
910 | 240 | { | 267 | int i = 0; |
911 | 241 | int i = 0; | 268 | fprintf(stdout, "Gesture type %d updated\n", gesture_type); |
912 | 242 | fprintf(stdout, "Gesture type %d updated\n", gesture_type); | 269 | for (i = 0; i < attr_count; ++i) |
913 | 243 | for (i = 0; i < attr_count; ++i) | 270 | print_attr(&attrs[i]); |
914 | 244 | print_attr(&attrs[i]); | 271 | gesture_match(gesture_type, gesture_id, attr_count, attrs, |
915 | 245 | gesture_match(gesture_type, gesture_id, attr_count, attrs, GINN_UPDATE); | 272 | GINN_UPDATE); |
916 | 246 | } | 273 | } |
917 | 247 | 274 | ||
918 | 248 | static void | 275 | static void |
919 | 249 | gesture_finish(void *cookie, | 276 | gesture_finish(void *cookie, |
920 | 250 | GeisGestureType gesture_type, | 277 | GeisGestureType gesture_type, |
921 | 251 | GeisGestureId gesture_id, | 278 | GeisGestureId gesture_id, |
922 | 252 | GeisSize attr_count, | 279 | GeisSize attr_count, GeisGestureAttr * attrs) |
923 | 253 | GeisGestureAttr *attrs) | 280 | { |
924 | 254 | { | 281 | int i = 0; |
925 | 255 | int i = 0; | 282 | fprintf(stdout, "Gesture type %d finished\n", gesture_type); |
926 | 256 | fprintf(stdout, "Gesture type %d finished\n", gesture_type); | 283 | for (i = 0; i < attr_count; ++i); //print_attr(&attrs[i]); |
927 | 257 | for (i = 0; i < attr_count; ++i) | 284 | gesture_match(gesture_type, gesture_id, attr_count, attrs, |
928 | 258 | ;//print_attr(&attrs[i]); | 285 | GINN_FINISH); |
929 | 259 | gesture_match(gesture_type, gesture_id, attr_count, attrs, GINN_FINISH); | 286 | } |
858 | 260 | } | ||
859 | 261 | |||
930 | 262 | 287 | ||
931 | 263 | GeisGestureFuncs gesture_funcs = { | 288 | GeisGestureFuncs gesture_funcs = { |
937 | 264 | gesture_added, | 289 | gesture_added, |
938 | 265 | gesture_removed, | 290 | gesture_removed, |
939 | 266 | gesture_start, | 291 | gesture_start, |
940 | 267 | gesture_update, | 292 | gesture_update, |
941 | 268 | gesture_finish | 293 | gesture_finish |
942 | 269 | }; | 294 | }; |
943 | 270 | 295 | ||
944 | 271 | |||
945 | 272 | /* | 296 | /* |
946 | 273 | * Searches for a default config file. | 297 | * Searches for a default config file. |
947 | 274 | * | 298 | * |
948 | 275 | * Returns a pointer to a config file name (which must be freed) or NULL | 299 | * Returns a pointer to a config file name (which must be freed) or NULL |
949 | 276 | * if no default config file was found. | 300 | * if no default config file was found. |
950 | 277 | */ | 301 | */ |
1138 | 278 | static char * | 302 | static char *ginn_default_config() |
1139 | 279 | ginn_default_config() | 303 | { |
1140 | 280 | { | 304 | static const char default_file_name[] = "/wishes.xml"; |
1141 | 281 | static const char default_file_name[] = "/wishes.xml"; | 305 | static const char *search_paths[] = { |
1142 | 282 | static const char *search_paths[] = | 306 | "etc", |
1143 | 283 | { | 307 | "../etc", |
1144 | 284 | "etc", | 308 | ".", |
1145 | 285 | "../etc", | 309 | "$HOME/.ginn", |
1146 | 286 | ".", | 310 | GINN_CONFIG_DIR |
1147 | 287 | "$HOME/.ginn", | 311 | }; |
1148 | 288 | GINN_CONFIG_DIR | 312 | static const int num_paths = |
1149 | 289 | }; | 313 | sizeof(search_paths) / sizeof(const char *); |
1150 | 290 | static const int num_paths = sizeof(search_paths) / sizeof(const char *); | 314 | int i; |
1151 | 291 | int i; | 315 | |
1152 | 292 | 316 | for (i = 0; i < num_paths; ++i) { | |
1153 | 293 | for (i=0; i < num_paths; ++i) | 317 | struct stat sbuf; |
1154 | 294 | { | 318 | char *file_name = NULL; |
1155 | 295 | struct stat sbuf; | 319 | |
1156 | 296 | char *file_name = NULL; | 320 | if (strstr(search_paths[i], "$HOME")) { |
1157 | 297 | 321 | char *home_dir = getenv("HOME"); | |
1158 | 298 | if (strstr(search_paths[i], "$HOME")) | 322 | if (!home_dir) { |
1159 | 299 | { | 323 | continue; |
1160 | 300 | char *home_dir = getenv("HOME"); | 324 | } else { |
1161 | 301 | if (!home_dir) | 325 | char *cdr = index(search_paths[i], '/'); |
1162 | 302 | { | 326 | size_t file_name_length = strlen(home_dir) |
1163 | 303 | continue; | 327 | + strlen(cdr) |
1164 | 304 | } | 328 | + strlen(default_file_name) |
1165 | 305 | else | 329 | + 1; |
1166 | 306 | { | 330 | file_name = calloc(file_name_length, sizeof(char)); |
1167 | 307 | char *cdr = index(search_paths[i], '/'); | 331 | strcpy(file_name, home_dir); |
1168 | 308 | size_t file_name_length = strlen(home_dir) | 332 | strcat(file_name, cdr); |
1169 | 309 | + strlen(cdr) | 333 | } |
1170 | 310 | + strlen(default_file_name) | 334 | } else { |
1171 | 311 | + 1; | 335 | size_t file_name_length = strlen(search_paths[i]) |
1172 | 312 | file_name = calloc(file_name_length, sizeof(char)); | 336 | + strlen(default_file_name) |
1173 | 313 | strcpy(file_name, home_dir); | 337 | + 1; |
1174 | 314 | strcat(file_name, cdr); | 338 | file_name = calloc(file_name_length, sizeof(char)); |
1175 | 315 | } | 339 | strcpy(file_name, search_paths[i]); |
1176 | 316 | } | 340 | } |
1177 | 317 | else | 341 | strcat(file_name, default_file_name); |
1178 | 318 | { | 342 | int sres = stat(file_name, &sbuf); |
1179 | 319 | size_t file_name_length = strlen(search_paths[i]) | 343 | if (sres == 0) { |
1180 | 320 | + strlen(default_file_name) | 344 | fprintf(stdout, "Using wishes file %s\n", file_name); |
1181 | 321 | + 1; | 345 | return file_name; |
1182 | 322 | file_name = calloc(file_name_length, sizeof(char)); | 346 | } |
1183 | 323 | strcpy(file_name, search_paths[i]); | 347 | free(file_name); |
1184 | 324 | } | 348 | } |
1185 | 325 | strcat(file_name, default_file_name); | 349 | |
1186 | 326 | int sres = stat(file_name, &sbuf); | 350 | return NULL; |
1187 | 327 | if (sres == 0) | 351 | } |
1188 | 328 | { | 352 | |
1189 | 329 | fprintf(stdout, "Using wishes file %s\n", file_name); | 353 | int main(int argc, char *argv[]) |
1190 | 330 | return file_name; | 354 | { |
1191 | 331 | } | 355 | GeisStatus status = GEIS_UNKNOWN_ERROR; |
1192 | 332 | free(file_name); | 356 | GeisXcbWinInfo xcb_win_info = { |
1193 | 333 | } | 357 | .display_name = NULL, |
1194 | 334 | 358 | .screenp = NULL, | |
1195 | 335 | return NULL; | 359 | .window_id = getRootWindow() |
1196 | 336 | } | 360 | }; |
1197 | 337 | 361 | GeisWinInfo win_info = { | |
1198 | 338 | 362 | GEIS_XCB_FULL_WINDOW, | |
1199 | 339 | int main(int argc, char* argv[]) | 363 | &xcb_win_info |
1200 | 340 | { | 364 | }; |
1201 | 341 | GeisStatus status = GEIS_UNKNOWN_ERROR; | 365 | GeisInstance instance; |
1202 | 342 | GeisXcbWinInfo xcb_win_info = { | 366 | struct ginn_config cfg; |
1203 | 343 | .display_name = NULL, | 367 | |
1204 | 344 | .screenp = NULL, | 368 | const char *sub_gestures_list[] = { |
1205 | 345 | .window_id = getRootWindow() | 369 | GEIS_GESTURE_TYPE_DRAG2, GEIS_GESTURE_TYPE_DRAG3, |
1206 | 346 | }; | 370 | GEIS_GESTURE_TYPE_DRAG4, GEIS_GESTURE_TYPE_DRAG5, |
1207 | 347 | GeisWinInfo win_info = { | 371 | GEIS_GESTURE_TYPE_PINCH2, GEIS_GESTURE_TYPE_PINCH3, |
1208 | 348 | GEIS_XCB_FULL_WINDOW, | 372 | GEIS_GESTURE_TYPE_PINCH4, GEIS_GESTURE_TYPE_PINCH5, |
1209 | 349 | &xcb_win_info | 373 | GEIS_GESTURE_TYPE_ROTATE2, GEIS_GESTURE_TYPE_ROTATE3, |
1210 | 350 | }; | 374 | GEIS_GESTURE_TYPE_ROTATE4, GEIS_GESTURE_TYPE_ROTATE5, |
1211 | 351 | GeisInstance instance; | 375 | GEIS_GESTURE_TYPE_TAP2, GEIS_GESTURE_TYPE_TAP3, |
1212 | 352 | struct ginn_config cfg; | 376 | GEIS_GESTURE_TYPE_TAP4, GEIS_GESTURE_TYPE_TAP5, NULL |
1213 | 353 | 377 | }; | |
1214 | 354 | const char * sub_gestures_list[]= { | 378 | { |
1215 | 355 | GEIS_GESTURE_TYPE_DRAG2, GEIS_GESTURE_TYPE_DRAG3, | 379 | char *config_file_name = NULL; |
1216 | 356 | GEIS_GESTURE_TYPE_DRAG4,GEIS_GESTURE_TYPE_DRAG5, | 380 | if (argc < 2) { |
1217 | 357 | GEIS_GESTURE_TYPE_PINCH2, GEIS_GESTURE_TYPE_PINCH3, | 381 | fprintf(stderr, "usage: %s <configxml>\n", argv[0]); |
1218 | 358 | GEIS_GESTURE_TYPE_PINCH4,GEIS_GESTURE_TYPE_PINCH5, | 382 | config_file_name = ginn_default_config(); |
1219 | 359 | GEIS_GESTURE_TYPE_ROTATE2, GEIS_GESTURE_TYPE_ROTATE3, | 383 | if (config_file_name) { |
1220 | 360 | GEIS_GESTURE_TYPE_ROTATE4,GEIS_GESTURE_TYPE_ROTATE5, | 384 | fprintf(stderr, |
1221 | 361 | GEIS_GESTURE_TYPE_TAP2, GEIS_GESTURE_TYPE_TAP3, | 385 | "using default configuration file %s ... \n", |
1222 | 362 | GEIS_GESTURE_TYPE_TAP4,GEIS_GESTURE_TYPE_TAP5, NULL }; | 386 | config_file_name); |
1223 | 363 | { | 387 | } |
1224 | 364 | char * config_file_name = NULL; | 388 | } else { |
1225 | 365 | if (argc < 2) { | 389 | config_file_name = strdup(argv[1]); |
1226 | 366 | fprintf(stderr, "usage: %s <configxml>\n", argv[0]); | 390 | } |
1227 | 367 | config_file_name = ginn_default_config(); | 391 | if (NULL == config_file_name) { |
1228 | 368 | if (config_file_name) | 392 | fprintf(stderr, "Could not find Ginn wishes\n"); |
1229 | 369 | { | 393 | return -1; |
1230 | 370 | fprintf(stderr, "using default configuration file %s ... \n", | 394 | } |
1231 | 371 | config_file_name); | 395 | |
1232 | 372 | } | 396 | if (ginn_config_open(&cfg, config_file_name)) { |
1233 | 373 | } | 397 | fprintf(stderr, "Could not load Ginn wishes\n"); |
1234 | 374 | else | 398 | return -1; |
1235 | 375 | { | 399 | } |
1236 | 376 | config_file_name = strdup(argv[1]); | 400 | free(config_file_name); |
1237 | 377 | } | 401 | } |
1238 | 378 | if (NULL == config_file_name) | 402 | |
1239 | 379 | { | 403 | ginn_config_print(&cfg); |
1240 | 380 | fprintf(stderr, "Could not find Ginn wishes\n"); | 404 | ap = (struct apps *) malloc(sizeof(struct apps)); |
1241 | 381 | return -1; | 405 | inita(ap); |
1242 | 382 | } | 406 | wp = (struct wish *) malloc(sizeof(struct wish)); |
1243 | 383 | 407 | initw(wp); | |
1244 | 384 | if ( ginn_config_open(&cfg, config_file_name) ) { | 408 | ginn_config_store(&cfg, wp, ap); |
1245 | 385 | fprintf(stderr, "Could not load Ginn wishes\n"); | 409 | wpEnd = wp; |
1246 | 386 | return -1; | 410 | while (wpEnd->next) |
1247 | 387 | } | 411 | wpEnd = wpEnd->next; |
1248 | 388 | free(config_file_name); | 412 | |
1249 | 389 | } | 413 | int pos = 0; |
1250 | 390 | 414 | printf("\n"); | |
1251 | 391 | ginn_config_print(&cfg); | 415 | while (strcmp(config_attr[pos].attrName, "")) { |
1252 | 392 | ap = (struct apps *) malloc(sizeof(struct apps)); inita(ap); | 416 | printf("DEBUG %d %s %.2f %.2f \n", pos, |
1253 | 393 | wp = (struct wish *) malloc(sizeof(struct wish)); initw(wp); | 417 | config_attr[pos].attrName, config_attr[pos].val, |
1254 | 394 | ginn_config_store(&cfg, wp, ap); | 418 | config_attr[pos].valMax); |
1255 | 395 | wpEnd=wp; | 419 | pos++; |
1256 | 396 | while (wpEnd->next) | 420 | } |
1257 | 397 | wpEnd=wpEnd->next; | 421 | |
1258 | 398 | 422 | status = geis_init(&win_info, &instance); | |
1259 | 399 | int pos=0; | 423 | if (status != GEIS_STATUS_SUCCESS) { |
1260 | 400 | printf("\n"); | 424 | fprintf(stderr, "error in geis_init\n"); |
1261 | 401 | while (strcmp(config_attr[pos].attrName,"")) { | 425 | return 1; |
1262 | 402 | printf("DEBUG %d %s %.2f %.2f \n", pos, config_attr[pos].attrName, config_attr[pos].val, config_attr[pos].valMax); | 426 | } |
1263 | 403 | pos++; | 427 | |
1264 | 404 | } | 428 | status = geis_configuration_supported(instance, GEIS_CONFIG_UNIX_FD); |
1265 | 405 | 429 | if (status != GEIS_STATUS_SUCCESS) { | |
1266 | 406 | status = geis_init(&win_info, &instance); | 430 | fprintf(stderr, "GEIS does not support Unix fd\n"); |
1267 | 407 | if (status != GEIS_STATUS_SUCCESS) | 431 | return 1; |
1268 | 408 | { | 432 | } |
1269 | 409 | fprintf(stderr, "error in geis_init\n"); | 433 | |
1270 | 410 | return 1; | 434 | int fd = -1; |
1271 | 411 | } | 435 | status = |
1272 | 412 | 436 | geis_configuration_get_value(instance, GEIS_CONFIG_UNIX_FD, &fd); | |
1273 | 413 | status = geis_configuration_supported(instance, GEIS_CONFIG_UNIX_FD); | 437 | if (status != GEIS_STATUS_SUCCESS) { |
1274 | 414 | if (status != GEIS_STATUS_SUCCESS) | 438 | fprintf(stderr, "error retrieving GEIS fd\n"); |
1275 | 415 | { | 439 | return 1; |
1276 | 416 | fprintf(stderr, "GEIS does not support Unix fd\n"); | 440 | } |
1277 | 417 | return 1; | 441 | |
1278 | 418 | } | 442 | status = geis_subscribe(instance, GEIS_ALL_INPUT_DEVICES, sub_gestures_list, // GEIS_ALL_GESTURES, |
1279 | 419 | 443 | &gesture_funcs, NULL); | |
1280 | 420 | int fd = -1; | 444 | if (status != GEIS_STATUS_SUCCESS) { |
1281 | 421 | status = geis_configuration_get_value(instance, GEIS_CONFIG_UNIX_FD, &fd); | 445 | fprintf(stderr, "error subscribing to gestures\n"); |
1282 | 422 | if (status != GEIS_STATUS_SUCCESS) | 446 | return 1; |
1283 | 423 | { | 447 | } |
1284 | 424 | fprintf(stderr, "error retrieving GEIS fd\n"); | 448 | |
1285 | 425 | return 1; | 449 | openDisplay(); |
1286 | 426 | } | 450 | |
1287 | 427 | 451 | while (1) { | |
1288 | 428 | status = geis_subscribe(instance, | 452 | fd_set read_fds; |
1289 | 429 | GEIS_ALL_INPUT_DEVICES, | 453 | FD_ZERO(&read_fds); |
1290 | 430 | sub_gestures_list, // GEIS_ALL_GESTURES, | 454 | FD_SET(fd, &read_fds); |
1291 | 431 | &gesture_funcs, | 455 | int sstat = select(fd + 1, &read_fds, NULL, NULL, NULL); |
1292 | 432 | NULL); | 456 | if (sstat < 0) { |
1293 | 433 | if (status != GEIS_STATUS_SUCCESS) | 457 | fprintf(stderr, "error %d in select(): %s\n", errno, |
1294 | 434 | { | 458 | strerror(errno)); |
1295 | 435 | fprintf(stderr, "error subscribing to gestures\n"); | 459 | break; |
1296 | 436 | return 1; | 460 | } |
1297 | 437 | } | 461 | |
1298 | 438 | 462 | if (FD_ISSET(fd, &read_fds)) { | |
1299 | 439 | openDisplay(); | 463 | geis_event_dispatch(instance); |
1300 | 440 | 464 | } | |
1301 | 441 | while(1) | 465 | } |
1302 | 442 | { | 466 | |
1303 | 443 | fd_set read_fds; | 467 | geis_finish(instance); |
1304 | 444 | FD_ZERO(&read_fds); | 468 | closeDisplay(); |
1305 | 445 | FD_SET(fd, &read_fds); | 469 | free(wp); |
1306 | 446 | int sstat = select(fd+1, &read_fds, NULL, NULL, NULL); | 470 | return 0; |
1307 | 447 | if (sstat < 0) | 471 | } |
1121 | 448 | { | ||
1122 | 449 | fprintf(stderr, "error %d in select(): %s\n", errno, strerror(errno)); | ||
1123 | 450 | break; | ||
1124 | 451 | } | ||
1125 | 452 | |||
1126 | 453 | if (FD_ISSET(fd, &read_fds)) | ||
1127 | 454 | { | ||
1128 | 455 | geis_event_dispatch(instance); | ||
1129 | 456 | } | ||
1130 | 457 | } | ||
1131 | 458 | |||
1132 | 459 | geis_finish(instance); | ||
1133 | 460 | closeDisplay(); | ||
1134 | 461 | free(wp); | ||
1135 | 462 | return 0; | ||
1136 | 463 | } | ||
1137 | 464 | |||
1308 | 465 | 472 | ||
1309 | === modified file 'src/xt.c' | |||
1310 | --- src/xt.c 2011-02-03 08:48:38 +0000 | |||
1311 | +++ src/xt.c 2011-03-16 16:26:15 +0000 | |||
1312 | @@ -21,61 +21,88 @@ | |||
1313 | 21 | #include <X11/extensions/XTest.h> | 21 | #include <X11/extensions/XTest.h> |
1314 | 22 | #include <X11/keysym.h> | 22 | #include <X11/keysym.h> |
1315 | 23 | 23 | ||
1317 | 24 | static Display* disp = NULL; | 24 | static Display *disp = NULL; |
1318 | 25 | 25 | ||
1319 | 26 | void openDisplay() | 26 | void openDisplay() |
1320 | 27 | { | 27 | { |
1322 | 28 | disp = XOpenDisplay(NULL); | 28 | disp = XOpenDisplay(NULL); |
1323 | 29 | } | 29 | } |
1324 | 30 | 30 | ||
1325 | 31 | void closeDisplay() | 31 | void closeDisplay() |
1326 | 32 | { | 32 | { |
1376 | 33 | XCloseDisplay(disp); | 33 | XCloseDisplay(disp); |
1377 | 34 | } | 34 | } |
1378 | 35 | 35 | ||
1379 | 36 | void | 36 | void movePointer(int x, int y) |
1380 | 37 | injKey(KeySym ks, char * modifiers[]) | 37 | { |
1381 | 38 | { | 38 | XTestFakeMotionEvent(disp, 0, x, y, CurrentTime); |
1382 | 39 | int i; | 39 | } |
1383 | 40 | 40 | ||
1384 | 41 | for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++) | 41 | void injKey(KeySym ks, char *modifiers[]) |
1385 | 42 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), True, CurrentTime); | 42 | { |
1386 | 43 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), True, CurrentTime); | 43 | int i; |
1387 | 44 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), False, CurrentTime); | 44 | |
1388 | 45 | for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++) | 45 | for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++) |
1389 | 46 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), False, CurrentTime); | 46 | XTestFakeKeyEvent(disp, |
1390 | 47 | 47 | XKeysymToKeycode(disp, | |
1391 | 48 | XFlush(disp); | 48 | XStringToKeysym(modifiers |
1392 | 49 | } | 49 | [i])), True, |
1393 | 50 | 50 | CurrentTime); | |
1394 | 51 | void | 51 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), True, CurrentTime); |
1395 | 52 | injButton(int btn, char * modifiers[]) | 52 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), False, |
1396 | 53 | { | 53 | CurrentTime); |
1397 | 54 | int i; | 54 | for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++) |
1398 | 55 | 55 | XTestFakeKeyEvent(disp, | |
1399 | 56 | for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++) | 56 | XKeysymToKeycode(disp, |
1400 | 57 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), True, CurrentTime); | 57 | XStringToKeysym(modifiers |
1401 | 58 | XTestFakeButtonEvent(disp, btn, True, CurrentTime); | 58 | [i])), False, |
1402 | 59 | XTestFakeButtonEvent(disp, btn, False, CurrentTime); | 59 | CurrentTime); |
1403 | 60 | for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++) | 60 | |
1404 | 61 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), False, CurrentTime); | 61 | XFlush(disp); |
1405 | 62 | 62 | } | |
1406 | 63 | XFlush(disp); | 63 | |
1407 | 64 | } | 64 | void injButton(int btn, char *modifiers[]) |
1408 | 65 | 65 | { | |
1409 | 66 | void | 66 | int i; |
1410 | 67 | injMixBtnKey(KeySym ks, int btn, char * modifiers[]) | 67 | |
1411 | 68 | { | 68 | for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++) |
1412 | 69 | int i; | 69 | XTestFakeKeyEvent(disp, |
1413 | 70 | 70 | XKeysymToKeycode(disp, | |
1414 | 71 | XTestFakeButtonEvent(disp, btn, True, CurrentTime); | 71 | XStringToKeysym(modifiers |
1415 | 72 | for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++) | 72 | [i])), True, |
1416 | 73 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), True, CurrentTime); | 73 | CurrentTime); |
1417 | 74 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), True, CurrentTime); | 74 | XTestFakeButtonEvent(disp, btn, True, CurrentTime); |
1418 | 75 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), False, CurrentTime); | 75 | XTestFakeButtonEvent(disp, btn, False, CurrentTime); |
1419 | 76 | for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++) | 76 | for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++) |
1420 | 77 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), False, CurrentTime); | 77 | XTestFakeKeyEvent(disp, |
1421 | 78 | XTestFakeButtonEvent(disp, btn, False, CurrentTime); | 78 | XKeysymToKeycode(disp, |
1422 | 79 | XFlush(disp); | 79 | XStringToKeysym(modifiers |
1423 | 80 | } | 80 | [i])), False, |
1424 | 81 | 81 | CurrentTime); | |
1425 | 82 | |||
1426 | 83 | XFlush(disp); | ||
1427 | 84 | } | ||
1428 | 85 | |||
1429 | 86 | void injMixBtnKey(KeySym ks, int btn, char *modifiers[]) | ||
1430 | 87 | { | ||
1431 | 88 | int i; | ||
1432 | 89 | |||
1433 | 90 | XTestFakeButtonEvent(disp, btn, True, CurrentTime); | ||
1434 | 91 | for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++) | ||
1435 | 92 | XTestFakeKeyEvent(disp, | ||
1436 | 93 | XKeysymToKeycode(disp, | ||
1437 | 94 | XStringToKeysym(modifiers | ||
1438 | 95 | [i])), True, | ||
1439 | 96 | CurrentTime); | ||
1440 | 97 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), True, CurrentTime); | ||
1441 | 98 | XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), False, | ||
1442 | 99 | CurrentTime); | ||
1443 | 100 | for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++) | ||
1444 | 101 | XTestFakeKeyEvent(disp, | ||
1445 | 102 | XKeysymToKeycode(disp, | ||
1446 | 103 | XStringToKeysym(modifiers | ||
1447 | 104 | [i])), False, | ||
1448 | 105 | CurrentTime); | ||
1449 | 106 | XTestFakeButtonEvent(disp, btn, False, CurrentTime); | ||
1450 | 107 | XFlush(disp); | ||
1451 | 108 | } |
Everything looks fine !
Thanks Chase !
Once merged, I think the indentation (rev85) can be seen a part, so it's OK for me !