Merge TouchResizeGrab into ResizeGrab
Browse files at this commit88ea7faddb3e3f8f86d431af7edb682a7c3410f9Parent: c00c6be4 changed files +136 -136
- src/handlers/xdg_shell.rs +3 -4
- src/input/mod.rs +1 -1
- src/input/resize_grab.rs +132 -22
- src/input/touch_resize_grab.rs +0 -109
src/handlers/xdg_shell.rsmodified+3 -4
| @@ -36,7 +36,6 @@ use tracing::field::Empty; | |||
| 36 | 36 | ||
| 37 | use crate::input::move_grab::MoveGrab; | 37 | use crate::input::move_grab::MoveGrab; |
| 38 | use crate::input::resize_grab::ResizeGrab; | 38 | use crate::input::resize_grab::ResizeGrab; |
| 39 | -use crate::input::touch_resize_grab::TouchResizeGrab; | ||
| 40 | use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME}; | 39 | use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME}; |
| 41 | use crate::layout::ActivateWindow; | 40 | use crate::layout::ActivateWindow; |
| 42 | use crate::niri::{CastTarget, PopupGrabState, State}; | 41 | use crate::niri::{CastTarget, PopupGrabState, State}; |
| @@ -236,13 +235,13 @@ impl XdgShellHandler for State { | |||
| 236 | } | 235 | } |
| 237 | 236 | ||
| 238 | match start_data { | 237 | match start_data { |
| 239 | - PointerOrTouchStartData::Pointer(start_data) => { | 238 | + PointerOrTouchStartData::Pointer(_) => { |
| 240 | let grab = ResizeGrab::new(start_data, window); | 239 | let grab = ResizeGrab::new(start_data, window); |
| 241 | pointer.set_grab(self, grab, serial, Focus::Clear); | 240 | pointer.set_grab(self, grab, serial, Focus::Clear); |
| 242 | } | 241 | } |
| 243 | - PointerOrTouchStartData::Touch(start_data) => { | 242 | + PointerOrTouchStartData::Touch(_) => { |
| 244 | let touch = self.niri.seat.get_touch().unwrap(); | 243 | let touch = self.niri.seat.get_touch().unwrap(); |
| 245 | - let grab = TouchResizeGrab::new(start_data, window); | 244 | + let grab = ResizeGrab::new(start_data, window); |
| 246 | touch.set_grab(self, grab, serial); | 245 | touch.set_grab(self, grab, serial); |
| 247 | } | 246 | } |
| 248 | } | 247 | } |
src/input/mod.rsmodified+1 -1
| @@ -65,7 +65,6 @@ pub mod scroll_tracker; | |||
| 65 | pub mod spatial_movement_grab; | 65 | pub mod spatial_movement_grab; |
| 66 | pub mod swipe_tracker; | 66 | pub mod swipe_tracker; |
| 67 | pub mod touch_overview_grab; | 67 | pub mod touch_overview_grab; |
| 68 | -pub mod touch_resize_grab; | ||
| 69 | 68 | ||
| 70 | use backend_ext::{NiriInputBackend as InputBackend, NiriInputDevice as _}; | 69 | use backend_ext::{NiriInputBackend as InputBackend, NiriInputDevice as _}; |
| 71 | 70 | ||
| @@ -2993,6 +2992,7 @@ impl State { | |||
| 2993 | button: button_code, | 2992 | button: button_code, |
| 2994 | location, | 2993 | location, |
| 2995 | }; | 2994 | }; |
| 2995 | + let start_data = PointerOrTouchStartData::Pointer(start_data); | ||
| 2996 | let grab = ResizeGrab::new(start_data, window.clone()); | 2996 | let grab = ResizeGrab::new(start_data, window.clone()); |
| 2997 | pointer.set_grab(self, grab, serial, Focus::Clear); | 2997 | pointer.set_grab(self, grab, serial, Focus::Clear); |
| 2998 | self.niri | 2998 | self.niri |
src/input/resize_grab.rsmodified+132 -22
| @@ -5,27 +5,55 @@ use smithay::input::pointer::{ | |||
| 5 | GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, | 5 | GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, |
| 6 | MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, | 6 | MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, |
| 7 | }; | 7 | }; |
| 8 | +use smithay::input::touch::{ | ||
| 9 | + self, GrabStartData as TouchGrabStartData, TouchGrab, TouchInnerHandle, | ||
| 10 | +}; | ||
| 8 | use smithay::input::SeatHandler; | 11 | use smithay::input::SeatHandler; |
| 9 | -use smithay::utils::{IsAlive, Logical, Point}; | 12 | +use smithay::utils::{IsAlive, Logical, Point, SERIAL_COUNTER}; |
| 10 | 13 | ||
| 14 | +use crate::input::PointerOrTouchStartData; | ||
| 11 | use crate::niri::State; | 15 | use crate::niri::State; |
| 16 | +use crate::utils::get_monotonic_time; | ||
| 12 | 17 | ||
| 13 | pub struct ResizeGrab { | 18 | pub struct ResizeGrab { |
| 14 | - start_data: PointerGrabStartData<State>, | 19 | + start_data: PointerOrTouchStartData<State>, |
| 15 | window: Window, | 20 | window: Window, |
| 21 | + | ||
| 22 | + // Accumulated and applied in frame(). | ||
| 23 | + new_location: Point<f64, Logical>, | ||
| 16 | } | 24 | } |
| 17 | 25 | ||
| 18 | impl ResizeGrab { | 26 | impl ResizeGrab { |
| 19 | - pub fn new(start_data: PointerGrabStartData<State>, window: Window) -> Self { | 27 | + pub fn new(start_data: PointerOrTouchStartData<State>, window: Window) -> Self { |
| 20 | - Self { start_data, window } | 28 | + let location = start_data.location(); |
| 29 | + | ||
| 30 | + Self { | ||
| 31 | + start_data, | ||
| 32 | + window, | ||
| 33 | + new_location: location, | ||
| 34 | + } | ||
| 21 | } | 35 | } |
| 22 | 36 | ||
| 23 | fn on_ungrab(&mut self, state: &mut State) { | 37 | fn on_ungrab(&mut self, state: &mut State) { |
| 24 | state.niri.layout.interactive_resize_end(&self.window); | 38 | state.niri.layout.interactive_resize_end(&self.window); |
| 25 | - state | 39 | + |
| 26 | - .niri | 40 | + if !self.start_data.is_touch() { |
| 27 | - .cursor_manager | 41 | + state |
| 28 | - .set_cursor_image(CursorImageStatus::default_named()); | 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) | ||
| 29 | } | 57 | } |
| 30 | } | 58 | } |
| 31 | 59 | ||
| @@ -40,19 +68,7 @@ impl PointerGrab<State> for ResizeGrab { | |||
| 40 | // While the grab is active, no client has pointer focus. | 68 | // While the grab is active, no client has pointer focus. |
| 41 | handle.motion(data, None, event); | 69 | handle.motion(data, None, event); |
| 42 | 70 | ||
| 43 | - if self.window.alive() { | 71 | + self.new_location = event.location; |
| 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); | ||
| 56 | } | 72 | } |
| 57 | 73 | ||
| 58 | fn relative_motion( | 74 | fn relative_motion( |
| @@ -91,6 +107,17 @@ impl PointerGrab<State> for ResizeGrab { | |||
| 91 | 107 | ||
| 92 | fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) { | 108 | fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) { |
| 93 | handle.frame(data); | 109 | 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 | + } | ||
| 94 | } | 121 | } |
| 95 | 122 | ||
| 96 | fn gesture_swipe_begin( | 123 | fn gesture_swipe_begin( |
| @@ -166,7 +193,90 @@ impl PointerGrab<State> for ResizeGrab { | |||
| 166 | } | 193 | } |
| 167 | 194 | ||
| 168 | fn start_data(&self) -> &PointerGrabStartData<State> { | 195 | 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() | ||
| 170 | } | 280 | } |
| 171 | 281 | ||
| 172 | fn unset(&mut self, data: &mut State) { | 282 | 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 | -} | ||