Skip to content

Commit

Permalink
refactor: address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BowDown097 committed Feb 4, 2025
1 parent d1b4af4 commit 40d449e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/Configuration guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>` | `null` | Map of app IDs (or classes) to icon names, overriding the app's default icon. |
| `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
7 changes: 4 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<String, String>>,
/// **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 @@ -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(),
)]),
Expand Down
6 changes: 2 additions & 4 deletions src/modules/focused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ impl Module<gtk::Box> 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)
Expand Down
21 changes: 8 additions & 13 deletions src/modules/launcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Module<gtk::Box> for LauncherModule {

fn spawn_controller(
&self,
_info: &ModuleInfo,
info: &ModuleInfo,
context: &WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
mut rx: mpsc::Receiver<Self::ReceiveMessage>,
) -> crate::Result<()> {
Expand All @@ -149,10 +149,9 @@ impl Module<gtk::Box> 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());

(
Expand All @@ -166,7 +165,7 @@ 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_overrides = arc_mut!(info.icon_overrides.clone());
let icon_overrides2 = Arc::clone(&icon_overrides);

let tx = context.tx.clone();
Expand All @@ -192,10 +191,8 @@ impl Module<gtk::Box> 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);
Expand Down Expand Up @@ -231,10 +228,8 @@ impl Module<gtk::Box> 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());
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<String, String>>,
pub icon_overrides: &'a HashMap<String, String>,
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit 40d449e

Please sign in to comment.