@@ -403,23 +403,32 @@ impl MonitorView { |
| 403 | let dy = dragged_center_y - other_center_y; | 403 | let dy = dragged_center_y - other_center_y; |
| 404 | | 404 | |
| 405 | // Determine snap position based on which side we're dropping on | 405 | // Determine snap position based on which side we're dropping on |
| | 406 | + // Also align on the perpendicular axis to ensure actual adjacency |
| 406 | let (new_x, new_y) = if dx.abs() > dy.abs() { | 407 | let (new_x, new_y) = if dx.abs() > dy.abs() { |
| 407 | // More horizontal - snap left or right | 408 | // More horizontal - snap left or right |
| | 409 | + // Clamp y to ensure vertical overlap with the target |
| | 410 | + let clamped_y = dragged.y |
| | 411 | + .max(other_rect.y - dragged.height as i32 + 1) |
| | 412 | + .min(other_rect.y + other_rect.height as i32 - 1); |
| 408 | if dx > 0 { | 413 | if dx > 0 { |
| 409 | // Dropping to the right of other - snap to right side | 414 | // Dropping to the right of other - snap to right side |
| 410 | - (other_rect.x + other_rect.width as i32, dragged.y) | 415 | + (other_rect.x + other_rect.width as i32, clamped_y) |
| 411 | } else { | 416 | } else { |
| 412 | // Dropping to the left of other - snap to left side | 417 | // Dropping to the left of other - snap to left side |
| 413 | - (other_rect.x - dragged.width as i32, dragged.y) | 418 | + (other_rect.x - dragged.width as i32, clamped_y) |
| 414 | } | 419 | } |
| 415 | } else { | 420 | } else { |
| 416 | // More vertical - snap above or below | 421 | // More vertical - snap above or below |
| | 422 | + // Clamp x to ensure horizontal overlap with the target |
| | 423 | + let clamped_x = dragged.x |
| | 424 | + .max(other_rect.x - dragged.width as i32 + 1) |
| | 425 | + .min(other_rect.x + other_rect.width as i32 - 1); |
| 417 | if dy > 0 { | 426 | if dy > 0 { |
| 418 | // Dropping below other - snap to bottom | 427 | // Dropping below other - snap to bottom |
| 419 | - (dragged.x, other_rect.y + other_rect.height as i32) | 428 | + (clamped_x, other_rect.y + other_rect.height as i32) |
| 420 | } else { | 429 | } else { |
| 421 | // Dropping above other - snap to top | 430 | // Dropping above other - snap to top |
| 422 | - (dragged.x, other_rect.y - dragged.height as i32) | 431 | + (clamped_x, other_rect.y - dragged.height as i32) |
| 423 | } | 432 | } |
| 424 | }; | 433 | }; |
| 425 | | 434 | |