forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

click_grab.rs151 lines, 4.3 KiBHistoryRawDownload
1use smithay::input::pointer::{
2 AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent,
3 GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent,
4 GestureSwipeUpdateEvent, GrabStartData, MotionEvent, PointerGrab, PointerInnerHandle,
5 RelativeMotionEvent,
6};
7use smithay::input::SeatHandler;
8use 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.
18pub struct ClickGrab<D: SeatHandler> {
19 start_data: GrabStartData<D>,
20 focus: Option<(D::PointerFocus, Point<f64, Logical>)>,
21}
22
23impl<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
32impl<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}