mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
Coalesce mouse events to make the GUI go fast.
A simple but effective optimization that avoids tons of redraw. :^)
This commit is contained in:
parent
57b13274da
commit
07873332e7
Notes:
sideshowbarker
2024-07-19 16:04:23 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/07873332e79
2 changed files with 16 additions and 3 deletions
|
@ -66,11 +66,26 @@ void EventLoop::postEvent(Object* receiver, OwnPtr<Event>&& event)
|
|||
void EventLoop::waitForEvent()
|
||||
{
|
||||
auto& mouse = PS2MouseDevice::the();
|
||||
auto& screen = AbstractScreen::the();
|
||||
bool prev_left_button = screen.left_mouse_button_pressed();
|
||||
bool prev_right_button = screen.right_mouse_button_pressed();
|
||||
int dx = 0;
|
||||
int dy = 0;
|
||||
while (mouse.has_data_available_for_reading()) {
|
||||
signed_byte data[3];
|
||||
ssize_t nread = mouse.read((byte*)data, 3);
|
||||
ASSERT(nread == 3);
|
||||
AbstractScreen::the().on_receive_mouse_data(data[1], -data[2], data[0] & 1, data[0] & 2);
|
||||
bool left_button = data[0] & 1;
|
||||
bool right_button = data[0] & 2;
|
||||
dx += data[1];
|
||||
dy += -data[2];
|
||||
if (left_button != prev_left_button || right_button != prev_right_button || !mouse.has_data_available_for_reading()) {
|
||||
prev_left_button = left_button;
|
||||
prev_right_button = right_button;
|
||||
screen.on_receive_mouse_data(dx, dy, left_button, right_button);
|
||||
dx = 0;
|
||||
dy = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -19,6 +19,4 @@ void Rect::intersect(const Rect& other)
|
|||
m_location.setY(t);
|
||||
m_size.setWidth((r - l) + 1);
|
||||
m_size.setHeight((b - t) + 1);
|
||||
|
||||
dbgprintf("intersection result: %d,%d %dx%d\n", x(), y(), width(), height());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue