Skip to content

Commit

Permalink
feat(bar): optional workspaces on Komorebi widget
Browse files Browse the repository at this point in the history
This commit makes the `workspaces` on `Komorebi` widget optional. This
way it allows adding the `workspaces` on one Alignment and the
`focused_window` on another one, for example.

For some reason if you had some widget on the `center_widgets` with only
icons, like the `focused_window` with just icons or the `workspaces`
with just icons and nothing else, EGUI wouldn't show the icon properly.
I believe that on the first frame the icons might not have been loaded
yet, so it set the height of the `center_widgets` Area to 0 and
afterwards it wouldn't grow to fit the icons unless we've made some
config change for example.

To fix this we've made the icons have fixed size which is equal to the
font size. For this it was required that the font size was added to the
`RenderConfig` so that the widgets would have access to it when
rendering.
  • Loading branch information
alex-ds13 committed Dec 14, 2024
1 parent 40c55de commit 9a9dd0b
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 175 deletions.
63 changes: 30 additions & 33 deletions komorebi-bar/src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl Komobar {
let theme_color = *self.bg_color.borrow();

self.render_config
.replace(config.new_renderconfig(theme_color));
.replace(config.new_renderconfig(theme_color, config.font_size));

self.bg_color
.replace(theme_color.try_apply_alpha(config.transparency_alpha));
Expand All @@ -281,34 +281,26 @@ impl Komobar {
Self::set_font_size(ctx, *font_size);
}

let mut komorebi_widget = None;
let mut komorebi_widget_idx = None;
let mut komorebi_notification_state = previous_notification_state;
let mut side = None;
let mut komorebi_widgets = Vec::new();

for (idx, widget_config) in config.left_widgets.iter().enumerate() {
if let WidgetConfig::Komorebi(config) = widget_config {
komorebi_widget = Some(Komorebi::from(config));
komorebi_widget_idx = Some(idx);
side = Some(Alignment::Left);
komorebi_widgets.push((Komorebi::from(config), idx, Alignment::Left));
}
}

if let Some(center_widgets) = &config.center_widgets {
for (idx, widget_config) in center_widgets.iter().enumerate() {
if let WidgetConfig::Komorebi(config) = widget_config {
komorebi_widget = Some(Komorebi::from(config));
komorebi_widget_idx = Some(idx);
side = Some(Alignment::Center);
komorebi_widgets.push((Komorebi::from(config), idx, Alignment::Center));
}
}
}

for (idx, widget_config) in config.right_widgets.iter().enumerate() {
if let WidgetConfig::Komorebi(config) = widget_config {
komorebi_widget = Some(Komorebi::from(config));
komorebi_widget_idx = Some(idx);
side = Some(Alignment::Right);
komorebi_widgets.push((Komorebi::from(config), idx, Alignment::Right));
}
}

Expand All @@ -335,28 +327,33 @@ impl Komobar {
.map(|config| config.as_boxed_bar_widget())
.collect::<Vec<Box<dyn BarWidget>>>();

if let (Some(idx), Some(mut widget), Some(side)) =
(komorebi_widget_idx, komorebi_widget, side)
{
match komorebi_notification_state {
None => {
komorebi_notification_state = Some(widget.komorebi_notification_state.clone());
}
Some(ref previous) => {
previous
.borrow_mut()
.update_from_config(&widget.komorebi_notification_state.borrow());
if !komorebi_widgets.is_empty() {
komorebi_widgets
.into_iter()
.for_each(|(mut widget, idx, side)| {
match komorebi_notification_state {
None => {
komorebi_notification_state =
Some(widget.komorebi_notification_state.clone());
}
Some(ref previous) => {
if widget.workspaces.map_or(false, |w| w.enable) {
previous.borrow_mut().update_from_config(
&widget.komorebi_notification_state.borrow(),
);
}

widget.komorebi_notification_state = previous.clone();
}
}
widget.komorebi_notification_state = previous.clone();
}
}

let boxed: Box<dyn BarWidget> = Box::new(widget);
match side {
Alignment::Left => left_widgets[idx] = boxed,
Alignment::Center => center_widgets[idx] = boxed,
Alignment::Right => right_widgets[idx] = boxed,
}
let boxed: Box<dyn BarWidget> = Box::new(widget);
match side {
Alignment::Left => left_widgets[idx] = boxed,
Alignment::Center => center_widgets[idx] = boxed,
Alignment::Right => right_widgets[idx] = boxed,
}
});
}

right_widgets.reverse();
Expand Down
Loading

0 comments on commit 9a9dd0b

Please sign in to comment.