fix(wm): remove ws rules from disconnected monitors

This commit makes sure that any workspace_rules that tried to move a
window to a monitor that has been disconnected are removed.

If the monitor is later reconnected the workspace_rules should be added
from the cached config.
This commit is contained in:
alex-ds13
2025-01-29 15:26:17 +00:00
committed by LGUG2Z
parent e408410c58
commit ff986fba67
+15 -2
View File
@@ -12,6 +12,7 @@ use crate::NotificationEvent;
use crate::State; use crate::State;
use crate::WindowManager; use crate::WindowManager;
use crate::WindowsApi; use crate::WindowsApi;
use crate::WORKSPACE_MATCHING_RULES;
use crossbeam_channel::Receiver; use crossbeam_channel::Receiver;
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
use crossbeam_utils::atomic::AtomicConsume; use crossbeam_utils::atomic::AtomicConsume;
@@ -298,7 +299,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
// These are monitors that have been removed // These are monitors that have been removed
let mut newly_removed_displays = vec![]; let mut newly_removed_displays = vec![];
for m in wm.monitors().iter() { for (m_idx, m) in wm.monitors().iter().enumerate() {
if !attached_devices.iter().any(|attached| { if !attached_devices.iter().any(|attached| {
attached.serial_number_id().eq(m.serial_number_id()) attached.serial_number_id().eq(m.serial_number_id())
|| attached.device_id().eq(m.device_id()) || attached.device_id().eq(m.device_id())
@@ -317,6 +318,18 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
} }
} }
// Remove any workspace_rules for this specific monitor
let mut workspace_rules = WORKSPACE_MATCHING_RULES.lock();
let mut rules_to_remove = Vec::new();
for (i, rule) in workspace_rules.iter().enumerate().rev() {
if rule.monitor_index == m_idx {
rules_to_remove.push(i);
}
}
for i in rules_to_remove {
workspace_rules.remove(i);
}
// Let's add their state to the cache for later // Let's add their state to the cache for later
monitor_cache.insert(id, m.into()); monitor_cache.insert(id, m.into());
} }
@@ -389,7 +402,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
// Check for and add any new monitors that may have been plugged in // Check for and add any new monitors that may have been plugged in
// Monitor and display index preferences get applied in this function // Monitor and display index preferences get applied in this function
WindowsApi::load_monitor_information(&mut wm.monitors)?; WindowsApi::load_monitor_information(&mut wm)?;
let post_addition_monitor_count = wm.monitors().len(); let post_addition_monitor_count = wm.monitors().len();