blob: 0fab0c8c353ce0ae47792a600c2515b7d36be03d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 { }
|