Skip to content

Commit 5ea59da

Browse files
committed
Update for i3 4.14
Add Event::ShutdownEvent from i3/i3@04dcf42
1 parent a344c5a commit 5ea59da

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ serde_json = "0.6.0"
1515
[features]
1616
i3-4-12 = []
1717
i3-4-13 = ["i3-4-12"]
18+
i3-4-14 = ["i3-4-13"]

src/event.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub enum Event {
1616
WindowEvent(WindowEventInfo),
1717
BarConfigEvent(BarConfigEventInfo),
1818
BindingEvent(BindingEventInfo),
19+
20+
#[cfg(feature = "i3-4-14")]
21+
ShutdownEvent(ShutdownEventInfo),
1922
}
2023

2124
/// Data for `WorkspaceEvent`.
@@ -211,6 +214,30 @@ impl FromStr for BindingEventInfo {
211214
}
212215
}
213216

217+
/// Data for `ShutdownEvent`.
218+
#[derive(Debug)]
219+
#[cfg(feature = "i3-4-14")]
220+
pub struct ShutdownEventInfo {
221+
pub change: ShutdownChange,
222+
}
223+
224+
#[cfg(feature = "i3-4-14")]
225+
impl FromStr for ShutdownEventInfo {
226+
type Err = json::error::Error;
227+
fn from_str(s: &str) -> Result<Self, Self::Err> {
228+
let val: json::Value = try!(json::from_str(s));
229+
let change = match val.find("change").unwrap().as_string().unwrap() {
230+
"restart" => ShutdownChange::Restart,
231+
"exit" => ShutdownChange::Exit,
232+
other => {
233+
warn!(target: "i3ipc", "Unknown ShutdownChange {}", other);
234+
ShutdownChange::Unknown
235+
},
236+
};
237+
Ok(ShutdownEventInfo { change: change })
238+
}
239+
}
240+
214241
/// Less important types
215242
pub mod inner {
216243
/// The kind of workspace change.
@@ -302,4 +329,14 @@ pub mod inner {
302329
/// A BindingChange we don't support yet.
303330
Unknown,
304331
}
332+
333+
/// The kind of shutdown change.
334+
#[derive(Debug)]
335+
#[cfg(feature = "i3-4-14")]
336+
pub enum ShutdownChange {
337+
Restart,
338+
Exit,
339+
/// A ShutdownChange we don't support yet.
340+
Unknown,
341+
}
305342
}

src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ impl<'a> Iterator for EventIterator<'a> {
178178
3 => event::Event::WindowEvent(try!(event::WindowEventInfo::from_str(payload))),
179179
4 => event::Event::BarConfigEvent(try!(event::BarConfigEventInfo::from_str(payload))),
180180
5 => event::Event::BindingEvent(try!(event::BindingEventInfo::from_str(payload))),
181-
_ => unreachable!()
181+
182+
#[cfg(feature = "i3-4-14")]
183+
6 => event::Event::ShutdownEvent(try!(event::ShutdownEventInfo::from_str(payload))),
184+
185+
_ => unreachable!("received an event we aren't subscribed to!")
182186
})
183187
}
184188

@@ -205,7 +209,9 @@ pub enum Subscription {
205209
Mode,
206210
Window,
207211
BarConfig,
208-
Binding
212+
Binding,
213+
#[cfg(feature = "i3-4-14")]
214+
Shutdown,
209215
}
210216

211217
/// Abstraction over an ipc socket to i3. Handles events.
@@ -239,7 +245,9 @@ impl I3EventListener {
239245
Subscription::Mode => "\"mode\"",
240246
Subscription::Window => "\"window\"",
241247
Subscription::BarConfig => "\"barconfig_update\"",
242-
Subscription::Binding => "\"binding\""})
248+
Subscription::Binding => "\"binding\"",
249+
#[cfg(feature = "i3-4-14")]
250+
Subscription::Shutdown => "\"shutdown\""})
243251
.collect::<Vec<_>>()
244252
.join(", ")[..]
245253
+ " ]";

0 commit comments

Comments
 (0)