accessibility_sys_ng/
ui_element.rs

1#![allow(non_upper_case_globals, non_camel_case_types)]
2use std::ffi::{c_uchar, c_void};
3
4use core_foundation_sys::{
5    array::CFArrayRef,
6    base::{CFIndex, CFTypeID, CFTypeRef},
7    dictionary::CFDictionaryRef,
8    runloop::CFRunLoopSourceRef,
9    string::CFStringRef,
10};
11
12use crate::AXError;
13
14pub enum __AXUIElement {}
15pub type AXUIElementRef = *mut __AXUIElement;
16
17unsafe impl Send for __AXUIElement {}
18
19pub enum __AXObserver {}
20pub type AXObserverRef = *mut __AXObserver;
21
22unsafe impl Send for __AXObserver {}
23
24pub type AXCopyMultipleAttributeOptions = u32;
25pub const kAXCopyMultipleAttributeOptionStopOnError: u32 = 0x1;
26
27// TODO(eiz): upstream these to core-foundation-rs
28pub type CGKeyCode = u16;
29pub type CGCharCode = u16;
30
31// TODO(eiz): ditto, this is from mach headers...
32pub type pid_t = i32;
33
34#[link(name = "ApplicationServices", kind = "framework")]
35extern "C" {
36    pub fn AXAPIEnabled() -> bool;
37    pub fn AXIsProcessTrustedWithOptions(options: CFDictionaryRef) -> bool;
38    pub static kAXTrustedCheckOptionPrompt: CFStringRef;
39    pub fn AXIsProcessTrusted() -> bool;
40    pub fn AXMakeProcessTrusted(executablePath: CFStringRef) -> AXError;
41
42    pub fn AXUIElementGetTypeID() -> CFTypeID;
43    pub fn AXUIElementCopyAttributeNames(
44        element: AXUIElementRef,
45        names: *mut CFArrayRef,
46    ) -> AXError;
47    pub fn AXUIElementCopyAttributeValue(
48        element: AXUIElementRef,
49        attribute: CFStringRef,
50        value: *mut CFTypeRef,
51    ) -> AXError;
52    pub fn AXUIElementGetAttributeValueCount(
53        element: AXUIElementRef,
54        attribute: CFStringRef,
55        count: *mut CFIndex,
56    ) -> AXError;
57    pub fn AXUIElementCopyAttributeValues(
58        element: AXUIElementRef,
59        attribute: CFStringRef,
60        index: CFIndex,
61        maxValues: CFIndex,
62        values: *mut CFArrayRef,
63    ) -> AXError;
64    pub fn AXUIElementIsAttributeSettable(
65        element: AXUIElementRef,
66        attribute: CFStringRef,
67        settable: *mut c_uchar,
68    ) -> AXError;
69    pub fn AXUIElementSetAttributeValue(
70        element: AXUIElementRef,
71        attribute: CFStringRef,
72        value: CFTypeRef,
73    ) -> AXError;
74    pub fn AXUIElementCopyMultipleAttributeValues(
75        element: AXUIElementRef,
76        attributes: CFArrayRef,
77        options: AXCopyMultipleAttributeOptions,
78        values: *mut CFArrayRef,
79    ) -> AXError;
80    pub fn AXUIElementCopyParameterizedAttributeNames(
81        element: AXUIElementRef,
82        names: *mut CFArrayRef,
83    ) -> AXError;
84    pub fn AXUIElementCopyParameterizedAttributeValue(
85        element: AXUIElementRef,
86        parameterizedAttribute: CFStringRef,
87        parameter: CFTypeRef,
88        result: *mut CFTypeRef,
89    ) -> AXError;
90    pub fn AXUIElementCopyActionNames(element: AXUIElementRef, names: *mut CFArrayRef) -> AXError;
91    pub fn AXUIElementCopyActionDescription(
92        element: AXUIElementRef,
93        action: CFStringRef,
94        description: *mut CFStringRef,
95    ) -> AXError;
96    pub fn AXUIElementPerformAction(element: AXUIElementRef, action: CFStringRef) -> AXError;
97    pub fn AXUIElementCopyElementAtPosition(
98        application: AXUIElementRef,
99        x: f32,
100        y: f32,
101        element: *mut AXUIElementRef,
102    ) -> AXError;
103    pub fn AXUIElementCreateApplication(pid: pid_t) -> AXUIElementRef;
104    pub fn AXUIElementCreateSystemWide() -> AXUIElementRef;
105    pub fn AXUIElementGetPid(element: AXUIElementRef, pid: *mut pid_t) -> AXError;
106    pub fn AXUIElementSetMessagingTimeout(
107        element: AXUIElementRef,
108        timeoutInSeconds: f32,
109    ) -> AXError;
110    pub fn AXUIElementPostKeyboardEvent(
111        application: AXUIElementRef,
112        keyChar: CGCharCode,
113        virtualKey: CGKeyCode,
114        keyDown: bool,
115    ) -> AXError;
116    pub fn AXObserverGetTypeID() -> CFTypeID;
117    pub fn AXObserverCreate(
118        application: pid_t,
119        callback: AXObserverCallback,
120        outObserver: *mut AXObserverRef,
121    ) -> AXError;
122    pub fn AXObserverCreateWithInfoCallback(
123        application: pid_t,
124        callback: AXObserverCallbackWithInfo,
125        outObserver: *mut AXObserverRef,
126    ) -> AXError;
127    pub fn AXObserverAddNotification(
128        observer: AXObserverRef,
129        element: AXUIElementRef,
130        notification: CFStringRef,
131        refcon: *mut c_void,
132    ) -> AXError;
133    pub fn AXObserverRemoveNotification(
134        observer: AXObserverRef,
135        element: AXUIElementRef,
136        notification: CFStringRef,
137    ) -> AXError;
138    pub fn AXObserverGetRunLoopSource(observer: AXObserverRef) -> CFRunLoopSourceRef;
139}
140
141pub type AXObserverCallback = unsafe extern "C" fn(
142    observer: AXObserverRef,
143    element: AXUIElementRef,
144    notification: CFStringRef,
145    refcon: *mut c_void,
146);
147pub type AXObserverCallbackWithInfo = unsafe extern "C" fn(
148    observer: AXObserverRef,
149    element: AXUIElementRef,
150    notification: CFStringRef,
151    info: CFDictionaryRef,
152    refcon: *mut c_void,
153);