diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-11 21:03:30 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-11 21:32:53 -0700 |
| commit | 960663d476d8a1391b8bcc4424f3f716147068ab (patch) | |
| tree | 3bf7e3372295f67c4afcad07c0b74e23624ab60f /src/x/color.rs | |
| parent | 89a6a257f89bba997e778160c53938be371ec6ac (diff) | |
all the xcb wrapper types are in individual files now
the trait inheritance structure isn't THAT convoluted, but having more than one of these in a file was obscuring things. Change-Id: I5132a6304796654d778d731be1ecb1c7b4e77120 Force-Push: yes
Diffstat (limited to 'src/x/color.rs')
| -rw-r--r-- | src/x/color.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/x/color.rs b/src/x/color.rs new file mode 100644 index 0000000..10ad651 --- /dev/null +++ b/src/x/color.rs @@ -0,0 +1,49 @@ +/* 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::x::connection::*; +use crate::x::display::*; + +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 connection = self.connection(); + + let colormap = self.screen().default_colormap(); + + let cookie = connection.send_request(&AllocColor { + cmap: colormap, + red, green, blue, + }); + + Ok(connection.wait_for_reply(cookie)?.pixel()) + } +} + +impl<T: DisplayExt> DisplayColorExt for T { } + |