diff options
Diffstat (limited to 'hw/xfree86/os-support/bsd/bsd_mouse.c')
-rw-r--r-- | hw/xfree86/os-support/bsd/bsd_mouse.c | 144 |
1 files changed, 138 insertions, 6 deletions
diff --git a/hw/xfree86/os-support/bsd/bsd_mouse.c b/hw/xfree86/os-support/bsd/bsd_mouse.c index f681d90d9..943bb9855 100644 --- a/hw/xfree86/os-support/bsd/bsd_mouse.c +++ b/hw/xfree86/os-support/bsd/bsd_mouse.c @@ -1,7 +1,30 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_mouse.c,v 1.24 2003/02/15 05:37:59 paulo Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_mouse.c,v 1.26 2003/10/10 20:56:05 herrb Exp $ */ /* - * Copyright 1999 by The XFree86 Project, Inc. + * Copyright (c) 1999-2003 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 copyright holder(s) + * and author(s) 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 copyright holder(s) and author(s). */ #include "X.h" @@ -45,6 +68,20 @@ static void usbSigioReadInput (int fd, void *closure); #endif +#if defined(__FreeBSD__) +/* These are for FreeBSD */ +#define DEFAULT_MOUSE_DEV "/dev/mouse" +#define DEFAULT_SYSMOUSE_DEV "/dev/sysmouse" +#define DEFAULT_PS2_DEV "/dev/psm0" + +static const char *mouseDevs[] = { + DEFAULT_MOUSE_DEV, + DEFAULT_SYSMOUSE_DEV, + DEFAULT_PS2_DEV, + NULL +}; +#endif + static int SupportedInterfaces(void) { @@ -196,6 +233,98 @@ SetSysMouseRes(InputInfoPtr pInfo, const char *protocol, int rate, int res) } #endif +#if defined(__FreeBSD__) + +#define MOUSED_PID_FILE "/var/run/moused.pid" + +/* + * Try to check if moused is running. DEFAULT_SYSMOUSE_DEV is useless without + * it. There doesn't seem to be a better way of checking. + */ +static Bool +MousedRunning(void) +{ + FILE *f = NULL; + unsigned int pid; + + if ((f = fopen(MOUSED_PID_FILE, "r")) != NULL) { + if (fscanf(f, "%u", &pid) == 1 && pid > 0) { + if (kill(pid, 0) == 0) { + fclose(f); + return TRUE; + } + } + fclose(f); + } + return FALSE; +} + +static const char * +FindDevice(InputInfoPtr pInfo, const char *protocol, int flags) +{ + int fd = -1; + const char **pdev, *dev = NULL; + Bool devMouse = FALSE; + struct stat devMouseStat; + struct stat sb; + + for (pdev = mouseDevs; *pdev; pdev++) { + SYSCALL (fd = open(*pdev, O_RDWR | O_NONBLOCK)); + if (fd == -1) { +#ifdef DEBUG + ErrorF("Cannot open %s (%s)\n", *pdev, strerror(errno)); +#endif + } else { + /* + * /dev/mouse is held until checks for matches with other devices + * are done. This is so that when it points to /dev/sysmouse, + * the test for whether /dev/sysmouse is usable can be made. + */ + if (!strcmp(*pdev, DEFAULT_MOUSE_DEV)) { + if (fstat(fd, &devMouseStat) == 0) + devMouse = TRUE; + close(fd); + continue; + } else if (!strcmp(*pdev, DEFAULT_SYSMOUSE_DEV)) { + /* Check if /dev/mouse is the same as /dev/sysmouse. */ + if (devMouse && fstat(fd, &sb) == 0 && + devMouseStat.st_dev == sb.st_dev && + devMouseStat.st_ino == sb.st_ino) { + /* If the same, use /dev/sysmouse. */ + devMouse = FALSE; + } + close(fd); + if (MousedRunning()) + break; + else { +#ifdef DEBUG + ErrorF("moused isn't running\n"); +#endif + } + } else { + close(fd); + break; + } + } + } + + if (*pdev) + dev = *pdev; + else if (devMouse) + dev = DEFAULT_MOUSE_DEV; + + if (dev) { + /* Set the Device option. */ + pInfo->conf_idev->commonOptions = + xf86AddNewOption(pInfo->conf_idev->commonOptions, "Device", dev); + xf86Msg(X_INFO, "%s: Setting Device option to \"%s\"\n", + pInfo->name, dev); + } + + return *pdev; +} +#endif + #if defined(WSCONS_SUPPORT) #define NUMEVENTS 64 @@ -502,11 +631,11 @@ usbPreInit(InputInfoPtr pInfo, const char *protocol, int flags) #ifdef USB_NEW_HID if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X), hid_input, &pUsbMse->loc_x, pUsbMse->iid) < 0) { - xf86Msg(X_WARNING, "%s: no x locator\n"); + xf86Msg(X_WARNING, "%s: no x locator\n", pInfo->name); } if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y), hid_input, &pUsbMse->loc_y, pUsbMse->iid) < 0) { - xf86Msg(X_WARNING, "%s: no y locator\n"); + xf86Msg(X_WARNING, "%s: no y locator\n", pInfo->name); } if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL), hid_input, &pUsbMse->loc_z, pUsbMse->iid) < 0) { @@ -514,11 +643,11 @@ usbPreInit(InputInfoPtr pInfo, const char *protocol, int flags) #else if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X), hid_input, &pUsbMse->loc_x) < 0) { - xf86Msg(X_WARNING, "%s: no x locator\n"); + xf86Msg(X_WARNING, "%s: no x locator\n", pInfo->name); } if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y), hid_input, &pUsbMse->loc_y) < 0) { - xf86Msg(X_WARNING, "%s: no y locator\n"); + xf86Msg(X_WARNING, "%s: no y locator\n", pInfo->name); } if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL), hid_input, &pUsbMse->loc_z) < 0) { @@ -589,6 +718,9 @@ xf86OSMouseInit(int flags) p->SetBMRes = SetSysMouseRes; p->SetMiscRes = SetSysMouseRes; #endif +#if defined(__FreeBSD__) + p->FindDevice = FindDevice; +#endif p->PreInit = bsdMousePreInit; return p; } |