summaryrefslogtreecommitdiff
path: root/src/conn_info/colours.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-06-21 19:13:12 +0100
committertcmal <me@aria.rip>2024-06-21 19:13:12 +0100
commit475253b7bcfd03a932c4b7efd969b3d2bf155035 (patch)
tree44789ce271d14c89cbff777e75f1e9ab6e1a5e64 /src/conn_info/colours.rs
parentc3e98e34ed7d42ef4271339de88f7131e7647442 (diff)
refactor connection-related stuff out, make things a bit cleaner
Diffstat (limited to 'src/conn_info/colours.rs')
-rw-r--r--src/conn_info/colours.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/conn_info/colours.rs b/src/conn_info/colours.rs
new file mode 100644
index 0000000..22b4fc2
--- /dev/null
+++ b/src/conn_info/colours.rs
@@ -0,0 +1,50 @@
+use crate::error::Result;
+use xcb::{
+ x::{AllocColor, Colormap},
+ Connection,
+};
+
+/// Caches colours in an X11 color map.
+pub struct Colours {
+ #[allow(unused)] // Make sure the colour map we're using doesn't go anywhere
+ cmap: Colormap,
+ border_normal: u32,
+ border_focused: u32,
+}
+
+impl Colours {
+ /// Load the colours into the given colour map
+ pub fn new_with(conn: &Connection, 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 {
+ 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(),
+ })
+ }
+
+ /// Get the pixel ID of the colour for an unfocused window's border.
+ pub const fn border_normal(&self) -> u32 {
+ self.border_normal
+ }
+
+ /// Get the pixel ID of the colour for a focused window's border.
+ pub const fn border_focused(&self) -> u32 {
+ self.border_focused
+ }
+}