accessibility_ng/
action.rs1use accessibility_sys_ng::{
2 kAXConfirmAction, kAXDecrementAction, kAXIncrementAction, kAXPickAction, kAXPressAction,
3 kAXRaiseAction, kAXShowAlternateUIAction, kAXShowDefaultUIAction, kAXShowMenuAction,
4};
5use core_foundation::string::CFString;
6
7use crate::{AXUIElement, ElementFinder, Error};
8
9macro_rules! performer {
10 (@decl $name:ident, $const:ident) => {
11 fn $name(&self) -> Result<(), Error>;
12 };
13 (@impl $name:ident, $const:ident) => {
14 fn $name(&self) -> Result<(), Error> {
15 self.perform_action(&CFString::from_static_string($const))
16 }
17 };
18}
19
20macro_rules! define_actions {
21 ($(($name:ident, $const:ident)),*,) => {
22 pub trait AXUIElementActions {
23 $(performer!(@decl $name, $const);)*
24 }
25
26 impl AXUIElementActions for AXUIElement {
27 $(performer!(@impl $name, $const);)*
28 }
29
30 impl AXUIElementActions for ElementFinder {
31 $(performer!(@impl $name, $const);)*
32 }
33 }
34}
35
36define_actions![
37 (press, kAXPressAction),
38 (increment, kAXIncrementAction),
39 (decrement, kAXDecrementAction),
40 (confirm, kAXConfirmAction),
41 (show_alternate_ui, kAXShowAlternateUIAction),
42 (show_default_ui, kAXShowDefaultUIAction),
43 (raise, kAXRaiseAction),
44 (show_menu, kAXShowMenuAction),
45 (pick, kAXPickAction),
46];