Task manager: right-click a window's pill for Minimize/Restore, Maximize, Quit
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
- Right-clicking a pill in the task manager opens that window's menu (titled with the window's title): Minimize (Restore when minimized), Maximize (Restore size when maximized) and Quit, which asks the app to close the window (xdg_toplevel close, like the title-bar close button). Empty task-bar space keeps the module's own menu (Module settings, Replace with, Remove widget). - Modules only get left clicks, so the shell draws the menu and hit-tests the pills itself: the pill geometry moved to lib/panel/tasks.mbt, shared by the tasks module and the shell. No WIT change, so every host works as before. - New menu row kind 6 and ShellAction::Window(id, WindowCommand); the compositor runs it through the same WM requests as the title-bar buttons. WinInfo carries `maximized`. - Tests: native end-to-end (menu rows, minimize/restore, maximize/restore size, Quit sends close, empty space keeps the module menu) and lib/panel pill geometry tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hiX13fXK1eMboRe5oQ
This commit is contained in:
9 files changed
+238
-35
No files matched your search
@@ -5,6 +5,7 @@ import {
|
|||||||
"chandra/desktop/interface/chandra/desktop/icons" @icons,
|
"chandra/desktop/interface/chandra/desktop/icons" @icons,
|
||||||
"chandra/desktop/lib/ui" @ui,
|
"chandra/desktop/lib/ui" @ui,
|
||||||
"chandra/desktop/lib/dock" @dock,
|
"chandra/desktop/lib/dock" @dock,
|
||||||
|
"chandra/desktop/lib/panel" @panel,
|
||||||
}
|
}
|
||||||
|
|
||||||
warnings = "-44"
|
warnings = "-44"
|
||||||
@@ -3,17 +3,12 @@
|
|||||||
/// Each pill starts with the app's icon: the one its .desktop file names, from the icon theme (the
|
/// Each pill starts with the app's icon: the one its .desktop file names, from the icon theme (the
|
||||||
/// `icons` capability), else the coloured letter tile the dock shows for that app id.
|
/// `icons` capability), else the coloured letter tile the dock shows for that app id.
|
||||||
/// The focused window's pill is lit, a minimized window's is dimmed; a click focuses the window and
|
/// The focused window's pill is lit, a minimized window's is dimmed; a click focuses the window and
|
||||||
/// restores it if it was minimized. When the bar is too narrow the pills shrink to fit, and below
|
/// restores it if it was minimized; a right-click opens the window's menu (drawn by the shell). When the bar is too narrow the pills shrink to fit, and below
|
||||||
/// `icon_only_w` they show just the icon.
|
/// `icon_only_w` they show just the icon.
|
||||||
|
|
||||||
///| Widest a pill gets, the gap between pills, and the narrowest before titles stop being readable.
|
///| Pill geometry is shared with the shell (lib/panel/tasks.mbt): it hit-tests right-clicks
|
||||||
let pill_max : Int = 140
|
/// on pills to show the window's menu (Quit, Minimize, Maximize).
|
||||||
|
let gap : Int = @panel.task_pill_gap
|
||||||
///|
|
|
||||||
let gap : Int = 6
|
|
||||||
|
|
||||||
///|
|
|
||||||
let pill_min : Int = 56
|
|
||||||
|
|
||||||
///| Pills narrower than this drop the title and show only the centred icon.
|
///| Pills narrower than this drop the title and show only the centred icon.
|
||||||
let icon_only_w : Int = 72
|
let icon_only_w : Int = 72
|
||||||
@@ -69,31 +64,12 @@ fn windows_sorted() -> Array[@windows.WindowInfo] {
|
|||||||
|
|
||||||
///| Pill width for `n` windows in a bar `w` wide.
|
///| Pill width for `n` windows in a bar `w` wide.
|
||||||
fn pill_w(n : Int, w : Int) -> Int {
|
fn pill_w(n : Int, w : Int) -> Int {
|
||||||
if n <= 0 {
|
@panel.task_pill_w(n, w)
|
||||||
return pill_max
|
|
||||||
}
|
|
||||||
let fit = (w - gap * (n - 1)) / n
|
|
||||||
if fit > pill_max {
|
|
||||||
pill_max
|
|
||||||
} else if fit < pill_min {
|
|
||||||
pill_min
|
|
||||||
} else {
|
|
||||||
fit
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The pill under a widget-local x, or -1.
|
///| The pill under a widget-local x, or -1.
|
||||||
fn pill_at(x : Int, n : Int) -> Int {
|
fn pill_at(x : Int, n : Int) -> Int {
|
||||||
let pw = pill_w(n, last_w.val)
|
@panel.task_pill_at(x, n, last_w.val)
|
||||||
if x < 0 {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
let i = x / (pw + gap)
|
|
||||||
if i < n && x - i * (pw + gap) < pw {
|
|
||||||
i
|
|
||||||
} else {
|
|
||||||
-1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///| `s` shortened with an ellipsis until it fits `max_w` pixels.
|
///| `s` shortened with an ellipsis until it fits `max_w` pixels.
|
||||||
|
|||||||
@@ -655,6 +655,7 @@ fn ChandraCompositor::build_scene(
|
|||||||
title: if win.title.length() > 0 { win.title } else { win.app_id },
|
title: if win.title.length() > 0 { win.title } else { win.app_id },
|
||||||
focused: win.focused,
|
focused: win.focused,
|
||||||
minimized: false,
|
minimized: false,
|
||||||
|
maximized: win.maximized,
|
||||||
})
|
})
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
@@ -668,6 +669,7 @@ fn ChandraCompositor::build_scene(
|
|||||||
title: if win.title.length() > 0 { win.title } else { win.app_id },
|
title: if win.title.length() > 0 { win.title } else { win.app_id },
|
||||||
focused: false,
|
focused: false,
|
||||||
minimized: true,
|
minimized: true,
|
||||||
|
maximized: win.maximized,
|
||||||
})
|
})
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
@@ -1122,6 +1124,29 @@ fn ChandraCompositor::activate_task(self : ChandraCompositor, wid : UInt64) -> U
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| A row of a task-bar pill's right-click menu: close (the app may still ask to save), minimize,
|
||||||
|
/// restore, or maximize / restore the size of window `wid`.
|
||||||
|
fn ChandraCompositor::window_command(
|
||||||
|
self : ChandraCompositor,
|
||||||
|
wid : UInt64,
|
||||||
|
cmd : @shell.WindowCommand,
|
||||||
|
) -> Unit {
|
||||||
|
if self.wm.windows.get(wid) is None {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
match cmd {
|
||||||
|
Close => self.press_title_button(wid, 3)
|
||||||
|
Minimize => self.press_title_button(wid, 1)
|
||||||
|
Restore => self.activate_task(wid)
|
||||||
|
ToggleMaximize => {
|
||||||
|
// A minimized window comes back first, then (un)maximizes in front.
|
||||||
|
self.activate_task(wid)
|
||||||
|
self.press_title_button(wid, 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.damage.mark_full()
|
||||||
|
}
|
||||||
|
|
||||||
///| Use the dark (configured) or the light theme, as the shell's Dark mode setting says, for the
|
///| Use the dark (configured) or the light theme, as the shell's Dark mode setting says, for the
|
||||||
/// shell, the panel modules, the window decorations and the switcher; redraws everything, and
|
/// shell, the panel modules, the window decorations and the switcher; redraws everything, and
|
||||||
/// (in the login session) tells apps through the system preference.
|
/// (in the login session) tells apps through the system preference.
|
||||||
@@ -1142,6 +1167,7 @@ fn ChandraCompositor::run_shell_actions(self : ChandraCompositor) -> Unit {
|
|||||||
@shell.ShellAction::ThemeChanged => self.apply_theme()
|
@shell.ShellAction::ThemeChanged => self.apply_theme()
|
||||||
@shell.ShellAction::Screenshot(code) => self.screenshot_request(code)
|
@shell.ShellAction::Screenshot(code) => self.screenshot_request(code)
|
||||||
@shell.ShellAction::SystemPower(a) => self.system_power(a)
|
@shell.ShellAction::SystemPower(a) => self.system_power(a)
|
||||||
|
@shell.ShellAction::Window(wid, cmd) => self.window_command(wid, cmd)
|
||||||
@shell.ShellAction::SetLayout(m) =>
|
@shell.ShellAction::SetLayout(m) =>
|
||||||
match m {
|
match m {
|
||||||
0 => self.set_layout_mode(@wm.LayoutMode::Tiling)
|
0 => self.set_layout_mode(@wm.LayoutMode::Tiling)
|
||||||
|
|||||||
@@ -305,6 +305,67 @@ test "the task list module focuses the window whose pill is clicked" {
|
|||||||
assert_true(focused() != first || other.length() == 1)
|
assert_true(focused() != first || other.length() == 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Quit" {
|
||||||
|
let socket_path = "/tmp/wayland-moon-taskmenu-" +
|
||||||
|
@sys.getpid().to_string() +
|
||||||
|
".sock"
|
||||||
|
let theme = @scene.ThemeTokens::moon_night()
|
||||||
|
let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
||||||
|
let (c, _shm, _surf, _xdg, tl, _deco) = open_and_configure_client(comp, socket_path, "A", "a")
|
||||||
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
||||||
|
ignore(comp.compose_frame())
|
||||||
|
let tasks = rect_of(comp, "tasks")
|
||||||
|
let cy = tasks.y + tasks.h / 2
|
||||||
|
let labels = fn() { comp.shell.menu_rows.map(r => r.label) }
|
||||||
|
// Pick menu row `label` (rows: 26px title, then 28px each).
|
||||||
|
let pick = fn(label : String, t : UInt) raise {
|
||||||
|
let i = labels().search(label).unwrap()
|
||||||
|
let m = comp.shell.menu_rect
|
||||||
|
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
|
||||||
|
}
|
||||||
|
// Pill 0 is window 1 (opening order): its menu, titled with its title.
|
||||||
|
click_at(comp, tasks.x + 20, cy, 1U, btn=273U)
|
||||||
|
assert_true(comp.shell.menu_open)
|
||||||
|
assert_eq(comp.shell.menu_title, "A")
|
||||||
|
assert_eq(labels(), ["Minimize", "Maximize", "Quit"])
|
||||||
|
// Minimize, then the same pill's menu offers Restore, which brings it back.
|
||||||
|
pick("Minimize", 10U)
|
||||||
|
assert_true(!comp.shell.menu_open)
|
||||||
|
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
||||||
|
click_at(comp, tasks.x + 20, cy, 20U, btn=273U)
|
||||||
|
assert_eq(labels(), ["Restore", "Maximize", "Quit"])
|
||||||
|
pick("Restore", 30U)
|
||||||
|
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
|
||||||
|
// Maximize, then Restore size.
|
||||||
|
let w0 = comp.windows.get(1UL).unwrap().geometry.w
|
||||||
|
click_at(comp, tasks.x + 20, cy, 40U, btn=273U)
|
||||||
|
pick("Maximize", 50U)
|
||||||
|
assert_true(comp.windows.get(1UL).unwrap().geometry.w > w0)
|
||||||
|
click_at(comp, tasks.x + 20, cy, 60U, btn=273U)
|
||||||
|
assert_eq(labels(), ["Minimize", "Restore size", "Quit"])
|
||||||
|
pick("Restore size", 70U)
|
||||||
|
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, w0)
|
||||||
|
// Pill 1 is window 2.
|
||||||
|
click_at(comp, tasks.x + 146 + 20, cy, 80U, btn=273U)
|
||||||
|
assert_eq(comp.shell.menu_title, "B")
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 85U) // Escape
|
||||||
|
assert_true(!comp.shell.menu_open)
|
||||||
|
// Quit asks the app to close its window (xdg_toplevel.close, opcode 1 on its toplevel).
|
||||||
|
ignore(drain_msgs(c))
|
||||||
|
click_at(comp, tasks.x + 20, cy, 90U, btn=273U)
|
||||||
|
pick("Quit", 100U)
|
||||||
|
for _i = 0; _i < 5; _i = _i + 1 {
|
||||||
|
comp.step()
|
||||||
|
@sys.sleep_ms(2)
|
||||||
|
}
|
||||||
|
assert_true(has_msg(drain_msgs(c), tl, 1U))
|
||||||
|
// Empty task-bar space keeps the module's own menu.
|
||||||
|
click_at(comp, tasks.x + tasks.w - 10, cy, 110U, btn=273U)
|
||||||
|
assert_eq(comp.shell.menu_title, "Task Manager")
|
||||||
|
assert_true(labels().contains("Remove widget"))
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
test "right-click a panel module to replace it in place, or remove it" {
|
test "right-click a panel module to replace it in place, or remove it" {
|
||||||
let comp = new_comp("swap")
|
let comp = new_comp("swap")
|
||||||
|
|||||||
@@ -132,8 +132,21 @@ pub(all) struct WinInfo {
|
|||||||
title : String
|
title : String
|
||||||
focused : Bool
|
focused : Bool
|
||||||
minimized : Bool
|
minimized : Bool
|
||||||
|
/// Maximized (also while minimized: restoring brings it back maximized).
|
||||||
|
maximized : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| What the window menu of a task-bar pill asks for (`ShellAction::Window`).
|
||||||
|
pub(all) enum WindowCommand {
|
||||||
|
/// Ask the app to close the window (xdg_toplevel close; the app may still ask to save).
|
||||||
|
Close
|
||||||
|
Minimize
|
||||||
|
/// Un-minimize and focus.
|
||||||
|
Restore
|
||||||
|
/// Maximize, or bring a maximized window back to its size.
|
||||||
|
ToggleMaximize
|
||||||
|
} derive(Eq, Debug)
|
||||||
|
|
||||||
///| Something a panel module asked the compositor to do.
|
///| Something a panel module asked the compositor to do.
|
||||||
pub(all) enum ShellAction {
|
pub(all) enum ShellAction {
|
||||||
SetLayout(Int)
|
SetLayout(Int)
|
||||||
@@ -147,6 +160,8 @@ pub(all) enum ShellAction {
|
|||||||
Screenshot(Int)
|
Screenshot(Int)
|
||||||
/// The settings module's Power tab asked to suspend (0), power off (1) or restart (2) now.
|
/// The settings module's Power tab asked to suspend (0), power off (1) or restart (2) now.
|
||||||
SystemPower(Int)
|
SystemPower(Int)
|
||||||
|
/// A row of a task-bar pill's right-click menu: do this to that window.
|
||||||
|
Window(UInt64, WindowCommand)
|
||||||
} derive(Eq, Debug)
|
} derive(Eq, Debug)
|
||||||
|
|
||||||
///| One wasm module loaded into the panel.
|
///| One wasm module loaded into the panel.
|
||||||
@@ -176,7 +191,8 @@ pub(all) struct CatalogEntry {
|
|||||||
|
|
||||||
///| One row of the right-click menu. `kind`: 0 replace with module `arg` (a path), 1 remove,
|
///| One row of the right-click menu. `kind`: 0 replace with module `arg` (a path), 1 remove,
|
||||||
/// 2 open System settings, 3 open the module's own settings, 4 set the module's setting `arg` to
|
/// 2 open System settings, 3 open the module's own settings, 4 set the module's setting `arg` to
|
||||||
/// `value`, 5 a heading or note (not clickable).
|
/// `value`, 5 a heading or note (not clickable), 6 a window command (`window_cmd`) for the window
|
||||||
|
/// whose task-bar pill was right-clicked (`window_id`).
|
||||||
pub(all) struct MenuRow {
|
pub(all) struct MenuRow {
|
||||||
label : String
|
label : String
|
||||||
kind : Int
|
kind : Int
|
||||||
@@ -185,11 +201,19 @@ pub(all) struct MenuRow {
|
|||||||
value : String
|
value : String
|
||||||
/// Draw a tick: the value a kind-4 row sets is the current one.
|
/// Draw a tick: the value a kind-4 row sets is the current one.
|
||||||
ticked : Bool
|
ticked : Bool
|
||||||
|
/// The window and command of a kind-6 row.
|
||||||
|
window_id : UInt64
|
||||||
|
window_cmd : WindowCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
///| A plain menu row (no setting value, no tick).
|
///| A plain menu row (no setting value, no tick).
|
||||||
fn menu_row(label : String, kind : Int, arg? : String = "") -> MenuRow {
|
fn menu_row(label : String, kind : Int, arg? : String = "") -> MenuRow {
|
||||||
{ label, kind, arg, value: "", ticked: false }
|
{ label, kind, arg, value: "", ticked: false, window_id: 0, window_cmd: Close }
|
||||||
|
}
|
||||||
|
|
||||||
|
///| A window-menu row: `cmd` for window `id`.
|
||||||
|
fn window_row(label : String, id : UInt64, cmd : WindowCommand) -> MenuRow {
|
||||||
|
{ label, kind: 6, arg: "", value: "", ticked: false, window_id: id, window_cmd: cmd }
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The desktop shell: wallpaper + a bottom panel made entirely of wasm modules
|
///| The desktop shell: wallpaper + a bottom panel made entirely of wasm modules
|
||||||
|
|||||||
@@ -718,7 +718,8 @@ let menu_w : Int = 250
|
|||||||
///| Most "Replace with" rows listed.
|
///| Most "Replace with" rows listed.
|
||||||
let max_replace_rows : Int = 8
|
let max_replace_rows : Int = 8
|
||||||
|
|
||||||
///| Right-click: on a module its menu (Module settings, System settings, replace, remove); on
|
///| Right-click: on a window's pill in the task manager that window's menu (Minimize or Restore,
|
||||||
|
/// Maximize, Quit); on a module its menu (Module settings, System settings, replace, remove); on
|
||||||
/// empty panel space System settings (whose Panel tab adds modules). True when consumed.
|
/// empty panel space System settings (whose Panel tab adds modules). True when consumed.
|
||||||
pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool {
|
pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||||
self.ensure_booted()
|
self.ensure_booted()
|
||||||
@@ -729,6 +730,10 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool
|
|||||||
self.menu_open = false
|
self.menu_open = false
|
||||||
self.dismiss_popups("")
|
self.dismiss_popups("")
|
||||||
match self.widget_at(x, y) {
|
match self.widget_at(x, y) {
|
||||||
|
Some(w) if self.task_at(w, x, y) is Some(win) => {
|
||||||
|
self.open_window_menu(win, x)
|
||||||
|
true
|
||||||
|
}
|
||||||
Some(w) => {
|
Some(w) => {
|
||||||
self.name_catalog()
|
self.name_catalog()
|
||||||
let rows : Array[MenuRow] = []
|
let rows : Array[MenuRow] = []
|
||||||
@@ -766,6 +771,43 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| The task manager module's id: its pills are hit-tested here (lib/panel/tasks.mbt) so a
|
||||||
|
/// right-click on one opens that window's menu.
|
||||||
|
let tasks_module_id : String = "org.chandra.tasks"
|
||||||
|
|
||||||
|
///| The window whose task-bar pill is under (x, y) when `w` is the task manager. The pills are
|
||||||
|
/// the windows in opening order (by id, as the module sorts them).
|
||||||
|
fn DesktopShell::task_at(self : DesktopShell, w : Widget, x : Int, y : Int) -> WinInfo? {
|
||||||
|
if w.pl.id != tasks_module_id || !inside(w.rect, x, y) {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
// The module sorts by the 32-bit id it is handed through `windows.list-windows`.
|
||||||
|
let key = (win : WinInfo) => win.id.to_int().reinterpret_as_uint()
|
||||||
|
let wins = self.windows.copy()
|
||||||
|
wins.sort_by((a, b) => key(a).compare(key(b)))
|
||||||
|
let i = @panel.task_pill_at(x - w.rect.x, wins.length(), w.rect.w)
|
||||||
|
if i >= 0 {
|
||||||
|
Some(wins[i])
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| The window menu of a task-bar pill, titled with the window's title.
|
||||||
|
fn DesktopShell::open_window_menu(self : DesktopShell, win : WinInfo, x : Int) -> Unit {
|
||||||
|
let rows = [
|
||||||
|
if win.minimized {
|
||||||
|
window_row("Restore", win.id, Restore)
|
||||||
|
} else {
|
||||||
|
window_row("Minimize", win.id, Minimize)
|
||||||
|
},
|
||||||
|
window_row(if win.maximized { "Restore size" } else { "Maximize" }, win.id, ToggleMaximize),
|
||||||
|
window_row("Quit", win.id, Close),
|
||||||
|
]
|
||||||
|
let title = if win.title.length() > 0 { win.title } else { "Window" }
|
||||||
|
self.open_menu(title, rows, "", x)
|
||||||
|
}
|
||||||
|
|
||||||
///| The module's own settings as menu rows: an on/off setting is one row, ticked when on; a
|
///| The module's own settings as menu rows: an on/off setting is one row, ticked when on; a
|
||||||
/// setting with choices is a heading and one row per choice, the current one ticked.
|
/// setting with choices is a heading and one row per choice, the current one ticked.
|
||||||
fn config_rows(items : Array[@wasm.ConfigItem]) -> Array[MenuRow] {
|
fn config_rows(items : Array[@wasm.ConfigItem]) -> Array[MenuRow] {
|
||||||
@@ -773,11 +815,11 @@ fn config_rows(items : Array[@wasm.ConfigItem]) -> Array[MenuRow] {
|
|||||||
for it in items {
|
for it in items {
|
||||||
if it.choices.length() == 0 {
|
if it.choices.length() == 0 {
|
||||||
let on = it.value == "on"
|
let on = it.value == "on"
|
||||||
rows.push({ label: it.label, kind: 4, arg: it.key, value: if on { "off" } else { "on" }, ticked: on })
|
rows.push({ ..menu_row(it.label, 4, arg=it.key), value: if on { "off" } else { "on" }, ticked: on })
|
||||||
} else {
|
} else {
|
||||||
rows.push(menu_row(it.label, 5))
|
rows.push(menu_row(it.label, 5))
|
||||||
for c in it.choices {
|
for c in it.choices {
|
||||||
rows.push({ label: c, kind: 4, arg: it.key, value: c, ticked: c == it.value })
|
rows.push({ ..menu_row(c, 4, arg=it.key), value: c, ticked: c == it.value })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -874,6 +916,7 @@ fn DesktopShell::menu_pointer_down(self : DesktopShell, x : Int, y : Int) -> Boo
|
|||||||
2 => ignore(self.open_settings(if row.arg == "panel" { Panel } else { Session }))
|
2 => ignore(self.open_settings(if row.arg == "panel" { Panel } else { Session }))
|
||||||
3 => self.open_module_settings(slot)
|
3 => self.open_module_settings(slot)
|
||||||
4 => self.choose_module_setting(slot, row.arg, row.value)
|
4 => self.choose_module_setting(slot, row.arg, row.value)
|
||||||
|
6 => self.actions.push(Window(row.window_id, row.window_cmd))
|
||||||
// A heading: the menu stays open.
|
// A heading: the menu stays open.
|
||||||
_ => self.menu_open = true
|
_ => self.menu_open = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,16 @@ pub fn layout(Int32, Int32, Int32, Int32, Int32, Array[SlotIn]) -> Result[PanelL
|
|||||||
|
|
||||||
pub fn popup_position(Int32, Int32, Int32, Int32, Int32, Int32) -> (Int32, Int32)
|
pub fn popup_position(Int32, Int32, Int32, Int32, Int32, Int32) -> (Int32, Int32)
|
||||||
|
|
||||||
|
pub fn task_pill_at(Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
pub let task_pill_gap : Int32
|
||||||
|
|
||||||
|
pub let task_pill_max : Int32
|
||||||
|
|
||||||
|
pub let task_pill_min : Int32
|
||||||
|
|
||||||
|
pub fn task_pill_w(Int32, Int32) -> Int32
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
|
|
||||||
// Types and methods
|
// Types and methods
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
///| Where the task manager (components/tasks) puts its window pills. It lives here, not in the
|
||||||
|
/// module, because the shell needs the same geometry to know which window a right-click hit: the
|
||||||
|
/// shell draws that window's menu (Quit, Minimize, Maximize) itself, since modules only get left
|
||||||
|
/// clicks.
|
||||||
|
|
||||||
|
///| Widest a pill gets, the gap between pills, and the narrowest before titles stop being readable.
|
||||||
|
pub let task_pill_max : Int = 140
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let task_pill_gap : Int = 6
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let task_pill_min : Int = 56
|
||||||
|
|
||||||
|
///| Pill width for `n` windows in a task bar `w` wide.
|
||||||
|
pub fn task_pill_w(n : Int, w : Int) -> Int {
|
||||||
|
if n <= 0 {
|
||||||
|
return task_pill_max
|
||||||
|
}
|
||||||
|
let fit = (w - task_pill_gap * (n - 1)) / n
|
||||||
|
if fit > task_pill_max {
|
||||||
|
task_pill_max
|
||||||
|
} else if fit < task_pill_min {
|
||||||
|
task_pill_min
|
||||||
|
} else {
|
||||||
|
fit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| The pill (an index into the windows in opening order) under a task-bar-local `x`, or -1, for
|
||||||
|
/// `n` windows in a bar `w` wide. Pills that would start past the bar's end aren't drawn.
|
||||||
|
pub fn task_pill_at(x : Int, n : Int, w : Int) -> Int {
|
||||||
|
let pw = task_pill_w(n, w)
|
||||||
|
if x < 0 || x >= w {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
let i = x / (pw + task_pill_gap)
|
||||||
|
if i < n && x - i * (pw + task_pill_gap) < pw {
|
||||||
|
i
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
///|
|
||||||
|
test "task pills: width shrinks to fit, clamped" {
|
||||||
|
inspect(@panel.task_pill_w(0, 300), content="140")
|
||||||
|
inspect(@panel.task_pill_w(2, 300), content="140")
|
||||||
|
inspect(@panel.task_pill_w(3, 300), content="96")
|
||||||
|
inspect(@panel.task_pill_w(20, 300), content="56")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "task pills: hit test skips the gaps and the space after the last pill" {
|
||||||
|
// 2 windows in 300px: pills at 0..139 and 146..285.
|
||||||
|
inspect(@panel.task_pill_at(0, 2, 300), content="0")
|
||||||
|
inspect(@panel.task_pill_at(139, 2, 300), content="0")
|
||||||
|
inspect(@panel.task_pill_at(142, 2, 300), content="-1")
|
||||||
|
inspect(@panel.task_pill_at(146, 2, 300), content="1")
|
||||||
|
inspect(@panel.task_pill_at(290, 2, 300), content="-1")
|
||||||
|
inspect(@panel.task_pill_at(-1, 2, 300), content="-1")
|
||||||
|
inspect(@panel.task_pill_at(10, 0, 300), content="-1")
|
||||||
|
}
|
||||||
Reference in new issue
Block a user