diff options
author | Dmitry Petrov <dpetroff@gmail.com> | 2021-12-13 23:12:01 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-20 10:37:52 +0100 |
commit | d61cc47055e27b007005ac2355728ce54cbbb50b (patch) | |
tree | 4359aab608b0880795f3c97ac11dac6b994eee08 | |
parent | 1afb6d5eca4c8f09768e5437139fe2e73ab0583c (diff) | |
download | serenity-d61cc47055e27b007005ac2355728ce54cbbb50b.zip |
Kernel: Add horizontal mouse scroll support
-rw-r--r-- | Kernel/API/MousePacket.h | 1 | ||||
-rw-r--r-- | Kernel/Devices/HID/MouseDevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Devices/HID/PS2MouseDevice.cpp | 12 | ||||
-rw-r--r-- | Kernel/Devices/VMWareBackdoor.cpp | 14 | ||||
-rw-r--r-- | Userland/Services/WindowServer/EventLoop.cpp | 6 |
5 files changed, 30 insertions, 5 deletions
diff --git a/Kernel/API/MousePacket.h b/Kernel/API/MousePacket.h index 23eebcc2dc..0ab8a5b4ec 100644 --- a/Kernel/API/MousePacket.h +++ b/Kernel/API/MousePacket.h @@ -12,6 +12,7 @@ struct MousePacket { int x { 0 }; int y { 0 }; int z { 0 }; + int w { 0 }; enum Button { LeftButton = 0x01, diff --git a/Kernel/Devices/HID/MouseDevice.cpp b/Kernel/Devices/HID/MouseDevice.cpp index 87441315fa..53d8f90dd9 100644 --- a/Kernel/Devices/HID/MouseDevice.cpp +++ b/Kernel/Devices/HID/MouseDevice.cpp @@ -35,7 +35,7 @@ ErrorOr<size_t> MouseDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& lock.unlock(); dbgln_if(MOUSE_DEBUG, "Mouse Read: Buttons {:x}", packet.buttons); - dbgln_if(MOUSE_DEBUG, "PS2 Mouse: X {}, Y {}, Z {}, Relative {}", packet.x, packet.y, packet.z, packet.buttons); + dbgln_if(MOUSE_DEBUG, "PS2 Mouse: X {}, Y {}, Z {}, W {}, Relative {}", packet.x, packet.y, packet.z, packet.w, packet.buttons); dbgln_if(MOUSE_DEBUG, "PS2 Mouse Read: Filter packets"); size_t bytes_read_from_packet = min(remaining_space_in_buffer, sizeof(MousePacket)); diff --git a/Kernel/Devices/HID/PS2MouseDevice.cpp b/Kernel/Devices/HID/PS2MouseDevice.cpp index fbf8a282b7..57b48c7e76 100644 --- a/Kernel/Devices/HID/PS2MouseDevice.cpp +++ b/Kernel/Devices/HID/PS2MouseDevice.cpp @@ -89,6 +89,7 @@ MousePacket PS2MouseDevice::parse_data_packet(const RawPacket& raw_packet) int x = raw_packet.bytes[1]; int y = raw_packet.bytes[2]; int z = 0; + int w = 0; if (m_has_wheel) { // FIXME: For non-Intellimouse, this is a full byte. // However, for now, m_has_wheel is only set for Intellimouse. @@ -97,6 +98,14 @@ MousePacket PS2MouseDevice::parse_data_packet(const RawPacket& raw_packet) // -1 in 4 bits if (z == 15) z = -1; + + if ((raw_packet.bytes[3] & 0xc0) == 0x40) { + // FIXME: Scroll only functions correctly when the sign is flipped there + w = -z; + z = 0; + } else { + w = 0; + } } bool x_overflow = raw_packet.bytes[0] & 0x40; bool y_overflow = raw_packet.bytes[0] & 0x80; @@ -114,6 +123,7 @@ MousePacket PS2MouseDevice::parse_data_packet(const RawPacket& raw_packet) packet.x = x; packet.y = y; packet.z = z; + packet.w = w; packet.buttons = raw_packet.bytes[0] & 0x07; if (m_has_five_buttons) { @@ -125,7 +135,7 @@ MousePacket PS2MouseDevice::parse_data_packet(const RawPacket& raw_packet) packet.is_relative = true; dbgln_if(PS2MOUSE_DEBUG, "PS2 Relative Mouse: Buttons {:x}", packet.buttons); - dbgln_if(PS2MOUSE_DEBUG, "Mouse: X {}, Y {}, Z {}", packet.x, packet.y, packet.z); + dbgln_if(PS2MOUSE_DEBUG, "Mouse: X {}, Y {}, Z {}, W {}", packet.x, packet.y, packet.z, packet.w); return packet; } diff --git a/Kernel/Devices/VMWareBackdoor.cpp b/Kernel/Devices/VMWareBackdoor.cpp index 4d34eeef0c..285bedd41e 100644 --- a/Kernel/Devices/VMWareBackdoor.cpp +++ b/Kernel/Devices/VMWareBackdoor.cpp @@ -211,16 +211,28 @@ MousePacket VMWareBackdoor::receive_mouse_packet() int x = command.bx; int y = command.cx; int z = static_cast<i8>(command.dx); // signed 8 bit value only! + int w = 0; + + // horizontal scroll is reported as +-2 by qemu + // FIXME: Scroll only functions correctly when the sign is flipped there + if (z == 2) { + w = -1; + z = 0; + } else if (z == -2) { + w = 1; + z = 0; + } if constexpr (PS2MOUSE_DEBUG) { dbgln("Absolute Mouse: Buttons {:x}", buttons); - dbgln("Mouse: x={}, y={}, z={}", x, y, z); + dbgln("Mouse: x={}, y={}, z={}, w={}", x, y, z, w); } MousePacket packet; packet.x = x; packet.y = y; packet.z = z; + packet.w = w; if (buttons & VMMOUSE_LEFT_CLICK) packet.buttons |= MousePacket::LeftButton; if (buttons & VMMOUSE_RIGHT_CLICK) diff --git a/Userland/Services/WindowServer/EventLoop.cpp b/Userland/Services/WindowServer/EventLoop.cpp index 101740f550..1b1831387e 100644 --- a/Userland/Services/WindowServer/EventLoop.cpp +++ b/Userland/Services/WindowServer/EventLoop.cpp @@ -64,7 +64,7 @@ void EventLoop::drain_mouse() bool state_is_sent = false; for (size_t i = 0; i < npackets; ++i) { auto& packet = packets[i]; - dbgln_if(WSMESSAGELOOP_DEBUG, "EventLoop: Mouse X {}, Y {}, Z {}, relative={}", packet.x, packet.y, packet.z, packet.is_relative); + dbgln_if(WSMESSAGELOOP_DEBUG, "EventLoop: Mouse X {}, Y {}, Z {}, W {}, relative={}", packet.x, packet.y, packet.z, packet.w, packet.is_relative); state.is_relative = packet.is_relative; if (packet.is_relative) { @@ -75,6 +75,7 @@ void EventLoop::drain_mouse() state.y = packet.y; } state.z += packet.z; + state.w += packet.w; state_is_sent = false; if (packet.buttons != state.buttons) { @@ -100,12 +101,13 @@ void EventLoop::drain_mouse() state.x = 0; state.y = 0; state.z = 0; + state.w = 0; } } } if (state_is_sent) return; - if (state.is_relative && (state.x || state.y || state.z)) + if (state.is_relative && (state.x || state.y || state.z || state.w)) screen_input.on_receive_mouse_data(state); if (!state.is_relative) screen_input.on_receive_mouse_data(state); |