From e521722f5fd339ef72ee51af88f3941b71b1d9cf Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Thu, 12 Nov 2026 22:40:42 -0700 Subject: okay, all the color stuff is well-organized now 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 --- src/x/color.rs | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/x/color.rs') 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 + -> xcb::Result { 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)) } } -- cgit 1.4.1