Implement touch interactive resize
Browse files at this commitda3e5c44248fdb12b700e3a99c3e777c57942dc7Parent: 26ab4df4 changed files +168 -16
- src/handlers/xdg_shell.rs +44 -16
- src/input/mod.rs +1 -0
- src/input/touch_resize_grab.rs +119 -0
- src/layout/workspace.rs +4 -0
src/handlers/xdg_shell.rsmodified+44 -16
| @@ -39,6 +39,7 @@ use tracing::field::Empty; | ||
| 39 | 39 | use crate::input::move_grab::MoveGrab; |
| 40 | 40 | use crate::input::resize_grab::ResizeGrab; |
| 41 | 41 | use crate::input::touch_move_grab::TouchMoveGrab; |
| 42 | +use crate::input::touch_resize_grab::TouchResizeGrab; | |
| 42 | 43 | use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME}; |
| 43 | 44 | use crate::layout::workspace::ColumnWidth; |
| 44 | 45 | use crate::niri::{PopupGrabState, State}; |
| @@ -149,24 +150,39 @@ impl XdgShellHandler for State { | ||
| 149 | 150 | serial: Serial, |
| 150 | 151 | edges: xdg_toplevel::ResizeEdge, |
| 151 | 152 | ) { |
| 153 | + let wl_surface = surface.wl_surface(); | |
| 154 | + | |
| 155 | + let mut grab_start_data = None; | |
| 156 | + | |
| 157 | + // See if this comes from a pointer grab. | |
| 152 | 158 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 153 | - if !pointer.has_grab(serial) { | |
| 154 | - return; | |
| 159 | + if pointer.has_grab(serial) { | |
| 160 | + if let Some(start_data) = pointer.grab_start_data() { | |
| 161 | + if let Some((focus, _)) = &start_data.focus { | |
| 162 | + if focus.id().same_client_as(&wl_surface.id()) { | |
| 163 | + grab_start_data = Some(PointerOrTouchStartData::Pointer(start_data)); | |
| 164 | + } | |
| 165 | + } | |
| 166 | + } | |
| 155 | 167 | } |
| 156 | 168 | |
| 157 | - let Some(start_data) = pointer.grab_start_data() else { | |
| 158 | - return; | |
| 159 | - }; | |
| 169 | + // See if this comes from a touch grab. | |
| 170 | + if let Some(touch) = self.niri.seat.get_touch() { | |
| 171 | + if touch.has_grab(serial) { | |
| 172 | + if let Some(start_data) = touch.grab_start_data() { | |
| 173 | + if let Some((focus, _)) = &start_data.focus { | |
| 174 | + if focus.id().same_client_as(&wl_surface.id()) { | |
| 175 | + grab_start_data = Some(PointerOrTouchStartData::Touch(start_data)); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + } | |
| 179 | + } | |
| 180 | + } | |
| 160 | 181 | |
| 161 | - let Some((focus, _)) = &start_data.focus else { | |
| 182 | + let Some(start_data) = grab_start_data else { | |
| 162 | 183 | return; |
| 163 | 184 | }; |
| 164 | 185 | |
| 165 | - let wl_surface = surface.wl_surface(); | |
| 166 | - if !focus.id().same_client_as(&wl_surface.id()) { | |
| 167 | - return; | |
| 168 | - } | |
| 169 | - | |
| 170 | 186 | let Some((mapped, _)) = self.niri.layout.find_window_and_output(wl_surface) else { |
| 171 | 187 | return; |
| 172 | 188 | }; |
| @@ -201,14 +217,26 @@ impl XdgShellHandler for State { | ||
| 201 | 217 | } |
| 202 | 218 | } |
| 203 | 219 | |
| 204 | - let grab = ResizeGrab::new(start_data, window.clone()); | |
| 205 | - | |
| 206 | - if !self.niri.layout.interactive_resize_begin(window, edges) { | |
| 220 | + if !self | |
| 221 | + .niri | |
| 222 | + .layout | |
| 223 | + .interactive_resize_begin(window.clone(), edges) | |
| 224 | + { | |
| 207 | 225 | return; |
| 208 | 226 | } |
| 209 | 227 | |
| 210 | - pointer.set_grab(self, grab, serial, Focus::Clear); | |
| 211 | - self.niri.pointer_grab_ongoing = true; | |
| 228 | + match start_data { | |
| 229 | + PointerOrTouchStartData::Pointer(start_data) => { | |
| 230 | + let grab = ResizeGrab::new(start_data, window); | |
| 231 | + pointer.set_grab(self, grab, serial, Focus::Clear); | |
| 232 | + self.niri.pointer_grab_ongoing = true; | |
| 233 | + } | |
| 234 | + PointerOrTouchStartData::Touch(start_data) => { | |
| 235 | + let touch = self.niri.seat.get_touch().unwrap(); | |
| 236 | + let grab = TouchResizeGrab::new(start_data, window); | |
| 237 | + touch.set_grab(self, grab, serial); | |
| 238 | + } | |
| 239 | + } | |
| 212 | 240 | } |
| 213 | 241 | |
| 214 | 242 | fn reposition_request( |
src/input/mod.rsmodified+1 -0
| @@ -46,6 +46,7 @@ pub mod scroll_tracker; | ||
| 46 | 46 | pub mod spatial_movement_grab; |
| 47 | 47 | pub mod swipe_tracker; |
| 48 | 48 | pub mod touch_move_grab; |
| 49 | +pub mod touch_resize_grab; | |
| 49 | 50 | |
| 50 | 51 | pub const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(400); |
| 51 | 52 |
src/input/touch_resize_grab.rsadded+119 -0
| @@ -0,0 +1,119 @@ | ||
| 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 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 | + seq: Serial, | |
| 34 | + ) { | |
| 35 | + handle.down(data, None, event, seq); | |
| 36 | + } | |
| 37 | + | |
| 38 | + fn up( | |
| 39 | + &mut self, | |
| 40 | + data: &mut State, | |
| 41 | + handle: &mut TouchInnerHandle<'_, State>, | |
| 42 | + event: &UpEvent, | |
| 43 | + seq: Serial, | |
| 44 | + ) { | |
| 45 | + handle.up(data, event, seq); | |
| 46 | + | |
| 47 | + if event.slot != self.start_data.slot { | |
| 48 | + return; | |
| 49 | + } | |
| 50 | + | |
| 51 | + handle.unset_grab(self, data); | |
| 52 | + } | |
| 53 | + | |
| 54 | + fn motion( | |
| 55 | + &mut self, | |
| 56 | + data: &mut State, | |
| 57 | + handle: &mut TouchInnerHandle<'_, State>, | |
| 58 | + _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>, | |
| 59 | + event: &MotionEvent, | |
| 60 | + seq: Serial, | |
| 61 | + ) { | |
| 62 | + handle.motion(data, None, event, seq); | |
| 63 | + | |
| 64 | + if event.slot != self.start_data.slot { | |
| 65 | + return; | |
| 66 | + } | |
| 67 | + | |
| 68 | + if self.window.alive() { | |
| 69 | + let delta = event.location - self.start_data.location; | |
| 70 | + let ongoing = data | |
| 71 | + .niri | |
| 72 | + .layout | |
| 73 | + .interactive_resize_update(&self.window, delta); | |
| 74 | + if ongoing { | |
| 75 | + return; | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + // The resize is no longer ongoing. | |
| 80 | + handle.unset_grab(self, data); | |
| 81 | + } | |
| 82 | + | |
| 83 | + fn frame(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, seq: Serial) { | |
| 84 | + handle.frame(data, seq); | |
| 85 | + } | |
| 86 | + | |
| 87 | + fn cancel(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, seq: Serial) { | |
| 88 | + handle.cancel(data, seq); | |
| 89 | + handle.unset_grab(self, data); | |
| 90 | + } | |
| 91 | + | |
| 92 | + fn shape( | |
| 93 | + &mut self, | |
| 94 | + data: &mut State, | |
| 95 | + handle: &mut TouchInnerHandle<'_, State>, | |
| 96 | + event: &ShapeEvent, | |
| 97 | + seq: Serial, | |
| 98 | + ) { | |
| 99 | + handle.shape(data, event, seq); | |
| 100 | + } | |
| 101 | + | |
| 102 | + fn orientation( | |
| 103 | + &mut self, | |
| 104 | + data: &mut State, | |
| 105 | + handle: &mut TouchInnerHandle<'_, State>, | |
| 106 | + event: &OrientationEvent, | |
| 107 | + seq: Serial, | |
| 108 | + ) { | |
| 109 | + handle.orientation(data, event, seq); | |
| 110 | + } | |
| 111 | + | |
| 112 | + fn start_data(&self) -> &TouchGrabStartData<State> { | |
| 113 | + &self.start_data | |
| 114 | + } | |
| 115 | + | |
| 116 | + fn unset(&mut self, data: &mut State) { | |
| 117 | + self.on_ungrab(data); | |
| 118 | + } | |
| 119 | +} |
src/layout/workspace.rsmodified+4 -0
| @@ -2978,6 +2978,10 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 2978 | 2978 | } |
| 2979 | 2979 | |
| 2980 | 2980 | pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool { |
| 2981 | + if self.interactive_resize.is_some() { | |
| 2982 | + return false; | |
| 2983 | + } | |
| 2984 | + | |
| 2981 | 2985 | let col = self |
| 2982 | 2986 | .columns |
| 2983 | 2987 | .iter_mut() |