diff --git a/komorebi-bar/src/bar.rs b/komorebi-bar/src/bar.rs index b3bcddaf..7d576d08 100644 --- a/komorebi-bar/src/bar.rs +++ b/komorebi-bar/src/bar.rs @@ -44,6 +44,8 @@ use eframe::egui::Visuals; use font_loader::system_fonts; use font_loader::system_fonts::FontPropertyBuilder; use komorebi_client::KomorebiTheme; +use komorebi_client::MonitorNotification; +use komorebi_client::NotificationEvent; use komorebi_client::SocketMessage; use komorebi_themes::catppuccin_egui; use komorebi_themes::Base16Value; @@ -644,6 +646,33 @@ impl eframe::App for Komobar { } }, Ok(KomorebiEvent::Notification(notification)) => { + let should_apply_config = if matches!( + notification.event, + NotificationEvent::Monitor(MonitorNotification::DisplayConnectionChange) + ) { + let state = ¬ification.state; + + // Store the monitor coordinates in case they've changed + MONITOR_RIGHT.store( + state.monitors.elements()[self.monitor_index].size().right, + Ordering::SeqCst, + ); + + MONITOR_TOP.store( + state.monitors.elements()[self.monitor_index].size().top, + Ordering::SeqCst, + ); + + MONITOR_LEFT.store( + state.monitors.elements()[self.monitor_index].size().left, + Ordering::SeqCst, + ); + + true + } else { + false + }; + if let Some(komorebi_notification_state) = &self.komorebi_notification_state { komorebi_notification_state .borrow_mut() @@ -659,6 +688,14 @@ impl eframe::App for Komobar { self.render_config.clone(), ); } + + if should_apply_config { + self.apply_config( + ctx, + &self.config.clone(), + self.komorebi_notification_state.clone(), + ); + } } Ok(KomorebiEvent::Reconnect) => { if let Err(error) = diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index e33a5cdb..cef64196 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -505,6 +505,7 @@ impl KomorebiNotificationState { ) { match notification.event { NotificationEvent::WindowManager(_) => {} + NotificationEvent::Monitor(_) => {} NotificationEvent::Socket(message) => match message { SocketMessage::ReloadStaticConfiguration(path) => { if let Ok(config) = komorebi_client::StaticConfig::read(&path) {