From 9ad8296732cacbd1a56dda9619b9e67cdc383241 Mon Sep 17 00:00:00 2001 From: missing <4a656666official@gmail.com> Date: Mon, 27 Jun 2022 10:45:22 -0500 Subject: [PATCH] focused border color --- src/config.rs | 7 +++++++ src/x11/client.rs | 33 +++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index e0644a3..c07ea6d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,6 +21,7 @@ use std::path::PathBuf; #[derive(Clone, Debug, Deserialize)] pub struct XcrabConfig { border_color: Option, + focused_color: Option, border_size: Option, gap_size: Option, pub msg: Option, @@ -32,6 +33,7 @@ pub struct XcrabMsgConfig { } const DEFAULT_BORDER_COLOR: u32 = 0xff_00_00; // red +const DEFAULT_FOCUSED_COLOR: u32 = 0x00_00_ff; // blue const DEFAULT_BORDER_SIZE: u16 = 5; const DEFAULT_GAP_SIZE: u16 = 10; @@ -39,6 +41,7 @@ impl Default for XcrabConfig { fn default() -> Self { Self { border_color: Some(DEFAULT_BORDER_COLOR), + focused_color: Some(DEFAULT_FOCUSED_COLOR), border_size: Some(DEFAULT_BORDER_SIZE), gap_size: Some(DEFAULT_GAP_SIZE), msg: None, // TODO: use a default socket path @@ -51,6 +54,10 @@ impl XcrabConfig { self.border_color.unwrap_or(DEFAULT_BORDER_COLOR) } + pub fn focused_color(&self) -> u32 { + self.focused_color.unwrap_or(DEFAULT_FOCUSED_COLOR) + } + pub fn border_size(&self) -> u16 { self.border_size.unwrap_or(DEFAULT_BORDER_SIZE) } diff --git a/src/x11/client.rs b/src/x11/client.rs index 63ee162..6af409b 100644 --- a/src/x11/client.rs +++ b/src/x11/client.rs @@ -14,7 +14,10 @@ // along with this program. If not, see . use breadx::prelude::{AsyncDisplayXprotoExt, SetMode}; -use breadx::{AsyncDisplay, BreadError, ConfigureWindowParameters, ErrorCode, EventMask, Window}; +use breadx::{ + AsyncDisplay, BreadError, ConfigureWindowParameters, ErrorCode, EventMask, Window, + WindowParameters, +}; use slotmap::{new_key_type, SlotMap}; use std::collections::HashMap; use std::future::Future; @@ -214,8 +217,7 @@ impl XcrabWindowManager { // ] // .choose(&mut rand::thread_rng()) // .unwrap(); - self.add_client_direction(conn, win, Direction::Right) - .await + self.add_client_direction(conn, win, Direction::Right).await } /// Adds a new client in the given direction from the focused window. @@ -393,7 +395,7 @@ impl XcrabWindowManager { self.clients.insert(win, new_rect_key); self.focused = Some(win); - + // update self.update_rectangle(conn, parent_key, None).await?; @@ -477,6 +479,7 @@ impl XcrabWindowManager { height: Some(dimensions.height.into()), ..Default::default() }, + self.focused.unwrap(), ) .await?; } @@ -512,8 +515,6 @@ impl XcrabWindowManager { .children .retain(|&v| v != client_key); - self.update_rectangle(conn, parent_key, None).await?; - self.clients.remove(&win); self.rects.remove(client_key); @@ -521,6 +522,8 @@ impl XcrabWindowManager { self.focused = Some(*self.clients.keys().next().unwrap()); } + self.update_rectangle(conn, parent_key, None).await?; + Ok(()) } } @@ -548,6 +551,7 @@ impl FramedWindow { self, conn: &mut Dpy, props: ConfigureWindowParameters, + focused_win: Window, ) -> Result<()> { let border_size = CONFIG.border_size(); let gap_size = CONFIG.gap_size(); @@ -558,6 +562,22 @@ impl FramedWindow { let width = props.width.map(|v| v - dimension_inset); let height = props.height.map(|v| v - dimension_inset); + let focused = focused_win == self.win; + + self.frame + .change_attributes_async( + conn, + WindowParameters { + border_pixel: Some(if focused { + CONFIG.focused_color() + } else { + CONFIG.border_color() + }), + ..Default::default() + }, + ) + .await?; + self.frame .configure_async( conn, @@ -621,6 +641,7 @@ async fn frame(conn: &mut Dpy, win: Window) -> Resul let frame = conn .create_simple_window_async( root, + // theoretically, all of these could be ignoring since they are set later geometry.x, geometry.y, geometry.width,