diff options
| -rw-r--r-- | src/main.rs | 11 | ||||
| -rw-r--r-- | src/xcolor.rs | 46 |
2 files changed, 55 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 436fcfa..2c07e95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use crate::xtypes::*; +use crate::xcolor::DisplayColorExt; use std::sync::Arc; @@ -12,6 +13,7 @@ use xcb::x::{ WindowClass }; +mod xcolor; mod xtypes; @@ -21,6 +23,7 @@ enum ScreenSide { Top, Bottom, Left, Right } struct DockConfiguration { thickness: u16, side: ScreenSide, + background_pixel: u32, } struct Dock { @@ -46,9 +49,13 @@ struct Rectangle<T> { fn main() -> xcb::Result<()> { let display = Arc::new(Display::new()?); + // #d4ffcc + let background_pixel = display.allocate_color(54484, 65535, 52428)?; + let _dock = Dock::new(Arc::clone(&display), DockConfiguration { thickness: 50, side: ScreenSide::Bottom, + background_pixel, })?; loop { @@ -81,6 +88,7 @@ impl Dock { let dock_bounds = Dock::compute_bounds(&screen, &configuration); + println!("back pixel {:?}", configuration.background_pixel); let window = Window::new(Arc::clone(&display), &mut CreateWindow { depth: x::COPY_FROM_PARENT as u8, wid: x::Window::none(), @@ -93,7 +101,7 @@ impl Dock { class: WindowClass::InputOutput, visual: screen.root_visual(), value_list: &[ - Cw::BackPixel(screen.black_pixel()), + Cw::BackPixel(configuration.background_pixel), Cw::EventMask(EventMask::EXPOSURE | EventMask::BUTTON_PRESS), ], })?; @@ -189,6 +197,5 @@ impl Dock { Rectangle { left, top, width, height } } } - } 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 { } + |