From e0f37250ffff5dcb3bc0e8cad63439995ce01a20 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 6 Dec 2011 11:40:33 +1000 Subject: Xi: deduplicate button motion mask setting No functional changes Signed-off-by: Peter Hutterer Reviewed-by: Chase Douglas --- Xi/exevents.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Xi/exevents.c b/Xi/exevents.c index b2e82ec06..211095743 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -703,6 +703,29 @@ ChangeMasterDeviceClasses(DeviceIntPtr device, DeviceChangedEvent *dce) XISendDeviceChangedEvent(device, dce); } +/** + * Add state and motionMask to the filter for this event. The protocol + * supports some extra masks for motion when a button is down: + * ButtonXMotionMask and the DeviceButtonMotionMask to trigger only when at + * least one button (or that specific button is down). These masks need to + * be added to the filters for core/XI motion events. + * + * @param device The device to update the mask for + * @param state The current button state mask + * @param motion_mask The motion mask (DeviceButtonMotionMask or 0) + */ +static void +UpdateDeviceMotionMask(DeviceIntPtr device, unsigned short state, + Mask motion_mask) +{ + Mask mask; + + mask = DevicePointerMotionMask | state | motion_mask; + SetMaskForEvent(device->id, mask, DeviceMotionNotify); + mask = PointerMotionMask | state | motion_mask; + SetMaskForEvent(device->id, mask, MotionNotify); +} + /** * Update the device state according to the data in the event. * @@ -801,7 +824,6 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event) device->valuator->motionHintWindow = NullWindow; set_key_up(device, key, KEY_PROCESSED); } else if (event->type == ET_ButtonPress) { - Mask mask; if (!b) return DONT_PROCESS; @@ -818,13 +840,8 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event) if (b->map[key] <= 5) b->state |= (Button1Mask >> 1) << b->map[key]; - /* Add state and motionMask to the filter for this event */ - mask = DevicePointerMotionMask | b->state | b->motionMask; - SetMaskForEvent(device->id, mask, DeviceMotionNotify); - mask = PointerMotionMask | b->state | b->motionMask; - SetMaskForEvent(device->id, mask, MotionNotify); + UpdateDeviceMotionMask(device, b->state, b->motionMask); } else if (event->type == ET_ButtonRelease) { - Mask mask; if (!b) return DONT_PROCESS; @@ -859,11 +876,7 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event) if (b->map[key] <= 5) b->state &= ~((Button1Mask >> 1) << b->map[key]); - /* Add state and motionMask to the filter for this event */ - mask = DevicePointerMotionMask | b->state | b->motionMask; - SetMaskForEvent(device->id, mask, DeviceMotionNotify); - mask = PointerMotionMask | b->state | b->motionMask; - SetMaskForEvent(device->id, mask, MotionNotify); + UpdateDeviceMotionMask(device, b->state, b->motionMask); } else if (event->type == ET_ProximityIn) device->proximity->in_proximity = TRUE; else if (event->type == ET_ProximityOut) -- cgit v1.2.3