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

+199 -1
View File
@@ -96,6 +96,9 @@ struct ClientConn {
shm_buffers : Map[UInt, ShmBufferState]
xdg_surfaces : Map[UInt, XdgSurfaceState]
toplevels : Map[UInt64, ToplevelState]
pointer_ids : Array[UInt]
keyboard_ids : Array[UInt]
mut seat_ver : UInt
mut alive : Bool
}
@@ -114,6 +117,9 @@ fn ClientConn::new(client_id : UInt, fd : Int) -> ClientConn {
shm_buffers: {},
xdg_surfaces: {},
toplevels: {},
pointer_ids: [],
keyboard_ids: [],
seat_ver: 1U,
alive: true,
}
}
@@ -158,6 +164,7 @@ pub(all) struct WaylandServer {
mut next_client_id : UInt
mut next_win_id : UInt64
mut next_serial : UInt
mut keymap : Bytes
}
///|
@@ -180,6 +187,7 @@ pub fn WaylandServer::listen(
next_client_id: 1U,
next_win_id: 1UL,
next_serial: 100U,
keymap: Bytes::from_array([]),
})
}
@@ -362,7 +370,7 @@ fn WaylandServer::dispatch_msg(
// bind(name: u32, interface: string, version: u32, id: new_id)
let _name = reader.u32()
let iface = reader.str()
let _ver = reader.u32()
let ver = reader.u32()
let new_id = reader.u32()
if iface == "wl_compositor" {
c.objects.set(new_id, ObjCompositor)
@@ -375,6 +383,7 @@ fn WaylandServer::dispatch_msg(
c.objects.set(new_id, ObjDecoManager)
} else if iface == "wl_seat" {
c.objects.set(new_id, ObjSeat)
c.seat_ver = ver
emit_seat_info(c, new_id)
} else if iface == "wl_data_device_manager" {
c.objects.set(new_id, ObjDataManager)
@@ -679,9 +688,12 @@ fn WaylandServer::dispatch_msg(
if opcode == 0U {
let pid = reader.u32()
c.objects.set(pid, ObjPointer)
c.pointer_ids.push(pid)
} else if opcode == 1U {
let kid = reader.u32()
c.objects.set(kid, ObjKeyboard)
c.keyboard_ids.push(kid)
self.send_keymap(c, kid)
} else if opcode == 2U {
let tid = reader.u32()
c.objects.set(tid, ObjTouch)
@@ -861,3 +873,189 @@ pub fn WaylandServer::send_toplevel_close(
None => ()
}
}
///| Keymap (xkb text, format xkb_v1) shared with every client keyboard; set by the backend.
pub fn WaylandServer::set_keymap(self : WaylandServer, keymap : Bytes) -> Unit {
self.keymap = keymap
}
///|
fn WaylandServer::send_keymap(self : WaylandServer, c : ClientConn, kid : UInt) -> Unit {
if self.keymap.length() > 0 {
let fd = @sys.memfd_create("moon-plasma-keymap", self.keymap.length())
if fd >= 0 {
ignore(@sys.pwrite_bytes(fd, self.keymap, 0))
let w = WireWriter::new()
w.u32(1U) // xkb_v1
w.u32(self.keymap.length().reinterpret_as_uint())
if c.alive {
ignore(@sys.sendmsg_fd(c.fd, w.finish_msg(kid, 0U), fd))
}
@sys.close_fd(fd)
}
}
if c.seat_ver >= 4U {
let r = WireWriter::new()
r.i32(25) // repeat rate (keys/s)
r.i32(400) // repeat delay (ms)
c.send_msg(r.finish_msg(kid, 5U))
}
}
///|
fn WaylandServer::win_client(
self : WaylandServer,
win_id : UInt64,
) -> (ClientConn, ToplevelState)? {
match self.win_to_client.get(win_id) {
None => None
Some(cid) =>
match self.find_client(cid) {
None => None
Some(c) =>
match c.toplevels.get(win_id) {
None => None
Some(tl) => Some((c, tl))
}
}
}
}
///|
fn fixed(v : Double) -> Int {
(v * 256.0).to_int()
}
///| wl_pointer.enter at surface-local (x, y).
pub fn WaylandServer::pointer_enter(self : WaylandServer, win_id : UInt64, x : Double, y : Double) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, tl)) =>
for pid in c.pointer_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(tl.wl_surface_id)
w.i32(fixed(x))
w.i32(fixed(y))
c.send_msg(w.finish_msg(pid, 0U))
self.pointer_frame(c, pid)
}
}
}
///|
pub fn WaylandServer::pointer_leave(self : WaylandServer, win_id : UInt64) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, tl)) =>
for pid in c.pointer_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(tl.wl_surface_id)
c.send_msg(w.finish_msg(pid, 1U))
self.pointer_frame(c, pid)
}
}
}
///|
pub fn WaylandServer::pointer_motion(self : WaylandServer, win_id : UInt64, time_ms : UInt, x : Double, y : Double) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, _)) =>
for pid in c.pointer_ids {
let w = WireWriter::new()
w.u32(time_ms)
w.i32(fixed(x))
w.i32(fixed(y))
c.send_msg(w.finish_msg(pid, 2U))
self.pointer_frame(c, pid)
}
}
}
///| `button` is a Linux evdev code (BTN_LEFT = 0x110); `pressed` true on press.
pub fn WaylandServer::pointer_button(self : WaylandServer, win_id : UInt64, time_ms : UInt, button : UInt, pressed : Bool) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, _)) =>
for pid in c.pointer_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(time_ms)
w.u32(button)
w.u32(if pressed { 1U } else { 0U })
c.send_msg(w.finish_msg(pid, 3U))
self.pointer_frame(c, pid)
}
}
}
///|
fn WaylandServer::pointer_frame(_self : WaylandServer, c : ClientConn, pid : UInt) -> Unit {
if c.seat_ver >= 5U {
c.send_msg(WireWriter::new().finish_msg(pid, 5U))
}
}
///|
pub fn WaylandServer::keyboard_enter(self : WaylandServer, win_id : UInt64) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, tl)) =>
for kid in c.keyboard_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(tl.wl_surface_id)
w.array([])
c.send_msg(w.finish_msg(kid, 1U))
}
}
}
///|
pub fn WaylandServer::keyboard_leave(self : WaylandServer, win_id : UInt64) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, tl)) =>
for kid in c.keyboard_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(tl.wl_surface_id)
c.send_msg(w.finish_msg(kid, 2U))
}
}
}
///| `key` is a Linux evdev keycode.
pub fn WaylandServer::keyboard_key(self : WaylandServer, win_id : UInt64, time_ms : UInt, key : UInt, pressed : Bool) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, _)) =>
for kid in c.keyboard_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(time_ms)
w.u32(key)
w.u32(if pressed { 1U } else { 0U })
c.send_msg(w.finish_msg(kid, 3U))
}
}
}
///|
pub fn WaylandServer::keyboard_modifiers(self : WaylandServer, win_id : UInt64, depressed : UInt, latched : UInt, locked : UInt, group : UInt) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, _)) =>
for kid in c.keyboard_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(depressed)
w.u32(latched)
w.u32(locked)
w.u32(group)
c.send_msg(w.finish_msg(kid, 4U))
}
}
}