Delta drew in a 640x480 corner of a full-size window: ask again when a client keeps another size
CI / test (push) Failing after 17s
CI / test (push) Failing after 17s
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
This commit is contained in:
5 files changed
+359
-7
No files matched your search
@@ -472,6 +472,17 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@wayland.CompositorEvent::ToplevelSizeChosen(wid, w, h) =>
|
||||
// The client keeps its own size after being asked twice. A floating window is the
|
||||
// client's to size: the frame follows it instead of padding the buffer out. A tiled,
|
||||
// maximized or fullscreen window keeps the compositor's size.
|
||||
match self.wm.windows.get(wid) {
|
||||
Some(r) =>
|
||||
if r.is_floating && !r.maximized && !r.fullscreen && self.wm.drag is None && self.split_drag is None {
|
||||
self.apply_actions(self.wm.handle_request(wid, @wm.WindowRequest::ResizeTo(w, h), self.work_area))
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@wayland.CompositorEvent::PopupOpened(wid, parent, rx, ry, w, h) => {
|
||||
// Keyboard focus stays on the parent until the popup grabs and maps: moving it away
|
||||
// early makes clients (Chrome, Qt) take the keyboard leave as "dismiss the menu".
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
///| 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()
|
||||
}
|
||||
@@ -13,6 +13,10 @@ struct TestWaylandClient {
|
||||
mut configured_w : Int
|
||||
mut configured_h : Int
|
||||
mut configure_serial : UInt?
|
||||
/// The last xdg_toplevel.configure had the maximized state.
|
||||
mut configured_max : Bool
|
||||
/// Every configure received, in order, as (width, height, maximized, serial).
|
||||
configures : Array[(Int, Int, Bool, UInt)]
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -30,6 +34,8 @@ fn TestWaylandClient::connect(socket_path : String) -> TestWaylandClient? {
|
||||
configured_w: 0,
|
||||
configured_h: 0,
|
||||
configure_serial: None,
|
||||
configured_max: false,
|
||||
configures: [],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -92,14 +98,22 @@ fn TestWaylandClient::read_events(
|
||||
// xdg_toplevel.configure(width, height, states)
|
||||
let w = reader.i32()
|
||||
let h = reader.i32()
|
||||
let _states = reader.array()
|
||||
let states = reader.array()
|
||||
self.configured_max = false
|
||||
for i = 0; i + 3 < states.length(); i = i + 4 {
|
||||
if states[i] == b'\x01' {
|
||||
self.configured_max = true
|
||||
}
|
||||
}
|
||||
if w > 0 && h > 0 {
|
||||
self.configured_w = w
|
||||
self.configured_h = h
|
||||
}
|
||||
} else if obj_id == xdg_surf_id && opcode == 0U {
|
||||
// xdg_surface.configure(serial)
|
||||
self.configure_serial = Some(reader.u32())
|
||||
let serial = reader.u32()
|
||||
self.configure_serial = Some(serial)
|
||||
self.configures.push((self.configured_w, self.configured_h, self.configured_max, serial))
|
||||
}
|
||||
off = off + size
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user