Skip to content

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

feat: clamp initial floating position to 90% of monitor's size

Lars Berger7558b7af0d2c
diff --git a/packages/wm/src/common/rect.rs b/packages/wm/src/common/rect.rs
index 114b29ec..b68dd840 100644
--- a/packages/wm/src/common/rect.rs
+++ b/packages/wm/src/common/rect.rs
@@ -91,12 +91,21 @@ impl Rect {
/// outer rectangle. Attempts to preserve the width and height of the
/// original rectangle.
pub fn clamp(&self, outer_rect: &Rect) -> Self {
- let x = self.left.max(outer_rect.left);
- let y = self.top.max(outer_rect.top);
- let width = self.width().min(outer_rect.width());
- let height = self.height().min(outer_rect.height());
+ Self::from_xy(
+ self.left.max(outer_rect.left),
+ self.top.max(outer_rect.top),
+ self.width().min(outer_rect.width()),
+ self.height().min(outer_rect.height()),
+ )
+ }
- Self::from_xy(x, y, width, height)
+ pub fn clamp_size(&self, width: i32, height: i32) -> Self {
+ Self::from_xy(
+ self.x(),
+ self.y(),
+ self.width().min(width),
+ self.height().min(height),
+ )
}
pub fn center_point(&self) -> (i32, i32) {
diff --git a/packages/wm/src/windows/commands/manage_window.rs b/packages/wm/src/windows/commands/manage_window.rs
index 66d1cd1f..93fdc4f8 100644
--- a/packages/wm/src/windows/commands/manage_window.rs
+++ b/packages/wm/src/windows/commands/manage_window.rs
@@ -99,15 +99,18 @@ fn create_window(
// Calculate where window should be placed when floating is enabled. Use
// the original width/height of the window and optionally position it in
// the center of the workspace.
- let floating_placement =
- if nearest_workspace.id() != target_workspace.id() || prefers_centered
- {
- native_window
- .frame_position()?
- .translate_to_center(&target_workspace.to_rect()?)
- } else {
- native_window.frame_position()?
- };
+ let is_same_workspace = nearest_workspace.id() == target_workspace.id();
+ let floating_placement = match !is_same_workspace || prefers_centered {
+ true => native_window
+ .frame_position()?
+ .translate_to_center(&target_workspace.to_rect()?),
+ false => native_window.frame_position()?,
+ }
+ // Clamp the window size to 90% of the monitor size.
+ .clamp_size(
+ (nearest_monitor.to_rect()?.width() as f32 * 0.9) as i32,
+ (nearest_monitor.to_rect()?.height() as f32 * 0.9) as i32,
+ );
let border_delta = native_window.border_delta()?;
let inner_gap = config.value.gaps.inner_gap.clone();