diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-11 20:39:00 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-11 20:39:00 -0700 |
| commit | 89a6a257f89bba997e778160c53938be371ec6ac (patch) | |
| tree | 96972e8ebb82cc6363eb8112944bc52c86221755 /src/xtypes.rs | |
| parent | c5f15297d53904ecfb1e2e6e2df915e380eff2e0 (diff) | |
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
Diffstat (limited to 'src/xtypes.rs')
| -rw-r--r-- | src/xtypes.rs | 29 |
1 files changed, 20 insertions, 9 deletions
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<T: HasDisplay> HasConnection for T { - fn connection(&self) -> &Connection { &self.display().connection } +impl HasConnection for Arc<Display> { + 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<Display>; fn atoms(&self) -> &Atoms { &self.display().atoms } } -impl HasDisplay for Display { - fn display(&self) -> &Display { self } +impl HasDisplay for Arc<Display> { + fn display(&self) -> &Arc<Display> { self } } -impl<T: HasWindow> HasDisplay for T { - fn display(&self) -> &Display { self.window().display.borrow() } +impl HasDisplay for Window { + fn display(&self) -> &Arc<Display> { &self.display } } pub trait ConnectionExt: HasConnection { + fn generate_id<T: XidNew>(&self) -> T { + let connection = self.connection(); + + connection.0.generate_id() + } + fn get_atom(&self, name: &[u8]) -> xcb::Result<Atom> { let connection = self.connection(); |