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/context.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/x/context.rs (limited to 'src/x/context.rs') diff --git a/src/x/context.rs b/src/x/context.rs new file mode 100644 index 0000000..0a8d11e --- /dev/null +++ b/src/x/context.rs @@ -0,0 +1,44 @@ +use crate::x::*; + +use std::sync::Arc; + +use xcb::x::{ self, Drawable, CreateGc, FreeGc }; + + +pub struct GraphicContext { + display: Arc, + context_id: x::Gcontext, +} + + +impl GraphicContext { + pub fn new(display: Arc, drawable: Drawable) + -> xcb::Result + { + let context_id: x::Gcontext = display.generate_id(); + let cookie = display.send_request_checked(&CreateGc { + cid: context_id, + drawable, + value_list: &[], + }); + display.check_request(cookie)?; + + Ok(GraphicContext { display, context_id }) + } +} + +impl Drop for GraphicContext { + fn drop(&mut self) { + let cookie = self.send_request_checked(&FreeGc { gc: self.context_id }); + let _ = self.check_request(cookie); // TODO + } +} + +impl HasDisplay for GraphicContext { + fn display(&self) -> &Arc { &self.display } +} + +impl HasConnection for GraphicContext { + fn connection(&self) -> &Connection { self.display.connection() } +} + -- cgit 1.4.1