Skip to content

Commit

Permalink
fix(wm): various monocle container regressions
Browse files Browse the repository at this point in the history
This commit fixes a number of monocle container-related regressions.

* Monocle container on one monitor preventing border updates on another
* Cross-monitor focus changes towards a monitor w/ a monocle container
* Cross-monitor move towards a monitor w/ a monocle container

re #819
  • Loading branch information
LGUG2Z committed May 17, 2024
1 parent fff7b5c commit bceb28d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
15 changes: 11 additions & 4 deletions komorebi/src/border_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result

let focused_monitor_idx = state.focused_monitor_idx();

for (monitor_idx, m) in state.monitors.elements().iter().enumerate() {
'monitors: for (monitor_idx, m) in state.monitors.elements().iter().enumerate() {
// Only operate on the focused workspace of each monitor
if let Some(ws) = m.focused_workspace() {
// Workspaces with tiling disabled don't have borders
Expand Down Expand Up @@ -208,15 +208,22 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result

{
let mut focus_state = FOCUS_STATE.lock();
focus_state.insert(border.hwnd, WindowKind::Monocle);
focus_state.insert(
border.hwnd,
if monitor_idx != focused_monitor_idx {
WindowKind::Unfocused
} else {
WindowKind::Monocle
},
);
}

let rect = WindowsApi::window_rect(
monocle.focused_window().copied().unwrap_or_default().hwnd(),
)?;

border.update(&rect)?;
continue 'receiver;
continue 'monitors;
}

let is_maximized = WindowsApi::is_zoomed(HWND(
Expand All @@ -236,7 +243,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
borders.remove(id);
}

continue 'receiver;
continue 'monitors;
}

// Destroy any borders not associated with the focused workspace
Expand Down
37 changes: 30 additions & 7 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,16 @@ impl WindowManager {
.ok_or_else(|| anyhow!("there is no container or monitor in this direction"))?;

self.focus_monitor(monitor_idx)?;

if let Ok(focused_workspace) = self.focused_workspace() {
if let Some(monocle) = focused_workspace.monocle_container() {
if let Some(window) = monocle.focused_window() {
WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect(
window.hwnd(),
)?)?;
}
}
}
}
Some(idx) => {
let workspace = self.focused_workspace_mut()?;
Expand All @@ -1304,13 +1314,14 @@ 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
let focused_window = self.focused_window_mut()?;
let focused_window_hwnd = focused_window.hwnd;
focused_window.focus(self.mouse_follows_focus)?;
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)?;
let focused_container = self.focused_container()?;
if let Some(stackbar) = focused_container.stackbar() {
stackbar.update(focused_container.windows(), focused_window_hwnd)?;
}
}

Ok(())
Expand Down Expand Up @@ -1361,7 +1372,19 @@ impl WindowManager {
// focus the target monitor
self.focus_monitor(target_monitor_idx)?;

// get the focused workspace on the target monitor
// unset monocle container on target workspace if there is one
let mut target_workspace_has_monocle = false;
if let Ok(target_workspace) = self.focused_workspace() {
if target_workspace.monocle_container().is_some() {
target_workspace_has_monocle = true;
}
}

if target_workspace_has_monocle {
self.toggle_monocle()?;
}

// get a mutable ref to the focused workspace on the target monitor
let target_workspace = self.focused_workspace_mut()?;

// insert the origin container into the focused workspace on the target monitor
Expand Down

0 comments on commit bceb28d

Please sign in to comment.