Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Pond: Combine mouse events into one
Browse files Browse the repository at this point in the history
This reduces IPC load by a considerable amount since mouse events usually come in multiple at a time.
  • Loading branch information
byteduck committed Jun 21, 2024
1 parent c4a8977 commit cd58acf
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions services/pond/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ bool Mouse::update() {
ssize_t nread = read(mouse_fd, &events, sizeof(MouseEvent) * 32);
if(!nread) return false;
int num_events = (int) nread / sizeof(MouseEvent);
Point total_delta {0, 0};
int total_z = 0;

for(int i = 0; i < num_events; i++) {
for(int i = 0; i < 1; i++) {
Gfx::Point new_pos = rect().position();
if(events[i].absolute) {
auto disp_dimensions = Display::inst().dimensions();
Expand All @@ -66,10 +68,22 @@ bool Mouse::update() {
new_pos = new_pos.constrain(parent()->rect());
Gfx::Point delta_pos = new_pos - rect().position();
set_position(new_pos);
_mouse_buttons = events[i].buttons;
Display::inst().create_mouse_events(delta_pos.x, delta_pos.y, events[i].z, _mouse_buttons);
total_delta += delta_pos;
total_z += events[i].z;

// If the mouse buttons changed, send a new event immediately.
// Otherwise, keep running delta totals so we don't create a bunch of unnecessary events
if (_mouse_buttons != events[i].buttons) {
_mouse_buttons = events[i].buttons;
Display::inst().create_mouse_events(total_delta.x, total_delta.y, total_z, _mouse_buttons);
total_delta = {0, 0};
total_z = 0;
}
}

if (total_delta.x != 0 || total_delta.y != 0 || total_z != 0)
Display::inst().create_mouse_events(total_delta.x, total_delta.y, total_z, _mouse_buttons);

return true;
}

Expand Down

0 comments on commit cd58acf

Please sign in to comment.