diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-12 22:40:42 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-12 22:40:42 -0700 |
| commit | e521722f5fd339ef72ee51af88f3941b71b1d9cf (patch) | |
| tree | 300734c3a95ad6c73908e8f203a1d70b53379be0 /src/x/color.rs | |
| parent | 9f61e842d01f910349458466c3749d92561f5cde (diff) | |
since color is one of those "the data is the point" types, rather than one that encapsulates remote state, both the xcb and xft stuff is handled by a single type, Color. Force-Push: yes Change-Id: I192c40b13dd9040897cbf043d5dd84d5a73f607b
Diffstat (limited to 'src/x/color.rs')
| -rw-r--r-- | src/x/color.rs | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/x/color.rs b/src/x/color.rs index 10ad651..d770379 100644 --- a/src/x/color.rs +++ b/src/x/color.rs @@ -7,9 +7,48 @@ use crate::x::connection::*; use crate::x::display::*; +use x11::xrender::XRenderColor; +use x11::xft::XftColor; use xcb::x::{ AllocColor, Visualtype }; +pub struct Color { + /* We need to store both the original 16-bit components and the pixel + * value. Additionally, there are situations in which we need to return + * an XftColor, which contains both of those. So, we might as well use it + * as the authoritative format. + * + * We treat the contents as opaque, to allow us to pretend it's + * something cleaner. :) + */ + font_color: XftColor, +} + + +impl Color { + /* Please notice that the constructor is private. */ + fn new(pixel: u32, red: u16, green: u16, blue: u16) -> Self { + Color { + font_color: XftColor { + pixel: pixel as u64, + color: XRenderColor { + red, green, blue, + alpha: 65535, + } + } + } + } + + pub fn as_pixel(&self) -> u32 { + self.font_color.pixel as u32 + } + + pub fn as_xft_color(&self) -> &XftColor { + &self.font_color + } +} + + pub trait DisplayColorExt: DisplayExt { /* This is sufficiently obscure knowledge that it's worth keeping here * even though it's unused. @@ -30,7 +69,7 @@ pub trait DisplayColorExt: DisplayExt { } fn allocate_color(&self, red: u16, green: u16, blue: u16) - -> xcb::Result<u32> + -> xcb::Result<Color> { let connection = self.connection(); @@ -41,7 +80,9 @@ pub trait DisplayColorExt: DisplayExt { red, green, blue, }); - Ok(connection.wait_for_reply(cookie)?.pixel()) + let pixel = connection.wait_for_reply(cookie)?.pixel(); + + Ok(Color::new(pixel, red, green, blue)) } } |