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