summaryrefslogtreecommitdiff
path: root/src/colours.rs
blob: 6f862c3a0c9b3c94d8138ab1a3bfee2660861f8c (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
use crate::error::*;
use xcb::{
    x::{AllocColor, Colormap},
    Connection,
};

pub struct Colours {
    cmap: Colormap,
    border_normal: u32,
    border_focused: u32,
}

impl Colours {
    pub fn new_with(conn: &Connection, cmap: Colormap) -> Result<Self> {
        let (border_normal, border_focused) = (
            conn.wait_for_reply(conn.send_request(&AllocColor {
                cmap,
                red: 0,
                green: 0,
                blue: 0,
            }))?,
            conn.wait_for_reply(conn.send_request(&AllocColor {
                cmap,
                red: u16::MAX,
                green: 0,
                blue: u16::MAX,
            }))?,
        );

        Ok(Self {
            cmap,
            border_normal: border_normal.pixel(),
            border_focused: border_focused.pixel(),
        })
    }

    pub fn border_normal(&self) -> u32 {
        self.border_normal
    }

    pub fn border_focused(&self) -> u32 {
        self.border_focused
    }
}