Skip to main content

SystemTheme

Struct SystemTheme 

Source
pub struct SystemTheme {
    pub name: String,
    pub is_dark: bool,
    pub light: ResolvedThemeVariant,
    pub dark: ResolvedThemeVariant,
    pub preset: String,
    /* private fields */
}
Expand description

Result of the OS-first pipeline. Holds both resolved variants.

Produced by SystemTheme::from_system() and SystemTheme::from_system_async(). Both light and dark are always populated: the OS-active variant comes from the reader + preset + resolve, the inactive variant comes from the preset + resolve.

Fields§

§name: String

Theme name (from reader or preset).

§is_dark: bool

Whether the OS is currently in dark mode.

§light: ResolvedThemeVariant

Resolved light variant (always populated).

§dark: ResolvedThemeVariant

Resolved dark variant (always populated).

§preset: String

The platform preset used (e.g., “kde-breeze”, “adwaita”, “macos-sonoma”).

Implementations§

Source§

impl SystemTheme

Source

pub fn active(&self) -> &ResolvedThemeVariant

Returns the OS-active resolved variant.

If is_dark is true, returns &self.dark; otherwise &self.light.

Source

pub fn pick(&self, is_dark: bool) -> &ResolvedThemeVariant

Pick a resolved variant by explicit preference.

pick(true) returns &self.dark, pick(false) returns &self.light.

Source

pub fn with_overlay(&self, overlay: &ThemeSpec) -> Result<Self>

Apply an app-level TOML overlay and re-resolve.

Merges the overlay onto the pre-resolve ThemeVariant (not the already-resolved ResolvedThemeVariant) so that changed source fields propagate correctly through resolve(). For example, changing defaults.accent in the overlay will cause button.primary_background, checkbox.checked_background, slider.fill, etc. to be re-derived from the new accent color.

§Examples
let system = native_theme::SystemTheme::from_system().unwrap();
let overlay = native_theme::ThemeSpec::from_toml(r##"
    [light.defaults]
    accent = "#ff6600"
    [dark.defaults]
    accent = "#ff6600"
"##).unwrap();
let customized = system.with_overlay(&overlay).unwrap();
// customized.active().defaults.accent is now #ff6600
// and all accent-derived fields are updated
Source

pub fn with_overlay_toml(&self, toml: &str) -> Result<Self>

Apply an app overlay from a TOML string.

Parses the TOML as a ThemeSpec and calls with_overlay.

Source

pub fn from_system() -> Result<Self>

Load the OS theme synchronously.

Detects the platform and desktop environment, reads the current theme settings, merges with a platform preset, and returns a fully resolved SystemTheme with both light and dark variants.

The return value goes through the full pipeline: reader output → resolve → validate → SystemTheme with both light and dark ResolvedThemeVariant variants.

§Platform Behavior
  • macOS: Calls from_macos() when the macos feature is enabled. Reads both light and dark variants via NSAppearance, merges with macos-sonoma preset.
  • Linux (KDE): Calls from_kde() when XDG_CURRENT_DESKTOP contains “KDE” and the kde feature is enabled, merges with kde-breeze preset.
  • Linux (other): Uses the adwaita preset. For live GNOME portal data, use from_system_async() (requires portal-tokio or portal-async-io feature).
  • Windows: Calls from_windows() when the windows feature is enabled, merges with windows-11 preset.
  • Other platforms: Returns Error::Unsupported.
§Errors
  • Error::Unsupported if the platform has no reader or the required feature is not enabled.
  • Error::Unavailable if the platform reader cannot access theme data.
§Examples
let system = native_theme::SystemTheme::from_system().unwrap();
let active = system.active();
Source

pub async fn from_system_async() -> Result<Self>

Async version of from_system() that uses D-Bus portal backend detection to improve desktop environment heuristics on Linux.

When XDG_CURRENT_DESKTOP is unset or unrecognized, queries the D-Bus session bus for portal backend activatable names to determine whether KDE or GNOME portal is running, then dispatches to the appropriate reader.

Returns a SystemTheme with both resolved light and dark variants, same as from_system().

On non-Linux platforms, behaves identically to from_system().

Trait Implementations§

Source§

impl Clone for SystemTheme

Source§

fn clone(&self) -> SystemTheme

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SystemTheme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.