summaryrefslogtreecommitdiff
path: root/dix/events.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-08-11 10:57:05 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-08-22 15:56:53 +1000
commit799879797505a5e891ccaec2bea73fd838c94b7a (patch)
treeaf2aadce557e39d7afc18841119bb42994734274 /dix/events.c
parent8c5a4d6fbecf79f2dc4f2d836d741203b2d5e856 (diff)
dix: abstract XI2 filter mask lookup
Don't access the xi2mask bytes directly or calculate the offsets manually, use a few helper functions instead. XI2 masks are a bit weird in the event handling code since they slot onto the legacy code. For core/XI 1.x events, the event mask is a CARD32. That mask is used together with the event filter (also 32 bit) to determine if event delivery should be attempted. XI2 masks are of arbitrary size and their mask is simply the byte of the mask that contains the event mask. Likewise, the filter is a single byte matching that mask. Provide helper functions get these bytes and masks in the right order instead of accessing them manually. EventIsDeliverable should be part of this cleanup patch but it will be gutted with the next patch. Co-Authored-by: Keith Packard <keithp@keithp.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'dix/events.c')
-rw-r--r--dix/events.c53
1 files changed, 38 insertions, 15 deletions
diff --git a/dix/events.c b/dix/events.c
index 8e07532ec..0e22fdc20 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -408,6 +408,24 @@ static const Mask default_filter[128] =
CantBeFiltered /* MappingNotify */
};
+static inline Mask
+GetEventFilterMask(DeviceIntPtr dev, int evtype)
+{
+ return filters[dev ? dev->id : 0][evtype];
+}
+
+static inline Mask
+GetXI2EventFilterMask(int evtype)
+{
+ return (1 << (evtype % 8));
+}
+
+static inline int
+GetXI2EventFilterOffset(int evtype)
+{
+ return (evtype / 8);
+}
+
/**
* For the given event, return the matching event filter. This filter may then
* be AND'ed with the selected event mask.
@@ -429,14 +447,28 @@ GetEventFilter(DeviceIntPtr dev, xEvent *event)
int evtype = 0;
if (event->u.u.type != GenericEvent)
- return filters[dev ? dev->id : 0][event->u.u.type];
+ return GetEventFilterMask(dev, event->u.u.type);
else if ((evtype = xi2_get_type(event)))
- return (1 << (evtype % 8));
+ return GetXI2EventFilterMask(evtype);
ErrorF("[dix] Unknown event type %d. No filter\n", event->u.u.type);
return 0;
}
/**
+ * Return the single byte of the device's XI2 mask that contains the mask
+ * for the event_type.
+ */
+static int
+GetXI2MaskByte(unsigned char xi2mask[][XI2MASKSIZE], DeviceIntPtr dev, int event_type)
+{
+ int byte = GetXI2EventFilterOffset(event_type);
+ return xi2mask[dev->id][byte] |
+ xi2mask[XIAllDevices][byte] |
+ (IsMaster(dev) ? xi2mask[XIAllMasterDevices][byte] : 0);
+}
+
+
+/**
* Return the windows complete XI2 mask for the given XI2 event type.
*/
Mask
@@ -452,9 +484,7 @@ GetWindowXI2Mask(DeviceIntPtr dev, WindowPtr win, xEvent* ev)
evtype = ((xGenericEvent*)ev)->evtype;
filter = GetEventFilter(dev, ev);
- return ((inputMasks->xi2mask[dev->id][evtype/8] & filter) ||
- inputMasks->xi2mask[XIAllDevices][evtype/8] ||
- (inputMasks->xi2mask[XIAllMasterDevices][evtype/8] && IsMaster(dev)));
+ return (GetXI2MaskByte(inputMasks->xi2mask, dev, evtype) & filter);
}
Mask
@@ -465,10 +495,7 @@ GetEventMask(DeviceIntPtr dev, xEvent *event, InputClients* other)
/* XI2 filters are only ever 8 bit, so let's return a 8 bit mask */
if ((evtype = xi2_get_type(event)))
{
- int byte = evtype / 8;
- return (other->xi2mask[dev->id][byte] |
- other->xi2mask[XIAllDevices][byte] |
- (IsMaster(dev)? other->xi2mask[XIAllMasterDevices][byte] : 0));
+ return GetXI2MaskByte(other->xi2mask, dev, evtype);
} else if (core_get_type(event) != 0)
return other->mask[XIAllDevices];
else
@@ -4061,9 +4088,7 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
if (rc == Success)
{
int evtype = xi2_get_type(xi2);
- mask = grab->xi2mask[XIAllDevices][evtype/8] |
- grab->xi2mask[XIAllMasterDevices][evtype/8] |
- grab->xi2mask[thisDev->id][evtype/8];
+ mask = GetXI2MaskByte(grab->xi2mask, thisDev, evtype);
/* try XI2 event */
FixUpEventFromWindow(pSprite, xi2, grab->window, None, TRUE);
/* XXX: XACE */
@@ -4542,9 +4567,7 @@ DeviceEnterLeaveEvent(
if (grab)
{
Mask mask;
- mask = grab->xi2mask[XIAllDevices][type/8] |
- grab->xi2mask[XIAllMasterDevices][type/8] |
- grab->xi2mask[mouse->id][type/8];
+ mask = GetXI2MaskByte(grab->xi2mask, mouse, type);
TryClientEvents(rClient(grab), mouse, (xEvent*)event, 1, mask,
filter, grab);
} else {