dix: change eventconvert to always return an array of xEvents
Just alloc the memory on demand rather than doing things with EventListPtrs etc. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
4026c63e4e
commit
64ea607810
|
@ -44,9 +44,9 @@
|
||||||
#include "listdev.h"
|
#include "listdev.h"
|
||||||
|
|
||||||
static int countValuators(DeviceEvent *ev, int *first);
|
static int countValuators(DeviceEvent *ev, int *first);
|
||||||
static int getValuatorEvents(DeviceEvent *ev, EventListPtr xi);
|
static int getValuatorEvents(DeviceEvent *ev, deviceValuator *xv);
|
||||||
static int eventToKeyButtonPointer(DeviceEvent *ev, EventListPtr xi, int *count);
|
static int eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count);
|
||||||
static int eventToClassesChanged(DeviceChangedEvent *ev, EventListPtr dcce,
|
static int eventToClassesChanged(DeviceChangedEvent *ev, xEvent **dcce,
|
||||||
int *count);
|
int *count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,24 +97,15 @@ EventToCore(InternalEvent *event, xEvent *core)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the given event @ev to the respective XI 1.x event and store it in
|
* Convert the given event @ev to the respective XI 1.x event and store it in
|
||||||
* @xi. @xi must be allocated by the caller, @count specifies the number of
|
* @xi. @xi is allocated on demand and must be freed by the caller.
|
||||||
* events in @xi.
|
* @count returns the number of events in @xi. If @count is 1, and the type of
|
||||||
*
|
* @xi is GenericEvent, then @xi may be larger than 32 bytes.
|
||||||
*
|
|
||||||
* If less than @count events are needed, @count is set to the events stored
|
|
||||||
* in @xi and Success is returned.
|
|
||||||
*
|
|
||||||
* If more than @count events are needed, @count is set to the number of
|
|
||||||
* events required, and BadAlloc is returned. @xi is untouched.
|
|
||||||
*
|
|
||||||
* If necessary, @xi is realloced using SetMinimumEventSize() to fit the
|
|
||||||
* largest event being returned.
|
|
||||||
*
|
*
|
||||||
* If the event cannot be converted into an XI event because of protocol
|
* If the event cannot be converted into an XI event because of protocol
|
||||||
* restrictions, @count is 0 and Success is returned.
|
* restrictions, @count is 0 and Success is returned.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
EventToXI(InternalEvent *ev, EventListPtr xi, int *count)
|
EventToXI(InternalEvent *ev, xEvent **xi, int *count)
|
||||||
{
|
{
|
||||||
switch (ev->u.any.type)
|
switch (ev->u.any.type)
|
||||||
{
|
{
|
||||||
|
@ -136,7 +127,7 @@ EventToXI(InternalEvent *ev, EventListPtr xi, int *count)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
eventToKeyButtonPointer(DeviceEvent *ev, EventListPtr xi, int *count)
|
eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count)
|
||||||
{
|
{
|
||||||
int num_events;
|
int num_events;
|
||||||
int first; /* dummy */
|
int first; /* dummy */
|
||||||
|
@ -152,15 +143,13 @@ eventToKeyButtonPointer(DeviceEvent *ev, EventListPtr xi, int *count)
|
||||||
num_events = (countValuators(ev, &first) + 5)/6; /* valuator ev */
|
num_events = (countValuators(ev, &first) + 5)/6; /* valuator ev */
|
||||||
num_events++; /* the actual event event */
|
num_events++; /* the actual event event */
|
||||||
|
|
||||||
if (*count < num_events)
|
*xi = xcalloc(num_events, sizeof(xEvent));
|
||||||
|
if (!(*xi))
|
||||||
{
|
{
|
||||||
*count = num_events;
|
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetMinimumEventSize(xi, *count, 32);
|
kbp = (deviceKeyButtonPointer*)(*xi);
|
||||||
|
|
||||||
kbp = (deviceKeyButtonPointer*)xi->event;
|
|
||||||
kbp->detail = ev->detail.button;
|
kbp->detail = ev->detail.button;
|
||||||
kbp->time = ev->time;
|
kbp->time = ev->time;
|
||||||
kbp->root = ev->root;
|
kbp->root = ev->root;
|
||||||
|
@ -183,10 +172,9 @@ eventToKeyButtonPointer(DeviceEvent *ev, EventListPtr xi, int *count)
|
||||||
case ET_ProximityOut: kbp->type = ProximityOut; break;
|
case ET_ProximityOut: kbp->type = ProximityOut; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (num_events > 1)
|
if (num_events > 1)
|
||||||
{
|
{
|
||||||
getValuatorEvents(ev, xi + 1);
|
getValuatorEvents(ev, (deviceValuator*)(kbp + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
*count = num_events;
|
*count = num_events;
|
||||||
|
@ -224,17 +212,15 @@ countValuators(DeviceEvent *ev, int *first)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
getValuatorEvents(DeviceEvent *ev, EventListPtr events)
|
getValuatorEvents(DeviceEvent *ev, deviceValuator *xv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
deviceValuator *xv;
|
|
||||||
int first_valuator, num_valuators;
|
int first_valuator, num_valuators;
|
||||||
|
|
||||||
num_valuators = countValuators(ev, &first_valuator);
|
num_valuators = countValuators(ev, &first_valuator);
|
||||||
|
|
||||||
/* FIXME: non-continuous valuator data in internal events*/
|
/* FIXME: non-continuous valuator data in internal events*/
|
||||||
for (i = 0; i < num_valuators; i += 6, events++) {
|
for (i = 0; i < num_valuators; i += 6, xv++) {
|
||||||
xv = (deviceValuator*)events->event;
|
|
||||||
xv->type = DeviceValuator;
|
xv->type = DeviceValuator;
|
||||||
xv->first_valuator = first_valuator + i;
|
xv->first_valuator = first_valuator + i;
|
||||||
xv->num_valuators = ((num_valuators - i) > 6) ? 6 : (num_valuators - i);
|
xv->num_valuators = ((num_valuators - i) > 6) ? 6 : (num_valuators - i);
|
||||||
|
@ -262,13 +248,14 @@ getValuatorEvents(DeviceEvent *ev, EventListPtr events)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
eventToClassesChanged(DeviceChangedEvent *ev, EventListPtr events, int *count)
|
eventToClassesChanged(DeviceChangedEvent *ev, xEvent **xi, int *count)
|
||||||
{
|
{
|
||||||
int len = sizeof(xEvent);
|
int len = sizeof(xEvent);
|
||||||
int namelen = 0; /* dummy */
|
int namelen = 0; /* dummy */
|
||||||
DeviceIntPtr slave;
|
DeviceIntPtr slave;
|
||||||
int rc;
|
int rc;
|
||||||
deviceClassesChangedEvent *dcce = (deviceClassesChangedEvent*)events->event;
|
deviceClassesChangedEvent *dcce;
|
||||||
|
|
||||||
|
|
||||||
rc = dixLookupDevice(&slave, ev->new_slaveid,
|
rc = dixLookupDevice(&slave, ev->new_slaveid,
|
||||||
serverClient, DixReadAccess);
|
serverClient, DixReadAccess);
|
||||||
|
@ -278,6 +265,11 @@ eventToClassesChanged(DeviceChangedEvent *ev, EventListPtr events, int *count)
|
||||||
|
|
||||||
SizeDeviceInfo(slave, &namelen, &len);
|
SizeDeviceInfo(slave, &namelen, &len);
|
||||||
|
|
||||||
|
*xi = xcalloc(1, len);
|
||||||
|
if (!(*xi))
|
||||||
|
return BadAlloc;
|
||||||
|
|
||||||
|
dcce = (deviceClassesChangedEvent*)(*xi);
|
||||||
dcce->type = GenericEvent;
|
dcce->type = GenericEvent;
|
||||||
dcce->extension = IReqCode;
|
dcce->extension = IReqCode;
|
||||||
dcce->evtype = XI_DeviceClassesChangedNotify;
|
dcce->evtype = XI_DeviceClassesChangedNotify;
|
||||||
|
@ -338,21 +330,19 @@ GetXIType(InternalEvent *event)
|
||||||
int
|
int
|
||||||
ConvertBackToXI(InternalEvent *event, xEvent *ev)
|
ConvertBackToXI(InternalEvent *event, xEvent *ev)
|
||||||
{
|
{
|
||||||
int count = GetMaximumEventsNum();
|
int count = 0;
|
||||||
int evlen, i;
|
int evlen, i;
|
||||||
|
xEvent *xi = NULL;
|
||||||
|
|
||||||
EventListPtr tmp_list = InitEventList(count);
|
|
||||||
|
|
||||||
SetMinimumEventSize(tmp_list, count, 1000); /* just to be sure */
|
if (EventToXI(event, &xi, &count))
|
||||||
|
|
||||||
if (EventToXI(event, tmp_list, &count))
|
|
||||||
ErrorF("[dix] conversion to XI failed\n");
|
ErrorF("[dix] conversion to XI failed\n");
|
||||||
|
|
||||||
if (tmp_list->event->u.u.type == GenericEvent)
|
if (xi->u.u.type == GenericEvent)
|
||||||
evlen = (GEV(tmp_list->event))->length * 4 + 32;
|
evlen = (GEV(xi))->length * 4 + 32;
|
||||||
else
|
else
|
||||||
evlen = count * 32;
|
evlen = count * 32;
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
memcpy(&ev[i], (tmp_list + i)->event, evlen);
|
memcpy(&ev[i], &xi[i], evlen);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
|
|
||||||
_X_INTERNAL int EventToCore(InternalEvent *event, xEvent *core);
|
_X_INTERNAL int EventToCore(InternalEvent *event, xEvent *core);
|
||||||
_X_INTERNAL int EventToXI(InternalEvent *ev, EventListPtr xi, int *count);
|
_X_INTERNAL int EventToXI(InternalEvent *ev, xEvent **xi, int *count);
|
||||||
_X_INTERNAL int GetCoreType(InternalEvent* ev);
|
_X_INTERNAL int GetCoreType(InternalEvent* ev);
|
||||||
_X_INTERNAL int GetXIType(InternalEvent* ev);
|
_X_INTERNAL int GetXIType(InternalEvent* ev);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue