niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·f2ce84b·Yuya Nishihara·2 years ago·1130 commits
| 1 | use std::time::Duration; |
| 2 | |
| 3 | use smithay::input::pointer::{ |
| 4 | AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent, |
| 5 | GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, |
| 6 | GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, |
| 7 | MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, |
| 8 | }; |
| 9 | use smithay::input::SeatHandler; |
| 10 | use smithay::utils::{Logical, Point}; |
| 11 | |
| 12 | use crate::niri::State; |
| 13 | |
| 14 | pub struct ViewOffsetGrab { |
| 15 | start_data: PointerGrabStartData<State>, |
| 16 | last_location: Point<f64, Logical>, |
| 17 | } |
| 18 | |
| 19 | impl ViewOffsetGrab { |
| 20 | pub fn new(start_data: PointerGrabStartData<State>) -> Self { |
| 21 | Self { |
| 22 | last_location: start_data.location, |
| 23 | start_data, |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | fn on_ungrab(&mut self, state: &mut State) { |
| 28 | let res = state |
| 29 | .niri |
| 30 | .layout |
| 31 | .view_offset_gesture_end(false, Some(false)); |
| 32 | if let Some(output) = res { |
| 33 | state.niri.queue_redraw(&output); |
| 34 | } |
| 35 | |
| 36 | state.niri.pointer_grab_ongoing = false; |
| 37 | state |
| 38 | .niri |
| 39 | .cursor_manager |
| 40 | .set_cursor_image(CursorImageStatus::default_named()); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl PointerGrab<State> for ViewOffsetGrab { |
| 45 | fn motion( |
| 46 | &mut self, |
| 47 | data: &mut State, |
| 48 | handle: &mut PointerInnerHandle<'_, State>, |
| 49 | _focus: Option<(<State as SeatHandler>::PointerFocus, Point<i32, Logical>)>, |
| 50 | event: &MotionEvent, |
| 51 | ) { |
| 52 | // While the grab is active, no client has pointer focus. |
| 53 | handle.motion(data, None, event); |
| 54 | |
| 55 | let timestamp = Duration::from_millis(u64::from(event.time)); |
| 56 | let delta = event.location - self.last_location; |
| 57 | self.last_location = event.location; |
| 58 | |
| 59 | let res = data |
| 60 | .niri |
| 61 | .layout |
| 62 | .view_offset_gesture_update(-delta.x, timestamp, false); |
| 63 | if let Some(output) = res { |
| 64 | if let Some(output) = output { |
| 65 | data.niri.queue_redraw(&output); |
| 66 | } |
| 67 | } else { |
| 68 | // The resize is no longer ongoing. |
| 69 | handle.unset_grab(self, data, event.serial, event.time, true); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | fn relative_motion( |
| 74 | &mut self, |
| 75 | data: &mut State, |
| 76 | handle: &mut PointerInnerHandle<'_, State>, |
| 77 | _focus: Option<(<State as SeatHandler>::PointerFocus, Point<i32, Logical>)>, |
| 78 | event: &RelativeMotionEvent, |
| 79 | ) { |
| 80 | // While the grab is active, no client has pointer focus. |
| 81 | handle.relative_motion(data, None, event); |
| 82 | } |
| 83 | |
| 84 | fn button( |
| 85 | &mut self, |
| 86 | data: &mut State, |
| 87 | handle: &mut PointerInnerHandle<'_, State>, |
| 88 | event: &ButtonEvent, |
| 89 | ) { |
| 90 | handle.button(data, event); |
| 91 | |
| 92 | if handle.current_pressed().is_empty() { |
| 93 | // No more buttons are pressed, release the grab. |
| 94 | handle.unset_grab(self, data, event.serial, event.time, true); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | fn axis( |
| 99 | &mut self, |
| 100 | data: &mut State, |
| 101 | handle: &mut PointerInnerHandle<'_, State>, |
| 102 | details: AxisFrame, |
| 103 | ) { |
| 104 | handle.axis(data, details); |
| 105 | } |
| 106 | |
| 107 | fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) { |
| 108 | handle.frame(data); |
| 109 | } |
| 110 | |
| 111 | fn gesture_swipe_begin( |
| 112 | &mut self, |
| 113 | data: &mut State, |
| 114 | handle: &mut PointerInnerHandle<'_, State>, |
| 115 | event: &GestureSwipeBeginEvent, |
| 116 | ) { |
| 117 | handle.gesture_swipe_begin(data, event); |
| 118 | } |
| 119 | |
| 120 | fn gesture_swipe_update( |
| 121 | &mut self, |
| 122 | data: &mut State, |
| 123 | handle: &mut PointerInnerHandle<'_, State>, |
| 124 | event: &GestureSwipeUpdateEvent, |
| 125 | ) { |
| 126 | handle.gesture_swipe_update(data, event); |
| 127 | } |
| 128 | |
| 129 | fn gesture_swipe_end( |
| 130 | &mut self, |
| 131 | data: &mut State, |
| 132 | handle: &mut PointerInnerHandle<'_, State>, |
| 133 | event: &GestureSwipeEndEvent, |
| 134 | ) { |
| 135 | handle.gesture_swipe_end(data, event); |
| 136 | } |
| 137 | |
| 138 | fn gesture_pinch_begin( |
| 139 | &mut self, |
| 140 | data: &mut State, |
| 141 | handle: &mut PointerInnerHandle<'_, State>, |
| 142 | event: &GesturePinchBeginEvent, |
| 143 | ) { |
| 144 | handle.gesture_pinch_begin(data, event); |
| 145 | } |
| 146 | |
| 147 | fn gesture_pinch_update( |
| 148 | &mut self, |
| 149 | data: &mut State, |
| 150 | handle: &mut PointerInnerHandle<'_, State>, |
| 151 | event: &GesturePinchUpdateEvent, |
| 152 | ) { |
| 153 | handle.gesture_pinch_update(data, event); |
| 154 | } |
| 155 | |
| 156 | fn gesture_pinch_end( |
| 157 | &mut self, |
| 158 | data: &mut State, |
| 159 | handle: &mut PointerInnerHandle<'_, State>, |
| 160 | event: &GesturePinchEndEvent, |
| 161 | ) { |
| 162 | handle.gesture_pinch_end(data, event); |
| 163 | } |
| 164 | |
| 165 | fn gesture_hold_begin( |
| 166 | &mut self, |
| 167 | data: &mut State, |
| 168 | handle: &mut PointerInnerHandle<'_, State>, |
| 169 | event: &GestureHoldBeginEvent, |
| 170 | ) { |
| 171 | handle.gesture_hold_begin(data, event); |
| 172 | } |
| 173 | |
| 174 | fn gesture_hold_end( |
| 175 | &mut self, |
| 176 | data: &mut State, |
| 177 | handle: &mut PointerInnerHandle<'_, State>, |
| 178 | event: &GestureHoldEndEvent, |
| 179 | ) { |
| 180 | handle.gesture_hold_end(data, event); |
| 181 | } |
| 182 | |
| 183 | fn start_data(&self) -> &PointerGrabStartData<State> { |
| 184 | &self.start_data |
| 185 | } |
| 186 | |
| 187 | fn unset(&mut self, data: &mut State) { |
| 188 | self.on_ungrab(data); |
| 189 | } |
| 190 | } |