input: provide a single function to init DeviceEvents to 0

getevents.c already had that function, but XKB was manually initializing it,
causing bugs when the event structure was updated in one place but not the
other.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2011-08-03 15:07:23 +10:00
parent 4b376ddeb4
commit 3a077f246e
4 changed files with 21 additions and 21 deletions

View File

@ -153,17 +153,6 @@ key_autorepeats(DeviceIntPtr pDev, int key_code)
(1 << (key_code & 7))); (1 << (key_code & 7)));
} }
static void
init_event(DeviceIntPtr dev, DeviceEvent* event, Time ms)
{
memset(event, 0, sizeof(DeviceEvent));
event->header = ET_Internal;
event->length = sizeof(DeviceEvent);
event->time = ms;
event->deviceid = dev->id;
event->sourceid = dev->id;
}
static void static void
init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail) init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail)
{ {
@ -1006,7 +995,7 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
set_raw_valuators(raw, &mask, raw->valuators.data); set_raw_valuators(raw, &mask, raw->valuators.data);
event = &events->device_event; event = &events->device_event;
init_event(pDev, event, ms); init_device_event(event, pDev, ms);
event->detail.key = key_code; event->detail.key = key_code;
if (type == KeyPress) { if (type == KeyPress) {
@ -1228,7 +1217,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
clipValuators(pDev, &mask); clipValuators(pDev, &mask);
event = &events->device_event; event = &events->device_event;
init_event(pDev, event, ms); init_device_event(event, pDev, ms);
if (type == MotionNotify) { if (type == MotionNotify) {
event->type = ET_Motion; event->type = ET_Motion;
@ -1321,7 +1310,7 @@ GetProximityEvents(InternalEvent *events, DeviceIntPtr pDev, int type, const Val
events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events); events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events);
event = &events->device_event; event = &events->device_event;
init_event(pDev, event, GetTimeInMillis()); init_device_event(event, pDev, GetTimeInMillis());
event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut; event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut;
clipValuators(pDev, &mask); clipValuators(pDev, &mask);
@ -1357,7 +1346,7 @@ PostSyntheticMotion(DeviceIntPtr pDev,
#endif #endif
memset(&ev, 0, sizeof(DeviceEvent)); memset(&ev, 0, sizeof(DeviceEvent));
init_event(pDev, &ev, time); init_device_event(&ev, pDev, time);
ev.root_x = x; ev.root_x = x;
ev.root_y = y; ev.root_y = y;
ev.type = ET_Motion; ev.type = ET_Motion;

View File

@ -584,3 +584,17 @@ void verify_internal_event(const InternalEvent *ev)
FatalError("Wrong event type %d. Aborting server\n", ev->any.header); FatalError("Wrong event type %d. Aborting server\n", ev->any.header);
} }
} }
/**
* Initializes the given event to zero (or default values), for the given
* device.
*/
void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms)
{
memset(event, 0, sizeof(DeviceEvent));
event->header = ET_Internal;
event->length = sizeof(DeviceEvent);
event->time = ms;
event->deviceid = dev->id;
event->sourceid = dev->id;
}

View File

@ -38,5 +38,6 @@ struct _ValuatorMask {
}; };
extern void verify_internal_event(const InternalEvent *ev); extern void verify_internal_event(const InternalEvent *ev);
extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms);
#endif #endif

View File

@ -124,15 +124,11 @@ AccessXKeyboardEvent(DeviceIntPtr keybd,
Bool isRepeat) Bool isRepeat)
{ {
DeviceEvent event; DeviceEvent event;
memset(&event, 0, sizeof(DeviceEvent));
event.header = ET_Internal; init_device_event(&event, keybd, GetTimeInMillis());
event.type = type; event.type = type;
event.detail.key = keyCode; event.detail.key = keyCode;
event.time = GetTimeInMillis();
event.length = sizeof(DeviceEvent);
event.key_repeat = isRepeat; event.key_repeat = isRepeat;
event.sourceid = keybd->id;
event.deviceid = keybd->id;
if (xkbDebugFlags&0x8) { if (xkbDebugFlags&0x8) {
DebugF("[xkb] AXKE: Key %d %s\n", keyCode, DebugF("[xkb] AXKE: Key %d %s\n", keyCode,