Make monitor hotplug display update non-blocking - #3
Conversation
|
Reviewed. This one doesn't even depend on Nix package availability —
Same caveat as the other PRs in this batch: no agent can trigger |
wm/update-displays called (sleep-for 2) synchronously on every exwm-randr-screen-change-hook firing. Since Emacs is single-threaded, this froze the entire WM/editor session for 2 full seconds on every monitor connect/disconnect. Replaced with run-with-timer: the hook returns immediately and the actual xrandr reconfiguration runs 2 seconds later, off the main thread's blocking path. Debounced via a module-level timer variable so a second hotplug event during that 2s window (e.g. plugging in two monitors close together) cancels and reschedules the wait instead of running the reconfiguration twice.
a96c3b3 to
4cfc009
Compare
|
@yottanami This one's waiting on you — no agent can trigger a real monitor hotplug or watch Emacs stay responsive during the wait, so per policy it holds for your confirmation before merge (see the review comment above for what was statically verified). Steps:
|
Summary
wm/update-displays(hooked toexwm-randr-screen-change-hook, which fires on every monitor connect/disconnect) called(sleep-for 2)synchronously. Since Emacs is single-threaded, this froze the entire WM/editor session for 2 full seconds every time.Replaced with
run-with-timer: the hook function now returns immediately, and the actualxrandrreconfiguration + workspace-monitor remapping runs 2 seconds later, off the blocking path. The 2s settle delay itself is preserved (per the issue: "if the delay exists to let hardware settle... keep the delay but make it async"), just non-blocking now.Debounced via a module-level
wm/--update-displays-timervariable: if the hook fires again while a wait is already pending (e.g. plugging in two monitors close together), the pending timer is cancelled and rescheduled rather than letting two reconfigurations run back-to-back. This wasn't strictly required by the issue, but it's the closest non-blocking equivalent to the old synchronous behavior, where a second hook firing simply couldn't start until the firstsleep-forfinished — without it, rapid hotplug events could double-run the xrandr command.Closes Men-in-Black-5/ideas#20
Test plan
nix/emacsbinary in my environment, needs a real check