X11 dock bridge: show and control host EWMH windows under --x11
CI / test (push) Failing after 2m37s

Under --x11 with a host EWMH window manager (e.g. Openbox in Gamerig),
Chandra is one top-level X11 client while other apps run directly on Xorg,
so the dock only saw Chandra's Wayland windows.

- compositor/x11: intern EWMH/ICCCM atoms and track _NET_CLIENT_LIST,
  _NET_ACTIVE_WINDOW, titles, and window states via PropertyChangeMask,
  filtering non-taskbar/child windows and adding focus, close, minimize,
  and toggle-maximize EWMH/ICCCM actions.
- compositor/shell: add resolve_external_app_id (matching WM_CLASS and
  StartupWMClass against installed .desktop files) and publish_windows.
- compositor/host: bridge ExternalWindow entries with bit-30 tagged IDs
  into shell.windows/win_list while keeping Wayland wm.windows and session
  snapshots untouched, and route activate_task / window_command actions.
- compositor/app, compositor/bin, docs/x11.md: wire external window sync
  before X11 input handling and register ExternalWindowHandler.

Verified: moon test --target native compositor/x11 compositor/shell (38/38),
external_windows_test.mbt + dock_test.mbt (3/3), build-compositor-wasm.sh,
and moon build --target native compositor/bin.
This commit is contained in:
nandi committed 2026-11-27 14:33:26 -08:00
1 parent 15b7c3f0e3
commit 1871d50a3e
12 files changed
+949 -68

No files matched your search

+152
View File
@@ -0,0 +1,152 @@
///| Host integration tests for external X11 EWMH windows bridged into the dock/panel.
/// Needs the dock module built: scripts/build-modules.sh.
///| Pick row `label` of the open right-click menu (26 px title, then 28 px per row).
fn ext_dock_pick(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit raise {
let i = comp.shell.menu_rows.map(r => r.label).search(label).unwrap()
let m = comp.shell.menu_rect
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
}
///| Centres of the dock's titled task pills in panel order, from its rendered FillRect pills.
fn ext_pill_centers(comp : @host.ChandraCompositor, slot : String) -> Array[(Int, Int)] {
let r = comp.shell.slot_rect(slot)
let out : Array[(Int, Int)] = []
for op in comp.shell.slot_ops(slot) {
match op {
FillRect(f) if f.rect.y == 3 && f.rect.h.reinterpret_as_int() == r.h - 6 && f.rect.w >= 60U =>
out.push((r.x + f.rect.x + f.rect.w.reinterpret_as_int() / 2, r.y + r.h / 2))
_ => ()
}
}
out
}
///|
test "external X11 windows show in the dock and route clicks, shortcuts, and menu commands" {
let socket_path = "/tmp/wayland-moon-ext-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
comp.shell.apps.clear()
comp.shell.exec.clear()
comp.shell.wm_classes.clear()
for a in [
("gamerig-astra", "Space Rage: Astra Incognita", "Game", "S", "gamerig-open astra", "astra"),
("com.mitchellh.ghostty", "Ghostty", "System", "G", "gamerig-open terminal", "com.mitchellh.ghostty"),
("steam", "Steam", "Game", "S", "gamerig-open steam", "steam"),
] {
comp.shell.apps.push({ id: a.0, name: a.1, comment: "", category: a.2, glyph: a.3 })
comp.shell.exec.set(a.0, a.4)
comp.shell.wm_classes.set(a.5, a.0)
}
comp.shell.apps_dirty = true
ignore(comp.compose_frame())
let slot = comp.shell.slot_of("dock")
assert_true(slot.length() > 0)
for s in comp.shell.slots() {
let m = comp.shell.slot_module(s)
if m == "inspector" || m == "layout" || m == "screenshot" {
ignore(comp.shell.unload_slot(s))
}
}
comp.shell.set_module_setting(slot, "pinned", "gamerig-astra;com.mitchellh.ghostty;steam")
ignore(comp.compose_frame())
let focuses : Array[Int] = []
let cmds : Array[(Int, @shell.WindowCommand)] = []
comp.set_external_window_handler({
focus: fn(xid) { focuses.push(xid) },
command: fn(xid, cmd) { cmds.push((xid, cmd)) },
})
let ghostty_xid = 0x0120_0007
let astra_xid = 0x0140_0003
let hades_xid = 0x0160_0011
let ext_wins : Array[@host.ExternalWindow] = [
{
host_id: ghostty_xid,
wm_class: "com.mitchellh.ghostty",
wm_instance: "ghostty",
title: "ubuntu@rig: ~",
focused: false,
minimized: false,
maximized: false,
},
{
host_id: astra_xid,
wm_class: "astra",
wm_instance: "astra",
title: "Space Rage: Astra Incognita",
focused: false,
minimized: false,
maximized: true,
},
{
host_id: hades_xid,
wm_class: "steam_app_1145360",
wm_instance: "steam_app_1145360",
title: "Hades",
focused: false,
minimized: false,
maximized: false,
},
]
comp.set_external_windows(ext_wins)
ignore(comp.compose_frame())
// Idle pinned icon (steam) comes first, then the three running task pills:
// gamerig-astra (merged with its pin via StartupWMClass "astra"), com.mitchellh.ghostty, steam_app_1145360.
assert_eq(comp.shell.dock_item_ids(), ["steam", "gamerig-astra", "com.mitchellh.ghostty", "steam_app_1145360"])
// Left-clicking Ghostty's pill routes its tagged XID cleanly through dock.wasm -> activate_task -> focus handler.
let pills = ext_pill_centers(comp, slot)
assert_eq(pills.length(), 3)
let (gx, gy) = pills[1]
click_at(comp, gx, gy, 10U)
assert_eq(focuses, [ghostty_xid])
// Super+2 targets the 2nd dock item (gamerig-astra) and routes to astra_xid.
comp.handle_input(@nested.InputEvent::Key(125U, true), 20U)
comp.handle_input(@nested.InputEvent::Key(3U, true), 21U)
comp.handle_input(@nested.InputEvent::Key(3U, false), 22U)
comp.handle_input(@nested.InputEvent::Key(125U, false), 23U)
ignore(comp.compose_frame())
assert_eq(focuses, [ghostty_xid, astra_xid])
// Right-clicking Ghostty's pill offers Minimize, Maximize, Quit and routes each command.
click_at(comp, gx, gy, 30U, btn=273U)
assert_true(comp.shell.menu_open)
assert_true(comp.shell.menu_rows.map(r => r.label).contains("Minimize"))
assert_true(comp.shell.menu_rows.map(r => r.label).contains("Maximize"))
assert_true(comp.shell.menu_rows.map(r => r.label).contains("Quit"))
ext_dock_pick(comp, "Minimize", 35U)
click_at(comp, gx, gy, 40U, btn=273U)
ext_dock_pick(comp, "Maximize", 45U)
click_at(comp, gx, gy, 50U, btn=273U)
ext_dock_pick(comp, "Quit", 55U)
assert_eq(cmds, [
(ghostty_xid, @shell.WindowCommand::Minimize),
(ghostty_xid, @shell.WindowCommand::ToggleMaximize),
(ghostty_xid, @shell.WindowCommand::Close),
])
// When Ghostty is minimized, its menu changes to Restore and picking it sends Restore.
comp.set_external_windows([
{ ..ext_wins[0], minimized: true },
ext_wins[1],
ext_wins[2],
])
ignore(comp.compose_frame())
click_at(comp, gx, gy, 60U, btn=273U)
assert_true(comp.shell.menu_rows.map(r => r.label).contains("Restore"))
ext_dock_pick(comp, "Restore", 65U)
assert_eq(cmds[cmds.length() - 1], (ghostty_xid, @shell.WindowCommand::Restore))
// External X11 windows are never persisted in Chandra's Wayland session snapshot.
assert_eq(comp.session_snapshot(0UL).length(), 0)
// Closing external windows removes the running pills and unpinned item from the dock.
comp.set_external_windows([])
ignore(comp.compose_frame())
assert_eq(comp.shell.dock_item_ids(), ["gamerig-astra", "com.mitchellh.ghostty", "steam"])
}