From 10d2ab21c7b77dbff97052f6800ff9c78863747a Mon Sep 17 00:00:00 2001 From: Csaba Date: Sun, 10 Nov 2024 01:59:42 +0100 Subject: [PATCH] hot-reload on grouping --- komorebi-bar/src/bar.rs | 16 +++++++--------- komorebi-bar/src/config.rs | 12 ++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/komorebi-bar/src/bar.rs b/komorebi-bar/src/bar.rs index eaab81d6..89bc6ff4 100644 --- a/komorebi-bar/src/bar.rs +++ b/komorebi-bar/src/bar.rs @@ -2,7 +2,6 @@ use crate::config::KomobarConfig; use crate::config::KomobarTheme; use crate::config::Position; use crate::config::PositionConfig; -use crate::group::Grouping; use crate::komorebi::Komorebi; use crate::komorebi::KomorebiNotificationState; use crate::process_hwnd; @@ -194,6 +193,8 @@ impl Komobar { } } + self.render_config.replace(config.into()); + match config.theme { Some(theme) => { apply_theme(ctx, theme, self.bg_color.clone()); @@ -319,14 +320,11 @@ impl Komobar { rx_config: Receiver, config: Arc, ) -> Self { + let conf: &KomobarConfig = &config; + let mut komobar = Self { config: config.clone(), - render_config: Rc::new(RefCell::new(RenderConfig { - grouping: match config.grouping { - Some(grouping) => grouping, - None => Grouping::None, - }, - })), + render_config: Rc::new(RefCell::new(conf.into())), komorebi_notification_state: None, left_widgets: vec![], right_widgets: vec![], @@ -336,9 +334,9 @@ impl Komobar { scale_factor: cc.egui_ctx.native_pixels_per_point().unwrap_or(1.0), }; - komobar.apply_config(&cc.egui_ctx, &config, None); + komobar.apply_config(&cc.egui_ctx, conf, None); // needs a double apply the first time for some reason - komobar.apply_config(&cc.egui_ctx, &config, None); + komobar.apply_config(&cc.egui_ctx, conf, None); komobar } diff --git a/komorebi-bar/src/config.rs b/komorebi-bar/src/config.rs index 72817788..98c794a8 100644 --- a/komorebi-bar/src/config.rs +++ b/komorebi-bar/src/config.rs @@ -1,4 +1,5 @@ use crate::group::Grouping; +use crate::widget::RenderConfig; use crate::widget::WidgetConfig; use eframe::egui::Color32; use eframe::egui::Pos2; @@ -70,6 +71,17 @@ impl KomobarConfig { } } +impl From<&KomobarConfig> for RenderConfig { + fn from(value: &KomobarConfig) -> Self { + RenderConfig { + grouping: match value.grouping { + Some(grouping) => grouping, + None => Grouping::None, + }, + } + } +} + #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] pub struct PositionConfig { /// The desired starting position of the bar (0,0 = top left of the screen)