|
@@ -5,7 +5,8 @@ pub struct Tray<'a> {
|
|
|
conn: &'a xcb::Connection,
|
|
|
atoms: &'a atom::Atoms<'a>,
|
|
|
screen: usize,
|
|
|
- window: xcb::Window
|
|
|
+ window: xcb::Window,
|
|
|
+ children: Vec<xcb::Window>
|
|
|
}
|
|
|
|
|
|
impl<'a> Tray<'a> {
|
|
@@ -14,7 +15,8 @@ impl<'a> Tray<'a> {
|
|
|
conn: conn,
|
|
|
atoms: atoms,
|
|
|
screen: screen,
|
|
|
- window: conn.generate_id()
|
|
|
+ window: conn.generate_id(),
|
|
|
+ children: vec![]
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -45,4 +47,47 @@ impl<'a> Tray<'a> {
|
|
|
let owner = xcb::get_selection_owner(self.conn, selection).get_reply().unwrap().owner();
|
|
|
owner == self.window
|
|
|
}
|
|
|
+
|
|
|
+ pub fn adopt(&mut self, window: xcb::Window) {
|
|
|
+ let offset = (self.children.len() * 20) as i16;
|
|
|
+ xcb::change_window_attributes(self.conn, window, &[
|
|
|
+ (xcb::CW_EVENT_MASK, xcb::EVENT_MASK_STRUCTURE_NOTIFY)
|
|
|
+ ]);
|
|
|
+ xcb::reparent_window(self.conn, window, self.window, offset, 0);
|
|
|
+ xcb::map_window(self.conn, window);
|
|
|
+ self.conn.flush();
|
|
|
+ self.children.push(window);
|
|
|
+ self.resize();
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn forget(&mut self, window: xcb::Window) {
|
|
|
+ self.children.retain(|child| *child != window);
|
|
|
+ self.resize();
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn resize(&self) {
|
|
|
+ let len = self.children.len();
|
|
|
+ if len > 0 {
|
|
|
+ xcb::configure_window(self.conn, self.window, &[
|
|
|
+ (xcb::CONFIG_WINDOW_WIDTH as u16, (len * 20) as u32)
|
|
|
+ ]);
|
|
|
+ xcb::map_window(self.conn, self.window);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ xcb::unmap_window(self.conn, self.window);
|
|
|
+ }
|
|
|
+ self.conn.flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn cleanup(&self) {
|
|
|
+ let setup = self.conn.get_setup();
|
|
|
+ let screen = setup.roots().nth(self.screen).unwrap();
|
|
|
+ let root = screen.root();
|
|
|
+
|
|
|
+ for child in self.children.iter() {
|
|
|
+ xcb::unmap_window(self.conn, *child);
|
|
|
+ xcb::reparent_window(self.conn, *child, root, 0, 0);
|
|
|
+ }
|
|
|
+ self.conn.flush();
|
|
|
+ }
|
|
|
}
|