mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-16 22:31:03 +02:00
feat(launcher): icon overrides
This commit is contained in:
parent
b296726aa4
commit
87c680122b
3 changed files with 50 additions and 7 deletions
|
@ -15,7 +15,8 @@ Optionally displays a launchable set of favourites.
|
||||||
|
|
||||||
| | Type | Default | Description |
|
| | 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_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. |
|
| `show_icons` | `boolean` | `true` | Whether to show app icons on the button. |
|
||||||
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
|
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
|
||||||
|
|
|
@ -24,16 +24,23 @@ pub struct Item {
|
||||||
pub open_state: OpenState,
|
pub open_state: OpenState,
|
||||||
pub windows: IndexMap<usize, Window>,
|
pub windows: IndexMap<usize, Window>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub icon_override: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Item {
|
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 {
|
Self {
|
||||||
app_id,
|
app_id,
|
||||||
favorite,
|
favorite,
|
||||||
open_state,
|
open_state,
|
||||||
windows: IndexMap::new(),
|
windows: IndexMap::new(),
|
||||||
name: String::new(),
|
name: String::new(),
|
||||||
|
icon_override,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +115,7 @@ impl From<ToplevelInfo> for Item {
|
||||||
open_state,
|
open_state,
|
||||||
windows,
|
windows,
|
||||||
name,
|
name,
|
||||||
|
icon_override: String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +175,9 @@ impl ItemButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
if appearance.show_icons {
|
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()
|
item.name.clone()
|
||||||
} else {
|
} else {
|
||||||
item.app_id.clone()
|
item.app_id.clone()
|
||||||
|
|
|
@ -15,6 +15,7 @@ use gtk::prelude::*;
|
||||||
use gtk::{Button, Orientation};
|
use gtk::{Button, Orientation};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{broadcast, mpsc};
|
use tokio::sync::{broadcast, mpsc};
|
||||||
|
@ -29,6 +30,12 @@ pub struct LauncherModule {
|
||||||
/// **Default**: `null`
|
/// **Default**: `null`
|
||||||
favorites: Option<Vec<String>>,
|
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.
|
/// Whether to show application names on the bar.
|
||||||
///
|
///
|
||||||
/// **Default**: `false`
|
/// **Default**: `false`
|
||||||
|
@ -149,24 +156,33 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
favorites
|
favorites
|
||||||
.iter()
|
.iter()
|
||||||
.map(|app_id| {
|
.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(),
|
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<_, _>>()
|
.collect::<IndexMap<_, _>>()
|
||||||
});
|
});
|
||||||
|
|
||||||
let items = arc_mut!(items);
|
let items = arc_mut!(items);
|
||||||
|
|
||||||
let items2 = Arc::clone(&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 tx = context.tx.clone();
|
||||||
let tx2 = context.tx.clone();
|
let tx2 = context.tx.clone();
|
||||||
|
|
||||||
let wl = context.client::<wayland::Client>();
|
let wl = context.client::<wayland::Client>();
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
let items = items2;
|
let items = items2;
|
||||||
|
let icon_overrides = icon_overrides2;
|
||||||
let tx = tx2;
|
let tx = tx2;
|
||||||
|
|
||||||
let mut wlrx = wl.subscribe_toplevels();
|
let mut wlrx = wl.subscribe_toplevels();
|
||||||
|
@ -180,7 +196,16 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
item.merge_toplevel(info.clone());
|
item.merge_toplevel(info.clone());
|
||||||
}
|
}
|
||||||
None => {
|
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);
|
let item = items.get_mut(&info.app_id);
|
||||||
match item {
|
match item {
|
||||||
None => {
|
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());
|
items.insert(app_id.clone(), item.clone());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue