Skip to content

Commit ab50e92

Browse files
committed
fix: window size across multiple monitors with different scaling
1 parent 2d12e1d commit ab50e92

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/wm-common/src/rect.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ impl Rect {
119119
)
120120
}
121121

122+
/// Contrains this rectanble to fit entirely within the given outer
123+
/// rectangle. Unlike `clamp`, this method adjusts both the position and
124+
/// size to ensure the rectangle doesn't extend beyond the boundaries.
125+
#[must_use]
126+
pub fn constrain_within(&self, outer_rect: &Rect) -> Self {
127+
let clamped_x = self.x().max(outer_rect.x());
128+
let clamped_y = self.y().max(outer_rect.y());
129+
130+
let max_width = outer_rect.right - clamped_x;
131+
let max_height = outer_rect.bottom - clamped_y;
132+
133+
Self::from_xy(
134+
clamped_x,
135+
clamped_y,
136+
self.width().min(max_width),
137+
self.height().min(max_height),
138+
)
139+
}
140+
122141
#[must_use]
123142
pub fn center_point(&self) -> Point {
124143
Point {

packages/wm/src/commands/general/platform_sync.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,18 @@ fn redraw_containers(
257257
},
258258
);
259259

260-
let rect = window
260+
let mut rect = window
261261
.to_rect()?
262262
.apply_delta(&window.total_border_delta()?, None);
263263

264+
// Constrain tiling windows to their workspace's bounds to prevent
265+
// overflow on multi-monitor setup with different scaling factors.
266+
if window.is_tiling_window() {
267+
if let Some(workspace) = window.workspace() {
268+
rect = rect.constrain_within(&workspace.to_rect()?);
269+
}
270+
}
271+
264272
let is_visible = matches!(
265273
window.display_state(),
266274
DisplayState::Showing | DisplayState::Shown

0 commit comments

Comments
 (0)