gardesk/gar / ce429d4

Browse files

Fix focus tracking and cross-monitor moves for window operations

- Set target workspace focus before switch_workspace in move_to_workspace
- Add set_focus after swap and cross-monitor fallback in swap_direction
- Call set_focus after move_to_monitor to update X11 focus
Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
ce429d442364cbaeac60686ae487711aeab16d2a
Parents
f6d02e8
Tree
8380e31

1 changed file

StatusFile+-
M gar/src/x11/events.rs 23 0
gar/src/x11/events.rsmodified
@@ -958,7 +958,24 @@ impl WindowManager {
958958
             // Re-apply layout
959959
             self.apply_layout()?;
960960
 
961
+            // Keep focus on the original window (now in swapped position)
962
+            self.set_focus(focused, true)?;
963
+
961964
             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
+            }
962979
         }
963980
 
964981
         Ok(())
@@ -1165,6 +1182,9 @@ impl WindowManager {
11651182
                 .insert_with_rect(window, target_focused, screen);
11661183
         }
11671184
 
1185
+        // Set target workspace focus to the moved window so switch_workspace will focus it
1186
+        self.workspaces[idx].focused = Some(window);
1187
+
11681188
         // If target workspace is visible, map the window; otherwise hide it
11691189
         if target_visible_on.is_some() {
11701190
             // Target is visible - map the window
@@ -1665,6 +1685,9 @@ impl WindowManager {
16651685
         // Apply layouts on both monitors
16661686
         self.apply_layout()?;
16671687
 
1688
+        // Set X11 focus on the moved window (updates focused_window, button grabs, EWMH)
1689
+        self.set_focus(window, true)?;
1690
+
16681691
         self.conn.flush()?;
16691692
         Ok(())
16701693
     }