button->down used inconsistently

Keith Packard keithp at keithp.com
Sat Jun 14 13:31:58 PDT 2008


Some parts of the server use button->down as a bitmask, other parts use
it as a per-button down count. It seems like using it consistently as a
bitmask would match the keyboard behaviour nicely. Also, lots of the
server already uses this as a bitmask, so changing that would be a lot
more invasive.

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 57fb65b..8a9619c 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -604,17 +604,17 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to)
         }
 
         to->button->buttonsDown = 0;
-        memset(to->button->down, 0, MAP_LENGTH);
+        memset(to->button->down, 0, sizeof (to->button->down));
         /* merge button states from all attached devices */
         for (sd = inputInfo.devices; sd; sd = sd->next)
         {
             if (sd->isMaster || sd->u.master != to)
                 continue;
 
-            for (i = 0; i < MAP_LENGTH; i++)
+            for (i = 0; i < sizeof (to->button->down); i++)
             {
-                to->button->down[i] += sd->button->down[i];
-                to->button->buttonsDown++;
+                to->button->down[i] |= sd->button->down[i];
+                to->button->buttonsDown += Ones(sd->button->down[i]);
             }
         }
 #ifdef XKB
@@ -923,8 +923,10 @@ UpdateDeviceState(DeviceIntPtr device, xEvent* xE, int count)
         if (!b)
             return DONT_PROCESS;
 
-        if (b->down[key]++ > 0)
+	kptr = &b->down[key >> 3];
+        if ((*kptr & bit) != 0)
             return DONT_PROCESS;
+	*kptr |= bit;
 	if (device->valuator)
 	    device->valuator->motionHintWindow = NullWindow;
         b->buttonsDown++;
@@ -938,10 +940,10 @@ UpdateDeviceState(DeviceIntPtr device, xEvent* xE, int count)
         if (!b)
             return DONT_PROCESS;
 
-        if (b->down[key] == 0)
-            return DONT_PROCESS;
-        if (--b->down[key] > 0)
+	kptr = &b->down[key >> 3];
+        if (!(*kptr & bit))
             return DONT_PROCESS;
+	*kptr &= ~bit;
 	if (device->valuator)
 	    device->valuator->motionHintWindow = NullWindow;
         if (b->buttonsDown >= 1 && !--b->buttonsDown)
diff --git a/dix/devices.c b/dix/devices.c
index b88d856..8eb6c25 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1153,7 +1153,7 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons,
     butc->buttonsDown = 0;
     butc->state = 0;
     butc->motionMask = 0;
-    bzero((char *)butc->down, MAP_LENGTH);
+    bzero((char *)butc->down, sizeof(butc->down));
 #ifdef XKB
     butc->xkb_acts=	NULL;
 #endif
diff --git a/include/inputstr.h b/include/inputstr.h
index 7209b2c..de66167 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -183,7 +183,7 @@ typedef struct _ButtonClassRec {
     CARD8		buttonsDown;	/* number of buttons currently down */
     unsigned short	state;
     Mask		motionMask;
-    CARD8		down[MAP_LENGTH];
+    CARD8		down[DOWN_LENGTH];
     CARD8		map[MAP_LENGTH];
 #ifdef XKB
     union _XkbAction    *xkb_acts;

-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.x.org/archives/xorg/attachments/20080614/c59c4563/attachment.pgp>


More information about the xorg mailing list