Skip to content

Commit

Permalink
initial support for inactive border
Browse files Browse the repository at this point in the history
  • Loading branch information
codic13 committed Oct 17, 2021
1 parent e537797 commit dcdcd4b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 18 deletions.
10 changes: 8 additions & 2 deletions examples/autostart
Expand Up @@ -19,5 +19,11 @@ xfce4-terminal
# Set border width to 1 px
wormc border-width 1

# Set border color (base 10 value). F.e.: 0x1793D1 -> 1545169
wormc border-pixel 1545169
# Set border color (base 16 value). F.e.: 0x1793D1 -> 1545169
# The first two characters are used as the opacity if you are running a compositor.
# If you want a solid frame, use FFRRGGBB. (note: these characters can technically
# be anywhere because it isn't part of the X standard, but in reality on sane
# servers they are the first two).

wormc active-border-pixel $((16#FF1793D1))
wormc inactive-border-pixel $((16#FF7A8478))
8 changes: 6 additions & 2 deletions src/ipc.rs
Expand Up @@ -10,7 +10,8 @@ pub enum IPC {
ClientMessage,
KillActiveClient,
SwitchTag,
BorderPixel,
ActiveBorderPixel,
InactiveBorderPixel,
BorderWidth,
BackgroundPixel,
TitleHeight,
Expand All @@ -34,7 +35,10 @@ where
.reply()?
.atom,
conn.intern_atom(false, b"_WORM_SWITCH_TAG")?.reply()?.atom,
conn.intern_atom(false, b"_WORM_BORDER_PIXEL")?
conn.intern_atom(false, b"_WORM_ACTIVE_BORDER_PIXEL")?
.reply()?
.atom,
conn.intern_atom(false, b"_WORM_INACTIVE_BORDER_PIXEL")?
.reply()?
.atom,
conn.intern_atom(false, b"_WORM_BORDER_WIDTH")?
Expand Down
75 changes: 63 additions & 12 deletions src/wm.rs
Expand Up @@ -38,7 +38,8 @@ struct Client {
struct Config {
pub border_width: u32,
pub title_height: u32,
pub border_pixel: u32,
pub active_border_pixel: u32,
pub inactive_border_pixel: u32,
pub background_pixel: u32,
}

Expand Down Expand Up @@ -193,7 +194,8 @@ where
config: Config {
border_width: 3,
title_height: 15,
border_pixel: 0xFFC3A070,
active_border_pixel: 0xFFC3A070,
inactive_border_pixel: 0xFF000000,
background_pixel: 0xFF291E1B,
//background_pixel: 0xFFFFFFFF,
},
Expand Down Expand Up @@ -324,7 +326,7 @@ where
| xproto::EventMask::PROPERTY_CHANGE,
)
.background_pixel(self.config.background_pixel)
.border_pixel(self.config.border_pixel)
.border_pixel(self.config.active_border_pixel)
.colormap(attr.colormap);
self.conn.create_window(
geom.depth,
Expand Down Expand Up @@ -388,6 +390,18 @@ where
.event_mask(xproto::EventMask::PROPERTY_CHANGE),
)?
.check()?;
for (idx, client) in self.clients.iter().enumerate() {
if idx != self.clients.len() - 1 {
// it's not the one we currently added
self.conn
.change_window_attributes(
client.frame,
&xproto::ChangeWindowAttributesAux::new()
.border_pixel(self.config.inactive_border_pixel),
)?
.check()?;
}
}
Ok(())
}

Expand All @@ -398,10 +412,19 @@ where
self.conn
.set_input_focus(xproto::InputFocus::PARENT, client.window, CURRENT_TIME)?
.check()?;
self.conn.configure_window(
client.frame,
&xproto::ConfigureWindowAux::new().stack_mode(xproto::StackMode::ABOVE),
)?;
self.conn
.configure_window(
client.frame,
&xproto::ConfigureWindowAux::new().stack_mode(xproto::StackMode::ABOVE),
)?
.check()?;
self.conn
.change_window_attributes(
client.frame,
&xproto::ChangeWindowAttributesAux::new()
.border_pixel(self.config.active_border_pixel),
)?
.check()?;
if let Ok(geom) = self.conn.get_geometry(ev.child)?.reply() {
self.button_press_geometry = Some(Geometry {
x: geom.x,
Expand All @@ -417,6 +440,17 @@ where
});
}
self.focused = Some(client_idx);
for (idx, client) in self.clients.iter().enumerate() {
if idx != client_idx {
self.conn
.change_window_attributes(
client.frame,
&xproto::ChangeWindowAttributesAux::new()
.border_pixel(self.config.inactive_border_pixel),
)?
.check()?;
}
}
Ok(())
}

Expand Down Expand Up @@ -596,7 +630,6 @@ where
}

fn handle_client_message(&mut self, ev: &xproto::ClientMessageEvent) -> Result<()> {
println!("ClientMessage");
// EWMH § _NET_WM_STATE; sent as a ClientMessage. in this the only thing we handle right
// now is fullscreen messages.
if ev.type_ == self.net_atoms[ewmh::Net::WMState as usize] {
Expand Down Expand Up @@ -718,14 +751,32 @@ where
.check()?;
self.update_tag_state()?;
}
data if data[0] == ipc::IPC::BorderPixel as u32 => {
self.config.border_pixel = data[1];
for client in self.clients.iter() {
data if data[0] == ipc::IPC::ActiveBorderPixel as u32 => {
self.config.active_border_pixel = data[1];
for (idx, client) in self.clients.iter().enumerate() {
if idx != self.focused.ok_or("client_message: no focused window")? {
continue;
}
self.conn
.change_window_attributes(
client.frame,
&xproto::ChangeWindowAttributesAux::new()
.border_pixel(self.config.active_border_pixel),
)?
.check()?;
}
}
data if data[0] == ipc::IPC::InactiveBorderPixel as u32 => {
self.config.inactive_border_pixel = data[1];
for (idx, client) in self.clients.iter().enumerate() {
if idx == self.focused.ok_or("client_message: no focused window")? {
continue;
}
self.conn
.change_window_attributes(
client.frame,
&xproto::ChangeWindowAttributesAux::new()
.border_pixel(self.config.border_pixel),
.border_pixel(self.config.inactive_border_pixel),
)?
.check()?;
}
Expand Down
11 changes: 9 additions & 2 deletions src/wormc.rs
Expand Up @@ -23,8 +23,15 @@ fn main() -> Result<()> {
match args[1].as_ref() {
"kill-active-client" => [ipc::IPC::KillActiveClient as u32, 0, 0, 0, 0],
"switch-tag" => [ipc::IPC::SwitchTag as u32, args[2].parse::<u32>()?, 0, 0, 0],
"border-pixel" => [
ipc::IPC::BorderPixel as u32,
"active-border-pixel" => [
ipc::IPC::ActiveBorderPixel as u32,
args[2].parse::<u32>()?,
0,
0,
0,
],
"inactive-border-pixel" => [
ipc::IPC::InactiveBorderPixel as u32,
args[2].parse::<u32>()?,
0,
0,
Expand Down

0 comments on commit dcdcd4b

Please sign in to comment.