1
0
Fork 0
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:
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

@ -12,6 +12,7 @@ Supports plain text and images.
| Name | Type | Default | Description | | Name | Type | Default | Description |
|-----------------------|---------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------| |-----------------------|---------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `icon` | `string/image` | `󰨸` | Icon to show on the widget button. | | `icon` | `string/image` | `󰨸` | Icon to show on the widget button. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `max_items` | `integer` | `10` | Maximum number of items to show in the popup. | | `max_items` | `integer` | `10` | Maximum number of items to show in the popup. |
| `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. | | `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
| `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. | | `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |

View file

@ -14,6 +14,7 @@ Optionally displays a launchable set of favourites.
| `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 |
| `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). |
<details> <details>
<summary>JSON</summary> <summary>JSON</summary>

View file

@ -27,6 +27,8 @@ in MPRIS mode, the widget will listen to all players and automatically detect/di
| `icons.track` | `string/image` | `` | Icon to show next to track title. | | `icons.track` | `string/image` | `` | Icon to show next to track title. |
| `icons.album` | `string/image` | `` | Icon to show next to album name. | | `icons.album` | `string/image` | `` | Icon to show next to album name. |
| `icons.artist` | `string/image` | `ﴁ` | Icon to show next to artist name. | | `icons.artist` | `string/image` | `ﴁ` | Icon to show next to artist name. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `cover_image_size` | `integer` | `128` | Size to render album art image at inside popup. |
| `host` | `string/image` | `localhost:6600` | [MPD Only] TCP or Unix socket for the MPD server. | | `host` | `string/image` | `localhost:6600` | [MPD Only] TCP or Unix socket for the MPD server. |
| `music_dir` | `string/image` | `$HOME/Music` | [MPD Only] Path to MPD server's music directory on disc. Required for album art. | | `music_dir` | `string/image` | `$HOME/Music` | [MPD Only] Path to MPD server's music directory on disc. Required for album art. |

View file

@ -11,6 +11,7 @@ Shows all current workspaces. Clicking a workspace changes focus to it.
| Name | Type | Default | Description | | Name | Type | Default | Description |
|----------------|-----------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |----------------|-----------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name_map` | `Map<string, string/image>` | `{}` | A map of actual workspace names to their display labels/images. Workspaces use their actual name if not present in the map. See [here](images) for information on images. | | `name_map` | `Map<string, string/image>` | `{}` | A map of actual workspace names to their display labels/images. Workspaces use their actual name if not present in the map. See [here](images) for information on images. |
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
| `all_monitors` | `boolean` | `false` | Whether to display workspaces from all monitors. When `false`, only shows workspaces on the current monitor. | | `all_monitors` | `boolean` | `false` | Whether to display workspaces from all monitors. When `false`, only shows workspaces on the current monitor. |
| `sort` | `added` or `alphanumeric` | `alphanumeric` | The method used for sorting workspaces. `added` always appends to the end, `alphanumeric` sorts by number/name. | | `sort` | `added` or `alphanumeric` | `alphanumeric` | The method used for sorting workspaces. `added` always appends to the end, `alphanumeric` sorts by number/name. |

View file

@ -21,6 +21,9 @@ pub struct ClipboardModule {
#[serde(default = "default_icon")] #[serde(default = "default_icon")]
icon: String, icon: String,
#[serde(default = "default_icon_size")]
icon_size: i32,
#[serde(default = "default_max_items")] #[serde(default = "default_max_items")]
max_items: usize, max_items: usize,
@ -35,6 +38,10 @@ fn default_icon() -> String {
String::from("󰨸") String::from("󰨸")
} }
const fn default_icon_size() -> i32 {
32
}
const fn default_max_items() -> usize { const fn default_max_items() -> usize {
10 10
} }
@ -120,7 +127,7 @@ impl Module<Button> for ClipboardModule {
) -> color_eyre::Result<ModuleWidget<Button>> { ) -> color_eyre::Result<ModuleWidget<Button>> {
let position = info.bar_position; 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.style_context().add_class("btn");
button.connect_clicked(move |button| { button.connect_clicked(move |button| {

View file

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

View file

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

View file

@ -88,6 +88,12 @@ pub struct MusicModule {
#[serde(default = "default_music_dir")] #[serde(default = "default_music_dir")]
pub(crate) music_dir: PathBuf, 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 -- // -- Common --
pub(crate) truncate: Option<TruncateMode>, pub(crate) truncate: Option<TruncateMode>,
@ -138,3 +144,11 @@ fn default_icon_artist() -> String {
fn default_music_dir() -> PathBuf { fn default_music_dir() -> PathBuf {
audio_dir().unwrap_or_else(|| home_dir().map(|dir| dir.join("Music")).unwrap_or_default()) 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
}

View file

@ -157,8 +157,8 @@ impl Module<Button> for MusicModule {
let button_contents = gtk::Box::new(Orientation::Horizontal, 5); let button_contents = gtk::Box::new(Orientation::Horizontal, 5);
button.add(&button_contents); button.add(&button_contents);
let icon_play = new_icon_label(&self.icons.play, 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, 24); let icon_pause = new_icon_label(&self.icons.pause, info.icon_theme, self.icon_size);
let label = Label::new(None); let label = Label::new(None);
label.set_angle(info.bar_position.get_angle()); 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 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"); 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"); 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"); 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"); btn_next.set_widget_name("btn-next");
controls_box.add(&btn_prev); controls_box.add(&btn_prev);
@ -290,7 +290,7 @@ impl Module<Button> for MusicModule {
volume_slider.set_inverted(true); volume_slider.set_inverted(true);
volume_slider.set_widget_name("slider"); 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_icon.style_context().add_class("icon");
volume_box.pack_start(&volume_slider, true, true, 0); 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 icon_theme = icon_theme.clone();
let image_size = self.cover_image_size;
let mut prev_cover = None; let mut prev_cover = None;
rx.attach(None, move |update| { rx.attach(None, move |update| {
@ -338,9 +339,9 @@ impl Module<Button> for MusicModule {
let new_cover = update.song.cover_path; let new_cover = update.song.cover_path;
if prev_cover != new_cover { if prev_cover != new_cover {
prev_cover = new_cover.clone(); prev_cover = new_cover.clone();
let res = match new_cover let res = match new_cover.map(|cover_path| {
.map(|cover_path| ImageProvider::parse(&cover_path, &icon_theme, 128)) ImageProvider::parse(&cover_path, &icon_theme, image_size)
{ }) {
Some(Ok(image)) => image.load_into_image(album_image.clone()), Some(Ok(image)) => image.load_into_image(album_image.clone()),
Some(Err(err)) => { Some(Err(err)) => {
album_image.set_from_pixbuf(None); album_image.set_from_pixbuf(None);
@ -451,7 +452,7 @@ impl IconLabel {
fn new(icon_input: &str, label: Option<&str>, icon_theme: &IconTheme) -> Self { fn new(icon_input: &str, label: Option<&str>, icon_theme: &IconTheme) -> Self {
let container = gtk::Box::new(Orientation::Horizontal, 5); 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); let label = Label::new(label);
icon.style_context().add_class("icon"); icon.style_context().add_class("icon");

View file

@ -41,21 +41,29 @@ pub struct WorkspacesModule {
#[serde(default)] #[serde(default)]
sort: SortOrder, sort: SortOrder,
#[serde(default = "default_icon_size")]
icon_size: i32,
#[serde(flatten)] #[serde(flatten)]
pub common: Option<CommonConfig>, pub common: Option<CommonConfig>,
} }
const fn default_icon_size() -> i32 {
32
}
/// Creates a button from a workspace /// Creates a button from a workspace
fn create_button( fn create_button(
name: &str, name: &str,
focused: bool, focused: bool,
name_map: &HashMap<String, String>, name_map: &HashMap<String, String>,
icon_theme: &IconTheme, icon_theme: &IconTheme,
icon_size: i32,
tx: &Sender<String>, tx: &Sender<String>,
) -> Button { ) -> Button {
let label = name_map.get(name).map_or(name, String::as_str); 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); button.set_widget_name(name);
let style_context = button.style_context(); let style_context = button.style_context();
@ -157,6 +165,7 @@ impl Module<gtk::Box> for WorkspacesModule {
let container = container.clone(); let container = container.clone();
let output_name = info.output_name.to_string(); let output_name = info.output_name.to_string();
let icon_theme = info.icon_theme.clone(); let icon_theme = info.icon_theme.clone();
let icon_size = self.icon_size;
// keep track of whether init event has fired previously // keep track of whether init event has fired previously
// since it fires for every workspace subscriber // since it fires for every workspace subscriber
@ -174,6 +183,7 @@ impl Module<gtk::Box> for WorkspacesModule {
workspace.focused, workspace.focused,
&name_map, &name_map,
&icon_theme, &icon_theme,
icon_size,
&context.controller_tx, &context.controller_tx,
); );
container.add(&item); container.add(&item);
@ -209,6 +219,7 @@ impl Module<gtk::Box> for WorkspacesModule {
workspace.focused, workspace.focused,
&name_map, &name_map,
&icon_theme, &icon_theme,
icon_size,
&context.controller_tx, &context.controller_tx,
); );
@ -233,6 +244,7 @@ impl Module<gtk::Box> for WorkspacesModule {
workspace.focused, workspace.focused,
&name_map, &name_map,
&icon_theme, &icon_theme,
icon_size,
&context.controller_tx, &context.controller_tx,
); );