Skip to content

Commit a1db3b8

Browse files
author
Carl
committed
Use client header bounds for multi-monitor restore checks
Signed-off-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
1 parent c6f8225 commit a1db3b8

2 files changed

Lines changed: 90 additions & 20 deletions

File tree

‎docs/shell-design.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ configured 1200×800 window. Visibility and decorations are not restored, so a
119119
macOS window hidden by Close reopens visibly after Quit/relaunch and platform
120120
chrome stays configuration-owned. Close/reopen without quitting on macOS still
121121
uses the existing window. Before restoring maximized/fullscreen mode, Buzz checks
122-
that the entire 48px header fits within a connected monitor's work area. An
122+
that both ends of the 48px client header are inside connected monitor work areas,
123+
allowing a header to span adjacent displays and ignoring invisible frame borders. An
123124
unreachable header falls back to the top of the primary work area (or the first
124125
available monitor), shrinking an oversized frame to fit. This covers partial
125126
overlap after removing a monitor, not just fully off-screen windows. Linux

‎src-tauri/src/window_state.rs‎

Lines changed: 88 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ pub(crate) fn builder() -> Builder {
1818

1919
// Called from app setup, after the configured main window has been created.
2020
pub(crate) fn restore<R: Runtime>(window: &Window<R>) -> tauri::Result<()> {
21+
if let Err(error) = restore_geometry(window) {
22+
eprintln!("Could not restore Buzz window geometry: {error}");
23+
}
24+
window.restore_state(StateFlags::MAXIMIZED | StateFlags::FULLSCREEN)
25+
}
26+
27+
fn restore_geometry<R: Runtime>(window: &Window<R>) -> tauri::Result<()> {
2128
window.restore_state(StateFlags::SIZE | StateFlags::POSITION)?;
2229
let monitors = window.available_monitors()?;
2330
let areas: Vec<_> = monitors
@@ -33,9 +40,15 @@ pub(crate) fn restore<R: Runtime>(window: &Window<R>) -> tauri::Result<()> {
3340
position: window.outer_position()?,
3441
size: window.outer_size()?,
3542
};
43+
// Client bounds exclude Windows' invisible DWM resize borders, which
44+
// legitimately extend outside the work area for edge-flush windows.
45+
let client = PhysicalRect {
46+
position: window.inner_position()?,
47+
size: window.inner_size()?,
48+
};
3649
// AppShell owns a 48 logical-pixel header on all desktop platforms.
3750
let header_height = (48.0 * window.scale_factor()?).ceil() as u32;
38-
if let Some(target) = reachable_frame(frame, header_height, &areas, fallback) {
51+
if let Some(target) = reachable_frame(frame, client, header_height, &areas, fallback) {
3952
if target.size != frame.size {
4053
let inner = window.inner_size()?;
4154
window.set_size(PhysicalSize::new(
@@ -52,25 +65,32 @@ pub(crate) fn restore<R: Runtime>(window: &Window<R>) -> tauri::Result<()> {
5265
window.set_position(target.position)?;
5366
}
5467
}
55-
window.restore_state(StateFlags::MAXIMIZED | StateFlags::FULLSCREEN)
68+
Ok(())
5669
}
5770

5871
fn reachable_frame(
5972
frame: PhysicalRect<i32, u32>,
73+
client: PhysicalRect<i32, u32>,
6074
header_height: u32,
6175
areas: &[PhysicalRect<i32, u32>],
6276
fallback: PhysicalRect<i32, u32>,
6377
) -> Option<PhysicalRect<i32, u32>> {
64-
let x = i64::from(frame.position.x);
65-
let y = i64::from(frame.position.y);
66-
let reachable = areas.iter().any(|area| {
67-
x >= i64::from(area.position.x)
68-
&& y >= i64::from(area.position.y)
69-
&& x + i64::from(frame.size.width)
70-
<= i64::from(area.position.x) + i64::from(area.size.width)
71-
&& y + i64::from(header_height)
72-
<= i64::from(area.position.y) + i64::from(area.size.height)
73-
});
78+
let x = i64::from(client.position.x);
79+
let y = i64::from(client.position.y);
80+
let right = x + i64::from(client.size.width.saturating_sub(1));
81+
let bottom = y + i64::from(header_height.saturating_sub(1));
82+
// A header may span adjacent monitors. Both control regions must remain
83+
// reachable, but need not belong to the same monitor.
84+
let reachable = [(x, y), (right, y), (x, bottom), (right, bottom)]
85+
.into_iter()
86+
.all(|(x, y)| {
87+
areas.iter().any(|area| {
88+
x >= i64::from(area.position.x)
89+
&& y >= i64::from(area.position.y)
90+
&& x < i64::from(area.position.x) + i64::from(area.size.width)
91+
&& y < i64::from(area.position.y) + i64::from(area.size.height)
92+
})
93+
});
7494
if reachable {
7595
return None;
7696
}
@@ -124,12 +144,12 @@ mod tests {
124144
let laptop = rect(0, 25, 1440, 875);
125145
let saved = rect(100, -450, 960, 640);
126146
assert_frame(
127-
super::reachable_frame(saved, 48, &[laptop], laptop),
147+
super::reachable_frame(saved, saved, 48, &[laptop], laptop),
128148
Some(rect(240, 25, 960, 640)),
129149
);
130150
let upper = rect(0, -900, 1440, 900);
131151
assert_frame(
132-
super::reachable_frame(saved, 48, &[laptop, upper], laptop),
152+
super::reachable_frame(saved, saved, 48, &[laptop, upper], laptop),
133153
None,
134154
);
135155
}
@@ -140,7 +160,7 @@ mod tests {
140160
let left = rect(-1920, 0, 1920, 1080);
141161
for saved in [rect(100, 120, 960, 640), rect(-1800, 80, 960, 640)] {
142162
assert_frame(
143-
super::reachable_frame(saved, 48, &[primary, left], primary),
163+
super::reachable_frame(saved, saved, 48, &[primary, left], primary),
144164
None,
145165
);
146166
}
@@ -156,7 +176,7 @@ mod tests {
156176
rect(100, 860, 960, 640),
157177
] {
158178
assert_frame(
159-
super::reachable_frame(saved, 48, &[area], area),
179+
super::reachable_frame(saved, saved, 48, &[area], area),
160180
Some(rect(240, 25, 960, 640)),
161181
);
162182
}
@@ -166,19 +186,68 @@ mod tests {
166186
fn oversized_window_fits_remaining_work_area_and_scaled_header_is_checked() {
167187
let area = rect(0, 50, 1440, 850);
168188
assert_frame(
169-
super::reachable_frame(rect(0, 50, 2800, 1800), 96, &[area], area),
189+
super::reachable_frame(
190+
rect(0, 50, 2800, 1800),
191+
rect(0, 50, 2800, 1800),
192+
96,
193+
&[area],
194+
area,
195+
),
170196
Some(area),
171197
);
172198
assert_frame(
173-
super::reachable_frame(rect(100, 820, 960, 640), 48, &[area], area),
199+
super::reachable_frame(
200+
rect(100, 820, 960, 640),
201+
rect(100, 820, 960, 640),
202+
48,
203+
&[area],
204+
area,
205+
),
174206
None,
175207
);
176208
assert_frame(
177-
super::reachable_frame(rect(100, 820, 960, 640), 96, &[area], area),
209+
super::reachable_frame(
210+
rect(100, 820, 960, 640),
211+
rect(100, 820, 960, 640),
212+
96,
213+
&[area],
214+
area,
215+
),
178216
Some(rect(240, 50, 960, 640)),
179217
);
180218
}
181219

220+
#[test]
221+
fn invisible_windows_frame_border_does_not_displace_edge_flush_client() {
222+
let area = rect(0, 0, 1920, 1040);
223+
assert_frame(
224+
super::reachable_frame(
225+
rect(-7, 0, 1934, 1047),
226+
rect(0, 0, 1920, 1040),
227+
48,
228+
&[area],
229+
area,
230+
),
231+
None,
232+
);
233+
}
234+
235+
#[test]
236+
fn header_can_span_adjacent_monitors_but_not_extend_above_either() {
237+
let left = rect(-1920, 0, 1920, 1080);
238+
let right = rect(0, 0, 1920, 1080);
239+
let spanning = rect(-480, 100, 960, 640);
240+
assert_frame(
241+
super::reachable_frame(spanning, spanning, 48, &[left, right], right),
242+
None,
243+
);
244+
let below = rect(0, 300, 1920, 1080);
245+
assert_frame(
246+
super::reachable_frame(spanning, spanning, 48, &[left, below], left),
247+
Some(rect(-1440, 0, 960, 640)),
248+
);
249+
}
250+
182251
fn fixture() -> (tempfile::TempDir, tauri::App<MockRuntime>) {
183252
let dir = tempfile::tempdir().unwrap();
184253
let mut context = mock_context(noop_assets());

0 commit comments

Comments
 (0)