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? mut surface : @scene.ShmBufferSnapshot?
/// A size change still to be sent to the client (coalesced while dragging a divider). /// A size change still to be sent to the client (coalesced while dragging a divider).
mut cfg_dirty : Bool 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. ///| A client popup (xdg_popup): menus, combo lists, tooltips.
@@ -371,14 +406,7 @@ fn ChandraCompositor::apply_actions(
win.cfg_dirty = true win.cfg_dirty = true
} else { } else {
win.cfg_dirty = false win.cfg_dirty = false
self.server.send_toplevel_configure( self.configure_window(win)
wid,
r.w,
r.h,
win.focused,
win.maximized,
win.fullscreen,
)
} }
self.damage.mark_full() self.damage.mark_full()
} }
@@ -410,20 +438,33 @@ fn ChandraCompositor::apply_actions(
///| Send the size changes coalesced during a divider drag. ///| Send the size changes coalesced during a divider drag.
fn ChandraCompositor::flush_configures(self : ChandraCompositor) -> Unit { fn ChandraCompositor::flush_configures(self : ChandraCompositor) -> Unit {
for wid, win in self.windows { for wid, win in self.windows {
ignore(wid)
if win.cfg_dirty { if win.cfg_dirty {
win.cfg_dirty = false win.cfg_dirty = false
self.server.send_toplevel_configure( self.configure_window(win)
wid,
win.geometry.w,
win.geometry.h,
win.focused,
win.maximized,
win.fullscreen,
)
} }
} }
} }
///| 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 { pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
self.flush_configures() self.flush_configures()
@@ -444,6 +485,9 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
fullscreen: false, fullscreen: false,
surface: None, surface: None,
cfg_dirty: false, cfg_dirty: false,
csd: false,
geo_x: 0,
geo_y: 0,
} }
self.windows.set(wid, win) self.windows.set(wid, win)
// An app whose window was last left somewhere reopens there, floating, kept on screen. // 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 // 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, // 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. // maximized or fullscreen window keeps the compositor's size.
match self.wm.windows.get(wid) { match (self.wm.windows.get(wid), self.windows.get(wid)) {
Some(r) => (Some(r), Some(win)) =>
if r.is_floating && !r.maximized && !r.fullscreen && self.wm.drag is None && self.split_drag is None { 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)) 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 => () None => ()
} }
@wayland.CompositorEvent::ToplevelResizeRequest(wid, edges) => self.client_resize(wid, edges)
@wayland.CompositorEvent::PopupOpened(wid, parent, rx, ry, w, h) => { @wayland.CompositorEvent::PopupOpened(wid, parent, rx, ry, w, h) => {
// Keyboard focus stays on the parent until the popup grabs and maps: moving it away // 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". // 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) self.apply_actions(actions)
} }
@wayland.CompositorEvent::ToplevelMoveRequest(_) => () @wayland.CompositorEvent::ToplevelMoveRequest(wid) => self.client_move(wid)
} }
} }
self.session_tick() self.session_tick()
@@ -720,6 +782,27 @@ fn ChandraCompositor::build_scene(
for wid in shown { for wid in shown {
match self.windows.get(wid) { 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) => { Some(win) => {
let (insets, deco_ops) = @scene.build_breeze_decoration( let (insets, deco_ops) = @scene.build_breeze_decoration(
win.title, win.title,
@@ -925,7 +1008,11 @@ pub fn ChandraCompositor::handle_gfx_events(
/// positioners are relative to). /// positioners are relative to).
fn ChandraCompositor::origin_of(self : ChandraCompositor, wid : UInt64) -> (Int, Int) { fn ChandraCompositor::origin_of(self : ChandraCompositor, wid : UInt64) -> (Int, Int) {
match self.windows.get(wid) { 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 => { None => {
for p in self.popups { for p in self.popups {
if p.id == wid { if p.id == wid {
@@ -1081,6 +1168,15 @@ fn ChandraCompositor::window_at(self : ChandraCompositor, x : Int, y : Int) -> (
match self.windows.get(order[i]) { match self.windows.get(order[i]) {
Some(win) => { Some(win) => {
let g = win.geometry 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 { if x >= g.x && x < g.x + g.w && y >= g.y && y < g.y + g.h {
return Some((win.id, true)) return Some((win.id, true))
} }
@@ -1482,8 +1578,9 @@ pub fn ChandraCompositor::handle_input(
self.shell.desktop_leave() self.shell.desktop_leave()
match self.windows.get(wid) { match self.windows.get(wid) {
Some(win) => { Some(win) => {
let lx = x - win.geometry.x.to_double() let (ox, oy) = win.surface_origin()
let ly = y - win.geometry.y.to_double() let lx = x - ox.to_double()
let ly = y - oy.to_double()
if self.ptr_win != Some(wid) { if self.ptr_win != Some(wid) {
self.leave_pointer() self.leave_pointer()
self.ptr_win = Some(wid) self.ptr_win = Some(wid)
@@ -1539,11 +1636,8 @@ pub fn ChandraCompositor::handle_input(
if self.ptr_win != Some(wid) { if self.ptr_win != Some(wid) {
self.leave_pointer() self.leave_pointer()
self.ptr_win = Some(wid) self.ptr_win = Some(wid)
self.server.pointer_enter( let (ox, oy) = win.surface_origin()
wid, self.server.pointer_enter(wid, self.ptr_x - ox.to_double(), self.ptr_y - oy.to_double())
self.ptr_x - win.geometry.x.to_double(),
self.ptr_y - win.geometry.y.to_double(),
)
} }
self.server.pointer_axis(wid, time_ms, axis, v, discrete) self.server.pointer_axis(wid, time_ms, axis, v, discrete)
} }
+181
View File
@@ -0,0 +1,181 @@
///| 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)
}
}
+9 -6
View File
@@ -157,6 +157,7 @@ fn open_and_configure_client(
socket_path : String, socket_path : String,
title : String, title : String,
app_id : String, app_id : String,
server_deco? : Bool = true,
) -> (TestWaylandClient, UInt, UInt, UInt, UInt, UInt) { ) -> (TestWaylandClient, UInt, UInt, UInt, UInt, UInt) {
let c = TestWaylandClient::connect(socket_path).unwrap() let c = TestWaylandClient::connect(socket_path).unwrap()
// 1. wl_display.get_registry(id=2) // 1. wl_display.get_registry(id=2)
@@ -206,12 +207,14 @@ fn open_and_configure_client(
w_a.str(app_id) w_a.str(app_id)
c.send(w_a.finish_msg(toplevel_id, 3U)) c.send(w_a.finish_msg(toplevel_id, 3U))
// get_toplevel_decoration // get_toplevel_decoration (GTK never does: it draws its own frame)
let deco_id = c.alloc_id() let deco_id = if server_deco { c.alloc_id() } else { 0U }
let w_dc = @wayland.WireWriter::new() if server_deco {
w_dc.u32(deco_id) let w_dc = @wayland.WireWriter::new()
w_dc.u32(toplevel_id) w_dc.u32(deco_id)
c.send(w_dc.finish_msg(deco_mgr_id, 1U)) w_dc.u32(toplevel_id)
c.send(w_dc.finish_msg(deco_mgr_id, 1U))
}
// initial commit // initial commit
let w_cm = @wayland.WireWriter::new() let w_cm = @wayland.WireWriter::new()
+51
View File
@@ -127,3 +127,54 @@ fn ChandraCompositor::title_bar_release(self : ChandraCompositor) -> Unit {
None => () None => ()
} }
} }
///|
/// xdg_toplevel.move from a client-decorated window (a press on its own title bar): the same
/// drag as a press on Chandra's title bar, without the double-click (the client handles that
/// and asks to maximize). Only while the press that asked for it is still held.
fn ChandraCompositor::client_move(self : ChandraCompositor, wid : UInt64) -> Unit {
if !self.press_fwd || self.ptr_win != Some(wid) || self.wm.drag is Some(_) {
return
}
// The compositor takes the pointer for the drag: the client sees it leave (and no release).
self.press_fwd = false
self.leave_pointer()
let x = self.ptr_x.to_int()
let y = self.ptr_y.to_int()
let tiled = match self.wm.windows.get(wid) {
Some(r) => !r.is_floating && !r.maximized && !r.fullscreen
None => return
}
self.title_press = Some({ wid, x, y, time: 0, held: true, moved: true, float_pending: tiled })
if !tiled {
ignore(self.wm.start_drag(wid, @wm.DragMode::Move, x, y))
}
}
///|
/// xdg_toplevel.resize from a client-decorated window (a press on its own border or shadow):
/// a floating window resizes from that edge, like Chandra's own resize zones. Tiled windows
/// resize through the dividers instead.
fn ChandraCompositor::client_resize(self : ChandraCompositor, wid : UInt64, edges : UInt) -> Unit {
if !self.press_fwd || self.ptr_win != Some(wid) || self.wm.drag is Some(_) {
return
}
match self.wm.windows.get(wid) {
Some(r) => if !r.is_floating || r.maximized || r.fullscreen { return }
None => return
}
let mode = match edges {
1U => @wm.DragMode::ResizeN
2U => @wm.DragMode::ResizeS
4U => @wm.DragMode::ResizeW
8U => @wm.DragMode::ResizeE
5U => @wm.DragMode::ResizeNW
9U => @wm.DragMode::ResizeNE
6U => @wm.DragMode::ResizeSW
10U => @wm.DragMode::ResizeSE
_ => return
}
self.press_fwd = false
self.leave_pointer()
ignore(self.wm.start_drag(wid, mode, self.ptr_x.to_int(), self.ptr_y.to_int()))
}
+43
View File
@@ -14,6 +14,14 @@ pub(all) enum CompositorEvent {
ToplevelFullscreenRequest(UInt64, Bool) ToplevelFullscreenRequest(UInt64, Bool)
ToplevelMinimizeRequest(UInt64, Bool) ToplevelMinimizeRequest(UInt64, Bool)
ToplevelMoveRequest(UInt64) ToplevelMoveRequest(UInt64)
/// xdg_toplevel.resize from a client-decorated window: (id, edges), the xdg_toplevel
/// resize_edge bits (1 top, 2 bottom, 4 left, 8 right).
ToplevelResizeRequest(UInt64, UInt)
/// Who draws the window's frame, sent with a commit when it changes: (id, client_side, x, y).
/// A client that never asked for server-side decoration (GTK: GNOME Files, most GNOME apps)
/// draws its own title bar and shadow; (x, y) is where its visible window starts inside the
/// buffer (xdg_surface.set_window_geometry), past the shadow.
ToplevelFrame(UInt64, Bool, Int, Int)
/// xdg_popup created: (id, parent window id, x, y, w, h) relative to the parent's content. /// xdg_popup created: (id, parent window id, x, y, w, h) relative to the parent's content.
PopupOpened(UInt64, UInt64, Int, Int, Int, Int) PopupOpened(UInt64, UInt64, Int, Int, Int, Int)
PopupCommitted(UInt64, @scene.ShmBufferSnapshot?) PopupCommitted(UInt64, @scene.ShmBufferSnapshot?)
@@ -131,6 +139,8 @@ struct ToplevelState {
/// How far the last configure got with a client drawing another size after acking it: /// 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. /// 0 not yet, 1 sent again, 2 reported as ToplevelSizeChosen.
mut cfg_retry : Int mut cfg_retry : Int
/// The last ToplevelFrame sent (client_side, x, y), None before the first.
mut frame_sent : (Bool, Int, Int)?
} }
///| xdg_positioner state. ///| xdg_positioner state.
@@ -638,6 +648,19 @@ fn WaylandServer::dispatch_msg(
Some(bid) => snapshot_shm_buffer(c, bid) Some(bid) => snapshot_shm_buffer(c, bid)
None => None None => None
} }
if snap is Some(_) {
// Who draws the frame: a client that never made an xdg-decoration
// object (GTK) decorates itself.
let (gx, gy) = match c.xdg_surfaces.get(tl.xdg_surface_id) {
Some(xs) => (xs.geo_x, xs.geo_y)
None => (0, 0)
}
let frame = (tl.deco_obj_id is None, gx, gy)
if tl.frame_sent != Some(frame) {
tl.frame_sent = Some(frame)
events.push(ToplevelFrame(wid, frame.0, gx, gy))
}
}
events.push(ToplevelCommitted(wid, snap)) events.push(ToplevelCommitted(wid, snap))
match snap { match snap {
Some(sn) => self.check_committed_size(c, tl, surf, sn, events) Some(sn) => self.check_committed_size(c, tl, surf, sn, events)
@@ -971,6 +994,7 @@ fn WaylandServer::dispatch_msg(
cfg_serial: 0U, cfg_serial: 0U,
acked_serial: 0U, acked_serial: 0U,
cfg_retry: 0, cfg_retry: 0,
frame_sent: None,
}) })
self.win_to_client.set(wid, c.client_id) self.win_to_client.set(wid, c.client_id)
} else if opcode == 2U { } else if opcode == 2U {
@@ -1023,6 +1047,7 @@ fn WaylandServer::dispatch_msg(
cfg_serial: 0U, cfg_serial: 0U,
acked_serial: 0U, acked_serial: 0U,
cfg_retry: 0, cfg_retry: 0,
frame_sent: None,
}) })
self.win_to_client.set(wid, c.client_id) self.win_to_client.set(wid, c.client_id)
// xdg_popup.configure(x, y, w, h) then xdg_surface.configure(serial) // xdg_popup.configure(x, y, w, h) then xdg_surface.configure(serial)
@@ -1133,6 +1158,11 @@ fn WaylandServer::dispatch_msg(
} else if opcode == 5U { } else if opcode == 5U {
// move // move
events.push(ToplevelMoveRequest(wid)) events.push(ToplevelMoveRequest(wid))
} else if opcode == 6U {
// resize(seat, serial, edges)
let _seat = reader.u32()
let _serial = reader.u32()
events.push(ToplevelResizeRequest(wid, reader.u32()))
} else if opcode == 8U { } else if opcode == 8U {
// set_min_size // set_min_size
let mw = reader.i32() let mw = reader.i32()
@@ -1173,6 +1203,11 @@ fn WaylandServer::dispatch_msg(
} }
ObjToplevelDeco(wid) => ObjToplevelDeco(wid) =>
if opcode == 0U { 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
_ => ()
}
c.objects.remove(obj_id) c.objects.remove(obj_id)
send_delete_id(c, obj_id) send_delete_id(c, obj_id)
} else if opcode == 1U || opcode == 2U { } else if opcode == 1U || opcode == 2U {
@@ -1345,6 +1380,7 @@ pub fn WaylandServer::send_toplevel_configure(
activated : Bool, activated : Bool,
maximized : Bool, maximized : Bool,
fullscreen : Bool, fullscreen : Bool,
tiled~ : Bool = false,
) -> Unit { ) -> Unit {
let cid = match self.win_to_client.get(win_id) { let cid = match self.win_to_client.get(win_id) {
Some(id) => id Some(id) => id
@@ -1375,6 +1411,13 @@ pub fn WaylandServer::send_toplevel_configure(
if activated { if activated {
push_state(4U) push_state(4U)
} }
if tiled && !maximized && !fullscreen {
// tiled_left/right/top/bottom (xdg_toplevel v2+): client-decorated windows drop their
// shadow and rounded corners, so neighbouring tiles meet cleanly.
for st in [5U, 6U, 7U, 8U] {
push_state(st)
}
}
tl.cfg_w = width tl.cfg_w = width
tl.cfg_h = height tl.cfg_h = height
tl.cfg_states = states tl.cfg_states = states