mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
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.
This commit is contained in:
parent
38b09ba133
commit
40a0a995af
1 changed files with 6 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue