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