From 5a45193ec36941c4176b5bd522781204b11163a9 Mon Sep 17 00:00:00 2001 From: Jonas Wischeropp Date: Tue, 1 Oct 2024 12:59:13 +0200 Subject: [PATCH 1/2] scale gaps by window scale --- packages/wm/src/common/length_value.rs | 12 +++++++++++- packages/wm/src/common/rect_delta.rs | 14 ++++++++++++++ .../src/containers/traits/tiling_size_getters.rs | 9 ++++++++- packages/wm/src/workspaces/workspace.rs | 8 ++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/packages/wm/src/common/length_value.rs b/packages/wm/src/common/length_value.rs index e67bd5a8e..ff67e0d60 100644 --- a/packages/wm/src/common/length_value.rs +++ b/packages/wm/src/common/length_value.rs @@ -1,4 +1,4 @@ -use std::str::FromStr; +use std::{ops::Mul, str::FromStr}; use anyhow::{bail, Context}; use regex::Regex; @@ -104,3 +104,13 @@ impl<'de> Deserialize<'de> for LengthValue { } } } + +impl Mul for LengthValue { + type Output = Self; + fn mul(self, rhs: f32) -> Self { + Self { + amount: self.amount * rhs, + unit: self.unit, + } + } +} diff --git a/packages/wm/src/common/rect_delta.rs b/packages/wm/src/common/rect_delta.rs index 99c776aea..daf15b53d 100644 --- a/packages/wm/src/common/rect_delta.rs +++ b/packages/wm/src/common/rect_delta.rs @@ -1,3 +1,5 @@ +use std::ops::Mul; + use serde::{Deserialize, Serialize}; use super::LengthValue; @@ -32,3 +34,15 @@ impl RectDelta { } } } + +impl Mul for RectDelta { + type Output = Self; + fn mul(self, rhs: f32) -> Self { + Self::new( + self.left * rhs, + self.top * rhs, + self.right * rhs, + self.bottom * rhs, + ) + } +} diff --git a/packages/wm/src/containers/traits/tiling_size_getters.rs b/packages/wm/src/containers/traits/tiling_size_getters.rs index 11143f96d..c7a42b06a 100644 --- a/packages/wm/src/containers/traits/tiling_size_getters.rs +++ b/packages/wm/src/containers/traits/tiling_size_getters.rs @@ -77,7 +77,14 @@ macro_rules! impl_tiling_size_getters { } fn inner_gap(&self) -> LengthValue { - self.0.borrow().inner_gap.clone() + let scale = match self.monitor() { + None => 1_f32, + Some(monitor) => match monitor.native().dpi() { + Ok(dpi) => dpi, + Err(_) => 1_f32, + }, + }; + self.0.borrow().inner_gap.clone() * scale } fn set_inner_gap(&self, inner_gap: LengthValue) { diff --git a/packages/wm/src/workspaces/workspace.rs b/packages/wm/src/workspaces/workspace.rs index b08aa747e..fc8780c85 100644 --- a/packages/wm/src/workspaces/workspace.rs +++ b/packages/wm/src/workspaces/workspace.rs @@ -139,7 +139,11 @@ impl PositionGetters for Workspace { .cloned() .context("Failed to get working area of parent monitor.")?; - let outer_gap = &self.0.borrow().outer_gap; - Ok(working_rect.apply_inverse_delta(outer_gap)) + let scale = match self.monitor() { + None => 1_f32, + Some(monitor) => monitor.native().dpi()?, + }; + let outer_gap = self.0.borrow().outer_gap.clone() * scale; + Ok(working_rect.apply_inverse_delta(&outer_gap)) } } From bf5e598f0224fcee23a0eee2e23b8f4d6d5e50a6 Mon Sep 17 00:00:00 2001 From: Jonas Wischeropp Date: Wed, 2 Oct 2024 16:02:16 +0200 Subject: [PATCH 2/2] add LengthValue::to_px_scaled --- packages/wm/src/common/length_value.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/wm/src/common/length_value.rs b/packages/wm/src/common/length_value.rs index ff67e0d60..fbeb91eec 100644 --- a/packages/wm/src/common/length_value.rs +++ b/packages/wm/src/common/length_value.rs @@ -32,6 +32,13 @@ impl LengthValue { } } + pub fn to_px_scaled(&self, total_px: i32, scale_factor: f32) -> i32 { + match self.unit { + LengthUnit::Percentage => self.to_px(total_px), + LengthUnit::Pixel => (scale_factor * self.amount) as i32, + } + } + pub fn to_percentage(&self, total_px: i32) -> f32 { match self.unit { LengthUnit::Percentage => self.amount,