1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-03 19:51:03 +02:00

feat: ability to configure image icon sizes

Adds `icon_size` option to following widgets:

- `clipboard`
- `launcher`
- `music`
- `workspaces`

Also adds `cover_image_size` option to `music`.
This commit is contained in:
Jake Stanger 2023-04-22 22:18:36 +01:00
parent 618e97f1e8
commit 2da28b9bf5
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
10 changed files with 83 additions and 25 deletions

View file

@ -136,27 +136,34 @@ pub struct ItemButton {
pub menu_state: Rc<RwLock<MenuState>>,
}
#[derive(Clone, Copy)]
pub struct AppearanceOptions {
pub show_names: bool,
pub show_icons: bool,
pub icon_size: i32,
}
impl ItemButton {
pub fn new(
item: &Item,
show_names: bool,
show_icons: bool,
orientation: Orientation,
appearance: AppearanceOptions,
icon_theme: &IconTheme,
orientation: Orientation,
tx: &Sender<ModuleUpdateEvent<LauncherUpdate>>,
controller_tx: &Sender<ItemEvent>,
) -> Self {
let mut button = Button::builder();
if show_names {
if appearance.show_names {
button = button.label(&item.name);
}
let button = button.build();
if show_icons {
if appearance.show_icons {
let gtk_image = gtk::Image::new();
let image = ImageProvider::parse(&item.app_id.clone(), icon_theme, 32);
let image =
ImageProvider::parse(&item.app_id.clone(), icon_theme, appearance.icon_size);
match image {
Ok(image) => {
button.set_image(Some(&gtk_image));
@ -217,7 +224,7 @@ impl ItemButton {
try_send!(
tx,
ModuleUpdateEvent::OpenPopup(Popup::widget_geometry(button, orientation,))
ModuleUpdateEvent::OpenPopup(Popup::widget_geometry(button, orientation))
);
} else {
try_send!(tx, ModuleUpdateEvent::ClosePopup);
@ -232,7 +239,7 @@ impl ItemButton {
Self {
button,
persistent: item.favorite,
show_names,
show_names: appearance.show_names,
menu_state,
}
}

View file

@ -6,6 +6,7 @@ use self::open_state::OpenState;
use crate::clients::wayland::{self, ToplevelChange};
use crate::config::CommonConfig;
use crate::desktop_file::find_desktop_file;
use crate::modules::launcher::item::AppearanceOptions;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::{lock, read_lock, try_send, write_lock};
use color_eyre::{Help, Report};
@ -33,10 +34,17 @@ pub struct LauncherModule {
#[serde(default = "crate::config::default_true")]
show_icons: bool,
#[serde(default = "default_icon_size")]
icon_size: i32,
#[serde(flatten)]
pub common: Option<CommonConfig>,
}
const fn default_icon_size() -> i32 {
32
}
#[derive(Debug, Clone)]
pub enum LauncherUpdate {
/// Adds item
@ -318,8 +326,13 @@ impl Module<gtk::Box> for LauncherModule {
let controller_tx = context.controller_tx.clone();
let appearance_options = AppearanceOptions {
show_names: self.show_names,
show_icons: self.show_icons,
icon_size: self.icon_size,
};
let show_names = self.show_names;
let show_icons = self.show_icons;
let orientation = info.bar_position.get_orientation();
let mut buttons = IndexMap::<String, ItemButton>::new();
@ -334,10 +347,9 @@ impl Module<gtk::Box> for LauncherModule {
} else {
let button = ItemButton::new(
&item,
show_names,
show_icons,
orientation,
appearance_options,
&icon_theme,
orientation,
&context.tx,
&controller_tx,
);