From cea4c230b40d5ea2851ed3f97f73b2554849dc34 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 11 Nov 2026 22:15:21 -0700 Subject: moves towards nontrivial drawing also, a little cleanup of trait consistency Force-Push: yes Change-Id: I71e07685d605ec93d98982b3660dcd8d154f8d9d --- src/x/context.rs | 33 ++++++++++++++++++++++++++------- src/x/window.rs | 26 +++++++++++--------------- 2 files changed, 37 insertions(+), 22 deletions(-) (limited to 'src/x') 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, - context_id: x::Gcontext, + context_id: xcb::x::Gcontext, +} + +impl HasDisplay for GraphicContext { + fn display(&self) -> &Arc { &self.display } +} + +impl HasConnection for GraphicContext { + fn connection(&self) -> &Connection { self.display.connection() } } @@ -15,7 +23,7 @@ impl GraphicContext { pub fn new(display: Arc, drawable: Drawable) -> xcb::Result { - 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 { &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 GraphicContextExt for T { } + diff --git a/src/x/window.rs b/src/x/window.rs index d264eb9..a1a4a19 100644 --- a/src/x/window.rs +++ b/src/x/window.rs @@ -18,6 +18,13 @@ pub struct Window { window_id: x::Window, } +impl HasConnection for Window { + fn connection(&self) -> &Connection { self.display.connection() } +} + +impl HasDisplay for Window { + fn display(&self) -> &Arc { &self.display } +} impl Window { @@ -39,8 +46,6 @@ impl Window { pub trait HasWindow { fn window(&self) -> &Window; - - fn window_id(&self) -> x::Window { self.window().window_id } } impl HasWindow for Window { @@ -52,19 +57,11 @@ impl> HasWindow for T { } -impl HasConnection for Window { - fn connection(&self) -> &Connection { self.display.connection() } -} - - -impl HasDisplay for Window { - fn display(&self) -> &Arc { &self.display } -} - - - - pub trait WindowExt: HasWindow + HasDisplay + HasConnection { + fn window_id(&self) -> x::Window { + self.window().window_id + } + fn map_window(&self) -> xcb::Result<()> { let connection = self.connection(); @@ -111,7 +108,6 @@ pub trait WindowExt: HasWindow + HasDisplay + HasConnection { Ok(()) } - fn set_cardinal_property(&self, property: &Atom, values: &[u32]) -> xcb::Result<()> { -- cgit 1.4.1