summary refs log tree commit diff
path: root/src/xcontext.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-11 20:39:00 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-11 20:39:00 -0700
commit89a6a257f89bba997e778160c53938be371ec6ac (patch)
tree96972e8ebb82cc6363eb8112944bc52c86221755 /src/xcontext.rs
parentc5f15297d53904ecfb1e2e6e2df915e380eff2e0 (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/xcontext.rs')
-rw-r--r--src/xcontext.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/xcontext.rs b/src/xcontext.rs
new file mode 100644
index 0000000..d9543f7
--- /dev/null
+++ b/src/xcontext.rs
@@ -0,0 +1,44 @@
+use crate::xtypes::*;
+
+use std::sync::Arc;
+
+use xcb::x::{ self, Drawable, CreateGc, FreeGc };
+
+
+pub struct GraphicContext {
+  display: Arc<Display>,
+  context_id: x::Gcontext,
+}
+
+
+impl GraphicContext {
+  pub fn new(display: Arc<Display>, drawable: Drawable)
+    -> xcb::Result<Self>
+  {
+    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<Display> { &self.display }
+}
+
+impl HasConnection for GraphicContext {
+  fn connection(&self) -> &Connection { self.display.connection() }
+}
+