forge
Explore
Log in

Don't you dare go Hollow

Implement scrolling the view during DnD

Browse files at this commit

ca1500ae90f33344fe776898ae11137bf7d1ecc1Ivan MolodetskikhParent: d7f3ca0
DnD is external to the layout, so we just inform it when one is ongoing.
src/handlers/mod.rsmodified+3 -0
@@ -344,6 +344,9 @@ impl ClientDndGrabHandler for State {
344 fn dropped(&mut self, target: Option<WlSurface>, validated: bool, _seat: Seat<Self>) {344 fn dropped(&mut self, target: Option<WlSurface>, validated: bool, _seat: Seat<Self>) {
345 trace!("client dropped, target: {target:?}, validated: {validated}");345 trace!("client dropped, target: {target:?}, validated: {validated}");
346 346
347+ // End DnD before activating a specific window below so that it takes precedence.
348+ self.niri.layout.dnd_end();
349+
347 // Activate the target output, since that's how Firefox drag-tab-into-new-window works for350 // Activate the target output, since that's how Firefox drag-tab-into-new-window works for
348 // example. On successful drop, additionally activate the target window.351 // example. On successful drop, additionally activate the target window.
349 let mut activate_output = true;352 let mut activate_output = true;
src/input/mod.rsmodified+37 -0
@@ -32,6 +32,7 @@ use smithay::output::Output;
32 use smithay::utils::{Logical, Point, Rectangle, Transform, SERIAL_COUNTER};32 use smithay::utils::{Logical, Point, Rectangle, Transform, SERIAL_COUNTER};
33 use smithay::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitor;33 use smithay::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitor;
34 use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};34 use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};
35+use smithay::wayland::selection::data_device::DnDGrab;
35 use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};36 use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
36 use touch_move_grab::TouchMoveGrab;37 use touch_move_grab::TouchMoveGrab;
37 38
@@ -1888,6 +1889,18 @@ impl State {
1888 // Activate a new confinement if necessary.1889 // Activate a new confinement if necessary.
1889 self.niri.maybe_activate_pointer_constraint();1890 self.niri.maybe_activate_pointer_constraint();
1890 1891
1892+ // Inform the layout of an ongoing DnD operation.
1893+ let mut is_dnd_grab = false;
1894+ pointer.with_grab(|_, grab| {
1895+ is_dnd_grab = grab.as_any().downcast_ref::<DnDGrab<Self>>().is_some();
1896+ });
1897+ if is_dnd_grab {
1898+ if let Some((output, pos_within_output)) = self.niri.output_under(new_pos) {
1899+ let output = output.clone();
1900+ self.niri.layout.dnd_update(output, pos_within_output);
1901+ }
1902+ }
1903+
1891 // Redraw to update the cursor position.1904 // Redraw to update the cursor position.
1892 // FIXME: redraw only outputs overlapping the cursor.1905 // FIXME: redraw only outputs overlapping the cursor.
1893 self.niri.queue_redraw_all();1906 self.niri.queue_redraw_all();
@@ -1950,6 +1963,18 @@ impl State {
1950 // We moved the regular pointer, so show it now.1963 // We moved the regular pointer, so show it now.
1951 self.niri.tablet_cursor_location = None;1964 self.niri.tablet_cursor_location = None;
1952 1965
1966+ // Inform the layout of an ongoing DnD operation.
1967+ let mut is_dnd_grab = false;
1968+ pointer.with_grab(|_, grab| {
1969+ is_dnd_grab = grab.as_any().downcast_ref::<DnDGrab<Self>>().is_some();
1970+ });
1971+ if is_dnd_grab {
1972+ if let Some((output, pos_within_output)) = self.niri.output_under(pos) {
1973+ let output = output.clone();
1974+ self.niri.layout.dnd_update(output, pos_within_output);
1975+ }
1976+ }
1977+
1953 // Redraw to update the cursor position.1978 // Redraw to update the cursor position.
1954 // FIXME: redraw only outputs overlapping the cursor.1979 // FIXME: redraw only outputs overlapping the cursor.
1955 self.niri.queue_redraw_all();1980 self.niri.queue_redraw_all();
@@ -2912,6 +2937,18 @@ impl State {
2912 time: evt.time_msec(),2937 time: evt.time_msec(),
2913 },2938 },
2914 );2939 );
2940+
2941+ // Inform the layout of an ongoing DnD operation.
2942+ let mut is_dnd_grab = false;
2943+ handle.with_grab(|_, grab| {
2944+ is_dnd_grab = grab.as_any().downcast_ref::<DnDGrab<Self>>().is_some();
2945+ });
2946+ if is_dnd_grab {
2947+ if let Some((output, pos_within_output)) = self.niri.output_under(touch_location) {
2948+ let output = output.clone();
2949+ self.niri.layout.dnd_update(output, pos_within_output);
2950+ }
2951+ }
2915 }2952 }
2916 fn on_touch_frame<I: InputBackend>(&mut self, _evt: I::TouchFrameEvent) {2953 fn on_touch_frame<I: InputBackend>(&mut self, _evt: I::TouchFrameEvent) {
2917 let Some(handle) = self.niri.seat.get_touch() else {2954 let Some(handle) = self.niri.seat.get_touch() else {
src/layout/mod.rsmodified+78 -22
@@ -278,6 +278,8 @@ pub struct Layout<W: LayoutElement> {
278 last_active_workspace_id: HashMap<String, WorkspaceId>,278 last_active_workspace_id: HashMap<String, WorkspaceId>,
279 /// Ongoing interactive move.279 /// Ongoing interactive move.
280 interactive_move: Option<InteractiveMoveState<W>>,280 interactive_move: Option<InteractiveMoveState<W>>,
281+ /// Ongoing drag-and-drop operation.
282+ dnd: Option<DndData>,
281 /// Clock for driving animations.283 /// Clock for driving animations.
282 clock: Clock,284 clock: Clock,
283 /// Time that we last updated render elements for.285 /// Time that we last updated render elements for.
@@ -400,6 +402,14 @@ struct InteractiveMoveData<W: LayoutElement> {
400 pub(self) pointer_ratio_within_window: (f64, f64),402 pub(self) pointer_ratio_within_window: (f64, f64),
401 }403 }
402 404
405+#[derive(Debug)]
406+pub struct DndData {
407+ /// Output where the pointer is currently located.
408+ output: Output,
409+ /// Current pointer position within output.
410+ pointer_pos_within_output: Point<f64, Logical>,
411+}
412+
403 #[derive(Debug, Clone, Copy)]413 #[derive(Debug, Clone, Copy)]
404 pub struct InteractiveResizeData {414 pub struct InteractiveResizeData {
405 pub(self) edges: ResizeEdge,415 pub(self) edges: ResizeEdge,
@@ -600,6 +610,7 @@ impl<W: LayoutElement> Layout<W> {
600 is_active: true,610 is_active: true,
601 last_active_workspace_id: HashMap::new(),611 last_active_workspace_id: HashMap::new(),
602 interactive_move: None,612 interactive_move: None,
613+ dnd: None,
603 clock,614 clock,
604 update_render_elements_time: Duration::ZERO,615 update_render_elements_time: Duration::ZERO,
605 options: Rc::new(options),616 options: Rc::new(options),
@@ -622,6 +633,7 @@ impl<W: LayoutElement> Layout<W> {
622 is_active: true,633 is_active: true,
623 last_active_workspace_id: HashMap::new(),634 last_active_workspace_id: HashMap::new(),
624 interactive_move: None,635 interactive_move: None,
636+ dnd: None,
625 clock,637 clock,
626 update_render_elements_time: Duration::ZERO,638 update_render_elements_time: Duration::ZERO,
627 options: opts,639 options: opts,
@@ -2518,7 +2530,7 @@ impl<W: LayoutElement> Layout<W> {
2518 workspace.verify_invariants(move_win_id.as_ref());2530 workspace.verify_invariants(move_win_id.as_ref());
2519 2531
2520 let has_view_offset_gesture = workspace.scrolling().view_offset().is_gesture();2532 let has_view_offset_gesture = workspace.scrolling().view_offset().is_gesture();
2521- if self.interactive_move.is_some() {2533+ if self.dnd.is_some() || self.interactive_move.is_some() {
2522 // We'd like to check that all workspaces have the gesture here, furthermore we2534 // We'd like to check that all workspaces have the gesture here, furthermore we
2523 // want to check that they have the gesture only if the interactive move2535 // want to check that they have the gesture only if the interactive move
2524 // targets the scrolling layout. However, we cannot do that because we start2536 // targets the scrolling layout. However, we cannot do that because we start
@@ -2545,23 +2557,30 @@ impl<W: LayoutElement> Layout<W> {
2545 pub fn advance_animations(&mut self) {2557 pub fn advance_animations(&mut self) {
2546 let _span = tracy_client::span!("Layout::advance_animations");2558 let _span = tracy_client::span!("Layout::advance_animations");
2547 2559
2560+ let mut dnd_scroll = None;
2561+ if let Some(dnd) = &self.dnd {
2562+ dnd_scroll = Some((dnd.output.clone(), dnd.pointer_pos_within_output));
2563+ }
2564+
2548 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {2565 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2549 move_.tile.advance_animations();2566 move_.tile.advance_animations();
2550 2567
2551- // Scroll the view if needed.2568+ if !move_.is_floating && dnd_scroll.is_none() {
2552- if !move_.is_floating {2569+ dnd_scroll = Some((move_.output.clone(), move_.pointer_pos_within_output));
2553- let output = move_.output.clone();2570+ }
2554- let pos_within_output = move_.pointer_pos_within_output;2571+ }
2555- if let Some(mon) = self.monitor_for_output_mut(&output) {2572+
2556- if let Some((ws, offset)) = mon.workspace_under(pos_within_output) {2573+ // Scroll the view if needed.
2557- let ws_id = ws.id();2574+ if let Some((output, pos_within_output)) = dnd_scroll {
2558- let ws = mon2575+ if let Some(mon) = self.monitor_for_output_mut(&output) {
2559- .workspaces2576+ if let Some((ws, offset)) = mon.workspace_under(pos_within_output) {
2560- .iter_mut()2577+ let ws_id = ws.id();
2561- .find(|ws| ws.id() == ws_id)2578+ let ws = mon
2562- .unwrap();2579+ .workspaces
2563- ws.dnd_scroll_gesture_scroll(pos_within_output - offset);2580+ .iter_mut()
2564- }2581+ .find(|ws| ws.id() == ws_id)
2582+ .unwrap();
2583+ ws.dnd_scroll_gesture_scroll(pos_within_output - offset);
2565 }2584 }
2566 }2585 }
2567 }2586 }
@@ -2581,6 +2600,13 @@ impl<W: LayoutElement> Layout<W> {
2581 }2600 }
2582 2601
2583 pub fn are_animations_ongoing(&self, output: Option<&Output>) -> bool {2602 pub fn are_animations_ongoing(&self, output: Option<&Output>) -> bool {
2603+ // Keep advancing animations if we might need to scroll the view.
2604+ if let Some(dnd) = &self.dnd {
2605+ if output.map_or(true, |output| *output == dnd.output) {
2606+ return true;
2607+ }
2608+ }
2609+
2584 if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {2610 if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
2585 if output.map_or(true, |output| *output == move_.output) {2611 if output.map_or(true, |output| *output == move_.output) {
2586 if move_.tile.are_animations_ongoing() {2612 if move_.tile.are_animations_ongoing() {
@@ -3991,6 +4017,33 @@ impl<W: LayoutElement> Layout<W> {
3991 move_.output == *output4017 move_.output == *output
3992 }4018 }
3993 4019
4020+ pub fn dnd_update(&mut self, output: Output, pointer_pos_within_output: Point<f64, Logical>) {
4021+ let begin_gesture = self.dnd.is_none();
4022+
4023+ self.dnd = Some(DndData {
4024+ output,
4025+ pointer_pos_within_output,
4026+ });
4027+
4028+ if begin_gesture {
4029+ for ws in self.workspaces_mut() {
4030+ ws.dnd_scroll_gesture_begin();
4031+ }
4032+ }
4033+ }
4034+
4035+ pub fn dnd_end(&mut self) {
4036+ if self.dnd.is_none() {
4037+ return;
4038+ }
4039+
4040+ self.dnd = None;
4041+
4042+ for ws in self.workspaces_mut() {
4043+ ws.view_offset_gesture_end(false, None);
4044+ }
4045+ }
4046+
3994 pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool {4047 pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool {
3995 match &mut self.monitor_set {4048 match &mut self.monitor_set {
3996 MonitorSet::Normal { monitors, .. } => {4049 MonitorSet::Normal { monitors, .. } => {
@@ -4349,7 +4402,8 @@ impl<W: LayoutElement> Layout<W> {
4349 4402
4350 self.is_active = is_active;4403 self.is_active = is_active;
4351 4404
4352- let mut ongoing_scrolling_dnd = None;4405+ let mut ongoing_scrolling_dnd = self.dnd.is_some().then_some(true);
4406+
4353 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {4407 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
4354 let win = move_.tile.window_mut();4408 let win = move_.tile.window_mut();
4355 4409
@@ -4364,15 +4418,17 @@ impl<W: LayoutElement> Layout<W> {
4364 win.send_pending_configure();4418 win.send_pending_configure();
4365 win.refresh();4419 win.refresh();
4366 4420
4367- ongoing_scrolling_dnd = Some(!move_.is_floating);4421+ ongoing_scrolling_dnd.get_or_insert(!move_.is_floating);
4368 } else if let Some(InteractiveMoveState::Starting { window_id, .. }) =4422 } else if let Some(InteractiveMoveState::Starting { window_id, .. }) =
4369 &self.interactive_move4423 &self.interactive_move
4370 {4424 {
4371- let (_, _, ws) = self4425+ ongoing_scrolling_dnd.get_or_insert_with(|| {
4372- .workspaces()4426+ let (_, _, ws) = self
4373- .find(|(_, _, ws)| ws.has_window(window_id))4427+ .workspaces()
4374- .unwrap();4428+ .find(|(_, _, ws)| ws.has_window(window_id))
4375- ongoing_scrolling_dnd = Some(!ws.is_floating(window_id));4429+ .unwrap();
4430+ !ws.is_floating(window_id)
4431+ });
4376 }4432 }
4377 4433
4378 match &mut self.monitor_set {4434 match &mut self.monitor_set {
src/layout/tests.rsmodified+19 -0
@@ -589,6 +589,15 @@ enum Op {
589 #[proptest(strategy = "1..=5usize")]589 #[proptest(strategy = "1..=5usize")]
590 window: usize,590 window: usize,
591 },591 },
592+ DndUpdate {
593+ #[proptest(strategy = "1..=5usize")]
594+ output_idx: usize,
595+ #[proptest(strategy = "-20000f64..20000f64")]
596+ px: f64,
597+ #[proptest(strategy = "-20000f64..20000f64")]
598+ py: f64,
599+ },
600+ DndEnd,
592 InteractiveResizeBegin {601 InteractiveResizeBegin {
593 #[proptest(strategy = "1..=5usize")]602 #[proptest(strategy = "1..=5usize")]
594 window: usize,603 window: usize,
@@ -1353,6 +1362,16 @@ impl Op {
1353 Op::InteractiveMoveEnd { window } => {1362 Op::InteractiveMoveEnd { window } => {
1354 layout.interactive_move_end(&window);1363 layout.interactive_move_end(&window);
1355 }1364 }
1365+ Op::DndUpdate { output_idx, px, py } => {
1366+ let name = format!("output{output_idx}");
1367+ let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1368+ return;
1369+ };
1370+ layout.dnd_update(output, Point::from((px, py)));
1371+ }
1372+ Op::DndEnd => {
1373+ layout.dnd_end();
1374+ }
1356 Op::InteractiveResizeBegin { window, edges } => {1375 Op::InteractiveResizeBegin { window, edges } => {
1357 layout.interactive_resize_begin(window, edges);1376 layout.interactive_resize_begin(window, edges);
1358 }1377 }