forge
Explore
Log in

Don't you dare go Hollow

Implement interactive window move

Browse files at this commit

e887ee93a30390b641bf647d694a1424f7ce4592Rasmus EnemanParent: d640e85
niri-config/src/lib.rsmodified+28 -0
@@ -421,6 +421,8 @@ pub struct Layout {
421 pub focus_ring: FocusRing,421 pub focus_ring: FocusRing,
422 #[knuffel(child, default)]422 #[knuffel(child, default)]
423 pub border: Border,423 pub border: Border,
424+ #[knuffel(child, default)]
425+ pub insert_hint: InsertHint,
424 #[knuffel(child, unwrap(children), default)]426 #[knuffel(child, unwrap(children), default)]
425 pub preset_column_widths: Vec<PresetSize>,427 pub preset_column_widths: Vec<PresetSize>,
426 #[knuffel(child)]428 #[knuffel(child)]
@@ -442,6 +444,7 @@ impl Default for Layout {
442 Self {444 Self {
443 focus_ring: Default::default(),445 focus_ring: Default::default(),
444 border: Default::default(),446 border: Default::default(),
447+ insert_hint: Default::default(),
445 preset_column_widths: Default::default(),448 preset_column_widths: Default::default(),
446 default_column_width: Default::default(),449 default_column_width: Default::default(),
447 center_focused_column: Default::default(),450 center_focused_column: Default::default(),
@@ -588,6 +591,23 @@ impl From<FocusRing> for Border {
588 }591 }
589 }592 }
590 593
594+#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
595+pub struct InsertHint {
596+ #[knuffel(child)]
597+ pub off: bool,
598+ #[knuffel(child, default = Self::default().color)]
599+ pub color: Color,
600+}
601+
602+impl Default for InsertHint {
603+ fn default() -> Self {
604+ Self {
605+ off: false,
606+ color: Color::from_rgba8_unpremul(127, 200, 255, 128),
607+ }
608+ }
609+}
610+
591 /// RGB color in [0, 1] with unpremultiplied alpha.611 /// RGB color in [0, 1] with unpremultiplied alpha.
592 #[derive(Debug, Default, Clone, Copy, PartialEq)]612 #[derive(Debug, Default, Clone, Copy, PartialEq)]
593 pub struct Color {613 pub struct Color {
@@ -3028,6 +3048,10 @@ mod tests {
3028 }3048 }
3029 3049
3030 center-focused-column "on-overflow"3050 center-focused-column "on-overflow"
3051+
3052+ insert-hint {
3053+ color "rgb(255, 200, 127)"
3054+ }
3031 }3055 }
3032 3056
3033 spawn-at-startup "alacritty" "-e" "fish"3057 spawn-at-startup "alacritty" "-e" "fish"
@@ -3226,6 +3250,10 @@ mod tests {
3226 active_gradient: None,3250 active_gradient: None,
3227 inactive_gradient: None,3251 inactive_gradient: None,
3228 },3252 },
3253+ insert_hint: InsertHint {
3254+ off: false,
3255+ color: Color::from_rgba8_unpremul(255, 200, 127, 255),
3256+ },
3229 preset_column_widths: vec![3257 preset_column_widths: vec![
3230 PresetSize::Proportion(0.25),3258 PresetSize::Proportion(0.25),
3231 PresetSize::Proportion(0.5),3259 PresetSize::Proportion(0.5),
niri-visual-tests/src/cases/layout.rsmodified+1 -5
@@ -198,11 +198,7 @@ impl TestCase for Layout {
198 }198 }
199 199
200 fn are_animations_ongoing(&self) -> bool {200 fn are_animations_ongoing(&self) -> bool {
201- self.layout201+ self.layout.are_animations_ongoing(Some(&self.output)) || !self.steps.is_empty()
202- .monitor_for_output(&self.output)
203- .unwrap()
204- .are_animations_ongoing()
205- || !self.steps.is_empty()
206 }202 }
207 203
208 fn advance_animations(&mut self, mut current_time: Duration) {204 fn advance_animations(&mut self, mut current_time: Duration) {
src/handlers/xdg_shell.rsmodified+50 -3
@@ -6,7 +6,7 @@ use smithay::desktop::{
6 PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window,6 PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window,
7 WindowSurfaceType,7 WindowSurfaceType,
8 };8 };
9-use smithay::input::pointer::Focus;9+use smithay::input::pointer::{Focus, PointerGrab};
10 use smithay::output::Output;10 use smithay::output::Output;
11 use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;11 use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
12 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_positioner::ConstraintAdjustment;12 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_positioner::ConstraintAdjustment;
@@ -36,6 +36,7 @@ use smithay::{
36 };36 };
37 use tracing::field::Empty;37 use tracing::field::Empty;
38 38
39+use crate::input::move_grab::MoveGrab;
39 use crate::input::resize_grab::ResizeGrab;40 use crate::input::resize_grab::ResizeGrab;
40 use crate::input::DOUBLE_CLICK_TIME;41 use crate::input::DOUBLE_CLICK_TIME;
41 use crate::layout::workspace::ColumnWidth;42 use crate::layout::workspace::ColumnWidth;
@@ -65,8 +66,54 @@ impl XdgShellHandler for State {
65 }66 }
66 }67 }
67 68
68- fn move_request(&mut self, _surface: ToplevelSurface, _seat: WlSeat, _serial: Serial) {69+ fn move_request(&mut self, surface: ToplevelSurface, _seat: WlSeat, serial: Serial) {
69- // FIXME70+ 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, output)) = self.niri.layout.find_window_and_output(wl_surface) else {
89+ return;
90+ };
91+
92+ let window = mapped.window.clone();
93+ let output = output.clone();
94+
95+ let output_pos = self
96+ .niri
97+ .global_space
98+ .output_geometry(&output)
99+ .unwrap()
100+ .loc
101+ .to_f64();
102+
103+ let pos_within_output = start_data.location - output_pos;
104+
105+ if !self
106+ .niri
107+ .layout
108+ .interactive_move_begin(window.clone(), &output, pos_within_output)
109+ {
110+ return;
111+ }
112+
113+ let grab = MoveGrab::new(start_data, window.clone());
114+
115+ pointer.set_grab(self, grab, serial, Focus::Clear);
116+ self.niri.pointer_grab_ongoing = true;
70 }117 }
71 118
72 fn resize_request(119 fn resize_request(
src/input/mod.rsmodified+36 -1
@@ -29,6 +29,7 @@ use smithay::utils::{Logical, Point, Rectangle, Transform, SERIAL_COUNTER};
29 use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};29 use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};
30 use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};30 use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
31 31
32+use self::move_grab::MoveGrab;
32 use self::resize_grab::ResizeGrab;33 use self::resize_grab::ResizeGrab;
33 use self::spatial_movement_grab::SpatialMovementGrab;34 use self::spatial_movement_grab::SpatialMovementGrab;
34 use crate::niri::State;35 use crate::niri::State;
@@ -36,6 +37,7 @@ use crate::ui::screenshot_ui::ScreenshotUi;
36 use crate::utils::spawning::spawn;37 use crate::utils::spawning::spawn;
37 use crate::utils::{center, get_monotonic_time, ResizeEdge};38 use crate::utils::{center, get_monotonic_time, ResizeEdge};
38 39
40+pub mod move_grab;
39 pub mod resize_grab;41 pub mod resize_grab;
40 pub mod scroll_tracker;42 pub mod scroll_tracker;
41 pub mod spatial_movement_grab;43 pub mod spatial_movement_grab;
@@ -1535,8 +1537,41 @@ impl State {
1535 if let Some(mapped) = self.niri.window_under_cursor() {1537 if let Some(mapped) = self.niri.window_under_cursor() {
1536 let window = mapped.window.clone();1538 let window = mapped.window.clone();
1537 1539
1540+ // Check if we need to start an interactive move.
1541+ if event.button() == Some(MouseButton::Left) && !pointer.is_grabbed() {
1542+ let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1543+ let mod_down = match self.backend.mod_key() {
1544+ CompositorMod::Super => mods.logo,
1545+ CompositorMod::Alt => mods.alt,
1546+ };
1547+ if mod_down {
1548+ let location = pointer.current_location();
1549+ let (output, pos_within_output) = self.niri.output_under(location).unwrap();
1550+ let output = output.clone();
1551+
1552+ self.niri.layout.activate_window(&window);
1553+
1554+ if self.niri.layout.interactive_move_begin(
1555+ window.clone(),
1556+ &output,
1557+ pos_within_output,
1558+ ) {
1559+ let start_data = PointerGrabStartData {
1560+ focus: None,
1561+ button: event.button_code(),
1562+ location,
1563+ };
1564+ let grab = MoveGrab::new(start_data, window.clone());
1565+ pointer.set_grab(self, grab, serial, Focus::Clear);
1566+ self.niri.pointer_grab_ongoing = true;
1567+ self.niri
1568+ .cursor_manager
1569+ .set_cursor_image(CursorImageStatus::Named(CursorIcon::Move));
1570+ }
1571+ }
1572+ }
1538 // Check if we need to start an interactive resize.1573 // Check if we need to start an interactive resize.
1539- if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() {1574+ else if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() {
1540 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();1575 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1541 let mod_down = match self.backend.mod_key() {1576 let mod_down = match self.backend.mod_key() {
1542 CompositorMod::Super => mods.logo,1577 CompositorMod::Super => mods.logo,
src/input/move_grab.rsadded+223 -0
@@ -0,0 +1,223 @@
1+use std::time::Duration;
2+
3+use smithay::backend::input::ButtonState;
4+use smithay::desktop::Window;
5+use smithay::input::pointer::{
6+ AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent,
7+ GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent,
8+ GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData,
9+ MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent,
10+};
11+use smithay::input::SeatHandler;
12+use smithay::utils::{IsAlive, Logical, Point};
13+
14+use crate::niri::State;
15+
16+pub struct MoveGrab {
17+ start_data: PointerGrabStartData<State>,
18+ last_location: Point<f64, Logical>,
19+ window: Window,
20+ is_moving: bool,
21+}
22+
23+impl MoveGrab {
24+ pub fn new(start_data: PointerGrabStartData<State>, window: Window) -> Self {
25+ Self {
26+ last_location: start_data.location,
27+ start_data,
28+ window,
29+ is_moving: false,
30+ }
31+ }
32+
33+ fn on_ungrab(&mut self, state: &mut State) {
34+ state.niri.layout.interactive_move_end(&self.window);
35+ // FIXME: only redraw the window output.
36+ state.niri.queue_redraw_all();
37+ state.niri.pointer_grab_ongoing = false;
38+ state
39+ .niri
40+ .cursor_manager
41+ .set_cursor_image(CursorImageStatus::default_named());
42+ }
43+}
44+
45+impl PointerGrab<State> for MoveGrab {
46+ fn motion(
47+ &mut self,
48+ data: &mut State,
49+ handle: &mut PointerInnerHandle<'_, State>,
50+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
51+ event: &MotionEvent,
52+ ) {
53+ // While the grab is active, no client has pointer focus.
54+ handle.motion(data, None, event);
55+
56+ if self.window.alive() {
57+ if let Some((output, pos_within_output)) = data.niri.output_under(event.location) {
58+ let output = output.clone();
59+ let event_delta = event.location - self.last_location;
60+ self.last_location = event.location;
61+ let ongoing = data.niri.layout.interactive_move_update(
62+ &self.window,
63+ event_delta,
64+ output,
65+ pos_within_output,
66+ );
67+ if ongoing {
68+ let timestamp = Duration::from_millis(u64::from(event.time));
69+ if self.is_moving {
70+ data.niri.layout.view_offset_gesture_update(
71+ -event_delta.x,
72+ timestamp,
73+ false,
74+ );
75+ }
76+ return;
77+ }
78+ } else {
79+ return;
80+ }
81+ }
82+
83+ // The move is no longer ongoing.
84+ handle.unset_grab(self, data, event.serial, event.time, true);
85+ }
86+
87+ fn relative_motion(
88+ &mut self,
89+ data: &mut State,
90+ handle: &mut PointerInnerHandle<'_, State>,
91+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
92+ event: &RelativeMotionEvent,
93+ ) {
94+ // While the grab is active, no client has pointer focus.
95+ handle.relative_motion(data, None, event);
96+ }
97+
98+ fn button(
99+ &mut self,
100+ data: &mut State,
101+ handle: &mut PointerInnerHandle<'_, State>,
102+ event: &ButtonEvent,
103+ ) {
104+ handle.button(data, event);
105+
106+ // MouseButton::Middle
107+ if event.button == 0x112 {
108+ if event.state == ButtonState::Pressed {
109+ let output = data
110+ .niri
111+ .output_under(handle.current_location())
112+ .map(|(output, _)| output)
113+ .cloned();
114+ // TODO: workspace switch gesture.
115+ if let Some(output) = output {
116+ self.is_moving = true;
117+ data.niri.layout.view_offset_gesture_begin(&output, false);
118+ }
119+ } else if event.state == ButtonState::Released {
120+ self.is_moving = false;
121+ data.niri.layout.view_offset_gesture_end(false, None);
122+ }
123+ }
124+
125+ if handle.current_pressed().is_empty() {
126+ // No more buttons are pressed, release the grab.
127+ handle.unset_grab(self, data, event.serial, event.time, true);
128+ }
129+ }
130+
131+ fn axis(
132+ &mut self,
133+ data: &mut State,
134+ handle: &mut PointerInnerHandle<'_, State>,
135+ details: AxisFrame,
136+ ) {
137+ handle.axis(data, details);
138+ }
139+
140+ fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) {
141+ handle.frame(data);
142+ }
143+
144+ fn gesture_swipe_begin(
145+ &mut self,
146+ data: &mut State,
147+ handle: &mut PointerInnerHandle<'_, State>,
148+ event: &GestureSwipeBeginEvent,
149+ ) {
150+ handle.gesture_swipe_begin(data, event);
151+ }
152+
153+ fn gesture_swipe_update(
154+ &mut self,
155+ data: &mut State,
156+ handle: &mut PointerInnerHandle<'_, State>,
157+ event: &GestureSwipeUpdateEvent,
158+ ) {
159+ handle.gesture_swipe_update(data, event);
160+ }
161+
162+ fn gesture_swipe_end(
163+ &mut self,
164+ data: &mut State,
165+ handle: &mut PointerInnerHandle<'_, State>,
166+ event: &GestureSwipeEndEvent,
167+ ) {
168+ handle.gesture_swipe_end(data, event);
169+ }
170+
171+ fn gesture_pinch_begin(
172+ &mut self,
173+ data: &mut State,
174+ handle: &mut PointerInnerHandle<'_, State>,
175+ event: &GesturePinchBeginEvent,
176+ ) {
177+ handle.gesture_pinch_begin(data, event);
178+ }
179+
180+ fn gesture_pinch_update(
181+ &mut self,
182+ data: &mut State,
183+ handle: &mut PointerInnerHandle<'_, State>,
184+ event: &GesturePinchUpdateEvent,
185+ ) {
186+ handle.gesture_pinch_update(data, event);
187+ }
188+
189+ fn gesture_pinch_end(
190+ &mut self,
191+ data: &mut State,
192+ handle: &mut PointerInnerHandle<'_, State>,
193+ event: &GesturePinchEndEvent,
194+ ) {
195+ handle.gesture_pinch_end(data, event);
196+ }
197+
198+ fn gesture_hold_begin(
199+ &mut self,
200+ data: &mut State,
201+ handle: &mut PointerInnerHandle<'_, State>,
202+ event: &GestureHoldBeginEvent,
203+ ) {
204+ handle.gesture_hold_begin(data, event);
205+ }
206+
207+ fn gesture_hold_end(
208+ &mut self,
209+ data: &mut State,
210+ handle: &mut PointerInnerHandle<'_, State>,
211+ event: &GestureHoldEndEvent,
212+ ) {
213+ handle.gesture_hold_end(data, event);
214+ }
215+
216+ fn start_data(&self) -> &PointerGrabStartData<State> {
217+ &self.start_data
218+ }
219+
220+ fn unset(&mut self, data: &mut State) {
221+ self.on_ungrab(data);
222+ }
223+}
src/ipc/server.rsmodified+3 -3
@@ -551,12 +551,12 @@ impl State {
551 }551 }
552 552
553 let Some(ipc_win) = state.windows.get(&id) else {553 let Some(ipc_win) = state.windows.get(&id) else {
554- let window = make_ipc_window(mapped, Some(ws_id));554+ let window = make_ipc_window(mapped, ws_id);
555 events.push(Event::WindowOpenedOrChanged { window });555 events.push(Event::WindowOpenedOrChanged { window });
556 return;556 return;
557 };557 };
558 558
559- let workspace_id = Some(ws_id.get());559+ let workspace_id = ws_id.map(|id| id.get());
560 let mut changed = ipc_win.workspace_id != workspace_id;560 let mut changed = ipc_win.workspace_id != workspace_id;
561 561
562 let wl_surface = mapped.toplevel().wl_surface();562 let wl_surface = mapped.toplevel().wl_surface();
@@ -572,7 +572,7 @@ impl State {
572 });572 });
573 573
574 if changed {574 if changed {
575- let window = make_ipc_window(mapped, Some(ws_id));575+ let window = make_ipc_window(mapped, ws_id);
576 events.push(Event::WindowOpenedOrChanged { window });576 events.push(Event::WindowOpenedOrChanged { window });
577 return;577 return;
578 }578 }
src/layout/mod.rsmodified+963 -14
@@ -43,19 +43,21 @@ 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::{self, Output};44 use smithay::output::{self, 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, Serial, Size, Transform};46+use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
47-use tile::Tile;47+use tile::{Tile, TileRenderElement};
48 use workspace::WorkspaceId;48 use workspace::WorkspaceId;
49 49
50 pub use self::monitor::MonitorRenderElement;50 pub use self::monitor::MonitorRenderElement;
51 use self::monitor::{Monitor, WorkspaceSwitch};51 use self::monitor::{Monitor, WorkspaceSwitch};
52-use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Workspace};52+use self::workspace::{compute_working_area, Column, ColumnWidth, InsertHint, OutputId, Workspace};
53+use crate::layout::workspace::InsertPosition;
53 use crate::niri_render_elements;54 use crate::niri_render_elements;
54 use crate::render_helpers::renderer::NiriRenderer;55 use crate::render_helpers::renderer::NiriRenderer;
55 use crate::render_helpers::snapshot::RenderSnapshot;56 use crate::render_helpers::snapshot::RenderSnapshot;
56 use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};57 use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
57 use crate::render_helpers::texture::TextureBuffer;58 use crate::render_helpers::texture::TextureBuffer;
58 use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements};59 use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements};
60+use crate::rubber_band::RubberBand;
59 use crate::utils::transaction::{Transaction, TransactionBlocker};61 use crate::utils::transaction::{Transaction, TransactionBlocker};
60 use crate::utils::{output_matches_name, output_size, round_logical_in_physical_max1, ResizeEdge};62 use crate::utils::{output_matches_name, output_size, round_logical_in_physical_max1, ResizeEdge};
61 use crate::window::ResolvedWindowRules;63 use crate::window::ResolvedWindowRules;
@@ -70,6 +72,9 @@ pub mod workspace;
70 /// Size changes up to this many pixels don't animate.72 /// Size changes up to this many pixels don't animate.
71 pub const RESIZE_ANIMATION_THRESHOLD: f64 = 10.;73 pub const RESIZE_ANIMATION_THRESHOLD: f64 = 10.;
72 74
75+/// Pointer needs to move this far to pull a window from the layout.
76+const INTERACTIVE_MOVE_START_THRESHOLD: f64 = 256. * 256.;
77+
73 niri_render_elements! {78 niri_render_elements! {
74 LayoutElementRenderElement<R> => {79 LayoutElementRenderElement<R> => {
75 Wayland = WaylandSurfaceRenderElement<R>,80 Wayland = WaylandSurfaceRenderElement<R>,
@@ -80,6 +85,41 @@ niri_render_elements! {
80 pub type LayoutElementRenderSnapshot =85 pub type LayoutElementRenderSnapshot =
81 RenderSnapshot<BakedBuffer<TextureBuffer<GlesTexture>>, BakedBuffer<SolidColorBuffer>>;86 RenderSnapshot<BakedBuffer<TextureBuffer<GlesTexture>>, BakedBuffer<SolidColorBuffer>>;
82 87
88+#[derive(Debug)]
89+enum InteractiveMoveState<W: LayoutElement> {
90+ /// Initial rubberbanding; the window remains in the layout.
91+ Starting {
92+ /// The window we're moving.
93+ window_id: W::Id,
94+ /// Current pointer delta from the starting location.
95+ pointer_delta: Point<f64, Logical>,
96+ /// Pointer location within the visual window geometry as ratio from geometry size.
97+ ///
98+ /// This helps the pointer remain inside the window as it resizes.
99+ pointer_ratio_within_window: (f64, f64),
100+ },
101+ /// Moving; the window is no longer in the layout.
102+ Moving(InteractiveMoveData<W>),
103+}
104+
105+#[derive(Debug)]
106+struct InteractiveMoveData<W: LayoutElement> {
107+ /// The window being moved.
108+ pub(self) tile: Tile<W>,
109+ /// Output where the window is currently located/rendered.
110+ pub(self) output: Output,
111+ /// Current pointer position within output.
112+ pub(self) pointer_pos_within_output: Point<f64, Logical>,
113+ /// Window column width.
114+ pub(self) width: ColumnWidth,
115+ /// Whether the window column was full-width.
116+ pub(self) is_full_width: bool,
117+ /// Pointer location within the visual window geometry as ratio from geometry size.
118+ ///
119+ /// This helps the pointer remain inside the window as it resizes.
120+ pub(self) pointer_ratio_within_window: (f64, f64),
121+}
122+
83 #[derive(Debug, Clone, Copy)]123 #[derive(Debug, Clone, Copy)]
84 pub struct InteractiveResizeData {124 pub struct InteractiveResizeData {
85 pub(self) edges: ResizeEdge,125 pub(self) edges: ResizeEdge,
@@ -216,6 +256,8 @@ pub struct Layout<W: LayoutElement> {
216 /// This normally indicates that the layout has keyboard focus, but not always. E.g. when the256 /// This normally indicates that the layout has keyboard focus, but not always. E.g. when the
217 /// screenshot UI is open, it keeps the layout drawing as active.257 /// screenshot UI is open, it keeps the layout drawing as active.
218 is_active: bool,258 is_active: bool,
259+ /// Ongoing interactive move.
260+ interactive_move: Option<InteractiveMoveState<W>>,
219 /// Configurable properties of the layout.261 /// Configurable properties of the layout.
220 options: Rc<Options>,262 options: Rc<Options>,
221 }263 }
@@ -246,6 +288,7 @@ pub struct Options {
246 pub struts: Struts,288 pub struts: Struts,
247 pub focus_ring: niri_config::FocusRing,289 pub focus_ring: niri_config::FocusRing,
248 pub border: niri_config::Border,290 pub border: niri_config::Border,
291+ pub insert_hint: niri_config::InsertHint,
249 pub center_focused_column: CenterFocusedColumn,292 pub center_focused_column: CenterFocusedColumn,
250 pub always_center_single_column: bool,293 pub always_center_single_column: bool,
251 /// Column widths that `toggle_width()` switches between.294 /// Column widths that `toggle_width()` switches between.
@@ -267,6 +310,7 @@ impl Default for Options {
267 struts: Default::default(),310 struts: Default::default(),
268 focus_ring: Default::default(),311 focus_ring: Default::default(),
269 border: Default::default(),312 border: Default::default(),
313+ insert_hint: Default::default(),
270 center_focused_column: Default::default(),314 center_focused_column: Default::default(),
271 always_center_single_column: false,315 always_center_single_column: false,
272 preset_column_widths: vec![316 preset_column_widths: vec![
@@ -296,6 +340,31 @@ pub struct RemovedTile<W: LayoutElement> {
296 is_full_width: bool,340 is_full_width: bool,
297 }341 }
298 342
343+impl<W: LayoutElement> InteractiveMoveState<W> {
344+ fn moving(&self) -> Option<&InteractiveMoveData<W>> {
345+ match self {
346+ InteractiveMoveState::Moving(move_) => Some(move_),
347+ _ => None,
348+ }
349+ }
350+}
351+
352+impl<W: LayoutElement> InteractiveMoveData<W> {
353+ fn tile_render_location(&self) -> Point<f64, Logical> {
354+ let scale = Scale::from(self.output.current_scale().fractional_scale());
355+ let window_size = self.tile.window_size();
356+ let pointer_offset_within_window = Point::from((
357+ window_size.w * self.pointer_ratio_within_window.0,
358+ window_size.h * self.pointer_ratio_within_window.1,
359+ ));
360+ let pos =
361+ self.pointer_pos_within_output - pointer_offset_within_window - self.tile.window_loc()
362+ + self.tile.render_offset();
363+ // Round to physical pixels.
364+ pos.to_physical_precise_round(scale).to_logical(scale)
365+ }
366+}
367+
299 impl Options {368 impl Options {
300 fn from_config(config: &Config) -> Self {369 fn from_config(config: &Config) -> Self {
301 let layout = &config.layout;370 let layout = &config.layout;
@@ -329,6 +398,7 @@ impl Options {
329 struts: layout.struts,398 struts: layout.struts,
330 focus_ring: layout.focus_ring,399 focus_ring: layout.focus_ring,
331 border: layout.border,400 border: layout.border,
401+ insert_hint: layout.insert_hint,
332 center_focused_column: layout.center_focused_column,402 center_focused_column: layout.center_focused_column,
333 always_center_single_column: layout.always_center_single_column,403 always_center_single_column: layout.always_center_single_column,
334 preset_column_widths,404 preset_column_widths,
@@ -360,6 +430,7 @@ impl<W: LayoutElement> Layout<W> {
360 Self {430 Self {
361 monitor_set: MonitorSet::NoOutputs { workspaces: vec![] },431 monitor_set: MonitorSet::NoOutputs { workspaces: vec![] },
362 is_active: true,432 is_active: true,
433+ interactive_move: None,
363 options: Rc::new(options),434 options: Rc::new(options),
364 }435 }
365 }436 }
@@ -376,6 +447,7 @@ impl<W: LayoutElement> Layout<W> {
376 Self {447 Self {
377 monitor_set: MonitorSet::NoOutputs { workspaces },448 monitor_set: MonitorSet::NoOutputs { workspaces },
378 is_active: true,449 is_active: true,
450+ interactive_move: None,
379 options: opts,451 options: opts,
380 }452 }
381 }453 }
@@ -693,6 +765,18 @@ impl<W: LayoutElement> Layout<W> {
693 width: Option<ColumnWidth>,765 width: Option<ColumnWidth>,
694 is_full_width: bool,766 is_full_width: bool,
695 ) -> Option<&Output> {767 ) -> Option<&Output> {
768+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
769+ if right_of == move_.tile.window().id() {
770+ let output = move_.output.clone();
771+ if self.monitor_for_output(&output).is_some() {
772+ self.add_window_on_output(&output, window, width, is_full_width);
773+ return Some(&self.monitor_for_output(&output).unwrap().output);
774+ } else {
775+ return self.add_window(window, width, is_full_width);
776+ }
777+ }
778+ }
779+
696 let width = self.resolve_default_width(&window, width);780 let width = self.resolve_default_width(&window, width);
697 781
698 match &mut self.monitor_set {782 match &mut self.monitor_set {
@@ -765,6 +849,30 @@ impl<W: LayoutElement> Layout<W> {
765 window: &W::Id,849 window: &W::Id,
766 transaction: Transaction,850 transaction: Transaction,
767 ) -> Option<RemovedTile<W>> {851 ) -> Option<RemovedTile<W>> {
852+ if let Some(state) = &self.interactive_move {
853+ match state {
854+ InteractiveMoveState::Starting { window_id, .. } => {
855+ if window_id == window {
856+ self.interactive_move_end(window);
857+ }
858+ }
859+ InteractiveMoveState::Moving(move_) => {
860+ if move_.tile.window().id() == window {
861+ let Some(InteractiveMoveState::Moving(move_)) =
862+ self.interactive_move.take()
863+ else {
864+ unreachable!()
865+ };
866+ return Some(RemovedTile {
867+ tile: move_.tile,
868+ width: move_.width,
869+ is_full_width: move_.is_full_width,
870+ });
871+ }
872+ }
873+ }
874+ }
875+
768 match &mut self.monitor_set {876 match &mut self.monitor_set {
769 MonitorSet::Normal { monitors, .. } => {877 MonitorSet::Normal { monitors, .. } => {
770 for mon in monitors {878 for mon in monitors {
@@ -811,6 +919,13 @@ impl<W: LayoutElement> Layout<W> {
811 }919 }
812 920
813 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {921 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {
922+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
923+ if move_.tile.window().id() == window {
924+ move_.tile.update_window();
925+ return;
926+ }
927+ }
928+
814 match &mut self.monitor_set {929 match &mut self.monitor_set {
815 MonitorSet::Normal { monitors, .. } => {930 MonitorSet::Normal { monitors, .. } => {
816 for mon in monitors {931 for mon in monitors {
@@ -834,6 +949,12 @@ impl<W: LayoutElement> Layout<W> {
834 }949 }
835 950
836 pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> {951 pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> {
952+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
953+ if move_.tile.window().is_wl_surface(wl_surface) {
954+ return Some((move_.tile.window(), &move_.output));
955+ }
956+ }
957+
837 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {958 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
838 for mon in monitors {959 for mon in monitors {
839 for ws in &mon.workspaces {960 for ws in &mon.workspaces {
@@ -939,6 +1060,12 @@ impl<W: LayoutElement> Layout<W> {
939 &mut self,1060 &mut self,
940 wl_surface: &WlSurface,1061 wl_surface: &WlSurface,
941 ) -> Option<(&mut W, Option<&Output>)> {1062 ) -> Option<(&mut W, Option<&Output>)> {
1063+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
1064+ if move_.tile.window().is_wl_surface(wl_surface) {
1065+ return Some((move_.tile.window_mut(), Some(&move_.output)));
1066+ }
1067+ }
1068+
942 match &mut self.monitor_set {1069 match &mut self.monitor_set {
943 MonitorSet::Normal { monitors, .. } => {1070 MonitorSet::Normal { monitors, .. } => {
944 for mon in monitors {1071 for mon in monitors {
@@ -962,6 +1089,12 @@ impl<W: LayoutElement> Layout<W> {
962 }1089 }
963 1090
964 pub fn window_loc(&self, window: &W::Id) -> Option<Point<f64, Logical>> {1091 pub fn window_loc(&self, window: &W::Id) -> Option<Point<f64, Logical>> {
1092+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
1093+ if move_.tile.window().id() == window {
1094+ return Some(move_.tile.window_loc());
1095+ }
1096+ }
1097+
965 match &self.monitor_set {1098 match &self.monitor_set {
966 MonitorSet::Normal { monitors, .. } => {1099 MonitorSet::Normal { monitors, .. } => {
967 for mon in monitors {1100 for mon in monitors {
@@ -1012,6 +1145,12 @@ impl<W: LayoutElement> Layout<W> {
1012 }1145 }
1013 1146
1014 pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 {1147 pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 {
1148+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
1149+ if move_.tile.window().id() == window {
1150+ return 0.;
1151+ }
1152+ }
1153+
1015 let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {1154 let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
1016 return 0.;1155 return 0.;
1017 };1156 };
@@ -1034,6 +1173,12 @@ impl<W: LayoutElement> Layout<W> {
1034 //1173 //
1035 // This function allows focus-follows-mouse to trigger only on the animation target1174 // This function allows focus-follows-mouse to trigger only on the animation target
1036 // workspace.1175 // workspace.
1176+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
1177+ if move_.tile.window().id() == window {
1178+ return true;
1179+ }
1180+ }
1181+
1037 let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {1182 let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
1038 return true;1183 return true;
1039 };1184 };
@@ -1057,6 +1202,12 @@ impl<W: LayoutElement> Layout<W> {
1057 }1202 }
1058 1203
1059 pub fn activate_window(&mut self, window: &W::Id) {1204 pub fn activate_window(&mut self, window: &W::Id) {
1205+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
1206+ if move_.tile.window().id() == window {
1207+ return;
1208+ }
1209+ }
1210+
1060 let MonitorSet::Normal {1211 let MonitorSet::Normal {
1061 monitors,1212 monitors,
1062 active_monitor_idx,1213 active_monitor_idx,
@@ -1146,6 +1297,10 @@ impl<W: LayoutElement> Layout<W> {
1146 }1297 }
1147 1298
1148 pub fn active_window(&self) -> Option<(&W, &Output)> {1299 pub fn active_window(&self) -> Option<(&W, &Output)> {
1300+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
1301+ return Some((move_.tile.window(), &move_.output));
1302+ }
1303+
1149 let MonitorSet::Normal {1304 let MonitorSet::Normal {
1150 monitors,1305 monitors,
1151 active_monitor_idx,1306 active_monitor_idx,
@@ -1171,17 +1326,31 @@ impl<W: LayoutElement> Layout<W> {
1171 panic!()1326 panic!()
1172 };1327 };
1173 1328
1329+ let moving_window = self
1330+ .interactive_move
1331+ .as_ref()
1332+ .and_then(|x| x.moving())
1333+ .filter(|move_| move_.output == *output)
1334+ .map(|move_| move_.tile.window())
1335+ .into_iter();
1336+
1174 let mon = monitors.iter().find(|mon| &mon.output == output).unwrap();1337 let mon = monitors.iter().find(|mon| &mon.output == output).unwrap();
1175- mon.workspaces.iter().flat_map(|ws| ws.windows())1338+ let mon_windows = mon.workspaces.iter().flat_map(|ws| ws.windows());
1339+
1340+ moving_window.chain(mon_windows)
1176 }1341 }
1177 1342
1178- pub fn with_windows(&self, mut f: impl FnMut(&W, Option<&Output>, WorkspaceId)) {1343+ pub fn with_windows(&self, mut f: impl FnMut(&W, Option<&Output>, Option<WorkspaceId>)) {
1344+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
1345+ f(move_.tile.window(), Some(&move_.output), None);
1346+ }
1347+
1179 match &self.monitor_set {1348 match &self.monitor_set {
1180 MonitorSet::Normal { monitors, .. } => {1349 MonitorSet::Normal { monitors, .. } => {
1181 for mon in monitors {1350 for mon in monitors {
1182 for ws in &mon.workspaces {1351 for ws in &mon.workspaces {
1183 for win in ws.windows() {1352 for win in ws.windows() {
1184- f(win, Some(&mon.output), ws.id());1353+ f(win, Some(&mon.output), Some(ws.id()));
1185 }1354 }
1186 }1355 }
1187 }1356 }
@@ -1189,7 +1358,7 @@ impl<W: LayoutElement> Layout<W> {
1189 MonitorSet::NoOutputs { workspaces } => {1358 MonitorSet::NoOutputs { workspaces } => {
1190 for ws in workspaces {1359 for ws in workspaces {
1191 for win in ws.windows() {1360 for win in ws.windows() {
1192- f(win, None, ws.id());1361+ f(win, None, Some(ws.id()));
1193 }1362 }
1194 }1363 }
1195 }1364 }
@@ -1197,6 +1366,10 @@ impl<W: LayoutElement> Layout<W> {
1197 }1366 }
1198 1367
1199 pub fn with_windows_mut(&mut self, mut f: impl FnMut(&mut W, Option<&Output>)) {1368 pub fn with_windows_mut(&mut self, mut f: impl FnMut(&mut W, Option<&Output>)) {
1369+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
1370+ f(move_.tile.window_mut(), Some(&move_.output));
1371+ }
1372+
1200 match &mut self.monitor_set {1373 match &mut self.monitor_set {
1201 MonitorSet::Normal { monitors, .. } => {1374 MonitorSet::Normal { monitors, .. } => {
1202 for mon in monitors {1375 for mon in monitors {
@@ -1248,7 +1421,15 @@ impl<W: LayoutElement> Layout<W> {
1248 return None;1421 return None;
1249 };1422 };
1250 1423
1251- monitors.iter().find(|monitor| &monitor.output == output)1424+ monitors.iter().find(|mon| &mon.output == output)
1425+ }
1426+
1427+ pub fn monitor_for_output_mut(&mut self, output: &Output) -> Option<&mut Monitor<W>> {
1428+ let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {
1429+ return None;
1430+ };
1431+
1432+ monitors.iter_mut().find(|mon| &mon.output == output)
1252 }1433 }
1253 1434
1254 pub fn monitor_for_workspace(&self, workspace_name: &str) -> Option<&Monitor<W>> {1435 pub fn monitor_for_workspace(&self, workspace_name: &str) -> Option<&Monitor<W>> {
@@ -1362,6 +1543,12 @@ impl<W: LayoutElement> Layout<W> {
1362 }1543 }
1363 1544
1364 pub fn consume_or_expel_window_left(&mut self, window: Option<&W::Id>) {1545 pub fn consume_or_expel_window_left(&mut self, window: Option<&W::Id>) {
1546+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
1547+ if window == Some(move_.tile.window().id()) {
1548+ return;
1549+ }
1550+ }
1551+
1365 let workspace = if let Some(window) = window {1552 let workspace = if let Some(window) = window {
1366 Some(1553 Some(
1367 self.workspaces_mut()1554 self.workspaces_mut()
@@ -1379,6 +1566,12 @@ impl<W: LayoutElement> Layout<W> {
1379 }1566 }
1380 1567
1381 pub fn consume_or_expel_window_right(&mut self, window: Option<&W::Id>) {1568 pub fn consume_or_expel_window_right(&mut self, window: Option<&W::Id>) {
1569+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
1570+ if window == Some(move_.tile.window().id()) {
1571+ return;
1572+ }
1573+ }
1574+
1382 let workspace = if let Some(window) = window {1575 let workspace = if let Some(window) = window {
1383 Some(1576 Some(
1384 self.workspaces_mut()1577 self.workspaces_mut()
@@ -1576,6 +1769,12 @@ impl<W: LayoutElement> Layout<W> {
1576 }1769 }
1577 1770
1578 pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) {1771 pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) {
1772+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
1773+ if window == Some(move_.tile.window().id()) {
1774+ return;
1775+ }
1776+ }
1777+
1579 let Some(monitor) = self.active_monitor() else {1778 let Some(monitor) = self.active_monitor() else {
1580 return;1779 return;
1581 };1780 };
@@ -1666,6 +1865,10 @@ impl<W: LayoutElement> Layout<W> {
1666 }1865 }
1667 1866
1668 pub fn focus(&self) -> Option<&W> {1867 pub fn focus(&self) -> Option<&W> {
1868+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
1869+ return Some(move_.tile.window());
1870+ }
1871+
1669 let MonitorSet::Normal {1872 let MonitorSet::Normal {
1670 monitors,1873 monitors,
1671 active_monitor_idx,1874 active_monitor_idx,
@@ -1694,6 +1897,20 @@ impl<W: LayoutElement> Layout<W> {
1694 return None;1897 return None;
1695 };1898 };
1696 1899
1900+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
1901+ let tile_pos = move_.tile_render_location();
1902+ let pos_within_tile = pos_within_output - tile_pos;
1903+
1904+ if move_.tile.is_in_input_region(pos_within_tile) {
1905+ let pos_within_surface = tile_pos + move_.tile.buf_loc();
1906+ return Some((move_.tile.window(), Some(pos_within_surface)));
1907+ } else if move_.tile.is_in_activation_region(pos_within_tile) {
1908+ return Some((move_.tile.window(), None));
1909+ }
1910+
1911+ return None;
1912+ };
1913+
1697 let mon = monitors.iter().find(|mon| &mon.output == output)?;1914 let mon = monitors.iter().find(|mon| &mon.output == output)?;
1698 mon.window_under(pos_within_output)1915 mon.window_under(pos_within_output)
1699 }1916 }
@@ -1715,8 +1932,43 @@ impl<W: LayoutElement> Layout<W> {
1715 fn verify_invariants(&self) {1932 fn verify_invariants(&self) {
1716 use std::collections::HashSet;1933 use std::collections::HashSet;
1717 1934
1935+ use approx::assert_abs_diff_eq;
1936+
1718 use crate::layout::monitor::WorkspaceSwitch;1937 use crate::layout::monitor::WorkspaceSwitch;
1719 1938
1939+ let mut move_win_id = None;
1940+ if let Some(state) = &self.interactive_move {
1941+ match state {
1942+ InteractiveMoveState::Starting {
1943+ window_id,
1944+ pointer_delta: _,
1945+ pointer_ratio_within_window: _,
1946+ } => {
1947+ assert!(
1948+ self.has_window(window_id),
1949+ "interactive move must be on an existing window"
1950+ );
1951+ move_win_id = Some(window_id.clone());
1952+ }
1953+ InteractiveMoveState::Moving(move_) => {
1954+ let scale = move_.output.current_scale().fractional_scale();
1955+ let options = Options::clone(&self.options).adjusted_for_scale(scale);
1956+ assert_eq!(
1957+ &*move_.tile.options, &options,
1958+ "interactive moved tile options must be \
1959+ base options adjusted for output scale"
1960+ );
1961+
1962+ let tile_pos = move_.tile_render_location();
1963+ let rounded_pos = tile_pos.to_physical_precise_round(scale).to_logical(scale);
1964+
1965+ // Tile position must be rounded to physical pixels.
1966+ assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5);
1967+ assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5);
1968+ }
1969+ }
1970+ }
1971+
1720 let mut seen_workspace_id = HashSet::new();1972 let mut seen_workspace_id = HashSet::new();
1721 let mut seen_workspace_name = Vec::<String>::new();1973 let mut seen_workspace_name = Vec::<String>::new();
1722 1974
@@ -1760,7 +2012,7 @@ impl<W: LayoutElement> Layout<W> {
1760 seen_workspace_name.push(name.clone());2012 seen_workspace_name.push(name.clone());
1761 }2013 }
1762 2014
1763- workspace.verify_invariants();2015+ workspace.verify_invariants(move_win_id.as_ref());
1764 }2016 }
1765 2017
1766 return;2018 return;
@@ -1869,7 +2121,7 @@ impl<W: LayoutElement> Layout<W> {
1869 seen_workspace_name.push(name.clone());2121 seen_workspace_name.push(name.clone());
1870 }2122 }
1871 2123
1872- workspace.verify_invariants();2124+ workspace.verify_invariants(move_win_id.as_ref());
1873 }2125 }
1874 }2126 }
1875 }2127 }
@@ -1877,6 +2129,10 @@ impl<W: LayoutElement> Layout<W> {
1877 pub fn advance_animations(&mut self, current_time: Duration) {2129 pub fn advance_animations(&mut self, current_time: Duration) {
1878 let _span = tracy_client::span!("Layout::advance_animations");2130 let _span = tracy_client::span!("Layout::advance_animations");
1879 2131
2132+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2133+ move_.tile.advance_animations(current_time);
2134+ }
2135+
1880 match &mut self.monitor_set {2136 match &mut self.monitor_set {
1881 MonitorSet::Normal { monitors, .. } => {2137 MonitorSet::Normal { monitors, .. } => {
1882 for mon in monitors {2138 for mon in monitors {
@@ -1891,9 +2147,46 @@ impl<W: LayoutElement> Layout<W> {
1891 }2147 }
1892 }2148 }
1893 2149
2150+ pub fn are_animations_ongoing(&self, output: Option<&Output>) -> bool {
2151+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
2152+ if move_.tile.are_animations_ongoing() {
2153+ return true;
2154+ }
2155+ }
2156+
2157+ let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
2158+ return false;
2159+ };
2160+
2161+ for mon in monitors {
2162+ if output.map_or(false, |output| mon.output != *output) {
2163+ continue;
2164+ }
2165+
2166+ if mon.are_animations_ongoing() {
2167+ return true;
2168+ }
2169+ }
2170+
2171+ false
2172+ }
2173+
1894 pub fn update_render_elements(&mut self, output: Option<&Output>) {2174 pub fn update_render_elements(&mut self, output: Option<&Output>) {
1895 let _span = tracy_client::span!("Layout::update_render_elements");2175 let _span = tracy_client::span!("Layout::update_render_elements");
1896 2176
2177+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2178+ if output.map_or(true, |output| move_.output == *output) {
2179+ let pos_within_output = move_.tile_render_location();
2180+ let view_rect = Rectangle::from_loc_and_size(
2181+ pos_within_output.upscale(-1.),
2182+ output_size(&move_.output),
2183+ );
2184+ move_.tile.update(true, view_rect);
2185+ }
2186+ }
2187+
2188+ self.update_insert_hint(output);
2189+
1897 let MonitorSet::Normal {2190 let MonitorSet::Normal {
1898 monitors,2191 monitors,
1899 active_monitor_idx,2192 active_monitor_idx,
@@ -1906,13 +2199,19 @@ impl<W: LayoutElement> Layout<W> {
1906 2199
1907 for (idx, mon) in monitors.iter_mut().enumerate() {2200 for (idx, mon) in monitors.iter_mut().enumerate() {
1908 if output.map_or(true, |output| mon.output == *output) {2201 if output.map_or(true, |output| mon.output == *output) {
1909- let is_active = self.is_active && idx == *active_monitor_idx;2202+ let is_active = self.is_active
2203+ && idx == *active_monitor_idx
2204+ && !matches!(self.interactive_move, Some(InteractiveMoveState::Moving(_)));
1910 mon.update_render_elements(is_active);2205 mon.update_render_elements(is_active);
1911 }2206 }
1912 }2207 }
1913 }2208 }
1914 2209
1915 pub fn update_shaders(&mut self) {2210 pub fn update_shaders(&mut self) {
2211+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2212+ move_.tile.update_shaders();
2213+ }
2214+
1916 match &mut self.monitor_set {2215 match &mut self.monitor_set {
1917 MonitorSet::Normal { monitors, .. } => {2216 MonitorSet::Normal { monitors, .. } => {
1918 for mon in monitors {2217 for mon in monitors {
@@ -1929,6 +2228,50 @@ impl<W: LayoutElement> Layout<W> {
1929 }2228 }
1930 }2229 }
1931 2230
2231+ fn update_insert_hint(&mut self, output: Option<&Output>) {
2232+ let _span = tracy_client::span!("Layout::update_insert_hint");
2233+
2234+ let _span = tracy_client::span!("Layout::update_insert_hint::clear");
2235+ for ws in self.workspaces_mut() {
2236+ ws.clear_insert_hint();
2237+ }
2238+
2239+ if !matches!(self.interactive_move, Some(InteractiveMoveState::Moving(_))) {
2240+ return;
2241+ }
2242+ let Some(InteractiveMoveState::Moving(move_)) = self.interactive_move.take() else {
2243+ unreachable!()
2244+ };
2245+ if output.map_or(false, |out| &move_.output != out) {
2246+ self.interactive_move = Some(InteractiveMoveState::Moving(move_));
2247+ return;
2248+ }
2249+
2250+ let _span = tracy_client::span!("Layout::update_insert_hint::update");
2251+
2252+ if let Some(mon) = self.monitor_for_output_mut(&move_.output) {
2253+ if let Some((ws, offset)) = mon.workspace_under(move_.pointer_pos_within_output) {
2254+ let ws_id = ws.id();
2255+ let ws = mon
2256+ .workspaces
2257+ .iter_mut()
2258+ .find(|ws| ws.id() == ws_id)
2259+ .unwrap();
2260+
2261+ // TODO: empty workspaces need to reset their view position right away for this to
2262+ // look right.
2263+ let position = ws.get_insert_position(move_.pointer_pos_within_output - offset);
2264+ ws.set_insert_hint(InsertHint {
2265+ position,
2266+ width: move_.width,
2267+ is_full_width: move_.is_full_width,
2268+ });
2269+ }
2270+ }
2271+
2272+ self.interactive_move = Some(InteractiveMoveState::Moving(move_));
2273+ }
2274+
1932 pub fn ensure_named_workspace(&mut self, ws_config: &WorkspaceConfig) {2275 pub fn ensure_named_workspace(&mut self, ws_config: &WorkspaceConfig) {
1933 if self.find_workspace_by_name(&ws_config.name.0).is_some() {2276 if self.find_workspace_by_name(&ws_config.name.0).is_some() {
1934 return;2277 return;
@@ -1974,6 +2317,11 @@ impl<W: LayoutElement> Layout<W> {
1974 pub fn update_config(&mut self, config: &Config) {2317 pub fn update_config(&mut self, config: &Config) {
1975 let options = Rc::new(Options::from_config(config));2318 let options = Rc::new(Options::from_config(config));
1976 2319
2320+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2321+ let scale = move_.output.current_scale().fractional_scale();
2322+ move_.tile.update_config(scale, options.clone());
2323+ }
2324+
1977 match &mut self.monitor_set {2325 match &mut self.monitor_set {
1978 MonitorSet::Normal { monitors, .. } => {2326 MonitorSet::Normal { monitors, .. } => {
1979 for mon in monitors {2327 for mon in monitors {
@@ -1998,6 +2346,12 @@ impl<W: LayoutElement> Layout<W> {
1998 }2346 }
1999 2347
2000 pub fn toggle_window_height(&mut self, window: Option<&W::Id>) {2348 pub fn toggle_window_height(&mut self, window: Option<&W::Id>) {
2349+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2350+ if window == Some(move_.tile.window().id()) {
2351+ return;
2352+ }
2353+ }
2354+
2001 let workspace = if let Some(window) = window {2355 let workspace = if let Some(window) = window {
2002 Some(2356 Some(
2003 self.workspaces_mut()2357 self.workspaces_mut()
@@ -2029,6 +2383,12 @@ impl<W: LayoutElement> Layout<W> {
2029 }2383 }
2030 2384
2031 pub fn set_window_height(&mut self, window: Option<&W::Id>, change: SizeChange) {2385 pub fn set_window_height(&mut self, window: Option<&W::Id>, change: SizeChange) {
2386+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2387+ if window == Some(move_.tile.window().id()) {
2388+ return;
2389+ }
2390+ }
2391+
2032 let workspace = if let Some(window) = window {2392 let workspace = if let Some(window) = window {
2033 Some(2393 Some(
2034 self.workspaces_mut()2394 self.workspaces_mut()
@@ -2046,6 +2406,12 @@ impl<W: LayoutElement> Layout<W> {
2046 }2406 }
2047 2407
2048 pub fn reset_window_height(&mut self, window: Option<&W::Id>) {2408 pub fn reset_window_height(&mut self, window: Option<&W::Id>) {
2409+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2410+ if window == Some(move_.tile.window().id()) {
2411+ return;
2412+ }
2413+ }
2414+
2049 let workspace = if let Some(window) = window {2415 let workspace = if let Some(window) = window {
2050 Some(2416 Some(
2051 self.workspaces_mut()2417 self.workspaces_mut()
@@ -2084,6 +2450,12 @@ impl<W: LayoutElement> Layout<W> {
2084 output: &Output,2450 output: &Output,
2085 target_ws_idx: Option<usize>,2451 target_ws_idx: Option<usize>,
2086 ) {2452 ) {
2453+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2454+ if window == Some(move_.tile.window().id()) {
2455+ return;
2456+ }
2457+ }
2458+
2087 if let MonitorSet::Normal {2459 if let MonitorSet::Normal {
2088 monitors,2460 monitors,
2089 active_monitor_idx,2461 active_monitor_idx,
@@ -2227,6 +2599,12 @@ impl<W: LayoutElement> Layout<W> {
2227 }2599 }
2228 2600
2229 pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) {2601 pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) {
2602+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
2603+ if move_.tile.window().id() == window {
2604+ return;
2605+ }
2606+ }
2607+
2230 match &mut self.monitor_set {2608 match &mut self.monitor_set {
2231 MonitorSet::Normal { monitors, .. } => {2609 MonitorSet::Normal { monitors, .. } => {
2232 for mon in monitors {2610 for mon in monitors {
@@ -2250,6 +2628,12 @@ impl<W: LayoutElement> Layout<W> {
2250 }2628 }
2251 2629
2252 pub fn toggle_fullscreen(&mut self, window: &W::Id) {2630 pub fn toggle_fullscreen(&mut self, window: &W::Id) {
2631+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
2632+ if move_.tile.window().id() == window {
2633+ return;
2634+ }
2635+ }
2636+
2253 match &mut self.monitor_set {2637 match &mut self.monitor_set {
2254 MonitorSet::Normal { monitors, .. } => {2638 MonitorSet::Normal { monitors, .. } => {
2255 for mon in monitors {2639 for mon in monitors {
@@ -2402,6 +2786,350 @@ impl<W: LayoutElement> Layout<W> {
2402 None2786 None
2403 }2787 }
2404 2788
2789+ pub fn interactive_move_begin(
2790+ &mut self,
2791+ window_id: W::Id,
2792+ output: &Output,
2793+ start_pos_within_output: Point<f64, Logical>,
2794+ ) -> bool {
2795+ if self.interactive_move.is_some() {
2796+ return false;
2797+ }
2798+
2799+ let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {
2800+ return false;
2801+ };
2802+
2803+ let Some((mon, (ws, ws_offset))) = monitors.iter().find_map(|mon| {
2804+ mon.workspaces_with_render_positions()
2805+ .find(|(ws, _)| ws.has_window(&window_id))
2806+ .map(|rv| (mon, rv))
2807+ }) else {
2808+ return false;
2809+ };
2810+
2811+ if mon.output() != output {
2812+ return false;
2813+ }
2814+
2815+ let (tile, tile_offset) = ws
2816+ .tiles_with_render_positions()
2817+ .find(|(tile, _)| tile.window().id() == &window_id)
2818+ .unwrap();
2819+ let window_offset = tile.window_loc();
2820+
2821+ let tile_pos = ws_offset + tile_offset;
2822+
2823+ let pointer_offset_within_window = start_pos_within_output - tile_pos - window_offset;
2824+ let window_size = tile.window_size();
2825+ let pointer_ratio_within_window = (
2826+ f64::clamp(pointer_offset_within_window.x / window_size.w, 0., 1.),
2827+ f64::clamp(pointer_offset_within_window.y / window_size.h, 0., 1.),
2828+ );
2829+
2830+ self.interactive_move = Some(InteractiveMoveState::Starting {
2831+ window_id,
2832+ pointer_delta: Point::from((0., 0.)),
2833+ pointer_ratio_within_window,
2834+ });
2835+
2836+ true
2837+ }
2838+
2839+ pub fn interactive_move_update(
2840+ &mut self,
2841+ window: &W::Id,
2842+ delta: Point<f64, Logical>,
2843+ output: Output,
2844+ pointer_pos_within_output: Point<f64, Logical>,
2845+ ) -> bool {
2846+ let Some(state) = self.interactive_move.take() else {
2847+ return false;
2848+ };
2849+
2850+ match state {
2851+ InteractiveMoveState::Starting {
2852+ window_id,
2853+ mut pointer_delta,
2854+ pointer_ratio_within_window,
2855+ } => {
2856+ if window_id != *window {
2857+ self.interactive_move = Some(InteractiveMoveState::Starting {
2858+ window_id,
2859+ pointer_delta,
2860+ pointer_ratio_within_window,
2861+ });
2862+ return false;
2863+ }
2864+
2865+ pointer_delta += delta;
2866+
2867+ let (cx, cy) = (pointer_delta.x, pointer_delta.y);
2868+ let sq_dist = cx * cx + cy * cy;
2869+
2870+ let factor = RubberBand {
2871+ stiffness: 1.0,
2872+ limit: 0.5,
2873+ }
2874+ .band(sq_dist / INTERACTIVE_MOVE_START_THRESHOLD);
2875+
2876+ let tile = self
2877+ .workspaces_mut()
2878+ .flat_map(|ws| ws.tiles_mut())
2879+ .find(|tile| *tile.window().id() == window_id)
2880+ .unwrap();
2881+ tile.interactive_move_offset = pointer_delta.upscale(factor);
2882+
2883+ // Put it back to be able to easily return.
2884+ self.interactive_move = Some(InteractiveMoveState::Starting {
2885+ window_id: window_id.clone(),
2886+ pointer_delta,
2887+ pointer_ratio_within_window,
2888+ });
2889+
2890+ if sq_dist < INTERACTIVE_MOVE_START_THRESHOLD {
2891+ return true;
2892+ }
2893+
2894+ // If the pointer is currently on the window's own output, then we can animate the
2895+ // window movement from its current (rubberbanded and possibly moved away) position
2896+ // to the pointer. Otherwise, we just teleport it as the layout code is not aware
2897+ // of monitor positions.
2898+ //
2899+ // FIXME: with floating layer, the layout code will know about monitor positions,
2900+ // so this will be potentially animatable.
2901+ let mut tile_pos = None;
2902+ if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
2903+ if let Some((mon, (ws, ws_offset))) = monitors.iter().find_map(|mon| {
2904+ mon.workspaces_with_render_positions()
2905+ .find(|(ws, _)| ws.has_window(window))
2906+ .map(|rv| (mon, rv))
2907+ }) {
2908+ if mon.output() == &output {
2909+ let (_, tile_offset) = ws
2910+ .tiles_with_render_positions()
2911+ .find(|(tile, _)| tile.window().id() == window)
2912+ .unwrap();
2913+
2914+ tile_pos = Some(ws_offset + tile_offset);
2915+ }
2916+ }
2917+ }
2918+
2919+ let RemovedTile {
2920+ mut tile,
2921+ width,
2922+ is_full_width,
2923+ } = self.remove_window(window, Transaction::new()).unwrap();
2924+
2925+ tile.stop_move_animations();
2926+ tile.interactive_move_offset = Point::from((0., 0.));
2927+ tile.window().output_enter(&output);
2928+ tile.window().set_preferred_scale_transform(
2929+ output.current_scale(),
2930+ output.current_transform(),
2931+ );
2932+
2933+ let scale = output.current_scale().fractional_scale();
2934+ tile.update_config(
2935+ scale,
2936+ Rc::new(Options::clone(&self.options).adjusted_for_scale(scale)),
2937+ );
2938+
2939+ // Unfullscreen and let the window pick a natural size.
2940+ //
2941+ // When we have floating, we will want to always send a (0, 0) size here, not just
2942+ // to unfullscreen. However, when implementing that, remember to check how GTK
2943+ // tiled window size restoration works. It seems to remember *some* last size with
2944+ // prefer-no-csd, and occasionally that last size can become the full-width size
2945+ // rather than a smaller size, which is annoying. Need to see if niri can use some
2946+ // heuristics to make this case behave better.
2947+ if tile.window().is_pending_fullscreen() {
2948+ tile.window_mut()
2949+ .request_size(Size::from((0, 0)), true, None);
2950+ }
2951+
2952+ let mut data = InteractiveMoveData {
2953+ tile,
2954+ output,
2955+ pointer_pos_within_output,
2956+ width,
2957+ is_full_width,
2958+ pointer_ratio_within_window,
2959+ };
2960+
2961+ if let Some(tile_pos) = tile_pos {
2962+ let new_tile_pos = data.tile_render_location();
2963+ data.tile.animate_move_from(tile_pos - new_tile_pos);
2964+ }
2965+
2966+ self.interactive_move = Some(InteractiveMoveState::Moving(data));
2967+ }
2968+ InteractiveMoveState::Moving(mut move_) => {
2969+ if window != move_.tile.window().id() {
2970+ self.interactive_move = Some(InteractiveMoveState::Moving(move_));
2971+ return false;
2972+ }
2973+
2974+ if output != move_.output {
2975+ move_.tile.window().output_leave(&move_.output);
2976+ move_.tile.window().output_enter(&output);
2977+ move_.tile.window().set_preferred_scale_transform(
2978+ output.current_scale(),
2979+ output.current_transform(),
2980+ );
2981+ let scale = output.current_scale().fractional_scale();
2982+ move_.tile.update_config(
2983+ scale,
2984+ Rc::new(Options::clone(&self.options).adjusted_for_scale(scale)),
2985+ );
2986+ move_.output = output.clone();
2987+ self.focus_output(&output);
2988+ }
2989+
2990+ move_.pointer_pos_within_output = pointer_pos_within_output;
2991+
2992+ self.interactive_move = Some(InteractiveMoveState::Moving(move_));
2993+ }
2994+ }
2995+
2996+ true
2997+ }
2998+
2999+ pub fn interactive_move_end(&mut self, window: &W::Id) {
3000+ let Some(move_) = &self.interactive_move else {
3001+ return;
3002+ };
3003+
3004+ let move_ = match move_ {
3005+ InteractiveMoveState::Starting { window_id, .. } => {
3006+ if window_id != window {
3007+ return;
3008+ }
3009+
3010+ let Some(InteractiveMoveState::Starting { window_id, .. }) =
3011+ self.interactive_move.take()
3012+ else {
3013+ unreachable!()
3014+ };
3015+
3016+ let tile = self
3017+ .workspaces_mut()
3018+ .flat_map(|ws| ws.tiles_mut())
3019+ .find(|tile| *tile.window().id() == window_id)
3020+ .unwrap();
3021+ let offset = tile.interactive_move_offset;
3022+ tile.interactive_move_offset = Point::from((0., 0.));
3023+ tile.animate_move_from(offset);
3024+
3025+ return;
3026+ }
3027+ InteractiveMoveState::Moving(move_) => move_,
3028+ };
3029+
3030+ if window != move_.tile.window().id() {
3031+ return;
3032+ }
3033+
3034+ let Some(InteractiveMoveState::Moving(move_)) = self.interactive_move.take() else {
3035+ unreachable!()
3036+ };
3037+
3038+ match &mut self.monitor_set {
3039+ MonitorSet::Normal {
3040+ monitors,
3041+ active_monitor_idx,
3042+ ..
3043+ } => {
3044+ let (mon, ws_idx, position, offset) = if let Some(mon) =
3045+ monitors.iter_mut().find(|mon| mon.output == move_.output)
3046+ {
3047+ let (ws, offset) = mon
3048+ .workspace_under(move_.pointer_pos_within_output)
3049+ // If the pointer is somehow outside the move output and a workspace switch
3050+ // is in progress, this won't necessarily do the expected thing, but also
3051+ // that is not really supposed to happen so eh?
3052+ .unwrap_or_else(|| mon.workspaces_with_render_positions().next().unwrap());
3053+
3054+ let ws_id = ws.id();
3055+ let ws_idx = mon
3056+ .workspaces
3057+ .iter_mut()
3058+ .position(|ws| ws.id() == ws_id)
3059+ .unwrap();
3060+
3061+ let ws = &mut mon.workspaces[ws_idx];
3062+ let position = ws.get_insert_position(move_.pointer_pos_within_output - offset);
3063+ (mon, ws_idx, position, offset)
3064+ } else {
3065+ let mon = &mut monitors[*active_monitor_idx];
3066+ let ws_id = mon.active_workspace().id();
3067+ let (_, offset) = mon
3068+ .workspaces_with_render_positions()
3069+ .find(|(ws, _)| ws.id() == ws_id)
3070+ .unwrap();
3071+ let ws_idx = mon.active_workspace_idx();
3072+ let ws = &mut mon.workspaces[ws_idx];
3073+ // No point in trying to use the pointer position on the wrong output.
3074+ let position = InsertPosition::NewColumn(ws.columns.len());
3075+ (mon, ws_idx, position, offset)
3076+ };
3077+
3078+ let win_id = move_.tile.window().id().clone();
3079+ let window_render_loc = move_.tile_render_location() + move_.tile.window_loc();
3080+
3081+ match position {
3082+ InsertPosition::NewColumn(column_idx) => {
3083+ mon.add_tile(
3084+ ws_idx,
3085+ Some(column_idx),
3086+ move_.tile,
3087+ true,
3088+ move_.width,
3089+ move_.is_full_width,
3090+ );
3091+ }
3092+ InsertPosition::InColumn(column_idx, tile_idx) => {
3093+ mon.add_tile_to_column(
3094+ ws_idx,
3095+ column_idx,
3096+ Some(tile_idx),
3097+ move_.tile,
3098+ true,
3099+ );
3100+ }
3101+ }
3102+
3103+ let ws = &mut mon.workspaces[ws_idx];
3104+ let (tile, tile_render_loc) = ws
3105+ .tiles_with_render_positions_mut(false)
3106+ .find(|(tile, _)| tile.window().id() == &win_id)
3107+ .unwrap();
3108+ let new_window_render_loc = offset + tile_render_loc + tile.window_loc();
3109+
3110+ tile.animate_move_from(window_render_loc - new_window_render_loc);
3111+ }
3112+ MonitorSet::NoOutputs { workspaces, .. } => {
3113+ let ws = if let Some(ws) = workspaces.get_mut(0) {
3114+ ws
3115+ } else {
3116+ workspaces.push(Workspace::new_no_outputs(self.options.clone()));
3117+ &mut workspaces[0]
3118+ };
3119+
3120+ // No point in trying to use the pointer position without outputs.
3121+ ws.add_tile(
3122+ None,
3123+ move_.tile,
3124+ true,
3125+ move_.width,
3126+ move_.is_full_width,
3127+ None,
3128+ );
3129+ }
3130+ }
3131+ }
3132+
2405 pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool {3133 pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool {
2406 match &mut self.monitor_set {3134 match &mut self.monitor_set {
2407 MonitorSet::Normal { monitors, .. } => {3135 MonitorSet::Normal { monitors, .. } => {
@@ -2430,6 +3158,12 @@ impl<W: LayoutElement> Layout<W> {
2430 window: &W::Id,3158 window: &W::Id,
2431 delta: Point<f64, Logical>,3159 delta: Point<f64, Logical>,
2432 ) -> bool {3160 ) -> bool {
3161+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
3162+ if move_.tile.window().id() == window {
3163+ return false;
3164+ }
3165+ }
3166+
2433 match &mut self.monitor_set {3167 match &mut self.monitor_set {
2434 MonitorSet::Normal { monitors, .. } => {3168 MonitorSet::Normal { monitors, .. } => {
2435 for mon in monitors {3169 for mon in monitors {
@@ -2453,6 +3187,12 @@ impl<W: LayoutElement> Layout<W> {
2453 }3187 }
2454 3188
2455 pub fn interactive_resize_end(&mut self, window: &W::Id) {3189 pub fn interactive_resize_end(&mut self, window: &W::Id) {
3190+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
3191+ if move_.tile.window().id() == window {
3192+ return;
3193+ }
3194+ }
3195+
2456 match &mut self.monitor_set {3196 match &mut self.monitor_set {
2457 MonitorSet::Normal { monitors, .. } => {3197 MonitorSet::Normal { monitors, .. } => {
2458 for mon in monitors {3198 for mon in monitors {
@@ -2490,6 +3230,12 @@ impl<W: LayoutElement> Layout<W> {
2490 }3230 }
2491 3231
2492 pub fn start_open_animation_for_window(&mut self, window: &W::Id) {3232 pub fn start_open_animation_for_window(&mut self, window: &W::Id) {
3233+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
3234+ if move_.tile.window().id() == window {
3235+ return;
3236+ }
3237+ }
3238+
2493 match &mut self.monitor_set {3239 match &mut self.monitor_set {
2494 MonitorSet::Normal { monitors, .. } => {3240 MonitorSet::Normal { monitors, .. } => {
2495 for mon in monitors {3241 for mon in monitors {
@@ -2523,6 +3269,14 @@ impl<W: LayoutElement> Layout<W> {
2523 pub fn store_unmap_snapshot(&mut self, renderer: &mut GlesRenderer, window: &W::Id) {3269 pub fn store_unmap_snapshot(&mut self, renderer: &mut GlesRenderer, window: &W::Id) {
2524 let _span = tracy_client::span!("Layout::store_unmap_snapshot");3270 let _span = tracy_client::span!("Layout::store_unmap_snapshot");
2525 3271
3272+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
3273+ if move_.tile.window().id() == window {
3274+ let scale = Scale::from(move_.output.current_scale().fractional_scale());
3275+ move_.tile.store_unmap_snapshot_if_empty(renderer, scale);
3276+ return;
3277+ }
3278+ }
3279+
2526 match &mut self.monitor_set {3280 match &mut self.monitor_set {
2527 MonitorSet::Normal { monitors, .. } => {3281 MonitorSet::Normal { monitors, .. } => {
2528 for mon in monitors {3282 for mon in monitors {
@@ -2546,6 +3300,13 @@ impl<W: LayoutElement> Layout<W> {
2546 }3300 }
2547 3301
2548 pub fn clear_unmap_snapshot(&mut self, window: &W::Id) {3302 pub fn clear_unmap_snapshot(&mut self, window: &W::Id) {
3303+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
3304+ if move_.tile.window().id() == window {
3305+ let _ = move_.tile.take_unmap_snapshot();
3306+ return;
3307+ }
3308+ }
3309+
2549 match &mut self.monitor_set {3310 match &mut self.monitor_set {
2550 MonitorSet::Normal { monitors, .. } => {3311 MonitorSet::Normal { monitors, .. } => {
2551 for mon in monitors {3312 for mon in monitors {
@@ -2576,6 +3337,35 @@ impl<W: LayoutElement> Layout<W> {
2576 ) {3337 ) {
2577 let _span = tracy_client::span!("Layout::start_close_animation_for_window");3338 let _span = tracy_client::span!("Layout::start_close_animation_for_window");
2578 3339
3340+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
3341+ if move_.tile.window().id() == window {
3342+ let Some(snapshot) = move_.tile.take_unmap_snapshot() else {
3343+ return;
3344+ };
3345+ let tile_pos = move_.tile_render_location();
3346+ let tile_size = move_.tile.tile_size();
3347+
3348+ let output = move_.output.clone();
3349+ let pointer_pos_within_output = move_.pointer_pos_within_output;
3350+ let Some(mon) = self.monitor_for_output_mut(&output) else {
3351+ return;
3352+ };
3353+ let Some((ws, offset)) = mon.workspace_under(pointer_pos_within_output) else {
3354+ return;
3355+ };
3356+ let ws_id = ws.id();
3357+ let ws = mon
3358+ .workspaces
3359+ .iter_mut()
3360+ .find(|ws| ws.id() == ws_id)
3361+ .unwrap();
3362+
3363+ let tile_pos = tile_pos + Point::from((ws.view_pos(), 0.)) - offset;
3364+ ws.start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker);
3365+ return;
3366+ }
3367+ }
3368+
2579 match &mut self.monitor_set {3369 match &mut self.monitor_set {
2580 MonitorSet::Normal { monitors, .. } => {3370 MonitorSet::Normal { monitors, .. } => {
2581 for mon in monitors {3371 for mon in monitors {
@@ -2598,11 +3388,44 @@ impl<W: LayoutElement> Layout<W> {
2598 }3388 }
2599 }3389 }
2600 3390
3391+ pub fn render_floating_for_output<R: NiriRenderer>(
3392+ &self,
3393+ renderer: &mut R,
3394+ output: &Output,
3395+ target: RenderTarget,
3396+ ) -> impl Iterator<Item = TileRenderElement<R>> {
3397+ let mut rv = None;
3398+
3399+ if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
3400+ if &move_.output == output {
3401+ let scale = Scale::from(move_.output.current_scale().fractional_scale());
3402+ let location = move_.tile_render_location();
3403+ rv = Some(move_.tile.render(renderer, location, scale, true, target));
3404+ }
3405+ }
3406+
3407+ rv.into_iter().flatten()
3408+ }
3409+
2601 pub fn refresh(&mut self, is_active: bool) {3410 pub fn refresh(&mut self, is_active: bool) {
2602 let _span = tracy_client::span!("Layout::refresh");3411 let _span = tracy_client::span!("Layout::refresh");
2603 3412
2604 self.is_active = is_active;3413 self.is_active = is_active;
2605 3414
3415+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
3416+ let win = move_.tile.window_mut();
3417+
3418+ win.set_active_in_column(true);
3419+ win.set_activated(true);
3420+
3421+ win.set_interactive_resize(None);
3422+
3423+ win.set_bounds(output_size(&move_.output).to_i32_round());
3424+
3425+ win.send_pending_configure();
3426+ win.refresh();
3427+ }
3428+
2606 match &mut self.monitor_set {3429 match &mut self.monitor_set {
2607 MonitorSet::Normal {3430 MonitorSet::Normal {
2608 monitors,3431 monitors,
@@ -2612,6 +3435,12 @@ impl<W: LayoutElement> Layout<W> {
2612 for (idx, mon) in monitors.iter_mut().enumerate() {3435 for (idx, mon) in monitors.iter_mut().enumerate() {
2613 let is_active = self.is_active && idx == *active_monitor_idx;3436 let is_active = self.is_active && idx == *active_monitor_idx;
2614 for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() {3437 for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() {
3438+ let is_active = is_active
3439+ && ws_idx == mon.active_workspace_idx
3440+ && !matches!(
3441+ self.interactive_move,
3442+ Some(InteractiveMoveState::Moving(_))
3443+ );
2615 ws.refresh(is_active);3444 ws.refresh(is_active);
2616 3445
2617 // Cancel the view offset gesture after workspace switches, moves, etc.3446 // Cancel the view offset gesture after workspace switches, moves, etc.
@@ -2691,8 +3520,18 @@ impl<W: LayoutElement> Layout<W> {
2691 }3520 }
2692 3521
2693 pub fn windows(&self) -> impl Iterator<Item = (Option<&Monitor<W>>, &W)> {3522 pub fn windows(&self) -> impl Iterator<Item = (Option<&Monitor<W>>, &W)> {
2694- self.workspaces()3523+ let moving_window = self
2695- .flat_map(|(mon, _, ws)| ws.windows().map(move |win| (mon, win)))3524+ .interactive_move
3525+ .as_ref()
3526+ .and_then(|x| x.moving())
3527+ .map(|move_| (self.monitor_for_output(&move_.output), move_.tile.window()))
3528+ .into_iter();
3529+
3530+ let rest = self
3531+ .workspaces()
3532+ .flat_map(|(mon, _, ws)| ws.windows().map(move |win| (mon, win)));
3533+
3534+ moving_window.chain(rest)
2696 }3535 }
2697 3536
2698 pub fn has_window(&self, window: &W::Id) -> bool {3537 pub fn has_window(&self, window: &W::Id) -> bool {
@@ -2913,7 +3752,7 @@ mod tests {
2913 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {3752 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
2914 any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| {3753 any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| {
2915 let loc: Point<i32, _> = Point::from((x.into(), y.into()));3754 let loc: Point<i32, _> = Point::from((x.into(), y.into()));
2916- let size: Size<i32, _> = Size::from((w.into(), h.into()));3755+ let size: Size<i32, _> = Size::from((w.max(1).into(), h.max(1).into()));
2917 Rectangle::from_loc_and_size(loc, size)3756 Rectangle::from_loc_and_size(loc, size)
2918 })3757 })
2919 }3758 }
@@ -3140,6 +3979,34 @@ mod tests {
3140 cancelled: bool,3979 cancelled: bool,
3141 is_touchpad: Option<bool>,3980 is_touchpad: Option<bool>,
3142 },3981 },
3982+ InteractiveMoveBegin {
3983+ #[proptest(strategy = "1..=5usize")]
3984+ window: usize,
3985+ #[proptest(strategy = "1..=5usize")]
3986+ output_idx: usize,
3987+ #[proptest(strategy = "-20000f64..20000f64")]
3988+ px: f64,
3989+ #[proptest(strategy = "-20000f64..20000f64")]
3990+ py: f64,
3991+ },
3992+ InteractiveMoveUpdate {
3993+ #[proptest(strategy = "1..=5usize")]
3994+ window: usize,
3995+ #[proptest(strategy = "-20000f64..20000f64")]
3996+ dx: f64,
3997+ #[proptest(strategy = "-20000f64..20000f64")]
3998+ dy: f64,
3999+ #[proptest(strategy = "1..=5usize")]
4000+ output_idx: usize,
4001+ #[proptest(strategy = "-20000f64..20000f64")]
4002+ px: f64,
4003+ #[proptest(strategy = "-20000f64..20000f64")]
4004+ py: f64,
4005+ },
4006+ InteractiveMoveEnd {
4007+ #[proptest(strategy = "1..=5usize")]
4008+ window: usize,
4009+ },
3143 InteractiveResizeBegin {4010 InteractiveResizeBegin {
3144 #[proptest(strategy = "1..=5usize")]4011 #[proptest(strategy = "1..=5usize")]
3145 window: usize,4012 window: usize,
@@ -3275,6 +4142,12 @@ mod tests {
3275 } => {4142 } => {
3276 let mut found_right_of = false;4143 let mut found_right_of = false;
3277 4144
4145+ if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
4146+ if move_.tile.window().0.id == id {
4147+ return;
4148+ }
4149+ }
4150+
3278 match &mut layout.monitor_set {4151 match &mut layout.monitor_set {
3279 MonitorSet::Normal { monitors, .. } => {4152 MonitorSet::Normal { monitors, .. } => {
3280 for mon in monitors {4153 for mon in monitors {
@@ -3322,6 +4195,12 @@ mod tests {
3322 let ws_name = format!("ws{ws_name}");4195 let ws_name = format!("ws{ws_name}");
3323 let mut found_workspace = false;4196 let mut found_workspace = false;
3324 4197
4198+ if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
4199+ if move_.tile.window().0.id == id {
4200+ return;
4201+ }
4202+ }
4203+
3325 match &mut layout.monitor_set {4204 match &mut layout.monitor_set {
3326 MonitorSet::Normal { monitors, .. } => {4205 MonitorSet::Normal { monitors, .. } => {
3327 for mon in monitors {4206 for mon in monitors {
@@ -3526,6 +4405,21 @@ mod tests {
3526 }4405 }
3527 Op::Communicate(id) => {4406 Op::Communicate(id) => {
3528 let mut update = false;4407 let mut update = false;
4408+
4409+ if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
4410+ if move_.tile.window().0.id == id {
4411+ if move_.tile.window().communicate() {
4412+ update = true;
4413+ }
4414+
4415+ if update {
4416+ // FIXME: serial.
4417+ layout.update_window(&id, None);
4418+ }
4419+ return;
4420+ }
4421+ }
4422+
3529 match &mut layout.monitor_set {4423 match &mut layout.monitor_set {
3530 MonitorSet::Normal { monitors, .. } => {4424 MonitorSet::Normal { monitors, .. } => {
3531 'outer: for mon in monitors {4425 'outer: for mon in monitors {
@@ -3617,6 +4511,40 @@ mod tests {
3617 } => {4511 } => {
3618 layout.workspace_switch_gesture_end(cancelled, is_touchpad);4512 layout.workspace_switch_gesture_end(cancelled, is_touchpad);
3619 }4513 }
4514+ Op::InteractiveMoveBegin {
4515+ window,
4516+ output_idx,
4517+ px,
4518+ py,
4519+ } => {
4520+ let name = format!("output{output_idx}");
4521+ let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
4522+ return;
4523+ };
4524+ layout.interactive_move_begin(window, &output, Point::from((px, py)));
4525+ }
4526+ Op::InteractiveMoveUpdate {
4527+ window,
4528+ dx,
4529+ dy,
4530+ output_idx,
4531+ px,
4532+ py,
4533+ } => {
4534+ let name = format!("output{output_idx}");
4535+ let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
4536+ return;
4537+ };
4538+ layout.interactive_move_update(
4539+ &window,
4540+ Point::from((dx, dy)),
4541+ output,
4542+ Point::from((px, py)),
4543+ );
4544+ }
4545+ Op::InteractiveMoveEnd { window } => {
4546+ layout.interactive_move_end(&window);
4547+ }
3620 Op::InteractiveResizeBegin { window, edges } => {4548 Op::InteractiveResizeBegin { window, edges } => {
3621 layout.interactive_resize_begin(window, edges);4549 layout.interactive_resize_begin(window, edges);
3622 }4550 }
@@ -4725,6 +5653,27 @@ mod tests {
4725 check_ops_with_options(options, &ops);5653 check_ops_with_options(options, &ops);
4726 }5654 }
4727 5655
5656+ #[test]
5657+ fn start_interactive_move_then_remove_window() {
5658+ let ops = [
5659+ Op::AddOutput(1),
5660+ Op::AddWindow {
5661+ id: 0,
5662+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
5663+ min_max_size: Default::default(),
5664+ },
5665+ Op::InteractiveMoveBegin {
5666+ window: 0,
5667+ output_idx: 1,
5668+ px: 0.,
5669+ py: 0.,
5670+ },
5671+ Op::CloseWindow(0),
5672+ ];
5673+
5674+ check_ops(&ops);
5675+ }
5676+
4728 fn arbitrary_spacing() -> impl Strategy<Value = f64> {5677 fn arbitrary_spacing() -> impl Strategy<Value = f64> {
4729 // Give equal weight to:5678 // Give equal weight to:
4730 // - 0: the element is disabled5679 // - 0: the element is disabled
src/layout/monitor.rsmodified+52 -1
@@ -9,6 +9,7 @@ use smithay::backend::renderer::element::utils::{
9 use smithay::output::Output;9 use smithay::output::Output;
10 use smithay::utils::{Logical, Point, Rectangle};10 use smithay::utils::{Logical, Point, Rectangle};
11 11
12+use super::tile::Tile;
12 use super::workspace::{13 use super::workspace::{
13 compute_working_area, Column, ColumnWidth, OutputId, Workspace, WorkspaceId,14 compute_working_area, Column, ColumnWidth, OutputId, Workspace, WorkspaceId,
14 WorkspaceRenderElement,15 WorkspaceRenderElement,
@@ -241,6 +242,56 @@ impl<W: LayoutElement> Monitor<W> {
241 }242 }
242 }243 }
243 244
245+ pub fn add_tile(
246+ &mut self,
247+ workspace_idx: usize,
248+ column_idx: Option<usize>,
249+ tile: Tile<W>,
250+ activate: bool,
251+ width: ColumnWidth,
252+ is_full_width: bool,
253+ ) {
254+ let workspace = &mut self.workspaces[workspace_idx];
255+
256+ workspace.add_tile(column_idx, tile, activate, width, is_full_width, None);
257+
258+ // After adding a new window, workspace becomes this output's own.
259+ workspace.original_output = OutputId::new(&self.output);
260+
261+ if workspace_idx == self.workspaces.len() - 1 {
262+ // Insert a new empty workspace.
263+ let ws = Workspace::new(self.output.clone(), self.options.clone());
264+ self.workspaces.push(ws);
265+ }
266+
267+ if activate {
268+ self.activate_workspace(workspace_idx);
269+ }
270+ }
271+
272+ pub fn add_tile_to_column(
273+ &mut self,
274+ workspace_idx: usize,
275+ column_idx: usize,
276+ tile_idx: Option<usize>,
277+ tile: Tile<W>,
278+ activate: bool,
279+ ) {
280+ let workspace = &mut self.workspaces[workspace_idx];
281+
282+ workspace.add_tile_to_column(column_idx, tile_idx, tile, activate);
283+
284+ // After adding a new window, workspace becomes this output's own.
285+ workspace.original_output = OutputId::new(&self.output);
286+
287+ // Since we're adding window to an existing column, the workspace isn't empty, and
288+ // therefore cannot be the last one, so we never need to insert a new empty workspace.
289+
290+ if activate {
291+ self.activate_workspace(workspace_idx);
292+ }
293+ }
294+
244 pub fn clean_up_workspaces(&mut self) {295 pub fn clean_up_workspaces(&mut self) {
245 assert!(self.workspace_switch.is_none());296 assert!(self.workspace_switch.is_none());
246 297
@@ -682,7 +733,7 @@ impl<W: LayoutElement> Monitor<W> {
682 }733 }
683 }734 }
684 735
685- pub fn are_animations_ongoing(&self) -> bool {736+ pub(super) fn are_animations_ongoing(&self) -> bool {
686 self.workspace_switch737 self.workspace_switch
687 .as_ref()738 .as_ref()
688 .is_some_and(|s| s.is_animation())739 .is_some_and(|s| s.is_animation())
src/layout/tile.rsmodified+12 -1
@@ -64,6 +64,9 @@ pub struct Tile<W: LayoutElement> {
64 /// The animation of a tile visually moving vertically.64 /// The animation of a tile visually moving vertically.
65 move_y_animation: Option<MoveAnimation>,65 move_y_animation: Option<MoveAnimation>,
66 66
67+ /// Offset during the initial interactive move rubberband.
68+ pub(super) interactive_move_offset: Point<f64, Logical>,
69+
67 /// Snapshot of the last render for use in the close animation.70 /// Snapshot of the last render for use in the close animation.
68 unmap_snapshot: Option<TileRenderSnapshot>,71 unmap_snapshot: Option<TileRenderSnapshot>,
69 72
@@ -90,7 +93,7 @@ niri_render_elements! {
90 }93 }
91 }94 }
92 95
93-type TileRenderSnapshot =96+pub type TileRenderSnapshot =
94 RenderSnapshot<TileRenderElement<GlesRenderer>, TileRenderElement<GlesRenderer>>;97 RenderSnapshot<TileRenderElement<GlesRenderer>, TileRenderElement<GlesRenderer>>;
95 98
96 #[derive(Debug)]99 #[derive(Debug)]
@@ -123,6 +126,7 @@ impl<W: LayoutElement> Tile<W> {
123 resize_animation: None,126 resize_animation: None,
124 move_x_animation: None,127 move_x_animation: None,
125 move_y_animation: None,128 move_y_animation: None,
129+ interactive_move_offset: Point::from((0., 0.)),
126 unmap_snapshot: None,130 unmap_snapshot: None,
127 rounded_corner_damage: Default::default(),131 rounded_corner_damage: Default::default(),
128 scale,132 scale,
@@ -305,6 +309,8 @@ impl<W: LayoutElement> Tile<W> {
305 offset.y += move_.from * move_.anim.value();309 offset.y += move_.from * move_.anim.value();
306 }310 }
307 311
312+ offset += self.interactive_move_offset;
313+
308 offset314 offset
309 }315 }
310 316
@@ -364,6 +370,11 @@ impl<W: LayoutElement> Tile<W> {
364 });370 });
365 }371 }
366 372
373+ pub fn stop_move_animations(&mut self) {
374+ self.move_x_animation = None;
375+ self.move_y_animation = None;
376+ }
377+
367 pub fn window(&self) -> &W {378 pub fn window(&self) -> &W {
368 &self.window379 &self.window
369 }380 }
src/layout/workspace.rsmodified+274 -28
@@ -8,6 +8,7 @@ use niri_config::{
8 };8 };
9 use niri_ipc::SizeChange;9 use niri_ipc::SizeChange;
10 use ordered_float::NotNan;10 use ordered_float::NotNan;
11+use smithay::backend::renderer::element::Kind;
11 use smithay::backend::renderer::gles::GlesRenderer;12 use smithay::backend::renderer::gles::GlesRenderer;
12 use smithay::desktop::{layer_map_for_output, Window};13 use smithay::desktop::{layer_map_for_output, Window};
13 use smithay::output::Output;14 use smithay::output::Output;
@@ -16,12 +17,13 @@ use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
16 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};17 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
17 18
18 use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};19 use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};
19-use super::tile::{Tile, TileRenderElement};20+use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};
20 use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};21 use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};
21 use crate::animation::Animation;22 use crate::animation::Animation;
22 use crate::input::swipe_tracker::SwipeTracker;23 use crate::input::swipe_tracker::SwipeTracker;
23 use crate::niri_render_elements;24 use crate::niri_render_elements;
24 use crate::render_helpers::renderer::NiriRenderer;25 use crate::render_helpers::renderer::NiriRenderer;
26+use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
25 use crate::render_helpers::RenderTarget;27 use crate::render_helpers::RenderTarget;
26 use crate::utils::id::IdCounter;28 use crate::utils::id::IdCounter;
27 use crate::utils::transaction::{Transaction, TransactionBlocker};29 use crate::utils::transaction::{Transaction, TransactionBlocker};
@@ -106,6 +108,12 @@ pub struct Workspace<W: LayoutElement> {
106 /// Windows in the closing animation.108 /// Windows in the closing animation.
107 closing_windows: Vec<ClosingWindow>,109 closing_windows: Vec<ClosingWindow>,
108 110
111+ /// Indication where an interactively-moved window is about to be placed.
112+ insert_hint: Option<InsertHint>,
113+
114+ /// Buffer for the insert hint.
115+ insert_hint_buffer: SolidColorBuffer,
116+
109 /// Configurable properties of the layout as received from the parent monitor.117 /// Configurable properties of the layout as received from the parent monitor.
110 pub(super) base_options: Rc<Options>,118 pub(super) base_options: Rc<Options>,
111 119
@@ -119,6 +127,19 @@ pub struct Workspace<W: LayoutElement> {
119 id: WorkspaceId,127 id: WorkspaceId,
120 }128 }
121 129
130+#[derive(Debug, PartialEq)]
131+pub enum InsertPosition {
132+ NewColumn(usize),
133+ InColumn(usize, usize),
134+}
135+
136+#[derive(Debug)]
137+pub struct InsertHint {
138+ pub position: InsertPosition,
139+ pub width: ColumnWidth,
140+ pub is_full_width: bool,
141+}
142+
122 #[derive(Debug, Clone)]143 #[derive(Debug, Clone)]
123 pub struct OutputId(String);144 pub struct OutputId(String);
124 145
@@ -418,6 +439,8 @@ impl<W: LayoutElement> Workspace<W> {
418 activate_prev_column_on_removal: None,439 activate_prev_column_on_removal: None,
419 view_offset_before_fullscreen: None,440 view_offset_before_fullscreen: None,
420 closing_windows: vec![],441 closing_windows: vec![],
442+ insert_hint: None,
443+ insert_hint_buffer: SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.]),
421 base_options,444 base_options,
422 options,445 options,
423 name: config.map(|c| c.name.0),446 name: config.map(|c| c.name.0),
@@ -456,6 +479,8 @@ impl<W: LayoutElement> Workspace<W> {
456 activate_prev_column_on_removal: None,479 activate_prev_column_on_removal: None,
457 view_offset_before_fullscreen: None,480 view_offset_before_fullscreen: None,
458 closing_windows: vec![],481 closing_windows: vec![],
482+ insert_hint: None,
483+ insert_hint_buffer: SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.]),
459 base_options,484 base_options,
460 options,485 options,
461 name: config.map(|c| c.name.0),486 name: config.map(|c| c.name.0),
@@ -534,6 +559,13 @@ impl<W: LayoutElement> Workspace<W> {
534 let view_rect = Rectangle::from_loc_and_size(col_pos, view_size);559 let view_rect = Rectangle::from_loc_and_size(col_pos, view_size);
535 col.update_render_elements(is_active, view_rect);560 col.update_render_elements(is_active, view_rect);
536 }561 }
562+
563+ if let Some(insert_hint) = &self.insert_hint {
564+ if let Some(area) = self.insert_hint_area(insert_hint) {
565+ self.insert_hint_buffer
566+ .update(area.size, self.options.insert_hint.color.to_array_premul());
567+ }
568+ }
537 }569 }
538 570
539 pub fn update_config(&mut self, base_options: Rc<Options>) {571 pub fn update_config(&mut self, base_options: Rc<Options>) {
@@ -565,10 +597,11 @@ impl<W: LayoutElement> Workspace<W> {
565 }597 }
566 598
567 pub fn windows_mut(&mut self) -> impl Iterator<Item = &mut W> + '_ {599 pub fn windows_mut(&mut self) -> impl Iterator<Item = &mut W> + '_ {
568- self.columns600+ self.tiles_mut().map(Tile::window_mut)
569- .iter_mut()601+ }
570- .flat_map(|col| col.tiles.iter_mut())602+
571- .map(Tile::window_mut)603+ pub fn tiles_mut(&mut self) -> impl Iterator<Item = &mut Tile<W>> + '_ {
604+ self.columns.iter_mut().flat_map(|col| col.tiles.iter_mut())
572 }605 }
573 606
574 pub fn current_output(&self) -> Option<&Output> {607 pub fn current_output(&self) -> Option<&Output> {
@@ -731,14 +764,17 @@ impl<W: LayoutElement> Workspace<W> {
731 });764 });
732 }765 }
733 766
734- fn compute_new_view_offset_for_column_fit(&self, current_x: f64, idx: usize) -> f64 {767+ fn compute_new_view_offset_fit(
735- let col = &self.columns[idx];768+ &self,
736- if col.is_fullscreen {769+ current_x: f64,
770+ col_x: f64,
771+ width: f64,
772+ is_fullscreen: bool,
773+ ) -> f64 {
774+ if is_fullscreen {
737 return 0.;775 return 0.;
738 }776 }
739 777
740- let new_col_x = self.column_x(idx);
741-
742 let final_x = if let Some(ViewOffsetAdjustment::Animation(anim)) = &self.view_offset_adj {778 let final_x = if let Some(ViewOffsetAdjustment::Animation(anim)) = &self.view_offset_adj {
743 current_x - self.view_offset + anim.to()779 current_x - self.view_offset + anim.to()
744 } else {780 } else {
@@ -748,8 +784,8 @@ impl<W: LayoutElement> Workspace<W> {
748 let new_offset = compute_new_view_offset(784 let new_offset = compute_new_view_offset(
749 final_x + self.working_area.loc.x,785 final_x + self.working_area.loc.x,
750 self.working_area.size.w,786 self.working_area.size.w,
751- new_col_x,787+ col_x,
752- col.width(),788+ width,
753 self.options.gaps,789 self.options.gaps,
754 );790 );
755 791
@@ -757,22 +793,45 @@ impl<W: LayoutElement> Workspace<W> {
757 new_offset - self.working_area.loc.x793 new_offset - self.working_area.loc.x
758 }794 }
759 795
760- fn compute_new_view_offset_for_column_centered(&self, current_x: f64, idx: usize) -> f64 {796+ fn compute_new_view_offset_centered(
761- let col = &self.columns[idx];797+ &self,
762- if col.is_fullscreen {798+ current_x: f64,
763- return self.compute_new_view_offset_for_column_fit(current_x, idx);799+ col_x: f64,
800+ width: f64,
801+ is_fullscreen: bool,
802+ ) -> f64 {
803+ if is_fullscreen {
804+ return self.compute_new_view_offset_fit(current_x, col_x, width, is_fullscreen);
764 }805 }
765 806
766- let width = col.width();
767-
768 // Columns wider than the view are left-aligned (the fit code can deal with that).807 // Columns wider than the view are left-aligned (the fit code can deal with that).
769 if self.working_area.size.w <= width {808 if self.working_area.size.w <= width {
770- return self.compute_new_view_offset_for_column_fit(current_x, idx);809+ return self.compute_new_view_offset_fit(current_x, col_x, width, is_fullscreen);
771 }810 }
772 811
773 -(self.working_area.size.w - width) / 2. - self.working_area.loc.x812 -(self.working_area.size.w - width) / 2. - self.working_area.loc.x
774 }813 }
775 814
815+ fn compute_new_view_offset_for_column_fit(&self, current_x: f64, idx: usize) -> f64 {
816+ let col = &self.columns[idx];
817+ self.compute_new_view_offset_fit(
818+ current_x,
819+ self.column_x(idx),
820+ col.width(),
821+ col.is_fullscreen,
822+ )
823+ }
824+
825+ fn compute_new_view_offset_for_column_centered(&self, current_x: f64, idx: usize) -> f64 {
826+ let col = &self.columns[idx];
827+ self.compute_new_view_offset_centered(
828+ current_x,
829+ self.column_x(idx),
830+ col.width(),
831+ col.is_fullscreen,
832+ )
833+ }
834+
776 fn compute_new_view_offset_for_column(835 fn compute_new_view_offset_for_column(
777 &self,836 &self,
778 current_x: f64,837 current_x: f64,
@@ -958,6 +1017,71 @@ impl<W: LayoutElement> Workspace<W> {
958 self.windows_mut().find(|win| win.is_wl_surface(wl_surface))1017 self.windows_mut().find(|win| win.is_wl_surface(wl_surface))
959 }1018 }
960 1019
1020+ pub fn set_insert_hint(&mut self, insert_hint: InsertHint) {
1021+ if self.options.insert_hint.off {
1022+ return;
1023+ }
1024+ self.insert_hint = Some(insert_hint);
1025+ }
1026+
1027+ pub fn clear_insert_hint(&mut self) {
1028+ self.insert_hint = None;
1029+ }
1030+
1031+ pub fn get_insert_position(&self, pos: Point<f64, Logical>) -> InsertPosition {
1032+ if self.columns.is_empty() {
1033+ return InsertPosition::NewColumn(0);
1034+ }
1035+
1036+ let x = pos.x + self.view_pos();
1037+
1038+ // Aim for the center of the gap.
1039+ let x = x + self.options.gaps / 2.;
1040+ let y = pos.y + self.options.gaps / 2.;
1041+
1042+ // Insert position is before the first column.
1043+ if x < 0. {
1044+ return InsertPosition::NewColumn(0);
1045+ }
1046+
1047+ // Find the closest gap between columns.
1048+ let (closest_col_idx, col_x) = self
1049+ .column_xs(self.data.iter().copied())
1050+ .enumerate()
1051+ .min_by_key(|(_, col_x)| NotNan::new((col_x - x).abs()).unwrap())
1052+ .unwrap();
1053+
1054+ // Find the column containing the position.
1055+ let (col_idx, _) = self
1056+ .column_xs(self.data.iter().copied())
1057+ .enumerate()
1058+ .take_while(|(_, col_x)| *col_x <= x)
1059+ .last()
1060+ .unwrap_or((0, 0.));
1061+
1062+ // Insert position is past the last column.
1063+ if col_idx == self.columns.len() {
1064+ return InsertPosition::NewColumn(closest_col_idx);
1065+ }
1066+
1067+ // Find the closest gap between tiles.
1068+ let col = &self.columns[col_idx];
1069+ let (closest_tile_idx, tile_off) = col
1070+ .tile_offsets()
1071+ .enumerate()
1072+ .min_by_key(|(_, tile_off)| NotNan::new((tile_off.y - y).abs()).unwrap())
1073+ .unwrap();
1074+
1075+ // Return the closest among the vertical and the horizontal gap.
1076+ let vert_dist = (col_x - x).abs();
1077+ let hor_dist = (tile_off.y - y).abs();
1078+ if vert_dist <= hor_dist {
1079+ InsertPosition::NewColumn(closest_col_idx)
1080+ } else {
1081+ InsertPosition::InColumn(col_idx, closest_tile_idx)
1082+ }
1083+ }
1084+
961 pub fn add_window(1085 pub fn add_window(
962 &mut self,1086 &mut self,
963 col_idx: Option<usize>,1087 col_idx: Option<usize>,
@@ -970,7 +1094,7 @@ impl<W: LayoutElement> Workspace<W> {
970 self.add_tile(col_idx, tile, activate, width, is_full_width, None);1094 self.add_tile(col_idx, tile, activate, width, is_full_width, None);
971 }1095 }
972 1096
973- fn add_tile(1097+ pub fn add_tile(
974 &mut self,1098 &mut self,
975 col_idx: Option<usize>,1099 col_idx: Option<usize>,
976 tile: Tile<W>,1100 tile: Tile<W>,
@@ -1488,8 +1612,6 @@ impl<W: LayoutElement> Workspace<W> {
1488 window: &W::Id,1612 window: &W::Id,
1489 blocker: TransactionBlocker,1613 blocker: TransactionBlocker,
1490 ) {1614 ) {
1491- let output_scale = Scale::from(self.scale.fractional_scale());
1492-
1493 let (tile, mut tile_pos) = self1615 let (tile, mut tile_pos) = self
1494 .tiles_with_render_positions_mut(false)1616 .tiles_with_render_positions_mut(false)
1495 .find(|(tile, _)| tile.window().id() == window)1617 .find(|(tile, _)| tile.window().id() == window)
@@ -1537,6 +1659,19 @@ impl<W: LayoutElement> Workspace<W> {
1537 tile_pos.x -= offset;1659 tile_pos.x -= offset;
1538 }1660 }
1539 1661
1662+ self.start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker);
1663+ }
1664+
1665+ pub fn start_close_animation_for_tile(
1666+ &mut self,
1667+ renderer: &mut GlesRenderer,
1668+ snapshot: TileRenderSnapshot,
1669+ tile_size: Size<f64, Logical>,
1670+ tile_pos: Point<f64, Logical>,
1671+ blocker: TransactionBlocker,
1672+ ) {
1673+ let output_scale = Scale::from(self.scale.fractional_scale());
1674+
1540 let anim = Animation::new(0., 1., 0., self.options.animations.window_close.anim);1675 let anim = Animation::new(0., 1., 0., self.options.animations.window_close.anim);
1541 1676
1542 let blocker = if self.options.disable_transactions {1677 let blocker = if self.options.disable_transactions {
@@ -1565,7 +1700,7 @@ impl<W: LayoutElement> Workspace<W> {
1565 }1700 }
1566 1701
1567 #[cfg(test)]1702 #[cfg(test)]
1568- pub fn verify_invariants(&self) {1703+ pub fn verify_invariants(&self, move_win_id: Option<&W::Id>) {
1569 use approx::assert_abs_diff_eq;1704 use approx::assert_abs_diff_eq;
1570 1705
1571 let scale = self.scale.fractional_scale();1706 let scale = self.scale.fractional_scale();
@@ -1601,7 +1736,11 @@ impl<W: LayoutElement> Workspace<W> {
1601 );1736 );
1602 }1737 }
1603 1738
1604- for (_, tile_pos) in self.tiles_with_render_positions() {1739+ for (tile, tile_pos) in self.tiles_with_render_positions() {
1740+ if Some(tile.window().id()) != move_win_id {
1741+ assert_eq!(tile.interactive_move_offset, Point::from((0., 0.)));
1742+ }
1743+
1605 let rounded_pos = tile_pos.to_physical_precise_round(scale).to_logical(scale);1744 let rounded_pos = tile_pos.to_physical_precise_round(scale).to_logical(scale);
1606 1745
1607 // Tile positions must be rounded to physical pixels.1746 // Tile positions must be rounded to physical pixels.
@@ -2046,7 +2185,7 @@ impl<W: LayoutElement> Workspace<W> {
2046 cancel_resize_for_column(&mut self.interactive_resize, col);2185 cancel_resize_for_column(&mut self.interactive_resize, col);
2047 }2186 }
2048 2187
2049- fn view_pos(&self) -> f64 {2188+ pub fn view_pos(&self) -> f64 {
2050 self.column_x(self.active_column_idx) + self.view_offset2189 self.column_x(self.active_column_idx) + self.view_offset
2051 }2190 }
2052 2191
@@ -2123,7 +2262,9 @@ impl<W: LayoutElement> Workspace<W> {
2123 zip(tiles, offsets)2262 zip(tiles, offsets)
2124 }2263 }
2125 2264
2126- fn tiles_with_render_positions(&self) -> impl Iterator<Item = (&Tile<W>, Point<f64, Logical>)> {2265+ pub fn tiles_with_render_positions(
2266+ &self,
2267+ ) -> impl Iterator<Item = (&Tile<W>, Point<f64, Logical>)> {
2127 let scale = self.scale.fractional_scale();2268 let scale = self.scale.fractional_scale();
2128 let view_off = Point::from((-self.view_pos(), 0.));2269 let view_off = Point::from((-self.view_pos(), 0.));
2129 self.columns_in_render_order()2270 self.columns_in_render_order()
@@ -2139,7 +2280,7 @@ impl<W: LayoutElement> Workspace<W> {
2139 })2280 })
2140 }2281 }
2141 2282
2142- fn tiles_with_render_positions_mut(2283+ pub fn tiles_with_render_positions_mut(
2143 &mut self,2284 &mut self,
2144 round: bool,2285 round: bool,
2145 ) -> impl Iterator<Item = (&mut Tile<W>, Point<f64, Logical>)> {2286 ) -> impl Iterator<Item = (&mut Tile<W>, Point<f64, Logical>)> {
@@ -2162,6 +2303,96 @@ impl<W: LayoutElement> Workspace<W> {
2162 })2303 })
2163 }2304 }
2164 2305
2306+ fn insert_hint_area(&self, insert_hint: &InsertHint) -> Option<Rectangle<f64, Logical>> {
2307+ let mut hint_area = match insert_hint.position {
2308+ InsertPosition::NewColumn(column_index) => {
2309+ if column_index == 0 || column_index == self.columns.len() {
2310+ let size =
2311+ Size::from((300., self.working_area.size.h - self.options.gaps * 2.));
2312+ let mut loc = Point::from((
2313+ self.column_x(column_index),
2314+ self.working_area.loc.y + self.options.gaps,
2315+ ));
2316+ if column_index == 0 && !self.columns.is_empty() {
2317+ loc.x -= size.w + self.options.gaps;
2318+ }
2319+ Rectangle::from_loc_and_size(loc, size)
2320+ } else if column_index > self.columns.len() {
2321+ error!("insert hint column index is out of range");
2322+ return None;
2323+ } else {
2324+ let size =
2325+ Size::from((300., self.working_area.size.h - self.options.gaps * 2.));
2326+ let loc = Point::from((
2327+ self.column_x(column_index) - size.w / 2. - self.options.gaps / 2.,
2328+ self.working_area.loc.y + self.options.gaps,
2329+ ));
2330+ Rectangle::from_loc_and_size(loc, size)
2331+ }
2332+ }
2333+ InsertPosition::InColumn(column_index, tile_index) => {
2334+ if column_index > self.columns.len() {
2335+ error!("insert hint column index is out of range");
2336+ return None;
2337+ }
2338+ if tile_index > self.columns[column_index].tiles.len() {
2339+ error!("insert hint tile index is out of range");
2340+ return None;
2341+ }
2342+
2343+ let (height, y) = if tile_index == 0 {
2344+ (150., self.columns[column_index].tile_offset(tile_index).y)
2345+ } else if tile_index == self.columns[column_index].tiles.len() {
2346+ (
2347+ 150.,
2348+ self.columns[column_index].tile_offset(tile_index).y
2349+ - self.options.gaps
2350+ - 150.,
2351+ )
2352+ } else {
2353+ (
2354+ 300.,
2355+ self.columns[column_index].tile_offset(tile_index).y
2356+ - self.options.gaps / 2.
2357+ - 150.,
2358+ )
2359+ };
2360+
2361+ let size = Size::from((self.data[column_index].width, height));
2362+ let loc = Point::from((self.column_x(column_index), y));
2363+ Rectangle::from_loc_and_size(loc, size)
2364+ }
2365+ };
2366+
2367+ // First window on an empty workspace will cancel out any view offset. Replicate this
2368+ // effect here.
2369+ if self.columns.is_empty() {
2370+ let view_offset = if self.is_centering_focused_column() {
2371+ self.compute_new_view_offset_centered(0., 0., hint_area.size.w, false)
2372+ } else {
2373+ self.compute_new_view_offset_fit(0., 0., hint_area.size.w, false)
2374+ };
2375+ hint_area.loc.x -= view_offset;
2376+ } else {
2377+ hint_area.loc.x -= self.view_pos();
2378+ }
2379+
2380+ let view_size = self.view_size();
2381+
2382+ // Make sure the hint is at least partially visible.
2383+ if matches!(insert_hint.position, InsertPosition::NewColumn(_)) {
2384+ hint_area.loc.x = hint_area.loc.x.max(-hint_area.size.w / 2.);
2385+ hint_area.loc.x = hint_area.loc.x.min(view_size.w - hint_area.size.w / 2.);
2386+ }
2387+
2388+ // Round to physical pixels.
2389+ hint_area = hint_area
2390+ .to_physical_precise_round(self.scale.fractional_scale())
2391+ .to_logical(self.scale.fractional_scale());
2392+
2393+ Some(hint_area)
2394+ }
2395+
2165 /// Returns the geometry of the active tile relative to and clamped to the view.2396 /// Returns the geometry of the active tile relative to and clamped to the view.
2166 ///2397 ///
2167 /// During animations, assumes the final view position.2398 /// During animations, assumes the final view position.
@@ -2438,7 +2669,22 @@ impl<W: LayoutElement> Workspace<W> {
2438 2669
2439 let mut rv = vec![];2670 let mut rv = vec![];
2440 2671
2441- // Draw the closing windows on top.2672+ // Draw the insert hint.
2673+ if let Some(insert_hint) = &self.insert_hint {
2674+ if let Some(area) = self.insert_hint_area(insert_hint) {
2675+ rv.push(
2676+ TileRenderElement::SolidColor(SolidColorRenderElement::from_buffer(
2677+ &self.insert_hint_buffer,
2678+ area.loc,
2679+ 1.,
2680+ Kind::Unspecified,
2681+ ))
2682+ .into(),
2683+ );
2684+ }
2685+ }
2686+
2687+ // Draw the closing windows on top of the other windows.
2442 let view_rect = Rectangle::from_loc_and_size((self.view_pos(), 0.), self.view_size);2688 let view_rect = Rectangle::from_loc_and_size((self.view_pos(), 0.), self.view_size);
2443 for closing in self.closing_windows.iter().rev() {2689 for closing in self.closing_windows.iter().rev() {
2444 let elem = closing.render(renderer.as_gles_renderer(), view_rect, output_scale, target);2690 let elem = closing.render(renderer.as_gles_renderer(), view_rect, output_scale, target);
src/niri.rsmodified+9 -5
@@ -116,6 +116,7 @@ use crate::input::{
116 apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_wheel_binds, TabletData,116 apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_wheel_binds, TabletData,
117 };117 };
118 use crate::ipc::server::IpcServer;118 use crate::ipc::server::IpcServer;
119+use crate::layout::tile::TileRenderElement;
119 use crate::layout::workspace::WorkspaceId;120 use crate::layout::workspace::WorkspaceId;
120 use crate::layout::{Layout, LayoutElement as _, MonitorRenderElement};121 use crate::layout::{Layout, LayoutElement as _, MonitorRenderElement};
121 use crate::protocols::foreign_toplevel::{self, ForeignToplevelManagerState};122 use crate::protocols::foreign_toplevel::{self, ForeignToplevelManagerState};
@@ -3076,6 +3077,10 @@ impl Niri {
3076 // Get monitor elements.3077 // Get monitor elements.
3077 let mon = self.layout.monitor_for_output(output).unwrap();3078 let mon = self.layout.monitor_for_output(output).unwrap();
3078 let monitor_elements: Vec<_> = mon.render_elements(renderer, target).collect();3079 let monitor_elements: Vec<_> = mon.render_elements(renderer, target).collect();
3080+ let float_elements: Vec<_> = self
3081+ .layout
3082+ .render_floating_for_output(renderer, output, target)
3083+ .collect();
3079 3084
3080 // Get layer-shell elements.3085 // Get layer-shell elements.
3081 let layer_map = layer_map_for_output(output);3086 let layer_map = layer_map_for_output(output);
@@ -3106,10 +3111,12 @@ impl Niri {
3106 3111
3107 // Then the regular monitor elements and the top layer in varying order.3112 // Then the regular monitor elements and the top layer in varying order.
3108 if mon.render_above_top_layer() {3113 if mon.render_above_top_layer() {
3114+ elements.extend(float_elements.into_iter().map(OutputRenderElements::from));
3109 elements.extend(monitor_elements.into_iter().map(OutputRenderElements::from));3115 elements.extend(monitor_elements.into_iter().map(OutputRenderElements::from));
3110 extend_from_layer(&mut elements, Layer::Top);3116 extend_from_layer(&mut elements, Layer::Top);
3111 } else {3117 } else {
3112 extend_from_layer(&mut elements, Layer::Top);3118 extend_from_layer(&mut elements, Layer::Top);
3119+ elements.extend(float_elements.into_iter().map(OutputRenderElements::from));
3113 elements.extend(monitor_elements.into_iter().map(OutputRenderElements::from));3120 elements.extend(monitor_elements.into_iter().map(OutputRenderElements::from));
3114 }3121 }
3115 3122
@@ -3151,11 +3158,7 @@ impl Niri {
3151 }3158 }
3152 }3159 }
3153 3160
3154- state.unfinished_animations_remain = self3161+ state.unfinished_animations_remain = self.layout.are_animations_ongoing(Some(output));
3155- .layout
3156- .monitor_for_output(output)
3157- .unwrap()
3158- .are_animations_ongoing();
3159 3162
3160 self.config_error_notification3163 self.config_error_notification
3161 .advance_animations(target_presentation_time);3164 .advance_animations(target_presentation_time);
@@ -4797,6 +4800,7 @@ impl ClientData for ClientState {
4797 niri_render_elements! {4800 niri_render_elements! {
4798 OutputRenderElements<R> => {4801 OutputRenderElements<R> => {
4799 Monitor = MonitorRenderElement<R>,4802 Monitor = MonitorRenderElement<R>,
4803+ Tile = TileRenderElement<R>,
4800 Wayland = WaylandSurfaceRenderElement<R>,4804 Wayland = WaylandSurfaceRenderElement<R>,
4801 NamedPointer = MemoryRenderBufferRenderElement<R>,4805 NamedPointer = MemoryRenderBufferRenderElement<R>,
4802 SolidColor = SolidColorRenderElement,4806 SolidColor = SolidColorRenderElement,