fix(wm): always focus desktop on empty ws

This commit ensures that when switching to a workspace, if that
workspace is empty, the desktop window will be focused (and focus will
be removed from the last focused window on the previous workspace)
regardless of the value of follow_focus.
This commit is contained in:
LGUG2Z
2024-10-03 10:31:31 -07:00
parent d9bffa06df
commit fe9b7e53b7
+11 -2
View File
@@ -825,10 +825,20 @@ impl WindowManager {
} }
} }
} }
} else {
if self.focused_workspace()?.containers().is_empty() {
let desktop_window = Window::from(WindowsApi::desktop_window()?);
match WindowsApi::raise_and_focus_window(desktop_window.hwnd) {
Ok(()) => {}
Err(error) => {
tracing::warn!("{} {}:{}", error, file!(), line!());
}
}
} }
// if we passed false for follow_focus and there is a container on the workspace // if we passed false for follow_focus and there is a container on the workspace
if !follow_focus && self.focused_container_mut().is_ok() { if self.focused_container_mut().is_ok() {
// and we have a stack with >1 windows // and we have a stack with >1 windows
if self.focused_container_mut()?.windows().len() > 1 if self.focused_container_mut()?.windows().len() > 1
// and we don't have a maxed window // and we don't have a maxed window
@@ -846,7 +856,6 @@ impl WindowManager {
// This is to correctly restore and focus when switching to a workspace which // This is to correctly restore and focus when switching to a workspace which
// contains a managed maximized window // contains a managed maximized window
if !follow_focus {
if let Some(window) = self.focused_workspace()?.maximized_window() { if let Some(window) = self.focused_workspace()?.maximized_window() {
window.restore(); window.restore();
if trigger_focus { if trigger_focus {