1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-16 14:21:03 +02:00

feat(launcher): icon overrides

This commit is contained in:
BowDown097 2025-01-10 19:52:30 -08:00
parent b296726aa4
commit 87c680122b
3 changed files with 50 additions and 7 deletions

View file

@ -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<string, string>` | `{}` | 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). |

View file

@ -24,16 +24,23 @@ pub struct Item {
pub open_state: OpenState,
pub windows: IndexMap<usize, Window>,
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<ToplevelInfo> 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()

View file

@ -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<Vec<String>>,
/// Map of app IDs (or classes) to icon names,
/// overriding the app's default icon.
///
/// **Default**; `null`
icon_overrides: Option<HashMap<String, String>>,
/// Whether to show application names on the bar.
///
/// **Default**: `false`
@ -149,24 +156,33 @@ impl Module<gtk::Box> 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::<IndexMap<_, _>>()
});
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::<wayland::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<gtk::Box> 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<gtk::Box> 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());