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

feat: change icon_overrides to apply to all resolved images

This commit is contained in:
Jake Stanger 2025-05-25 15:52:27 +01:00
parent 3e55d87c3a
commit 3a0e102afc
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
7 changed files with 18 additions and 64 deletions

View file

@ -280,11 +280,12 @@ 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: The following table lists each of the top-level bar config options:
| Name | Type | Default | Description | | Name | Type | Default | Description |
|--------------------|-----------------------------------------|---------|-------------------------------------------------------------------------------| |--------------------|-----------------------------------------|---------|--------------------------------------------------------------------------------------------------------------------------------|
| `ironvar_defaults` | `Map<string, string>` | `{}` | Map of [ironvar](ironvars) keys against their default values. | | `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. | | `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. | | `icon_theme` | `string` | `null` | Name of the GTK icon theme to use. Leave blank to use default. |
| `icon_overrides` | `Map<string, string>` | `{}` | Map of image inputs to override names. Usually used for app IDs (or classes) to icon names, overriding the app's default icon. |
> [!TIP] > [!TIP]
> `monitors` is only required if you are following **2b** or **2c** (ie not the same bar across all monitors). > `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:
| `layer` | `background` or `bottom` or `top` or `overlay` | `top` | The layer-shell layer to place the bar on. | | `layer` | `background` or `bottom` or `top` or `overlay` | `top` | The layer-shell layer to place the bar on. |
| `exclusive_zone` | `boolean` | `true` unless `start_hidden` is enabled. | Whether the bar should reserve an exclusive zone around it. | | `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. | | `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. |
| `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. | | `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. | | `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. | | `start` | `Module[]` | `[]` | Array of left or top modules. |

View file

@ -6,11 +6,9 @@ use color_eyre::Result;
use glib::Propagation; use glib::Propagation;
use gtk::gdk::Monitor; use gtk::gdk::Monitor;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, IconTheme, Orientation, Window, WindowType}; use gtk::{Application, ApplicationWindow, Orientation, Window, WindowType};
use gtk_layer_shell::LayerShell; use gtk_layer_shell::LayerShell;
use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use tracing::{debug, info}; use tracing::{debug, info};
@ -25,7 +23,6 @@ pub struct Bar {
name: String, name: String,
monitor_name: String, monitor_name: String,
monitor_size: (i32, i32), monitor_size: (i32, i32),
icon_overrides: Arc<HashMap<String, String>>,
position: BarPosition, position: BarPosition,
ironbar: Rc<Ironbar>, ironbar: Rc<Ironbar>,
@ -46,7 +43,6 @@ impl Bar {
app: &Application, app: &Application,
monitor_name: String, monitor_name: String,
monitor_size: (i32, i32), monitor_size: (i32, i32),
icon_overrides: Arc<HashMap<String, String>>,
config: BarConfig, config: BarConfig,
ironbar: Rc<Ironbar>, ironbar: Rc<Ironbar>,
) -> Self { ) -> Self {
@ -96,7 +92,6 @@ impl Bar {
name, name,
monitor_name, monitor_name,
monitor_size, monitor_size,
icon_overrides,
position, position,
ironbar, ironbar,
window, window,
@ -257,11 +252,6 @@ impl Bar {
monitor: &Monitor, monitor: &Monitor,
output_size: (i32, i32), output_size: (i32, i32),
) -> Result<BarLoadResult> { ) -> Result<BarLoadResult> {
let icon_theme = IconTheme::new();
if let Some(ref theme) = config.icon_theme {
icon_theme.set_custom_theme(Some(theme));
}
let app = &self.window.application().expect("to exist"); let app = &self.window.application().expect("to exist");
macro_rules! info { macro_rules! info {
@ -272,15 +262,13 @@ impl Bar {
monitor, monitor,
output_name: &self.monitor_name, output_name: &self.monitor_name,
location: $location, location: $location,
icon_theme: &icon_theme,
icon_overrides: self.icon_overrides.clone(),
} }
}; };
} }
// popup ignores module location so can bodge this for now // popup ignores module location so can bodge this for now
let popup = Popup::new( let popup = Popup::new(
self.ironbar.clone(), &self.ironbar,
&info!(ModuleLocation::Left), &info!(ModuleLocation::Left),
output_size, output_size,
config.popup_gap, config.popup_gap,
@ -404,17 +392,9 @@ pub fn create_bar(
monitor: &Monitor, monitor: &Monitor,
monitor_name: String, monitor_name: String,
monitor_size: (i32, i32), monitor_size: (i32, i32),
icon_overrides: Arc<HashMap<String, String>>,
config: BarConfig, config: BarConfig,
ironbar: Rc<Ironbar>, ironbar: Rc<Ironbar>,
) -> Result<Bar> { ) -> Result<Bar> {
let bar = Bar::new( let bar = Bar::new(app, monitor_name, monitor_size, config, ironbar);
app,
monitor_name,
monitor_size,
icon_overrides,
config,
ironbar,
);
bar.init(monitor) bar.init(monitor)
} }

View file

@ -166,10 +166,7 @@ impl Provider {
) -> Result<Option<ImageLocation>> { ) -> Result<Option<ImageLocation>> {
const MAX_RECURSE_DEPTH: u8 = 2; const MAX_RECURSE_DEPTH: u8 = 2;
let input = self let input = self.overrides.get(input).map_or(input, String::as_str);
.overrides
.get(input)
.map_or(input, String::as_str);
let should_parse_desktop_file = !Self::is_explicit_input(input); let should_parse_desktop_file = !Self::is_explicit_input(input);

View file

@ -394,7 +394,7 @@ fn load_output_bars(
}; };
let config = ironbar.config.borrow(); let config = ironbar.config.borrow();
let icon_overrides = Arc::new(config.icon_overrides.clone());
let display = get_display(); let display = get_display();
let pos = output.logical_position.unwrap_or_default(); let pos = output.logical_position.unwrap_or_default();
@ -416,7 +416,6 @@ fn load_output_bars(
&monitor, &monitor,
monitor_name.to_string(), monitor_name.to_string(),
output_size, output_size,
icon_overrides,
config.clone(), config.clone(),
ironbar.clone(), ironbar.clone(),
)?] )?]
@ -429,7 +428,6 @@ fn load_output_bars(
&monitor, &monitor,
monitor_name.to_string(), monitor_name.to_string(),
output_size, output_size,
icon_overrides.clone(),
config.clone(), config.clone(),
ironbar.clone(), ironbar.clone(),
) )
@ -440,7 +438,6 @@ fn load_output_bars(
&monitor, &monitor,
monitor_name.to_string(), monitor_name.to_string(),
output_size, output_size,
icon_overrides,
config.bar.clone(), config.bar.clone(),
ironbar.clone(), ironbar.clone(),
)?], )?],

View file

@ -261,11 +261,7 @@ impl Module<gtk::Box> for KeyboardModule {
let caps = IconLabel::new(&self.icons.caps_off, self.icon_size, &image_provider); let caps = IconLabel::new(&self.icons.caps_off, self.icon_size, &image_provider);
let num = IconLabel::new(&self.icons.num_off, self.icon_size, &image_provider); let num = IconLabel::new(&self.icons.num_off, self.icon_size, &image_provider);
let scroll = IconLabel::new( let scroll = IconLabel::new(&self.icons.scroll_off, self.icon_size, &image_provider);
&self.icons.scroll_off,
self.icon_size,
&image_provider,
);
caps.label().set_angle(self.layout.angle(info)); caps.label().set_angle(self.layout.angle(info));
caps.label().set_justify(self.layout.justify.into()); caps.label().set_justify(self.layout.justify.into());

View file

@ -23,23 +23,16 @@ 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( pub fn new(app_id: String, open_state: OpenState, favorite: bool) -> Self {
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,
} }
} }
@ -114,7 +107,6 @@ impl From<ToplevelInfo> for Item {
open_state, open_state,
windows, windows,
name, name,
icon_override: String::new(),
} }
} }
} }
@ -179,9 +171,7 @@ impl ItemButton {
} }
if appearance.show_icons { if appearance.show_icons {
let input = if !item.icon_override.is_empty() { let input = if item.app_id.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()

View file

@ -30,17 +30,11 @@ impl Pagination {
) -> Self { ) -> Self {
let scroll_box = gtk::Box::new(orientation, 0); let scroll_box = gtk::Box::new(orientation, 0);
let scroll_back = IconButton::new( let scroll_back =
icon_context.back, IconButton::new(icon_context.back, icon_context.size, image_provider.clone());
icon_context.size,
image_provider.clone(),
);
let scroll_fwd = IconButton::new( let scroll_fwd =
icon_context.fwd, IconButton::new(icon_context.fwd, icon_context.size, image_provider.clone());
icon_context.size,
image_provider.clone(),
);
scroll_back.set_sensitive(false); scroll_back.set_sensitive(false);
scroll_fwd.set_sensitive(false); scroll_fwd.set_sensitive(false);