feat(wm): selectively handle uncloak events

This commit adds selective handling for WindowManagerEvent::Uncloak
alongside Show and Manage, avoiding the workspace-switching logic that
is known to cause infinite workspace loops.
This commit is contained in:
LGUG2Z
2024-05-08 08:58:30 -07:00
parent 482a7b1d7f
commit 4802b55452
+23 -20
View File
@@ -284,27 +284,31 @@ impl WindowManager {
} }
} }
} }
WindowManagerEvent::Show(_, window) | WindowManagerEvent::Manage(window) => { WindowManagerEvent::Show(_, window)
let mut switch_to = None; | WindowManagerEvent::Manage(window)
for (i, monitors) in self.monitors().iter().enumerate() { | WindowManagerEvent::Uncloak(_, window) => {
for (j, workspace) in monitors.workspaces().iter().enumerate() { if !matches!(event, WindowManagerEvent::Uncloak(_, _)) {
if workspace.contains_window(window.hwnd) { let mut switch_to = None;
switch_to = Some((i, j)); for (i, monitors) in self.monitors().iter().enumerate() {
for (j, workspace) in monitors.workspaces().iter().enumerate() {
if workspace.contains_window(window.hwnd) {
switch_to = Some((i, j));
}
} }
} }
}
if let Some((known_monitor_idx, known_workspace_idx)) = switch_to { if let Some((known_monitor_idx, known_workspace_idx)) = switch_to {
if self.focused_monitor_idx() != known_monitor_idx if self.focused_monitor_idx() != known_monitor_idx
|| self || self
.focused_monitor() .focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))? .ok_or_else(|| anyhow!("there is no monitor"))?
.focused_workspace_idx() .focused_workspace_idx()
!= known_workspace_idx != known_workspace_idx
{ {
self.focus_monitor(known_monitor_idx)?; self.focus_monitor(known_monitor_idx)?;
self.focus_workspace(known_workspace_idx)?; self.focus_workspace(known_workspace_idx)?;
return Ok(()); return Ok(());
}
} }
} }
@@ -583,8 +587,7 @@ impl WindowManager {
} }
WindowManagerEvent::DisplayChange(..) WindowManagerEvent::DisplayChange(..)
| WindowManagerEvent::MouseCapture(..) | WindowManagerEvent::MouseCapture(..)
| WindowManagerEvent::Cloak(..) | WindowManagerEvent::Cloak(..) => {}
| WindowManagerEvent::Uncloak(..) => {}
}; };
if !self.focused_workspace()?.tile() { if !self.focused_workspace()?.tile() {