diff --git a/docs/Configuration guide.md b/docs/Configuration guide.md index 3ff70b0..d63bb67 100644 --- a/docs/Configuration guide.md +++ b/docs/Configuration guide.md @@ -272,6 +272,7 @@ The following table lists each of the top-level bar config options: | `position` | `top` or `bottom` or `left` or `right` | `bottom` | The bar's position on screen. | | `anchor_to_edges` | `boolean` | `false` | Whether to anchor the bar to the edges of the screen. Setting to false centres the bar. | | `height` | `integer` | `42` | The bar's height in pixels. | +| `icon_theme` | `string` | `null` | Name of the GTK icon theme to use. Leave blank to use default. | | `start` | `Module[]` | `[]` | Array of left or top modules. | | `center` | `Module[]` | `[]` | Array of center modules. | | `end` | `Module[]` | `[]` | Array of right or bottom modules. | diff --git a/docs/modules/Focused.md b/docs/modules/Focused.md index d581c77..1397121 100644 --- a/docs/modules/Focused.md +++ b/docs/modules/Focused.md @@ -12,7 +12,6 @@ Displays the title and/or icon of the currently focused window. | `show_icon` | `boolean` | `true` | Whether to show the app's icon | | `show_title` | `boolean` | `true` | Whether to show the app's title | | `icon_size` | `integer` | `32` | Size of icon in pixels | -| `icon_theme` | `string` | `null` | GTK icon theme to use | | `truncate` or `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand version if specifying a length. | | `truncate.length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. | diff --git a/docs/modules/Launcher.md b/docs/modules/Launcher.md index 3ca9936..58784f0 100644 --- a/docs/modules/Launcher.md +++ b/docs/modules/Launcher.md @@ -14,7 +14,6 @@ Optionally displays a launchable set of favourites. | `favorites` | `string[]` | `[]` | List of app IDs (or classes) to always show at the start of the launcher | | `show_names` | `boolean` | `false` | Whether to show app names on the button label. Names will still show on tooltips when set to false. | | `show_icons` | `boolean` | `true` | Whether to show app icons on the button. | -| `icon_theme` | `string` | `null` | GTK icon theme to use. |
JSON diff --git a/src/bar.rs b/src/bar.rs index c5db9a6..333f925 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -8,7 +8,7 @@ use crate::{await_sync, read_lock, send, write_lock, Config}; use color_eyre::Result; use gtk::gdk::{EventMask, Monitor, ScrollDirection}; use gtk::prelude::*; -use gtk::{Application, ApplicationWindow, EventBox, Orientation, Widget}; +use gtk::{Application, ApplicationWindow, EventBox, IconTheme, Orientation, Widget}; use std::sync::{Arc, RwLock}; use tokio::spawn; use tokio::sync::mpsc; @@ -140,6 +140,11 @@ fn load_modules( monitor: &Monitor, output_name: &str, ) -> Result<()> { + let icon_theme = IconTheme::new(); + if let Some(ref theme) = config.icon_theme { + icon_theme.set_custom_theme(Some(theme)); + } + macro_rules! info { ($location:expr) => { ModuleInfo { @@ -148,6 +153,7 @@ fn load_modules( monitor, output_name, location: $location, + icon_theme: &icon_theme, } }; } diff --git a/src/config/mod.rs b/src/config/mod.rs index 51f1d21..f29a2ff 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -73,6 +73,9 @@ pub struct Config { #[serde(default = "default_bar_height")] pub height: i32, + /// GTK icon theme to use. + pub icon_theme: Option, + pub start: Option>, pub center: Option>, pub end: Option>, diff --git a/src/image.rs b/src/image.rs index 31d5440..696c227 100644 --- a/src/image.rs +++ b/src/image.rs @@ -35,6 +35,16 @@ impl<'a> ImageProvider<'a> { Ok(Self { location, size }) } + /// Returns true if the input starts with a prefix + /// that is supported by the parser + /// (ie the parser would not fallback to checking the input). + pub fn is_definitely_image_input(input: &str) -> bool { + input.starts_with("icon:") + || input.starts_with("file://") + || input.starts_with("http://") + || input.starts_with("https://") + } + fn get_location(input: String, theme: &'a IconTheme, size: i32) -> Result { let (input_type, input_name) = input .split_once(':') diff --git a/src/modules/clock.rs b/src/modules/clock.rs index 2156ef9..2d6d6bd 100644 --- a/src/modules/clock.rs +++ b/src/modules/clock.rs @@ -82,7 +82,7 @@ impl Module