niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·055a94d·Ivan Molodetskikh·1 year ago·2247 commits
| 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 | } |