Xi: keep a counter of buttons down to avoid duplicate press/release events.

If two devices are attached to the same master device, pressing button 1 on
each of them leads to two button presses from the same device. Some apps
really don't like that.

So we just put a counter in place and only send the first press and the last
release.
This commit is contained in:
Peter Hutterer 2008-01-09 17:36:39 +10:30
parent 20ace6321a
commit 4e85c7c322
3 changed files with 24 additions and 9 deletions

View File

@ -348,13 +348,28 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to)
}
ALLOC_COPY_CLASS_IF(button, ButtonClassRec);
#ifdef XKB
if (to->button)
{
int i;
DeviceIntPtr sd;
memset(to->button, 0, MAP_LENGTH);
/* 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++)
{
to->button->down[i] += sd->button->down[i];
}
}
#ifdef XKB
to->button->xkb_acts = NULL;
/* XXX: XkbAction needs to be copied */
}
#endif
}
ALLOC_COPY_CLASS_IF(focus, FocusClassRec);
ALLOC_COPY_CLASS_IF(proximity, ProximityClassRec);
ALLOC_COPY_CLASS_IF(absolute, AbsoluteClassRec);
@ -541,8 +556,8 @@ UpdateDeviceState(DeviceIntPtr device, xEvent* xE, int count)
if (!b)
return DONT_PROCESS;
kptr = &b->down[key >> 3];
*kptr |= bit;
if (b->down[key]++ > 0)
return DONT_PROCESS;
if (device->valuator)
device->valuator->motionHintWindow = NullWindow;
b->buttonsDown++;
@ -556,10 +571,10 @@ UpdateDeviceState(DeviceIntPtr device, xEvent* xE, int count)
if (!b)
return DONT_PROCESS;
kptr = &b->down[key >> 3];
if (!(*kptr & bit))
if (b->down[key] == 0)
return DONT_PROCESS;
if (--b->down[key] > 0)
return DONT_PROCESS;
*kptr &= ~bit;
if (device->valuator)
device->valuator->motionHintWindow = NullWindow;
if (b->buttonsDown >= 1 && !--b->buttonsDown)

View File

@ -1178,7 +1178,7 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons,
butc->buttonsDown = 0;
butc->state = 0;
butc->motionMask = 0;
bzero((char *)butc->down, DOWN_LENGTH);
bzero((char *)butc->down, MAP_LENGTH);
#ifdef XKB
butc->xkb_acts= NULL;
#endif

View File

@ -184,7 +184,7 @@ typedef struct _ButtonClassRec {
CARD8 buttonsDown; /* number of buttons currently down */
unsigned short state;
Mask motionMask;
CARD8 down[DOWN_LENGTH];
CARD8 down[MAP_LENGTH];
CARD8 map[MAP_LENGTH];
#ifdef XKB
union _XkbAction *xkb_acts;