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
@@ -132,8 +132,21 @@ pub(all) struct WinInfo {
|
||||
title : String
|
||||
focused : 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.
|
||||
pub(all) enum ShellAction {
|
||||
SetLayout(Int)
|
||||
@@ -147,6 +160,8 @@ pub(all) enum ShellAction {
|
||||
Screenshot(Int)
|
||||
/// The settings module's Power tab asked to suspend (0), power off (1) or restart (2) now.
|
||||
SystemPower(Int)
|
||||
/// A row of a task-bar pill's right-click menu: do this to that window.
|
||||
Window(UInt64, WindowCommand)
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///| 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,
|
||||
/// 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 {
|
||||
label : String
|
||||
kind : Int
|
||||
@@ -185,11 +201,19 @@ pub(all) struct MenuRow {
|
||||
value : String
|
||||
/// Draw a tick: the value a kind-4 row sets is the current one.
|
||||
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).
|
||||
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
|
||||
|
||||
@@ -718,7 +718,8 @@ let menu_w : Int = 250
|
||||
///| Most "Replace with" rows listed.
|
||||
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.
|
||||
pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
self.ensure_booted()
|
||||
@@ -729,6 +730,10 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool
|
||||
self.menu_open = false
|
||||
self.dismiss_popups("")
|
||||
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) => {
|
||||
self.name_catalog()
|
||||
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
|
||||
/// setting with choices is a heading and one row per choice, the current one ticked.
|
||||
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 {
|
||||
if it.choices.length() == 0 {
|
||||
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 {
|
||||
rows.push(menu_row(it.label, 5))
|
||||
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 }))
|
||||
3 => self.open_module_settings(slot)
|
||||
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.
|
||||
_ => self.menu_open = true
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user