Nested window: follow the host's size instead of being cropped

The --window backend pinned its xdg_toplevel to a fixed size (min == max ==
1280x720 or --size) and ignored xdg_toplevel.configure. Whenever the host gave
the window less room than that (a tiling host, a maximized/snapped window, a
screen smaller than the default once its own panels and title bar are taken
off), the host cropped the 1280x720 buffer and the right/bottom of the desktop,
panel included, was cut off. Fullscreen only looked right when the screen
happened to be at least that big.

- nested: drop the max size (min 640x400), read the configure size and, on
  xdg_wm_base v4, configure_bounds to fit the first size on screen; report a
  new size through take_resize.
- compositor: MoonPlasmaCompositor::resize recomputes the work area, tells
  clients the new wl_output mode, reflows every workspace and pulls floating
  windows back inside (WmState::fit_work_area), and forces a full redraw.
- both main loops (wasm component and native) resize before presenting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hkYa7dkDnotDeMSdX7
This commit is contained in:
Claude authored and V committed 2026-11-25 17:07:33 +00:00
1 parent 0f4c84b966
commit 7248e0ca6e
9 files changed
+220 -22

No files matched your search

+77 -11
View File
@@ -48,10 +48,29 @@ pub(all) struct NestedWindow {
mut closed : Bool
mut px : Double
mut py : Double
width : Int
height : Int
/// Current window size: what the compositor draws at and what each frame is attached as.
mut width : Int
mut height : Int
/// Size from the latest xdg_toplevel.configure (0 = the host leaves it to us), applied when
/// the xdg_surface.configure that ends the sequence arrives.
mut cfg_w : Int
mut cfg_h : Int
/// Largest size the host suggests for a window (xdg_toplevel.configure_bounds: the screen
/// minus its panels); 0 = unknown. The first size is fitted inside it.
mut bound_w : Int
mut bound_h : Int
/// Set when the host resized the window; cleared by take_resize.
mut resized : Bool
/// The first configure was handled.
mut mapped : Bool
}
///| Smallest size the window may be resized to (the panel and a window or two still fit).
pub let min_width : Int = 640
///|
pub let min_height : Int = 400
///|
fn NestedWindow::alloc(self : NestedWindow) -> UInt {
let id = self.next_id
@@ -164,10 +183,39 @@ fn NestedWindow::dispatch(
w.u32(serial)
self.send(w.finish_msg(self.xdg_surf_id, 4U))
self.configured = true
// The host chose a size (resized, maximized, tiled or fullscreen): draw at that size, so
// the desktop is never cropped to a window smaller than our buffer.
// Left to us, the first size still has to fit the screen the host has room for.
let fit_w = if !self.mapped && self.bound_w > 0 && self.width > self.bound_w {
clamp_min(self.bound_w, min_width)
} else {
self.width
}
let fit_h = if !self.mapped && self.bound_h > 0 && self.height > self.bound_h {
clamp_min(self.bound_h, min_height)
} else {
self.height
}
self.mapped = true
let nw = if self.cfg_w > 0 { clamp_min(self.cfg_w, min_width) } else { fit_w }
let nh = if self.cfg_h > 0 { clamp_min(self.cfg_h, min_height) } else { fit_h }
if nw != self.width || nh != self.height {
self.width = nw
self.height = nh
self.resized = true
}
}
} else if obj == self.toplevel_id {
if op == 1U {
if op == 0U {
// configure(width, height, states): 0 x 0 means "pick your own size".
self.cfg_w = r.i32()
self.cfg_h = r.i32()
} else if op == 1U {
self.closed = true
} else if op == 2U {
// configure_bounds(width, height), xdg_wm_base v4+
self.bound_w = r.i32()
self.bound_h = r.i32()
}
} else if obj == self.seat_id {
if op == 0U {
@@ -351,6 +399,12 @@ pub fn NestedWindow::open(
py: 0.0,
width,
height,
cfg_w: 0,
cfg_h: 0,
bound_w: 0,
bound_h: 0,
resized: false,
mapped: false,
}
let w = @wayland.WireWriter::new()
w.u32(2U)
@@ -358,7 +412,7 @@ pub fn NestedWindow::open(
self.roundtrip()
self.comp_id = self.bind("wl_compositor", 4U)
self.shm_id = self.bind("wl_shm", 1U)
self.wm_id = self.bind("xdg_wm_base", 2U)
self.wm_id = self.bind("xdg_wm_base", 4U) // v4: configure_bounds
self.seat_id = self.bind("wl_seat", 5U)
self.shape_mgr_id = self.bind("wp_cursor_shape_manager_v1", 1U)
if self.comp_id == 0U || self.shm_id == 0U || self.wm_id == 0U {
@@ -384,14 +438,11 @@ pub fn NestedWindow::open(
let w5 = @wayland.WireWriter::new()
w5.str(app_id)
self.send(w5.finish_msg(self.toplevel_id, 3U))
// Fixed size: min == max == output size.
let w6 = @wayland.WireWriter::new()
w6.i32(width)
w6.i32(height)
self.send(w6.finish_msg(self.toplevel_id, 7U)) // set_max_size
// Resizable: the host may give us any size from the minimum up (no max size), and the
// compositor follows it (see take_resize).
let w7 = @wayland.WireWriter::new()
w7.i32(width)
w7.i32(height)
w7.i32(min_width)
w7.i32(min_height)
self.send(w7.finish_msg(self.toplevel_id, 8U)) // set_min_size
self.send(@wayland.WireWriter::new().finish_msg(self.surf_id, 6U)) // commit
let mut tries = 0
@@ -414,6 +465,21 @@ pub fn NestedWindow::poll(self : NestedWindow) -> Bool {
!self.closed
}
///|
fn clamp_min(v : Int, lo : Int) -> Int {
if v < lo { lo } else { v }
}
///| The new window size if the host resized the window since the last call. The caller resizes
/// the desktop to it before presenting the next frame.
pub fn NestedWindow::take_resize(self : NestedWindow) -> (Int, Int)? {
if !self.resized {
return None
}
self.resized = false
Some((self.width, self.height))
}
///| Take all input received since the last call.
pub fn NestedWindow::take_input(self : NestedWindow) -> Array[InputEvent] {
let out = self.input.copy()