aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Kondratyev <wulf@FreeBSD.org>2025-09-21 13:14:48 +0000
committerVladimir Kondratyev <wulf@FreeBSD.org>2025-09-21 13:14:48 +0000
commit1335bf5ce1c9f0bf15c1fbed502f49e5a4950e32 (patch)
treebe480af939f76cd8d6b60421176759721fb9a23d
parentb1442e6b8d34971d3311e08dc72cafc6649c27db (diff)
moused(8): Add command line option to restrict interface type
to evdev or sysmouse. It is required to avoid receiving of double events on hybrid devices supporting both interfaces like ums (4). MFC after: 1 day Reviewed by: glebius (via private chat) Differential Revision: https://reviews.freebsd.org/D52647
-rw-r--r--libexec/rc/rc.conf2
-rwxr-xr-xlibexec/rc/rc.d/moused7
-rw-r--r--usr.sbin/moused/moused/moused.831
-rw-r--r--usr.sbin/moused/moused/moused.c39
4 files changed, 60 insertions, 19 deletions
diff --git a/libexec/rc/rc.conf b/libexec/rc/rc.conf
index 0ef3012892dd..b5482f081ce5 100644
--- a/libexec/rc/rc.conf
+++ b/libexec/rc/rc.conf
@@ -589,7 +589,7 @@ saver="NO" # screen saver: Uses /boot/kernel/${saver}_saver.ko
moused_nondefault_enable="NO" # Treat non-default mice as enabled unless
# specifically overridden in rc.conf(5).
moused_enable="NO" # Run the mouse daemon.
-moused_type="auto" # See man page for rc.conf(5) for available settings.
+moused_type="evdev" # See man page for rc.conf(5) for available settings.
moused_port="auto" # Set to your mouse port.
moused_flags="" # Any additional flags to moused.
mousechar_start="NO" # if 0xd0-0xd3 default range is occupied in your
diff --git a/libexec/rc/rc.d/moused b/libexec/rc/rc.d/moused
index aaf0dd0890a8..64e4f815eea9 100755
--- a/libexec/rc/rc.d/moused
+++ b/libexec/rc/rc.d/moused
@@ -16,6 +16,7 @@ start_cmd="moused_start"
pidprefix="/var/run/moused"
pidfile="${pidprefix}.pid"
pidarg=
+typearg=
load_rc_config $name
# doesn't make sense to run in a svcj: nojail keyword
@@ -49,15 +50,17 @@ moused_start()
eval myflags=\${moused_${ms}_flags-$moused_flags}
eval myport=\${moused_${ms}_port-/dev/$ms}
eval mytype=\${moused_${ms}_type-$moused_type}
+ if [ -n "$mytype" ] && check_kern_features evdev_support; then
+ typearg="-t ${mytype}"
+ fi
else
ms="default"
myflags="$moused_flags"
myport="$moused_port"
- mytype="$moused_type"
fi
startmsg -n "Starting ${ms} moused"
- /usr/sbin/moused ${myflags} -p ${myport} -t ${mytype} ${pidarg}
+ /usr/sbin/moused ${myflags} -p ${myport} ${typearg} ${pidarg}
startmsg '.'
mousechar_arg=
diff --git a/usr.sbin/moused/moused/moused.8 b/usr.sbin/moused/moused/moused.8
index 96feeda336c9..2483f8a04b2a 100644
--- a/usr.sbin/moused/moused/moused.8
+++ b/usr.sbin/moused/moused/moused.8
@@ -49,7 +49,7 @@
.Op Fl m Ar N=M
.Op Fl w Ar N
.Op Fl z Ar target
-.Op Fl t Ar mousetype
+.Op Fl t Ar interfacetype
.Op Fl l Ar level
.Op Fl 3 Op Fl E Ar timeout
.Op Fl T Ar distance Ns Op , Ns Ar time Ns Op , Ns Ar after
@@ -329,9 +329,32 @@ or
.Ar high .
This option may not be supported by all the device.
.It Fl t Ar type
-Ignored.
-Used for compatibiliy with legacy
-.Nm .
+Force the interface type of the mouse attached to the port.
+You may explicitly specify a type listed below, or use
+.Ar auto
+to let the
+.Nm
+utility automatically select an appropriate protocol for the given
+character device.
+If you entirely omit this option in the command line,
+.Fl t Ar auto
+is assumed.
+.Pp
+Valid types for this option are listed below.
+.Bl -tag -compact -width systemmouse
+.It Ar evdev
+Input event device usualy residing in
+.Pa /dev/input .
+.It Ar sysmouse
+Traditional protocol used by e.g.
+.Xr ums 4
+and
+.Xr psm 4
+drivers.
+.El
+.Pp
+Note that this option restricts usage of the given port rather then gives
+a hint.
.It Fl q Ar config
Path to configuration file.
.It Fl Q Ar quirks
diff --git a/usr.sbin/moused/moused/moused.c b/usr.sbin/moused/moused/moused.c
index acd6e5223685..36cb8cc27eab 100644
--- a/usr.sbin/moused/moused/moused.c
+++ b/usr.sbin/moused/moused/moused.c
@@ -448,6 +448,7 @@ static const char *config_file = CONFDIR "/moused.conf";
#endif
static const char *quirks_path = QUIRKSDIR;
static struct quirks_context *quirks;
+static enum device_if force_if = DEVICE_IF_UNKNOWN;
static int opt_rate = 0;
static int opt_resolution = MOUSE_RES_UNKNOWN;
@@ -529,7 +530,8 @@ main(int argc, char *argv[])
struct rodent *r;
pid_t mpid;
int c;
- int i;
+ u_int i;
+ int n;
u_long ul;
char *errstr;
@@ -552,26 +554,26 @@ main(int argc, char *argv[])
break;
case 'a':
- i = sscanf(optarg, "%lf,%lf", &opt_accelx, &opt_accely);
- if (i == 0) {
+ n = sscanf(optarg, "%lf,%lf", &opt_accelx, &opt_accely);
+ if (n == 0) {
warnx("invalid linear acceleration argument "
"'%s'", optarg);
usage();
}
- if (i == 1)
+ if (n == 1)
opt_accely = opt_accelx;
break;
case 'A':
opt_exp_accel = true;
- i = sscanf(optarg, "%lf,%lf", &opt_expoaccel,
+ n = sscanf(optarg, "%lf,%lf", &opt_expoaccel,
&opt_expoffset);
- if (i == 0) {
+ if (n == 0) {
warnx("invalid exponential acceleration "
"argument '%s'", optarg);
usage();
}
- if (i == 1)
+ if (n == 1)
opt_expoffset = 1.0;
break;
@@ -646,8 +648,19 @@ main(int argc, char *argv[])
break;
case 't':
- if (strcmp(optarg, "auto") != 0)
- warnx("ignore mouse type `%s'", optarg);
+ if (strcmp(optarg, "auto") == 0) {
+ force_if = DEVICE_IF_UNKNOWN;
+ break;
+ }
+ for (i = 0; i < nitems(rifs); i++)
+ if (strcmp(optarg, rifs[i].name) == 0) {
+ force_if = i;
+ break;
+ }
+ if (i == nitems(rifs)) {
+ warnx("no such interface type `%s'", optarg);
+ usage();
+ }
break;
case 'w':
@@ -1224,7 +1237,7 @@ usage(void)
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
"usage: moused [-dfg] [-I file] [-F rate] [-r resolution]",
" [-VH [-U threshold]] [-a X[,Y]] [-C threshold] [-m N=M] [-w N]",
- " [-z N] [-t <mousetype>] [-l level] [-3 [-E timeout]]",
+ " [-z N] [-t <interfacetype>] [-l level] [-3 [-E timeout]]",
" [-T distance[,time[,after]]] -p <port> [-q config] [-Q quirks]",
" moused [-d] -i <port|if|type|model|all> -p <port>");
exit(1);
@@ -1338,9 +1351,11 @@ r_identify_if(int fd)
{
int dummy;
- if (ioctl(fd, EVIOCGVERSION, &dummy) >= 0)
+ if ((force_if == DEVICE_IF_UNKNOWN || force_if == DEVICE_IF_EVDEV) &&
+ ioctl(fd, EVIOCGVERSION, &dummy) >= 0)
return (DEVICE_IF_EVDEV);
- if (ioctl(fd, MOUSE_GETLEVEL, &dummy) >= 0)
+ if ((force_if == DEVICE_IF_UNKNOWN || force_if == DEVICE_IF_SYSMOUSE) &&
+ ioctl(fd, MOUSE_GETLEVEL, &dummy) >= 0)
return (DEVICE_IF_SYSMOUSE);
return (DEVICE_IF_UNKNOWN);
}