From 3a0e102afcac028a4dd98035ba992d84b48aca81 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 25 May 2025 15:52:27 +0100 Subject: [PATCH] feat: change `icon_overrides` to apply to all resolved images --- docs/Configuration guide.md | 12 ++++++------ src/bar.rs | 26 +++----------------------- src/image/provider.rs | 5 +---- src/main.rs | 5 +---- src/modules/keyboard.rs | 6 +----- src/modules/launcher/item.rs | 14 ++------------ src/modules/launcher/pagination.rs | 14 ++++---------- 7 files changed, 18 insertions(+), 64 deletions(-) diff --git a/docs/Configuration guide.md b/docs/Configuration guide.md index a93b7c6..fd92b50 100644 --- a/docs/Configuration guide.md +++ b/docs/Configuration guide.md @@ -280,11 +280,12 @@ Check [here](config) for an example config file for a fully configured bar in ea The following table lists each of the top-level bar config options: -| Name | Type | Default | Description | -|--------------------|-----------------------------------------|---------|-------------------------------------------------------------------------------| -| `ironvar_defaults` | `Map` | `{}` | Map of [ironvar](ironvars) keys against their default values. | -| `monitors` | `Map` | `null` | Map of monitor names against bar configs. | -| `icon_overrides` | `Map` | `{}` | Map of app IDs (or classes) to icon names, overriding the app's default icon. | +| Name | Type | Default | Description | +|--------------------|-----------------------------------------|---------|--------------------------------------------------------------------------------------------------------------------------------| +| `ironvar_defaults` | `Map` | `{}` | Map of [ironvar](ironvars) keys against their default values. | +| `monitors` | `Map` | `null` | Map of monitor names against bar configs. | +| `icon_theme` | `string` | `null` | Name of the GTK icon theme to use. Leave blank to use default. | +| `icon_overrides` | `Map` | `{}` | Map of image inputs to override names. Usually used for app IDs (or classes) to icon names, overriding the app's default icon. | > [!TIP] > `monitors` is only required if you are following **2b** or **2c** (ie not the same bar across all monitors). @@ -309,7 +310,6 @@ The following table lists each of the bar-level bar config options: | `layer` | `background` or `bottom` or `top` or `overlay` | `top` | The layer-shell layer to place the bar on. | | `exclusive_zone` | `boolean` | `true` unless `start_hidden` is enabled. | Whether the bar should reserve an exclusive zone around it. | | `popup_gap` | `integer` | `5` | The gap between the bar and popup window. | -| `icon_theme` | `string` | `null` | Name of the GTK icon theme to use. Leave blank to use default. | | `start_hidden` | `boolean` | `false`, or `true` if `autohide` set | Whether the bar should be hidden when the application starts. Enabled by default when `autohide` is set. | | `autohide` | `integer` | `null` | The duration in milliseconds before the bar is hidden after the cursor leaves. Leave unset to disable auto-hide behaviour. | | `start` | `Module[]` | `[]` | Array of left or top modules. | diff --git a/src/bar.rs b/src/bar.rs index 8ec6ae2..1056f46 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -6,11 +6,9 @@ use color_eyre::Result; use glib::Propagation; use gtk::gdk::Monitor; use gtk::prelude::*; -use gtk::{Application, ApplicationWindow, IconTheme, Orientation, Window, WindowType}; +use gtk::{Application, ApplicationWindow, Orientation, Window, WindowType}; use gtk_layer_shell::LayerShell; -use std::collections::HashMap; use std::rc::Rc; -use std::sync::Arc; use std::time::Duration; use tracing::{debug, info}; @@ -25,7 +23,6 @@ pub struct Bar { name: String, monitor_name: String, monitor_size: (i32, i32), - icon_overrides: Arc>, position: BarPosition, ironbar: Rc, @@ -46,7 +43,6 @@ impl Bar { app: &Application, monitor_name: String, monitor_size: (i32, i32), - icon_overrides: Arc>, config: BarConfig, ironbar: Rc, ) -> Self { @@ -96,7 +92,6 @@ impl Bar { name, monitor_name, monitor_size, - icon_overrides, position, ironbar, window, @@ -257,11 +252,6 @@ impl Bar { monitor: &Monitor, output_size: (i32, i32), ) -> Result { - let icon_theme = IconTheme::new(); - if let Some(ref theme) = config.icon_theme { - icon_theme.set_custom_theme(Some(theme)); - } - let app = &self.window.application().expect("to exist"); macro_rules! info { @@ -272,15 +262,13 @@ impl Bar { monitor, output_name: &self.monitor_name, location: $location, - icon_theme: &icon_theme, - icon_overrides: self.icon_overrides.clone(), } }; } // popup ignores module location so can bodge this for now let popup = Popup::new( - self.ironbar.clone(), + &self.ironbar, &info!(ModuleLocation::Left), output_size, config.popup_gap, @@ -404,17 +392,9 @@ pub fn create_bar( monitor: &Monitor, monitor_name: String, monitor_size: (i32, i32), - icon_overrides: Arc>, config: BarConfig, ironbar: Rc, ) -> Result { - let bar = Bar::new( - app, - monitor_name, - monitor_size, - icon_overrides, - config, - ironbar, - ); + let bar = Bar::new(app, monitor_name, monitor_size, config, ironbar); bar.init(monitor) } diff --git a/src/image/provider.rs b/src/image/provider.rs index 0cdd33a..7fd0db8 100644 --- a/src/image/provider.rs +++ b/src/image/provider.rs @@ -166,10 +166,7 @@ impl Provider { ) -> Result> { const MAX_RECURSE_DEPTH: u8 = 2; - let input = self - .overrides - .get(input) - .map_or(input, String::as_str); + let input = self.overrides.get(input).map_or(input, String::as_str); let should_parse_desktop_file = !Self::is_explicit_input(input); diff --git a/src/main.rs b/src/main.rs index 760d83c..856be26 100644 --- a/src/main.rs +++ b/src/main.rs @@ -394,7 +394,7 @@ fn load_output_bars( }; let config = ironbar.config.borrow(); - let icon_overrides = Arc::new(config.icon_overrides.clone()); + let display = get_display(); let pos = output.logical_position.unwrap_or_default(); @@ -416,7 +416,6 @@ fn load_output_bars( &monitor, monitor_name.to_string(), output_size, - icon_overrides, config.clone(), ironbar.clone(), )?] @@ -429,7 +428,6 @@ fn load_output_bars( &monitor, monitor_name.to_string(), output_size, - icon_overrides.clone(), config.clone(), ironbar.clone(), ) @@ -440,7 +438,6 @@ fn load_output_bars( &monitor, monitor_name.to_string(), output_size, - icon_overrides, config.bar.clone(), ironbar.clone(), )?], diff --git a/src/modules/keyboard.rs b/src/modules/keyboard.rs index f09da0c..0ad98ee 100644 --- a/src/modules/keyboard.rs +++ b/src/modules/keyboard.rs @@ -261,11 +261,7 @@ impl Module for KeyboardModule { let caps = IconLabel::new(&self.icons.caps_off, self.icon_size, &image_provider); let num = IconLabel::new(&self.icons.num_off, self.icon_size, &image_provider); - let scroll = IconLabel::new( - &self.icons.scroll_off, - self.icon_size, - &image_provider, - ); + let scroll = IconLabel::new(&self.icons.scroll_off, self.icon_size, &image_provider); caps.label().set_angle(self.layout.angle(info)); caps.label().set_justify(self.layout.justify.into()); diff --git a/src/modules/launcher/item.rs b/src/modules/launcher/item.rs index 0b655ab..e25c43e 100644 --- a/src/modules/launcher/item.rs +++ b/src/modules/launcher/item.rs @@ -23,23 +23,16 @@ pub struct Item { pub open_state: OpenState, pub windows: IndexMap, pub name: String, - pub icon_override: String, } impl Item { - pub fn new( - app_id: String, - icon_override: String, - open_state: OpenState, - favorite: bool, - ) -> Self { + pub fn new(app_id: String, open_state: OpenState, favorite: bool) -> Self { Self { app_id, favorite, open_state, windows: IndexMap::new(), name: String::new(), - icon_override, } } @@ -114,7 +107,6 @@ impl From for Item { open_state, windows, name, - icon_override: String::new(), } } } @@ -179,9 +171,7 @@ impl ItemButton { } if appearance.show_icons { - let input = if !item.icon_override.is_empty() { - item.icon_override.clone() - } else if item.app_id.is_empty() { + let input = if item.app_id.is_empty() { item.name.clone() } else { item.app_id.clone() diff --git a/src/modules/launcher/pagination.rs b/src/modules/launcher/pagination.rs index 2a23b60..804ee33 100644 --- a/src/modules/launcher/pagination.rs +++ b/src/modules/launcher/pagination.rs @@ -30,17 +30,11 @@ impl Pagination { ) -> Self { let scroll_box = gtk::Box::new(orientation, 0); - let scroll_back = IconButton::new( - icon_context.back, - icon_context.size, - image_provider.clone(), - ); + let scroll_back = + IconButton::new(icon_context.back, icon_context.size, image_provider.clone()); - let scroll_fwd = IconButton::new( - icon_context.fwd, - icon_context.size, - image_provider.clone(), - ); + let scroll_fwd = + IconButton::new(icon_context.fwd, icon_context.size, image_provider.clone()); scroll_back.set_sensitive(false); scroll_fwd.set_sensitive(false);