fix(wm): address regression from 5e714ca

This commit fixes a regression introduced in 5e714ca which broke the
cross-monitor mouse move behaviour.
This commit is contained in:
LGUG2Z
2024-04-09 11:10:21 -07:00
parent 21be01b9aa
commit 3d0ed4cfc4
+39 -21
View File
@@ -340,34 +340,52 @@ impl WindowManager {
let workspace = self.focused_workspace_mut()?; let workspace = self.focused_workspace_mut()?;
if workspace.contains_managed_window(window.hwnd) { let focused_container_idx = workspace.focused_container_idx();
let focused_container_idx = workspace.focused_container_idx(); let new_position = WindowsApi::window_rect(window.hwnd())?;
let old_position = *workspace
.latest_layout()
.get(focused_container_idx)
// If the move was to another monitor with an empty workspace, the
// workspace here will refer to that empty workspace, which won't
// have any latest layout set. We fall back to a Default for Rect
// which allows us to make a reasonable guess that the drag has taken
// place across a monitor boundary to an empty workspace
.unwrap_or(&Rect::default());
let new_position = WindowsApi::window_rect(window.hwnd())?; // This will be true if we have moved to an empty workspace on another monitor
let mut moved_across_monitors = old_position == Rect::default();
if let Some((origin_monitor_idx, origin_workspace_idx, _)) = pending {
// If we didn't move to another monitor with an empty workspace, it is
// still possible that we moved to another monitor with a populated workspace
if !moved_across_monitors {
// So we'll check if the origin monitor index and the target monitor index
// are different, if they are, we can set the override
moved_across_monitors = origin_monitor_idx != target_monitor_idx;
let old_position = *workspace if moved_across_monitors {
.latest_layout() // Want to make sure that we exclude unmanaged windows from cross-monitor
.get(focused_container_idx) // moves with a mouse, otherwise the currently focused idx container will
// If the move was to another monitor with an empty workspace, the // be moved when we just want to drag an unmanaged window
// workspace here will refer to that empty workspace, which won't let origin_workspace = self
// have any latest layout set. We fall back to a Default for Rect .monitors()
// which allows us to make a reasonable guess that the drag has taken .get(origin_monitor_idx)
// place across a monitor boundary to an empty workspace .ok_or_else(|| anyhow!("cannot get monitor idx"))?
.unwrap_or(&Rect::default()); .workspaces()
.get(origin_workspace_idx)
.ok_or_else(|| anyhow!("cannot get workspace idx"))?;
// This will be true if we have moved to an empty workspace on another monitor let managed_window =
let mut moved_across_monitors = old_position == Rect::default(); origin_workspace.contains_managed_window(window.hwnd);
if let Some((origin_monitor_idx, _, _)) = pending { if !managed_window {
// If we didn't move to another monitor with an empty workspace, it is moved_across_monitors = false;
// still possible that we moved to another monitor with a populated workspace }
if !moved_across_monitors {
// So we'll check if the origin monitor index and the target monitor index
// are different, if they are, we can set the override
moved_across_monitors = origin_monitor_idx != target_monitor_idx;
} }
} }
}
let workspace = self.focused_workspace_mut()?;
if workspace.contains_managed_window(window.hwnd) || moved_across_monitors {
let resize = Rect { let resize = Rect {
left: new_position.left - old_position.left, left: new_position.left - old_position.left,
top: new_position.top - old_position.top, top: new_position.top - old_position.top,