[PATCH v2 2/4] Input: Add DeviceEventSource enum

Daniel Stone daniels at collabora.com
Fri Nov 20 07:37:29 PST 2015


Add a flag to DeviceEvents, giving the source of the event. Currently
this only supports a 'normal' flag, but will be used later to add a
'focus-in' flag, noting events synthesised from key/button arrays on
focus-in notifications.

Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 dix/getevents.c      | 24 +++++++++++++-----------
 dix/inpututils.c     |  4 +++-
 include/eventstr.h   |  9 +++++++++
 include/inpututils.h |  4 +++-
 xkb/xkbAccessX.c     |  2 +-
 5 files changed, 29 insertions(+), 14 deletions(-)

v2: New, after review.

diff --git a/dix/getevents.c b/dix/getevents.c
index 7ebddc4..f04b415 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1092,6 +1092,7 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     CARD32 ms = 0;
     DeviceEvent *event;
     RawDeviceEvent *raw;
+    enum DeviceEventSource source_type = EVENT_SOURCE_NORMAL;
 
 #if XSERVER_DTRACE
     if (XSERVER_INPUT_EVENT_ENABLED()) {
@@ -1126,14 +1127,15 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
 
     ms = GetTimeInMillis();
 
-    raw = &events->raw_event;
-    events++;
-    num_events++;
-
-    init_raw(pDev, raw, ms, type, key_code);
+    if (source_type == EVENT_SOURCE_NORMAL) {
+        raw = &events->raw_event;
+        init_raw(pDev, raw, ms, type, key_code);
+        events++;
+        num_events++;
+    }
 
     event = &events->device_event;
-    init_device_event(event, pDev, ms);
+    init_device_event(event, pDev, ms, source_type);
     event->detail.key = key_code;
 
     if (type == KeyPress) {
@@ -1468,7 +1470,7 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
     }
 
     event = &events->device_event;
-    init_device_event(event, pDev, ms);
+    init_device_event(event, pDev, ms, EVENT_SOURCE_NORMAL);
 
     if (type == MotionNotify) {
         event->type = ET_Motion;
@@ -1804,7 +1806,7 @@ GetProximityEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
         UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events);
 
     event = &events->device_event;
-    init_device_event(event, pDev, GetTimeInMillis());
+    init_device_event(event, pDev, GetTimeInMillis(), EVENT_SOURCE_NORMAL);
     event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut;
 
     clipValuators(pDev, &mask);
@@ -1939,7 +1941,7 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid,
     event = &events->device_event;
     num_events++;
 
-    init_device_event(event, dev, ms);
+    init_device_event(event, dev, ms, EVENT_SOURCE_NORMAL);
 
     switch (type) {
     case XI_TouchBegin:
@@ -2054,7 +2056,7 @@ GetDixTouchEnd(InternalEvent *ievent, DeviceIntPtr dev, TouchPointInfoPtr ti,
 
     BUG_WARN(!dev->enabled);
 
-    init_device_event(event, dev, ms);
+    init_device_event(event, dev, ms, EVENT_SOURCE_NORMAL);
 
     event->sourceid = ti->sourceid;
     event->type = ET_TouchEnd;
@@ -2098,7 +2100,7 @@ PostSyntheticMotion(DeviceIntPtr pDev,
 #endif
 
     memset(&ev, 0, sizeof(DeviceEvent));
-    init_device_event(&ev, pDev, time);
+    init_device_event(&ev, pDev, time, EVENT_SOURCE_NORMAL);
     ev.root_x = x;
     ev.root_y = y;
     ev.type = ET_Motion;
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 1363988..5b7da3a 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -727,7 +727,8 @@ verify_internal_event(const InternalEvent *ev)
  * device.
  */
 void
-init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms)
+init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms,
+                  enum DeviceEventSource source_type)
 {
     memset(event, 0, sizeof(DeviceEvent));
     event->header = ET_Internal;
@@ -735,6 +736,7 @@ init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms)
     event->time = ms;
     event->deviceid = dev->id;
     event->sourceid = dev->id;
+    event->source_type = source_type;
 }
 
 int
diff --git a/include/eventstr.h b/include/eventstr.h
index cce903d..4fd846f 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -25,6 +25,7 @@
 #ifndef EVENTSTR_H
 #define EVENTSTR_H
 
+#include "inputstr.h"
 #include <events.h>
 /**
  * @file events.h
@@ -78,6 +79,13 @@ enum EventType {
 };
 
 /**
+ * How a DeviceEvent was provoked
+ */
+enum DeviceEventSource {
+  EVENT_SOURCE_NORMAL = 0, /**< Default: from a user action (e.g. key press) */
+};
+
+/**
  * Used for ALL input device events internal in the server until
  * copied into the matching protocol event.
  *
@@ -124,6 +132,7 @@ struct _DeviceEvent {
     int key_repeat;   /**< Internally-generated key repeat event */
     uint32_t flags;   /**< Flags to be copied into the generated event */
     uint32_t resource; /**< Touch event resource, only for TOUCH_REPLAYING */
+    enum DeviceEventSource source_type; /**< How this event was provoked */
 };
 
 /**
diff --git a/include/inpututils.h b/include/inpututils.h
index 4e90815..48c95c4 100644
--- a/include/inpututils.h
+++ b/include/inpututils.h
@@ -30,6 +30,7 @@
 #define INPUTUTILS_H
 
 #include "input.h"
+#include "eventstr.h"
 #include <X11/extensions/XI2proto.h>
 
 extern Mask event_filters[MAXDEVICES][MAXEVENTS];
@@ -43,7 +44,8 @@ struct _ValuatorMask {
 };
 
 extern void verify_internal_event(const InternalEvent *ev);
-extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms);
+extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms,
+                              enum DeviceEventSource event_source);
 extern int event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd);
 extern void event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd,
                             DeviceEvent *event);
diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 7fd6a48..02e820b 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -126,7 +126,7 @@ AccessXKeyboardEvent(DeviceIntPtr keybd, int type, BYTE keyCode, Bool isRepeat)
 {
     DeviceEvent event;
 
-    init_device_event(&event, keybd, GetTimeInMillis());
+    init_device_event(&event, keybd, GetTimeInMillis(), EVENT_SOURCE_NORMAL);
     event.type = type;
     event.detail.key = keyCode;
     event.key_repeat = isRepeat;
-- 
2.5.0



More information about the xorg-devel mailing list