diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-11 17:31:19 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-11 18:01:29 -0700 |
| commit | c5f15297d53904ecfb1e2e6e2df915e380eff2e0 (patch) | |
| tree | 408a195c22542e9cb374a0ac6aca565839a347d0 /src/xcolor.rs | |
| parent | cc1bed1f1f3e26a6a00b292ace94b6991c181ff9 (diff) | |
do proper color management
well, sort of. we can't test indexed color, so there's no code specifically accounting for it. ah well. Change-Id: Ic12854c17fd7d433a7ee129ad5663d1bdb2ee541 Force-Push: yes
Diffstat (limited to 'src/xcolor.rs')
| -rw-r--r-- | src/xcolor.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/xcolor.rs b/src/xcolor.rs new file mode 100644 index 0000000..0fab0c8 --- /dev/null +++ b/src/xcolor.rs @@ -0,0 +1,46 @@ +/* Color management in X has become an obscure topic because everyone prefers + * to assume they have 24-bit direct. In dealing with it, [1] has been an + * important resource. + * + * [1] https://xcb.freedesktop.org/xlibtoxcbtranslationguide/ + */ +use crate::xtypes::*; + +use xcb::x::{ AllocColor, Visualtype }; + + +pub trait DisplayColorExt: DisplayExt { + /* This is sufficiently obscure knowledge that it's worth keeping here + * even though it's unused. + */ + #[allow(dead_code)] + fn find_root_visual(&self) -> Option<&Visualtype> { + let visual_id = self.screen().root_visual(); + + for depth in self.screen().allowed_depths() { + for visual in depth.visuals() { + if visual_id == visual.visual_id() { + return Some(visual); + } + } + } + + None + } + + fn allocate_color(&self, red: u16, green: u16, blue: u16) + -> xcb::Result<u32> + { + let colormap = self.screen().default_colormap(); + + let cookie = self.send_request(&AllocColor { + cmap: colormap, + red, green, blue, + }); + + Ok(self.wait_for_reply(cookie)?.pixel()) + } +} + +impl<T: DisplayExt> DisplayColorExt for T { } + |