pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

xf86-input-mouse-dfbsd: Update wip/xf86-input-mouse-dfbsd to 1.9.3



Module Name:	pkgsrc-wip
Committed By:	David Shao <davshao%gmail.com@localhost>
Pushed By:	dshao
Date:		Sat Feb 23 20:46:52 2019 -0800
Changeset:	8b6e7186787f48d2353fec8667ea7df88c136f68

Modified Files:
	xf86-input-mouse-dfbsd/Makefile
	xf86-input-mouse-dfbsd/distinfo
	xf86-input-mouse-dfbsd/patches/patch-src_bsd__mouse.c
	xf86-input-mouse-dfbsd/patches/patch-src_mouse.c
	xf86-input-mouse-dfbsd/patches/patch-src_mouse.h
	xf86-input-mouse-dfbsd/patches/patch-src_mousePriv.h
Removed Files:
	xf86-input-mouse-dfbsd/TODO
	xf86-input-mouse-dfbsd/options.mk
	xf86-input-mouse-dfbsd/patch-src_bsd__mouse.c

Log Message:
xf86-input-mouse-dfbsd: Update wip/xf86-input-mouse-dfbsd to 1.9.3

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=8b6e7186787f48d2353fec8667ea7df88c136f68

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 xf86-input-mouse-dfbsd/Makefile                    |   17 +-
 xf86-input-mouse-dfbsd/TODO                        |    5 -
 xf86-input-mouse-dfbsd/distinfo                    |   18 +-
 xf86-input-mouse-dfbsd/options.mk                  |   45 -
 xf86-input-mouse-dfbsd/patch-src_bsd__mouse.c      | 1272 --------------------
 .../patches/patch-src_bsd__mouse.c                 |  727 +++++------
 xf86-input-mouse-dfbsd/patches/patch-src_mouse.c   |  158 ++-
 xf86-input-mouse-dfbsd/patches/patch-src_mouse.h   |   44 +-
 .../patches/patch-src_mousePriv.h                  |   24 +-
 9 files changed, 399 insertions(+), 1911 deletions(-)

diffs:
diff --git a/xf86-input-mouse-dfbsd/Makefile b/xf86-input-mouse-dfbsd/Makefile
index 0d6ca010d6..ea9fb95e71 100644
--- a/xf86-input-mouse-dfbsd/Makefile
+++ b/xf86-input-mouse-dfbsd/Makefile
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.27 2016/11/17 08:06:52 wiz Exp $
+# $NetBSD: Makefile,v 1.30 2018/06/19 07:12:45 wiz Exp $
 
-DISTNAME=	xf86-input-mouse-1.9.2
-PKGREVISION=	1
+DISTNAME=	xf86-input-mouse-1.9.3
 CATEGORIES=	x11
 MASTER_SITES=	${MASTER_SITE_XORG:=driver/}
 EXTRACT_SUFX=	.tar.bz2
@@ -9,14 +8,24 @@ EXTRACT_SUFX=	.tar.bz2
 MAINTAINER=	joerg%NetBSD.org@localhost
 HOMEPAGE=	http://xorg.freedesktop.org/
 COMMENT=	Modular Xorg mouse driver
+LICENSE=	mit
 
 USE_LIBTOOL=	YES
 GNU_CONFIGURE=	YES
 USE_TOOLS+=	pkg-config
 
 CONFIGURE_ENV.SunOS+=	DRIVER_MAN_SUFFIX=4
+CFLAGS.DragonFly+= -Wno-array-bounds
 
-.include "options.mk"
+.include "../../mk/bsd.prefs.mk"
+
+.if ${OPSYS} == "FreeBSD" || ${OPSYS} == "DragonFly"
+SUBST_CLASSES+=                 freebsdusb 
+SUBST_STAGE.freebsdusb=		post-extract
+SUBST_MESSAGE.freebsdusb=	Patching src/Makefile.in for DragonFly or FreeBSD compatible USB 
+SUBST_FILES.freebsdusb+=	src/Makefile.in
+SUBST_SED.freebsdusb+=		-e 's|-module -avoid-version|-module -avoid-version -lusbhid|'
+.endif
 
 .include "../../x11/xorgproto/buildlink3.mk"
 .include "../../x11/modular-xorg-server/buildlink3.mk"
diff --git a/xf86-input-mouse-dfbsd/TODO b/xf86-input-mouse-dfbsd/TODO
deleted file mode 100644
index fa30aa8da1..0000000000
--- a/xf86-input-mouse-dfbsd/TODO
+++ /dev/null
@@ -1,5 +0,0 @@
-Copy port to x11/xf86-input-mouse, do not install from wip.
-
-Implements patches from FreeBSD ports / DragonFly dports
-discussed in pkg/50068
-(x11/xf86-input-mouse dports patches for DragonFly and FreeBSD)
diff --git a/xf86-input-mouse-dfbsd/distinfo b/xf86-input-mouse-dfbsd/distinfo
index e5669ca6aa..459f888662 100644
--- a/xf86-input-mouse-dfbsd/distinfo
+++ b/xf86-input-mouse-dfbsd/distinfo
@@ -1,11 +1,11 @@
-$NetBSD: distinfo,v 1.19 2016/11/17 08:06:52 wiz Exp $
+$NetBSD: distinfo,v 1.21 2018/06/19 07:12:45 wiz Exp $
 
-SHA1 (xf86-input-mouse-1.9.2.tar.bz2) = d3a0839ad5a33665bb261a4fba33e3a6271817dc
-RMD160 (xf86-input-mouse-1.9.2.tar.bz2) = c7d68c0de19787ceda4e4307b113b6d74e0cb62d
-SHA512 (xf86-input-mouse-1.9.2.tar.bz2) = 30fdc4f699d434e2fb4a9f8d2f4f980538d646a6e4d2d572737fc5498c0bce0fb1ba080173ea0aa3480f574dde3f58d5a7ac837afdb29640ccb092b3f18ff209
-Size (xf86-input-mouse-1.9.2.tar.bz2) = 377685 bytes
-SHA1 (patch-src_bsd__mouse.c) = fe3ab90a099583a881cddbd1f7da0e689de2253a
-SHA1 (patch-src_mouse.c) = a9ecfd46516fbab2dc4d8e395748a0b6312a24c7
-SHA1 (patch-src_mouse.h) = 2c663b40f8c845ed0f03998edf6d5ddaf4876b71
-SHA1 (patch-src_mousePriv.h) = 20400aecdff2255b0bbf1e42a3d813054814acda
+SHA1 (xf86-input-mouse-1.9.3.tar.bz2) = b3982998808ba43117fc066c4ecc94ce67c5818e
+RMD160 (xf86-input-mouse-1.9.3.tar.bz2) = f73da46dfc7d389531d52e0495db2c2bc4990027
+SHA512 (xf86-input-mouse-1.9.3.tar.bz2) = d99f5b4b1ef1aa4cbf1a92549e412f54f121bc804e4d6643248ad7ea18081b38b958bd289dc8476ebc0f6ef5f7424c2f2a8abcfaa30cae5378829549af6b148f
+Size (xf86-input-mouse-1.9.3.tar.bz2) = 382013 bytes
+SHA1 (patch-src_bsd__mouse.c) = f0718cbe4889f957034e4195a2f138de40b18110
+SHA1 (patch-src_mouse.c) = 04d063d2ea364727309de23d144a3cc4289887b1
+SHA1 (patch-src_mouse.h) = 365fc23f82de0223872be21563af2244585bd537
+SHA1 (patch-src_mousePriv.h) = 6c4ca5f997514e77a937fa8c739a495a6a5e0a43
 SHA1 (patch-src_sun__mouse.c) = e23157bc9bdb5840ac008648d1c9a894e7a900cc
diff --git a/xf86-input-mouse-dfbsd/options.mk b/xf86-input-mouse-dfbsd/options.mk
deleted file mode 100644
index 49417d243c..0000000000
--- a/xf86-input-mouse-dfbsd/options.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-PKG_OPTIONS_VAR=	PKG_OPTIONS.xf86-input-mouse
-# dflyu4b is for DragonFly BSD newer USB stack, ported from newer FreeBSD
-#     #include <bus/u4b/usb.h>
-# dflyusb is for DragonFly BSD older USB stack, OS version < 300703
-#     #include <bus/usb/usb.h>
-# fbsdusb is for FreeBSD USB stack 
-#     #include <dev/usb/usb.h>
-PKG_SUPPORTED_OPTIONS=	dflyu4b dflyusb fbsdusb 
-PKG_SUGGESTED_OPTIONS=
-
-.include "../../mk/bsd.options.mk"
-
-.if ${OPSYS} == "DragonFly"
-.  if !empty(OS_VERSION:M[0-2].*) || !empty(OS_VERSION:M3.0*)
-PKG_SUGGESTED_OPTIONS+=	dflyusb 
-.  else
-# Assume Dragonfly 3.1 - 3.6 users built U4B stack
-# 3.8 and after U4B is the default
-PKG_SUGGESTED_OPTIONS+=	dflyu4b 
-.  endif
-.endif
-
-.if ${OPSYS} == "FreeBSD"
-PKG_SUGGESTED_OPTIONS+=	fbsdusb
-.endif
-
-.if !empty(PKG_OPTIONS:Mdflyu4b) || !empty(PKG_OPTIONS:Mdflyusb) || !empty(PKG_OPTIONS:Mfbsdusb)
-CPPFLAGS+=	-DFREEBSD_USB
-.endif
-
-.if !empty(PKG_OPTIONS:Mdflyu4b)
-CPPFLAGS+=	-DDRAGONFLY_U4B
-.endif
-
-.if !empty(PKG_OPTIONS:Mdflyusb)
-CPPFLAGS+=	-DDRAGONFLY_USB
-.endif
-
-.if !empty(PKG_OPTIONS:Mdflyu4b) || !empty(PKG_OPTIONS:Mdflyusb) || !empty(PKG_OPTIONS:Mfbsdusb)
-SUBST_CLASSES+=			freebsdusb 
-SUBST_STAGE.freebsdusb=		post-extract
-SUBST_MESSAGE.freebsdusb=	Patching src/Makefile.in for DragonFly or FreeBSD compatible USB 
-SUBST_FILES.freebsdusb+=	src/Makefile.in
-SUBST_SED.freebsdusb+=		-e 's|-module -avoid-version|-module -avoid-version -lusbhid|'
-.endif
diff --git a/xf86-input-mouse-dfbsd/patch-src_bsd__mouse.c b/xf86-input-mouse-dfbsd/patch-src_bsd__mouse.c
deleted file mode 100644
index d07560aa31..0000000000
--- a/xf86-input-mouse-dfbsd/patch-src_bsd__mouse.c
+++ /dev/null
@@ -1,1272 +0,0 @@
-$NetBSD$
-
-Patches from FreeBSD ports / DragonFly dports with include guards.
-Support for different versions of system libusb headers.
-
---- src/bsd_mouse.c.orig	2015-04-20 01:07:33.000000000 +0000
-+++ src/bsd_mouse.c
-@@ -26,6 +26,41 @@
-  * authorization from the copyright holder(s) and author(s).
-  */
- 
-+/* PKGSRC note: To support newer versions of DragonFly and FreeBSD,
-+ * this file is patched using DragonFly dports
-+ * x11-drivers/xf86-input-mouse/files/patch-src-bsd_mouse.c and
-+ * x11-drivers/xf86-input-mouse/dragonfly/patch-src_bsd__mouse.c
-+ * as of master commit 4f04bfe0ea83 ... Tue Jul 14 22:56:44 2015 -0700
-+ * The patch's code is enclosed in include defined(FREEBSD_USB) while the
-+ * original code is enclosed in include !defined(FREEBSD_USB).
-+ */
-+
-+/* DRAGONFLY_U4B is the usb system after OS version 300703
-+ * DRAGONFLY_USB is the usb system before OS version 300703
-+ * FREEBSD_USB must be defined if either DRAGONFLY_U4B or DRAGONFLY_USB are.
-+ */
-+
-+#if defined(FREEBSD_USB)
-+
-+/*
-+ * XXX - Should this be autoconf'd instead?
-+ */
-+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-+
-+#if !defined(USBMOUSE_SUPPORT)
-+#define USBMOUSE_SUPPORT
-+#endif
-+#if !defined(HAS_LIB_USB_HID)
-+#define HAS_LIB_USB_HID
-+#endif
-+#if !defined(XPS2_SUPPORT)
-+#define XPS2_SUPPORT
-+#endif
-+
-+#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
-+
-+#endif /* defined(FREEBSD_USB) */
-+
- #include <xorg-server.h>
- 
- #include <X11/X.h>
-@@ -33,12 +68,33 @@
- #include "xf86Priv.h"
- #include "xf86_OSlib.h"
- #include "xf86Xinput.h"
-+#if defined(FREEBSD_USB)
-+#include <exevents.h>
-+#endif
- #include "mouse.h"
- #include "xisb.h"
- #include "mipointer.h"
-+
-+#if defined(FREEBSD_USB)
-+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
-+#define HAVE_PROPERTIES 1
-+#endif
-+#ifdef HAVE_PROPERTIES
-+#include <X11/Xatom.h>
-+#include <xserver-properties.h>
-+/* 1.6 has properties, but no labels */
-+#ifdef AXIS_LABEL_PROP
-+#define HAVE_LABELS
-+#else
-+#undef HAVE_LABELS
-+#endif
-+#endif
-+#endif /* defined(FREEBSD_USB) */
-+
- #ifdef WSCONS_SUPPORT
- #include <dev/wscons/wsconsio.h>
- #endif
-+
- #ifdef USBMOUSE_SUPPORT
- #ifdef HAS_LIB_USB_HID
- #include <usbhid.h>
-@@ -46,10 +102,25 @@
- #include "usb.h"
- #endif
- 
-+#if defined(FREEBSD_USB)
-+
-+#if defined(DRAGONFLY_U4B)
-+#include <sys/param.h>
-+#include <bus/u4b/usb.h>
-+#elif defined(DRAGONFLY_USB)
-+#include <sys/param.h>
-+#include <bus/usb/usb.h>
-+#else
- #include <dev/usb/usb.h>
-+#endif
-+
-+#endif /* defined(FREEBSD_USB) */
-+
-+#if !defined(FREEBSD_USB)
- #ifdef USB_GET_REPORT_ID
- #define USB_NEW_HID
- #endif
-+#endif /* !defined(FREEBSD_USB) */
- 
- #define HUP_GENERIC_DESKTOP     0x0001
- #define HUP_BUTTON              0x0009
-@@ -76,10 +147,17 @@ static const char *FindDevice(InputInfoP
- #define DEFAULT_SYSMOUSE_DEV            "/dev/sysmouse"
- #define DEFAULT_PS2_DEV                 "/dev/psm0"
- 
-+#if defined(FREEBSD_USB)
-+#define DEFAULT_USB_DEV                 "/dev/ums0"
-+#endif
-+
- static const char *mouseDevs[] = {
-         DEFAULT_MOUSE_DEV,
-         DEFAULT_SYSMOUSE_DEV,
-         DEFAULT_PS2_DEV,
-+#if defined(FREEBSD_USB)
-+        DEFAULT_USB_DEV,
-+#endif
-         NULL
- };
- #elif (defined(__OpenBSD__) || defined(__NetBSD__)) && defined(WSCONS_SUPPORT)
-@@ -97,11 +175,23 @@ static const char *mouseDevs[] = {
- static int
- SupportedInterfaces(void)
- {
-+#if !defined(FREEBSD_USB)
-+
- #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__)
-     return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_AUTO | MSE_MISC;
- #else
-     return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO | MSE_MISC;
- #endif
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+#if defined(__NetBSD__)
-+    return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_AUTO | MSE_MISC;
-+#else
-+    return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO | MSE_MISC;
-+#endif
-+
-+#endif /* !defined(FREEBSD_USB) */
- }
- 
- /* Names of protocols that are handled internally here. */
-@@ -178,9 +268,34 @@ static struct {
-         { MOUSE_PROTO_SYSMOUSE,         "SysMouse" }
- };
- 
-+#if defined(FREEBSD_USB)
-+#ifdef XPS2_SUPPORT
-+static struct {
-+        int dmodel;
-+        const char *name;
-+} ps2proto[] = {
-+        { MOUSE_MODEL_NETSCROLL,        "NetScrollPS/2" },
-+        { MOUSE_MODEL_NET,              "NetMousePS/2" },
-+        { MOUSE_MODEL_GLIDEPOINT,       "GlidePointPS/2" },
-+        { MOUSE_MODEL_THINK,            "ThinkingMousePS/2" },
-+        { MOUSE_MODEL_INTELLI,          "IMPS/2" },
-+        { MOUSE_MODEL_MOUSEMANPLUS,     "MouseManPlusPS/2" },
-+        { MOUSE_MODEL_EXPLORER,         "ExplorerPS/2" },
-+        { MOUSE_MODEL_4D,               "IMPS/2" },
-+        { MOUSE_MODEL_4DPLUS,           "IMPS/2" },
-+};
-+#endif
-+#endif /* defined(FREEBSD_USB) */
-+
- static const char *
- SetupAuto(InputInfoPtr pInfo, int *protoPara)
- {
-+#if defined(FREEBSD_USB)
-+#ifdef XPS2_SUPPORT
-+    const char *dev;
-+#endif
-+    const char *proto;
-+#endif /* defined(FREEBSD_USB) */
-     int i;
-     mousehw_t hw;
-     mousemode_t mode;
-@@ -189,6 +304,14 @@ SetupAuto(InputInfoPtr pInfo, int *proto
-         return NULL;
- 
-     /* set the driver operation level, if applicable */
-+#if defined (FREEBSD_USB)
-+#ifdef XPS2_SUPPORT
-+    dev = xf86FindOptionValue(pInfo->options, "Device");
-+    if (dev != NULL && !strncmp(dev, DEFAULT_PS2_DEV, 8))
-+        i = 2;
-+    else
-+#endif
-+#endif /* defined(FREEBSD_USB) */
-     i = 1;
-     ioctl(pInfo->fd, MOUSE_SETLEVEL, &i);
- 
-@@ -207,9 +330,27 @@ SetupAuto(InputInfoPtr pInfo, int *proto
-                     protoPara[0] = mode.syncmask[0];
-                     protoPara[1] = mode.syncmask[1];
-                 }
-+#if defined(FREEBSD_USB)
-+                proto = devproto[i].name;
-+#ifdef XPS2_SUPPORT
-+                if (mode.protocol == MOUSE_PROTO_PS2)
-+                    for (i = 0; i < sizeof(ps2proto)/sizeof(ps2proto[0]); ++i)
-+                        if (hw.model == ps2proto[i].dmodel) {
-+                           proto = ps2proto[i].name;
-+                           break;
-+                }
-+#endif
-+#endif /* defined(FREEBSD_USB) */
-+
-+#if !defined(FREEBSD_USB)
-                 xf86MsgVerb(X_INFO, 3, "%s: SetupAuto: protocol is %s\n",
-                             pInfo->name, devproto[i].name);
-                 return devproto[i].name;
-+#else /* defined(FREEBSD_USB) */
-+                xf86MsgVerb(X_INFO, 3, "%s: SetupAuto: protocol is %s\n",
-+                            pInfo->name, proto);
-+                return proto;
-+#endif /* !defined(FREEBSD_USB) */
-             }
-         }
-     }
-@@ -227,6 +368,9 @@ SetSysMouseRes(InputInfoPtr pInfo, const
-     mode.rate = rate > 0 ? rate : -1;
-     mode.resolution = res > 0 ? res : -1;
-     mode.accelfactor = -1;
-+
-+#if !defined(FREEBSD_USB)
-+
- #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-     if (pMse->autoProbe ||
-         (protocol && xf86NameCmp(protocol, "SysMouse") == 0)) {
-@@ -241,13 +385,35 @@ SetSysMouseRes(InputInfoPtr pInfo, const
- #else
-     mode.level = -1;
- #endif
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-+    if (pMse->autoProbe ||
-+        (protocol && xf86NameCmp(protocol, "SysMouse") == 0)) {
-+        /*
-+         * As the FreeBSD sysmouse driver defaults to protocol level 0
-+         * everytime it is closed we enforce protocol level 1 again at
-+         * this point.
-+         */
-+        mode.level = 1;
-+    } else
-+#endif
-+    mode.level = -1;
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-     ioctl(pInfo->fd, MOUSE_SETMODE, &mode);
- }
- #endif
- 
- #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
- 
-+#if !defined(FREEBSD_USB)
- #define MOUSED_PID_FILE "/var/run/moused.pid"
-+#endif
-+
-+#if !defined(FREEBSD_USB)
- 
- /*
-  * Try to check if moused is running.  DEFAULT_SYSMOUSE_DEV is useless without
-@@ -271,20 +437,66 @@ MousedRunning(void)
-     return FALSE;
- }
- 
-+#else /* defined(FREEBSD_USB) */
-+
-+/*
-+ * Try to check if moused is running.  DEFAULT_SYSMOUSE_DEV is useless without
-+ * it.  Also, try to check if the device is used by moused.  If it is opened
-+ * by moused, we do not want to use it directly.  There doesn't seem to be
-+ * a better way of checking.
-+ */
-+static Bool
-+MousedRunning(const char *dev)
-+{
-+    char cmd[128];
-+    FILE *f = NULL;
-+    unsigned int i;
-+
-+    if (dev)
-+        sprintf(cmd, "sh -c 'fstat %s | grep -c moused' 2>/dev/null", dev);
-+    else
-+        sprintf(cmd, "sh -c 'pgrep -nx moused' 2>/dev/null");
-+    if ((f = popen(cmd, "r")) != NULL) {
-+        if (fscanf(f, "%u", &i) == 1 && i > 0) {
-+            pclose(f);
-+            return TRUE;
-+        }
-+        pclose(f);
-+    }
-+    return FALSE;
-+}
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
- static const char *
- FindDevice(InputInfoPtr pInfo, const char *protocol, int flags)
- {
-+#if !defined(FREEBSD_USB)
-     int fd = -1;
-+#else
-+    int ret = -1;
-+#endif
-     const char **pdev, *dev = NULL;
-     Bool devMouse = FALSE;
-     struct stat devMouseStat;
-     struct stat sb;
- 
-     for (pdev = mouseDevs; *pdev; pdev++) {
-+
-+#if !defined(FREEBSD_USB)
-         SYSCALL (fd = open(*pdev, O_RDWR | O_NONBLOCK));
-         if (fd == -1) {
-+#else
-+        SYSCALL (ret = stat(*pdev, &sb));
-+        if (ret == -1) {
-+#endif /* !defined(FREEBSD_USB) */
-+
- #ifdef DEBUG
-+#if !defined(FREEBSD_USB)
-             ErrorF("Cannot open %s (%s)\n", *pdev, strerror(errno));
-+#else
-+            ErrorF("Cannot stat %s (%s)\n", *pdev, strerror(errno));
-+#endif /* !defined(FREEBSD_USB) */
- #endif
-         } else {
-             /*
-@@ -293,28 +505,70 @@ FindDevice(InputInfoPtr pInfo, const cha
-              * the test for whether /dev/sysmouse is usable can be made.
-              */
-             if (!strcmp(*pdev, DEFAULT_MOUSE_DEV)) {
-+#if !defined(FREEBSD_USB)
-                 if (fstat(fd, &devMouseStat) == 0)
-                     devMouse = TRUE;
-                 close(fd);
-+#else
-+                memcpy(&devMouseStat, &sb, sizeof(devMouseStat));
-+                devMouse = TRUE;
-+#endif /* !defined(FREEBSD_USB) */
-                 continue;
-             } else if (!strcmp(*pdev, DEFAULT_SYSMOUSE_DEV)) {
-                 /* Check if /dev/mouse is the same as /dev/sysmouse. */
-+#if !defined(FREEBSD_USB)
-                 if (devMouse && fstat(fd, &sb) == 0 &&
-                     devMouseStat.st_dev == sb.st_dev &&
-                     devMouseStat.st_ino == sb.st_ino) {
-+#else
-+                if (devMouse && devMouseStat.st_dev == sb.st_dev &&
-+                    devMouseStat.st_ino == sb.st_ino) {
-+#endif /* !defined(FREEBSD_USB) */
-                     /* If the same, use /dev/sysmouse. */
-                     devMouse = FALSE;
-                 }
-+
-+#if !defined(FREEBSD_USB)
-                 close(fd);
-                 if (MousedRunning())
-+#else
-+                if (MousedRunning(NULL))
-+#endif /* !defined(FREEBSD_USB) */
-+
-                     break;
-+
-+#if !defined(FREEBSD_USB)
-                 else {
- #ifdef DEBUG
-                     ErrorF("moused isn't running\n");
- #endif
-                 }
-+#endif /* !defined(FREEBSD_USB) */
-+
-             } else {
-+
-+#if !defined(FREEBSD_USB)
-+
-                 close(fd);
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+                /* Check if /dev/mouse is the same as this device. */
-+                if (devMouse && devMouseStat.st_dev == sb.st_dev &&
-+                    devMouseStat.st_ino == sb.st_ino) {
-+                    /* If the same, use this device. */
-+                    devMouse = FALSE;
-+                }
-+                if (MousedRunning(*pdev))
-+                    continue;
-+                /* ums(4) does not support anything but SysMouse protocol. */
-+                if (!strncmp(*pdev, DEFAULT_USB_DEV, 8) && protocol &&
-+                    xf86NameCmp(protocol, "auto") != 0 &&
-+                    xf86NameCmp(protocol, "sysmouse") != 0)
-+                    continue;
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-                 break;
-             }
-         }
-@@ -486,8 +740,17 @@ wsconsPreInit(InputInfoPtr pInfo, const
- 
- #if defined(USBMOUSE_SUPPORT)
- 
-+#if defined(FREEBSD_USB)
-+#define MAXRIDS		64
-+#define MAXACOLS	8
-+#define MAXLCOLS	16
-+#endif
-+
- typedef struct _UsbMseRec {
-     int packetSize;
-+
-+#if !defined(FREEBSD_USB)
-+
-     int iid;
-     hid_item_t loc_x;           /* x locator item */
-     hid_item_t loc_y;           /* y locator item */
-@@ -495,22 +758,92 @@ typedef struct _UsbMseRec {
-     hid_item_t loc_w;           /* z (wheel) locator item */
-     hid_item_t loc_btn[MSE_MAXBUTTONS]; /* buttons locator items */
-    unsigned char *buffer;
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+    int iid, nrids, nacols, opened;
-+    struct {
-+	int32_t rid;
-+	int size;
-+    } rids[MAXRIDS];
-+    struct UsbMseAcol {
-+	InputInfoPtr pInfo;
-+	int nlcols, nbuttons, hasZ, hasW;
-+	int xmin, xmax, ymin, ymax, pmin, pmax, px, py;
-+	int cxmin, cxmax, cymin, cymax, cpmin, cpmax;
-+	struct UsbMseLcol {
-+	    hid_item_t loc_x;		/* x locator item */
-+	    hid_item_t loc_y;		/* y locator item */
-+	    hid_item_t loc_z;		/* z (wheel) locator item */
-+	    hid_item_t loc_w;		/* w (hwheel) locator item */
-+	    hid_item_t loc_p;		/* Tip Pressure */
-+	    hid_item_t loc_valid;		/* Touch Valid */
-+	    hid_item_t loc_in_range;	/* In Range */
-+	    hid_item_t loc_btn[MSE_MAXBUTTONS]; /* buttons locator items */
-+	} lcols[MAXLCOLS];
-+	hid_item_t loc_cc;		/* contact count */
-+    } acols[MAXACOLS];
-+    unsigned char *buffer;
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
- } UsbMseRec, *UsbMsePtr;
- 
-+#if defined(FREEBSD_USB)
-+static int *
-+usbGetReportSizePtr(UsbMsePtr pUsbMse, int32_t rid)
-+{
-+    int i;
-+
-+    for (i = 0; i < pUsbMse->nrids; i++) {
-+	if (pUsbMse->rids[i].rid == rid)
-+	    return (&pUsbMse->rids[i].size);
-+    }
-+    for (i = 0; i < MAXRIDS; i++) {
-+	if (pUsbMse->rids[i].size == 0) {
-+	    pUsbMse->rids[i].rid = rid;
-+	    pUsbMse->nrids = max(pUsbMse->nrids, i + 1);
-+	    return (&pUsbMse->rids[i].size);
-+	}
-+    }
-+    return (NULL);
-+}
-+#endif /* defined(FREEBSD_USB) */
-+
- static int
- usbMouseProc(DeviceIntPtr pPointer, int what)
- {
-     InputInfoPtr pInfo;
-     MouseDevPtr pMse;
-     UsbMsePtr pUsbMse;
-+#if defined(FREEBSD_USB)
-+    struct UsbMseAcol *acol;
-+#endif
-     unsigned char map[MSE_MAXBUTTONS + 1];
-+
-+#if !defined(FREEBSD_USB)
-     int nbuttons;
-+#else /* defined (FREEBSD_USB) */
-+    int nacol, nbuttons;
-+#ifdef HAVE_LABELS
-+    Atom btn_labels[MSE_MAXBUTTONS] = {0};
-+    Atom axes_labels[3] = { 0, 0, 0 };
-+#endif
-+#endif /* !defined(FREEBSD_USB) */
- 
-     pInfo = pPointer->public.devicePrivate;
-     pMse = pInfo->private;
-     pMse->device = pPointer;
-     pUsbMse = pMse->mousePriv;
- 
-+#if defined(FREEBSD_USB)
-+    for (nacol = 0; nacol < (pUsbMse->nacols - 1); nacol++) {
-+	if (pUsbMse->acols[nacol].pInfo == pInfo)
-+	    break;
-+    }
-+    acol = &pUsbMse->acols[nacol];
-+#endif
-+
-     switch (what) {
-     case DEVICE_INIT:
-         pPointer->public.on = FALSE;
-@@ -518,23 +851,114 @@ usbMouseProc(DeviceIntPtr pPointer, int
-         for (nbuttons = 0; nbuttons < MSE_MAXBUTTONS; ++nbuttons)
-             map[nbuttons + 1] = nbuttons + 1;
- 
-+#if !defined(FREEBSD_USB)
-         InitPointerDeviceStruct((DevicePtr)pPointer,
-                                 map,
-                                 min(pMse->buttons, MSE_MAXBUTTONS),
-                                 miPointerGetMotionEvents,
-                                 pMse->Ctrl,
-                                 miPointerGetMotionBufferSize());
-+#else /* defined(FREEBSD_USB) */
-+
-+#ifdef HAVE_LABELS
-+	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);
-+	axes_labels[0] = XIGetKnownProperty((acol->xmin != acol->xmax)
-+	    ? AXIS_LABEL_PROP_ABS_X : AXIS_LABEL_PROP_REL_X);
-+	axes_labels[1] = XIGetKnownProperty((acol->xmin != acol->xmax)
-+	    ? AXIS_LABEL_PROP_ABS_Y : AXIS_LABEL_PROP_REL_Y);
-+	axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
-+#endif
-+
-+	InitButtonClassDeviceStruct(pPointer, min(pMse->buttons, MSE_MAXBUTTONS),
-+#ifdef HAVE_LABELS
-+	    btn_labels,
-+#endif
-+	    map);
-+	InitValuatorClassDeviceStruct(pPointer, (acol->pmin != acol->pmax) ? 3 : 2,
-+#ifdef HAVE_LABELS
-+	    axes_labels,
-+#endif
-+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
-+	    miPointerGetMotionEvents,
-+#elif GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
-+	    GetMotionHistory,
-+#endif
-+	    GetMotionHistorySize(),
-+	    (acol->xmin != acol->xmax || acol->ymin != acol->ymax) ?
-+	     Absolute : Relative);
-+	InitPtrFeedbackClassDeviceStruct(pPointer, pMse->Ctrl);
-+
-+#endif /* !defined(FREEBSD_USB) */
- 
-         /* X valuator */
-+#if !defined(FREEBSD_USB)
-+
-         xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
-         xf86InitValuatorDefaults(pPointer, 0);
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+	xf86InitValuatorAxisStruct(pPointer, 0,
-+#ifdef HAVE_LABELS
-+	    axes_labels[0],
-+#endif
-+	    (acol->xmin != acol->xmax) ? acol->xmin : -1,
-+	    (acol->xmin != acol->xmax) ? acol->xmax : -1,
-+	    1, 0, 1
-+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
-+	    , (acol->xmin != acol->xmax) ? Absolute : Relative
-+#endif
-+	    );
-+        xf86InitValuatorDefaults(pPointer, 0);
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-         /* Y valuator */
-+
-+#if !defined(FREEBSD_USB)
-+
-         xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
-         xf86InitValuatorDefaults(pPointer, 1);
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+	xf86InitValuatorAxisStruct(pPointer, 1,
-+#ifdef HAVE_LABELS
-+	    axes_labels[1],
-+#endif
-+	    (acol->ymin != acol->ymax) ? acol->ymin : -1,
-+	    (acol->ymin != acol->ymax) ? acol->ymax : -1,
-+	    1, 0, 1
-+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
-+	    , (acol->ymin != acol->ymax) ? Absolute : Relative
-+#endif
-+	    );
-+        xf86InitValuatorDefaults(pPointer, 1);
-+	/* Pressure valuator */
-+	if (acol->pmin != acol->pmax) {
-+	    xf86InitValuatorAxisStruct(pPointer, 2,
-+#ifdef HAVE_LABELS
-+		axes_labels[2],
-+#endif
-+		acol->pmin, acol->pmax, 1, 0, 1
-+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
-+		, Absolute
-+#endif
-+		);
-+	    xf86InitValuatorDefaults(pPointer, 2);
-+	}
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-         xf86MotionHistoryAllocate(pInfo);
-         break;
- 
-     case DEVICE_ON:
-+
-+#if !defined(FREEBSD_USB)
-+
-         pInfo->fd = xf86OpenSerial(pInfo->options);
-         if (pInfo->fd == -1)
-             xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
-@@ -551,6 +975,30 @@ usbMouseProc(DeviceIntPtr pPointer, int
-                     AddEnabledDevice(pInfo->fd);
-             }
-         }
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+	if (pUsbMse->opened++ == 0) {
-+		pInfo->fd = xf86OpenSerial(pInfo->options);
-+		if (pInfo->fd == -1)
-+		    xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
-+		else {
-+		    pMse->buffer = XisbNew(pInfo->fd, pUsbMse->packetSize);
-+		    if (!pMse->buffer) {
-+			free(pMse);
-+			xf86CloseSerial(pInfo->fd);
-+			pInfo->fd = -1;
-+		    } else {
-+			xf86FlushInput(pInfo->fd);
-+			if (!xf86InstallSIGIOHandler (pInfo->fd, usbSigioReadInput, 
-+						      pInfo))
-+			    AddEnabledDevice(pInfo->fd);
-+		    }
-+		}
-+        }
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-         pMse->lastButtons = 0;
-         pMse->lastMappedButtons = 0;
-         pMse->emulateState = 0;
-@@ -571,6 +1019,9 @@ usbMouseProc(DeviceIntPtr pPointer, int
-             xf86CloseSerial(pInfo->fd);
-             pInfo->fd = -1;
-         }
-+#if defined(FREEBSD_USB)
-+        pUsbMse->opened--;
-+#endif
-         pPointer->public.on = FALSE;
-         usleep(300000);
-         break;
-@@ -586,27 +1037,86 @@ usbReadInput(InputInfoPtr pInfo)
- {
-     MouseDevPtr pMse;
-     UsbMsePtr pUsbMse;
-+
-+#if !defined(FREEBSD_USB)
-     int buttons = pMse->lastButtons;
-     int dx = 0, dy = 0, dz = 0, dw = 0;
-     int n, c;
-+#else
-+    int buttons, cc;
-+    int dx, dy, dz, dw, dp, upd, v, nx, ny, np, in_range;
-+    int n, c, rid, *sizep, nacol, nlcol;
-+#endif /* !defined(FREEBSD_USB) */
-+
-     unsigned char *pBuf;
- 
-+#if defined(FREEBSD_USB)
-+    struct UsbMseAcol *acol;
-+    struct UsbMseLcol *lcol;
-+#endif
-     pMse = pInfo->private;
-     pUsbMse = pMse->mousePriv;
- 
-     XisbBlockDuration(pMse->buffer, -1);
-+#if defined(FREEBSD_USB)
-+next:
-+#endif
-     pBuf = pUsbMse->buffer;
-     n = 0;
-+
-+#if !defined(FREEBSD_USB)
-+
-     while ((c = XisbRead(pMse->buffer)) >= 0 && n < pUsbMse->packetSize) {
-         pBuf[n++] = (unsigned char)c;
-+
-+    }
-+#else /* defined(FREEBSD_USB) */
-+
-+    if (pUsbMse->iid) {
-+	rid = XisbRead(pMse->buffer);
-+	if (rid < 0)
-+	    return;
-+	pBuf[n++] = (unsigned char)rid;
-+    } else
-+	rid = 0;
-+    sizep = usbGetReportSizePtr(pUsbMse, rid);
-+    if (sizep == NULL || *sizep == 0) {
-+	xf86Msg(X_WARNING, "%s: unknown report ID %d\n", pInfo->name, rid);
-+	goto next;
-     }
-+    while (n < *sizep && (c = XisbRead(pMse->buffer)) >= 0) {
-+        pBuf[n++] = (unsigned char)c;
-+    }
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-     if (n == 0)
-         return;
-+
-+#if !defined(FREEBSD_USB)
-+
-     if (n != pUsbMse->packetSize) {
-         LogMessageVerbSigSafe(X_WARNING, -1,
-                               "%s: incomplete packet, size %d\n",
-                               pInfo->name, n);
-     }
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+    if (n == 0)
-+        return;
-+//    xf86MsgVerb(X_INFO, 3, "pkt: %d %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
-+//	n, pBuf[0], pBuf[1], pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6], pBuf[7], pBuf[8], pBuf[9]);
-+    if (n != *sizep) {
-+        LogMessageVerbSigSafe(X_WARNING, -1,
-+                              "%s: incomplete packet, size %d\n",
-+                              pInfo->name, n);
-+    }
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-+#if !defined(FREEBSD_USB)
-+
-     /* discard packets with an id that don't match the mouse */
-     /* XXX this is probably not the right thing */
-     if (pUsbMse->iid != 0) {
-@@ -625,6 +1135,122 @@ usbReadInput(InputInfoPtr pInfo)
-     }
-     pMse->PostEvent(pInfo, buttons, dx, dy, dz, dw);
-     return;
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+    for (nacol = 0; nacol < pUsbMse->nacols; nacol++) {
-+	acol = &pUsbMse->acols[nacol];
-+	if (acol->pInfo == NULL)
-+	    continue;
-+	nx = ny = np = upd = 0;
-+	buttons = cc = 0;
-+	dx = dy = dz = dw = dp = 0;
-+	for (nlcol = 0; nlcol < pUsbMse->acols[nacol].nlcols; nlcol++) {
-+	    lcol = &acol->lcols[nlcol];
-+
-+	    if (lcol->loc_valid.usage != 0 && rid == lcol->loc_valid.report_ID &&
-+		    hid_get_data(pBuf, &lcol->loc_valid) == 0)
-+		continue;
-+	    if (lcol->loc_in_range.usage != 0 && rid == lcol->loc_in_range.report_ID)
-+		in_range = hid_get_data(pBuf, &lcol->loc_in_range);
-+	    else
-+		in_range = 1;
-+	    if (in_range && lcol->loc_x.usage != 0 && rid == lcol->loc_x.report_ID && nx == 0) {
-+		v = hid_get_data(pBuf, &lcol->loc_x);
-+		if (acol->xmin != acol->xmax) {
-+		    v = xf86ScaleAxis(v, acol->xmax, acol->xmin,
-+			lcol->loc_x.logical_maximum, lcol->loc_x.logical_minimum);
-+		    if (acol->cxmin != acol->cxmax)
-+		        v = xf86ScaleAxis(v, acol->xmax, acol->xmin,
-+			    acol->cxmax, acol->cxmin);
-+		}
-+		dx += v;
-+		nx++;
-+	    }
-+	    if (in_range && lcol->loc_y.usage != 0 && rid == lcol->loc_y.report_ID && ny == 0) {
-+		v = hid_get_data(pBuf, &lcol->loc_y);
-+		if (acol->xmin != acol->xmax) {
-+		    v = xf86ScaleAxis(v, acol->ymax, acol->ymin,
-+			lcol->loc_y.logical_maximum, lcol->loc_y.logical_minimum);
-+		    if (acol->cymin != acol->cymax)
-+		        v = xf86ScaleAxis(v, acol->ymax, acol->ymin,
-+			    acol->cymax, acol->cymin);
-+		}
-+		dy += v;
-+		ny++;
-+	    }
-+	    if (lcol->loc_z.usage != 0 && rid == lcol->loc_z.report_ID) {
-+		dz -= hid_get_data(pBuf, &lcol->loc_z);
-+		upd = 1;
-+	    }
-+	    if (lcol->loc_w.usage != 0 && rid == lcol->loc_w.report_ID) {
-+		dw += hid_get_data(pBuf, &lcol->loc_w);
-+		upd = 1;
-+	    }
-+	    if (lcol->loc_p.usage != 0 && rid == lcol->loc_p.report_ID && np == 0) {
-+		v = hid_get_data(pBuf, &lcol->loc_p);
-+		    v = xf86ScaleAxis(v, acol->pmax, acol->pmin,
-+			lcol->loc_p.logical_maximum, lcol->loc_p.logical_minimum);
-+		    if (acol->cpmin != acol->cpmax)
-+		        v = xf86ScaleAxis(v, acol->pmax, acol->pmin,
-+			    acol->cpmax, acol->cpmin);
-+		dp += v;
-+		np++;
-+	    }
-+
-+	    for (n = 0; n < acol->nbuttons; n++) {
-+		if (lcol->loc_btn[n].usage != 0 && rid == lcol->loc_btn[n].report_ID) {
-+		    if (hid_get_data(pBuf, &lcol->loc_btn[n]))
-+			buttons |= (1 << UMS_BUT(n));
-+		    upd = 1;
-+		}
-+	    }
-+	}
-+	if (acol->loc_cc.usage != 0 && rid == acol->loc_cc.report_ID)
-+	    cc = hid_get_data(pBuf, &acol->loc_cc);
-+	else
-+	    cc = (nx || ny) ? 1 : 0;
-+	if (cc > 1)
-+	    buttons = (1 << UMS_BUT(1));
-+	if (nx != 0 && acol->xmin != acol->xmax)
-+	    dx /= nx;
-+	if (ny != 0 && acol->ymin != acol->ymax)
-+	    dy /= ny;
-+	if (np != 0 && acol->pmin != acol->pmax)
-+	    dp /= np;
-+//	if (upd || nx || ny || np)
-+//	    xf86MsgVerb(X_INFO, 3, "%d cc %d dx %d dy %d dz %d dw %d press %d buttons %02x\n",
-+//		nacol, cc, dx, dy, dz, dw, dp, buttons);
-+	if (nx != 0 || ny != 0) {
-+	    if (acol->pmin != acol->pmax) {
-+		xf86PostMotionEvent(acol->pInfo->dev,
-+			    /* is_absolute: */    TRUE,
-+			    /* first_valuator: */ 0,
-+			    /* num_valuators: */  3,
-+			    dx, dy, dp);
-+	    } else if (acol->xmin != acol->xmax || acol->ymin != acol->ymax) {
-+		xf86PostMotionEvent(acol->pInfo->dev,
-+			    /* is_absolute: */    TRUE,
-+			    /* first_valuator: */ 0,
-+			    /* num_valuators: */  2,
-+			    dx, dy);
-+	    }
-+	}
-+	if (upd || (nx != 0) || (ny != 0)) {
-+	    ((MouseDevPtr)acol->pInfo->private)->PostEvent(acol->pInfo, buttons,
-+		((acol->xmin != acol->xmax) ? dx - acol->px : dx),
-+		((acol->ymin != acol->ymax) ? dy - acol->py : dy),
-+		dz, dw);
-+	}
-+	if (nx > 0)
-+	    acol->px = dx;
-+	if (ny > 0)
-+	    acol->py = dy;
-+    }
-+    goto next;
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
- }
- 
- static void
-@@ -633,15 +1259,27 @@ usbSigioReadInput (int fd, void *closure
-     usbReadInput ((InputInfoPtr) closure);
- }
- 
-+#if !defined(FREEBSD_USB)
- /* This function is called when the protocol is "usb". */
- static Bool
- usbPreInit(InputInfoPtr pInfo, const char *protocol, int flags)
-+#else
-+static Bool
-+usbInitFirst(InputInfoPtr pInfo)
-+#endif /* !defined(FREEBSD_USB) */
- {
-     MouseDevPtr pMse = pInfo->private;
-     UsbMsePtr pUsbMse;
-     report_desc_t reportDesc;
-+#if !defined(FREEBSD_USB)
-     int i;
--
-+#else
-+    hid_data_t d;
-+    hid_item_t h;
-+    struct UsbMseAcol *acol;
-+    struct UsbMseLcol *lcol;
-+    int mdepth, rsize, *rsizep, acolused, lcolused, used;
-+#endif /* !defined(FREEBSD_USB) */
-     pUsbMse = malloc(sizeof(UsbMseRec));
-     if (pUsbMse == NULL) {
-         xf86Msg(X_ERROR, "%s: cannot allocate UsbMouseRec\n", pInfo->name);
-@@ -649,12 +1287,16 @@ usbPreInit(InputInfoPtr pInfo, const cha
-         return FALSE;
-     }
- 
-+#if !defined(FREEBSD_USB)
-     pMse->protocol = protocol;
-     xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
- 
-     /* Collect the options, and process the common options. */
-     COLLECT_INPUT_OPTIONS(pInfo, NULL);
-     xf86ProcessCommonOptions(pInfo, pInfo->options);
-+#else
-+    bzero(pUsbMse, sizeof(UsbMseRec));
-+#endif /* !defined(FREEBSD_USB) */
- 
-     /* Check if the device can be opened. */
-     pInfo->fd = xf86OpenSerial(pInfo->options);
-@@ -670,6 +1312,9 @@ usbPreInit(InputInfoPtr pInfo, const cha
-     }
-     /* Get USB informations */
-     reportDesc = hid_get_report_desc(pInfo->fd);
-+
-+#if !defined(FREEBSD_USB)
-+
-     /* Get packet size & iid */
- #ifdef USB_NEW_HID
-     if (ioctl(pInfo->fd, USB_GET_REPORT_ID, &pUsbMse->iid) == -1) {
-@@ -683,6 +1328,139 @@ usbPreInit(InputInfoPtr pInfo, const cha
-     pUsbMse->packetSize = hid_report_size(reportDesc, hid_input,
-                                               &pUsbMse->iid);
- #endif
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+    mdepth = 0;
-+    pUsbMse->nacols = 0;
-+    acol = &pUsbMse->acols[pUsbMse->nacols];
-+    lcol = &acol->lcols[acol->nlcols];
-+    acolused = 0;
-+    lcolused = 0;
-+    d = hid_start_parse(reportDesc, (1 << hid_input) |
-+	(1 << hid_collection) | (1 << hid_endcollection), -1);
-+    while (hid_get_item(d, &h)) {
-+	switch (h.kind) {
-+	case hid_collection:
-+	    if (mdepth != 0)
-+		mdepth++;
-+	    else if (h.collection == 1 &&
-+		    (h.usage == 0x00010001 || h.usage == 0x00010002 ||
-+		     (h.usage >= 0x000d0001 && h.usage <= 0x000d000d))) {
-+		mdepth++;
-+		if (acolused) {
-+		    if (lcolused) {
-+			acol->nlcols++;
-+			lcolused = 0;
-+		    }
-+		    pUsbMse->nacols++;
-+		    acolused = 0;
-+		    acol = &pUsbMse->acols[pUsbMse->nacols];
-+		    lcol = &acol->lcols[acol->nlcols];
-+		}
-+	    }
-+	    if (lcolused && (h.collection == 0 ||
-+		    h.collection == 2 || h.collection == 3)) {
-+		acol->nlcols++;
-+		lcolused = 0;
-+		lcol = &acol->lcols[acol->nlcols];
-+	    }
-+	    break;
-+	case hid_endcollection:
-+	    if (mdepth != 0)
-+		mdepth--;
-+	    break;
-+	case hid_input:
-+	    if (h.report_ID != 0)
-+		pUsbMse->iid = 1;
-+	    rsize = pUsbMse->iid +
-+		(h.pos + (h.report_size * h.report_count) + 7) / 8;
-+	    if ((rsizep = usbGetReportSizePtr(pUsbMse, h.report_ID)) != NULL)
-+		*rsizep = max(*rsizep, rsize);
-+	    pUsbMse->packetSize = max(pUsbMse->packetSize, rsize);
-+	    if (mdepth == 0)
-+		break;
-+	    used = 1;
-+	    if (h.usage == 0x00010030) { /* X */
-+		lcol->loc_x = h;
-+		if ((h.flags & 0x04) == 0) {
-+		    if (acol->xmin == acol->xmax) {
-+			acol->xmin = h.logical_minimum;
-+			acol->xmax = h.logical_maximum;
-+		    } else {
-+			acol->xmin = min(acol->xmin, h.logical_minimum);
-+			acol->xmax = max(acol->xmax, h.logical_maximum);
-+		    }
-+		}
-+	    } else if (h.usage == 0x00010031) { /* Y */
-+		lcol->loc_y = h;
-+		if ((h.flags & 0x04) == 0) {
-+		    if (acol->ymin == acol->ymax) {
-+			acol->ymin = h.logical_minimum;
-+			acol->ymax = h.logical_maximum;
-+		    } else {
-+			acol->ymin = min(acol->ymin, h.logical_minimum);
-+			acol->ymax = max(acol->ymax, h.logical_maximum);
-+		    }
-+		}
-+	    } else if (h.usage == 0x00010038) { /* Z */
-+		lcol->loc_z = h;
-+		acol->hasZ = 1;
-+	    } else if (h.usage == 0x000c0238) { /* W */
-+		lcol->loc_w = h;
-+		acol->hasW = 1;
-+	    } else if (h.usage == 0x000d0030) { /* Press */
-+		lcol->loc_p = h;
-+		if ((h.flags & 0x04) == 0) {
-+		    if (acol->pmin == acol->pmax) {
-+			acol->pmin = h.logical_minimum;
-+			acol->pmax = h.logical_maximum;
-+		    } else {
-+			acol->pmin = min(acol->pmin, h.logical_minimum);
-+			acol->pmax = max(acol->pmax, h.logical_maximum);
-+		    }
-+		}
-+	    } else if (h.usage == 0x000d0032) /* In Range */
-+		lcol->loc_in_range = h;
-+	    else if (h.usage == 0x000d0047) /* Valid */
-+		lcol->loc_valid = h;
-+	    else if (h.usage > 0x00090000 &&
-+		h.usage <= 0x00090000 + MSE_MAXBUTTONS) { /* Buttons */
-+		    lcol->loc_btn[(h.usage & 0xffff) - 1] = h;
-+		    acol->nbuttons = max(acol->nbuttons, h.usage & 0xffff);
-+	    } else if (h.usage == 0x000d0042) { /* Tip Switch */
-+		lcol->loc_btn[0] = h;
-+		acol->nbuttons = max(acol->nbuttons, 1);
-+	    } else if (h.usage == 0x000d0044) { /* Barrel Switch */
-+		lcol->loc_btn[1] = h;
-+		acol->nbuttons = max(acol->nbuttons, 2);
-+	    } else if (h.usage == 0x000d0045) { /* Eraser */
-+		lcol->loc_btn[3] = h;
-+		acol->nbuttons = max(acol->nbuttons, 4);
-+	    } else if (h.usage == 0x000d0046) { /* Tablet Pick */
-+		lcol->loc_btn[2] = h;
-+		acol->nbuttons = max(acol->nbuttons, 3);
-+	    } else if (h.usage == 0x000d0054) /* Contact Count */
-+		acol->loc_cc = h;
-+	    else
-+		used = 0;
-+	    lcolused += used;
-+	    acolused += used;
-+	    break;
-+	default:
-+	    break;
-+	}
-+    }
-+    if (lcolused)
-+	acol->nlcols++;
-+    if (acolused)
-+	pUsbMse->nacols++;
-+    hid_end_parse(d);
-+    xf86Msg(X_DEFAULT, "%s: Found %d usable logical collections\n",
-+	pInfo->name, pUsbMse->nacols);
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-     /* Allocate buffer */
-     if (pUsbMse->packetSize <= 8) {
-         pUsbMse->buffer = pMse->protoBuf;
-@@ -692,10 +1470,15 @@ usbPreInit(InputInfoPtr pInfo, const cha
-     if (pUsbMse->buffer == NULL) {
-         xf86Msg(X_ERROR, "%s: cannot allocate buffer\n", pInfo->name);
-         free(pUsbMse);
-+#if !defined(FREEBSD_USB)
-         free(pMse);
-+#endif
-         xf86CloseSerial(pInfo->fd);
-         return FALSE;
-     }
-+
-+#if !defined(FREEBSD_USB)
-+
- #ifdef USB_NEW_HID
-     if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
-                    hid_input, &pUsbMse->loc_x, pUsbMse->iid) < 0) {
-@@ -733,12 +1516,15 @@ usbPreInit(InputInfoPtr pInfo, const cha
-     }
-     pMse->buttons = i-1;
- 
-+#endif /* !defined(FREEBSD_USB) */
-+
-     xf86CloseSerial(pInfo->fd);
-     pInfo->fd = -1;
- 
-     /* Private structure */
-     pMse->mousePriv = pUsbMse;
- 
-+#if !defined(FREEBSD_USB)
-     /* Process common mouse options (like Emulate3Buttons, etc). */
-     pMse->CommonOptions(pInfo);
- 
-@@ -749,8 +1535,137 @@ usbPreInit(InputInfoPtr pInfo, const cha
- #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
-     pInfo->flags |= XI86_CONFIGURED;
- #endif
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-     return TRUE;
- }
-+
-+#if defined(FREEBSD_USB)
-+
-+/* This function is called when the protocol is "usb". */
-+static Bool
-+usbPreInit(InputInfoPtr pInfo, const char *protocol, int flags)
-+{
-+    InputInfoPtr pMatch;
-+    MouseDevPtr pMse = pInfo->private;
-+    UsbMsePtr pUsbMse;
-+    struct UsbMseAcol *acol;
-+    char *str;
-+    int i, colopt;
-+
-+    pMse->protocol = protocol;
-+    xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
-+
-+    /* Collect the options, and process the common options. */
-+    COLLECT_INPUT_OPTIONS(pInfo, NULL);
-+    xf86ProcessCommonOptions(pInfo, pInfo->options);
-+
-+    /* Check if this HID device is already opened. */
-+    for (pMatch = xf86FirstLocalDevice(); pMatch != NULL; pMatch = pMatch->next) {
-+	if ((pInfo != pMatch) && strstr(pMatch->drv->driverName, "mouse")) {
-+	    char *dev1, *dev2;
-+
-+	    dev1 = xf86SetStrOption(pInfo->options, "Device", NULL);
-+	    dev2 = xf86SetStrOption(pMatch->options, "Device", NULL);
-+	    if (strcmp(dev1, dev2) == 0) {
-+		free(dev1);
-+		free(dev2);
-+		break;
-+	    }
-+	    free(dev1);
-+	    free(dev2);
-+	}
-+    }
-+    if (pMatch == NULL) {
-+	xf86Msg(X_DEFAULT, "%s: Opening new HID device\n", pInfo->name);
-+	if (!usbInitFirst(pInfo)) {
-+	    free(pMse);
-+	    return FALSE;
-+	}
-+    } else {
-+	pMse->mousePriv = ((MouseDevPtr)pMatch->private)->mousePriv;
-+	xf86Msg(X_DEFAULT, "%s: Attaching to already opened HID device\n",
-+	    pInfo->name);
-+    }
-+    pUsbMse = pMse->mousePriv;
-+
-+    /* Attach to collection, respecting "Collection" option. */
-+    colopt = xf86SetIntOption(pInfo->options, "Collection", 0);
-+    for (i = 0; i < pUsbMse->nacols; i++) {
-+	if (pUsbMse->acols[i].pInfo == NULL &&
-+		(colopt == 0 || i == colopt - 1)) {
-+	    pUsbMse->acols[i].pInfo = pInfo;
-+	    break;
-+	}
-+    }
-+    xf86Msg(colopt == 0 ? X_DEFAULT : X_CONFIG,
-+	"%s: Collection: %d\n", pInfo->name,
-+	i == pUsbMse->nacols ? colopt : i + 1);
-+    if (i == pUsbMse->nacols) {
-+	xf86Msg(X_ERROR,
-+	    "%s: Application collection not found or already handled\n",
-+	    pInfo->name);
-+	free(pMse);
-+	return FALSE;
-+    }
-+
-+    acol = &pUsbMse->acols[i];
-+    pMse->buttons = acol->nbuttons;
-+    if (pMse->buttons == 2)
-+	pMse->buttons = 3;
-+    if (acol->xmin != acol->xmax || acol->ymin != acol->ymax)
-+	pMse->disableXY = TRUE;
-+    pMse->hasZ = acol->hasZ;
-+    pMse->hasW = acol->hasW;
-+
-+    /* Process common mouse options (like Emulate3Buttons, etc). */
-+    pMse->CommonOptions(pInfo);
-+
-+    /* Process "Calibration" option. */
-+    str = xf86CheckStrOption(pInfo->options, "Calibration", NULL);
-+    if (str != NULL && (acol->xmin != acol->xmax || acol->ymin != acol->ymax)) {
-+	int j, xmin, xmax, ymin, ymax, pmin, pmax;
-+
-+	j = sscanf(str, "%d %d %d %d %d %d", &xmin, &xmax, &ymin, &ymax, &pmin, &pmax);
-+	if (j == 4) {
-+	    xf86Msg(X_CONFIG, "%s: Calibration: %d %d %d %d\n",
-+		pInfo->name, xmin, xmax, ymin, ymax);
-+	    acol->cxmin = xmin;
-+	    acol->cxmax = xmax;
-+	    acol->cymin = ymin;
-+	    acol->cymax = ymax;
-+	} else if (j == 6) {
-+	    xf86Msg(X_CONFIG, "%s: Calibration: %d %d %d %d %d %d\n",
-+		pInfo->name, xmin, xmax, ymin, ymax, pmin, pmax);
-+	    acol->cxmin = xmin;
-+	    acol->cxmax = xmax;
-+	    acol->cymin = ymin;
-+	    acol->cymax = ymax;
-+	    acol->cpmin = pmin;
-+	    acol->cpmax = pmax;
-+	} else
-+	    xf86Msg(X_WARNING, "%s: Calibration: Invalid arguments\n",
-+		pInfo->name);
-+	free(str);
-+    } else if (acol->xmin != acol->xmax || acol->ymin != acol->ymax) {
-+	xf86Msg(X_DEFAULT, "%s: Calibration: %d %d %d %d %d %d\n",
-+	    pInfo->name, acol->xmin, acol->xmax, acol->ymin, acol->ymax,
-+	    acol->pmin, acol->pmax);
-+    }
-+
-+    /* Setup the local procs. */
-+    pInfo->device_control = usbMouseProc;
-+    pInfo->read_input = usbReadInput;
-+
-+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
-+    pInfo->flags |= XI86_CONFIGURED;
-+#endif
-+    return TRUE;
-+}
-+
-+#endif /* defined(FREEBSD_USB) */
-+
- #endif /* USBMOUSE */
- 
- static Bool
-@@ -784,7 +1699,15 @@ OSMouseInit(int flags)
-     p->CheckProtocol = CheckProtocol;
- #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)) && defined(MOUSE_PROTO_SYSMOUSE)
-     p->SetupAuto = SetupAuto;
-+
-+#if !defined(FREEBSD_USB)
-+    p->SetPS2Res = SetSysMouseRes;
-+#else
-+#ifndef XPS2_SUPPORT
-     p->SetPS2Res = SetSysMouseRes;
-+#endif
-+#endif
-+
-     p->SetBMRes = SetSysMouseRes;
-     p->SetMiscRes = SetSysMouseRes;
- #endif
diff --git a/xf86-input-mouse-dfbsd/patches/patch-src_bsd__mouse.c b/xf86-input-mouse-dfbsd/patches/patch-src_bsd__mouse.c
index c0a89a49bf..0ff731eb5f 100644
--- a/xf86-input-mouse-dfbsd/patches/patch-src_bsd__mouse.c
+++ b/xf86-input-mouse-dfbsd/patches/patch-src_bsd__mouse.c
@@ -1,31 +1,13 @@
 $NetBSD$
 
-Patches from FreeBSD ports / DragonFly dports with include guards.
-Support for different versions of system libusb headers.
-Patches from FreeBSD ports svn commit: r431436
+Patches from FreeBSD ports / DragonFly dports x11-drivers/xf86-input-mouse 1.9.2.
 
---- src/bsd_mouse.c.orig	2015-04-20 01:07:33.000000000 +0000
+--- src/bsd_mouse.c.orig	2018-06-19 04:36:21.000000000 +0000
 +++ src/bsd_mouse.c
-@@ -26,6 +26,41 @@
+@@ -26,6 +26,23 @@
   * authorization from the copyright holder(s) and author(s).
   */
  
-+/* PKGSRC note: To support newer versions of DragonFly and FreeBSD,
-+ * this file is patched using DragonFly dports
-+ * x11-drivers/xf86-input-mouse/files/patch-src-bsd_mouse.c and
-+ * x11-drivers/xf86-input-mouse/dragonfly/patch-src_bsd__mouse.c
-+ * as of master commit 4f04bfe0ea83 ... Tue Jul 14 22:56:44 2015 -0700
-+ * The patch's code is enclosed in include defined(FREEBSD_USB) while the
-+ * original code is enclosed in include !defined(FREEBSD_USB).
-+ */
-+
-+/* DRAGONFLY_U4B is the usb system after OS version 300703
-+ * DRAGONFLY_USB is the usb system before OS version 300703
-+ * FREEBSD_USB must be defined if either DRAGONFLY_U4B or DRAGONFLY_USB are.
-+ */
-+
-+#if defined(FREEBSD_USB)
-+
 +/*
 + * XXX - Should this be autoconf'd instead?
 + */
@@ -42,24 +24,21 @@ Patches from FreeBSD ports svn commit: r431436
 +#endif
 +
 +#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
-+
-+#endif /* defined(FREEBSD_USB) */
 +
  #include <xorg-server.h>
  
  #include <X11/X.h>
-@@ -33,12 +68,33 @@
+@@ -33,9 +50,27 @@
  #include "xf86Priv.h"
  #include "xf86_OSlib.h"
  #include "xf86Xinput.h"
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +#include <exevents.h>
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  #include "mouse.h"
  #include "xisb.h"
  #include "mipointer.h"
-+
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
 +#define HAVE_PROPERTIES 1
 +#endif
@@ -73,88 +52,76 @@ Patches from FreeBSD ports svn commit: r431436
 +#undef HAVE_LABELS
 +#endif
 +#endif
-+#endif /* defined(FREEBSD_USB) */
-+
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  #ifdef WSCONS_SUPPORT
  #include <dev/wscons/wsconsio.h>
  #endif
-+
- #ifdef USBMOUSE_SUPPORT
- #ifdef HAS_LIB_USB_HID
- #include <usbhid.h>
-@@ -46,10 +102,25 @@
+@@ -46,10 +81,22 @@
  #include "usb.h"
  #endif
  
-+#if defined(FREEBSD_USB)
-+
-+#if defined(DRAGONFLY_U4B)
-+#include <sys/param.h>
-+#include <bus/u4b/usb.h>
-+#elif defined(DRAGONFLY_USB)
++#if defined(__DragonFly__)
 +#include <sys/param.h>
++#  if __DragonFly_version < 300703
 +#include <bus/usb/usb.h>
++#  else
++#include <bus/u4b/usb.h>
++#  endif
 +#else
  #include <dev/usb/usb.h>
 +#endif
 +
-+#endif /* defined(FREEBSD_USB) */
-+
-+#if !defined(FREEBSD_USB)
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
  #ifdef USB_GET_REPORT_ID
  #define USB_NEW_HID
  #endif
-+#endif /* !defined(FREEBSD_USB) */
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
  
  #define HUP_GENERIC_DESKTOP     0x0001
  #define HUP_BUTTON              0x0009
-@@ -76,10 +147,17 @@ static const char *FindDevice(InputInfoP
+@@ -66,8 +113,10 @@
+ #endif /* USBMOUSE_SUPPORT */
+ 
+ #ifdef USBMOUSE_SUPPORT
++#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 23
+ static void usbSigioReadInput (int fd, void *closure);
+ #endif
++#endif
+ static const char *FindDevice(InputInfoPtr, const char *, int);
+ 
+ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
+@@ -75,11 +124,17 @@ static const char *FindDevice(InputInfoP
+ #define DEFAULT_MOUSE_DEV               "/dev/mouse"
  #define DEFAULT_SYSMOUSE_DEV            "/dev/sysmouse"
  #define DEFAULT_PS2_DEV                 "/dev/psm0"
- 
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +#define DEFAULT_USB_DEV                 "/dev/ums0"
-+#endif
-+
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+ 
  static const char *mouseDevs[] = {
          DEFAULT_MOUSE_DEV,
          DEFAULT_SYSMOUSE_DEV,
          DEFAULT_PS2_DEV,
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +        DEFAULT_USB_DEV,
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
          NULL
  };
  #elif (defined(__OpenBSD__) || defined(__NetBSD__)) && defined(WSCONS_SUPPORT)
-@@ -97,11 +175,23 @@ static const char *mouseDevs[] = {
+@@ -97,7 +152,7 @@ static const char *mouseDevs[] = {
  static int
  SupportedInterfaces(void)
  {
-+#if !defined(FREEBSD_USB)
-+
- #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__)
+-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__)
++#if defined(__NetBSD__)
      return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_AUTO | MSE_MISC;
  #else
      return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO | MSE_MISC;
- #endif
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+#if defined(__NetBSD__)
-+    return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_AUTO | MSE_MISC;
-+#else
-+    return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO | MSE_MISC;
-+#endif
-+
-+#endif /* !defined(FREEBSD_USB) */
- }
- 
- /* Names of protocols that are handled internally here. */
-@@ -178,9 +268,34 @@ static struct {
+@@ -178,9 +233,35 @@ static struct {
          { MOUSE_PROTO_SYSMOUSE,         "SysMouse" }
  };
  
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +#ifdef XPS2_SUPPORT
 +static struct {
 +        int dmodel;
@@ -171,40 +138,42 @@ Patches from FreeBSD ports svn commit: r431436
 +        { MOUSE_MODEL_4DPLUS,           "IMPS/2" },
 +};
 +#endif
-+#endif /* defined(FREEBSD_USB) */
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
 +
  static const char *
  SetupAuto(InputInfoPtr pInfo, int *protoPara)
  {
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +#ifdef XPS2_SUPPORT
 +    const char *dev;
 +#endif
 +    const char *proto;
-+#endif /* defined(FREEBSD_USB) */
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
++
      int i;
      mousehw_t hw;
      mousemode_t mode;
-@@ -189,6 +304,14 @@ SetupAuto(InputInfoPtr pInfo, int *proto
+@@ -188,7 +269,15 @@ SetupAuto(InputInfoPtr pInfo, int *proto
+     if (pInfo->fd == -1)
          return NULL;
  
-     /* set the driver operation level, if applicable */
-+#if defined (FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +#ifdef XPS2_SUPPORT
+     /* set the driver operation level, if applicable */
 +    dev = xf86FindOptionValue(pInfo->options, "Device");
 +    if (dev != NULL && !strncmp(dev, DEFAULT_PS2_DEV, 8))
 +        i = 2;
 +    else
 +#endif
-+#endif /* defined(FREEBSD_USB) */
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      i = 1;
      ioctl(pInfo->fd, MOUSE_SETLEVEL, &i);
  
-@@ -207,9 +330,27 @@ SetupAuto(InputInfoPtr pInfo, int *proto
+@@ -207,9 +296,25 @@ SetupAuto(InputInfoPtr pInfo, int *proto
                      protoPara[0] = mode.syncmask[0];
                      protoPara[1] = mode.syncmask[1];
                  }
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +                proto = devproto[i].name;
 +#ifdef XPS2_SUPPORT
 +                if (mode.protocol == MOUSE_PROTO_PS2)
@@ -214,85 +183,63 @@ Patches from FreeBSD ports svn commit: r431436
 +                           break;
 +                }
 +#endif
-+#endif /* defined(FREEBSD_USB) */
-+
-+#if !defined(FREEBSD_USB)
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
                  xf86MsgVerb(X_INFO, 3, "%s: SetupAuto: protocol is %s\n",
-                             pInfo->name, devproto[i].name);
-                 return devproto[i].name;
-+#else /* defined(FREEBSD_USB) */
-+                xf86MsgVerb(X_INFO, 3, "%s: SetupAuto: protocol is %s\n",
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +                            pInfo->name, proto);
 +                return proto;
-+#endif /* !defined(FREEBSD_USB) */
++#else
+                             pInfo->name, devproto[i].name);
+                 return devproto[i].name;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
              }
          }
      }
-@@ -227,6 +368,9 @@ SetSysMouseRes(InputInfoPtr pInfo, const
-     mode.rate = rate > 0 ? rate : -1;
-     mode.resolution = res > 0 ? res : -1;
-     mode.accelfactor = -1;
-+
-+#if !defined(FREEBSD_USB)
-+
- #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-     if (pMse->autoProbe ||
+@@ -232,41 +337,41 @@ SetSysMouseRes(InputInfoPtr pInfo, const
          (protocol && xf86NameCmp(protocol, "SysMouse") == 0)) {
-@@ -241,13 +385,35 @@ SetSysMouseRes(InputInfoPtr pInfo, const
- #else
-     mode.level = -1;
- #endif
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-+    if (pMse->autoProbe ||
-+        (protocol && xf86NameCmp(protocol, "SysMouse") == 0)) {
-+        /*
-+         * As the FreeBSD sysmouse driver defaults to protocol level 0
+         /*
+          * As the FreeBSD sysmouse driver defaults to protocol level 0
+-         * everytime it is opened we enforce protocol level 1 again at
 +         * everytime it is closed we enforce protocol level 1 again at
-+         * this point.
-+         */
-+        mode.level = 1;
-+    } else
-+#endif
+          * this point.
+          */
+         mode.level = 1;
+     } else
+-        mode.level = -1;
+-#else
+-    mode.level = -1;
+ #endif
 +    mode.level = -1;
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
      ioctl(pInfo->fd, MOUSE_SETMODE, &mode);
  }
  #endif
  
  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
- 
-+#if !defined(FREEBSD_USB)
- #define MOUSED_PID_FILE "/var/run/moused.pid"
-+#endif
-+
-+#if !defined(FREEBSD_USB)
- 
+-
+-#define MOUSED_PID_FILE "/var/run/moused.pid"
+-
  /*
   * Try to check if moused is running.  DEFAULT_SYSMOUSE_DEV is useless without
-@@ -271,20 +437,66 @@ MousedRunning(void)
-     return FALSE;
- }
- 
-+#else /* defined(FREEBSD_USB) */
-+
-+/*
-+ * 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.
 + * it.  Also, try to check if the device is used by moused.  If it is opened
 + * by moused, we do not want to use it directly.  There doesn't seem to be
 + * a better way of checking.
-+ */
-+static Bool
+  */
+ static Bool
+-MousedRunning(void)
 +MousedRunning(const char *dev)
-+{
+ {
 +    char cmd[128];
-+    FILE *f = NULL;
+     FILE *f = NULL;
+-    unsigned int pid;
 +    unsigned int i;
-+
+ 
+-    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;
+-            }
 +    if (dev)
 +        sprintf(cmd, "sh -c 'fstat %s | grep -c moused' 2>/dev/null", dev);
 +    else
@@ -301,98 +248,64 @@ Patches from FreeBSD ports svn commit: r431436
 +        if (fscanf(f, "%u", &i) == 1 && i > 0) {
 +            pclose(f);
 +            return TRUE;
-+        }
+         }
+-        fclose(f);
 +        pclose(f);
-+    }
-+    return FALSE;
-+}
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
+     }
+     return FALSE;
+ }
+@@ -274,17 +379,17 @@ MousedRunning(void)
  static const char *
  FindDevice(InputInfoPtr pInfo, const char *protocol, int flags)
  {
-+#if !defined(FREEBSD_USB)
-     int fd = -1;
-+#else
+-    int fd = -1;
 +    int ret = -1;
-+#endif
      const char **pdev, *dev = NULL;
      Bool devMouse = FALSE;
      struct stat devMouseStat;
      struct stat sb;
  
      for (pdev = mouseDevs; *pdev; pdev++) {
-+
-+#if !defined(FREEBSD_USB)
-         SYSCALL (fd = open(*pdev, O_RDWR | O_NONBLOCK));
-         if (fd == -1) {
-+#else
+-        SYSCALL (fd = open(*pdev, O_RDWR | O_NONBLOCK));
+-        if (fd == -1) {
 +        SYSCALL (ret = stat(*pdev, &sb));
 +        if (ret == -1) {
-+#endif /* !defined(FREEBSD_USB) */
-+
  #ifdef DEBUG
-+#if !defined(FREEBSD_USB)
-             ErrorF("Cannot open %s (%s)\n", *pdev, strerror(errno));
-+#else
+-            ErrorF("Cannot open %s (%s)\n", *pdev, strerror(errno));
 +            ErrorF("Cannot stat %s (%s)\n", *pdev, strerror(errno));
-+#endif /* !defined(FREEBSD_USB) */
  #endif
          } else {
              /*
-@@ -293,28 +505,70 @@ FindDevice(InputInfoPtr pInfo, const cha
+@@ -293,28 +398,32 @@ FindDevice(InputInfoPtr pInfo, const cha
               * the test for whether /dev/sysmouse is usable can be made.
               */
              if (!strcmp(*pdev, DEFAULT_MOUSE_DEV)) {
-+#if !defined(FREEBSD_USB)
-                 if (fstat(fd, &devMouseStat) == 0)
-                     devMouse = TRUE;
-                 close(fd);
-+#else
+-                if (fstat(fd, &devMouseStat) == 0)
+-                    devMouse = TRUE;
+-                close(fd);
 +                memcpy(&devMouseStat, &sb, sizeof(devMouseStat));
 +                devMouse = TRUE;
-+#endif /* !defined(FREEBSD_USB) */
                  continue;
              } else if (!strcmp(*pdev, DEFAULT_SYSMOUSE_DEV)) {
                  /* Check if /dev/mouse is the same as /dev/sysmouse. */
-+#if !defined(FREEBSD_USB)
-                 if (devMouse && fstat(fd, &sb) == 0 &&
-                     devMouseStat.st_dev == sb.st_dev &&
-                     devMouseStat.st_ino == sb.st_ino) {
-+#else
+-                if (devMouse && fstat(fd, &sb) == 0 &&
+-                    devMouseStat.st_dev == sb.st_dev &&
 +                if (devMouse && devMouseStat.st_dev == sb.st_dev &&
-+                    devMouseStat.st_ino == sb.st_ino) {
-+#endif /* !defined(FREEBSD_USB) */
+                     devMouseStat.st_ino == sb.st_ino) {
                      /* If the same, use /dev/sysmouse. */
                      devMouse = FALSE;
                  }
-+
-+#if !defined(FREEBSD_USB)
-                 close(fd);
-                 if (MousedRunning())
-+#else
+-                close(fd);
+-                if (MousedRunning())
 +                if (MousedRunning(NULL))
-+#endif /* !defined(FREEBSD_USB) */
-+
                      break;
-+
-+#if !defined(FREEBSD_USB)
-                 else {
- #ifdef DEBUG
-                     ErrorF("moused isn't running\n");
- #endif
-                 }
-+#endif /* !defined(FREEBSD_USB) */
-+
+-                else {
+-#ifdef DEBUG
+-                    ErrorF("moused isn't running\n");
+-#endif
+-                }
              } else {
-+
-+#if !defined(FREEBSD_USB)
-+
-                 close(fd);
-+
-+#else /* defined(FREEBSD_USB) */
-+
+-                close(fd);
 +                /* Check if /dev/mouse is the same as this device. */
 +                if (devMouse && devMouseStat.st_dev == sb.st_dev &&
 +                    devMouseStat.st_ino == sb.st_ino) {
@@ -406,37 +319,22 @@ Patches from FreeBSD ports svn commit: r431436
 +                    xf86NameCmp(protocol, "auto") != 0 &&
 +                    xf86NameCmp(protocol, "sysmouse") != 0)
 +                    continue;
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
                  break;
              }
          }
-@@ -486,8 +740,17 @@ wsconsPreInit(InputInfoPtr pInfo, const
+@@ -486,8 +595,39 @@ wsconsPreInit(InputInfoPtr pInfo, const
  
  #if defined(USBMOUSE_SUPPORT)
  
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +#define MAXRIDS		64
 +#define MAXACOLS	8
 +#define MAXLCOLS	16
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
 +
  typedef struct _UsbMseRec {
      int packetSize;
-+
-+#if !defined(FREEBSD_USB)
-+
-     int iid;
-     hid_item_t loc_x;           /* x locator item */
-     hid_item_t loc_y;           /* y locator item */
-@@ -495,22 +758,92 @@ typedef struct _UsbMseRec {
-     hid_item_t loc_w;           /* z (wheel) locator item */
-     hid_item_t loc_btn[MSE_MAXBUTTONS]; /* buttons locator items */
-    unsigned char *buffer;
-+
-+#else /* defined(FREEBSD_USB) */
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    int iid, nrids, nacols, opened;
 +    struct {
 +	int32_t rid;
@@ -460,12 +358,18 @@ Patches from FreeBSD ports svn commit: r431436
 +	hid_item_t loc_cc;		/* contact count */
 +    } acols[MAXACOLS];
 +    unsigned char *buffer;
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
++#else
+     int iid;
+     hid_item_t loc_x;           /* x locator item */
+     hid_item_t loc_y;           /* y locator item */
+@@ -495,21 +635,61 @@ typedef struct _UsbMseRec {
+     hid_item_t loc_w;           /* z (wheel) locator item */
+     hid_item_t loc_btn[MSE_MAXBUTTONS]; /* buttons locator items */
+    unsigned char *buffer;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  } UsbMseRec, *UsbMsePtr;
  
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +static int *
 +usbGetReportSizePtr(UsbMsePtr pUsbMse, int32_t rid)
 +{
@@ -484,7 +388,7 @@ Patches from FreeBSD ports svn commit: r431436
 +    }
 +    return (NULL);
 +}
-+#endif /* defined(FREEBSD_USB) */
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
 +
  static int
  usbMouseProc(DeviceIntPtr pPointer, int what)
@@ -492,50 +396,39 @@ Patches from FreeBSD ports svn commit: r431436
      InputInfoPtr pInfo;
      MouseDevPtr pMse;
      UsbMsePtr pUsbMse;
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    struct UsbMseAcol *acol;
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      unsigned char map[MSE_MAXBUTTONS + 1];
-+
-+#if !defined(FREEBSD_USB)
-     int nbuttons;
-+#else /* defined (FREEBSD_USB) */
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    int nacol, nbuttons;
 +#ifdef HAVE_LABELS
 +    Atom btn_labels[MSE_MAXBUTTONS] = {0};
 +    Atom axes_labels[3] = { 0, 0, 0 };
 +#endif
-+#endif /* !defined(FREEBSD_USB) */
++#else
+     int nbuttons;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  
      pInfo = pPointer->public.devicePrivate;
      pMse = pInfo->private;
      pMse->device = pPointer;
      pUsbMse = pMse->mousePriv;
- 
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    for (nacol = 0; nacol < (pUsbMse->nacols - 1); nacol++) {
 +	if (pUsbMse->acols[nacol].pInfo == pInfo)
 +	    break;
 +    }
 +    acol = &pUsbMse->acols[nacol];
-+#endif
-+
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+ 
      switch (what) {
      case DEVICE_INIT:
-         pPointer->public.on = FALSE;
-@@ -518,23 +851,114 @@ usbMouseProc(DeviceIntPtr pPointer, int
+@@ -518,23 +698,120 @@ usbMouseProc(DeviceIntPtr pPointer, int
          for (nbuttons = 0; nbuttons < MSE_MAXBUTTONS; ++nbuttons)
              map[nbuttons + 1] = nbuttons + 1;
  
-+#if !defined(FREEBSD_USB)
-         InitPointerDeviceStruct((DevicePtr)pPointer,
-                                 map,
-                                 min(pMse->buttons, MSE_MAXBUTTONS),
-                                 miPointerGetMotionEvents,
-                                 pMse->Ctrl,
-                                 miPointerGetMotionBufferSize());
-+#else /* defined(FREEBSD_USB) */
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +#ifdef HAVE_LABELS
 +	btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
 +	btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
@@ -565,17 +458,17 @@ Patches from FreeBSD ports svn commit: r431436
 +	    (acol->xmin != acol->xmax || acol->ymin != acol->ymax) ?
 +	     Absolute : Relative);
 +	InitPtrFeedbackClassDeviceStruct(pPointer, pMse->Ctrl);
-+
-+#endif /* !defined(FREEBSD_USB) */
++#else
+         InitPointerDeviceStruct((DevicePtr)pPointer,
+                                 map,
+                                 min(pMse->buttons, MSE_MAXBUTTONS),
+                                 miPointerGetMotionEvents,
+                                 pMse->Ctrl,
+                                 miPointerGetMotionBufferSize());
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  
          /* X valuator */
-+#if !defined(FREEBSD_USB)
-+
-         xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
-         xf86InitValuatorDefaults(pPointer, 0);
-+
-+#else /* defined(FREEBSD_USB) */
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +	xf86InitValuatorAxisStruct(pPointer, 0,
 +#ifdef HAVE_LABELS
 +	    axes_labels[0],
@@ -587,19 +480,12 @@ Patches from FreeBSD ports svn commit: r431436
 +	    , (acol->xmin != acol->xmax) ? Absolute : Relative
 +#endif
 +	    );
-+        xf86InitValuatorDefaults(pPointer, 0);
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
++#else
+         xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+         xf86InitValuatorDefaults(pPointer, 0);
          /* Y valuator */
-+
-+#if !defined(FREEBSD_USB)
-+
-         xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
-         xf86InitValuatorDefaults(pPointer, 1);
-+
-+#else /* defined(FREEBSD_USB) */
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +	xf86InitValuatorAxisStruct(pPointer, 1,
 +#ifdef HAVE_LABELS
 +	    axes_labels[1],
@@ -611,7 +497,11 @@ Patches from FreeBSD ports svn commit: r431436
 +	    , (acol->ymin != acol->ymax) ? Absolute : Relative
 +#endif
 +	    );
-+        xf86InitValuatorDefaults(pPointer, 1);
++#else
+         xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+         xf86InitValuatorDefaults(pPointer, 1);
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +	/* Pressure valuator */
 +	if (acol->pmin != acol->pmax) {
 +	    xf86InitValuatorAxisStruct(pPointer, 2,
@@ -625,30 +515,12 @@ Patches from FreeBSD ports svn commit: r431436
 +		);
 +	    xf86InitValuatorDefaults(pPointer, 2);
 +	}
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
          xf86MotionHistoryAllocate(pInfo);
          break;
  
      case DEVICE_ON:
-+
-+#if !defined(FREEBSD_USB)
-+
-         pInfo->fd = xf86OpenSerial(pInfo->options);
-         if (pInfo->fd == -1)
-             xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
-@@ -548,9 +972,33 @@ usbMouseProc(DeviceIntPtr pPointer, int
-                 xf86FlushInput(pInfo->fd);
-                 if (!xf86InstallSIGIOHandler (pInfo->fd, usbSigioReadInput,
-                                               pInfo))
--                    AddEnabledDevice(pInfo->fd);
-+                    xf86AddEnabledDevice(pInfo);
-             }
-         }
-+
-+#else /* defined(FREEBSD_USB) */
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +	if (pUsbMse->opened++ == 0) {
 +		pInfo->fd = xf86OpenSerial(pInfo->options);
 +		if (pInfo->fd == -1)
@@ -661,76 +533,77 @@ Patches from FreeBSD ports svn commit: r431436
 +			pInfo->fd = -1;
 +		    } else {
 +			xf86FlushInput(pInfo->fd);
++#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 23
 +			if (!xf86InstallSIGIOHandler (pInfo->fd, usbSigioReadInput, 
 +						      pInfo))
-+			    xf86AddEnabledDevice(pInfo);
++#endif
++                            xf86AddEnabledDevice(pInfo);
 +		    }
 +		}
-+        }
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
++         }
++#else
+         pInfo->fd = xf86OpenSerial(pInfo->options);
+         if (pInfo->fd == -1)
+             xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+@@ -553,6 +830,7 @@ usbMouseProc(DeviceIntPtr pPointer, int
+                     AddEnabledDevice(pInfo->fd);
+             }
+         }
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
          pMse->lastButtons = 0;
          pMse->lastMappedButtons = 0;
          pMse->emulateState = 0;
-@@ -560,7 +1008,7 @@ usbMouseProc(DeviceIntPtr pPointer, int
+@@ -562,7 +840,11 @@ usbMouseProc(DeviceIntPtr pPointer, int
      case DEVICE_OFF:
      case DEVICE_CLOSE:
          if (pInfo->fd != -1) {
--            RemoveEnabledDevice(pInfo->fd);
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +            xf86RemoveEnabledDevice(pInfo);
++#else
+             RemoveEnabledDevice(pInfo->fd);
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
              if (pUsbMse->packetSize > 8 && pUsbMse->buffer) {
                  free(pUsbMse->buffer);
              }
-@@ -571,6 +1019,9 @@ usbMouseProc(DeviceIntPtr pPointer, int
+@@ -573,6 +855,9 @@ usbMouseProc(DeviceIntPtr pPointer, int
              xf86CloseSerial(pInfo->fd);
              pInfo->fd = -1;
          }
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +        pUsbMse->opened--;
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
          pPointer->public.on = FALSE;
          usleep(300000);
          break;
-@@ -586,27 +1037,86 @@ usbReadInput(InputInfoPtr pInfo)
+@@ -588,27 +873,73 @@ usbReadInput(InputInfoPtr pInfo)
  {
      MouseDevPtr pMse;
      UsbMsePtr pUsbMse;
-+
-+#if !defined(FREEBSD_USB)
-     int buttons = pMse->lastButtons;
-     int dx = 0, dy = 0, dz = 0, dw = 0;
-     int n, c;
-+#else
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    int buttons, cc;
 +    int dx, dy, dz, dw, dp, upd, v, nx, ny, np, in_range;
 +    int n, c, rid, *sizep, nacol, nlcol;
-+#endif /* !defined(FREEBSD_USB) */
-+
++#else
+     int buttons = pMse->lastButtons;
+     int dx = 0, dy = 0, dz = 0, dw = 0;
+     int n, c;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      unsigned char *pBuf;
- 
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    struct UsbMseAcol *acol;
 +    struct UsbMseLcol *lcol;
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+ 
      pMse = pInfo->private;
      pUsbMse = pMse->mousePriv;
  
      XisbBlockDuration(pMse->buffer, -1);
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +next:
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      pBuf = pUsbMse->buffer;
      n = 0;
-+
-+#if !defined(FREEBSD_USB)
-+
-     while ((c = XisbRead(pMse->buffer)) >= 0 && n < pUsbMse->packetSize) {
-         pBuf[n++] = (unsigned char)c;
-+
-+    }
-+#else /* defined(FREEBSD_USB) */
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    if (pUsbMse->iid) {
 +	rid = XisbRead(pMse->buffer);
 +	if (rid < 0)
@@ -742,50 +615,27 @@ Patches from FreeBSD ports svn commit: r431436
 +    if (sizep == NULL || *sizep == 0) {
 +	xf86Msg(X_WARNING, "%s: unknown report ID %d\n", pInfo->name, rid);
 +	goto next;
-     }
-+    while (n < *sizep && (c = XisbRead(pMse->buffer)) >= 0) {
-+        pBuf[n++] = (unsigned char)c;
 +    }
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
++    while (n < *sizep && (c = XisbRead(pMse->buffer)) >= 0) {
++#else
+     while ((c = XisbRead(pMse->buffer)) >= 0 && n < pUsbMse->packetSize) {
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+         pBuf[n++] = (unsigned char)c;
+     }
      if (n == 0)
          return;
-+
-+#if !defined(FREEBSD_USB)
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++//    xf86MsgVerb(X_INFO, 3, "pkt: %d %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
++//	n, pBuf[0], pBuf[1], pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6], pBuf[7], pBuf[8], pBuf[9]);
++    if (n != *sizep) {
++#else
      if (n != pUsbMse->packetSize) {
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
          LogMessageVerbSigSafe(X_WARNING, -1,
                                "%s: incomplete packet, size %d\n",
                                pInfo->name, n);
      }
-+
-+#else /* defined(FREEBSD_USB) */
-+
-+    if (n == 0)
-+        return;
-+//    xf86MsgVerb(X_INFO, 3, "pkt: %d %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
-+//	n, pBuf[0], pBuf[1], pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6], pBuf[7], pBuf[8], pBuf[9]);
-+    if (n != *sizep) {
-+        LogMessageVerbSigSafe(X_WARNING, -1,
-+                              "%s: incomplete packet, size %d\n",
-+                              pInfo->name, n);
-+    }
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-+#if !defined(FREEBSD_USB)
-+
-     /* discard packets with an id that don't match the mouse */
-     /* XXX this is probably not the right thing */
-     if (pUsbMse->iid != 0) {
-@@ -625,6 +1135,122 @@ usbReadInput(InputInfoPtr pInfo)
-     }
-     pMse->PostEvent(pInfo, buttons, dx, dy, dz, dw);
-     return;
-+
-+#else /* defined(FREEBSD_USB) */
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    for (nacol = 0; nacol < pUsbMse->nacols; nacol++) {
 +	acol = &pUsbMse->acols[nacol];
 +	if (acol->pInfo == NULL)
@@ -795,7 +645,17 @@ Patches from FreeBSD ports svn commit: r431436
 +	dx = dy = dz = dw = dp = 0;
 +	for (nlcol = 0; nlcol < pUsbMse->acols[nacol].nlcols; nlcol++) {
 +	    lcol = &acol->lcols[nlcol];
-+
++#else
+     /* discard packets with an id that don't match the mouse */
+     /* XXX this is probably not the right thing */
+     if (pUsbMse->iid != 0) {
+@@ -619,30 +950,152 @@ usbReadInput(InputInfoPtr pInfo)
+     dy = hid_get_data(pBuf, &pUsbMse->loc_y);
+     dz = hid_get_data(pBuf, &pUsbMse->loc_z);
+     dw = hid_get_data(pBuf, &pUsbMse->loc_w);
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +	    if (lcol->loc_valid.usage != 0 && rid == lcol->loc_valid.report_ID &&
 +		    hid_get_data(pBuf, &lcol->loc_valid) == 0)
 +		continue;
@@ -894,77 +754,76 @@ Patches from FreeBSD ports svn commit: r431436
 +	    acol->px = dx;
 +	if (ny > 0)
 +	    acol->py = dy;
-+    }
++#else
+     buttons = 0;
+     for (n = 0; n < pMse->buttons; n++) {
+         if (hid_get_data(pBuf, &pUsbMse->loc_btn[n]))
+             buttons |= (1 << UMS_BUT(n));
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+     }
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    goto next;
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
++#else
+     pMse->PostEvent(pInfo, buttons, dx, dy, dz, dw);
+     return;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  }
  
++#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 23
  static void
-@@ -633,15 +1259,27 @@ usbSigioReadInput (int fd, void *closure
+ usbSigioReadInput (int fd, void *closure)
+ {
      usbReadInput ((InputInfoPtr) closure);
  }
++#endif
  
-+#if !defined(FREEBSD_USB)
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
  /* This function is called when the protocol is "usb". */
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
  static Bool
- usbPreInit(InputInfoPtr pInfo, const char *protocol, int flags)
-+#else
-+static Bool
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +usbInitFirst(InputInfoPtr pInfo)
-+#endif /* !defined(FREEBSD_USB) */
++#else
+ usbPreInit(InputInfoPtr pInfo, const char *protocol, int flags)
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  {
      MouseDevPtr pMse = pInfo->private;
      UsbMsePtr pUsbMse;
      report_desc_t reportDesc;
-+#if !defined(FREEBSD_USB)
-     int i;
--
-+#else
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    hid_data_t d;
 +    hid_item_t h;
 +    struct UsbMseAcol *acol;
 +    struct UsbMseLcol *lcol;
 +    int mdepth, rsize, *rsizep, acolused, lcolused, used;
-+#endif /* !defined(FREEBSD_USB) */
++#else
+     int i;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+ 
      pUsbMse = malloc(sizeof(UsbMseRec));
      if (pUsbMse == NULL) {
-         xf86Msg(X_ERROR, "%s: cannot allocate UsbMouseRec\n", pInfo->name);
-@@ -649,12 +1287,16 @@ usbPreInit(InputInfoPtr pInfo, const cha
+@@ -651,12 +1104,16 @@ usbPreInit(InputInfoPtr pInfo, const cha
          return FALSE;
      }
  
-+#if !defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    bzero(pUsbMse, sizeof(UsbMseRec));
++#else
      pMse->protocol = protocol;
      xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
  
      /* Collect the options, and process the common options. */
      COLLECT_INPUT_OPTIONS(pInfo, NULL);
      xf86ProcessCommonOptions(pInfo, pInfo->options);
-+#else
-+    bzero(pUsbMse, sizeof(UsbMseRec));
-+#endif /* !defined(FREEBSD_USB) */
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  
      /* Check if the device can be opened. */
      pInfo->fd = xf86OpenSerial(pInfo->options);
-@@ -670,6 +1312,9 @@ usbPreInit(InputInfoPtr pInfo, const cha
+@@ -672,6 +1129,128 @@ usbPreInit(InputInfoPtr pInfo, const cha
      }
      /* Get USB informations */
      reportDesc = hid_get_report_desc(pInfo->fd);
-+
-+#if !defined(FREEBSD_USB)
-+
-     /* Get packet size & iid */
- #ifdef USB_NEW_HID
-     if (ioctl(pInfo->fd, USB_GET_REPORT_ID, &pUsbMse->iid) == -1) {
-@@ -683,6 +1328,139 @@ usbPreInit(InputInfoPtr pInfo, const cha
-     pUsbMse->packetSize = hid_report_size(reportDesc, hid_input,
-                                               &pUsbMse->iid);
- #endif
-+
-+#else /* defined(FREEBSD_USB) */
-+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    mdepth = 0;
 +    pUsbMse->nacols = 0;
 +    acol = &pUsbMse->acols[pUsbMse->nacols];
@@ -1084,7 +943,18 @@ Patches from FreeBSD ports svn commit: r431436
 +	default:
 +	    break;
 +	}
-+    }
++     }
++#else
+     /* Get packet size & iid */
+ #ifdef USB_NEW_HID
+     if (ioctl(pInfo->fd, USB_GET_REPORT_ID, &pUsbMse->iid) == -1) {
+@@ -685,6 +1264,18 @@ usbPreInit(InputInfoPtr pInfo, const cha
+     pUsbMse->packetSize = hid_report_size(reportDesc, hid_input,
+                                               &pUsbMse->iid);
+ #endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
++
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    if (lcolused)
 +	acol->nlcols++;
 +    if (acolused)
@@ -1092,55 +962,39 @@ Patches from FreeBSD ports svn commit: r431436
 +    hid_end_parse(d);
 +    xf86Msg(X_DEFAULT, "%s: Found %d usable logical collections\n",
 +	pInfo->name, pUsbMse->nacols);
-+
-+#endif /* !defined(FREEBSD_USB) */
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
 +
      /* Allocate buffer */
      if (pUsbMse->packetSize <= 8) {
          pUsbMse->buffer = pMse->protoBuf;
-@@ -692,10 +1470,15 @@ usbPreInit(InputInfoPtr pInfo, const cha
+@@ -694,10 +1285,13 @@ usbPreInit(InputInfoPtr pInfo, const cha
      if (pUsbMse->buffer == NULL) {
          xf86Msg(X_ERROR, "%s: cannot allocate buffer\n", pInfo->name);
          free(pUsbMse);
-+#if !defined(FREEBSD_USB)
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
          free(pMse);
-+#endif
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
          xf86CloseSerial(pInfo->fd);
          return FALSE;
      }
-+
-+#if !defined(FREEBSD_USB)
-+
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
  #ifdef USB_NEW_HID
      if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
                     hid_input, &pUsbMse->loc_x, pUsbMse->iid) < 0) {
-@@ -733,12 +1516,15 @@ usbPreInit(InputInfoPtr pInfo, const cha
+@@ -734,16 +1328,131 @@ usbPreInit(InputInfoPtr pInfo, const cha
+             break;
      }
      pMse->buttons = i-1;
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
  
-+#endif /* !defined(FREEBSD_USB) */
-+
      xf86CloseSerial(pInfo->fd);
      pInfo->fd = -1;
  
      /* Private structure */
      pMse->mousePriv = pUsbMse;
- 
-+#if !defined(FREEBSD_USB)
-     /* Process common mouse options (like Emulate3Buttons, etc). */
-     pMse->CommonOptions(pInfo);
- 
-@@ -749,8 +1535,137 @@ usbPreInit(InputInfoPtr pInfo, const cha
- #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
-     pInfo->flags |= XI86_CONFIGURED;
- #endif
-+
-+#endif /* !defined(FREEBSD_USB) */
-+
-     return TRUE;
- }
-+
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    return TRUE;
++}
 +
 +/* This function is called when the protocol is "usb". */
 +static Bool
@@ -1217,10 +1071,12 @@ Patches from FreeBSD ports svn commit: r431436
 +	pMse->disableXY = TRUE;
 +    pMse->hasZ = acol->hasZ;
 +    pMse->hasW = acol->hasW;
-+
-+    /* Process common mouse options (like Emulate3Buttons, etc). */
-+    pMse->CommonOptions(pInfo);
-+
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+ 
+     /* Process common mouse options (like Emulate3Buttons, etc). */
+     pMse->CommonOptions(pInfo);
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    /* Process "Calibration" option. */
 +    str = xf86CheckStrOption(pInfo->options, "Calibration", NULL);
 +    if (str != NULL && (acol->xmin != acol->xmax || acol->ymin != acol->ymax)) {
@@ -1252,35 +1108,18 @@ Patches from FreeBSD ports svn commit: r431436
 +	    pInfo->name, acol->xmin, acol->xmax, acol->ymin, acol->ymax,
 +	    acol->pmin, acol->pmax);
 +    }
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
 +
-+    /* Setup the local procs. */
-+    pInfo->device_control = usbMouseProc;
-+    pInfo->read_input = usbReadInput;
-+
-+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
-+    pInfo->flags |= XI86_CONFIGURED;
-+#endif
-+    return TRUE;
-+}
-+
-+#endif /* defined(FREEBSD_USB) */
-+
- #endif /* USBMOUSE */
- 
- static Bool
-@@ -784,7 +1699,15 @@ OSMouseInit(int flags)
+     /* Setup the local procs. */
+     pInfo->device_control = usbMouseProc;
+     pInfo->read_input = usbReadInput;
+@@ -786,7 +1495,9 @@ OSMouseInit(int flags)
      p->CheckProtocol = CheckProtocol;
  #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)) && defined(MOUSE_PROTO_SYSMOUSE)
      p->SetupAuto = SetupAuto;
-+
-+#if !defined(FREEBSD_USB)
-+    p->SetPS2Res = SetSysMouseRes;
-+#else
 +#ifndef XPS2_SUPPORT
      p->SetPS2Res = SetSysMouseRes;
 +#endif
-+#endif
-+
      p->SetBMRes = SetSysMouseRes;
      p->SetMiscRes = SetSysMouseRes;
  #endif
diff --git a/xf86-input-mouse-dfbsd/patches/patch-src_mouse.c b/xf86-input-mouse-dfbsd/patches/patch-src_mouse.c
index f45f0f72e2..14ac4e3a81 100644
--- a/xf86-input-mouse-dfbsd/patches/patch-src_mouse.c
+++ b/xf86-input-mouse-dfbsd/patches/patch-src_mouse.c
@@ -1,42 +1,27 @@
 $NetBSD$
 
-Patches from FreeBSD ports / DragonFly dports with include guards.
-Support for different versions of system libusb headers.
+Patches from FreeBSD ports / DragonFly dports x11-drivers/xf86-input-mouse 1.9.2.
 
---- src/mouse.c.orig	2016-09-06 03:53:31.000000000 +0000
+--- src/mouse.c.orig	2018-06-19 04:36:21.000000000 +0000
 +++ src/mouse.c
-@@ -43,6 +43,13 @@
-  * and to help limited dexterity persons
-  */
- 
-+/* PKGSRC note: To support newer versions of DragonFly and FreeBSD,
-+ * this file is patched using DragonFly dports
-+ * x11-drivers/xf86-input-mouse/files/patch-src_mouse.c
-+ * as of master commit 4f04bfe0ea83 ... Tue Jul 14 22:56:44 2015 -0700
-+ * The patch's code is enclosed in include defined(FREEBSD_USB) while the
-+ * original code is enclosed in include !defined(FREEBSD_USB).
-+ */
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
-@@ -304,13 +311,45 @@ MouseCommonOptions(InputInfoPtr pInfo)
+@@ -304,13 +304,45 @@ MouseCommonOptions(InputInfoPtr pInfo)
  
      pMse = pInfo->private;
  
-+#if !defined(FREEBSD_USB)
-     pMse->buttons = xf86SetIntOption(pInfo->options, "Buttons", 0);
-+#else
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    i = xf86SetIntOption(pInfo->options, "Buttons", 0);
 +    if (i != 0)
 +        pMse->buttons = i;
-+#endif
++#else
+     pMse->buttons = xf86SetIntOption(pInfo->options, "Buttons", 0);
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      if (!pMse->buttons) {
          pMse->buttons = MSE_DFLTBUTTONS;
          buttons_from = X_DEFAULT;
      }
      origButtons = pMse->buttons;
  
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    s = xf86SetStrOption(pInfo->options, "ButtonMapping", NULL);
 +    if (s) {
 +        int b, n = 0;
@@ -60,168 +45,177 @@ Support for different versions of system libusb headers.
 +        if (f > pMse->buttons)
 +            pMse->buttons = f;
 +    }
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
 +
      pMse->emulate3Buttons = xf86SetBoolOption(pInfo->options,
                                                "Emulate3Buttons", FALSE);
      if (!xf86FindOptionValue(pInfo->options,"Emulate3Buttons")) {
-@@ -322,6 +361,10 @@ MouseCommonOptions(InputInfoPtr pInfo)
+@@ -322,6 +354,10 @@ MouseCommonOptions(InputInfoPtr pInfo)
                                               "Emulate3Timeout", 50);
      if (pMse->emulate3Buttons || pMse->emulate3ButtonsSoft) {
          MessageType from = X_CONFIG;
-+#if defined(FREEBSD_USB)
-+       if (pMse->buttons < 3)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++	if (pMse->buttons < 3)
 +            pMse->buttons = 3;
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
          if (pMse->emulate3ButtonsSoft)
              from = X_DEFAULT;
          xf86Msg(from, "%s: Emulate3Buttons, Emulate3Timeout: %d\n",
-@@ -329,6 +372,10 @@ MouseCommonOptions(InputInfoPtr pInfo)
+@@ -329,6 +365,10 @@ MouseCommonOptions(InputInfoPtr pInfo)
      }
  
      pMse->chordMiddle = xf86SetBoolOption(pInfo->options, "ChordMiddle", FALSE);
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    if (pMse->chordMiddle && pMse->buttons < 3)
-+           pMse->buttons = 3;
-+#endif
++	    pMse->buttons = 3;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      pMse->flipXY = xf86SetBoolOption(pInfo->options, "FlipXY", FALSE);
      if (xf86SetBoolOption(pInfo->options, "InvX", FALSE)) {
          pMse->invX = -1;
-@@ -339,7 +386,9 @@ MouseCommonOptions(InputInfoPtr pInfo)
+@@ -339,7 +379,9 @@ MouseCommonOptions(InputInfoPtr pInfo)
      } else
          pMse->invY = 1;
      pMse->angleOffset = xf86SetIntOption(pInfo->options, "AngleOffset", 0);
 -
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    pMse->sensitivity = xf86SetRealOption(pInfo->options, "Sensitivity", 1.0);
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  
      if (pMse->pDragLock)
          free(pMse->pDragLock);
-@@ -449,14 +498,25 @@ MouseCommonOptions(InputInfoPtr pInfo)
+@@ -449,14 +491,25 @@ MouseCommonOptions(InputInfoPtr pInfo)
          free(s);
      }
  
-+#if !defined(FREEBSD_USB)
-     s = xf86SetStrOption(pInfo->options, "ZAxisMapping", "4 5");
-+#else
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    s = xf86SetStrOption(pInfo->options, "ZAxisMapping",
 +        pMse->hasZ ? ( pMse->hasW ? "4 5 6 7" : "4 5" ) : "off");
-+#endif
++#else
+     s = xf86SetStrOption(pInfo->options, "ZAxisMapping", "4 5");
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      if (s) {
          int b1 = 0, b2 = 0, b3 = 0, b4 = 0;
          char *msg = NULL;
  
          pMse->negativeZ = pMse->positiveZ = MSE_NOAXISMAP;
          pMse->negativeW = pMse->positiveW = MSE_NOAXISMAP;
-+#if !defined(FREEBSD_USB)
-         if (!xf86NameCmp(s, "x")) {
-+#else
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +        if (!xf86NameCmp(s, "off")) {
 +            msg = xstrdup("off");
-+        } else if (!xf86NameCmp(s, "x")) {
-+#endif
++	} else if (!xf86NameCmp(s, "x")) {
++#else
+         if (!xf86NameCmp(s, "x")) {
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
              pMse->negativeZ = pMse->positiveZ = MSE_MAPTOX;
              msg = xstrdup("X axis");
          } else if (!xf86NameCmp(s, "y")) {
-@@ -605,6 +665,7 @@ MouseCommonOptions(InputInfoPtr pInfo)
+@@ -605,6 +658,7 @@ MouseCommonOptions(InputInfoPtr pInfo)
                  pInfo->name, wheelButton, pMse->wheelInertia,
                  pMse->wheelButtonTimeout);
      }
-+#if !defined(FREEBSD_USB)
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
      s = xf86SetStrOption(pInfo->options, "ButtonMapping", NULL);
      if (s) {
         int b, n = 0;
-@@ -628,6 +689,7 @@ MouseCommonOptions(InputInfoPtr pInfo)
+@@ -628,6 +682,7 @@ MouseCommonOptions(InputInfoPtr pInfo)
          if (f > pMse->buttons)
              pMse->buttons = f;
      }
-+#endif
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
      if (origButtons != pMse->buttons)
          buttons_from = X_CONFIG;
      xf86Msg(buttons_from, "%s: Buttons: %d\n", pInfo->name, pMse->buttons);
-@@ -709,7 +771,9 @@ MouseHWOptions(InputInfoPtr pInfo)
+@@ -709,7 +764,9 @@ MouseHWOptions(InputInfoPtr pInfo)
      }
      pMse->sampleRate = xf86SetIntOption(pInfo->options, "SampleRate", 0);
      pMse->resolution = xf86SetIntOption(pInfo->options, "Resolution", 0);
-+#if !defined(FREEBSD_USB)
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
      mPriv->sensitivity = xf86SetRealOption(pInfo->options, "Sensitivity", 1.0);
-+#endif
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
  }
  
  static void
-@@ -998,6 +1062,11 @@ MousePreInit(InputDriverPtr drv, InputIn
+@@ -996,6 +1053,10 @@ MousePreInit(InputDriverPtr drv, InputIn
+     /* Default Mapping: 1 2 3 8 9 10 11 ... */
      for (i = 0; i < MSE_MAXBUTTONS; i++)
          pMse->buttonMap[i] = 1 << (i > 2 && i < MSE_MAXBUTTONS-4 ? i+4 : i);
- 
-+#if defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    pMse->hasZ = 1;
 +    pMse->hasW = 0;
-+#endif
-+
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+ 
      protocol = MousePickProtocol(pInfo, device, protocol, &protocolID);
  
-     if (!device)
-@@ -2288,6 +2357,11 @@ MouseDoPostEvent(InputInfoPtr pInfo, int
+@@ -2197,7 +2258,11 @@ MouseDoPostEvent(InputInfoPtr pInfo, int
+ 
+     if (pMse->emulateWheel) {
+         /* Emulate wheel button handling */
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++        if (pMse->wheelButton == 0)
++#else
+         if(pMse->wheelButton == 0)
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
+             wheelButtonMask = 0;
+         else
+             wheelButtonMask = 1 << (pMse->wheelButton - 1);
+@@ -2287,6 +2352,11 @@ MouseDoPostEvent(InputInfoPtr pInfo, int
                          }
                      }
                  }
-+#if defined (FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +            } else {
 +                pMse->wheelXDistance = 0;
 +                pMse->wheelYDistance = 0;
-+#endif
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
              }
  
              /* Absorb the mouse movement while the wheel button is pressed. */
-@@ -2305,7 +2379,11 @@ MouseDoPostEvent(InputInfoPtr pInfo, int
+@@ -2304,7 +2374,11 @@ MouseDoPostEvent(InputInfoPtr pInfo, int
      if (pMse->emulate3ButtonsSoft && pMse->emulate3Pending && (dx || dy))
          buttonTimer(pInfo);
  
-+#if !defined(FREEBSD_USB)
-     if (dx || dy)
-+#else
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 +    if ((dx || dy) && !pMse->disableXY)
-+#endif
++#else
+     if (dx || dy)
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
          xf86PostMotionEvent(pInfo->dev, 0, 0, 2, dx, dy);
  
      if (change) {
-@@ -2418,12 +2496,16 @@ MousePostEvent(InputInfoPtr pInfo, int t
+@@ -2417,12 +2491,16 @@ MousePostEvent(InputInfoPtr pInfo, int t
                 int dx, int dy, int dz, int dw)
  {
      MouseDevPtr pMse;
-+#if !defined(FREEBSD_USB)
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
      mousePrivPtr mousepriv;
-+#endif
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
      int zbutton = 0, wbutton = 0, zbuttoncount = 0, wbuttoncount = 0;
      int i, b, buttons = 0;
  
      pMse = pInfo->private;
-+#if !defined(FREEBSD_USB)
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
      mousepriv = (mousePrivPtr)pMse->mousePriv;
-+#endif
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
  
      if (pMse->protocolID == PROT_MMHIT)
          b = reverseBits(hitachMap, truebuttons);
-@@ -2516,12 +2598,21 @@ MousePostEvent(InputInfoPtr pInfo, int t
+@@ -2515,11 +2593,19 @@ MousePostEvent(InputInfoPtr pInfo, int t
  
      /* Accumulate the scaled dx, dy in the private variables
         fracdx,fracdy and return the integer number part */
-+#if !defined(FREEBSD_USB)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    if (pMse->sensitivity != 0) {
++        pMse->fracdx += pMse->sensitivity*dx;
++        pMse->fracdy += pMse->sensitivity*dy;
++        pMse->fracdx -= ( dx=(int)(pMse->fracdx) );
++        pMse->fracdy -= ( dy=(int)(pMse->fracdy) );
++#else
      if (mousepriv) {
          mousepriv->fracdx += mousepriv->sensitivity*dx;
          mousepriv->fracdy += mousepriv->sensitivity*dy;
          mousepriv->fracdx -= ( dx=(int)(mousepriv->fracdx) );
          mousepriv->fracdy -= ( dy=(int)(mousepriv->fracdy) );
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      }
-+#else
-+    if (pMse->sensitivity != 0) {
-+        pMse->fracdx += pMse->sensitivity*dx;
-+        pMse->fracdy += pMse->sensitivity*dy;
-+        pMse->fracdx -= ( dx=(int)(pMse->fracdx) );
-+        pMse->fracdy -= ( dy=(int)(pMse->fracdy) );
-+    }
-+#endif
  
      /* If mouse wheel movement has to be mapped on a button, we need to
-      * loop for button press and release events. */
diff --git a/xf86-input-mouse-dfbsd/patches/patch-src_mouse.h b/xf86-input-mouse-dfbsd/patches/patch-src_mouse.h
index 79b97c7f5e..902863f407 100644
--- a/xf86-input-mouse-dfbsd/patches/patch-src_mouse.h
+++ b/xf86-input-mouse-dfbsd/patches/patch-src_mouse.h
@@ -1,51 +1,35 @@
 $NetBSD$
 
-Patches from FreeBSD ports / DragonFly dports with include guards.
-Support for different versions of system libusb headers.
+Patches from FreeBSD ports / DragonFly dports x11-drivers/xf86-input-mouse 1.9.2.
 
 --- src/mouse.h.orig	2012-10-08 01:40:07.000000000 +0000
 +++ src/mouse.h
-@@ -27,6 +27,14 @@
- 
- /* Public interface to OS-specific mouse support. */
- 
-+/* PKGSRC note: To support newer versions of DragonFly and FreeBSD,
-+ * this file is patched using DragonFly dports
-+ * x11-drivers/xf86-input-mouse/files/patch-src_mouse.h
-+ * as of master commit 4f04bfe0ea83 ... Tue Jul 14 22:56:44 2015 -0700
-+ * The patch's code is enclosed in include defined(FREEBSD_USB) while the
-+ * original code is enclosed in include !defined(FREEBSD_USB).
-+ */
-+
- #ifndef _XF86OSMOUSE_H_
- #define _XF86OSMOUSE_H_
- 
-@@ -220,10 +228,17 @@ typedef struct _MouseDevRec {
+@@ -220,10 +220,17 @@ typedef struct _MouseDevRec {
      Bool                emulate3ButtonsSoft;
      int                 emulate3Timeout;/* Timeout for 3 button emulation */
      Bool                chordMiddle;
-+#if defined(FREEBSD_USB)
-+    Bool		disableXY;
-+#endif
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    Bool                disableXY;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      Bool                flipXY;
      int                 invX;
      int                 invY;
      int                 resolution;
-+#if defined(FREEBSD_USB)
-+    Bool		hasW;
-+    Bool		hasZ;
-+#endif
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    Bool                hasW;
++    Bool                hasZ;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
      int                 negativeZ;      /* button mask */
      int                 positiveZ;      /* button mask */
      int                 negativeW;      /* button mask */
-@@ -262,6 +277,10 @@ typedef struct _MouseDevRec {
+@@ -262,6 +269,10 @@ typedef struct _MouseDevRec {
      int                 doubleClickOldSourceState;
      int                 lastMappedButtons;
      int                 buttonMap[MSE_MAXBUTTONS];
-+#if defined(FREEBSD_USB)
-+    float		fracdx, fracdy;
-+    float		sensitivity;
-+#endif
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    float               fracdx,fracdy;
++    float               sensitivity;
++#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) */
  } MouseDevRec, *MouseDevPtr;
  
  #endif /* _XF86OSMOUSE_H_ */
diff --git a/xf86-input-mouse-dfbsd/patches/patch-src_mousePriv.h b/xf86-input-mouse-dfbsd/patches/patch-src_mousePriv.h
index 9a07313b0a..27518282e8 100644
--- a/xf86-input-mouse-dfbsd/patches/patch-src_mousePriv.h
+++ b/xf86-input-mouse-dfbsd/patches/patch-src_mousePriv.h
@@ -1,33 +1,17 @@
 $NetBSD$
 
-Patches from FreeBSD ports / DragonFly dports with include guards.
-Support for different versions of system libusb headers.
+Patches from FreeBSD ports / DragonFly dports x11-drivers/xf86-input-mouse 1.9.2.
 
 --- src/mousePriv.h.orig	2012-05-28 00:01:45.000000000 +0000
 +++ src/mousePriv.h
-@@ -2,6 +2,14 @@
-  * Copyright (c) 1997-1999 by The XFree86 Project, Inc.
-  */
- 
-+/* PKGSRC note: To support newer versions of DragonFly and FreeBSD,
-+ * this file is patched using DragonFly dports
-+ * x11-drivers/xf86-input-mouse/files/patch-src_mousePriv.h
-+ * as of master commit 4f04bfe0ea83 ... Tue Jul 14 22:56:44 2015 -0700
-+ * The patch's code is enclosed in include defined(FREEBSD_USB) while the
-+ * original code is enclosed in include !defined(FREEBSD_USB).
-+ */
-+
- #ifndef _X_MOUSEPRIV_H
- #define _X_MOUSEPRIV_H
- 
-@@ -63,8 +71,10 @@ typedef struct {
+@@ -63,8 +63,10 @@ typedef struct {
      int         acc;
      CARD32      pnpLast;
      Bool        disablePnPauto;
-+#if !defined(FREEBSD_USB)
++#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__)
      float       fracdx,fracdy;
      float       sensitivity;
-+#endif
++#endif /* !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) */
  } mousePrivRec, *mousePrivPtr;
  
  /* mouse proto flags */


Home | Main Index | Thread Index | Old Index