From 44ddfd2bf5eef8da6211e9c57e93c773038f261e Mon Sep 17 00:00:00 2001 From: Liav A Date: Tue, 4 Feb 2020 02:38:50 +0200 Subject: [PATCH] WindowServer: Fix the drain mouse mechanism Now we actually check if the Mouse packet relative flag is enabled or not. In addition to that, we have debug messages for mouse point changes. --- Servers/WindowServer/WSEventLoop.cpp | 17 ++++++++++++++--- Servers/WindowServer/WSScreen.cpp | 12 ++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Servers/WindowServer/WSEventLoop.cpp b/Servers/WindowServer/WSEventLoop.cpp index b45a1f2d86..3c9d10e125 100644 --- a/Servers/WindowServer/WSEventLoop.cpp +++ b/Servers/WindowServer/WSEventLoop.cpp @@ -98,8 +98,12 @@ void WSEventLoop::drain_mouse() if (nread == 0) break; ASSERT(nread == sizeof(packet)); +#ifdef WSMESSAGELOOP_DEBUG + dbgprintf("WSEventLoop: Mouse X %d, Y %d, Z %d, relative %d\n", packet.x, packet.y, packet.z, packet.is_relative); +#endif buttons = packet.buttons; + state.is_relative = packet.is_relative; if (packet.is_relative) { state.x += packet.x; state.y -= packet.y; @@ -112,14 +116,21 @@ void WSEventLoop::drain_mouse() if (buttons != state.buttons) { state.buttons = buttons; +#ifdef WSMESSAGELOOP_DEBUG + dbgprintf("WSEventLoop: Mouse Button Event\n"); +#endif screen.on_receive_mouse_data(state); - state.x = 0; - state.y = 0; - state.z = 0; + if (state.is_relative) { + state.x = 0; + state.y = 0; + state.z = 0; + } } } if (state.is_relative && (state.x || state.y || state.z)) screen.on_receive_mouse_data(state); + if (!state.is_relative) + screen.on_receive_mouse_data(state); } void WSEventLoop::drain_keyboard() diff --git a/Servers/WindowServer/WSScreen.cpp b/Servers/WindowServer/WSScreen.cpp index 20875e962e..a7527e2816 100644 --- a/Servers/WindowServer/WSScreen.cpp +++ b/Servers/WindowServer/WSScreen.cpp @@ -105,10 +105,18 @@ void WSScreen::set_buffer(int index) void WSScreen::on_receive_mouse_data(const MousePacket& packet) { auto prev_location = m_cursor_location; - if (packet.is_relative) + if (packet.is_relative) { m_cursor_location.move_by(packet.x, packet.y); - else +#ifdef WSSCREEN_DEBUG + dbgprintf("WSScreen: New Relative mouse point @ X %d, Y %d\n", m_cursor_location.x(), m_cursor_location.y()); +#endif + } else { m_cursor_location = { packet.x * m_width / 0xffff, packet.y * m_height / 0xffff }; +#ifdef WSSCREEN_DEBUG + dbgprintf("WSScreen: New Absolute mouse point @ X %d, Y %d\n", m_cursor_location.x(), m_cursor_location.y()); +#endif + } + m_cursor_location.constrain(rect()); unsigned buttons = packet.buttons;