gardesk/gar / 84ab76b

Browse files

fix: use cursor state for tiled resize instead of re-detecting

Instead of re-detecting the edge during button press (which might fail
due to slight coordinate differences), use the tiled_edge_cursor state
that was already set by motion detection. If the cursor changed to a
resize cursor, we know we're on a valid edge and can use that state
directly to start the resize operation.
Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
84ab76ba2697b4065ff516b81a1b21114e73c644
Parents
a6575bf
Tree
e255851

1 changed file

StatusFile+-
M gar/src/x11/events.rs 45 50
gar/src/x11/events.rsmodified
@@ -715,59 +715,54 @@ impl WindowManager {
715715
             }
716716
         }
717717
 
718
-        // Check for edge resize on TILED windows (click near edge with adjacent window)
719
-        if !has_mod && event.detail == 1 && self.windows.contains_key(&window) && !self.is_floating(window) {
720
-            let work_area = self.work_area();
721
-            let geometries = self.current_workspace().tree.calculate_geometries(work_area);
722
-
723
-            // Find the geometry of the clicked window
724
-            if let Some((_, my_rect)) = geometries.iter().find(|(w, _)| *w == window) {
725
-                let my_rect = *my_rect;
726
-                if let Some((w1, w2, direction)) =
727
-                    self.find_tiled_resize_edge(window, &my_rect, event.root_x, event.root_y, &geometries)
728
-                {
729
-                    // Calculate container size from both windows
730
-                    let other_rect = geometries.iter().find(|(w, _)| *w == if w1 == window { w2 } else { w1 }).map(|(_, r)| r);
731
-                    let container_size = if let Some(other) = other_rect {
732
-                        match direction {
733
-                            Direction::Left | Direction::Right => my_rect.width + other.width,
734
-                            Direction::Up | Direction::Down => my_rect.height + other.height,
735
-                        }
736
-                    } else {
737
-                        match direction {
738
-                            Direction::Left | Direction::Right => my_rect.width * 2,
739
-                            Direction::Up | Direction::Down => my_rect.height * 2,
740
-                        }
741
-                    };
718
+        // Check for edge resize on TILED windows - use cursor state from motion detection
719
+        // If the cursor was changed to resize cursor, we know we're on a valid edge
720
+        if !has_mod && event.detail == 1 {
721
+            if let Some((w1, w2, direction)) = self.tiled_edge_cursor {
722
+                let work_area = self.work_area();
723
+                let geometries = self.current_workspace().tree.calculate_geometries(work_area);
724
+
725
+                // Calculate container size from both windows
726
+                let rect1 = geometries.iter().find(|(w, _)| *w == w1).map(|(_, r)| r);
727
+                let rect2 = geometries.iter().find(|(w, _)| *w == w2).map(|(_, r)| r);
728
+                let container_size = match (rect1, rect2) {
729
+                    (Some(r1), Some(r2)) => match direction {
730
+                        Direction::Left | Direction::Right => r1.width + r2.width,
731
+                        Direction::Up | Direction::Down => r1.height + r2.height,
732
+                    },
733
+                    _ => match direction {
734
+                        Direction::Left | Direction::Right => work_area.width,
735
+                        Direction::Up | Direction::Down => work_area.height,
736
+                    },
737
+                };
742738
 
743
-                    // Get current ratio from tree (use w1 which is the "left/top" window)
744
-                    let start_ratio = self
745
-                        .current_workspace()
746
-                        .tree
747
-                        .get_split_ratio(w1, direction)
748
-                        .unwrap_or(0.5);
739
+                // Get current ratio from tree (use w1 which is the "left/top" window)
740
+                let start_ratio = self
741
+                    .current_workspace()
742
+                    .tree
743
+                    .get_split_ratio(w1, direction)
744
+                    .unwrap_or(0.5);
749745
 
750
-                    let start_pos = match direction {
751
-                        Direction::Left | Direction::Right => event.root_x,
752
-                        Direction::Up | Direction::Down => event.root_y,
753
-                    };
746
+                let start_pos = match direction {
747
+                    Direction::Left | Direction::Right => event.root_x,
748
+                    Direction::Up | Direction::Down => event.root_y,
749
+                };
754750
 
755
-                    self.drag_state = Some(DragState::TiledResize {
756
-                        direction,
757
-                        start_pos,
758
-                        start_ratio,
759
-                        window: w1,
760
-                        container_size,
761
-                        workspace: self.focused_workspace,
762
-                    });
763
-
764
-                    let cursor = match direction {
765
-                        Direction::Left | Direction::Right => self.conn.cursor_h_double,
766
-                        Direction::Up | Direction::Down => self.conn.cursor_v_double,
767
-                    };
768
-                    self.conn.grab_pointer(Some(cursor))?;
769
-                    return Ok(());
770
-                }
751
+                self.drag_state = Some(DragState::TiledResize {
752
+                    direction,
753
+                    start_pos,
754
+                    start_ratio,
755
+                    window: w1,
756
+                    container_size,
757
+                    workspace: self.focused_workspace,
758
+                });
759
+
760
+                let cursor = match direction {
761
+                    Direction::Left | Direction::Right => self.conn.cursor_h_double,
762
+                    Direction::Up | Direction::Down => self.conn.cursor_v_double,
763
+                };
764
+                self.conn.grab_pointer(Some(cursor))?;
765
+                return Ok(());
771766
             }
772767
         }
773768