From 89a6a257f89bba997e778160c53938be371ec6ac Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 11 Nov 2026 20:39:00 -0700 Subject: graphics contexts! with RAII! much trait refactoring the way forward to structure this cleanly is clear now, as well, but not implemented yet Force-Push: yes Change-Id: Ib3905edcfd49bf19d0fa7e4285f2edfed312d539 --- src/xtypes.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/xtypes.rs') diff --git a/src/xtypes.rs b/src/xtypes.rs index 3f67e58..89bb622 100644 --- a/src/xtypes.rs +++ b/src/xtypes.rs @@ -2,6 +2,7 @@ use std::borrow::Borrow; use std::sync::Arc; use std::ops::Deref; +use xcb::XidNew; use xcb::x::{ self, Atom, @@ -10,7 +11,7 @@ use xcb::x::{ InternAtom, MapWindow, PropMode, - Screen + Screen, }; @@ -72,7 +73,7 @@ impl Window { let display_ref: &Display = display.borrow(); let connection: &Connection = &display_ref.connection; - let window_id: x::Window = connection.0.generate_id(); + let window_id: x::Window = connection.generate_id(); create_window.wid = window_id; let cookie = connection.send_request_checked(create_window); @@ -136,27 +137,37 @@ impl HasConnection for Connection { fn connection(&self) -> &Connection { self } } -impl HasConnection for T { - fn connection(&self) -> &Connection { &self.display().connection } +impl HasConnection for Arc { + fn connection(&self) -> &Connection { &self.connection } +} + +impl HasConnection for Window { + fn connection(&self) -> &Connection { &self.display.connection } } pub trait HasDisplay { - fn display(&self) -> &Display; + fn display(&self) -> &Arc; fn atoms(&self) -> &Atoms { &self.display().atoms } } -impl HasDisplay for Display { - fn display(&self) -> &Display { self } +impl HasDisplay for Arc { + fn display(&self) -> &Arc { self } } -impl HasDisplay for T { - fn display(&self) -> &Display { self.window().display.borrow() } +impl HasDisplay for Window { + fn display(&self) -> &Arc { &self.display } } pub trait ConnectionExt: HasConnection { + fn generate_id(&self) -> T { + let connection = self.connection(); + + connection.0.generate_id() + } + fn get_atom(&self, name: &[u8]) -> xcb::Result { let connection = self.connection(); -- cgit 1.4.1