Merge lp:~oif-team/ginn/scroll-pointer-fixes into lp:ginn

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
Reviewer Review Type Date Requested Status
Mohamed IKBEL Boulabiar (community) Approve
Review via email: mp+53649@code.launchpad.net

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.
Revision history for this message
Mohamed IKBEL Boulabiar (boulabiar) wrote :

Everything looks fine !
Thanks Chase !

Once merged, I think the indentation (rev85) can be seen a part, so it's OK for me !

review: Approve

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 <wish gesture="Drag" fingers="2">
6 <action name="action5" when="update">
7 <trigger prop="delta y" min="20" max="80"/>
8- <key>Down</key>
9+ <button>4</button>
10 </action>
11 </wish>
12 <wish gesture="Drag" fingers="2">
13 <action name="action6" when="update">
14 <trigger prop="delta y" min="-80" max="-20"/>
15- <key>Up</key>
16+ <button>5</button>
17 </action>
18 </wish>
19
20
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 #include <libbamf/bamf-matcher.h>
26 #include <string.h>
27
28-char *
29-getName(char * deskfile)
30-{
31- char *temp;
32- temp = strdup(strrchr(deskfile, '/'));
33- return strndup(temp+1, strlen(temp)-9);
34-}
35-
36-char *
37-getCurrentApp()
38-{
39- g_type_init();
40- char *deskfile, *appName;
41- char* temp;
42-
43- BamfApplication * app = bamf_matcher_get_active_application(bamf_matcher_get_default());
44- if (app) {
45- appName = (char*)bamf_view_get_name(BAMF_VIEW(app));
46- temp = bamf_application_get_desktop_file(app);
47-
48- if (strchr(appName,' ') && temp)
49- return getName((char*)temp);
50- else
51- return appName;
52- }
53- else
54- return "";
55-
56-}
57-
58+char *getName(char *deskfile)
59+{
60+ char *temp;
61+ temp = strdup(strrchr(deskfile, '/'));
62+ return strndup(temp + 1, strlen(temp) - 9);
63+}
64+
65+char *getCurrentApp()
66+{
67+ g_type_init();
68+ char *deskfile, *appName;
69+ char *temp;
70+
71+ BamfApplication *app =
72+ bamf_matcher_get_active_application(bamf_matcher_get_default());
73+ if (app) {
74+ appName = (char *) bamf_view_get_name(BAMF_VIEW(app));
75+ temp = bamf_application_get_desktop_file(app);
76+
77+ if (strchr(appName, ' ') && temp)
78+ return getName((char *) temp);
79+ else
80+ return appName;
81+ } else
82+ return "";
83+
84+}
85
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 #include "config.h"
91 #include <libxml/parser.h>
92
93-void
94-debugOut(struct wish * wp) {
95- int i;
96- printf("\n key : %s ", wp->key);
97- printf("\n button : %d ", wp->button);
98- for(i=0 ; i<4 ; i++)
99+void debugOut(struct wish *wp)
100+{
101+ int i;
102+ printf("\n key : %s ", wp->key);
103+ printf("\n button : %d ", wp->button);
104+ for (i = 0; i < 4; i++)
105 printf("\t mod%d : %s ", i, wp->modifiers[i]);
106- for(i=0 ; i<4 ; i++ ) {
107+ for (i = 0; i < 4; i++) {
108 printf("\n attrName : %s ", wp->config_attr[i].attrName);
109 printf("\t val : %.2f ", wp->config_attr[i].val);
110 printf("\t valMax : %.2f", wp->config_attr[i].valMax);
111- }
112- printf("\n pMe : %x pNext : %x ", wp, wp->next);
113- printf("\n===================================================");
114+ }
115+ printf("\n pMe : %x pNext : %x ", wp, wp->next);
116+ printf("\n===================================================");
117 }
118
119 int ginn_config_open(struct ginn_config *cfg, const char *path)
120 {
121- memset(cfg, 0, sizeof(*cfg));
122- cfg->doc = xmlReadFile(path, NULL, 0);
123- if (cfg->doc == NULL) {
124- fprintf(stderr, "Failed to parse %s\n", path);
125- return -1;
126- }
127- return 0;
128+ memset(cfg, 0, sizeof(*cfg));
129+ cfg->doc = xmlReadFile(path, NULL, 0);
130+ if (cfg->doc == NULL) {
131+ fprintf(stderr, "Failed to parse %s\n", path);
132+ return -1;
133+ }
134+ return 0;
135 }
136
137 void ginn_config_close(struct ginn_config *cfg)
138 {
139- xmlFreeDoc(cfg->doc);
140-}
141-
142-
143-static void print_node(const xmlNode *root, int depth)
144-{
145- xmlNode *node;
146- for (node = root; node; node = node->next) {
147- int i;
148- if (node->type != XML_ELEMENT_NODE)
149- continue;
150- for (i = 0; i < depth; i++)
151- printf(" ");
152- printf("%s\n", node->name);
153- print_node(node->children, depth + 1);
154- }
155-}
156-
157-static int ginn_str2state(const char *str){
158- if (str == NULL) return -1;
159- if (strcmp(str, "start") == 0) return GINN_START;
160- if (strcmp(str, "update") == 0) return GINN_UPDATE;
161- if (strcmp(str, "finish") == 0) return GINN_FINISH;
162- fprintf(stderr, "ERROR: Undefined state: %s\n", str);
163- return -2;
164-}
165-
166-static int ginn_str2bool(const char *str){
167- if (str == NULL) return -1;
168- if (strcmp(str, "true") == 0) return 1;
169- if (strcmp(str, "false") == 0) return 0;
170- fprintf(stderr, "ERROR: Invalid value for boolean attribute: %s\n", str);
171- return -2;
172-}
173-
174-void store_1config(xmlNode *node, struct wish *wp, int *position)
175-{
176- if (0==strcmp(node->name, "wish")) {
177- // printf(" gesture %s fingers %s ",(xmlGetProp(node, "gesture")),(xmlGetProp(node, "fingers")));
178- wp->config_attr[0].attrName = "gesture name";
179- switch (xmlGetProp(node, "gesture")[0]) {
180- case 'D': wp->config_attr[0].val=wp->config_attr[0].valMax= 0; break;
181- case 'P': wp->config_attr[0].val=wp->config_attr[0].valMax= 1; break;
182- case 'R': wp->config_attr[0].val=wp->config_attr[0].valMax= 2; break;
183- case 'T': wp->config_attr[0].val=wp->config_attr[0].valMax=15; break;
184- }
185- wp->config_attr[1].attrName = "touches";
186- wp->config_attr[1].val = atoi(xmlGetProp(node, "fingers"));
187- wp->config_attr[1].valMax = atoi(xmlGetProp(node, "fingers"));
188- }
189- if (0==strcmp(node->name, "action")) {
190- wp->when = ginn_str2state(xmlGetProp(node, "when"));
191- if (wp->when < 0)
192- fprintf(stderr, "ERROR: you must provide property 'when' to the action: %s\n", xmlGetProp(node, "name"));
193- }
194- if (0==strcmp(node->name, "trigger")) {
195- wp->config_attr[*position].attrName = xmlGetProp(node, "prop");
196- wp->config_attr[*position].val = atof(xmlGetProp(node, "min"));
197- wp->config_attr[*position].valMax = atof(xmlGetProp(node, "max"));
198- int acc = ginn_str2bool(xmlGetProp(node, "accumulate"));
199- wp->config_attr[*position].accumulate = acc == -1 ? GINN_DEFAULT_ACCUMULATE : acc;
200- wp->config_attr[*position].accumVal = 0;
201- (*position)++;
202- }
203- if (0==strcmp(node->name, "key") || 0==strcmp(node->name, "button")) {
204- if (xmlGetProp(node, "modifier1"))
205- wp->modifiers[0] = xmlGetProp(node, "modifier1");
206- if (xmlGetProp(node, "modifier2"))
207- wp->modifiers[1] = xmlGetProp(node, "modifier2");
208- if (xmlGetProp(node, "modifier3"))
209- wp->modifiers[2] = xmlGetProp(node, "modifier3");
210- if (xmlGetProp(node, "modifier4"))
211- wp->modifiers[3] = xmlGetProp(node, "modifier4");
212- }
213- if (0==strcmp(node->name, "key"))
214- wp->key = xmlNodeGetContent(node);
215- if (0==strcmp(node->name, "button"))
216- wp->button = atoi(xmlNodeGetContent(node));
217- if (0==strcmp(node->name, "button"))
218- printf("Button : %d ", wp->button);
219-}
220-
221-void parse_node(const xmlNode *root, int depth, struct wish *wp, struct apps *ap)
222-{
223- xmlNode *node;
224- int position=2;
225- for (node = root; node; node = node->next) {
226- if (node->type != XML_ELEMENT_NODE)
227- continue;
228-
229- if ( (0==strcmp(node->name, "application")) ) {
230- if (0!=strcmp(ap->appName, "")) {
231- ap = ap->next = (struct apps *) malloc(sizeof(struct apps));
232- inita(ap);
233- }
234- ap->appName=xmlGetProp(node, "name");
235- wp = ap->wp = (struct wish *) malloc(sizeof(struct wish));
236- initw(wp);
237- }
238- if ( (0==strcmp(node->name, "wish")) && (0==strcmp(wp->config_attr[0].attrName, "gesture name")) ) {
239- if (!(wp->next)) {
240- wp->next = (struct wish *) malloc(sizeof(struct wish));
241- initw(wp->next);
242- }
243- wp = wp->next;
244- position=2;
245- }
246- store_1config(node, wp, &position);
247- parse_node(node->children, depth + 1, wp, ap);
248- }
249-}
250-
251-
252-void ginn_config_store(const struct ginn_config *cfg, struct wish *w, struct apps *a)
253-{
254- const xmlNode *root = xmlDocGetRootElement(cfg->doc);
255- parse_node(root, 0, w, a);
256+ xmlFreeDoc(cfg->doc);
257+}
258+
259+static void print_node(const xmlNode * root, int depth)
260+{
261+ xmlNode *node;
262+ for (node = root; node; node = node->next) {
263+ int i;
264+ if (node->type != XML_ELEMENT_NODE)
265+ continue;
266+ for (i = 0; i < depth; i++)
267+ printf(" ");
268+ printf("%s\n", node->name);
269+ print_node(node->children, depth + 1);
270+ }
271+}
272+
273+static int ginn_str2state(const char *str)
274+{
275+ if (str == NULL)
276+ return -1;
277+ if (strcmp(str, "start") == 0)
278+ return GINN_START;
279+ if (strcmp(str, "update") == 0)
280+ return GINN_UPDATE;
281+ if (strcmp(str, "finish") == 0)
282+ return GINN_FINISH;
283+ fprintf(stderr, "ERROR: Undefined state: %s\n", str);
284+ return -2;
285+}
286+
287+static int ginn_str2bool(const char *str)
288+{
289+ if (str == NULL)
290+ return -1;
291+ if (strcmp(str, "true") == 0)
292+ return 1;
293+ if (strcmp(str, "false") == 0)
294+ return 0;
295+ fprintf(stderr, "ERROR: Invalid value for boolean attribute: %s\n",
296+ str);
297+ return -2;
298+}
299+
300+void store_1config(xmlNode * node, struct wish *wp, int *position)
301+{
302+ if (0 == strcmp(node->name, "wish")) {
303+ // printf(" gesture %s fingers %s ",(xmlGetProp(node, "gesture")),(xmlGetProp(node, "fingers")));
304+ wp->config_attr[0].attrName = "gesture name";
305+ switch (xmlGetProp(node, "gesture")[0]) {
306+ case 'D':
307+ wp->config_attr[0].val = wp->config_attr[0].valMax = 0;
308+ break;
309+ case 'P':
310+ wp->config_attr[0].val = wp->config_attr[0].valMax = 1;
311+ break;
312+ case 'R':
313+ wp->config_attr[0].val = wp->config_attr[0].valMax = 2;
314+ break;
315+ case 'T':
316+ wp->config_attr[0].val = wp->config_attr[0].valMax = 15;
317+ break;
318+ }
319+ wp->config_attr[1].attrName = "touches";
320+ wp->config_attr[1].val = atoi(xmlGetProp(node, "fingers"));
321+ wp->config_attr[1].valMax = atoi(xmlGetProp(node, "fingers"));
322+ }
323+ if (0 == strcmp(node->name, "action")) {
324+ wp->when = ginn_str2state(xmlGetProp(node, "when"));
325+ if (wp->when < 0)
326+ fprintf(stderr,
327+ "ERROR: you must provide property 'when' to the action: %s\n",
328+ xmlGetProp(node, "name"));
329+ }
330+ if (0 == strcmp(node->name, "trigger")) {
331+ wp->config_attr[*position].attrName = xmlGetProp(node, "prop");
332+ wp->config_attr[*position].val = atof(xmlGetProp(node, "min"));
333+ wp->config_attr[*position].valMax = atof(xmlGetProp(node, "max"));
334+ int acc = ginn_str2bool(xmlGetProp(node, "accumulate"));
335+ wp->config_attr[*position].accumulate =
336+ acc == -1 ? GINN_DEFAULT_ACCUMULATE : acc;
337+ wp->config_attr[*position].accumVal = 0;
338+ (*position)++;
339+ }
340+ if (0 == strcmp(node->name, "key")
341+ || 0 == strcmp(node->name, "button")) {
342+ if (xmlGetProp(node, "modifier1"))
343+ wp->modifiers[0] = xmlGetProp(node, "modifier1");
344+ if (xmlGetProp(node, "modifier2"))
345+ wp->modifiers[1] = xmlGetProp(node, "modifier2");
346+ if (xmlGetProp(node, "modifier3"))
347+ wp->modifiers[2] = xmlGetProp(node, "modifier3");
348+ if (xmlGetProp(node, "modifier4"))
349+ wp->modifiers[3] = xmlGetProp(node, "modifier4");
350+ }
351+ if (0 == strcmp(node->name, "key"))
352+ wp->key = xmlNodeGetContent(node);
353+ if (0 == strcmp(node->name, "button"))
354+ wp->button = atoi(xmlNodeGetContent(node));
355+ if (0 == strcmp(node->name, "button"))
356+ printf("Button : %d ", wp->button);
357+}
358+
359+void
360+parse_node(const xmlNode * root, int depth, struct wish *wp,
361+ struct apps *ap)
362+{
363+ xmlNode *node;
364+ int position = 2;
365+ for (node = root; node; node = node->next) {
366+ if (node->type != XML_ELEMENT_NODE)
367+ continue;
368+
369+ if ((0 == strcmp(node->name, "application"))) {
370+ if (0 != strcmp(ap->appName, "")) {
371+ ap = ap->next =
372+ (struct apps *) malloc(sizeof(struct apps));
373+ inita(ap);
374+ }
375+ ap->appName = xmlGetProp(node, "name");
376+ wp = ap->wp = (struct wish *) malloc(sizeof(struct wish));
377+ initw(wp);
378+ }
379+ if ((0 == strcmp(node->name, "wish"))
380+ && (0 == strcmp(wp->config_attr[0].attrName, "gesture name"))) {
381+ if (!(wp->next)) {
382+ wp->next = (struct wish *) malloc(sizeof(struct wish));
383+ initw(wp->next);
384+ }
385+ wp = wp->next;
386+ position = 2;
387+ }
388+ store_1config(node, wp, &position);
389+ parse_node(node->children, depth + 1, wp, ap);
390+ }
391+}
392+
393+void
394+ginn_config_store(const struct ginn_config *cfg, struct wish *w,
395+ struct apps *a)
396+{
397+ const xmlNode *root = xmlDocGetRootElement(cfg->doc);
398+ parse_node(root, 0, w, a);
399 }
400
401 void ginn_config_print(const struct ginn_config *cfg)
402 {
403- const xmlNode *root = xmlDocGetRootElement(cfg->doc);
404- print_node(root, 0);
405+ const xmlNode *root = xmlDocGetRootElement(cfg->doc);
406+ print_node(root, 0);
407 }
408-
409
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 #define GINN_DEFAULT_ACCUMULATE 1
415
416 typedef struct ginn_config {
417- xmlDocPtr doc;
418- xmlNodePtr root;
419+ xmlDocPtr doc;
420+ xmlNodePtr root;
421 } cfg;
422
423 typedef struct att {
424- char *attrName ;
425- float val ;
426- float valMax;
427- int accumulate;
428- float accumVal;
429+ char *attrName;
430+ float val;
431+ float valMax;
432+ int accumulate;
433+ float accumVal;
434 } att;
435
436 typedef struct wish {
437- att config_attr[25];
438- char *key;
439- int button;
440- char *modifiers[4];
441- struct wish* next;
442- int when;
443+ att config_attr[25];
444+ char *key;
445+ int button;
446+ char *modifiers[4];
447+ struct wish *next;
448+ int when;
449 } wish;
450
451 typedef struct apps {
452- char *appName;
453- struct wish *wp;
454- struct apps *next;
455+ char *appName;
456+ struct wish *wp;
457+ struct apps *next;
458 } apps;
459
460-#endif /* GINN_CONFIG_H */
461+#endif /* GINN_CONFIG_H */
462
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 #include <X11/Xlib.h>
468 #include <X11/keysym.h>
469
470-att config_attr[25] = { [0 ... 24] = {.attrName="", .val=0, .valMax=0 } };
471+att config_attr[25] = {[0 ... 24] = {.attrName = "",.val = 0,.valMax = 0}
472+};
473
474-wish w1 = { .config_attr = { [0 ... 24] = {.attrName="", .val=0, .valMax=0 } },
475- .key ="",
476- .next=NULL };
477+wish w1 = {.config_attr = {[0 ... 24] =
478+ {.attrName = "",.val = 0,.valMax = 0}
479+ }
480+,
481+.key = "",
482+.next = NULL
483+};
484
485 wish *wp, *wpEnd;
486 apps *ap;
487
488-static int
489-inside (float x, float a, float b){
490- return ((x<=b) && (x>=a));
491-}
492-
493-void
494-initw(struct wish *wp) {
495- int i;
496- wp->button=0;
497- wp->key="";
498- wp->next=NULL;
499- for(i=0 ; i<4 ; i++)
500- wp->modifiers[i]="";
501- for(i=0 ; i<25 ; i++ ) {
502- wp->config_attr[i].attrName="";
503- wp->config_attr[i].val=0;
504- wp->config_attr[i].valMax=0;
505- }
506-}
507-
508-void
509-inita(struct apps *ap) {
510- ap->next=NULL;
511- ap->wp =NULL;
512- ap->appName="";
513-}
514-
515-static void clear_accum_attrs(att *attrs){
516- int i = 0;
517- while (strcmp(attrs[i].attrName, "") != 0){
518- if (attrs[i].accumulate) attrs[i].accumVal = 0;
519- i++;
520- }
521-}
522-
523-static void
524-update_wishes()
525-{
526- char *activeApp;
527- apps* tmpAp = ap;
528- int diff=0;
529-
530- activeApp = (char*)getCurrentApp();
531- printf(" --ActiveApp %s\n",activeApp);
532- if (activeApp)
533- diff = strcmp(activeApp,ap->appName);
534-
535- while ( diff && ap->next ) {
536- ap = ap->next;
537- diff = strcmp(activeApp,ap->appName);
538- }
539-
540- if (!diff)
541- wpEnd->next = ap->wp;
542- else
543- wpEnd->next = NULL;
544-
545- ap = tmpAp;
546-}
547-
548-static void
549-gesture_match( GeisGestureType gesture_type,
550- GeisGestureId gesture_id,
551- GeisSize attr_count,
552- GeisGestureAttr *attrs,
553- int state)
554-{
555- struct wish *topw;
556- topw=wp;
557- update_wishes();
558- while (wp && ( 0!=strcmp(wp->key,"") || wp->button )) {
559- int valid=1;
560- if (gesture_type==wp->config_attr[0].val && attrs[8].integer_val==wp->config_attr[1].val) {
561- int attrsI=9, cAttrI=2;
562- do {
563- if (0==strcmp(attrs[attrsI].name, wp->config_attr[cAttrI].attrName)){
564- printf("DEBUG -- comparing %s %s : ", attrs[attrsI].name, wp->config_attr[cAttrI].attrName);
565- printf("%.2f %.2f %.2f \n", attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax);
566- printf("%i \n", inside(attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax));
567- if (wp->config_attr[cAttrI].accumulate){
568- wp->config_attr[cAttrI].accumVal += attrs[attrsI].float_val;
569- valid= valid && inside(wp->config_attr[cAttrI].accumVal, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax);
570- }
571- else valid = valid && inside(attrs[attrsI].float_val, wp->config_attr[cAttrI].val, wp->config_attr[cAttrI].valMax);
572- attrsI++; cAttrI++;
573- } else attrsI++;
574- } while ( (0!=strcmp(wp->config_attr[cAttrI].attrName,"")) && attrsI<18 );
575- if (valid && wp->when == state){
576- if ((0!=wp->button) && (0 != strcmp(wp->key, "")))
577- { injMixBtnKey(XStringToKeysym(wp->key), wp->button, wp->modifiers);
578- printf("MIX -- MIX");
579-}
580- else {
581- if (0!=wp->button)
582- injButton(wp->button, wp->modifiers);
583- if (0 != strcmp(wp->key, ""))
584- injKey(XStringToKeysym(wp->key), wp->modifiers);
585- }
586- clear_accum_attrs(wp->config_attr);
587- }
588- }
589- if (state == GINN_FINISH) clear_accum_attrs(wp->config_attr);
590- wp=wp->next;
591- }
592- wp=topw;
593+static int inside(float x, float a, float b)
594+{
595+ return ((x <= b) && (x >= a));
596+}
597+
598+void initw(struct wish *wp)
599+{
600+ int i;
601+ wp->button = 0;
602+ wp->key = "";
603+ wp->next = NULL;
604+ for (i = 0; i < 4; i++)
605+ wp->modifiers[i] = "";
606+ for (i = 0; i < 25; i++) {
607+ wp->config_attr[i].attrName = "";
608+ wp->config_attr[i].val = 0;
609+ wp->config_attr[i].valMax = 0;
610+ }
611+}
612+
613+void inita(struct apps *ap)
614+{
615+ ap->next = NULL;
616+ ap->wp = NULL;
617+ ap->appName = "";
618+}
619+
620+static void clear_accum_attrs(att * attrs)
621+{
622+ int i = 0;
623+ while (strcmp(attrs[i].attrName, "") != 0) {
624+ if (attrs[i].accumulate)
625+ attrs[i].accumVal = 0;
626+ i++;
627+ }
628+}
629+
630+static void update_wishes()
631+{
632+ char *activeApp;
633+ apps *tmpAp = ap;
634+ int diff = 0;
635+
636+ activeApp = (char *) getCurrentApp();
637+ printf(" --ActiveApp %s\n", activeApp);
638+ if (activeApp)
639+ diff = strcmp(activeApp, ap->appName);
640+
641+ while (diff && ap->next) {
642+ ap = ap->next;
643+ diff = strcmp(activeApp, ap->appName);
644+ }
645+
646+ if (!diff)
647+ wpEnd->next = ap->wp;
648+ else
649+ wpEnd->next = NULL;
650+
651+ ap = tmpAp;
652+}
653+
654+static void
655+gesture_match(GeisGestureType gesture_type,
656+ GeisGestureId gesture_id,
657+ GeisSize attr_count, GeisGestureAttr * attrs, int state)
658+{
659+ struct wish *topw;
660+ topw = wp;
661+ update_wishes();
662+ while (wp && (0 != strcmp(wp->key, "") || wp->button)) {
663+ int valid = 1;
664+ if (gesture_type == wp->config_attr[0].val
665+ && attrs[8].integer_val == wp->config_attr[1].val) {
666+ int attrsI = 9, cAttrI = 2;
667+ do {
668+ if (0 ==
669+ strcmp(attrs[attrsI].name,
670+ wp->config_attr[cAttrI].attrName)) {
671+ printf("DEBUG -- comparing %s %s : ",
672+ attrs[attrsI].name,
673+ wp->config_attr[cAttrI].attrName);
674+ printf("%.2f %.2f %.2f \n",
675+ attrs[attrsI].float_val,
676+ wp->config_attr[cAttrI].val,
677+ wp->config_attr[cAttrI].valMax);
678+ printf("%i \n",
679+ inside(attrs[attrsI].float_val,
680+ wp->config_attr[cAttrI].val,
681+ wp->config_attr[cAttrI].valMax));
682+ if (wp->config_attr[cAttrI].accumulate) {
683+ wp->config_attr[cAttrI].accumVal +=
684+ attrs[attrsI].float_val;
685+ valid = valid
686+ && inside(wp->config_attr
687+ [cAttrI].accumVal,
688+ wp->config_attr
689+ [cAttrI].val,
690+ wp->config_attr[cAttrI].valMax);
691+ } else
692+ valid = valid
693+ && inside(attrs[attrsI].float_val,
694+ wp->config_attr
695+ [cAttrI].val,
696+ wp->config_attr[cAttrI].valMax);
697+ attrsI++;
698+ cAttrI++;
699+ } else
700+ attrsI++;
701+ } while ((0 != strcmp(wp->config_attr[cAttrI].attrName, ""))
702+ && attrsI < 18);
703+ if (valid && wp->when == state) {
704+ if ((0 != wp->button)
705+ && (0 != strcmp(wp->key, ""))) {
706+ injMixBtnKey(XStringToKeysym(wp->key),
707+ wp->button, wp->modifiers);
708+ printf("MIX -- MIX");
709+ } else {
710+ if (0 != wp->button)
711+ injButton(wp->button, wp->modifiers);
712+ if (0 != strcmp(wp->key, ""))
713+ injKey(XStringToKeysym(wp->key), wp->modifiers);
714+ }
715+ clear_accum_attrs(wp->config_attr);
716+ }
717+ }
718+ if (state == GINN_FINISH)
719+ clear_accum_attrs(wp->config_attr);
720+ wp = wp->next;
721+ }
722+ wp = topw;
723 }
724
725 static Window getRootWindow()
726 {
727- Display *display = NULL;
728- Window window = 0;
729-
730- display = XOpenDisplay(NULL);
731- if (!display)
732- {
733- fprintf(stderr, "error opening X11 display.\n");
734- exit(1);
735- }
736-
737- window = DefaultRootWindow(display);
738-
739- XCloseDisplay(display);
740-
741- return window;
742+ Display *display = NULL;
743+ Window window = 0;
744+
745+ display = XOpenDisplay(NULL);
746+ if (!display) {
747+ fprintf(stderr, "error opening X11 display.\n");
748+ exit(1);
749+ }
750+
751+ window = DefaultRootWindow(display);
752+
753+ XCloseDisplay(display);
754+
755+ return window;
756 }
757
758-static void
759-print_attr(GeisGestureAttr *attr)
760+static void print_attr(GeisGestureAttr * attr)
761 {
762- fprintf(stdout, "\tattr %s=", attr->name);
763- switch (attr->type)
764- {
765+ fprintf(stdout, "\tattr %s=", attr->name);
766+ switch (attr->type) {
767 case GEIS_ATTR_TYPE_BOOLEAN:
768- fprintf(stdout, "%s\n", attr->boolean_val ? "true" : "false");
769- break;
770+ fprintf(stdout, "%s\n", attr->boolean_val ? "true" : "false");
771+ break;
772 case GEIS_ATTR_TYPE_FLOAT:
773- fprintf(stdout, "%f\n", attr->float_val);
774- break;
775+ fprintf(stdout, "%f\n", attr->float_val);
776+ break;
777 case GEIS_ATTR_TYPE_INTEGER:
778- fprintf(stdout, "%d\n", attr->integer_val);
779- break;
780+ fprintf(stdout, "%d\n", attr->integer_val);
781+ break;
782 case GEIS_ATTR_TYPE_STRING:
783- fprintf(stdout, "\"%s\"\n", attr->string_val);
784- break;
785+ fprintf(stdout, "\"%s\"\n", attr->string_val);
786+ break;
787 default:
788- fprintf(stdout, "<unknown>\n");
789- break;
790- }
791-}
792-
793-static void
794-gesture_added(void *cookie,
795- GeisGestureType gesture_type,
796- GeisGestureId gesture_id,
797- GeisSize attr_count,
798- GeisGestureAttr *attrs)
799-{
800- int i = 0;
801- fprintf(stdout, "Gesture type %d added\n", gesture_type);
802- for (i = 0; i < attr_count; ++i)
803- print_attr(&attrs[i]);
804-}
805-
806-static void
807-gesture_removed(void *cookie,
808- GeisGestureType gesture_type,
809- GeisGestureId gesture_id,
810- GeisSize attr_count,
811- GeisGestureAttr *attrs)
812-{
813- int i = 0;
814- fprintf(stdout, "Gesture type %d removed\n", gesture_type);
815- for (i = 0; i < attr_count; ++i)
816- print_attr(&attrs[i]);
817-}
818-
819-static void
820-gesture_start(void *cookie,
821- GeisGestureType gesture_type,
822- GeisGestureId gesture_id,
823- GeisSize attr_count,
824- GeisGestureAttr *attrs)
825-{
826- int i = 0;
827- fprintf(stdout, "Gesture type %d started\n", gesture_type);
828- for (i = 0; i < attr_count; ++i)
829- print_attr(&attrs[i]);
830-}
831-
832-static void
833-gesture_update(void *cookie,
834- GeisGestureType gesture_type,
835- GeisGestureId gesture_id,
836- GeisSize attr_count,
837- GeisGestureAttr *attrs)
838-{
839- int i = 0;
840- fprintf(stdout, "Gesture type %d updated\n", gesture_type);
841- for (i = 0; i < attr_count; ++i)
842- print_attr(&attrs[i]);
843- gesture_match(gesture_type, gesture_id, attr_count, attrs, GINN_UPDATE);
844-}
845-
846-static void
847-gesture_finish(void *cookie,
848- GeisGestureType gesture_type,
849- GeisGestureId gesture_id,
850- GeisSize attr_count,
851- GeisGestureAttr *attrs)
852-{
853- int i = 0;
854- fprintf(stdout, "Gesture type %d finished\n", gesture_type);
855- for (i = 0; i < attr_count; ++i)
856- ;//print_attr(&attrs[i]);
857- gesture_match(gesture_type, gesture_id, attr_count, attrs, GINN_FINISH);
858-}
859-
860+ fprintf(stdout, "<unknown>\n");
861+ break;
862+ }
863+}
864+
865+static void
866+gesture_added(void *cookie,
867+ GeisGestureType gesture_type,
868+ GeisGestureId gesture_id,
869+ GeisSize attr_count, GeisGestureAttr * attrs)
870+{
871+ int i = 0;
872+ fprintf(stdout, "Gesture type %d added\n", gesture_type);
873+ for (i = 0; i < attr_count; ++i)
874+ print_attr(&attrs[i]);
875+}
876+
877+static void
878+gesture_removed(void *cookie,
879+ GeisGestureType gesture_type,
880+ GeisGestureId gesture_id,
881+ GeisSize attr_count, GeisGestureAttr * attrs)
882+{
883+ int i = 0;
884+ fprintf(stdout, "Gesture type %d removed\n", gesture_type);
885+ for (i = 0; i < attr_count; ++i)
886+ print_attr(&attrs[i]);
887+}
888+
889+static void
890+gesture_start(void *cookie,
891+ GeisGestureType gesture_type,
892+ GeisGestureId gesture_id,
893+ GeisSize attr_count, GeisGestureAttr * attrs)
894+{
895+ int i = 0;
896+ fprintf(stdout, "Gesture type %d started\n", gesture_type);
897+ for (i = 0; i < attr_count; ++i)
898+ print_attr(&attrs[i]);
899+
900+ // In GEIS v1, we know that the focus coords are in attrs 5 and 6
901+ movePointer((int)attrs[5].float_val, (int)attrs[6].float_val);
902+}
903+
904+static void
905+gesture_update(void *cookie,
906+ GeisGestureType gesture_type,
907+ GeisGestureId gesture_id,
908+ GeisSize attr_count, GeisGestureAttr * attrs)
909+{
910+ int i = 0;
911+ fprintf(stdout, "Gesture type %d updated\n", gesture_type);
912+ for (i = 0; i < attr_count; ++i)
913+ print_attr(&attrs[i]);
914+ gesture_match(gesture_type, gesture_id, attr_count, attrs,
915+ GINN_UPDATE);
916+}
917+
918+static void
919+gesture_finish(void *cookie,
920+ GeisGestureType gesture_type,
921+ GeisGestureId gesture_id,
922+ GeisSize attr_count, GeisGestureAttr * attrs)
923+{
924+ int i = 0;
925+ fprintf(stdout, "Gesture type %d finished\n", gesture_type);
926+ for (i = 0; i < attr_count; ++i); //print_attr(&attrs[i]);
927+ gesture_match(gesture_type, gesture_id, attr_count, attrs,
928+ GINN_FINISH);
929+}
930
931 GeisGestureFuncs gesture_funcs = {
932- gesture_added,
933- gesture_removed,
934- gesture_start,
935- gesture_update,
936- gesture_finish
937+ gesture_added,
938+ gesture_removed,
939+ gesture_start,
940+ gesture_update,
941+ gesture_finish
942 };
943
944-
945 /*
946 * Searches for a default config file.
947 *
948 * Returns a pointer to a config file name (which must be freed) or NULL
949 * if no default config file was found.
950 */
951-static char *
952-ginn_default_config()
953-{
954- static const char default_file_name[] = "/wishes.xml";
955- static const char *search_paths[] =
956- {
957- "etc",
958- "../etc",
959- ".",
960- "$HOME/.ginn",
961- GINN_CONFIG_DIR
962- };
963- static const int num_paths = sizeof(search_paths) / sizeof(const char *);
964- int i;
965-
966- for (i=0; i < num_paths; ++i)
967- {
968- struct stat sbuf;
969- char *file_name = NULL;
970-
971- if (strstr(search_paths[i], "$HOME"))
972- {
973- char *home_dir = getenv("HOME");
974- if (!home_dir)
975- {
976- continue;
977- }
978- else
979- {
980- char *cdr = index(search_paths[i], '/');
981- size_t file_name_length = strlen(home_dir)
982- + strlen(cdr)
983- + strlen(default_file_name)
984- + 1;
985- file_name = calloc(file_name_length, sizeof(char));
986- strcpy(file_name, home_dir);
987- strcat(file_name, cdr);
988- }
989- }
990- else
991- {
992- size_t file_name_length = strlen(search_paths[i])
993- + strlen(default_file_name)
994- + 1;
995- file_name = calloc(file_name_length, sizeof(char));
996- strcpy(file_name, search_paths[i]);
997- }
998- strcat(file_name, default_file_name);
999- int sres = stat(file_name, &sbuf);
1000- if (sres == 0)
1001- {
1002- fprintf(stdout, "Using wishes file %s\n", file_name);
1003- return file_name;
1004- }
1005- free(file_name);
1006- }
1007-
1008- return NULL;
1009-}
1010-
1011-
1012-int main(int argc, char* argv[])
1013-{
1014- GeisStatus status = GEIS_UNKNOWN_ERROR;
1015- GeisXcbWinInfo xcb_win_info = {
1016- .display_name = NULL,
1017- .screenp = NULL,
1018- .window_id = getRootWindow()
1019- };
1020- GeisWinInfo win_info = {
1021- GEIS_XCB_FULL_WINDOW,
1022- &xcb_win_info
1023- };
1024- GeisInstance instance;
1025- struct ginn_config cfg;
1026-
1027- const char * sub_gestures_list[]= {
1028- GEIS_GESTURE_TYPE_DRAG2, GEIS_GESTURE_TYPE_DRAG3,
1029- GEIS_GESTURE_TYPE_DRAG4,GEIS_GESTURE_TYPE_DRAG5,
1030- GEIS_GESTURE_TYPE_PINCH2, GEIS_GESTURE_TYPE_PINCH3,
1031- GEIS_GESTURE_TYPE_PINCH4,GEIS_GESTURE_TYPE_PINCH5,
1032- GEIS_GESTURE_TYPE_ROTATE2, GEIS_GESTURE_TYPE_ROTATE3,
1033- GEIS_GESTURE_TYPE_ROTATE4,GEIS_GESTURE_TYPE_ROTATE5,
1034- GEIS_GESTURE_TYPE_TAP2, GEIS_GESTURE_TYPE_TAP3,
1035- GEIS_GESTURE_TYPE_TAP4,GEIS_GESTURE_TYPE_TAP5, NULL };
1036- {
1037- char * config_file_name = NULL;
1038- if (argc < 2) {
1039- fprintf(stderr, "usage: %s <configxml>\n", argv[0]);
1040- config_file_name = ginn_default_config();
1041- if (config_file_name)
1042- {
1043- fprintf(stderr, "using default configuration file %s ... \n",
1044- config_file_name);
1045- }
1046- }
1047- else
1048- {
1049- config_file_name = strdup(argv[1]);
1050- }
1051- if (NULL == config_file_name)
1052- {
1053- fprintf(stderr, "Could not find Ginn wishes\n");
1054- return -1;
1055- }
1056-
1057- if ( ginn_config_open(&cfg, config_file_name) ) {
1058- fprintf(stderr, "Could not load Ginn wishes\n");
1059- return -1;
1060- }
1061- free(config_file_name);
1062- }
1063-
1064- ginn_config_print(&cfg);
1065- ap = (struct apps *) malloc(sizeof(struct apps)); inita(ap);
1066- wp = (struct wish *) malloc(sizeof(struct wish)); initw(wp);
1067- ginn_config_store(&cfg, wp, ap);
1068- wpEnd=wp;
1069- while (wpEnd->next)
1070- wpEnd=wpEnd->next;
1071-
1072- int pos=0;
1073- printf("\n");
1074- while (strcmp(config_attr[pos].attrName,"")) {
1075- printf("DEBUG %d %s %.2f %.2f \n", pos, config_attr[pos].attrName, config_attr[pos].val, config_attr[pos].valMax);
1076- pos++;
1077- }
1078-
1079- status = geis_init(&win_info, &instance);
1080- if (status != GEIS_STATUS_SUCCESS)
1081- {
1082- fprintf(stderr, "error in geis_init\n");
1083- return 1;
1084- }
1085-
1086- status = geis_configuration_supported(instance, GEIS_CONFIG_UNIX_FD);
1087- if (status != GEIS_STATUS_SUCCESS)
1088- {
1089- fprintf(stderr, "GEIS does not support Unix fd\n");
1090- return 1;
1091- }
1092-
1093- int fd = -1;
1094- status = geis_configuration_get_value(instance, GEIS_CONFIG_UNIX_FD, &fd);
1095- if (status != GEIS_STATUS_SUCCESS)
1096- {
1097- fprintf(stderr, "error retrieving GEIS fd\n");
1098- return 1;
1099- }
1100-
1101- status = geis_subscribe(instance,
1102- GEIS_ALL_INPUT_DEVICES,
1103- sub_gestures_list, // GEIS_ALL_GESTURES,
1104- &gesture_funcs,
1105- NULL);
1106- if (status != GEIS_STATUS_SUCCESS)
1107- {
1108- fprintf(stderr, "error subscribing to gestures\n");
1109- return 1;
1110- }
1111-
1112- openDisplay();
1113-
1114- while(1)
1115- {
1116- fd_set read_fds;
1117- FD_ZERO(&read_fds);
1118- FD_SET(fd, &read_fds);
1119- int sstat = select(fd+1, &read_fds, NULL, NULL, NULL);
1120- if (sstat < 0)
1121- {
1122- fprintf(stderr, "error %d in select(): %s\n", errno, strerror(errno));
1123- break;
1124- }
1125-
1126- if (FD_ISSET(fd, &read_fds))
1127- {
1128- geis_event_dispatch(instance);
1129- }
1130- }
1131-
1132- geis_finish(instance);
1133- closeDisplay();
1134- free(wp);
1135- return 0;
1136-}
1137-
1138+static char *ginn_default_config()
1139+{
1140+ static const char default_file_name[] = "/wishes.xml";
1141+ static const char *search_paths[] = {
1142+ "etc",
1143+ "../etc",
1144+ ".",
1145+ "$HOME/.ginn",
1146+ GINN_CONFIG_DIR
1147+ };
1148+ static const int num_paths =
1149+ sizeof(search_paths) / sizeof(const char *);
1150+ int i;
1151+
1152+ for (i = 0; i < num_paths; ++i) {
1153+ struct stat sbuf;
1154+ char *file_name = NULL;
1155+
1156+ if (strstr(search_paths[i], "$HOME")) {
1157+ char *home_dir = getenv("HOME");
1158+ if (!home_dir) {
1159+ continue;
1160+ } else {
1161+ char *cdr = index(search_paths[i], '/');
1162+ size_t file_name_length = strlen(home_dir)
1163+ + strlen(cdr)
1164+ + strlen(default_file_name)
1165+ + 1;
1166+ file_name = calloc(file_name_length, sizeof(char));
1167+ strcpy(file_name, home_dir);
1168+ strcat(file_name, cdr);
1169+ }
1170+ } else {
1171+ size_t file_name_length = strlen(search_paths[i])
1172+ + strlen(default_file_name)
1173+ + 1;
1174+ file_name = calloc(file_name_length, sizeof(char));
1175+ strcpy(file_name, search_paths[i]);
1176+ }
1177+ strcat(file_name, default_file_name);
1178+ int sres = stat(file_name, &sbuf);
1179+ if (sres == 0) {
1180+ fprintf(stdout, "Using wishes file %s\n", file_name);
1181+ return file_name;
1182+ }
1183+ free(file_name);
1184+ }
1185+
1186+ return NULL;
1187+}
1188+
1189+int main(int argc, char *argv[])
1190+{
1191+ GeisStatus status = GEIS_UNKNOWN_ERROR;
1192+ GeisXcbWinInfo xcb_win_info = {
1193+ .display_name = NULL,
1194+ .screenp = NULL,
1195+ .window_id = getRootWindow()
1196+ };
1197+ GeisWinInfo win_info = {
1198+ GEIS_XCB_FULL_WINDOW,
1199+ &xcb_win_info
1200+ };
1201+ GeisInstance instance;
1202+ struct ginn_config cfg;
1203+
1204+ const char *sub_gestures_list[] = {
1205+ GEIS_GESTURE_TYPE_DRAG2, GEIS_GESTURE_TYPE_DRAG3,
1206+ GEIS_GESTURE_TYPE_DRAG4, GEIS_GESTURE_TYPE_DRAG5,
1207+ GEIS_GESTURE_TYPE_PINCH2, GEIS_GESTURE_TYPE_PINCH3,
1208+ GEIS_GESTURE_TYPE_PINCH4, GEIS_GESTURE_TYPE_PINCH5,
1209+ GEIS_GESTURE_TYPE_ROTATE2, GEIS_GESTURE_TYPE_ROTATE3,
1210+ GEIS_GESTURE_TYPE_ROTATE4, GEIS_GESTURE_TYPE_ROTATE5,
1211+ GEIS_GESTURE_TYPE_TAP2, GEIS_GESTURE_TYPE_TAP3,
1212+ GEIS_GESTURE_TYPE_TAP4, GEIS_GESTURE_TYPE_TAP5, NULL
1213+ };
1214+ {
1215+ char *config_file_name = NULL;
1216+ if (argc < 2) {
1217+ fprintf(stderr, "usage: %s <configxml>\n", argv[0]);
1218+ config_file_name = ginn_default_config();
1219+ if (config_file_name) {
1220+ fprintf(stderr,
1221+ "using default configuration file %s ... \n",
1222+ config_file_name);
1223+ }
1224+ } else {
1225+ config_file_name = strdup(argv[1]);
1226+ }
1227+ if (NULL == config_file_name) {
1228+ fprintf(stderr, "Could not find Ginn wishes\n");
1229+ return -1;
1230+ }
1231+
1232+ if (ginn_config_open(&cfg, config_file_name)) {
1233+ fprintf(stderr, "Could not load Ginn wishes\n");
1234+ return -1;
1235+ }
1236+ free(config_file_name);
1237+ }
1238+
1239+ ginn_config_print(&cfg);
1240+ ap = (struct apps *) malloc(sizeof(struct apps));
1241+ inita(ap);
1242+ wp = (struct wish *) malloc(sizeof(struct wish));
1243+ initw(wp);
1244+ ginn_config_store(&cfg, wp, ap);
1245+ wpEnd = wp;
1246+ while (wpEnd->next)
1247+ wpEnd = wpEnd->next;
1248+
1249+ int pos = 0;
1250+ printf("\n");
1251+ while (strcmp(config_attr[pos].attrName, "")) {
1252+ printf("DEBUG %d %s %.2f %.2f \n", pos,
1253+ config_attr[pos].attrName, config_attr[pos].val,
1254+ config_attr[pos].valMax);
1255+ pos++;
1256+ }
1257+
1258+ status = geis_init(&win_info, &instance);
1259+ if (status != GEIS_STATUS_SUCCESS) {
1260+ fprintf(stderr, "error in geis_init\n");
1261+ return 1;
1262+ }
1263+
1264+ status = geis_configuration_supported(instance, GEIS_CONFIG_UNIX_FD);
1265+ if (status != GEIS_STATUS_SUCCESS) {
1266+ fprintf(stderr, "GEIS does not support Unix fd\n");
1267+ return 1;
1268+ }
1269+
1270+ int fd = -1;
1271+ status =
1272+ geis_configuration_get_value(instance, GEIS_CONFIG_UNIX_FD, &fd);
1273+ if (status != GEIS_STATUS_SUCCESS) {
1274+ fprintf(stderr, "error retrieving GEIS fd\n");
1275+ return 1;
1276+ }
1277+
1278+ status = geis_subscribe(instance, GEIS_ALL_INPUT_DEVICES, sub_gestures_list, // GEIS_ALL_GESTURES,
1279+ &gesture_funcs, NULL);
1280+ if (status != GEIS_STATUS_SUCCESS) {
1281+ fprintf(stderr, "error subscribing to gestures\n");
1282+ return 1;
1283+ }
1284+
1285+ openDisplay();
1286+
1287+ while (1) {
1288+ fd_set read_fds;
1289+ FD_ZERO(&read_fds);
1290+ FD_SET(fd, &read_fds);
1291+ int sstat = select(fd + 1, &read_fds, NULL, NULL, NULL);
1292+ if (sstat < 0) {
1293+ fprintf(stderr, "error %d in select(): %s\n", errno,
1294+ strerror(errno));
1295+ break;
1296+ }
1297+
1298+ if (FD_ISSET(fd, &read_fds)) {
1299+ geis_event_dispatch(instance);
1300+ }
1301+ }
1302+
1303+ geis_finish(instance);
1304+ closeDisplay();
1305+ free(wp);
1306+ return 0;
1307+}
1308
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 #include <X11/extensions/XTest.h>
1314 #include <X11/keysym.h>
1315
1316-static Display* disp = NULL;
1317+static Display *disp = NULL;
1318
1319 void openDisplay()
1320 {
1321- disp = XOpenDisplay(NULL);
1322+ disp = XOpenDisplay(NULL);
1323 }
1324
1325 void closeDisplay()
1326 {
1327- XCloseDisplay(disp);
1328-}
1329-
1330-void
1331-injKey(KeySym ks, char * modifiers[])
1332-{
1333- int i;
1334-
1335- for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++)
1336- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), True, CurrentTime);
1337- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), True, CurrentTime);
1338- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), False, CurrentTime);
1339- for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++)
1340- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), False, CurrentTime);
1341-
1342- XFlush(disp);
1343-}
1344-
1345-void
1346-injButton(int btn, char * modifiers[])
1347-{
1348- int i;
1349-
1350- for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++)
1351- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), True, CurrentTime);
1352- XTestFakeButtonEvent(disp, btn, True, CurrentTime);
1353- XTestFakeButtonEvent(disp, btn, False, CurrentTime);
1354- for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++)
1355- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), False, CurrentTime);
1356-
1357- XFlush(disp);
1358-}
1359-
1360-void
1361-injMixBtnKey(KeySym ks, int btn, char * modifiers[])
1362-{
1363- int i;
1364-
1365- XTestFakeButtonEvent(disp, btn, True, CurrentTime);
1366- for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++)
1367- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), True, CurrentTime);
1368- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), True, CurrentTime);
1369- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), False, CurrentTime);
1370- for (i=0 ; i<4 && 0!=strcmp(modifiers[i],"") ; i++)
1371- XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XStringToKeysym(modifiers[i])), False, CurrentTime);
1372- XTestFakeButtonEvent(disp, btn, False, CurrentTime);
1373- XFlush(disp);
1374-}
1375-
1376+ XCloseDisplay(disp);
1377+}
1378+
1379+void movePointer(int x, int y)
1380+{
1381+ XTestFakeMotionEvent(disp, 0, x, y, CurrentTime);
1382+}
1383+
1384+void injKey(KeySym ks, char *modifiers[])
1385+{
1386+ int i;
1387+
1388+ for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++)
1389+ XTestFakeKeyEvent(disp,
1390+ XKeysymToKeycode(disp,
1391+ XStringToKeysym(modifiers
1392+ [i])), True,
1393+ CurrentTime);
1394+ XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), True, CurrentTime);
1395+ XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), False,
1396+ CurrentTime);
1397+ for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++)
1398+ XTestFakeKeyEvent(disp,
1399+ XKeysymToKeycode(disp,
1400+ XStringToKeysym(modifiers
1401+ [i])), False,
1402+ CurrentTime);
1403+
1404+ XFlush(disp);
1405+}
1406+
1407+void injButton(int btn, char *modifiers[])
1408+{
1409+ int i;
1410+
1411+ for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++)
1412+ XTestFakeKeyEvent(disp,
1413+ XKeysymToKeycode(disp,
1414+ XStringToKeysym(modifiers
1415+ [i])), True,
1416+ CurrentTime);
1417+ XTestFakeButtonEvent(disp, btn, True, CurrentTime);
1418+ XTestFakeButtonEvent(disp, btn, False, CurrentTime);
1419+ for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++)
1420+ XTestFakeKeyEvent(disp,
1421+ XKeysymToKeycode(disp,
1422+ XStringToKeysym(modifiers
1423+ [i])), False,
1424+ CurrentTime);
1425+
1426+ XFlush(disp);
1427+}
1428+
1429+void injMixBtnKey(KeySym ks, int btn, char *modifiers[])
1430+{
1431+ int i;
1432+
1433+ XTestFakeButtonEvent(disp, btn, True, CurrentTime);
1434+ for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++)
1435+ XTestFakeKeyEvent(disp,
1436+ XKeysymToKeycode(disp,
1437+ XStringToKeysym(modifiers
1438+ [i])), True,
1439+ CurrentTime);
1440+ XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), True, CurrentTime);
1441+ XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, ks), False,
1442+ CurrentTime);
1443+ for (i = 0; i < 4 && 0 != strcmp(modifiers[i], ""); i++)
1444+ XTestFakeKeyEvent(disp,
1445+ XKeysymToKeycode(disp,
1446+ XStringToKeysym(modifiers
1447+ [i])), False,
1448+ CurrentTime);
1449+ XTestFakeButtonEvent(disp, btn, False, CurrentTime);
1450+ XFlush(disp);
1451+}