diff options
author | Peter Hutterer <peter@cs.unisa.edu.au> | 2008-06-15 20:00:41 +0930 |
---|---|---|
committer | Peter Hutterer <peter@cs.unisa.edu.au> | 2008-06-18 10:17:08 +0930 |
commit | d21155a3e9b51df946766926bc6155c8972c4439 (patch) | |
tree | e0273dd5288f36aedeacd5a4ebfb9116e5080902 | |
parent | 2b9c829bdebd16910bdf48b9d64862e3d34f5b7f (diff) |
input: fix up usage of button->down, used to be a bitmask, is now an array.
device->button->down used to be a 32-byte bitmask with one bit for each
button. This has changed into a 256-byte array, with one byte assigned for
each button. Some of the callers were still using this array as a bitmask
however, this is fixed with this patch.
Thanks to Keith Packard for pointing this out. See also:
http://lists.freedesktop.org/archives/xorg/2008-June/036202.html
-rw-r--r-- | Xi/exevents.c | 10 | ||||
-rw-r--r-- | Xi/queryst.c | 6 | ||||
-rw-r--r-- | dix/devices.c | 2 | ||||
-rw-r--r-- | dix/events.c | 4 | ||||
-rw-r--r-- | include/inputstr.h | 3 | ||||
-rw-r--r-- | xkb/xkbActions.c | 4 |
6 files changed, 16 insertions, 13 deletions
diff --git a/Xi/exevents.c b/Xi/exevents.c index 6f88b57f3..4736a1284 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -1153,9 +1153,11 @@ FixDeviceStateNotify(DeviceIntPtr dev, deviceStateNotify * ev, KeyClassPtr k, ev->num_valuators = 0; if (b) { + int i; ev->classes_reported |= (1 << ButtonClass); ev->num_buttons = b->numButtons; - memmove((char *)&ev->buttons[0], (char *)b->down, 4); + for (i = 0; i < 32; i++) + SetBitIf(ev->buttons, b->down, i); } else if (k) { ev->classes_reported |= (1 << KeyClass); ev->num_keys = k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode; @@ -1270,11 +1272,13 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, first += 3; nval -= 3; if (nbuttons > 32) { + int i; (ev - 1)->deviceid |= MORE_EVENTS; bev = (deviceButtonStateNotify *) ev++; bev->type = DeviceButtonStateNotify; bev->deviceid = dev->id; - memmove((char *)&bev->buttons[0], (char *)&b->down[4], 28); + for (i = 32; i < MAP_LENGTH; i++) + SetBitIf(bev->buttons, b->down, i); } if (nval > 0) { (ev - 1)->deviceid |= MORE_EVENTS; @@ -1692,7 +1696,7 @@ SetButtonMapping(ClientPtr client, DeviceIntPtr dev, int nElts, BYTE * map) if (BadDeviceMap(&map[0], nElts, 1, 255, &client->errorValue)) return BadValue; for (i = 0; i < nElts; i++) - if ((b->map[i + 1] != map[i]) && BitIsOn(b->down, i + 1)) + if ((b->map[i + 1] != map[i]) && (b->down[i + 1])) return MappingBusy; for (i = 0; i < nElts; i++) b->map[i + 1] = map[i]; diff --git a/Xi/queryst.c b/Xi/queryst.c index 71ab79be8..268bdd78b 100644 --- a/Xi/queryst.c +++ b/Xi/queryst.c @@ -119,7 +119,7 @@ ProcXQueryDeviceState(ClientPtr client) total_length += (sizeof(xValuatorState) + (v->numAxes * sizeof(int))); num_classes++; } - buf = (char *)xalloc(total_length); + buf = (char *)xcalloc(total_length, 1); if (!buf) return BadAlloc; savbuf = buf; @@ -139,8 +139,8 @@ ProcXQueryDeviceState(ClientPtr client) tb->class = ButtonClass; tb->length = sizeof(xButtonState); tb->num_buttons = b->numButtons; - for (i = 0; i < 32; i++) - tb->buttons[i] = b->down[i]; + for (i = 0; i < MAP_LENGTH; i++) + SetBitIf(tb->buttons, b->down, i); buf += sizeof(xButtonState); } diff --git a/dix/devices.c b/dix/devices.c index b88d856e6..3581cde8f 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -1734,7 +1734,7 @@ DoSetPointerMapping(ClientPtr client, DeviceIntPtr device, BYTE *map, int n) if ((dev->coreEvents || dev == inputInfo.pointer) && dev->button) { for (i = 0; i < n; i++) { if ((device->button->map[i + 1] != map[i]) && - BitIsOn(device->button->down, i + 1)) { + device->button->down[i + 1]) { return MappingBusy; } } diff --git a/dix/events.c b/dix/events.c index 81919737a..a35e9e404 100644 --- a/dix/events.c +++ b/dix/events.c @@ -4077,15 +4077,11 @@ ProcessPointerEvent (xEvent *xE, DeviceIntPtr mouse, int count) if (xE->u.u.type != MotionNotify) { int key; - BYTE *kptr; - int bit; XE_KBPTR.rootX = pSprite->hot.x; XE_KBPTR.rootY = pSprite->hot.y; key = xE->u.u.detail; - kptr = &butc->down[key >> 3]; - bit = 1 << (key & 7); switch (xE->u.u.type) { case ButtonPress: diff --git a/include/inputstr.h b/include/inputstr.h index 7209b2cb3..11fe031a0 100644 --- a/include/inputstr.h +++ b/include/inputstr.h @@ -57,6 +57,9 @@ SOFTWARE. #include "privates.h" #define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7))) +/* If byte[i] in src is non-zero, set bit i in dst, otherwise set bit to 0 */ +#define SetBitIf(dst, src, i) \ + (src[i]) ? (dst[i/8] |= (1 << (i % 8))) : (dst[i/8] &= ~(1 << (i % 8))); #define SameClient(obj,client) \ (CLIENT_BITS((obj)->resource) == (client)->clientAsMask) diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c index 41b4e4c8e..8a2682562 100644 --- a/xkb/xkbActions.c +++ b/xkb/xkbActions.c @@ -1045,7 +1045,7 @@ int button; switch (pAction->type) { case XkbSA_LockDeviceBtn: if ((pAction->devbtn.flags&XkbSA_LockNoLock)|| - (dev->button->down[button/8]&(1L<<(button%8)))) + (dev->button->down[button])) return 0; XkbDDXFakeDeviceButton(dev,True,button); filter->upAction.type= XkbSA_NoAction; @@ -1077,7 +1077,7 @@ int button; switch (filter->upAction.type) { case XkbSA_LockDeviceBtn: if ((filter->upAction.devbtn.flags&XkbSA_LockNoUnlock)|| - ((dev->button->down[button/8]&(1L<<(button%8)))==0)) + ((dev->button->down[button])==0)) return 0; XkbDDXFakeDeviceButton(dev,False,button); break; |