Skip to content

Commit

Permalink
fix(wm): address monocle mode visual artifacts
Browse files Browse the repository at this point in the history
This commit addresses two visual artifacts with monocle mode:

* Flashing of background windows when switching to a monocle container
  on another monitor is now gone
* Stackbars are automatically disabled whenever a container enters
  monocle mode

re #819
  • Loading branch information
LGUG2Z committed May 17, 2024
1 parent bceb28d commit 835472d
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,9 @@ impl WindowManager {

let new_idx = workspace.new_idx_for_direction(direction);

// TODO: clean this up, this is awful
let mut cross_monitor_monocle = false;

// if there is no container in that direction for this workspace
match new_idx {
None => {
Expand All @@ -1297,6 +1300,8 @@ impl WindowManager {
WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect(
window.hwnd(),
)?)?;

cross_monitor_monocle = true;
}
}
}
Expand All @@ -1314,13 +1319,15 @@ impl WindowManager {
// With this piece of code, we check if we have changed focus to a container stack with
// a stackbar, and if we have, we run a quick update to make sure the focused text colour
// has been applied
if let Ok(focused_window) = self.focused_window_mut() {
let focused_window_hwnd = focused_window.hwnd;
focused_window.focus(self.mouse_follows_focus)?;

let focused_container = self.focused_container()?;
if let Some(stackbar) = focused_container.stackbar() {
stackbar.update(focused_container.windows(), focused_window_hwnd)?;
if !cross_monitor_monocle {
if let Ok(focused_window) = self.focused_window_mut() {
let focused_window_hwnd = focused_window.hwnd;
focused_window.focus(self.mouse_follows_focus)?;

let focused_container = self.focused_container()?;
if let Some(stackbar) = focused_container.stackbar() {
stackbar.update(focused_container.windows(), focused_window_hwnd)?;
}
}
}

Expand Down Expand Up @@ -1741,14 +1748,33 @@ impl WindowManager {
tracing::info!("enabling monocle");

let workspace = self.focused_workspace_mut()?;
workspace.new_monocle_container()
workspace.new_monocle_container()?;

if let Some(monocle) = workspace.monocle_container_mut() {
monocle.set_stackbar_mode(StackbarMode::Never);
}

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

Ok(())
}

#[tracing::instrument(skip(self))]
pub fn monocle_off(&mut self) -> Result<()> {
tracing::info!("disabling monocle");

let workspace = self.focused_workspace_mut()?;

if let Some(monocle) = workspace.monocle_container_mut() {
monocle.set_stackbar_mode(STACKBAR_MODE.load());
}

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

workspace.reintegrate_monocle_container()
}

Expand Down

0 comments on commit 835472d

Please sign in to comment.