use crate::x::atoms::Atoms; use crate::x::connection::*; use std::sync::Arc; use xcb::x::Screen; pub struct Display { connection: Connection, screen_index: i32, atoms: Atoms, } impl HasConnection for Arc { fn connection(&self) -> &Connection { &self.connection } } impl Display { pub fn new() -> xcb::Result { let (connection, screen_index) = Connection::connect(None)?; let atoms = connection.get_atoms()?; Ok(Display { connection, screen_index, atoms }) } pub fn screen_index(&self) -> i32 { self.screen_index } } pub trait HasDisplay { fn display(&self) -> &Arc; fn atoms(&self) -> &Atoms { &self.display().atoms } } impl HasDisplay for Arc { fn display(&self) -> &Arc { self } } pub trait DisplayExt: HasDisplay + HasConnection { fn screen(&self) -> &Screen { let setup = self.connection().get_setup(); let screen_index = self.display().screen_index() as usize; &setup.roots().nth(screen_index).unwrap() } } impl DisplayExt for T { }