- 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:
1 parent
095bbc5906
commit
70ad87f2d2
18 files changed
+1094
-3
No files matched your search
@@ -53,6 +53,11 @@ pub(all) struct MoonPlasmaCompositor {
|
||||
mut layout_mode : @wm.LayoutMode
|
||||
/// Set when the user asked to end the session (the logout button); the main loop then exits.
|
||||
mut quit_requested : Bool
|
||||
/// Alt+Tab switcher (switcher.mbt): whether it is up, its window list (most recent first) and selection.
|
||||
mut switcher_on : Bool
|
||||
mut switcher : Array[UInt64]
|
||||
mut switcher_sel : Int
|
||||
mut alt_down : Bool
|
||||
/// Milliseconds spent so far in the shell (panel modules) and in the rasteriser, for --profile.
|
||||
/// The last composed frame and what it was made from: an unchanged desktop is not redrawn.
|
||||
mut last_frame : @renderer.Pixmap?
|
||||
@@ -110,6 +115,10 @@ pub fn MoonPlasmaCompositor::new(
|
||||
super_solo: false,
|
||||
layout_mode: @wm.LayoutMode::Tiling,
|
||||
quit_requested: false,
|
||||
switcher_on: false,
|
||||
switcher: [],
|
||||
switcher_sel: 0,
|
||||
alt_down: false,
|
||||
last_frame: None,
|
||||
last_sig: None,
|
||||
frame_changed: true,
|
||||
@@ -457,6 +466,9 @@ pub fn MoonPlasmaCompositor::compose_frame(
|
||||
self.shell.win_list = entries
|
||||
let t0 = @sys.monotonic_ms()
|
||||
let (bg_ops, panel_ops) = self.shell.render(self.output_w, self.output_h, self.theme)
|
||||
if self.switcher_on {
|
||||
panel_ops.append(self.switcher_ops())
|
||||
}
|
||||
self.run_shell_actions()
|
||||
scene.background_ops = bg_ops
|
||||
scene.panel_ops = panel_ops
|
||||
@@ -1128,7 +1140,9 @@ pub fn MoonPlasmaCompositor::handle_input(
|
||||
}
|
||||
}
|
||||
Key(code, pressed) =>
|
||||
if code == 125U || code == 126U {
|
||||
if self.switcher_key(code, pressed, time_ms) {
|
||||
self.super_solo = false
|
||||
} else if code == 125U || code == 126U {
|
||||
// Super (left/right): a bare tap toggles the launcher search; never reaches clients.
|
||||
if pressed {
|
||||
self.super_solo = true
|
||||
|
||||
@@ -251,8 +251,8 @@ test "title-bar buttons minimize, maximize and close windows" {
|
||||
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
||||
assert_true(!comp.wm.stacking_order().contains(1UL))
|
||||
let tasks = rect_of(comp, "tasks")
|
||||
// pills: the visible window first, the minimized one second (140 wide, 6 apart)
|
||||
click((tasks.x + 146 + 20, tasks.y + tasks.h / 2), 30U)
|
||||
// pills are in opening order (140 wide, 6 apart): window 1, the minimized one, is first
|
||||
click((tasks.x + 20, tasks.y + tasks.h / 2), 30U)
|
||||
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
|
||||
// Close window 2: the client receives xdg_toplevel.close (opcode 1 on its toplevel).
|
||||
ignore(drain_msgs(c))
|
||||
@@ -978,3 +978,55 @@ test "a window dragged somewhere reopens there, saved per app in state.edn" {
|
||||
assert_eq(g2.y, g1.y)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "alt-tab switches to the previous window, tab again goes further back, escape cancels" {
|
||||
let socket_path = "/tmp/wayland-moon-alt-" + @sys.getpid().to_string() + ".sock"
|
||||
let theme = @scene.ThemeTokens::moon_night()
|
||||
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
||||
ignore(open_and_configure_client(comp, socket_path, "A", "a"))
|
||||
ignore(open_and_configure_client(comp, socket_path, "B", "b"))
|
||||
ignore(open_and_configure_client(comp, socket_path, "C", "c"))
|
||||
ignore(comp.compose_frame())
|
||||
let focused = fn() {
|
||||
let mut f = 0UL
|
||||
for id, w in comp.windows {
|
||||
if w.focused {
|
||||
f = id
|
||||
}
|
||||
}
|
||||
f
|
||||
}
|
||||
let key = fn(code : UInt, down : Bool, t : UInt) {
|
||||
comp.handle_input(@nested.InputEvent::Key(code, down), t)
|
||||
}
|
||||
assert_eq(focused(), 3UL)
|
||||
// Alt+Tab, release Alt: the window used before this one.
|
||||
key(56U, true, 1U)
|
||||
key(15U, true, 2U)
|
||||
key(15U, false, 3U)
|
||||
assert_true(comp.switcher_open())
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(comp.frame_changed) // the switcher is drawn
|
||||
assert_eq(focused(), 3UL) // nothing switches until Alt is released
|
||||
key(56U, false, 4U)
|
||||
assert_false(comp.switcher_open())
|
||||
assert_eq(focused(), 2UL)
|
||||
// Alt+Tab+Tab: two back in use order (3 was used before 2, then 1).
|
||||
key(56U, true, 10U)
|
||||
key(15U, true, 11U)
|
||||
key(15U, true, 12U)
|
||||
key(56U, false, 13U)
|
||||
assert_eq(focused(), 1UL)
|
||||
// Escape closes it without switching.
|
||||
key(56U, true, 20U)
|
||||
key(15U, true, 21U)
|
||||
assert_true(comp.switcher_open())
|
||||
key(1U, true, 22U)
|
||||
assert_false(comp.switcher_open())
|
||||
key(56U, false, 23U)
|
||||
assert_eq(focused(), 1UL)
|
||||
// With the Alt not held, Tab is an ordinary key.
|
||||
key(15U, true, 30U)
|
||||
assert_false(comp.switcher_open())
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user