srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/x11/src/platform/tests.rs
diff options
context:
space:
mode:
authorsrdusr <[email protected]>2025-11-10 09:31:00 +0200
committersrdusr <[email protected]>2025-11-10 09:31:00 +0200
commitf988203a7c22d945383efa9609f5c8a09a9506d2 (patch)
treea88281daee61cf148362e7b83132a86a5ae43444 /crates/x11/src/platform/tests.rs
parentea78f94027ecd2c690904a6d7729e9e3cc190a20 (diff)
downloadsrdwm-f988203a7c22d945383efa9609f5c8a09a9506d2.tar.gz
srdwm-f988203a7c22d945383efa9609f5c8a09a9506d2.zip
Fix a maximized X11 window overhanging the screen by its own border
Reported by the aegis-fc peer session testing srdwm's own layer-shell strut handling: a maximized X11 client sat 4-8px past the right and bottom screen edges whenever its border was nonzero. set_border_width sets the frame's native X11 border-width attribute, which the X server draws outside a window's own declared width/height on all four sides - unlike every other backend's own border in this compositor (rendered as ordinary pixels inside the allocated geometry rect). apply_geometry configured the frame at geometry's own x/y/width/ height verbatim, so a nonzero native border pushed the frame's true visible footprint 2*border_width past every edge of what geometry actually promised. Fixed by shifting the configured origin inward and the configured size down by border_width on both axes (frame_geometry_for, pulled out as a pure function so it's unit-tested without a real X11 connection) - the visible footprint, native border included, now lands exactly on geometry. border_width == 0 reduces to the prior behavior exactly.
Diffstat (limited to 'crates/x11/src/platform/tests.rs')
-rw-r--r--crates/x11/src/platform/tests.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/x11/src/platform/tests.rs b/crates/x11/src/platform/tests.rs
index 7af5455..fbae5ff 100644
--- a/crates/x11/src/platform/tests.rs
+++ b/crates/x11/src/platform/tests.rs
@@ -95,3 +95,35 @@
let usable = usable_rect(full, (1920, 1080), std::iter::empty());
assert_eq!(usable, full);
}
+
+ #[test]
+ fn zero_border_width_leaves_the_frame_geometry_unchanged() {
+ let geom = Rect::new(0, 0, 1920, 1080);
+ assert_eq!(frame_geometry_for(geom, 0), (0, 0, 1920, 1080));
+ }
+
+ #[test]
+ fn a_real_border_width_keeps_the_true_footprint_equal_to_the_requested_geometry() {
+ // Live-reported bug: a maximized window with a native X11 border
+ // sat 2*border_width pixels past the right/bottom edges, since the
+ // border draws outside the configured width/height. The true
+ // on-screen footprint - configured origin minus the border on the
+ // near side, configured size plus the border on both sides - must
+ // reproduce the original geometry exactly.
+ let geom = Rect::new(100, 50, 1920, 1080);
+ let (x, y, w, h) = frame_geometry_for(geom, 4);
+ assert_eq!((x - 4, y - 4, w + 8, h + 8), (geom.x, geom.y, geom.width, geom.height));
+ }
+
+ #[test]
+ fn a_maximized_window_no_longer_overhangs_the_monitor_with_a_real_border() {
+ // The exact live scenario: a window maximized to fill the whole
+ // monitor must not visually extend past it just because it also
+ // has a nonzero border.
+ let monitor = Rect::new(0, 0, 1920, 1080);
+ let (x, y, w, h) = frame_geometry_for(monitor, 4);
+ assert_eq!(x - 4, 0, "left edge (including border) must not sit left of the monitor");
+ assert_eq!(y - 4, 0, "top edge (including border) must not sit above the monitor");
+ assert_eq!(x + w as i32 + 4, 1920, "right edge (including border) must not overhang the monitor");
+ assert_eq!(y + h as i32 + 4, 1080, "bottom edge (including border) must not overhang the monitor");
+ }