From 40a0a995afd1f83181ac6fa482286749af31d23a Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 24 Oct 2021 17:51:29 +0200 Subject: [PATCH] WindowServer: Prevent sending duplicate MousePackets when clicking If a mouse button was clicked, `EventLoop::drain_mouse()` would always send the last MousePacket state to the screen input - even if that state is equivalent to the last state sent as part of the button logic. By remembering if the state was already sent, we prevent sending that state a second time saving some resources in the process. --- Userland/Services/WindowServer/EventLoop.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/Services/WindowServer/EventLoop.cpp b/Userland/Services/WindowServer/EventLoop.cpp index fc20cda1f2..b4b3eeee45 100644 --- a/Userland/Services/WindowServer/EventLoop.cpp +++ b/Userland/Services/WindowServer/EventLoop.cpp @@ -86,6 +86,8 @@ void EventLoop::drain_mouse() size_t npackets = nread / sizeof(MousePacket); if (!npackets) return; + + 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); @@ -99,11 +101,13 @@ void EventLoop::drain_mouse() state.y = packet.y; } state.z += packet.z; + state_is_sent = false; if (packet.buttons != state.buttons) { state.buttons = packet.buttons; dbgln_if(WSMESSAGELOOP_DEBUG, "EventLoop: Mouse Button Event"); screen_input.on_receive_mouse_data(state); + state_is_sent = true; if (state.is_relative) { state.x = 0; state.y = 0; @@ -111,6 +115,8 @@ void EventLoop::drain_mouse() } } } + if (state_is_sent) + return; if (state.is_relative && (state.x || state.y || state.z)) screen_input.on_receive_mouse_data(state); if (!state.is_relative)