This commit is contained in:
2026-09-09 11:44:23 +02:00
parent 1367b03b97
commit 50caed0110
3 changed files with 144 additions and 12 deletions
+33 -1
View File
@@ -174,7 +174,39 @@ fn run() -> Result<ExitCode, Box<dyn Error>> {
// A leave only counts once it has failed to come back, because sway also
// cycles focus off and on in a single batch as the pointer crosses us.
loop {
queue.blocking_dispatch(&mut app)?;
// When a navigation key is held, we need to fire repeat events on a
// timer rather than blocking indefinitely. Use a timed poll so we
// wake up when the next repeat is due without burning the CPU.
if let Some(next) = app.repeat_next {
let now = Instant::now();
if now >= next {
let qh = queue.handle();
app.fire_repeat(&qh);
conn.flush()?;
} else {
// Poll for events with a timeout set to when the next repeat fires.
let left = next - now;
queue.dispatch_pending(&mut app)?;
if !app.finished() {
conn.flush()?;
let Some(guard) = conn.prepare_read() else { continue };
let fd = guard.connection_fd();
let mut fds = [PollFd::new(&fd, PollFlags::IN)];
let timeout = Timespec {
tv_sec: left.as_secs() as _,
tv_nsec: left.subsec_nanos() as _,
};
match rustix::event::poll(&mut fds, Some(&timeout)) {
Ok(_) | Err(rustix::io::Errno::INTR) => {}
Err(e) => return Err(Box::new(e)),
}
guard.read()?;
}
continue;
}
} else {
queue.blocking_dispatch(&mut app)?;
}
if !app.finished()
&& !app.focused
&& !pump_for(