1 | use crate::{ |
2 | error::AtspiError, |
3 | events::{Accessible, EventBodyOwned, GenericEvent, HasMatchRule, HasRegistryEventString}, |
4 | Event, |
5 | }; |
6 | use zvariant::ObjectPath; |
7 | |
8 | /// All events related to the `org.a11y.atspi.Event.Terminal` interface. |
9 | #[derive (Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)] |
10 | pub enum TerminalEvents { |
11 | /// See: [`LineChangedEvent`]. |
12 | LineChanged(LineChangedEvent), |
13 | /// See: [`ColumnCountChangedEvent`]. |
14 | ColumnCountChanged(ColumnCountChangedEvent), |
15 | /// See: [`LineCountChangedEvent`]. |
16 | LineCountChanged(LineCountChangedEvent), |
17 | /// See: [`ApplicationChangedEvent`]. |
18 | ApplicationChanged(ApplicationChangedEvent), |
19 | /// See: [`CharWidthChangedEvent`]. |
20 | CharWidthChanged(CharWidthChangedEvent), |
21 | } |
22 | |
23 | impl_from_interface_event_enum_for_event!(TerminalEvents, Event::Terminal); |
24 | impl_try_from_event_for_user_facing_event_type!(TerminalEvents, Event::Terminal); |
25 | |
26 | event_wrapper_test_cases!(TerminalEvents, LineChangedEvent); |
27 | |
28 | impl HasMatchRule for TerminalEvents { |
29 | const MATCH_RULE_STRING: &'static str = |
30 | "type='signal',interface='org.a11y.atspi.Event.Terminal'" ; |
31 | } |
32 | |
33 | /// A line of text has been changed. |
34 | #[derive (Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] |
35 | pub struct LineChangedEvent { |
36 | /// The [`Accessible`] which the event applies to. |
37 | pub item: crate::events::Accessible, |
38 | } |
39 | |
40 | /// The width of a terminal emulator has changed sufficiently such that the number of characters |
41 | /// able to fit on one *visual* line has changed. |
42 | #[derive (Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] |
43 | pub struct ColumnCountChangedEvent { |
44 | /// The [`Accessible`] which the event applies to. |
45 | pub item: crate::events::Accessible, |
46 | } |
47 | |
48 | /// The height of a terminal emulator has changed sufficiently such that the number of lines |
49 | /// able to fit within the terminal has changed. |
50 | #[derive (Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] |
51 | pub struct LineCountChangedEvent { |
52 | /// The [`Accessible`] which the event applies to. |
53 | pub item: crate::events::Accessible, |
54 | } |
55 | |
56 | #[derive (Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] |
57 | pub struct ApplicationChangedEvent { |
58 | /// The [`Accessible`] which the event applies to. |
59 | pub item: crate::events::Accessible, |
60 | } |
61 | |
62 | /// The width of a terminal emulator has changed sufficiently such that the number of characters |
63 | /// able to fit on one *visual* line has changed. |
64 | #[derive (Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] |
65 | pub struct CharWidthChangedEvent { |
66 | /// The [`Accessible`] which the event applies to. |
67 | pub item: crate::events::Accessible, |
68 | } |
69 | |
70 | impl GenericEvent<'_> for LineChangedEvent { |
71 | const DBUS_MEMBER: &'static str = "LineChanged" ; |
72 | const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Terminal" ; |
73 | const MATCH_RULE_STRING: &'static str = |
74 | "type='signal',interface='org.a11y.atspi.Event.Terminal',member='LineChanged'" ; |
75 | const REGISTRY_EVENT_STRING: &'static str = "Terminal:" ; |
76 | |
77 | type Body = EventBodyOwned; |
78 | |
79 | fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> { |
80 | Ok(Self { item }) |
81 | } |
82 | fn sender(&self) -> String { |
83 | self.item.name.clone() |
84 | } |
85 | fn path<'a>(&self) -> ObjectPath<'_> { |
86 | self.item.path.clone().into() |
87 | } |
88 | fn body(&self) -> Self::Body { |
89 | let copy: LineChangedEvent = self.clone(); |
90 | copy.into() |
91 | } |
92 | } |
93 | |
94 | impl GenericEvent<'_> for ColumnCountChangedEvent { |
95 | const DBUS_MEMBER: &'static str = "ColumncountChanged" ; |
96 | const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Terminal" ; |
97 | const MATCH_RULE_STRING: &'static str = |
98 | "type='signal',interface='org.a11y.atspi.Event.Terminal',member='ColumncountChanged'" ; |
99 | const REGISTRY_EVENT_STRING: &'static str = "Terminal:" ; |
100 | |
101 | type Body = EventBodyOwned; |
102 | |
103 | fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> { |
104 | Ok(Self { item }) |
105 | } |
106 | fn sender(&self) -> String { |
107 | self.item.name.clone() |
108 | } |
109 | fn path<'a>(&self) -> ObjectPath<'_> { |
110 | self.item.path.clone().into() |
111 | } |
112 | fn body(&self) -> Self::Body { |
113 | let copy: ColumnCountChangedEvent = self.clone(); |
114 | copy.into() |
115 | } |
116 | } |
117 | |
118 | impl GenericEvent<'_> for LineCountChangedEvent { |
119 | const DBUS_MEMBER: &'static str = "LinecountChanged" ; |
120 | const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Terminal" ; |
121 | const MATCH_RULE_STRING: &'static str = |
122 | "type='signal',interface='org.a11y.atspi.Event.Terminal',member='LinecountChanged'" ; |
123 | const REGISTRY_EVENT_STRING: &'static str = "Terminal:" ; |
124 | |
125 | type Body = EventBodyOwned; |
126 | |
127 | fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> { |
128 | Ok(Self { item }) |
129 | } |
130 | fn sender(&self) -> String { |
131 | self.item.name.clone() |
132 | } |
133 | fn path<'a>(&self) -> ObjectPath<'_> { |
134 | self.item.path.clone().into() |
135 | } |
136 | fn body(&self) -> Self::Body { |
137 | let copy: LineCountChangedEvent = self.clone(); |
138 | copy.into() |
139 | } |
140 | } |
141 | |
142 | impl GenericEvent<'_> for ApplicationChangedEvent { |
143 | const DBUS_MEMBER: &'static str = "ApplicationChanged" ; |
144 | const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Terminal" ; |
145 | const MATCH_RULE_STRING: &'static str = |
146 | "type='signal',interface='org.a11y.atspi.Event.Terminal',member='ApplicationChanged'" ; |
147 | const REGISTRY_EVENT_STRING: &'static str = "Terminal:" ; |
148 | |
149 | type Body = EventBodyOwned; |
150 | |
151 | fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> { |
152 | Ok(Self { item }) |
153 | } |
154 | fn sender(&self) -> String { |
155 | self.item.name.clone() |
156 | } |
157 | fn path<'a>(&self) -> ObjectPath<'_> { |
158 | self.item.path.clone().into() |
159 | } |
160 | fn body(&self) -> Self::Body { |
161 | let copy: ApplicationChangedEvent = self.clone(); |
162 | copy.into() |
163 | } |
164 | } |
165 | |
166 | impl GenericEvent<'_> for CharWidthChangedEvent { |
167 | const DBUS_MEMBER: &'static str = "CharwidthChanged" ; |
168 | const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Terminal" ; |
169 | const MATCH_RULE_STRING: &'static str = |
170 | "type='signal',interface='org.a11y.atspi.Event.Terminal',member='CharwidthChanged'" ; |
171 | const REGISTRY_EVENT_STRING: &'static str = "Terminal:" ; |
172 | |
173 | type Body = EventBodyOwned; |
174 | |
175 | fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> { |
176 | Ok(Self { item }) |
177 | } |
178 | fn sender(&self) -> String { |
179 | self.item.name.clone() |
180 | } |
181 | fn path<'a>(&self) -> ObjectPath<'_> { |
182 | self.item.path.clone().into() |
183 | } |
184 | fn body(&self) -> Self::Body { |
185 | let copy: CharWidthChangedEvent = self.clone(); |
186 | copy.into() |
187 | } |
188 | } |
189 | |
190 | #[cfg (feature = "zbus" )] |
191 | impl TryFrom<&zbus::Message> for TerminalEvents { |
192 | type Error = AtspiError; |
193 | fn try_from(ev: &zbus::Message) -> Result<Self, Self::Error> { |
194 | let member: MemberName<'_> = ev |
195 | .member() |
196 | .ok_or(err:AtspiError::MemberMatch("Event without member" .into()))?; |
197 | match member.as_str() { |
198 | "LineChanged" => Ok(TerminalEvents::LineChanged(ev.try_into()?)), |
199 | "ColumncountChanged" => Ok(TerminalEvents::ColumnCountChanged(ev.try_into()?)), |
200 | "LinecountChanged" => Ok(TerminalEvents::LineCountChanged(ev.try_into()?)), |
201 | "ApplicationChanged" => Ok(TerminalEvents::ApplicationChanged(ev.try_into()?)), |
202 | "CharwidthChanged" => Ok(TerminalEvents::CharWidthChanged(ev.try_into()?)), |
203 | _ => Err(AtspiError::MemberMatch("No matching member for Terminal" .into())), |
204 | } |
205 | } |
206 | } |
207 | |
208 | impl_from_user_facing_event_for_interface_event_enum!( |
209 | LineChangedEvent, |
210 | TerminalEvents, |
211 | TerminalEvents::LineChanged |
212 | ); |
213 | impl_from_user_facing_type_for_event_enum!(LineChangedEvent, Event::Terminal); |
214 | impl_try_from_event_for_user_facing_type!( |
215 | LineChangedEvent, |
216 | TerminalEvents::LineChanged, |
217 | Event::Terminal |
218 | ); |
219 | event_test_cases!(LineChangedEvent); |
220 | impl_to_dbus_message!(LineChangedEvent); |
221 | impl_from_dbus_message!(LineChangedEvent); |
222 | impl From<LineChangedEvent> for EventBodyOwned { |
223 | fn from(_event: LineChangedEvent) -> Self { |
224 | EventBodyOwned { |
225 | properties: std::collections::HashMap::new(), |
226 | kind: String::default(), |
227 | detail1: i32::default(), |
228 | detail2: i32::default(), |
229 | any_data: zvariant::Value::U8(0).into(), |
230 | } |
231 | } |
232 | } |
233 | |
234 | impl_from_user_facing_event_for_interface_event_enum!( |
235 | ColumnCountChangedEvent, |
236 | TerminalEvents, |
237 | TerminalEvents::ColumnCountChanged |
238 | ); |
239 | impl_from_user_facing_type_for_event_enum!(ColumnCountChangedEvent, Event::Terminal); |
240 | impl_try_from_event_for_user_facing_type!( |
241 | ColumnCountChangedEvent, |
242 | TerminalEvents::ColumnCountChanged, |
243 | Event::Terminal |
244 | ); |
245 | event_test_cases!(ColumnCountChangedEvent); |
246 | impl_to_dbus_message!(ColumnCountChangedEvent); |
247 | impl_from_dbus_message!(ColumnCountChangedEvent); |
248 | impl From<ColumnCountChangedEvent> for EventBodyOwned { |
249 | fn from(_event: ColumnCountChangedEvent) -> Self { |
250 | EventBodyOwned { |
251 | properties: std::collections::HashMap::new(), |
252 | kind: String::default(), |
253 | detail1: i32::default(), |
254 | detail2: i32::default(), |
255 | any_data: zvariant::Value::U8(0).into(), |
256 | } |
257 | } |
258 | } |
259 | |
260 | impl_from_user_facing_event_for_interface_event_enum!( |
261 | LineCountChangedEvent, |
262 | TerminalEvents, |
263 | TerminalEvents::LineCountChanged |
264 | ); |
265 | impl_from_user_facing_type_for_event_enum!(LineCountChangedEvent, Event::Terminal); |
266 | impl_try_from_event_for_user_facing_type!( |
267 | LineCountChangedEvent, |
268 | TerminalEvents::LineCountChanged, |
269 | Event::Terminal |
270 | ); |
271 | event_test_cases!(LineCountChangedEvent); |
272 | impl_to_dbus_message!(LineCountChangedEvent); |
273 | impl_from_dbus_message!(LineCountChangedEvent); |
274 | impl From<LineCountChangedEvent> for EventBodyOwned { |
275 | fn from(_event: LineCountChangedEvent) -> Self { |
276 | EventBodyOwned { |
277 | properties: std::collections::HashMap::new(), |
278 | kind: String::default(), |
279 | detail1: i32::default(), |
280 | detail2: i32::default(), |
281 | any_data: zvariant::Value::U8(0).into(), |
282 | } |
283 | } |
284 | } |
285 | |
286 | impl_from_user_facing_event_for_interface_event_enum!( |
287 | ApplicationChangedEvent, |
288 | TerminalEvents, |
289 | TerminalEvents::ApplicationChanged |
290 | ); |
291 | impl_from_user_facing_type_for_event_enum!(ApplicationChangedEvent, Event::Terminal); |
292 | impl_try_from_event_for_user_facing_type!( |
293 | ApplicationChangedEvent, |
294 | TerminalEvents::ApplicationChanged, |
295 | Event::Terminal |
296 | ); |
297 | event_test_cases!(ApplicationChangedEvent); |
298 | impl_to_dbus_message!(ApplicationChangedEvent); |
299 | impl_from_dbus_message!(ApplicationChangedEvent); |
300 | impl From<ApplicationChangedEvent> for EventBodyOwned { |
301 | fn from(_event: ApplicationChangedEvent) -> Self { |
302 | EventBodyOwned { |
303 | properties: std::collections::HashMap::new(), |
304 | kind: String::default(), |
305 | detail1: i32::default(), |
306 | detail2: i32::default(), |
307 | any_data: zvariant::Value::U8(0).into(), |
308 | } |
309 | } |
310 | } |
311 | |
312 | impl_from_user_facing_event_for_interface_event_enum!( |
313 | CharWidthChangedEvent, |
314 | TerminalEvents, |
315 | TerminalEvents::CharWidthChanged |
316 | ); |
317 | impl_from_user_facing_type_for_event_enum!(CharWidthChangedEvent, Event::Terminal); |
318 | impl_try_from_event_for_user_facing_type!( |
319 | CharWidthChangedEvent, |
320 | TerminalEvents::CharWidthChanged, |
321 | Event::Terminal |
322 | ); |
323 | event_test_cases!(CharWidthChangedEvent); |
324 | impl_to_dbus_message!(CharWidthChangedEvent); |
325 | impl_from_dbus_message!(CharWidthChangedEvent); |
326 | impl From<CharWidthChangedEvent> for EventBodyOwned { |
327 | fn from(_event: CharWidthChangedEvent) -> Self { |
328 | EventBodyOwned { |
329 | properties: std::collections::HashMap::new(), |
330 | kind: String::default(), |
331 | detail1: i32::default(), |
332 | detail2: i32::default(), |
333 | any_data: zvariant::Value::U8(0).into(), |
334 | } |
335 | } |
336 | } |
337 | |
338 | impl HasRegistryEventString for TerminalEvents { |
339 | const REGISTRY_EVENT_STRING: &'static str = "Terminal:" ; |
340 | } |
341 | |