use serde::{Deserialize, Serialize};
use zbus::zvariant::Type;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
#[repr(u32)]
pub enum EventType {
KeyPressed,
KeyReleased,
ButtonPressed,
ButtonReleased,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
#[repr(u32)]
pub enum KeySynthType {
Press,
Release,
Pressrelease,
Sym,
String,
Lockmodifiers,
Unlockmodifiers,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
pub struct DeviceEvent<'a> {
pub event_type: EventType,
pub id: i32,
pub hw_code: i32,
pub modifiers: i32,
pub timestamp: i32,
pub event_string: &'a str,
pub is_text: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
pub struct EventListenerMode {
pub synchronous: bool,
pub preemptive: bool,
pub global: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
pub struct KeyDefinition<'a> {
pub keycode: i32,
pub keysym: i32,
pub keystring: &'a str,
pub unused: i32,
}
#[zbus::proxy(
interface = "org.a11y.atspi.DeviceEventController",
default_path = "/org/a11y/atspi/registry/deviceeventcontroller",
default_service = "org.a11y.atspi.Registry"
)]
trait DeviceEventController {
fn deregister_device_event_listener(
&self,
listener: &zbus::zvariant::ObjectPath<'_>,
types: EventType,
) -> zbus::Result<()>;
fn deregister_keystroke_listener(
&self,
listener: &zbus::zvariant::ObjectPath<'_>,
keys: &[KeyDefinition<'_>],
mask: u32,
type_: EventType,
) -> zbus::Result<()>;
fn generate_keyboard_event(
&self,
keycode: i32,
keystring: &str,
type_: KeySynthType,
) -> zbus::Result<()>;
fn generate_mouse_event(&self, x: i32, y: i32, event_name: &str) -> zbus::Result<()>;
fn notify_listeners_async(&self, event: &DeviceEvent<'_>) -> zbus::Result<()>;
fn notify_listeners_sync(&self, event: &DeviceEvent<'_>) -> zbus::Result<bool>;
fn register_device_event_listener(
&self,
listener: &zbus::zvariant::ObjectPath<'_>,
types: EventType,
) -> zbus::Result<bool>;
fn register_keystroke_listener(
&self,
listener: &zbus::zvariant::ObjectPath<'_>,
keys: &[KeyDefinition<'_>],
mask: u32,
type_: &[EventType],
mode: &EventListenerMode,
) -> zbus::Result<bool>;
}