@@ -958,7 +958,24 @@ impl WindowManager { |
| 958 | 958 | // Re-apply layout |
| 959 | 959 | self.apply_layout()?; |
| 960 | 960 | |
| 961 | + // Keep focus on the original window (now in swapped position) |
| 962 | + self.set_focus(focused, true)?; |
| 963 | + |
| 961 | 964 | tracing::debug!("Swapped with window {} in direction {:?}", target, direction); |
| 965 | + } else if self.monitors.len() > 1 { |
| 966 | + // No adjacent window - try moving to adjacent monitor |
| 967 | + let target_monitor = match direction { |
| 968 | + Direction::Left => Some("prev"), |
| 969 | + Direction::Right => Some("next"), |
| 970 | + // For up/down with horizontal monitor arrangement, could also try prev/next |
| 971 | + // but typically vertical movement doesn't cross monitors |
| 972 | + Direction::Up | Direction::Down => None, |
| 973 | + }; |
| 974 | + |
| 975 | + if let Some(target) = target_monitor { |
| 976 | + tracing::debug!("No adjacent window, moving to {} monitor", target); |
| 977 | + self.move_to_monitor(target)?; |
| 978 | + } |
| 962 | 979 | } |
| 963 | 980 | |
| 964 | 981 | Ok(()) |
@@ -1165,6 +1182,9 @@ impl WindowManager { |
| 1165 | 1182 | .insert_with_rect(window, target_focused, screen); |
| 1166 | 1183 | } |
| 1167 | 1184 | |
| 1185 | + // Set target workspace focus to the moved window so switch_workspace will focus it |
| 1186 | + self.workspaces[idx].focused = Some(window); |
| 1187 | + |
| 1168 | 1188 | // If target workspace is visible, map the window; otherwise hide it |
| 1169 | 1189 | if target_visible_on.is_some() { |
| 1170 | 1190 | // Target is visible - map the window |
@@ -1665,6 +1685,9 @@ impl WindowManager { |
| 1665 | 1685 | // Apply layouts on both monitors |
| 1666 | 1686 | self.apply_layout()?; |
| 1667 | 1687 | |
| 1688 | + // Set X11 focus on the moved window (updates focused_window, button grabs, EWMH) |
| 1689 | + self.set_focus(window, true)?; |
| 1690 | + |
| 1668 | 1691 | self.conn.flush()?; |
| 1669 | 1692 | Ok(()) |
| 1670 | 1693 | } |