diff options
Diffstat (limited to 'src/x/display.rs')
| -rw-r--r-- | src/x/display.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/x/display.rs b/src/x/display.rs new file mode 100644 index 0000000..ca552db --- /dev/null +++ b/src/x/display.rs @@ -0,0 +1,56 @@ +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<Display> { + fn connection(&self) -> &Connection { &self.connection } +} + + +impl Display { + pub fn new() -> xcb::Result<Display> { + 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<Display>; + + fn atoms(&self) -> &Atoms { &self.display().atoms } +} + +impl HasDisplay for Arc<Display> { + fn display(&self) -> &Arc<Display> { 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<T: HasDisplay + HasConnection> DisplayExt for T { } + |