Restore floating size during interactive move
Browse files at this commit96e493d8b1bcfdd62f608256f2fe1b90904d5798Parent: e4094532 changed files +91 -0
- src/layout/mod.rs +17 -0
- src/tests/floating.rs +74 -0
src/layout/mod.rsmodified+17 -0
| @@ -2717,6 +2717,23 @@ impl<W: LayoutElement> Layout<W> { | ||
| 2717 | 2717 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 2718 | 2718 | if window.is_none() || window == Some(move_.tile.window().id()) { |
| 2719 | 2719 | move_.is_floating = !move_.is_floating; |
| 2720 | + | |
| 2721 | + // When going to floating, restore the floating window size. | |
| 2722 | + if move_.is_floating { | |
| 2723 | + let floating_size = move_.tile.floating_window_size(); | |
| 2724 | + let win = move_.tile.window_mut(); | |
| 2725 | + let mut size = floating_size.unwrap_or_else(|| win.expected_size()); | |
| 2726 | + // Make sure fixed-size through window rules keeps working. | |
| 2727 | + let min_size = win.min_size(); | |
| 2728 | + let max_size = win.max_size(); | |
| 2729 | + if min_size.w != 0 && min_size.w == max_size.w { | |
| 2730 | + size.w = min_size.w; | |
| 2731 | + } | |
| 2732 | + if min_size.h != 0 && min_size.h == max_size.h { | |
| 2733 | + size.h = min_size.h; | |
| 2734 | + } | |
| 2735 | + win.request_size_once(size, true); | |
| 2736 | + } | |
| 2720 | 2737 | return; |
| 2721 | 2738 | } |
| 2722 | 2739 | } |
src/tests/floating.rsmodified+74 -0
| @@ -651,3 +651,77 @@ fn state_change_doesnt_break_use_window_size() { | ||
| 651 | 651 | @"size: 300 × 600, bounds: 1920 × 1080, states: [Activated]" |
| 652 | 652 | ); |
| 653 | 653 | } |
| 654 | + | |
| 655 | +#[test] | |
| 656 | +fn interactive_move_restores_floating_size_when_set_to_floating() { | |
| 657 | + let (mut f, id, surface) = set_up(); | |
| 658 | + | |
| 659 | + f.niri().layout.toggle_window_floating(None); | |
| 660 | + f.double_roundtrip(id); | |
| 661 | + | |
| 662 | + // Change size while we're floating and commit to make niri remember it. | |
| 663 | + let window = f.client(id).window(&surface); | |
| 664 | + window.set_size(200, 200); | |
| 665 | + window.ack_last_and_commit(); | |
| 666 | + f.double_roundtrip(id); | |
| 667 | + | |
| 668 | + let _ = f.client(id).window(&surface).recent_configures(); | |
| 669 | + | |
| 670 | + // Change back to tiling. | |
| 671 | + f.niri().layout.toggle_window_floating(None); | |
| 672 | + f.double_roundtrip(id); | |
| 673 | + | |
| 674 | + // We should get a tiled size configure. | |
| 675 | + assert_snapshot!( | |
| 676 | + f.client(id).window(&surface).format_recent_configures(), | |
| 677 | + @"size: 200 × 1048, bounds: 1888 × 1048, states: [Activated]" | |
| 678 | + ); | |
| 679 | + | |
| 680 | + // Resize as requested. | |
| 681 | + let window = f.client(id).window(&surface); | |
| 682 | + let (_, configure) = window.configures_received.last().unwrap(); | |
| 683 | + window.set_size(configure.size.0 as u16, configure.size.1 as u16); | |
| 684 | + window.ack_last_and_commit(); | |
| 685 | + f.roundtrip(id); | |
| 686 | + | |
| 687 | + // Start an interactive move. | |
| 688 | + let output = f.niri_output(1); | |
| 689 | + let niri = f.niri(); | |
| 690 | + let mapped = niri.layout.windows().next().unwrap().1; | |
| 691 | + let window_id = mapped.window.clone(); | |
| 692 | + niri.layout | |
| 693 | + .interactive_move_begin(window_id.clone(), &output, Point::default()); | |
| 694 | + niri.layout.interactive_move_update( | |
| 695 | + &window_id, | |
| 696 | + Point::from((1000., 0.)), | |
| 697 | + output, | |
| 698 | + Point::default(), | |
| 699 | + ); | |
| 700 | + f.double_roundtrip(id); | |
| 701 | + | |
| 702 | + // This shouldn't request any new size because interactive move targets tiling. | |
| 703 | + assert_snapshot!( | |
| 704 | + f.client(id).window(&surface).format_recent_configures(), | |
| 705 | + @"size: 200 × 1048, bounds: 1920 × 1080, states: [Activated]" | |
| 706 | + ); | |
| 707 | + | |
| 708 | + // Change interactive move to target floating. | |
| 709 | + f.niri().layout.toggle_window_floating(None); | |
| 710 | + f.double_roundtrip(id); | |
| 711 | + | |
| 712 | + // This should restore the floating window size (200 × 200). | |
| 713 | + assert_snapshot!( | |
| 714 | + f.client(id).window(&surface).format_recent_configures(), | |
| 715 | + @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" | |
| 716 | + ); | |
| 717 | + | |
| 718 | + // End the interactive move, placing the window into floating. | |
| 719 | + f.niri().layout.interactive_move_end(&window_id); | |
| 720 | + f.double_roundtrip(id); | |
| 721 | + | |
| 722 | + // This should keep the floating window size (200 × 200). | |
| 723 | + assert_snapshot!( | |
| 724 | + f.client(id).window(&surface).format_recent_configures(), | |
| 725 | + @"" | |
| 726 | + ); | |
| 727 | +} |