From d5e4e08863266d1373c74c7a9f8b75cc27220d38 Mon Sep 17 00:00:00 2001 From: BowDown097 Date: Wed, 5 Feb 2025 07:40:54 -0800 Subject: [PATCH] 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 70dfb46d..50682cf4 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 e54489a6..31d619d5 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 d8aeb953..b689bde2 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 bfb3e9ad..71a66b20 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 a3c0bb34..75a5b6ff 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();