xdg_popup support: right-click menus in client apps (Konsole etc.)
CI / test (push) Failing after 37s

- server: xdg_positioner state, get_popup placement + configure, popup commits,
  popup_done; popups share the toplevel table so pointer/keyboard routing is reused
- compositor: popups drawn above windows and panel, input goes to the popup under the
  pointer, keyboard focus follows the popup, a click outside dismisses them
- test: a client opens a popup, clicks inside it, and is told to dismiss it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-25 00:03:49 -08:00
1 parent 3b2e19ace5
commit bc1e3dfdbd
5 files changed
+491 -5

No files matched your search

+124
View File
@@ -553,3 +553,127 @@ test "the desktop card can be dragged across the wallpaper" {
assert_true(!comp.shell.desk_hit(gx, gy))
assert_true(!comp.shell.desk_dragging())
}
///|
test "an xdg_popup (right-click menu) is placed, drawn, clickable and dismissed from outside" {
let socket_path = "/tmp/wayland-moon-popup-" + @sys.getpid().to_string() + ".sock"
let theme = @scene.ThemeTokens::moon_night()
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
let (c, shm, surf, xdg, _tl, _deco) = open_and_configure_client(comp, socket_path, "T", "t")
commit_shm_frame(comp, c, shm, surf, xdg, 1UL)
let win = comp.windows.get(1UL).unwrap().geometry
let reg_id = 2U
let seat_id = bind_global(c, reg_id, "wl_seat", 7U)
let ptr_id = c.alloc_id()
let w1 = @wayland.WireWriter::new()
w1.u32(ptr_id)
c.send(w1.finish_msg(seat_id, 0U))
let comp_id = bind_global(c, reg_id, "wl_compositor", 5U)
let wm_id = bind_global(c, reg_id, "xdg_wm_base", 5U)
// Positioner: 100x60 popup whose top-left sits at (50, 60) in the window.
let pos_id = c.alloc_id()
let a = @wayland.WireWriter::new()
a.u32(pos_id)
c.send(a.finish_msg(wm_id, 1U))
let b = @wayland.WireWriter::new()
b.i32(100)
b.i32(60)
c.send(b.finish_msg(pos_id, 1U))
let d = @wayland.WireWriter::new()
d.i32(50)
d.i32(60)
d.i32(1)
d.i32(1)
c.send(d.finish_msg(pos_id, 2U))
let e = @wayland.WireWriter::new()
e.u32(2U) // anchor: top-left of the rect (bottom edge); use top_left below
c.send(e.finish_msg(pos_id, 3U))
let f = @wayland.WireWriter::new()
f.u32(8U) // gravity bottom_right: popup extends right and down from the anchor point
c.send(f.finish_msg(pos_id, 4U))
let psurf = c.alloc_id()
let g = @wayland.WireWriter::new()
g.u32(psurf)
c.send(g.finish_msg(comp_id, 0U))
let pxdg = c.alloc_id()
let h = @wayland.WireWriter::new()
h.u32(pxdg)
h.u32(psurf)
c.send(h.finish_msg(wm_id, 2U))
let popup_id = c.alloc_id()
let i = @wayland.WireWriter::new()
i.u32(popup_id)
i.u32(xdg)
i.u32(pos_id)
c.send(i.finish_msg(pxdg, 2U))
c.send(@wayland.WireWriter::new().finish_msg(psurf, 6U))
for _n = 0; _n < 5; _n = _n + 1 {
comp.step()
@sys.sleep_ms(2)
}
assert_eq(comp.popups.length(), 1)
let msgs = drain_msgs(c)
assert_true(has_msg(msgs, popup_id, 0U)) // xdg_popup.configure
// Attach a 100x60 buffer.
let bytes = 100 * 60 * 4
let pixels : Array[Byte] = Array::make(bytes, b'\xff')
let memfd = @sys.memfd_create("popup-shm", bytes)
ignore(@sys.pwrite_bytes(memfd, Bytes::from_array(pixels), 0))
let pool = c.alloc_id()
let j = @wayland.WireWriter::new()
j.u32(pool)
j.i32(bytes)
c.send(j.finish_msg(shm, 0U), send_fd=memfd)
@sys.close_fd(memfd)
let buf = c.alloc_id()
let k = @wayland.WireWriter::new()
k.u32(buf)
k.i32(0)
k.i32(100)
k.i32(60)
k.i32(400)
k.u32(0U)
c.send(k.finish_msg(pool, 0U))
let l = @wayland.WireWriter::new()
l.u32(buf)
l.i32(0)
l.i32(0)
c.send(l.finish_msg(psurf, 1U))
c.send(@wayland.WireWriter::new().finish_msg(psurf, 6U))
for _n = 0; _n < 10; _n = _n + 1 {
comp.step()
@sys.sleep_ms(2)
}
let p = comp.popups[0]
assert_true(p.surface is Some(_))
let px = win.x + 50 + 5
let py = win.y + 60 + 5
// Clicking inside the popup reaches the client (not the window beneath).
drain_msgs(c) |> ignore
click_at(comp, px, py, 10U)
let msgs2 = drain_msgs(c)
assert_true(has_msg(msgs2, ptr_id, 0U)) // pointer enter on the popup surface
assert_true(has_msg(msgs2, ptr_id, 3U)) // button
// The popup is drawn above the window.
let pm = comp.compose_frame()
let (_, _, _, _) = (pm.width, pm.height, 0, 0)
// Clicking outside asks it to close.
click_at(comp, win.x + win.w - 20, win.y + win.h - 20, 20U)
let msgs3 = drain_msgs(c)
assert_true(has_msg(msgs3, popup_id, 1U)) // xdg_popup.popup_done
// The client destroys it: gone from the compositor.
c.send(@wayland.WireWriter::new().finish_msg(popup_id, 0U))
for _n = 0; _n < 5; _n = _n + 1 {
comp.step()
@sys.sleep_ms(2)
}
assert_eq(comp.popups.length(), 0)
}