1use serde::Serialize;
6
7#[derive(Debug, Clone, Copy, Serialize)]
9#[serde(rename_all = "lowercase")]
10pub enum MouseButton {
11 None,
12 Left,
13 Middle,
14 Right,
15 Back,
16 Forward,
17}
18
19#[derive(Debug, Clone, Copy, Serialize)]
21#[serde(rename_all = "camelCase")]
22pub enum MouseEventType {
23 MousePressed,
24 MouseReleased,
25 MouseMoved,
26 MouseWheel,
27}
28
29#[derive(Debug, Clone, Copy, Serialize)]
31#[serde(rename_all = "camelCase")]
32pub enum KeyEventType {
33 KeyDown,
34 KeyUp,
35 RawKeyDown,
36 Char,
37}
38
39#[derive(Debug, Clone, Serialize)]
41#[serde(rename_all = "camelCase")]
42pub struct DispatchMouseEventParams {
43 #[serde(rename = "type")]
45 pub event_type: MouseEventType,
46 pub x: f64,
48 pub y: f64,
50 #[serde(skip_serializing_if = "Option::is_none")]
52 pub button: Option<MouseButton>,
53 #[serde(skip_serializing_if = "Option::is_none")]
55 pub click_count: Option<i32>,
56 #[serde(skip_serializing_if = "Option::is_none")]
58 pub modifiers: Option<i32>,
59 #[serde(skip_serializing_if = "Option::is_none")]
61 pub timestamp: Option<f64>,
62}
63
64impl DispatchMouseEventParams {
65 pub fn mouse_move(x: f64, y: f64) -> Self {
67 Self {
68 event_type: MouseEventType::MouseMoved,
69 x,
70 y,
71 button: None,
72 click_count: None,
73 modifiers: None,
74 timestamp: None,
75 }
76 }
77
78 pub fn mouse_down(x: f64, y: f64, button: MouseButton) -> Self {
80 Self {
81 event_type: MouseEventType::MousePressed,
82 x,
83 y,
84 button: Some(button),
85 click_count: Some(1),
86 modifiers: None,
87 timestamp: None,
88 }
89 }
90
91 pub fn mouse_up(x: f64, y: f64, button: MouseButton) -> Self {
93 Self {
94 event_type: MouseEventType::MouseReleased,
95 x,
96 y,
97 button: Some(button),
98 click_count: Some(1),
99 modifiers: None,
100 timestamp: None,
101 }
102 }
103
104 pub fn mouse_wheel(x: f64, y: f64, delta_x: f64, delta_y: f64) -> DispatchMouseWheelParams {
106 DispatchMouseWheelParams {
107 event_type: MouseEventType::MouseWheel,
108 x,
109 y,
110 delta_x,
111 delta_y,
112 modifiers: None,
113 pointer_type: None,
114 }
115 }
116}
117
118#[derive(Debug, Clone, Serialize)]
120#[serde(rename_all = "camelCase")]
121pub struct DispatchMouseWheelParams {
122 #[serde(rename = "type")]
124 pub event_type: MouseEventType,
125 pub x: f64,
127 pub y: f64,
129 pub delta_x: f64,
131 pub delta_y: f64,
133 #[serde(skip_serializing_if = "Option::is_none")]
135 pub modifiers: Option<i32>,
136 #[serde(skip_serializing_if = "Option::is_none")]
138 pub pointer_type: Option<String>,
139}
140
141#[derive(Debug, Clone, Serialize)]
143#[serde(rename_all = "camelCase")]
144pub struct DispatchKeyEventParams {
145 #[serde(rename = "type")]
147 pub event_type: KeyEventType,
148 #[serde(skip_serializing_if = "Option::is_none")]
150 pub modifiers: Option<i32>,
151 #[serde(skip_serializing_if = "Option::is_none")]
153 pub timestamp: Option<f64>,
154 #[serde(skip_serializing_if = "Option::is_none")]
156 pub text: Option<String>,
157 #[serde(skip_serializing_if = "Option::is_none")]
159 pub unmodified_text: Option<String>,
160 #[serde(skip_serializing_if = "Option::is_none")]
162 pub key_identifier: Option<String>,
163 #[serde(skip_serializing_if = "Option::is_none")]
165 pub code: Option<String>,
166 #[serde(skip_serializing_if = "Option::is_none")]
168 pub key: Option<String>,
169 #[serde(skip_serializing_if = "Option::is_none")]
171 pub windows_virtual_key_code: Option<i32>,
172 #[serde(skip_serializing_if = "Option::is_none")]
174 pub native_virtual_key_code: Option<i32>,
175 #[serde(skip_serializing_if = "Option::is_none")]
177 pub auto_repeat: Option<bool>,
178 #[serde(skip_serializing_if = "Option::is_none")]
180 pub is_keypad: Option<bool>,
181 #[serde(skip_serializing_if = "Option::is_none")]
183 pub is_system_key: Option<bool>,
184 #[serde(skip_serializing_if = "Option::is_none")]
186 pub commands: Option<Vec<String>>,
187}
188
189impl DispatchKeyEventParams {
190 pub fn key_down(key: &str) -> Self {
192 Self {
193 event_type: KeyEventType::KeyDown,
194 modifiers: None,
195 timestamp: None,
196 text: None,
197 unmodified_text: None,
198 key_identifier: None,
199 code: Some(key.to_string()),
200 key: Some(key.to_string()),
201 windows_virtual_key_code: None,
202 native_virtual_key_code: None,
203 auto_repeat: None,
204 is_keypad: None,
205 is_system_key: None,
206 commands: None,
207 }
208 }
209
210 pub fn key_up(key: &str) -> Self {
212 Self {
213 event_type: KeyEventType::KeyUp,
214 modifiers: None,
215 timestamp: None,
216 text: None,
217 unmodified_text: None,
218 key_identifier: None,
219 code: Some(key.to_string()),
220 key: Some(key.to_string()),
221 windows_virtual_key_code: None,
222 native_virtual_key_code: None,
223 auto_repeat: None,
224 is_keypad: None,
225 is_system_key: None,
226 commands: None,
227 }
228 }
229
230 pub fn char(text: &str) -> Self {
232 Self {
233 event_type: KeyEventType::Char,
234 modifiers: None,
235 timestamp: None,
236 text: Some(text.to_string()),
237 unmodified_text: Some(text.to_string()),
238 key_identifier: None,
239 code: None,
240 key: None,
241 windows_virtual_key_code: None,
242 native_virtual_key_code: None,
243 auto_repeat: None,
244 is_keypad: None,
245 is_system_key: None,
246 commands: None,
247 }
248 }
249}
250
251#[derive(Debug, Clone, Serialize)]
253#[serde(rename_all = "camelCase")]
254pub struct InsertTextParams {
255 pub text: String,
257}
258
259pub mod modifiers {
261 pub const ALT: i32 = 1;
262 pub const CTRL: i32 = 2;
263 pub const META: i32 = 4;
264 pub const SHIFT: i32 = 8;
265}
266
267#[derive(Debug, Clone, Copy, Serialize)]
269#[serde(rename_all = "camelCase")]
270pub enum TouchEventType {
271 TouchStart,
272 TouchEnd,
273 TouchMove,
274 TouchCancel,
275}
276
277#[derive(Debug, Clone, Serialize)]
279#[serde(rename_all = "camelCase")]
280pub struct TouchPoint {
281 pub x: f64,
283 pub y: f64,
285 #[serde(skip_serializing_if = "Option::is_none")]
287 pub radius_x: Option<f64>,
288 #[serde(skip_serializing_if = "Option::is_none")]
290 pub radius_y: Option<f64>,
291 #[serde(skip_serializing_if = "Option::is_none")]
293 pub rotation_angle: Option<f64>,
294 #[serde(skip_serializing_if = "Option::is_none")]
296 pub force: Option<f64>,
297 #[serde(skip_serializing_if = "Option::is_none")]
299 pub id: Option<i32>,
300}
301
302impl TouchPoint {
303 pub fn new(x: f64, y: f64) -> Self {
305 Self {
306 x,
307 y,
308 radius_x: None,
309 radius_y: None,
310 rotation_angle: None,
311 force: None,
312 id: None,
313 }
314 }
315
316 #[must_use]
318 pub fn with_id(mut self, id: i32) -> Self {
319 self.id = Some(id);
320 self
321 }
322}
323
324#[derive(Debug, Clone, Serialize)]
326#[serde(rename_all = "camelCase")]
327pub struct DispatchTouchEventParams {
328 #[serde(rename = "type")]
330 pub event_type: TouchEventType,
331 pub touch_points: Vec<TouchPoint>,
333 #[serde(skip_serializing_if = "Option::is_none")]
335 pub modifiers: Option<i32>,
336 #[serde(skip_serializing_if = "Option::is_none")]
338 pub timestamp: Option<f64>,
339}
340
341impl DispatchTouchEventParams {
342 pub fn touch_start(x: f64, y: f64) -> Self {
344 Self {
345 event_type: TouchEventType::TouchStart,
346 touch_points: vec![TouchPoint::new(x, y)],
347 modifiers: None,
348 timestamp: None,
349 }
350 }
351
352 pub fn touch_end() -> Self {
354 Self {
355 event_type: TouchEventType::TouchEnd,
356 touch_points: vec![],
357 modifiers: None,
358 timestamp: None,
359 }
360 }
361
362 pub fn touch_move(x: f64, y: f64) -> Self {
364 Self {
365 event_type: TouchEventType::TouchMove,
366 touch_points: vec![TouchPoint::new(x, y)],
367 modifiers: None,
368 timestamp: None,
369 }
370 }
371
372 pub fn touch_cancel() -> Self {
374 Self {
375 event_type: TouchEventType::TouchCancel,
376 touch_points: vec![],
377 modifiers: None,
378 timestamp: None,
379 }
380 }
381}
382
383#[derive(Debug, Clone, Copy, Serialize)]
385#[serde(rename_all = "camelCase")]
386pub enum DragEventType {
387 DragEnter,
388 DragOver,
389 Drop,
390 DragCancel,
391}
392
393#[derive(Debug, Clone, Serialize)]
395#[serde(rename_all = "camelCase")]
396pub struct DragDataItem {
397 pub mime_type: String,
399 pub data: String,
401}
402
403#[derive(Debug, Clone, Serialize)]
405#[serde(rename_all = "camelCase")]
406pub struct DragData {
407 pub items: Vec<DragDataItem>,
409 #[serde(skip_serializing_if = "Option::is_none")]
411 pub drag_operations_mask: Option<i32>,
412}
413
414impl DragData {
415 pub fn new() -> Self {
417 Self {
418 items: vec![],
419 drag_operations_mask: None,
420 }
421 }
422
423 #[must_use]
425 pub fn with_text(mut self, text: &str) -> Self {
426 self.items.push(DragDataItem {
427 mime_type: "text/plain".to_string(),
428 data: text.to_string(),
429 });
430 self
431 }
432}
433
434impl Default for DragData {
435 fn default() -> Self {
436 Self::new()
437 }
438}
439
440#[derive(Debug, Clone, Serialize)]
442#[serde(rename_all = "camelCase")]
443pub struct DispatchDragEventParams {
444 #[serde(rename = "type")]
446 pub event_type: DragEventType,
447 pub x: f64,
449 pub y: f64,
451 pub data: DragData,
453 #[serde(skip_serializing_if = "Option::is_none")]
455 pub modifiers: Option<i32>,
456}