forge
Explore
Log in

Don't you dare go Hollow

Unify pointer & touch move grab, add view offset to it

Browse files at this commit

0cd8484bdce68fa3eae493dcb220abeb440ab5cdIvan MolodetskikhParent: 9d522ed
src/handlers/xdg_shell.rsmodified+9 -26
@@ -40,7 +40,6 @@ use tracing::field::Empty;
40 40
41 use crate::input::move_grab::MoveGrab;41 use crate::input::move_grab::MoveGrab;
42 use crate::input::resize_grab::ResizeGrab;42 use crate::input::resize_grab::ResizeGrab;
43-use crate::input::touch_move_grab::TouchMoveGrab;
44 use crate::input::touch_resize_grab::TouchResizeGrab;43 use crate::input::touch_resize_grab::TouchResizeGrab;
45 use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME};44 use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME};
46 use crate::layout::ActivateWindow;45 use crate::layout::ActivateWindow;
@@ -133,33 +132,17 @@ impl XdgShellHandler for State {
133 let window = mapped.window.clone();132 let window = mapped.window.clone();
134 let output = output.clone();133 let output = output.clone();
135 134
136- let output_pos = self135+ match &start_data {
137- .niri136+ PointerOrTouchStartData::Pointer(_) => {
138- .global_space137+ if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true) {
139- .output_geometry(&output)138+ pointer.set_grab(self, grab, serial, Focus::Clear);
140- .unwrap()139+ }
141- .loc
142- .to_f64();
143-
144- let pos_within_output = start_data.location() - output_pos;
145-
146- if !self
147- .niri
148- .layout
149- .interactive_move_begin(window.clone(), &output, pos_within_output)
150- {
151- return;
152- }
153-
154- match start_data {
155- PointerOrTouchStartData::Pointer(start_data) => {
156- let grab = MoveGrab::new(start_data, window, false);
157- pointer.set_grab(self, grab, serial, Focus::Clear);
158 }140 }
159- PointerOrTouchStartData::Touch(start_data) => {141+ PointerOrTouchStartData::Touch(_) => {
160 let touch = self.niri.seat.get_touch().unwrap();142 let touch = self.niri.seat.get_touch().unwrap();
161- let grab = TouchMoveGrab::new(start_data, window);143+ if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true) {
162- touch.set_grab(self, grab, serial);144+ touch.set_grab(self, grab, serial);
145+ }
163 }146 }
164 }147 }
165 148
src/input/mod.rsmodified+44 -37
@@ -36,7 +36,6 @@ use smithay::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitor;
36 use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};36 use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};
37 use smithay::wayland::selection::data_device::DnDGrab;37 use smithay::wayland::selection::data_device::DnDGrab;
38 use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};38 use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
39-use touch_move_grab::TouchMoveGrab;
40 use touch_overview_grab::TouchOverviewGrab;39 use touch_overview_grab::TouchOverviewGrab;
41 40
42 use self::move_grab::MoveGrab;41 use self::move_grab::MoveGrab;
@@ -59,7 +58,6 @@ pub mod scroll_swipe_gesture;
59 pub mod scroll_tracker;58 pub mod scroll_tracker;
60 pub mod spatial_movement_grab;59 pub mod spatial_movement_grab;
61 pub mod swipe_tracker;60 pub mod swipe_tracker;
62-pub mod touch_move_grab;
63 pub mod touch_overview_grab;61 pub mod touch_overview_grab;
64 pub mod touch_resize_grab;62 pub mod touch_resize_grab;
65 63
@@ -84,6 +82,28 @@ impl<D: SeatHandler> PointerOrTouchStartData<D> {
84 PointerOrTouchStartData::Touch(x) => x.location,82 PointerOrTouchStartData::Touch(x) => x.location,
85 }83 }
86 }84 }
85+
86+ pub fn unwrap_pointer(&self) -> &PointerGrabStartData<D> {
87+ match self {
88+ PointerOrTouchStartData::Pointer(x) => x,
89+ PointerOrTouchStartData::Touch(_) => panic!("start_data is not Pointer"),
90+ }
91+ }
92+
93+ pub fn unwrap_touch(&self) -> &TouchGrabStartData<D> {
94+ match self {
95+ PointerOrTouchStartData::Pointer(_) => panic!("start_data is not Touch"),
96+ PointerOrTouchStartData::Touch(x) => x,
97+ }
98+ }
99+
100+ pub fn is_pointer(&self) -> bool {
101+ matches!(self, Self::Pointer(_))
102+ }
103+
104+ pub fn is_touch(&self) -> bool {
105+ matches!(self, Self::Touch(_))
106+ }
87 }107 }
88 108
89 impl State {109 impl State {
@@ -2773,31 +2793,19 @@ impl State {
2773 let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());2793 let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());
2774 if is_overview_open || mod_down {2794 if is_overview_open || mod_down {
2775 let location = pointer.current_location();2795 let location = pointer.current_location();
2776- let (output, pos_within_output) = self.niri.output_under(location).unwrap();
2777- let output = output.clone();
2778 2796
2779 if !is_overview_open {2797 if !is_overview_open {
2780 self.niri.layout.activate_window(&window);2798 self.niri.layout.activate_window(&window);
2781 }2799 }
2782 2800
2783- if self.niri.layout.interactive_move_begin(2801+ let start_data = PointerGrabStartData {
2784- window.clone(),2802+ focus: None,
2785- &output,2803+ button: button_code,
2786- pos_within_output,2804+ location,
2787- ) {2805+ };
2788- let start_data = PointerGrabStartData {2806+ let start_data = PointerOrTouchStartData::Pointer(start_data);
2789- focus: None,2807+ if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), false) {
2790- button: button_code,
2791- location,
2792- };
2793- let grab = MoveGrab::new(start_data, window.clone(), is_overview_open);
2794 pointer.set_grab(self, grab, serial, Focus::Clear);2808 pointer.set_grab(self, grab, serial, Focus::Clear);
2795-
2796- if !is_overview_open {
2797- self.niri
2798- .cursor_manager
2799- .set_cursor_image(CursorImageStatus::Named(CursorIcon::Move));
2800- }
2801 }2809 }
2802 }2810 }
2803 }2811 }
@@ -4037,22 +4045,15 @@ impl State {
4037 } else if let Some((window, _)) = under.window {4045 } else if let Some((window, _)) = under.window {
4038 self.niri.layout.activate_window(&window);4046 self.niri.layout.activate_window(&window);
4039 4047
4040- // Check if we need to start an interactive move.4048+ // Check if we need to start a touch move grab.
4041 if mod_down {4049 if mod_down {
4042- let (output, pos_within_output) = self.niri.output_under(pos).unwrap();4050+ let start_data = TouchGrabStartData {
4043- let output = output.clone();4051+ focus: None,
4044-4052+ slot,
4045- if self.niri.layout.interactive_move_begin(4053+ location: pos,
4046- window.clone(),4054+ };
4047- &output,4055+ let start_data = PointerOrTouchStartData::Touch(start_data);
4048- pos_within_output,4056+ if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true) {
4049- ) {
4050- let start_data = TouchGrabStartData {
4051- focus: None,
4052- slot,
4053- location: pos,
4054- };
4055- let grab = TouchMoveGrab::new(start_data, window.clone());
4056 handle.set_grab(self, grab, serial);4057 handle.set_grab(self, grab, serial);
4057 }4058 }
4058 }4059 }
@@ -4908,13 +4909,19 @@ fn grab_allows_hot_corner(grab: &(dyn PointerGrab<State> + 'static)) -> bool {
4908 //4909 //
4909 // Some notable grabs not mentioned here:4910 // Some notable grabs not mentioned here:
4910 // - DnDGrab allows hot corner to DnD across workspaces.4911 // - DnDGrab allows hot corner to DnD across workspaces.
4911- // - MoveGrab allows hot corner to DnD across workspaces.
4912 // - ClickGrab keeps pointer focus on the window, so the hot corner doesn't trigger.4912 // - ClickGrab keeps pointer focus on the window, so the hot corner doesn't trigger.
4913 // - Touch grabs: touch doesn't trigger the hot corner.4913 // - Touch grabs: touch doesn't trigger the hot corner.
4914 if grab.is::<ResizeGrab>() || grab.is::<SpatialMovementGrab>() {4914 if grab.is::<ResizeGrab>() || grab.is::<SpatialMovementGrab>() {
4915 return false;4915 return false;
4916 }4916 }
4917 4917
4918+ if let Some(grab) = grab.downcast_ref::<MoveGrab>() {
4919+ // Window move allows hot corner to DnD across workspaces.
4920+ if !grab.is_move() {
4921+ return false;
4922+ }
4923+ }
4924+
4918 true4925 true
4919 }4926 }
4920 4927
src/input/move_grab.rsmodified+333 -59
@@ -1,3 +1,5 @@
1+use std::time::Duration;
2+
1 use smithay::backend::input::ButtonState;3 use smithay::backend::input::ButtonState;
2 use smithay::desktop::Window;4 use smithay::desktop::Window;
3 use smithay::input::pointer::{5 use smithay::input::pointer::{
@@ -7,107 +9,279 @@ use smithay::input::pointer::{
7 GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle,9 GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle,
8 RelativeMotionEvent,10 RelativeMotionEvent,
9 };11 };
12+use smithay::input::touch::{
13+ self, GrabStartData as TouchGrabStartData, TouchGrab, TouchInnerHandle,
14+};
10 use smithay::input::SeatHandler;15 use smithay::input::SeatHandler;
11-use smithay::utils::{IsAlive, Logical, Point};16+use smithay::output::Output;
17+use smithay::utils::{IsAlive, Logical, Point, Serial};
12 18
19+use crate::input::PointerOrTouchStartData;
13 use crate::niri::State;20 use crate::niri::State;
14 21
15 pub struct MoveGrab {22 pub struct MoveGrab {
16- start_data: PointerGrabStartData<State>,23+ start_data: PointerOrTouchStartData<State>,
24+ start_output: Output,
25+ start_pos_within_output: Point<f64, Logical>,
17 last_location: Point<f64, Logical>,26 last_location: Point<f64, Logical>,
18 window: Window,27 window: Window,
19 gesture: GestureState,28 gesture: GestureState,
29+ enable_view_offset: bool,
20 }30 }
21 31
22 #[derive(Debug, Clone, Copy, PartialEq, Eq)]32 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
23 enum GestureState {33 enum GestureState {
24 Recognizing,34 Recognizing,
25 Move,35 Move,
36+ ViewOffset,
26 }37 }
27 38
28 impl MoveGrab {39 impl MoveGrab {
29 pub fn new(40 pub fn new(
30- start_data: PointerGrabStartData<State>,41+ state: &mut State,
42+ start_data: PointerOrTouchStartData<State>,
31 window: Window,43 window: Window,
32- use_threshold: bool,44+ enable_view_offset: bool,
33- ) -> Self {45+ ) -> Option<Self> {
34- let gesture = if use_threshold {46+ let (output, pos_within_output) = state.niri.output_under(start_data.location())?;
35- GestureState::Recognizing
36- } else {
37- GestureState::Move
38- };
39 47
40- Self {48+ Some(Self {
41- last_location: start_data.location,49+ last_location: start_data.location(),
42 start_data,50 start_data,
51+ start_output: output.clone(),
52+ start_pos_within_output: pos_within_output,
43 window,53 window,
44- gesture,54+ gesture: GestureState::Recognizing,
45- }55+ enable_view_offset,
56+ })
46 }57 }
47 58
48- fn on_ungrab(&mut self, state: &mut State) {59+ pub fn is_move(&self) -> bool {
49- state.niri.layout.interactive_move_end(&self.window);60+ self.gesture == GestureState::Move
61+ }
62+
63+ fn on_ungrab(&mut self, data: &mut State) {
64+ let layout = &mut data.niri.layout;
65+ match self.gesture {
66+ GestureState::Recognizing => {
67+ // Activate the window on release. This is most prominent in the overview where
68+ // windows are not activated on click. In the overview, we also try to do a nice
69+ // synchronized workspace animation.
70+ if layout.is_overview_open() {
71+ let res = layout.workspaces().find_map(|(mon, ws_idx, ws)| {
72+ ws.windows()
73+ .any(|w| w.window == self.window)
74+ .then(|| (mon.map(|mon| mon.output().clone()), ws_idx))
75+ });
76+ if let Some((Some(output), ws_idx)) = res {
77+ layout.focus_output(&output);
78+ layout.toggle_overview_to_workspace(ws_idx);
79+ }
80+ }
81+
82+ layout.activate_window(&self.window);
83+ }
84+ GestureState::Move => layout.interactive_move_end(&self.window),
85+ GestureState::ViewOffset => {
86+ layout.view_offset_gesture_end(Some(false));
87+ }
88+ }
89+
90+ if self.start_data.is_pointer() {
91+ data.niri
92+ .cursor_manager
93+ .set_cursor_image(CursorImageStatus::default_named());
94+ }
95+
50 // FIXME: only redraw the window output.96 // FIXME: only redraw the window output.
51- state.niri.queue_redraw_all();97+ data.niri.queue_redraw_all();
52- state
53- .niri
54- .cursor_manager
55- .set_cursor_image(CursorImageStatus::default_named());
56 }98 }
57-}
58 99
59-impl PointerGrab<State> for MoveGrab {100+ fn begin_move(&mut self, data: &mut State) -> bool {
60- fn motion(101+ if !data.niri.layout.interactive_move_begin(
102+ self.window.clone(),
103+ &self.start_output,
104+ self.start_pos_within_output,
105+ ) {
106+ // Can no longer start the move.
107+ return false;
108+ }
109+
110+ self.gesture = GestureState::Move;
111+
112+ if self.start_data.is_pointer() {
113+ data.niri
114+ .cursor_manager
115+ .set_cursor_image(CursorImageStatus::Named(CursorIcon::Move));
116+ }
117+
118+ true
119+ }
120+
121+ fn begin_view_offset(&mut self, data: &mut State) -> bool {
122+ let layout = &mut data.niri.layout;
123+ let Some((output, ws_idx)) = layout.workspaces().find_map(|(mon, ws_idx, ws)| {
124+ let ws_idx = ws
125+ .windows()
126+ .any(|w| w.window == self.window)
127+ .then_some(ws_idx)?;
128+ let output = mon?.output().clone();
129+ Some((output, ws_idx))
130+ }) else {
131+ // Can no longer start the gesture.
132+ return false;
133+ };
134+
135+ layout.view_offset_gesture_begin(&output, Some(ws_idx), false);
136+
137+ self.gesture = GestureState::ViewOffset;
138+
139+ if self.start_data.is_pointer() {
140+ data.niri
141+ .cursor_manager
142+ .set_cursor_image(CursorImageStatus::Named(CursorIcon::AllScroll));
143+ }
144+
145+ true
146+ }
147+
148+ fn on_motion(
61 &mut self,149 &mut self,
62 data: &mut State,150 data: &mut State,
63- handle: &mut PointerInnerHandle<'_, State>,151+ location: Point<f64, Logical>,
64- _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,152+ timestamp: Duration,
65- event: &MotionEvent,153+ ) -> bool {
66- ) {154+ let mut delta = location - self.last_location;
67- // While the grab is active, no client has pointer focus.155+ self.last_location = location;
68- handle.motion(data, None, event);
69 156
70- if self.window.alive() {157+ // Try to recognize the gesture.
71- if let Some((output, pos_within_output)) = data.niri.output_under(event.location) {158+ if self.gesture == GestureState::Recognizing {
72- let output = output.clone();159+ // Check if the window has closed.
73- let event_delta = event.location - self.last_location;160+ if !self.window.alive() {
74- self.last_location = event.location;161+ return false;
162+ }
75 163
76- if self.gesture == GestureState::Recognizing {164+ // Check if the gesture moved far enough to decide.
77- let c = event.location - self.start_data.location;165+ let c = location - self.start_data.location();
166+ if c.x * c.x + c.y * c.y >= 8. * 8. {
167+ let is_floating = data
168+ .niri
169+ .layout
170+ .workspaces()
171+ .find_map(|(_, _, ws)| {
172+ ws.windows()
173+ .any(|w| w.window == self.window)
174+ .then(|| ws.is_floating(&self.window))
175+ })
176+ .unwrap_or(false);
78 177
79- // Check if the gesture moved far enough to decide.178+ let is_view_offset =
80- if c.x * c.x + c.y * c.y >= 8. * 8. {179+ self.enable_view_offset && !is_floating && c.x.abs() > c.y.abs();
81- self.gesture = GestureState::Move;
82 180
83- data.niri181+ let started = if is_view_offset {
84- .cursor_manager182+ self.begin_view_offset(data)
85- .set_cursor_image(CursorImageStatus::Named(CursorIcon::Move));183+ } else {
86- }184+ self.begin_move(data)
185+ };
186+ if !started {
187+ return false;
87 }188 }
88 189
89- if self.gesture != GestureState::Move {190+ // Apply the whole delta that accumulated during recognizing.
90- return;191+ delta = c;
91- }192+ }
193+ }
194+
195+ match self.gesture {
196+ GestureState::Recognizing => return true,
197+ GestureState::Move => {
198+ let Some((output, pos_within_output)) = data.niri.output_under(self.last_location)
199+ else {
200+ return true;
201+ };
202+ let output = output.clone();
92 203
93 let ongoing = data.niri.layout.interactive_move_update(204 let ongoing = data.niri.layout.interactive_move_update(
94 &self.window,205 &self.window,
95- event_delta,206+ delta,
96 output,207 output,
97 pos_within_output,208 pos_within_output,
98 );209 );
99 if ongoing {210 if ongoing {
100 // FIXME: only redraw the previous and the new output.211 // FIXME: only redraw the previous and the new output.
101 data.niri.queue_redraw_all();212 data.niri.queue_redraw_all();
102- return;213+ return true;
103 }214 }
104- } else {215+ }
105- return;216+ GestureState::ViewOffset => {
217+ let res = data
218+ .niri
219+ .layout
220+ .view_offset_gesture_update(-delta.x, timestamp, false);
221+ if let Some(output) = res {
222+ if let Some(output) = output {
223+ data.niri.queue_redraw(&output);
224+ }
225+ return true;
226+ }
227+ }
228+ }
229+
230+ false
231+ }
232+
233+ fn on_toggle_floating(&mut self, data: &mut State) -> bool {
234+ if self.gesture == GestureState::ViewOffset {
235+ return true;
236+ }
237+
238+ // Start move if still recognizing.
239+ if self.gesture == GestureState::Recognizing {
240+ let Some((output, pos_within_output)) = data.niri.output_under(self.last_location)
241+ else {
242+ return false;
243+ };
244+ let output = output.clone();
245+
246+ if !self.begin_move(data) {
247+ return false;
248+ }
249+
250+ // Apply the delta accumulated during recognizing.
251+ let ongoing = data.niri.layout.interactive_move_update(
252+ &self.window,
253+ self.last_location - self.start_data.location(),
254+ output,
255+ pos_within_output,
256+ );
257+ if !ongoing {
258+ return false;
106 }259 }
107 }260 }
108 261
109- // The move is no longer ongoing.262+ data.niri.layout.toggle_window_floating(Some(&self.window));
110- handle.unset_grab(self, data, event.serial, event.time, true);263+ data.niri.queue_redraw_all();
264+
265+ true
266+ }
267+}
268+
269+impl PointerGrab<State> for MoveGrab {
270+ fn motion(
271+ &mut self,
272+ data: &mut State,
273+ handle: &mut PointerInnerHandle<'_, State>,
274+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
275+ event: &MotionEvent,
276+ ) {
277+ // While the grab is active, no client has pointer focus.
278+ handle.motion(data, None, event);
279+
280+ let timestamp = Duration::from_millis(u64::from(event.time));
281+ if !self.on_motion(data, event.location, timestamp) {
282+ // The gesture is no longer ongoing.
283+ handle.unset_grab(self, data, event.serial, event.time, true);
284+ }
111 }285 }
112 286
113 fn relative_motion(287 fn relative_motion(
@@ -129,18 +303,25 @@ impl PointerGrab<State> for MoveGrab {
129 ) {303 ) {
130 handle.button(data, event);304 handle.button(data, event);
131 305
306+ let start_data = self.start_data.unwrap_pointer();
307+
308+ if !handle.current_pressed().contains(&start_data.button) {
309+ // The button that initiated the grab was released.
310+ handle.unset_grab(self, data, event.serial, event.time, true);
311+ return;
312+ }
313+
132 // When moving with the left button, right toggles floating, and vice versa.314 // When moving with the left button, right toggles floating, and vice versa.
133- let toggle_floating_button = if self.start_data.button == 0x110 {315+ let toggle_floating_button = if start_data.button == 0x110 {
134 0x111316 0x111
135 } else {317 } else {
136 0x110318 0x110
137 };319 };
138- if event.button == toggle_floating_button && event.state == ButtonState::Pressed {320+ if event.state != ButtonState::Pressed || event.button != toggle_floating_button {
139- data.niri.layout.toggle_window_floating(Some(&self.window));321+ return;
140 }322 }
141 323
142- if !handle.current_pressed().contains(&self.start_data.button) {324+ if !self.on_toggle_floating(data) {
143- // The button that initiated the grab was released.
144 handle.unset_grab(self, data, event.serial, event.time, true);325 handle.unset_grab(self, data, event.serial, event.time, true);
145 }326 }
146 }327 }
@@ -231,7 +412,100 @@ impl PointerGrab<State> for MoveGrab {
231 }412 }
232 413
233 fn start_data(&self) -> &PointerGrabStartData<State> {414 fn start_data(&self) -> &PointerGrabStartData<State> {
234- &self.start_data415+ self.start_data.unwrap_pointer()
416+ }
417+
418+ fn unset(&mut self, data: &mut State) {
419+ self.on_ungrab(data);
420+ }
421+}
422+
423+impl TouchGrab<State> for MoveGrab {
424+ fn down(
425+ &mut self,
426+ data: &mut State,
427+ handle: &mut TouchInnerHandle<'_, State>,
428+ _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>,
429+ event: &touch::DownEvent,
430+ seq: Serial,
431+ ) {
432+ handle.down(data, None, event, seq);
433+
434+ if event.slot == self.start_data.unwrap_touch().slot {
435+ return;
436+ }
437+
438+ if !self.on_toggle_floating(data) {
439+ handle.unset_grab(self, data);
440+ }
441+ }
442+
443+ fn up(
444+ &mut self,
445+ data: &mut State,
446+ handle: &mut TouchInnerHandle<'_, State>,
447+ event: &touch::UpEvent,
448+ seq: Serial,
449+ ) {
450+ handle.up(data, event, seq);
451+
452+ if event.slot == self.start_data.unwrap_touch().slot {
453+ handle.unset_grab(self, data);
454+ }
455+ }
456+
457+ fn motion(
458+ &mut self,
459+ data: &mut State,
460+ handle: &mut TouchInnerHandle<'_, State>,
461+ _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>,
462+ event: &touch::MotionEvent,
463+ seq: Serial,
464+ ) {
465+ handle.motion(data, None, event, seq);
466+
467+ if event.slot != self.start_data.unwrap_touch().slot {
468+ return;
469+ }
470+
471+ let timestamp = Duration::from_millis(u64::from(event.time));
472+ if !self.on_motion(data, event.location, timestamp) {
473+ // The gesture is no longer ongoing.
474+ handle.unset_grab(self, data);
475+ }
476+ }
477+
478+ fn frame(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, seq: Serial) {
479+ handle.frame(data, seq);
480+ }
481+
482+ fn cancel(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, seq: Serial) {
483+ handle.cancel(data, seq);
484+ handle.unset_grab(self, data);
485+ }
486+
487+ fn shape(
488+ &mut self,
489+ data: &mut State,
490+ handle: &mut TouchInnerHandle<'_, State>,
491+ event: &touch::ShapeEvent,
492+ seq: Serial,
493+ ) {
494+ handle.shape(data, event, seq);
495+ }
496+
497+ fn orientation(
498+ &mut self,
499+ data: &mut State,
500+ handle: &mut TouchInnerHandle<'_, State>,
501+ event: &touch::OrientationEvent,
502+ seq: Serial,
503+ ) {
504+ handle.orientation(data, event, seq);
505+ }
506+
507+ fn start_data(&self) -> &TouchGrabStartData<State> {
508+ self.start_data.unwrap_touch()
235 }509 }
236 510
237 fn unset(&mut self, data: &mut State) {511 fn unset(&mut self, data: &mut State) {
src/input/touch_move_grab.rsdeleted+0 -136
@@ -1,136 +0,0 @@
1-use smithay::desktop::Window;
2-use smithay::input::touch::{
3- DownEvent, GrabStartData as TouchGrabStartData, MotionEvent, OrientationEvent, ShapeEvent,
4- TouchGrab, TouchInnerHandle, UpEvent,
5-};
6-use smithay::input::SeatHandler;
7-use smithay::utils::{IsAlive, Logical, Point, Serial};
8-
9-use crate::niri::State;
10-
11-pub struct TouchMoveGrab {
12- start_data: TouchGrabStartData<State>,
13- last_location: Point<f64, Logical>,
14- window: Window,
15-}
16-
17-impl TouchMoveGrab {
18- pub fn new(start_data: TouchGrabStartData<State>, window: Window) -> Self {
19- Self {
20- last_location: start_data.location,
21- start_data,
22- window,
23- }
24- }
25-
26- fn on_ungrab(&mut self, state: &mut State) {
27- state.niri.layout.interactive_move_end(&self.window);
28- // FIXME: only redraw the window output.
29- state.niri.queue_redraw_all();
30- }
31-}
32-
33-impl TouchGrab<State> for TouchMoveGrab {
34- fn down(
35- &mut self,
36- data: &mut State,
37- handle: &mut TouchInnerHandle<'_, State>,
38- _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>,
39- event: &DownEvent,
40- seq: Serial,
41- ) {
42- handle.down(data, None, event, seq);
43- }
44-
45- fn up(
46- &mut self,
47- data: &mut State,
48- handle: &mut TouchInnerHandle<'_, State>,
49- event: &UpEvent,
50- seq: Serial,
51- ) {
52- handle.up(data, event, seq);
53-
54- if event.slot != self.start_data.slot {
55- return;
56- }
57-
58- handle.unset_grab(self, data);
59- }
60-
61- fn motion(
62- &mut self,
63- data: &mut State,
64- handle: &mut TouchInnerHandle<'_, State>,
65- _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>,
66- event: &MotionEvent,
67- seq: Serial,
68- ) {
69- handle.motion(data, None, event, seq);
70-
71- if event.slot != self.start_data.slot {
72- return;
73- }
74-
75- if self.window.alive() {
76- if let Some((output, pos_within_output)) = data.niri.output_under(event.location) {
77- let output = output.clone();
78- let event_delta = event.location - self.last_location;
79- self.last_location = event.location;
80- let ongoing = data.niri.layout.interactive_move_update(
81- &self.window,
82- event_delta,
83- output,
84- pos_within_output,
85- );
86- if ongoing {
87- // FIXME: only redraw the previous and the new output.
88- data.niri.queue_redraw_all();
89- return;
90- }
91- } else {
92- return;
93- }
94- }
95-
96- // The move is no longer ongoing.
97- handle.unset_grab(self, data);
98- }
99-
100- fn frame(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, seq: Serial) {
101- handle.frame(data, seq);
102- }
103-
104- fn cancel(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, seq: Serial) {
105- handle.cancel(data, seq);
106- handle.unset_grab(self, data);
107- }
108-
109- fn shape(
110- &mut self,
111- data: &mut State,
112- handle: &mut TouchInnerHandle<'_, State>,
113- event: &ShapeEvent,
114- seq: Serial,
115- ) {
116- handle.shape(data, event, seq);
117- }
118-
119- fn orientation(
120- &mut self,
121- data: &mut State,
122- handle: &mut TouchInnerHandle<'_, State>,
123- event: &OrientationEvent,
124- seq: Serial,
125- ) {
126- handle.orientation(data, event, seq);
127- }
128-
129- fn start_data(&self) -> &TouchGrabStartData<State> {
130- &self.start_data
131- }
132-
133- fn unset(&mut self, data: &mut State) {
134- self.on_ungrab(data);
135- }
136-}
src/layout/mod.rsmodified+0 -30
@@ -4040,16 +4040,12 @@ impl<W: LayoutElement> Layout<W> {
4040 mon.dnd_scroll_gesture_end();4040 mon.dnd_scroll_gesture_end();
4041 }4041 }
4042 4042
4043- let mut ws_id = None;
4044 for ws in self.workspaces_mut() {4043 for ws in self.workspaces_mut() {
4045- let id = ws.id();
4046 if let Some(tile) = ws.tiles_mut().find(|tile| *tile.window().id() == window_id)4044 if let Some(tile) = ws.tiles_mut().find(|tile| *tile.window().id() == window_id)
4047 {4045 {
4048 let offset = tile.interactive_move_offset;4046 let offset = tile.interactive_move_offset;
4049 tile.interactive_move_offset = Point::from((0., 0.));4047 tile.interactive_move_offset = Point::from((0., 0.));
4050 tile.animate_move_from(offset);4048 tile.animate_move_from(offset);
4051-
4052- ws_id = Some(id);
4053 }4049 }
4054 4050
4055 // Unlock the view on the workspaces, but if the moved window was active,4051 // Unlock the view on the workspaces, but if the moved window was active,
@@ -4064,32 +4060,6 @@ impl<W: LayoutElement> Layout<W> {
4064 }4060 }
4065 }4061 }
4066 4062
4067- // In the overview, we want to click on a window to focus it, and also to
4068- // click-and-drag to move the window. The way we handle this is by always starting
4069- // the interactive move (to get frozen view), then, when in the overview, *not*
4070- // calling interactive_move_update() until the cursor moves far enough. This means
4071- // that if we "just click" then we end up in this branch with state == Starting.
4072- // Close the overview in this case.
4073- if self.overview_open {
4074- let ws_id = ws_id.unwrap();
4075- if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
4076- for mon in monitors {
4077- if let Some(ws_idx) =
4078- mon.workspaces.iter().position(|ws| ws.id() == ws_id)
4079- {
4080- mon.activate_workspace_with_anim_config(
4081- ws_idx,
4082- Some(self.options.animations.overview_open_close.0),
4083- );
4084- break;
4085- }
4086- }
4087- }
4088-
4089- self.activate_window(&window_id);
4090- self.close_overview();
4091- }
4092-
4093 return;4063 return;
4094 }4064 }
4095 InteractiveMoveState::Moving(move_) => move_,4065 InteractiveMoveState::Moving(move_) => move_,