From 4579ebac1d049ec451d4e7c2619dc55ea911a9df Mon Sep 17 00:00:00 2001 From: tcmal Date: Fri, 21 Jun 2024 21:00:25 +0100 Subject: move border colours to config --- src/conn_info/colours.rs | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'src/conn_info/colours.rs') 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 { // 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, + ) + } +} -- cgit v1.2.3