Skip to content

Commit

Permalink
fix(wm): always focus desktop on empty ws
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LGUG2Z committed Oct 3, 2024
1 parent d9bffa0 commit b565b10
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,28 +825,40 @@ impl WindowManager {
}
}
}
}
} else {
if self.focused_workspace()?.containers().is_empty() {
let desktop_window = Window::from(WindowsApi::desktop_window()?);

// if we passed false for follow_focus and there is a container on the workspace
if !follow_focus && self.focused_container_mut().is_ok() {
// and we have a stack with >1 windows
if self.focused_container_mut()?.windows().len() > 1
// and we don't have a maxed window
&& self.focused_workspace()?.maximized_window().is_none()
// and we don't have a monocle container
&& self.focused_workspace()?.monocle_container().is_none()
{
if let Ok(window) = self.focused_window_mut() {
if trigger_focus {
window.focus(self.mouse_follows_focus)?;
let rect = self.focused_monitor_size()?;
WindowsApi::center_cursor_in_rect(&rect)?;

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 self.focused_container_mut().is_ok() {
// and we have a stack with >1 windows
if self.focused_container_mut()?.windows().len() > 1
// and we don't have a maxed window
&& self.focused_workspace()?.maximized_window().is_none()
// and we don't have a monocle container
&& self.focused_workspace()?.monocle_container().is_none()
{
if let Ok(window) = self.focused_window_mut() {
if trigger_focus {
window.focus(self.mouse_follows_focus)?;
}
}
}
}
}

// This is to correctly restore and focus when switching to a workspace which
// contains a managed maximized window
if !follow_focus {
// This is to correctly restore and focus when switching to a workspace which
// contains a managed maximized window
if let Some(window) = self.focused_workspace()?.maximized_window() {
window.restore();
if trigger_focus {
Expand Down

0 comments on commit b565b10

Please sign in to comment.