In the future, xsetwacom should support a --set Button1 "key a b c button 1
key a" mapping. This is the first step towards it.

Signed-off-by: Peter Hutterer <[email protected]>
---
 tools/xsetwacom.c |   55 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
index 68574b6..8996758 100644
--- a/tools/xsetwacom.c
+++ b/tools/xsetwacom.c
@@ -1126,6 +1126,30 @@ static int is_modifier(const char* modifier)
        return 0;
 }
 
+static int special_map_keystrokes(int argc, char **argv, unsigned long *ndata, 
unsigned long* data);
+
+/* Valid keywords for the --set ButtonX options */
+struct keywords {
+       const char *keyword;
+       int (*func)(int, char **, unsigned long*, unsigned long *);
+} keywords[] = {
+       {"key", special_map_keystrokes},
+       { NULL, NULL }
+};
+
+static inline int is_valid_keyword(const char *keyword)
+{
+       struct keywords *kw = keywords;
+
+       while(kw->keyword)
+       {
+               if (strcmp(keyword, kw->keyword) == 0)
+                       return 1;
+               kw++;
+       }
+       return 0;
+}
+
 /*
    Map gibberish like "ctrl alt f2" into the matching AC_KEY values.
    Returns 1 on success or 0 otherwise.
@@ -1143,6 +1167,9 @@ static int special_map_keystrokes(int argc, char **argv, 
unsigned long *ndata, u
 
                if (strlen(key) > 1)
                {
+                       if (is_valid_keyword(key))
+                               break;
+
                        switch(key[0])
                        {
                                case '+':
@@ -1253,14 +1280,6 @@ static void special_map_buttons(Display *dpy, XDevice 
*dev, param_t* param, int
        int nwords = 0;
        char **words = NULL;
 
-       struct keywords {
-               const char *keyword;
-               int (*func)(int, char **, unsigned long*, unsigned long *);
-       } keywords[] = {
-               {"key", special_map_keystrokes},
-               { NULL, NULL }
-       };
-
        TRACE("Special %s map for device %ld.\n", param->name, dev->device_id);
 
        if (slen >= strlen(param->name) || strncmp(param->name, "Button", slen))
@@ -1300,12 +1319,22 @@ static void special_map_buttons(Display *dpy, XDevice 
*dev, param_t* param, int
        words = strjoinsplit(argc, argv, &nwords);
        for (i = 0; i < nwords; i++)
        {
-               int j;
-               for (j = 0; keywords[j].keyword; j++)
+               int j = 0;
+               while (keywords[j].keyword && i < nwords)
+               {
+                       int parsed = 0;
                        if (strcasecmp(words[i], keywords[j].keyword) == 0)
-                               i += keywords[j].func(nwords - i - 1,
-                                                     &words[i + 1],
-                                                     &nitems, data);
+                       {
+                               parsed = keywords[j].func(nwords - i - 1,
+                                                         &words[i + 1],
+                                                         &nitems, data);
+                               i += parsed;
+                       }
+                       if (parsed)
+                               j = parsed = 0; /* restart with first keyword */
+                       else
+                               j++;
+               }
        }
 
        XChangeDeviceProperty(dpy, dev, prop, XA_INTEGER, 32,
-- 
1.6.6.1


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to