summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
diff options
context:
space:
mode:
authorTheConfuZzledDude <theconfuzzleddude@gmail.com>2022-12-26 17:27:48 +0000
committerTheConfuZzledDude <theconfuzzleddude@gmail.com>2022-12-26 17:27:48 +0000
commit288fa635f92760f71f638a5a411e63fafe9cb44e (patch)
tree579aecc12bfce491ea70145a9276f0d3bede8e6d /Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
parent27d596b89ca8d8a9c4d05a457ae8fa9134e9ffa4 (diff)
InputCommon/XInput2: Changed axis value reading to be more correct
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp66
1 files changed, 37 insertions, 29 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
index 7789b903ac..c0594b6662 100644
--- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
@@ -92,8 +92,8 @@ void PopulateDevices(void* const hwnd)
if (current_master->use == XIMasterPointer)
{
- // We need to query the master for the scroll wheel's increment, since the increment used varies
- // depending on what input driver is being used. For example, xf86-libinput uses 120.0.
+ // We need to query the master for the scroll wheel's increment, since the increment used
+ // varies depending on what input driver is being used. For example, xf86-libinput uses 120.0.
for (int j = 0; j < current_master->num_classes; j++)
{
if (current_master->classes[j]->type == XIScrollClass)
@@ -106,8 +106,9 @@ void PopulateDevices(void* const hwnd)
}
// Since current_master is a master pointer, its attachment must
// be a master keyboard.
- g_controller_interface.AddDevice(std::make_shared<KeyboardMouse>(
- (Window)hwnd, xi_opcode, current_master->deviceid, current_master->attachment, scroll_increment));
+ g_controller_interface.AddDevice(
+ std::make_shared<KeyboardMouse>((Window)hwnd, xi_opcode, current_master->deviceid,
+ current_master->attachment, scroll_increment));
}
}
@@ -149,8 +150,10 @@ void KeyboardMouse::SelectEventsForDevice(XIEventMask* mask, int deviceid)
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), scroll_increment(scroll_increment)
+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),
+ scroll_increment(scroll_increment)
{
// The cool thing about each KeyboardMouse object having its own Display
// is that each one gets its own separate copy of the X11 event stream,
@@ -321,34 +324,39 @@ void KeyboardMouse::UpdateInput()
m_state.keyboard[dev_event->detail / 8] &= ~(1 << (dev_event->detail % 8));
break;
case XI_RawMotion:
+ {
mouse_moved = true;
- // always safe because there is always at least one byte in
- // raw_event->valuators.mask, and if a bit is set in the mask,
- // then the value in raw_values is also available.
- if (XIMaskIsSet(raw_event->valuators.mask, 0))
- {
- delta_delta = raw_event->raw_values[0];
- // test for inf and nan
- if (delta_delta == delta_delta && 1 + delta_delta != delta_delta)
- delta_x += delta_delta;
- }
- if (XIMaskIsSet(raw_event->valuators.mask, 1))
- {
- delta_delta = raw_event->raw_values[1];
- // test for inf and nan
- if (delta_delta == delta_delta && 1 + delta_delta != delta_delta)
- delta_y += delta_delta;
- }
- if (XIMaskIsSet(raw_event->valuators.mask, 3))
+ float values[4] = {};
+ size_t value_idx = 0;
+
+ // We only care about the first 4 axes, which should always be available at minimum
+ for (int i = 0; i < 4; ++i)
{
- // Scroll wheel input gets scaled to be similar to the mouse axes
- delta_delta = raw_event->raw_values[0] * 8.0 / scroll_increment;
- // test for inf and nan
- if (delta_delta == delta_delta && 1 + delta_delta != delta_delta)
- delta_z += delta_delta;
+ if (XIMaskIsSet(raw_event->valuators.mask, i))
+ {
+ values[i] = raw_event->raw_values[value_idx++];
+ }
}
+
+ delta_delta = values[0];
+ // test for inf and nan
+ if (delta_delta == delta_delta && 1 + delta_delta != delta_delta)
+ delta_x += delta_delta;
+
+ delta_delta = values[1];
+ // test for inf and nan
+ if (delta_delta == delta_delta && 1 + delta_delta != delta_delta)
+ delta_y += delta_delta;
+
+ // Scroll wheel input gets scaled to be similar to the mouse axes
+ delta_delta = values[3] * 8.0 / scroll_increment;
+ // test for inf and nan
+ if (delta_delta == delta_delta && 1 + delta_delta != delta_delta)
+ delta_z += delta_delta;
+
break;
+ }
case XI_FocusOut:
// Clear keyboard state on FocusOut as we will not be receiving KeyRelease events.
m_state.keyboard.fill(0);