Commit 6d6fd688 authored by Laércio de Sousa's avatar Laércio de Sousa Committed by Adam Jackson

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's avatarAdam Jackson <ajax@redhat.com>
Signed-off-by: Laércio de Sousa's avatarLaércio de Sousa <laerciosousa@sme-mogidascruzes.sp.gov.br>
parent 2c3e8768
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment