kdrive: switch to new InputOption API.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Peter Hutterer 2011-10-25 11:40:58 +10:00
parent af3f64fb77
commit 16ac78a53c

View File

@ -344,7 +344,7 @@ KdEnableInput (void)
} }
static KdKeyboardDriver * static KdKeyboardDriver *
KdFindKeyboardDriver (char *name) KdFindKeyboardDriver (const char *name)
{ {
KdKeyboardDriver *ret; KdKeyboardDriver *ret;
@ -361,7 +361,7 @@ KdFindKeyboardDriver (char *name)
} }
static KdPointerDriver * static KdPointerDriver *
KdFindPointerDriver (char *name) KdFindPointerDriver (const char *name)
{ {
KdPointerDriver *ret; KdPointerDriver *ret;
@ -1040,33 +1040,33 @@ KdRemovePointer (KdPointerInfo *pi)
static Bool static Bool
KdGetOptions (InputOption **options, char *string) KdGetOptions (InputOption **options, char *string)
{ {
InputOption *newopt = NULL, **tmpo = NULL; InputOption *newopt = NULL;
char *key = NULL,
*value = NULL;
int tam_key = 0; int tam_key = 0;
newopt = calloc(1, sizeof (InputOption));
if (!newopt)
return FALSE;
for (tmpo = options; *tmpo; tmpo = &(*tmpo)->next)
; /* Hello, I'm here */
*tmpo = newopt;
if (strchr(string, '=')) if (strchr(string, '='))
{ {
tam_key = (strchr(string, '=') - string); tam_key = (strchr(string, '=') - string);
newopt->key = (char *)malloc(tam_key); key = malloc(tam_key);
strncpy(newopt->key, string, tam_key); strncpy(key, string, tam_key);
newopt->key[tam_key] = '\0'; key[tam_key] = '\0';
newopt->value = strdup(strchr(string, '=') + 1); value = strdup(strchr(string, '=') + 1);
} }
else else
{ {
newopt->key = strdup(string); key = strdup(string);
newopt->value = NULL; value = NULL;
} }
newopt->next = NULL;
return TRUE; newopt = input_option_new(*options, key, value);
if (newopt)
*options = newopt;
free(key);
free(value);
return (newopt != NULL);
} }
static void static void
@ -1074,23 +1074,26 @@ KdParseKbdOptions (KdKeyboardInfo *ki)
{ {
InputOption *option = NULL; InputOption *option = NULL;
for (option = ki->options; option; option = option->next) nt_list_for_each_entry(option, ki->options, next)
{ {
if (strcasecmp(option->key, "XkbRules") == 0) const char *key = input_option_get_key(option);
ki->xkbRules = option->value; const char *value = input_option_get_value(option);
else if (strcasecmp(option->key, "XkbModel") == 0)
ki->xkbModel = option->value; if (strcasecmp(key, "XkbRules") == 0)
else if (strcasecmp(option->key, "XkbLayout") == 0) ki->xkbRules = strdup(value);
ki->xkbLayout = option->value; else if (strcasecmp(key, "XkbModel") == 0)
else if (strcasecmp(option->key, "XkbVariant") == 0) ki->xkbModel = strdup(value);
ki->xkbVariant = option->value; else if (strcasecmp(key, "XkbLayout") == 0)
else if (strcasecmp(option->key, "XkbOptions") == 0) ki->xkbLayout = strdup(value);
ki->xkbOptions = option->value; else if (strcasecmp(key, "XkbVariant") == 0)
else if (!strcasecmp (option->key, "device")) ki->xkbVariant = strdup(value);
ki->path = strdup(option->value); else if (strcasecmp(key, "XkbOptions") == 0)
ki->xkbOptions = strdup(value);
else if (!strcasecmp (key, "device"))
ki->path = strdup(value);
else else
ErrorF("Kbd option key (%s) of value (%s) not assigned!\n", ErrorF("Kbd option key (%s) of value (%s) not assigned!\n",
option->key, option->value); key, value);
} }
} }
@ -1171,23 +1174,26 @@ KdParsePointerOptions (KdPointerInfo *pi)
{ {
InputOption *option = NULL; InputOption *option = NULL;
for (option = pi->options; option; option = option->next) nt_list_for_each_entry(option, pi->options, next)
{ {
if (!strcmp (option->key, "emulatemiddle")) const char *key = input_option_get_key(option);
const char *value = input_option_get_value(option);
if (!strcmp (key, "emulatemiddle"))
pi->emulateMiddleButton = TRUE; pi->emulateMiddleButton = TRUE;
else if (!strcmp (option->key, "noemulatemiddle")) else if (!strcmp (key, "noemulatemiddle"))
pi->emulateMiddleButton = FALSE; pi->emulateMiddleButton = FALSE;
else if (!strcmp (option->key, "transformcoord")) else if (!strcmp (key, "transformcoord"))
pi->transformCoordinates = TRUE; pi->transformCoordinates = TRUE;
else if (!strcmp (option->key, "rawcoord")) else if (!strcmp (key, "rawcoord"))
pi->transformCoordinates = FALSE; pi->transformCoordinates = FALSE;
else if (!strcasecmp (option->key, "device")) else if (!strcasecmp (key, "device"))
pi->path = strdup(option->value); pi->path = strdup(value);
else if (!strcasecmp (option->key, "protocol")) else if (!strcasecmp (key, "protocol"))
pi->protocol = strdup(option->value); pi->protocol = strdup(value);
else else
ErrorF("Pointer option key (%s) of value (%s) not assigned!\n", ErrorF("Pointer option key (%s) of value (%s) not assigned!\n",
option->key, option->value); key, value);
} }
} }
@ -2216,14 +2222,17 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
KdPointerInfo *pi = NULL; KdPointerInfo *pi = NULL;
KdKeyboardInfo *ki = NULL; KdKeyboardInfo *ki = NULL;
for (option = options; option; option = option->next) { nt_list_for_each_entry(option, options, next) {
if (strcmp(option->key, "type") == 0) { const char *key = input_option_get_key(option);
if (strcmp(option->value, "pointer") == 0) { const char *value = input_option_get_value(option);
if (strcmp(key, "type") == 0) {
if (strcmp(value, "pointer") == 0) {
pi = KdNewPointer(); pi = KdNewPointer();
if (!pi) if (!pi)
return BadAlloc; return BadAlloc;
} }
else if (strcmp(option->value, "keyboard") == 0) { else if (strcmp(value, "keyboard") == 0) {
ki = KdNewKeyboard(); ki = KdNewKeyboard();
if (!ki) if (!ki)
return BadAlloc; return BadAlloc;
@ -2234,16 +2243,16 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
} }
} }
#ifdef CONFIG_HAL #ifdef CONFIG_HAL
else if (strcmp(option->key, "_source") == 0 && else if (strcmp(key, "_source") == 0 &&
strcmp(option->value, "server/hal") == 0) strcmp(value, "server/hal") == 0)
{ {
ErrorF("Ignoring device from HAL.\n"); ErrorF("Ignoring device from HAL.\n");
return BadValue; return BadValue;
} }
#endif #endif
#ifdef CONFIG_UDEV #ifdef CONFIG_UDEV
else if (strcmp(option->key, "_source") == 0 && else if (strcmp(key, "_source") == 0 &&
strcmp(option->value, "server/udev") == 0) strcmp(value, "server/udev") == 0)
{ {
ErrorF("Ignoring device from udev.\n"); ErrorF("Ignoring device from udev.\n");
return BadValue; return BadValue;
@ -2258,16 +2267,19 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
/* FIXME: change this code below to use KdParseKbdOptions and /* FIXME: change this code below to use KdParseKbdOptions and
* KdParsePointerOptions */ * KdParsePointerOptions */
for (option = options; option; option = option->next) { nt_list_for_each_entry(option, options, next) {
if (strcmp(option->key, "device") == 0) { const char *key = input_option_get_key(option);
if (pi && option->value) const char *value = input_option_get_value(option);
pi->path = strdup(option->value);
else if (ki && option->value) if (strcmp(key, "device") == 0) {
ki->path = strdup(option->value); if (pi && value)
pi->path = strdup(value);
else if (ki && value)
ki->path = strdup(value);
} }
else if (strcmp(option->key, "driver") == 0) { else if (strcmp(key, "driver") == 0) {
if (pi) { if (pi) {
pi->driver = KdFindPointerDriver(option->value); pi->driver = KdFindPointerDriver(value);
if (!pi->driver) { if (!pi->driver) {
ErrorF("couldn't find driver!\n"); ErrorF("couldn't find driver!\n");
KdFreePointer(pi); KdFreePointer(pi);
@ -2276,7 +2288,7 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
pi->options = options; pi->options = options;
} }
else if (ki) { else if (ki) {
ki->driver = KdFindKeyboardDriver(option->value); ki->driver = KdFindKeyboardDriver(value);
if (!ki->driver) { if (!ki->driver) {
ErrorF("couldn't find driver!\n"); ErrorF("couldn't find driver!\n");
KdFreeKeyboard(ki); KdFreeKeyboard(ki);