feat: Default GTK theme without dependencies
The following patch relies on `gsettings`, which should be installed by the GTK suite on most distros, instead of linking with GTK.
This commit is contained in:
parent
c6c8962d87
commit
8470bb3183
1 changed files with 36 additions and 0 deletions
36
src/lib.rs
36
src/lib.rs
|
|
@ -89,6 +89,42 @@ pub fn list_themes() -> Vec<&'static str> {
|
||||||
themes
|
themes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the default GTK theme if set.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```rust
|
||||||
|
/// use freedesktop_icons::default_theme_gtk;
|
||||||
|
///
|
||||||
|
/// let theme = default_theme_gtk();
|
||||||
|
///
|
||||||
|
/// assert_eq!(Some("Adwaita"), theme);
|
||||||
|
/// ```
|
||||||
|
pub fn default_theme_gtk() -> Option<&'static str> {
|
||||||
|
// Calling gsettings is the simplest way to retrieve the default icon theme without adding
|
||||||
|
// GTK as a dependency. There seems to be several ways to set the default GTK theme
|
||||||
|
// including a file in XDG_CONFIG_HOME as well as an env var. Gsettings is the most
|
||||||
|
// straightforward method.
|
||||||
|
let gsettings = std::process::Command::new("gsettings")
|
||||||
|
.args(["get", "org.gnome.desktop.interface", "icon-theme"])
|
||||||
|
.output()
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
|
// Only return the theme if it's in the cache.
|
||||||
|
if gsettings.status.success() {
|
||||||
|
let name = String::from_utf8(gsettings.stdout).ok()?;
|
||||||
|
let name = name.trim().trim_matches('\'');
|
||||||
|
THEMES.get(name).and_then(|themes| {
|
||||||
|
themes.first().and_then(|path| {
|
||||||
|
path.index
|
||||||
|
.section(Some("Icon Theme"))
|
||||||
|
.and_then(|section| section.get("Name"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The lookup builder struct, holding all the lookup query parameters.
|
/// The lookup builder struct, holding all the lookup query parameters.
|
||||||
pub struct LookupBuilder<'a> {
|
pub struct LookupBuilder<'a> {
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue