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 | |
| parent | 960663d476d8a1391b8bcc4424f3f716147068ab (diff) | |
moves towards nontrivial drawing
also, a little cleanup of trait consistency Force-Push: yes Change-Id: I71e07685d605ec93d98982b3660dcd8d154f8d9d
| -rw-r--r-- | src/main.rs | 19 | ||||
| -rw-r--r-- | src/x.rs | 2 | ||||
| -rw-r--r-- | src/x/context.rs | 33 | ||||
| -rw-r--r-- | src/x/window.rs | 26 |
4 files changed, 47 insertions, 33 deletions
diff --git a/src/main.rs b/src/main.rs index 51cb7bf..5ad82a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -206,20 +206,19 @@ impl Dock { println!("redraw"); let drawable = Drawable::Window(self.window_id()); - let _context = GraphicContext::new(Arc::clone(self.display()), - drawable); + let context = GraphicContext::new( + Arc::clone(self.display()), drawable)?; - /* let black = self.screen().black_pixel(); - let cookie = connection.send_request_checked(&PolyFillRectangle { - drawable: Drawable::Window(self.window_id()), - property: *property, - r#type: xcb::x::ATOM_CARDINAL, - data: values, + let cookie = self.send_request_checked(&PolyFillRectangle { + drawable: drawable, + gc: context.graphic_context_id(), + rectangles: &[xcb::x::Rectangle { + x: 0, y: 0, width: 25, height: 25 + }], }); - connection.check_request(cookie)?; - */ + self.check_request(cookie)?; Ok(()) } diff --git a/src/x.rs b/src/x.rs index dcef69b..d4eadfc 100644 --- a/src/x.rs +++ b/src/x.rs @@ -1,5 +1,5 @@ pub use color::DisplayColorExt; -pub use context::GraphicContext; +pub use context::{ GraphicContext, HasGraphicContext, GraphicContextExt }; pub use connection::{ Connection, HasConnection, ConnectionExt }; pub use display::{ Display, HasDisplay, DisplayExt }; pub use window::{ Window, HasWindow, WindowExt }; 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 { } + 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<Display> { &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<T: Deref<Target=Window>> HasWindow for T { } -impl HasConnection for Window { - fn connection(&self) -> &Connection { self.display.connection() } -} - - -impl HasDisplay for Window { - fn display(&self) -> &Arc<Display> { &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<()> { |