From 87c680122b673afd50d27a89389a1e04ea8dc48c Mon Sep 17 00:00:00 2001 From: BowDown097 Date: Fri, 10 Jan 2025 19:52:30 -0800 Subject: [PATCH 1/6] feat(launcher): icon overrides --- docs/modules/Launcher.md | 3 ++- src/modules/launcher/item.rs | 14 +++++++++++-- src/modules/launcher/mod.rs | 40 ++++++++++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/docs/modules/Launcher.md b/docs/modules/Launcher.md index 4a68c30..e00371d 100644 --- a/docs/modules/Launcher.md +++ b/docs/modules/Launcher.md @@ -15,7 +15,8 @@ Optionally displays a launchable set of favourites. | | Type | Default | Description | |-----------------------------|---------------------------------------------|----------|--------------------------------------------------------------------------------------------------------------------------| -| `favorites` | `string[]` | `[]` | List of app IDs (or classes) to always show at the start of the launcher | +| `favorites` | `string[]` | `[]` | List of app IDs (or classes) to always show at the start of the launcher. | +| `icon_overrides` | `map` | `{}` | Map of app IDs (or classes) to icon names, overriding the app's default icon. | | `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_size` | `integer` | `32` | Size to render icon at (image icons only). | diff --git a/src/modules/launcher/item.rs b/src/modules/launcher/item.rs index 3b2fa37..0bcd265 100644 --- a/src/modules/launcher/item.rs +++ b/src/modules/launcher/item.rs @@ -24,16 +24,23 @@ 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, open_state: OpenState, favorite: bool) -> Self { + pub fn new( + app_id: String, + icon_override: String, + open_state: OpenState, + favorite: bool, + ) -> Self { Self { app_id, favorite, open_state, windows: IndexMap::new(), name: String::new(), + icon_override, } } @@ -108,6 +115,7 @@ impl From for Item { open_state, windows, name, + icon_override: String::new(), } } } @@ -167,7 +175,9 @@ impl ItemButton { } if appearance.show_icons { - let input = if item.app_id.is_empty() { + let input = if !item.icon_override.is_empty() { + item.icon_override.clone() + } else if item.app_id.is_empty() { item.name.clone() } else { item.app_id.clone() diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index 2359aeb..c302d50 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -15,6 +15,7 @@ use gtk::prelude::*; use gtk::{Button, Orientation}; use indexmap::IndexMap; use serde::Deserialize; +use std::collections::HashMap; use std::process::{Command, Stdio}; use std::sync::Arc; use tokio::sync::{broadcast, mpsc}; @@ -29,6 +30,12 @@ pub struct LauncherModule { /// **Default**: `null` favorites: Option>, + /// Map of app IDs (or classes) to icon names, + /// overriding the app's default icon. + /// + /// **Default**; `null` + icon_overrides: Option>, + /// Whether to show application names on the bar. /// /// **Default**: `false` @@ -149,24 +156,33 @@ impl Module for LauncherModule { favorites .iter() .map(|app_id| { + let icon_override = self + .icon_overrides + .as_ref() + .and_then(|overrides| overrides.get(app_id)) + .map_or_else(String::new, |v| v.to_string()); + ( app_id.to_string(), - Item::new(app_id.to_string(), OpenState::Closed, true), + Item::new(app_id.to_string(), icon_override, OpenState::Closed, true), ) }) .collect::>() }); let items = arc_mut!(items); - let items2 = Arc::clone(&items); + let icon_overrides = arc_mut!(self.icon_overrides.clone()); + let icon_overrides2 = Arc::clone(&icon_overrides); + let tx = context.tx.clone(); let tx2 = context.tx.clone(); let wl = context.client::(); spawn(async move { let items = items2; + let icon_overrides = icon_overrides2; let tx = tx2; let mut wlrx = wl.subscribe_toplevels(); @@ -180,7 +196,16 @@ impl Module for LauncherModule { item.merge_toplevel(info.clone()); } None => { - items.insert(info.app_id.clone(), Item::from(info.clone())); + let mut item = Item::from(info.clone()); + let icon_overrides = lock!(icon_overrides); + + if let Some(overrides) = icon_overrides.as_ref() { + if let Some(icon) = overrides.get(&info.app_id) { + item.icon_override = icon.clone(); + } + } + + items.insert(info.app_id.clone(), item); } } } @@ -210,7 +235,14 @@ impl Module for LauncherModule { let item = items.get_mut(&info.app_id); match item { None => { - let item: Item = info.into(); + let mut item: Item = info.into(); + let icon_overrides = lock!(icon_overrides); + + if let Some(overrides) = icon_overrides.as_ref() { + if let Some(icon) = overrides.get(&app_id) { + item.icon_override = icon.clone(); + } + } items.insert(app_id.clone(), item.clone()); From d1b4af47105e6904d4790f8c9f5fde3929731fe0 Mon Sep 17 00:00:00 2001 From: BowDown097 Date: Thu, 16 Jan 2025 21:39:06 -0800 Subject: [PATCH 2/6] refactor: make icon overrides bar-level and apply to focused module --- docs/Configuration guide.md | 3 ++- docs/modules/Launcher.md | 1 - src/bar.rs | 1 + src/config/mod.rs | 7 +++++++ src/modules/focused.rs | 11 ++++++++++- src/modules/launcher/mod.rs | 11 ++--------- src/modules/mod.rs | 2 ++ 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/docs/Configuration guide.md b/docs/Configuration guide.md index 25e1b22..2b22cd9 100644 --- a/docs/Configuration guide.md +++ b/docs/Configuration guide.md @@ -309,6 +309,7 @@ The following table lists each of the bar-level bar config options: | `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. | +| `icon_overrides` | `map` | `null` | Map of app IDs (or classes) to icon names, overriding the app's default icon. | | `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. | @@ -353,4 +354,4 @@ For information on the `Script` type, and embedding scripts in strings, see [her | `name` | `string` | `null` | Sets the unique widget name, allowing you to style it using `#name`. | | `class` | `string` | `null` | Sets one or more CSS classes, allowing you to style it using `.class`. | -For more information on styling, please see the [styling guide](styling-guide). \ No newline at end of file +For more information on styling, please see the [styling guide](styling-guide). diff --git a/docs/modules/Launcher.md b/docs/modules/Launcher.md index e00371d..2c93432 100644 --- a/docs/modules/Launcher.md +++ b/docs/modules/Launcher.md @@ -16,7 +16,6 @@ Optionally displays a launchable set of favourites. | | Type | Default | Description | |-----------------------------|---------------------------------------------|----------|--------------------------------------------------------------------------------------------------------------------------| | `favorites` | `string[]` | `[]` | List of app IDs (or classes) to always show at the start of the launcher. | -| `icon_overrides` | `map` | `{}` | Map of app IDs (or classes) to icon names, overriding the app's default icon. | | `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_size` | `integer` | `32` | Size to render icon at (image icons only). | diff --git a/src/bar.rs b/src/bar.rs index 518cadb..e54489a 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -268,6 +268,7 @@ impl Bar { output_name: &self.monitor_name, location: $location, icon_theme: &icon_theme, + icon_overrides: &config.icon_overrides, } }; } diff --git a/src/config/mod.rs b/src/config/mod.rs index b4d7371..7d22a51 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -290,6 +290,12 @@ pub struct BarConfig { /// **Default**: `null` pub icon_theme: Option, + /// Map of app IDs (or classes) to icon names, + /// overriding the app's default icon. + /// + /// **Default**; `null` + pub icon_overrides: Option>, + /// An array of modules to append to the start of the bar. /// Depending on the orientation, this is either the top of the left edge. /// @@ -338,6 +344,7 @@ impl Default for BarConfig { start_hidden: None, autohide: None, icon_theme: None, + icon_overrides: None, start: Some(vec![ModuleConfig::Label( LabelModule::new("ℹ️ Using default config".to_string()).into(), )]), diff --git a/src/modules/focused.rs b/src/modules/focused.rs index 250493e..e8f9da3 100644 --- a/src/modules/focused.rs +++ b/src/modules/focused.rs @@ -133,6 +133,7 @@ impl Module for FocusedModule { info: &ModuleInfo, ) -> Result> { let icon_theme = info.icon_theme; + let icon_overrides = info.icon_overrides; let container = gtk::Box::new(info.bar_position.orientation(), 5); @@ -153,9 +154,17 @@ impl Module for FocusedModule { { let icon_theme = icon_theme.clone(); + let icon_overrides = icon_overrides.clone(); glib_recv!(context.subscribe(), data => { - if let Some((name, id)) = data { + if let Some((name, mut id)) = data { if self.show_icon { + + if let Some(ref overrides) = icon_overrides { + if let Some(icon) = overrides.get(&id) { + id = icon.clone(); + } + } + match ImageProvider::parse(&id, &icon_theme, true, self.icon_size) .map(|image| image.load_into_image(&icon)) { diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index c302d50..6f6c1bd 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -15,7 +15,6 @@ use gtk::prelude::*; use gtk::{Button, Orientation}; use indexmap::IndexMap; use serde::Deserialize; -use std::collections::HashMap; use std::process::{Command, Stdio}; use std::sync::Arc; use tokio::sync::{broadcast, mpsc}; @@ -30,12 +29,6 @@ pub struct LauncherModule { /// **Default**: `null` favorites: Option>, - /// Map of app IDs (or classes) to icon names, - /// overriding the app's default icon. - /// - /// **Default**; `null` - icon_overrides: Option>, - /// Whether to show application names on the bar. /// /// **Default**: `false` @@ -156,7 +149,7 @@ impl Module for LauncherModule { favorites .iter() .map(|app_id| { - let icon_override = self + let icon_override = _info .icon_overrides .as_ref() .and_then(|overrides| overrides.get(app_id)) @@ -173,7 +166,7 @@ impl Module for LauncherModule { let items = arc_mut!(items); let items2 = Arc::clone(&items); - let icon_overrides = arc_mut!(self.icon_overrides.clone()); + let icon_overrides = arc_mut!(_info.icon_overrides.clone()); let icon_overrides2 = Arc::clone(&icon_overrides); let tx = context.tx.clone(); diff --git a/src/modules/mod.rs b/src/modules/mod.rs index dfcce62..3528914 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::fmt::Debug; use std::rc::Rc; use std::sync::Arc; @@ -71,6 +72,7 @@ pub struct ModuleInfo<'a> { pub monitor: &'a Monitor, pub output_name: &'a str, pub icon_theme: &'a IconTheme, + pub icon_overrides: &'a Option>, } #[derive(Debug, Clone)] From 40d449e011f83175b9a69251ee827d5a1af32dca Mon Sep 17 00:00:00 2001 From: BowDown097 Date: Tue, 4 Feb 2025 09:48:10 -0800 Subject: [PATCH 3/6] refactor: address requested changes --- docs/Configuration guide.md | 2 +- src/config/mod.rs | 7 ++++--- src/modules/focused.rs | 6 ++---- src/modules/launcher/mod.rs | 21 ++++++++------------- src/modules/mod.rs | 2 +- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/docs/Configuration guide.md b/docs/Configuration guide.md index 2b22cd9..70dfb46 100644 --- a/docs/Configuration guide.md +++ b/docs/Configuration guide.md @@ -309,7 +309,7 @@ The following table lists each of the bar-level bar config options: | `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. | -| `icon_overrides` | `map` | `null` | Map of app IDs (or classes) to icon names, overriding the app's default icon. | +| `icon_overrides` | `Map` | `{}` | Map of app IDs (or classes) to icon names, overriding the app's default icon. | | `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/config/mod.rs b/src/config/mod.rs index 7d22a51..d8aeb95 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -293,8 +293,9 @@ pub struct BarConfig { /// Map of app IDs (or classes) to icon names, /// overriding the app's default icon. /// - /// **Default**; `null` - pub icon_overrides: Option>, + /// **Default**; `{}` + #[serde(default)] + pub icon_overrides: HashMap, /// An array of modules to append to the start of the bar. /// Depending on the orientation, this is either the top of the left edge. @@ -344,7 +345,7 @@ impl Default for BarConfig { start_hidden: None, autohide: None, icon_theme: None, - icon_overrides: None, + icon_overrides: HashMap::default(), start: Some(vec![ModuleConfig::Label( LabelModule::new("ℹ️ Using default config".to_string()).into(), )]), diff --git a/src/modules/focused.rs b/src/modules/focused.rs index e8f9da3..bfb3e9a 100644 --- a/src/modules/focused.rs +++ b/src/modules/focused.rs @@ -159,10 +159,8 @@ impl Module for FocusedModule { if let Some((name, mut id)) = data { if self.show_icon { - if let Some(ref overrides) = icon_overrides { - if let Some(icon) = overrides.get(&id) { - id = icon.clone(); - } + if let Some(icon) = icon_overrides.get(&id) { + id = icon.clone(); } match ImageProvider::parse(&id, &icon_theme, true, self.icon_size) diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index 6f6c1bd..a3c0bb3 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -138,7 +138,7 @@ impl Module for LauncherModule { fn spawn_controller( &self, - _info: &ModuleInfo, + info: &ModuleInfo, context: &WidgetContext, mut rx: mpsc::Receiver, ) -> crate::Result<()> { @@ -149,10 +149,9 @@ impl Module for LauncherModule { favorites .iter() .map(|app_id| { - let icon_override = _info + let icon_override = info .icon_overrides - .as_ref() - .and_then(|overrides| overrides.get(app_id)) + .get(app_id) .map_or_else(String::new, |v| v.to_string()); ( @@ -166,7 +165,7 @@ impl Module for LauncherModule { let items = arc_mut!(items); let items2 = Arc::clone(&items); - let icon_overrides = arc_mut!(_info.icon_overrides.clone()); + let icon_overrides = arc_mut!(info.icon_overrides.clone()); let icon_overrides2 = Arc::clone(&icon_overrides); let tx = context.tx.clone(); @@ -192,10 +191,8 @@ impl Module for LauncherModule { let mut item = Item::from(info.clone()); let icon_overrides = lock!(icon_overrides); - if let Some(overrides) = icon_overrides.as_ref() { - if let Some(icon) = overrides.get(&info.app_id) { - item.icon_override = icon.clone(); - } + if let Some(icon) = icon_overrides.get(&info.app_id) { + item.icon_override = icon.clone(); } items.insert(info.app_id.clone(), item); @@ -231,10 +228,8 @@ impl Module for LauncherModule { let mut item: Item = info.into(); let icon_overrides = lock!(icon_overrides); - if let Some(overrides) = icon_overrides.as_ref() { - if let Some(icon) = overrides.get(&app_id) { - item.icon_override = icon.clone(); - } + if let Some(icon) = icon_overrides.get(&app_id) { + item.icon_override = icon.clone(); } items.insert(app_id.clone(), item.clone()); diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 3528914..484d145 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -72,7 +72,7 @@ pub struct ModuleInfo<'a> { pub monitor: &'a Monitor, pub output_name: &'a str, pub icon_theme: &'a IconTheme, - pub icon_overrides: &'a Option>, + pub icon_overrides: &'a HashMap, } #[derive(Debug, Clone)] From d5e4e08863266d1373c74c7a9f8b75cc27220d38 Mon Sep 17 00:00:00 2001 From: BowDown097 Date: Wed, 5 Feb 2025 07:40:54 -0800 Subject: [PATCH 4/6] refactor: address requested changes (2) --- docs/Configuration guide.md | 10 +++++----- src/bar.rs | 2 +- src/config/mod.rs | 15 +++++++-------- src/modules/focused.rs | 9 ++++----- src/modules/launcher/mod.rs | 6 +----- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/docs/Configuration guide.md b/docs/Configuration guide.md index 70dfb46..50682cf 100644 --- a/docs/Configuration guide.md +++ b/docs/Configuration guide.md @@ -280,10 +280,11 @@ 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. | +| 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. | > [!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: | `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. | -| `icon_overrides` | `Map` | `{}` | Map of app IDs (or classes) to icon names, overriding the app's default icon. | | `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 e54489a..31d619d 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -268,7 +268,7 @@ impl Bar { output_name: &self.monitor_name, location: $location, icon_theme: &icon_theme, - icon_overrides: &config.icon_overrides, + icon_overrides: &self.ironbar.config.borrow().icon_overrides, } }; } diff --git a/src/config/mod.rs b/src/config/mod.rs index d8aeb95..b689bde 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -290,13 +290,6 @@ pub struct BarConfig { /// **Default**: `null` pub icon_theme: Option, - /// Map of app IDs (or classes) to icon names, - /// overriding the app's default icon. - /// - /// **Default**; `{}` - #[serde(default)] - pub icon_overrides: HashMap, - /// An array of modules to append to the start of the bar. /// Depending on the orientation, this is either the top of the left edge. /// @@ -345,7 +338,6 @@ impl Default for BarConfig { start_hidden: None, autohide: None, icon_theme: None, - icon_overrides: HashMap::default(), start: Some(vec![ModuleConfig::Label( LabelModule::new("ℹ️ Using default config".to_string()).into(), )]), @@ -396,6 +388,13 @@ pub struct Config { /// /// Providing this option overrides the single, global `bar` option. pub monitors: Option>, + + /// Map of app IDs (or classes) to icon names, + /// overriding the app's default icon. + /// + /// **Default**: `{}` + #[serde(default)] + pub icon_overrides: HashMap, } const fn default_layer() -> gtk_layer_shell::Layer { diff --git a/src/modules/focused.rs b/src/modules/focused.rs index bfb3e9a..71a66b2 100644 --- a/src/modules/focused.rs +++ b/src/modules/focused.rs @@ -9,6 +9,7 @@ use color_eyre::Result; use gtk::prelude::*; use gtk::Label; use serde::Deserialize; +use std::sync::Arc; use tokio::sync::mpsc; use tracing::debug; @@ -132,9 +133,6 @@ impl Module for FocusedModule { context: WidgetContext, info: &ModuleInfo, ) -> Result> { - let icon_theme = info.icon_theme; - let icon_overrides = info.icon_overrides; - let container = gtk::Box::new(info.bar_position.orientation(), 5); let icon = gtk::Image::new(); @@ -153,8 +151,9 @@ impl Module for FocusedModule { container.add(&label); { - let icon_theme = icon_theme.clone(); - let icon_overrides = icon_overrides.clone(); + let icon_overrides = Arc::new(info.icon_overrides.clone()); + let icon_theme = info.icon_theme.clone(); + glib_recv!(context.subscribe(), data => { if let Some((name, mut id)) = data { if self.show_icon { diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index a3c0bb3..75a5b6f 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -165,8 +165,7 @@ impl Module for LauncherModule { let items = arc_mut!(items); let items2 = Arc::clone(&items); - let icon_overrides = arc_mut!(info.icon_overrides.clone()); - let icon_overrides2 = Arc::clone(&icon_overrides); + let icon_overrides = Arc::new(info.icon_overrides.clone()); let tx = context.tx.clone(); let tx2 = context.tx.clone(); @@ -174,7 +173,6 @@ impl Module for LauncherModule { let wl = context.client::(); spawn(async move { let items = items2; - let icon_overrides = icon_overrides2; let tx = tx2; let mut wlrx = wl.subscribe_toplevels(); @@ -189,7 +187,6 @@ impl Module for LauncherModule { } None => { let mut item = Item::from(info.clone()); - let icon_overrides = lock!(icon_overrides); if let Some(icon) = icon_overrides.get(&info.app_id) { item.icon_override = icon.clone(); @@ -226,7 +223,6 @@ impl Module for LauncherModule { match item { None => { let mut item: Item = info.into(); - let icon_overrides = lock!(icon_overrides); if let Some(icon) = icon_overrides.get(&app_id) { item.icon_override = icon.clone(); From 2fd49e0f3a4e08289d4d3553218529d7efbd9144 Mon Sep 17 00:00:00 2001 From: BowDown097 Date: Wed, 5 Feb 2025 09:11:28 -0800 Subject: [PATCH 5/6] refactor: address requested changes (3) --- src/bar.rs | 3 ++- src/modules/focused.rs | 3 +-- src/modules/launcher/mod.rs | 2 +- src/modules/mod.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bar.rs b/src/bar.rs index 31d619d..cbcdfdc 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -9,6 +9,7 @@ use gtk::prelude::*; use gtk::{Application, ApplicationWindow, IconTheme, Orientation, Window, WindowType}; use gtk_layer_shell::LayerShell; use std::rc::Rc; +use std::sync::Arc; use std::time::Duration; use tracing::{debug, info}; @@ -268,7 +269,7 @@ impl Bar { output_name: &self.monitor_name, location: $location, icon_theme: &icon_theme, - icon_overrides: &self.ironbar.config.borrow().icon_overrides, + icon_overrides: Arc::new(self.ironbar.config.borrow().icon_overrides.clone()), } }; } diff --git a/src/modules/focused.rs b/src/modules/focused.rs index 71a66b2..87fc81d 100644 --- a/src/modules/focused.rs +++ b/src/modules/focused.rs @@ -9,7 +9,6 @@ use color_eyre::Result; use gtk::prelude::*; use gtk::Label; use serde::Deserialize; -use std::sync::Arc; use tokio::sync::mpsc; use tracing::debug; @@ -151,7 +150,7 @@ impl Module for FocusedModule { container.add(&label); { - let icon_overrides = Arc::new(info.icon_overrides.clone()); + let icon_overrides = info.icon_overrides.clone(); let icon_theme = info.icon_theme.clone(); glib_recv!(context.subscribe(), data => { diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index 75a5b6f..fa8c206 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -165,7 +165,7 @@ impl Module for LauncherModule { let items = arc_mut!(items); let items2 = Arc::clone(&items); - let icon_overrides = Arc::new(info.icon_overrides.clone()); + let icon_overrides = info.icon_overrides.clone(); let tx = context.tx.clone(); let tx2 = context.tx.clone(); diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 484d145..a4a6a81 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -72,7 +72,7 @@ pub struct ModuleInfo<'a> { pub monitor: &'a Monitor, pub output_name: &'a str, pub icon_theme: &'a IconTheme, - pub icon_overrides: &'a HashMap, + pub icon_overrides: Arc>, } #[derive(Debug, Clone)] From c2beda852d5183fa6ee8874b8e19b15757fe06c2 Mon Sep 17 00:00:00 2001 From: BowDown097 Date: Sat, 8 Feb 2025 04:42:27 -0800 Subject: [PATCH 6/6] refactor: ensure one copy of icon_overrides --- src/bar.rs | 16 ++++++++++++++-- src/main.rs | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/bar.rs b/src/bar.rs index cbcdfdc..73feba2 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -8,6 +8,7 @@ use gtk::gdk::Monitor; use gtk::prelude::*; use gtk::{Application, ApplicationWindow, IconTheme, Orientation, Window, WindowType}; use gtk_layer_shell::LayerShell; +use std::collections::HashMap; use std::rc::Rc; use std::sync::Arc; use std::time::Duration; @@ -24,6 +25,7 @@ pub struct Bar { name: String, monitor_name: String, monitor_size: (i32, i32), + icon_overrides: Arc>, position: BarPosition, ironbar: Rc, @@ -44,6 +46,7 @@ impl Bar { app: &Application, monitor_name: String, monitor_size: (i32, i32), + icon_overrides: Arc>, config: BarConfig, ironbar: Rc, ) -> Self { @@ -93,6 +96,7 @@ impl Bar { name, monitor_name, monitor_size, + icon_overrides, position, ironbar, window, @@ -269,7 +273,7 @@ impl Bar { output_name: &self.monitor_name, location: $location, icon_theme: &icon_theme, - icon_overrides: Arc::new(self.ironbar.config.borrow().icon_overrides.clone()), + icon_overrides: self.icon_overrides.clone(), } }; } @@ -400,9 +404,17 @@ 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, config, ironbar); + let bar = Bar::new( + app, + monitor_name, + monitor_size, + icon_overrides, + config, + ironbar, + ); bar.init(monitor) } diff --git a/src/main.rs b/src/main.rs index 03e5091..0fe9480 100644 --- a/src/main.rs +++ b/src/main.rs @@ -383,6 +383,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(); @@ -406,6 +407,7 @@ fn load_output_bars( &monitor, monitor_name.to_string(), output_size, + icon_overrides, config.clone(), ironbar.clone(), )?] @@ -418,6 +420,7 @@ fn load_output_bars( &monitor, monitor_name.to_string(), output_size, + icon_overrides.clone(), config.clone(), ironbar.clone(), ) @@ -428,6 +431,7 @@ fn load_output_bars( &monitor, monitor_name.to_string(), output_size, + icon_overrides, config.bar.clone(), ironbar.clone(), )?],