swayipc_types/error/
event.rs

1use crate::{
2    Error::UnimplementedEvent,
3    Event::{self, *},
4    Fallible,
5};
6
7impl Event {
8    pub fn decode((payload_type, payload): (u32, Vec<u8>)) -> Fallible<Self> {
9        // strip the highest order bit indicating it's an event
10        // since we dont convert to hex we also dont match on the (hex) values written in the sway-ipc docs!
11        let event_type = (payload_type << 1) >> 1;
12        Ok(match event_type {
13            0 => Workspace(serde_json::from_slice(&payload)?),
14            1 => Output(serde_json::from_slice(&payload)?),
15            2 => Mode(serde_json::from_slice(&payload)?),
16            3 => Window(serde_json::from_slice(&payload)?),
17            4 => BarConfigUpdate(serde_json::from_slice(&payload)?),
18            5 => Binding(serde_json::from_slice(&payload)?),
19            6 => Shutdown(serde_json::from_slice(&payload)?),
20            7 => Tick(serde_json::from_slice(&payload)?),
21            20 => BarStateUpdate(serde_json::from_slice(&payload)?),
22            21 => Input(serde_json::from_slice(&payload)?),
23            _ => return Err(UnimplementedEvent(event_type, payload)),
24        })
25    }
26}