mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-09-18 07:41:25 +02:00
fix(bar): handle monitor disconnect/reconnect
This commit allows a bar to be disabled when it's monitor is disconnected and re-enabled when said monitor reconnects. This commit also uses the new `monitor_usr_idx_map` to properly map the monitor index given by the users on config to the actual monitor index on the `WindowManager` - in case some middle monitor gets disconnected the index of the monitors to the "right" of that one will be lowered by 1. This should allow for the following in cases with monitor A, B and C: if monitor B disconnects, its bar will be disabled and monitor C will properly change its monitor index internally to 1 so it still gets the infos from monitor C (which now will have index 1 on the `WindowManager`).
This commit is contained in:
@@ -38,6 +38,7 @@ use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -121,6 +122,7 @@ impl From<&KomorebiConfig> for Komorebi {
|
||||
focused_container_information: KomorebiNotificationStateContainerInformation::EMPTY,
|
||||
stack_accent: None,
|
||||
monitor_index: MONITOR_INDEX.load(Ordering::SeqCst),
|
||||
monitor_usr_idx_map: HashMap::new(),
|
||||
})),
|
||||
workspaces: value.workspaces,
|
||||
layout: value.layout.clone(),
|
||||
@@ -483,6 +485,7 @@ pub struct KomorebiNotificationState {
|
||||
pub work_area_offset: Option<Rect>,
|
||||
pub stack_accent: Option<Color32>,
|
||||
pub monitor_index: usize,
|
||||
pub monitor_usr_idx_map: HashMap<usize, usize>,
|
||||
}
|
||||
|
||||
impl KomorebiNotificationState {
|
||||
@@ -553,6 +556,13 @@ impl KomorebiNotificationState {
|
||||
}
|
||||
|
||||
self.monitor_index = monitor_index;
|
||||
self.monitor_usr_idx_map = notification.state.monitor_usr_idx_map.clone();
|
||||
|
||||
if monitor_index >= notification.state.monitors.elements().len() {
|
||||
// The bar's monitor is diconnected, so the bar is disabled no need to check anything
|
||||
// any further otherwise we'll get `OutOfBounds` panics.
|
||||
return;
|
||||
}
|
||||
|
||||
self.mouse_follows_focus = notification.state.mouse_follows_focus;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user