From 960663d476d8a1391b8bcc4424f3f716147068ab Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 11 Nov 2026 21:03:30 -0700 Subject: all the xcb wrapper types are in individual files now the trait inheritance structure isn't THAT convoluted, but having more than one of these in a file was obscuring things. Change-Id: I5132a6304796654d778d731be1ecb1c7b4e77120 Force-Push: yes --- src/x/display.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/x/display.rs (limited to 'src/x/display.rs') 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 { + 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 { } + -- cgit 1.4.1