--- xorg/Xi/adddev.c.inputhotplug~ 2006-03-04 20:27:32.000000000 +0100 +++ xorg/Xi/adddev.c 2006-03-04 20:27:32.000000000 +0100 @@ -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); +} --- xorg/Xi/adddev.h.inputhotplug~ 2006-03-04 20:27:32.000000000 +0100 +++ xorg/Xi/adddev.h 2006-03-04 20:27:32.000000000 +0100 @@ -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 */ --- xorg/Xi/exglobals.h.inputhotplug~ 2006-03-04 17:55:16.000000000 +0100 +++ xorg/Xi/exglobals.h 2006-03-04 20:33:17.000000000 +0100 @@ -51,6 +51,7 @@ extern Mask DeviceOwnerGrabButtonMask; extern Mask DeviceButtonGrabMask; extern Mask DeviceButtonMotionMask; +extern Mask DevicePresenceNotifyMask; extern Mask PropagateMask[]; extern int DeviceValuator; @@ -67,6 +68,7 @@ extern int DeviceKeyStateNotify; extern int DeviceButtonStateNotify; extern int DeviceMappingNotify; +extern int DevicePresenceNotify; extern int ChangeDeviceNotify; extern int RT_INPUTCLIENT; --- xorg/Xi/extinit.c.inputhotplug~ 2006-03-04 17:55:16.000000000 +0100 +++ xorg/Xi/extinit.c 2006-03-04 20:40:31.000000000 +0100 @@ -73,6 +73,7 @@ #include "swaprep.h" /* modules local to Xi */ +#include "adddev.h" #include "allowev.h" #include "chgdctl.h" #include "chgfctl.h" @@ -99,6 +100,7 @@ #include "listdev.h" #include "opendev.h" #include "queryst.h" +#include "rmdev.h" #include "selectev.h" #include "sendexev.h" #include "chgkmap.h" @@ -165,6 +167,7 @@ Mask DeviceOwnerGrabButtonMask; Mask DeviceButtonGrabMask; Mask DeviceButtonMotionMask; +Mask DevicePresenceNotifyMask; int DeviceValuator; int DeviceKeyPress; @@ -181,6 +184,7 @@ int DeviceButtonStateNotify; int DeviceMappingNotify; int ChangeDeviceNotify; +int DevicePresenceNotify; int RT_INPUTCLIENT; @@ -201,8 +205,8 @@ */ static XExtensionVersion thisversion = { XI_Present, - XI_Add_XChangeDeviceControl_Major, - XI_Add_XChangeDeviceControl_Minor + XI_Add_XAddInputDevice_Major, + XI_Add_XAddInputDevice_Minor }; /********************************************************************** @@ -245,6 +249,7 @@ EventSwapVector[DeviceButtonStateNotify] = SEventIDispatch; EventSwapVector[DeviceMappingNotify] = SEventIDispatch; EventSwapVector[ChangeDeviceNotify] = SEventIDispatch; + EventSwapVector[DevicePresenceNotify] = SEventIDispatch; } else { FatalError("IExtensionInit: AddExtensions failed\n"); } @@ -331,6 +336,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); } @@ -420,6 +429,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); } @@ -499,6 +512,10 @@ 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"); } @@ -554,6 +571,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"); } @@ -648,6 +667,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. @@ -674,6 +705,7 @@ ChangeDeviceNotify = DeviceMappingNotify + 1; DeviceKeyStateNotify = ChangeDeviceNotify + 1; DeviceButtonStateNotify = DeviceKeyStateNotify + 1; + DevicePresenceNotify = DeviceButtonStateNotify + 1; event_base[KeyClass] = DeviceKeyPress; event_base[ButtonClass] = DeviceButtonPress; @@ -747,6 +779,9 @@ DeviceOwnerGrabButtonMask = GetNextExtEventMask(); SetEventInfo(DeviceOwnerGrabButtonMask, _deviceOwnerGrabButton); SetEventInfo(0, _noExtensionEvent); + + DevicePresenceNotifyMask = GetNextExtEventMask(); + SetMaskForExtEvent(DevicePresenceNotifyMask, DevicePresenceNotify); } /************************************************************************ @@ -823,6 +858,7 @@ EventSwapVector[DeviceButtonStateNotify] = NotImplemented; EventSwapVector[DeviceMappingNotify] = NotImplemented; EventSwapVector[ChangeDeviceNotify] = NotImplemented; + EventSwapVector[DevicePresenceNotify] = NotImplemented; RestoreExtensionEvents(); } --- xorg/Xi/Makefile.am.inputhotplug~ 2005-12-02 07:02:38.000000000 +0100 +++ xorg/Xi/Makefile.am 2006-03-04 20:27:32.000000000 +0100 @@ -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 \ --- xorg/Xi/rmdev.c.inputhotplug~ 2006-03-04 20:27:32.000000000 +0100 +++ xorg/Xi/rmdev.c 2006-03-04 20:27:32.000000000 +0100 @@ -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); +} --- xorg/Xi/rmdev.h.inputhotplug~ 2006-03-04 20:27:32.000000000 +0100 +++ xorg/Xi/rmdev.h 2006-03-04 20:27:32.000000000 +0100 @@ -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 */ --- xorg/Xi/selectev.c.inputhotplug~ 2006-03-04 17:55:16.000000000 +0100 +++ xorg/Xi/selectev.c 2006-03-04 20:45:29.000000000 +0100 @@ -74,6 +74,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. @@ -131,6 +178,13 @@ return Success; } + if (HandleDevicePresenceMask(client, pWin, (XEventClass *) & stuff[i], + &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) --- xorg/Xi/stubs.c.inputhotplug~ 2006-03-04 17:55:16.000000000 +0100 +++ xorg/Xi/stubs.c 2006-03-04 20:46:35.000000000 +0100 @@ -291,3 +291,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; +} --- xorg/Xprint/ddxInit.c.inputhotplug~ 2006-01-07 00:06:14.000000000 +0100 +++ xorg/Xprint/ddxInit.c 2006-03-04 20:27:32.000000000 +0100 @@ -368,6 +368,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 */ --- xorg/hw/darwin/darwinXinput.c.inputhotplug~ 2005-04-20 14:25:19.000000000 +0200 +++ xorg/hw/darwin/darwinXinput.c 2006-03-04 20:27:32.000000000 +0100 @@ -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; +} --- xorg/hw/dmx/input/dmxxinput.c.inputhotplug~ 2005-07-12 02:52:48.000000000 +0200 +++ xorg/hw/dmx/input/dmxxinput.c 2006-03-04 20:27:32.000000000 +0100 @@ -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; +} --- xorg/hw/xfree86/common/xf86Helper.c.inputhotplug~ 2006-03-04 17:55:18.000000000 +0100 +++ xorg/hw/xfree86/common/xf86Helper.c 2006-03-04 20:27:32.000000000 +0100 @@ -143,6 +143,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) { @@ -377,6 +390,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) { --- xorg/hw/xfree86/common/xf86Init.c.inputhotplug~ 2006-02-13 05:43:40.000000000 +0100 +++ xorg/hw/xfree86/common/xf86Init.c 2006-03-04 20:27:32.000000000 +0100 @@ -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; --- xorg/hw/xfree86/common/xf86Xinput.c.inputhotplug~ 2005-10-21 21:06:13.000000000 +0200 +++ xorg/hw/xfree86/common/xf86Xinput.c 2006-03-04 20:27:32.000000000 +0100 @@ -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 /* --- xorg/hw/xfree86/common/xf86Xinput.h.inputhotplug~ 2006-03-04 17:55:18.000000000 +0100 +++ xorg/hw/xfree86/common/xf86Xinput.h 2006-03-04 20:27:32.000000000 +0100 @@ -211,8 +211,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, --- xorg/include/extinit.h.inputhotplug~ 2005-08-24 13:18:30.000000000 +0200 +++ xorg/include/extinit.h 2006-03-04 20:27:32.000000000 +0100 @@ -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 */ --- xorg/include/XIstubs.h.inputhotplug~ 2005-08-24 13:18:30.000000000 +0200 +++ xorg/include/XIstubs.h 2006-03-04 20:27:32.000000000 +0100 @@ -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 */