Skip to content

Commit

Permalink
refactor: address requested changes (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
BowDown097 committed Feb 5, 2025
1 parent 40d449e commit d5e4e08
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
10 changes: 5 additions & 5 deletions docs/Configuration guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>` | `{}` | Map of [ironvar](ironvars) keys against their default values. |
| `monitors` | `Map<string, BarConfig or BarConfig[]>` | `null` | Map of monitor names against bar configs. |
| Name | Type | Default | Description |
|--------------------|-----------------------------------------|---------|-------------------------------------------------------------------------------|
| `ironvar_defaults` | `Map<string, string>` | `{}` | Map of [ironvar](ironvars) keys against their default values. |
| `monitors` | `Map<string, BarConfig or BarConfig[]>` | `null` | Map of monitor names against bar configs. |
| `icon_overrides` | `Map<string, string>` | `{}` | 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).
Expand All @@ -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<string, string>` | `{}` | 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. |
Expand Down
2 changes: 1 addition & 1 deletion src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
};
}
Expand Down
15 changes: 7 additions & 8 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,6 @@ pub struct BarConfig {
/// **Default**: `null`
pub icon_theme: Option<String>,

/// Map of app IDs (or classes) to icon names,
/// overriding the app's default icon.
///
/// **Default**; `{}`
#[serde(default)]
pub icon_overrides: HashMap<String, String>,

/// 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.
///
Expand Down Expand Up @@ -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(),
)]),
Expand Down Expand Up @@ -396,6 +388,13 @@ pub struct Config {
///
/// Providing this option overrides the single, global `bar` option.
pub monitors: Option<HashMap<String, MonitorConfig>>,

/// Map of app IDs (or classes) to icon names,
/// overriding the app's default icon.
///
/// **Default**: `{}`
#[serde(default)]
pub icon_overrides: HashMap<String, String>,
}

const fn default_layer() -> gtk_layer_shell::Layer {
Expand Down
9 changes: 4 additions & 5 deletions src/modules/focused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -132,9 +133,6 @@ impl Module<gtk::Box> for FocusedModule {
context: WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
info: &ModuleInfo,
) -> Result<ModuleParts<gtk::Box>> {
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();
Expand All @@ -153,8 +151,9 @@ impl Module<gtk::Box> 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 {
Expand Down
6 changes: 1 addition & 5 deletions src/modules/launcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,14 @@ impl Module<gtk::Box> 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();

let wl = context.client::<wayland::Client>();
spawn(async move {
let items = items2;
let icon_overrides = icon_overrides2;
let tx = tx2;

let mut wlrx = wl.subscribe_toplevels();
Expand All @@ -189,7 +187,6 @@ impl Module<gtk::Box> 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();
Expand Down Expand Up @@ -226,7 +223,6 @@ impl Module<gtk::Box> 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();
Expand Down

0 comments on commit d5e4e08

Please sign in to comment.