summaryrefslogtreecommitdiff
path: root/src/conn_info/colours.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/conn_info/colours.rs')
-rw-r--r--src/conn_info/colours.rs43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/conn_info/colours.rs b/src/conn_info/colours.rs
index d678bdb..a57538f 100644
--- a/src/conn_info/colours.rs
+++ b/src/conn_info/colours.rs
@@ -1,4 +1,7 @@
-use crate::error::Result;
+use crate::{
+ config::{BORDER_FOCUSED, BORDER_NORMAL},
+ error::Result,
+};
use xcb::{
x::{AllocColor, Colormap, FreeColors},
Connection as RawConnection,
@@ -17,18 +20,22 @@ impl Colours {
pub fn new_with(conn: &RawConnection, cmap: Colormap) -> Result<Self> {
// TODO: Move these colours out to config.rs
let (border_normal, border_focused) = (
- conn.wait_for_reply(conn.send_request(&AllocColor {
+ conn.send_request(&AllocColor {
cmap,
- red: 0,
- green: 0,
- blue: 0,
- }))?,
- conn.wait_for_reply(conn.send_request(&AllocColor {
+ red: BORDER_NORMAL.0,
+ green: BORDER_NORMAL.1,
+ blue: BORDER_NORMAL.2,
+ }),
+ conn.send_request(&AllocColor {
cmap,
- red: u16::MAX,
- green: 0,
- blue: u16::MAX,
- }))?,
+ red: BORDER_FOCUSED.0,
+ green: BORDER_FOCUSED.1,
+ blue: BORDER_FOCUSED.2,
+ }),
+ );
+ let (border_normal, border_focused) = (
+ conn.wait_for_reply(border_normal)?,
+ conn.wait_for_reply(border_focused)?,
);
Ok(Self {
@@ -58,3 +65,17 @@ impl Colours {
});
}
}
+
+/// RGB Colour helper struct to make configuration more convenient.
+pub struct Colour(u16, u16, u16);
+
+impl Colour {
+ /// Get colour from a hex value, such as `0xff00ff`. The top 8 bits are ignored.
+ pub const fn from_hex(hex: u32) -> Self {
+ Self(
+ ((hex >> 16 & 0xff) as u16) << 8,
+ ((hex >> 8 & 0xff) as u16) << 8,
+ ((hex & 0xff) as u16) << 8,
+ )
+ }
+}