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, use watch::on_theme_change (feature watch): on each event call invalidate_caches() and re-read crate::SystemTheme::from_system().

§Platform Behavior

  • Linux: Checks GTK_THEME for :dark or -dark; on KDE (with the kde feature) reads kdeglobals’ background luminance; then gsettings color-scheme (2-second timeout); then kdeglobals on other desktops (with kde); finally gtk-3.0/settings.ini gtk-application-prefer-dark-theme.
  • 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).