From 78da614d67c09e197dffc1cebb1c5ce2357c7128 Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:06:00 +0200 Subject: Add per-window resize-margin override (Hyprland's extend_border_grab_area) MISSING.md had listed this as needing to touch srdwm_core::window:: hit_test's signature at every call site, including the honest-stub Windows/macOS backends - overstated on closer inspection: that shared function already takes a plain resize_margin: i32 parameter, agnostic to where the value comes from. The only real change needed was reading Window.resize_margin.unwrap_or(wm-wide default) instead of always the WM-wide value, at the single call site inside WindowManager::hit_test in core - no backend touched at all. Window.resize_margin: Option, WindowRuleActions.resize_margin to match, applied in add_window/reapply_rules_if_pending the same way opacity already is. Settable via a rule action or srd.window.set_resize_margin(n) on the focused window. --- crates/config/src/engine/general.rs | 1 + crates/config/src/engine/register.rs | 1 + crates/config/src/engine/window.rs | 14 ++++++++++++++ 3 files changed, 16 insertions(+) (limited to 'crates/config/src') diff --git a/crates/config/src/engine/general.rs b/crates/config/src/engine/general.rs index d1a762a..96ea4d3 100644 --- a/crates/config/src/engine/general.rs +++ b/crates/config/src/engine/general.rs @@ -184,6 +184,7 @@ impl Engine { border_width: actions.get("border_width")?, pinned: actions.get("pinned")?, opacity: actions.get("opacity")?, + resize_margin: actions.get("resize_margin")?, }, }; state.borrow().wm.borrow_mut().add_rule(rule); diff --git a/crates/config/src/engine/register.rs b/crates/config/src/engine/register.rs index d68d253..abe919b 100644 --- a/crates/config/src/engine/register.rs +++ b/crates/config/src/engine/register.rs @@ -45,6 +45,7 @@ impl Engine { window.set("set_border_color", self.fn_window_set_border_color()?)?; window.set("set_border_width", self.fn_window_set_border_width()?)?; window.set("set_opacity", self.fn_window_set_opacity()?)?; + window.set("set_resize_margin", self.fn_window_set_resize_margin()?)?; window.set("set_floating", self.fn_window_set_floating()?)?; window.set("toggle_floating", self.fn_window_action(WindowAction::ToggleFloating)?)?; window.set("is_floating", self.fn_window_is_floating()?)?; diff --git a/crates/config/src/engine/window.rs b/crates/config/src/engine/window.rs index 6193f81..a7e6bf3 100644 --- a/crates/config/src/engine/window.rs +++ b/crates/config/src/engine/window.rs @@ -153,6 +153,20 @@ impl Engine { })?) } + pub(super) fn fn_window_set_resize_margin(&self) -> Result> { + let state = self.state.clone(); + Ok(self.lua.create_function(move |_, margin: i32| { + let wm = state.borrow().wm.clone(); + let mut wm = wm.borrow_mut(); + if let Some(id) = wm.focused_id() { + if let Some(w) = wm.window_mut(id) { + w.resize_margin = Some(margin); + } + } + Ok(()) + })?) + } + pub(super) fn fn_window_set_floating(&self) -> Result> { let state = self.state.clone(); Ok(self.lua.create_function(move |_, floating: bool| { -- cgit v1.2.3