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

+11
View File
@@ -244,6 +244,17 @@ pub fn run(args : Array[String]) -> Int {
if n.keymap.length() > 0 {
comp.server.set_keymap(n.keymap)
}
// The window was resized (or maximized / made fullscreen): follow it, or the
// desktop stays drawn at the old size and is cropped by the smaller window.
match n.take_resize() {
Some((nw, nh)) => {
width = nw
height = nh
comp.resize(nw, nh)
need_present = true
}
None => ()
}
let now_ms = @sys.monotonic_ms().to_uint()
for ev in n.take_input() {
comp.handle_input(ev, now_ms)
+5
View File
@@ -148,6 +148,11 @@ fn main {
if n.keymap.length() > 0 {
comp.server.set_keymap(n.keymap)
}
// Follow the window's size, or the desktop is cropped when the window is smaller.
match n.take_resize() {
Some((nw, nh)) => comp.resize(nw, nh)
None => ()
}
let now_ms = @env.now().to_uint()
for ev in n.take_input() {
comp.handle_input(ev, now_ms)
+31 -9
View File
@@ -33,9 +33,9 @@ pub(all) struct MoonPlasmaCompositor {
server : @wayland.WaylandServer
wm : @wm.WmState
theme : @scene.ThemeTokens
output_w : Int
output_h : Int
work_area : @wm.Rect
mut output_w : Int
mut output_h : Int
mut work_area : @wm.Rect
windows : Map[UInt64, HostWindow]
damage : @scene.DamageTracker
shell : @shell.DesktopShell
@@ -91,12 +91,7 @@ pub fn MoonPlasmaCompositor::new(
titlebar_h=32,
border_w=2,
)
let out_rect : @wm.Rect = { x: 0, y: 0, w: output_w, h: output_h }
let work_area = @wm.compute_work_area(
out_rect,
excl_top=32, // room for the server-side title bar drawn above each client
excl_bottom=theme.panel_height,
)
let work_area = work_area_for(output_w, output_h, theme)
let shell = @shell.DesktopShell::new(socket_path)
shell.set_output(theme, output_w, output_h)
Some({
@@ -135,6 +130,33 @@ pub fn MoonPlasmaCompositor::new(
})
}
///| The part of a `w` x `h` output windows are laid out in.
fn work_area_for(w : Int, h : Int, theme : @scene.ThemeTokens) -> @wm.Rect {
@wm.compute_work_area(
{ x: 0, y: 0, w, h },
excl_top=32, // room for the server-side title bar drawn above each client
excl_bottom=theme.panel_height,
)
}
///| The output changed size (the nested window was resized, maximized or made fullscreen):
/// lay the desktop out for the new size, so nothing is drawn past the edge and cropped away.
pub fn MoonPlasmaCompositor::resize(self : MoonPlasmaCompositor, w : Int, h : Int) -> Unit {
if w <= 0 || h <= 0 || (w == self.output_w && h == self.output_h) {
return
}
self.output_w = w
self.output_h = h
self.work_area = work_area_for(w, h, self.theme)
self.server.set_output_size(w, h)
self.shell.set_output(self.theme, w, h)
self.apply_actions(self.wm.fit_work_area(self.work_area))
self.last_frame = None
self.last_sig = None
self.frame_changed = true
self.damage.mark_full()
}
///|
pub fn MoonPlasmaCompositor::close(self : MoonPlasmaCompositor) -> Unit {
for _, win in self.windows {
+16
View File
@@ -0,0 +1,16 @@
///| Resizing the output (the nested window was resized): the desktop is drawn at the new size.
///|
test "resize redraws the desktop at the new output size" {
let socket_path = "/tmp/wayland-moon-resize-" + @sys.getpid().to_string() + ".sock"
let comp = @host.MoonPlasmaCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
let before = comp.compose_frame()
assert_eq((before.width, before.height), (1280, 720))
comp.resize(900, 560)
let after = comp.compose_frame()
assert_eq((after.width, after.height), (900, 560))
assert_eq((comp.output_w, comp.output_h), (900, 560))
assert_eq(comp.work_area.h, 560 - 32 - comp.theme.panel_height)
assert_eq(comp.server.output_w, 900)
comp.close()
}
+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()
+27 -2
View File
@@ -221,8 +221,8 @@ fn ClientConn::close_all(self : ClientConn) -> Unit {
pub(all) struct WaylandServer {
socket_path : String
listen_fd : Int
output_w : Int
output_h : Int
mut output_w : Int
mut output_h : Int
clients : Array[ClientConn]
win_to_client : Map[UInt64, UInt]
mut next_client_id : UInt
@@ -321,6 +321,31 @@ fn emit_seat_info(c : ClientConn, seat_id : UInt) -> Unit {
c.send_msg(w2.finish_msg(seat_id, 1U))
}
///| The output changed size (the nested window was resized): tell every bound wl_output.
pub fn WaylandServer::set_output_size(self : WaylandServer, w : Int, h : Int) -> Unit {
if w == self.output_w && h == self.output_h {
return
}
self.output_w = w
self.output_h = h
for c in self.clients {
if !c.alive {
continue
}
for id, kind in c.objects {
if kind is ObjOutput {
let m = WireWriter::new()
m.u32(3U) // current | preferred
m.i32(w)
m.i32(h)
m.i32(60000)
c.send_msg(m.finish_msg(id, 1U))
c.send_msg(WireWriter::new().finish_msg(id, 2U)) // done
}
}
}
}
///|
fn emit_output_info(
c : ClientConn,