Skip to content

Commit

Permalink
fix(wm): smooth transitions to monocle workspaces
Browse files Browse the repository at this point in the history
This commit adds hiding and restoring of other containers on a workspace
with monocle on/off, and exits early when a monocle container is found
on workspace restores to avoid flashing of other containers before the
workspace focus operation completes.

Focus is also restored when focusing a monocle container on another
monitor as part of a cross-monitor focus operation.

The border rendering for monocle containers has also been tightened up.

re #819
  • Loading branch information
LGUG2Z committed May 18, 2024
1 parent d2470b1 commit 27cd173
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
27 changes: 15 additions & 12 deletions komorebi/src/border_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result

// Handle the monocle container separately
if let Some(monocle) = ws.monocle_container() {
let mut to_remove = vec![];
for (id, border) in borders.iter() {
if borders_monitors.get(id).copied().unwrap_or_default() == monitor_idx {
border.destroy()?;
to_remove.push(id.clone());
}
}

for id in &to_remove {
borders.remove(id);
}

let border = match borders.entry(monocle.id().clone()) {
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
Expand Down Expand Up @@ -223,6 +211,21 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
)?;

border.update(&rect)?;

let border_hwnd = border.hwnd;
let mut to_remove = vec![];
for (id, b) in borders.iter() {
if borders_monitors.get(id).copied().unwrap_or_default() == monitor_idx
&& border_hwnd != b.hwnd
{
b.destroy()?;
to_remove.push(id.clone());
}
}

for id in &to_remove {
borders.remove(id);
}
continue 'monitors;
}

Expand Down
3 changes: 3 additions & 0 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@ impl WindowManager {
if let Ok(focused_workspace) = self.focused_workspace() {
if let Some(monocle) = focused_workspace.monocle_container() {
if let Some(window) = monocle.focused_window() {
window.focus(self.mouse_follows_focus)?;
WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect(
window.hwnd(),
)?)?;
Expand Down Expand Up @@ -1756,6 +1757,7 @@ impl WindowManager {

for container in workspace.containers_mut() {
container.set_stackbar_mode(StackbarMode::Never);
container.hide(None);
}

Ok(())
Expand All @@ -1773,6 +1775,7 @@ impl WindowManager {

for container in workspace.containers_mut() {
container.set_stackbar_mode(STACKBAR_MODE.load());
container.restore();
}

workspace.reintegrate_monocle_container()
Expand Down
12 changes: 8 additions & 4 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ impl Workspace {
}

pub fn restore(&mut self, mouse_follows_focus: bool) -> Result<()> {
if let Some(container) = self.monocle_container_mut() {
if let Some(window) = container.focused_window() {
container.restore();
window.focus(mouse_follows_focus)?;
return Ok(());
}
}

let idx = self.focused_container_idx();
let mut to_focus = None;

Expand All @@ -196,10 +204,6 @@ impl Workspace {
container.restore();
}

if let Some(container) = self.monocle_container_mut() {
container.restore();
}

for window in self.floating_windows() {
window.restore();
}
Expand Down

0 comments on commit 27cd173

Please sign in to comment.