Subsurfaces are drawn and get the pointer: Chrome's toolbar bubbles work
CI / test (push) Canceled after 14m47s

Chrome draws the bubbles of its toolbar buttons (bookmark star, downloads, extensions) as
wl_subsurfaces of the window, not xdg_popups. Chandra accepted wl_subcompositor.get_subsurface
but never drew a subsurface or sent it input, so those buttons seemed to do nothing (the
bookmark was even added, with no bubble). Menus (xdg_popup) were unaffected.

- Server: subsurface state (parent, position) per child surface; a child commit or
  set_position reports SubsurfaceCommitted(window, child, x, y, buffer) with the position
  added up to the window's surface, and a null buffer or destroy reports SubsurfaceUnmapped.
- Host: HostWindow.subs, drawn above the window as undecorated scene nodes (no change to any
  renderer); the pointer enters the topmost subsurface under it (ptr_sub) with its own
  coordinates, so clicks reach the bubble.

Checked headless with Chromium 158 on Ozone Wayland, in both frame modes: the star bubble
opens and its Remove button works. Test in 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 04:19:53 +00:00
1 parent 41c6ec1135
commit db442879f5
3 files changed
+371 -83

No files matched your search

+192 -75
View File
@@ -18,6 +18,39 @@ pub(all) struct HostWindow {
mut csd : Bool mut csd : Bool
mut geo_x : Int mut geo_x : Int
mut geo_y : Int mut geo_y : Int
/// Mapped wl_subsurfaces, bottom to top, drawn above the window (Chrome's toolbar bubbles).
subs : Array[HostSub]
}
///| A window's wl_subsurface: its wl_surface id, position relative to the window's surface
/// origin, and last buffer.
pub(all) struct HostSub {
sid : UInt
mut x : Int
mut y : Int
mut surface : @scene.ShmBufferSnapshot?
}
///| The surface of window `self` under screen point (x, y): (subsurface id, or 0 for the window
/// itself, and the point in that surface's coordinates).
fn HostWindow::surface_at(self : HostWindow, x : Double, y : Double) -> (UInt, Double, Double) {
let (ox, oy) = self.surface_origin()
let mut i = self.subs.length() - 1
while i >= 0 {
let sub = self.subs[i]
match sub.surface {
Some(snap) => {
let sx = (ox + sub.x).to_double()
let sy = (oy + sub.y).to_double()
if x >= sx && x < sx + snap.width.to_double() && y >= sy && y < sy + snap.height.to_double() {
return (sub.sid, x - sx, y - sy)
}
}
None => ()
}
i = i - 1
}
(0U, x - ox.to_double(), y - oy.to_double())
} }
///| The window style in use (Settings > Session > Flat window frames). Global because the frame's ///| The window style in use (Settings > Session > Flat window frames). Global because the frame's
@@ -115,6 +148,8 @@ pub(all) struct ChandraCompositor {
mut ptr_x : Double mut ptr_x : Double
mut ptr_y : Double mut ptr_y : Double
mut ptr_win : UInt64? mut ptr_win : UInt64?
/// The subsurface of `ptr_win` the pointer is over (its wl_surface id), 0 for the window itself.
mut ptr_sub : UInt
/// Divider being dragged between tiled windows. /// Divider being dragged between tiled windows.
mut split_drag : @wm.SplitHandle? mut split_drag : @wm.SplitHandle?
/// The last left press on a title bar (titleclick.mbt): drag to move, double-click to maximize. /// The last left press on a title bar (titleclick.mbt): drag to move, double-click to maximize.
@@ -289,6 +324,7 @@ pub fn ChandraCompositor::new(
ptr_y: 0.0, ptr_y: 0.0,
popups: [], popups: [],
ptr_win: None, ptr_win: None,
ptr_sub: 0U,
split_drag: None, split_drag: None,
title_press: None, title_press: None,
press_fwd: false, press_fwd: false,
@@ -525,6 +561,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
surface: None, surface: None,
cfg_dirty: false, cfg_dirty: false,
csd: false, csd: false,
subs: [],
geo_x: 0, geo_x: 0,
geo_y: 0, geo_y: 0,
} }
@@ -628,6 +665,48 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
} }
None => () None => ()
} }
@wayland.CompositorEvent::SubsurfaceCommitted(wid, sid, x, y, snap) =>
match self.windows.get(wid) {
Some(win) => {
let sub = match win.subs.search_by(s => s.sid == sid) {
Some(i) => win.subs[i]
None => {
let s : HostSub = { sid, x, y, surface: None }
win.subs.push(s)
s
}
}
sub.x = x
sub.y = y
match snap {
Some(sn) => {
release_snapshot(sub.surface)
sub.surface = Some(sn)
}
None => ()
}
self.damage.mark_full()
}
None => release_snapshot(snap)
}
@wayland.CompositorEvent::SubsurfaceUnmapped(wid, sid) =>
match self.windows.get(wid) {
Some(win) =>
match win.subs.search_by(s => s.sid == sid) {
Some(i) => {
release_snapshot(win.subs[i].surface)
win.subs.remove(i) |> ignore
if self.ptr_win == Some(wid) && self.ptr_sub == sid {
// Gone from under the pointer: the next motion enters the window again.
self.ptr_win = None
self.ptr_sub = 0U
}
self.damage.mark_full()
}
None => ()
}
None => ()
}
@wayland.CompositorEvent::ToplevelResizeRequest(wid, edges) => self.client_resize(wid, edges) @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
@@ -682,7 +761,12 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
@wayland.CompositorEvent::ToplevelClosed(wid) => { @wayland.CompositorEvent::ToplevelClosed(wid) => {
self.close_popup(wid) self.close_popup(wid)
match self.windows.get(wid) { match self.windows.get(wid) {
Some(win) => release_snapshot(win.surface) Some(win) => {
release_snapshot(win.surface)
for sub in win.subs {
release_snapshot(sub.surface)
}
}
None => () None => ()
} }
self.thumb_forget(wid) self.thumb_forget(wid)
@@ -692,6 +776,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
ignore(self.restore_claimed.remove(wid)) ignore(self.restore_claimed.remove(wid))
if self.ptr_win == Some(wid) { if self.ptr_win == Some(wid) {
self.ptr_win = None self.ptr_win = None
self.ptr_sub = 0U
} }
if self.kbd_win == Some(wid) { if self.kbd_win == Some(wid) {
self.kbd_win = None self.kbd_win = None
@@ -814,6 +899,83 @@ pub fn ChandraCompositor::restore_state(self : ChandraCompositor) -> Unit {
} }
} }
///|
///| The scene node for window `wid`: Chandra's frame around it, or none when the client draws
/// its own (or the window is fullscreen).
fn ChandraCompositor::push_window_node(self : ChandraCompositor, scene : @scene.SceneGraph, wid : UInt64) -> Unit {
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) if win.fullscreen =>
scene.windows.push({
id: win.id,
title: win.title,
app_id: win.app_id,
focused: win.focused,
fullscreen: true,
geometry: win.geometry,
deco_insets: (0, 0, 0, 0),
deco_ops: [],
surface: win.surface,
})
Some(win) => {
let outer = frame_rect(win.geometry)
let btn = fn(st : (UInt64, Int)?) {
match st {
Some((w, b)) if w == win.id => b
_ => 0
}
}
let (insets, deco_ops) = @scene.build_window_decoration(
window_style.val,
{
title: win.title,
app_id: win.app_id,
focused: win.focused,
maximized: win.maximized,
hover: btn(self.deco_hover),
pressed: btn(self.deco_pressed),
},
outer.w,
outer.h,
self.theme,
fn(s, size, bold) { @renderer.text_width(s, size, bold, false) },
)
scene.windows.push({
id: win.id,
title: win.title,
app_id: win.app_id,
focused: win.focused,
fullscreen: win.fullscreen,
geometry: win.geometry,
deco_insets: insets,
deco_ops,
surface: win.surface,
})
}
None => ()
}
}
///| ///|
fn ChandraCompositor::build_scene( fn ChandraCompositor::build_scene(
self : ChandraCompositor, self : ChandraCompositor,
@@ -827,76 +989,30 @@ fn ChandraCompositor::build_scene(
let shown = if self.overview is Some(_) { [] } else { order } let shown = if self.overview is Some(_) { [] } else { order }
for wid in shown { for wid in shown {
self.push_window_node(scene, wid)
// Its subsurfaces, above it (undecorated scene nodes at the subsurface's place).
match self.windows.get(wid) { match self.windows.get(wid) {
Some(win) if win.csd => { Some(win) if win.subs.length() > 0 => {
// 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 (ox, oy) = win.surface_origin()
let r = win.client_rect() for sub in win.subs {
let (bw, bh) = match win.surface { match sub.surface {
Some(s) => (s.width, s.height) Some(snap) =>
None => (r.w, r.h) scene.windows.push({
} id: win.id,
scene.windows.push({ title: win.title,
id: win.id, app_id: win.app_id,
title: win.title, focused: win.focused,
app_id: win.app_id, fullscreen: true,
focused: win.focused, geometry: @scene.Rect::new(ox + sub.x, oy + sub.y, snap.width, snap.height),
fullscreen: true, deco_insets: (0, 0, 0, 0),
geometry: @scene.Rect::new(ox, oy, bw, bh), deco_ops: [],
deco_insets: (0, 0, 0, 0), surface: Some(snap),
deco_ops: [], })
surface: win.surface, None => ()
})
}
Some(win) if win.fullscreen =>
scene.windows.push({
id: win.id,
title: win.title,
app_id: win.app_id,
focused: win.focused,
fullscreen: true,
geometry: win.geometry,
deco_insets: (0, 0, 0, 0),
deco_ops: [],
surface: win.surface,
})
Some(win) => {
let outer = frame_rect(win.geometry)
let btn = fn(st : (UInt64, Int)?) {
match st {
Some((w, b)) if w == win.id => b
_ => 0
} }
} }
let (insets, deco_ops) = @scene.build_window_decoration(
window_style.val,
{
title: win.title,
app_id: win.app_id,
focused: win.focused,
maximized: win.maximized,
hover: btn(self.deco_hover),
pressed: btn(self.deco_pressed),
},
outer.w,
outer.h,
self.theme,
fn(s, size, bold) { @renderer.text_width(s, size, bold, false) },
)
scene.windows.push({
id: win.id,
title: win.title,
app_id: win.app_id,
focused: win.focused,
fullscreen: win.fullscreen,
geometry: win.geometry,
deco_insets: insets,
deco_ops,
surface: win.surface,
})
} }
None => () _ => ()
} }
} }
@@ -1637,8 +1753,9 @@ fn ChandraCompositor::handle_at(
fn ChandraCompositor::leave_pointer(self : ChandraCompositor) -> Unit { fn ChandraCompositor::leave_pointer(self : ChandraCompositor) -> Unit {
match self.ptr_win { match self.ptr_win {
Some(w) => { Some(w) => {
self.server.pointer_leave(w) self.server.pointer_leave(w, sub=self.ptr_sub)
self.ptr_win = None self.ptr_win = None
self.ptr_sub = 0U
} }
None => () None => ()
} }
@@ -1790,13 +1907,12 @@ 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 (ox, oy) = win.surface_origin() let (sub, lx, ly) = win.surface_at(x, y)
let lx = x - ox.to_double() if self.ptr_win != Some(wid) || self.ptr_sub != sub {
let ly = y - oy.to_double()
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(wid, lx, ly) self.ptr_sub = sub
self.server.pointer_enter(wid, lx, ly, sub~)
} }
self.server.pointer_motion(wid, time_ms, lx, ly) self.server.pointer_motion(wid, time_ms, lx, ly)
} }
@@ -1845,11 +1961,12 @@ pub fn ChandraCompositor::handle_input(
Some((wid, true)) => Some((wid, true)) =>
match self.windows.get(wid) { match self.windows.get(wid) {
Some(win) => { Some(win) => {
if self.ptr_win != Some(wid) { let (sub, lx, ly) = win.surface_at(self.ptr_x, self.ptr_y)
if self.ptr_win != Some(wid) || self.ptr_sub != sub {
self.leave_pointer() self.leave_pointer()
self.ptr_win = Some(wid) self.ptr_win = Some(wid)
let (ox, oy) = win.surface_origin() self.ptr_sub = sub
self.server.pointer_enter(wid, self.ptr_x - ox.to_double(), self.ptr_y - oy.to_double()) self.server.pointer_enter(wid, lx, ly, sub~)
} }
self.server.pointer_axis(wid, time_ms, axis, v, discrete) self.server.pointer_axis(wid, time_ms, axis, v, discrete)
} }
+76
View File
@@ -320,3 +320,79 @@ test "a maximized GTK window has no resize zones, and restores to its size" {
assert_false(comp.windows.get(1UL).unwrap().maximized) assert_false(comp.windows.get(1UL).unwrap().maximized)
assert_eq((after.w, after.h), (before.w, before.h)) assert_eq((after.w, after.h), (before.w, before.h))
} }
///| A solid 0xBBGGRR buffer of `w` x `h` in its own pool.
fn solid_buffer(c : TestWaylandClient, shm : UInt, w : Int, h : Int, b : Byte, g : Byte, r : Byte) -> UInt {
let fd = solid_memfd(w, h, b, g, r)
let pool = c.alloc_id()
let p = @wayland.WireWriter::new()
p.u32(pool)
p.i32(w * h * 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(w)
cb.i32(h)
cb.i32(w * 4)
cb.u32(0U)
c.send(cb.finish_msg(pool, 0U))
buf
}
///|
test "a subsurface (Chrome's toolbar bubbles) is drawn over its window and gets the pointer" {
// Chrome draws the bookmark-star, downloads and extensions bubbles as wl_subsurfaces of the
// window. Chandra accepted them but never drew them or sent them input: the buttons seemed
// to do nothing.
let socket_path = "/tmp/wayland-moon-csd-sub-" + @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, "Chrome", "chromium")
ignore(answer_configures(comp, c, shm, surf, xdg, tl, fn(w, h, _m) { (w, h) }))
// wl_registry is object 2; wl_compositor and wl_subcompositor by name.
let comp_id = bind_global(c, 2U, "wl_compositor", 5U)
let subc = bind_global(c, 2U, "wl_subcompositor", 1U)
let child = c.alloc_id()
let cs = @wayland.WireWriter::new()
cs.u32(child)
c.send(cs.finish_msg(comp_id, 0U))
let sub = c.alloc_id()
let gs = @wayland.WireWriter::new()
gs.u32(sub)
gs.u32(child)
gs.u32(surf)
c.send(gs.finish_msg(subc, 1U))
let sp = @wayland.WireWriter::new()
sp.i32(100)
sp.i32(50)
c.send(sp.finish_msg(sub, 1U)) // set_position
let buf = solid_buffer(c, shm, 40, 30, b'\xff', b'\x00', b'\x00')
attach_commit(comp, c, child, Some(buf))
let win = comp.windows.get(1UL).unwrap()
assert_eq(win.subs.length(), 1)
let (ox, oy) = win.surface_origin()
let blue = Some(@scene.Rgba::new(0, 0, 0xff, 0xff))
assert_eq(comp.compose_frame().pixel(ox + 110, oy + 60), blue)
assert_true(comp.compose_frame().pixel(ox + 90, oy + 60) != blue)
// The pointer over it enters the subsurface, at its own coordinates.
comp.handle_input(@nested.InputEvent::PointerMove((ox + 110).to_double(), (oy + 60).to_double()), 10U)
assert_eq(comp.ptr_win, Some(1UL))
assert_eq(comp.ptr_sub, child)
comp.handle_input(@nested.InputEvent::PointerMove((ox + 90).to_double(), (oy + 60).to_double()), 11U)
assert_eq(comp.ptr_sub, 0U)
// A null buffer unmaps it.
let a = @wayland.WireWriter::new()
a.u32(0U)
a.i32(0)
a.i32(0)
c.send(a.finish_msg(child, 1U))
attach_commit(comp, c, child, None)
assert_eq(comp.windows.get(1UL).unwrap().subs.length(), 0)
assert_true(comp.compose_frame().pixel(ox + 110, oy + 60) != blue)
}
+103 -8
View File
@@ -33,6 +33,20 @@ pub(all) enum CompositorEvent {
/// xdg_surface.set_window_geometry on a popup: (id, x, y) of the visible menu inside its /// xdg_surface.set_window_geometry on a popup: (id, x, y) of the visible menu inside its
/// buffer. The positioner places that point, so the buffer is drawn this much up/left. /// buffer. The positioner places that point, so the buffer is drawn this much up/left.
PopupGeometry(UInt64, Int, Int) PopupGeometry(UInt64, Int, Int)
/// A wl_subsurface of a window committed or moved: (window, child wl_surface id, x, y, buffer)
/// with (x, y) relative to the window's surface (nested subsurfaces added up). The buffer is
/// None when only the position changed. Chrome draws its toolbar bubbles (bookmark star,
/// downloads, extensions) this way.
SubsurfaceCommitted(UInt64, UInt, Int, Int, @scene.ShmBufferSnapshot?)
/// The subsurface was unmapped (null buffer) or destroyed: (window, child wl_surface id).
SubsurfaceUnmapped(UInt64, UInt)
}
///| wl_subsurface state, keyed by the child wl_surface id.
struct SubState {
parent : UInt
mut x : Int
mut y : Int
} }
///| ///|
@@ -64,7 +78,7 @@ enum ObjKind {
/// wl_output with the version the client bound (done and scale are since version 2). /// wl_output with the version the client bound (done and scale are since version 2).
ObjOutput(UInt) ObjOutput(UInt)
ObjSubcompositor ObjSubcompositor
ObjSubsurface ObjSubsurface(UInt)
ObjDataManager ObjDataManager
ObjDataSource ObjDataSource
ObjDataDevice ObjDataDevice
@@ -104,6 +118,8 @@ struct SurfaceState {
mut window_id : UInt64? mut window_id : UInt64?
/// wl_surface.set_buffer_scale: the buffer is this many times the window's size. /// wl_surface.set_buffer_scale: the buffer is this many times the window's size.
mut buffer_scale : Int mut buffer_scale : Int
/// The pending attach is a null buffer (the surface is being unmapped).
mut attached_null : Bool
/// org_kde_kwin_server_decoration mode Server: Chandra draws this window's frame (GTK 3 apps /// org_kde_kwin_server_decoration mode Server: Chandra draws this window's frame (GTK 3 apps
/// without their own header bar, like Webby). /// without their own header bar, like Webby).
mut kde_ssd : Bool mut kde_ssd : Bool
@@ -182,6 +198,7 @@ struct ClientConn {
shm_pools : Map[UInt, ShmPoolState] shm_pools : Map[UInt, ShmPoolState]
shm_buffers : Map[UInt, ShmBufferState] shm_buffers : Map[UInt, ShmBufferState]
xdg_surfaces : Map[UInt, XdgSurfaceState] xdg_surfaces : Map[UInt, XdgSurfaceState]
subsurfaces : Map[UInt, SubState]
toplevels : Map[UInt64, ToplevelState] toplevels : Map[UInt64, ToplevelState]
positioners : Map[UInt, PosState] positioners : Map[UInt, PosState]
pointer_ids : Array[UInt] pointer_ids : Array[UInt]
@@ -212,6 +229,7 @@ fn ClientConn::new(client_id : UInt, fd : Int) -> ClientConn {
shm_pools: {}, shm_pools: {},
shm_buffers: {}, shm_buffers: {},
xdg_surfaces: {}, xdg_surfaces: {},
subsurfaces: {},
toplevels: {}, toplevels: {},
positioners: {}, positioners: {},
pointer_ids: [], pointer_ids: [],
@@ -606,6 +624,7 @@ fn WaylandServer::dispatch_msg(
window_id: None, window_id: None,
buffer_scale: 1, buffer_scale: 1,
kde_ssd: false, kde_ssd: false,
attached_null: false,
}) })
} else if opcode == 1U { } else if opcode == 1U {
let rid = reader.u32() let rid = reader.u32()
@@ -617,6 +636,12 @@ fn WaylandServer::dispatch_msg(
Some(surf) => Some(surf) =>
if opcode == 0U { if opcode == 0U {
// destroy // destroy
if c.subsurfaces.contains(sid) {
match sub_root(c, sid) {
Some((wid, _, _)) => events.push(SubsurfaceUnmapped(wid, sid))
None => ()
}
}
c.surfaces.remove(sid) c.surfaces.remove(sid)
c.objects.remove(sid) c.objects.remove(sid)
send_delete_id(c, sid) send_delete_id(c, sid)
@@ -625,6 +650,7 @@ fn WaylandServer::dispatch_msg(
let buf_id = reader.u32() let buf_id = reader.u32()
let _x = reader.i32() let _x = reader.i32()
let _y = reader.i32() let _y = reader.i32()
surf.attached_null = buf_id == 0U
surf.attached_buffer = if buf_id == 0U { surf.attached_buffer = if buf_id == 0U {
None None
} else { } else {
@@ -640,6 +666,25 @@ fn WaylandServer::dispatch_msg(
surf.buffer_scale = if sc > 0 { sc } else { 1 } surf.buffer_scale = if sc > 0 { sc } else { 1 }
} else if opcode == 6U { } else if opcode == 6U {
// commit // commit
if surf.window_id is None && c.subsurfaces.contains(sid) {
match sub_root(c, sid) {
Some((wid, ax, ay)) =>
if surf.attached_null {
events.push(SubsurfaceUnmapped(wid, sid))
} else {
match surf.attached_buffer {
Some(bid) =>
match snapshot_shm_buffer(c, bid) {
Some(snap) => events.push(SubsurfaceCommitted(wid, sid, ax, ay, Some(snap)))
None => ()
}
None => ()
}
}
None => ()
}
}
surf.attached_null = false
match surf.window_id { match surf.window_id {
Some(wid) => Some(wid) =>
match c.toplevels.get(wid) { match c.toplevels.get(wid) {
@@ -722,9 +767,12 @@ fn WaylandServer::dispatch_msg(
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 { } else if opcode == 1U {
// get_subsurface(id: new_id, surface, parent): accepted, not composited yet // get_subsurface(id: new_id, surface, parent)
let sub_id = reader.u32() let sub_id = reader.u32()
c.objects.set(sub_id, ObjSubsurface) let child = reader.u32()
let parent = reader.u32()
c.objects.set(sub_id, ObjSubsurface(child))
c.subsurfaces.set(child, { parent, x: 0, y: 0 })
} }
ObjDataManager => ObjDataManager =>
if opcode == 0U { if opcode == 0U {
@@ -836,10 +884,30 @@ fn WaylandServer::dispatch_msg(
let _serial = reader.u32() let _serial = reader.u32()
c.cursor_shape = reader.u32() c.cursor_shape = reader.u32()
} }
ObjSubsurface => ObjSubsurface(child) =>
if opcode == 0U { if opcode == 0U {
match sub_root(c, child) {
Some((wid, _, _)) => events.push(SubsurfaceUnmapped(wid, child))
None => ()
}
c.subsurfaces.remove(child)
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 {
// set_position(x, y): taken at once (the parent's next commit would apply it).
let x = reader.i32()
let y = reader.i32()
match c.subsurfaces.get(child) {
Some(st) => {
st.x = x
st.y = y
match sub_root(c, child) {
Some((wid, ax, ay)) => events.push(SubsurfaceCommitted(wid, child, ax, ay, None))
None => ()
}
}
None => ()
}
} }
ObjShm => ObjShm =>
if opcode == 0U { if opcode == 0U {
@@ -1667,14 +1735,15 @@ fn fixed(v : Double) -> Int {
} }
///| wl_pointer.enter at surface-local (x, y). ///| wl_pointer.enter at surface-local (x, y).
pub fn WaylandServer::pointer_enter(self : WaylandServer, win_id : UInt64, x : Double, y : Double) -> Unit { ///| `sub`: the window's subsurface (its wl_surface id) under the pointer, 0 for the window itself.
pub fn WaylandServer::pointer_enter(self : WaylandServer, win_id : UInt64, x : Double, y : Double, sub? : UInt = 0U) -> Unit {
match self.win_client(win_id) { match self.win_client(win_id) {
None => () None => ()
Some((c, tl)) => Some((c, tl)) =>
for pid in c.pointer_ids { for pid in c.pointer_ids {
let w = WireWriter::new() let w = WireWriter::new()
w.u32(self.next_serial()) w.u32(self.next_serial())
w.u32(tl.wl_surface_id) w.u32(if sub != 0U && c.surfaces.contains(sub) { sub } else { tl.wl_surface_id })
w.i32(fixed(x)) w.i32(fixed(x))
w.i32(fixed(y)) w.i32(fixed(y))
c.send_msg(w.finish_msg(pid, 0U)) c.send_msg(w.finish_msg(pid, 0U))
@@ -1684,14 +1753,17 @@ pub fn WaylandServer::pointer_enter(self : WaylandServer, win_id : UInt64, x : D
} }
///| ///|
pub fn WaylandServer::pointer_leave(self : WaylandServer, win_id : UInt64) -> Unit { pub fn WaylandServer::pointer_leave(self : WaylandServer, win_id : UInt64, sub? : UInt = 0U) -> Unit {
match self.win_client(win_id) { match self.win_client(win_id) {
None => () None => ()
Some((c, tl)) => Some((c, tl)) =>
for pid in c.pointer_ids { for pid in c.pointer_ids {
if sub != 0U && !c.surfaces.contains(sub) {
continue // the subsurface is gone: nothing to leave
}
let w = WireWriter::new() let w = WireWriter::new()
w.u32(self.next_serial()) w.u32(self.next_serial())
w.u32(tl.wl_surface_id) w.u32(if sub != 0U { sub } else { tl.wl_surface_id })
c.send_msg(w.finish_msg(pid, 1U)) c.send_msg(w.finish_msg(pid, 1U))
self.pointer_frame(c, pid) self.pointer_frame(c, pid)
} }
@@ -2117,3 +2189,26 @@ pub fn WaylandServer::pump_transfers(self : WaylandServer) -> Unit {
pub fn WaylandServer::pending_transfers(self : WaylandServer) -> Int { pub fn WaylandServer::pending_transfers(self : WaylandServer) -> Int {
self.transfers.length() self.transfers.length()
} }
///| The window a subsurface belongs to, and its position relative to that window's surface
/// (nested subsurfaces added up). None while it hangs off a surface with no window yet.
fn sub_root(c : ClientConn, child : UInt) -> (UInt64, Int, Int)? {
let mut x = 0
let mut y = 0
let mut cur = child
for _depth = 0; _depth < 16; _depth = _depth + 1 {
match c.subsurfaces.get(cur) {
Some(st) => {
x = x + st.x
y = y + st.y
cur = st.parent
}
None =>
return match c.surfaces.get(cur) {
Some({ window_id: Some(wid), .. }) => Some((wid, x, y))
_ => None
}
}
}
None
}