niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·9ff2f83·Ivan Molodetskikh·1 year ago·2099 commits
| 1 | use smithay::backend::input::ButtonState; |
| 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::{Logical, Point}; |
| 10 | |
| 11 | use crate::niri::State; |
| 12 | use crate::window::Mapped; |
| 13 | |
| 14 | pub struct PickWindowGrab { |
| 15 | start_data: PointerGrabStartData<State>, |
| 16 | } |
| 17 | |
| 18 | impl PickWindowGrab { |
| 19 | pub fn new(start_data: PointerGrabStartData<State>) -> Self { |
| 20 | Self { start_data } |
| 21 | } |
| 22 | |
| 23 | fn on_ungrab(&mut self, state: &mut State) { |
| 24 | if let Some(tx) = state.niri.pick_window.take() { |
| 25 | let _ = tx.send_blocking(None); |
| 26 | } |
| 27 | state |
| 28 | .niri |
| 29 | .cursor_manager |
| 30 | .set_cursor_image(CursorImageStatus::default_named()); |
| 31 | // Redraw to update the cursor. |
| 32 | state.niri.queue_redraw_all(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | impl PointerGrab<State> for PickWindowGrab { |
| 37 | fn motion( |
| 38 | &mut self, |
| 39 | data: &mut State, |
| 40 | handle: &mut PointerInnerHandle<'_, State>, |
| 41 | _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>, |
| 42 | event: &MotionEvent, |
| 43 | ) { |
| 44 | handle.motion(data, None, event); |
| 45 | } |
| 46 | |
| 47 | fn relative_motion( |
| 48 | &mut self, |
| 49 | data: &mut State, |
| 50 | handle: &mut PointerInnerHandle<'_, State>, |
| 51 | _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>, |
| 52 | event: &RelativeMotionEvent, |
| 53 | ) { |
| 54 | handle.relative_motion(data, None, event); |
| 55 | } |
| 56 | |
| 57 | fn button( |
| 58 | &mut self, |
| 59 | data: &mut State, |
| 60 | handle: &mut PointerInnerHandle<'_, State>, |
| 61 | event: &ButtonEvent, |
| 62 | ) { |
| 63 | if event.state != ButtonState::Pressed { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | // We're handling this press, don't send the release to the window. |
| 68 | data.niri.suppressed_buttons.insert(event.button); |
| 69 | |
| 70 | if let Some(tx) = data.niri.pick_window.take() { |
| 71 | let _ = tx.send_blocking( |
| 72 | data.niri |
| 73 | .window_under(handle.current_location()) |
| 74 | .map(Mapped::id), |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | handle.unset_grab(self, data, event.serial, event.time, true); |
| 79 | } |
| 80 | |
| 81 | fn axis( |
| 82 | &mut self, |
| 83 | data: &mut State, |
| 84 | handle: &mut PointerInnerHandle<'_, State>, |
| 85 | details: AxisFrame, |
| 86 | ) { |
| 87 | handle.axis(data, details); |
| 88 | } |
| 89 | |
| 90 | fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) { |
| 91 | handle.frame(data); |
| 92 | } |
| 93 | |
| 94 | fn gesture_swipe_begin( |
| 95 | &mut self, |
| 96 | data: &mut State, |
| 97 | handle: &mut PointerInnerHandle<'_, State>, |
| 98 | event: &GestureSwipeBeginEvent, |
| 99 | ) { |
| 100 | handle.gesture_swipe_begin(data, event); |
| 101 | } |
| 102 | |
| 103 | fn gesture_swipe_update( |
| 104 | &mut self, |
| 105 | data: &mut State, |
| 106 | handle: &mut PointerInnerHandle<'_, State>, |
| 107 | event: &GestureSwipeUpdateEvent, |
| 108 | ) { |
| 109 | handle.gesture_swipe_update(data, event); |
| 110 | } |
| 111 | |
| 112 | fn gesture_swipe_end( |
| 113 | &mut self, |
| 114 | data: &mut State, |
| 115 | handle: &mut PointerInnerHandle<'_, State>, |
| 116 | event: &GestureSwipeEndEvent, |
| 117 | ) { |
| 118 | handle.gesture_swipe_end(data, event); |
| 119 | } |
| 120 | |
| 121 | fn gesture_pinch_begin( |
| 122 | &mut self, |
| 123 | data: &mut State, |
| 124 | handle: &mut PointerInnerHandle<'_, State>, |
| 125 | event: &GesturePinchBeginEvent, |
| 126 | ) { |
| 127 | handle.gesture_pinch_begin(data, event); |
| 128 | } |
| 129 | |
| 130 | fn gesture_pinch_update( |
| 131 | &mut self, |
| 132 | data: &mut State, |
| 133 | handle: &mut PointerInnerHandle<'_, State>, |
| 134 | event: &GesturePinchUpdateEvent, |
| 135 | ) { |
| 136 | handle.gesture_pinch_update(data, event); |
| 137 | } |
| 138 | |
| 139 | fn gesture_pinch_end( |
| 140 | &mut self, |
| 141 | data: &mut State, |
| 142 | handle: &mut PointerInnerHandle<'_, State>, |
| 143 | event: &GesturePinchEndEvent, |
| 144 | ) { |
| 145 | handle.gesture_pinch_end(data, event); |
| 146 | } |
| 147 | |
| 148 | fn gesture_hold_begin( |
| 149 | &mut self, |
| 150 | data: &mut State, |
| 151 | handle: &mut PointerInnerHandle<'_, State>, |
| 152 | event: &GestureHoldBeginEvent, |
| 153 | ) { |
| 154 | handle.gesture_hold_begin(data, event); |
| 155 | } |
| 156 | |
| 157 | fn gesture_hold_end( |
| 158 | &mut self, |
| 159 | data: &mut State, |
| 160 | handle: &mut PointerInnerHandle<'_, State>, |
| 161 | event: &GestureHoldEndEvent, |
| 162 | ) { |
| 163 | handle.gesture_hold_end(data, event); |
| 164 | } |
| 165 | |
| 166 | fn start_data(&self) -> &PointerGrabStartData<State> { |
| 167 | &self.start_data |
| 168 | } |
| 169 | |
| 170 | fn unset(&mut self, data: &mut State) { |
| 171 | self.on_ungrab(data); |
| 172 | } |
| 173 | } |