[PATCH] mi: ensure chained button mappings from SD -> MD (#19282)

Peter Hutterer peter.hutterer at who-t.net
Wed Jan 7 19:16:18 PST 2009


After copying the master event, flip the detail field to the mapped button of
the SD, not the physical button. This way if the SD has a mapping 1:3 and the
MD has a mapping of 3:4, a press on button 1 on the SD results in a core event
on button 4.

X.Org Bug 19282 <http://bugs.freedesktop.org/show_bug.cgi?id=19282>

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 mi/mieq.c       |   26 ++++++++++++++++++++++++--
 xkb/ddxDevBtn.c |    2 +-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/mi/mieq.c b/mi/mieq.c
index 82bbb2c..e1f647d 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -277,15 +277,32 @@ ChangeDeviceID(DeviceIntPtr dev, xEvent* event)
         DebugF("[mi] Unknown event type (%d), cannot change id.\n", type);
 }
 
+static void
+FixUpEventForMaster(DeviceIntPtr mdev, DeviceIntPtr sdev, xEvent* original,
+                    EventListPtr master, int count)
+{
+    /* Ensure chained button mappings, i.e. that the detail field is the
+     * value of the mapped button on the SD, not the physical button */
+    if (original->u.u.type == DeviceButtonPress || original->u.u.type == DeviceButtonRelease)
+    {
+        int btn = original->u.u.detail;
+        if (!sdev->button)
+            return; /* Should never happen */
+
+        master->event->u.u.detail = sdev->button->map[btn];
+    }
+}
+
 /**
  * Copy the given event into master.
  * @param mdev The master device
+ * @param sdev The slave device the original event comes from
  * @param original The event as it came from the EQ
  * @param master The event after being copied
  * @param count Number of events in original.
  */
 void
-CopyGetMasterEvent(DeviceIntPtr mdev, xEvent* original,
+CopyGetMasterEvent(DeviceIntPtr mdev, DeviceIntPtr sdev, xEvent* original,
                    EventListPtr master, int count)
 {
     int len = count * sizeof(xEvent);
@@ -300,9 +317,14 @@ CopyGetMasterEvent(DeviceIntPtr mdev, xEvent* original,
 
     memcpy(master->event, original, len);
     while (count--)
+    {
         ChangeDeviceID(mdev, &master->event[count]);
+        FixUpEventForMaster(mdev, sdev, original, master, count);
+    }
 }
 
+
+
 /* Call this from ProcessInputEvents(). */
 void
 mieqProcessInputEvents(void)
@@ -365,7 +387,7 @@ mieqProcessInputEvents(void)
         }
         else {
             if (master)
-                CopyGetMasterEvent(master, event, masterEvents, nevents);
+                CopyGetMasterEvent(master, dev, event, masterEvents, nevents);
 
             /* If someone's registered a custom event handler, let them
              * steal it. */
diff --git a/xkb/ddxDevBtn.c b/xkb/ddxDevBtn.c
index 709efc1..03fb440 100644
--- a/xkb/ddxDevBtn.c
+++ b/xkb/ddxDevBtn.c
@@ -116,7 +116,7 @@ DeviceIntPtr		master = NULL;
         if (!IsPointerDevice(master))
             master = GetPairedDevice(dev->u.master);
 
-        CopyGetMasterEvent(master, &events, masterEvents, count);
+        CopyGetMasterEvent(master, dev, &events, masterEvents, count);
     }
 
     (*dev->public.processInputProc)((xEventPtr)btn, dev, count);
-- 
1.6.0.6



More information about the xorg mailing list