Skip to content

Commit

Permalink
fix: #312 removing window borders when setting a client to fullscreen…
Browse files Browse the repository at this point in the history
… via ewmh hooks
  • Loading branch information
sminez committed Oct 15, 2024
1 parent 331a081 commit 74962e5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
36 changes: 31 additions & 5 deletions examples/ewmh_compatability/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,29 @@
//! `penrose::extensions::hooks::ewmh`.
use penrose::{
builtin::{
actions::{exit, log_current_state, modify_with, send_layout_message, spawn},
actions::{
exit,
floating::{sink_focused, MouseDragHandler, MouseResizeHandler},
log_current_state, modify_with, send_layout_message, spawn,
},
layout::{
messages::{ExpandMain, IncMain, ShrinkMain},
transformers::{Gaps, ReflectHorizontal, ReserveTop},
MainAndStack,
},
},
core::{
bindings::{parse_keybindings_with_xmodmap, KeyEventHandler},
bindings::{
click_handler, parse_keybindings_with_xmodmap, KeyEventHandler, MouseEventHandler,
MouseState,
},
layout::LayoutStack,
Config, WindowManager,
},
extensions::hooks::{add_ewmh_hooks, SpawnOnStartup},
extensions::{
actions::toggle_fullscreen,
hooks::{add_ewmh_hooks, SpawnOnStartup},
},
map, stack,
x11rb::RustConn,
Result,
Expand All @@ -32,7 +42,6 @@ use tracing_subscriber::{self, prelude::*};

fn raw_key_bindings() -> HashMap<String, Box<dyn KeyEventHandler<RustConn>>> {
let mut raw_bindings = map! {
// map_keys: |k: &str| format!("C-{k}");
map_keys: |k: &str| k.to_owned();

"M-j" => modify_with(|cs| cs.focus_down()),
Expand All @@ -53,6 +62,8 @@ fn raw_key_bindings() -> HashMap<String, Box<dyn KeyEventHandler<RustConn>>> {
"M-S-s" => log_current_state(),
"M-Return" => spawn("st"),
"M-A-Escape" => exit(),

"M-S-f" => toggle_fullscreen(),
};

for tag in &["1", "2", "3", "4", "5", "6", "7", "8", "9"] {
Expand All @@ -71,6 +82,21 @@ fn raw_key_bindings() -> HashMap<String, Box<dyn KeyEventHandler<RustConn>>> {
raw_bindings
}

fn mouse_bindings() -> HashMap<MouseState, Box<dyn MouseEventHandler<RustConn>>> {
use penrose::core::bindings::{
ModifierKey::{Meta, Shift},
MouseButton::{Left, Middle, Right},
};

map! {
map_keys: |(button, modifiers)| MouseState { button, modifiers };

(Left, vec![Shift, Meta]) => MouseDragHandler::boxed_default(),
(Right, vec![Shift, Meta]) => MouseResizeHandler::boxed_default(),
(Middle, vec![Shift, Meta]) => click_handler(sink_focused()),
}
}

fn layouts() -> LayoutStack {
let max_main = 1;
let ratio = 0.6;
Expand Down Expand Up @@ -104,7 +130,7 @@ fn main() -> Result<()> {

let conn = RustConn::new()?;
let key_bindings = parse_keybindings_with_xmodmap(raw_key_bindings())?;
let wm = WindowManager::new(config, key_bindings, HashMap::new(), conn)?;
let wm = WindowManager::new(config, key_bindings, mouse_bindings(), conn)?;

wm.run()
}
5 changes: 4 additions & 1 deletion src/extensions/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
builtin::actions::{key_handler, modify_with},
core::{bindings::KeyEventHandler, layout::LayoutStack, State},
util::spawn,
x::{atom::Atom, property::Prop, XConn, XConnExt},
x::{atom::Atom, property::Prop, ClientConfig, XConn, XConnExt},
Error, Result, Xid,
};
use tracing::{debug, error};
Expand Down Expand Up @@ -52,9 +52,12 @@ pub fn set_fullscreen_state<X: XConn>(
.r;
state.client_set.float(id, r)?;
wstate.push(*full_screen);
x.set_client_config(id, &[ClientConfig::BorderPx(0)])?; // remove borders
} else if currently_fullscreen && (action == Remove || action == Toggle) {
state.client_set.sink(&id);
wstate.retain(|&val| val != *full_screen);
// replace borders
x.set_client_config(id, &[ClientConfig::BorderPx(state.config.border_width)])?;
}

x.set_prop(id, net_wm_state, Prop::Cardinal(wstate))?;
Expand Down

0 comments on commit 74962e5

Please # to comment.