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.
This commit is contained in:
parent
b2a98c41ee
commit
620955d397
|
@ -130,39 +130,6 @@ void PopulateDevices(void* const hwnd)
|
||||||
XIFreeDeviceInfo(all_masters);
|
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,
|
KeyboardMouse::KeyboardMouse(Window window, int opcode, int pointer, int keyboard,
|
||||||
double scroll_increment_)
|
double scroll_increment_)
|
||||||
: m_window(window), xi_opcode(opcode), pointer_deviceid(pointer), keyboard_deviceid(keyboard),
|
: 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 = mask_buf;
|
||||||
mask.mask_len = sizeof(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;
|
XIEventMask mask;
|
||||||
mask.mask = mask_buf;
|
mask.mask = mask_buf;
|
||||||
mask.mask_len = sizeof(mask_buf);
|
mask.mask_len = sizeof(mask_buf);
|
||||||
|
mask.deviceid = keyboard_deviceid;
|
||||||
SelectEventsForDevice(&mask, keyboard_deviceid);
|
XISelectEvents(m_display, DefaultRootWindow(m_display), &mask, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keyboard Keys
|
// Keyboard Keys
|
||||||
|
|
|
@ -108,7 +108,6 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SelectEventsForDevice(XIEventMask* mask, int deviceid);
|
|
||||||
void UpdateCursor(bool should_center_mouse);
|
void UpdateCursor(bool should_center_mouse);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue