Skip to content

Commit 3e0bda3

Browse files
committed
[x11] Reduce MotionNotify events processing rate
1 parent 7d86c17 commit 3e0bda3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

os/x11/event_queue.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ void EventQueueX11::getEvent(Event& ev, double timeout)
132132
// key pressed.
133133
const bool removeRepeats = (!WindowX11::translateDeadKeys());
134134

135+
XEvent lastXMotion;
136+
lastXMotion.type = 0;
135137
for (int i = 0; i < events; ++i) {
136138
XNextEvent(display, &event);
137139

@@ -158,10 +160,31 @@ void EventQueueX11::getEvent(Event& ev, double timeout)
158160
processX11Event(event2);
159161
}
160162
else {
163+
// We discard most motion events because they are sent at a too high rate.
164+
// Instead we can just keep the latest, and process it when appropriate.
165+
if (event.type == MotionNotify) {
166+
lastXMotion = event;
167+
continue;
168+
}
169+
170+
// When an Enter/Leave/ButtonPress/ButtonRelease is received we cannot
171+
// delay the latest motion event further, because the order of the events must
172+
// be preserved in these cases.
173+
if (lastXMotion.type == MotionNotify &&
174+
(event.type == EnterNotify || event.type == LeaveNotify || event.type == ButtonPress ||
175+
event.type == ButtonRelease)) {
176+
processX11Event(lastXMotion);
177+
lastXMotion.type = 0;
178+
}
179+
161180
processX11Event(event);
162181
}
163182
}
164183

184+
// If there is a pending motion event, process it now.
185+
if (lastXMotion.type == MotionNotify)
186+
processX11Event(lastXMotion);
187+
165188
if (!m_events.try_pop(ev))
166189
ev.setType(Event::None);
167190
}

0 commit comments

Comments
 (0)