Skip to content

Linux: the reduced-motion preference is read from disk on the UI thread on every focus change #655

Done

Description

@adeerkhan

crates/rune/src/platform/preferences.rs:26-39

pub(crate) fn reduced_motion() -> bool {
    ...
    if std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default().split(':').any(|d| d.eq_ignore_ascii_case("KDE"))
        && let Some(config) = config
        && let Ok(contents) = std::fs::read_to_string(config.join("kdeglobals"))
        ...

On KDE, every call opens, reads and closes ~/.config/kdeglobals synchronously on the UI thread,
uncached, and then falls through to a GLib schema lookup and g_settings_get_boolean.

It is called from:

  • crates/rune/src/window/events.rs:354 — the WindowEvent::Focused handler (every focus change);
  • crates/rune/src/window.rs:540 — window setup;
  • crates/rune/src/overlay.rs:391 and crates/rune/src/overlay/any_host.rs:129 — both overlay hosts, on focus.

This breaks the rule AGENTS.md states for this repo:

No file I/O in the frame loop: never read, stat, write, sync or rename a file on the UI thread
during frames, input or animation. On Windows each open and MoveFileExW rename runs antivirus
filter callbacks and can fail with a sharing violation.

A focus change is input handling. On a network home directory (~/.config on NFS or a redirected
profile) the read can stall the UI thread for hundreds of milliseconds, right when the user clicks
into the window.

The macOS and Windows branches use native APIs and are cheap; only the Linux/KDE branch touches
the filesystem.

Fix

Cache the answer and refresh it from the existing change sources (or a settings-portal
subscription, as portal_appearance already does for color-scheme), so focus handling does no
I/O.

Related: #527 asks for more Settings portal keys with change signals — this is the file-read path
it would replace.

Activity

  1. purian23 commented on Nov 12, 2026

    @purian23

    There's another cost in the same lookup: the GSettings read dlopens libgio, and GLib's D-Bus, main-loop, dconf and thread-pool threads then stay for the life of the process.

    For apps that supply reduced motion themselves (Cx::reduced_motion), our stopgap is an opt-out called before run (rune::leave_reduced_motion_to_app()), so Rune never looks it up. Reading it from the settings portal (#527) would remove both costs.

  2. Hona commented on Nov 23, 2026

    @Hona
    Member

    Fixed on dev in #1766 (5126d252c).

    Previously, crates/rune/src/platform/preferences.rs read ~/.config/kdeglobals synchronously and dlopened libgio-2.0.so.0 on the UI thread on every focus change. Following Google Chrome (ui/gfx/animation/animation.cc, ui/linux/portal_settings_linux.cc, components/dbus/thread_linux/dbus_thread_linux.cc), GTK 4 (gdk/wayland/gdksettings-wayland.c), Qt 6 (QXdgDesktopPortalTheme), and the XDG Desktop Portal org.freedesktop.portal.Settings specification, Linux reduced motion is now cached in memory and kept up to date off the UI thread from org.freedesktop.appearance reduced-motion and org.gnome.desktop.interface enable-animations via SettingChanged on the shared portal worker thread. The kdeglobals / GSettings fallback now runs at most once off the UI thread only when the portal answers neither key (or when the dbus feature is off), avoiding both focus-time file I/O and unnecessary libgio loading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions