Bring back old ClickGrab location-preserving behavior
Browse files at this commitc00c6bed7db49354d0efe2e2cc6134472332c4c1Parent: d6550bf3 changed files +161 -1
- src/handlers/mod.rs +9 -1
- src/input/click_grab.rs +151 -0
- src/input/mod.rs +1 -0
src/handlers/mod.rsmodified+9 -1
| @@ -15,7 +15,7 @@ use smithay::backend::drm::DrmNode; | |||
| 15 | use smithay::backend::input::{InputEvent, TabletToolDescriptor}; | 15 | use smithay::backend::input::{InputEvent, TabletToolDescriptor}; |
| 16 | use smithay::desktop::{PopupKind, PopupManager}; | 16 | use smithay::desktop::{PopupKind, PopupManager}; |
| 17 | use smithay::input::dnd::{self, DnDGrab, DndGrabHandler, DndTarget}; | 17 | use smithay::input::dnd::{self, DnDGrab, DndGrabHandler, DndTarget}; |
| 18 | -use smithay::input::pointer::{CursorIcon, CursorImageStatus, Focus, PointerHandle}; | 18 | +use smithay::input::pointer::{self, CursorIcon, CursorImageStatus, Focus, PointerHandle}; |
| 19 | use smithay::input::tablet::TabletSeatHandler; | 19 | use smithay::input::tablet::TabletSeatHandler; |
| 20 | use smithay::input::{keyboard, Seat, SeatHandler, SeatState}; | 20 | use smithay::input::{keyboard, Seat, SeatHandler, SeatState}; |
| 21 | use smithay::output::Output; | 21 | use smithay::output::Output; |
| @@ -65,6 +65,7 @@ use smithay::wayland::xdg_activation::{ | |||
| 65 | }; | 65 | }; |
| 66 | 66 | ||
| 67 | pub use crate::handlers::xdg_shell::KdeDecorationsModeState; | 67 | pub use crate::handlers::xdg_shell::KdeDecorationsModeState; |
| 68 | +use crate::input::click_grab::ClickGrab; | ||
| 68 | use crate::layout::workspace::WorkspaceId; | 69 | use crate::layout::workspace::WorkspaceId; |
| 69 | use crate::layout::ActivateWindow; | 70 | use crate::layout::ActivateWindow; |
| 70 | use crate::niri::{DndIcon, NewClient, State}; | 71 | use crate::niri::{DndIcon, NewClient, State}; |
| @@ -124,6 +125,13 @@ impl SeatHandler for State { | |||
| 124 | keyboard.led_update(led_state.into()); | 125 | keyboard.led_update(led_state.into()); |
| 125 | } | 126 | } |
| 126 | } | 127 | } |
| 128 | + | ||
| 129 | + fn click_grab( | ||
| 130 | + &mut self, | ||
| 131 | + start_data: pointer::GrabStartData<Self>, | ||
| 132 | + ) -> impl pointer::PointerGrab<Self> { | ||
| 133 | + ClickGrab::new(start_data) | ||
| 134 | + } | ||
| 127 | } | 135 | } |
| 128 | 136 | ||
| 129 | impl TabletSeatHandler for State { | 137 | impl TabletSeatHandler for State { |
src/input/click_grab.rsadded+151 -0
| @@ -0,0 +1,151 @@ | |||
| 1 | +use smithay::input::pointer::{ | ||
| 2 | + AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, | ||
| 3 | + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent, | ||
| 4 | + GestureSwipeUpdateEvent, GrabStartData, MotionEvent, PointerGrab, PointerInnerHandle, | ||
| 5 | + RelativeMotionEvent, | ||
| 6 | +}; | ||
| 7 | +use smithay::input::SeatHandler; | ||
| 8 | +use smithay::utils::{Logical, Point}; | ||
| 9 | + | ||
| 10 | +// ClickGrab from Smithay, but without the grab location updates. | ||
| 11 | +// | ||
| 12 | +// When clicking on a partially off-screen window, such that it will scroll into the view, updating | ||
| 13 | +// the focus location will cause a move event, essentially a short DnD, which might result in some | ||
| 14 | +// unintended action. | ||
| 15 | +// | ||
| 16 | +// Not updating in this case avoids any unintentional DnD. It does cause offset cursor movement if | ||
| 17 | +// you hold and keep moving, but that can't cause mistakes as easily, so it's the lesser evil. | ||
| 18 | +pub struct ClickGrab<D: SeatHandler> { | ||
| 19 | + start_data: GrabStartData<D>, | ||
| 20 | + focus: Option<(D::PointerFocus, Point<f64, Logical>)>, | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +impl<D: SeatHandler> ClickGrab<D> { | ||
| 24 | + pub fn new(start_data: GrabStartData<D>) -> Self { | ||
| 25 | + Self { | ||
| 26 | + focus: start_data.focus.clone(), | ||
| 27 | + start_data, | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +impl<D: SeatHandler + 'static> PointerGrab<D> for ClickGrab<D> { | ||
| 33 | + fn motion( | ||
| 34 | + &mut self, | ||
| 35 | + data: &mut D, | ||
| 36 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 37 | + _focus: Option<(<D as SeatHandler>::PointerFocus, Point<f64, Logical>)>, | ||
| 38 | + event: &MotionEvent, | ||
| 39 | + ) { | ||
| 40 | + handle.motion(data, self.focus.clone(), event); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + fn relative_motion( | ||
| 44 | + &mut self, | ||
| 45 | + data: &mut D, | ||
| 46 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 47 | + focus: Option<(<D as SeatHandler>::PointerFocus, Point<f64, Logical>)>, | ||
| 48 | + event: &RelativeMotionEvent, | ||
| 49 | + ) { | ||
| 50 | + handle.relative_motion(data, focus, event); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + fn button( | ||
| 54 | + &mut self, | ||
| 55 | + data: &mut D, | ||
| 56 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 57 | + event: &ButtonEvent, | ||
| 58 | + ) { | ||
| 59 | + handle.button(data, event); | ||
| 60 | + if handle.current_pressed().is_empty() { | ||
| 61 | + // no more buttons are pressed, release the grab | ||
| 62 | + handle.unset_grab(self, data, event.serial, event.time, false); | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + fn axis(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>, details: AxisFrame) { | ||
| 67 | + handle.axis(data, details); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + fn frame(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>) { | ||
| 71 | + handle.frame(data); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + fn gesture_swipe_begin( | ||
| 75 | + &mut self, | ||
| 76 | + data: &mut D, | ||
| 77 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 78 | + event: &GestureSwipeBeginEvent, | ||
| 79 | + ) { | ||
| 80 | + handle.gesture_swipe_begin(data, event); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + fn gesture_swipe_update( | ||
| 84 | + &mut self, | ||
| 85 | + data: &mut D, | ||
| 86 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 87 | + event: &GestureSwipeUpdateEvent, | ||
| 88 | + ) { | ||
| 89 | + handle.gesture_swipe_update(data, event); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + fn gesture_swipe_end( | ||
| 93 | + &mut self, | ||
| 94 | + data: &mut D, | ||
| 95 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 96 | + event: &GestureSwipeEndEvent, | ||
| 97 | + ) { | ||
| 98 | + handle.gesture_swipe_end(data, event); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + fn gesture_pinch_begin( | ||
| 102 | + &mut self, | ||
| 103 | + data: &mut D, | ||
| 104 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 105 | + event: &GesturePinchBeginEvent, | ||
| 106 | + ) { | ||
| 107 | + handle.gesture_pinch_begin(data, event); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + fn gesture_pinch_update( | ||
| 111 | + &mut self, | ||
| 112 | + data: &mut D, | ||
| 113 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 114 | + event: &GesturePinchUpdateEvent, | ||
| 115 | + ) { | ||
| 116 | + handle.gesture_pinch_update(data, event); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + fn gesture_pinch_end( | ||
| 120 | + &mut self, | ||
| 121 | + data: &mut D, | ||
| 122 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 123 | + event: &GesturePinchEndEvent, | ||
| 124 | + ) { | ||
| 125 | + handle.gesture_pinch_end(data, event); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + fn gesture_hold_begin( | ||
| 129 | + &mut self, | ||
| 130 | + data: &mut D, | ||
| 131 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 132 | + event: &GestureHoldBeginEvent, | ||
| 133 | + ) { | ||
| 134 | + handle.gesture_hold_begin(data, event); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + fn gesture_hold_end( | ||
| 138 | + &mut self, | ||
| 139 | + data: &mut D, | ||
| 140 | + handle: &mut PointerInnerHandle<'_, D>, | ||
| 141 | + event: &GestureHoldEndEvent, | ||
| 142 | + ) { | ||
| 143 | + handle.gesture_hold_end(data, event); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + fn start_data(&self) -> &GrabStartData<D> { | ||
| 147 | + &self.start_data | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + fn unset(&mut self, _data: &mut D) {} | ||
| 151 | +} | ||
src/input/mod.rsmodified+1 -0
| @@ -55,6 +55,7 @@ use crate::utils::spawning::{spawn, spawn_sh}; | |||
| 55 | use crate::utils::{center, get_monotonic_time, CastSessionId, ResizeEdge}; | 55 | use crate::utils::{center, get_monotonic_time, CastSessionId, ResizeEdge}; |
| 56 | 56 | ||
| 57 | pub mod backend_ext; | 57 | pub mod backend_ext; |
| 58 | +pub mod click_grab; | ||
| 58 | pub mod move_grab; | 59 | pub mod move_grab; |
| 59 | pub mod pick_color_grab; | 60 | pub mod pick_color_grab; |
| 60 | pub mod pick_window_grab; | 61 | pub mod pick_window_grab; |