From 0a9787ae36ae17f7a68a57fac452423db0d793ef Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 02:27:04 +0000 Subject: [PATCH] Chrome's own frame: honor zxdg_toplevel_decoration_v1.set_mode(client_side) Chrome with "Use system title bar and borders" off, and its installed web apps (PWAs), ask for client-side decoration. Chandra always answered server-side, and Chrome kept drawing its own title bar and shadow anyway (window geometry 10px in), so Chandra's title bar showed above Chrome's with Chrome's shadow as a gap. Now a client asking for client_side gets it and is framed like a GTK window (ToplevelFrame client_side); unset_mode or server_side keep Chandra's frame. Checked with Chromium 158 on Ozone Wayland, headless. Test in csd_test.mbt. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DPL5hkfW5ttNd831XmdsC5 --- compositor/host/csd_test.mbt | 38 +++++++++++++++++++++++++++++++++++ compositor/wayland/server.mbt | 26 ++++++++++++++++++------ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/compositor/host/csd_test.mbt b/compositor/host/csd_test.mbt index 74e592a..c195019 100644 --- a/compositor/host/csd_test.mbt +++ b/compositor/host/csd_test.mbt @@ -179,3 +179,41 @@ test "dragging a GTK header bar moves the window, and its border resizes it" { comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 23U) } } + +///| +test "Chrome asking to draw its own frame gets it, instead of a second one around it" { + // Chrome with "Use system title bar and borders" off (and its installed web apps) asks for + // client-side decoration and keeps drawing its own title bar and shadow even when told + // server-side: Chandra's title bar showed above Chrome's, with Chrome's shadow as a gap. + let socket_path = "/tmp/wayland-moon-csd-chrome-" + @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, "YouTube", "chrome-youtube") + assert_eq(c.deco_mode, Some(2U)) + // zxdg_toplevel_decoration_v1.set_mode(client_side) + let m = @wayland.WireWriter::new() + m.u32(1U) + c.send(m.finish_msg(deco, 1U)) + for _i = 0; _i < 4; _i = _i + 1 { + comp.step() + c.read_events(xdg, tl, deco) + @sys.sleep_ms(2) + } + assert_eq(c.deco_mode, Some(1U)) + ignore(gtk_frame(comp, c, shm, surf, xdg, tl)) + let win = comp.windows.get(1UL).unwrap() + assert_true(win.csd) + let r = win.client_rect() + assert_eq((r.w, r.h), (win.geometry.w + 4, win.geometry.h + 34)) + + // unset_mode: back to Chandra's frame. + c.send(@wayland.WireWriter::new().finish_msg(deco, 2U)) + for _i = 0; _i < 4; _i = _i + 1 { + comp.step() + c.read_events(xdg, tl, deco) + @sys.sleep_ms(2) + } + assert_eq(c.deco_mode, Some(2U)) + ignore(gtk_frame(comp, c, shm, surf, xdg, tl)) + assert_false(comp.windows.get(1UL).unwrap().csd) +} diff --git a/compositor/wayland/server.mbt b/compositor/wayland/server.mbt index 9c4a03c..5f95b20 100644 --- a/compositor/wayland/server.mbt +++ b/compositor/wayland/server.mbt @@ -141,6 +141,9 @@ struct ToplevelState { mut cfg_retry : Int /// The last ToplevelFrame sent (client_side, x, y), None before the first. mut frame_sent : (Bool, Int, Int)? + /// zxdg_toplevel_decoration_v1.set_mode(client_side): the client wants to draw its own frame + /// (Chrome with "Use system title bar and borders" off) and is told it may. + mut wants_csd : Bool } ///| xdg_positioner state. @@ -465,7 +468,7 @@ fn send_delete_id(c : ClientConn, id : UInt) -> Unit { ///| fn send_decoration_mode(c : ClientConn, deco_id : UInt, mode : UInt) -> Unit { let w = WireWriter::new() - w.u32(mode) // 2 = ServerSide + w.u32(mode) // 1 = ClientSide, 2 = ServerSide c.send_msg(w.finish_msg(deco_id, 0U)) } @@ -655,7 +658,7 @@ fn WaylandServer::dispatch_msg( Some(xs) => (xs.geo_x, xs.geo_y) None => (0, 0) } - let frame = (tl.deco_obj_id is None, gx, gy) + let frame = (tl.deco_obj_id is None || tl.wants_csd, gx, gy) if tl.frame_sent != Some(frame) { tl.frame_sent = Some(frame) events.push(ToplevelFrame(wid, frame.0, gx, gy)) @@ -995,6 +998,7 @@ fn WaylandServer::dispatch_msg( acked_serial: 0U, cfg_retry: 0, frame_sent: None, + wants_csd: false, }) self.win_to_client.set(wid, c.client_id) } else if opcode == 2U { @@ -1048,6 +1052,7 @@ fn WaylandServer::dispatch_msg( acked_serial: 0U, cfg_retry: 0, frame_sent: None, + wants_csd: false, }) self.win_to_client.set(wid, c.client_id) // xdg_popup.configure(x, y, w, h) then xdg_surface.configure(serial) @@ -1205,15 +1210,24 @@ fn WaylandServer::dispatch_msg( if opcode == 0U { // Without its decoration object the client goes back to drawing its own frame. match c.toplevels.get(wid) { - Some(tl) if tl.deco_obj_id == Some(obj_id) => tl.deco_obj_id = None + Some(tl) if tl.deco_obj_id == Some(obj_id) => { + tl.deco_obj_id = None + tl.wants_csd = false + } _ => () } c.objects.remove(obj_id) send_delete_id(c, obj_id) } else if opcode == 1U || opcode == 2U { - // Always enforce Server-Side Decoration (2) - ignore(wid) - send_decoration_mode(c, obj_id, 2U) + // set_mode(mode) / unset_mode. A client asking to draw its own frame gets it: Chrome + // (custom frame) keeps drawing its title bar and shadow even when told server-side, + // which showed both frames. Anything else, and unset_mode, gets Chandra's frame. + let csd = opcode == 1U && reader.u32() == 1U + match c.toplevels.get(wid) { + Some(tl) => tl.wants_csd = csd + None => () + } + send_decoration_mode(c, obj_id, if csd { 1U } else { 2U }) } ObjSeat => if opcode == 0U {