Skip to content

Commit

Permalink
fix(bar): check monitor connection on all notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ds13 authored and LGUG2Z committed Feb 21, 2025
1 parent ec8519d commit b7ebd3f
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions komorebi-bar/src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,50 +673,50 @@ impl eframe::App for Komobar {
}
},
Ok(KomorebiEvent::Notification(notification)) => {
let should_apply_config = if matches!(
notification.event,
NotificationEvent::Monitor(MonitorNotification::DisplayConnectionChange)
) {
let state = &notification.state;
let usr_monitor_index = match &self.config.monitor {
MonitorConfigOrIndex::MonitorConfig(monitor_config) => monitor_config.index,
MonitorConfigOrIndex::Index(idx) => *idx,
};
let monitor_index = state
.monitor_usr_idx_map
.get(&usr_monitor_index)
.map_or(usr_monitor_index, |i| *i);
self.monitor_index = monitor_index;

if self.monitor_index >= state.monitors.elements().len() {
// Monitor for this bar got disconnected lets disable the bar until it
// reconnects
self.disabled = true;
tracing::warn!(
"This bar's monitor got disconnected. The bar will be disabled until it reconnects..."
let state = &notification.state;
let usr_monitor_index = match &self.config.monitor {
MonitorConfigOrIndex::MonitorConfig(monitor_config) => monitor_config.index,
MonitorConfigOrIndex::Index(idx) => *idx,
};
let monitor_index = state
.monitor_usr_idx_map
.get(&usr_monitor_index)
.map_or(usr_monitor_index, |i| *i);
self.monitor_index = monitor_index;

if self.monitor_index >= state.monitors.elements().len() {
// Monitor for this bar got disconnected lets disable the bar until it
// reconnects
self.disabled = true;
tracing::warn!(
"This bar's monitor got disconnected. The bar will be disabled until it reconnects..."
);
return;
} else {
if self.disabled {
tracing::info!(
"This bar's monitor reconnected. The bar will be enabled again!"
);
return;
} else {
if self.disabled {
tracing::info!(
"This bar's monitor reconnected. The bar will be enabled again!"
);

// Restore the bar in case it has been minimized when the monitor
// disconnected
if let Some(hwnd) = self.hwnd {
let window = komorebi_client::Window::from(hwnd);
if window.is_miminized() {
komorebi_client::WindowsApi::restore_window(hwnd);
}
// Restore the bar in case it has been minimized when the monitor
// disconnected
if let Some(hwnd) = self.hwnd {
let window = komorebi_client::Window::from(hwnd);
if window.is_miminized() {
komorebi_client::WindowsApi::restore_window(hwnd);
}

// Reposition the Bar
self.position_bar();
}
self.disabled = false;

// Reposition the Bar
self.position_bar();
}
self.disabled = false;
}

let should_apply_config = if matches!(
notification.event,
NotificationEvent::Monitor(MonitorNotification::DisplayConnectionChange)
) {
// Store the monitor coordinates in case they've changed
MONITOR_RIGHT.store(
state.monitors.elements()[self.monitor_index].size().right,
Expand Down

0 comments on commit b7ebd3f

Please sign in to comment.