xkb: when faking mouse button events, fake them on the correct devices.

When MouseKeys are activated, keyboard devices may generate fake mouse button
events through XKB. Let's get then running through the appropriate paths, i.e.
as XI events on the correct device.

To make matters more fun, ProcessOtherEvents drops events if the DIX device
state cannot be updated accordingly, i.e. all button events from keyboard
devices.
Hence we need to get the paired MD for the device in XkbDDXFakeDeviceButton,
and post the event through the paired MD (usually the VCP).

Removes now-unused ddxFakeBtn.c.

Note: this patch only half-arsedly fixed button events, motion events are a
more complicated matter.
This commit is contained in:
Peter Hutterer 2008-10-31 14:36:48 +10:30
parent 4971315296
commit cbc6f98395
6 changed files with 34 additions and 73 deletions

View File

@ -274,7 +274,7 @@ ChangeDeviceID(DeviceIntPtr dev, xEvent* event)
* @param master The event after being copied
* @param count Number of events in original.
*/
static void
void
CopyGetMasterEvent(DeviceIntPtr mdev, xEvent* original,
xEvent** master, int count)
{

View File

@ -6,7 +6,6 @@ AM_CFLAGS = $(DIX_CFLAGS) \
DDX_SRCS = \
ddxBeep.c \
ddxCtrls.c \
ddxFakeBtn.c \
ddxFakeMtn.c \
ddxInit.c \
ddxKeyClick.c \

View File

@ -47,11 +47,13 @@ XkbDDXFakeDeviceButton(DeviceIntPtr dev,Bool press,int button)
{
int * devVal;
INT32 * evVal;
xEvent events[2];
xEvent events[2],
*m_events = NULL; /* master dev */
deviceKeyButtonPointer *btn;
deviceValuator * val;
int x,y;
int nAxes, i, count;
DeviceIntPtr master = NULL;
if (dev == inputInfo.pointer || !dev->public.on)
return;
@ -95,6 +97,28 @@ int nAxes, i, count;
count= 1+((nAxes+5)/6);
}
/* XXX: This is obnoxious. ProcessOtherEvent updates the DIX device state,
* but may not do anything if the device state is invalid. This happens if
* we post a mouse event from a pure keyboard device. So we need to hack
* around that by getting the master, then posting the event for the
* pointer paired with the master.
*
* Note:the DeviceButtonEvent on the SD itself will do nothing in most
* cases, unless dev is both a keyboard and a mouse.
*/
if (!dev->isMaster && dev->u.master) {
master = dev->u.master;
if (!IsPointerDevice(master))
master = GetPairedDevice(dev->u.master);
CopyGetMasterEvent(master, &events, &m_events, count);
}
(*dev->public.processInputProc)((xEventPtr)btn, dev, count);
if (master) {
(*master->public.processInputProc)(m_events, master, count);
xfree(m_events);
}
return;
}

View File

@ -1,59 +0,0 @@
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <stdio.h>
#define NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <xkbsrv.h>
#include <X11/extensions/XI.h>
void
XkbDDXFakePointerButton(int event,int button)
{
xEvent ev;
int x,y;
DevicePtr ptr;
if ((ptr = (DevicePtr)inputInfo.pointer)==NULL)
return;
GetSpritePosition(inputInfo.pointer, &x,&y);
ev.u.u.type = event;
ev.u.u.detail = button;
ev.u.keyButtonPointer.time = GetTimeInMillis();
ev.u.keyButtonPointer.rootX = x;
ev.u.keyButtonPointer.rootY = y;
(*ptr->processInputProc)( &ev, (DeviceIntPtr)ptr, 1 );
return;
}

View File

@ -595,9 +595,6 @@ _XkbFilterPointerBtn( XkbSrvInfoPtr xkbi,
unsigned keycode,
XkbAction * pAction)
{
if (xkbi->device == inputInfo.keyboard)
return 0;
if (filter->keycode==0) { /* initial press */
int button= pAction->btn.button;
@ -617,7 +614,7 @@ _XkbFilterPointerBtn( XkbSrvInfoPtr xkbi,
((pAction->btn.flags&XkbSA_LockNoLock)==0)) {
xkbi->lockedPtrButtons|= (1<<button);
AccessXCancelRepeatKey(xkbi,keycode);
XkbDDXFakePointerButton(ButtonPress,button);
XkbDDXFakeDeviceButton(xkbi->device, 1, button);
filter->upAction.type= XkbSA_NoAction;
}
break;
@ -628,12 +625,12 @@ _XkbFilterPointerBtn( XkbSrvInfoPtr xkbi,
if (pAction->btn.count>0) {
nClicks= pAction->btn.count;
for (i=0;i<nClicks;i++) {
XkbDDXFakePointerButton(ButtonPress,button);
XkbDDXFakePointerButton(ButtonRelease,button);
XkbDDXFakeDeviceButton(xkbi->device, 1, button);
XkbDDXFakeDeviceButton(xkbi->device, 0, button);
}
filter->upAction.type= XkbSA_NoAction;
}
else XkbDDXFakePointerButton(ButtonPress,button);
else XkbDDXFakeDeviceButton(xkbi->device, 1, button);
}
break;
case XkbSA_SetPtrDflt:
@ -689,7 +686,7 @@ _XkbFilterPointerBtn( XkbSrvInfoPtr xkbi,
}
xkbi->lockedPtrButtons&= ~(1<<button);
case XkbSA_PtrBtn:
XkbDDXFakePointerButton(ButtonRelease,button);
XkbDDXFakeDeviceButton(xkbi->device, 0, button);
break;
}
filter->active = 0;

View File

@ -870,7 +870,7 @@ XkbSrvInfoPtr xkbi;
* Faking a release of the button here solves the problem.
*/
DebugF("[xkb] Faking release of button %d\n", xE[0].u.u.detail);
XkbDDXFakePointerButton(ButtonRelease, xE[0].u.u.detail);
XkbDDXFakeDeviceButton(xkbi->device, 0, xE[0].u.u.detail);
}
}
else {
@ -923,12 +923,12 @@ XkbSrvInfoPtr xkbi;
((xE[i].u.keyButtonPointer.state >> 7) & button_mask) == button_mask &&
(xkbi->lockedPtrButtons & button_mask) == button_mask) {
DebugF("[xkb] Faking release of button %d\n", xE[i].u.u.detail);
XkbDDXFakePointerButton(ButtonRelease, xE[i].u.u.detail);
XkbDDXFakeDeviceButton(xkbi->device, 0, xE[i].u.u.detail);
} else if (type == DeviceButtonPress &&
((((deviceKeyButtonPointer*)&xE[i])->state >> 7) & button_mask) == button_mask &&
(xkbi->lockedPtrButtons & button_mask) == button_mask) {
DebugF("[xkb] Faking release of button %d\n", ((deviceKeyButtonPointer*)&xE[i])->state);
XkbDDXFakePointerButton(DeviceButtonRelease, ((deviceKeyButtonPointer*)&xE[i])->state);
XkbDDXFakeDeviceButton(xkbi->device, 0, ((deviceKeyButtonPointer*)&xE[i])->state);
}
}
}