[PATCH v5 RESEND RFC 02/10] kdrive: fix up NewInputDeviceRequest() implementation

Laércio de Sousa laerciosousa at sme-mogidascruzes.sp.gov.br
Mon Aug 24 05:44:54 PDT 2015


This patch simplifies NewInputDeviceRequest() implementation
in kinput.c, making use of improved KdParseKbdOptions()/KdParsePointerOptions()
and merging several "if (ki)"/"if (pi)" clauses.

Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
---
 hw/kdrive/src/kinput.c | 76 ++++++++++++++++++++------------------------------
 1 file changed, 30 insertions(+), 46 deletions(-)

diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 057f53b..12e9128 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1080,6 +1080,8 @@ KdParseKbdOptions(KdKeyboardInfo * ki)
             ki->xkbOptions = strdup(value);
         else if (!strcasecmp(key, "device"))
             ki->path = strdup(value);
+        else if (!strcasecmp(key, "driver"))
+            ki->driver = KdFindKeyboardDriver(value);
         else
             ErrorF("Kbd option key (%s) of value (%s) not assigned!\n",
                    key, value);
@@ -1160,18 +1162,20 @@ KdParsePointerOptions(KdPointerInfo * pi)
         const char *key = input_option_get_key(option);
         const char *value = input_option_get_value(option);
 
-        if (!strcmp(key, "emulatemiddle"))
+        if (!strcasecmp(key, "emulatemiddle"))
             pi->emulateMiddleButton = TRUE;
-        else if (!strcmp(key, "noemulatemiddle"))
+        else if (!strcasecmp(key, "noemulatemiddle"))
             pi->emulateMiddleButton = FALSE;
-        else if (!strcmp(key, "transformcoord"))
+        else if (!strcasecmp(key, "transformcoord"))
             pi->transformCoordinates = TRUE;
-        else if (!strcmp(key, "rawcoord"))
+        else if (!strcasecmp(key, "rawcoord"))
             pi->transformCoordinates = FALSE;
         else if (!strcasecmp(key, "device"))
             pi->path = strdup(value);
         else if (!strcasecmp(key, "protocol"))
             pi->protocol = strdup(value);
+        else if (!strcasecmp(key, "driver"))
+            pi->driver = KdFindPointerDriver(value);
         else
             ErrorF("Pointer option key (%s) of value (%s) not assigned!\n",
                    key, value);
@@ -2187,68 +2191,48 @@ NewInputDeviceRequest(InputOption *options, InputAttributes * attrs,
 #endif
     }
 
-    if (!ki && !pi) {
-        ErrorF("unrecognised device identifier!\n");
-        return BadValue;
-    }
-
-    /* FIXME: change this code below to use KdParseKbdOptions and
-     * KdParsePointerOptions */
-    nt_list_for_each_entry(option, options, list.next) {
-        const char *key = input_option_get_key(option);
-        const char *value = input_option_get_value(option);
+    if (pi) {
+        pi->options = options;
+        KdParsePointerOptions(pi);
 
-        if (strcmp(key, "device") == 0) {
-            if (pi && value)
-                pi->path = strdup(value);
-            else if (ki && value)
-                ki->path = strdup(value);
-        }
-        else if (strcmp(key, "driver") == 0) {
-            if (pi) {
-                pi->driver = KdFindPointerDriver(value);
-                if (!pi->driver) {
-                    ErrorF("couldn't find driver!\n");
-                    KdFreePointer(pi);
-                    return BadValue;
-                }
-                pi->options = options;
-            }
-            else if (ki) {
-                ki->driver = KdFindKeyboardDriver(value);
-                if (!ki->driver) {
-                    ErrorF("couldn't find driver!\n");
-                    KdFreeKeyboard(ki);
-                    return BadValue;
-                }
-                ki->options = options;
-            }
+        if (!pi->driver) {
+            ErrorF("couldn't find driver!\n");
+            KdFreePointer(pi);
+            return BadValue;
         }
-    }
 
-    if (pi) {
         if (KdAddPointer(pi) != Success ||
             ActivateDevice(pi->dixdev, TRUE) != Success ||
             EnableDevice(pi->dixdev, TRUE) != TRUE) {
             ErrorF("couldn't add or enable pointer\n");
             return BadImplementation;
         }
+
+        *pdev = pi->dixdev;
     }
     else if (ki) {
+        ki->options = options;
+        KdParseKbdOptions(ki);
+
+        if (!ki->driver) {
+            ErrorF("couldn't find driver!\n");
+            KdFreeKeyboard(ki);
+            return BadValue;
+        }
+
         if (KdAddKeyboard(ki) != Success ||
             ActivateDevice(ki->dixdev, TRUE) != Success ||
             EnableDevice(ki->dixdev, TRUE) != TRUE) {
             ErrorF("couldn't add or enable keyboard\n");
             return BadImplementation;
         }
-    }
 
-    if (pi) {
-        *pdev = pi->dixdev;
-    }
-    else if (ki) {
         *pdev = ki->dixdev;
     }
+    else {
+        ErrorF("unrecognised device identifier!\n");
+        return BadValue;
+    }
 
     return Success;
 }
-- 
2.5.0



More information about the xorg-devel mailing list