bspc_rs/parser/parse_events/
mod.rs1use super::errors::ParseError;
2use super::utils::{from_hex_to_id, get_event_type, process_event_reply};
3use crate::events::*;
4
5use std::str::FromStr;
6
7pub mod desktop_events;
8pub mod monitor_events;
9pub mod node_events;
10
11impl FromStr for Event {
12 type Err = ParseError;
13
14 fn from_str(input: &str) -> Result<Self, Self::Err> {
15 if let Ok(x) = input.parse::<NodeEvent>() {
16 return Ok(Event::NodeEvent(x));
17 }
18
19 if let Ok(x) = input.parse::<DesktopEvent>() {
20 return Ok(Event::DesktopEvent(x));
21 }
22
23 if let Ok(x) = input.parse::<MonitorEvent>() {
24 return Ok(Event::MonitorEvent(x));
25 }
26
27 if let Ok(x) = input.parse::<ReportInfo>() {
28 return Ok(Event::Report(x));
29 }
30
31 if let Ok(x) = input.parse::<PointerActionInfo>() {
32 return Ok(Event::PointerAction(x));
33 }
34
35 Err(ParseError::ConversionFailed)
36 }
37}
38
39impl FromStr for PointerActionInfo {
40 type Err = ParseError;
41
42 fn from_str(input: &str) -> Result<Self, Self::Err> {
43 let reply = process_event_reply(input, "pointer_action", 5)?;
44
45 Ok(Self {
46 monitor_id: from_hex_to_id(reply[1])?,
47 desktop_id: from_hex_to_id(reply[2])?,
48 node_id: from_hex_to_id(reply[3])?,
49 action: reply[4].parse()?,
50 action_state: reply[5].parse()?,
51 })
52 }
53}
54
55impl FromStr for ReportInfo {
56 type Err = ParseError;
57
58 fn from_str(input: &str) -> Result<Self, Self::Err> {
59 todo!();
60 }
61}