1use serde::{Deserialize, Serialize};
14use zbus::zvariant::Type;
15
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
17#[repr(u32)]
18pub enum EventType {
19 KeyPressed,
20 KeyReleased,
21 ButtonPressed,
22 ButtonReleased,
23}
24
25#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
26#[repr(u32)]
27pub enum KeySynthType {
28 Press,
29 Release,
30 Pressrelease,
31 Sym,
32 String,
33 Lockmodifiers,
34 Unlockmodifiers,
35}
36
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
38pub struct DeviceEvent<'a> {
39 pub event_type: EventType,
40 pub id: i32,
41 pub hw_code: i32,
42 pub modifiers: i32,
43 pub timestamp: i32,
44 pub event_string: &'a str,
45 pub is_text: bool,
46}
47
48#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
49pub struct EventListenerMode {
50 pub synchronous: bool,
55 pub preemptive: bool,
58 pub global: bool,
61}
62
63#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
64pub struct KeyDefinition<'a> {
65 pub keycode: i32,
66 pub keysym: i32,
67 pub keystring: &'a str,
68 pub unused: i32,
69}
70
71#[zbus::proxy(
72 interface = "org.a11y.atspi.DeviceEventController",
73 default_path = "/org/a11y/atspi/registry/deviceeventcontroller",
74 default_service = "org.a11y.atspi.Registry"
75)]
76pub trait DeviceEventController {
77 fn deregister_device_event_listener(
79 &self,
80 listener: &zbus::zvariant::ObjectPath<'_>,
81 types: EventType,
82 ) -> zbus::Result<()>;
83
84 fn deregister_keystroke_listener(
86 &self,
87 listener: &zbus::zvariant::ObjectPath<'_>,
88 keys: &[KeyDefinition<'_>],
89 mask: u32,
90 type_: EventType,
91 ) -> zbus::Result<()>;
92
93 fn generate_keyboard_event(
95 &self,
96 keycode: i32,
97 keystring: &str,
98 type_: KeySynthType,
99 ) -> zbus::Result<()>;
100
101 fn generate_mouse_event(&self, x: i32, y: i32, event_name: &str) -> zbus::Result<()>;
103
104 fn notify_listeners_async(&self, event: &DeviceEvent<'_>) -> zbus::Result<()>;
106
107 fn notify_listeners_sync(&self, event: &DeviceEvent<'_>) -> zbus::Result<bool>;
109
110 fn register_device_event_listener(
112 &self,
113 listener: &zbus::zvariant::ObjectPath<'_>,
114 types: EventType,
115 ) -> zbus::Result<bool>;
116
117 fn register_keystroke_listener(
119 &self,
120 listener: &zbus::zvariant::ObjectPath<'_>,
121 keys: &[KeyDefinition<'_>],
122 mask: u32,
123 type_: &[EventType],
124 mode: &EventListenerMode,
125 ) -> zbus::Result<bool>;
126}