Files
chandra/compositor/host/csd_test.mbt
T
Claude 90fdda2455
CI / test (push) Successful in 2m57s
Client-drawn window frames: GTK apps (GNOME Files) get no second title bar
GTK never asks for server-side decoration (it has no xdg-decoration support), so it draws its
own header bar plus a transparent shadow margin around it, and says where the real window is
with xdg_surface.set_window_geometry. Chandra drew its Breeze frame around every window anyway
and blitted the whole buffer from the frame's corner: a second title bar on top, and the
content shifted down/right by the shadow (a see-through gap), with the right/bottom cut off.

- The server reports per window who draws the frame (ToplevelFrame: client-side when the
  client never made a zxdg_toplevel_decoration_v1, plus the window-geometry offset).
- A client-decorated window gets no Chandra frame and fills the frame's whole box
  (HostWindow::client_rect): it is configured for that size, drawn with its buffer shifted by
  the geometry offset (its own shadow drawn around it), and pointer coordinates and popup
  placement use the same origin. Tiling, title-bar hit areas and resize zones are unchanged.
- xdg_toplevel.move / resize (dragging a header bar, a CSD border) start Chandra's move and
  resize drags; they were ignored before.
- Tiled windows get the tiled_left/right/top/bottom states, so GTK drops its shadow and
  rounded corners there.

Checked with real Nautilus 46 and gtk4-demo on the headless native compositor. Tests:
compositor/host/csd_test.mbt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hkfW5ttNd831XmdsC5
2026-11-26 01:35:31 +00:00

182 lines
6.9 KiB
MoonBit

///| Client-side decorated windows: GTK apps (GNOME Files, most GNOME apps) never ask for
/// server-side decoration, draw their own title bar, and put a shadow around it in the buffer.
///| The shadow a GTK window draws around itself, in buffer pixels.
let gtk_shadow : Int = 24
///| Answer the last configure the way GTK does: a buffer `w` x `h` plus the shadow on every
/// side, the visible window (solid red, its own title bar included) announced with
/// set_window_geometry, the shadow transparent.
fn gtk_frame(
comp : @host.ChandraCompositor,
c : TestWaylandClient,
shm : UInt,
surf : UInt,
xdg : UInt,
tl : UInt,
) -> (Int, Int) {
for _i = 0; _i < 6; _i = _i + 1 {
comp.step()
c.read_events(xdg, tl, 0U)
@sys.sleep_ms(2)
}
for cfg in c.configures {
let ack = @wayland.WireWriter::new()
ack.u32(cfg.3)
c.send(ack.finish_msg(xdg, 4U))
}
c.configures.clear()
let w = c.configured_w
let h = c.configured_h
let s = gtk_shadow
let bw = w + 2 * s
let bh = h + 2 * s
let px : Array[Byte] = Array(capacity=bw * bh * 4)
for y = 0; y < bh; y = y + 1 {
for x = 0; x < bw; x = x + 1 {
if x >= s && x < s + w && y >= s && y < s + h {
px.push(b'\x00')
px.push(b'\x00')
px.push(b'\xff')
px.push(b'\xff')
} else {
for _k = 0; _k < 4; _k = _k + 1 {
px.push(b'\x00')
}
}
}
}
let fd = @sys.memfd_create("gtk-frame", bw * bh * 4)
ignore(@sys.pwrite_bytes(fd, Bytes::from_array(px), 0))
let pool = c.alloc_id()
let p = @wayland.WireWriter::new()
p.u32(pool)
p.i32(bw * bh * 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(bw)
cb.i32(bh)
cb.i32(bw * 4)
cb.u32(0U)
c.send(cb.finish_msg(pool, 0U))
// xdg_surface.set_window_geometry(x, y, w, h)
let g = @wayland.WireWriter::new()
g.i32(s)
g.i32(s)
g.i32(w)
g.i32(h)
c.send(g.finish_msg(xdg, 3U))
attach_commit(comp, c, surf, Some(buf))
(w, h)
}
///|
fn csd_setup(name : String) -> (@host.ChandraCompositor, TestWaylandClient, UInt, UInt, UInt, UInt) {
let socket_path = "/tmp/wayland-moon-csd-" + name + "-" + @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, _) = open_and_configure_client(
comp,
socket_path,
"Home",
"org.gnome.Nautilus",
server_deco=false,
)
(comp, c, shm, surf, xdg, tl)
}
///|
test "a GTK window draws its own frame: no second title bar, and its shadow is not the window" {
// GNOME Files showed its own header bar inside a Chandra-titled frame, with its transparent
// shadow margin drawn as part of the window (content shifted down/right and cut off).
let (comp, c, shm, surf, xdg, tl) = csd_setup("frame")
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
let win = comp.windows.get(1UL).unwrap()
assert_true(win.csd)
assert_eq((win.geo_x, win.geo_y), (gtk_shadow, gtk_shadow))
// The client is asked to fill the frame's whole box: where Chandra's title bar would be is its own.
let r = win.client_rect()
assert_eq((r.w, r.h), (win.geometry.w + 4, win.geometry.h + 34))
let (w, h) = gtk_frame(comp, c, shm, surf, xdg, tl)
assert_eq((w, h), (r.w, r.h))
let red = Some(@scene.Rgba::new(0xff, 0, 0, 0xff))
let frame = comp.compose_frame()
// The client's pixels start right at the box's top-left (no Chandra title bar over them)
// and fill it to the bottom-right corner.
assert_eq(frame.pixel(r.x + 3, r.y + 3), red)
assert_eq(frame.pixel(r.x + r.w - 3, r.y + r.h - 3), red)
// The transparent shadow is not drawn as part of the window.
assert_true(frame.pixel(r.x + r.w + 10, r.y + 10) != red)
assert_true(frame.pixel(r.x + 10, r.y - 10) != red)
}
///|
test "a server-decorated client keeps Chandra's frame" {
let socket_path = "/tmp/wayland-moon-csd-ssd-" + @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, _) = open_and_configure_client(comp, socket_path, "Dolphin", "org.kde.dolphin")
let size_for = fn(w, h, _max) { (w, h) }
ignore(answer_configures(comp, c, shm, surf, xdg, tl, size_for))
let win = comp.windows.get(1UL).unwrap()
assert_false(win.csd)
let r = win.client_rect()
assert_eq((r.x, r.y, r.w, r.h), (win.geometry.x, win.geometry.y, win.geometry.w, win.geometry.h))
}
///|
test "dragging a GTK header bar moves the window, and its border resizes it" {
let (comp, c, shm, surf, xdg, tl) = csd_setup("move")
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
let before = comp.windows.get(1UL).unwrap().geometry
let r = comp.windows.get(1UL).unwrap().client_rect()
// Press on the header bar (the client's own), which answers with xdg_toplevel.move.
let (px, py) = (r.x + r.w / 2, r.y + 15)
comp.handle_input(@nested.InputEvent::PointerMove(px.to_double(), py.to_double()), 10U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 11U)
assert_true(comp.wm.drag is None) // the press went to the client, not to a Chandra title bar
let mv = @wayland.WireWriter::new()
mv.u32(0U) // seat
mv.u32(1U) // serial
c.send(mv.finish_msg(tl, 5U))
for _i = 0; _i < 4; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
assert_true(comp.wm.drag is Some(_))
comp.handle_input(@nested.InputEvent::PointerMove((px + 60).to_double(), (py + 40).to_double()), 12U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 13U)
let after = comp.windows.get(1UL).unwrap().geometry
assert_eq((after.x - before.x, after.y - before.y), (60, 40))
assert_eq((after.w, after.h), (before.w, before.h))
// xdg_toplevel.resize from the bottom-right corner (edges 10).
let r = comp.windows.get(1UL).unwrap().client_rect()
let (px, py) = (r.x + r.w - 2, r.y + r.h - 2)
comp.handle_input(@nested.InputEvent::PointerMove(px.to_double(), py.to_double()), 20U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 21U)
let rs = @wayland.WireWriter::new()
rs.u32(0U)
rs.u32(2U)
rs.u32(10U)
c.send(rs.finish_msg(tl, 6U))
for _i = 0; _i < 4; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
if comp.wm.drag is Some(_) {
comp.handle_input(@nested.InputEvent::PointerMove((px + 30).to_double(), (py + 20).to_double()), 22U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 23U)
let resized = comp.windows.get(1UL).unwrap().geometry
assert_eq((resized.w - after.w, resized.h - after.h), (30, 20))
} else {
// The press landed in one of Chandra's own resize zones instead: also a resize.
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 23U)
}
}