From b08fdcde6f53586e6a55224d65c7ad113f541440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sun, 10 Nov 2024 12:57:04 +0100 Subject: [PATCH] PadBlocker: Avoid blocking non-trackpad devices Exposes a new field on mouse events named "device" that specifices what type of device the event originates from. This is then used in PadBlocker to ignore events that don't originate from trackpads. This field should also be exposed to the public API in case any program in userspace want to use it, as it may be useful for other purposes. Fixes #19238 and #17821 Change-Id: Ic0f8c088cf5d2b0414a8e69498b48f2a3e370d73 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8557 Tested-by: Commit checker robot Reviewed-by: Adrien Destugues Reviewed-by: waddlesplash --- headers/os/interface/Input.h | 8 ++++++++ .../devices/easypen/EasyPenInputDevice.cpp | 3 +++ .../input_server/devices/mouse/MouseInputDevice.cpp | 10 ++++++++-- .../devices/serial_mouse/MouseInputDevice.cpp | 3 +++ .../devices/tablet/TabletInputDevice.cpp | 8 ++++++-- .../input_server/filters/padblocker/PadBlocker.cpp | 7 +++++++ src/servers/input/InputServer.cpp | 13 ++++++++++++- 7 files changed, 47 insertions(+), 5 deletions(-) diff --git a/headers/os/interface/Input.h b/headers/os/interface/Input.h index 6b691ac9b3..ee03d577f7 100644 --- a/headers/os/interface/Input.h +++ b/headers/os/interface/Input.h @@ -25,6 +25,14 @@ enum input_device_type { }; +enum input_pointing_device_subtype { + B_UNKNOWN_DEVICE_SUBTYPE = 0, + B_MOUSE_DEVICE_SUBTYPE = 1, + B_TOUCHPAD_DEVICE_SUBTYPE = 2, + B_TABLET_DEVICE_SUBTYPE = 3 +}; + + enum input_device_notification { B_INPUT_DEVICE_ADDED = 0x0001, B_INPUT_DEVICE_STARTED = 0x0002, diff --git a/src/add-ons/input_server/devices/easypen/EasyPenInputDevice.cpp b/src/add-ons/input_server/devices/easypen/EasyPenInputDevice.cpp index 0695e6e4c9..f47afb1091 100644 --- a/src/add-ons/input_server/devices/easypen/EasyPenInputDevice.cpp +++ b/src/add-ons/input_server/devices/easypen/EasyPenInputDevice.cpp @@ -277,6 +277,7 @@ EasyPenInputDevice::DeviceWatcher(void *arg) } message->AddInt64("when", movements.timestamp); + message->AddInt32("be:device_subtype", B_TABLET_DEVICE_SUBTYPE); message->AddInt32("buttons", movements.buttons); message->AddFloat("x", movements.xpos); message->AddFloat("y", movements.ypos); @@ -287,6 +288,7 @@ EasyPenInputDevice::DeviceWatcher(void *arg) message = new BMessage(B_MOUSE_MOVED); if (message) { message->AddInt64("when", movements.timestamp); + message->AddInt32("be:device_subtype", B_TABLET_DEVICE_SUBTYPE); message->AddInt32("buttons", movements.buttons); message->AddFloat("x", movements.xpos); message->AddFloat("y", movements.ypos); @@ -307,6 +309,7 @@ EasyPenInputDevice::DeviceWatcher(void *arg) message = new BMessage(B_MOUSE_WHEEL_CHANGED); if (message) { message->AddInt64("when", movements.timestamp); + message->AddInt32("be:device_subtype", B_TABLET_DEVICE_SUBTYPE); message->AddFloat("be:wheel_delta_x", movements.wheel_xdelta); message->AddFloat("be:wheel_delta_y", movements.wheel_ydelta); diff --git a/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp b/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp index d2e5dff2f1..b5e624b2c5 100644 --- a/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp +++ b/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp @@ -517,7 +517,11 @@ MouseDevice::_ControlThread() && message->AddFloat("be:wheel_delta_x", movements.wheel_xdelta) == B_OK && message->AddFloat("be:wheel_delta_y", - movements.wheel_ydelta) == B_OK) + movements.wheel_ydelta) == B_OK + && message->AddInt32("be:device_subtype", + fIsTouchpad + ? B_TOUCHPAD_DEVICE_SUBTYPE + : B_MOUSE_DEVICE_SUBTYPE) == B_OK) fTarget.EnqueueMessage(message); else delete message; @@ -637,7 +641,9 @@ MouseDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons, if (message->AddInt64("when", when) < B_OK || message->AddInt32("buttons", buttons) < B_OK || message->AddInt32("x", deltaX) < B_OK - || message->AddInt32("y", deltaY) < B_OK) { + || message->AddInt32("y", deltaY) < B_OK + || message->AddInt32("be:device_subtype", + fIsTouchpad ? B_TOUCHPAD_DEVICE_SUBTYPE : B_MOUSE_DEVICE_SUBTYPE) < B_OK) { delete message; return NULL; } diff --git a/src/add-ons/input_server/devices/serial_mouse/MouseInputDevice.cpp b/src/add-ons/input_server/devices/serial_mouse/MouseInputDevice.cpp index ab355fb116..e153b2ec0e 100644 --- a/src/add-ons/input_server/devices/serial_mouse/MouseInputDevice.cpp +++ b/src/add-ons/input_server/devices/serial_mouse/MouseInputDevice.cpp @@ -276,6 +276,7 @@ MouseInputDevice::DeviceWatcher(void* arg) message = new BMessage(B_MOUSE_UP); message->AddInt64("when", movements.timestamp); + message->AddInt32("be:device_subtype", B_MOUSE_DEVICE_SUBTYPE); message->AddInt32("buttons", movements.buttons); if ((buttons & movements.buttons) > 0) { @@ -333,6 +334,7 @@ MouseInputDevice::DeviceWatcher(void* arg) message = new BMessage(B_MOUSE_MOVED); if (message) { message->AddInt64("when", movements.timestamp); + message->AddInt32("be:device_subtype", B_MOUSE_DEVICE_SUBTYPE); message->AddInt32("buttons", movements.buttons); message->AddInt32("x", xdelta); message->AddInt32("y", ydelta); @@ -345,6 +347,7 @@ MouseInputDevice::DeviceWatcher(void* arg) message = new BMessage(B_MOUSE_WHEEL_CHANGED); if (message) { message->AddInt64("when", movements.timestamp); + message->AddInt32("be:device_subtype", B_MOUSE_DEVICE_SUBTYPE); message->AddFloat("be:wheel_delta_x", movements.wheel_xdelta); message->AddFloat("be:wheel_delta_y", movements.wheel_ydelta); diff --git a/src/add-ons/input_server/devices/tablet/TabletInputDevice.cpp b/src/add-ons/input_server/devices/tablet/TabletInputDevice.cpp index 403d50c87d..31ae1a2a76 100644 --- a/src/add-ons/input_server/devices/tablet/TabletInputDevice.cpp +++ b/src/add-ons/input_server/devices/tablet/TabletInputDevice.cpp @@ -381,7 +381,9 @@ TabletDevice::_ControlThread() && message->AddFloat("be:wheel_delta_x", movements.wheel_xdelta) == B_OK && message->AddFloat("be:wheel_delta_y", - movements.wheel_ydelta) == B_OK) + movements.wheel_ydelta) == B_OK + && message->AddInt32("be:device_subtype", + B_TABLET_DEVICE_SUBTYPE) == B_OK) fTarget.EnqueueMessage(message); else delete message; @@ -433,7 +435,9 @@ TabletDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons, if (message->AddInt64("when", when) < B_OK || message->AddInt32("buttons", buttons) < B_OK || message->AddFloat("x", xPosition) < B_OK - || message->AddFloat("y", yPosition) < B_OK) { + || message->AddFloat("y", yPosition) < B_OK + || message->AddInt32("be:device_subtype", + B_TABLET_DEVICE_SUBTYPE) < B_OK) { delete message; return NULL; } diff --git a/src/add-ons/input_server/filters/padblocker/PadBlocker.cpp b/src/add-ons/input_server/filters/padblocker/PadBlocker.cpp index 000b7efa47..3416f72f78 100644 --- a/src/add-ons/input_server/filters/padblocker/PadBlocker.cpp +++ b/src/add-ons/input_server/filters/padblocker/PadBlocker.cpp @@ -46,6 +46,7 @@ #include #include +#include #include #if DEBUG @@ -162,10 +163,16 @@ filter_result PadBlocker::Filter(BMessage *message, BList *outList) case B_MOUSE_DOWN: { + int32 device; // do nothing if disabled if (_threshold == 0) break; + // only block touchpad devices + if (message->FindInt32("be:device_subtype", &device) != B_OK + || device != B_TOUCHPAD_DEVICE_SUBTYPE) + break; + bigtime_t now = system_time(); // if less than the threshold has passed, tell input server // to ignore this message diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index 33e5972d0f..336b7b17a1 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -1681,13 +1681,24 @@ InputServer::_SanitizeEvents(EventList& events) for (int32 index = 0; BMessage* event = (BMessage*)events.ItemAt(index); index++) { switch (event->what) { + case B_MOUSE_WHEEL_CHANGED: + { + int32 device; + if (event->FindInt32("be:device_subtype", &device) != B_OK) + event->AddInt32("be:device_subtype", B_UNKNOWN_DEVICE_SUBTYPE); + + break; + } case B_MOUSE_MOVED: case B_MOUSE_DOWN: { - int32 buttons; + int32 buttons, device; if (event->FindInt32("buttons", &buttons) != B_OK) event->AddInt32("buttons", 0); + if (event->FindInt32("be:device_subtype", &device) != B_OK) + event->AddInt32("be:device_subtype", B_UNKNOWN_DEVICE_SUBTYPE); + // supposed to fall through } case B_MOUSE_UP: