kdrive: fix up NewInputDeviceRequest() implementation

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 <ajax@redhat.com>
Signed-off-by: Laércio de Sousa <laerciosousa@sme-mogidascruzes.sp.gov.br>
This commit is contained in:
Laércio de Sousa 2015-12-11 11:43:06 -02:00 committed by Adam Jackson
parent 2c3e876844
commit 6d6fd688ec

View File

@ -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);
pi->options = options;
KdParsePointerOptions(pi);
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) {
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;
}