mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41: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:
parent
618e97f1e8
commit
2da28b9bf5
10 changed files with 83 additions and 25 deletions
|
@ -21,6 +21,9 @@ pub struct ClipboardModule {
|
|||
#[serde(default = "default_icon")]
|
||||
icon: String,
|
||||
|
||||
#[serde(default = "default_icon_size")]
|
||||
icon_size: i32,
|
||||
|
||||
#[serde(default = "default_max_items")]
|
||||
max_items: usize,
|
||||
|
||||
|
@ -35,6 +38,10 @@ fn default_icon() -> String {
|
|||
String::from("")
|
||||
}
|
||||
|
||||
const fn default_icon_size() -> i32 {
|
||||
32
|
||||
}
|
||||
|
||||
const fn default_max_items() -> usize {
|
||||
10
|
||||
}
|
||||
|
@ -120,7 +127,7 @@ impl Module<Button> for ClipboardModule {
|
|||
) -> color_eyre::Result<ModuleWidget<Button>> {
|
||||
let position = info.bar_position;
|
||||
|
||||
let button = new_icon_button(&self.icon, info.icon_theme, 32);
|
||||
let button = new_icon_button(&self.icon, info.icon_theme, self.icon_size);
|
||||
button.style_context().add_class("btn");
|
||||
|
||||
button.connect_clicked(move |button| {
|
||||
|
|
|
@ -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(>k_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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -88,6 +88,12 @@ pub struct MusicModule {
|
|||
#[serde(default = "default_music_dir")]
|
||||
pub(crate) music_dir: PathBuf,
|
||||
|
||||
#[serde(default = "default_icon_size")]
|
||||
pub(crate) icon_size: i32,
|
||||
|
||||
#[serde(default = "default_cover_image_size")]
|
||||
pub(crate) cover_image_size: i32,
|
||||
|
||||
// -- Common --
|
||||
pub(crate) truncate: Option<TruncateMode>,
|
||||
|
||||
|
@ -138,3 +144,11 @@ fn default_icon_artist() -> String {
|
|||
fn default_music_dir() -> PathBuf {
|
||||
audio_dir().unwrap_or_else(|| home_dir().map(|dir| dir.join("Music")).unwrap_or_default())
|
||||
}
|
||||
|
||||
const fn default_icon_size() -> i32 {
|
||||
24
|
||||
}
|
||||
|
||||
const fn default_cover_image_size() -> i32 {
|
||||
128
|
||||
}
|
||||
|
|
|
@ -157,8 +157,8 @@ impl Module<Button> for MusicModule {
|
|||
let button_contents = gtk::Box::new(Orientation::Horizontal, 5);
|
||||
button.add(&button_contents);
|
||||
|
||||
let icon_play = new_icon_label(&self.icons.play, info.icon_theme, 24);
|
||||
let icon_pause = new_icon_label(&self.icons.pause, info.icon_theme, 24);
|
||||
let icon_play = new_icon_label(&self.icons.play, info.icon_theme, self.icon_size);
|
||||
let icon_pause = new_icon_label(&self.icons.pause, info.icon_theme, self.icon_size);
|
||||
let label = Label::new(None);
|
||||
|
||||
label.set_angle(info.bar_position.get_angle());
|
||||
|
@ -261,16 +261,16 @@ impl Module<Button> for MusicModule {
|
|||
|
||||
let controls_box = gtk::Box::builder().name("controls").build();
|
||||
|
||||
let btn_prev = new_icon_button(&icons.prev, icon_theme, 24);
|
||||
let btn_prev = new_icon_button(&icons.prev, icon_theme, self.icon_size);
|
||||
btn_prev.set_widget_name("btn-prev");
|
||||
|
||||
let btn_play = new_icon_button(&icons.play, icon_theme, 24);
|
||||
let btn_play = new_icon_button(&icons.play, icon_theme, self.icon_size);
|
||||
btn_play.set_widget_name("btn-play");
|
||||
|
||||
let btn_pause = new_icon_button(&icons.pause, icon_theme, 24);
|
||||
let btn_pause = new_icon_button(&icons.pause, icon_theme, self.icon_size);
|
||||
btn_pause.set_widget_name("btn-pause");
|
||||
|
||||
let btn_next = new_icon_button(&icons.next, icon_theme, 24);
|
||||
let btn_next = new_icon_button(&icons.next, icon_theme, self.icon_size);
|
||||
btn_next.set_widget_name("btn-next");
|
||||
|
||||
controls_box.add(&btn_prev);
|
||||
|
@ -290,7 +290,7 @@ impl Module<Button> for MusicModule {
|
|||
volume_slider.set_inverted(true);
|
||||
volume_slider.set_widget_name("slider");
|
||||
|
||||
let volume_icon = new_icon_label(&icons.volume, icon_theme, 24);
|
||||
let volume_icon = new_icon_label(&icons.volume, icon_theme, self.icon_size);
|
||||
volume_icon.style_context().add_class("icon");
|
||||
|
||||
volume_box.pack_start(&volume_slider, true, true, 0);
|
||||
|
@ -330,6 +330,7 @@ impl Module<Button> for MusicModule {
|
|||
|
||||
{
|
||||
let icon_theme = icon_theme.clone();
|
||||
let image_size = self.cover_image_size;
|
||||
|
||||
let mut prev_cover = None;
|
||||
rx.attach(None, move |update| {
|
||||
|
@ -338,9 +339,9 @@ impl Module<Button> for MusicModule {
|
|||
let new_cover = update.song.cover_path;
|
||||
if prev_cover != new_cover {
|
||||
prev_cover = new_cover.clone();
|
||||
let res = match new_cover
|
||||
.map(|cover_path| ImageProvider::parse(&cover_path, &icon_theme, 128))
|
||||
{
|
||||
let res = match new_cover.map(|cover_path| {
|
||||
ImageProvider::parse(&cover_path, &icon_theme, image_size)
|
||||
}) {
|
||||
Some(Ok(image)) => image.load_into_image(album_image.clone()),
|
||||
Some(Err(err)) => {
|
||||
album_image.set_from_pixbuf(None);
|
||||
|
@ -451,7 +452,7 @@ impl IconLabel {
|
|||
fn new(icon_input: &str, label: Option<&str>, icon_theme: &IconTheme) -> Self {
|
||||
let container = gtk::Box::new(Orientation::Horizontal, 5);
|
||||
|
||||
let icon = new_icon_label(icon_input, icon_theme, 32);
|
||||
let icon = new_icon_label(icon_input, icon_theme, 24);
|
||||
let label = Label::new(label);
|
||||
|
||||
icon.style_context().add_class("icon");
|
||||
|
|
|
@ -41,21 +41,29 @@ pub struct WorkspacesModule {
|
|||
#[serde(default)]
|
||||
sort: SortOrder,
|
||||
|
||||
#[serde(default = "default_icon_size")]
|
||||
icon_size: i32,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub common: Option<CommonConfig>,
|
||||
}
|
||||
|
||||
const fn default_icon_size() -> i32 {
|
||||
32
|
||||
}
|
||||
|
||||
/// Creates a button from a workspace
|
||||
fn create_button(
|
||||
name: &str,
|
||||
focused: bool,
|
||||
name_map: &HashMap<String, String>,
|
||||
icon_theme: &IconTheme,
|
||||
icon_size: i32,
|
||||
tx: &Sender<String>,
|
||||
) -> Button {
|
||||
let label = name_map.get(name).map_or(name, String::as_str);
|
||||
|
||||
let button = new_icon_button(label, icon_theme, 32);
|
||||
let button = new_icon_button(label, icon_theme, icon_size);
|
||||
button.set_widget_name(name);
|
||||
|
||||
let style_context = button.style_context();
|
||||
|
@ -157,6 +165,7 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
let container = container.clone();
|
||||
let output_name = info.output_name.to_string();
|
||||
let icon_theme = info.icon_theme.clone();
|
||||
let icon_size = self.icon_size;
|
||||
|
||||
// keep track of whether init event has fired previously
|
||||
// since it fires for every workspace subscriber
|
||||
|
@ -174,6 +183,7 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
workspace.focused,
|
||||
&name_map,
|
||||
&icon_theme,
|
||||
icon_size,
|
||||
&context.controller_tx,
|
||||
);
|
||||
container.add(&item);
|
||||
|
@ -209,6 +219,7 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
workspace.focused,
|
||||
&name_map,
|
||||
&icon_theme,
|
||||
icon_size,
|
||||
&context.controller_tx,
|
||||
);
|
||||
|
||||
|
@ -233,6 +244,7 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
workspace.focused,
|
||||
&name_map,
|
||||
&icon_theme,
|
||||
icon_size,
|
||||
&context.controller_tx,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue