From a4128b72760961addcc253a0c284fe42f92f01d6 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:41:54 +0000 Subject: [PATCH] fix(bar): handle komorebi theme change properly Previously if we changed/set the theme on `komorebi.json` it would apply that theme to the bar without taking into account the transparency alpha, also after removing the `theme` from `komorebi.json` file it wasn't applying the theme from the bar config. This commit fixes these issues. --- komorebi-bar/src/bar.rs | 21 ++++++++++++--------- komorebi-bar/src/komorebi.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/komorebi-bar/src/bar.rs b/komorebi-bar/src/bar.rs index f58b0263..01e9cbdb 100644 --- a/komorebi-bar/src/bar.rs +++ b/komorebi-bar/src/bar.rs @@ -59,7 +59,7 @@ pub struct Komobar { pub scale_factor: f32, } -pub fn apply_theme(ctx: &Context, theme: KomobarTheme, bg_color: Rc>) { +pub fn apply_theme(ctx: &Context, theme: KomobarTheme, bg_color: Rc>, transparency_alpha: Option) { match theme { KomobarTheme::Catppuccin { name: catppuccin, @@ -139,6 +139,12 @@ pub fn apply_theme(ctx: &Context, theme: KomobarTheme, bg_color: Rc { - apply_theme(ctx, theme, self.bg_color.clone()); + apply_theme(ctx, theme, self.bg_color.clone(), config.transparency_alpha); } None => { let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else( @@ -224,7 +230,7 @@ impl Komobar { match komorebi_client::StaticConfig::read(&config) { Ok(config) => { if let Some(theme) = config.theme { - apply_theme(ctx, KomobarTheme::from(theme), self.bg_color.clone()); + apply_theme(ctx, KomobarTheme::from(theme), self.bg_color.clone(), config.transparency_alpha); let stack_accent = match theme { KomorebiTheme::Catppuccin { @@ -266,18 +272,13 @@ impl Komobar { } } - let theme_color = *self.bg_color.borrow(); - - self.bg_color - .replace(theme_color.try_apply_alpha(config.transparency_alpha)); - 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); } self.render_config - .replace(config.new_renderconfig(ctx, theme_color)); + .replace(config.new_renderconfig(ctx, *self.bg_color.borrow())); let mut komorebi_notification_state = previous_notification_state; let mut komorebi_widgets = Vec::new(); @@ -476,6 +477,8 @@ impl eframe::App for Komobar { self.config.monitor.index, self.rx_gui.clone(), self.bg_color.clone(), + self.config.transparency_alpha, + self.config.theme, ); } diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index 535a82c7..0280b06c 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -496,6 +496,8 @@ impl KomorebiNotificationState { monitor_index: usize, rx_gui: Receiver, bg_color: Rc>, + transparency_alpha: Option, + default_theme: Option, ) { match rx_gui.try_recv() { Err(error) => match error { @@ -513,13 +515,33 @@ impl KomorebiNotificationState { SocketMessage::ReloadStaticConfiguration(path) => { if let Ok(config) = komorebi_client::StaticConfig::read(&path) { if let Some(theme) = config.theme { - apply_theme(ctx, KomobarTheme::from(theme), bg_color.clone()); + apply_theme( + ctx, + KomobarTheme::from(theme), + bg_color.clone(), + transparency_alpha, + ); tracing::info!("applied theme from updated komorebi.json"); + } else if let Some(default_theme) = default_theme { + apply_theme( + ctx, + default_theme, + bg_color.clone(), + transparency_alpha, + ); + tracing::info!("removed theme from updated komorebi.json and applied default theme"); + } else { + tracing::warn!("theme was removed from updated komorebi.json but there was no default theme to apply"); } } } SocketMessage::Theme(theme) => { - apply_theme(ctx, KomobarTheme::from(theme), bg_color); + apply_theme( + ctx, + KomobarTheme::from(theme), + bg_color, + transparency_alpha, + ); tracing::info!("applied theme from komorebi socket message"); } _ => {}