diff --git a/Servers/WindowServer/WSEventLoop.cpp b/Servers/WindowServer/WSEventLoop.cpp index b45a1f2d86a..3c9d10e125a 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 20875e962e0..a7527e28161 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;