[PATCH 17/17] input: provide a single function to init DeviceEvents to 0

Peter Hutterer peter.hutterer at who-t.net
Sun Aug 7 23:21:13 PDT 2011


getevents.c alreayd 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 at who-t.net>
---
 dix/getevents.c      |   19 ++++---------------
 dix/inpututils.c     |   14 ++++++++++++++
 include/inpututils.h |    1 +
 xkb/xkbAccessX.c     |    8 ++------
 4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/dix/getevents.c b/dix/getevents.c
index f7f4617..be2840c 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -154,17 +154,6 @@ key_autorepeats(DeviceIntPtr pDev, int key_code)
 }
 
 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
 init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail)
 {
     memset(event, 0, sizeof(RawDeviceEvent));
@@ -1006,7 +995,7 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     set_raw_valuators(raw, &mask, raw->valuators.data);
 
     event = &events->device_event;
-    init_event(pDev, event, ms);
+    init_device_event(event, pDev, ms);
     event->detail.key = key_code;
 
     if (type == KeyPress) {
@@ -1228,7 +1217,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     clipValuators(pDev, &mask);
 
     event = &events->device_event;
-    init_event(pDev, event, ms);
+    init_device_event(event, pDev, ms);
 
     if (type == MotionNotify) {
         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);
 
     event = &events->device_event;
-    init_event(pDev, event, GetTimeInMillis());
+    init_device_event(event, pDev, GetTimeInMillis());
     event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut;
 
     clipValuators(pDev, &mask);
@@ -1357,7 +1346,7 @@ PostSyntheticMotion(DeviceIntPtr pDev,
 #endif
 
     memset(&ev, 0, sizeof(DeviceEvent));
-    init_event(pDev, &ev, time);
+    init_device_event(&ev, pDev, time);
     ev.root_x = x;
     ev.root_y = y;
     ev.type = ET_Motion;
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 49e1758..9632076 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -584,3 +584,17 @@ void verify_internal_event(const InternalEvent *ev)
         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;
+}
diff --git a/include/inpututils.h b/include/inpututils.h
index 92a7543..63e1a26 100644
--- a/include/inpututils.h
+++ b/include/inpututils.h
@@ -38,5 +38,6 @@ struct _ValuatorMask {
 };
 
 extern void verify_internal_event(const InternalEvent *ev);
+extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms);
 
 #endif
diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 12fe2a1..4115ff2 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -124,15 +124,11 @@ AccessXKeyboardEvent(DeviceIntPtr	keybd,
 				 Bool		isRepeat)
 {
     DeviceEvent event;
-    memset(&event, 0, sizeof(DeviceEvent));
-    event.header = ET_Internal;
+
+    init_device_event(&event, keybd, GetTimeInMillis());
     event.type = type;
     event.detail.key = keyCode;
-    event.time = GetTimeInMillis();
-    event.length = sizeof(DeviceEvent);
     event.key_repeat = isRepeat;
-    event.sourceid = keybd->id;
-    event.deviceid = keybd->id;
 
     if (xkbDebugFlags&0x8) {
 	DebugF("[xkb] AXKE: Key %d %s\n", keyCode,
-- 
1.7.6



More information about the xorg-devel mailing list