From 6d6fd688ecf95f2e84f2af276d681ff42f9d5610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?La=C3=A9rcio=20de=20Sousa?= Date: Fri, 11 Dec 2015 11:43:06 -0200 Subject: [PATCH] kdrive: fix up NewInputDeviceRequest() implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch simplifies NewInputDeviceRequest() implementation in kinput.c, making use of improved KdParseKbdOptions() / KdParsePointerOptions() and merging several "if (ki)"/"if (pi)" clauses. Reviewed-by: Adam Jackson Signed-off-by: LaƩrcio de Sousa --- hw/kdrive/src/kinput.c | 80 +++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 48 deletions(-) diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c index 1fdaa52aa..980fd3ea2 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 (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) { + pi->options = options; + KdParsePointerOptions(pi); + + if (!pi->driver) { + ErrorF("couldn't find driver!\n"); + KdFreePointer(pi); + return BadValue; + } + 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; }