whoami/
desktop_env.rs

1use alloc::string::String;
2use core::fmt::{self, Display, Formatter};
3
4/// The desktop environment of a system
5#[derive(Debug, PartialEq, Eq, Clone)]
6#[non_exhaustive]
7pub enum DesktopEnvironment {
8    /// Unknown desktop environment
9    Unknown(String),
10    /// Running as Web Assembly on a web page
11    WebBrowser(String),
12    /// Popular GTK-based desktop environment on Linux
13    Gnome,
14    /// One of the desktop environments for a specific version of Windows
15    Windows,
16    /// Linux desktop environment optimized for low resource requirements
17    Lxde,
18    /// Stacking window manager for X Windows on Linux
19    Openbox,
20    /// Desktop environment for Linux, BSD and illumos
21    Mate,
22    /// Lightweight desktop enivornment for unix-like operating systems
23    Xfce,
24    /// KDE Plasma desktop enviroment
25    Plasma,
26    /// Default desktop environment on Linux Mint
27    Cinnamon,
28    /// Tiling window manager for Linux
29    I3,
30    /// Desktop environment for MacOS
31    Aqua,
32    /// Desktop environment for iOS
33    Ios,
34    /// Desktop environment for Android
35    Android,
36    /// A desktop environment for a video game console
37    Console,
38    /// Ubuntu-branded GNOME
39    Ubuntu,
40    /// Default shell for Fuchsia
41    Ermine,
42    /// Default desktop environment for Redox
43    Orbital,
44    /// Wayland scrolling window manager for Linux
45    Niri,
46    /// Wayland tiling window manager for Linux
47    Hyprland,
48    /// Rust based desktop environment on Linux
49    Cosmic,
50}
51
52impl Display for DesktopEnvironment {
53    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
54        if let Self::Unknown(_) = self {
55            f.write_str("Unknown: ")?;
56        }
57
58        f.write_str(match self {
59            Self::Unknown(de) => de,
60            Self::WebBrowser(de) => return write!(f, "WebBrowser ({de})"),
61            Self::Gnome => "Gnome",
62            Self::Windows => "Windows",
63            Self::Lxde => "LXDE",
64            Self::Openbox => "Openbox",
65            Self::Mate => "Mate",
66            Self::Xfce => "XFCE",
67            Self::Plasma => "KDE Plasma",
68            Self::Cinnamon => "Cinnamon",
69            Self::I3 => "I3",
70            Self::Aqua => "Aqua",
71            Self::Ios => "IOS",
72            Self::Android => "Android",
73            Self::Console => "Console",
74            Self::Ubuntu => "Ubuntu",
75            Self::Ermine => "Ermine",
76            Self::Orbital => "Orbital",
77            Self::Niri => "Niri",
78            Self::Hyprland => "Hyprland",
79            Self::Cosmic => "Cosmic",
80        })
81    }
82}
83
84impl DesktopEnvironment {
85    /// Returns true if the desktop environment is based on GTK.
86    #[must_use]
87    pub const fn is_gtk(&self) -> bool {
88        matches!(
89            self,
90            Self::Gnome
91                | Self::Ubuntu
92                | Self::Cinnamon
93                | Self::Lxde
94                | Self::Mate
95                | Self::Xfce
96                | Self::Niri
97        )
98    }
99
100    /// Returns true if the desktop environment is based on KDE.
101    #[must_use]
102    pub const fn is_kde(&self) -> bool {
103        matches!(self, Self::Plasma)
104    }
105}