Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: add `gaps.scale_with_dpi` config option for adjusting inner/outer gaps (#768)

lars-berger829bf0abcd63
diff --git a/packages/wm/src/common/commands/platform_sync.rs b/packages/wm/src/common/commands/platform_sync.rs
index 579fd7a0..31bb7012 100644
--- a/packages/wm/src/common/commands/platform_sync.rs
+++ b/packages/wm/src/common/commands/platform_sync.rs
@@ -125,8 +125,9 @@ fn redraw_containers(state: &mut WmState) -> anyhow::Result<()> {
},
);
- let rect =
- window.to_rect()?.apply_delta(&window.total_border_delta()?);
+ let rect = window
+ .to_rect()?
+ .apply_delta(&window.total_border_delta()?, None);
let is_visible = match window.display_state() {
DisplayState::Showing | DisplayState::Shown => true,
diff --git a/packages/wm/src/common/commands/reload_config.rs b/packages/wm/src/common/commands/reload_config.rs
index 91710a50..df252f98 100644
--- a/packages/wm/src/common/commands/reload_config.rs
+++ b/packages/wm/src/common/commands/reload_config.rs
@@ -123,11 +123,11 @@ fn update_container_gaps(state: &mut WmState, config: &UserConfig) {
.filter_map(|container| container.as_tiling_container().ok());
for container in tiling_containers {
- container.set_inner_gap(config.value.gaps.inner_gap.clone());
+ container.set_gaps_config(config.value.gaps.clone());
}
for workspace in state.workspaces() {
- workspace.set_outer_gap(config.value.gaps.outer_gap.clone());
+ workspace.set_gaps_config(config.value.gaps.clone());
}
}
diff --git a/packages/wm/src/common/events/handle_display_settings_changed.rs b/packages/wm/src/common/events/handle_display_settings_changed.rs
index 3f8f5552..64661946 100644
--- a/packages/wm/src/common/events/handle_display_settings_changed.rs
+++ b/packages/wm/src/common/events/handle_display_settings_changed.rs
@@ -3,10 +3,7 @@ use tracing::info;
use crate::{
common::platform::Platform,
- containers::{
- traits::{CommonGetters, PositionGetters},
- WindowContainer,
- },
+ containers::traits::{CommonGetters, PositionGetters},
monitors::commands::{
add_monitor, remove_monitor, sort_monitors, update_monitor,
},
diff --git a/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs b/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs
index 4bb3953d..a9fef03a 100644
--- a/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs
+++ b/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs
@@ -171,7 +171,7 @@ fn drop_as_tiling_window(
if should_split {
let split_container = SplitContainer::new(
tiling_direction.inverse(),
- config.value.gaps.inner_gap.clone(),
+ config.value.gaps.clone(),
);
wrap_in_split_container(
diff --git a/packages/wm/src/common/length_value.rs b/packages/wm/src/common/length_value.rs
index fbeb91ee..d4b7c8e1 100644
--- a/packages/wm/src/common/length_value.rs
+++ b/packages/wm/src/common/length_value.rs
@@ -1,4 +1,4 @@
-use std::{ops::Mul, str::FromStr};
+use std::str::FromStr;
use anyhow::{bail, Context};
use regex::Regex;
@@ -25,17 +25,12 @@ impl LengthValue {
}
}
- pub fn to_px(&self, total_px: i32) -> i32 {
- match self.unit {
- LengthUnit::Percentage => (self.amount * total_px as f32) as i32,
- LengthUnit::Pixel => self.amount as i32,
- }
- }
+ pub fn to_px(&self, total_px: i32, scale_factor: Option<f32>) -> i32 {
+ let scale_factor = scale_factor.unwrap_or(1.0);
- 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,
+ LengthUnit::Percentage => (self.amount * total_px as f32) as i32,
+ LengthUnit::Pixel => (self.amount * scale_factor) as i32,
}
}
@@ -111,13 +106,3 @@ impl<'de> Deserialize<'de> for LengthValue {
}
}
}
-
-impl Mul<f32> 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.rs b/packages/wm/src/common/rect.rs
index 353fc578..bb858cd3 100644
--- a/packages/wm/src/common/rect.rs
+++ b/packages/wm/src/common/rect.rs
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
-use super::{Direction, Point, RectDelta};
+use super::{Direction, LengthValue, Point, RectDelta};
#[derive(Debug, Deserialize, Clone, Serialize, Eq, PartialEq)]
pub struct Rect {
@@ -115,23 +115,39 @@ impl Rect {
}
}
- // TODO: Pass in a `Rect` for unit conversion.
- pub fn apply_delta(&self, delta: &RectDelta) -> Self {
+ /// Gets the delta between this rect and another rect.
+ pub fn delta(&self, other: &Rect) -> RectDelta {
+ RectDelta {
+ left: LengthValue::from_px(self.left - other.left),
+ top: LengthValue::from_px(self.top - other.top),
+ right: LengthValue::from_px(self.right - other.right),
+ bottom: LengthValue::from_px(self.bottom - other.bottom),
+ }
+ }
+
+ pub fn apply_delta(
+ &self,
+ delta: &RectDelta,
+ scale_factor: Option<f32>,
+ ) -> Self {
Self::from_ltrb(
- self.left - delta.left.to_px(self.width()),
- self.top - delta.top.to_px(self.height()),
- self.right + delta.right.to_px(self.width()),
- self.bottom + delta.bottom.to_px(self.height()),
+ self.left - delta.left.to_px(self.width(), scale_factor),
+ self.top - delta.top.to_px(self.height(), scale_factor),
+ self.right + delta.right.to_px(self.width(), scale_factor),
+ self.bottom + delta.bottom.to_px(self.height(), scale_factor),
)
}
- // TODO: Pass in a `Rect` for unit conversion.
- pub fn apply_inverse_delta(&self, delta: &RectDelta) -> Self {
+ pub fn apply_inverse_delta(
+ &self,
+ delta: &RectDelta,
+ scale_factor: Option<f32>,
+ ) -> Self {
Self::from_ltrb(
- self.left + delta.left.to_px(self.width()),
- self.top + delta.top.to_px(self.height()),
- self.right - delta.right.to_px(self.width()),
- self.bottom - delta.bottom.to_px(self.height()),
+ self.left + delta.left.to_px(self.width(), scale_factor),
+ self.top + delta.top.to_px(self.height(), scale_factor),
+ self.right - delta.right.to_px(self.width(), scale_factor),
+ self.bottom - delta.bottom.to_px(self.height(), scale_factor),
)
}
diff --git a/packages/wm/src/common/rect_delta.rs b/packages/wm/src/common/rect_delta.rs
index daf15b53..99c776ae 100644
--- a/packages/wm/src/common/rect_delta.rs
+++ b/packages/wm/src/common/rect_delta.rs
@@ -1,5 +1,3 @@
-use std::ops::Mul;
-
use serde::{Deserialize, Serialize};
use super::LengthValue;
@@ -34,15 +32,3 @@ impl RectDelta {
}
}
}
-
-impl Mul<f32> 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/commands/toggle_tiling_direction.rs b/packages/wm/src/containers/commands/toggle_tiling_direction.rs
index 29256fba..62c74f9d 100644
--- a/packages/wm/src/containers/commands/toggle_tiling_direction.rs
+++ b/packages/wm/src/containers/commands/toggle_tiling_direction.rs
@@ -72,7 +72,7 @@ fn toggle_window_direction(
// Create a new split container to wrap the window.
let split_container = SplitContainer::new(
parent.tiling_direction().inverse(),
- config.value.gaps.inner_gap.clone(),
+ config.value.gaps.clone(),
);
wrap_in_split_container(
diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rs
index 0adcb672..6ea19cef 100644
--- a/packages/wm/src/containers/container.rs
+++ b/packages/wm/src/containers/container.rs
@@ -10,12 +10,12 @@ use uuid::Uuid;
use super::{RootContainer, SplitContainer};
use crate::{
common::{
- platform::NativeWindow, Direction, DisplayState, LengthValue, Rect,
- RectDelta, TilingDirection,
+ platform::NativeWindow, Direction, DisplayState, Rect, RectDelta,
+ TilingDirection,
},
containers::{traits::*, ContainerDto},
monitors::Monitor,
- user_config::{UserConfig, WindowRuleConfig},
+ user_config::{GapsConfig, UserConfig, WindowRuleConfig},
windows::{
traits::*, ActiveDrag, NonTilingWindow, TilingWindow, WindowState,
},
diff --git a/packages/wm/src/containers/split_container.rs b/packages/wm/src/containers/split_container.rs
index 18126c3e..0d06a5e4 100644
--- a/packages/wm/src/containers/split_container.rs
+++ b/packages/wm/src/containers/split_container.rs
@@ -17,10 +17,11 @@ use super::{
WindowContainer,
};
use crate::{
- common::{LengthValue, Rect, TilingDirection},
+ common::{Rect, TilingDirection},
impl_common_getters, impl_container_debug,
impl_position_getters_as_resizable, impl_tiling_direction_getters,
impl_tiling_size_getters,
+ user_config::GapsConfig,
};
#[derive(Clone)]
@@ -33,7 +34,7 @@ struct SplitContainerInner {
child_focus_order: VecDeque<Uuid>,
tiling_size: f32,
tiling_direction: TilingDirection,
- inner_gap: LengthValue,
+ gaps_config: GapsConfig,
}
/// User-friendly representation of a split container.
@@ -58,7 +59,7 @@ pub struct SplitContainerDto {
impl SplitContainer {
pub fn new(
tiling_direction: TilingDirection,
- inner_gap: LengthValue,
+ gaps_config: GapsConfig,
) -> Self {
let split = SplitContainerInner {
id: Uuid::new_v4(),
@@ -67,7 +68,7 @@ impl SplitContainer {
child_focus_order: VecDeque::new(),
tiling_size: 1.0,
tiling_direction,
- inner_gap,
+ gaps_config,
};
Self(Rc::new(RefCell::new(split)))
diff --git a/packages/wm/src/containers/traits/position_getters.rs b/packages/wm/src/containers/traits/position_getters.rs
index 003129a1..d37b3a6a 100644
--- a/packages/wm/src/containers/traits/position_getters.rs
+++ b/packages/wm/src/containers/traits/position_getters.rs
@@ -23,15 +23,11 @@ macro_rules! impl_position_getters_as_resizable {
.context("Parent does not have a tiling direction.")?;
let parent_rect = parent.to_rect()?;
- let monitor = self.monitor().context("No monitor.")?;
+ let (horizontal_gap, vertical_gap) = self.inner_gaps()?;
let inner_gap = match parent.tiling_direction() {
- TilingDirection::Vertical => {
- self.inner_gap().to_px(monitor.to_rect()?.height())
- }
- TilingDirection::Horizontal => {
- self.inner_gap().to_px(monitor.to_rect()?.width())
- }
+ TilingDirection::Vertical => vertical_gap,
+ TilingDirection::Horizontal => horizontal_gap,
};
let (width, height) = match parent.tiling_direction() {
diff --git a/packages/wm/src/containers/traits/tiling_size_getters.rs b/packages/wm/src/containers/traits/tiling_size_getters.rs
index c7a42b06..4406e986 100644
--- a/packages/wm/src/containers/traits/tiling_size_getters.rs
+++ b/packages/wm/src/containers/traits/tiling_size_getters.rs
@@ -1,10 +1,13 @@
+use std::cell::Ref;
+
use ambassador::delegatable_trait;
use anyhow::Context;
-use super::{CommonGetters, TilingDirectionGetters};
+use super::{CommonGetters, PositionGetters, TilingDirectionGetters};
use crate::{
- common::{LengthValue, TilingDirection},
+ common::TilingDirection,
containers::{Container, DirectionContainer, TilingContainer},
+ user_config::GapsConfig,
};
pub const MIN_TILING_SIZE: f32 = 0.01;
@@ -15,9 +18,30 @@ pub trait TilingSizeGetters: CommonGetters {
fn set_tiling_size(&self, tiling_size: f32);
- fn inner_gap(&self) -> LengthValue;
+ fn gaps_config(&self) -> Ref<'_, GapsConfig>;
+
+ fn set_gaps_config(&self, gaps_config: GapsConfig);
- fn set_inner_gap(&self, inner_gap: LengthValue);
+ /// Gets the horizontal and vertical gaps between windows in pixels.
+ fn inner_gaps(&self) -> anyhow::Result<(i32, i32)> {
+ let monitor = self.monitor().context("No monitor.")?;
+ let monitor_rect = monitor.to_rect()?;
+ let gaps_config = self.gaps_config();
+
+ let scale_factor = match gaps_config.scale_with_dpi {
+ true => monitor.native().dpi()?,
+ false => 1.,
+ };
+
+ Ok((
+ gaps_config
+ .inner_gap
+ .to_px(monitor_rect.height(), Some(scale_factor)),
+ gaps_config
+ .inner_gap
+ .to_px(monitor_rect.width(), Some(scale_factor)),
+ ))
+ }
/// Gets the container to resize when resizing a tiling window.
fn container_to_resize(
@@ -76,19 +100,12 @@ macro_rules! impl_tiling_size_getters {
self.0.borrow_mut().tiling_size = tiling_size;
}
- fn inner_gap(&self) -> LengthValue {
- 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 gaps_config(&self) -> Ref<'_, GapsConfig> {
+ Ref::map(self.0.borrow(), |inner| &inner.gaps_config)
}
- fn set_inner_gap(&self, inner_gap: LengthValue) {
- self.0.borrow_mut().inner_gap = inner_gap;
+ fn set_gaps_config(&self, gaps_config: GapsConfig) {
+ self.0.borrow_mut().gaps_config = gaps_config;
}
}
};
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index 792e1b62..e0dbc2f6 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -372,6 +372,10 @@ pub struct BindingModeConfig {
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GapsConfig {
+ /// Whether to scale the gaps with the DPI of the monitor.
+ #[serde(default = "default_bool::<true>")]
+ pub scale_with_dpi: bool,
+
/// Gap between adjacent windows.
pub inner_gap: LengthValue,
diff --git a/packages/wm/src/windows/commands/manage_window.rs b/packages/wm/src/windows/commands/manage_window.rs
index 70c4ffd3..73fb6640 100644
--- a/packages/wm/src/windows/commands/manage_window.rs
+++ b/packages/wm/src/windows/commands/manage_window.rs
@@ -123,7 +123,7 @@ fn create_window(
LengthValue::from_px(0),
);
- let inner_gap = config.value.gaps.inner_gap.clone();
+ let gaps_config = config.value.gaps.clone();
let window_state =
window_state_to_create(&native_window, &nearest_monitor, config)?;
@@ -134,7 +134,7 @@ fn create_window(
None,
border_delta,
floating_placement,
- inner_gap,
+ gaps_config,
Vec::new(),
None,
)
diff --git a/packages/wm/src/windows/commands/move_window_in_direction.rs b/packages/wm/src/windows/commands/move_window_in_direction.rs
index f052ae79..e4b73198 100644
--- a/packages/wm/src/windows/commands/move_window_in_direction.rs
+++ b/packages/wm/src/windows/commands/move_window_in_direction.rs
@@ -281,7 +281,7 @@ fn invert_workspace_tiling_direction(
if workspace_children.len() > 1 {
let split_container = SplitContainer::new(
workspace.tiling_direction(),
- config.value.gaps.inner_gap.clone(),
+ config.value.gaps.clone(),
);
wrap_in_split_container(
diff --git a/packages/wm/src/windows/commands/resize_window.rs b/packages/wm/src/windows/commands/resize_window.rs
index a9d66587..10e50b4c 100644
--- a/packages/wm/src/windows/commands/resize_window.rs
+++ b/packages/wm/src/windows/commands/resize_window.rs
@@ -1,5 +1,3 @@
-use anyhow::Context;
-
use super::set_window_size;
use crate::{
common::LengthValue,
@@ -16,8 +14,6 @@ pub fn resize_window(
height_delta: Option<LengthValue>,
state: &mut WmState,
) -> anyhow::Result<()> {
- let monitor = window.monitor().context("No monitor")?;
- let monitor_rect = monitor.to_rect()?;
let window_rect = window.to_rect()?;
let target_width = match width_delta {
@@ -29,10 +25,14 @@ pub fn resize_window(
.and_then(|parent| {
parent.to_rect().ok().map(|rect| rect.width())
})
- .map(|parent_width| {
- parent_width
- - tiling_window.inner_gap().to_px(monitor_rect.width())
- * tiling_window.tiling_siblings().count() as i32
+ .and_then(|parent_width| {
+ let (horizontal_gap, _) = tiling_window.inner_gaps().ok()?;
+
+ Some(
+ parent_width
+ - horizontal_gap
+ * tiling_window.tiling_siblings().count() as i32,
+ )
}),
_ => window.parent().and_then(|parent| {
parent.to_rect().ok().map(|rect| rect.width())
@@ -40,7 +40,7 @@ pub fn resize_window(
};
parent_width.map(|parent_width| {
- window_rect.width() + delta.to_px(parent_width)
+ window_rect.width() + delta.to_px(parent_width, None)
})
}
_ => None,
@@ -55,10 +55,14 @@ pub fn resize_window(
.and_then(|parent| {
parent.to_rect().ok().map(|rect| rect.width())
})
- .map(|parent_height| {
- parent_height
- - tiling_window.inner_gap().to_px(monitor_rect.height())
- * tiling_window.tiling_siblings().count() as i32
+ .and_then(|parent_height| {
+ let (_, vertical_gap) = tiling_window.inner_gaps().ok()?;
+
+ Some(
+ parent_height
+ - vertical_gap
+ * tiling_window.tiling_siblings().count() as i32,
+ )
}),
_ => window.parent().and_then(|parent| {
parent.to_rect().ok().map(|rect| rect.width())
@@ -66,7 +70,7 @@ pub fn resize_window(
};
parent_height.map(|parent_height| {
- window_rect.height() + delta.to_px(parent_height)
+ window_rect.height() + delta.to_px(parent_height, None)
})
}
_ => None,
diff --git a/packages/wm/src/windows/commands/set_window_size.rs b/packages/wm/src/windows/commands/set_window_size.rs
index b61f9323..64893b4a 100644
--- a/packages/wm/src/windows/commands/set_window_size.rs
+++ b/packages/wm/src/windows/commands/set_window_size.rs
@@ -66,25 +66,23 @@ fn set_tiling_window_length(
is_width_resize: bool,
state: &mut WmState,
) -> anyhow::Result<()> {
- let monitor = window.monitor().context("No monitor")?;
- let monitor_rect = monitor.to_rect()?;
-
// When resizing a tiling window, the container to resize can actually be
// an ancestor split container.
let container_to_resize = window.container_to_resize(is_width_resize)?;
if let Some(container_to_resize) = container_to_resize {
let parent = container_to_resize.parent().context("No parent.")?;
+ let (horizontal_gap, vertical_gap) =
+ container_to_resize.inner_gaps()?;
+
let parent_length = match is_width_resize {
true => {
parent.to_rect()?.width()
- - window.inner_gap().to_px(monitor_rect.width())
- * window.tiling_siblings().count() as i32
+ - horizontal_gap * window.tiling_siblings().count() as i32
}
false => {
parent.to_rect()?.height()
- - window.inner_gap().to_px(monitor_rect.height())
- * window.tiling_siblings().count() as i32
+ - vertical_gap * window.tiling_siblings().count() as i32
}
};
@@ -132,7 +130,7 @@ fn set_floating_window_size(
};
let target_width_px = target_width
- .map(|target_width| target_width.to_px(monitor_rect.width()));
+ .map(|target_width| target_width.to_px(monitor_rect.width(), None));
let new_width = length_with_clamp(
target_width_px,
@@ -141,7 +139,7 @@ fn set_floating_window_size(
);
let target_height_px = target_height
- .map(|target_height| target_height.to_px(monitor_rect.height()));
+ .map(|target_height| target_height.to_px(monitor_rect.height(), None));
let new_height = length_with_clamp(
target_height_px,
diff --git a/packages/wm/src/windows/commands/update_window_state.rs b/packages/wm/src/windows/commands/update_window_state.rs
index 88e5a5f4..0dc4c082 100644
--- a/packages/wm/src/windows/commands/update_window_state.rs
+++ b/packages/wm/src/windows/commands/update_window_state.rs
@@ -73,8 +73,7 @@ fn set_tiling(
// Default to inserting at the end of the workspace.
.unwrap_or((workspace.clone().into(), workspace.child_count()));
- let tiling_window =
- window.to_tiling(config.value.gaps.inner_gap.clone());
+ let tiling_window = window.to_tiling(config.value.gaps.clone());
// Replace the original window with the created tiling window.
replace_container(
diff --git a/packages/wm/src/windows/non_tiling_window.rs b/packages/wm/src/windows/non_tiling_window.rs
index 63f46dcc..a72d4a18 100644
--- a/packages/wm/src/windows/non_tiling_window.rs
+++ b/packages/wm/src/windows/non_tiling_window.rs
@@ -11,16 +11,14 @@ use super::{
traits::WindowGetters, ActiveDrag, TilingWindow, WindowDto, WindowState,
};
use crate::{
- common::{
- platform::NativeWindow, DisplayState, LengthValue, Rect, RectDelta,
- },
+ common::{platform::NativeWindow, DisplayState, Rect, RectDelta},
containers::{
traits::{CommonGetters, PositionGetters},
Container, ContainerDto, DirectionContainer, TilingContainer,
WindowContainer,
},
impl_common_getters, impl_container_debug, impl_window_getters,
- user_config::WindowRuleConfig,
+ user_config::{GapsConfig, WindowRuleConfig},
};
#[derive(Clone)]
@@ -86,14 +84,14 @@ impl NonTilingWindow {
self.0.borrow_mut().insertion_target = insertion_target;
}
- pub fn to_tiling(&self, inner_gap: LengthValue) -> TilingWindow {
+ pub fn to_tiling(&self, gaps_config: GapsConfig) -> TilingWindow {
TilingWindow::new(
Some(self.id()),
self.native().clone(),
Some(self.state()),
self.border_delta(),
self.floating_placement(),
- inner_gap,
+ gaps_config,
self.done_window_rules(),
self.active_drag(),
)
diff --git a/packages/wm/src/windows/tiling_window.rs b/packages/wm/src/windows/tiling_window.rs
index da073458..9364350d 100644
--- a/packages/wm/src/windows/tiling_window.rs
+++ b/packages/wm/src/windows/tiling_window.rs
@@ -12,8 +12,7 @@ use super::{
};
use crate::{
common::{
- platform::NativeWindow, DisplayState, LengthValue, Rect, RectDelta,
- TilingDirection,
+ platform::NativeWindow, DisplayState, Rect, RectDelta, TilingDirection,
},
containers::{
traits::{
@@ -26,7 +25,7 @@ use crate::{
impl_common_getters, impl_container_debug,
impl_position_getters_as_resizable, impl_tiling_size_getters,
impl_window_getters,
- user_config::WindowRuleConfig,
+ user_config::{GapsConfig, WindowRuleConfig},
windows::active_drag::ActiveDrag,
};
@@ -46,7 +45,7 @@ struct TilingWindowInner {
border_delta: RectDelta,
has_pending_dpi_adjustment: bool,
floating_placement: Rect,
- inner_gap: LengthValue,
+ gaps_config: GapsConfig,
done_window_rules: Vec<WindowRuleConfig>,
active_drag: Option<ActiveDrag>,
}
@@ -58,7 +57,7 @@ impl TilingWindow {
prev_state: Option<WindowState>,
border_delta: RectDelta,
floating_placement: Rect,
- inner_gap: LengthValue,
+ gaps_config: GapsConfig,
done_window_rules: Vec<WindowRuleConfig>,
active_drag: Option<ActiveDrag>,
) -> Self {
@@ -75,7 +74,7 @@ impl TilingWindow {
border_delta,
has_pending_dpi_adjustment: false,
floating_placement,
- inner_gap,
+ gaps_config,
done_window_rules,
active_drag,
};
diff --git a/packages/wm/src/windows/traits/window_getters.rs b/packages/wm/src/windows/traits/window_getters.rs
index 60e9b2f0..16b2387b 100644
--- a/packages/wm/src/windows/traits/window_getters.rs
+++ b/packages/wm/src/windows/traits/window_getters.rs
@@ -72,16 +72,20 @@ pub trait WindowGetters {
// TODO: Allow percentage length values.
Ok(RectDelta {
left: LengthValue::from_px(
- border_delta.left.to_px(0) + shadow_border_delta.left.to_px(0),
+ border_delta.left.to_px(0, None)
+ + shadow_border_delta.left.to_px(0, None),
),
right: LengthValue::from_px(
- border_delta.right.to_px(0) + shadow_border_delta.right.to_px(0),
+ border_delta.right.to_px(0, None)
+ + shadow_border_delta.right.to_px(0, None),
),
top: LengthValue::from_px(
- border_delta.top.to_px(0) + shadow_border_delta.top.to_px(0),
+ border_delta.top.to_px(0, None)
+ + shadow_border_delta.top.to_px(0, None),
),
bottom: LengthValue::from_px(
- border_delta.bottom.to_px(0) + shadow_border_delta.bottom.to_px(0),
+ border_delta.bottom.to_px(0, None)
+ + shadow_border_delta.bottom.to_px(0, None),
),
})
}
diff --git a/packages/wm/src/workspaces/commands/activate_workspace.rs b/packages/wm/src/workspaces/commands/activate_workspace.rs
index 20744544..91e9323b 100644
--- a/packages/wm/src/workspaces/commands/activate_workspace.rs
+++ b/packages/wm/src/workspaces/commands/activate_workspace.rs
@@ -61,7 +61,7 @@ pub fn activate_workspace(
let workspace = Workspace::new(
workspace_config.clone(),
- config.value.gaps.outer_gap.clone(),
+ config.value.gaps.clone(),
tiling_direction,
);
diff --git a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs b/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
index af170673..1e86993f 100644
--- a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
+++ b/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
@@ -6,7 +6,6 @@ use crate::{
containers::{
commands::move_container_within_tree,
traits::{CommonGetters, PositionGetters},
- WindowContainer,
},
user_config::UserConfig,
windows::traits::WindowGetters,
diff --git a/packages/wm/src/workspaces/workspace.rs b/packages/wm/src/workspaces/workspace.rs
index fc8780c8..29b323e8 100644
--- a/packages/wm/src/workspaces/workspace.rs
+++ b/packages/wm/src/workspaces/workspace.rs
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::{
- common::{Rect, RectDelta, TilingDirection},
+ common::{Rect, TilingDirection},
containers::{
traits::{CommonGetters, PositionGetters, TilingDirectionGetters},
Container, ContainerDto, DirectionContainer, TilingContainer,
@@ -17,7 +17,7 @@ use crate::{
},
impl_common_getters, impl_container_debug,
impl_tiling_direction_getters,
- user_config::WorkspaceConfig,
+ user_config::{GapsConfig, WorkspaceConfig},
};
#[derive(Clone)]
@@ -29,9 +29,9 @@ struct WorkspaceInner {
parent: Option<Container>,
children: VecDeque<Container>,
child_focus_order: VecDeque<Uuid>,
- tiling_direction: TilingDirection,
config: WorkspaceConfig,
- outer_gap: RectDelta,
+ gaps_config: GapsConfig,
+ tiling_direction: TilingDirection,
}
/// User-friendly representation of a workspace.
@@ -58,7 +58,7 @@ pub struct WorkspaceDto {
impl Workspace {
pub fn new(
config: WorkspaceConfig,
- outer_gap: RectDelta,
+ gaps_config: GapsConfig,
tiling_direction: TilingDirection,
) -> Self {
let workspace = WorkspaceInner {
@@ -66,9 +66,9 @@ impl Workspace {
parent: None,
children: VecDeque::new(),
child_focus_order: VecDeque::new(),
- tiling_direction,
config,
- outer_gap,
+ gaps_config,
+ tiling_direction,
};
Self(Rc::new(RefCell::new(workspace)))
@@ -93,8 +93,8 @@ impl Workspace {
.unwrap_or(false)
}
- pub fn set_outer_gap(&self, outer_gap: RectDelta) {
- self.0.borrow_mut().outer_gap = outer_gap;
+ pub fn set_gaps_config(&self, gaps_config: GapsConfig) {
+ self.0.borrow_mut().gaps_config = gaps_config;
}
pub fn to_dto(&self) -> anyhow::Result<ContainerDto> {
@@ -131,19 +131,28 @@ impl_tiling_direction_getters!(Workspace);
impl PositionGetters for Workspace {
fn to_rect(&self) -> anyhow::Result<Rect> {
- let working_rect = self
- .monitor()
- .context("Workspace has no parent monitor.")?
- .native()
- .working_rect()
- .cloned()
- .context("Failed to get working area of parent monitor.")?;
+ let monitor =
+ self.monitor().context("Workspace has no parent monitor.")?;
- let scale = match self.monitor() {
- None => 1_f32,
- Some(monitor) => monitor.native().dpi()?,
+ let gaps_config = &self.0.borrow().gaps_config;
+ let scale_factor = match &gaps_config.scale_with_dpi {
+ true => monitor.native().dpi()?,
+ false => 1.,
};
- let outer_gap = self.0.borrow().outer_gap.clone() * scale;
- Ok(working_rect.apply_inverse_delta(&outer_gap))
+
+ // Get delta between monitor bounds and its working area.
+ let working_delta = monitor
+ .native()
+ .working_rect()
+ .context("Failed to get working area of parent monitor.")?
+ .delta(&monitor.to_rect()?);
+
+ Ok(
+ monitor
+ .to_rect()?
+ // Scale the gaps if `scale_with_dpi` is enabled.
+ .apply_inverse_delta(&gaps_config.outer_gap, Some(scale_factor))
+ .apply_delta(&working_delta, None),
+ )
}
}
diff --git a/resources/assets/sample-config.yaml b/resources/assets/sample-config.yaml
index e94956f1..2b1be0f4 100644
--- a/resources/assets/sample-config.yaml
+++ b/resources/assets/sample-config.yaml
@@ -28,6 +28,9 @@ general:
trigger: 'monitor_focus'
gaps:
+ # Whether to scale the gaps with the DPI of the monitor.
+ scale_with_dpi: true
+
# Gap between adjacent windows.
inner_gap: '20px'
@@ -47,7 +50,8 @@ window_effects:
enabled: true
color: '#8dbcff'
- # Remove the title bar from the window's frame.
+ # Remove the title bar from the window's frame. Note that this can
+ # cause rendering issues for some applications.
hide_title_bar:
enabled: false