1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- use xcb;
- use ui::tray;
- use ui::x11;
- use std::cell::RefCell;
- use std::rc::Rc;
- pub struct Panel {
- pub conn: x11::Connection,
- pub window: xcb::Window,
- pub width: u16,
- tray: RefCell<Option<tray::Tray>>,
- finishing: RefCell<bool>
- }
- impl Panel {
- pub fn new(conn: x11::Connection) -> Rc<Panel> {
- let panel = Rc::new(Panel {
- window: conn.generate_id(),
- width: conn.default_screen().width,
- conn: conn,
- tray: RefCell::new(None),
- finishing: RefCell::new(false)
- });
- let tray = tray::Tray::new(Rc::downgrade(&panel));
- *panel.tray.borrow_mut() = Some(tray);
- panel
- }
- pub fn create(&self) {
- let conn = &self.conn;
- let screen = conn.default_screen();
- xcb::create_window(
- conn,
- xcb::COPY_FROM_PARENT as u8,
- self.window,
- screen.root,
- 0, 0,
- screen.width, 20,
- 0,
- xcb::WINDOW_CLASS_INPUT_OUTPUT as u16,
- xcb::COPY_FROM_PARENT,
- &[
- (xcb::CW_BACK_PIXEL, 0xFF000000),
- (xcb::CW_EVENT_MASK, xcb::EVENT_MASK_PROPERTY_CHANGE | xcb::EVENT_MASK_STRUCTURE_NOTIFY)
- ]
- );
- self.set_property(
- conn.atom(x11::_NET_WM_WINDOW_TYPE),
- xcb::ATOM_ATOM,
- 32,
- &[conn.atom(x11::_NET_WM_WINDOW_TYPE_DOCK)]
- );
- xcb::map_window(conn, self.window);
- conn.flush();
- }
- pub fn set_property<T>(&self, name: xcb::Atom, type_: xcb::Atom, format: u8, data: &[T]) {
- xcb::change_property(
- &self.conn,
- xcb::PROP_MODE_REPLACE as u8,
- self.window,
- name,
- type_,
- format,
- data
- );
- }
- pub fn handle_event(&self, event: xcb::GenericEvent) -> bool {
- let tray = self.tray.borrow_mut().as_mut().unwrap().handle_event(&event);
- if self.is_finishing() && event.response_type() == xcb::DESTROY_NOTIFY {
- let event: &xcb::DestroyNotifyEvent = xcb::cast_event(&event);
- if event.window() == self.window {
- return true
- }
- }
- tray
- }
- pub fn is_finishing(&self) -> bool {
- *self.finishing.borrow()
- }
- pub fn finish(&self) {
- *self.finishing.borrow_mut() = true;
- self.tray.borrow_mut().as_mut().unwrap().finish();
- xcb::destroy_window(&self.conn, self.window);
- self.conn.flush();
- }
- }
|