--- xserver-old/xorg/hw/darwin/darwinXinput.c 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/hw/darwin/darwinXinput.c 2005-12-25 22:54:18.000000000 -0500 @@ -308,3 +308,16 @@ return (BadMatch); } } + +int +AddAndEnableInputDevice (const char *name, const char *driver, + xDeviceOption *options_list, int num_options) +{ + return !Success; +} + +int +DisableAndRemoveInputDevice (const char *name) +{ + return !Success; +} --- xserver-old/xorg/hw/dmx/input/dmxxinput.c 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/hw/dmx/input/dmxxinput.c 2005-12-25 22:54:18.000000000 -0500 @@ -154,3 +154,16 @@ { return BadMatch; } + +int +AddAndEnableInputDevice (const char *name, const char *driver, + xDeviceOption *options_list, int num_options) +{ + return !Success; +} + +int +DisableAndRemoveInputDevice (const char *name) +{ + return !Success; +} --- xserver-old/xorg/hw/xfree86/common/xf86Helper.c 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/hw/xfree86/common/xf86Helper.c 2005-12-25 22:54:18.000000000 -0500 @@ -140,6 +140,19 @@ xf86InputDriverList[drvIndex] = NULL; } +InputDriverPtr +xf86LookupInputDriver(const char *name) +{ + int i; + + for (i = 0; i < xf86NumInputDrivers; i++) { + if (xf86InputDriverList[i] && xf86InputDriverList[i]->driverName && + xf86NameCmp(name, xf86InputDriverList[i]->driverName) == 0) + return xf86InputDriverList[i]; + } + return NULL; +} + void xf86AddModuleInfo(ModuleInfoPtr info, pointer module) { @@ -374,6 +387,19 @@ xfree(pInp); } +InputInfoPtr +xf86LookupInput(const char *name) +{ + InputInfoPtr p; + + for (p = xf86InputDevs; p != NULL; p = p->next) { + if (strcmp(name, p->name) == 0) + return p; + } + + return NULL; +} + Bool xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad) { --- xserver-old/xorg/hw/xfree86/common/xf86Init.c 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/hw/xfree86/common/xf86Init.c 2005-12-25 22:54:18.000000000 -0500 @@ -1007,20 +1007,6 @@ } -static InputDriverPtr -MatchInput(IDevPtr pDev) -{ - int i; - - for (i = 0; i < xf86NumInputDrivers; i++) { - if (xf86InputDriverList[i] && xf86InputDriverList[i]->driverName && - xf86NameCmp(pDev->driver, xf86InputDriverList[i]->driverName) == 0) - return xf86InputDriverList[i]; - } - return NULL; -} - - /* * InitInput -- * Initialize all supported input devices. @@ -1057,7 +1043,7 @@ } #endif - if ((pDrv = MatchInput(pDev)) == NULL) { + if ((pDrv = xf86LookupInputDriver(pDev->driver)) == NULL) { xf86Msg(X_ERROR, "No Input driver matching `%s'\n", pDev->driver); /* XXX For now, just continue. */ continue; --- xserver-old/xorg/hw/xfree86/common/xf86Xinput.c 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/hw/xfree86/common/xf86Xinput.c 2005-12-25 22:54:18.000000000 -0500 @@ -65,6 +65,7 @@ #include "xf86Xinput.h" #ifdef XINPUT #include "XIstubs.h" +#include "xf86Optrec.h" #endif #include "mipointer.h" #include "xf86InPriv.h" @@ -620,6 +621,112 @@ return (*local->control_proc)(local, control); } } + +int +AddAndEnableInputDevice (const char *name, const char *driver, + xDeviceOption *option_list, int num_options) +{ + IDevRec *idev; + InputDriverPtr drv; + InputInfoPtr pInfo; + DeviceIntPtr dev; + int i; + + pInfo = xf86LookupInput(name); + if (pInfo != NULL) { + /* Device already present */ + return BadName; + } + + if (!xf86LoadOneModule((char *) driver, NULL)) { + return BadName; + } + + drv = xf86LookupInputDriver(driver); + if (drv == NULL) { + xf86Msg(X_ERROR, "No Input driver matching `%s'\n", driver); + return BadName; + } + + if (!drv->PreInit) { + xf86Msg(X_ERROR, + "Input driver `%s' has no PreInit function (ignoring)\n", + drv->driverName); + return BadImplementation; + } + + idev = xalloc(sizeof *idev); + idev->identifier = xstrdup(name); + idev->driver = xstrdup(driver); + idev->commonOptions = NULL; + for (i = 0; i < num_options; i++) + idev->commonOptions = xf86addNewOption(idev->commonOptions, + option_list[i].name, + option_list[i].value); + idev->extraOptions = NULL; + + pInfo = drv->PreInit(drv, idev, 0); + + if (!pInfo) { + xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n", name); + return BadMatch; + } + else if (!(pInfo->flags & XI86_CONFIGURED)) { + xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n", name); + xf86DeleteInput(pInfo, 0); + return BadMatch; + } + + xf86ActivateDevice(pInfo); + + dev = pInfo->dev; + dev->inited = ((*dev->deviceProc)(dev, DEVICE_INIT) == Success); + if (dev->inited && dev->startup) + EnableDevice(dev); + + return Success; +} + +int +DisableAndRemoveInputDevice(const char *identifier) +{ + InputInfoPtr pInfo; + LocalDevicePtr local = (LocalDevicePtr) pInfo; + DeviceIntPtr dev; + + ErrorF("DisableAndRemoveInputDevice(\"%s\"): not implemented yet\n", + identifier); + + /* TODO: + * + * - if XInput clients have selected input from this device, + * clean that up + * Is this really needed? + * + */ + + pInfo = xf86LookupInput(identifier); + if (pInfo == NULL) + { + return BadName; + } + + local = (LocalDevicePtr) pInfo; + + if ((local->flags & XI86_CORE_POINTER) || + (local->flags & XI86_CORE_KEYBOARD)) + { + return BadMatch; + } + + dev = pInfo->dev; + RemoveDevice(dev); + + xf86DeleteInput(pInfo, 0); + + return Success; +} + #endif /* --- xserver-old/xorg/hw/xfree86/common/xf86Xinput.h 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/hw/xfree86/common/xf86Xinput.h 2005-12-25 22:54:18.000000000 -0500 @@ -210,8 +210,10 @@ /* xf86Helper.c */ void xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags); void xf86DeleteInputDriver(int drvIndex); +InputDriverPtr xf86LookupInputDriver(const char *name); InputInfoPtr xf86AllocateInput(InputDriverPtr drv, int flags); void xf86DeleteInput(InputInfoPtr pInp, int flags); +InputInfoPtr xf86LookupInput(const char *name); /* xf86Option.c */ void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts, --- xserver-old/xorg/include/extinit.h 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/include/extinit.h 2005-12-25 22:54:18.000000000 -0500 @@ -93,6 +93,12 @@ ); void +SDevicePresenceNotifyEvent ( + devicePresenceNotify * /* from */, + devicePresenceNotify * /* to */ + ); + +void SChangeDeviceNotifyEvent ( changeDeviceNotify * /* from */, changeDeviceNotify * /* to */ @@ -104,6 +110,7 @@ deviceMappingNotify * /* to */ ); + void FixExtensionEvents ( ExtensionEntry * /* extEntry */ --- xserver-old/xorg/include/XIstubs.h 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/include/XIstubs.h 2005-12-25 22:54:18.000000000 -0500 @@ -73,4 +73,15 @@ DeviceIntPtr /* dev */, xDeviceCtl * /* control */); +int +AddAndEnableInputDevice ( + const char * /* name */, + const char * /* driver */, + xDeviceOption * /* options_list */, + int /* num_options*/); + +int +DisableAndRemoveInputDevice ( + const char * /* name */); + #endif /* XI_STUBS_H */ --- xserver-old/xorg/Xi/adddev.c 1969-12-31 19:00:00.000000000 -0500 +++ xserver/xorg/Xi/adddev.c 2005-12-25 22:54:18.000000000 -0500 @@ -0,0 +1,197 @@ +/* + * Copyright © 2004 Red Hat, Inc. + * + * 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, and that the name of Red Hat not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Red Hat makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT + * 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. + * + * Author: Kristian Høgsberg (krh@redhat.com) + */ + +/*********************************************************************** + * + * Request to add an extension input device. + * + */ + +#define NEED_EVENTS +#define NEED_REPLIES +#include "X.h" /* for inputstr.h */ +#include "Xproto.h" /* Request macro */ +#include "inputstr.h" /* DeviceIntPtr */ +#include "XI.h" +#include "XIproto.h" +#include "XIstubs.h" +#include "windowstr.h" /* window structure */ +#include "extnsionst.h" +#include "extinit.h" /* LookupDeviceIntRec */ +#include "exglobals.h" +#include "chgptr.h" + +#include "adddev.h" + +int +SProcXAddInputDevice(ClientPtr client) +{ + register char n; + + REQUEST(xAddInputDeviceReq); + swaps(&stuff->length, n); + return ProcXAddInputDevice(client); +} + +int +XiGetString(ClientPtr client, char *end, char **p, char **res) +{ + int length; + char *str; + char n; + + *res = NULL; + if (*p + 4 > end) + return BadLength; + + length = ** (CARD16 **) p; + *p += 4; + if (client->swapped) { + swaps(&length, n); + } + + if (*p + length > end) + return BadLength; + + str = xalloc(length + 1); + if (str == NULL) + return BadAlloc; + + memcpy(str, *p, length); + str[length] = '\0'; + *p += (length + 3) & ~3; + + *res = str; + return Success; +} + +static void +FreeDeviceOptionList(xDeviceOption *option_list, int noptions) +{ + int i; + + for (i = 0; i < noptions; i++) { + xfree(option_list[i].name); + xfree(option_list[i].value); + } + xfree(option_list); +} + +/*********************************************************************** + * + * This procedure causes the server to add a new input device. + * + */ + +int +ProcXAddInputDevice(ClientPtr client) +{ + char *name, *driver, *p, *end; + int res, noptions, i; + xDeviceOption *option_list; + xAddInputDeviceReply rep; + devicePresenceNotify ev; + DeviceIntRec dummyDev; + + REQUEST(xAddInputDeviceReq); + REQUEST_AT_LEAST_SIZE(xAddInputDeviceReq); + + noptions = 0; + option_list = NULL; + + p = (char *) &stuff[1]; + end = p + stuff->length * 4; + + res = XiGetString(client, end, &p, &name); + if (res != Success) + goto exit_failure; + + res = XiGetString(client, end, &p, &driver); + if (res != Success) + goto exit_failure; + + if (p + 4 > end) { + SendErrorToClient(client, IReqCode, X_AddInputDevice, 0, BadLength); + return Success; + } + + noptions = * (CARD16 *) p; + p += 4; + option_list = xcalloc(sizeof(xDeviceOption), noptions); + for (i = 0; i < noptions; i++) { + res = XiGetString(client, end, &p, &option_list[i].name); + if (res != Success) + goto exit_failure; + + res = XiGetString(client, end, &p, &option_list[i].value); + if (res != Success) + goto exit_failure; + } + + res = AddAndEnableInputDevice(name, driver, option_list, noptions); + if (res != Success) + goto exit_failure; + + ev.type = DevicePresenceNotify; + ev.time = currentTime.milliseconds; + + dummyDev.id = 0; + SendEventToAllWindows (&dummyDev, DevicePresenceNotifyMask, + (xEvent *)&ev, 1); + + rep.repType = X_Reply; + rep.RepType = X_AddInputDevice; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.status = res; + + WriteReplyToClient(client, sizeof (xAddInputDeviceReply), &rep); + xfree(name); + FreeDeviceOptionList(option_list, noptions); + + return Success; + + exit_failure: + xfree(name); + FreeDeviceOptionList(option_list, noptions); + + SendErrorToClient(client, IReqCode, X_AddInputDevice, 0, res); + return Success; +} + +/*********************************************************************** + * + * This procedure writes the reply for the XOpenDevice function, + * if the client and server have a different byte ordering. + * + */ + +void +SRepXAddInputDevice (ClientPtr client, int size, xAddInputDeviceReply *rep) +{ + register char n; + + swaps(&rep->sequenceNumber, n); + swapl(&rep->length, n); + WriteToClient(client, size, (char *)rep); +} --- xserver-old/xorg/Xi/adddev.h 1969-12-31 19:00:00.000000000 -0500 +++ xserver/xorg/Xi/adddev.h 2005-12-25 22:54:18.000000000 -0500 @@ -0,0 +1,39 @@ +/* + * Copyright © 2004 Red Hat, Inc. + * + * 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, and that the name of Red Hat not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Red Hat makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT + * 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. + * + * Author: Kristian Høgsberg (krh@redhat.com) + */ + +#ifndef ADDDEV_H +#define ADDDEV_H 1 + +int +XiGetString(ClientPtr client, char *end, char **p, char **res); + +int +SProcXAddInputDevice(ClientPtr client); + +int +ProcXAddInputDevice(ClientPtr client); + +void +SRepXAddInputDevice (ClientPtr client, int size, xAddInputDeviceReply *rep); + +#endif /* ADDDEV_H */ --- xserver-old/xorg/Xi/exglobals.h 2005-12-25 22:39:22.000000000 -0500 +++ xserver/xorg/Xi/exglobals.h 2005-12-25 22:54:18.000000000 -0500 @@ -52,6 +52,7 @@ extern Mask DeviceOwnerGrabButtonMask; extern Mask DeviceButtonGrabMask; extern Mask DeviceButtonMotionMask; +extern Mask DevicePresenceNotifyMask; extern Mask PropagateMask[]; extern int DeviceValuator; @@ -68,6 +69,7 @@ extern int DeviceKeyStateNotify; extern int DeviceButtonStateNotify; extern int DeviceMappingNotify; +extern int DevicePresenceNotify; extern int ChangeDeviceNotify; extern int RT_INPUTCLIENT; --- xserver-old/xorg/Xi/extinit.c 2005-12-25 22:39:22.000000000 -0500 +++ xserver/xorg/Xi/extinit.c 2005-12-25 22:54:18.000000000 -0500 @@ -76,6 +76,7 @@ #include "swaprep.h" /* modules local to Xi */ +#include "adddev.h" #include "allowev.h" #include "chgdctl.h" #include "chgfctl.h" @@ -102,6 +103,7 @@ #include "listdev.h" #include "opendev.h" #include "queryst.h" +#include "rmdev.h" #include "selectev.h" #include "sendexev.h" #include "chgkmap.h" @@ -167,6 +169,7 @@ Mask DeviceOwnerGrabButtonMask; Mask DeviceButtonGrabMask; Mask DeviceButtonMotionMask; +Mask DevicePresenceNotifyMask; int DeviceValuator; int DeviceKeyPress; @@ -183,6 +186,7 @@ int DeviceButtonStateNotify; int DeviceMappingNotify; int ChangeDeviceNotify; +int DevicePresenceNotify; int RT_INPUTCLIENT; @@ -204,8 +208,8 @@ static XExtensionVersion thisversion = {XI_Present, - XI_Add_XChangeDeviceControl_Major, - XI_Add_XChangeDeviceControl_Minor}; + XI_Add_XAddInputDevice_Major, + XI_Add_XAddInputDevice_Minor}; /********************************************************************** * @@ -248,6 +252,7 @@ EventSwapVector[DeviceButtonStateNotify] = SEventIDispatch; EventSwapVector[DeviceMappingNotify] = SEventIDispatch; EventSwapVector[ChangeDeviceNotify] = SEventIDispatch; + EventSwapVector[DevicePresenceNotify] = SEventIDispatch; } else { @@ -337,6 +342,10 @@ return(ProcXGetDeviceControl(client)); else if (stuff->data == X_ChangeDeviceControl) return(ProcXChangeDeviceControl(client)); + else if (stuff->data == X_AddInputDevice) + return(ProcXAddInputDevice(client)); + else if (stuff->data == X_RemoveInputDevice) + return(ProcXRemoveInputDevice(client)); else { SendErrorToClient(client, IReqCode, stuff->data, 0, BadRequest); @@ -428,6 +437,10 @@ return(SProcXGetDeviceControl(client)); else if (stuff->data == X_ChangeDeviceControl) return(SProcXChangeDeviceControl(client)); + else if (stuff->data == X_AddInputDevice) + return(SProcXAddInputDevice(client)); + else if (stuff->data == X_RemoveInputDevice) + return(SProcXRemoveInputDevice(client)); else { SendErrorToClient(client, IReqCode, stuff->data, 0, BadRequest); @@ -495,6 +508,10 @@ SRepXGetDeviceControl (client, len, (xGetDeviceControlReply *)rep); else if (rep->RepType == X_ChangeDeviceControl) SRepXChangeDeviceControl (client, len, (xChangeDeviceControlReply *)rep); + else if (rep->RepType == X_AddInputDevice) + SRepXAddInputDevice (client, len, (xAddInputDeviceReply *)rep); + else if (rep->RepType == X_RemoveInputDevice) + SRepXRemoveInputDevice (client, len, (xRemoveInputDeviceReply *)rep); else { FatalError("XINPUT confused sending swapped reply"); @@ -567,6 +584,8 @@ DO_SWAP(SDeviceMappingNotifyEvent, deviceMappingNotify); else if (type == ChangeDeviceNotify) DO_SWAP(SChangeDeviceNotifyEvent, changeDeviceNotify); + else if (type == DevicePresenceNotify) + DO_SWAP(SDevicePresenceNotifyEvent, devicePresenceNotify); else { FatalError("XInputExtension: Impossible event!\n"); @@ -676,6 +695,18 @@ swapl(&to->time, n); } +void +SDevicePresenceNotifyEvent (from, to) + devicePresenceNotify *from; + devicePresenceNotify *to; + { + register char n; + + *to = *from; + swaps(&to->sequenceNumber,n); + swapl(&to->time, n); + } + /************************************************************************ * * This function sets up extension event types and masks. @@ -703,6 +734,7 @@ ChangeDeviceNotify = DeviceMappingNotify + 1; DeviceKeyStateNotify = ChangeDeviceNotify + 1; DeviceButtonStateNotify = DeviceKeyStateNotify + 1; + DevicePresenceNotify = DeviceButtonStateNotify + 1; event_base[KeyClass] = DeviceKeyPress; event_base[ButtonClass] = DeviceButtonPress; @@ -776,6 +808,9 @@ DeviceOwnerGrabButtonMask = GetNextExtEventMask(); SetEventInfo (DeviceOwnerGrabButtonMask, _deviceOwnerGrabButton); SetEventInfo (0, _noExtensionEvent); + + DevicePresenceNotifyMask = GetNextExtEventMask(); + SetMaskForExtEvent(DevicePresenceNotifyMask, DevicePresenceNotify); } /************************************************************************ @@ -854,6 +889,7 @@ EventSwapVector[DeviceButtonStateNotify] = NotImplemented; EventSwapVector[DeviceMappingNotify] = NotImplemented; EventSwapVector[ChangeDeviceNotify] = NotImplemented; + EventSwapVector[DevicePresenceNotify] = NotImplemented; RestoreExtensionEvents (); } --- xserver-old/xorg/Xi/Makefile.am 2005-12-25 22:39:22.000000000 -0500 +++ xserver/xorg/Xi/Makefile.am 2005-12-25 22:41:37.000000000 -0500 @@ -3,6 +3,8 @@ AM_CFLAGS = $(DIX_CFLAGS) @SERVER_DEFINES@ @LOADER_DEFINES@ libXi_la_SOURCES = \ + adddev.c \ + adddev.h \ allowev.c \ allowev.h \ chgdctl.c \ @@ -56,6 +58,8 @@ opendev.h \ queryst.c \ queryst.h \ + rmdev.c \ + rmdev.h \ selectev.c \ selectev.h \ sendexev.c \ --- xserver-old/xorg/Xi/rmdev.c 1969-12-31 19:00:00.000000000 -0500 +++ xserver/xorg/Xi/rmdev.c 2005-12-25 22:54:18.000000000 -0500 @@ -0,0 +1,107 @@ +/* + * Copyright © 2004 Red Hat, Inc. + * + * 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, and that the name of Red Hat not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Red Hat makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT + * 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. + * + * Author: Kristian Høgsberg (krh@redhat.com) + */ + +#define NEED_EVENTS +#define NEED_REPLIES +#include "X.h" /* for inputstr.h */ +#include "Xproto.h" /* Request macro */ +#include "inputstr.h" /* DeviceIntPtr */ +#include "XI.h" +#include "XIproto.h" +#include "XIstubs.h" +#include "windowstr.h" /* window structure */ +#include "extnsionst.h" +#include "extinit.h" /* LookupDeviceIntRec */ +#include "exglobals.h" +#include "chgptr.h" + +#include "adddev.h" +#include "rmdev.h" + +int +SProcXRemoveInputDevice(ClientPtr client) +{ + register char n; + + REQUEST(xRemoveInputDeviceReq); + swaps(&stuff->length, n); + return ProcXRemoveInputDevice(client); +} + +int +ProcXRemoveInputDevice(ClientPtr client) +{ + char *name, *p, *end; + int res; + xRemoveInputDeviceReply rep; + devicePresenceNotify ev; + DeviceIntRec dummyDev; + + REQUEST(xRemoveInputDeviceReq); + REQUEST_AT_LEAST_SIZE(xRemoveInputDeviceReq); + + p = (char *) &stuff[1]; + end = p + stuff->length * 4; + + res = XiGetString(client, end, &p, &name); + if (res != Success) + goto exit_failure; + + res = DisableAndRemoveInputDevice(name); + if (res != Success) + goto exit_failure; + + ev.type = DevicePresenceNotify; + ev.time = currentTime.milliseconds; + + dummyDev.id = 0; + SendEventToAllWindows (&dummyDev, DevicePresenceNotifyMask, + (xEvent *)&ev, 1); + rep.repType = X_Reply; + rep.RepType = X_RemoveInputDevice; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.status = res; + + WriteReplyToClient(client, sizeof (xRemoveInputDeviceReply), &rep); + xfree(name); + + return Success; + + exit_failure: + xfree(name); + + SendErrorToClient(client, IReqCode, X_AddInputDevice, 0, res); + return Success; +} + +void +SRepXRemoveInputDevice (ClientPtr client, int size, + xRemoveInputDeviceReply *rep) +{ + register char n; + + swaps(&rep->sequenceNumber, n); + swapl(&rep->length, n); + WriteToClient(client, size, (char *)rep); +} --- xserver-old/xorg/Xi/rmdev.h 1969-12-31 19:00:00.000000000 -0500 +++ xserver/xorg/Xi/rmdev.h 2005-12-25 22:54:18.000000000 -0500 @@ -0,0 +1,37 @@ +/* + * Copyright © 2004 Red Hat, Inc. + * + * 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, and that the name of Red Hat not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Red Hat makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT + * 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. + * + * Author: Kristian Høgsberg (krh@redhat.com) + */ + +#ifndef RMDEV_H +#define RMDEV_H 1 + +int +SProcXRemoveInputDevice(ClientPtr client); + +int +ProcXRemoveInputDevice(ClientPtr client); + +void +SRepXRemoveInputDevice (ClientPtr client, int size, + xRemoveInputDeviceReply *rep); + +#endif /* RMDEV_H */ --- xserver-old/xorg/Xi/selectev.c 2005-12-25 22:39:22.000000000 -0500 +++ xserver/xorg/Xi/selectev.c 2005-12-25 22:54:18.000000000 -0500 @@ -77,6 +77,53 @@ extern Mask ExtExclusiveMasks[]; extern Mask ExtValidMasks[]; +static int +HandleDevicePresenceMask(ClientPtr client, WindowPtr win, + XEventClass *cls, CARD16 *count) +{ + int i, j; + Mask mask; + + /* We use the device ID 256 to select events that aren't bound to + * any device. For now we only handle the device presence event, + * but this could be extended to other events that aren't bound to + * a device. + * + * In order not to break in CreateMaskFromList() we remove the + * entries with device ID 256 from the XEventClass array. + */ + + mask = 0; + for (i = 0, j = 0; i < *count; i++) { + if (cls[i] >> 8 != 256) { + cls[j] = cls[i]; + j++; + continue; + } + + switch (cls[i] & 0xff) { + case _devicePresence: + mask |= DevicePresenceNotifyMask; + break; + } + } + + *count = j; + + if (mask == 0) + return Success; + + /* We always only use mksidx = 0 for events not bound to + * devices */ + + if (AddExtensionClient (win, client, mask, 0) != Success) + return BadAlloc; + + RecalculateDeviceDeliverableEvents(win); + + return Success; +} + /*********************************************************************** * * Handle requests from clients with a different byte order. @@ -139,6 +186,16 @@ return Success; } + if (HandleDevicePresenceMask(client, pWin, + (XEventClass *)&stuff[1], + &stuff->count) != Success) + { + SendErrorToClient(client, IReqCode, X_SelectExtensionEvent, 0, + BadAlloc); + return Success; + } + + if ((ret = CreateMaskFromList (client, (XEventClass *)&stuff[1], stuff->count, tmp, NULL, X_SelectExtensionEvent)) != Success) return Success; --- xserver-old/xorg/Xi/stubs.c 2005-12-25 22:39:22.000000000 -0500 +++ xserver/xorg/Xi/stubs.c 2005-12-25 22:54:18.000000000 -0500 @@ -315,3 +315,16 @@ return (BadMatch); } } + +int +AddAndEnableInputDevice (const char *name, const char *driver, + xDeviceOption *options_list, int num_options) +{ + return !Success; +} + +int +DisableAndRemoveInputDevice (const char *name) +{ + return !Success; +} --- xserver-old/xorg/Xprint/ddxInit.c 2005-12-25 22:39:23.000000000 -0500 +++ xserver/xorg/Xprint/ddxInit.c 2005-12-25 22:54:18.000000000 -0500 @@ -363,6 +363,18 @@ return BadMatch; } +int +AddAndEnableInputDevice (const char *name, const char *driver, + xDeviceOption *options_list, int num_options) +{ + return !Success; +} + +int +DisableAndRemoveInputDevice (const char *name) +{ + return !Success; +} #endif /* XINPUT */