Task manager panel module and Alt+Tab window switcher
CI / test (push) Failing after 18s

- components/tasks: the 'tasks' module the panel and components.txt already named but whose source
  was missing. One pill per window in opening order (stable, not stacking order), focused lit,
  minimized dimmed, hover, titles shortened, pills shrink to fit; click focuses/restores.
  Tests that loaded it (task list, title-bar minimize/restore) pass again.
- compositor/host/switcher.mbt: hold Alt, press Tab: most-recently-used window list with the
  previous window selected; Tab/Shift+Tab/arrows move, releasing Alt switches (restoring a
  minimized window), Escape cancels. Tab is not forwarded to clients.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-25 03:39:19 -08:00
1 parent 095bbc5906
commit 70ad87f2d2
18 files changed
+1094 -3

No files matched your search

+172
View File
@@ -0,0 +1,172 @@
///| Alt+Tab window switcher.
///
/// Hold Alt and press Tab: a list of the open windows (minimized ones too), most recently used
/// first, with the previous window selected. Each further Tab moves down the list (Shift+Tab up,
/// the arrow keys too); releasing Alt switches to the selected window (restoring it if it was
/// minimized) and Escape cancels. The Tab presses are not forwarded to clients, and the client
/// that had focus is told Alt was let go so it doesn't think it is still held.
///| evdev codes.
let key_tab : UInt = 15
///|
let key_esc : UInt = 1
///|
let key_lalt : UInt = 56
///|
let key_ralt : UInt = 100
///|
let key_up : UInt = 103
///|
let key_down : UInt = 108
///|
let key_left : UInt = 105
///|
let key_right : UInt = 106
///| Windows of the active workspace, most recently used first (minimized ones included).
fn MoonPlasmaCompositor::switcher_candidates(self : MoonPlasmaCompositor) -> Array[UInt64] {
let out : Array[UInt64] = []
for ws in self.wm.workspaces {
if ws.id == self.wm.active_workspace {
for id in ws.mru {
if self.windows.contains(id) && !out.contains(id) {
out.push(id)
}
}
}
}
// Anything the MRU list doesn't know about yet goes last.
for id, _ in self.windows {
if !out.contains(id) {
out.push(id)
}
}
out
}
///| True while the switcher is on screen.
pub fn MoonPlasmaCompositor::switcher_open(self : MoonPlasmaCompositor) -> Bool {
self.switcher_on
}
///| Close the switcher; with `commit`, switch to the selected window.
fn MoonPlasmaCompositor::switcher_close(self : MoonPlasmaCompositor, commit : Bool) -> Unit {
if !self.switcher_on {
return
}
self.switcher_on = false
if commit && self.switcher_sel >= 0 && self.switcher_sel < self.switcher.length() {
self.activate_task(self.switcher[self.switcher_sel])
}
self.switcher.clear()
self.damage.mark_full()
}
///| Handle a key for the switcher. Returns true when the key is consumed (not for clients).
fn MoonPlasmaCompositor::switcher_key(self : MoonPlasmaCompositor, code : UInt, pressed : Bool, time_ms : UInt) -> Bool {
if code == key_lalt || code == key_ralt {
self.alt_down = pressed
if !pressed && self.switcher_on {
self.switcher_close(true)
}
return false // clients still see Alt itself
}
if !pressed {
// Releases of keys we swallowed must not reach a client either.
return self.switcher_on && (code == key_tab || code == key_esc || code == key_up || code == key_down || code == key_left || code == key_right)
}
if code == key_tab && self.alt_down && !self.shell.inspecting() {
let shift = (self.mods & 1U) != 0U
if !self.switcher_on {
let c = self.switcher_candidates()
if c.length() < 2 {
return true // nothing to switch to; still not a client's Tab
}
// Let the client that had focus see Alt released: it won't get the real release.
match self.kbd_win {
Some(w) => {
self.server.keyboard_key(w, time_ms, key_lalt, false)
self.server.keyboard_modifiers(w, 0U, 0U, 0U, 0U)
}
None => ()
}
self.switcher = c
self.switcher_on = true
self.switcher_sel = if shift { c.length() - 1 } else { 1 }
} else {
let n = self.switcher.length()
self.switcher_sel = if shift { (self.switcher_sel + n - 1) % n } else { (self.switcher_sel + 1) % n }
}
self.damage.mark_full()
return true
}
if self.switcher_on {
let n = self.switcher.length()
if code == key_esc {
self.switcher_close(false)
} else if code == key_down || code == key_right {
self.switcher_sel = (self.switcher_sel + 1) % n
self.damage.mark_full()
} else if code == key_up || code == key_left {
self.switcher_sel = (self.switcher_sel + n - 1) % n
self.damage.mark_full()
}
return true // while the switcher is up, keys belong to it
}
false
}
///| The switcher's draw ops: a centred list, the selected row lit. Empty when closed.
fn MoonPlasmaCompositor::switcher_ops(self : MoonPlasmaCompositor) -> Array[@scene.DrawOp] {
let ops : Array[@scene.DrawOp] = []
if !self.switcher_on {
return ops
}
let p = self.theme.palette
let n = self.switcher.length()
let row_h = 38
let pad = 10
let w = if self.output_w < 560 { self.output_w - 20 } else { 520 }
let h = n * row_h + pad * 2
let x = (self.output_w - w) / 2
let y = (self.output_h - h) / 2
let r = self.theme.radius + 4
let fs = self.theme.font_size + 1
// Dim everything behind it a little, then the card.
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, self.output_w, self.output_h), @scene.Rgba::new(0, 0, 0, 90), 0))
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(x, y, w, h), p.surface_popup, r))
ops.push(@scene.DrawOp::StrokeRect(@scene.Rect::new(x, y, w, h), p.border, 1, r))
for i = 0; i < n; i = i + 1 {
let id = self.switcher[i]
let ry = y + pad + i * row_h
let sel = i == self.switcher_sel
let (title, app, minimized) = match self.windows.get(id) {
Some(win) => {
let m = match self.wm.windows.get(id) {
Some(rec) => rec.minimized
None => false
}
(if win.title.length() > 0 { win.title } else { win.app_id }, win.app_id, m)
}
None => ("", "", false)
}
if sel {
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(x + pad, ry, w - pad * 2, row_h - 4), p.accent, self.theme.radius))
}
let fg = if sel { p.accent_foreground } else if minimized { p.foreground_muted } else { p.foreground }
let cw = (fs * 11 + 19) / 20
let max_chars = (w - pad * 2 - 150) / cw
let shown = if title.length() > max_chars && max_chars > 1 { title[:max_chars - 1].to_string() + "…" } else { title }
ops.push(@scene.DrawOp::Text(x + pad + 12, ry + (row_h - 4) / 2, shown, fs, fg, @scene.TextAlign::Left, sel))
let tag = if minimized { app + " (minimized)" } else { app }
ops.push(@scene.DrawOp::Text(x + w - pad - 12, ry + (row_h - 4) / 2, tag, fs - 2, if sel { p.accent_foreground } else { p.foreground_muted }, @scene.TextAlign::Right, false))
}
ops
}