Skip to main content

system_is_dark

Function system_is_dark 

Source
pub fn system_is_dark() -> bool
Expand description

Detect whether the system is using a dark color scheme.

Uses synchronous, platform-specific checks so the result is available immediately at window creation time (before any async portal response).

§Caching

The result is cached after the first call and reused on subsequent calls. Call invalidate_caches() to clear the cached value so the next call re-queries the OS. For a fresh reading without affecting the cache, use detect_is_dark() instead.

For live dark-mode tracking, subscribe to OS appearance-change events (D-Bus SettingChanged on Linux, NSAppearance KVO on macOS, UISettings.ColorValuesChanged on Windows) and call SystemTheme::from_system() to get a fresh SystemTheme with updated resolved variants.

§Platform Behavior

  • Linux: Checks GTK_THEME env var for :dark suffix or -dark in name; queries gsettings for color-scheme (with 2-second timeout); falls back to KDE kdeglobals background luminance (with kde feature); reads gtk-3.0/settings.ini for gtk-application-prefer-dark-theme=1 as final fallback.
  • macOS: Reads AppleInterfaceStyle via NSUserDefaults (with macos feature) or defaults subprocess (without).
  • Windows: Checks foreground color luminance from UISettings via BT.601 coefficients (requires windows feature).
  • Other platforms / missing features: Returns false (light).