forge
Explore
Log in

Don't you dare go Hollow

Merge TouchResizeGrab into ResizeGrab

Browse files at this commit

88ea7faddb3e3f8f86d431af7edb682a7c3410f9Ivan MolodetskikhParent: c00c6be
Follow the MoveGrab pattern.
src/handlers/xdg_shell.rsmodified+3 -4
@@ -36,7 +36,6 @@ use tracing::field::Empty;
3636
3737 use crate::input::move_grab::MoveGrab;
3838 use crate::input::resize_grab::ResizeGrab;
39-use crate::input::touch_resize_grab::TouchResizeGrab;
4039 use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME};
4140 use crate::layout::ActivateWindow;
4241 use crate::niri::{CastTarget, PopupGrabState, State};
@@ -236,13 +235,13 @@ impl XdgShellHandler for State {
236235 }
237236
238237 match start_data {
239- PointerOrTouchStartData::Pointer(start_data) => {
238+ PointerOrTouchStartData::Pointer(_) => {
240239 let grab = ResizeGrab::new(start_data, window);
241240 pointer.set_grab(self, grab, serial, Focus::Clear);
242241 }
243- PointerOrTouchStartData::Touch(start_data) => {
242+ PointerOrTouchStartData::Touch(_) => {
244243 let touch = self.niri.seat.get_touch().unwrap();
245- let grab = TouchResizeGrab::new(start_data, window);
244+ let grab = ResizeGrab::new(start_data, window);
246245 touch.set_grab(self, grab, serial);
247246 }
248247 }
src/input/mod.rsmodified+1 -1
@@ -65,7 +65,6 @@ pub mod scroll_tracker;
6565 pub mod spatial_movement_grab;
6666 pub mod swipe_tracker;
6767 pub mod touch_overview_grab;
68-pub mod touch_resize_grab;
6968
7069 use backend_ext::{NiriInputBackend as InputBackend, NiriInputDevice as _};
7170
@@ -2993,6 +2992,7 @@ impl State {
29932992 button: button_code,
29942993 location,
29952994 };
2995+ let start_data = PointerOrTouchStartData::Pointer(start_data);
29962996 let grab = ResizeGrab::new(start_data, window.clone());
29972997 pointer.set_grab(self, grab, serial, Focus::Clear);
29982998 self.niri
src/input/resize_grab.rsmodified+132 -22
@@ -5,27 +5,55 @@ use smithay::input::pointer::{
55 GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData,
66 MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent,
77 };
8+use smithay::input::touch::{
9+ self, GrabStartData as TouchGrabStartData, TouchGrab, TouchInnerHandle,
10+};
811 use smithay::input::SeatHandler;
9-use smithay::utils::{IsAlive, Logical, Point};
12+use smithay::utils::{IsAlive, Logical, Point, SERIAL_COUNTER};
1013
14+use crate::input::PointerOrTouchStartData;
1115 use crate::niri::State;
16+use crate::utils::get_monotonic_time;
1217
1318 pub struct ResizeGrab {
14- start_data: PointerGrabStartData<State>,
19+ start_data: PointerOrTouchStartData<State>,
1520 window: Window,
21+
22+ // Accumulated and applied in frame().
23+ new_location: Point<f64, Logical>,
1624 }
1725
1826 impl ResizeGrab {
19- pub fn new(start_data: PointerGrabStartData<State>, window: Window) -> Self {
20- Self { start_data, window }
27+ pub fn new(start_data: PointerOrTouchStartData<State>, window: Window) -> Self {
28+ let location = start_data.location();
29+
30+ Self {
31+ start_data,
32+ window,
33+ new_location: location,
34+ }
2135 }
2236
2337 fn on_ungrab(&mut self, state: &mut State) {
2438 state.niri.layout.interactive_resize_end(&self.window);
25- state
26- .niri
27- .cursor_manager
28- .set_cursor_image(CursorImageStatus::default_named());
39+
40+ if !self.start_data.is_touch() {
41+ state
42+ .niri
43+ .cursor_manager
44+ .set_cursor_image(CursorImageStatus::default_named());
45+ }
46+ }
47+
48+ fn on_frame(&mut self, data: &mut State) -> bool {
49+ if !self.window.alive() {
50+ return false;
51+ }
52+
53+ let delta = self.new_location - self.start_data.location();
54+ data.niri
55+ .layout
56+ .interactive_resize_update(&self.window, delta)
2957 }
3058 }
3159
@@ -40,19 +68,7 @@ impl PointerGrab<State> for ResizeGrab {
4068 // While the grab is active, no client has pointer focus.
4169 handle.motion(data, None, event);
4270
43- if self.window.alive() {
44- let delta = event.location - self.start_data.location;
45- let ongoing = data
46- .niri
47- .layout
48- .interactive_resize_update(&self.window, delta);
49- if ongoing {
50- return;
51- }
52- }
53-
54- // The resize is no longer ongoing.
55- handle.unset_grab(self, data, event.serial, event.time, true);
71+ self.new_location = event.location;
5672 }
5773
5874 fn relative_motion(
@@ -91,6 +107,17 @@ impl PointerGrab<State> for ResizeGrab {
91107
92108 fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) {
93109 handle.frame(data);
110+
111+ if !self.on_frame(data) {
112+ // The gesture is no longer ongoing.
113+ handle.unset_grab(
114+ self,
115+ data,
116+ SERIAL_COUNTER.next_serial(),
117+ get_monotonic_time().as_millis() as u32,
118+ true,
119+ );
120+ }
94121 }
95122
96123 fn gesture_swipe_begin(
@@ -166,7 +193,90 @@ impl PointerGrab<State> for ResizeGrab {
166193 }
167194
168195 fn start_data(&self) -> &PointerGrabStartData<State> {
169- &self.start_data
196+ self.start_data.unwrap_pointer()
197+ }
198+
199+ fn unset(&mut self, data: &mut State) {
200+ self.on_ungrab(data);
201+ }
202+}
203+
204+impl TouchGrab<State> for ResizeGrab {
205+ fn down(
206+ &mut self,
207+ data: &mut State,
208+ handle: &mut TouchInnerHandle<'_, State>,
209+ _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>,
210+ event: &touch::DownEvent,
211+ ) {
212+ handle.down(data, None, event);
213+ }
214+
215+ fn up(
216+ &mut self,
217+ data: &mut State,
218+ handle: &mut TouchInnerHandle<'_, State>,
219+ event: &touch::UpEvent,
220+ ) {
221+ handle.up(data, event);
222+
223+ if event.slot != self.start_data.unwrap_touch().slot {
224+ return;
225+ }
226+
227+ handle.unset_grab(self, data);
228+ }
229+
230+ fn motion(
231+ &mut self,
232+ data: &mut State,
233+ handle: &mut TouchInnerHandle<'_, State>,
234+ _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>,
235+ event: &touch::MotionEvent,
236+ ) {
237+ handle.motion(data, None, event);
238+
239+ if event.slot != self.start_data.unwrap_touch().slot {
240+ return;
241+ }
242+
243+ self.new_location = event.location;
244+ }
245+
246+ fn frame(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>) {
247+ handle.frame(data);
248+
249+ if !self.on_frame(data) {
250+ // The gesture is no longer ongoing.
251+ handle.unset_grab(self, data);
252+ }
253+ }
254+
255+ fn cancel(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>) {
256+ handle.cancel(data);
257+ handle.unset_grab(self, data);
258+ }
259+
260+ fn shape(
261+ &mut self,
262+ data: &mut State,
263+ handle: &mut TouchInnerHandle<'_, State>,
264+ event: &touch::ShapeEvent,
265+ ) {
266+ handle.shape(data, event);
267+ }
268+
269+ fn orientation(
270+ &mut self,
271+ data: &mut State,
272+ handle: &mut TouchInnerHandle<'_, State>,
273+ event: &touch::OrientationEvent,
274+ ) {
275+ handle.orientation(data, event);
276+ }
277+
278+ fn start_data(&self) -> &TouchGrabStartData<State> {
279+ self.start_data.unwrap_touch()
170280 }
171281
172282 fn unset(&mut self, data: &mut State) {
src/input/touch_resize_grab.rsdeleted+0 -109
@@ -1,109 +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};
8-
9-use crate::niri::State;
10-
11-pub struct TouchResizeGrab {
12- start_data: TouchGrabStartData<State>,
13- window: Window,
14-}
15-
16-impl TouchResizeGrab {
17- pub fn new(start_data: TouchGrabStartData<State>, window: Window) -> Self {
18- Self { start_data, window }
19- }
20-
21- fn on_ungrab(&mut self, state: &mut State) {
22- state.niri.layout.interactive_resize_end(&self.window);
23- }
24-}
25-
26-impl TouchGrab<State> for TouchResizeGrab {
27- fn down(
28- &mut self,
29- data: &mut State,
30- handle: &mut TouchInnerHandle<'_, State>,
31- _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>,
32- event: &DownEvent,
33- ) {
34- handle.down(data, None, event);
35- }
36-
37- fn up(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, event: &UpEvent) {
38- handle.up(data, event);
39-
40- if event.slot != self.start_data.slot {
41- return;
42- }
43-
44- handle.unset_grab(self, data);
45- }
46-
47- fn motion(
48- &mut self,
49- data: &mut State,
50- handle: &mut TouchInnerHandle<'_, State>,
51- _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>,
52- event: &MotionEvent,
53- ) {
54- handle.motion(data, None, event);
55-
56- if event.slot != self.start_data.slot {
57- return;
58- }
59-
60- if self.window.alive() {
61- let delta = event.location - self.start_data.location;
62- let ongoing = data
63- .niri
64- .layout
65- .interactive_resize_update(&self.window, delta);
66- if ongoing {
67- return;
68- }
69- }
70-
71- // The resize is no longer ongoing.
72- handle.unset_grab(self, data);
73- }
74-
75- fn frame(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>) {
76- handle.frame(data);
77- }
78-
79- fn cancel(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>) {
80- handle.cancel(data);
81- handle.unset_grab(self, data);
82- }
83-
84- fn shape(
85- &mut self,
86- data: &mut State,
87- handle: &mut TouchInnerHandle<'_, State>,
88- event: &ShapeEvent,
89- ) {
90- handle.shape(data, event);
91- }
92-
93- fn orientation(
94- &mut self,
95- data: &mut State,
96- handle: &mut TouchInnerHandle<'_, State>,
97- event: &OrientationEvent,
98- ) {
99- handle.orientation(data, event);
100- }
101-
102- fn start_data(&self) -> &TouchGrabStartData<State> {
103- &self.start_data
104- }
105-
106- fn unset(&mut self, data: &mut State) {
107- self.on_ungrab(data);
108- }
109-}