Implement interactive mouse resizing
Browse files at this commit9dfa121b8e31082314d1c9347a60ef2e596494cbParent: c4ebb9f13 changed files +888 -70
- niri-visual-tests/src/cases/layout.rs +1 -1
- niri-visual-tests/src/test_window.rs +12 -2
- src/handlers/compositor.rs +16 -2
- src/handlers/xdg_shell.rs +39 -5
- src/input.rs +37 -4
- src/layout/mod.rs +154 -7
- src/layout/monitor.rs +42 -1
- src/layout/workspace.rs +308 -45
- src/lib.rs +1 -0
- src/niri.rs +2 -2
- src/resize_grab.rs +171 -0
- src/utils/mod.rs +28 -0
- src/window/mapped.rs +77 -1
niri-visual-tests/src/cases/layout.rsmodified+1 -1
| @@ -186,7 +186,7 @@ impl TestCase for Layout { | |||
| 186 | self.layout.update_output_size(&self.output); | 186 | self.layout.update_output_size(&self.output); |
| 187 | for win in &self.windows { | 187 | for win in &self.windows { |
| 188 | if win.communicate() { | 188 | if win.communicate() { |
| 189 | - self.layout.update_window(win.id()); | 189 | + self.layout.update_window(win.id(), None); |
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| 192 | } | 192 | } |
niri-visual-tests/src/test_window.rsmodified+12 -2
| @@ -2,7 +2,9 @@ use std::cell::RefCell; | |||
| 2 | use std::cmp::{max, min}; | 2 | use std::cmp::{max, min}; |
| 3 | use std::rc::Rc; | 3 | use std::rc::Rc; |
| 4 | 4 | ||
| 5 | -use niri::layout::{LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot}; | 5 | +use niri::layout::{ |
| 6 | + InteractiveResizeData, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot, | ||
| 7 | +}; | ||
| 6 | use niri::render_helpers::renderer::NiriRenderer; | 8 | use niri::render_helpers::renderer::NiriRenderer; |
| 7 | use niri::render_helpers::{RenderTarget, SplitElements}; | 9 | use niri::render_helpers::{RenderTarget, SplitElements}; |
| 8 | use niri::window::ResolvedWindowRules; | 10 | use niri::window::ResolvedWindowRules; |
| @@ -10,7 +12,7 @@ use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRen | |||
| 10 | use smithay::backend::renderer::element::{Id, Kind}; | 12 | use smithay::backend::renderer::element::{Id, Kind}; |
| 11 | use smithay::output::Output; | 13 | use smithay::output::Output; |
| 12 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 14 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 13 | -use smithay::utils::{Logical, Point, Scale, Size, Transform}; | 15 | +use smithay::utils::{Logical, Point, Scale, Serial, Size, Transform}; |
| 14 | 16 | ||
| 15 | #[derive(Debug)] | 17 | #[derive(Debug)] |
| 16 | struct TestWindowInner { | 18 | struct TestWindowInner { |
| @@ -237,4 +239,12 @@ impl LayoutElement for TestWindow { | |||
| 237 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { | 239 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { |
| 238 | None | 240 | None |
| 239 | } | 241 | } |
| 242 | + | ||
| 243 | + fn set_interactive_resize(&mut self, _data: Option<InteractiveResizeData>) {} | ||
| 244 | + | ||
| 245 | + fn cancel_interactive_resize(&mut self) {} | ||
| 246 | + | ||
| 247 | + fn interactive_resize_data(&mut self, _serial: Serial) -> Option<InteractiveResizeData> { | ||
| 248 | + None | ||
| 249 | + } | ||
| 240 | } | 250 | } |
src/handlers/compositor.rsmodified+16 -2
| @@ -13,6 +13,7 @@ use smithay::wayland::compositor::{ | |||
| 13 | SurfaceAttributes, | 13 | SurfaceAttributes, |
| 14 | }; | 14 | }; |
| 15 | use smithay::wayland::dmabuf::get_dmabuf; | 15 | use smithay::wayland::dmabuf::get_dmabuf; |
| 16 | +use smithay::wayland::shell::xdg::XdgToplevelSurfaceData; | ||
| 16 | use smithay::wayland::shm::{ShmHandler, ShmState}; | 17 | use smithay::wayland::shm::{ShmHandler, ShmState}; |
| 17 | use smithay::{delegate_compositor, delegate_shm}; | 18 | use smithay::{delegate_compositor, delegate_shm}; |
| 18 | 19 | ||
| @@ -237,8 +238,21 @@ impl CompositorHandler for State { | |||
| 237 | return; | 238 | return; |
| 238 | } | 239 | } |
| 239 | 240 | ||
| 241 | + let serial = with_states(surface, |states| { | ||
| 242 | + let role = states | ||
| 243 | + .data_map | ||
| 244 | + .get::<XdgToplevelSurfaceData>() | ||
| 245 | + .unwrap() | ||
| 246 | + .lock() | ||
| 247 | + .unwrap(); | ||
| 248 | + role.configure_serial | ||
| 249 | + }); | ||
| 250 | + if serial.is_none() { | ||
| 251 | + error!("commit on a mapped surface without a configured serial"); | ||
| 252 | + } | ||
| 253 | + | ||
| 240 | // The toplevel remains mapped. | 254 | // The toplevel remains mapped. |
| 241 | - self.niri.layout.update_window(&window); | 255 | + self.niri.layout.update_window(&window, serial); |
| 242 | 256 | ||
| 243 | // Popup placement depends on window size which might have changed. | 257 | // Popup placement depends on window size which might have changed. |
| 244 | self.update_reactive_popups(&window, &output); | 258 | self.update_reactive_popups(&window, &output); |
| @@ -256,7 +270,7 @@ impl CompositorHandler for State { | |||
| 256 | let window = mapped.window.clone(); | 270 | let window = mapped.window.clone(); |
| 257 | let output = output.clone(); | 271 | let output = output.clone(); |
| 258 | window.on_commit(); | 272 | window.on_commit(); |
| 259 | - self.niri.layout.update_window(&window); | 273 | + self.niri.layout.update_window(&window, None); |
| 260 | self.niri.queue_redraw(&output); | 274 | self.niri.queue_redraw(&output); |
| 261 | return; | 275 | return; |
| 262 | } | 276 | } |
src/handlers/xdg_shell.rsmodified+39 -5
| @@ -11,6 +11,7 @@ use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{se | |||
| 11 | use smithay::reexports::wayland_server::protocol::wl_output; | 11 | use smithay::reexports::wayland_server::protocol::wl_output; |
| 12 | use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; | 12 | use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; |
| 13 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 13 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 14 | +use smithay::reexports::wayland_server::Resource; | ||
| 14 | use smithay::utils::{Logical, Rectangle, Serial}; | 15 | use smithay::utils::{Logical, Rectangle, Serial}; |
| 15 | use smithay::wayland::compositor::{ | 16 | use smithay::wayland::compositor::{ |
| 16 | add_pre_commit_hook, send_surface_state, with_states, BufferAssignment, HookId, | 17 | add_pre_commit_hook, send_surface_state, with_states, BufferAssignment, HookId, |
| @@ -31,6 +32,7 @@ use smithay::{ | |||
| 31 | 32 | ||
| 32 | use crate::layout::workspace::ColumnWidth; | 33 | use crate::layout::workspace::ColumnWidth; |
| 33 | use crate::niri::{PopupGrabState, State}; | 34 | use crate::niri::{PopupGrabState, State}; |
| 35 | +use crate::resize_grab::ResizeGrab; | ||
| 34 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; | 36 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; |
| 35 | 37 | ||
| 36 | impl XdgShellHandler for State { | 38 | impl XdgShellHandler for State { |
| @@ -60,12 +62,44 @@ impl XdgShellHandler for State { | |||
| 60 | 62 | ||
| 61 | fn resize_request( | 63 | fn resize_request( |
| 62 | &mut self, | 64 | &mut self, |
| 63 | - _surface: ToplevelSurface, | 65 | + surface: ToplevelSurface, |
| 64 | _seat: WlSeat, | 66 | _seat: WlSeat, |
| 65 | - _serial: Serial, | 67 | + serial: Serial, |
| 66 | - _edges: ResizeEdge, | 68 | + edges: ResizeEdge, |
| 67 | ) { | 69 | ) { |
| 68 | - // FIXME | 70 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 71 | + if !pointer.has_grab(serial) { | ||
| 72 | + return; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + let Some(start_data) = pointer.grab_start_data() else { | ||
| 76 | + return; | ||
| 77 | + }; | ||
| 78 | + | ||
| 79 | + let Some((focus, _)) = &start_data.focus else { | ||
| 80 | + return; | ||
| 81 | + }; | ||
| 82 | + | ||
| 83 | + let wl_surface = surface.wl_surface(); | ||
| 84 | + if !focus.id().same_client_as(&wl_surface.id()) { | ||
| 85 | + return; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + let Some((mapped, _)) = self.niri.layout.find_window_and_output(wl_surface) else { | ||
| 89 | + return; | ||
| 90 | + }; | ||
| 91 | + | ||
| 92 | + let window = mapped.window.clone(); | ||
| 93 | + if !self | ||
| 94 | + .niri | ||
| 95 | + .layout | ||
| 96 | + .interactive_resize_begin(window.clone(), edges.into()) | ||
| 97 | + { | ||
| 98 | + return; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + let grab = ResizeGrab::new(start_data, window); | ||
| 102 | + pointer.set_grab(self, grab, serial, Focus::Clear); | ||
| 69 | } | 103 | } |
| 70 | 104 | ||
| 71 | fn reposition_request( | 105 | fn reposition_request( |
| @@ -799,7 +833,7 @@ impl State { | |||
| 799 | drop(config); | 833 | drop(config); |
| 800 | let output = output.cloned(); | 834 | let output = output.cloned(); |
| 801 | let window = mapped.window.clone(); | 835 | let window = mapped.window.clone(); |
| 802 | - self.niri.layout.update_window(&window); | 836 | + self.niri.layout.update_window(&window, None); |
| 803 | 837 | ||
| 804 | if let Some(output) = output { | 838 | if let Some(output) = output { |
| 805 | self.niri.queue_redraw(&output); | 839 | self.niri.queue_redraw(&output); |
src/input.rsmodified+37 -4
| @@ -10,16 +10,17 @@ use niri_ipc::LayoutSwitchTarget; | |||
| 10 | use smithay::backend::input::{ | 10 | use smithay::backend::input::{ |
| 11 | AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, | 11 | AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, |
| 12 | GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, | 12 | GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, |
| 13 | - InputBackend, InputEvent, KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, | 13 | + InputBackend, InputEvent, KeyState, KeyboardKeyEvent, MouseButton, PointerAxisEvent, |
| 14 | - PointerMotionEvent, ProximityState, TabletToolButtonEvent, TabletToolEvent, | 14 | + PointerButtonEvent, PointerMotionEvent, ProximityState, TabletToolButtonEvent, TabletToolEvent, |
| 15 | TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent, | 15 | TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent, |
| 16 | }; | 16 | }; |
| 17 | use smithay::backend::libinput::LibinputInputBackend; | 17 | use smithay::backend::libinput::LibinputInputBackend; |
| 18 | use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState}; | 18 | use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState}; |
| 19 | use smithay::input::pointer::{ | 19 | use smithay::input::pointer::{ |
| 20 | - AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent, | 20 | + AxisFrame, ButtonEvent, CursorImageStatus, Focus, GestureHoldBeginEvent, GestureHoldEndEvent, |
| 21 | GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, | 21 | GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, |
| 22 | - GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent, RelativeMotionEvent, | 22 | + GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, |
| 23 | + MotionEvent, RelativeMotionEvent, | ||
| 23 | }; | 24 | }; |
| 24 | use smithay::input::touch::{DownEvent, MotionEvent as TouchMotionEvent, UpEvent}; | 25 | use smithay::input::touch::{DownEvent, MotionEvent as TouchMotionEvent, UpEvent}; |
| 25 | use smithay::utils::{Logical, Point, SERIAL_COUNTER}; | 26 | use smithay::utils::{Logical, Point, SERIAL_COUNTER}; |
| @@ -27,6 +28,7 @@ use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerCons | |||
| 27 | use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; | 28 | use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; |
| 28 | 29 | ||
| 29 | use crate::niri::State; | 30 | use crate::niri::State; |
| 31 | +use crate::resize_grab::ResizeGrab; | ||
| 30 | use crate::ui::screenshot_ui::ScreenshotUi; | 32 | use crate::ui::screenshot_ui::ScreenshotUi; |
| 31 | use crate::utils::spawning::spawn; | 33 | use crate::utils::spawning::spawn; |
| 32 | use crate::utils::{center, get_monotonic_time}; | 34 | use crate::utils::{center, get_monotonic_time}; |
| @@ -1073,6 +1075,37 @@ impl State { | |||
| 1073 | let window = mapped.window.clone(); | 1075 | let window = mapped.window.clone(); |
| 1074 | self.niri.layout.activate_window(&window); | 1076 | self.niri.layout.activate_window(&window); |
| 1075 | 1077 | ||
| 1078 | + // Check if we need to start an interactive resize. | ||
| 1079 | + if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() { | ||
| 1080 | + let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | ||
| 1081 | + let mod_down = match self.backend.mod_key() { | ||
| 1082 | + CompositorMod::Super => mods.logo, | ||
| 1083 | + CompositorMod::Alt => mods.alt, | ||
| 1084 | + }; | ||
| 1085 | + if mod_down { | ||
| 1086 | + let location = pointer.current_location(); | ||
| 1087 | + let (output, pos_within_output) = self.niri.output_under(location).unwrap(); | ||
| 1088 | + let edges = self | ||
| 1089 | + .niri | ||
| 1090 | + .layout | ||
| 1091 | + .resize_edges_under(output, pos_within_output) | ||
| 1092 | + .unwrap(); | ||
| 1093 | + if self | ||
| 1094 | + .niri | ||
| 1095 | + .layout | ||
| 1096 | + .interactive_resize_begin(window.clone(), edges) | ||
| 1097 | + { | ||
| 1098 | + let start_data = PointerGrabStartData { | ||
| 1099 | + focus: None, | ||
| 1100 | + button: event.button_code(), | ||
| 1101 | + location, | ||
| 1102 | + }; | ||
| 1103 | + let grab = ResizeGrab::new(start_data, window); | ||
| 1104 | + pointer.set_grab(self, grab, serial, Focus::Clear); | ||
| 1105 | + } | ||
| 1106 | + } | ||
| 1107 | + } | ||
| 1108 | + | ||
| 1076 | // FIXME: granular. | 1109 | // FIXME: granular. |
| 1077 | self.niri.queue_redraw_all(); | 1110 | self.niri.queue_redraw_all(); |
| 1078 | } else if let Some(output) = self.niri.output_under_cursor() { | 1111 | } else if let Some(output) = self.niri.output_under_cursor() { |
src/layout/mod.rsmodified+154 -7
| @@ -43,7 +43,7 @@ use smithay::backend::renderer::element::Id; | |||
| 43 | use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; | 43 | use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; |
| 44 | use smithay::output::Output; | 44 | use smithay::output::Output; |
| 45 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 45 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 46 | -use smithay::utils::{Logical, Point, Scale, Size, Transform}; | 46 | +use smithay::utils::{Logical, Point, Scale, Serial, Size, Transform}; |
| 47 | 47 | ||
| 48 | use self::monitor::Monitor; | 48 | use self::monitor::Monitor; |
| 49 | pub use self::monitor::MonitorRenderElement; | 49 | pub use self::monitor::MonitorRenderElement; |
| @@ -52,7 +52,7 @@ use crate::niri_render_elements; | |||
| 52 | use crate::render_helpers::renderer::NiriRenderer; | 52 | use crate::render_helpers::renderer::NiriRenderer; |
| 53 | use crate::render_helpers::snapshot::RenderSnapshot; | 53 | use crate::render_helpers::snapshot::RenderSnapshot; |
| 54 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; | 54 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; |
| 55 | -use crate::utils::output_size; | 55 | +use crate::utils::{output_size, ResizeEdge}; |
| 56 | use crate::window::ResolvedWindowRules; | 56 | use crate::window::ResolvedWindowRules; |
| 57 | 57 | ||
| 58 | pub mod closing_window; | 58 | pub mod closing_window; |
| @@ -74,9 +74,16 @@ niri_render_elements! { | |||
| 74 | pub type LayoutElementRenderSnapshot = | 74 | pub type LayoutElementRenderSnapshot = |
| 75 | RenderSnapshot<BakedBuffer<TextureBuffer<GlesTexture>>, BakedBuffer<SolidColorBuffer>>; | 75 | RenderSnapshot<BakedBuffer<TextureBuffer<GlesTexture>>, BakedBuffer<SolidColorBuffer>>; |
| 76 | 76 | ||
| 77 | +#[derive(Debug, Clone, Copy)] | ||
| 78 | +pub struct InteractiveResizeData { | ||
| 79 | + pub edges: ResizeEdge, | ||
| 80 | + pub original_view_offset: i32, | ||
| 81 | + pub original_column_width: i32, | ||
| 82 | +} | ||
| 83 | + | ||
| 77 | pub trait LayoutElement { | 84 | pub trait LayoutElement { |
| 78 | /// Type that can be used as a unique ID of this element. | 85 | /// Type that can be used as a unique ID of this element. |
| 79 | - type Id: PartialEq; | 86 | + type Id: PartialEq + std::fmt::Debug; |
| 80 | 87 | ||
| 81 | /// Unique ID of this element. | 88 | /// Unique ID of this element. |
| 82 | fn id(&self) -> &Self::Id; | 89 | fn id(&self) -> &Self::Id; |
| @@ -166,6 +173,10 @@ pub trait LayoutElement { | |||
| 166 | 173 | ||
| 167 | fn animation_snapshot(&self) -> Option<&LayoutElementRenderSnapshot>; | 174 | fn animation_snapshot(&self) -> Option<&LayoutElementRenderSnapshot>; |
| 168 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot>; | 175 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot>; |
| 176 | + | ||
| 177 | + fn set_interactive_resize(&mut self, data: Option<InteractiveResizeData>); | ||
| 178 | + fn cancel_interactive_resize(&mut self); | ||
| 179 | + fn interactive_resize_data(&mut self, serial: Serial) -> Option<InteractiveResizeData>; | ||
| 169 | } | 180 | } |
| 170 | 181 | ||
| 171 | #[derive(Debug)] | 182 | #[derive(Debug)] |
| @@ -669,13 +680,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 669 | rv | 680 | rv |
| 670 | } | 681 | } |
| 671 | 682 | ||
| 672 | - pub fn update_window(&mut self, window: &W::Id) { | 683 | + pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) { |
| 673 | match &mut self.monitor_set { | 684 | match &mut self.monitor_set { |
| 674 | MonitorSet::Normal { monitors, .. } => { | 685 | MonitorSet::Normal { monitors, .. } => { |
| 675 | for mon in monitors { | 686 | for mon in monitors { |
| 676 | for ws in &mut mon.workspaces { | 687 | for ws in &mut mon.workspaces { |
| 677 | if ws.has_window(window) { | 688 | if ws.has_window(window) { |
| 678 | - ws.update_window(window); | 689 | + ws.update_window(window, serial); |
| 679 | return; | 690 | return; |
| 680 | } | 691 | } |
| 681 | } | 692 | } |
| @@ -684,7 +695,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 684 | MonitorSet::NoOutputs { workspaces, .. } => { | 695 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 685 | for ws in workspaces { | 696 | for ws in workspaces { |
| 686 | if ws.has_window(window) { | 697 | if ws.has_window(window) { |
| 687 | - ws.update_window(window); | 698 | + ws.update_window(window, serial); |
| 688 | return; | 699 | return; |
| 689 | } | 700 | } |
| 690 | } | 701 | } |
| @@ -1225,6 +1236,19 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1225 | mon.window_under(pos_within_output) | 1236 | mon.window_under(pos_within_output) |
| 1226 | } | 1237 | } |
| 1227 | 1238 | ||
| 1239 | + pub fn resize_edges_under( | ||
| 1240 | + &self, | ||
| 1241 | + output: &Output, | ||
| 1242 | + pos_within_output: Point<f64, Logical>, | ||
| 1243 | + ) -> Option<ResizeEdge> { | ||
| 1244 | + let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { | ||
| 1245 | + return None; | ||
| 1246 | + }; | ||
| 1247 | + | ||
| 1248 | + let mon = monitors.iter().find(|mon| &mon.output == output)?; | ||
| 1249 | + mon.resize_edges_under(pos_within_output) | ||
| 1250 | + } | ||
| 1251 | + | ||
| 1228 | #[cfg(test)] | 1252 | #[cfg(test)] |
| 1229 | fn verify_invariants(&self) { | 1253 | fn verify_invariants(&self) { |
| 1230 | use std::collections::HashSet; | 1254 | use std::collections::HashSet; |
| @@ -1760,6 +1784,79 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1760 | None | 1784 | None |
| 1761 | } | 1785 | } |
| 1762 | 1786 | ||
| 1787 | + pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool { | ||
| 1788 | + match &mut self.monitor_set { | ||
| 1789 | + MonitorSet::Normal { monitors, .. } => { | ||
| 1790 | + for mon in monitors { | ||
| 1791 | + for ws in &mut mon.workspaces { | ||
| 1792 | + if ws.has_window(&window) { | ||
| 1793 | + return ws.interactive_resize_begin(window, edges); | ||
| 1794 | + } | ||
| 1795 | + } | ||
| 1796 | + } | ||
| 1797 | + } | ||
| 1798 | + MonitorSet::NoOutputs { workspaces, .. } => { | ||
| 1799 | + for ws in workspaces { | ||
| 1800 | + if ws.has_window(&window) { | ||
| 1801 | + return ws.interactive_resize_begin(window, edges); | ||
| 1802 | + } | ||
| 1803 | + } | ||
| 1804 | + } | ||
| 1805 | + } | ||
| 1806 | + | ||
| 1807 | + false | ||
| 1808 | + } | ||
| 1809 | + | ||
| 1810 | + pub fn interactive_resize_update( | ||
| 1811 | + &mut self, | ||
| 1812 | + window: &W::Id, | ||
| 1813 | + delta: Point<f64, Logical>, | ||
| 1814 | + ) -> bool { | ||
| 1815 | + match &mut self.monitor_set { | ||
| 1816 | + MonitorSet::Normal { monitors, .. } => { | ||
| 1817 | + for mon in monitors { | ||
| 1818 | + for ws in &mut mon.workspaces { | ||
| 1819 | + if ws.has_window(window) { | ||
| 1820 | + return ws.interactive_resize_update(window, delta); | ||
| 1821 | + } | ||
| 1822 | + } | ||
| 1823 | + } | ||
| 1824 | + } | ||
| 1825 | + MonitorSet::NoOutputs { workspaces, .. } => { | ||
| 1826 | + for ws in workspaces { | ||
| 1827 | + if ws.has_window(window) { | ||
| 1828 | + return ws.interactive_resize_update(window, delta); | ||
| 1829 | + } | ||
| 1830 | + } | ||
| 1831 | + } | ||
| 1832 | + } | ||
| 1833 | + | ||
| 1834 | + false | ||
| 1835 | + } | ||
| 1836 | + | ||
| 1837 | + pub fn interactive_resize_end(&mut self, window: &W::Id) { | ||
| 1838 | + match &mut self.monitor_set { | ||
| 1839 | + MonitorSet::Normal { monitors, .. } => { | ||
| 1840 | + for mon in monitors { | ||
| 1841 | + for ws in &mut mon.workspaces { | ||
| 1842 | + if ws.has_window(window) { | ||
| 1843 | + ws.interactive_resize_end(Some(window)); | ||
| 1844 | + return; | ||
| 1845 | + } | ||
| 1846 | + } | ||
| 1847 | + } | ||
| 1848 | + } | ||
| 1849 | + MonitorSet::NoOutputs { workspaces, .. } => { | ||
| 1850 | + for ws in workspaces { | ||
| 1851 | + if ws.has_window(window) { | ||
| 1852 | + ws.interactive_resize_end(Some(window)); | ||
| 1853 | + return; | ||
| 1854 | + } | ||
| 1855 | + } | ||
| 1856 | + } | ||
| 1857 | + } | ||
| 1858 | + } | ||
| 1859 | + | ||
| 1763 | pub fn move_workspace_down(&mut self) { | 1860 | pub fn move_workspace_down(&mut self) { |
| 1764 | let Some(monitor) = self.active_monitor() else { | 1861 | let Some(monitor) = self.active_monitor() else { |
| 1765 | return; | 1862 | return; |
| @@ -2107,6 +2204,14 @@ mod tests { | |||
| 2107 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { | 2204 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { |
| 2108 | None | 2205 | None |
| 2109 | } | 2206 | } |
| 2207 | + | ||
| 2208 | + fn set_interactive_resize(&mut self, _data: Option<InteractiveResizeData>) {} | ||
| 2209 | + | ||
| 2210 | + fn cancel_interactive_resize(&mut self) {} | ||
| 2211 | + | ||
| 2212 | + fn interactive_resize_data(&mut self, _serial: Serial) -> Option<InteractiveResizeData> { | ||
| 2213 | + None | ||
| 2214 | + } | ||
| 2110 | } | 2215 | } |
| 2111 | 2216 | ||
| 2112 | fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> { | 2217 | fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> { |
| @@ -2148,6 +2253,20 @@ mod tests { | |||
| 2148 | prop_oneof![(-10f64..10f64), (-50000f64..50000f64),] | 2253 | prop_oneof![(-10f64..10f64), (-50000f64..50000f64),] |
| 2149 | } | 2254 | } |
| 2150 | 2255 | ||
| 2256 | + fn arbitrary_resize_edge() -> impl Strategy<Value = ResizeEdge> { | ||
| 2257 | + prop_oneof![ | ||
| 2258 | + Just(ResizeEdge::RIGHT), | ||
| 2259 | + Just(ResizeEdge::BOTTOM), | ||
| 2260 | + Just(ResizeEdge::LEFT), | ||
| 2261 | + Just(ResizeEdge::TOP), | ||
| 2262 | + Just(ResizeEdge::BOTTOM_RIGHT), | ||
| 2263 | + Just(ResizeEdge::BOTTOM_LEFT), | ||
| 2264 | + Just(ResizeEdge::TOP_RIGHT), | ||
| 2265 | + Just(ResizeEdge::TOP_LEFT), | ||
| 2266 | + Just(ResizeEdge::empty()), | ||
| 2267 | + ] | ||
| 2268 | + } | ||
| 2269 | + | ||
| 2151 | #[derive(Debug, Clone, Copy, Arbitrary)] | 2270 | #[derive(Debug, Clone, Copy, Arbitrary)] |
| 2152 | enum Op { | 2271 | enum Op { |
| 2153 | AddOutput(#[proptest(strategy = "1..=5usize")] usize), | 2272 | AddOutput(#[proptest(strategy = "1..=5usize")] usize), |
| @@ -2237,6 +2356,24 @@ mod tests { | |||
| 2237 | WorkspaceSwitchGestureEnd { | 2356 | WorkspaceSwitchGestureEnd { |
| 2238 | cancelled: bool, | 2357 | cancelled: bool, |
| 2239 | }, | 2358 | }, |
| 2359 | + InteractiveResizeBegin { | ||
| 2360 | + #[proptest(strategy = "1..=5usize")] | ||
| 2361 | + window: usize, | ||
| 2362 | + #[proptest(strategy = "arbitrary_resize_edge()")] | ||
| 2363 | + edges: ResizeEdge, | ||
| 2364 | + }, | ||
| 2365 | + InteractiveResizeUpdate { | ||
| 2366 | + #[proptest(strategy = "1..=5usize")] | ||
| 2367 | + window: usize, | ||
| 2368 | + #[proptest(strategy = "-20000f64..20000f64")] | ||
| 2369 | + dx: f64, | ||
| 2370 | + #[proptest(strategy = "-20000f64..20000f64")] | ||
| 2371 | + dy: f64, | ||
| 2372 | + }, | ||
| 2373 | + InteractiveResizeEnd { | ||
| 2374 | + #[proptest(strategy = "1..=5usize")] | ||
| 2375 | + window: usize, | ||
| 2376 | + }, | ||
| 2240 | } | 2377 | } |
| 2241 | 2378 | ||
| 2242 | impl Op { | 2379 | impl Op { |
| @@ -2455,7 +2592,8 @@ mod tests { | |||
| 2455 | } | 2592 | } |
| 2456 | 2593 | ||
| 2457 | if update { | 2594 | if update { |
| 2458 | - layout.update_window(&id); | 2595 | + // FIXME: serial. |
| 2596 | + layout.update_window(&id, None); | ||
| 2459 | } | 2597 | } |
| 2460 | } | 2598 | } |
| 2461 | Op::MoveWorkspaceToOutput(id) => { | 2599 | Op::MoveWorkspaceToOutput(id) => { |
| @@ -2495,6 +2633,15 @@ mod tests { | |||
| 2495 | Op::WorkspaceSwitchGestureEnd { cancelled } => { | 2633 | Op::WorkspaceSwitchGestureEnd { cancelled } => { |
| 2496 | layout.workspace_switch_gesture_end(cancelled); | 2634 | layout.workspace_switch_gesture_end(cancelled); |
| 2497 | } | 2635 | } |
| 2636 | + Op::InteractiveResizeBegin { window, edges } => { | ||
| 2637 | + layout.interactive_resize_begin(window, edges); | ||
| 2638 | + } | ||
| 2639 | + Op::InteractiveResizeUpdate { window, dx, dy } => { | ||
| 2640 | + layout.interactive_resize_update(&window, Point::from((dx, dy))); | ||
| 2641 | + } | ||
| 2642 | + Op::InteractiveResizeEnd { window } => { | ||
| 2643 | + layout.interactive_resize_end(&window); | ||
| 2644 | + } | ||
| 2498 | } | 2645 | } |
| 2499 | } | 2646 | } |
| 2500 | } | 2647 | } |
src/layout/monitor.rsmodified+42 -1
| @@ -19,7 +19,7 @@ use crate::render_helpers::renderer::NiriRenderer; | |||
| 19 | use crate::render_helpers::RenderTarget; | 19 | use crate::render_helpers::RenderTarget; |
| 20 | use crate::rubber_band::RubberBand; | 20 | use crate::rubber_band::RubberBand; |
| 21 | use crate::swipe_tracker::SwipeTracker; | 21 | use crate::swipe_tracker::SwipeTracker; |
| 22 | -use crate::utils::output_size; | 22 | +use crate::utils::{output_size, ResizeEdge}; |
| 23 | 23 | ||
| 24 | /// Amount of touchpad movement to scroll the height of one workspace. | 24 | /// Amount of touchpad movement to scroll the height of one workspace. |
| 25 | const WORKSPACE_GESTURE_MOVEMENT: f64 = 300.; | 25 | const WORKSPACE_GESTURE_MOVEMENT: f64 = 300.; |
| @@ -722,6 +722,47 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 722 | } | 722 | } |
| 723 | } | 723 | } |
| 724 | 724 | ||
| 725 | + pub fn resize_edges_under(&self, pos_within_output: Point<f64, Logical>) -> Option<ResizeEdge> { | ||
| 726 | + match &self.workspace_switch { | ||
| 727 | + Some(switch) => { | ||
| 728 | + let size = output_size(&self.output); | ||
| 729 | + | ||
| 730 | + let render_idx = switch.current_idx(); | ||
| 731 | + let before_idx = render_idx.floor(); | ||
| 732 | + let after_idx = render_idx.ceil(); | ||
| 733 | + | ||
| 734 | + let offset = ((render_idx - before_idx) * size.h as f64).round() as i32; | ||
| 735 | + | ||
| 736 | + if after_idx < 0. || before_idx as usize >= self.workspaces.len() { | ||
| 737 | + return None; | ||
| 738 | + } | ||
| 739 | + | ||
| 740 | + let after_idx = after_idx as usize; | ||
| 741 | + | ||
| 742 | + let (idx, ws_offset) = if pos_within_output.y < (size.h - offset) as f64 { | ||
| 743 | + if before_idx < 0. { | ||
| 744 | + return None; | ||
| 745 | + } | ||
| 746 | + | ||
| 747 | + (before_idx as usize, Point::from((0, offset))) | ||
| 748 | + } else { | ||
| 749 | + if after_idx >= self.workspaces.len() { | ||
| 750 | + return None; | ||
| 751 | + } | ||
| 752 | + | ||
| 753 | + (after_idx, Point::from((0, -size.h + offset))) | ||
| 754 | + }; | ||
| 755 | + | ||
| 756 | + let ws = &self.workspaces[idx]; | ||
| 757 | + ws.resize_edges_under(pos_within_output + ws_offset.to_f64()) | ||
| 758 | + } | ||
| 759 | + None => { | ||
| 760 | + let ws = &self.workspaces[self.active_workspace_idx]; | ||
| 761 | + ws.resize_edges_under(pos_within_output) | ||
| 762 | + } | ||
| 763 | + } | ||
| 764 | + } | ||
| 765 | + | ||
| 725 | pub fn render_above_top_layer(&self) -> bool { | 766 | pub fn render_above_top_layer(&self) -> bool { |
| 726 | // Render above the top layer only if the view is stationary. | 767 | // Render above the top layer only if the view is stationary. |
| 727 | if self.workspace_switch.is_some() { | 768 | if self.workspace_switch.is_some() { |
src/layout/workspace.rsmodified+308 -45
| @@ -10,19 +10,19 @@ use smithay::desktop::{layer_map_for_output, Window}; | |||
| 10 | use smithay::output::Output; | 10 | use smithay::output::Output; |
| 11 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 11 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| 12 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 12 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 13 | -use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; | 13 | +use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size}; |
| 14 | use smithay::wayland::compositor::send_surface_state; | 14 | use smithay::wayland::compositor::send_surface_state; |
| 15 | 15 | ||
| 16 | use super::closing_window::{ClosingWindow, ClosingWindowRenderElement}; | 16 | use super::closing_window::{ClosingWindow, ClosingWindowRenderElement}; |
| 17 | use super::tile::{Tile, TileRenderElement}; | 17 | use super::tile::{Tile, TileRenderElement}; |
| 18 | -use super::{LayoutElement, Options}; | 18 | +use super::{InteractiveResizeData, LayoutElement, Options}; |
| 19 | use crate::animation::Animation; | 19 | use crate::animation::Animation; |
| 20 | use crate::niri_render_elements; | 20 | use crate::niri_render_elements; |
| 21 | use crate::render_helpers::renderer::NiriRenderer; | 21 | use crate::render_helpers::renderer::NiriRenderer; |
| 22 | use crate::render_helpers::RenderTarget; | 22 | use crate::render_helpers::RenderTarget; |
| 23 | use crate::swipe_tracker::SwipeTracker; | 23 | use crate::swipe_tracker::SwipeTracker; |
| 24 | use crate::utils::id::IdCounter; | 24 | use crate::utils::id::IdCounter; |
| 25 | -use crate::utils::output_size; | 25 | +use crate::utils::{output_size, ResizeEdge}; |
| 26 | use crate::window::ResolvedWindowRules; | 26 | use crate::window::ResolvedWindowRules; |
| 27 | 27 | ||
| 28 | /// Amount of touchpad movement to scroll the view for the width of one working area. | 28 | /// Amount of touchpad movement to scroll the view for the width of one working area. |
| @@ -57,6 +57,9 @@ pub struct Workspace<W: LayoutElement> { | |||
| 57 | /// Index of the currently active column, if any. | 57 | /// Index of the currently active column, if any. |
| 58 | pub active_column_idx: usize, | 58 | pub active_column_idx: usize, |
| 59 | 59 | ||
| 60 | + /// Ongoing interactive resize. | ||
| 61 | + interactive_resize: Option<InteractiveResize<W>>, | ||
| 62 | + | ||
| 60 | /// Offset of the view computed from the active column. | 63 | /// Offset of the view computed from the active column. |
| 61 | /// | 64 | /// |
| 62 | /// Any gaps, including left padding from work area left exclusive zone, is handled | 65 | /// Any gaps, including left padding from work area left exclusive zone, is handled |
| @@ -128,6 +131,13 @@ struct ViewGesture { | |||
| 128 | static_view_offset: i32, | 131 | static_view_offset: i32, |
| 129 | } | 132 | } |
| 130 | 133 | ||
| 134 | +#[derive(Debug)] | ||
| 135 | +struct InteractiveResize<W: LayoutElement> { | ||
| 136 | + window: W::Id, | ||
| 137 | + original_window_size: Size<i32, Logical>, | ||
| 138 | + data: InteractiveResizeData, | ||
| 139 | +} | ||
| 140 | + | ||
| 131 | /// Width of a column. | 141 | /// Width of a column. |
| 132 | #[derive(Debug, Clone, Copy, PartialEq)] | 142 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 133 | pub enum ColumnWidth { | 143 | pub enum ColumnWidth { |
| @@ -257,6 +267,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 257 | output: Some(output), | 267 | output: Some(output), |
| 258 | columns: vec![], | 268 | columns: vec![], |
| 259 | active_column_idx: 0, | 269 | active_column_idx: 0, |
| 270 | + interactive_resize: None, | ||
| 260 | view_offset: 0, | 271 | view_offset: 0, |
| 261 | view_offset_adj: None, | 272 | view_offset_adj: None, |
| 262 | activate_prev_column_on_removal: None, | 273 | activate_prev_column_on_removal: None, |
| @@ -275,6 +286,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 275 | working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)), | 286 | working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)), |
| 276 | columns: vec![], | 287 | columns: vec![], |
| 277 | active_column_idx: 0, | 288 | active_column_idx: 0, |
| 289 | + interactive_resize: None, | ||
| 278 | view_offset: 0, | 290 | view_offset: 0, |
| 279 | view_offset_adj: None, | 291 | view_offset_adj: None, |
| 280 | activate_prev_column_on_removal: None, | 292 | activate_prev_column_on_removal: None, |
| @@ -697,6 +709,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 697 | // A different column was activated; reset the flag. | 709 | // A different column was activated; reset the flag. |
| 698 | self.activate_prev_column_on_removal = None; | 710 | self.activate_prev_column_on_removal = None; |
| 699 | self.view_offset_before_fullscreen = None; | 711 | self.view_offset_before_fullscreen = None; |
| 712 | + self.interactive_resize = None; | ||
| 700 | } | 713 | } |
| 701 | 714 | ||
| 702 | pub fn has_windows(&self) -> bool { | 715 | pub fn has_windows(&self) -> bool { |
| @@ -957,6 +970,13 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 957 | tile.window().output_leave(output); | 970 | tile.window().output_leave(output); |
| 958 | } | 971 | } |
| 959 | 972 | ||
| 973 | + // Stop interactive resize. | ||
| 974 | + if let Some(resize) = &self.interactive_resize { | ||
| 975 | + if tile.window().id() == &resize.window { | ||
| 976 | + self.interactive_resize = None; | ||
| 977 | + } | ||
| 978 | + } | ||
| 979 | + | ||
| 960 | if column.tiles.is_empty() { | 980 | if column.tiles.is_empty() { |
| 961 | if column_idx + 1 == self.active_column_idx { | 981 | if column_idx + 1 == self.active_column_idx { |
| 962 | // The previous column, that we were going to activate upon removal of the active | 982 | // The previous column, that we were going to activate upon removal of the active |
| @@ -1055,6 +1075,17 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1055 | } | 1075 | } |
| 1056 | } | 1076 | } |
| 1057 | 1077 | ||
| 1078 | + // Stop interactive resize. | ||
| 1079 | + if let Some(resize) = &self.interactive_resize { | ||
| 1080 | + if column | ||
| 1081 | + .tiles | ||
| 1082 | + .iter() | ||
| 1083 | + .any(|tile| tile.window().id() == &resize.window) | ||
| 1084 | + { | ||
| 1085 | + self.interactive_resize = None; | ||
| 1086 | + } | ||
| 1087 | + } | ||
| 1088 | + | ||
| 1058 | if column_idx + 1 == self.active_column_idx { | 1089 | if column_idx + 1 == self.active_column_idx { |
| 1059 | // The previous column, that we were going to activate upon removal of the active | 1090 | // The previous column, that we were going to activate upon removal of the active |
| 1060 | // column, has just been itself removed. | 1091 | // column, has just been itself removed. |
| @@ -1109,7 +1140,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1109 | .into_window() | 1140 | .into_window() |
| 1110 | } | 1141 | } |
| 1111 | 1142 | ||
| 1112 | - pub fn update_window(&mut self, window: &W::Id) { | 1143 | + pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) { |
| 1113 | let (col_idx, column) = self | 1144 | let (col_idx, column) = self |
| 1114 | .columns | 1145 | .columns |
| 1115 | .iter_mut() | 1146 | .iter_mut() |
| @@ -1153,31 +1184,64 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1153 | } | 1184 | } |
| 1154 | } | 1185 | } |
| 1155 | 1186 | ||
| 1156 | - if col_idx == self.active_column_idx | 1187 | + if col_idx == self.active_column_idx { |
| 1157 | - && !matches!(self.view_offset_adj, Some(ViewOffsetAdjustment::Gesture(_))) | 1188 | + let col = &mut self.columns[col_idx]; |
| 1158 | - { | 1189 | + let tile = &mut col.tiles[tile_idx]; |
| 1159 | - // We might need to move the view to ensure the resized window is still visible. | 1190 | + let window = tile.window_mut(); |
| 1160 | - let current_x = self.view_pos(); | 1191 | + |
| 1161 | - | 1192 | + let resize = serial.and_then(|serial| window.interactive_resize_data(serial)); |
| 1162 | - // Upon unfullscreening, restore the view offset. | 1193 | + |
| 1163 | - let is_fullscreen = self.columns[col_idx].tiles[tile_idx].is_fullscreen(); | 1194 | + // If this was the last resize commit, this function will now return None. This way we |
| 1164 | - if was_fullscreen && !is_fullscreen { | 1195 | + // can animate the window into view after the last resize commit. |
| 1165 | - if let Some(prev_offset) = self.view_offset_before_fullscreen.take() { | 1196 | + let resize_still_ongoing = serial |
| 1166 | - self.animate_view_offset(current_x, col_idx, prev_offset); | 1197 | + .and_then(|serial| window.interactive_resize_data(serial)) |
| 1198 | + .is_some(); | ||
| 1199 | + | ||
| 1200 | + if let Some(resize) = resize { | ||
| 1201 | + // If this is an interactive resize commit of an active window, then we need to | ||
| 1202 | + // either preserve the view offset or adjust it accordingly. | ||
| 1203 | + let centered = self.options.center_focused_column == CenterFocusedColumn::Always; | ||
| 1204 | + | ||
| 1205 | + let width = col.width(); | ||
| 1206 | + if centered { | ||
| 1207 | + self.view_offset = | ||
| 1208 | + -(self.working_area.size.w - width) / 2 - self.working_area.loc.x; | ||
| 1209 | + } else if resize.edges.contains(ResizeEdge::LEFT) { | ||
| 1210 | + self.view_offset = | ||
| 1211 | + resize.original_view_offset + width - resize.original_column_width; | ||
| 1167 | } | 1212 | } |
| 1213 | + | ||
| 1214 | + // We *could* compute the right offsets here to preserve the gesture but it's | ||
| 1215 | + // pretty edge-case-y so it's fine to just cancel it. | ||
| 1216 | + self.view_offset_adj = None; | ||
| 1168 | } | 1217 | } |
| 1169 | 1218 | ||
| 1170 | - // Synchronize the horizontal view movement with the resize so that it looks nice. This | 1219 | + if !resize_still_ongoing |
| 1171 | - // is especially important for always-centered view. | 1220 | + && !matches!(self.view_offset_adj, Some(ViewOffsetAdjustment::Gesture(_))) |
| 1172 | - let config = if started_resize_anim { | 1221 | + { |
| 1173 | - self.options.animations.window_resize.anim | 1222 | + // We might need to move the view to ensure the resized window is still visible. |
| 1174 | - } else { | 1223 | + let current_x = self.view_pos(); |
| 1175 | - self.options.animations.horizontal_view_movement.0 | ||
| 1176 | - }; | ||
| 1177 | 1224 | ||
| 1178 | - // FIXME: we will want to skip the animation in some cases here to make continuously | 1225 | + // Upon unfullscreening, restore the view offset. |
| 1179 | - // resizing windows not look janky. | 1226 | + let is_fullscreen = self.columns[col_idx].tiles[tile_idx].is_fullscreen(); |
| 1180 | - self.animate_view_offset_to_column_with_config(current_x, col_idx, None, config); | 1227 | + if was_fullscreen && !is_fullscreen { |
| 1228 | + if let Some(prev_offset) = self.view_offset_before_fullscreen.take() { | ||
| 1229 | + self.animate_view_offset(current_x, col_idx, prev_offset); | ||
| 1230 | + } | ||
| 1231 | + } | ||
| 1232 | + | ||
| 1233 | + // Synchronize the horizontal view movement with the resize so that it looks nice. | ||
| 1234 | + // This is especially important for always-centered view. | ||
| 1235 | + let config = if started_resize_anim { | ||
| 1236 | + self.options.animations.window_resize.anim | ||
| 1237 | + } else { | ||
| 1238 | + self.options.animations.horizontal_view_movement.0 | ||
| 1239 | + }; | ||
| 1240 | + | ||
| 1241 | + // FIXME: we will want to skip the animation in some cases here to make continuously | ||
| 1242 | + // resizing windows not look janky. | ||
| 1243 | + self.animate_view_offset_to_column_with_config(current_x, col_idx, None, config); | ||
| 1244 | + } | ||
| 1181 | } | 1245 | } |
| 1182 | } | 1246 | } |
| 1183 | 1247 | ||
| @@ -1332,10 +1396,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1332 | column.verify_invariants(); | 1396 | column.verify_invariants(); |
| 1333 | } | 1397 | } |
| 1334 | 1398 | ||
| 1399 | + let col = &self.columns[self.active_column_idx]; | ||
| 1400 | + | ||
| 1335 | // When we have an unfullscreen view offset stored, the active column should have a | 1401 | // When we have an unfullscreen view offset stored, the active column should have a |
| 1336 | // fullscreen tile. | 1402 | // fullscreen tile. |
| 1337 | if self.view_offset_before_fullscreen.is_some() { | 1403 | if self.view_offset_before_fullscreen.is_some() { |
| 1338 | - let col = &self.columns[self.active_column_idx]; | ||
| 1339 | assert!( | 1404 | assert!( |
| 1340 | col.is_fullscreen | 1405 | col.is_fullscreen |
| 1341 | || col.tiles.iter().any(|tile| { | 1406 | || col.tiles.iter().any(|tile| { |
| @@ -1344,6 +1409,16 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1344 | ); | 1409 | ); |
| 1345 | } | 1410 | } |
| 1346 | } | 1411 | } |
| 1412 | + | ||
| 1413 | + if let Some(resize) = &self.interactive_resize { | ||
| 1414 | + assert!( | ||
| 1415 | + self.columns | ||
| 1416 | + .iter() | ||
| 1417 | + .flat_map(|col| &col.tiles) | ||
| 1418 | + .any(|tile| tile.window().id() == &resize.window), | ||
| 1419 | + "interactive resize window must be present on the workspace" | ||
| 1420 | + ); | ||
| 1421 | + } | ||
| 1347 | } | 1422 | } |
| 1348 | 1423 | ||
| 1349 | pub fn focus_left(&mut self) { | 1424 | pub fn focus_left(&mut self) { |
| @@ -1394,7 +1469,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1394 | let current_col_x = self.column_x(self.active_column_idx); | 1469 | let current_col_x = self.column_x(self.active_column_idx); |
| 1395 | let next_col_x = self.column_x(self.active_column_idx + 1); | 1470 | let next_col_x = self.column_x(self.active_column_idx + 1); |
| 1396 | 1471 | ||
| 1397 | - let column = self.columns.remove(self.active_column_idx); | 1472 | + let mut column = self.columns.remove(self.active_column_idx); |
| 1473 | + cancel_resize_if_this_column(&mut self.interactive_resize, &mut column); | ||
| 1398 | self.columns.insert(new_idx, column); | 1474 | self.columns.insert(new_idx, column); |
| 1399 | 1475 | ||
| 1400 | // Preserve the camera position when moving to the left. | 1476 | // Preserve the camera position when moving to the left. |
| @@ -1696,6 +1772,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1696 | self.active_column_idx, | 1772 | self.active_column_idx, |
| 1697 | self.options.animations.horizontal_view_movement.0, | 1773 | self.options.animations.horizontal_view_movement.0, |
| 1698 | ); | 1774 | ); |
| 1775 | + | ||
| 1776 | + if !self.columns.is_empty() { | ||
| 1777 | + let col = &mut self.columns[self.active_column_idx]; | ||
| 1778 | + cancel_resize_if_this_column(&mut self.interactive_resize, col); | ||
| 1779 | + } | ||
| 1699 | } | 1780 | } |
| 1700 | 1781 | ||
| 1701 | fn view_pos(&self) -> i32 { | 1782 | fn view_pos(&self) -> i32 { |
| @@ -1818,12 +1899,48 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1818 | }) | 1899 | }) |
| 1819 | } | 1900 | } |
| 1820 | 1901 | ||
| 1902 | + pub fn resize_edges_under(&self, pos: Point<f64, Logical>) -> Option<ResizeEdge> { | ||
| 1903 | + if self.columns.is_empty() { | ||
| 1904 | + return None; | ||
| 1905 | + } | ||
| 1906 | + | ||
| 1907 | + self.tiles_in_render_order().find_map(|(tile, tile_pos)| { | ||
| 1908 | + let pos_within_tile = pos - tile_pos.to_f64(); | ||
| 1909 | + | ||
| 1910 | + // This logic should be consistent with window_under() in when it returns Some vs. | ||
| 1911 | + // None. | ||
| 1912 | + if tile.is_in_input_region(pos_within_tile) | ||
| 1913 | + || tile.is_in_activation_region(pos_within_tile) | ||
| 1914 | + { | ||
| 1915 | + let size = tile.tile_size().to_f64(); | ||
| 1916 | + | ||
| 1917 | + let mut edges = ResizeEdge::empty(); | ||
| 1918 | + if pos_within_tile.x < size.w / 3. { | ||
| 1919 | + edges |= ResizeEdge::LEFT; | ||
| 1920 | + } else if 2. * size.w / 3. < pos_within_tile.x { | ||
| 1921 | + edges |= ResizeEdge::RIGHT; | ||
| 1922 | + } | ||
| 1923 | + if pos_within_tile.y < size.h / 3. { | ||
| 1924 | + edges |= ResizeEdge::TOP; | ||
| 1925 | + } else if 2. * size.h / 3. < pos_within_tile.y { | ||
| 1926 | + edges |= ResizeEdge::BOTTOM; | ||
| 1927 | + } | ||
| 1928 | + return Some(edges); | ||
| 1929 | + } | ||
| 1930 | + | ||
| 1931 | + None | ||
| 1932 | + }) | ||
| 1933 | + } | ||
| 1934 | + | ||
| 1821 | pub fn toggle_width(&mut self) { | 1935 | pub fn toggle_width(&mut self) { |
| 1822 | if self.columns.is_empty() { | 1936 | if self.columns.is_empty() { |
| 1823 | return; | 1937 | return; |
| 1824 | } | 1938 | } |
| 1825 | 1939 | ||
| 1826 | - self.columns[self.active_column_idx].toggle_width(); | 1940 | + let col = &mut self.columns[self.active_column_idx]; |
| 1941 | + col.toggle_width(); | ||
| 1942 | + | ||
| 1943 | + cancel_resize_if_this_column(&mut self.interactive_resize, col); | ||
| 1827 | } | 1944 | } |
| 1828 | 1945 | ||
| 1829 | pub fn toggle_full_width(&mut self) { | 1946 | pub fn toggle_full_width(&mut self) { |
| @@ -1831,7 +1948,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1831 | return; | 1948 | return; |
| 1832 | } | 1949 | } |
| 1833 | 1950 | ||
| 1834 | - self.columns[self.active_column_idx].toggle_full_width(); | 1951 | + let col = &mut self.columns[self.active_column_idx]; |
| 1952 | + col.toggle_full_width(); | ||
| 1953 | + | ||
| 1954 | + cancel_resize_if_this_column(&mut self.interactive_resize, col); | ||
| 1835 | } | 1955 | } |
| 1836 | 1956 | ||
| 1837 | pub fn set_column_width(&mut self, change: SizeChange) { | 1957 | pub fn set_column_width(&mut self, change: SizeChange) { |
| @@ -1839,7 +1959,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1839 | return; | 1959 | return; |
| 1840 | } | 1960 | } |
| 1841 | 1961 | ||
| 1842 | - self.columns[self.active_column_idx].set_column_width(change); | 1962 | + let col = &mut self.columns[self.active_column_idx]; |
| 1963 | + col.set_column_width(change, None, true); | ||
| 1964 | + | ||
| 1965 | + cancel_resize_if_this_column(&mut self.interactive_resize, col); | ||
| 1843 | } | 1966 | } |
| 1844 | 1967 | ||
| 1845 | pub fn set_window_height(&mut self, change: SizeChange) { | 1968 | pub fn set_window_height(&mut self, change: SizeChange) { |
| @@ -1847,7 +1970,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1847 | return; | 1970 | return; |
| 1848 | } | 1971 | } |
| 1849 | 1972 | ||
| 1850 | - self.columns[self.active_column_idx].set_window_height(change); | 1973 | + let col = &mut self.columns[self.active_column_idx]; |
| 1974 | + col.set_window_height(change, None, true); | ||
| 1975 | + | ||
| 1976 | + cancel_resize_if_this_column(&mut self.interactive_resize, col); | ||
| 1851 | } | 1977 | } |
| 1852 | 1978 | ||
| 1853 | pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) { | 1979 | pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) { |
| @@ -1867,6 +1993,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1867 | 1993 | ||
| 1868 | let mut col = &mut self.columns[col_idx]; | 1994 | let mut col = &mut self.columns[col_idx]; |
| 1869 | 1995 | ||
| 1996 | + cancel_resize_if_this_column(&mut self.interactive_resize, col); | ||
| 1997 | + | ||
| 1870 | if is_fullscreen && col.tiles.len() > 1 { | 1998 | if is_fullscreen && col.tiles.len() > 1 { |
| 1871 | // This wasn't the only window in its column; extract it into a separate column. | 1999 | // This wasn't the only window in its column; extract it into a separate column. |
| 1872 | let target_window_was_focused = | 2000 | let target_window_was_focused = |
| @@ -2188,8 +2316,124 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2188 | true | 2316 | true |
| 2189 | } | 2317 | } |
| 2190 | 2318 | ||
| 2319 | + pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool { | ||
| 2320 | + let col = self | ||
| 2321 | + .columns | ||
| 2322 | + .iter_mut() | ||
| 2323 | + .find(|col| col.contains(&window)) | ||
| 2324 | + .unwrap(); | ||
| 2325 | + | ||
| 2326 | + if col.is_fullscreen { | ||
| 2327 | + return false; | ||
| 2328 | + } | ||
| 2329 | + | ||
| 2330 | + let tile = col | ||
| 2331 | + .tiles | ||
| 2332 | + .iter_mut() | ||
| 2333 | + .find(|tile| tile.window().id() == &window) | ||
| 2334 | + .unwrap(); | ||
| 2335 | + | ||
| 2336 | + let original_window_size = tile.window_size(); | ||
| 2337 | + | ||
| 2338 | + let resize = InteractiveResize { | ||
| 2339 | + window, | ||
| 2340 | + original_window_size, | ||
| 2341 | + data: InteractiveResizeData { | ||
| 2342 | + edges, | ||
| 2343 | + original_view_offset: self.view_offset, | ||
| 2344 | + original_column_width: col.width(), | ||
| 2345 | + }, | ||
| 2346 | + }; | ||
| 2347 | + self.interactive_resize = Some(resize); | ||
| 2348 | + | ||
| 2349 | + // Stop ongoing animation. | ||
| 2350 | + self.view_offset_adj = None; | ||
| 2351 | + | ||
| 2352 | + true | ||
| 2353 | + } | ||
| 2354 | + | ||
| 2355 | + pub fn interactive_resize_update( | ||
| 2356 | + &mut self, | ||
| 2357 | + window: &W::Id, | ||
| 2358 | + delta: Point<f64, Logical>, | ||
| 2359 | + ) -> bool { | ||
| 2360 | + let Some(resize) = &self.interactive_resize else { | ||
| 2361 | + return false; | ||
| 2362 | + }; | ||
| 2363 | + | ||
| 2364 | + if window != &resize.window { | ||
| 2365 | + return false; | ||
| 2366 | + } | ||
| 2367 | + | ||
| 2368 | + let col = self | ||
| 2369 | + .columns | ||
| 2370 | + .iter_mut() | ||
| 2371 | + .find(|col| col.contains(window)) | ||
| 2372 | + .unwrap(); | ||
| 2373 | + | ||
| 2374 | + let tile_idx = col | ||
| 2375 | + .tiles | ||
| 2376 | + .iter() | ||
| 2377 | + .position(|tile| tile.window().id() == window) | ||
| 2378 | + .unwrap(); | ||
| 2379 | + | ||
| 2380 | + if resize.data.edges.intersects(ResizeEdge::LEFT_RIGHT) { | ||
| 2381 | + let mut dx = delta.x; | ||
| 2382 | + if resize.data.edges.contains(ResizeEdge::LEFT) { | ||
| 2383 | + dx = -dx; | ||
| 2384 | + }; | ||
| 2385 | + | ||
| 2386 | + if self.options.center_focused_column == CenterFocusedColumn::Always { | ||
| 2387 | + dx *= 2.; | ||
| 2388 | + } | ||
| 2389 | + | ||
| 2390 | + let window_width = (f64::from(resize.original_window_size.w) + dx).round() as i32; | ||
| 2391 | + col.set_column_width(SizeChange::SetFixed(window_width), Some(tile_idx), false); | ||
| 2392 | + } | ||
| 2393 | + | ||
| 2394 | + if resize.data.edges.intersects(ResizeEdge::TOP_BOTTOM) { | ||
| 2395 | + // Prevent the simplest case of weird resizing (top edge when this is the topmost | ||
| 2396 | + // window). | ||
| 2397 | + if !(resize.data.edges.contains(ResizeEdge::TOP) && tile_idx == 0) { | ||
| 2398 | + let mut dy = delta.y; | ||
| 2399 | + if resize.data.edges.contains(ResizeEdge::TOP) { | ||
| 2400 | + dy = -dy; | ||
| 2401 | + }; | ||
| 2402 | + | ||
| 2403 | + // FIXME: some smarter height distribution would be nice here so that vertical | ||
| 2404 | + // resizes work as expected in more cases. | ||
| 2405 | + | ||
| 2406 | + let window_height = (f64::from(resize.original_window_size.h) + dy).round() as i32; | ||
| 2407 | + col.set_window_height(SizeChange::SetFixed(window_height), Some(tile_idx), false); | ||
| 2408 | + } | ||
| 2409 | + } | ||
| 2410 | + | ||
| 2411 | + true | ||
| 2412 | + } | ||
| 2413 | + | ||
| 2414 | + pub fn interactive_resize_end(&mut self, window: Option<&W::Id>) { | ||
| 2415 | + let Some(resize) = &self.interactive_resize else { | ||
| 2416 | + return; | ||
| 2417 | + }; | ||
| 2418 | + | ||
| 2419 | + if let Some(window) = window { | ||
| 2420 | + if window != &resize.window { | ||
| 2421 | + return; | ||
| 2422 | + } | ||
| 2423 | + } | ||
| 2424 | + | ||
| 2425 | + self.interactive_resize = None; | ||
| 2426 | + } | ||
| 2427 | + | ||
| 2191 | pub fn refresh(&mut self, is_active: bool) { | 2428 | pub fn refresh(&mut self, is_active: bool) { |
| 2192 | for (col_idx, col) in self.columns.iter_mut().enumerate() { | 2429 | for (col_idx, col) in self.columns.iter_mut().enumerate() { |
| 2430 | + let mut col_resize_data = None; | ||
| 2431 | + if let Some(resize) = &self.interactive_resize { | ||
| 2432 | + if col.contains(&resize.window) { | ||
| 2433 | + col_resize_data = Some(resize.data); | ||
| 2434 | + } | ||
| 2435 | + } | ||
| 2436 | + | ||
| 2193 | for (tile_idx, tile) in col.tiles.iter_mut().enumerate() { | 2437 | for (tile_idx, tile) in col.tiles.iter_mut().enumerate() { |
| 2194 | let win = tile.window_mut(); | 2438 | let win = tile.window_mut(); |
| 2195 | let active = is_active | 2439 | let active = is_active |
| @@ -2197,6 +2441,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2197 | && col.active_tile_idx == tile_idx; | 2441 | && col.active_tile_idx == tile_idx; |
| 2198 | win.set_activated(active); | 2442 | win.set_activated(active); |
| 2199 | 2443 | ||
| 2444 | + win.set_interactive_resize(col_resize_data); | ||
| 2445 | + | ||
| 2200 | let border_config = win.rules().border.resolve_against(self.options.border); | 2446 | let border_config = win.rules().border.resolve_against(self.options.border); |
| 2201 | let bounds = compute_toplevel_bounds( | 2447 | let bounds = compute_toplevel_bounds( |
| 2202 | border_config, | 2448 | border_config, |
| @@ -2310,10 +2556,10 @@ impl<W: LayoutElement> Column<W> { | |||
| 2310 | } | 2556 | } |
| 2311 | } | 2557 | } |
| 2312 | 2558 | ||
| 2313 | - fn set_width(&mut self, width: ColumnWidth) { | 2559 | + fn set_width(&mut self, width: ColumnWidth, animate: bool) { |
| 2314 | self.width = width; | 2560 | self.width = width; |
| 2315 | self.is_full_width = false; | 2561 | self.is_full_width = false; |
| 2316 | - self.update_tile_sizes(true); | 2562 | + self.update_tile_sizes(animate); |
| 2317 | } | 2563 | } |
| 2318 | 2564 | ||
| 2319 | pub fn advance_animations(&mut self, current_time: Duration) { | 2565 | pub fn advance_animations(&mut self, current_time: Duration) { |
| @@ -2695,7 +2941,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2695 | } | 2941 | } |
| 2696 | }; | 2942 | }; |
| 2697 | let width = ColumnWidth::Preset(idx); | 2943 | let width = ColumnWidth::Preset(idx); |
| 2698 | - self.set_width(width); | 2944 | + self.set_width(width, true); |
| 2699 | } | 2945 | } |
| 2700 | 2946 | ||
| 2701 | fn toggle_full_width(&mut self) { | 2947 | fn toggle_full_width(&mut self) { |
| @@ -2703,7 +2949,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2703 | self.update_tile_sizes(true); | 2949 | self.update_tile_sizes(true); |
| 2704 | } | 2950 | } |
| 2705 | 2951 | ||
| 2706 | - fn set_column_width(&mut self, change: SizeChange) { | 2952 | + fn set_column_width(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) { |
| 2707 | let width = if self.is_full_width { | 2953 | let width = if self.is_full_width { |
| 2708 | ColumnWidth::Proportion(1.) | 2954 | ColumnWidth::Proportion(1.) |
| 2709 | } else { | 2955 | } else { |
| @@ -2724,9 +2970,10 @@ impl<W: LayoutElement> Column<W> { | |||
| 2724 | let width = match (current, change) { | 2970 | let width = match (current, change) { |
| 2725 | (_, SizeChange::SetFixed(fixed)) => { | 2971 | (_, SizeChange::SetFixed(fixed)) => { |
| 2726 | // As a special case, setting a fixed column width will compute it in such a way | 2972 | // As a special case, setting a fixed column width will compute it in such a way |
| 2727 | - // that the active window gets that width. This is the intention behind the ability | 2973 | + // that the specified (usually active) window gets that width. This is the |
| 2728 | - // to set a fixed size. | 2974 | + // intention behind the ability to set a fixed size. |
| 2729 | - let tile = &self.tiles[self.active_tile_idx]; | 2975 | + let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); |
| 2976 | + let tile = &self.tiles[tile_idx]; | ||
| 2730 | ColumnWidth::Fixed(tile.tile_width_for_window_width(fixed).clamp(1, MAX_PX)) | 2977 | ColumnWidth::Fixed(tile.tile_width_for_window_width(fixed).clamp(1, MAX_PX)) |
| 2731 | } | 2978 | } |
| 2732 | (_, SizeChange::SetProportion(proportion)) => { | 2979 | (_, SizeChange::SetProportion(proportion)) => { |
| @@ -2749,12 +2996,13 @@ impl<W: LayoutElement> Column<W> { | |||
| 2749 | (ColumnWidth::Preset(_), _) => unreachable!(), | 2996 | (ColumnWidth::Preset(_), _) => unreachable!(), |
| 2750 | }; | 2997 | }; |
| 2751 | 2998 | ||
| 2752 | - self.set_width(width); | 2999 | + self.set_width(width, animate); |
| 2753 | } | 3000 | } |
| 2754 | 3001 | ||
| 2755 | - fn set_window_height(&mut self, change: SizeChange) { | 3002 | + fn set_window_height(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) { |
| 2756 | - let current = self.heights[self.active_tile_idx]; | 3003 | + let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); |
| 2757 | - let tile = &self.tiles[self.active_tile_idx]; | 3004 | + let current = self.heights[tile_idx]; |
| 3005 | + let tile = &self.tiles[tile_idx]; | ||
| 2758 | let current_window_px = match current { | 3006 | let current_window_px = match current { |
| 2759 | WindowHeight::Auto => tile.window_size().h, | 3007 | WindowHeight::Auto => tile.window_size().h, |
| 2760 | WindowHeight::Fixed(height) => height, | 3008 | WindowHeight::Fixed(height) => height, |
| @@ -2787,7 +3035,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2787 | }; | 3035 | }; |
| 2788 | 3036 | ||
| 2789 | // Clamp it against the window height constraints. | 3037 | // Clamp it against the window height constraints. |
| 2790 | - let win = &self.tiles[self.active_tile_idx].window(); | 3038 | + let win = &self.tiles[tile_idx].window(); |
| 2791 | let min_h = win.min_size().h; | 3039 | let min_h = win.min_size().h; |
| 2792 | let max_h = win.max_size().h; | 3040 | let max_h = win.max_size().h; |
| 2793 | 3041 | ||
| @@ -2798,8 +3046,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 2798 | window_height = window_height.max(min_h); | 3046 | window_height = window_height.max(min_h); |
| 2799 | } | 3047 | } |
| 2800 | 3048 | ||
| 2801 | - self.heights[self.active_tile_idx] = WindowHeight::Fixed(window_height.clamp(1, MAX_PX)); | 3049 | + self.heights[tile_idx] = WindowHeight::Fixed(window_height.clamp(1, MAX_PX)); |
| 2802 | - self.update_tile_sizes(true); | 3050 | + self.update_tile_sizes(animate); |
| 2803 | } | 3051 | } |
| 2804 | 3052 | ||
| 2805 | fn set_fullscreen(&mut self, is_fullscreen: bool) { | 3053 | fn set_fullscreen(&mut self, is_fullscreen: bool) { |
| @@ -2917,3 +3165,18 @@ fn compute_toplevel_bounds( | |||
| 2917 | max(working_area_size.h - gaps * 2 - border, 1), | 3165 | max(working_area_size.h - gaps * 2 - border, 1), |
| 2918 | )) | 3166 | )) |
| 2919 | } | 3167 | } |
| 3168 | + | ||
| 3169 | +fn cancel_resize_if_this_column<W: LayoutElement>( | ||
| 3170 | + interactive_resize: &mut Option<InteractiveResize<W>>, | ||
| 3171 | + column: &mut Column<W>, | ||
| 3172 | +) { | ||
| 3173 | + if let Some(resize) = interactive_resize { | ||
| 3174 | + if column.contains(&resize.window) { | ||
| 3175 | + *interactive_resize = None; | ||
| 3176 | + | ||
| 3177 | + for tile in &mut column.tiles { | ||
| 3178 | + tile.window_mut().cancel_interactive_resize(); | ||
| 3179 | + } | ||
| 3180 | + } | ||
| 3181 | + } | ||
| 3182 | +} | ||
src/lib.rsmodified+1 -0
| @@ -15,6 +15,7 @@ pub mod layout; | |||
| 15 | pub mod niri; | 15 | pub mod niri; |
| 16 | pub mod protocols; | 16 | pub mod protocols; |
| 17 | pub mod render_helpers; | 17 | pub mod render_helpers; |
| 18 | +pub mod resize_grab; | ||
| 18 | pub mod rubber_band; | 19 | pub mod rubber_band; |
| 19 | pub mod scroll_tracker; | 20 | pub mod scroll_tracker; |
| 20 | pub mod swipe_tracker; | 21 | pub mod swipe_tracker; |
src/niri.rsmodified+2 -2
| @@ -995,7 +995,7 @@ impl State { | |||
| 995 | } | 995 | } |
| 996 | }); | 996 | }); |
| 997 | for win in windows { | 997 | for win in windows { |
| 998 | - self.niri.layout.update_window(&win); | 998 | + self.niri.layout.update_window(&win, None); |
| 999 | } | 999 | } |
| 1000 | } | 1000 | } |
| 1001 | 1001 | ||
| @@ -2414,7 +2414,7 @@ impl Niri { | |||
| 2414 | drop(config); | 2414 | drop(config); |
| 2415 | 2415 | ||
| 2416 | for win in windows { | 2416 | for win in windows { |
| 2417 | - self.layout.update_window(&win); | 2417 | + self.layout.update_window(&win, None); |
| 2418 | win.toplevel() | 2418 | win.toplevel() |
| 2419 | .expect("no X11 support") | 2419 | .expect("no X11 support") |
| 2420 | .send_pending_configure(); | 2420 | .send_pending_configure(); |
src/resize_grab.rsadded+171 -0
| @@ -0,0 +1,171 @@ | |||
| 1 | +use smithay::desktop::Window; | ||
| 2 | +use smithay::input::pointer::{ | ||
| 3 | + AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, | ||
| 4 | + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent, | ||
| 5 | + GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, | ||
| 6 | + PointerInnerHandle, RelativeMotionEvent, | ||
| 7 | +}; | ||
| 8 | +use smithay::input::SeatHandler; | ||
| 9 | +use smithay::utils::{IsAlive, Logical, Point}; | ||
| 10 | + | ||
| 11 | +use crate::niri::State; | ||
| 12 | + | ||
| 13 | +pub struct ResizeGrab { | ||
| 14 | + start_data: PointerGrabStartData<State>, | ||
| 15 | + window: Window, | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +impl ResizeGrab { | ||
| 19 | + pub fn new(start_data: PointerGrabStartData<State>, window: Window) -> Self { | ||
| 20 | + Self { start_data, window } | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + fn on_ungrab(&mut self, state: &mut State) { | ||
| 24 | + state.niri.layout.interactive_resize_end(&self.window); | ||
| 25 | + } | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +impl PointerGrab<State> for ResizeGrab { | ||
| 29 | + fn motion( | ||
| 30 | + &mut self, | ||
| 31 | + data: &mut State, | ||
| 32 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 33 | + _focus: Option<(<State as SeatHandler>::PointerFocus, Point<i32, Logical>)>, | ||
| 34 | + event: &MotionEvent, | ||
| 35 | + ) { | ||
| 36 | + // While the grab is active, no client has pointer focus. | ||
| 37 | + handle.motion(data, None, event); | ||
| 38 | + | ||
| 39 | + if self.window.alive() { | ||
| 40 | + let delta = event.location - self.start_data.location; | ||
| 41 | + let ongoing = data | ||
| 42 | + .niri | ||
| 43 | + .layout | ||
| 44 | + .interactive_resize_update(&self.window, delta); | ||
| 45 | + if ongoing { | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + // The resize is no longer ongoing. | ||
| 51 | + handle.unset_grab(self, data, event.serial, event.time, true); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + fn relative_motion( | ||
| 55 | + &mut self, | ||
| 56 | + data: &mut State, | ||
| 57 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 58 | + _focus: Option<(<State as SeatHandler>::PointerFocus, Point<i32, Logical>)>, | ||
| 59 | + event: &RelativeMotionEvent, | ||
| 60 | + ) { | ||
| 61 | + // While the grab is active, no client has pointer focus. | ||
| 62 | + handle.relative_motion(data, None, event); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + fn button( | ||
| 66 | + &mut self, | ||
| 67 | + data: &mut State, | ||
| 68 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 69 | + event: &ButtonEvent, | ||
| 70 | + ) { | ||
| 71 | + handle.button(data, event); | ||
| 72 | + | ||
| 73 | + if handle.current_pressed().is_empty() { | ||
| 74 | + // No more buttons are pressed, release the grab. | ||
| 75 | + handle.unset_grab(self, data, event.serial, event.time, true); | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + fn axis( | ||
| 80 | + &mut self, | ||
| 81 | + data: &mut State, | ||
| 82 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 83 | + details: AxisFrame, | ||
| 84 | + ) { | ||
| 85 | + handle.axis(data, details); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) { | ||
| 89 | + handle.frame(data); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + fn gesture_swipe_begin( | ||
| 93 | + &mut self, | ||
| 94 | + data: &mut State, | ||
| 95 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 96 | + event: &GestureSwipeBeginEvent, | ||
| 97 | + ) { | ||
| 98 | + handle.gesture_swipe_begin(data, event); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + fn gesture_swipe_update( | ||
| 102 | + &mut self, | ||
| 103 | + data: &mut State, | ||
| 104 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 105 | + event: &GestureSwipeUpdateEvent, | ||
| 106 | + ) { | ||
| 107 | + handle.gesture_swipe_update(data, event); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + fn gesture_swipe_end( | ||
| 111 | + &mut self, | ||
| 112 | + data: &mut State, | ||
| 113 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 114 | + event: &GestureSwipeEndEvent, | ||
| 115 | + ) { | ||
| 116 | + handle.gesture_swipe_end(data, event); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + fn gesture_pinch_begin( | ||
| 120 | + &mut self, | ||
| 121 | + data: &mut State, | ||
| 122 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 123 | + event: &GesturePinchBeginEvent, | ||
| 124 | + ) { | ||
| 125 | + handle.gesture_pinch_begin(data, event); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + fn gesture_pinch_update( | ||
| 129 | + &mut self, | ||
| 130 | + data: &mut State, | ||
| 131 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 132 | + event: &GesturePinchUpdateEvent, | ||
| 133 | + ) { | ||
| 134 | + handle.gesture_pinch_update(data, event); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + fn gesture_pinch_end( | ||
| 138 | + &mut self, | ||
| 139 | + data: &mut State, | ||
| 140 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 141 | + event: &GesturePinchEndEvent, | ||
| 142 | + ) { | ||
| 143 | + handle.gesture_pinch_end(data, event); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + fn gesture_hold_begin( | ||
| 147 | + &mut self, | ||
| 148 | + data: &mut State, | ||
| 149 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 150 | + event: &GestureHoldBeginEvent, | ||
| 151 | + ) { | ||
| 152 | + handle.gesture_hold_begin(data, event); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + fn gesture_hold_end( | ||
| 156 | + &mut self, | ||
| 157 | + data: &mut State, | ||
| 158 | + handle: &mut PointerInnerHandle<'_, State>, | ||
| 159 | + event: &GestureHoldEndEvent, | ||
| 160 | + ) { | ||
| 161 | + handle.gesture_hold_end(data, event); | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + fn start_data(&self) -> &PointerGrabStartData<State> { | ||
| 165 | + &self.start_data | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + fn unset(&mut self, data: &mut State) { | ||
| 169 | + self.on_ungrab(data); | ||
| 170 | + } | ||
| 171 | +} | ||
src/utils/mod.rsmodified+28 -0
| @@ -7,11 +7,13 @@ use std::sync::atomic::AtomicBool; | |||
| 7 | use std::time::Duration; | 7 | use std::time::Duration; |
| 8 | 8 | ||
| 9 | use anyhow::{ensure, Context}; | 9 | use anyhow::{ensure, Context}; |
| 10 | +use bitflags::bitflags; | ||
| 10 | use directories::UserDirs; | 11 | use directories::UserDirs; |
| 11 | use git_version::git_version; | 12 | use git_version::git_version; |
| 12 | use niri_config::Config; | 13 | use niri_config::Config; |
| 13 | use smithay::output::Output; | 14 | use smithay::output::Output; |
| 14 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; | 15 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; |
| 16 | +use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | ||
| 15 | use smithay::utils::{Logical, Point, Rectangle, Size, Transform}; | 17 | use smithay::utils::{Logical, Point, Rectangle, Size, Transform}; |
| 16 | 18 | ||
| 17 | pub mod id; | 19 | pub mod id; |
| @@ -21,6 +23,32 @@ pub mod watcher; | |||
| 21 | 23 | ||
| 22 | pub static IS_SYSTEMD_SERVICE: AtomicBool = AtomicBool::new(false); | 24 | pub static IS_SYSTEMD_SERVICE: AtomicBool = AtomicBool::new(false); |
| 23 | 25 | ||
| 26 | +bitflags! { | ||
| 27 | + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
| 28 | + pub struct ResizeEdge: u32 { | ||
| 29 | + const TOP = 0b0001; | ||
| 30 | + const BOTTOM = 0b0010; | ||
| 31 | + const LEFT = 0b0100; | ||
| 32 | + const RIGHT = 0b1000; | ||
| 33 | + | ||
| 34 | + const TOP_LEFT = Self::TOP.bits() | Self::LEFT.bits(); | ||
| 35 | + const BOTTOM_LEFT = Self::BOTTOM.bits() | Self::LEFT.bits(); | ||
| 36 | + | ||
| 37 | + const TOP_RIGHT = Self::TOP.bits() | Self::RIGHT.bits(); | ||
| 38 | + const BOTTOM_RIGHT = Self::BOTTOM.bits() | Self::RIGHT.bits(); | ||
| 39 | + | ||
| 40 | + const LEFT_RIGHT = Self::LEFT.bits() | Self::RIGHT.bits(); | ||
| 41 | + const TOP_BOTTOM = Self::TOP.bits() | Self::BOTTOM.bits(); | ||
| 42 | + } | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +impl From<xdg_toplevel::ResizeEdge> for ResizeEdge { | ||
| 46 | + #[inline] | ||
| 47 | + fn from(x: xdg_toplevel::ResizeEdge) -> Self { | ||
| 48 | + Self::from_bits(x as u32).unwrap() | ||
| 49 | + } | ||
| 50 | +} | ||
| 51 | + | ||
| 24 | pub fn version() -> String { | 52 | pub fn version() -> String { |
| 25 | format!( | 53 | format!( |
| 26 | "{} ({})", | 54 | "{} ({})", |
src/window/mapped.rsmodified+77 -1
| @@ -19,7 +19,9 @@ use smithay::wayland::compositor::{ | |||
| 19 | use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface}; | 19 | use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface}; |
| 20 | 20 | ||
| 21 | use super::{ResolvedWindowRules, WindowRef}; | 21 | use super::{ResolvedWindowRules, WindowRef}; |
| 22 | -use crate::layout::{LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot}; | 22 | +use crate::layout::{ |
| 23 | + InteractiveResizeData, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot, | ||
| 24 | +}; | ||
| 23 | use crate::niri::WindowOffscreenId; | 25 | use crate::niri::WindowOffscreenId; |
| 24 | use crate::render_helpers::renderer::NiriRenderer; | 26 | use crate::render_helpers::renderer::NiriRenderer; |
| 25 | use crate::render_helpers::snapshot::RenderSnapshot; | 27 | use crate::render_helpers::snapshot::RenderSnapshot; |
| @@ -56,6 +58,23 @@ pub struct Mapped { | |||
| 56 | 58 | ||
| 57 | /// Snapshot right before an animated commit. | 59 | /// Snapshot right before an animated commit. |
| 58 | animation_snapshot: Option<LayoutElementRenderSnapshot>, | 60 | animation_snapshot: Option<LayoutElementRenderSnapshot>, |
| 61 | + | ||
| 62 | + /// State of an ongoing interactive resize. | ||
| 63 | + interactive_resize: Option<InteractiveResize>, | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +/// Interactive resize state. | ||
| 67 | +#[derive(Debug)] | ||
| 68 | +enum InteractiveResize { | ||
| 69 | + /// The resize is ongoing. | ||
| 70 | + Ongoing(InteractiveResizeData), | ||
| 71 | + /// The resize has stopped and we're waiting to send the last configure. | ||
| 72 | + WaitingForLastConfigure(InteractiveResizeData), | ||
| 73 | + /// We had sent the last resize configure and are waiting for the corresponding commit. | ||
| 74 | + WaitingForLastCommit { | ||
| 75 | + data: InteractiveResizeData, | ||
| 76 | + serial: Serial, | ||
| 77 | + }, | ||
| 59 | } | 78 | } |
| 60 | 79 | ||
| 61 | impl Mapped { | 80 | impl Mapped { |
| @@ -70,6 +89,7 @@ impl Mapped { | |||
| 70 | animate_next_configure: false, | 89 | animate_next_configure: false, |
| 71 | animate_serials: Vec::new(), | 90 | animate_serials: Vec::new(), |
| 72 | animation_snapshot: None, | 91 | animation_snapshot: None, |
| 92 | + interactive_resize: None, | ||
| 73 | } | 93 | } |
| 74 | } | 94 | } |
| 75 | 95 | ||
| @@ -427,6 +447,20 @@ impl LayoutElement for Mapped { | |||
| 427 | if self.animate_next_configure { | 447 | if self.animate_next_configure { |
| 428 | self.animate_serials.push(serial); | 448 | self.animate_serials.push(serial); |
| 429 | } | 449 | } |
| 450 | + | ||
| 451 | + self.interactive_resize = match self.interactive_resize.take() { | ||
| 452 | + Some(InteractiveResize::WaitingForLastConfigure(data)) => { | ||
| 453 | + Some(InteractiveResize::WaitingForLastCommit { data, serial }) | ||
| 454 | + } | ||
| 455 | + x => x, | ||
| 456 | + } | ||
| 457 | + } else { | ||
| 458 | + self.interactive_resize = match self.interactive_resize.take() { | ||
| 459 | + // We probably started and stopped resizing in the same loop cycle without anything | ||
| 460 | + // changing. | ||
| 461 | + Some(InteractiveResize::WaitingForLastConfigure { .. }) => None, | ||
| 462 | + x => x, | ||
| 463 | + } | ||
| 430 | } | 464 | } |
| 431 | 465 | ||
| 432 | self.animate_next_configure = false; | 466 | self.animate_next_configure = false; |
| @@ -459,4 +493,46 @@ impl LayoutElement for Mapped { | |||
| 459 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { | 493 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { |
| 460 | self.animation_snapshot.take() | 494 | self.animation_snapshot.take() |
| 461 | } | 495 | } |
| 496 | + | ||
| 497 | + fn set_interactive_resize(&mut self, data: Option<InteractiveResizeData>) { | ||
| 498 | + self.toplevel().with_pending_state(|state| { | ||
| 499 | + if data.is_some() { | ||
| 500 | + state.states.set(xdg_toplevel::State::Resizing); | ||
| 501 | + } else { | ||
| 502 | + state.states.unset(xdg_toplevel::State::Resizing); | ||
| 503 | + } | ||
| 504 | + }); | ||
| 505 | + | ||
| 506 | + if let Some(data) = data { | ||
| 507 | + self.interactive_resize = Some(InteractiveResize::Ongoing(data)); | ||
| 508 | + } else { | ||
| 509 | + self.interactive_resize = match self.interactive_resize.take() { | ||
| 510 | + Some(InteractiveResize::Ongoing(data)) => { | ||
| 511 | + Some(InteractiveResize::WaitingForLastConfigure(data)) | ||
| 512 | + } | ||
| 513 | + x => x, | ||
| 514 | + } | ||
| 515 | + } | ||
| 516 | + } | ||
| 517 | + | ||
| 518 | + fn cancel_interactive_resize(&mut self) { | ||
| 519 | + self.set_interactive_resize(None); | ||
| 520 | + self.interactive_resize = None; | ||
| 521 | + } | ||
| 522 | + | ||
| 523 | + fn interactive_resize_data(&mut self, commit_serial: Serial) -> Option<InteractiveResizeData> { | ||
| 524 | + let resize = self.interactive_resize.as_ref()?; | ||
| 525 | + match resize { | ||
| 526 | + InteractiveResize::Ongoing(data) | InteractiveResize::WaitingForLastConfigure(data) => { | ||
| 527 | + Some(*data) | ||
| 528 | + } | ||
| 529 | + InteractiveResize::WaitingForLastCommit { data, serial } => { | ||
| 530 | + let rv = Some(*data); | ||
| 531 | + if commit_serial.is_no_older_than(serial) { | ||
| 532 | + self.interactive_resize = None; | ||
| 533 | + } | ||
| 534 | + rv | ||
| 535 | + } | ||
| 536 | + } | ||
| 537 | + } | ||
| 462 | } | 538 | } |