Make the desktop interactive: pointer/keyboard routing, launcher popup, app launching
CI / test (push) Successful in 25s
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:
1 parent
a1b85474f8
commit
a63f65806d
10 files changed
+740
-33
No files matched your search
+125
-2
@@ -128,11 +128,120 @@ fn now() -> @types.Datetime {
|
||||
///| The desktop shell: wallpaper + bottom panel with launcher, task list and clock.
|
||||
pub(all) struct DesktopShell {
|
||||
launcher_state : @launcher.State
|
||||
apps : Array[@types.AppEntry]
|
||||
exec : Map[String, String]
|
||||
/// Wayland socket handed to launched apps as WAYLAND_DISPLAY.
|
||||
display : String
|
||||
mut screen_w : Int
|
||||
mut launcher_rect : @scene.Rect
|
||||
mut popup_rect : @scene.Rect
|
||||
}
|
||||
|
||||
///| Apps the launcher offers, kept only if their executable exists.
|
||||
/// (id, name, comment, category, glyph, executable)
|
||||
let candidates : Array[(String, String, String, String, String, String)] = [
|
||||
("org.moonplasma.terminal", "Terminal", "Command-line shell", "System", ">_", "foot"),
|
||||
("org.moonplasma.konsole", "Konsole", "KDE terminal", "System", ">_", "konsole"),
|
||||
("org.moonplasma.files", "Files", "Browse folders and files", "Utilities", "F", "dolphin"),
|
||||
("org.moonplasma.browser", "Web Browser", "Browse the web", "Internet", "W", "firefox"),
|
||||
("org.moonplasma.editor", "Text Editor", "Edit plain text files", "Utilities", "T", "kate"),
|
||||
("org.moonplasma.settings", "System Settings", "Configure the desktop", "System", "S", "systemsettings"),
|
||||
]
|
||||
|
||||
///|
|
||||
pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
let apps : Array[@types.AppEntry] = []
|
||||
let exec : Map[String, String] = {}
|
||||
for c in candidates {
|
||||
let (id, name, comment, category, glyph, bin) = c
|
||||
if @sys.has_exe(bin) {
|
||||
apps.push({ id, name, comment, category, glyph })
|
||||
exec.set(id, bin)
|
||||
}
|
||||
}
|
||||
{
|
||||
launcher_state: @launcher.State::new(),
|
||||
apps,
|
||||
exec,
|
||||
display,
|
||||
screen_w: 0,
|
||||
launcher_rect: { x: 0, y: 0, w: 0, h: 0 },
|
||||
popup_rect: { x: 0, y: 0, w: 0, h: 0 },
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn DesktopShell::new() -> DesktopShell {
|
||||
{ launcher_state: @launcher.State::new() }
|
||||
fn inside(r : @scene.Rect, x : Int, y : Int) -> Bool {
|
||||
r.w > 0 && x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h
|
||||
}
|
||||
|
||||
///| True while the launcher popup is open (it then owns keyboard input).
|
||||
pub fn DesktopShell::popup_open(self : DesktopShell) -> Bool {
|
||||
self.launcher_state.open
|
||||
}
|
||||
|
||||
///| True if (x, y) is over the launcher button or its open popup.
|
||||
pub fn DesktopShell::hit(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
inside(self.launcher_rect, x, y) ||
|
||||
(self.launcher_state.open && inside(self.popup_rect, x, y))
|
||||
}
|
||||
|
||||
///|
|
||||
fn DesktopShell::launch(self : DesktopShell, id : String) -> Result[Unit, String] {
|
||||
match self.exec.get(id) {
|
||||
None => Err("no executable for " + id)
|
||||
Some(bin) =>
|
||||
if @sys.spawn(bin, self.display) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err("could not start " + bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Pointer press at (x, y). Returns true when the shell consumed it.
|
||||
pub fn DesktopShell::pointer_down(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
let launch = fn(id : String) { self.launch(id) }
|
||||
if inside(self.launcher_rect, x, y) {
|
||||
ignore(
|
||||
@launcher.handle_event(self.apps, self.launcher_state, Widget, PointerDown({ x: x - self.launcher_rect.x, y: y - self.launcher_rect.y }), launch),
|
||||
)
|
||||
true
|
||||
} else if self.launcher_state.open {
|
||||
if inside(self.popup_rect, x, y) {
|
||||
ignore(
|
||||
@launcher.handle_event(self.apps, self.launcher_state, Popup, PointerDown({ x: x - self.popup_rect.x, y: y - self.popup_rect.y }), launch),
|
||||
)
|
||||
true
|
||||
} else {
|
||||
// Click outside: dismiss, and let the click through.
|
||||
ignore(@launcher.handle_event(self.apps, self.launcher_state, Popup, FocusLost, launch))
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
///| Pointer motion; returns true when over the popup (so windows don't see it).
|
||||
pub fn DesktopShell::pointer_move(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
if self.launcher_state.open {
|
||||
let launch = fn(id : String) { self.launch(id) }
|
||||
if inside(self.popup_rect, x, y) {
|
||||
ignore(
|
||||
@launcher.handle_event(self.apps, self.launcher_state, Popup, PointerMove({ x: x - self.popup_rect.x, y: y - self.popup_rect.y }), launch),
|
||||
)
|
||||
return true
|
||||
}
|
||||
ignore(@launcher.handle_event(self.apps, self.launcher_state, Popup, PointerLeave, launch))
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
///| Key name as used by lib/launcher ("Escape", "Backspace", "Enter" or one character).
|
||||
pub fn DesktopShell::key_down(self : DesktopShell, name : String) -> Unit {
|
||||
let launch = fn(id : String) { self.launch(id) }
|
||||
ignore(@launcher.handle_event(self.apps, self.launcher_state, Popup, KeyDown(name), launch))
|
||||
}
|
||||
|
||||
///| Build the (background, panel) render-lists for the current frame.
|
||||
@@ -145,6 +254,7 @@ pub fn DesktopShell::render(
|
||||
window_titles : Array[String],
|
||||
) -> (Array[@scene.DrawOp], Array[@scene.DrawOp]) {
|
||||
let tokens = conv_theme(theme)
|
||||
self.screen_w = w
|
||||
let bg : Array[@scene.DrawOp] = []
|
||||
translate(@libshell.render_background(@ui.size(w, h), tokens), 0, 0, bg)
|
||||
|
||||
@@ -173,6 +283,9 @@ pub fn DesktopShell::render(
|
||||
_ => []
|
||||
}
|
||||
translate(local, p.x, p.y, panel_ops)
|
||||
if p.id == "launcher" {
|
||||
self.launcher_rect = { x: p.x, y: p.y, w: p.w, h: p.h }
|
||||
}
|
||||
if p.id == "tasks" {
|
||||
let mut tx = 0
|
||||
for title in window_titles {
|
||||
@@ -194,5 +307,15 @@ pub fn DesktopShell::render(
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.launcher_state.open {
|
||||
let size = @launcher.popup_size(self.apps, self.launcher_state)
|
||||
let pw = size.w.reinterpret_as_int()
|
||||
let ph = size.h.reinterpret_as_int()
|
||||
let (px, py) = @panel.popup_position(w, h - theme.panel_height, self.launcher_rect.x, pw, ph, 6)
|
||||
self.popup_rect = { x: px, y: py, w: pw, h: ph }
|
||||
translate(@launcher.render_popup(self.apps, tokens, self.launcher_state), px, py, panel_ops)
|
||||
} else {
|
||||
self.popup_rect = { x: 0, y: 0, w: 0, h: 0 }
|
||||
}
|
||||
(bg, panel_ops)
|
||||
}
|
||||
Reference in new issue
Block a user