From 620955d397d4c40aca06a0811294ccb90a6434f0 Mon Sep 17 00:00:00 2001 From: Jeffrey Bosboom Date: Sat, 15 Apr 2023 02:13:03 -0700 Subject: [PATCH] XInput2: Listen to master devices only A comment removed by this commit gives two reasons for listening to slave devices, both of which no longer apply: - "Only slaves emit raw motion events": perhaps this was true when the comment was written, but now master devices provide raw motion events along with the other raw events. - "Selecting slave keyboards avoids dealing with key focus": we get raw key events regardless of the focus. Listening to both master and slave devices results in duplicate raw events. For button and key events, that's a tiny waste of time setting the update flag a second time, but for raw mouse events the raw motion will be processed twice. That makes this commit a user-facing change. --- .../ControllerInterface/Xlib/XInput2.cpp | 40 ++----------------- .../ControllerInterface/Xlib/XInput2.h | 1 - 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp index 4c47da4fc5..d90139fe03 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp @@ -130,39 +130,6 @@ void PopulateDevices(void* const hwnd) XIFreeDeviceInfo(all_masters); } -// Apply the event mask to the device and all its slaves. Only used in the -// constructor. Remember, each KeyboardMouse has its own copy of the event -// stream, which is how multiple event masks can "coexist." -void KeyboardMouse::SelectEventsForDevice(XIEventMask* mask, int deviceid) -{ - // Set the event mask for the master device. - mask->deviceid = deviceid; - XISelectEvents(m_display, DefaultRootWindow(m_display), mask, 1); - - // Query all the master device's slaves and set the same event mask for - // those too. There are two reasons we want to do this. For mouse devices, - // we want the raw motion events, and only slaves (i.e. physical hardware - // devices) emit those. For keyboard devices, selecting slaves avoids - // dealing with key focus. - - int num_slaves; - XIDeviceInfo* const all_slaves = XIQueryDevice(m_display, XIAllDevices, &num_slaves); - - for (int i = 0; i < num_slaves; i++) - { - XIDeviceInfo* const slave = &all_slaves[i]; - if ((slave->use != XISlavePointer && slave->use != XISlaveKeyboard) || - slave->attachment != deviceid) - { - continue; - } - mask->deviceid = slave->deviceid; - XISelectEvents(m_display, DefaultRootWindow(m_display), mask, 1); - } - - XIFreeDeviceInfo(all_slaves); -} - KeyboardMouse::KeyboardMouse(Window window, int opcode, int pointer, int keyboard, double scroll_increment_) : m_window(window), xi_opcode(opcode), pointer_deviceid(pointer), keyboard_deviceid(keyboard), @@ -198,7 +165,8 @@ KeyboardMouse::KeyboardMouse(Window window, int opcode, int pointer, int keyboar mask.mask = mask_buf; mask.mask_len = sizeof(mask_buf); - SelectEventsForDevice(&mask, pointer_deviceid); + mask.deviceid = pointer_deviceid; + XISelectEvents(m_display, DefaultRootWindow(m_display), &mask, 1); } { @@ -209,8 +177,8 @@ KeyboardMouse::KeyboardMouse(Window window, int opcode, int pointer, int keyboar XIEventMask mask; mask.mask = mask_buf; mask.mask_len = sizeof(mask_buf); - - SelectEventsForDevice(&mask, keyboard_deviceid); + mask.deviceid = keyboard_deviceid; + XISelectEvents(m_display, DefaultRootWindow(m_display), &mask, 1); } // Keyboard Keys diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h index 52c78ab752..6a4f8436f1 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h @@ -108,7 +108,6 @@ private: }; private: - void SelectEventsForDevice(XIEventMask* mask, int deviceid); void UpdateCursor(bool should_center_mouse); public: