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() } }