Skip to content

A treemap for finding and removing what fills your disk, for Omarchy. Rust + GPUI.

Rust

app: follow the system's light or dark setting on Windows, GNOME and KDE

Tobi Lütke41328cdc6704
diff --git a/README.md b/README.md
index 708b04b..54e5272 100644
--- a/README.md
+++ b/README.md
@@ -280,8 +280,8 @@ The same program, with Windows' answers to the questions above:
them.
- **Hidden** still means a name starting with a dot; the hidden attribute is
not consulted, so `-H` does not drop `AppData`.
-- **The theme** is gpui-omarchy's default, since there is no Omarchy theme
- to follow.
+- **The theme** follows Windows' light or dark setting, since there is no
+ Omarchy theme to follow. It does on macOS too, and on GNOME and KDE.
## What it refuses to do
diff --git a/crates/disktree-app/src/appearance.rs b/crates/disktree-app/src/appearance.rs
index caa1eb6..274bce6 100644
--- a/crates/disktree-app/src/appearance.rs
+++ b/crates/disktree-app/src/appearance.rs
@@ -1,9 +1,9 @@
//! Light or dark when there is no Omarchy theme to follow.
//!
-//! On Omarchy, gpui-omarchy follows the desktop's theme files. A Mac has none,
-//! and gpui-omarchy would then stay on its dark default whatever the system
-//! is set to; there the app follows the system appearance instead, with the
-//! crate's own dark and light palettes, and switches when it does.
+//! On Omarchy, gpui-omarchy follows the desktop's theme files. Elsewhere there
+//! are none, and gpui-omarchy would then stay on its dark default whatever
+//! the system is set to; there the app follows the system appearance instead,
+//! with the crate's own dark and light palettes, and switches when it does.
use std::path::Path;
@@ -11,9 +11,11 @@ use gpui_kit::{App, Window, WindowAppearance};
use gpui_omarchy::Theme;
/// Whether the system appearance, rather than an Omarchy theme, decides the
-/// colours: on macOS, unless an Omarchy theme is installed there anyway.
+/// colours: unless an Omarchy theme is installed, on macOS and Windows, and
+/// on a Linux desktop that states a preference.
pub fn follows_system(home: Option<&Path>) -> bool {
- cfg!(target_os = "macos")
+ let desktop = std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default();
+ states_a_preference(&desktop)
&& !home.is_some_and(|home| {
[".local/state/omarchy/current", ".config/omarchy/current"]
.iter()
@@ -21,6 +23,18 @@ pub fn follows_system(home: Option<&Path>) -> bool {
})
}
+/// Whether the system has a light or dark setting to follow. macOS and
+/// Windows always do. On Linux GPUI asks the desktop portal, which reads "no
+/// preference" as light: a window manager that never sets one would turn
+/// the app light, so only GNOME and KDE, whose settings do, are followed.
+fn states_a_preference(desktop: &str) -> bool {
+ cfg!(any(target_os = "macos", windows))
+ || desktop.split(':').any(|name| {
+ ["gnome", "kde", "ubuntu", "unity", "pantheon", "cinnamon"]
+ .contains(&name.to_ascii_lowercase().as_str())
+ })
+}
+
/// Apply the palette for `appearance`. Applying an explicit theme also stops
/// gpui-omarchy watching for theme files that are not there.
pub fn apply(appearance: WindowAppearance, cx: &mut App) {
@@ -41,3 +55,17 @@ pub fn follow(window: &Window) {
.observe_window_appearance(|window, cx| apply(window.appearance(), cx))
.detach();
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn a_linux_desktop_is_followed_only_if_it_states_a_preference() {
+ let native = cfg!(any(target_os = "macos", windows));
+ assert!(states_a_preference("ubuntu:GNOME"));
+ assert!(states_a_preference("KDE"));
+ assert_eq!(states_a_preference("Hyprland"), native);
+ assert_eq!(states_a_preference(""), native);
+ }
+}