git: 4a0db5e2920c - main - evdev: Extend EVIOCGRAB ioctl scope to cover sysmouse interface
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 17 Nov 2022 21:50:49 UTC
The branch main has been updated by wulf:
URL: https://cgit.FreeBSD.org/src/commit/?id=4a0db5e2920c0e0df52d6888bdd732df95706dfc
commit 4a0db5e2920c0e0df52d6888bdd732df95706dfc
Author: Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2022-11-17 21:48:42 +0000
Commit: Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-11-17 21:48:42 +0000
evdev: Extend EVIOCGRAB ioctl scope to cover sysmouse interface
of psm(4), ums(4) and sysmouse(4) drivers.
EVIOCGRAB ioctl execution on /dev/input/event# device node gains
exclusive access to this device to caller. It is used mostly for
development purposes and remote control software. See e.g.
https://reviews.freebsd.org/D30020 which is the reason of creation
of this change.
MFC after: 2 weeks
Tested by: corvink
Differential revision: https://reviews.freebsd.org/D30542
---
sys/dev/atkbdc/psm.c | 12 ++++++++----
sys/dev/evdev/evdev.c | 11 +++++++++++
sys/dev/evdev/evdev.h | 1 +
sys/dev/syscons/sysmouse.c | 2 ++
sys/dev/usb/input/ums.c | 4 ++++
sys/dev/vt/vt_sysmouse.c | 2 ++
6 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/sys/dev/atkbdc/psm.c b/sys/dev/atkbdc/psm.c
index b3e036ebc134..97bf1b859dd2 100644
--- a/sys/dev/atkbdc/psm.c
+++ b/sys/dev/atkbdc/psm.c
@@ -5111,6 +5111,10 @@ psmsoftintr(void *arg)
break;
}
+ /* Store last packet for reinjection if it has not been set already */
+ if (timevalisset(&sc->idletimeout) && sc->idlepacket.inputbytes == 0)
+ sc->idlepacket = *pb;
+
#ifdef EVDEV_SUPPORT
if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE &&
sc->hw.model != MOUSE_MODEL_ELANTECH &&
@@ -5144,6 +5148,10 @@ psmsoftintr(void *arg)
evdev_push_mouse_btn(sc->evdev_r, ms.button);
evdev_sync(sc->evdev_r);
}
+
+ if ((sc->evdev_a != NULL && evdev_is_grabbed(sc->evdev_a)) ||
+ (sc->evdev_r != NULL && evdev_is_grabbed(sc->evdev_r)))
+ goto next;
#endif
/* scale values */
@@ -5164,10 +5172,6 @@ psmsoftintr(void *arg)
}
}
- /* Store last packet for reinjection if it has not been set already */
- if (timevalisset(&sc->idletimeout) && sc->idlepacket.inputbytes == 0)
- sc->idlepacket = *pb;
-
ms.dx = x;
ms.dy = y;
ms.dz = z;
diff --git a/sys/dev/evdev/evdev.c b/sys/dev/evdev/evdev.c
index 2fd7c2e201ea..a0a039f0b691 100644
--- a/sys/dev/evdev/evdev.c
+++ b/sys/dev/evdev/evdev.c
@@ -1094,6 +1094,17 @@ evdev_release_client(struct evdev_dev *evdev, struct evdev_client *client)
return (0);
}
+bool
+evdev_is_grabbed(struct evdev_dev *evdev)
+{
+ /*
+ * The function is intended to be called from evdev-unrelated parts of
+ * code like syscons-compatible parts of mouse and keyboard drivers.
+ * That makes unlocked read-only access acceptable.
+ */
+ return (evdev->ev_grabber != NULL);
+}
+
static void
evdev_repeat_callout(void *arg)
{
diff --git a/sys/dev/evdev/evdev.h b/sys/dev/evdev/evdev.h
index 90bea09b70c9..892e6b1bc071 100644
--- a/sys/dev/evdev/evdev.h
+++ b/sys/dev/evdev/evdev.h
@@ -154,6 +154,7 @@ void evdev_set_repeat_params(struct evdev_dev *, uint16_t, int);
int evdev_set_report_size(struct evdev_dev *, size_t);
void evdev_set_flag(struct evdev_dev *, uint16_t);
void *evdev_get_softc(struct evdev_dev *);
+bool evdev_is_grabbed(struct evdev_dev *);
/* Multitouch related functions: */
int evdev_mt_id_to_slot(struct evdev_dev *, int32_t);
diff --git a/sys/dev/syscons/sysmouse.c b/sys/dev/syscons/sysmouse.c
index ef851058a6ef..73167bdb34f8 100644
--- a/sys/dev/syscons/sysmouse.c
+++ b/sys/dev/syscons/sysmouse.c
@@ -295,6 +295,8 @@ sysmouse_event(mouse_info_t *info)
#ifdef EVDEV_SUPPORT
smdev_evdev_write(x, y, z, mouse_status.button);
+ if (evdev_is_grabbed(sysmouse_evdev))
+ goto done;
#endif
if (!tty_opened(sysmouse_tty))
diff --git a/sys/dev/usb/input/ums.c b/sys/dev/usb/input/ums.c
index 5b3ac2af4cd0..987c4b9d1309 100644
--- a/sys/dev/usb/input/ums.c
+++ b/sys/dev/usb/input/ums.c
@@ -875,6 +875,10 @@ ums_put_queue(struct ums_softc *sc, int32_t dx, int32_t dy,
{
uint8_t buf[8];
+#ifdef EVDEV_SUPPORT
+ if (evdev_is_grabbed(sc->sc_evdev))
+ return;
+#endif
if (1) {
if (dx > 254)
dx = 254;
diff --git a/sys/dev/vt/vt_sysmouse.c b/sys/dev/vt/vt_sysmouse.c
index e10ac829abf3..c6426f3a8f17 100644
--- a/sys/dev/vt/vt_sysmouse.c
+++ b/sys/dev/vt/vt_sysmouse.c
@@ -249,6 +249,8 @@ sysmouse_process_event(mouse_info_t *mi)
#ifdef EVDEV_SUPPORT
sysmouse_evdev_store(x, y, z, sysmouse_status.button);
+ if (evdev_is_grabbed(sysmouse_evdev))
+ goto done;
#endif
/* The first five bytes are compatible with MouseSystems. */