2006-11-26 11:13:41 -07:00
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
Copyright 1987, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
|
in this Software without prior written authorization from The Open Group.
|
|
|
|
|
|
|
|
|
|
|
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
2006-11-26 11:13:41 -07:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
2009-09-06 13:44:18 -06:00
|
|
|
both that copyright notice and this permission notice appear in
|
2006-11-26 11:13:41 -07:00
|
|
|
supporting documentation, and that the name of Digital not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
2009-09-06 13:44:18 -06:00
|
|
|
software without specific, written prior permission.
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
DIGITAL 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 <X11/X.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "resource.h"
|
|
|
|
#include <X11/Xproto.h>
|
2009-09-06 13:44:18 -06:00
|
|
|
#include <X11/Xatom.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "windowstr.h"
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "cursorstr.h"
|
|
|
|
#include "dixstruct.h"
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "ptrveloc.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "site.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "xkbsrv.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "privates.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "xace.h"
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "mi.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#include "dispatch.h"
|
|
|
|
#include "swaprep.h"
|
|
|
|
#include "dixevents.h"
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "mipointer.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "eventstr.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
#include <X11/extensions/XI.h>
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <X11/extensions/XI2.h>
|
2007-11-24 12:04:00 -07:00
|
|
|
#include <X11/extensions/XIproto.h>
|
2010-12-05 08:36:02 -07:00
|
|
|
#include <math.h>
|
|
|
|
#include <pixman.h>
|
2007-11-24 12:04:00 -07:00
|
|
|
#include "exglobals.h"
|
|
|
|
#include "exevents.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "xiquerydevice.h" /* for SizeDeviceClasses */
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "xiproperty.h"
|
|
|
|
#include "enterleave.h" /* for EnterWindow() */
|
|
|
|
#include "xserver-properties.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "xichangehierarchy.h" /* For XISendDeviceHierarchyEvent */
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
* This file handles input device-related stuff.
|
|
|
|
*/
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
static void RecalculateMasterButtons(DeviceIntPtr slave);
|
|
|
|
|
|
|
|
static void
|
|
|
|
DeviceSetTransform(DeviceIntPtr dev, float *transform)
|
|
|
|
{
|
|
|
|
struct pixman_f_transform scale;
|
|
|
|
double sx, sy;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* calculate combined transformation matrix:
|
|
|
|
*
|
|
|
|
* M = InvScale * Transform * Scale
|
|
|
|
*
|
|
|
|
* So we can later transform points using M * p
|
|
|
|
*
|
|
|
|
* Where:
|
|
|
|
* Scale scales coordinates into 0..1 range
|
|
|
|
* Transform is the user supplied (affine) transform
|
|
|
|
* InvScale scales coordinates back up into their native range
|
|
|
|
*/
|
|
|
|
sx = dev->valuator->axes[0].max_value - dev->valuator->axes[0].min_value;
|
|
|
|
sy = dev->valuator->axes[1].max_value - dev->valuator->axes[1].min_value;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
/* invscale */
|
|
|
|
pixman_f_transform_init_scale(&scale, sx, sy);
|
|
|
|
scale.m[0][2] = dev->valuator->axes[0].min_value;
|
|
|
|
scale.m[1][2] = dev->valuator->axes[1].min_value;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
/* transform */
|
|
|
|
for (y=0; y<3; y++)
|
|
|
|
for (x=0; x<3; x++)
|
|
|
|
dev->transform.m[y][x] = *transform++;
|
|
|
|
|
|
|
|
pixman_f_transform_multiply(&dev->transform, &scale, &dev->transform);
|
|
|
|
|
|
|
|
/* scale */
|
|
|
|
pixman_f_transform_init_scale(&scale, 1.0 / sx, 1.0 / sy);
|
|
|
|
scale.m[0][2] = -dev->valuator->axes[0].min_value / sx;
|
|
|
|
scale.m[1][2] = -dev->valuator->axes[1].min_value / sy;
|
|
|
|
|
|
|
|
pixman_f_transform_multiply(&dev->transform, &dev->transform, &scale);
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/**
|
|
|
|
* DIX property handler.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
DeviceSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
|
|
|
|
BOOL checkonly)
|
|
|
|
{
|
|
|
|
if (property == XIGetKnownProperty(XI_PROP_ENABLED))
|
|
|
|
{
|
|
|
|
if (prop->format != 8 || prop->type != XA_INTEGER || prop->size != 1)
|
|
|
|
return BadValue;
|
|
|
|
|
|
|
|
/* Don't allow disabling of VCP/VCK */
|
|
|
|
if ((dev == inputInfo.pointer || dev == inputInfo.keyboard) &&
|
|
|
|
!(*(CARD8*)prop->data))
|
|
|
|
return BadAccess;
|
|
|
|
|
|
|
|
if (!checkonly)
|
|
|
|
{
|
|
|
|
if ((*((CARD8*)prop->data)) && !dev->enabled)
|
2010-07-27 13:02:24 -06:00
|
|
|
EnableDevice(dev, TRUE);
|
2009-09-06 13:44:18 -06:00
|
|
|
else if (!(*((CARD8*)prop->data)) && dev->enabled)
|
2010-07-27 13:02:24 -06:00
|
|
|
DisableDevice(dev, TRUE);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
} else if (property == XIGetKnownProperty(XI_PROP_TRANSFORM))
|
|
|
|
{
|
|
|
|
float *f = (float*)prop->data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (prop->format != 32 || prop->size != 9 ||
|
|
|
|
prop->type != XIGetKnownProperty(XATOM_FLOAT))
|
|
|
|
return BadValue;
|
|
|
|
|
|
|
|
for (i=0; i<9; i++)
|
|
|
|
if (!isfinite(f[i]))
|
|
|
|
return BadValue;
|
|
|
|
|
|
|
|
if (!checkonly)
|
|
|
|
DeviceSetTransform(dev, f);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pair the keyboard to the pointer device. Keyboard events will follow the
|
|
|
|
* pointer sprite. Only applicable for master devices.
|
|
|
|
* If the client is set, the request to pair comes from some client. In this
|
|
|
|
* case, we need to check for access. If the client is NULL, it's from an
|
|
|
|
* internal automatic pairing, we must always permit this.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
PairDevices(ClientPtr client, DeviceIntPtr ptr, DeviceIntPtr kbd)
|
|
|
|
{
|
|
|
|
if (!ptr)
|
|
|
|
return BadDevice;
|
|
|
|
|
|
|
|
/* Don't allow pairing for slave devices */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!IsMaster(ptr) || !IsMaster(kbd))
|
2009-09-06 13:44:18 -06:00
|
|
|
return BadDevice;
|
|
|
|
|
|
|
|
if (ptr->spriteInfo->paired)
|
|
|
|
return BadDevice;
|
|
|
|
|
|
|
|
if (kbd->spriteInfo->spriteOwner)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
free(kbd->spriteInfo->sprite);
|
2009-09-06 13:44:18 -06:00
|
|
|
kbd->spriteInfo->sprite = NULL;
|
|
|
|
kbd->spriteInfo->spriteOwner = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
kbd->spriteInfo->sprite = ptr->spriteInfo->sprite;
|
|
|
|
kbd->spriteInfo->paired = ptr;
|
|
|
|
ptr->spriteInfo->paired = kbd;
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find and return the next unpaired MD pointer device.
|
|
|
|
*/
|
|
|
|
static DeviceIntPtr
|
|
|
|
NextFreePointerDevice(void)
|
|
|
|
{
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
for (dev = inputInfo.devices; dev; dev = dev->next)
|
2010-07-27 13:02:24 -06:00
|
|
|
if (IsMaster(dev) &&
|
2009-09-06 13:44:18 -06:00
|
|
|
dev->spriteInfo->spriteOwner &&
|
|
|
|
!dev->spriteInfo->paired)
|
|
|
|
return dev;
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new input device and init it to sane values. The device is added
|
|
|
|
* to the server's off_devices list.
|
|
|
|
*
|
|
|
|
* @param deviceProc Callback for device control function (switch dev on/off).
|
|
|
|
* @return The newly created device.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
DeviceIntPtr
|
2009-09-06 13:44:18 -06:00
|
|
|
AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
DeviceIntPtr dev, *prev; /* not a typo */
|
|
|
|
DeviceIntPtr devtmp;
|
|
|
|
int devid;
|
2009-09-06 13:44:18 -06:00
|
|
|
char devind[MAXDEVICES];
|
|
|
|
BOOL enabled;
|
2010-12-05 08:36:02 -07:00
|
|
|
float transform[9];
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* Find next available id, 0 and 1 are reserved */
|
2009-09-06 13:44:18 -06:00
|
|
|
memset(devind, 0, sizeof(char)*MAXDEVICES);
|
2007-11-24 12:04:00 -07:00
|
|
|
for (devtmp = inputInfo.devices; devtmp; devtmp = devtmp->next)
|
|
|
|
devind[devtmp->id]++;
|
|
|
|
for (devtmp = inputInfo.off_devices; devtmp; devtmp = devtmp->next)
|
|
|
|
devind[devtmp->id]++;
|
2010-07-27 13:02:24 -06:00
|
|
|
for (devid = 2; devid < MAXDEVICES && devind[devid]; devid++)
|
2007-11-24 12:04:00 -07:00
|
|
|
;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (devid >= MAXDEVICES)
|
2006-11-26 11:13:41 -07:00
|
|
|
return (DeviceIntPtr)NULL;
|
2010-12-05 08:36:02 -07:00
|
|
|
dev = _dixAllocateObjectWithPrivates(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec),
|
|
|
|
sizeof(DeviceIntRec) + sizeof(SpriteInfoRec),
|
|
|
|
offsetof(DeviceIntRec, devPrivates), PRIVATE_DEVICE);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!dev)
|
|
|
|
return (DeviceIntPtr)NULL;
|
2007-11-24 12:04:00 -07:00
|
|
|
dev->id = devid;
|
2011-11-05 07:32:40 -06:00
|
|
|
dev->public.processInputProc = ProcessOtherEvent;
|
|
|
|
dev->public.realInputProc = ProcessOtherEvent;
|
2006-11-26 11:13:41 -07:00
|
|
|
dev->public.enqueueInputProc = EnqueueEvent;
|
|
|
|
dev->deviceProc = deviceProc;
|
|
|
|
dev->startup = autoStart;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* device grab defaults */
|
|
|
|
dev->deviceGrab.grabTime = currentTime;
|
|
|
|
dev->deviceGrab.ActivateGrab = ActivateKeyboardGrab;
|
|
|
|
dev->deviceGrab.DeactivateGrab = DeactivateKeyboardGrab;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
XkbSetExtension(dev, ProcessKeyboardEvent);
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
dev->coreEvents = TRUE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* sprite defaults */
|
|
|
|
dev->spriteInfo = (SpriteInfoPtr)&dev[1];
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* security creation/labeling check
|
|
|
|
*/
|
2009-09-06 13:44:18 -06:00
|
|
|
if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixCreateAccess)) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(dev);
|
2008-11-02 08:26:08 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inputInfo.numDevices++;
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
for (prev = &inputInfo.off_devices; *prev; prev = &(*prev)->next)
|
|
|
|
;
|
|
|
|
*prev = dev;
|
|
|
|
dev->next = NULL;
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
enabled = FALSE;
|
|
|
|
XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_ENABLED),
|
|
|
|
XA_INTEGER, 8, PropModeReplace, 1, &enabled,
|
|
|
|
FALSE);
|
|
|
|
XISetDevicePropertyDeletable(dev, XIGetKnownProperty(XI_PROP_ENABLED), FALSE);
|
2010-12-05 08:36:02 -07:00
|
|
|
|
|
|
|
/* unity matrix */
|
|
|
|
memset(transform, 0, sizeof(transform));
|
|
|
|
transform[0] = transform[4] = transform[8] = 1.0f;
|
|
|
|
|
|
|
|
XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_TRANSFORM),
|
|
|
|
XIGetKnownProperty(XATOM_FLOAT), 32,
|
|
|
|
PropModeReplace, 9, transform, FALSE);
|
|
|
|
XISetDevicePropertyDeletable(dev, XIGetKnownProperty(XI_PROP_TRANSFORM),
|
|
|
|
FALSE);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
XIRegisterPropertyHandler(dev, DeviceSetProperty, NULL, NULL);
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
|
|
|
SendDevicePresenceEvent(int deviceid, int type)
|
|
|
|
{
|
|
|
|
DeviceIntRec dummyDev;
|
|
|
|
devicePresenceNotify ev;
|
|
|
|
|
|
|
|
memset(&dummyDev, 0, sizeof(DeviceIntRec));
|
|
|
|
ev.type = DevicePresenceNotify;
|
|
|
|
ev.time = currentTime.milliseconds;
|
|
|
|
ev.devchange = type;
|
|
|
|
ev.deviceid = deviceid;
|
|
|
|
dummyDev.id = XIAllDevices;
|
|
|
|
SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
|
|
|
|
(xEvent*)&ev, 1);
|
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
/**
|
2009-09-06 13:44:18 -06:00
|
|
|
* Enable the device through the driver, add the device to the device list.
|
2007-11-24 12:04:00 -07:00
|
|
|
* Switch device ON through the driver and push it onto the global device
|
2009-09-06 13:44:18 -06:00
|
|
|
* list. Initialize the DIX sprite or pair the device. All clients are
|
|
|
|
* notified about the device being enabled.
|
2007-11-24 12:04:00 -07:00
|
|
|
*
|
2009-09-06 13:44:18 -06:00
|
|
|
* A master pointer device needs to be enabled before a master keyboard
|
|
|
|
* device.
|
2007-11-24 12:04:00 -07:00
|
|
|
*
|
|
|
|
* @param The device to be enabled.
|
2010-07-27 13:02:24 -06:00
|
|
|
* @param sendevent True if an XI2 event should be sent.
|
2007-11-24 12:04:00 -07:00
|
|
|
* @return TRUE on success or FALSE otherwise.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
Bool
|
2010-07-27 13:02:24 -06:00
|
|
|
EnableDevice(DeviceIntPtr dev, BOOL sendevent)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
DeviceIntPtr *prev;
|
|
|
|
int ret;
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr other;
|
|
|
|
BOOL enabled;
|
2010-07-27 13:02:24 -06:00
|
|
|
int flags[MAXDEVICES] = {0};
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (prev = &inputInfo.off_devices;
|
|
|
|
*prev && (*prev != dev);
|
|
|
|
prev = &(*prev)->next)
|
|
|
|
;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
if (!dev->spriteInfo->sprite)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
if (IsMaster(dev))
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
/* Sprites appear on first root window, so we can hardcode it */
|
|
|
|
if (dev->spriteInfo->spriteOwner)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
InitializeSprite(dev, screenInfo.screens[0]->root);
|
2009-09-06 13:44:18 -06:00
|
|
|
/* mode doesn't matter */
|
2010-12-05 08:36:02 -07:00
|
|
|
EnterWindow(dev, screenInfo.screens[0]->root, NotifyAncestor);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
else if ((other = NextFreePointerDevice()) == NULL)
|
|
|
|
{
|
|
|
|
ErrorF("[dix] cannot find pointer to pair with. "
|
|
|
|
"This is a bug.\n");
|
|
|
|
return FALSE;
|
|
|
|
} else
|
|
|
|
PairDevices(NULL, other, dev);
|
|
|
|
} else
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
if (dev->coreEvents)
|
|
|
|
other = (IsPointerDevice(dev)) ? inputInfo.pointer :
|
|
|
|
inputInfo.keyboard;
|
|
|
|
else
|
|
|
|
other = NULL; /* auto-float non-core devices */
|
2009-09-06 13:44:18 -06:00
|
|
|
AttachDevice(NULL, dev, other);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if ((*prev != dev) || !dev->inited ||
|
2007-11-24 12:04:00 -07:00
|
|
|
((ret = (*dev->deviceProc)(dev, DEVICE_ON)) != Success)) {
|
2009-09-06 13:44:18 -06:00
|
|
|
ErrorF("[dix] couldn't enable device %d\n", dev->id);
|
2006-11-26 11:13:41 -07:00
|
|
|
return FALSE;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
dev->enabled = TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
*prev = dev->next;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
for (prev = &inputInfo.devices; *prev; prev = &(*prev)->next)
|
|
|
|
;
|
|
|
|
*prev = dev;
|
|
|
|
dev->next = NULL;
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
enabled = TRUE;
|
|
|
|
XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_ENABLED),
|
|
|
|
XA_INTEGER, 8, PropModeReplace, 1, &enabled,
|
|
|
|
TRUE);
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
SendDevicePresenceEvent(dev->id, DeviceEnabled);
|
|
|
|
if (sendevent)
|
|
|
|
{
|
|
|
|
flags[dev->id] |= XIDeviceEnabled;
|
|
|
|
XISendDeviceHierarchyEvent(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
RecalculateMasterButtons(dev);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
/**
|
|
|
|
* Switch a device off through the driver and push it onto the off_devices
|
|
|
|
* list. A device will not send events while disabled. All clients are
|
|
|
|
* notified about the device being disabled.
|
|
|
|
*
|
2009-09-06 13:44:18 -06:00
|
|
|
* Master keyboard devices have to be disabled before master pointer devices
|
|
|
|
* otherwise things turn bad.
|
|
|
|
*
|
2010-07-27 13:02:24 -06:00
|
|
|
* @param sendevent True if an XI2 event should be sent.
|
2007-11-24 12:04:00 -07:00
|
|
|
* @return TRUE on success or FALSE otherwise.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
Bool
|
2010-07-27 13:02:24 -06:00
|
|
|
DisableDevice(DeviceIntPtr dev, BOOL sendevent)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr *prev, other;
|
|
|
|
BOOL enabled;
|
2010-07-27 13:02:24 -06:00
|
|
|
int flags[MAXDEVICES] = {0};
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (prev = &inputInfo.devices;
|
|
|
|
*prev && (*prev != dev);
|
|
|
|
prev = &(*prev)->next)
|
|
|
|
;
|
|
|
|
if (*prev != dev)
|
|
|
|
return FALSE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* float attached devices */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (IsMaster(dev))
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
for (other = inputInfo.devices; other; other = other->next)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!IsMaster(other) && GetMaster(other, MASTER_ATTACHED) == dev)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
AttachDevice(NULL, other, NULL);
|
2010-07-27 13:02:24 -06:00
|
|
|
flags[other->id] |= XISlaveDetached;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (other = inputInfo.devices; other; other = other->next)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
if (IsMaster(other) && other->lastSlave == dev)
|
|
|
|
other->lastSlave = NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (IsMaster(dev) && dev->spriteInfo->sprite)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
for (other = inputInfo.devices; other; other = other->next)
|
|
|
|
{
|
|
|
|
if (other->spriteInfo->paired == dev)
|
|
|
|
{
|
|
|
|
ErrorF("[dix] cannot disable device, still paired. "
|
|
|
|
"This is a bug. \n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
(void)(*dev->deviceProc)(dev, DEVICE_OFF);
|
2007-11-24 12:04:00 -07:00
|
|
|
dev->enabled = FALSE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/* now that the device is disabled, we can reset the signal handler's
|
|
|
|
* last.slave */
|
|
|
|
OsBlockSignals();
|
|
|
|
for (other = inputInfo.devices; other; other = other->next)
|
|
|
|
{
|
|
|
|
if (other->last.slave == dev)
|
|
|
|
other->last.slave = NULL;
|
|
|
|
}
|
|
|
|
OsReleaseSignals();
|
|
|
|
|
|
|
|
LeaveWindow(dev);
|
|
|
|
SetFocusOut(dev);
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
*prev = dev->next;
|
|
|
|
dev->next = inputInfo.off_devices;
|
|
|
|
inputInfo.off_devices = dev;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
enabled = FALSE;
|
|
|
|
XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_ENABLED),
|
|
|
|
XA_INTEGER, 8, PropModeReplace, 1, &enabled,
|
|
|
|
TRUE);
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
SendDevicePresenceEvent(dev->id, DeviceDisabled);
|
|
|
|
if (sendevent)
|
|
|
|
{
|
|
|
|
flags[dev->id] = XIDeviceDisabled;
|
|
|
|
XISendDeviceHierarchyEvent(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
RecalculateMasterButtons(dev);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
/**
|
|
|
|
* Initialise a new device through the driver and tell all clients about the
|
|
|
|
* new device.
|
2009-09-06 13:44:18 -06:00
|
|
|
*
|
|
|
|
* Must be called before EnableDevice.
|
2007-11-24 12:04:00 -07:00
|
|
|
* The device will NOT send events until it is enabled!
|
|
|
|
*
|
2010-07-27 13:02:24 -06:00
|
|
|
* @param sendevent True if an XI2 event should be sent.
|
2007-11-24 12:04:00 -07:00
|
|
|
* @return Success or an error code on failure.
|
|
|
|
*/
|
|
|
|
int
|
2010-07-27 13:02:24 -06:00
|
|
|
ActivateDevice(DeviceIntPtr dev, BOOL sendevent)
|
2007-11-24 12:04:00 -07:00
|
|
|
{
|
|
|
|
int ret = Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
ScreenPtr pScreen = screenInfo.screens[0];
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
if (!dev || !dev->deviceProc)
|
|
|
|
return BadImplementation;
|
|
|
|
|
|
|
|
ret = (*dev->deviceProc) (dev, DEVICE_INIT);
|
|
|
|
dev->inited = (ret == Success);
|
2009-09-06 13:44:18 -06:00
|
|
|
if (!dev->inited)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Initialize memory for sprites. */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (IsMaster(dev) && dev->spriteInfo->spriteOwner)
|
|
|
|
if (!pScreen->DeviceCursorInitialize(dev, pScreen))
|
|
|
|
ret = BadAlloc;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
SendDevicePresenceEvent(dev->id, DeviceAdded);
|
|
|
|
if (sendevent)
|
|
|
|
{
|
|
|
|
int flags[MAXDEVICES] = {0};
|
|
|
|
flags[dev->id] = XISlaveAdded;
|
|
|
|
XISendDeviceHierarchyEvent(flags);
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ring the bell.
|
|
|
|
* The actual task of ringing the bell is the job of the DDX.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
CoreKeyboardBell(int volume, DeviceIntPtr pDev, pointer arg, int something)
|
|
|
|
{
|
|
|
|
KeybdCtrl *ctrl = arg;
|
|
|
|
|
|
|
|
DDXRingBell(volume, ctrl->bell_pitch, ctrl->bell_duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CoreKeyboardCtl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-09-06 13:44:18 -06:00
|
|
|
* Device control function for the Virtual Core Keyboard.
|
2007-11-24 12:04:00 -07:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2007-11-24 12:04:00 -07:00
|
|
|
CoreKeyboardProc(DeviceIntPtr pDev, int what)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (what) {
|
|
|
|
case DEVICE_INIT:
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!InitKeyboardDeviceStruct(pDev, NULL, CoreKeyboardBell,
|
|
|
|
CoreKeyboardCtl))
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
ErrorF("Keyboard initialization failed. This could be a missing "
|
|
|
|
"or incorrect setup of xkeyboard-config.\n");
|
|
|
|
return BadValue;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
return Success;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
case DEVICE_ON:
|
|
|
|
case DEVICE_OFF:
|
|
|
|
return Success;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
case DEVICE_CLOSE:
|
2010-07-27 13:02:24 -06:00
|
|
|
return Success;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return BadMatch;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Device control function for the Virtual Core Pointer.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2007-11-24 12:04:00 -07:00
|
|
|
CorePointerProc(DeviceIntPtr pDev, int what)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
#define NBUTTONS 10
|
|
|
|
#define NAXES 2
|
|
|
|
BYTE map[NBUTTONS + 1];
|
2007-11-24 12:04:00 -07:00
|
|
|
int i = 0;
|
2010-07-27 13:02:24 -06:00
|
|
|
Atom btn_labels[NBUTTONS] = {0};
|
|
|
|
Atom axes_labels[NAXES] = {0};
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
switch (what) {
|
|
|
|
case DEVICE_INIT:
|
2010-07-27 13:02:24 -06:00
|
|
|
for (i = 1; i <= NBUTTONS; i++)
|
2007-11-24 12:04:00 -07:00
|
|
|
map[i] = i;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
|
|
|
|
btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
|
|
|
|
btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
|
|
|
|
btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
|
|
|
|
btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
|
|
|
|
btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
|
|
|
|
btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
|
|
|
|
/* don't know about the rest */
|
|
|
|
|
|
|
|
axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
|
|
|
|
axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
|
|
|
|
|
|
|
|
if (!InitPointerDeviceStruct((DevicePtr)pDev, map, NBUTTONS, btn_labels,
|
2009-09-06 13:44:18 -06:00
|
|
|
(PtrCtrlProcPtr)NoopDDA,
|
2010-07-27 13:02:24 -06:00
|
|
|
GetMotionHistorySize(), NAXES, axes_labels))
|
|
|
|
{
|
|
|
|
ErrorF("Could not initialize device '%s'. Out of memory.\n",
|
|
|
|
pDev->name);
|
|
|
|
return BadAlloc; /* IPDS only fails on allocs */
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
pDev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2;
|
2009-09-06 13:44:18 -06:00
|
|
|
pDev->last.valuators[0] = pDev->valuator->axisVal[0];
|
2007-11-24 12:04:00 -07:00
|
|
|
pDev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2;
|
2009-09-06 13:44:18 -06:00
|
|
|
pDev->last.valuators[1] = pDev->valuator->axisVal[1];
|
2007-11-24 12:04:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_CLOSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
#undef NBUTTONS
|
|
|
|
#undef NAXES
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the two core devices, VCP and VCK (see events.c).
|
2009-09-06 13:44:18 -06:00
|
|
|
* Both devices are not tied to physical devices, but guarantee that there is
|
|
|
|
* always a keyboard and a pointer present and keep the protocol semantics.
|
|
|
|
*
|
2007-11-24 12:04:00 -07:00
|
|
|
* Note that the server MUST have two core devices at all times, even if there
|
|
|
|
* is no physical device connected.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
InitCoreDevices(void)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
if (AllocDevicePair(serverClient, "Virtual core",
|
|
|
|
&inputInfo.pointer, &inputInfo.keyboard,
|
|
|
|
CorePointerProc, CoreKeyboardProc,
|
|
|
|
TRUE) != Success)
|
2009-09-06 13:44:18 -06:00
|
|
|
FatalError("Failed to allocate core devices");
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (ActivateDevice(inputInfo.pointer, TRUE) != Success ||
|
|
|
|
ActivateDevice(inputInfo.keyboard, TRUE) != Success)
|
|
|
|
FatalError("Failed to activate core devices.");
|
|
|
|
if (!EnableDevice(inputInfo.pointer, TRUE) ||
|
|
|
|
!EnableDevice(inputInfo.keyboard, TRUE))
|
|
|
|
FatalError("Failed to enable core devices.");
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
InitXTestDevices();
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activate all switched-off devices and then enable all those devices.
|
2009-09-06 13:44:18 -06:00
|
|
|
*
|
2007-11-24 12:04:00 -07:00
|
|
|
* Will return an error if no core keyboard or core pointer is present.
|
|
|
|
* In theory this should never happen if you call InitCoreDevices() first.
|
2009-09-06 13:44:18 -06:00
|
|
|
*
|
|
|
|
* InitAndStartDevices needs to be called AFTER the windows are initialized.
|
|
|
|
* Devices will start sending events after InitAndStartDevices() has
|
|
|
|
* completed.
|
|
|
|
*
|
2007-11-24 12:04:00 -07:00
|
|
|
* @return Success or error code on failure.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
int
|
2010-07-27 13:02:24 -06:00
|
|
|
InitAndStartDevices(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
DeviceIntPtr dev, next;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
for (dev = inputInfo.off_devices; dev; dev = dev->next) {
|
|
|
|
DebugF("(dix) initialising device %d\n", dev->id);
|
2008-06-14 18:17:32 -06:00
|
|
|
if (!dev->inited)
|
2010-07-27 13:02:24 -06:00
|
|
|
ActivateDevice(dev, TRUE);
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* enable real devices */
|
2006-11-26 11:13:41 -07:00
|
|
|
for (dev = inputInfo.off_devices; dev; dev = next)
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
DebugF("(dix) enabling device %d\n", dev->id);
|
2006-11-26 11:13:41 -07:00
|
|
|
next = dev->next;
|
|
|
|
if (dev->inited && dev->startup)
|
2010-07-27 13:02:24 -06:00
|
|
|
EnableDevice(dev, TRUE);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the given device class and reset the pointer to NULL.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
FreeDeviceClass(int type, pointer *class)
|
|
|
|
{
|
|
|
|
if (!(*class))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case KeyClass:
|
|
|
|
{
|
|
|
|
KeyClassPtr* k = (KeyClassPtr*)class;
|
|
|
|
if ((*k)->xkbInfo)
|
|
|
|
{
|
|
|
|
XkbFreeInfo((*k)->xkbInfo);
|
|
|
|
(*k)->xkbInfo = NULL;
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free((*k));
|
2009-09-06 13:44:18 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ButtonClass:
|
|
|
|
{
|
|
|
|
ButtonClassPtr *b = (ButtonClassPtr*)class;
|
2010-12-05 08:36:02 -07:00
|
|
|
free((*b)->xkb_acts);
|
|
|
|
free((*b));
|
2009-09-06 13:44:18 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ValuatorClass:
|
|
|
|
{
|
|
|
|
ValuatorClassPtr *v = (ValuatorClassPtr*)class;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free((*v)->motion);
|
|
|
|
free((*v));
|
2009-09-06 13:44:18 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FocusClass:
|
|
|
|
{
|
|
|
|
FocusClassPtr *f = (FocusClassPtr*)class;
|
2010-12-05 08:36:02 -07:00
|
|
|
free((*f)->trace);
|
|
|
|
free((*f));
|
2009-09-06 13:44:18 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ProximityClass:
|
|
|
|
{
|
|
|
|
ProximityClassPtr *p = (ProximityClassPtr*)class;
|
2010-12-05 08:36:02 -07:00
|
|
|
free((*p));
|
2009-09-06 13:44:18 -06:00
|
|
|
break;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
*class = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FreeFeedbackClass(int type, pointer *class)
|
|
|
|
{
|
|
|
|
if (!(*class))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case KbdFeedbackClass:
|
|
|
|
{
|
|
|
|
KbdFeedbackPtr *kbdfeed = (KbdFeedbackPtr*)class;
|
|
|
|
KbdFeedbackPtr k, knext;
|
|
|
|
for (k = (*kbdfeed); k; k = knext) {
|
|
|
|
knext = k->next;
|
|
|
|
if (k->xkb_sli)
|
|
|
|
XkbFreeSrvLedInfo(k->xkb_sli);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(k);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PtrFeedbackClass:
|
|
|
|
{
|
|
|
|
PtrFeedbackPtr *ptrfeed = (PtrFeedbackPtr*)class;
|
|
|
|
PtrFeedbackPtr p, pnext;
|
|
|
|
|
|
|
|
for (p = (*ptrfeed); p; p = pnext) {
|
|
|
|
pnext = p->next;
|
2010-12-05 08:36:02 -07:00
|
|
|
free(p);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IntegerFeedbackClass:
|
|
|
|
{
|
|
|
|
IntegerFeedbackPtr *intfeed = (IntegerFeedbackPtr*)class;
|
|
|
|
IntegerFeedbackPtr i, inext;
|
|
|
|
|
|
|
|
for (i = (*intfeed); i; i = inext) {
|
|
|
|
inext = i->next;
|
2010-12-05 08:36:02 -07:00
|
|
|
free(i);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case StringFeedbackClass:
|
|
|
|
{
|
|
|
|
StringFeedbackPtr *stringfeed = (StringFeedbackPtr*)class;
|
|
|
|
StringFeedbackPtr s, snext;
|
|
|
|
|
|
|
|
for (s = (*stringfeed); s; s = snext) {
|
|
|
|
snext = s->next;
|
2010-12-05 08:36:02 -07:00
|
|
|
free(s->ctrl.symbols_supported);
|
|
|
|
free(s->ctrl.symbols_displayed);
|
|
|
|
free(s);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BellFeedbackClass:
|
|
|
|
{
|
|
|
|
BellFeedbackPtr *bell = (BellFeedbackPtr*)class;
|
|
|
|
BellFeedbackPtr b, bnext;
|
|
|
|
|
|
|
|
for (b = (*bell); b; b = bnext) {
|
|
|
|
bnext = b->next;
|
2010-12-05 08:36:02 -07:00
|
|
|
free(b);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LedFeedbackClass:
|
|
|
|
{
|
|
|
|
LedFeedbackPtr *leds = (LedFeedbackPtr*)class;
|
|
|
|
LedFeedbackPtr l, lnext;
|
|
|
|
|
|
|
|
for (l = (*leds); l; l = lnext) {
|
|
|
|
lnext = l->next;
|
|
|
|
if (l->xkb_sli)
|
|
|
|
XkbFreeSrvLedInfo(l->xkb_sli);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(l);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
*class = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FreeAllDeviceClasses(ClassesPtr classes)
|
|
|
|
{
|
|
|
|
if (!classes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FreeDeviceClass(KeyClass, (pointer)&classes->key);
|
|
|
|
FreeDeviceClass(ValuatorClass, (pointer)&classes->valuator);
|
|
|
|
FreeDeviceClass(ButtonClass, (pointer)&classes->button);
|
|
|
|
FreeDeviceClass(FocusClass, (pointer)&classes->focus);
|
|
|
|
FreeDeviceClass(ProximityClass, (pointer)&classes->proximity);
|
|
|
|
|
|
|
|
FreeFeedbackClass(KbdFeedbackClass, (pointer)&classes->kbdfeed);
|
|
|
|
FreeFeedbackClass(PtrFeedbackClass, (pointer)&classes->ptrfeed);
|
|
|
|
FreeFeedbackClass(IntegerFeedbackClass, (pointer)&classes->intfeed);
|
|
|
|
FreeFeedbackClass(StringFeedbackClass, (pointer)&classes->stringfeed);
|
|
|
|
FreeFeedbackClass(BellFeedbackClass, (pointer)&classes->bell);
|
|
|
|
FreeFeedbackClass(LedFeedbackClass, (pointer)&classes->leds);
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
/**
|
2009-09-06 13:44:18 -06:00
|
|
|
* Close down a device and free all resources.
|
2007-11-24 12:04:00 -07:00
|
|
|
* Once closed down, the driver will probably not expect you that you'll ever
|
|
|
|
* enable it again and free associated structs. If you want the device to just
|
|
|
|
* be disabled, DisableDevice().
|
|
|
|
* Don't call this function directly, use RemoveDevice() instead.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
static void
|
2007-11-24 12:04:00 -07:00
|
|
|
CloseDevice(DeviceIntPtr dev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
ScreenPtr screen = screenInfo.screens[0];
|
|
|
|
ClassesPtr classes;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
XIDeleteAllDeviceProperties(dev);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (dev->inited)
|
|
|
|
(void)(*dev->deviceProc)(dev, DEVICE_CLOSE);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* free sprite memory */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (IsMaster(dev) && dev->spriteInfo->sprite)
|
2009-09-06 13:44:18 -06:00
|
|
|
screen->DeviceCursorCleanup(dev, screen);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* free acceleration info */
|
|
|
|
if(dev->valuator && dev->valuator->accelScheme.AccelCleanupProc)
|
|
|
|
dev->valuator->accelScheme.AccelCleanupProc(dev);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
while (dev->xkb_interest)
|
|
|
|
XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(dev->name);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
classes = (ClassesPtr)&dev->key;
|
|
|
|
FreeAllDeviceClasses(classes);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (IsMaster(dev))
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
classes = dev->unused_classes;
|
2009-09-06 13:44:18 -06:00
|
|
|
FreeAllDeviceClasses(classes);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(classes);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (DevHasCursor(dev) && dev->spriteInfo->sprite) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (dev->spriteInfo->sprite->current)
|
|
|
|
FreeCursor(dev->spriteInfo->sprite->current, None);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(dev->spriteInfo->sprite->spriteTrace);
|
|
|
|
free(dev->spriteInfo->sprite);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* a client may have the device set as client pointer */
|
|
|
|
for (j = 0; j < currentMaxClients; j++)
|
|
|
|
{
|
|
|
|
if (clients[j] && clients[j]->clientPtr == dev)
|
|
|
|
{
|
|
|
|
clients[j]->clientPtr = NULL;
|
|
|
|
clients[j]->clientPtr = PickPointer(clients[j]);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(dev->deviceGrab.sync.event);
|
2011-11-05 07:32:40 -06:00
|
|
|
free(dev->config_info); /* Allocated in xf86ActivateDevice. */
|
|
|
|
dev->config_info = NULL;
|
2010-12-05 08:36:02 -07:00
|
|
|
dixFreeObjectWithPrivates(dev, PRIVATE_DEVICE);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* Shut down all devices of one list and free all resources.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
void
|
|
|
|
CloseDeviceList(DeviceIntPtr *listHead)
|
|
|
|
{
|
|
|
|
/* Used to mark devices that we tried to free */
|
|
|
|
Bool freedIds[MAXDEVICES];
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (listHead == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXDEVICES; i++)
|
|
|
|
freedIds[i] = FALSE;
|
|
|
|
|
|
|
|
dev = *listHead;
|
|
|
|
while (dev != NULL)
|
|
|
|
{
|
|
|
|
freedIds[dev->id] = TRUE;
|
|
|
|
DeleteInputDeviceRequest(dev);
|
|
|
|
|
|
|
|
dev = *listHead;
|
|
|
|
while (dev != NULL && freedIds[dev->id])
|
|
|
|
dev = dev->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
/**
|
2009-09-06 13:44:18 -06:00
|
|
|
* Shut down all devices, free all resources, etc.
|
2007-11-24 12:04:00 -07:00
|
|
|
* Only useful if you're shutting down the server!
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
void
|
2007-11-24 12:04:00 -07:00
|
|
|
CloseDownDevices(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr dev;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2011-12-18 09:08:59 -07:00
|
|
|
OsBlockSignals();
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Float all SDs before closing them. Note that at this point resources
|
|
|
|
* (e.g. cursors) have been freed already, so we can't just call
|
|
|
|
* AttachDevice(NULL, dev, NULL). Instead, we have to forcibly set master
|
|
|
|
* to NULL and pretend nothing happened.
|
|
|
|
*/
|
|
|
|
for (dev = inputInfo.devices; dev; dev = dev->next)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!IsMaster(dev) && !IsFloating(dev))
|
|
|
|
dev->master = NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
CloseDeviceList(&inputInfo.devices);
|
|
|
|
CloseDeviceList(&inputInfo.off_devices);
|
|
|
|
|
|
|
|
CloseDevice(inputInfo.pointer);
|
|
|
|
CloseDevice(inputInfo.keyboard);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
inputInfo.devices = NULL;
|
|
|
|
inputInfo.off_devices = NULL;
|
|
|
|
inputInfo.keyboard = NULL;
|
|
|
|
inputInfo.pointer = NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
XkbDeleteRulesDflts();
|
2011-12-18 09:08:59 -07:00
|
|
|
|
|
|
|
OsReleaseSignals();
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the cursor sprite for all devices. This needs to be done before any
|
|
|
|
* resources are freed or any device is deleted.
|
|
|
|
*/
|
|
|
|
void
|
2010-07-27 13:02:24 -06:00
|
|
|
UndisplayDevices(void)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
ScreenPtr screen = screenInfo.screens[0];
|
|
|
|
|
|
|
|
for (dev = inputInfo.devices; dev; dev = dev->next)
|
|
|
|
screen->DisplayCursor(dev, screen, NullCursor);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
/**
|
|
|
|
* Remove a device from the device list, closes it and thus frees all
|
2009-09-06 13:44:18 -06:00
|
|
|
* resources.
|
2007-11-24 12:04:00 -07:00
|
|
|
* Removes both enabled and disabled devices and notifies all devices about
|
|
|
|
* the removal of the device.
|
2009-09-06 13:44:18 -06:00
|
|
|
*
|
|
|
|
* No PresenceNotify is sent for device that the client never saw. This can
|
|
|
|
* happen if a malloc fails during the addition of master devices. If
|
|
|
|
* dev->init is FALSE it means the client never received a DeviceAdded event,
|
|
|
|
* so let's not send a DeviceRemoved event either.
|
2010-07-27 13:02:24 -06:00
|
|
|
*
|
|
|
|
* @param sendevent True if an XI2 event should be sent.
|
2007-11-24 12:04:00 -07:00
|
|
|
*/
|
|
|
|
int
|
2010-07-27 13:02:24 -06:00
|
|
|
RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
DeviceIntPtr prev,tmp,next;
|
|
|
|
int ret = BadMatch;
|
2009-09-06 13:44:18 -06:00
|
|
|
ScreenPtr screen = screenInfo.screens[0];
|
2007-11-24 12:04:00 -07:00
|
|
|
int deviceid;
|
2009-09-06 13:44:18 -06:00
|
|
|
int initialized;
|
2010-07-27 13:02:24 -06:00
|
|
|
int flags[MAXDEVICES] = {0};
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
DebugF("(dix) removing device %d\n", dev->id);
|
|
|
|
|
|
|
|
if (!dev || dev == inputInfo.keyboard || dev == inputInfo.pointer)
|
|
|
|
return BadImplementation;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
initialized = dev->inited;
|
2007-11-24 12:04:00 -07:00
|
|
|
deviceid = dev->id;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (initialized)
|
|
|
|
{
|
|
|
|
if (DevHasCursor(dev))
|
|
|
|
screen->DisplayCursor(dev, screen, NullCursor);
|
|
|
|
|
|
|
|
DisableDevice(dev, sendevent);
|
|
|
|
flags[dev->id] = XIDeviceDisabled;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
for (tmp = inputInfo.devices; tmp; (prev = tmp), (tmp = next)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
next = tmp->next;
|
2007-11-24 12:04:00 -07:00
|
|
|
if (tmp == dev) {
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (prev==NULL)
|
|
|
|
inputInfo.devices = next;
|
|
|
|
else
|
|
|
|
prev->next = next;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved;
|
2009-09-06 13:44:18 -06:00
|
|
|
CloseDevice(tmp);
|
2007-11-24 12:04:00 -07:00
|
|
|
ret = Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
prev = NULL;
|
|
|
|
for (tmp = inputInfo.off_devices; tmp; (prev = tmp), (tmp = next)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
next = tmp->next;
|
2007-11-24 12:04:00 -07:00
|
|
|
if (tmp == dev) {
|
2010-07-27 13:02:24 -06:00
|
|
|
flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved;
|
2006-11-26 11:13:41 -07:00
|
|
|
CloseDevice(tmp);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
if (prev == NULL)
|
2006-11-26 11:13:41 -07:00
|
|
|
inputInfo.off_devices = next;
|
|
|
|
else
|
|
|
|
prev->next = next;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
ret = Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
if (ret == Success && initialized) {
|
2007-11-24 12:04:00 -07:00
|
|
|
inputInfo.numDevices--;
|
2010-07-27 13:02:24 -06:00
|
|
|
SendDevicePresenceEvent(deviceid, DeviceRemoved);
|
|
|
|
if (sendevent)
|
|
|
|
XISendDeviceHierarchyEvent(flags);
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-11-24 12:04:00 -07:00
|
|
|
NumMotionEvents(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
/* only called to fill data in initial connection reply.
|
|
|
|
* VCP is ok here, it is the only fixed device we have. */
|
2006-11-26 11:13:41 -07:00
|
|
|
return inputInfo.pointer->valuator->numMotionEvents;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
int
|
|
|
|
dixLookupDevice(DeviceIntPtr *pDev, int id, ClientPtr client, Mask access_mode)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
DeviceIntPtr dev;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
|
|
|
*pDev = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (dev=inputInfo.devices; dev; dev=dev->next) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (dev->id == id)
|
2008-11-02 08:26:08 -07:00
|
|
|
goto found;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
for (dev=inputInfo.off_devices; dev; dev=dev->next) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (dev->id == id)
|
2008-11-02 08:26:08 -07:00
|
|
|
goto found;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
return BadDevice;
|
|
|
|
|
|
|
|
found:
|
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
|
|
|
|
if (rc == Success)
|
|
|
|
*pDev = dev;
|
|
|
|
return rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QueryMinMaxKeyCodes(KeyCode *minCode, KeyCode *maxCode)
|
|
|
|
{
|
|
|
|
if (inputInfo.keyboard) {
|
2010-07-27 13:02:24 -06:00
|
|
|
*minCode = inputInfo.keyboard->key->xkbInfo->desc->min_key_code;
|
|
|
|
*maxCode = inputInfo.keyboard->key->xkbInfo->desc->max_key_code;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* Notably, this function does not expand the destination's keycode range, or
|
|
|
|
* notify clients. */
|
2006-11-26 11:13:41 -07:00
|
|
|
Bool
|
2007-11-24 12:04:00 -07:00
|
|
|
SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
int i, j;
|
2010-07-27 13:02:24 -06:00
|
|
|
KeySym *tmp;
|
2006-11-26 11:13:41 -07:00
|
|
|
int rowDif = src->minKeyCode - dst->minKeyCode;
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
/* if keysym map size changes, grow map first */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (src->mapWidth < dst->mapWidth) {
|
|
|
|
for (i = src->minKeyCode; i <= src->maxKeyCode; i++) {
|
|
|
|
#define SI(r, c) (((r - src->minKeyCode) * src->mapWidth) + (c))
|
|
|
|
#define DI(r, c) (((r - dst->minKeyCode) * dst->mapWidth) + (c))
|
2006-11-26 11:13:41 -07:00
|
|
|
for (j = 0; j < src->mapWidth; j++)
|
|
|
|
dst->map[DI(i, j)] = src->map[SI(i, j)];
|
|
|
|
for (j = src->mapWidth; j < dst->mapWidth; j++)
|
|
|
|
dst->map[DI(i, j)] = NoSymbol;
|
|
|
|
#undef SI
|
|
|
|
#undef DI
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
else if (src->mapWidth > dst->mapWidth) {
|
|
|
|
i = sizeof(KeySym) * src->mapWidth *
|
|
|
|
(dst->maxKeyCode - dst->minKeyCode + 1);
|
2010-12-05 08:36:02 -07:00
|
|
|
tmp = calloc(sizeof(KeySym), i);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!tmp)
|
2009-09-06 13:44:18 -06:00
|
|
|
return FALSE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (dst->map) {
|
|
|
|
for (i = 0; i <= dst->maxKeyCode-dst->minKeyCode; i++)
|
|
|
|
memmove(&tmp[i * src->mapWidth], &dst->map[i * dst->mapWidth],
|
|
|
|
dst->mapWidth * sizeof(KeySym));
|
2010-12-05 08:36:02 -07:00
|
|
|
free(dst->map);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
dst->mapWidth = src->mapWidth;
|
2010-07-27 13:02:24 -06:00
|
|
|
dst->map = tmp;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
else if (!dst->map) {
|
|
|
|
i = sizeof(KeySym) * src->mapWidth *
|
|
|
|
(dst->maxKeyCode - dst->minKeyCode + 1);
|
2010-12-05 08:36:02 -07:00
|
|
|
tmp = calloc(sizeof(KeySym), i);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
dst->map = tmp;
|
|
|
|
dst->mapWidth = src->mapWidth;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
memmove(&dst->map[rowDif * dst->mapWidth], src->map,
|
|
|
|
(src->maxKeyCode - src->minKeyCode + 1) *
|
|
|
|
dst->mapWidth * sizeof(KeySym));
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
|
|
|
InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels,
|
2006-11-26 11:13:41 -07:00
|
|
|
CARD8 *map)
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
ButtonClassPtr butc;
|
2006-11-26 11:13:41 -07:00
|
|
|
int i;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
butc = calloc(1, sizeof(ButtonClassRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!butc)
|
|
|
|
return FALSE;
|
|
|
|
butc->numButtons = numButtons;
|
2010-07-27 13:02:24 -06:00
|
|
|
butc->sourceid = dev->id;
|
2006-11-26 11:13:41 -07:00
|
|
|
for (i = 1; i <= numButtons; i++)
|
|
|
|
butc->map[i] = map[i];
|
2010-07-27 13:02:24 -06:00
|
|
|
for (i = numButtons + 1; i < MAP_LENGTH; i++)
|
|
|
|
butc->map[i] = i;
|
|
|
|
memcpy(butc->labels, labels, numButtons * sizeof(Atom));
|
2006-11-26 11:13:41 -07:00
|
|
|
dev->button = butc;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/**
|
|
|
|
* Allocate a valuator class and set up the pointers for the axis values
|
|
|
|
* appropriately.
|
|
|
|
*
|
|
|
|
* @param src If non-NULL, the memory is reallocated from src. If NULL, the
|
|
|
|
* memory is calloc'd.
|
|
|
|
* @parma numAxes Number of axes to allocate.
|
|
|
|
* @return The allocated valuator struct.
|
|
|
|
*/
|
|
|
|
ValuatorClassPtr
|
|
|
|
AllocValuatorClass(ValuatorClassPtr src, int numAxes)
|
|
|
|
{
|
|
|
|
ValuatorClassPtr v;
|
|
|
|
/* force alignment with double */
|
|
|
|
union align_u { ValuatorClassRec valc; double d; } *align;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
size = sizeof(union align_u) + numAxes * (sizeof(double) + sizeof(AxisInfo));
|
|
|
|
align = (union align_u *) realloc(src, size);
|
|
|
|
|
|
|
|
if (!align)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!src)
|
|
|
|
memset(align, 0, size);
|
|
|
|
|
|
|
|
v = &align->valc;
|
|
|
|
v->numAxes = numAxes;
|
|
|
|
v->axisVal = (double*)(align + 1);
|
|
|
|
v->axes = (AxisInfoPtr)(v->axisVal + numAxes);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
|
|
|
InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
|
2006-11-26 11:13:41 -07:00
|
|
|
int numMotionEvents, int mode)
|
|
|
|
{
|
|
|
|
int i;
|
2007-11-24 12:04:00 -07:00
|
|
|
ValuatorClassPtr valc;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
if (numAxes > MAX_VALUATORS)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"Device '%s' has %d axes, only using first %d.\n",
|
|
|
|
dev->name, numAxes, MAX_VALUATORS);
|
|
|
|
numAxes = MAX_VALUATORS;
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
valc = AllocValuatorClass(NULL, numAxes);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!valc)
|
2011-11-05 07:32:40 -06:00
|
|
|
return FALSE;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
valc->sourceid = dev->id;
|
2007-11-24 12:04:00 -07:00
|
|
|
valc->motion = NULL;
|
|
|
|
valc->first_motion = 0;
|
|
|
|
valc->last_motion = 0;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
valc->numMotionEvents = numMotionEvents;
|
|
|
|
valc->motionHintWindow = NullWindow;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
if (mode & OutOfProximity)
|
|
|
|
InitProximityClassDeviceStruct(dev);
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
dev->valuator = valc;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
AllocateMotionHistory(dev);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
for (i=0; i<numAxes; i++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
InitValuatorAxisStruct(dev, i, labels[i], NO_AXIS_LIMITS, NO_AXIS_LIMITS,
|
2011-11-05 07:32:40 -06:00
|
|
|
0, 0, 0, mode);
|
2007-11-24 12:04:00 -07:00
|
|
|
valc->axisVal[i]=0;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
dev->last.numValuators = numAxes;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (IsMaster(dev) || /* do not accelerate master or xtest devices */
|
|
|
|
IsXTestDevice(dev, NULL))
|
2009-09-06 13:44:18 -06:00
|
|
|
InitPointerAccelerationScheme(dev, PtrAccelNoOp);
|
|
|
|
else
|
|
|
|
InitPointerAccelerationScheme(dev, PtrAccelDefault);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* global list of acceleration schemes */
|
|
|
|
ValuatorAccelerationRec pointerAccelerationScheme[] = {
|
2011-11-05 07:32:40 -06:00
|
|
|
{PtrAccelNoOp, NULL, NULL, NULL, NULL},
|
|
|
|
{PtrAccelPredictable, acceleratePointerPredictable, NULL,
|
|
|
|
InitPredictableAccelerationScheme, AccelerationDefaultCleanup},
|
|
|
|
{PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL, NULL},
|
|
|
|
{-1, NULL, NULL, NULL, NULL} /* terminator */
|
2009-09-06 13:44:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* install an acceleration scheme. returns TRUE on success, and should not
|
|
|
|
* change anything if unsuccessful.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2009-09-06 13:44:18 -06:00
|
|
|
InitPointerAccelerationScheme(DeviceIntPtr dev,
|
|
|
|
int scheme)
|
|
|
|
{
|
|
|
|
int x, i = -1;
|
|
|
|
ValuatorClassPtr val;
|
|
|
|
|
|
|
|
val = dev->valuator;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!val)
|
|
|
|
return FALSE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (IsMaster(dev) && scheme != PtrAccelNoOp)
|
2010-07-27 13:02:24 -06:00
|
|
|
return FALSE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
for (x = 0; pointerAccelerationScheme[x].number >= 0; x++) {
|
2009-09-06 13:44:18 -06:00
|
|
|
if(pointerAccelerationScheme[x].number == scheme){
|
|
|
|
i = x;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (-1 == i)
|
2009-09-06 13:44:18 -06:00
|
|
|
return FALSE;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (val->accelScheme.AccelCleanupProc)
|
|
|
|
val->accelScheme.AccelCleanupProc(dev);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (pointerAccelerationScheme[i].AccelInitProc) {
|
|
|
|
if (!pointerAccelerationScheme[i].AccelInitProc(dev,
|
|
|
|
&pointerAccelerationScheme[i])) {
|
|
|
|
return FALSE;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
} else {
|
|
|
|
val->accelScheme = pointerAccelerationScheme[i];
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2006-11-26 11:13:41 -07:00
|
|
|
InitFocusClassDeviceStruct(DeviceIntPtr dev)
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
FocusClassPtr focc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
focc = malloc(sizeof(FocusClassRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!focc)
|
|
|
|
return FALSE;
|
|
|
|
focc->win = PointerRootWin;
|
|
|
|
focc->revert = None;
|
|
|
|
focc->time = currentTime;
|
|
|
|
focc->trace = (WindowPtr *)NULL;
|
|
|
|
focc->traceSize = 0;
|
|
|
|
focc->traceGood = 0;
|
2010-07-27 13:02:24 -06:00
|
|
|
focc->sourceid = dev->id;
|
2006-11-26 11:13:41 -07:00
|
|
|
dev->focus = focc;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2006-11-26 11:13:41 -07:00
|
|
|
InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc)
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
PtrFeedbackPtr feedc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
feedc = malloc(sizeof(PtrFeedbackClassRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!feedc)
|
|
|
|
return FALSE;
|
|
|
|
feedc->CtrlProc = controlProc;
|
|
|
|
feedc->ctrl = defaultPointerControl;
|
|
|
|
feedc->ctrl.id = 0;
|
|
|
|
if ( (feedc->next = dev->ptrfeed) )
|
|
|
|
feedc->ctrl.id = dev->ptrfeed->ctrl.id + 1;
|
|
|
|
dev->ptrfeed = feedc;
|
|
|
|
(*controlProc)(dev, &feedc->ctrl);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
static LedCtrl defaultLedControl = {
|
2006-11-26 11:13:41 -07:00
|
|
|
DEFAULT_LEDS, DEFAULT_LEDS_MASK, 0};
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
static BellCtrl defaultBellControl = {
|
2006-11-26 11:13:41 -07:00
|
|
|
DEFAULT_BELL,
|
|
|
|
DEFAULT_BELL_PITCH,
|
|
|
|
DEFAULT_BELL_DURATION,
|
|
|
|
0};
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
static IntegerCtrl defaultIntegerControl = {
|
2006-11-26 11:13:41 -07:00
|
|
|
DEFAULT_INT_RESOLUTION,
|
|
|
|
DEFAULT_INT_MIN_VALUE,
|
|
|
|
DEFAULT_INT_MAX_VALUE,
|
|
|
|
DEFAULT_INT_DISPLAYED,
|
|
|
|
0};
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2006-11-26 11:13:41 -07:00
|
|
|
InitStringFeedbackClassDeviceStruct (
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr dev, StringCtrlProcPtr controlProc,
|
2006-11-26 11:13:41 -07:00
|
|
|
int max_symbols, int num_symbols_supported, KeySym *symbols)
|
|
|
|
{
|
|
|
|
int i;
|
2007-11-24 12:04:00 -07:00
|
|
|
StringFeedbackPtr feedc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
feedc = malloc(sizeof(StringFeedbackClassRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!feedc)
|
|
|
|
return FALSE;
|
|
|
|
feedc->CtrlProc = controlProc;
|
|
|
|
feedc->ctrl.num_symbols_supported = num_symbols_supported;
|
|
|
|
feedc->ctrl.num_symbols_displayed = 0;
|
|
|
|
feedc->ctrl.max_symbols = max_symbols;
|
2010-12-05 08:36:02 -07:00
|
|
|
feedc->ctrl.symbols_supported = malloc(sizeof (KeySym) * num_symbols_supported);
|
|
|
|
feedc->ctrl.symbols_displayed = malloc(sizeof (KeySym) * max_symbols);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
free(feedc->ctrl.symbols_supported);
|
|
|
|
free(feedc->ctrl.symbols_displayed);
|
|
|
|
free(feedc);
|
2006-11-26 11:13:41 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
for (i=0; i<num_symbols_supported; i++)
|
|
|
|
*(feedc->ctrl.symbols_supported+i) = *symbols++;
|
|
|
|
for (i=0; i<max_symbols; i++)
|
2010-07-27 13:02:24 -06:00
|
|
|
*(feedc->ctrl.symbols_displayed+i) = (KeySym) 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
feedc->ctrl.id = 0;
|
|
|
|
if ( (feedc->next = dev->stringfeed) )
|
|
|
|
feedc->ctrl.id = dev->stringfeed->ctrl.id + 1;
|
|
|
|
dev->stringfeed = feedc;
|
|
|
|
(*controlProc)(dev, &feedc->ctrl);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2009-09-06 13:44:18 -06:00
|
|
|
InitBellFeedbackClassDeviceStruct (DeviceIntPtr dev, BellProcPtr bellProc,
|
2006-11-26 11:13:41 -07:00
|
|
|
BellCtrlProcPtr controlProc)
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
BellFeedbackPtr feedc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
feedc = malloc(sizeof(BellFeedbackClassRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!feedc)
|
|
|
|
return FALSE;
|
|
|
|
feedc->CtrlProc = controlProc;
|
|
|
|
feedc->BellProc = bellProc;
|
|
|
|
feedc->ctrl = defaultBellControl;
|
|
|
|
feedc->ctrl.id = 0;
|
|
|
|
if ( (feedc->next = dev->bell) )
|
|
|
|
feedc->ctrl.id = dev->bell->ctrl.id + 1;
|
|
|
|
dev->bell = feedc;
|
|
|
|
(*controlProc)(dev, &feedc->ctrl);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2006-11-26 11:13:41 -07:00
|
|
|
InitLedFeedbackClassDeviceStruct (DeviceIntPtr dev, LedCtrlProcPtr controlProc)
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
LedFeedbackPtr feedc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
feedc = malloc(sizeof(LedFeedbackClassRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!feedc)
|
|
|
|
return FALSE;
|
|
|
|
feedc->CtrlProc = controlProc;
|
|
|
|
feedc->ctrl = defaultLedControl;
|
|
|
|
feedc->ctrl.id = 0;
|
|
|
|
if ( (feedc->next = dev->leds) )
|
|
|
|
feedc->ctrl.id = dev->leds->ctrl.id + 1;
|
|
|
|
feedc->xkb_sli= NULL;
|
|
|
|
dev->leds = feedc;
|
|
|
|
(*controlProc)(dev, &feedc->ctrl);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2006-11-26 11:13:41 -07:00
|
|
|
InitIntegerFeedbackClassDeviceStruct (DeviceIntPtr dev, IntegerCtrlProcPtr controlProc)
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
IntegerFeedbackPtr feedc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
feedc = malloc(sizeof(IntegerFeedbackClassRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!feedc)
|
|
|
|
return FALSE;
|
|
|
|
feedc->CtrlProc = controlProc;
|
|
|
|
feedc->ctrl = defaultIntegerControl;
|
|
|
|
feedc->ctrl.id = 0;
|
|
|
|
if ( (feedc->next = dev->intfeed) )
|
|
|
|
feedc->ctrl.id = dev->intfeed->ctrl.id + 1;
|
|
|
|
dev->intfeed = feedc;
|
|
|
|
(*controlProc)(dev, &feedc->ctrl);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
|
|
|
InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons, Atom* btn_labels,
|
2007-11-24 12:04:00 -07:00
|
|
|
PtrCtrlProcPtr controlProc, int numMotionEvents,
|
2010-07-27 13:02:24 -06:00
|
|
|
int numAxes, Atom *axes_labels)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
DeviceIntPtr dev = (DeviceIntPtr)device;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
return(InitButtonClassDeviceStruct(dev, numButtons, btn_labels, map) &&
|
|
|
|
InitValuatorClassDeviceStruct(dev, numAxes, axes_labels,
|
|
|
|
numMotionEvents, Relative) &&
|
2006-11-26 11:13:41 -07:00
|
|
|
InitPtrFeedbackClassDeviceStruct(dev, controlProc));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-09-06 13:44:18 -06:00
|
|
|
* Check if the given buffer contains elements between low (inclusive) and
|
|
|
|
* high (inclusive) only.
|
|
|
|
*
|
|
|
|
* @return TRUE if the device map is invalid, FALSE otherwise.
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
|
|
|
Bool
|
2007-11-24 12:04:00 -07:00
|
|
|
BadDeviceMap(BYTE *buff, int length, unsigned low, unsigned high, XID *errval)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
int i;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
if (buff[i]) /* only check non-zero elements */
|
|
|
|
{
|
|
|
|
if ((low > buff[i]) || (high < buff[i]))
|
|
|
|
{
|
|
|
|
*errval = buff[i];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
int
|
2006-11-26 11:13:41 -07:00
|
|
|
ProcSetModifierMapping(ClientPtr client)
|
|
|
|
{
|
|
|
|
xSetModifierMappingReply rep;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST(xSetModifierMappingReq);
|
|
|
|
REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
if (client->req_len != ((stuff->numKeyPerModifier << 1) +
|
2010-07-27 13:02:24 -06:00
|
|
|
bytes_to_int32(sizeof(xSetModifierMappingReq))))
|
2006-11-26 11:13:41 -07:00
|
|
|
return BadLength;
|
|
|
|
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
rc = change_modmap(client, PickKeyboard(client), (KeyCode *)&stuff[1],
|
|
|
|
stuff->numKeyPerModifier);
|
|
|
|
if (rc == MappingFailed || rc == -1)
|
|
|
|
return BadValue;
|
|
|
|
if (rc != Success && rc != MappingSuccess && rc != MappingFailed &&
|
|
|
|
rc != MappingBusy)
|
2008-11-02 08:26:08 -07:00
|
|
|
return rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.success = rc;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcGetModifierMapping(ClientPtr client)
|
|
|
|
{
|
|
|
|
xGetModifierMappingReply rep;
|
2010-07-27 13:02:24 -06:00
|
|
|
int max_keys_per_mod = 0;
|
|
|
|
KeyCode *modkeymap = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xReq);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
generate_modkeymap(client, PickKeyboard(client), &modkeymap,
|
|
|
|
&max_keys_per_mod);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(&rep, 0, sizeof(xGetModifierMappingReply));
|
2006-11-26 11:13:41 -07:00
|
|
|
rep.type = X_Reply;
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.numKeyPerModifier = max_keys_per_mod;
|
2006-11-26 11:13:41 -07:00
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
/* length counts 4 byte quantities - there are 8 modifiers 1 byte big */
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.length = max_keys_per_mod << 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
WriteReplyToClient(client, sizeof(xGetModifierMappingReply), &rep);
|
2010-07-27 13:02:24 -06:00
|
|
|
(void)WriteToClient(client, max_keys_per_mod * 8, (char *) modkeymap);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(modkeymap);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcChangeKeyboardMapping(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xChangeKeyboardMappingReq);
|
|
|
|
unsigned len;
|
|
|
|
KeySymsRec keysyms;
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr pDev, tmp;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
len = client->req_len - bytes_to_int32(sizeof(xChangeKeyboardMappingReq));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (len != (stuff->keyCodes * stuff->keySymsPerKeyCode))
|
|
|
|
return BadLength;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
pDev = PickKeyboard(client);
|
|
|
|
|
|
|
|
if ((stuff->firstKeyCode < pDev->key->xkbInfo->desc->min_key_code) ||
|
|
|
|
(stuff->firstKeyCode > pDev->key->xkbInfo->desc->max_key_code)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->firstKeyCode;
|
|
|
|
return BadValue;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
if (((unsigned)(stuff->firstKeyCode + stuff->keyCodes - 1) >
|
2010-07-27 13:02:24 -06:00
|
|
|
pDev->key->xkbInfo->desc->max_key_code) ||
|
|
|
|
(stuff->keySymsPerKeyCode == 0)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->keySymsPerKeyCode;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
keysyms.minKeyCode = stuff->firstKeyCode;
|
|
|
|
keysyms.maxKeyCode = stuff->firstKeyCode + stuff->keyCodes - 1;
|
|
|
|
keysyms.mapWidth = stuff->keySymsPerKeyCode;
|
2010-07-27 13:02:24 -06:00
|
|
|
keysyms.map = (KeySym *) &stuff[1];
|
2007-12-13 14:47:48 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, pDev, DixManageAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbApplyMappingChange(pDev, &keysyms, stuff->firstKeyCode,
|
|
|
|
stuff->keyCodes, NULL, client);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
for (tmp = inputInfo.devices; tmp; tmp = tmp->next) {
|
2011-11-05 07:32:40 -06:00
|
|
|
if (IsMaster(tmp) || GetMaster(tmp, MASTER_KEYBOARD) != pDev)
|
2010-07-27 13:02:24 -06:00
|
|
|
continue;
|
|
|
|
if (!tmp->key)
|
|
|
|
continue;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, pDev, DixManageAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
continue;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbApplyMappingChange(tmp, &keysyms, stuff->firstKeyCode,
|
|
|
|
stuff->keyCodes, NULL, client);
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcSetPointerMapping(ClientPtr client)
|
|
|
|
{
|
|
|
|
BYTE *map;
|
2007-11-24 12:04:00 -07:00
|
|
|
int ret;
|
2009-09-06 13:44:18 -06:00
|
|
|
int i, j;
|
|
|
|
DeviceIntPtr ptr = PickPointer(client);
|
2006-11-26 11:13:41 -07:00
|
|
|
xSetPointerMappingReply rep;
|
2008-11-02 08:26:08 -07:00
|
|
|
REQUEST(xSetPointerMappingReq);
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (client->req_len !=
|
|
|
|
bytes_to_int32(sizeof(xSetPointerMappingReq) + stuff->nElts))
|
2006-11-26 11:13:41 -07:00
|
|
|
return BadLength;
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
rep.success = MappingSuccess;
|
|
|
|
map = (BYTE *)&stuff[1];
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
/* So we're bounded here by the number of core buttons. This check
|
|
|
|
* probably wants disabling through XFixes. */
|
2009-09-06 13:44:18 -06:00
|
|
|
/* MPX: With ClientPointer, we can return the right number of buttons.
|
|
|
|
* Let's just hope nobody changed ClientPointer between GetPointerMapping
|
|
|
|
* and SetPointerMapping
|
|
|
|
*/
|
|
|
|
if (stuff->nElts != ptr->button->numButtons) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->nElts;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* Core protocol specs don't allow for duplicate mappings; this check
|
|
|
|
* almost certainly wants disabling through XFixes too. */
|
|
|
|
for (i = 0; i < stuff->nElts; i++) {
|
|
|
|
for (j = i + 1; j < stuff->nElts; j++) {
|
|
|
|
if (map[i] && map[i] == map[j]) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = map[i];
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
ret = ApplyPointerMapping(ptr, map, stuff->nElts, client);
|
|
|
|
if (ret == MappingBusy)
|
2007-11-24 12:04:00 -07:00
|
|
|
rep.success = ret;
|
2010-07-27 13:02:24 -06:00
|
|
|
else if (ret == -1)
|
|
|
|
return BadValue;
|
|
|
|
else if (ret != Success)
|
|
|
|
return ret;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
WriteReplyToClient(client, sizeof(xSetPointerMappingReply), &rep);
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcGetKeyboardMapping(ClientPtr client)
|
|
|
|
{
|
|
|
|
xGetKeyboardMappingReply rep;
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr kbd = PickKeyboard(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbDescPtr xkb;
|
|
|
|
KeySymsPtr syms;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
|
|
|
REQUEST(xGetKeyboardMappingReq);
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xGetKeyboardMappingReq);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, kbd, DixGetAttrAccess);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
xkb = kbd->key->xkbInfo->desc;
|
|
|
|
|
|
|
|
if ((stuff->firstKeyCode < xkb->min_key_code) ||
|
|
|
|
(stuff->firstKeyCode > xkb->max_key_code)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->firstKeyCode;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
if (stuff->firstKeyCode + stuff->count > xkb->max_key_code + 1) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->count;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
syms = XkbGetCoreMap(kbd);
|
|
|
|
if (!syms)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
memset(&rep, 0, sizeof(xGetKeyboardMappingReply));
|
2006-11-26 11:13:41 -07:00
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.keySymsPerKeyCode = syms->mapWidth;
|
2006-11-26 11:13:41 -07:00
|
|
|
/* length is a count of 4 byte quantities and KeySyms are 4 bytes */
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.length = syms->mapWidth * stuff->count;
|
2006-11-26 11:13:41 -07:00
|
|
|
WriteReplyToClient(client, sizeof(xGetKeyboardMappingReply), &rep);
|
|
|
|
client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
|
2010-07-27 13:02:24 -06:00
|
|
|
WriteSwappedDataToClient(client,
|
|
|
|
syms->mapWidth * stuff->count * sizeof(KeySym),
|
|
|
|
&syms->map[syms->mapWidth * (stuff->firstKeyCode -
|
|
|
|
syms->minKeyCode)]);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(syms->map);
|
|
|
|
free(syms);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcGetPointerMapping(ClientPtr client)
|
|
|
|
{
|
|
|
|
xGetPointerMappingReply rep;
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Apps may get different values each time they call GetPointerMapping as
|
|
|
|
* the ClientPointer could change. */
|
|
|
|
DeviceIntPtr ptr = PickPointer(client);
|
|
|
|
ButtonClassPtr butc = ptr->button;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xReq);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, ptr, DixGetAttrAccess);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.nElts = (butc) ? butc->numButtons : 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
rep.length = ((unsigned)rep.nElts + (4-1))/4;
|
|
|
|
WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (butc)
|
|
|
|
WriteToClient(client, (int)rep.nElts, (char *)&butc->map[1]);
|
2009-09-06 13:44:18 -06:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NoteLedState(DeviceIntPtr keybd, int led, Bool on)
|
|
|
|
{
|
|
|
|
KeybdCtrl *ctrl = &keybd->kbdfeed->ctrl;
|
|
|
|
if (on)
|
|
|
|
ctrl->leds |= ((Leds)1 << (led - 1));
|
|
|
|
else
|
|
|
|
ctrl->leds &= ~((Leds)1 << (led - 1));
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2006-11-26 11:13:41 -07:00
|
|
|
Ones(unsigned long mask) /* HACKMEM 169 */
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
unsigned long y;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
y = (mask >> 1) &033333333333;
|
|
|
|
y = mask - y - ((y >>1) & 033333333333);
|
|
|
|
return (((y + (y >> 3)) & 030707070707) % 077);
|
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
static int
|
|
|
|
DoChangeKeyboardControl (ClientPtr client, DeviceIntPtr keybd, XID *vlist,
|
|
|
|
BITS32 vmask)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
#define DO_ALL (-1)
|
|
|
|
KeybdCtrl ctrl;
|
|
|
|
int t;
|
|
|
|
int led = DO_ALL;
|
|
|
|
int key = DO_ALL;
|
2007-11-24 12:04:00 -07:00
|
|
|
BITS32 index2;
|
|
|
|
int mask = vmask, i;
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbEventCauseRec cause;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ctrl = keybd->kbdfeed->ctrl;
|
2007-11-24 12:04:00 -07:00
|
|
|
while (vmask) {
|
2006-11-26 11:13:41 -07:00
|
|
|
index2 = (BITS32) lowbit (vmask);
|
|
|
|
vmask &= ~index2;
|
2007-11-24 12:04:00 -07:00
|
|
|
switch (index2) {
|
2009-09-06 13:44:18 -06:00
|
|
|
case KBKeyClickPercent:
|
2006-11-26 11:13:41 -07:00
|
|
|
t = (INT8)*vlist;
|
|
|
|
vlist++;
|
2007-11-24 12:04:00 -07:00
|
|
|
if (t == -1) {
|
2006-11-26 11:13:41 -07:00
|
|
|
t = defaultKeyboardControl.click;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
else if (t < 0 || t > 100) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = t;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
ctrl.click = t;
|
|
|
|
break;
|
|
|
|
case KBBellPercent:
|
|
|
|
t = (INT8)*vlist;
|
|
|
|
vlist++;
|
2007-11-24 12:04:00 -07:00
|
|
|
if (t == -1) {
|
2006-11-26 11:13:41 -07:00
|
|
|
t = defaultKeyboardControl.bell;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
else if (t < 0 || t > 100) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = t;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
ctrl.bell = t;
|
|
|
|
break;
|
|
|
|
case KBBellPitch:
|
|
|
|
t = (INT16)*vlist;
|
|
|
|
vlist++;
|
2007-11-24 12:04:00 -07:00
|
|
|
if (t == -1) {
|
2006-11-26 11:13:41 -07:00
|
|
|
t = defaultKeyboardControl.bell_pitch;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
else if (t < 0) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = t;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
ctrl.bell_pitch = t;
|
|
|
|
break;
|
|
|
|
case KBBellDuration:
|
|
|
|
t = (INT16)*vlist;
|
|
|
|
vlist++;
|
|
|
|
if (t == -1)
|
|
|
|
t = defaultKeyboardControl.bell_duration;
|
2007-11-24 12:04:00 -07:00
|
|
|
else if (t < 0) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = t;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
ctrl.bell_duration = t;
|
|
|
|
break;
|
|
|
|
case KBLed:
|
|
|
|
led = (CARD8)*vlist;
|
|
|
|
vlist++;
|
2007-11-24 12:04:00 -07:00
|
|
|
if (led < 1 || led > 32) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = led;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
if (!(mask & KBLedMode))
|
2006-11-26 11:13:41 -07:00
|
|
|
return BadMatch;
|
|
|
|
break;
|
|
|
|
case KBLedMode:
|
|
|
|
t = (CARD8)*vlist;
|
|
|
|
vlist++;
|
2007-11-24 12:04:00 -07:00
|
|
|
if (t == LedModeOff) {
|
2006-11-26 11:13:41 -07:00
|
|
|
if (led == DO_ALL)
|
|
|
|
ctrl.leds = 0x0;
|
|
|
|
else
|
|
|
|
ctrl.leds &= ~(((Leds)(1)) << (led - 1));
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
else if (t == LedModeOn) {
|
2006-11-26 11:13:41 -07:00
|
|
|
if (led == DO_ALL)
|
|
|
|
ctrl.leds = ~0L;
|
|
|
|
else
|
|
|
|
ctrl.leds |= (((Leds)(1)) << (led - 1));
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = t;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
XkbSetCauseCoreReq(&cause,X_ChangeKeyboardControl,client);
|
|
|
|
XkbSetIndicators(keybd,((led == DO_ALL) ? ~0L : (1L<<(led-1))),
|
|
|
|
ctrl.leds, &cause);
|
|
|
|
ctrl.leds = keybd->kbdfeed->ctrl.leds;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
break;
|
|
|
|
case KBKey:
|
|
|
|
key = (KeyCode)*vlist;
|
|
|
|
vlist++;
|
2010-07-27 13:02:24 -06:00
|
|
|
if ((KeyCode)key < keybd->key->xkbInfo->desc->min_key_code ||
|
|
|
|
(KeyCode)key > keybd->key->xkbInfo->desc->max_key_code) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = key;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
if (!(mask & KBAutoRepeatMode))
|
2006-11-26 11:13:41 -07:00
|
|
|
return BadMatch;
|
|
|
|
break;
|
|
|
|
case KBAutoRepeatMode:
|
|
|
|
i = (key >> 3);
|
|
|
|
mask = (1 << (key & 7));
|
|
|
|
t = (CARD8)*vlist;
|
|
|
|
vlist++;
|
2010-07-27 13:02:24 -06:00
|
|
|
if (key != DO_ALL)
|
2007-11-24 12:04:00 -07:00
|
|
|
XkbDisableComputedAutoRepeats(keybd,key);
|
|
|
|
if (t == AutoRepeatModeOff) {
|
2006-11-26 11:13:41 -07:00
|
|
|
if (key == DO_ALL)
|
|
|
|
ctrl.autoRepeat = FALSE;
|
|
|
|
else
|
|
|
|
ctrl.autoRepeats[i] &= ~mask;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
else if (t == AutoRepeatModeOn) {
|
2006-11-26 11:13:41 -07:00
|
|
|
if (key == DO_ALL)
|
|
|
|
ctrl.autoRepeat = TRUE;
|
|
|
|
else
|
|
|
|
ctrl.autoRepeats[i] |= mask;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
else if (t == AutoRepeatModeDefault) {
|
2006-11-26 11:13:41 -07:00
|
|
|
if (key == DO_ALL)
|
|
|
|
ctrl.autoRepeat = defaultKeyboardControl.autoRepeat;
|
|
|
|
else
|
|
|
|
ctrl.autoRepeats[i] =
|
|
|
|
(ctrl.autoRepeats[i] & ~mask) |
|
|
|
|
(defaultKeyboardControl.autoRepeats[i] & mask);
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = t;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2007-11-24 12:04:00 -07:00
|
|
|
client->errorValue = mask;
|
2006-11-26 11:13:41 -07:00
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keybd->kbdfeed->ctrl = ctrl;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/* The XKB RepeatKeys control and core protocol global autorepeat */
|
|
|
|
/* value are linked */
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbSetRepeatKeys(keybd, key, keybd->kbdfeed->ctrl.autoRepeat);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return Success;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#undef DO_ALL
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* Changes kbd control on the ClientPointer and all attached SDs.
|
|
|
|
*/
|
2007-11-24 12:04:00 -07:00
|
|
|
int
|
|
|
|
ProcChangeKeyboardControl (ClientPtr client)
|
|
|
|
{
|
|
|
|
XID *vlist;
|
|
|
|
BITS32 vmask;
|
|
|
|
int ret = Success, error = Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr pDev = NULL, keyboard;
|
2007-11-24 12:04:00 -07:00
|
|
|
REQUEST(xChangeKeyboardControlReq);
|
|
|
|
|
|
|
|
REQUEST_AT_LEAST_SIZE(xChangeKeyboardControlReq);
|
|
|
|
|
|
|
|
vmask = stuff->mask;
|
|
|
|
vlist = (XID *)&stuff[1];
|
|
|
|
|
|
|
|
if (client->req_len != (sizeof(xChangeKeyboardControlReq)>>2)+Ones(vmask))
|
|
|
|
return BadLength;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
keyboard = PickKeyboard(client);
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
|
2011-11-05 07:32:40 -06:00
|
|
|
if ((pDev == keyboard ||
|
|
|
|
(!IsMaster(pDev) && GetMaster(pDev, MASTER_KEYBOARD) == keyboard))
|
|
|
|
&& pDev->kbdfeed && pDev->kbdfeed->CtrlProc) {
|
2008-11-02 08:26:08 -07:00
|
|
|
ret = XaceHook(XACE_DEVICE_ACCESS, client, pDev, DixManageAccess);
|
|
|
|
if (ret != Success)
|
|
|
|
return ret;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
|
2011-11-05 07:32:40 -06:00
|
|
|
if ((pDev == keyboard ||
|
|
|
|
(!IsMaster(pDev) && GetMaster(pDev, MASTER_KEYBOARD) == keyboard))
|
|
|
|
&& pDev->kbdfeed && pDev->kbdfeed->CtrlProc) {
|
2007-11-24 12:04:00 -07:00
|
|
|
ret = DoChangeKeyboardControl(client, pDev, vlist, vmask);
|
|
|
|
if (ret != Success)
|
|
|
|
error = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
int
|
|
|
|
ProcGetKeyboardControl (ClientPtr client)
|
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc, i;
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr kbd = PickKeyboard(client);
|
|
|
|
KeybdCtrl *ctrl = &kbd->kbdfeed->ctrl;
|
2006-11-26 11:13:41 -07:00
|
|
|
xGetKeyboardControlReply rep;
|
|
|
|
REQUEST_SIZE_MATCH(xReq);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, kbd, DixGetAttrAccess);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 5;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
rep.globalAutoRepeat = ctrl->autoRepeat;
|
|
|
|
rep.keyClickPercent = ctrl->click;
|
|
|
|
rep.bellPercent = ctrl->bell;
|
|
|
|
rep.bellPitch = ctrl->bell_pitch;
|
|
|
|
rep.bellDuration = ctrl->bell_duration;
|
|
|
|
rep.ledMask = ctrl->leds;
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
rep.map[i] = ctrl->autoRepeats[i];
|
|
|
|
WriteReplyToClient(client, sizeof(xGetKeyboardControlReply), &rep);
|
|
|
|
return Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
ProcBell(ClientPtr client)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr dev, keybd = PickKeyboard(client);
|
2006-11-26 11:13:41 -07:00
|
|
|
int base = keybd->kbdfeed->ctrl.bell;
|
|
|
|
int newpercent;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST(xBellReq);
|
|
|
|
REQUEST_SIZE_MATCH(xBellReq);
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
if (stuff->percent < -100 || stuff->percent > 100) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->percent;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
newpercent = (base * stuff->percent) / 100;
|
|
|
|
if (stuff->percent < 0)
|
|
|
|
newpercent = base + newpercent;
|
|
|
|
else
|
2009-09-06 13:44:18 -06:00
|
|
|
newpercent = base - newpercent + stuff->percent;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
for (dev = inputInfo.devices; dev; dev = dev->next) {
|
2011-11-05 07:32:40 -06:00
|
|
|
if ((dev == keybd ||
|
|
|
|
(!IsMaster(dev) && GetMaster(dev, MASTER_KEYBOARD) == keybd)) &&
|
2010-07-27 13:02:24 -06:00
|
|
|
dev->kbdfeed && dev->kbdfeed->BellProc) {
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixBellAccess);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbHandleBell(FALSE, FALSE, dev, newpercent,
|
|
|
|
&dev->kbdfeed->ctrl, 0, None, NULL, client);
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
ProcChangePointerControl(ClientPtr client)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr dev, mouse = PickPointer(client);
|
2006-11-26 11:13:41 -07:00
|
|
|
PtrCtrl ctrl; /* might get BadValue part way through */
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST(xChangePointerControlReq);
|
|
|
|
REQUEST_SIZE_MATCH(xChangePointerControlReq);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
ctrl = mouse->ptrfeed->ctrl;
|
2007-11-24 12:04:00 -07:00
|
|
|
if ((stuff->doAccel != xTrue) && (stuff->doAccel != xFalse)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->doAccel;
|
2010-12-05 08:36:02 -07:00
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
if ((stuff->doThresh != xTrue) && (stuff->doThresh != xFalse)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->doThresh;
|
2010-12-05 08:36:02 -07:00
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
if (stuff->doAccel) {
|
|
|
|
if (stuff->accelNum == -1) {
|
2006-11-26 11:13:41 -07:00
|
|
|
ctrl.num = defaultPointerControl.num;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
else if (stuff->accelNum < 0) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->accelNum;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
else {
|
|
|
|
ctrl.num = stuff->accelNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stuff->accelDenum == -1) {
|
2006-11-26 11:13:41 -07:00
|
|
|
ctrl.den = defaultPointerControl.den;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
else if (stuff->accelDenum <= 0) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->accelDenum;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
else {
|
|
|
|
ctrl.den = stuff->accelDenum;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
if (stuff->doThresh) {
|
|
|
|
if (stuff->threshold == -1) {
|
2006-11-26 11:13:41 -07:00
|
|
|
ctrl.threshold = defaultPointerControl.threshold;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
else if (stuff->threshold < 0) {
|
2006-11-26 11:13:41 -07:00
|
|
|
client->errorValue = stuff->threshold;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
else {
|
|
|
|
ctrl.threshold = stuff->threshold;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
for (dev = inputInfo.devices; dev; dev = dev->next) {
|
2011-11-05 07:32:40 -06:00
|
|
|
if ((dev == mouse ||
|
|
|
|
(!IsMaster(dev) && GetMaster(dev, MASTER_POINTER) == mouse)) &&
|
2010-12-05 08:36:02 -07:00
|
|
|
dev->ptrfeed) {
|
2010-07-27 13:02:24 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixManageAccess);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
for (dev = inputInfo.devices; dev; dev = dev->next) {
|
2011-11-05 07:32:40 -06:00
|
|
|
if ((dev == mouse ||
|
|
|
|
(!IsMaster(dev) && GetMaster(dev, MASTER_POINTER) == mouse)) &&
|
2010-12-05 08:36:02 -07:00
|
|
|
dev->ptrfeed) {
|
2010-07-27 13:02:24 -06:00
|
|
|
dev->ptrfeed->ctrl = ctrl;
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
ProcGetPointerControl(ClientPtr client)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr ptr = PickPointer(client);
|
|
|
|
PtrCtrl *ctrl = &ptr->ptrfeed->ctrl;
|
2006-11-26 11:13:41 -07:00
|
|
|
xGetPointerControlReply rep;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xReq);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, ptr, DixGetAttrAccess);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
rep.threshold = ctrl->threshold;
|
|
|
|
rep.accelNumerator = ctrl->num;
|
|
|
|
rep.accelDenominator = ctrl->den;
|
|
|
|
WriteReplyToClient(client, sizeof(xGenericReply), &rep);
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-24 12:04:00 -07:00
|
|
|
MaybeStopHint(DeviceIntPtr dev, ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
GrabPtr grab = dev->deviceGrab.grab;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if ((grab && SameClient(grab, client) &&
|
|
|
|
((grab->eventMask & PointerMotionHintMask) ||
|
|
|
|
(grab->ownerEvents &&
|
|
|
|
(EventMaskForClient(dev->valuator->motionHintWindow, client) &
|
|
|
|
PointerMotionHintMask)))) ||
|
|
|
|
(!grab &&
|
|
|
|
(EventMaskForClient(dev->valuator->motionHintWindow, client) &
|
|
|
|
PointerMotionHintMask)))
|
|
|
|
dev->valuator->motionHintWindow = NullWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcGetMotionEvents(ClientPtr client)
|
|
|
|
{
|
|
|
|
WindowPtr pWin;
|
|
|
|
xTimecoord * coords = (xTimecoord *) NULL;
|
|
|
|
xGetMotionEventsReply rep;
|
2007-11-24 12:04:00 -07:00
|
|
|
int i, count, xmin, xmax, ymin, ymax, rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
unsigned long nEvents;
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr mouse = PickPointer(client);
|
2006-11-26 11:13:41 -07:00
|
|
|
TimeStamp start, stop;
|
|
|
|
REQUEST(xGetMotionEventsReq);
|
|
|
|
REQUEST_SIZE_MATCH(xGetMotionEventsReq);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, mouse, DixReadAccess);
|
2007-11-24 12:04:00 -07:00
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (mouse->valuator->motionHintWindow)
|
|
|
|
MaybeStopHint(mouse, client);
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
nEvents = 0;
|
|
|
|
start = ClientTimeToServerTime(stuff->start);
|
|
|
|
stop = ClientTimeToServerTime(stuff->stop);
|
|
|
|
if ((CompareTimeStamps(start, stop) != LATER) &&
|
|
|
|
(CompareTimeStamps(start, currentTime) != LATER) &&
|
|
|
|
mouse->valuator->numMotionEvents)
|
|
|
|
{
|
|
|
|
if (CompareTimeStamps(stop, currentTime) == LATER)
|
|
|
|
stop = currentTime;
|
2009-09-06 13:44:18 -06:00
|
|
|
count = GetMotionHistory(mouse, &coords, start.milliseconds,
|
|
|
|
stop.milliseconds, pWin->drawable.pScreen,
|
|
|
|
TRUE);
|
2006-11-26 11:13:41 -07:00
|
|
|
xmin = pWin->drawable.x - wBorderWidth (pWin);
|
|
|
|
xmax = pWin->drawable.x + (int)pWin->drawable.width +
|
|
|
|
wBorderWidth (pWin);
|
|
|
|
ymin = pWin->drawable.y - wBorderWidth (pWin);
|
|
|
|
ymax = pWin->drawable.y + (int)pWin->drawable.height +
|
|
|
|
wBorderWidth (pWin);
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if ((xmin <= coords[i].x) && (coords[i].x < xmax) &&
|
|
|
|
(ymin <= coords[i].y) && (coords[i].y < ymax))
|
|
|
|
{
|
|
|
|
coords[nEvents].time = coords[i].time;
|
|
|
|
coords[nEvents].x = coords[i].x - pWin->drawable.x;
|
|
|
|
coords[nEvents].y = coords[i].y - pWin->drawable.y;
|
|
|
|
nEvents++;
|
|
|
|
}
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.length = nEvents * bytes_to_int32(sizeof(xTimecoord));
|
2006-11-26 11:13:41 -07:00
|
|
|
rep.nEvents = nEvents;
|
|
|
|
WriteReplyToClient(client, sizeof(xGetMotionEventsReply), &rep);
|
|
|
|
if (nEvents)
|
|
|
|
{
|
|
|
|
client->pSwapReplyFunc = (ReplySwapPtr) SwapTimeCoordWrite;
|
|
|
|
WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord),
|
|
|
|
(char *)coords);
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(coords);
|
2006-11-26 11:13:41 -07:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcQueryKeymap(ClientPtr client)
|
|
|
|
{
|
|
|
|
xQueryKeymapReply rep;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc, i;
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr keybd = PickKeyboard(client);
|
|
|
|
CARD8 *down = keybd->key->down;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xReq);
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
rep.length = 2;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc != Success && rc != BadAccess)
|
2008-11-02 08:26:08 -07:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
for (i = 0; i<32; i++)
|
|
|
|
rep.map[i] = down[i];
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc == BadAccess)
|
|
|
|
memset(rep.map, 0, 32);
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recalculate the number of buttons for the master device. The number of
|
|
|
|
* buttons on the master device is equal to the number of buttons on the
|
|
|
|
* slave device with the highest number of buttons.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
RecalculateMasterButtons(DeviceIntPtr slave)
|
|
|
|
{
|
|
|
|
DeviceIntPtr dev, master;
|
|
|
|
int maxbuttons = 0;
|
|
|
|
|
|
|
|
if (!slave->button || IsMaster(slave))
|
|
|
|
return;
|
|
|
|
|
|
|
|
master = GetMaster(slave, MASTER_POINTER);
|
|
|
|
if (!master)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (dev = inputInfo.devices; dev; dev = dev->next)
|
|
|
|
{
|
|
|
|
if (IsMaster(dev) ||
|
2011-11-05 07:32:40 -06:00
|
|
|
GetMaster(dev, MASTER_ATTACHED) != master ||
|
2010-07-27 13:02:24 -06:00
|
|
|
!dev->button)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
maxbuttons = max(maxbuttons, dev->button->numButtons);
|
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
if (master->button && master->button->numButtons != maxbuttons)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
DeviceChangedEvent event;
|
|
|
|
|
|
|
|
memset(&event, 0, sizeof(event));
|
|
|
|
|
|
|
|
master->button->numButtons = maxbuttons;
|
|
|
|
|
|
|
|
event.header = ET_Internal;
|
|
|
|
event.type = ET_DeviceChanged;
|
2010-12-05 08:36:02 -07:00
|
|
|
event.time = GetTimeInMillis();
|
2010-07-27 13:02:24 -06:00
|
|
|
event.deviceid = master->id;
|
|
|
|
event.flags = DEVCHANGE_POINTER_EVENT | DEVCHANGE_DEVICE_CHANGE;
|
|
|
|
event.buttons.num_buttons = maxbuttons;
|
|
|
|
memcpy(&event.buttons.names, master->button->labels, maxbuttons *
|
|
|
|
sizeof(Atom));
|
|
|
|
|
|
|
|
if (master->valuator)
|
|
|
|
{
|
|
|
|
event.num_valuators = master->valuator->numAxes;
|
|
|
|
for (i = 0; i < event.num_valuators; i++)
|
|
|
|
{
|
|
|
|
event.valuators[i].min = master->valuator->axes[i].min_value;
|
|
|
|
event.valuators[i].max = master->valuator->axes[i].max_value;
|
|
|
|
event.valuators[i].resolution = master->valuator->axes[i].resolution;
|
2011-11-05 07:32:40 -06:00
|
|
|
event.valuators[i].mode = master->valuator->axes[i].mode;
|
2010-07-27 13:02:24 -06:00
|
|
|
event.valuators[i].name = master->valuator->axes[i].label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (master->key)
|
|
|
|
{
|
|
|
|
event.keys.min_keycode = master->key->xkbInfo->desc->min_key_code;
|
|
|
|
event.keys.max_keycode = master->key->xkbInfo->desc->max_key_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
XISendDeviceChangedEvent(master, master, &event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/**
|
|
|
|
* Generate release events for all keys/button currently down on this
|
|
|
|
* device.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ReleaseButtonsAndKeys(DeviceIntPtr dev)
|
|
|
|
{
|
|
|
|
InternalEvent* eventlist = InitEventList(GetMaximumEventsNum());
|
|
|
|
ButtonClassPtr b = dev->button;
|
|
|
|
KeyClassPtr k = dev->key;
|
|
|
|
int i, j, nevents;
|
|
|
|
|
|
|
|
if (!eventlist) /* no release events for you */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Release all buttons */
|
|
|
|
for (i = 0; b && i < b->numButtons; i++)
|
|
|
|
{
|
|
|
|
if (BitIsOn(b->down, i))
|
|
|
|
{
|
|
|
|
nevents = GetPointerEvents(eventlist, dev, ButtonRelease, i, 0, NULL);
|
|
|
|
for (j = 0; j < nevents; j++)
|
|
|
|
mieqProcessDeviceEvent(dev, &eventlist[j], NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release all keys */
|
|
|
|
for (i = 0; k && i < MAP_LENGTH; i++)
|
|
|
|
{
|
|
|
|
if (BitIsOn(k->down, i))
|
|
|
|
{
|
|
|
|
nevents = GetKeyboardEvents(eventlist, dev, KeyRelease, i, NULL);
|
|
|
|
for (j = 0; j < nevents; j++)
|
|
|
|
mieqProcessDeviceEvent(dev, &eventlist[j], NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeEventList(eventlist, GetMaximumEventsNum());
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/**
|
|
|
|
* Attach device 'dev' to device 'master'.
|
|
|
|
* Client is set to the client that issued the request, or NULL if it comes
|
|
|
|
* from some internal automatic pairing.
|
|
|
|
*
|
|
|
|
* Master may be NULL to set the device floating.
|
|
|
|
*
|
|
|
|
* We don't allow multi-layer hierarchies right now. You can't attach a slave
|
|
|
|
* to another slave.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master)
|
|
|
|
{
|
|
|
|
ScreenPtr screen;
|
|
|
|
DeviceIntPtr oldmaster;
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!dev || IsMaster(dev))
|
2009-09-06 13:44:18 -06:00
|
|
|
return BadDevice;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (master && !IsMaster(master)) /* can't attach to slaves */
|
2009-09-06 13:44:18 -06:00
|
|
|
return BadDevice;
|
|
|
|
|
|
|
|
/* set from floating to floating? */
|
2011-11-05 07:32:40 -06:00
|
|
|
if (IsFloating(dev) && !master && dev->enabled)
|
2009-09-06 13:44:18 -06:00
|
|
|
return Success;
|
|
|
|
|
|
|
|
/* free the existing sprite. */
|
2011-11-05 07:32:40 -06:00
|
|
|
if (IsFloating(dev) && dev->spriteInfo->paired == dev)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
screen = miPointerGetScreen(dev);
|
|
|
|
screen->DeviceCursorCleanup(dev, screen);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(dev->spriteInfo->sprite);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
oldmaster = GetMaster(dev, MASTER_ATTACHED);
|
|
|
|
dev->master = master;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* If device is set to floating, we need to create a sprite for it,
|
|
|
|
* otherwise things go bad. However, we don't want to render the cursor,
|
|
|
|
* so we reset spriteOwner.
|
|
|
|
* Sprite has to be forced to NULL first, otherwise InitializeSprite won't
|
|
|
|
* alloc new memory but overwrite the previous one.
|
|
|
|
*/
|
|
|
|
if (!master)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
WindowPtr currentRoot;
|
|
|
|
|
|
|
|
if (dev->spriteInfo->sprite)
|
2011-11-05 07:32:40 -06:00
|
|
|
currentRoot = GetCurrentRootWindow(dev);
|
2010-07-27 13:02:24 -06:00
|
|
|
else /* new device auto-set to floating */
|
2010-12-05 08:36:02 -07:00
|
|
|
currentRoot = screenInfo.screens[0]->root;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* we need to init a fake sprite */
|
|
|
|
screen = currentRoot->drawable.pScreen;
|
|
|
|
screen->DeviceCursorInitialize(dev, screen);
|
|
|
|
dev->spriteInfo->sprite = NULL;
|
|
|
|
InitializeSprite(dev, currentRoot);
|
|
|
|
dev->spriteInfo->spriteOwner = FALSE;
|
|
|
|
dev->spriteInfo->paired = dev;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
dev->spriteInfo->sprite = master->spriteInfo->sprite;
|
|
|
|
dev->spriteInfo->paired = master;
|
|
|
|
dev->spriteInfo->spriteOwner = FALSE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
RecalculateMasterButtons(master);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* XXX: in theory, the MD should change back to its old, original
|
|
|
|
* classes when the last SD is detached. Thanks to the XTEST devices,
|
|
|
|
* we'll always have an SD attached until the MD is removed.
|
|
|
|
* So let's not worry about that.
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the device paired with the given device or NULL.
|
|
|
|
* Returns the device paired with the parent master if the given device is a
|
|
|
|
* slave device.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr
|
2009-09-06 13:44:18 -06:00
|
|
|
GetPairedDevice(DeviceIntPtr dev)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!IsMaster(dev) && !IsFloating(dev))
|
|
|
|
dev = GetMaster(dev, MASTER_ATTACHED);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
return dev->spriteInfo->paired;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-07-27 13:02:24 -06:00
|
|
|
* Returns the right master for the type of event needed. If the event is a
|
|
|
|
* keyboard event.
|
|
|
|
* This function may be called with a master device as argument. If so, the
|
|
|
|
* returned master is either the device itself or the paired master device.
|
|
|
|
* If dev is a floating slave device, NULL is returned.
|
|
|
|
*
|
2011-11-05 07:32:40 -06:00
|
|
|
* @type ::MASTER_KEYBOARD or ::MASTER_POINTER or ::MASTER_ATTACHED
|
|
|
|
* @return The requested master device. In the case of MASTER_ATTACHED, this
|
|
|
|
* is the directly attached master to this device, regardless of the type.
|
|
|
|
* Otherwise, it is either the master keyboard or pointer for this device.
|
2010-07-27 13:02:24 -06:00
|
|
|
*/
|
|
|
|
DeviceIntPtr
|
|
|
|
GetMaster(DeviceIntPtr dev, int which)
|
|
|
|
{
|
|
|
|
DeviceIntPtr master;
|
|
|
|
|
|
|
|
if (IsMaster(dev))
|
|
|
|
master = dev;
|
|
|
|
else
|
2011-11-05 07:32:40 -06:00
|
|
|
master = dev->master;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (master && which != MASTER_ATTACHED)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
if (which == MASTER_KEYBOARD)
|
|
|
|
{
|
|
|
|
if (master->type != MASTER_KEYBOARD)
|
|
|
|
master = GetPairedDevice(master);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (master->type != MASTER_POINTER)
|
|
|
|
master = GetPairedDevice(master);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return master;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new device pair (== one pointer, one keyboard device).
|
2009-09-06 13:44:18 -06:00
|
|
|
* Only allocates the devices, you will need to call ActivateDevice() and
|
|
|
|
* EnableDevice() manually.
|
2010-07-27 13:02:24 -06:00
|
|
|
* Either a master or a slave device can be created depending on
|
|
|
|
* the value for master.
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
|
|
|
int
|
2010-07-27 13:02:24 -06:00
|
|
|
AllocDevicePair (ClientPtr client, char* name,
|
|
|
|
DeviceIntPtr* ptr,
|
|
|
|
DeviceIntPtr* keybd,
|
|
|
|
DeviceProc ptr_proc,
|
|
|
|
DeviceProc keybd_proc,
|
|
|
|
Bool master)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
DeviceIntPtr pointer;
|
|
|
|
DeviceIntPtr keyboard;
|
|
|
|
|
|
|
|
*ptr = *keybd = NULL;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
pointer = AddInputDevice(client, ptr_proc, TRUE);
|
2009-09-06 13:44:18 -06:00
|
|
|
if (!pointer)
|
|
|
|
return BadAlloc;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
if (asprintf(&pointer->name, "%s pointer", name) == -1) {
|
|
|
|
pointer->name = NULL;
|
|
|
|
RemoveDevice(pointer, FALSE);
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
pointer->public.processInputProc = ProcessOtherEvent;
|
|
|
|
pointer->public.realInputProc = ProcessOtherEvent;
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbSetExtension(pointer, ProcessPointerEvent);
|
2009-09-06 13:44:18 -06:00
|
|
|
pointer->deviceGrab.ActivateGrab = ActivatePointerGrab;
|
|
|
|
pointer->deviceGrab.DeactivateGrab = DeactivatePointerGrab;
|
|
|
|
pointer->coreEvents = TRUE;
|
|
|
|
pointer->spriteInfo->spriteOwner = TRUE;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
pointer->lastSlave = NULL;
|
2010-07-27 13:02:24 -06:00
|
|
|
pointer->last.slave = NULL;
|
|
|
|
pointer->type = (master) ? MASTER_POINTER : SLAVE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
keyboard = AddInputDevice(client, keybd_proc, TRUE);
|
2009-09-06 13:44:18 -06:00
|
|
|
if (!keyboard)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
RemoveDevice(pointer, FALSE);
|
2009-09-06 13:44:18 -06:00
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (asprintf(&keyboard->name, "%s keyboard", name) == -1) {
|
|
|
|
keyboard->name = NULL;
|
|
|
|
RemoveDevice(keyboard, FALSE);
|
|
|
|
RemoveDevice(pointer, FALSE);
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
keyboard->public.processInputProc = ProcessOtherEvent;
|
|
|
|
keyboard->public.realInputProc = ProcessOtherEvent;
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbSetExtension(keyboard, ProcessKeyboardEvent);
|
2009-09-06 13:44:18 -06:00
|
|
|
keyboard->deviceGrab.ActivateGrab = ActivateKeyboardGrab;
|
|
|
|
keyboard->deviceGrab.DeactivateGrab = DeactivateKeyboardGrab;
|
|
|
|
keyboard->coreEvents = TRUE;
|
|
|
|
keyboard->spriteInfo->spriteOwner = FALSE;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
keyboard->lastSlave = NULL;
|
2010-07-27 13:02:24 -06:00
|
|
|
keyboard->last.slave = NULL;
|
|
|
|
keyboard->type = (master) ? MASTER_KEYBOARD : SLAVE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* The ClassesRec stores the device classes currently not used. */
|
2010-12-05 08:36:02 -07:00
|
|
|
pointer->unused_classes = calloc(1, sizeof(ClassesRec));
|
|
|
|
keyboard->unused_classes = calloc(1, sizeof(ClassesRec));
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
*ptr = pointer;
|
|
|
|
*keybd = keyboard;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return Success;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/**
|
|
|
|
* Return Relative or Absolute for the device.
|
|
|
|
*/
|
|
|
|
int valuator_get_mode(DeviceIntPtr dev, int axis)
|
|
|
|
{
|
|
|
|
return (dev->valuator->axes[axis].mode & DeviceMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the given mode for the axis. If axis is VALUATOR_MODE_ALL_AXES, then
|
|
|
|
* set the mode for all axes.
|
|
|
|
*/
|
|
|
|
void valuator_set_mode(DeviceIntPtr dev, int axis, int mode)
|
|
|
|
{
|
|
|
|
if (axis != VALUATOR_MODE_ALL_AXES)
|
|
|
|
dev->valuator->axes[axis].mode = mode;
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < dev->valuator->numAxes; i++)
|
|
|
|
dev->valuator->axes[i].mode = mode;
|
|
|
|
}
|
|
|
|
}
|