Skip to content

Commit

Permalink
fix(bar): apply roundings on komorebi.json change
Browse files Browse the repository at this point in the history
Group roundings were getting lost when applying the theme after a
`komorebi.json` change/save trigger. Now we reapply these groupings on
the `apply_theme` to make sure they are always correct.
  • Loading branch information
alex-ds13 committed Dec 18, 2024
1 parent 6654a39 commit f173cbc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
59 changes: 42 additions & 17 deletions komorebi-bar/src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub fn apply_theme(
theme: KomobarTheme,
bg_color: Rc<RefCell<Color32>>,
transparency_alpha: Option<u8>,
grouping: Option<Grouping>,
) {
match theme {
KomobarTheme::Catppuccin {
Expand Down Expand Up @@ -150,6 +151,21 @@ pub fn apply_theme(
let theme_color = *bg_color.borrow();

bg_color.replace(theme_color.try_apply_alpha(transparency_alpha));

// apply rounding to the widgets
if let Some(Grouping::Bar(config) | Grouping::Alignment(config) | Grouping::Widget(config)) =
&grouping
{
if let Some(rounding) = config.rounding {
ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.rounding = rounding.into();
style.visuals.widgets.inactive.rounding = rounding.into();
style.visuals.widgets.hovered.rounding = rounding.into();
style.visuals.widgets.active.rounding = rounding.into();
style.visuals.widgets.open.rounding = rounding.into();
});
}
}
}

impl Komobar {
Expand Down Expand Up @@ -216,7 +232,13 @@ impl Komobar {
let background_color_before_transparency = *self.bg_color.borrow();
match config.theme {
Some(theme) => {
apply_theme(ctx, theme, self.bg_color.clone(), config.transparency_alpha);
apply_theme(
ctx,
theme,
self.bg_color.clone(),
config.transparency_alpha,
config.grouping,
);
}
None => {
let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
Expand All @@ -233,6 +255,7 @@ impl Komobar {
);

let bar_transparency_alpha = config.transparency_alpha;
let bar_grouping = config.grouping;
let config = home_dir.join("komorebi.json");
match komorebi_client::StaticConfig::read(&config) {
Ok(config) => {
Expand All @@ -242,6 +265,7 @@ impl Komobar {
KomobarTheme::from(theme),
self.bg_color.clone(),
bar_transparency_alpha,
bar_grouping,
);

let stack_accent = match theme {
Expand All @@ -263,27 +287,27 @@ impl Komobar {
Err(_) => {
ctx.set_style(Style::default());
self.bg_color.replace(Style::default().visuals.panel_fill);

// apply rounding to the widgets since we didn't call `apply_theme`
if let Some(
Grouping::Bar(config) | Grouping::Alignment(config) | Grouping::Widget(config),
) = &bar_grouping
{
if let Some(rounding) = config.rounding {
ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.rounding = rounding.into();
style.visuals.widgets.inactive.rounding = rounding.into();
style.visuals.widgets.hovered.rounding = rounding.into();
style.visuals.widgets.active.rounding = rounding.into();
style.visuals.widgets.open.rounding = rounding.into();
});
}
}
}
}
}
}

// apply rounding to the widgets
if let Some(
Grouping::Bar(config) | Grouping::Alignment(config) | Grouping::Widget(config),
) = &config.grouping
{
if let Some(rounding) = config.rounding {
ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.rounding = rounding.into();
style.visuals.widgets.inactive.rounding = rounding.into();
style.visuals.widgets.hovered.rounding = rounding.into();
style.visuals.widgets.active.rounding = rounding.into();
style.visuals.widgets.open.rounding = rounding.into();
});
}
}

if let Some(font_size) = &config.font_size {
tracing::info!("attempting to set custom font size: {font_size}");
Self::set_font_size(ctx, *font_size);
Expand Down Expand Up @@ -512,6 +536,7 @@ impl eframe::App for Komobar {
self.rx_gui.clone(),
self.bg_color.clone(),
self.config.transparency_alpha,
self.config.grouping,
self.config.theme,
);
}
Expand Down
5 changes: 5 additions & 0 deletions komorebi-bar/src/komorebi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::bar::apply_theme;
use crate::config::DisplayFormat;
use crate::config::KomobarTheme;
use crate::komorebi_layout::KomorebiLayout;
use crate::render::Grouping;
use crate::render::RenderConfig;
use crate::selected_frame::SelectableFrame;
use crate::ui::CustomUi;
Expand Down Expand Up @@ -497,6 +498,7 @@ impl KomorebiNotificationState {
rx_gui: Receiver<komorebi_client::Notification>,
bg_color: Rc<RefCell<Color32>>,
transparency_alpha: Option<u8>,
grouping: Option<Grouping>,
default_theme: Option<KomobarTheme>,
) {
match rx_gui.try_recv() {
Expand All @@ -520,6 +522,7 @@ impl KomorebiNotificationState {
KomobarTheme::from(theme),
bg_color.clone(),
transparency_alpha,
grouping,
);
tracing::info!("applied theme from updated komorebi.json");
} else if let Some(default_theme) = default_theme {
Expand All @@ -528,6 +531,7 @@ impl KomorebiNotificationState {
default_theme,
bg_color.clone(),
transparency_alpha,
grouping,
);
tracing::info!("removed theme from updated komorebi.json and applied default theme");
} else {
Expand All @@ -541,6 +545,7 @@ impl KomorebiNotificationState {
KomobarTheme::from(theme),
bg_color,
transparency_alpha,
grouping,
);
tracing::info!("applied theme from komorebi socket message");
}
Expand Down

0 comments on commit f173cbc

Please sign in to comment.