diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-11 22:15:21 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-11 22:15:21 -0700 |
| commit | cea4c230b40d5ea2851ed3f97f73b2554849dc34 (patch) | |
| tree | b4050e1f499c81df4d9a2fe368c2ebcc7d9e982b /src/x/context.rs | |
| parent | 960663d476d8a1391b8bcc4424f3f716147068ab (diff) | |
moves towards nontrivial drawing
also, a little cleanup of trait consistency Force-Push: yes Change-Id: I71e07685d605ec93d98982b3660dcd8d154f8d9d
Diffstat (limited to 'src/x/context.rs')
| -rw-r--r-- | src/x/context.rs | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/x/context.rs b/src/x/context.rs index 0a8d11e..9e3796d 100644 --- a/src/x/context.rs +++ b/src/x/context.rs @@ -2,12 +2,20 @@ use crate::x::*; use std::sync::Arc; -use xcb::x::{ self, Drawable, CreateGc, FreeGc }; +use xcb::x::{ Drawable, CreateGc, FreeGc }; pub struct GraphicContext { display: Arc<Display>, - context_id: x::Gcontext, + context_id: xcb::x::Gcontext, +} + +impl HasDisplay for GraphicContext { + fn display(&self) -> &Arc<Display> { &self.display } +} + +impl HasConnection for GraphicContext { + fn connection(&self) -> &Connection { self.display.connection() } } @@ -15,7 +23,7 @@ impl GraphicContext { pub fn new(display: Arc<Display>, drawable: Drawable) -> xcb::Result<Self> { - let context_id: x::Gcontext = display.generate_id(); + let context_id: xcb::x::Gcontext = display.generate_id(); let cookie = display.send_request_checked(&CreateGc { cid: context_id, drawable, @@ -34,11 +42,22 @@ impl Drop for GraphicContext { } } -impl HasDisplay for GraphicContext { - fn display(&self) -> &Arc<Display> { &self.display } + +pub trait HasGraphicContext { + fn graphic_context(&self) -> &GraphicContext; } -impl HasConnection for GraphicContext { - fn connection(&self) -> &Connection { self.display.connection() } +impl HasGraphicContext for GraphicContext { + fn graphic_context(&self) -> &GraphicContext { self } } + + +pub trait GraphicContextExt: HasGraphicContext + HasDisplay + HasConnection { + fn graphic_context_id(&self) -> xcb::x::Gcontext { + self.graphic_context().context_id + } +} + +impl<T: HasGraphicContext + HasDisplay + HasConnection> GraphicContextExt for T { } + |