1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// Compare with https://github.com/Smithay/smithay/blob/8e49b9b/anvil/src/focus.rs
use smithay::input::Seat;
mod __external_trait_def {
pub(crate) mod smithay {
#[thin_delegate::external_trait_def]
pub(crate) mod utils {
#[thin_delegate::register]
pub trait IsAlive {
/// Check if object is alive
fn alive(&self) -> bool;
}
}
pub(crate) mod input {
#[thin_delegate::external_trait_def(with_uses = true)]
pub(crate) mod keyboard {
use smithay::backend::input::KeyState;
use smithay::input::keyboard::{KeysymHandle, ModifiersState};
use smithay::input::SeatHandler;
use smithay::utils::Serial;
#[thin_delegate::register]
pub trait KeyboardTarget<D>:
IsAlive + PartialEq + Clone + fmt::Debug + Send
where
D: SeatHandler,
{
/// Keyboard focus of a given seat was assigned to this handler
fn enter(
&self,
seat: &Seat<D>,
data: &mut D,
keys: Vec<KeysymHandle<'_>>,
serial: Serial,
);
/// The keyboard focus of a given seat left this handler
fn leave(&self, seat: &Seat<D>, data: &mut D, serial: Serial);
/// A key was pressed on a keyboard from a given seat
fn key(
&self,
seat: &Seat<D>,
data: &mut D,
key: KeysymHandle<'_>,
state: KeyState,
serial: Serial,
time: u32,
);
/// Hold modifiers were changed on a keyboard from a given seat
fn modifiers(
&self,
seat: &Seat<D>,
data: &mut D,
modifiers: ModifiersState,
serial: Serial,
);
}
}
#[thin_delegate::external_trait_def(with_uses = true)]
pub(crate) mod pointer {
use smithay::input::pointer::{
AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent,
GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent,
MotionEvent, RelativeMotionEvent,
};
use smithay::input::SeatHandler;
use smithay::utils::{IsAlive, Serial};
#[thin_delegate::register]
pub trait PointerTarget<D>:
IsAlive + PartialEq + Clone + fmt::Debug + Send
where
D: SeatHandler,
{
/// A pointer of a given seat entered this handler
fn enter(&self, seat: &Seat<D>, data: &mut D, event: &MotionEvent);
/// A pointer of a given seat moved over this handler
fn motion(&self, seat: &Seat<D>, data: &mut D, event: &MotionEvent);
/// A pointer of a given seat that provides relative motion moved over this handler
fn relative_motion(
&self,
seat: &Seat<D>,
data: &mut D,
event: &RelativeMotionEvent,
);
/// A pointer of a given seat clicked a button
fn button(&self, seat: &Seat<D>, data: &mut D, event: &ButtonEvent);
/// A pointer of a given seat scrolled on an axis
fn axis(&self, seat: &Seat<D>, data: &mut D, frame: AxisFrame);
/// End of a pointer frame
fn frame(&self, seat: &Seat<D>, data: &mut D);
/// A pointer of a given seat started a swipe gesture
fn gesture_swipe_begin(
&self,
seat: &Seat<D>,
data: &mut D,
event: &GestureSwipeBeginEvent,
);
/// A pointer of a given seat updated a swipe gesture
fn gesture_swipe_update(
&self,
seat: &Seat<D>,
data: &mut D,
event: &GestureSwipeUpdateEvent,
);
/// A pointer of a given seat ended a swipe gesture
fn gesture_swipe_end(
&self,
seat: &Seat<D>,
data: &mut D,
event: &GestureSwipeEndEvent,
);
/// A pointer of a given seat started a pinch gesture
fn gesture_pinch_begin(
&self,
seat: &Seat<D>,
data: &mut D,
event: &GesturePinchBeginEvent,
);
/// A pointer of a given seat updated a pinch gesture
fn gesture_pinch_update(
&self,
seat: &Seat<D>,
data: &mut D,
event: &GesturePinchUpdateEvent,
);
/// A pointer of a given seat ended a pinch gesture
fn gesture_pinch_end(
&self,
seat: &Seat<D>,
data: &mut D,
event: &GesturePinchEndEvent,
);
/// A pointer of a given seat started a hold gesture
fn gesture_hold_begin(
&self,
seat: &Seat<D>,
data: &mut D,
event: &GestureHoldBeginEvent,
);
/// A pointer of a given seat ended a hold gesture
fn gesture_hold_end(
&self,
seat: &Seat<D>,
data: &mut D,
event: &GestureHoldEndEvent,
);
/// A pointer of a given seat left this handler
fn leave(&self, seat: &Seat<D>, data: &mut D, serial: Serial, time: u32);
/// A pointer of a given seat moved from another handler to this handler
fn replace(
&self,
replaced: <D as SeatHandler>::PointerFocus,
seat: &Seat<D>,
data: &mut D,
event: &MotionEvent,
) {
PointerTarget::<D>::leave(&replaced, seat, data, event.serial, event.time);
PointerTarget::<D>::enter(self, seat, data, event);
}
}
}
#[thin_delegate::external_trait_def(with_uses = true)]
pub(crate) mod touch {
use smithay::input::touch::{
DownEvent, MotionEvent, OrientationEvent, ShapeEvent, UpEvent,
};
use smithay::input::SeatHandler;
use smithay::utils::Serial;
#[thin_delegate::register]
pub trait TouchTarget<D>: IsAlive + PartialEq + Clone + fmt::Debug + Send
where
D: SeatHandler,
{
/// A new touch point has appeared on the target.
///
/// This touch point is assigned a unique ID. Future events from this touch point reference this ID.
/// The ID ceases to be valid after a touch up event and may be reused in the future.
fn down(&self, seat: &Seat<D>, data: &mut D, event: &DownEvent, seq: Serial);
/// The touch point has disappeared.
///
/// No further events will be sent for this touch point and the touch point's ID
/// is released and may be reused in a future touch down event.
fn up(&self, seat: &Seat<D>, data: &mut D, event: &UpEvent, seq: Serial);
/// A touch point has changed coordinates.
fn motion(
&self,
seat: &Seat<D>,
data: &mut D,
event: &MotionEvent,
seq: Serial,
);
/// Indicates the end of a set of events that logically belong together.
fn frame(&self, seat: &Seat<D>, data: &mut D, seq: Serial);
/// Touch session cancelled.
///
/// Touch cancellation applies to all touch points currently active on this target.
/// The client is responsible for finalizing the touch points, future touch points on
/// this target may reuse the touch point ID.
fn cancel(&self, seat: &Seat<D>, data: &mut D, seq: Serial);
/// Sent when a touch point has changed its shape.
///
/// A touch point shape is approximated by an ellipse through the major and minor axis length.
/// The major axis length describes the longer diameter of the ellipse, while the minor axis
/// length describes the shorter diameter. Major and minor are orthogonal and both are specified
/// in surface-local coordinates. The center of the ellipse is always at the touch point location
/// as reported by [`TouchTarget::down`] or [`TouchTarget::motion`].
fn shape(&self, seat: &Seat<D>, data: &mut D, event: &ShapeEvent, seq: Serial);
/// Sent when a touch point has changed its orientation.
///
/// The orientation describes the clockwise angle of a touch point's major axis to the positive surface
/// y-axis and is normalized to the -180 to +180 degree range. The granularity of orientation depends
/// on the touch device, some devices only support binary rotation values between 0 and 90 degrees.
fn orientation(
&self,
seat: &Seat<D>,
data: &mut D,
event: &OrientationEvent,
seq: Serial,
);
}
}
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[thin_delegate::register]
struct Window(smithay::desktop::Window);
#[thin_delegate::fill_delegate(external_trait_def = __external_trait_def::smithay::utils)]
impl smithay::utils::IsAlive for Window {}
#[thin_delegate::fill_delegate(
external_trait_def = __external_trait_def::smithay::input::keyboard,
scheme = |f| {
match self.0.underlying_surface() {
smithay::desktop::WindowSurface::Wayland(s) => f(s.wl_surface()),
smithay::desktop::WindowSurface::X11(s) => f(s),
}
}
)]
impl smithay::input::keyboard::KeyboardTarget<State> for Window {}
#[derive(Debug, Clone, PartialEq)]
#[thin_delegate::register]
enum KeyboardFocusTarget {
Window(Window),
LayerSurface(smithay::desktop::LayerSurface),
Popup(smithay::desktop::PopupKind),
}
#[thin_delegate::fill_delegate(external_trait_def = __external_trait_def::smithay::utils)]
impl smithay::utils::IsAlive for KeyboardFocusTarget {}
#[thin_delegate::fill_delegate(
external_trait_def = __external_trait_def::smithay::input::keyboard,
scheme = |f| {
match self {
Self::Window(w) => f(w),
Self::LayerSurface(s) => f(s.wl_surface()),
Self::Popup(p) => f(p.wl_surface()),
}
}
)]
impl smithay::input::keyboard::KeyboardTarget<State> for KeyboardFocusTarget {}
#[derive(Debug, Clone, PartialEq)]
#[thin_delegate::register]
enum PointerFocusTarget {
WlSurface(smithay::reexports::wayland_server::protocol::wl_surface::WlSurface),
X11Surface(smithay::xwayland::X11Surface),
}
#[thin_delegate::fill_delegate(external_trait_def = __external_trait_def::smithay::utils)]
impl smithay::utils::IsAlive for PointerFocusTarget {}
#[thin_delegate::fill_delegate(external_trait_def = __external_trait_def::smithay::input::pointer)]
impl smithay::input::pointer::PointerTarget<State> for PointerFocusTarget {}
#[thin_delegate::fill_delegate(external_trait_def = __external_trait_def::smithay::input::touch)]
impl smithay::input::touch::TouchTarget<State> for PointerFocusTarget {}
struct State;
#[allow(unused)]
impl smithay::input::SeatHandler for State {
type KeyboardFocus = KeyboardFocusTarget;
type PointerFocus = PointerFocusTarget;
type TouchFocus = PointerFocusTarget;
fn seat_state(&mut self) -> &mut smithay::input::SeatState<State> {
todo!();
}
fn focus_changed(&mut self, seat: &Seat<Self>, target: Option<&KeyboardFocusTarget>) {
todo!();
}
fn cursor_image(
&mut self,
_seat: &Seat<Self>,
image: smithay::input::pointer::CursorImageStatus,
) {
todo!();
}
fn led_state_changed(
&mut self,
_seat: &Seat<Self>,
led_state: smithay::input::keyboard::LedState,
) {
todo!();
}
}
fn main() {}