summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-11-04 11:29:01 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-12-09 14:56:23 +1000
commit86bb3781b336c09e4279136ed81974de5acdba7f (patch)
tree56f325228d63a7a77507df0bc524bcf9c4fe095b
parentb8b90cd1610331ff12fa3f70bf372670af7795ec (diff)
input: swap the server over to use the XI2mask struct
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
-rw-r--r--Xi/exevents.c35
-rw-r--r--Xi/xigrabdev.c15
-rw-r--r--Xi/xipassivegrab.c13
-rw-r--r--Xi/xiselectev.c5
-rw-r--r--dix/events.c43
-rw-r--r--dix/grabs.c38
-rw-r--r--include/inputstr.h8
7 files changed, 98 insertions, 59 deletions
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 8ef974609..7a84c6b3d 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1631,6 +1631,7 @@ SelectForWindow(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client,
static void
FreeInputClient(InputClientsPtr *other)
{
+ xi2mask_free(&(*other)->xi2mask);
free(*other);
*other = NULL;
}
@@ -1653,6 +1654,9 @@ AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx)
return BadAlloc;
if (!pWin->optional->inputMasks && !MakeInputMasks(pWin))
goto bail;
+ others->xi2mask = xi2mask_new();
+ if (!others->xi2mask)
+ goto bail;
others->mask[mskidx] = mask;
others->resource = FakeClientID(client->index);
others->next = pWin->optional->inputMasks->inputClients;
@@ -1674,6 +1678,12 @@ MakeInputMasks(WindowPtr pWin)
imasks = calloc(1, sizeof(struct _OtherInputMasks));
if (!imasks)
return FALSE;
+ imasks->xi2mask = xi2mask_new();
+ if (!imasks->xi2mask)
+ {
+ free(imasks);
+ return FALSE;
+ }
pWin->optional->inputMasks = imasks;
return TRUE;
}
@@ -1681,6 +1691,7 @@ MakeInputMasks(WindowPtr pWin)
static void
FreeInputMask(OtherInputMasks **imask)
{
+ xi2mask_free(&(*imask)->xi2mask);
free(*imask);
*imask = NULL;
}
@@ -1691,20 +1702,17 @@ RecalculateDeviceDeliverableEvents(WindowPtr pWin)
InputClientsPtr others;
struct _OtherInputMasks *inputMasks; /* default: NULL */
WindowPtr pChild, tmp;
- int i, j;
+ int i;
pChild = pWin;
while (1) {
if ((inputMasks = wOtherInputMasks(pChild)) != 0) {
- for (i = 0; i < EMASKSIZE; i++)
- memset(inputMasks->xi2mask[i], 0, sizeof(inputMasks->xi2mask[i]));
+ xi2mask_zero(inputMasks->xi2mask, -1);
for (others = inputMasks->inputClients; others;
others = others->next) {
for (i = 0; i < EMASKSIZE; i++)
inputMasks->inputEvents[i] |= others->mask[i];
- for (i = 0; i < EMASKSIZE; i++)
- for (j = 0; j < XI2MASKSIZE; j++)
- inputMasks->xi2mask[i][j] |= others->xi2mask[i][j];
+ xi2mask_merge(inputMasks->xi2mask, others->xi2mask);
}
for (i = 0; i < EMASKSIZE; i++)
inputMasks->deliverableEvents[i] = inputMasks->inputEvents[i];
@@ -2188,14 +2196,12 @@ XISetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client,
for (others = wOtherInputMasks(win)->inputClients; others;
others = others->next) {
if (SameClient(others, client)) {
- memset(others->xi2mask[dev->id], 0,
- sizeof(others->xi2mask[dev->id]));
+ xi2mask_zero(others->xi2mask, dev->id);
break;
}
}
}
- len = min(len, sizeof(others->xi2mask[dev->id]));
if (len && !others)
{
@@ -2204,11 +2210,14 @@ XISetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client,
others= wOtherInputMasks(win)->inputClients;
}
- if (others)
- memset(others->xi2mask[dev->id], 0, sizeof(others->xi2mask[dev->id]));
+ if (others) {
+ xi2mask_zero(others->xi2mask, dev->id);
+ len = min(len, xi2mask_mask_size(others->xi2mask));
+ }
- if (len)
- memcpy(others->xi2mask[dev->id], mask, len);
+ if (len) {
+ xi2mask_set_one_mask(others->xi2mask, dev->id, mask, len);
+ }
RecalculateDeviceDeliverableEvents(win);
diff --git a/Xi/xigrabdev.c b/Xi/xigrabdev.c
index a9b655c0e..1cfbf243b 100644
--- a/Xi/xigrabdev.c
+++ b/Xi/xigrabdev.c
@@ -41,6 +41,7 @@
#include "exglobals.h" /* BadDevice */
#include "exevents.h"
#include "xigrabdev.h"
+#include "inpututils.h"
int
SProcXIGrabDevice(ClientPtr client)
@@ -64,7 +65,7 @@ ProcXIGrabDevice(ClientPtr client)
xXIGrabDeviceReply rep;
int ret = Success;
uint8_t status;
- GrabMask mask;
+ GrabMask mask = { 0 };
int mask_len;
REQUEST(xXIGrabDeviceReq);
@@ -81,9 +82,13 @@ ProcXIGrabDevice(ClientPtr client)
stuff->mask_len * 4) != Success)
return BadValue;
- mask_len = min(sizeof(mask.xi2mask[stuff->deviceid]), stuff->mask_len * 4);
- memset(mask.xi2mask, 0, sizeof(mask.xi2mask));
- memcpy(mask.xi2mask, (char*)&stuff[1], mask_len);
+ mask.xi2mask = xi2mask_new();
+ if (!mask.xi2mask)
+ return BadAlloc;
+
+ mask_len = min(xi2mask_mask_size(mask.xi2mask), stuff->mask_len * 4);
+ /* FIXME: I think the old code was broken here */
+ xi2mask_set_one_mask(mask.xi2mask, dev->id, (unsigned char*)&stuff[1], mask_len);
ret = GrabDevice(client, dev, stuff->grab_mode,
stuff->paired_device_mode,
@@ -96,6 +101,8 @@ ProcXIGrabDevice(ClientPtr client)
None /* confineTo */,
&status);
+ xi2mask_free(&mask.xi2mask);
+
if (ret != Success)
return ret;
diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 4fa887a42..4860757fc 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -44,6 +44,7 @@
#include "xipassivegrab.h"
#include "dixgrabs.h"
#include "misc.h"
+#include "inpututils.h"
int
SProcXIPassiveGrabDevice(ClientPtr client)
@@ -82,7 +83,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
int i, ret = Success;
uint32_t *modifiers;
xXIGrabModifierInfo *modifiers_failed;
- GrabMask mask;
+ GrabMask mask = { 0 };
GrabParameters param;
void *tmp;
int mask_len;
@@ -124,9 +125,12 @@ ProcXIPassiveGrabDevice(ClientPtr client)
stuff->mask_len * 4) != Success)
return BadValue;
- mask_len = min(sizeof(mask.xi2mask[stuff->deviceid]), stuff->mask_len * 4);
- memset(mask.xi2mask, 0, sizeof(mask.xi2mask));
- memcpy(mask.xi2mask[stuff->deviceid], &stuff[1], mask_len * 4);
+ mask.xi2mask = xi2mask_new();
+ if (!mask.xi2mask)
+ return BadAlloc;
+
+ mask_len = min(xi2mask_mask_size(mask.xi2mask), stuff->mask_len * 4);
+ xi2mask_set_one_mask(mask.xi2mask, stuff->deviceid, (unsigned char*)&stuff[1], mask_len * 4);
rep.repType = X_Reply;
rep.RepType = X_XIPassiveGrabDevice;
@@ -212,6 +216,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
free(modifiers_failed);
out:
+ xi2mask_free(&mask.xi2mask);
return ret;
}
diff --git a/Xi/xiselectev.c b/Xi/xiselectev.c
index 3af4f1fb9..ee14edb6d 100644
--- a/Xi/xiselectev.c
+++ b/Xi/xiselectev.c
@@ -33,6 +33,7 @@
#include "exglobals.h"
#include "exevents.h"
#include <X11/extensions/XI2proto.h>
+#include "inpututils.h"
#include "xiselectev.h"
@@ -249,7 +250,7 @@ ProcXIGetSelectedEvents(ClientPtr client)
for (i = 0; i < MAXDEVICES; i++)
{
int j;
- unsigned char *devmask = others->xi2mask[i];
+ const unsigned char *devmask = xi2mask_get_one_mask(others->xi2mask, i);
if (i > 2)
{
@@ -259,7 +260,7 @@ ProcXIGetSelectedEvents(ClientPtr client)
}
- for (j = XI2MASKSIZE - 1; j >= 0; j--)
+ for (j = xi2mask_mask_size(others->xi2mask) - 1; j >= 0; j--)
{
if (devmask[j] != 0)
{
diff --git a/dix/events.c b/dix/events.c
index 8f8531cf1..59caa918f 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -420,12 +420,6 @@ 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.
@@ -459,12 +453,15 @@ GetEventFilter(DeviceIntPtr dev, xEvent *event)
* for the event_type.
*/
static int
-GetXI2MaskByte(unsigned char xi2mask[][XI2MASKSIZE], DeviceIntPtr dev, int event_type)
+GetXI2MaskByte(XI2Mask *mask, DeviceIntPtr dev, int event_type)
{
- int byte = GetXI2EventFilterOffset(event_type);
- return xi2mask[dev->id][byte] |
- xi2mask[XIAllDevices][byte] |
- (IsMaster(dev) ? xi2mask[XIAllMasterDevices][byte] : 0);
+ /* we just return the matching filter because that's the only use
+ * for this mask anyway.
+ */
+ if (xi2mask_isset(mask, dev, event_type))
+ return GetXI2EventFilterMask(event_type);
+ else
+ return 0;
}
@@ -476,16 +473,14 @@ Bool
WindowXI2MaskIsset(DeviceIntPtr dev, WindowPtr win, xEvent* ev)
{
OtherInputMasks *inputMasks = wOtherInputMasks(win);
- int filter;
int evtype;
if (!inputMasks || xi2_get_type(ev) == 0)
return 0;
evtype = ((xGenericEvent*)ev)->evtype;
- filter = GetEventFilter(dev, ev);
- return !!(GetXI2MaskByte(inputMasks->xi2mask, dev, evtype) & filter);
+ return xi2mask_isset(inputMasks->xi2mask, dev, evtype);
}
Mask
@@ -2011,8 +2006,7 @@ ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win,
tempGrab->deviceMask = (inputMasks) ? inputMasks->inputEvents[dev->id]: 0;
if (inputMasks)
- memcpy(tempGrab->xi2mask, inputMasks->xi2mask,
- sizeof(tempGrab->xi2mask));
+ xi2mask_merge(tempGrab->xi2mask, inputMasks->xi2mask);
(*dev->deviceGrab.ActivateGrab)(dev, tempGrab,
currentTime, TRUE | ImplicitGrabMask);
@@ -2561,10 +2555,7 @@ EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event, WindowPtr win)
if ((type = GetXI2Type(event)) != 0)
{
- filter = GetXI2EventFilterMask(type);
-
- if (inputMasks &&
- (GetXI2MaskByte(inputMasks->xi2mask, dev, type) & filter))
+ if (inputMasks && xi2mask_isset(inputMasks->xi2mask, dev, type))
rc |= EVENT_XI2_MASK;
}
@@ -4155,12 +4146,11 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
if (rc == Success)
{
int evtype = xi2_get_type(xi2);
- mask = GetXI2MaskByte(grab->xi2mask, thisDev, evtype);
+ mask = xi2mask_isset(grab->xi2mask, thisDev, evtype);
/* try XI2 event */
FixUpEventFromWindow(pSprite, xi2, grab->window, None, TRUE);
/* XXX: XACE */
- deliveries = TryClientEvents(rClient(grab), thisDev, xi2, 1, mask,
- GetEventFilter(thisDev, xi2), grab);
+ deliveries = TryClientEvents(rClient(grab), thisDev, xi2, 1, mask, 1, grab);
} else if (rc != BadMatch)
ErrorF("[dix] %s: XI2 conversion failed in DGE (%d, %d). Skipping delivery.\n",
thisDev->name, event->any.type, rc);
@@ -4634,9 +4624,8 @@ DeviceEnterLeaveEvent(
if (grab)
{
Mask mask;
- mask = GetXI2MaskByte(grab->xi2mask, mouse, type);
- TryClientEvents(rClient(grab), mouse, (xEvent*)event, 1, mask,
- filter, grab);
+ mask = xi2mask_isset(grab->xi2mask, mouse, type);
+ TryClientEvents(rClient(grab), mouse, (xEvent*)event, 1, mask, 1, grab);
} else {
if (!WindowXI2MaskIsset(mouse, pWin, (xEvent*)event))
goto out;
@@ -5100,7 +5089,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
else if (grabtype == GRABTYPE_XI)
tempGrab->eventMask = mask->xi;
else
- memcpy(tempGrab->xi2mask, mask->xi2mask, sizeof(tempGrab->xi2mask));
+ xi2mask_merge(tempGrab->xi2mask, mask->xi2mask);
tempGrab->device = dev;
tempGrab->cursor = cursor;
tempGrab->confineTo = confineTo;
diff --git a/dix/grabs.c b/dix/grabs.c
index a1d56c5ed..aced130a7 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -60,6 +60,7 @@ SOFTWARE.
#include "dixgrabs.h"
#include "xace.h"
#include "exevents.h"
+#include "inpututils.h"
#define BITMASK(i) (((Mask)1) << ((i) & 31))
#define MASKIDX(i) ((i) >> 5)
@@ -122,13 +123,15 @@ PrintDeviceGrabInfo(DeviceIntPtr dev)
}
else if (grab->grabtype == GRABTYPE_XI2)
{
- for (i = 0; i < EMASKSIZE; i++)
+ for (i = 0; i < xi2mask_num_masks(grab->xi2mask); i++)
{
+ const unsigned char *mask;
int print;
print = 0;
for (j = 0; j < XI2MASKSIZE; j++)
{
- if (grab->xi2mask[i][j])
+ mask = xi2mask_get_one_mask(grab->xi2mask, i);
+ if (mask[j])
{
print = 1;
break;
@@ -137,8 +140,8 @@ PrintDeviceGrabInfo(DeviceIntPtr dev)
if (!print)
continue;
ErrorF(" xi2 event mask for device %d: 0x", dev->id);
- for (j = 0; j < XI2MASKSIZE; j++)
- ErrorF("%x", grab->xi2mask[i][j]);
+ for (j = 0; j < xi2mask_mask_size(grab->xi2mask); j++)
+ ErrorF("%x", mask[j]);
ErrorF("\n");
}
}
@@ -185,6 +188,14 @@ AllocGrab(void)
{
GrabPtr grab = calloc(1, sizeof(GrabRec));
+ if (grab) {
+ grab->xi2mask = xi2mask_new();
+ if (!grab->xi2mask) {
+ free(grab);
+ grab = NULL;
+ }
+ }
+
return grab;
}
@@ -227,7 +238,7 @@ CreateGrab(
grab->next = NULL;
if (grabtype == GRABTYPE_XI2)
- memcpy(grab->xi2mask, mask->xi2mask, sizeof(mask->xi2mask));
+ xi2mask_merge(grab->xi2mask, mask->xi2mask);
if (cursor)
cursor->refcnt++;
return grab;
@@ -243,6 +254,7 @@ FreeGrab(GrabPtr pGrab)
if (pGrab->cursor)
FreeCursor(pGrab->cursor, (Cursor)0);
+ xi2mask_free(&pGrab->xi2mask);
free(pGrab);
}
@@ -251,6 +263,7 @@ CopyGrab(GrabPtr dst, const GrabPtr src)
{
Mask *mdetails_mask = NULL;
Mask *details_mask = NULL;
+ XI2Mask *xi2mask;
if (src->cursor)
src->cursor->refcnt++;
@@ -273,9 +286,24 @@ CopyGrab(GrabPtr dst, const GrabPtr src)
memcpy(details_mask, src->detail.pMask, len);
}
+ if (!dst->xi2mask) {
+ xi2mask = xi2mask_new();
+ if (!xi2mask) {
+ free(mdetails_mask);
+ free(details_mask);
+ return FALSE;
+ }
+ } else {
+ xi2mask = dst->xi2mask;
+ xi2mask_zero(xi2mask, -1);
+ }
+
*dst = *src;
dst->modifiersDetail.pMask = mdetails_mask;
dst->detail.pMask = details_mask;
+ dst->xi2mask = xi2mask;
+
+ xi2mask_merge(dst->xi2mask, src->xi2mask);
return TRUE;
}
diff --git a/include/inputstr.h b/include/inputstr.h
index a73ace830..5634f3cfc 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -118,7 +118,7 @@ typedef struct _InputClients {
XID resource; /**< id for putting into resource manager */
Mask mask[EMASKSIZE]; /**< Actual XI event mask, deviceid is index */
/** XI2 event masks. One per device, each bit is a mask of (1 << type) */
- unsigned char xi2mask[EMASKSIZE][XI2MASKSIZE];
+ struct _XI2Mask *xi2mask;
} InputClients;
/**
@@ -148,7 +148,7 @@ typedef struct _OtherInputMasks {
/** The clients that selected for events */
InputClientsPtr inputClients;
/* XI2 event masks. One per device, each bit is a mask of (1 << type) */
- unsigned char xi2mask[EMASKSIZE][XI2MASKSIZE];
+ struct _XI2Mask *xi2mask;
} OtherInputMasks;
/*
@@ -176,7 +176,7 @@ typedef enum {
union _GrabMask {
Mask core;
Mask xi;
- char xi2mask[EMASKSIZE][XI2MASKSIZE];
+ struct _XI2Mask *xi2mask;
};
/**
@@ -210,7 +210,7 @@ typedef struct _GrabRec {
Mask eventMask;
Mask deviceMask;
/* XI2 event masks. One per device, each bit is a mask of (1 << type) */
- unsigned char xi2mask[EMASKSIZE][XI2MASKSIZE];
+ struct _XI2Mask *xi2mask;
} GrabRec;
/**