[PATCH kdrive/ephyr v7 1/9] kdrive: fix up NewInputDeviceRequest() implementation

Laércio de Sousa laerciosousa at sme-mogidascruzes.sp.gov.br
Fri Dec 11 05:43:06 PST 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 1fdaa52..980fd3e 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1091,6 +1091,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);
@@ -1171,18 +1173,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);
@@ -2152,68 +2156,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.1.4



More information about the xorg-devel mailing list