Skip to content

fix: process state change events synchronously on main thread#25

Merged
typester merged 1 commit intomainfrom
fix/process-state
Feb 27, 2026
Merged

fix: process state change events synchronously on main thread#25
typester merged 1 commit intomainfrom
fix/process-state

Conversation

@typester
Copy link
Owner

When screenParametersChanged fires, set_displays() migrates nodes in Rust and calls notify() → onStateChange() on the main thread. Previously, onStateChange always used DispatchQueue.main.async, so the migration events were queued rather than processed immediately. This caused handleDisplayChange (which runs right after set_displays returns) to read stale Swift-side nodes, creating windows on the wrong display.

Fix: use MainActor.assumeIsolated to process events synchronously when already on the main thread, ensuring nodes are updated before handleDisplayChange runs. Background thread callbacks (from IPC server) continue to use DispatchQueue.main.async as before.

When screenParametersChanged fires, set_displays() migrates nodes in Rust
and calls notify() → onStateChange() on the main thread. Previously,
onStateChange always used DispatchQueue.main.async, so the migration events
were queued rather than processed immediately. This caused handleDisplayChange
(which runs right after set_displays returns) to read stale Swift-side nodes,
creating windows on the wrong display.

Fix: use MainActor.assumeIsolated to process events synchronously when
already on the main thread, ensuring nodes are updated before
handleDisplayChange runs. Background thread callbacks (from IPC server)
continue to use DispatchQueue.main.async as before.
@typester typester merged commit 61b9f6e into main Feb 27, 2026
2 checks passed
@typester typester deleted the fix/process-state branch February 27, 2026 03:57
typester pushed a commit that referenced this pull request Feb 27, 2026
🤖 I have created a release *beep* *boop*
---


## [0.1.11](v0.1.10...v0.1.11)
(2026-02-27)


### Features

* add version subcommand to CLI
([#26](#26))
([9c253e5](9c253e5))


### Bug Fixes

* process state change events synchronously on main thread
([#25](#25))
([61b9f6e](61b9f6e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant