i3ipc_types/
event.rs

1//! For subscribing and receiving events, each struct matches a particular
2//! `Subscribe` variant. For instance, subscribing with `Subscribe::Workspace`
3//! will net `Event::Workspace` when workspace events are sent over the ipc.
4use serde::{Deserialize, Serialize};
5
6use crate::reply;
7
8#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone, Copy)]
9#[serde(rename_all = "snake_case")]
10pub enum Subscribe {
11    Workspace,
12    Output,
13    Mode,
14    Window,
15    #[serde(rename = "barconfig_update")]
16    BarConfigUpdate,
17    Binding,
18    Shutdown,
19    Tick,
20}
21
22impl From<u32> for Subscribe {
23    fn from(num: u32) -> Self {
24        match num {
25            0 => Subscribe::Workspace,
26            1 => Subscribe::Output,
27            2 => Subscribe::Mode,
28            3 => Subscribe::Window,
29            4 => Subscribe::BarConfigUpdate,
30            5 => Subscribe::Binding,
31            6 => Subscribe::Shutdown,
32            7 => Subscribe::Tick,
33            _ => panic!("Unknown event found"),
34        }
35    }
36}
37
38impl From<Subscribe> for u32 {
39    fn from(evt: Subscribe) -> Self {
40        match evt {
41            Subscribe::Workspace => 0,
42            Subscribe::Output => 1,
43            Subscribe::Mode => 2,
44            Subscribe::Window => 3,
45            Subscribe::BarConfigUpdate => 4,
46            Subscribe::Binding => 5,
47            Subscribe::Shutdown => 6,
48            Subscribe::Tick => 7,
49        }
50    }
51}
52
53#[derive(Debug)]
54pub enum Event {
55    Workspace(Box<WorkspaceData>),
56    Output(OutputData),
57    Mode(ModeData),
58    Window(Box<WindowData>),
59    BarConfig(BarConfigData),
60    Binding(BindingData),
61    Shutdown(ShutdownData),
62    Tick(TickData),
63}
64
65#[derive(Deserialize, Serialize, Eq, PartialEq, Hash, Debug, Copy, Clone)]
66#[serde(rename_all = "lowercase")]
67pub enum WorkspaceChange {
68    Focus,
69    Init,
70    Empty,
71    Urgent,
72    Rename,
73    Reload,
74    Restored,
75    Move,
76}
77
78#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
79pub struct WorkspaceData {
80    pub change: WorkspaceChange,
81    pub current: Option<reply::Node>,
82    pub old: Option<reply::Node>,
83}
84
85#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone)]
86pub struct OutputData {
87    pub change: String,
88}
89
90#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone)]
91pub struct ModeData {
92    pub change: String,
93    pub pango_markup: bool,
94}
95
96#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
97pub struct WindowData {
98    pub change: WindowChange,
99    pub container: reply::Node,
100}
101
102#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone, Copy)]
103#[serde(rename_all = "snake_case")]
104pub enum WindowChange {
105    ///  the window has become managed by i3  
106    New,
107    /// the window has closed
108    Close,
109    /// the window has received input focus
110    Focus,
111    /// the window’s title has changed
112    Title,
113    /// the window has entered or exited fullscreen mode
114    FullscreenMode,
115    /// the window has changed its position in the tree
116    Move,
117    /// the window has transitioned to or from floating
118    Floating,
119    /// the window has become urgent or lost its urgent status
120    Urgent,
121    /// a mark has been added to or removed from the window
122    Mark,
123}
124
125pub type BarConfigData = reply::BarConfig;
126
127#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone)]
128pub struct BindingData {
129    pub change: String,
130    pub binding: BindingObject,
131}
132
133#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone)]
134pub struct BindingObject {
135    pub command: String,
136    pub event_state_mask: Vec<String>,
137    pub input_code: isize,
138    pub symbol: Option<String>,
139    pub input_type: BindType,
140}
141
142#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone, Copy)]
143#[serde(rename_all = "lowercase")]
144pub enum BindType {
145    Keyboard,
146    Mouse,
147}
148
149#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone)]
150pub struct ShutdownData {
151    pub change: ShutdownChange,
152}
153
154#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone, Copy)]
155#[serde(rename_all = "lowercase")]
156pub enum ShutdownChange {
157    Restart,
158    Exit,
159}
160
161#[derive(Deserialize, Serialize, Eq, Hash, PartialEq, Debug, Clone)]
162pub struct TickData {
163    pub first: bool,
164    pub payload: String,
165}