Make interactive move keep in the same layout (floating/tiling)
Browse files at this commit71842f07bdc566498f503b1924e959278eec2eadParent: f2bec1f2 changed files +31 -27
- src/layout/mod.rs +25 -4
- src/layout/scrolling.rs +6 -23
src/layout/mod.rsmodified+25 -4
| @@ -327,6 +327,8 @@ struct InteractiveMoveData<W: LayoutElement> { | |||
| 327 | pub(self) width: ColumnWidth, | 327 | pub(self) width: ColumnWidth, |
| 328 | /// Whether the window column was full-width. | 328 | /// Whether the window column was full-width. |
| 329 | pub(self) is_full_width: bool, | 329 | pub(self) is_full_width: bool, |
| 330 | + /// Whether the window targets the floating layout. | ||
| 331 | + pub(self) is_floating: bool, | ||
| 330 | /// Pointer location within the visual window geometry as ratio from geometry size. | 332 | /// Pointer location within the visual window geometry as ratio from geometry size. |
| 331 | /// | 333 | /// |
| 332 | /// This helps the pointer remain inside the window as it resizes. | 334 | /// This helps the pointer remain inside the window as it resizes. |
| @@ -2451,6 +2453,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2451 | return; | 2453 | return; |
| 2452 | } | 2454 | } |
| 2453 | 2455 | ||
| 2456 | + // No insert hint when targeting floating. | ||
| 2457 | + if move_.is_floating { | ||
| 2458 | + self.interactive_move = Some(InteractiveMoveState::Moving(move_)); | ||
| 2459 | + return; | ||
| 2460 | + } | ||
| 2461 | + | ||
| 2454 | let _span = tracy_client::span!("Layout::update_insert_hint::update"); | 2462 | let _span = tracy_client::span!("Layout::update_insert_hint::update"); |
| 2455 | 2463 | ||
| 2456 | if let Some(mon) = self.monitor_for_output_mut(&move_.output) { | 2464 | if let Some(mon) = self.monitor_for_output_mut(&move_.output) { |
| @@ -2661,6 +2669,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2661 | pub fn toggle_window_floating(&mut self, window: Option<&W::Id>) { | 2669 | pub fn toggle_window_floating(&mut self, window: Option<&W::Id>) { |
| 2662 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | 2670 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 2663 | if window.is_none() || window == Some(move_.tile.window().id()) { | 2671 | if window.is_none() || window == Some(move_.tile.window().id()) { |
| 2672 | + move_.is_floating = !move_.is_floating; | ||
| 2664 | return; | 2673 | return; |
| 2665 | } | 2674 | } |
| 2666 | } | 2675 | } |
| @@ -3193,7 +3202,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3193 | mut tile, | 3202 | mut tile, |
| 3194 | width, | 3203 | width, |
| 3195 | is_full_width, | 3204 | is_full_width, |
| 3196 | - is_floating: _, | 3205 | + is_floating, |
| 3197 | } = self.remove_window(window, Transaction::new()).unwrap(); | 3206 | } = self.remove_window(window, Transaction::new()).unwrap(); |
| 3198 | 3207 | ||
| 3199 | tile.stop_move_animations(); | 3208 | tile.stop_move_animations(); |
| @@ -3242,6 +3251,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3242 | pointer_pos_within_output, | 3251 | pointer_pos_within_output, |
| 3243 | width, | 3252 | width, |
| 3244 | is_full_width, | 3253 | is_full_width, |
| 3254 | + is_floating, | ||
| 3245 | pointer_ratio_within_window, | 3255 | pointer_ratio_within_window, |
| 3246 | }; | 3256 | }; |
| 3247 | 3257 | ||
| @@ -3345,14 +3355,25 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3345 | .position(|ws| ws.id() == ws_id) | 3355 | .position(|ws| ws.id() == ws_id) |
| 3346 | .unwrap(); | 3356 | .unwrap(); |
| 3347 | 3357 | ||
| 3348 | - let ws = &mut mon.workspaces[ws_idx]; | 3358 | + let position = if move_.is_floating { |
| 3349 | - let position = ws.get_insert_position(move_.pointer_pos_within_output - offset); | 3359 | + InsertPosition::Floating |
| 3360 | + } else { | ||
| 3361 | + let ws = &mut mon.workspaces[ws_idx]; | ||
| 3362 | + ws.get_insert_position(move_.pointer_pos_within_output - offset) | ||
| 3363 | + }; | ||
| 3364 | + | ||
| 3350 | (mon, ws_idx, position, offset) | 3365 | (mon, ws_idx, position, offset) |
| 3351 | } else { | 3366 | } else { |
| 3352 | let mon = &mut monitors[*active_monitor_idx]; | 3367 | let mon = &mut monitors[*active_monitor_idx]; |
| 3353 | // No point in trying to use the pointer position on the wrong output. | 3368 | // No point in trying to use the pointer position on the wrong output. |
| 3354 | let (ws, offset) = mon.workspaces_with_render_positions().next().unwrap(); | 3369 | let (ws, offset) = mon.workspaces_with_render_positions().next().unwrap(); |
| 3355 | - let position = ws.get_insert_position(Point::from((0., 0.))); | 3370 | + |
| 3371 | + let position = if move_.is_floating { | ||
| 3372 | + InsertPosition::Floating | ||
| 3373 | + } else { | ||
| 3374 | + ws.get_insert_position(Point::from((0., 0.))) | ||
| 3375 | + }; | ||
| 3376 | + | ||
| 3356 | let ws_id = ws.id(); | 3377 | let ws_id = ws.id(); |
| 3357 | let ws_idx = mon | 3378 | let ws_idx = mon |
| 3358 | .workspaces | 3379 | .workspaces |
src/layout/scrolling.rsmodified+6 -23
| @@ -26,11 +26,6 @@ use crate::window::ResolvedWindowRules; | |||
| 26 | /// Amount of touchpad movement to scroll the view for the width of one working area. | 26 | /// Amount of touchpad movement to scroll the view for the width of one working area. |
| 27 | const VIEW_GESTURE_WORKING_AREA_MOVEMENT: f64 = 1200.; | 27 | const VIEW_GESTURE_WORKING_AREA_MOVEMENT: f64 = 1200.; |
| 28 | 28 | ||
| 29 | -/// Maximum distance to the target position for an interactively moved window. | ||
| 30 | -/// | ||
| 31 | -/// If the distance is higher than this, the window will instead remain floating. | ||
| 32 | -const WINDOW_INSERT_MAX_DISTANCE: f64 = 50.; | ||
| 33 | - | ||
| 34 | /// A scrollable-tiling space for windows. | 29 | /// A scrollable-tiling space for windows. |
| 35 | #[derive(Debug)] | 30 | #[derive(Debug)] |
| 36 | pub struct ScrollingSpace<W: LayoutElement> { | 31 | pub struct ScrollingSpace<W: LayoutElement> { |
| @@ -662,9 +657,9 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 662 | self.insert_hint = None; | 657 | self.insert_hint = None; |
| 663 | } | 658 | } |
| 664 | 659 | ||
| 665 | - fn compute_insert_position(&self, pos: Point<f64, Logical>) -> (InsertPosition, f64) { | 660 | + pub fn get_insert_position(&self, pos: Point<f64, Logical>) -> InsertPosition { |
| 666 | if self.columns.is_empty() { | 661 | if self.columns.is_empty() { |
| 667 | - return (InsertPosition::NewColumn(0), pos.x.abs()); | 662 | + return InsertPosition::NewColumn(0); |
| 668 | } | 663 | } |
| 669 | 664 | ||
| 670 | let x = pos.x + self.view_pos(); | 665 | let x = pos.x + self.view_pos(); |
| @@ -675,7 +670,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 675 | 670 | ||
| 676 | // Insert position is before the first column. | 671 | // Insert position is before the first column. |
| 677 | if x < 0. { | 672 | if x < 0. { |
| 678 | - return (InsertPosition::NewColumn(0), -x); | 673 | + return InsertPosition::NewColumn(0); |
| 679 | } | 674 | } |
| 680 | 675 | ||
| 681 | // Find the closest gap between columns. | 676 | // Find the closest gap between columns. |
| @@ -695,8 +690,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 695 | 690 | ||
| 696 | // Insert position is past the last column. | 691 | // Insert position is past the last column. |
| 697 | if col_idx == self.columns.len() { | 692 | if col_idx == self.columns.len() { |
| 698 | - // col_x should be what we expect if pos.x is past the last column. | 693 | + return InsertPosition::NewColumn(closest_col_idx); |
| 699 | - return (InsertPosition::NewColumn(closest_col_idx), x - col_x); | ||
| 700 | } | 694 | } |
| 701 | 695 | ||
| 702 | // Find the closest gap between tiles. | 696 | // Find the closest gap between tiles. |
| @@ -711,21 +705,10 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 711 | let vert_dist = (col_x - x).abs(); | 705 | let vert_dist = (col_x - x).abs(); |
| 712 | let hor_dist = (tile_off.y - y).abs(); | 706 | let hor_dist = (tile_off.y - y).abs(); |
| 713 | if vert_dist <= hor_dist { | 707 | if vert_dist <= hor_dist { |
| 714 | - (InsertPosition::NewColumn(closest_col_idx), vert_dist) | 708 | + InsertPosition::NewColumn(closest_col_idx) |
| 715 | } else { | 709 | } else { |
| 716 | - ( | 710 | + InsertPosition::InColumn(col_idx, closest_tile_idx) |
| 717 | - InsertPosition::InColumn(col_idx, closest_tile_idx), | ||
| 718 | - hor_dist, | ||
| 719 | - ) | ||
| 720 | - } | ||
| 721 | - } | ||
| 722 | - | ||
| 723 | - pub fn get_insert_position(&self, pos: Point<f64, Logical>) -> InsertPosition { | ||
| 724 | - let (position, distance) = self.compute_insert_position(pos); | ||
| 725 | - if distance > WINDOW_INSERT_MAX_DISTANCE { | ||
| 726 | - return InsertPosition::Floating; | ||
| 727 | } | 711 | } |
| 728 | - position | ||
| 729 | } | 712 | } |
| 730 | 713 | ||
| 731 | pub fn add_tile( | 714 | pub fn add_tile( |