Skip to content

fix(linux): redraw windows when late fallback preference reads resolve and sync preference tests on condvar - #2128

Merged
Hona merged 1 commit into
devfrom
fix/noticed-platform-prefs-timeout
Nov 25, 2026
Merged

Hona merged 1 commit into
devfrom
fix/noticed-platform-prefs-timeout

Conversation

@Hona

@Hona Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member

Root cause

Platform audit of reduced_motion() and double_click_interval():

  • macOS, Windows, Web: do not use CachedReducedMotion / CachedDoubleClick (macOS reads NSWorkspace / NSEvent synchronously with live NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification; Windows reads SystemParametersInfoW / GetDoubleClickTime synchronously; Web receives matchMedia events).
  • Linux with dbus (default): portal_appearance.rs waits up to 100 ms at launch, then updates atomics and calls redraw_windows() when a late answer arrives so open windows immediately reread preferences::reduced_motion() and preferences::double_click_interval().
  • Linux without dbus (--no-default-features): CachedReducedMotion (fix(linux): follow Settings portal reduced-motion off the UI thread and cache fallback #1766) and CachedDoubleClick (feat(linux): read double-click interval from XDG Settings portal with kdeglobals and GSettings fallback #1923) in crates/rune/src/platform/preferences.rs waited 100 ms (FIRST_ANSWER) and returned the default (false / 0.5 s) on timeout. When the worker finished late, it wrote the real value into its atomic (so a later redraw/focus change would read it), but never notified open windows or overlays to redraw—leaving an idle window on the default until an unrelated redraw or focus change.
  • In crates/rune/src/platform/preferences_tests.rs, cached_fallback_reads_once_off_the_calling_thread and cached_double_click_fallback_reads_once_off_the_calling_thread asserted the worker's answer on the first get_or_init call without waiting for the worker thread, so under heavy CPU load they raced the 100 ms launch timeout.

Changes

  • crates/rune/src/platform/preferences.rs:
    • replace OnceLock + Atomic* + mpsc::sync_channel in CachedReducedMotion and CachedDoubleClick with an explicit CacheState<T> (Unstarted / Pending { timed_out } / Ready { value, late_changed }) state machine backed by Mutex + Condvar, keeping FIRST_ANSWER = 100 ms so launch never waits longer.
    • when a slow worker resolves to a non-default value after a caller timed out, invoke on_late (redraw_fallback_windows()) outside the lock; register Linux non-dbus windows in preferences::window_dark and overlays in crates/rune/src/overlay/lifetime.rs via follow_fallback(&window) (which also requests a redraw if a late non-default answer already landed before registration).
    • expose #[cfg(test)] helpers get_or_init_with, wait_ready, and late_changed.
  • crates/rune/src/platform/preferences_tests.rs:
    • synchronize the three existing cached-fallback tests on wait_ready() instead of racing the 100 ms launch timeout.
    • add deterministic gate-driven tests slow_reduced_motion_fallback_returns_default_then_publishes_and_notifies_on_late_answer and slow_double_click_fallback_returns_default_then_publishes_and_notifies_on_late_answer (using Duration::ZERO wait and a Condvar gate, no sleeps).
  • changelog/unreleased/2026-11-25-platform-prefs-late-redraw.md: record the fix.

Verification

  • Windows: all 9 platform::preferences:: tests passed 208/208 under 64-thread CPU load; platform:: and no_motion passed; cargo clippy -p rune --lib --bins --tests (0 errors), cargo check-wasm (0 errors), and scripts/file-size.sh passed.
  • macOS: cargo test -p rune --lib platform:: (290/290) and cargo clippy -p rune --lib --bins --tests (0 errors) passed.
  • Linux: cargo clippy -p rune --lib --bins --tests (with dbus) and cargo clippy -p rune --no-default-features --lib --bins --tests (without dbus) both passed with 0 errors (compiled in Linux aarch64 container, not executed there).

@Hona
Hona merged commit 3a883a0 into dev Nov 25, 2026
@Hona
Hona deleted the fix/noticed-platform-prefs-timeout branch November 25, 2026 05:16
Hona added a commit that referenced this pull request Nov 25, 2026
…une and procwatch (#2370)

A feature-set warning sweep across Linux, macOS, Windows, and wasm32 found
eight dead-code warnings under optional and non-default feature sets:

- `crates/rune/src/open_path.rs:203` (`file_uri_from_bytes`, added in #1947):
  used on Unix only under `feature = "dbus"` (FileManager1) and tests; gate
  with `feature = "dbus"` alongside `test`.
- `crates/rune/src/platform/preferences.rs:77` (`DEFAULT_DOUBLE_CLICK_SECS`,
  added in #1923/#2128): used on Linux only under `feature = "dbus"` and tests;
  gate with `all(target_os = "linux", feature = "dbus")` alongside `test`.
- `crates/rune/src/window/titlebar/linux.rs:82` (`Sides::ALL`, added in #2244):
  used only in `linux_tests.rs`; gate with `#[cfg(test)]`.
- `crates/rune/src/frame/live_log.rs:33` (`CAPTURED` / `capture_frames`, added
  in #2309): used only in `window/win32/resize_sync/tests.rs` under
  `frame-profile`; gate with `#[cfg(all(test, target_os = "windows"))]`.
- `crates/procwatch/src/alloc/sites.rs:222,271,413,418` (`report`, `unsampled`,
  `os::modules`, `os::nt_heaps`, added in #744): `alloc-sites` sampling and
  dumper are Windows-only; gate the implementation behind `#[cfg(windows)]`
  with clean `#[cfg(not(windows))]` no-op stubs.
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