Make the desktop interactive: pointer/keyboard routing, launcher popup, app launching
CI / test (push) Successful in 25s

- server: wl_pointer/wl_keyboard events (enter/leave/motion/button/key/modifiers),
  host keymap shared with client keyboards
- nested: receives host pointer + keyboard + keymap, queues InputEvents
- host: routes input to the launcher popup or the window under the pointer;
  click-to-focus moves keyboard focus
- shell: launcher button opens lib/launcher popup; entries start real apps
  (foot, konsole, dolphin, firefox, kate, systemsettings if installed) with
  WAYLAND_DISPLAY pointed at the compositor
- sys: has_exe + spawn
- e2e test for input delivery and the launcher popup

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-24 19:11:15 -08:00
1 parent a1b85474f8
commit a63f65806d
10 files changed
+740 -33

No files matched your search

+74 -26
View File
@@ -1,10 +1,22 @@
///| Nested backend: shows the compositor's frames in a window of the host
/// Wayland session. The compositor is a plain Wayland *client* here (wl_shm
/// buffers over SCM_RIGHTS + xdg_toplevel), reusing the same wire code and C
/// shim as the server side, and forwards host pointer input to the gfx surface.
/// shim as the server side, and queues host pointer/keyboard input for the compositor.
///| Input forwarded from the host session (pointer in window pixels; key = evdev code).
pub(all) enum InputEvent {
PointerMove(Double, Double)
PointerButton(UInt, Bool)
Key(UInt, Bool)
Modifiers(UInt, UInt, UInt, UInt)
}
///|
pub(all) struct NestedWindow {
input : Array[InputEvent]
fds : Array[Int]
mut keymap : Bytes
mut keyboard_id : UInt
fd : Int
rx : Array[Byte]
globals : Map[String, (UInt, UInt)]
@@ -60,12 +72,12 @@ fn NestedWindow::bind(self : NestedWindow, iface : String, ver : UInt) -> UInt {
}
///| Read and dispatch everything pending on the host socket (non-blocking).
fn NestedWindow::pump_events(self : NestedWindow, surface : @gfx.Surface?) -> Unit {
fn NestedWindow::pump_events(self : NestedWindow) -> Unit {
let scratch : FixedArray[Byte] = FixedArray::make(16384, b'\x00')
while @sys.poll_read(self.fd, 0) > 0 {
let (n, rfd) = @sys.recvmsg_fd(self.fd, scratch, 16384)
if rfd >= 0 {
@sys.close_fd(rfd)
self.fds.push(rfd)
}
if n <= 0 {
self.closed = true
@@ -85,7 +97,7 @@ fn NestedWindow::pump_events(self : NestedWindow, surface : @gfx.Surface?) -> Un
break
}
let r = @wayland.WireReader::from_array(self.rx, off + 8)
self.dispatch(obj, op, r, surface)
self.dispatch(obj, op, r)
off = off + size
}
if off > 0 {
@@ -106,7 +118,6 @@ fn NestedWindow::dispatch(
obj : UInt,
op : UInt,
r : @wayland.WireReader,
surface : @gfx.Surface?,
) -> Unit {
if obj == 1U {
if op == 0U {
@@ -149,15 +160,51 @@ fn NestedWindow::dispatch(
self.closed = true
}
} else if obj == self.seat_id {
if op == 0U && self.pointer_id == 0U {
if op == 0U {
let caps = r.u32()
if (caps & 1U) != 0U {
if (caps & 1U) != 0U && self.pointer_id == 0U {
let id = self.alloc()
let w = @wayland.WireWriter::new()
w.u32(id)
self.send(w.finish_msg(self.seat_id, 0U))
self.pointer_id = id
}
if (caps & 2U) != 0U && self.keyboard_id == 0U {
let id = self.alloc()
let w = @wayland.WireWriter::new()
w.u32(id)
self.send(w.finish_msg(self.seat_id, 1U))
self.keyboard_id = id
}
}
} else if self.keyboard_id != 0U && obj == self.keyboard_id {
match op {
0U => {
// keymap(format, fd, size)
let _format = r.u32()
let size = r.u32().reinterpret_as_int()
if self.fds.length() > 0 {
let fd = self.fds.remove(0)
self.keymap = @sys.mmap_read(fd, size)
@sys.close_fd(fd)
}
}
3U => {
let _serial = r.u32()
let _time = r.u32()
let key = r.u32()
let state = r.u32()
self.input.push(Key(key, state == 1U))
}
4U => {
let _serial = r.u32()
let dep = r.u32()
let lat = r.u32()
let lock = r.u32()
let group = r.u32()
self.input.push(Modifiers(dep, lat, lock, group))
}
_ => ()
}
} else if self.pointer_id != 0U && obj == self.pointer_id {
match op {
@@ -166,30 +213,20 @@ fn NestedWindow::dispatch(
let _surf = r.u32()
self.px = r.i32().to_double() / 256.0
self.py = r.i32().to_double() / 256.0
self.input.push(PointerMove(self.px, self.py))
}
2U => {
let _time = r.u32()
self.px = r.i32().to_double() / 256.0
self.py = r.i32().to_double() / 256.0
match surface {
Some(s) => s.push_pointer_move(self.px, self.py)
None => ()
}
self.input.push(PointerMove(self.px, self.py))
}
3U => {
let _serial = r.u32()
let _time = r.u32()
let _button = r.u32()
let button = r.u32()
let state = r.u32()
match surface {
Some(s) =>
if state == 1U {
s.push_pointer_down(self.px, self.py)
} else {
s.push_pointer_up(self.px, self.py)
}
None => ()
}
self.input.push(PointerButton(button, state == 1U))
}
_ => ()
}
@@ -214,7 +251,7 @@ fn NestedWindow::roundtrip(self : NestedWindow) -> Unit {
let mut tries = 0
while !self.sync_done && !self.closed && tries < 500 {
ignore(@sys.poll_read(self.fd, 10))
self.pump_events(None)
self.pump_events()
tries = tries + 1
}
self.sync_cb = 0U
@@ -241,6 +278,10 @@ pub fn NestedWindow::open(
}
let self : NestedWindow = {
fd,
input: [],
fds: [],
keymap: Bytes::from_array([]),
keyboard_id: 0U,
rx: [],
globals: {},
live_buffers: {},
@@ -308,7 +349,7 @@ pub fn NestedWindow::open(
let mut tries = 0
while !self.configured && !self.closed && tries < 500 {
ignore(@sys.poll_read(self.fd, 10))
self.pump_events(None)
self.pump_events()
tries = tries + 1
}
if !self.configured {
@@ -318,13 +359,20 @@ pub fn NestedWindow::open(
Some(self)
}
///| Pump host events (forwarding pointer input to `surface`). False once the
///| Pump host events (input is queued; see take_input). False once the
/// window was closed or the host went away.
pub fn NestedWindow::poll(self : NestedWindow, surface : @gfx.Surface) -> Bool {
self.pump_events(Some(surface))
pub fn NestedWindow::poll(self : NestedWindow) -> Bool {
self.pump_events()
!self.closed
}
///| Take all input received since the last call.
pub fn NestedWindow::take_input(self : NestedWindow) -> Array[InputEvent] {
let out = self.input.copy()
self.input.clear()
out
}
///| Show `pixmap` (RGBA8888) in the window. Skipped while the host has not yet
/// consumed the previous frame, so a slow host never builds a backlog.
pub fn NestedWindow::present(self : NestedWindow, pixmap : @renderer.Pixmap) -> Unit {