diff options
author | tcmal <me@aria.rip> | 2024-06-21 21:00:25 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-06-21 21:00:25 +0100 |
commit | 4579ebac1d049ec451d4e7c2619dc55ea911a9df (patch) | |
tree | 4573f2e87e6b48bc1749c387fcc10921f0d5c330 | |
parent | 8d3bb2a4b5a3058b51ade1df41378077d5afc691 (diff) |
move border colours to config
-rw-r--r-- | src/config.rs | 8 | ||||
-rw-r--r-- | src/conn_info/colours.rs | 43 | ||||
-rw-r--r-- | src/conn_info/mod.rs | 10 |
3 files changed, 47 insertions, 14 deletions
diff --git a/src/config.rs b/src/config.rs index c36a313..e6478b3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,17 @@ +#![allow(clippy::unreadable_literal)] // Colours are more readable this way imo use std::process::Command; use xcb::x::ModMask; use xkeysym::Keysym; -use crate::keys::{Keybind, Keybinds}; +use crate::{ + conn_info::Colour, + keys::{Keybind, Keybinds}, +}; pub const BORDER_WIDTH: u16 = 3; +pub const BORDER_NORMAL: Colour = Colour::from_hex(0x000000); +pub const BORDER_FOCUSED: Colour = Colour::from_hex(0xff0000); /// The keybinds to use. pub const KEYBINDS: Keybinds = Keybinds(&[Keybind { 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, + ) + } +} diff --git a/src/conn_info/mod.rs b/src/conn_info/mod.rs index 521bf3e..bd6f0cd 100644 --- a/src/conn_info/mod.rs +++ b/src/conn_info/mod.rs @@ -1,9 +1,10 @@ +use std::fmt::Debug; use xcb::{ x::{ self, ChangeProperty, ChangeWindowAttributes, CreateWindow, DeleteProperty, DestroyWindow, Window, WindowClass, }, - Connection as RawConnection, + Connection as RawConnection, Cookie, }; mod atoms; @@ -11,7 +12,12 @@ mod colours; mod cursors; mod keys; -pub use self::{atoms::Atoms, colours::Colours, cursors::Cursors, keys::KeyboardInfo}; +pub use self::{ + atoms::Atoms, + colours::{Colour, Colours}, + cursors::Cursors, + keys::KeyboardInfo, +}; use crate::error::{Error, Result}; /// The connection, along with some cached resources required for WM operations. |