From 16ac78a53c1edeae183db8672104587b306cfe13 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 25 Oct 2011 11:40:58 +1000 Subject: [PATCH 01/17] kdrive: switch to new InputOption API. Signed-off-by: Peter Hutterer Reviewed-by: Keith Packard --- hw/kdrive/src/kinput.c | 132 ++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 60 deletions(-) diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c index c14dd8241..15c9ae2eb 100644 --- a/hw/kdrive/src/kinput.c +++ b/hw/kdrive/src/kinput.c @@ -344,7 +344,7 @@ KdEnableInput (void) } static KdKeyboardDriver * -KdFindKeyboardDriver (char *name) +KdFindKeyboardDriver (const char *name) { KdKeyboardDriver *ret; @@ -361,7 +361,7 @@ KdFindKeyboardDriver (char *name) } static KdPointerDriver * -KdFindPointerDriver (char *name) +KdFindPointerDriver (const char *name) { KdPointerDriver *ret; @@ -1040,33 +1040,33 @@ KdRemovePointer (KdPointerInfo *pi) static Bool KdGetOptions (InputOption **options, char *string) { - InputOption *newopt = NULL, **tmpo = NULL; + InputOption *newopt = NULL; + char *key = NULL, + *value = NULL; 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, '=')) { tam_key = (strchr(string, '=') - string); - newopt->key = (char *)malloc(tam_key); - strncpy(newopt->key, string, tam_key); - newopt->key[tam_key] = '\0'; - newopt->value = strdup(strchr(string, '=') + 1); + key = malloc(tam_key); + strncpy(key, string, tam_key); + key[tam_key] = '\0'; + value = strdup(strchr(string, '=') + 1); } else { - newopt->key = strdup(string); - newopt->value = NULL; + key = strdup(string); + 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 @@ -1074,23 +1074,26 @@ KdParseKbdOptions (KdKeyboardInfo *ki) { 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) - ki->xkbRules = option->value; - else if (strcasecmp(option->key, "XkbModel") == 0) - ki->xkbModel = option->value; - else if (strcasecmp(option->key, "XkbLayout") == 0) - ki->xkbLayout = option->value; - else if (strcasecmp(option->key, "XkbVariant") == 0) - ki->xkbVariant = option->value; - else if (strcasecmp(option->key, "XkbOptions") == 0) - ki->xkbOptions = option->value; - else if (!strcasecmp (option->key, "device")) - ki->path = strdup(option->value); + const char *key = input_option_get_key(option); + const char *value = input_option_get_value(option); + + if (strcasecmp(key, "XkbRules") == 0) + ki->xkbRules = strdup(value); + else if (strcasecmp(key, "XkbModel") == 0) + ki->xkbModel = strdup(value); + else if (strcasecmp(key, "XkbLayout") == 0) + ki->xkbLayout = strdup(value); + else if (strcasecmp(key, "XkbVariant") == 0) + ki->xkbVariant = strdup(value); + else if (strcasecmp(key, "XkbOptions") == 0) + ki->xkbOptions = strdup(value); + else if (!strcasecmp (key, "device")) + ki->path = strdup(value); else 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; - 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; - else if (!strcmp (option->key, "noemulatemiddle")) + else if (!strcmp (key, "noemulatemiddle")) pi->emulateMiddleButton = FALSE; - else if (!strcmp (option->key, "transformcoord")) + else if (!strcmp (key, "transformcoord")) pi->transformCoordinates = TRUE; - else if (!strcmp (option->key, "rawcoord")) + else if (!strcmp (key, "rawcoord")) pi->transformCoordinates = FALSE; - else if (!strcasecmp (option->key, "device")) - pi->path = strdup(option->value); - else if (!strcasecmp (option->key, "protocol")) - pi->protocol = strdup(option->value); + else if (!strcasecmp (key, "device")) + pi->path = strdup(value); + else if (!strcasecmp (key, "protocol")) + pi->protocol = strdup(value); else 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; KdKeyboardInfo *ki = NULL; - for (option = options; option; option = option->next) { - if (strcmp(option->key, "type") == 0) { - if (strcmp(option->value, "pointer") == 0) { + nt_list_for_each_entry(option, options, next) { + const char *key = input_option_get_key(option); + const char *value = input_option_get_value(option); + + if (strcmp(key, "type") == 0) { + if (strcmp(value, "pointer") == 0) { pi = KdNewPointer(); if (!pi) return BadAlloc; } - else if (strcmp(option->value, "keyboard") == 0) { + else if (strcmp(value, "keyboard") == 0) { ki = KdNewKeyboard(); if (!ki) return BadAlloc; @@ -2234,16 +2243,16 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs, } } #ifdef CONFIG_HAL - else if (strcmp(option->key, "_source") == 0 && - strcmp(option->value, "server/hal") == 0) + else if (strcmp(key, "_source") == 0 && + strcmp(value, "server/hal") == 0) { ErrorF("Ignoring device from HAL.\n"); return BadValue; } #endif #ifdef CONFIG_UDEV - else if (strcmp(option->key, "_source") == 0 && - strcmp(option->value, "server/udev") == 0) + else if (strcmp(key, "_source") == 0 && + strcmp(value, "server/udev") == 0) { ErrorF("Ignoring device from udev.\n"); return BadValue; @@ -2258,16 +2267,19 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs, /* FIXME: change this code below to use KdParseKbdOptions and * KdParsePointerOptions */ - for (option = options; option; option = option->next) { - if (strcmp(option->key, "device") == 0) { - if (pi && option->value) - pi->path = strdup(option->value); - else if (ki && option->value) - ki->path = strdup(option->value); + nt_list_for_each_entry(option, options, 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(option->key, "driver") == 0) { + else if (strcmp(key, "driver") == 0) { if (pi) { - pi->driver = KdFindPointerDriver(option->value); + pi->driver = KdFindPointerDriver(value); if (!pi->driver) { ErrorF("couldn't find driver!\n"); KdFreePointer(pi); @@ -2276,7 +2288,7 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs, pi->options = options; } else if (ki) { - ki->driver = KdFindKeyboardDriver(option->value); + ki->driver = KdFindKeyboardDriver(value); if (!ki->driver) { ErrorF("couldn't find driver!\n"); KdFreeKeyboard(ki); From c39c8d34282b82d73c3c69a16cf0c2816256d85b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 10 Aug 2011 14:38:58 +1000 Subject: [PATCH 02/17] input: switch InputOption to use XF86OptionRec storage. Use the same struct for both InputOption and XF86OptionRec so we don't need to convert to and fro the two in the config backends. Signed-off-by: Peter Hutterer Reviewed-by: Dan Nicholson Reviewed-by: Daniel Stone --- dix/inpututils.c | 34 ++++++++++++++++--------------- hw/kdrive/src/kinput.c | 9 ++++---- hw/xfree86/common/xf86Option.c | 1 + hw/xfree86/common/xf86Optionstr.h | 13 ++---------- hw/xfree86/common/xf86Xinput.c | 5 +++-- hw/xfree86/parser/Flags.c | 5 +++-- hw/xfree86/parser/Layout.c | 2 +- include/inputstr.h | 7 ------- include/list.h | 12 +++++++++++ include/optionstr.h | 14 +++++++++++++ 10 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 include/optionstr.h diff --git a/dix/inpututils.c b/dix/inpututils.c index 2915e6766..5797f9256 100644 --- a/dix/inpututils.c +++ b/dix/inpututils.c @@ -38,6 +38,7 @@ #include "inpututils.h" #include "eventstr.h" #include "scrnintstr.h" +#include "optionstr.h" /* Check if a button map change is okay with the device. * Returns -1 for BadValue, as it collides with MappingBusy. */ @@ -670,8 +671,9 @@ point_on_screen(ScreenPtr pScreen, int x, int y) static void input_option_free(InputOption *o) { - free(o->key); - free(o->value); + free(o->opt_name); + free(o->opt_val); + free(o->opt_comment); free(o); } @@ -701,7 +703,7 @@ input_option_new(InputOption* list, const char *key, const char *value) if (list) { - nt_list_for_each_entry(opt, list, next) + nt_list_for_each_entry(opt, list, list.next) { if (strcmp(input_option_get_key(opt), key) == 0) { @@ -715,13 +717,13 @@ input_option_new(InputOption* list, const char *key, const char *value) if (!opt) return NULL; - nt_list_init(opt, next); + nt_list_init(opt, list.next); input_option_set_key(opt, key); input_option_set_value(opt, value); if (list) { - nt_list_append(opt, list, InputOption, next); + nt_list_append(opt, list, InputOption, list.next); return list; } else return opt; @@ -732,9 +734,9 @@ input_option_free_element(InputOption *list, const char *key) { InputOption *element; - nt_list_for_each_entry(element, list, next) { + nt_list_for_each_entry(element, list, list.next) { if (strcmp(input_option_get_key(element), key) == 0) { - nt_list_del(element, list, InputOption, next); + nt_list_del(element, list, InputOption, list.next); input_option_free(element); break; } @@ -750,8 +752,8 @@ input_option_free_list(InputOption **opt) { InputOption *element, *tmp; - nt_list_for_each_entry_safe(element, tmp, *opt, next) { - nt_list_del(element, *opt, InputOption, next); + nt_list_for_each_entry_safe(element, tmp, *opt, list.next) { + nt_list_del(element, *opt, InputOption, list.next); input_option_free(element); } *opt = NULL; @@ -768,7 +770,7 @@ input_option_find(InputOption *list, const char *key) { InputOption *element; - nt_list_for_each_entry(element, list, next) { + nt_list_for_each_entry(element, list, list.next) { if (strcmp(input_option_get_key(element), key) == 0) return element; } @@ -779,29 +781,29 @@ input_option_find(InputOption *list, const char *key) const char* input_option_get_key(const InputOption *opt) { - return opt->key; + return opt->opt_name; } const char* input_option_get_value(const InputOption *opt) { - return opt->value; + return opt->opt_val; } void input_option_set_key(InputOption *opt, const char *key) { - free(opt->key); + free(opt->opt_name); if (key) - opt->key = strdup(key); + opt->opt_name = strdup(key); } void input_option_set_value(InputOption *opt, const char *value) { - free(opt->value); + free(opt->opt_val); if (value) - opt->value = strdup(value); + opt->opt_val = strdup(value); } diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c index 15c9ae2eb..a1bbcaace 100644 --- a/hw/kdrive/src/kinput.c +++ b/hw/kdrive/src/kinput.c @@ -49,6 +49,7 @@ #include "eventstr.h" #include "xserver-properties.h" #include "inpututils.h" +#include "optionstr.h" #define AtomFromName(x) MakeAtom(x, strlen(x), 1) @@ -1074,7 +1075,7 @@ KdParseKbdOptions (KdKeyboardInfo *ki) { InputOption *option = NULL; - nt_list_for_each_entry(option, ki->options, next) + nt_list_for_each_entry(option, ki->options, list.next) { const char *key = input_option_get_key(option); const char *value = input_option_get_value(option); @@ -1174,7 +1175,7 @@ KdParsePointerOptions (KdPointerInfo *pi) { InputOption *option = NULL; - nt_list_for_each_entry(option, pi->options, next) + nt_list_for_each_entry(option, pi->options, list.next) { const char *key = input_option_get_key(option); const char *value = input_option_get_value(option); @@ -2222,7 +2223,7 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs, KdPointerInfo *pi = NULL; KdKeyboardInfo *ki = NULL; - nt_list_for_each_entry(option, options, next) { + 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); @@ -2267,7 +2268,7 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs, /* FIXME: change this code below to use KdParseKbdOptions and * KdParsePointerOptions */ - nt_list_for_each_entry(option, options, next) { + 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); diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c index 73b6573f1..1a1f42ab5 100644 --- a/hw/xfree86/common/xf86Option.c +++ b/hw/xfree86/common/xf86Option.c @@ -44,6 +44,7 @@ #include "xf86Xinput.h" #include "xf86Optrec.h" #include "xf86Parser.h" +#include "optionstr.h" static Bool ParseOptionValue(int scrnIndex, XF86OptionPtr options, OptionInfoPtr p, Bool markUsed); diff --git a/hw/xfree86/common/xf86Optionstr.h b/hw/xfree86/common/xf86Optionstr.h index 8cc82d34c..fc9385617 100644 --- a/hw/xfree86/common/xf86Optionstr.h +++ b/hw/xfree86/common/xf86Optionstr.h @@ -24,16 +24,7 @@ #ifndef XF86OPTIONSTR_H #define XF86OPTIONSTR_H - -/* - * all records that need to be linked lists should contain a GenericList as - * their first field. - */ -typedef struct generic_list_rec -{ - void *next; -} -GenericListRec, *GenericListPtr, *glp; +#include "list.h" /* * All options are stored using this data type. @@ -48,6 +39,6 @@ typedef struct _XF86OptionRec } XF86OptionRec; -typedef struct _XF86OptionRec *XF86OptionPtr; +typedef struct _InputOption *XF86OptionPtr; #endif diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c index ea1f92761..425b35957 100644 --- a/hw/xfree86/common/xf86Xinput.c +++ b/hw/xfree86/common/xf86Xinput.c @@ -68,6 +68,7 @@ #include "exglobals.h" #include "eventstr.h" #include "inpututils.h" +#include "optionstr.h" #include /* InputClassMatches */ #ifdef HAVE_FNMATCH_H @@ -908,7 +909,7 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs, if (!pInfo) return BadAlloc; - nt_list_for_each_entry(option, options, next) { + nt_list_for_each_entry(option, options, list.next) { if (strcasecmp(input_option_get_key(option), "driver") == 0) { if (pInfo->driver) { rval = BadRequest; @@ -946,7 +947,7 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs, } } - nt_list_for_each_entry(option, options, next) { + nt_list_for_each_entry(option, options, list.next) { /* Copy option key/value strings from the provided list */ pInfo->options = xf86AddNewOption(pInfo->options, input_option_get_key(option), diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c index 7a0794bb0..f0a61707b 100644 --- a/hw/xfree86/parser/Flags.c +++ b/hw/xfree86/parser/Flags.c @@ -63,6 +63,7 @@ #include "Configint.h" #include #include "Xprintf.h" +#include "optionstr.h" extern LexRec val; @@ -203,7 +204,7 @@ addNewOption2 (XF86OptionPtr head, char *name, char *val, int used) free(new->opt_val); } else - new = calloc (1, sizeof (XF86OptionRec)); + new = calloc (1, sizeof (*new)); new->opt_name = name; new->opt_val = val; new->opt_used = used; @@ -284,7 +285,7 @@ xf86newOption(char *name, char *value) { XF86OptionPtr opt; - opt = calloc(1, sizeof (XF86OptionRec)); + opt = calloc(1, sizeof (*opt)); if (!opt) return NULL; diff --git a/hw/xfree86/parser/Layout.c b/hw/xfree86/parser/Layout.c index e1f770bc3..4487b0df6 100644 --- a/hw/xfree86/parser/Layout.c +++ b/hw/xfree86/parser/Layout.c @@ -63,7 +63,7 @@ #include "xf86tokens.h" #include "Configint.h" #include - +#include "optionstr.h" /* Needed for auto server layout */ extern int xf86CheckBoolOption(void* optlist, const char *name, int deflt); diff --git a/include/inputstr.h b/include/inputstr.h index 9d4108ef5..7a1554075 100644 --- a/include/inputstr.h +++ b/include/inputstr.h @@ -621,11 +621,4 @@ static inline WindowPtr DeepestSpriteWin(SpritePtr sprite) return sprite->spriteTrace[sprite->spriteTraceGood - 1]; } -struct _InputOption { - char *key; - char *value; - struct _InputOption *next; -}; - - #endif /* INPUTSTRUCT_H */ diff --git a/include/list.h b/include/list.h index 7825dce52..4706e178b 100644 --- a/include/list.h +++ b/include/list.h @@ -438,4 +438,16 @@ list_is_empty(struct list *head) nt_list_init(__e, _member); \ } while(0) +/** + * DO NOT USE THIS. + * This is a remainder of the xfree86 DDX attempt of having a set of generic + * list functions. Unfortunately, the xf86OptionRec uses it and we can't + * easily get rid of it. Do not use for new code. + */ +typedef struct generic_list_rec +{ + void *next; +} +GenericListRec, *GenericListPtr, *glp; + #endif diff --git a/include/optionstr.h b/include/optionstr.h new file mode 100644 index 000000000..a71d245fa --- /dev/null +++ b/include/optionstr.h @@ -0,0 +1,14 @@ +#ifndef OPTIONSTR_H_ +#define OPTIONSTR_H_ +#include "list.h" + + +struct _InputOption { + GenericListRec list; + char *opt_name; + char *opt_val; + int opt_used; + char *opt_comment; +}; + +#endif /* INPUTSTRUCT_H */ From aeab26e9e1751e1e3514798fa53e9bd604b0d254 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 10 Aug 2011 15:58:34 +1000 Subject: [PATCH 03/17] xfree86: use xf86AddNewOption instead of xf86addNewOption The former strdups for us. If the strdup fails we miss out on the CorePointer option (default on anyway) and we're likely to fall over soon anyway, so let's pretend this is the same behaviour. Signed-off-by: Peter Hutterer Reviewed-by: Alan Coopersmith Reviewed-by: Daniel Stone --- hw/xfree86/common/xf86Config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index 5c46152b2..96e98c10c 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -1194,8 +1194,8 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) if (Pointer) foundPointer = configInput(Pointer, confInput, from); if (foundPointer) { - Pointer->options = xf86addNewOption(Pointer->options, - xnfstrdup("CorePointer"), "on"); + Pointer->options = xf86AddNewOption(Pointer->options, + "CorePointer", "on"); servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer); } } @@ -1284,8 +1284,8 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) if (Keyboard) foundKeyboard = configInput(Keyboard, confInput, from); if (foundKeyboard) { - Keyboard->options = xf86addNewOption(Keyboard->options, - xnfstrdup("CoreKeyboard"), "on"); + Keyboard->options = xf86AddNewOption(Keyboard->options, + "CoreKeyboard", "on"); servlayoutp->inputs = addDevice(servlayoutp->inputs, Keyboard); } } From f9067c1dd8ce9058eb48a20dfae52bc8cf3a1e55 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 5 Aug 2011 14:05:58 +1000 Subject: [PATCH 04/17] xfree86: Fix a comment, the old function doesn't exist anymore Signed-off-by: Peter Hutterer Reviewed-by: Alan Coopersmith Reviewed-by: Daniel Stone --- hw/xfree86/common/xf86Option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c index 1a1f42ab5..9c528782f 100644 --- a/hw/xfree86/common/xf86Option.c +++ b/hw/xfree86/common/xf86Option.c @@ -299,7 +299,7 @@ xf86CheckPercentOption(XF86OptionPtr optlist, const char *name, double deflt) return LookupPercentOption(optlist, name, deflt, FALSE); } /* - * addNewOption() has the required property of replacing the option value + * xf86AddNewOption() has the required property of replacing the option value * if the option is already present. */ XF86OptionPtr From 1ecc427a39d41e723912492b846512fd0ad9af2d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 10 Aug 2011 14:37:41 +1000 Subject: [PATCH 05/17] dix: move #if statement to stop compiler warning ptrveloc.c: In function 'QueryTrackers': ptrveloc.c:598:34: warning: variable 'used_offset' set but not used [-Wunused-but-set-variable] used_offset is used, but only in the debugging code. Move the #if statement to ignore that warning. Signed-off-by: Peter Hutterer Reviewed-by: Alan Coopersmith Reviewed-by: Daniel Stone --- dix/ptrveloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c index 53a0d0397..7b6f56049 100644 --- a/dix/ptrveloc.c +++ b/dix/ptrveloc.c @@ -649,13 +649,13 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){ DebugAccelF("(dix prtacc) query: last tracker in effect\n"); used_offset = vel->num_tracker-1; } -#ifdef PTRACCEL_DEBUGGING if(used_offset >= 0){ +#ifdef PTRACCEL_DEBUGGING MotionTracker *tracker = TRACKER(vel, used_offset); DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n", used_offset, tracker->dx, tracker->dy, cur_t - tracker->time); - } #endif + } return result; } From e4cd24e717ef1059804b3f6bb483810b708cd56a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 5 Aug 2011 14:48:02 +1000 Subject: [PATCH 06/17] xfree86: use NewInputDeviceRequest for xorg.conf devices too Only use one init path for input devices - through NIDR. This requires that inp_driver and inp_identifier from the XF86ConfInputRec are copied over into the options for NIDR to see them. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- hw/xfree86/common/xf86Config.c | 8 ++++++++ hw/xfree86/common/xf86Init.c | 29 +---------------------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index 96e98c10c..cb4be4210 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -1196,6 +1196,10 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) if (foundPointer) { Pointer->options = xf86AddNewOption(Pointer->options, "CorePointer", "on"); + Pointer->options = xf86AddNewOption(Pointer->options, + "driver", confInput->inp_driver); + Pointer->options = xf86AddNewOption(Pointer->options, + "identifier", confInput->inp_identifier); servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer); } } @@ -1286,6 +1290,10 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) if (foundKeyboard) { Keyboard->options = xf86AddNewOption(Keyboard->options, "CoreKeyboard", "on"); + Keyboard->options = xf86AddNewOption(Keyboard->options, + "driver", confInput->inp_driver); + Keyboard->options = xf86AddNewOption(Keyboard->options, + "identifier", confInput->inp_identifier); servlayoutp->inputs = addDevice(servlayoutp->inputs, Keyboard); } } diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index 74e0bc220..a0fdf29ad 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -811,21 +811,6 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) NULL); } -static InputInfoPtr -duplicateDevice(InputInfoPtr pInfo) -{ - InputInfoPtr dup = calloc(1, sizeof(InputInfoRec)); - if (dup) { - dup->name = strdup(pInfo->name); - dup->driver = strdup(pInfo->driver); - dup->options = xf86OptionListDuplicate(pInfo->options); - /* type_name is a const string */ - dup->type_name = pInfo->type_name; - dup->fd = -1; - } - return dup; -} - /** * Initialize all supported input devices present and referenced in the * xorg.conf. @@ -842,20 +827,8 @@ InitInput(int argc, char **argv) /* Initialize all configured input devices */ for (pInfo = xf86ConfigLayout.inputs; pInfo && *pInfo; pInfo++) { - InputInfoPtr dup; - /* Replace obsolete keyboard driver with kbd */ - if (!xf86NameCmp((*pInfo)->driver, "keyboard")) { - strcpy((*pInfo)->driver, "kbd"); - } - - /* Data passed into xf86NewInputDevice will be freed on shutdown. - * Duplicate from xf86ConfigLayout.inputs, otherwise we don't have any - * xorg.conf input devices in the second generation - */ - dup = duplicateDevice(*pInfo); - /* If one fails, the others will too */ - if (xf86NewInputDevice(dup, &dev, TRUE) == BadAlloc) + if (NewInputDeviceRequest((*pInfo)->options, NULL, &dev) == BadAlloc) break; } From 6f33593dc087d367d899d1cb6e6e30b282d922e2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 21 Oct 2011 09:09:55 +1000 Subject: [PATCH 07/17] xfree86 doc: replace driver "keyboard" with "kbd" We've deprecated keyboard a long time ago Signed-off-by: Peter Hutterer Reviewed-by: Alan Coopersmith --- hw/xfree86/doc/ddxDesign.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml index a4baad557..0d5e952a2 100644 --- a/hw/xfree86/doc/ddxDesign.xml +++ b/hw/xfree86/doc/ddxDesign.xml @@ -189,7 +189,7 @@ following changes: Keyboard &k.identifier; "Implicit Core Keyboard" - &k.driver; "keyboard" + &k.driver; "kbd" Pointer @@ -206,7 +206,7 @@ following changes: is no &k.serverlayout; section, if the command line options is used, or if the &k.serverlayout; section doesn't reference any &k.inputdevice; sections. In this case, the first - sections with drivers "keyboard" and "mouse" are used as the core + sections with drivers "kbd" and "mouse" are used as the core keyboard and pointer respectively. From e3f6a76dd480717eae4b17ad8e2ff707de2ffe4c Mon Sep 17 00:00:00 2001 From: Andreas Wettstein Date: Thu, 11 Aug 2011 16:33:33 +1000 Subject: [PATCH 08/17] xkb: Support noLock and noUnlock flags for LockMods These flags are required by the XKB spec section 6.3. Signed-off-by: Andreas Wettstein Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- xkb/xkbActions.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c index 4b5405ab0..000002a45 100644 --- a/xkb/xkbActions.c +++ b/xkb/xkbActions.c @@ -344,15 +344,18 @@ _XkbFilterLockState( XkbSrvInfoPtr xkbi, filter->keycode = keycode; filter->active = 1; filter->filterOthers = 0; - filter->priv = 0; + filter->priv = xkbi->state.locked_mods&pAction->mods.mask; filter->filter = _XkbFilterLockState; filter->upAction = *pAction; - xkbi->state.locked_mods^= pAction->mods.mask; + if (!(filter->upAction.mods.flags&XkbSA_LockNoLock)) + xkbi->state.locked_mods|= pAction->mods.mask; xkbi->setMods = pAction->mods.mask; } else if (filter->keycode==keycode) { filter->active = 0; xkbi->clearMods = filter->upAction.mods.mask; + if (!(filter->upAction.mods.flags&XkbSA_LockNoUnlock)) + xkbi->state.locked_mods&= ~filter->priv; } return 1; } From 8473e441b0f832775153281bc3df5e2d4feb2b36 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 18 Oct 2011 17:11:27 +1000 Subject: [PATCH 09/17] dix: add ScrollInfo to DeviceChangedEvents 3304bbff9b4ed63f1a47410a5320a136420ba2c6 added smooth scrolling support for pointer events and for XIQueryDevice but didn't add the matching parts to XIDeviceChangedEvents. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- dix/eventconvert.c | 53 ++++++++++++++++++++++++++++++++ dix/getevents.c | 1 + include/eventstr.h | 1 + test/xi2/protocol-eventconvert.c | 20 ++++++++++++ 4 files changed, 75 insertions(+) diff --git a/dix/eventconvert.c b/dix/eventconvert.c index 189cb85d0..ff42b0398 100644 --- a/dix/eventconvert.c +++ b/dix/eventconvert.c @@ -43,8 +43,10 @@ #include "inputstr.h" #include "misc.h" #include "eventstr.h" +#include "exevents.h" #include "exglobals.h" #include "eventconvert.h" +#include "inpututils.h" #include "xiquerydevice.h" #include "xkbsrv.h" @@ -481,6 +483,40 @@ appendValuatorInfo(DeviceChangedEvent *dce, xXIValuatorInfo *info, int axisnumbe return info->length * 4; } +static int +appendScrollInfo(DeviceChangedEvent *dce, xXIScrollInfo *info, int axisnumber) +{ + if (dce->valuators[axisnumber].scroll.type == SCROLL_TYPE_NONE) + return 0; + + info->type = XIScrollClass; + info->length = sizeof(xXIScrollInfo)/4; + info->number = axisnumber; + switch(dce->valuators[axisnumber].scroll.type) + { + case SCROLL_TYPE_VERTICAL: + info->scroll_type = XIScrollTypeVertical; + break; + case SCROLL_TYPE_HORIZONTAL: + info->scroll_type = XIScrollTypeHorizontal; + break; + default: + ErrorF("[Xi] Unknown scroll type %d. This is a bug.\n", dce->valuators[axisnumber].scroll.type); + break; + } + info->increment = double_to_fp3232(dce->valuators[axisnumber].scroll.increment); + info->sourceid = dce->sourceid; + + info->flags = 0; + + if (dce->valuators[axisnumber].scroll.flags & SCROLL_FLAG_DONT_EMULATE) + info->flags |= XIScrollFlagNoEmulation; + if (dce->valuators[axisnumber].scroll.flags & SCROLL_FLAG_PREFERRED) + info->flags |= XIScrollFlagPreferred; + + return info->length * 4; +} + static int eventToDeviceChanged(DeviceChangedEvent *dce, xEvent **xi) { @@ -496,8 +532,16 @@ eventToDeviceChanged(DeviceChangedEvent *dce, xEvent **xi) len += pad_to_int32(bits_to_bytes(dce->buttons.num_buttons)); } if (dce->num_valuators) + { + int i; + len += sizeof(xXIValuatorInfo) * dce->num_valuators; + for (i = 0; i < dce->num_valuators; i++) + if (dce->valuators[i].scroll.type != SCROLL_TYPE_NONE) + len += sizeof(xXIScrollInfo); + } + nkeys = (dce->keys.max_keycode > 0) ? dce->keys.max_keycode - dce->keys.min_keycode + 1 : 0; if (nkeys > 0) @@ -543,6 +587,15 @@ eventToDeviceChanged(DeviceChangedEvent *dce, xEvent **xi) dcce->num_classes += dce->num_valuators; for (i = 0; i < dce->num_valuators; i++) ptr += appendValuatorInfo(dce, (xXIValuatorInfo*)ptr, i); + + for (i = 0; i < dce->num_valuators; i++) + { + if (dce->valuators[i].scroll.type != SCROLL_TYPE_NONE) + { + dcce->num_classes++; + ptr += appendScrollInfo(dce, (xXIScrollInfo*)ptr, i); + } + } } *xi = (xEvent*)dcce; diff --git a/dix/getevents.c b/dix/getevents.c index 7be39dc33..31c69bf0b 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -243,6 +243,7 @@ CreateClassesChangedEvent(InternalEvent* event, dce->valuators[i].resolution = slave->valuator->axes[i].resolution; dce->valuators[i].mode = slave->valuator->axes[i].mode; dce->valuators[i].name = slave->valuator->axes[i].label; + dce->valuators[i].scroll = slave->valuator->axes[i].scroll; } } if (slave->key) diff --git a/include/eventstr.h b/include/eventstr.h index 2de077fd2..4d836fb14 100644 --- a/include/eventstr.h +++ b/include/eventstr.h @@ -153,6 +153,7 @@ struct _DeviceChangedEvent uint32_t resolution; /**< Resolution counts/m */ uint8_t mode; /**< Relative or Absolute */ Atom name; /**< Axis name */ + ScrollInfo scroll; /**< Smooth scrolling info */ } valuators[MAX_VALUATORS]; struct { diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c index bfa23b51f..41a3001ad 100644 --- a/test/xi2/protocol-eventconvert.c +++ b/test/xi2/protocol-eventconvert.c @@ -748,6 +748,26 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in, } break; + case XIScrollClass: + { + xXIScrollInfo *s = (xXIScrollInfo*)any; + assert(s->length == + bytes_to_int32(sizeof(xXIScrollInfo))); + + assert(s->sourceid == in->sourceid); + assert(s->number < in->num_valuators); + switch(s->type) + { + case XIScrollTypeVertical: + assert(in->valuators[s->number].scroll.type == SCROLL_TYPE_VERTICAL); + break; + case XIScrollTypeHorizontal: + assert(in->valuators[s->number].scroll.type == SCROLL_TYPE_HORIZONTAL); + break; + } + if (s->flags & XIScrollFlagPreferred) + assert(in->valuators[s->number].scroll.flags & SCROLL_FLAG_PREFERRED); + } default: printf("Invalid class type.\n\n"); assert(1); From fcdd2587a17437b643b4592aa7f65d11c05a4cd8 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 18 Oct 2011 17:41:29 +1000 Subject: [PATCH 10/17] dix: drop unused argument from XISendDeviceChangedEvent Instead of device and master (and just using master), drop the master argument and let the callers pass in the device the event is to be sent for. No effective functional changes. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- Xi/exevents.c | 6 +++--- dix/devices.c | 2 +- include/exevents.h | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Xi/exevents.c b/Xi/exevents.c index 74a78ecf2..2ae5a62eb 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -651,7 +651,7 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to, DeviceChangedEvent *dc * Send an XI2 DeviceChangedEvent to all interested clients. */ void -XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, DeviceChangedEvent *dce) +XISendDeviceChangedEvent(DeviceIntPtr device, DeviceChangedEvent *dce) { xXIDeviceChangedEvent *dcce; int rc; @@ -665,7 +665,7 @@ XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, DeviceChanged /* we don't actually swap if there's a NullClient, swapping is done * later when event is delivered. */ - SendEventToAllWindows(master, XI_DeviceChangedMask, (xEvent*)dcce, 1); + SendEventToAllWindows(device, XI_DeviceChangedMask, (xEvent*)dcce, 1); free(dcce); } @@ -699,7 +699,7 @@ ChangeMasterDeviceClasses(DeviceIntPtr device, DeviceChangedEvent *dce) /* FIXME: the classes may have changed since we generated the event. */ DeepCopyDeviceClasses(slave, device, dce); - XISendDeviceChangedEvent(slave, device, dce); + XISendDeviceChangedEvent(device, dce); } /** diff --git a/dix/devices.c b/dix/devices.c index 64557aaf1..7c196e077 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -2360,7 +2360,7 @@ RecalculateMasterButtons(DeviceIntPtr slave) event.keys.max_keycode = master->key->xkbInfo->desc->max_key_code; } - XISendDeviceChangedEvent(master, master, &event); + XISendDeviceChangedEvent(master, &event); } } diff --git a/include/exevents.h b/include/exevents.h index 4fe6c61a9..720fb2e5a 100644 --- a/include/exevents.h +++ b/include/exevents.h @@ -322,8 +322,7 @@ extern int XIShouldNotify(ClientPtr client, DeviceIntPtr dev); extern void -XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, - DeviceChangedEvent *dce); +XISendDeviceChangedEvent(DeviceIntPtr device, DeviceChangedEvent *dce); extern int XISetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client, From e9dee21fa3213bfe87b2b728a38eb41d3ba0e664 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 18 Oct 2011 17:47:59 +1000 Subject: [PATCH 11/17] dix: pass the flags into the CreateClassesChangedEvent No effective functional changes, prep work for future patches. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- dix/getevents.c | 7 +++---- include/input.h | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dix/getevents.c b/dix/getevents.c index 31c69bf0b..8057e6296 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -209,7 +209,7 @@ void CreateClassesChangedEvent(InternalEvent* event, DeviceIntPtr master, DeviceIntPtr slave, - int type) + int flags) { int i; DeviceChangedEvent *dce; @@ -223,8 +223,7 @@ CreateClassesChangedEvent(InternalEvent* event, dce->length = sizeof(DeviceChangedEvent); dce->type = ET_DeviceChanged; dce->time = ms; - dce->flags = type; - dce->flags |= DEVCHANGE_SLAVE_SWITCH; + dce->flags = flags; dce->sourceid = slave->id; if (slave->button) @@ -674,7 +673,7 @@ UpdateFromMaster(InternalEvent* events, DeviceIntPtr dev, int type, int *num_eve if (master && master->last.slave != dev) { - CreateClassesChangedEvent(events, master, dev, type); + CreateClassesChangedEvent(events, master, dev, type | DEVCHANGE_SLAVE_SWITCH); if (IsPointerDevice(master)) { updateSlaveDeviceCoords(master, dev); diff --git a/include/input.h b/include/input.h index a1930bb66..4eee47ce4 100644 --- a/include/input.h +++ b/include/input.h @@ -427,7 +427,8 @@ extern _X_EXPORT void FreeEventList(InternalEvent *list, int num_events); extern void CreateClassesChangedEvent(InternalEvent *event, DeviceIntPtr master, DeviceIntPtr slave, - int type); + int flags); + extern InternalEvent * UpdateFromMaster( InternalEvent *events, DeviceIntPtr pDev, From d77dec6971e4a0b306c8dbd5adf627908d7972cb Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 19 Oct 2011 12:11:16 +1000 Subject: [PATCH 12/17] Xi: ensure the deviceid for DeviceChangedEvents is always the right one If we're sending the event for a given device, make sure the deviceid is that of the device. This allows callers to use the same DCE for slave and master without having to fiddle the DCE's internal fields. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- Xi/exevents.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Xi/exevents.c b/Xi/exevents.c index 2ae5a62eb..7afb69e24 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -699,6 +699,7 @@ ChangeMasterDeviceClasses(DeviceIntPtr device, DeviceChangedEvent *dce) /* FIXME: the classes may have changed since we generated the event. */ DeepCopyDeviceClasses(slave, device, dce); + dce->deviceid = device->id; XISendDeviceChangedEvent(device, dce); } From 1f4af6c12fb5d4c19f4eac3df768517c9132cc88 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 19 Oct 2011 12:28:37 +1000 Subject: [PATCH 13/17] dix: accept a NULL master for CreateClassesChangedEvent If a floating device changes, the master is NULL but we must still create a DCE for it. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- dix/getevents.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dix/getevents.c b/dix/getevents.c index 8057e6296..4845a106c 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -218,7 +218,7 @@ CreateClassesChangedEvent(InternalEvent* event, dce = &event->changed_event; memset(dce, 0, sizeof(DeviceChangedEvent)); dce->deviceid = slave->id; - dce->masterid = master->id; + dce->masterid = master ? master->id : 0; dce->header = ET_Internal; dce->length = sizeof(DeviceChangedEvent); dce->type = ET_DeviceChanged; From 4bb5d8fae4f9a70f12591315f0b267a2ea826a0c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 19 Oct 2011 13:17:51 +1000 Subject: [PATCH 14/17] Xi: send DeviceChangedEvents when the scroll valuators change value Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- Xi/exevents.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Xi/exevents.c b/Xi/exevents.c index 7afb69e24..053c76f22 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -1103,6 +1103,8 @@ SetScrollValuator(DeviceIntPtr dev, int axnum, enum ScrollType type, double incr { AxisInfoPtr ax; int *current_ax; + InternalEvent dce; + DeviceIntPtr master; if (!dev || !dev->valuator || axnum >= dev->valuator->numAxes) return FALSE; @@ -1139,7 +1141,16 @@ SetScrollValuator(DeviceIntPtr dev, int axnum, enum ScrollType type, double incr ax->scroll.type = type; ax->scroll.increment = increment; ax->scroll.flags = flags; - /* FIXME: generate DeviceChanged Events */ + + master = GetMaster(dev, MASTER_ATTACHED); + CreateClassesChangedEvent(&dce, master, dev, DEVCHANGE_POINTER_EVENT | DEVCHANGE_DEVICE_CHANGE); + XISendDeviceChangedEvent(dev, &dce.changed_event); + + /* if the current slave is us, update the master. If not, we'll update + * whenever the next slave switch happens anyway. CMDC sends the event + * for us */ + if (master && master->lastSlave == dev) + ChangeMasterDeviceClasses(master, &dce.changed_event); return TRUE; } From 7500d841f4c709ae0edc6420332096d3b9ef9fcc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 20 Oct 2011 16:49:28 +1000 Subject: [PATCH 15/17] test: fix test with new double -> fp3232 conversion functions Signed-off-by: Peter Hutterer Tested-by: Dave Airlie Reviewed-by: Dave Airlie --- test/xi2/protocol-eventconvert.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c index 41a3001ad..ba2d96ad1 100644 --- a/test/xi2/protocol-eventconvert.c +++ b/test/xi2/protocol-eventconvert.c @@ -30,6 +30,7 @@ #include "eventstr.h" #include "eventconvert.h" #include "exevents.h" +#include "inpututils.h" #include static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out, @@ -104,8 +105,7 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out, value = (FP3232*)(((unsigned char*)&out[1]) + out->valuators_len * 4); value += nvals; - vi.integral = trunc(in->valuators.data[i]); - vi.frac = in->valuators.data[i] - vi.integral; + vi = double_to_fp3232(in->valuators.data[i]); vo.integral = value->integral; vo.frac = value->frac; @@ -120,8 +120,7 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out, raw_value = value + bits_set; - vi.integral = trunc(in->valuators.data_raw[i]); - vi.frac = in->valuators.data_raw[i] - vi.integral; + vi = double_to_fp3232(in->valuators.data_raw[i]); vo.integral = raw_value->integral; vo.frac = raw_value->frac; From ffe20acedb3cdc4811eb52f8fc540ba6af7339fa Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 20 Oct 2011 16:42:20 +1000 Subject: [PATCH 16/17] Use new FP1616/FP3232 conversion functions Signed-off-by: Peter Hutterer Reviewed-by: Jeremy Huddleston --- Xi/xiquerydevice.c | 7 +++---- dix/eventconvert.c | 14 ++++---------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c index 9961d1b6f..5f543f620 100644 --- a/Xi/xiquerydevice.c +++ b/Xi/xiquerydevice.c @@ -41,6 +41,7 @@ #include "xserver-properties.h" #include "exevents.h" #include "xace.h" +#include "inpututils.h" #include "xiquerydevice.h" @@ -351,8 +352,7 @@ ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber, info->min.frac = 0; info->max.integral = v->axes[axisnumber].max_value; info->max.frac = 0; - info->value.integral = (int)v->axisVal[axisnumber]; - info->value.frac = (int)(v->axisVal[axisnumber] * (1 << 16) * (1 << 16)); + info->value = double_to_fp3232(v->axisVal[axisnumber]); info->resolution = v->axes[axisnumber].resolution; info->number = axisnumber; info->mode = valuator_get_mode(dev, axisnumber); @@ -402,8 +402,7 @@ ListScrollInfo(DeviceIntPtr dev, xXIScrollInfo *info, int axisnumber) ErrorF("[Xi] Unknown scroll type %d. This is a bug.\n", axis->scroll.type); break; } - info->increment.integral = (int)axis->scroll.increment; - info->increment.frac = (unsigned int)(axis->scroll.increment * (1UL << 16) * (1UL << 16)); + info->increment = double_to_fp3232(axis->scroll.increment); info->sourceid = v->sourceid; info->flags = 0; diff --git a/dix/eventconvert.c b/dix/eventconvert.c index ff42b0398..c9da39685 100644 --- a/dix/eventconvert.c +++ b/dix/eventconvert.c @@ -49,6 +49,7 @@ #include "inpututils.h" #include "xiquerydevice.h" #include "xkbsrv.h" +#include "inpututils.h" static int countValuators(DeviceEvent *ev, int *first); @@ -686,9 +687,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi) if (BitIsOn(ev->valuators.mask, i)) { SetBit(ptr, i); - axisval->integral = trunc(ev->valuators.data[i]); - axisval->frac = (ev->valuators.data[i] - axisval->integral) * - (1 << 16) * (1 << 16); + *axisval = double_to_fp3232(ev->valuators.data[i]); axisval++; } } @@ -732,13 +731,8 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi) if (BitIsOn(ev->valuators.mask, i)) { SetBit(ptr, i); - axisval->integral = trunc(ev->valuators.data[i]); - axisval->frac = (ev->valuators.data[i] - axisval->integral) * - (1 << 16) * (1 << 16); - axisval_raw->integral = trunc(ev->valuators.data_raw[i]); - axisval_raw->frac = - (ev->valuators.data_raw[i] - axisval_raw->integral) * - (1 << 16) * (1 << 16); + *axisval = double_to_fp3232(ev->valuators.data[i]); + *axisval_raw = double_to_fp3232(ev->valuators.data_raw[i]); axisval++; axisval_raw++; } From a41214bc9a0f326c6dc129e4a6382efb8b826862 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 25 Oct 2011 12:57:07 +1000 Subject: [PATCH 17/17] kdrive: check for null memory, fix OOB If key/value allocation failed, don't bother adding another InputOption. And make sure the memory allocated is large enough for the trailing \0 Signed-off-by: Peter Hutterer Reviewed-by: Jeremy Huddleston --- hw/kdrive/src/kinput.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c index a1bbcaace..6a1ce49e0 100644 --- a/hw/kdrive/src/kinput.c +++ b/hw/kdrive/src/kinput.c @@ -1049,10 +1049,15 @@ KdGetOptions (InputOption **options, char *string) if (strchr(string, '=')) { tam_key = (strchr(string, '=') - string); - key = malloc(tam_key); + key = malloc(tam_key + 1); + if (!key) + goto out; + strncpy(key, string, tam_key); key[tam_key] = '\0'; value = strdup(strchr(string, '=') + 1); + if (!value) + goto out; } else { @@ -1064,6 +1069,7 @@ KdGetOptions (InputOption **options, char *string) if (newopt) *options = newopt; +out: free(key); free(value);