forked from InfoshockTech/xcrab
focused border color
This commit is contained in:
parent
6407d4ec0e
commit
9ad8296732
|
@ -21,6 +21,7 @@ use std::path::PathBuf;
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct XcrabConfig {
|
pub struct XcrabConfig {
|
||||||
border_color: Option<u32>,
|
border_color: Option<u32>,
|
||||||
|
focused_color: Option<u32>,
|
||||||
border_size: Option<u16>,
|
border_size: Option<u16>,
|
||||||
gap_size: Option<u16>,
|
gap_size: Option<u16>,
|
||||||
pub msg: Option<XcrabMsgConfig>,
|
pub msg: Option<XcrabMsgConfig>,
|
||||||
|
@ -32,6 +33,7 @@ pub struct XcrabMsgConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_BORDER_COLOR: u32 = 0xff_00_00; // red
|
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_BORDER_SIZE: u16 = 5;
|
||||||
const DEFAULT_GAP_SIZE: u16 = 10;
|
const DEFAULT_GAP_SIZE: u16 = 10;
|
||||||
|
|
||||||
|
@ -39,6 +41,7 @@ impl Default for XcrabConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
border_color: Some(DEFAULT_BORDER_COLOR),
|
border_color: Some(DEFAULT_BORDER_COLOR),
|
||||||
|
focused_color: Some(DEFAULT_FOCUSED_COLOR),
|
||||||
border_size: Some(DEFAULT_BORDER_SIZE),
|
border_size: Some(DEFAULT_BORDER_SIZE),
|
||||||
gap_size: Some(DEFAULT_GAP_SIZE),
|
gap_size: Some(DEFAULT_GAP_SIZE),
|
||||||
msg: None, // TODO: use a default socket path
|
msg: None, // TODO: use a default socket path
|
||||||
|
@ -51,6 +54,10 @@ impl XcrabConfig {
|
||||||
self.border_color.unwrap_or(DEFAULT_BORDER_COLOR)
|
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 {
|
pub fn border_size(&self) -> u16 {
|
||||||
self.border_size.unwrap_or(DEFAULT_BORDER_SIZE)
|
self.border_size.unwrap_or(DEFAULT_BORDER_SIZE)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,10 @@
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use breadx::prelude::{AsyncDisplayXprotoExt, SetMode};
|
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 slotmap::{new_key_type, SlotMap};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
@ -214,8 +217,7 @@ impl XcrabWindowManager {
|
||||||
// ]
|
// ]
|
||||||
// .choose(&mut rand::thread_rng())
|
// .choose(&mut rand::thread_rng())
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
self.add_client_direction(conn, win, Direction::Right)
|
self.add_client_direction(conn, win, Direction::Right).await
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a new client in the given direction from the focused window.
|
/// 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.clients.insert(win, new_rect_key);
|
||||||
|
|
||||||
self.focused = Some(win);
|
self.focused = Some(win);
|
||||||
|
|
||||||
// update
|
// update
|
||||||
self.update_rectangle(conn, parent_key, None).await?;
|
self.update_rectangle(conn, parent_key, None).await?;
|
||||||
|
|
||||||
|
@ -477,6 +479,7 @@ impl XcrabWindowManager {
|
||||||
height: Some(dimensions.height.into()),
|
height: Some(dimensions.height.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
self.focused.unwrap(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
@ -512,8 +515,6 @@ impl XcrabWindowManager {
|
||||||
.children
|
.children
|
||||||
.retain(|&v| v != client_key);
|
.retain(|&v| v != client_key);
|
||||||
|
|
||||||
self.update_rectangle(conn, parent_key, None).await?;
|
|
||||||
|
|
||||||
self.clients.remove(&win);
|
self.clients.remove(&win);
|
||||||
self.rects.remove(client_key);
|
self.rects.remove(client_key);
|
||||||
|
|
||||||
|
@ -521,6 +522,8 @@ impl XcrabWindowManager {
|
||||||
self.focused = Some(*self.clients.keys().next().unwrap());
|
self.focused = Some(*self.clients.keys().next().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.update_rectangle(conn, parent_key, None).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,6 +551,7 @@ impl FramedWindow {
|
||||||
self,
|
self,
|
||||||
conn: &mut Dpy,
|
conn: &mut Dpy,
|
||||||
props: ConfigureWindowParameters,
|
props: ConfigureWindowParameters,
|
||||||
|
focused_win: Window,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let border_size = CONFIG.border_size();
|
let border_size = CONFIG.border_size();
|
||||||
let gap_size = CONFIG.gap_size();
|
let gap_size = CONFIG.gap_size();
|
||||||
|
@ -558,6 +562,22 @@ impl FramedWindow {
|
||||||
let width = props.width.map(|v| v - dimension_inset);
|
let width = props.width.map(|v| v - dimension_inset);
|
||||||
let height = props.height.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
|
self.frame
|
||||||
.configure_async(
|
.configure_async(
|
||||||
conn,
|
conn,
|
||||||
|
@ -621,6 +641,7 @@ async fn frame<Dpy: AsyncDisplay + ?Sized>(conn: &mut Dpy, win: Window) -> Resul
|
||||||
let frame = conn
|
let frame = conn
|
||||||
.create_simple_window_async(
|
.create_simple_window_async(
|
||||||
root,
|
root,
|
||||||
|
// theoretically, all of these could be ignoring since they are set later
|
||||||
geometry.x,
|
geometry.x,
|
||||||
geometry.y,
|
geometry.y,
|
||||||
geometry.width,
|
geometry.width,
|
||||||
|
|
Loading…
Reference in a new issue