From aba8133c9c5a50753c388d76407868ac69f4134b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 8 Dec 2010 14:02:17 +1000 Subject: [PATCH 1/5] dix: clear up an overly convoluted if statement. No functional changes, just improves readability. This statement had things added to/removed from it for a few server releases while the input event queue was revamped. What made sense once is now mainly confusing. Signed-off-by: Peter Hutterer Reviewed-by: Chase Douglas --- dix/getevents.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/dix/getevents.c b/dix/getevents.c index 25889de46..9feb2166b 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -1104,18 +1104,26 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, if (!pDev->enabled) return 0; + if (!scr || !pDev->valuator) + return 0; + + switch (type) + { + case MotionNotify: + if (!mask_in || valuator_mask_num_valuators(mask_in) <= 0) + return 0; + break; + case ButtonPress: + case ButtonRelease: + if (!pDev->button || !buttons) + return 0; + break; + default: + return 0; + } + ms = GetTimeInMillis(); /* before pointer update to help precision */ - if (!scr || !pDev->valuator || - (type != MotionNotify && type != ButtonPress && type != ButtonRelease) || - (type != MotionNotify && !pDev->button) || - ((type == ButtonPress || type == ButtonRelease) && !buttons)) - return 0; - - if (type == MotionNotify && - (!mask_in || valuator_mask_num_valuators(mask_in) <= 0)) - return 0; - events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events); raw = (RawDeviceEvent*)events->event; From 9cf055892dd413932e54b43cc2dfea70bafd525f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 8 Dec 2010 14:43:51 +1000 Subject: [PATCH 2/5] xfree86: don't set movement flags for non-valuator events. If a device doesn't send valuators, don't try to move its position. Signed-off-by: Peter Hutterer Reviewed-by: Chase Douglas --- hw/xfree86/common/xf86Xinput.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c index c2cf4382c..4ee83360c 100644 --- a/hw/xfree86/common/xf86Xinput.c +++ b/hw/xfree86/common/xf86Xinput.c @@ -1015,10 +1015,13 @@ xf86PostMotionEventM(DeviceIntPtr device, int dx = 0, dy = 0; #endif - if (is_absolute) - flags = POINTER_ABSOLUTE; - else - flags = POINTER_RELATIVE | POINTER_ACCELERATE; + if (valuator_mask_num_valuators(mask) > 0) + { + if (is_absolute) + flags = POINTER_ABSOLUTE; + else + flags = POINTER_RELATIVE | POINTER_ACCELERATE; + } #if XFreeXDGA /* The evdev driver may not always send all axes across. */ @@ -1160,10 +1163,13 @@ xf86PostButtonEventM(DeviceIntPtr device, int index; #endif - if (is_absolute) - flags = POINTER_ABSOLUTE; - else - flags = POINTER_RELATIVE | POINTER_ACCELERATE; + if (valuator_mask_num_valuators(mask) > 0) + { + if (is_absolute) + flags = POINTER_ABSOLUTE; + else + flags = POINTER_RELATIVE | POINTER_ACCELERATE; + } #if XFreeXDGA if (miPointerGetScreen(device)) { From 0d440a1c6e219cd39dbddd2b7e813c6431aac6ea Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 8 Dec 2010 14:52:19 +1000 Subject: [PATCH 3/5] dix: allow for button-only input devices (#21457) Add a few checks for the existence of a valuator class on the device to avoid null-pointer dereferences for button events from devices without a valuator class. X.Org Bug 21457 Signed-off-by: Peter Hutterer Reviewed-by: Chase Douglas Reviewed-by: Daniel Stone --- dix/getevents.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/dix/getevents.c b/dix/getevents.c index 9feb2166b..794df420b 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -767,7 +767,7 @@ moveRelative(DeviceIntPtr dev, int *x, int *y, ValuatorMask *mask) /* if attached, clip both x and y to the defined limits (usually * co-ord space limit). If it is attached, we need x/y to go over the * limits to be able to change screens. */ - if(dev->u.master) { + if(dev->u.master && dev->valuator) { if (valuator_get_mode(dev, 0) == Absolute) clipAxis(dev, 0, x); if (valuator_get_mode(dev, 1) == Absolute) @@ -830,7 +830,7 @@ positionSprite(DeviceIntPtr dev, int *x, int *y, float x_frac, float y_frac, int old_screenx, old_screeny; /* scale x&y to screen */ - if (dev->valuator->numAxes > 0) { + if (dev->valuator && dev->valuator->numAxes > 0) { *screenx = rescaleValuatorAxis(*x, x_frac, screenx_frac, dev->valuator->axes + 0, NULL, scr->width); } else { @@ -838,7 +838,7 @@ positionSprite(DeviceIntPtr dev, int *x, int *y, float x_frac, float y_frac, *screenx_frac = dev->last.remainder[0]; } - if (dev->valuator->numAxes > 1) { + if (dev->valuator && dev->valuator->numAxes > 1) { *screeny = rescaleValuatorAxis(*y, y_frac, screeny_frac, dev->valuator->axes + 1, NULL, scr->height); } else { @@ -872,18 +872,21 @@ positionSprite(DeviceIntPtr dev, int *x, int *y, float x_frac, float y_frac, dev->u.master->last.remainder[1] = *screeny_frac; } - /* Crossed screen? Scale back to device coordiantes */ - if(*screenx != old_screenx) + if (dev->valuator) { - scr = miPointerGetScreen(dev); - *x = rescaleValuatorAxis(*screenx, *screenx_frac, &x_frac, NULL, - dev->valuator->axes + 0, scr->width); - } - if(*screeny != old_screeny) - { - scr = miPointerGetScreen(dev); - *y = rescaleValuatorAxis(*screeny, *screeny_frac, &y_frac, NULL, - dev->valuator->axes + 1, scr->height); + /* Crossed screen? Scale back to device coordiantes */ + if(*screenx != old_screenx) + { + scr = miPointerGetScreen(dev); + *x = rescaleValuatorAxis(*screenx, *screenx_frac, &x_frac, NULL, + dev->valuator->axes + 0, scr->width); + } + if(*screeny != old_screeny) + { + scr = miPointerGetScreen(dev); + *y = rescaleValuatorAxis(*screeny, *screeny_frac, &y_frac, NULL, + dev->valuator->axes + 1, scr->height); + } } /* dropy x/y (device coordinates) back into valuators for next event */ @@ -904,6 +907,9 @@ positionSprite(DeviceIntPtr dev, int *x, int *y, float x_frac, float y_frac, static void updateHistory(DeviceIntPtr dev, ValuatorMask *mask, CARD32 ms) { + if (!dev->valuator) + return; + updateMotionHistory(dev, ms, mask, dev->last.valuators); if (dev->u.master) { @@ -1104,7 +1110,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, if (!pDev->enabled) return 0; - if (!scr || !pDev->valuator) + if (!scr) return 0; switch (type) From 9db9e964f6ca553dcbd3b7b037745d9581eaa065 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 10 Dec 2010 13:23:13 +1000 Subject: [PATCH 4/5] xfree86: swap the order to-be-merged lists in xf86CollectInputOptions. Current order causes the user-configured option list to be overwritten with the default list supplied by the driver. Swap around so we overwrite the driver's default values instead. This only affected options supplied by the driver such as XkbLayout in the case of evdev. Reported-by: Sebastian Glita Reported-by: Simon Thum Signed-off-by: Peter Hutterer Reviewed-by: Simon Thum Reviewed-by: Dan Nicholson Tested-by: Sebastian Glita --- 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 d49aa310f..16c27e5ee 100644 --- a/hw/xfree86/common/xf86Option.c +++ b/hw/xfree86/common/xf86Option.c @@ -130,7 +130,7 @@ xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts) if (defaultOpts) { XF86OptionPtr tmp =xf86optionListCreate(defaultOpts, -1, 0); if (pInfo->options) - pInfo->options = xf86optionListMerge(pInfo->options, tmp); + pInfo->options = xf86optionListMerge(tmp, pInfo->options); else pInfo->options = tmp; } From 8a8fdd762ad89c350854943311ec4aadc50245fa Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 13 Dec 2010 11:28:30 +1000 Subject: [PATCH 5/5] xfree86: always report the input options before initialising the device. After collecting the driver's default options, report the list of options set for the device before calling PreInit(). This helps with debugging those cases where options are not merged correctly. xf86OptionListReport reports with verbosity 5, higher than the default verbosity so this won't generate logspam in the default case. Signed-off-by: Peter Hutterer Reviewed-by: Dan Nicholson Reviewed-by: Simon Thum --- hw/xfree86/common/xf86Xinput.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c index 4ee83360c..b9006ab07 100644 --- a/hw/xfree86/common/xf86Xinput.c +++ b/hw/xfree86/common/xf86Xinput.c @@ -684,6 +684,7 @@ xf86AddInput(InputDriverPtr drv, InputInfoPtr pInfo) pInfo->next = NULL; xf86CollectInputOptions(pInfo, (const char**)drv->default_options); + xf86OptionListReport(pInfo->options); xf86ProcessCommonOptions(pInfo, pInfo->options); }