Debian Codegraph @

third_party/rust/dbus/examples/unity_focused_window.rs

raw
1 extern crate dbus;
2
3 // Tracks currently focused window under the Unity desktop by listening to the
4 // FocusedWindowChanged signal. The signal contains "window_id", "app_id" and "stage",
5 // we print only "app_id".
6
7 use dbus::{Connection, BusType, ConnectionItem};
8
9 fn focus_msg(ci: &ConnectionItem) -> Option<&str> {
10 let m = if let &ConnectionItem::Signal(ref s) = ci { s } else { return None };
11 if &*m.interface().unwrap() != "com.canonical.Unity.WindowStack" { return None };
12 if &*m.member().unwrap() != "FocusedWindowChanged" { return None };
13 let (_, app) = m.get2::<u32, &str>();
14 app
15 }
16
17 fn main() {
18 let c = Connection::get_private(BusType::Session).unwrap();
19 c.add_match("interface='com.canonical.Unity.WindowStack',member='FocusedWindowChanged'").unwrap();
20
21 for i in c.iter(1000) {
22 if let Some(app) = focus_msg(&i) { println!("{} has now focus.", app) };
23 }
24 }
25