[PATCH 2/3] dix: add aux. functions for button_is_down, set_button_down, set_button_up.

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 5 16:31:31 PDT 2010


Same as the matching key functions. Buttons, like keys, can have two states
for down/up - one posted, one processed. Posted is set during event
generation (usually in the signal handler). Processed is set during event
processing when the event queue is emptied and events are being delivered to
the client.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---

> Want to add and use button equivalents for completeness, and then get
> rid of kptr? :)

your wish, my command and whatnot.

 Xi/exevents.c   |   14 ++++++--------
 dix/getevents.c |   35 +++++++++++++++++++++++++++++++++--
 include/input.h |    9 +++++++--
 3 files changed, 46 insertions(+), 12 deletions(-)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index df13190..e990aeb 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -747,7 +747,6 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
     KeyClassPtr k       = NULL;
     ButtonClassPtr b    = NULL;
     ValuatorClassPtr v  = NULL;
-    BYTE *kptr          = NULL;
 
     /* This event is always the first we get, before the actual events with
      * the data. However, the way how the DDX is set up, "device" will
@@ -835,10 +834,10 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
         if (!b)
             return DONT_PROCESS;
 
-        kptr = &b->down[key >> 3];
-        if ((*kptr & bit) != 0)
+        if (button_is_down(device, key, BUTTON_PROCESSED))
             return DONT_PROCESS;
-        *kptr |= bit;
+
+        set_button_down(device, key, BUTTON_PROCESSED);
 	if (device->valuator)
 	    device->valuator->motionHintWindow = NullWindow;
         if (!b->map[key])
@@ -858,8 +857,7 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
         if (!b)
             return DONT_PROCESS;
 
-        kptr = &b->down[key>>3];
-        if (!(*kptr & bit))
+        if (!button_is_down(device, key, BUTTON_PROCESSED))
             return DONT_PROCESS;
         if (IsMaster(device)) {
             DeviceIntPtr sd;
@@ -874,11 +872,11 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
                     continue;
                 if (!sd->button)
                     continue;
-                if ((sd->button->down[key>>3] & bit) != 0)
+                if (button_is_down(sd, key, BUTTON_PROCESSED))
                     return DONT_PROCESS;
             }
         }
-        *kptr &= ~bit;
+        set_button_up(device, key, BUTTON_PROCESSED);
 	if (device->valuator)
 	    device->valuator->motionHintWindow = NullWindow;
         if (!b->map[key])
diff --git a/dix/getevents.c b/dix/getevents.c
index 1d505e5..a9b6e82 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -91,6 +91,37 @@ GetMotionHistorySize(void)
 }
 
 void
+set_button_down(DeviceIntPtr pDev, int button, int type)
+{
+    if (type == BUTTON_PROCESSED)
+        SetBit(pDev->button->down, button);
+    else
+        SetBit(pDev->button->postdown, button);
+}
+
+void
+set_button_up(DeviceIntPtr pDev, int button, int type)
+{
+    if (type == BUTTON_PROCESSED)
+        ClearBit(pDev->button->down, button);
+    else
+        ClearBit(pDev->button->postdown, button);
+}
+
+Bool
+button_is_down(DeviceIntPtr pDev, int button, int type)
+{
+    int ret = 0;
+
+    if (type & BUTTON_PROCESSED)
+        ret |= !!BitIsOn(pDev->button->down, button);
+    if (type & BUTTON_POSTED)
+        ret |= !!BitIsOn(pDev->button->postdown, button);
+
+    return ret;
+}
+
+void
 set_key_down(DeviceIntPtr pDev, int key_code, int type)
 {
     if (type == KEY_PROCESSED)
@@ -1123,11 +1154,11 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
     else {
         if (type == ButtonPress) {
             event->type = ET_ButtonPress;
-            pDev->button->postdown[buttons >> 3] |= (1 << (buttons & 7));
+            set_button_down(pDev, buttons, BUTTON_POSTED);
         }
         else if (type == ButtonRelease) {
             event->type = ET_ButtonRelease;
-            pDev->button->postdown[buttons >> 3] &= ~(1 << (buttons & 7));
+            set_button_up(pDev, buttons, BUTTON_POSTED);
         }
         event->detail.button = buttons;
     }
diff --git a/include/input.h b/include/input.h
index 0a08ea4..55b1537 100644
--- a/include/input.h
+++ b/include/input.h
@@ -228,14 +228,19 @@ typedef struct _InputAttributes {
 #define ATTR_TOUCHPAD (1<<4)
 #define ATTR_TOUCHSCREEN (1<<5)
 
-/* Key has been run through all input processing and events sent to clients. */
+/* Key/Button has been run through all input processing and events sent to clients. */
 #define KEY_PROCESSED 1
-/* Key has not been fully processed, no events have been sent. */
+#define BUTTON_PROCESSED 1
+/* Key/Button has not been fully processed, no events have been sent. */
 #define KEY_POSTED 2
+#define BUTTON_POSTED 2
 
 extern void set_key_down(DeviceIntPtr pDev, int key_code, int type);
 extern void set_key_up(DeviceIntPtr pDev, int key_code, int type);
 extern int key_is_down(DeviceIntPtr pDev, int key_code, int type);
+extern void set_button_down(DeviceIntPtr pDev, int button, int type);
+extern void set_button_up(DeviceIntPtr pDev, int button, int type);
+extern int button_is_down(DeviceIntPtr pDev, int button, int type);
 
 extern void InitCoreDevices(void);
 extern void InitXTestDevices(void);
-- 
1.7.1


More information about the xorg-devel mailing list