Files
Claude 0fc2598d27
CI / test (push) Failing after 17s
Delta drew in a 640x480 corner of a full-size window: ask again when a client keeps another size
GPUI apps (Delta, Zed) answer a configure that takes the maximized state away by going back to
their old floating size, whatever size it asks for. Unmaximized into a tiled slot (or a layout
change while maximized), Delta kept drawing 640x480 and Chandra padded it out with the bottom
right colour to the whole frame, so only the sidebar and toolbar showed.

The server now tracks each toplevel's last configure and the serial the client acked. When a
client commits a buffer of another size after acking the latest configure, the same configure
is sent once more (GPUI, no longer maximized then, takes it). A client that still keeps its own
size gets a ToplevelSizeChosen: a floating window's frame follows it, a tiled, maximized or
fullscreen window keeps the compositor's size. Sizes take set_window_geometry and
set_buffer_scale into account.

CHANDRA_DEBUG_CONFIGURE=1 logs configures, acks and committed buffer sizes to stderr.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiKUmCPZNFNiGwd8EW
2026-11-25 20:55:58 +00:00

168 lines
6.3 KiB
MoonBit

///| Clients that answer a configure with another size than the one asked for.
///| What a GPUI app (Zed, Delta) does with a configure (gpui's wayland window.rs): leaving the
/// maximized state, it goes back to the size it had before, whatever size the configure asks
/// for; otherwise it takes the configure's size and remembers it as its floating size.
struct GpuiModel {
mut maximized : Bool
mut bounds_w : Int
mut bounds_h : Int
}
///|
fn GpuiModel::respond(self : GpuiModel, w : Int, h : Int, max : Bool) -> (Int, Int) {
let got_unmaximized = self.maximized && !max
self.maximized = max
if max {
(w, h)
} else if got_unmaximized {
(self.bounds_w, self.bounds_h)
} else {
self.bounds_w = w
self.bounds_h = h
(w, h)
}
}
///|
fn pump_client(comp : @host.ChandraCompositor, c : TestWaylandClient, xdg : UInt, tl : UInt) -> Unit {
for _i = 0; _i < 6; _i = _i + 1 {
comp.step()
c.read_events(xdg, tl, 0U)
@sys.sleep_ms(2)
}
}
///| Ack every configure received since the last call, the way `size_for` decides, then draw
/// one solid frame of the last size. Returns that size (or None when nothing was configured).
fn answer_configures(
comp : @host.ChandraCompositor,
c : TestWaylandClient,
shm : UInt,
surf : UInt,
xdg : UInt,
tl : UInt,
size_for : (Int, Int, Bool) -> (Int, Int),
) -> (Int, Int)? {
pump_client(comp, c, xdg, tl)
if c.configures.length() == 0 {
return None
}
let mut size = (0, 0)
for cfg in c.configures {
let (w, h, max, serial) = cfg
size = size_for(w, h, max)
let ack = @wayland.WireWriter::new()
ack.u32(serial)
c.send(ack.finish_msg(xdg, 4U))
}
c.configures.clear()
let (w, h) = size
let fd = solid_memfd(w, h, b'\x80', b'\x80', b'\x80')
let pool = c.alloc_id()
let p = @wayland.WireWriter::new()
p.u32(pool)
p.i32(w * h * 4)
c.send(p.finish_msg(shm, 0U), send_fd=fd)
@sys.close_fd(fd)
let buf = c.alloc_id()
let cb = @wayland.WireWriter::new()
cb.u32(buf)
cb.i32(0)
cb.i32(w)
cb.i32(h)
cb.i32(w * 4)
cb.u32(0U)
c.send(cb.finish_msg(pool, 0U))
attach_commit(comp, c, surf, Some(buf))
Some(size)
}
///|
fn toplevel_request(comp : @host.ChandraCompositor, c : TestWaylandClient, tl : UInt, opcode : UInt) -> Unit {
c.send(@wayland.WireWriter::new().finish_msg(tl, opcode))
for _i = 0; _i < 3; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
}
///|
fn drawn_size(comp : @host.ChandraCompositor, wid : UInt64) -> (Int, Int) {
match comp.windows.get(wid) {
Some({ surface: Some(s), .. }) => (s.width, s.height)
_ => (0, 0)
}
}
///|
fn frame_size(comp : @host.ChandraCompositor, wid : UInt64) -> (Int, Int) {
let g = comp.windows.get(wid).unwrap().geometry
(g.w, g.h)
}
///|
test "a GPUI app leaving the maximized state for a tiled slot draws the whole window" {
// Delta showed its sidebar and toolbar in a 640x480 corner of a full-screen frame: unmaximized
// into a tiled slot, GPUI went back to its old floating size, and nothing asked it again.
let socket_path = "/tmp/wayland-moon-gpui-unmax-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
comp.set_layout_mode(@wm.LayoutMode::Floating)
let (c, shm, surf, xdg, tl, _deco) = open_and_configure_client(comp, socket_path, "Delta", "dev.delta.Delta")
let gpui : GpuiModel = { maximized: false, bounds_w: 0, bounds_h: 0 }
let size_for = fn(w, h, max) { gpui.respond(w, h, max) }
ignore(answer_configures(comp, c, shm, surf, xdg, tl, size_for))
assert_eq(drawn_size(comp, 1UL), (640, 480))
assert_eq(frame_size(comp, 1UL), (640, 480))
// Maximize, tile the desktop, then leave the maximized state: the window keeps its tiled slot.
toplevel_request(comp, c, tl, 9U) // set_maximized
ignore(answer_configures(comp, c, shm, surf, xdg, tl, size_for))
comp.set_layout_mode(@wm.LayoutMode::Tiling)
ignore(answer_configures(comp, c, shm, surf, xdg, tl, size_for))
toplevel_request(comp, c, tl, 10U) // unset_maximized
assert_eq(answer_configures(comp, c, shm, surf, xdg, tl, size_for), Some((640, 480)))
// Chandra asks again with the same configure; out of the maximized state, GPUI takes it.
let again = answer_configures(comp, c, shm, surf, xdg, tl, size_for)
let slot = frame_size(comp, 1UL)
assert_true(slot.0 > 1000 && slot.1 > 500)
assert_eq(again, Some(slot))
assert_eq(drawn_size(comp, 1UL), slot)
// ...and then leaves it alone: no configure loop.
assert_eq(answer_configures(comp, c, shm, surf, xdg, tl, size_for), None)
@sys.close_fd(c.fd)
comp.close()
}
///|
test "a floating window that keeps its own size gets a frame of that size" {
let socket_path = "/tmp/wayland-moon-own-size-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
comp.set_layout_mode(@wm.LayoutMode::Floating)
let (c, shm, surf, xdg, tl, _deco) = open_and_configure_client(comp, socket_path, "Fixed", "org.example.fixed")
let fixed = fn(_w, _h, _max) { (500, 400) }
ignore(answer_configures(comp, c, shm, surf, xdg, tl, fixed)) // asked 640x480, drew 500x400
ignore(answer_configures(comp, c, shm, surf, xdg, tl, fixed)) // asked again, same answer
ignore(answer_configures(comp, c, shm, surf, xdg, tl, fixed)) // the frame follows: 500x400
assert_eq(frame_size(comp, 1UL), (500, 400))
assert_eq(drawn_size(comp, 1UL), (500, 400))
assert_eq(answer_configures(comp, c, shm, surf, xdg, tl, fixed), None)
@sys.close_fd(c.fd)
comp.close()
}
///|
test "a tiled window that keeps its own size is asked once more, then left alone" {
let socket_path = "/tmp/wayland-moon-tiled-own-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
let (c, shm, surf, xdg, tl, _deco) = open_and_configure_client(comp, socket_path, "Fixed", "org.example.fixed")
let slot = frame_size(comp, 1UL)
let fixed = fn(_w, _h, _max) { (500, 400) }
ignore(answer_configures(comp, c, shm, surf, xdg, tl, fixed))
ignore(answer_configures(comp, c, shm, surf, xdg, tl, fixed))
assert_eq(answer_configures(comp, c, shm, surf, xdg, tl, fixed), None)
assert_eq(frame_size(comp, 1UL), slot)
@sys.close_fd(c.fd)
comp.close()
}