Client-drawn window frames: GTK apps (GNOME Files) get no second title bar
CI / test (push) Successful in 2m57s

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
This commit is contained in:
Claude committed 2026-11-26 01:35:31 +00:00
1 parent b097116ded
commit 90fdda2455
5 files changed
+405 -33

No files matched your search

+121 -27
View File
@@ -12,6 +12,41 @@ pub(all) struct HostWindow {
mut surface : @scene.ShmBufferSnapshot?
/// A size change still to be sent to the client (coalesced while dragging a divider).
mut cfg_dirty : Bool
/// The client draws its own title bar and shadow (GTK: GNOME Files and most GNOME apps).
/// Chandra then draws no frame: the client fills the box the frame would have taken
/// (`client_rect`), and `geo_x`/`geo_y` is where that box starts inside its buffer.
mut csd : Bool
mut geo_x : Int
mut geo_y : Int
}
///| Height of the server-side title bar above `geometry`, and the frame's side/bottom border:
/// the layout in `@scene.build_breeze_decoration` (outer box w + 4, h + 34).
let frame_top : Int = 32
///|
let frame_side : Int = 2
///| The box the client's own window fills on screen. A server-decorated window's is its
/// geometry (Chandra's frame goes around it); a client-decorated one takes the frame's whole
/// outer box, so tiling, title-bar hit areas and resize zones are the same for both kinds.
pub fn HostWindow::client_rect(self : HostWindow) -> @scene.Rect {
let g = self.geometry
if self.csd && !self.fullscreen {
@scene.Rect::new(g.x - frame_side, g.y - frame_top, g.w + 2 * frame_side, g.h + frame_top + frame_side)
} else {
g
}
}
///| Screen position of the client buffer's top-left pixel (surface-local (0, 0)).
pub fn HostWindow::surface_origin(self : HostWindow) -> (Int, Int) {
let r = self.client_rect()
if self.csd {
(r.x - self.geo_x, r.y - self.geo_y)
} else {
(r.x, r.y)
}
}
///| A client popup (xdg_popup): menus, combo lists, tooltips.
@@ -371,14 +406,7 @@ fn ChandraCompositor::apply_actions(
win.cfg_dirty = true
} else {
win.cfg_dirty = false
self.server.send_toplevel_configure(
wid,
r.w,
r.h,
win.focused,
win.maximized,
win.fullscreen,
)
self.configure_window(win)
}
self.damage.mark_full()
}
@@ -410,20 +438,33 @@ fn ChandraCompositor::apply_actions(
///| Send the size changes coalesced during a divider drag.
fn ChandraCompositor::flush_configures(self : ChandraCompositor) -> Unit {
for wid, win in self.windows {
ignore(wid)
if win.cfg_dirty {
win.cfg_dirty = false
self.server.send_toplevel_configure(
wid,
win.geometry.w,
win.geometry.h,
win.focused,
win.maximized,
win.fullscreen,
)
self.configure_window(win)
}
}
}
///| Send a window its size and states. A client-decorated window is asked for the frame's whole
/// box (`client_rect`): its own title bar goes where Chandra's would have been.
fn ChandraCompositor::configure_window(self : ChandraCompositor, win : HostWindow) -> Unit {
let r = win.client_rect()
let tiled = match self.wm.windows.get(win.id) {
Some(rec) => !rec.is_floating
None => false
}
self.server.send_toplevel_configure(
win.id,
r.w,
r.h,
win.focused,
win.maximized,
win.fullscreen,
tiled~,
)
}
///|
pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
self.flush_configures()
@@ -444,6 +485,9 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
fullscreen: false,
surface: None,
cfg_dirty: false,
csd: false,
geo_x: 0,
geo_y: 0,
}
self.windows.set(wid, win)
// An app whose window was last left somewhere reopens there, floating, kept on screen.
@@ -521,13 +565,31 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
// 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) =>
match (self.wm.windows.get(wid), self.windows.get(wid)) {
(Some(r), Some(win)) =>
if r.is_floating && !r.maximized && !r.fullscreen && self.wm.drag is None && self.split_drag is None {
// A client-decorated window's size includes the room of Chandra's frame.
let (w, h) = if win.csd { (w - 2 * frame_side, h - frame_top - frame_side) } else { (w, h) }
self.apply_actions(self.wm.handle_request(wid, @wm.WindowRequest::ResizeTo(w, h), self.work_area))
}
_ => ()
}
@wayland.CompositorEvent::ToplevelFrame(wid, csd, gx, gy) =>
match self.windows.get(wid) {
Some(win) => {
let changed = win.csd != csd
win.csd = csd
win.geo_x = gx
win.geo_y = gy
if changed {
// The client's box just grew or shrank by the frame: ask for the new size.
self.configure_window(win)
}
self.damage.mark_full()
}
None => ()
}
@wayland.CompositorEvent::ToplevelResizeRequest(wid, edges) => self.client_resize(wid, edges)
@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".
@@ -622,7 +684,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
)
self.apply_actions(actions)
}
@wayland.CompositorEvent::ToplevelMoveRequest(_) => ()
@wayland.CompositorEvent::ToplevelMoveRequest(wid) => self.client_move(wid)
}
}
self.session_tick()
@@ -720,6 +782,27 @@ fn ChandraCompositor::build_scene(
for wid in shown {
match self.windows.get(wid) {
Some(win) if win.csd => {
// The client draws its own frame and shadow: no Chandra frame (`fullscreen` in the
// scene means "undecorated"), and the whole buffer is drawn, shadow included.
let (ox, oy) = win.surface_origin()
let r = win.client_rect()
let (bw, bh) = match win.surface {
Some(s) => (s.width, s.height)
None => (r.w, r.h)
}
scene.windows.push({
id: win.id,
title: win.title,
app_id: win.app_id,
focused: win.focused,
fullscreen: true,
geometry: @scene.Rect::new(ox, oy, bw, bh),
deco_insets: (0, 0, 0, 0),
deco_ops: [],
surface: win.surface,
})
}
Some(win) => {
let (insets, deco_ops) = @scene.build_breeze_decoration(
win.title,
@@ -925,7 +1008,11 @@ pub fn ChandraCompositor::handle_gfx_events(
/// positioners are relative to).
fn ChandraCompositor::origin_of(self : ChandraCompositor, wid : UInt64) -> (Int, Int) {
match self.windows.get(wid) {
Some(win) => (win.geometry.x, win.geometry.y)
Some(win) => {
// Popups are placed relative to the window geometry (past a client-drawn shadow).
let r = win.client_rect()
(r.x, r.y)
}
None => {
for p in self.popups {
if p.id == wid {
@@ -1081,6 +1168,15 @@ fn ChandraCompositor::window_at(self : ChandraCompositor, x : Int, y : Int) -> (
match self.windows.get(order[i]) {
Some(win) => {
let g = win.geometry
if win.csd {
// A client-decorated window is all client: its title bar is its own.
let r = win.client_rect()
if x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h {
return Some((win.id, true))
}
i = i - 1
continue
}
if x >= g.x && x < g.x + g.w && y >= g.y && y < g.y + g.h {
return Some((win.id, true))
}
@@ -1482,8 +1578,9 @@ pub fn ChandraCompositor::handle_input(
self.shell.desktop_leave()
match self.windows.get(wid) {
Some(win) => {
let lx = x - win.geometry.x.to_double()
let ly = y - win.geometry.y.to_double()
let (ox, oy) = win.surface_origin()
let lx = x - ox.to_double()
let ly = y - oy.to_double()
if self.ptr_win != Some(wid) {
self.leave_pointer()
self.ptr_win = Some(wid)
@@ -1539,11 +1636,8 @@ pub fn ChandraCompositor::handle_input(
if self.ptr_win != Some(wid) {
self.leave_pointer()
self.ptr_win = Some(wid)
self.server.pointer_enter(
wid,
self.ptr_x - win.geometry.x.to_double(),
self.ptr_y - win.geometry.y.to_double(),
)
let (ox, oy) = win.surface_origin()
self.server.pointer_enter(wid, self.ptr_x - ox.to_double(), self.ptr_y - oy.to_double())
}
self.server.pointer_axis(wid, time_ms, axis, v, discrete)
}