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 <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Gustaf Alhäll 2024-11-10 12:57:04 +01:00 committed by waddlesplash
parent fd7bde29e9
commit b08fdcde6f
7 changed files with 47 additions and 5 deletions

View File

@ -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 { enum input_device_notification {
B_INPUT_DEVICE_ADDED = 0x0001, B_INPUT_DEVICE_ADDED = 0x0001,
B_INPUT_DEVICE_STARTED = 0x0002, B_INPUT_DEVICE_STARTED = 0x0002,

View File

@ -277,6 +277,7 @@ EasyPenInputDevice::DeviceWatcher(void *arg)
} }
message->AddInt64("when", movements.timestamp); message->AddInt64("when", movements.timestamp);
message->AddInt32("be:device_subtype", B_TABLET_DEVICE_SUBTYPE);
message->AddInt32("buttons", movements.buttons); message->AddInt32("buttons", movements.buttons);
message->AddFloat("x", movements.xpos); message->AddFloat("x", movements.xpos);
message->AddFloat("y", movements.ypos); message->AddFloat("y", movements.ypos);
@ -287,6 +288,7 @@ EasyPenInputDevice::DeviceWatcher(void *arg)
message = new BMessage(B_MOUSE_MOVED); message = new BMessage(B_MOUSE_MOVED);
if (message) { if (message) {
message->AddInt64("when", movements.timestamp); message->AddInt64("when", movements.timestamp);
message->AddInt32("be:device_subtype", B_TABLET_DEVICE_SUBTYPE);
message->AddInt32("buttons", movements.buttons); message->AddInt32("buttons", movements.buttons);
message->AddFloat("x", movements.xpos); message->AddFloat("x", movements.xpos);
message->AddFloat("y", movements.ypos); message->AddFloat("y", movements.ypos);
@ -307,6 +309,7 @@ EasyPenInputDevice::DeviceWatcher(void *arg)
message = new BMessage(B_MOUSE_WHEEL_CHANGED); message = new BMessage(B_MOUSE_WHEEL_CHANGED);
if (message) { if (message) {
message->AddInt64("when", movements.timestamp); 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_x", movements.wheel_xdelta);
message->AddFloat("be:wheel_delta_y", movements.wheel_ydelta); message->AddFloat("be:wheel_delta_y", movements.wheel_ydelta);

View File

@ -517,7 +517,11 @@ MouseDevice::_ControlThread()
&& message->AddFloat("be:wheel_delta_x", && message->AddFloat("be:wheel_delta_x",
movements.wheel_xdelta) == B_OK movements.wheel_xdelta) == B_OK
&& message->AddFloat("be:wheel_delta_y", && 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); fTarget.EnqueueMessage(message);
else else
delete message; delete message;
@ -637,7 +641,9 @@ MouseDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons,
if (message->AddInt64("when", when) < B_OK if (message->AddInt64("when", when) < B_OK
|| message->AddInt32("buttons", buttons) < B_OK || message->AddInt32("buttons", buttons) < B_OK
|| message->AddInt32("x", deltaX) < 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; delete message;
return NULL; return NULL;
} }

View File

@ -276,6 +276,7 @@ MouseInputDevice::DeviceWatcher(void* arg)
message = new BMessage(B_MOUSE_UP); message = new BMessage(B_MOUSE_UP);
message->AddInt64("when", movements.timestamp); message->AddInt64("when", movements.timestamp);
message->AddInt32("be:device_subtype", B_MOUSE_DEVICE_SUBTYPE);
message->AddInt32("buttons", movements.buttons); message->AddInt32("buttons", movements.buttons);
if ((buttons & movements.buttons) > 0) { if ((buttons & movements.buttons) > 0) {
@ -333,6 +334,7 @@ MouseInputDevice::DeviceWatcher(void* arg)
message = new BMessage(B_MOUSE_MOVED); message = new BMessage(B_MOUSE_MOVED);
if (message) { if (message) {
message->AddInt64("when", movements.timestamp); message->AddInt64("when", movements.timestamp);
message->AddInt32("be:device_subtype", B_MOUSE_DEVICE_SUBTYPE);
message->AddInt32("buttons", movements.buttons); message->AddInt32("buttons", movements.buttons);
message->AddInt32("x", xdelta); message->AddInt32("x", xdelta);
message->AddInt32("y", ydelta); message->AddInt32("y", ydelta);
@ -345,6 +347,7 @@ MouseInputDevice::DeviceWatcher(void* arg)
message = new BMessage(B_MOUSE_WHEEL_CHANGED); message = new BMessage(B_MOUSE_WHEEL_CHANGED);
if (message) { if (message) {
message->AddInt64("when", movements.timestamp); 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_x", movements.wheel_xdelta);
message->AddFloat("be:wheel_delta_y", movements.wheel_ydelta); message->AddFloat("be:wheel_delta_y", movements.wheel_ydelta);

View File

@ -381,7 +381,9 @@ TabletDevice::_ControlThread()
&& message->AddFloat("be:wheel_delta_x", && message->AddFloat("be:wheel_delta_x",
movements.wheel_xdelta) == B_OK movements.wheel_xdelta) == B_OK
&& message->AddFloat("be:wheel_delta_y", && 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); fTarget.EnqueueMessage(message);
else else
delete message; delete message;
@ -433,7 +435,9 @@ TabletDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons,
if (message->AddInt64("when", when) < B_OK if (message->AddInt64("when", when) < B_OK
|| message->AddInt32("buttons", buttons) < B_OK || message->AddInt32("buttons", buttons) < B_OK
|| message->AddFloat("x", xPosition) < 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; delete message;
return NULL; return NULL;
} }

View File

@ -46,6 +46,7 @@
#include <OS.h> #include <OS.h>
#include <StorageKit.h> #include <StorageKit.h>
#include <add-ons/input_server/InputServerDevice.h>
#include <add-ons/input_server/InputServerFilter.h> #include <add-ons/input_server/InputServerFilter.h>
#if DEBUG #if DEBUG
@ -162,10 +163,16 @@ filter_result PadBlocker::Filter(BMessage *message, BList *outList)
case B_MOUSE_DOWN: case B_MOUSE_DOWN:
{ {
int32 device;
// do nothing if disabled // do nothing if disabled
if (_threshold == 0) if (_threshold == 0)
break; 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(); bigtime_t now = system_time();
// if less than the threshold has passed, tell input server // if less than the threshold has passed, tell input server
// to ignore this message // to ignore this message

View File

@ -1681,13 +1681,24 @@ InputServer::_SanitizeEvents(EventList& events)
for (int32 index = 0; BMessage* event = (BMessage*)events.ItemAt(index); for (int32 index = 0; BMessage* event = (BMessage*)events.ItemAt(index);
index++) { index++) {
switch (event->what) { 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_MOVED:
case B_MOUSE_DOWN: case B_MOUSE_DOWN:
{ {
int32 buttons; int32 buttons, device;
if (event->FindInt32("buttons", &buttons) != B_OK) if (event->FindInt32("buttons", &buttons) != B_OK)
event->AddInt32("buttons", 0); 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 // supposed to fall through
} }
case B_MOUSE_UP: case B_MOUSE_UP: