Subsurfaces are drawn and get the pointer: Chrome's toolbar bubbles work
CI / test (push) Canceled after 14m47s
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:
3 files changed
+371
-83
No files matched your search
+192
-75
@@ -18,6 +18,39 @@ pub(all) struct HostWindow {
|
||||
mut csd : Bool
|
||||
mut geo_x : 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
|
||||
@@ -115,6 +148,8 @@ pub(all) struct ChandraCompositor {
|
||||
mut ptr_x : Double
|
||||
mut ptr_y : Double
|
||||
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.
|
||||
mut split_drag : @wm.SplitHandle?
|
||||
/// 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,
|
||||
popups: [],
|
||||
ptr_win: None,
|
||||
ptr_sub: 0U,
|
||||
split_drag: None,
|
||||
title_press: None,
|
||||
press_fwd: false,
|
||||
@@ -525,6 +561,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
|
||||
surface: None,
|
||||
cfg_dirty: false,
|
||||
csd: false,
|
||||
subs: [],
|
||||
geo_x: 0,
|
||||
geo_y: 0,
|
||||
}
|
||||
@@ -628,6 +665,48 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
|
||||
}
|
||||
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::PopupOpened(wid, parent, rx, ry, w, h) => {
|
||||
// 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) => {
|
||||
self.close_popup(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 => ()
|
||||
}
|
||||
self.thumb_forget(wid)
|
||||
@@ -692,6 +776,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
|
||||
ignore(self.restore_claimed.remove(wid))
|
||||
if self.ptr_win == Some(wid) {
|
||||
self.ptr_win = None
|
||||
self.ptr_sub = 0U
|
||||
}
|
||||
if self.kbd_win == Some(wid) {
|
||||
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(
|
||||
self : ChandraCompositor,
|
||||
@@ -827,76 +989,30 @@ fn ChandraCompositor::build_scene(
|
||||
let shown = if self.overview is Some(_) { [] } else { order }
|
||||
|
||||
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) {
|
||||
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.
|
||||
Some(win) if win.subs.length() > 0 => {
|
||||
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
|
||||
for sub in win.subs {
|
||||
match sub.surface {
|
||||
Some(snap) =>
|
||||
scene.windows.push({
|
||||
id: win.id,
|
||||
title: win.title,
|
||||
app_id: win.app_id,
|
||||
focused: win.focused,
|
||||
fullscreen: true,
|
||||
geometry: @scene.Rect::new(ox + sub.x, oy + sub.y, snap.width, snap.height),
|
||||
deco_insets: (0, 0, 0, 0),
|
||||
deco_ops: [],
|
||||
surface: Some(snap),
|
||||
})
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
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 {
|
||||
match self.ptr_win {
|
||||
Some(w) => {
|
||||
self.server.pointer_leave(w)
|
||||
self.server.pointer_leave(w, sub=self.ptr_sub)
|
||||
self.ptr_win = None
|
||||
self.ptr_sub = 0U
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@@ -1790,13 +1907,12 @@ pub fn ChandraCompositor::handle_input(
|
||||
self.shell.desktop_leave()
|
||||
match self.windows.get(wid) {
|
||||
Some(win) => {
|
||||
let (ox, oy) = win.surface_origin()
|
||||
let lx = x - ox.to_double()
|
||||
let ly = y - oy.to_double()
|
||||
if self.ptr_win != Some(wid) {
|
||||
let (sub, lx, ly) = win.surface_at(x, y)
|
||||
if self.ptr_win != Some(wid) || self.ptr_sub != sub {
|
||||
self.leave_pointer()
|
||||
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)
|
||||
}
|
||||
@@ -1845,11 +1961,12 @@ pub fn ChandraCompositor::handle_input(
|
||||
Some((wid, true)) =>
|
||||
match self.windows.get(wid) {
|
||||
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.ptr_win = Some(wid)
|
||||
let (ox, oy) = win.surface_origin()
|
||||
self.server.pointer_enter(wid, self.ptr_x - ox.to_double(), self.ptr_y - oy.to_double())
|
||||
self.ptr_sub = sub
|
||||
self.server.pointer_enter(wid, lx, ly, sub~)
|
||||
}
|
||||
self.server.pointer_axis(wid, time_ms, axis, v, discrete)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user