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
@@ -5,6 +5,10 @@ pub(all) enum CompositorEvent {
|
||||
ToplevelOpened(UInt64, String, String, Int, Int)
|
||||
ToplevelUpdated(UInt64, String, String)
|
||||
ToplevelCommitted(UInt64, @scene.ShmBufferSnapshot?)
|
||||
/// The client acked the compositor's last configure, was asked again, and still drew a
|
||||
/// different size: (id, w, h) is the size it chose. A floating window takes it (xdg-shell lets
|
||||
/// a client pick its own size when it is not maximized, fullscreen or tiled).
|
||||
ToplevelSizeChosen(UInt64, Int, Int)
|
||||
ToplevelClosed(UInt64)
|
||||
ToplevelMaximizeRequest(UInt64, Bool)
|
||||
ToplevelFullscreenRequest(UInt64, Bool)
|
||||
@@ -85,6 +89,8 @@ struct SurfaceState {
|
||||
mut pending_frame_cb : UInt?
|
||||
mut xdg_surface_id : UInt?
|
||||
mut window_id : UInt64?
|
||||
/// wl_surface.set_buffer_scale: the buffer is this many times the window's size.
|
||||
mut buffer_scale : Int
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -94,6 +100,9 @@ struct XdgSurfaceState {
|
||||
/// set_window_geometry origin: where the visible window starts inside the buffer (shadows).
|
||||
mut geo_x : Int
|
||||
mut geo_y : Int
|
||||
/// set_window_geometry size (0 until the client sets one: the window is the whole buffer).
|
||||
mut geo_w : Int
|
||||
mut geo_h : Int
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -112,6 +121,16 @@ struct ToplevelState {
|
||||
mut has_parent : Bool
|
||||
/// Set for xdg_popup surfaces (they live in `toplevels` so input routing is shared).
|
||||
popup_parent : UInt64?
|
||||
/// The last xdg_toplevel.configure sent: size, states and its xdg_surface serial (0 = none).
|
||||
mut cfg_w : Int
|
||||
mut cfg_h : Int
|
||||
mut cfg_states : Array[Byte]
|
||||
mut cfg_serial : UInt
|
||||
/// The serial of the last configure the client acked.
|
||||
mut acked_serial : UInt
|
||||
/// How far the last configure got with a client drawing another size after acking it:
|
||||
/// 0 not yet, 1 sent again, 2 reported as ToplevelSizeChosen.
|
||||
mut cfg_retry : Int
|
||||
}
|
||||
|
||||
///| xdg_positioner state.
|
||||
@@ -261,6 +280,8 @@ pub(all) struct WaylandServer {
|
||||
mut own_data : Bytes
|
||||
/// Clipboard pastes of `own_data` still being written: (pipe fd, bytes written, give up at ms).
|
||||
transfers : Array[(Int, Int, UInt64)]
|
||||
/// CHANDRA_DEBUG_CONFIGURE=1: log each configure, ack and committed buffer size to stderr.
|
||||
mut debug_configure : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -290,6 +311,7 @@ pub fn WaylandServer::listen(
|
||||
own_mimes: [],
|
||||
own_data: Bytes::from_array([]),
|
||||
transfers: [],
|
||||
debug_configure: @sys.getenv("CHANDRA_DEBUG_CONFIGURE").length() > 0,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -555,6 +577,7 @@ fn WaylandServer::dispatch_msg(
|
||||
pending_frame_cb: None,
|
||||
xdg_surface_id: None,
|
||||
window_id: None,
|
||||
buffer_scale: 1,
|
||||
})
|
||||
} else if opcode == 1U {
|
||||
let rid = reader.u32()
|
||||
@@ -583,6 +606,10 @@ fn WaylandServer::dispatch_msg(
|
||||
// frame(callback)
|
||||
let cb_id = reader.u32()
|
||||
surf.pending_frame_cb = Some(cb_id)
|
||||
} else if opcode == 8U {
|
||||
// set_buffer_scale(scale)
|
||||
let sc = reader.i32()
|
||||
surf.buffer_scale = if sc > 0 { sc } else { 1 }
|
||||
} else if opcode == 6U {
|
||||
// commit
|
||||
match surf.window_id {
|
||||
@@ -612,6 +639,10 @@ fn WaylandServer::dispatch_msg(
|
||||
None => None
|
||||
}
|
||||
events.push(ToplevelCommitted(wid, snap))
|
||||
match snap {
|
||||
Some(sn) => self.check_committed_size(c, tl, surf, sn, events)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@@ -854,7 +885,7 @@ fn WaylandServer::dispatch_msg(
|
||||
let xsid = reader.u32()
|
||||
let wl_sid = reader.u32()
|
||||
c.objects.set(xsid, ObjXdgSurface(xsid))
|
||||
c.xdg_surfaces.set(xsid, { wl_surface_id: wl_sid, window_id: None, geo_x: 0, geo_y: 0 })
|
||||
c.xdg_surfaces.set(xsid, { wl_surface_id: wl_sid, window_id: None, geo_x: 0, geo_y: 0, geo_w: 0, geo_h: 0 })
|
||||
match c.surfaces.get(wl_sid) {
|
||||
Some(s) => s.xdg_surface_id = Some(xsid)
|
||||
None => ()
|
||||
@@ -865,14 +896,34 @@ fn WaylandServer::dispatch_msg(
|
||||
c.xdg_surfaces.remove(xsid)
|
||||
c.objects.remove(xsid)
|
||||
send_delete_id(c, xsid)
|
||||
} else if opcode == 4U {
|
||||
// ack_configure(serial)
|
||||
let serial = reader.u32()
|
||||
match c.xdg_surfaces.get(xsid) {
|
||||
Some({ window_id: Some(wid), .. }) =>
|
||||
match c.toplevels.get(wid) {
|
||||
Some(tl) => {
|
||||
tl.acked_serial = serial
|
||||
if self.debug_configure {
|
||||
@sys.log("chandra-wl: window \{wid} ack_configure \{serial}")
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
} else if opcode == 3U {
|
||||
// set_window_geometry(x, y, w, h)
|
||||
let gx = reader.i32()
|
||||
let gy = reader.i32()
|
||||
let gw = reader.i32()
|
||||
let gh = reader.i32()
|
||||
match c.xdg_surfaces.get(xsid) {
|
||||
Some(xs) => {
|
||||
xs.geo_x = gx
|
||||
xs.geo_y = gy
|
||||
xs.geo_w = gw
|
||||
xs.geo_h = gh
|
||||
match xs.window_id {
|
||||
Some(wid) =>
|
||||
match c.toplevels.get(wid) {
|
||||
@@ -914,6 +965,12 @@ fn WaylandServer::dispatch_msg(
|
||||
opened_sent: false,
|
||||
has_parent: false,
|
||||
popup_parent: None,
|
||||
cfg_w: 0,
|
||||
cfg_h: 0,
|
||||
cfg_states: [],
|
||||
cfg_serial: 0U,
|
||||
acked_serial: 0U,
|
||||
cfg_retry: 0,
|
||||
})
|
||||
self.win_to_client.set(wid, c.client_id)
|
||||
} else if opcode == 2U {
|
||||
@@ -960,6 +1017,12 @@ fn WaylandServer::dispatch_msg(
|
||||
opened_sent: true,
|
||||
has_parent: true,
|
||||
popup_parent: Some(parent_wid),
|
||||
cfg_w: 0,
|
||||
cfg_h: 0,
|
||||
cfg_states: [],
|
||||
cfg_serial: 0U,
|
||||
acked_serial: 0U,
|
||||
cfg_retry: 0,
|
||||
})
|
||||
self.win_to_client.set(wid, c.client_id)
|
||||
// xdg_popup.configure(x, y, w, h) then xdg_surface.configure(serial)
|
||||
@@ -1312,16 +1375,111 @@ pub fn WaylandServer::send_toplevel_configure(
|
||||
if activated {
|
||||
push_state(4U)
|
||||
}
|
||||
tl.cfg_w = width
|
||||
tl.cfg_h = height
|
||||
tl.cfg_states = states
|
||||
tl.cfg_retry = 0
|
||||
self.write_configure(c, tl)
|
||||
}
|
||||
|
||||
///| Write the toplevel's current configure (cfg_w, cfg_h, cfg_states) with a new serial.
|
||||
fn WaylandServer::write_configure(
|
||||
self : WaylandServer,
|
||||
c : ClientConn,
|
||||
tl : ToplevelState,
|
||||
) -> Unit {
|
||||
let w1 = WireWriter::new()
|
||||
w1.i32(width)
|
||||
w1.i32(height)
|
||||
w1.array(states)
|
||||
w1.i32(tl.cfg_w)
|
||||
w1.i32(tl.cfg_h)
|
||||
w1.array(tl.cfg_states)
|
||||
c.send_msg(w1.finish_msg(tl.wl_toplevel_id, 0U))
|
||||
|
||||
let serial = self.next_serial()
|
||||
tl.cfg_serial = serial
|
||||
let w2 = WireWriter::new()
|
||||
w2.u32(self.next_serial())
|
||||
w2.u32(serial)
|
||||
c.send_msg(w2.finish_msg(tl.xdg_surface_id, 0U))
|
||||
if self.debug_configure {
|
||||
let names : Array[String] = []
|
||||
for i = 0; i + 3 < tl.cfg_states.length(); i = i + 4 {
|
||||
names.push(
|
||||
match tl.cfg_states[i].to_int() {
|
||||
1 => "maximized"
|
||||
2 => "fullscreen"
|
||||
3 => "resizing"
|
||||
4 => "activated"
|
||||
n => n.to_string()
|
||||
},
|
||||
)
|
||||
}
|
||||
@sys.log(
|
||||
"chandra-wl: window \{tl.win_id} configure \{tl.cfg_w}x\{tl.cfg_h} [\{names.join(",")}] serial \{serial}" +
|
||||
(if tl.cfg_retry > 0 { " (sent again)" } else { "" }),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
///| After a commit with a buffer: compare the window's size with the configure the client acked.
|
||||
///
|
||||
/// A client may answer a configure with another size. GPUI apps (Zed, Delta) do on purpose when
|
||||
/// a configure takes the maximized state away: they go back to the size they had before being
|
||||
/// maximized, even when the compositor asked for a tiled window's full size. The window then
|
||||
/// showed the app in a small corner of a large frame. Asked once more with the same configure (the
|
||||
/// client is no longer in the maximized state then), they take the size. A client that still
|
||||
/// picks its own size gets a ToplevelSizeChosen, and the host keeps it for a floating window.
|
||||
fn WaylandServer::check_committed_size(
|
||||
self : WaylandServer,
|
||||
c : ClientConn,
|
||||
tl : ToplevelState,
|
||||
surf : SurfaceState,
|
||||
snap : @scene.ShmBufferSnapshot,
|
||||
events : Array[CompositorEvent],
|
||||
) -> Unit {
|
||||
let (w, h) = committed_size(c, surf, snap)
|
||||
if self.debug_configure {
|
||||
@sys.log(
|
||||
"chandra-wl: window \{tl.win_id} commit buffer \{snap.width}x\{snap.height} scale \{surf.buffer_scale} -> window \{w}x\{h} (configured \{tl.cfg_w}x\{tl.cfg_h}, acked \{tl.acked_serial}/\{tl.cfg_serial})",
|
||||
)
|
||||
}
|
||||
// Only once the client has acked the latest configure: before that, an old-sized frame is
|
||||
// just the client catching up.
|
||||
if tl.cfg_serial == 0U || tl.acked_serial != tl.cfg_serial || tl.cfg_w <= 0 || tl.cfg_h <= 0 {
|
||||
return
|
||||
}
|
||||
if w == tl.cfg_w && h == tl.cfg_h {
|
||||
return
|
||||
}
|
||||
if tl.cfg_retry == 0 {
|
||||
tl.cfg_retry = 1
|
||||
self.write_configure(c, tl)
|
||||
} else if tl.cfg_retry == 1 {
|
||||
tl.cfg_retry = 2
|
||||
events.push(ToplevelSizeChosen(tl.win_id, w, h))
|
||||
}
|
||||
}
|
||||
|
||||
///| The window size a committed buffer stands for: the window geometry when the client set one
|
||||
/// (a client drawing its own shadows), else the buffer divided by its scale.
|
||||
fn committed_size(
|
||||
c : ClientConn,
|
||||
surf : SurfaceState,
|
||||
snap : @scene.ShmBufferSnapshot,
|
||||
) -> (Int, Int) {
|
||||
let geo = match surf.xdg_surface_id {
|
||||
Some(xsid) =>
|
||||
match c.xdg_surfaces.get(xsid) {
|
||||
Some(xs) if xs.geo_w > 0 && xs.geo_h > 0 => Some((xs.geo_w, xs.geo_h))
|
||||
_ => None
|
||||
}
|
||||
None => None
|
||||
}
|
||||
match geo {
|
||||
Some(g) => g
|
||||
None => {
|
||||
let sc = if surf.buffer_scale > 0 { surf.buffer_scale } else { 1 }
|
||||
(snap.width / sc, snap.height / sc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
|
||||
Reference in new issue
Block a user