summaryrefslogtreecommitdiff
path: root/src/conn_info/colours.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-06-21 21:00:25 +0100
committertcmal <me@aria.rip>2024-06-21 21:00:25 +0100
commit4579ebac1d049ec451d4e7c2619dc55ea911a9df (patch)
tree4573f2e87e6b48bc1749c387fcc10921f0d5c330 /src/conn_info/colours.rs
parent8d3bb2a4b5a3058b51ade1df41378077d5afc691 (diff)
move border colours to config
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,
+ )
+ }
+}