Dock and task manager are one module: titled window pills, pins, Super+1..9
CI / test (push) Failing after 30s
CI / test (push) Failing after 30s
The panel had a task list and, beside it, a dock showing the same running
apps again. They are now one module, the dock, in the task list's place:
- Pinned apps, then running ones; an app with windows is a pill with its
window's title (or name and window count) while there is room, an icon
when the panel is crowded ("Show window titles" in Dock settings).
- Its right-click menu has the task list's window commands (Minimize /
Restore, Maximize) for a single window, or the app's windows by title.
- It stretches like the task list did; new panels get it instead of
tasks. A saved panel's "tasks" becomes the dock (one dock, where the
task list was); pins are the dock's own setting, so they carry over.
- An empty dock shows a "+ Add apps" tile that opens the Applications
menu, where right-clicking an app offers Open and Pin to dock (adding a
dock to the panel if there is none).
- Super+1 .. Super+9 open the dock's first nine apps like a click
(shortcut "dock-apps", rebindable in Settings > Shortcuts).
- "New window" / "Open" only for apps the catalog can start.
The tasks component, lib/panel's pill geometry and the taskbar-widget
world are gone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiPCFHRxaJQvwex6ry
This commit is contained in:
28 files changed
+795
-1125
No files matched your search
@@ -3,7 +3,7 @@
|
|||||||
A modular, KDE-Plasma-inspired Wayland desktop where **every part is a WebAssembly component**
|
A modular, KDE-Plasma-inspired Wayland desktop where **every part is a WebAssembly component**
|
||||||
(Component Model, WIT interfaces) written in [MoonBit](https://www.moonbitlang.com), on top of a
|
(Component Model, WIT interfaces) written in [MoonBit](https://www.moonbitlang.com), on top of a
|
||||||
deliberately small host. The compositor itself (Wayland server, window manager, scene, shell) is a
|
deliberately small host. The compositor itself (Wayland server, window manager, scene, shell) is a
|
||||||
component, and so is every panel module: the clock, the task manager, the launcher, the settings.
|
component, and so is every panel module: the clock, the dock (task manager), the launcher, the settings.
|
||||||
|
|
||||||
Chandra was called moon-plasma until 2026-11-25. The code, the WIT packages (`chandra:*`), the
|
Chandra was called moon-plasma until 2026-11-25. The code, the WIT packages (`chandra:*`), the
|
||||||
session (`chandra-session`) and the paths (`~/.config/chandra`) all use the new name; an old
|
session (`chandra-session`) and the paths (`~/.config/chandra`) all use the new name; an old
|
||||||
@@ -120,6 +120,7 @@ new keys)
|
|||||||
| Super (tap) | Open the application launcher |
|
| Super (tap) | Open the application launcher |
|
||||||
| Alt+Tab | Window switcher, with a live preview of each window |
|
| Alt+Tab | Window switcher, with a live preview of each window |
|
||||||
| Super+D | Show the desktop (minimize every window); again to bring them back |
|
| Super+D | Show the desktop (minimize every window); again to bring them back |
|
||||||
|
| Super+1 .. Super+9 | Open the dock's first nine apps (or bring their windows forward) |
|
||||||
| Super+Shift+S | Screenshot: select a region or click a window (F full screen, W active window) |
|
| Super+Shift+S | Screenshot: select a region or click a window (F full screen, W active window) |
|
||||||
| Print / Super+Print / Super+Ctrl+Print | Screenshot of the full screen / active window / window under the pointer |
|
| Print / Super+Print / Super+Ctrl+Print | Screenshot of the full screen / active window / window under the pointer |
|
||||||
| Super+Shift+R | Record a region or window (Enter starts) |
|
| Super+Shift+R | Record a region or window (Enter starts) |
|
||||||
@@ -135,13 +136,17 @@ a recording shortcut again to stop.
|
|||||||
(reload every panel module from disk, keeping the panel and module settings; windows and apps
|
(reload every panel module from disk, keeping the panel and module settings; windows and apps
|
||||||
keep running), **Log out**, **Suspend**, **Restart** and **Power off**. Log out, Restart and
|
keep running), **Log out**, **Suspend**, **Restart** and **Power off**. Log out, Restart and
|
||||||
Power off ask for a second click.
|
Power off ask for a second click.
|
||||||
* **Dock**: pinned apps, then the other running apps after a divider, with their theme icons and a
|
* **Dock**, the panel's task manager: pinned apps, then the other running apps after a divider,
|
||||||
dot per open window (lit when the app has focus). Click to start an app or bring its newest
|
with their theme icons and a dot per open window (lit when the app has focus). An app with
|
||||||
window forward; click a focused app again to step through its windows. Hover for the app's
|
windows is a pill with its window's title (or its name and window count) while there is room,
|
||||||
name; right-click an icon for Open / New window, Pin or Unpin, Move left / right, Quit, and
|
just its icon when the panel gets crowded. Click to start an app or bring its newest window
|
||||||
Dock settings (icon size, magnification, whether running apps show). Pins live in state.edn.
|
forward (restoring it if minimized); click a focused app again to step through its windows.
|
||||||
* **Task manager**: a pill per window with the app's real icon from its `.desktop` file;
|
**Super+1** .. **Super+9** do the same for the first nine. Right-click an app for Open / New
|
||||||
right-click a pill for Minimize, Maximize and Quit.
|
window, Pin or Unpin, Move left / right, its window's Minimize and Maximize (or a list of its
|
||||||
|
windows), Quit, and Dock settings (icon size, magnification, running apps, window titles).
|
||||||
|
Pin apps from there or by right-clicking them in the Launcher's menu; an empty dock shows a "+"
|
||||||
|
that opens it. Pins live in state.edn. (It replaced the separate Task Manager: a saved panel
|
||||||
|
with the old `tasks` module gets the dock in its place.)
|
||||||
* **Network**: Wi-Fi and wired status, connect to Wi-Fi networks (with passwords), Wi-Fi and
|
* **Network**: Wi-Fi and wired status, connect to Wi-Fi networks (with passwords), Wi-Fi and
|
||||||
airplane switches, through NetworkManager over D-Bus (read-only sysfs status without it).
|
airplane switches, through NetworkManager over D-Bus (read-only sysfs status without it).
|
||||||
* **Battery**: charge, charging state, time left, low-battery warning (only added on machines
|
* **Battery**: charge, charging state, time left, low-battery warning (only added on machines
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
///| Implementation of `chandra:desktop/plasmoid` for the dock: pinned apps, then running ones,
|
///| Implementation of `chandra:desktop/plasmoid` for the dock, the panel's task manager: pinned
|
||||||
/// with their theme icons and a dot per open window. A click starts the app or brings its windows
|
/// apps, then running ones, with their theme icons, a dot per open window and (room allowing)
|
||||||
|
/// their window titles. A click starts the app or brings its windows
|
||||||
/// forward. Layout, hit-testing and drawing live in lib/dock (the shell uses the same code for the
|
/// forward. Layout, hit-testing and drawing live in lib/dock (the shell uses the same code for the
|
||||||
/// hover label and the per-app right-click menu); this adapts host capabilities.
|
/// hover label and the per-app right-click menu); this adapts host capabilities.
|
||||||
|
|
||||||
@@ -12,9 +13,22 @@ let width : Ref[Int] = Ref::new(200)
|
|||||||
///|
|
///|
|
||||||
let height : Ref[Int] = Ref::new(34)
|
let height : Ref[Int] = Ref::new(34)
|
||||||
|
|
||||||
///| The windows as the dock sees them.
|
///| The windows as the dock sees them: `all` has the app ids, `list-windows` (by the low 32 bits
|
||||||
|
/// of the id) which are minimized.
|
||||||
fn dock_windows() -> Array[@logic.DockWindow] {
|
fn dock_windows() -> Array[@logic.DockWindow] {
|
||||||
@windows.all().map(d => { id: d.id, app_id: d.app_id, focused: d.focused })
|
let mini : Map[UInt, Bool] = Map([])
|
||||||
|
for w in @windows.list_windows() {
|
||||||
|
if w.minimized != 0U {
|
||||||
|
mini.set(w.id, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@windows.all().map(d => {
|
||||||
|
id: d.id,
|
||||||
|
app_id: d.app_id,
|
||||||
|
focused: d.focused,
|
||||||
|
title: d.title,
|
||||||
|
minimized: mini.contains((d.id & 0xFFFFFFFFUL).to_uint()),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The window with keyboard focus, if any.
|
///| The window with keyboard focus, if any.
|
||||||
@@ -40,7 +54,8 @@ pub fn info() -> PlasmoidInfo {
|
|||||||
// The shell works out the real width from the items as they change.
|
// The shell works out the real width from the items as they change.
|
||||||
preferred: { w: @logic.preferred_width(current_items(), @logic.config, 34).reinterpret_as_uint(), h: 34U },
|
preferred: { w: @logic.preferred_width(current_items(), @logic.config, 34).reinterpret_as_uint(), h: 34U },
|
||||||
min_width: 60,
|
min_width: 60,
|
||||||
stretch: false,
|
// The panel's task list: it takes the free room, and what follows packs right.
|
||||||
|
stretch: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ let categories : Array[String] = ["Apps and windows", "System", "Clocks", "Other
|
|||||||
///| Which group a module (by id, its file stem) belongs to; modules we don't know go in "Other".
|
///| Which group a module (by id, its file stem) belongs to; modules we don't know go in "Other".
|
||||||
fn category_of(id : String) -> String {
|
fn category_of(id : String) -> String {
|
||||||
match id {
|
match id {
|
||||||
"launcher" | "dock" | "tasks" | "layout" => "Apps and windows"
|
"launcher" | "dock" | "layout" => "Apps and windows"
|
||||||
"session-settings" | "network" | "battery" | "screenshot" => "System"
|
"session-settings" | "network" | "battery" | "screenshot" => "System"
|
||||||
"clock-digital" | "clock-binary" | "moon-disc" => "Clocks"
|
"clock-digital" | "clock-binary" | "moon-disc" => "Clocks"
|
||||||
_ => "Other"
|
_ => "Other"
|
||||||
@@ -159,8 +159,7 @@ fn category_of(id : String) -> String {
|
|||||||
fn description_of(id : String) -> String {
|
fn description_of(id : String) -> String {
|
||||||
match id {
|
match id {
|
||||||
"launcher" => "Start apps; reload, log out or power off"
|
"launcher" => "Start apps; reload, log out or power off"
|
||||||
"dock" => "Pinned apps, one click away"
|
"dock" => "Pinned apps and your open windows"
|
||||||
"tasks" => "Your open windows"
|
|
||||||
"layout" => "Switch tiling and floating"
|
"layout" => "Switch tiling and floating"
|
||||||
"session-settings" => "This settings window"
|
"session-settings" => "This settings window"
|
||||||
"network" => "Wi-Fi and wired network"
|
"network" => "Wi-Fi and wired network"
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
|
||||||
|
|
||||||
///|
|
|
||||||
pub fn mbt_ffi_cabi_realloc(
|
|
||||||
src_offset : Int,
|
|
||||||
src_size : Int,
|
|
||||||
_dst_alignment : Int,
|
|
||||||
dst_size : Int,
|
|
||||||
) -> Int {
|
|
||||||
// malloc
|
|
||||||
if src_offset == 0 && src_size == 0 {
|
|
||||||
return mbt_ffi_malloc(dst_size)
|
|
||||||
}
|
|
||||||
// free
|
|
||||||
if dst_size == 0 {
|
|
||||||
mbt_ffi_free(src_offset)
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
// realloc
|
|
||||||
let dst = mbt_ffi_malloc(dst_size)
|
|
||||||
mbt_ffi_copy(dst, src_offset, if src_size < dst_size { src_size } else { dst_size })
|
|
||||||
mbt_ffi_free(src_offset)
|
|
||||||
dst
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_copy(dest : Int, src : Int, len : Int) =
|
|
||||||
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
|
||||||
#|(func (param i32) (result i32) (local i32)
|
|
||||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
|
||||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
|
||||||
#| local.get 1)
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
|
||||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
|
|
||||||
@plasmoid.wasmExportInfoPostReturn(p0)
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
|
||||||
@plasmoid.wasmExportRenderPostReturn(p0)
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
|
||||||
@plasmoid.wasmExportPopupPostReturn(p0)
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
|
||||||
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportInfo() -> Int {
|
|
||||||
@plasmoid.wasmExportInfo()
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
|
||||||
@plasmoid.wasmExportRender(p0, p1)
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportPopup() -> Int {
|
|
||||||
@plasmoid.wasmExportPopup()
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
The widget (plasmoid) contract.
|
|
||||||
@@ -1,431 +0,0 @@
|
|||||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportInfo() -> Int {
|
|
||||||
|
|
||||||
let (result) : (PlasmoidInfo) = info();
|
|
||||||
let return_area = mbt_ffi_malloc(32)
|
|
||||||
|
|
||||||
let ptr = mbt_ffi_str2ptr((result).id)
|
|
||||||
mbt_ffi_store32((return_area) + 4, (result).id.length())
|
|
||||||
mbt_ffi_store32((return_area) + 0, ptr)
|
|
||||||
|
|
||||||
let ptr0 = mbt_ffi_str2ptr((result).name)
|
|
||||||
mbt_ffi_store32((return_area) + 12, (result).name.length())
|
|
||||||
mbt_ffi_store32((return_area) + 8, ptr0)
|
|
||||||
mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 }))
|
|
||||||
let ret = return_area
|
|
||||||
return ret
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
|
|
||||||
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
|
||||||
mbt_ffi_free(mbt_ffi_load32((p0) + 8))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
|
||||||
|
|
||||||
let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()});
|
|
||||||
let return_area = mbt_ffi_malloc(8)
|
|
||||||
|
|
||||||
let address = mbt_ffi_malloc((result).length() * 32);
|
|
||||||
for index = 0; index < (result).length(); index = index + 1 {
|
|
||||||
let iter_elem : @types.DrawOp = (result)[(index)]
|
|
||||||
let iter_base = address + (index * 32);
|
|
||||||
|
|
||||||
match iter_elem {
|
|
||||||
FillRect(payload) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (0))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
StrokeRect(payload0) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (1))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Line(payload1) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (2))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload1).start).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload1).start).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, ((payload1).end).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 16, ((payload1).end).y)
|
|
||||||
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Circle(payload2) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (3))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload2).center).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload2).center).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 }))
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Text(payload3) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (4))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y)
|
|
||||||
|
|
||||||
let ptr = mbt_ffi_str2ptr((payload3).text)
|
|
||||||
mbt_ffi_store32((iter_base) + 16, (payload3).text.length())
|
|
||||||
mbt_ffi_store32((iter_base) + 12, ptr)
|
|
||||||
mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal())
|
|
||||||
mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 }))
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
PushClip(payload4) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (5))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, (payload4).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, (payload4).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
PopClip => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (6))
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Image(payload6) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (7))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload6).rect).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload6).rect).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, (((payload6).rect).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 16, (((payload6).rect).h).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 20, ((payload6).image).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
mbt_ffi_store32((return_area) + 4, (result).length())
|
|
||||||
mbt_ffi_store32((return_area) + 0, address)
|
|
||||||
let ret = return_area
|
|
||||||
return ret
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
|
||||||
|
|
||||||
for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 {
|
|
||||||
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32)
|
|
||||||
|
|
||||||
match (mbt_ffi_load8_u((iter_base) + 0)) {
|
|
||||||
0 => ()
|
|
||||||
1 => ()
|
|
||||||
2 => ()
|
|
||||||
3 => ()
|
|
||||||
4 => {
|
|
||||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
|
|
||||||
|
|
||||||
}
|
|
||||||
5 => ()
|
|
||||||
6 => ()
|
|
||||||
7 => ()
|
|
||||||
_ => panic()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportPopup() -> Int {
|
|
||||||
|
|
||||||
let (result) : (PopupSurface?) = popup();
|
|
||||||
let return_area = mbt_ffi_malloc(20)
|
|
||||||
|
|
||||||
match (result) {
|
|
||||||
None => {
|
|
||||||
mbt_ffi_store8((return_area) + 0, (0))
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Some(payload0) => {
|
|
||||||
mbt_ffi_store8((return_area) + 0, (1))
|
|
||||||
mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int())
|
|
||||||
|
|
||||||
let address = mbt_ffi_malloc(((payload0).ops).length() * 32);
|
|
||||||
for index = 0; index < ((payload0).ops).length(); index = index + 1 {
|
|
||||||
let iter_elem : @types.DrawOp = ((payload0).ops)[(index)]
|
|
||||||
let iter_base = address + (index * 32);
|
|
||||||
|
|
||||||
match iter_elem {
|
|
||||||
FillRect(payload1) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (0))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 24, ((payload1).radius).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
StrokeRect(payload2) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (1))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload2).rect).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload2).rect).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, (((payload2).rect).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 16, (((payload2).rect).h).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 20, (((payload2).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 21, (((payload2).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 22, (((payload2).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 23, (((payload2).color).a).to_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 24, ((payload2).width).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 28, ((payload2).radius).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Line(payload3) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (2))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload3).start).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload3).start).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, ((payload3).end).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 16, ((payload3).end).y)
|
|
||||||
mbt_ffi_store8((iter_base) + 20, (((payload3).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 21, (((payload3).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 22, (((payload3).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 23, (((payload3).color).a).to_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 24, ((payload3).width).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Circle(payload4) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (3))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload4).center).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload4).center).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, ((payload4).radius).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 16, (((payload4).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 17, (((payload4).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 18, (((payload4).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 19, (((payload4).color).a).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 20, (if (payload4).filled { 1 } else { 0 }))
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Text(payload5) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (4))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload5).origin).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload5).origin).y)
|
|
||||||
|
|
||||||
let ptr = mbt_ffi_str2ptr((payload5).text)
|
|
||||||
mbt_ffi_store32((iter_base) + 16, (payload5).text.length())
|
|
||||||
mbt_ffi_store32((iter_base) + 12, ptr)
|
|
||||||
mbt_ffi_store32((iter_base) + 20, (((payload5).style).size).reinterpret_as_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 24, ((((payload5).style).color).r).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 25, ((((payload5).style).color).g).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 26, ((((payload5).style).color).b).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 27, ((((payload5).style).color).a).to_int())
|
|
||||||
mbt_ffi_store8((iter_base) + 28, ((payload5).style).align.ordinal())
|
|
||||||
mbt_ffi_store8((iter_base) + 29, (if ((payload5).style).bold { 1 } else { 0 }))
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
PushClip(payload6) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (5))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, (payload6).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, (payload6).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, ((payload6).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 16, ((payload6).h).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
PopClip => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (6))
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
Image(payload8) => {
|
|
||||||
mbt_ffi_store8((iter_base) + 0, (7))
|
|
||||||
mbt_ffi_store32((iter_base) + 4, ((payload8).rect).x)
|
|
||||||
mbt_ffi_store32((iter_base) + 8, ((payload8).rect).y)
|
|
||||||
mbt_ffi_store32((iter_base) + 12, (((payload8).rect).w).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 16, (((payload8).rect).h).reinterpret_as_int())
|
|
||||||
mbt_ffi_store32((iter_base) + 20, ((payload8).image).reinterpret_as_int())
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
mbt_ffi_store32((return_area) + 16, ((payload0).ops).length())
|
|
||||||
mbt_ffi_store32((return_area) + 12, address)
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let ret = return_area
|
|
||||||
return ret
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
|
||||||
|
|
||||||
match (mbt_ffi_load8_u((p0) + 0)) {
|
|
||||||
0 => ()
|
|
||||||
1 => {
|
|
||||||
|
|
||||||
for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 {
|
|
||||||
let iter_base = (mbt_ffi_load32((p0) + 12)) + (index * 32)
|
|
||||||
|
|
||||||
match (mbt_ffi_load8_u((iter_base) + 0)) {
|
|
||||||
0 => ()
|
|
||||||
1 => ()
|
|
||||||
2 => ()
|
|
||||||
3 => ()
|
|
||||||
4 => {
|
|
||||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
|
|
||||||
|
|
||||||
}
|
|
||||||
5 => ()
|
|
||||||
6 => ()
|
|
||||||
7 => ()
|
|
||||||
_ => panic()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
mbt_ffi_free(mbt_ffi_load32((p0) + 12))
|
|
||||||
|
|
||||||
}
|
|
||||||
_ => panic()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
#doc(hidden)
|
|
||||||
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
|
||||||
|
|
||||||
let lifted = match (p1) {
|
|
||||||
0 => {
|
|
||||||
|
|
||||||
@types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3})
|
|
||||||
}
|
|
||||||
1 => {
|
|
||||||
|
|
||||||
@types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3})
|
|
||||||
}
|
|
||||||
2 => {
|
|
||||||
|
|
||||||
@types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3})
|
|
||||||
}
|
|
||||||
3 => {
|
|
||||||
|
|
||||||
@types.InputEvent::PointerLeave
|
|
||||||
}
|
|
||||||
4 => {
|
|
||||||
|
|
||||||
@types.InputEvent::FocusLost
|
|
||||||
}
|
|
||||||
5 => {
|
|
||||||
|
|
||||||
let result = mbt_ffi_ptr2str(p2, p3)
|
|
||||||
|
|
||||||
@types.InputEvent::KeyDown(result)
|
|
||||||
}
|
|
||||||
_ => panic()
|
|
||||||
}
|
|
||||||
|
|
||||||
let (result0) : (Bool) = on_event(Surface::from(p0), lifted);
|
|
||||||
let ret = (if result0 { 1 } else { 0 })
|
|
||||||
return ret
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
|
||||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
|
||||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
|
||||||
#|(func (param i32) (param i32) (result i32)
|
|
||||||
#| local.get 0
|
|
||||||
#| local.get 1 call $moonbit.init_array16
|
|
||||||
#| local.get 0)
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
|
||||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
|
||||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
|
||||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
|
||||||
#|(func (param i32) (result i32) (local i32)
|
|
||||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
|
||||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
|
||||||
#| local.get 1)
|
|
||||||
|
|
||||||
///|
|
|
||||||
#owned(str)
|
|
||||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
|
||||||
#|(func (param i32) (result i32) local.get 0)
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import {
|
|
||||||
"chandra/desktop/interface/chandra/desktop/types" @types,
|
|
||||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
|
||||||
"chandra/desktop/interface/chandra/desktop/windows" @windows,
|
|
||||||
"chandra/desktop/interface/chandra/desktop/icons" @icons,
|
|
||||||
"chandra/desktop/lib/ui" @ui,
|
|
||||||
"chandra/desktop/lib/dock" @dock,
|
|
||||||
"chandra/desktop/lib/panel" @panel,
|
|
||||||
}
|
|
||||||
|
|
||||||
warnings = "-44"
|
|
||||||
@@ -1,184 +0,0 @@
|
|||||||
///| Implementation of `chandra:desktop/plasmoid` for the task manager: one pill per open
|
|
||||||
/// window, in the order the windows were opened (so the bar doesn't reshuffle when focus changes).
|
|
||||||
/// 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.
|
|
||||||
/// 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; 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.
|
|
||||||
|
|
||||||
///| Pill geometry is shared with the shell (lib/panel/tasks.mbt): it hit-tests right-clicks
|
|
||||||
/// on pills to show the window's menu (Quit, Minimize, Maximize).
|
|
||||||
let gap : Int = @panel.task_pill_gap
|
|
||||||
|
|
||||||
///| Pills narrower than this drop the title and show only the centred icon.
|
|
||||||
let icon_only_w : Int = 72
|
|
||||||
|
|
||||||
///| Edge of the icon tile in a bar `h` pixels tall.
|
|
||||||
fn icon_size(h : Int) -> Int {
|
|
||||||
let s = h - 12
|
|
||||||
if s < 14 { 14 } else if s > 22 { 22 } else { s }
|
|
||||||
}
|
|
||||||
|
|
||||||
///| App id of every window, by window id, from the richer `windows.all` view (the task-bar
|
|
||||||
/// rows carry only titles).
|
|
||||||
fn app_ids() -> Map[UInt, String] {
|
|
||||||
let m : Map[UInt, String] = Map([])
|
|
||||||
for d in @windows.all() {
|
|
||||||
m.set((d.id & 0xFFFFFFFFUL).to_uint(), d.app_id)
|
|
||||||
}
|
|
||||||
m
|
|
||||||
}
|
|
||||||
|
|
||||||
///| The app's icon `s` pixels square centred on (cx, cy): its theme icon when the host has one,
|
|
||||||
/// else the letter tile (keyed by the app id, or the title for windows without one).
|
|
||||||
fn pill_icon(cx : Int, cy : Int, s : Int, app : String, title : String) -> Array[@types.DrawOp] {
|
|
||||||
let handle = if app.length() > 0 { @icons.app_icon(app) } else { 0U }
|
|
||||||
if handle != 0U {
|
|
||||||
return [Image({ rect: @ui.rect(cx - s / 2, cy - s / 2, s, s), image: handle })]
|
|
||||||
}
|
|
||||||
let key = if app.length() > 0 { app } else { title }
|
|
||||||
@dock.app_icon(cx, cy, s, key, @dock.app_glyph(app, title))
|
|
||||||
}
|
|
||||||
|
|
||||||
///| The width the module was last drawn at, and the pill the pointer is over (-1: none).
|
|
||||||
let last_w : Ref[Int] = { val: 300 }
|
|
||||||
|
|
||||||
///|
|
|
||||||
let hover : Ref[Int] = { val: -1 }
|
|
||||||
|
|
||||||
///| Windows in opening order (ids grow as windows open), whatever the host's stacking order says.
|
|
||||||
fn windows_sorted() -> Array[@windows.WindowInfo] {
|
|
||||||
let ws = @windows.list_windows()
|
|
||||||
let n = ws.length()
|
|
||||||
for i = 1; i < n; i = i + 1 {
|
|
||||||
let cur = ws[i]
|
|
||||||
let mut j = i - 1
|
|
||||||
while j >= 0 && ws[j].id > cur.id {
|
|
||||||
ws[j + 1] = ws[j]
|
|
||||||
j = j - 1
|
|
||||||
}
|
|
||||||
ws[j + 1] = cur
|
|
||||||
}
|
|
||||||
ws
|
|
||||||
}
|
|
||||||
|
|
||||||
///| Pill width for `n` windows in a bar `w` wide.
|
|
||||||
fn pill_w(n : Int, w : Int) -> Int {
|
|
||||||
@panel.task_pill_w(n, w)
|
|
||||||
}
|
|
||||||
|
|
||||||
///| The pill under a widget-local x, or -1.
|
|
||||||
fn pill_at(x : Int, n : Int) -> Int {
|
|
||||||
@panel.task_pill_at(x, n, last_w.val)
|
|
||||||
}
|
|
||||||
|
|
||||||
///| `s` shortened with an ellipsis until it fits `max_w` pixels.
|
|
||||||
fn fit_text(s : String, size : Int, max_w : Int) -> String {
|
|
||||||
if (s.length() * ((size * 11 + 19) / 20)) <= max_w {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
let mut n = s.length()
|
|
||||||
while n > 1 && ((n + 1) * ((size * 11 + 19) / 20)) > max_w {
|
|
||||||
n = n - 1
|
|
||||||
}
|
|
||||||
s[:n].to_string() + "…"
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
pub fn info() -> PlasmoidInfo {
|
|
||||||
{
|
|
||||||
id: "org.chandra.tasks",
|
|
||||||
name: "Task Manager",
|
|
||||||
preferred: { w: 300, h: 34 },
|
|
||||||
min_width: 120,
|
|
||||||
stretch: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
|
|
||||||
let t = @theme.get_tokens()
|
|
||||||
let w = size.w.reinterpret_as_int()
|
|
||||||
let h = size.h.reinterpret_as_int()
|
|
||||||
last_w.val = w
|
|
||||||
let r = t.radius.reinterpret_as_int()
|
|
||||||
let fs = t.font_size.reinterpret_as_int()
|
|
||||||
let ws = windows_sorted()
|
|
||||||
let pw = pill_w(ws.length(), w)
|
|
||||||
let ids = app_ids()
|
|
||||||
let ops : Array[@types.DrawOp] = []
|
|
||||||
for i = 0; i < ws.length(); i = i + 1 {
|
|
||||||
let x = i * (pw + gap)
|
|
||||||
if x >= w {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
let win = ws[i]
|
|
||||||
let focused = win.focused == 1U
|
|
||||||
let minimized = win.minimized == 1U
|
|
||||||
let bg = if focused {
|
|
||||||
t.palette.accent
|
|
||||||
} else if i == hover.val {
|
|
||||||
t.palette.surface_popup
|
|
||||||
} else {
|
|
||||||
t.palette.surface_hover
|
|
||||||
}
|
|
||||||
let fg = if focused {
|
|
||||||
t.palette.accent_foreground
|
|
||||||
} else if minimized {
|
|
||||||
@ui.with_alpha(t.palette.foreground, 140)
|
|
||||||
} else {
|
|
||||||
t.palette.foreground
|
|
||||||
}
|
|
||||||
ops.push(@ui.fill_rect(@ui.rect(x, 0, pw, h), bg, radius=r))
|
|
||||||
if minimized && !focused {
|
|
||||||
ops.push(@ui.stroke_rect(@ui.rect(x, 0, pw, h), t.palette.border, width=1, radius=r))
|
|
||||||
}
|
|
||||||
let title = if win.title.length() > 0 { win.title } else { "(untitled)" }
|
|
||||||
let app = ids.get(win.id).unwrap_or("")
|
|
||||||
let isz = icon_size(h)
|
|
||||||
if pw < icon_only_w {
|
|
||||||
ops.append(pill_icon(x + pw / 2, h / 2, isz, app, title))
|
|
||||||
} else {
|
|
||||||
ops.append(pill_icon(x + 6 + isz / 2, h / 2, isz, app, title))
|
|
||||||
let tx = x + 6 + isz + 6
|
|
||||||
ops.push(@ui.text(tx, h / 2, fit_text(title, fs, x + pw - 8 - tx), fs, fg, bold=focused))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ops
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
pub fn popup() -> PopupSurface? {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
|
||||||
match (target, event) {
|
|
||||||
(WIDGET, PointerMove(p)) => {
|
|
||||||
let i = pill_at(p.x, windows_sorted().length())
|
|
||||||
if i != hover.val {
|
|
||||||
hover.val = i
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(WIDGET, PointerLeave) =>
|
|
||||||
if hover.val != -1 {
|
|
||||||
hover.val = -1
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
(WIDGET, PointerDown(p)) => {
|
|
||||||
let ws = windows_sorted()
|
|
||||||
let i = pill_at(p.x, ws.length())
|
|
||||||
if i >= 0 {
|
|
||||||
@windows.focus_window(ws[i].id)
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
|
||||||
///|
|
|
||||||
pub(all) struct PlasmoidInfo {
|
|
||||||
id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool
|
|
||||||
}
|
|
||||||
///|
|
|
||||||
pub(all) struct PopupSurface {
|
|
||||||
size : @types.Size; ops : Array[@types.DrawOp]
|
|
||||||
}
|
|
||||||
///|
|
|
||||||
pub(all) enum Surface {
|
|
||||||
WIDGET; POPUP
|
|
||||||
} derive()
|
|
||||||
|
|
||||||
///|
|
|
||||||
pub fn Surface::ordinal(self : Surface) -> Int {
|
|
||||||
match self {
|
|
||||||
WIDGET => 0
|
|
||||||
POPUP => 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
pub fn Surface::from(self : Int) -> Surface {
|
|
||||||
match self {
|
|
||||||
0 => WIDGET
|
|
||||||
1 => POPUP
|
|
||||||
_ => panic()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
///|
|
|
||||||
declare pub fn info() -> PlasmoidInfo
|
|
||||||
///|
|
|
||||||
/// Draw the widget into a `size` box (local coordinates).
|
|
||||||
declare pub fn render(size : @types.Size) -> Array[@types.DrawOp]
|
|
||||||
///|
|
|
||||||
/// Present when the widget wants a popup surface (e.g. a launcher menu).
|
|
||||||
declare pub fn popup() -> PopupSurface?
|
|
||||||
///|
|
|
||||||
/// Returns true when the widget's visuals changed and a redraw is needed.
|
|
||||||
declare pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool
|
|
||||||
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import {
|
|
||||||
"chandra/desktop/components/tasks/gen/interface/chandra/desktop/plasmoid" @plasmoid,
|
|
||||||
}
|
|
||||||
|
|
||||||
warnings = "-44"
|
|
||||||
|
|
||||||
pkgtype(kind: "foreign_library")
|
|
||||||
|
|
||||||
options(
|
|
||||||
link: {
|
|
||||||
"wasm": {
|
|
||||||
"export-memory-name": "memory",
|
|
||||||
"heap-start-address": 16,
|
|
||||||
"exports": [
|
|
||||||
"mbt_ffi_cabi_realloc:cabi_realloc",
|
|
||||||
"wasmExportInfo:chandra:desktop/plasmoid@0.1.0#info",
|
|
||||||
"wasmExportInfoPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#info",
|
|
||||||
"wasmExportOnEvent:chandra:desktop/plasmoid@0.1.0#on-event",
|
|
||||||
"wasmExportPopup:chandra:desktop/plasmoid@0.1.0#popup",
|
|
||||||
"wasmExportPopupPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#popup",
|
|
||||||
"wasmExportRender:chandra:desktop/plasmoid@0.1.0#render",
|
|
||||||
"wasmExportRenderPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#render"
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
@@ -6,9 +6,8 @@
|
|||||||
test "dock screenshots: hover label and an app's menu" {
|
test "dock screenshots: hover label and an app's menu" {
|
||||||
let socket_path = "/tmp/wayland-moon-dockshot-" + @sys.getpid().to_string() + ".sock"
|
let socket_path = "/tmp/wayland-moon-dockshot-" + @sys.getpid().to_string() + ".sock"
|
||||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||||
assert_true(comp.shell.load_path("build/components/dock.wasm") is Some(_))
|
|
||||||
ignore(comp.compose_frame())
|
ignore(comp.compose_frame())
|
||||||
let slot = comp.shell.slots().filter(s => comp.shell.slot_module(s).contains("dock"))[0]
|
let slot = comp.shell.slot_of("dock")
|
||||||
// Room for the dock's running apps on a 1280-wide screen.
|
// Room for the dock's running apps on a 1280-wide screen.
|
||||||
for s in comp.shell.slots() {
|
for s in comp.shell.slots() {
|
||||||
let m = comp.shell.slot_module(s)
|
let m = comp.shell.slot_module(s)
|
||||||
@@ -19,6 +18,8 @@ test "dock screenshots: hover label and an app's menu" {
|
|||||||
comp.shell.set_module_setting(
|
comp.shell.set_module_setting(
|
||||||
slot, "pinned", "libreoffice-writer;libreoffice-calc;libreoffice-impress;debian-xterm;vim",
|
slot, "pinned", "libreoffice-writer;libreoffice-calc;libreoffice-impress;debian-xterm;vim",
|
||||||
)
|
)
|
||||||
|
// Icons only, to see the magnification (titles are the default).
|
||||||
|
comp.shell.set_module_setting(slot, "titles", "off")
|
||||||
let _a = open_and_configure_client(comp, socket_path, "Report.odt", "libreoffice-writer")
|
let _a = open_and_configure_client(comp, socket_path, "Report.odt", "libreoffice-writer")
|
||||||
let _b = open_and_configure_client(comp, socket_path, "Notes.odt", "libreoffice-writer")
|
let _b = open_and_configure_client(comp, socket_path, "Notes.odt", "libreoffice-writer")
|
||||||
let _c = open_and_configure_client(comp, socket_path, "Terminal", "xterm")
|
let _c = open_and_configure_client(comp, socket_path, "Terminal", "xterm")
|
||||||
@@ -39,3 +40,94 @@ test "dock screenshots: hover label and an app's menu" {
|
|||||||
assert_true(comp.shell.menu_rows.map(m => m.label).contains("Close 2 windows"))
|
assert_true(comp.shell.menu_rows.map(m => m.label).contains("Close 2 windows"))
|
||||||
ignore(@sys.write_file_bytes("_build/dock_menu.png", @renderer.encode_png(comp.compose_frame())))
|
ignore(@sys.write_file_bytes("_build/dock_menu.png", @renderer.encode_png(comp.compose_frame())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| Pick row `label` of the open right-click menu (rows: 26px title, then 28px each).
|
||||||
|
fn dock_pick(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit raise {
|
||||||
|
let i = comp.shell.menu_rows.map(r => r.label).search(label).unwrap()
|
||||||
|
let m = comp.shell.menu_rect
|
||||||
|
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
///| A key pressed and released with Super held (evdev codes).
|
||||||
|
fn super_key(comp : @host.ChandraCompositor, code : UInt, t : UInt) -> Unit {
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(125U, true), t)
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(code, true), t + 1U)
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(code, false), t + 2U)
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(125U, false), t + 3U)
|
||||||
|
ignore(comp.compose_frame())
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "the dock is the panel's task manager: empty + opens Applications, pin from there, Super+number" {
|
||||||
|
let socket_path = "/tmp/wayland-moon-dockbar-" + @sys.getpid().to_string() + ".sock"
|
||||||
|
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||||
|
ignore(comp.compose_frame())
|
||||||
|
// A fresh panel has the dock where the task list was; the old id is an alias of it.
|
||||||
|
let slot = comp.shell.slot_of("dock")
|
||||||
|
assert_true(slot.length() > 0)
|
||||||
|
assert_eq(comp.shell.slot_of("tasks"), slot)
|
||||||
|
// It stretches: the clock still packs against the right edge.
|
||||||
|
let r = comp.shell.slot_rect(slot)
|
||||||
|
assert_true(r.w > 300)
|
||||||
|
let clock = comp.shell.slot_rect(comp.shell.slot_of("clock-digital"))
|
||||||
|
assert_true(clock.x > 900)
|
||||||
|
// Nothing pinned, nothing running: a "+" that opens the Applications menu.
|
||||||
|
comp.shell.set_module_setting(slot, "pinned", ";")
|
||||||
|
ignore(comp.compose_frame())
|
||||||
|
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 14).to_double(), (r.y + r.h / 2).to_double()), 8U)
|
||||||
|
ignore(@sys.write_file_bytes("_build/dock_empty.png", @renderer.encode_png(comp.compose_frame())))
|
||||||
|
click_at(comp, r.x + 14, r.y + r.h / 2, 10U)
|
||||||
|
let launcher = comp.shell.slot_of("launcher")
|
||||||
|
let pr = comp.shell.slot_popup_rect(launcher)
|
||||||
|
assert_true(pr.w > 0)
|
||||||
|
// Right-click the first app there: Open, Pin to dock. Pinning keeps the menu open.
|
||||||
|
click_at(comp, pr.x + 40, pr.y + 60, 20U, btn=273U)
|
||||||
|
assert_true(comp.shell.menu_open)
|
||||||
|
assert_eq(comp.shell.menu_rows.map(r => r.label), ["Open", "Pin to dock"])
|
||||||
|
let first = comp.shell.menu_title
|
||||||
|
ignore(@sys.write_file_bytes("_build/dock_pin_from_menu.png", @renderer.encode_png(comp.compose_frame())))
|
||||||
|
dock_pick(comp, "Pin to dock", 25U)
|
||||||
|
assert_true(comp.shell.slot_popup_rect(launcher).w > 0)
|
||||||
|
let pinned = comp.shell.module_setting("dock", "pinned").unwrap_or("")
|
||||||
|
assert_true(pinned.length() > 1 && pinned != ";")
|
||||||
|
// The same app's menu now offers Unpin.
|
||||||
|
click_at(comp, pr.x + 40, pr.y + 60, 30U, btn=273U)
|
||||||
|
assert_eq(comp.shell.menu_title, first)
|
||||||
|
assert_true(comp.shell.menu_rows.map(r => r.label).contains("Unpin from dock"))
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 35U) // Escape closes the menu
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(1U, false), 36U)
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 37U) // and the Applications menu
|
||||||
|
comp.handle_input(@nested.InputEvent::Key(1U, false), 38U)
|
||||||
|
// Two running apps pinned in front: Super+2 brings the second one's window forward.
|
||||||
|
comp.shell.set_module_setting(slot, "pinned", "libreoffice-writer;libreoffice-calc;vim")
|
||||||
|
let _a = open_and_configure_client(comp, socket_path, "Report.odt", "libreoffice-writer")
|
||||||
|
let _b = open_and_configure_client(comp, socket_path, "Budget.ods", "libreoffice-calc")
|
||||||
|
let _c = open_and_configure_client(comp, socket_path, "Notes.odt", "libreoffice-writer")
|
||||||
|
ignore(comp.compose_frame())
|
||||||
|
let focused = fn() {
|
||||||
|
let mut f = ""
|
||||||
|
for _, w in comp.windows {
|
||||||
|
if w.focused {
|
||||||
|
f = w.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f
|
||||||
|
}
|
||||||
|
super_key(comp, 3U, 40U) // Super+2
|
||||||
|
assert_eq(focused(), "Budget.ods")
|
||||||
|
super_key(comp, 2U, 50U) // Super+1: Writer's newest window, then its other one
|
||||||
|
assert_eq(focused(), "Notes.odt")
|
||||||
|
super_key(comp, 2U, 60U)
|
||||||
|
assert_eq(focused(), "Report.odt")
|
||||||
|
// Writer's menu lists its two windows by title; picking one brings it forward.
|
||||||
|
let r = comp.shell.slot_rect(slot)
|
||||||
|
click_at(comp, r.x + 6 + 12, r.y + r.h / 2, 70U, btn=273U)
|
||||||
|
let labels = comp.shell.menu_rows.map(r => r.label)
|
||||||
|
assert_true(labels.contains("Report.odt") && labels.contains("Notes.odt"))
|
||||||
|
ignore(@sys.write_file_bytes("_build/dock_bar_menu.png", @renderer.encode_png(comp.compose_frame())))
|
||||||
|
dock_pick(comp, "Notes.odt", 80U)
|
||||||
|
ignore(comp.compose_frame())
|
||||||
|
assert_eq(focused(), "Notes.odt")
|
||||||
|
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 6 + 30 + 12).to_double(), (r.y + r.h / 2).to_double()), 90U)
|
||||||
|
ignore(@sys.write_file_bytes("_build/dock_bar.png", @renderer.encode_png(comp.compose_frame())))
|
||||||
|
}
|
||||||
@@ -262,8 +262,11 @@ test "title-bar buttons minimize, maximize and close windows" {
|
|||||||
click(btn(1UL, 1), 20U)
|
click(btn(1UL, 1), 20U)
|
||||||
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
||||||
assert_true(!comp.wm.stacking_order().contains(1UL))
|
assert_true(!comp.wm.stacking_order().contains(1UL))
|
||||||
let tasks = rect_of(comp, "tasks")
|
// The dock with nothing pinned: one titled pill per app, in opening order (150 wide, 6 apart):
|
||||||
// pills are in opening order (140 wide, 6 apart): window 1, the minimized one, is first
|
// window 1's app, the minimized one, is first.
|
||||||
|
comp.shell.set_module_setting(comp.shell.slot_of("dock"), "pinned", ";")
|
||||||
|
ignore(comp.compose_frame())
|
||||||
|
let tasks = rect_of(comp, "dock")
|
||||||
click((tasks.x + 20, tasks.y + tasks.h / 2), 30U)
|
click((tasks.x + 20, tasks.y + tasks.h / 2), 30U)
|
||||||
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
|
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
|
||||||
// Close window 2: the client receives xdg_toplevel.close (opcode 1 on its toplevel).
|
// Close window 2: the client receives xdg_toplevel.close (opcode 1 on its toplevel).
|
||||||
@@ -277,7 +280,7 @@ test "title-bar buttons minimize, maximize and close windows" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
test "the task list module focuses the window whose pill is clicked" {
|
test "the dock focuses the window whose pill is clicked" {
|
||||||
let socket_path = "/tmp/wayland-moon-tasks-" +
|
let socket_path = "/tmp/wayland-moon-tasks-" +
|
||||||
@sys.getpid().to_string() +
|
@sys.getpid().to_string() +
|
||||||
".sock"
|
".sock"
|
||||||
@@ -285,6 +288,7 @@ test "the task list module focuses the window whose pill is clicked" {
|
|||||||
let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
||||||
let _a = open_and_configure_client(comp, socket_path, "A", "a")
|
let _a = open_and_configure_client(comp, socket_path, "A", "a")
|
||||||
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
||||||
|
comp.shell.set_module_setting(comp.shell.slot_of("dock"), "pinned", ";")
|
||||||
ignore(comp.compose_frame())
|
ignore(comp.compose_frame())
|
||||||
let focused = fn() {
|
let focused = fn() {
|
||||||
let mut f = 0UL
|
let mut f = 0UL
|
||||||
@@ -295,18 +299,18 @@ test "the task list module focuses the window whose pill is clicked" {
|
|||||||
}
|
}
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
let tasks = rect_of(comp, "tasks")
|
let tasks = rect_of(comp, "dock")
|
||||||
assert_true(tasks.w > 300) // the stretching module takes the free space
|
assert_true(tasks.w > 300) // the stretching module takes the free space
|
||||||
let first = comp.wm.stacking_order()[0]
|
let first = comp.wm.stacking_order()[0]
|
||||||
click_at(comp, tasks.x + 20, tasks.y + tasks.h / 2, 1U) // pill 0
|
click_at(comp, tasks.x + 20, tasks.y + tasks.h / 2, 1U) // pill 0
|
||||||
assert_eq(focused(), first)
|
assert_eq(focused(), first)
|
||||||
let other = comp.wm.stacking_order()
|
let other = comp.wm.stacking_order()
|
||||||
click_at(comp, tasks.x + 146 + 20, tasks.y + tasks.h / 2, 10U) // pill 1
|
click_at(comp, tasks.x + 156 + 20, tasks.y + tasks.h / 2, 10U) // pill 1
|
||||||
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" {
|
test "right-click an app in the dock for its window's menu: Minimize, Maximize, Quit" {
|
||||||
let socket_path = "/tmp/wayland-moon-taskmenu-" +
|
let socket_path = "/tmp/wayland-moon-taskmenu-" +
|
||||||
@sys.getpid().to_string() +
|
@sys.getpid().to_string() +
|
||||||
".sock"
|
".sock"
|
||||||
@@ -314,8 +318,9 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
|
|||||||
let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
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 (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")
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
||||||
|
comp.shell.set_module_setting(comp.shell.slot_of("dock"), "pinned", ";")
|
||||||
ignore(comp.compose_frame())
|
ignore(comp.compose_frame())
|
||||||
let tasks = rect_of(comp, "tasks")
|
let tasks = rect_of(comp, "dock")
|
||||||
let cy = tasks.y + tasks.h / 2
|
let cy = tasks.y + tasks.h / 2
|
||||||
let labels = fn() { comp.shell.menu_rows.map(r => r.label) }
|
let labels = fn() { comp.shell.menu_rows.map(r => r.label) }
|
||||||
// Pick menu row `label` (rows: 26px title, then 28px each).
|
// Pick menu row `label` (rows: 26px title, then 28px each).
|
||||||
@@ -324,17 +329,17 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
|
|||||||
let m = comp.shell.menu_rect
|
let m = comp.shell.menu_rect
|
||||||
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
|
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.
|
// Pill 0 is window 1's app (opening order): its menu, titled with the app's name.
|
||||||
click_at(comp, tasks.x + 20, cy, 1U, btn=273U)
|
click_at(comp, tasks.x + 20, cy, 1U, btn=273U)
|
||||||
assert_true(comp.shell.menu_open)
|
assert_true(comp.shell.menu_open)
|
||||||
assert_eq(comp.shell.menu_title, "A")
|
assert_eq(comp.shell.menu_title, "a")
|
||||||
assert_eq(labels(), ["Minimize", "Maximize", "Quit"])
|
assert_eq(labels(), ["Pin to dock", "Minimize", "Maximize", "Quit", "Dock settings..."])
|
||||||
// Minimize, then the same pill's menu offers Restore, which brings it back.
|
// Minimize, then the same pill's menu offers Restore, which brings it back.
|
||||||
pick("Minimize", 10U)
|
pick("Minimize", 10U)
|
||||||
assert_true(!comp.shell.menu_open)
|
assert_true(!comp.shell.menu_open)
|
||||||
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
||||||
click_at(comp, tasks.x + 20, cy, 20U, btn=273U)
|
click_at(comp, tasks.x + 20, cy, 20U, btn=273U)
|
||||||
assert_eq(labels(), ["Restore", "Maximize", "Quit"])
|
assert_eq(labels(), ["Pin to dock", "Restore", "Maximize", "Quit", "Dock settings..."])
|
||||||
pick("Restore", 30U)
|
pick("Restore", 30U)
|
||||||
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
|
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
|
||||||
// Maximize, then Restore size.
|
// Maximize, then Restore size.
|
||||||
@@ -343,12 +348,12 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
|
|||||||
pick("Maximize", 50U)
|
pick("Maximize", 50U)
|
||||||
assert_true(comp.windows.get(1UL).unwrap().geometry.w > w0)
|
assert_true(comp.windows.get(1UL).unwrap().geometry.w > w0)
|
||||||
click_at(comp, tasks.x + 20, cy, 60U, btn=273U)
|
click_at(comp, tasks.x + 20, cy, 60U, btn=273U)
|
||||||
assert_eq(labels(), ["Minimize", "Restore size", "Quit"])
|
assert_eq(labels(), ["Pin to dock", "Minimize", "Restore size", "Quit", "Dock settings..."])
|
||||||
pick("Restore size", 70U)
|
pick("Restore size", 70U)
|
||||||
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, w0)
|
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, w0)
|
||||||
// Pill 1 is window 2.
|
// Pill 1 is window 2's app.
|
||||||
click_at(comp, tasks.x + 146 + 20, cy, 80U, btn=273U)
|
click_at(comp, tasks.x + 156 + 20, cy, 80U, btn=273U)
|
||||||
assert_eq(comp.shell.menu_title, "B")
|
assert_eq(comp.shell.menu_title, "b")
|
||||||
comp.handle_input(@nested.InputEvent::Key(1U, true), 85U) // Escape
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 85U) // Escape
|
||||||
assert_true(!comp.shell.menu_open)
|
assert_true(!comp.shell.menu_open)
|
||||||
// Quit asks the app to close its window (xdg_toplevel.close, opcode 1 on its toplevel).
|
// Quit asks the app to close its window (xdg_toplevel.close, opcode 1 on its toplevel).
|
||||||
@@ -360,9 +365,9 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
|
|||||||
@sys.sleep_ms(2)
|
@sys.sleep_ms(2)
|
||||||
}
|
}
|
||||||
assert_true(has_msg(drain_msgs(c), tl, 1U))
|
assert_true(has_msg(drain_msgs(c), tl, 1U))
|
||||||
// Empty task-bar space keeps the module's own menu.
|
// Empty dock space keeps the module's own menu.
|
||||||
click_at(comp, tasks.x + tasks.w - 10, cy, 110U, btn=273U)
|
click_at(comp, tasks.x + tasks.w - 10, cy, 110U, btn=273U)
|
||||||
assert_eq(comp.shell.menu_title, "Task Manager")
|
assert_eq(comp.shell.menu_title, "Dock")
|
||||||
assert_true(labels().contains("Remove widget"))
|
assert_true(labels().contains("Remove widget"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,9 +619,9 @@ test "the wasm picker opens the settings module's Panel tab, which loads and unl
|
|||||||
assert_true(texts.contains("Browse for a module file..."))
|
assert_true(texts.contains("Browse for a module file..."))
|
||||||
// The Add list leaves out what is already in the panel (but a clock can be added twice) and
|
// The Add list leaves out what is already in the panel (but a clock can be added twice) and
|
||||||
// has no cryptic instance counts.
|
// has no cryptic instance counts.
|
||||||
assert_eq(texts.filter(t => t == "Task Manager").length(), 1)
|
assert_eq(texts.filter(t => t == "Dock").length(), 1)
|
||||||
assert_false(texts.contains("x1"))
|
assert_false(texts.contains("x1"))
|
||||||
assert_true(texts.contains("Pinned apps, one click away")) // the Dock's description
|
assert_true(texts.contains("The time in binary")) // the Binary Clock's description
|
||||||
let loaded = comp.shell.slots().length()
|
let loaded = comp.shell.slots().length()
|
||||||
assert_eq(comp.shell.slot_of("clock-binary"), "")
|
assert_eq(comp.shell.slot_of("clock-binary"), "")
|
||||||
let by = row_y("Binary Clock", false)
|
let by = row_y("Binary Clock", false)
|
||||||
@@ -930,25 +935,24 @@ test "the dock: pinned and running apps, window dots, the hover label and the pe
|
|||||||
comp.shell.apps.clear()
|
comp.shell.apps.clear()
|
||||||
for id in ["foot", "firefox", "gimp"] {
|
for id in ["foot", "firefox", "gimp"] {
|
||||||
comp.shell.apps.push({ id, name: id.to_upper(), comment: "", category: "", glyph: "x" })
|
comp.shell.apps.push({ id, name: id.to_upper(), comment: "", category: "", glyph: "x" })
|
||||||
|
comp.shell.exec.set(id, id)
|
||||||
}
|
}
|
||||||
comp.shell.apps_dirty = true
|
comp.shell.apps_dirty = true
|
||||||
assert_true(comp.shell.load_path("build/components/dock.wasm") is Some(_))
|
|
||||||
ignore(comp.compose_frame())
|
ignore(comp.compose_frame())
|
||||||
let slot = comp.shell.slots().filter(s => comp.shell.slot_module(s).contains("dock"))[0]
|
// The dock is in the default panel; icons only here (titled pills are the default).
|
||||||
|
let slot = comp.shell.slot_of("dock")
|
||||||
|
comp.shell.set_module_setting(slot, "titles", "off")
|
||||||
let pinned = fn() {
|
let pinned = fn() {
|
||||||
comp.shell.slot_config(slot).filter(it => it.key == "pinned")[0].value
|
comp.shell.slot_config(slot).filter(it => it.key == "pinned")[0].value
|
||||||
}
|
}
|
||||||
// Nothing chosen yet: the catalog's first apps, saved so launches don't reorder them.
|
// Nothing chosen yet: the catalog's first apps, saved so launches don't reorder them.
|
||||||
assert_eq(pinned(), "foot;firefox;gimp")
|
assert_eq(pinned(), "foot;firefox;gimp")
|
||||||
// The pinned list isn't a row of the dock's settings menu.
|
|
||||||
let w0 = comp.shell.slot_rect(slot).w
|
|
||||||
// A foot window joins foot's icon; an unknown app gets its own icon after the pinned ones.
|
// A foot window joins foot's icon; an unknown app gets its own icon after the pinned ones.
|
||||||
let _a = open_and_configure_client(comp, socket_path, "Term", "foot")
|
let _a = open_and_configure_client(comp, socket_path, "Term", "foot")
|
||||||
let _b = open_and_configure_client(comp, socket_path, "Other", "zzz")
|
let _b = open_and_configure_client(comp, socket_path, "Other", "zzz")
|
||||||
ignore(comp.compose_frame())
|
ignore(comp.compose_frame())
|
||||||
ignore(comp.compose_frame())
|
ignore(comp.compose_frame())
|
||||||
let r = comp.shell.slot_rect(slot)
|
let r = comp.shell.slot_rect(slot)
|
||||||
assert_true(r.w > w0) // the dock grew for the running app
|
|
||||||
let cy = r.y + r.h / 2
|
let cy = r.y + r.h / 2
|
||||||
let pitch = 24 + 6 // medium icons
|
let pitch = 24 + 6 // medium icons
|
||||||
let x_of = fn(i : Int) { r.x + 6 + i * pitch + 12 + (if i >= 3 { 11 } else { 0 }) }
|
let x_of = fn(i : Int) { r.x + 6 + i * pitch + 12 + (if i >= 3 { 11 } else { 0 }) }
|
||||||
@@ -968,7 +972,9 @@ test "the dock: pinned and running apps, window dots, the hover label and the pe
|
|||||||
click_at(comp, x_of(0), cy, 10U, btn=273U)
|
click_at(comp, x_of(0), cy, 10U, btn=273U)
|
||||||
assert_true(comp.shell.menu_open)
|
assert_true(comp.shell.menu_open)
|
||||||
assert_eq(comp.shell.menu_title, "FOOT")
|
assert_eq(comp.shell.menu_title, "FOOT")
|
||||||
assert_eq(labels(), ["New window", "Unpin from dock", "Move right", "Quit", "Dock settings..."])
|
assert_eq(labels(), [
|
||||||
|
"New window", "Unpin from dock", "Move right", "Minimize", "Maximize", "Quit", "Dock settings...",
|
||||||
|
])
|
||||||
assert_eq(comp.shell.dock_hover_name(), "") // no label over the menu
|
assert_eq(comp.shell.dock_hover_name(), "") // no label over the menu
|
||||||
pick("Move right", 20U)
|
pick("Move right", 20U)
|
||||||
assert_eq(pinned(), "firefox;foot;gimp")
|
assert_eq(pinned(), "firefox;foot;gimp")
|
||||||
@@ -983,7 +989,8 @@ test "the dock: pinned and running apps, window dots, the hover label and the pe
|
|||||||
let x2 = r.x + 6 + 2 * pitch + 11 + 12
|
let x2 = r.x + 6 + 2 * pitch + 11 + 12
|
||||||
click_at(comp, x2, cy, 50U, btn=273U)
|
click_at(comp, x2, cy, 50U, btn=273U)
|
||||||
assert_eq(comp.shell.menu_title, "zzz")
|
assert_eq(comp.shell.menu_title, "zzz")
|
||||||
assert_eq(labels(), ["New window", "Pin to dock", "Quit", "Dock settings..."])
|
// Not in the app catalog: nothing to start a new window with.
|
||||||
|
assert_eq(labels(), ["Pin to dock", "Minimize", "Maximize", "Quit", "Dock settings..."])
|
||||||
pick("Pin to dock", 60U)
|
pick("Pin to dock", 60U)
|
||||||
assert_eq(pinned(), "foot;gimp;zzz")
|
assert_eq(pinned(), "foot;gimp;zzz")
|
||||||
// Dock settings: the visible settings only.
|
// Dock settings: the visible settings only.
|
||||||
@@ -998,7 +1005,7 @@ test "the dock: pinned and running apps, window dots, the hover label and the pe
|
|||||||
pick("Large", 90U)
|
pick("Large", 90U)
|
||||||
comp.handle_input(@nested.InputEvent::Key(1U, true), 95U) // Escape
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 95U) // Escape
|
||||||
ignore(comp.compose_frame())
|
ignore(comp.compose_frame())
|
||||||
assert_true(comp.shell.slot_rect(slot).w > r.w) // bigger icons, wider dock
|
assert_eq(comp.shell.module_setting("dock", "icon-size"), Some("Large"))
|
||||||
// A left click on a running app's icon focuses its window.
|
// A left click on a running app's icon focuses its window.
|
||||||
let focused = fn() {
|
let focused = fn() {
|
||||||
let mut f = 0UL
|
let mut f = 0UL
|
||||||
|
|||||||
@@ -84,9 +84,21 @@ fn ChandraCompositor::shortcut_key(self : ChandraCompositor, code : UInt, presse
|
|||||||
if @shell.is_modifier_key(code) || self.shell.inspecting() {
|
if @shell.is_modifier_key(code) || self.shell.inspecting() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
match self.shell.shortcuts.lookup({ mods: self.held_mods(), key: code }) {
|
let combo : @shell.KeyCombo = { mods: self.held_mods(), key: code }
|
||||||
|
match self.shell.shortcuts.lookup(combo) {
|
||||||
// Window switching is the switcher's (switcher_key runs before this).
|
// Window switching is the switcher's (switcher_key runs before this).
|
||||||
None | Some(SwitchWindows) => false
|
Some(SwitchWindows) => false
|
||||||
|
// Super+2 .. Super+9 aren't in the table: they follow the "Open dock app" combo.
|
||||||
|
None | Some(DockApps) =>
|
||||||
|
match self.shell.shortcuts.dock_app(combo) {
|
||||||
|
Some(n) if self.open_dock_app(n) => {
|
||||||
|
self.sc_swallow.push(code)
|
||||||
|
self.super_solo = false
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Some(_) => false
|
||||||
|
None => false
|
||||||
|
}
|
||||||
Some(action) => {
|
Some(action) => {
|
||||||
self.sc_swallow.push(code)
|
self.sc_swallow.push(code)
|
||||||
self.run_shortcut(action)
|
self.run_shortcut(action)
|
||||||
@@ -117,8 +129,20 @@ pub fn ChandraCompositor::run_shortcut(self : ChandraCompositor, action : @shell
|
|||||||
RecordRegion => self.toggle_recording(ShotMode::Region)
|
RecordRegion => self.toggle_recording(ShotMode::Region)
|
||||||
RecordScreen => self.toggle_recording(ShotMode::FullScreen)
|
RecordScreen => self.toggle_recording(ShotMode::FullScreen)
|
||||||
RecordWindow => self.toggle_recording(ShotMode::WindowUnderCursor)
|
RecordWindow => self.toggle_recording(ShotMode::WindowUnderCursor)
|
||||||
|
DockApps => ignore(self.open_dock_app(1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| Super+`n`: the dock's `n`-th app, as if its icon were clicked. False when there is no dock
|
||||||
|
/// or no such app (the key then goes to the focused window as usual).
|
||||||
|
fn ChandraCompositor::open_dock_app(self : ChandraCompositor, n : Int) -> Bool {
|
||||||
|
if self.shell.inspecting() || !self.shell.open_dock_item(n) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
self.run_shell_actions()
|
||||||
|
self.damage.mark_full()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
///| evdev code of Backspace (unbinds while capturing).
|
///| evdev code of Backspace (unbinds while capturing).
|
||||||
let key_backspace : UInt = 14
|
let key_backspace : UInt = 14
|
||||||
@@ -34,6 +34,7 @@ test "the default shortcuts are the compositor's long-standing combos" {
|
|||||||
("record-region", "Super+Shift+R"),
|
("record-region", "Super+Shift+R"),
|
||||||
("record-screen", "Super+Alt+R"),
|
("record-screen", "Super+Alt+R"),
|
||||||
("record-window", "Super+Ctrl+R"),
|
("record-window", "Super+Ctrl+R"),
|
||||||
|
("dock-apps", "Super+1"),
|
||||||
]
|
]
|
||||||
let sc = @shell.Shortcuts::defaults()
|
let sc = @shell.Shortcuts::defaults()
|
||||||
assert_eq(@shell.shortcut_table.length(), want.length())
|
assert_eq(@shell.shortcut_table.length(), want.length())
|
||||||
|
|||||||
+209
-5
@@ -26,7 +26,23 @@ fn dock_config(w : Widget) -> @dock.DockConfig {
|
|||||||
|
|
||||||
///| The windows as the dock sees them.
|
///| The windows as the dock sees them.
|
||||||
fn DesktopShell::dock_windows(self : DesktopShell) -> Array[@dock.DockWindow] {
|
fn DesktopShell::dock_windows(self : DesktopShell) -> Array[@dock.DockWindow] {
|
||||||
self.win_list.map(e => { id: e.id, app_id: e.app_id, focused: e.focused })
|
self.win_list.map(e => {
|
||||||
|
id: e.id,
|
||||||
|
app_id: e.app_id,
|
||||||
|
focused: e.focused,
|
||||||
|
title: e.title,
|
||||||
|
minimized: self.win_info(e.id).map(i => i.minimized).unwrap_or(false),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
///| The window list entry (minimized, maximized) of window `id`.
|
||||||
|
fn DesktopShell::win_info(self : DesktopShell, id : UInt64) -> WinInfo? {
|
||||||
|
for w in self.windows {
|
||||||
|
if w.id == id {
|
||||||
|
return Some(w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The dock in `w`'s settings and icons, as the module computes them.
|
///| The dock in `w`'s settings and icons, as the module computes them.
|
||||||
@@ -163,7 +179,9 @@ fn DesktopShell::open_dock_menu(
|
|||||||
let it = items[i]
|
let it = items[i]
|
||||||
let rows : Array[MenuRow] = []
|
let rows : Array[MenuRow] = []
|
||||||
let n = it.windows.length()
|
let n = it.windows.length()
|
||||||
|
if self.command_for(it.id) is Some(_) {
|
||||||
rows.push(dock_row(if n == 0 { "Open" } else { "New window" }, 7, it.id))
|
rows.push(dock_row(if n == 0 { "Open" } else { "New window" }, 7, it.id))
|
||||||
|
}
|
||||||
if it.pinned {
|
if it.pinned {
|
||||||
rows.push(dock_row("Unpin from dock", 8, it.id))
|
rows.push(dock_row("Unpin from dock", 8, it.id))
|
||||||
let pinned = items.filter(x => x.pinned).length()
|
let pinned = items.filter(x => x.pinned).length()
|
||||||
@@ -176,6 +194,30 @@ fn DesktopShell::open_dock_menu(
|
|||||||
} else {
|
} else {
|
||||||
rows.push(dock_row("Pin to dock", 8, it.id))
|
rows.push(dock_row("Pin to dock", 8, it.id))
|
||||||
}
|
}
|
||||||
|
if n == 1 {
|
||||||
|
// The window's own commands, as the task list had them.
|
||||||
|
match self.win_info(it.windows[0]) {
|
||||||
|
Some(win) => {
|
||||||
|
rows.push(
|
||||||
|
if win.minimized {
|
||||||
|
window_row("Restore", win.id, Restore)
|
||||||
|
} else {
|
||||||
|
window_row("Minimize", win.id, Minimize)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
rows.push(window_row(if win.maximized { "Restore size" } else { "Maximize" }, win.id, ToggleMaximize))
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
} else if n > 1 {
|
||||||
|
// Its windows by title, so one can be picked straight away (a click cycles through them).
|
||||||
|
rows.push(menu_row("Windows", 5))
|
||||||
|
for win in it.windows {
|
||||||
|
let min = self.win_info(win).map(i => i.minimized).unwrap_or(false)
|
||||||
|
let label = self.window_title(win) + (if min { " (minimized)" } else { "" })
|
||||||
|
rows.push({ ..menu_row(label, 6), window_id: win, window_cmd: Restore })
|
||||||
|
}
|
||||||
|
}
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
rows.push(dock_row("Quit", 10, it.id))
|
rows.push(dock_row("Quit", 10, it.id))
|
||||||
} else if n > 1 {
|
} else if n > 1 {
|
||||||
@@ -185,15 +227,25 @@ fn DesktopShell::open_dock_menu(
|
|||||||
self.open_menu(it.name, rows, w.slot, x)
|
self.open_menu(it.name, rows, w.slot, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
///| A dock menu row was chosen for the dock in `slot`.
|
///| A dock menu row was chosen for the dock in `slot`. "Pin to dock" from the Applications menu
|
||||||
|
/// when there is no dock yet (`slot` "") puts one in the panel first.
|
||||||
fn DesktopShell::dock_menu_choice(self : DesktopShell, slot : String, row : MenuRow) -> Unit {
|
fn DesktopShell::dock_menu_choice(self : DesktopShell, slot : String, row : MenuRow) -> Unit {
|
||||||
match self.widget_by_slot(slot) {
|
let dock = match self.widget_by_slot(slot) {
|
||||||
|
Some(w) => Some(w)
|
||||||
|
None if row.kind == 8 => self.add_dock()
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
if row.kind == 7 {
|
||||||
|
self.launch_catalog_app(row.arg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
match dock {
|
||||||
None => ()
|
None => ()
|
||||||
Some(w) => {
|
Some(w) => {
|
||||||
|
let slot = w.slot
|
||||||
let (cfg, items) = self.dock_state(w)
|
let (cfg, items) = self.dock_state(w)
|
||||||
let pins = cfg.pins(self.apps)
|
let pins = cfg.pins(self.apps)
|
||||||
match row.kind {
|
match row.kind {
|
||||||
7 => self.launch_catalog_app(row.arg)
|
|
||||||
8 => self.set_module_setting(slot, "pinned", @dock.encode_pins(@dock.toggle_pin(pins, row.arg)))
|
8 => self.set_module_setting(slot, "pinned", @dock.encode_pins(@dock.toggle_pin(pins, row.arg)))
|
||||||
9 => {
|
9 => {
|
||||||
let delta = if row.value == "-1" { -1 } else { 1 }
|
let delta = if row.value == "-1" { -1 } else { 1 }
|
||||||
@@ -220,7 +272,10 @@ fn DesktopShell::dock_label(self : DesktopShell) -> (String, Int)? {
|
|||||||
match self.dock_item_at(w, self.ptr_x, self.ptr_y) {
|
match self.dock_item_at(w, self.ptr_x, self.ptr_y) {
|
||||||
Some((items, i)) => {
|
Some((items, i)) => {
|
||||||
let cfg = dock_config(w)
|
let cfg = dock_config(w)
|
||||||
Some((items[i].name, w.rect.x + @dock.item_center(items, cfg, w.rect.h, i)))
|
if @dock.titled_at(items, cfg, w.rect.w, w.rect.h, i) {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
Some((items[i].name, w.rect.x + @dock.item_center(items, cfg, w.rect.w, w.rect.h, i)))
|
||||||
}
|
}
|
||||||
None => None
|
None => None
|
||||||
}
|
}
|
||||||
@@ -263,3 +318,152 @@ fn DesktopShell::render_dock_label(self : DesktopShell, tokens : @theme.Tokens,
|
|||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- pinning from elsewhere
|
||||||
|
|
||||||
|
///| The first dock in the panel, if any.
|
||||||
|
fn DesktopShell::dock_widget(self : DesktopShell) -> Widget? {
|
||||||
|
for w in self.widgets {
|
||||||
|
if w.is_dock() {
|
||||||
|
return Some(w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
///| A window's title ("Window" when it has none).
|
||||||
|
fn DesktopShell::window_title(self : DesktopShell, id : UInt64) -> String {
|
||||||
|
for e in self.win_list {
|
||||||
|
if e.id == id && e.title.length() > 0 {
|
||||||
|
return e.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"Window"
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Put a dock into the panel, just after the Applications button (or first), with its
|
||||||
|
/// first pins settled. None when the dock module can't be found or loaded.
|
||||||
|
fn DesktopShell::add_dock(self : DesktopShell) -> Widget? {
|
||||||
|
self.name_catalog()
|
||||||
|
match self.find_module("dock") {
|
||||||
|
None => {
|
||||||
|
self.say("Dock module not found (build it with scripts/build-modules.sh)")
|
||||||
|
None
|
||||||
|
}
|
||||||
|
Some(c) =>
|
||||||
|
match self.load_path(c.path) {
|
||||||
|
None => None
|
||||||
|
Some(w) => {
|
||||||
|
let mut at = 0
|
||||||
|
for i = 0; i < self.widgets.length(); i = i + 1 {
|
||||||
|
if self.widgets[i].module_id == launcher_module {
|
||||||
|
at = i + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.widgets.retain(x => x.slot != w.slot)
|
||||||
|
self.widgets.insert(at, w)
|
||||||
|
self.settle_dock_pins()
|
||||||
|
self.save_panel_config()
|
||||||
|
Some(w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| "Pin to dock" or "Unpin from dock" for app `id` (a catalog or window app id) as a row of
|
||||||
|
/// another menu, and the dock's slot that row acts on ("" when there is no dock yet: pinning
|
||||||
|
/// then adds one).
|
||||||
|
fn DesktopShell::pin_row(self : DesktopShell, id : String) -> (MenuRow, String) {
|
||||||
|
match self.dock_widget() {
|
||||||
|
Some(w) => {
|
||||||
|
let pinned = dock_config(w).pins(self.apps).contains(id)
|
||||||
|
(dock_row(if pinned { "Unpin from dock" } else { "Pin to dock" }, 8, id), w.slot)
|
||||||
|
}
|
||||||
|
None => (dock_row("Pin to dock", 8, id), "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| The right-click menu of an app in the Applications menu: Open, and Pin to dock / Unpin.
|
||||||
|
fn DesktopShell::open_app_menu(self : DesktopShell, app : @types.AppEntry, x : Int) -> Unit {
|
||||||
|
let (pin, slot) = self.pin_row(app.id)
|
||||||
|
self.open_menu(app.name, [dock_row("Open", 7, app.id), pin], slot, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
///| The app under (x, y) in the Applications menu's popup, if it is open there.
|
||||||
|
fn DesktopShell::launcher_app_at(self : DesktopShell, x : Int, y : Int) -> @types.AppEntry? {
|
||||||
|
match self.popup_at(x, y) {
|
||||||
|
Some(w) if w.module_id == launcher_module => {
|
||||||
|
let shown = @launcher.filter(self.apps, self.launcher_state.query)
|
||||||
|
let i = @launcher.row_at(self.apps, self.launcher_state, { x: x - w.popup_rect.x, y: y - w.popup_rect.y })
|
||||||
|
if i >= 0 && i < shown.length() {
|
||||||
|
Some(shown[i])
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Follow an event the launcher module was handed, so the shell knows what its popup lists
|
||||||
|
/// (its search text) for the right-click menu. The module's own state stays the truth for
|
||||||
|
/// whether it is open.
|
||||||
|
fn DesktopShell::follow_launcher(self : DesktopShell, w : Widget, popup : Bool, ev : @wasm.PlasmoidEvent) -> Unit {
|
||||||
|
let st = self.launcher_state
|
||||||
|
let e : @types.InputEvent = match ev {
|
||||||
|
PointerMove(x, y) => PointerMove({ x, y })
|
||||||
|
PointerDown(x, y) => PointerDown({ x, y })
|
||||||
|
PointerUp(x, y) => PointerUp({ x, y })
|
||||||
|
PointerLeave => PointerLeave
|
||||||
|
FocusLost => FocusLost
|
||||||
|
KeyDown(k) => KeyDown(k)
|
||||||
|
}
|
||||||
|
ignore(@launcher.handle_event(self.apps, st, if popup { Popup } else { Widget }, e, _ => Ok(())))
|
||||||
|
if w.popup_rect.w == 0 {
|
||||||
|
@launcher.close(st)
|
||||||
|
} else if !st.open {
|
||||||
|
// Open in the module (its launch failed and kept it open): open here too.
|
||||||
|
ignore(@launcher.handle_event(self.apps, st, Widget, PointerDown({ x: 0, y: 0 }), _ => Ok(())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Super+`n` (1-based): what a click on the dock's `n`-th icon does, start the app or bring its
|
||||||
|
/// windows forward. False when there is no dock or no such icon.
|
||||||
|
pub fn DesktopShell::open_dock_item(self : DesktopShell, n : Int) -> Bool {
|
||||||
|
self.ensure_booted()
|
||||||
|
match self.dock_widget() {
|
||||||
|
None => false
|
||||||
|
Some(w) => {
|
||||||
|
let (_, items) = self.dock_state(w)
|
||||||
|
if n < 1 || n > items.length() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let mut focused : UInt64? = None
|
||||||
|
for e in self.win_list {
|
||||||
|
if e.focused {
|
||||||
|
focused = Some(e.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match @dock.activate(items[n - 1], focused) {
|
||||||
|
Launch(id) => self.launch_catalog_app(id)
|
||||||
|
Focus(win) => self.actions.push(FocusWindow(win))
|
||||||
|
Nothing => ()
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| A left click on the dock in `w` at (x, y): the empty dock's "+" opens the Applications menu,
|
||||||
|
/// where right-clicking an app pins it. True when the shell took the click.
|
||||||
|
fn DesktopShell::dock_click(self : DesktopShell, w : Widget) -> Bool {
|
||||||
|
if !w.is_dock() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let (_, items) = self.dock_state(w)
|
||||||
|
if items.length() > 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
self.toggle_launcher()
|
||||||
|
true
|
||||||
|
}
|
||||||
@@ -351,6 +351,9 @@ pub(all) struct DesktopShell {
|
|||||||
wit_cache : Map[String, String]
|
wit_cache : Map[String, String]
|
||||||
/// Most-recently-launched app ids, newest first (persisted).
|
/// Most-recently-launched app ids, newest first (persisted).
|
||||||
recents : Array[String]
|
recents : Array[String]
|
||||||
|
/// The launcher module's state as the shell follows it (dock.mbt `follow_launcher`): what its
|
||||||
|
/// popup lists, for the right-click "Pin to dock" menu.
|
||||||
|
launcher_state : @launcher.State
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -459,6 +462,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
|||||||
comps: [],
|
comps: [],
|
||||||
wit_cache: {},
|
wit_cache: {},
|
||||||
recents: [],
|
recents: [],
|
||||||
|
launcher_state: @launcher.State::new(),
|
||||||
}
|
}
|
||||||
sh.order_apps()
|
sh.order_apps()
|
||||||
sh
|
sh
|
||||||
@@ -634,6 +638,9 @@ fn DesktopShell::deliver(self : DesktopShell, w : Widget, popup : Bool, ev : @wa
|
|||||||
// The module may have unloaded itself (or been replaced) while handling the event.
|
// The module may have unloaded itself (or been replaced) while handling the event.
|
||||||
if self.widget_by_slot(w.slot) is Some(_) {
|
if self.widget_by_slot(w.slot) is Some(_) {
|
||||||
self.refresh_popup(w)
|
self.refresh_popup(w)
|
||||||
|
if w.module_id == launcher_module {
|
||||||
|
self.follow_launcher(w, popup, ev)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
changed
|
changed
|
||||||
}
|
}
|
||||||
@@ -780,6 +787,7 @@ pub fn DesktopShell::pointer_up(self : DesktopShell) -> Bool {
|
|||||||
self.save_panel_config()
|
self.save_panel_config()
|
||||||
} else {
|
} else {
|
||||||
match self.widget_by_slot(slot) {
|
match self.widget_by_slot(slot) {
|
||||||
|
Some(w) if self.dock_click(w) => ()
|
||||||
Some(w) => ignore(self.deliver(w, false, PointerDown(self.drag_x0 - w.rect.x, self.drag_y0 - w.rect.y)))
|
Some(w) => ignore(self.deliver(w, false, PointerDown(self.drag_x0 - w.rect.x, self.drag_y0 - w.rect.y)))
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ pub(all) enum ShortcutAction {
|
|||||||
RecordRegion
|
RecordRegion
|
||||||
RecordScreen
|
RecordScreen
|
||||||
RecordWindow
|
RecordWindow
|
||||||
|
/// The dock's apps by number: the combo opens the first, the same modifiers with 2 .. 9 the
|
||||||
|
/// second to ninth (when the combo's key is 1). Like clicking the icon: start the app or bring
|
||||||
|
/// its windows forward. See `Shortcuts::dock_app`.
|
||||||
|
DockApps
|
||||||
} derive(Eq, Debug)
|
} derive(Eq, Debug)
|
||||||
|
|
||||||
///| One row of the shortcut table.
|
///| One row of the shortcut table.
|
||||||
@@ -77,6 +81,7 @@ pub let shortcut_table : Array[ShortcutDef] = [
|
|||||||
{ id: "record-region", label: "Record a region", action: RecordRegion, default_text: "Super+Shift+R" },
|
{ id: "record-region", label: "Record a region", action: RecordRegion, default_text: "Super+Shift+R" },
|
||||||
{ id: "record-screen", label: "Record the screen", action: RecordScreen, default_text: "Super+Alt+R" },
|
{ id: "record-screen", label: "Record the screen", action: RecordScreen, default_text: "Super+Alt+R" },
|
||||||
{ id: "record-window", label: "Record a window", action: RecordWindow, default_text: "Super+Ctrl+R" },
|
{ id: "record-window", label: "Record a window", action: RecordWindow, default_text: "Super+Ctrl+R" },
|
||||||
|
{ id: "dock-apps", label: "Open dock app 1-9", action: DockApps, default_text: "Super+1" },
|
||||||
]
|
]
|
||||||
|
|
||||||
///| evdev code -> key name, for the keys a combo can end in (US layout names).
|
///| evdev code -> key name, for the keys a combo can end in (US layout names).
|
||||||
@@ -487,3 +492,42 @@ pub fn DesktopShell::publish_shortcuts(self : DesktopShell) -> Unit {
|
|||||||
}
|
}
|
||||||
@wasm.publish(Shortcuts, t)
|
@wasm.publish(Shortcuts, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| evdev codes of the 1 and 9 keys (the row above the letters).
|
||||||
|
let key_1 : UInt = 2
|
||||||
|
|
||||||
|
///|
|
||||||
|
let key_9 : UInt = 10
|
||||||
|
|
||||||
|
///| Which of the dock's apps (1-9) `combo` opens: the "Open dock app" combo itself is the first,
|
||||||
|
/// and when that combo ends in 1, the same modifiers with 2 .. 9 open the second to ninth.
|
||||||
|
pub fn Shortcuts::dock_app(self : Shortcuts, combo : KeyCombo) -> Int? {
|
||||||
|
let mods = combo.mods & combo_mods
|
||||||
|
for i = 0; i < self.bindings.length(); i = i + 1 {
|
||||||
|
if shortcut_table[i].action == DockApps {
|
||||||
|
match self.bindings[i] {
|
||||||
|
Some(c) if c.mods == mods => {
|
||||||
|
if c.key == key_1 && combo.key >= key_1 && combo.key <= key_9 {
|
||||||
|
return Some((combo.key - key_1).reinterpret_as_int() + 1)
|
||||||
|
}
|
||||||
|
if same_key(c.key, combo.key) {
|
||||||
|
return Some(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "Super+1 .. Super+9 open the dock's apps" {
|
||||||
|
let sc = Shortcuts::defaults()
|
||||||
|
assert_eq(sc.dock_app({ mods: mod_logo, key: 2 }), Some(1))
|
||||||
|
assert_eq(sc.dock_app({ mods: mod_logo, key: 6 }), Some(5))
|
||||||
|
assert_eq(sc.dock_app({ mods: mod_logo, key: 10 }), Some(9))
|
||||||
|
assert_eq(sc.dock_app({ mods: mod_logo, key: 11 }), None) // 0
|
||||||
|
assert_eq(sc.dock_app({ mods: mod_logo | mod_shift, key: 3 }), None)
|
||||||
|
assert_eq(sc.dock_app({ mods: 0, key: 3 }), None)
|
||||||
|
}
|
||||||
@@ -11,9 +11,10 @@
|
|||||||
/// and opens that tab. A module may also export `module-config`: its own settings, listed under
|
/// and opens that tab. A module may also export `module-config`: its own settings, listed under
|
||||||
/// "Module settings..." in its right-click menu and remembered in state.edn (module_config.mbt).
|
/// "Module settings..." in its right-click menu and remembered in state.edn (module_config.mbt).
|
||||||
|
|
||||||
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
|
///| Modules loaded into a fresh panel, in order. The dock (pinned and running apps, the task
|
||||||
|
/// manager) stretches, so what follows it packs right.
|
||||||
let default_panel : Array[String] = [
|
let default_panel : Array[String] = [
|
||||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital", "screenshot",
|
"launcher", "inspector", "layout", "dock", "moon-disc", "network", "clock-digital", "screenshot",
|
||||||
"session-settings",
|
"session-settings",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -47,9 +48,13 @@ test "a fresh panel gets the battery module only on a machine with a battery" {
|
|||||||
/// - logout, the Log out button, is the Application Launcher's session row (Reload, Log out,
|
/// - logout, the Log out button, is the Application Launcher's session row (Reload, Log out,
|
||||||
/// Suspend, Restart, Power off). A saved panel drops it, or gets the launcher in its place when
|
/// Suspend, Restart, Power off). A saved panel drops it, or gets the launcher in its place when
|
||||||
/// it had none (migrate_panel).
|
/// it had none (migrate_panel).
|
||||||
|
/// - tasks, the Task Manager's window pills, is the dock: pinned and running apps, titled pills
|
||||||
|
/// when there is room, each window's menu. A saved panel with both keeps one dock, where the
|
||||||
|
/// task list was (migrate_panel); the dock's pins carry over (they are the dock's own setting).
|
||||||
let retired_modules : Map[String, String] = {
|
let retired_modules : Map[String, String] = {
|
||||||
"clock-digital12": "clock-digital",
|
"clock-digital12": "clock-digital",
|
||||||
"logout": "launcher",
|
"logout": "launcher",
|
||||||
|
"tasks": "dock",
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The id a module goes by now ("clock-digital12" -> "clock-digital").
|
///| The id a module goes by now ("clock-digital12" -> "clock-digital").
|
||||||
@@ -105,7 +110,7 @@ fn stem(path : String) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The WIT world ("clock-widget", "taskbar-widget", ...) a module was built for, read from the
|
///| The WIT world ("clock-widget", "dock-widget", ...) a module was built for, read from the
|
||||||
/// `<name>.meta.json` that build-modules.sh writes next to it; "" when unknown (a module loaded
|
/// `<name>.meta.json` that build-modules.sh writes next to it; "" when unknown (a module loaded
|
||||||
/// from elsewhere). Two modules are interchangeable only when their worlds match.
|
/// from elsewhere). Two modules are interchangeable only when their worlds match.
|
||||||
fn module_world(path : String) -> String {
|
fn module_world(path : String) -> String {
|
||||||
@@ -222,12 +227,21 @@ fn wall_secs() -> Int {
|
|||||||
/// module list "wallpaper" or "module-manager": the settings module takes the first one's place
|
/// module list "wallpaper" or "module-manager": the settings module takes the first one's place
|
||||||
/// (a panel that already has it just drops them). The Log out button moved into the launcher the
|
/// (a panel that already has it just drops them). The Log out button moved into the launcher the
|
||||||
/// same way: "logout" becomes the launcher when the panel has none, else it is dropped. Other
|
/// same way: "logout" becomes the launcher when the panel has none, else it is dropped. Other
|
||||||
/// retired modules (clock-digital12) become the module that replaced them.
|
/// retired modules (clock-digital12) become the module that replaced them; the task list and the
|
||||||
|
/// dock become one dock, in the task list's place.
|
||||||
fn migrate_panel(entries : Array[String]) -> Array[String] {
|
fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||||
let has_settings = entries.contains("session-settings")
|
let has_settings = entries.contains("session-settings")
|
||||||
let has_launcher = entries.contains("launcher")
|
let has_launcher = entries.contains("launcher")
|
||||||
|
// One dock, where the task list was when there was one (it sat in the stretching place).
|
||||||
|
let dock_at = match entries.search("tasks") {
|
||||||
|
Some(i) => i
|
||||||
|
None => entries.search("dock").unwrap_or(-1)
|
||||||
|
}
|
||||||
let out : Array[String] = []
|
let out : Array[String] = []
|
||||||
for e in entries {
|
for i, e in entries {
|
||||||
|
if (e == "tasks" || e == "dock") && i != dock_at {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if e == "wallpaper" || e == "module-manager" {
|
if e == "wallpaper" || e == "module-manager" {
|
||||||
if !has_settings && !out.contains("session-settings") {
|
if !has_settings && !out.contains("session-settings") {
|
||||||
out.push("session-settings")
|
out.push("session-settings")
|
||||||
@@ -251,9 +265,17 @@ test "a saved panel's wallpaper button becomes the settings module" {
|
|||||||
assert_eq(migrate_panel(["clock"]), ["clock"])
|
assert_eq(migrate_panel(["clock"]), ["clock"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "a saved panel's task list and dock become one dock, in the task list's place" {
|
||||||
|
assert_eq(migrate_panel(["launcher", "tasks", "clock-digital", "dock"]), ["launcher", "dock", "clock-digital"])
|
||||||
|
assert_eq(migrate_panel(["dock", "launcher", "tasks"]), ["launcher", "dock"])
|
||||||
|
assert_eq(migrate_panel(["launcher", "dock", "clock-digital"]), ["launcher", "dock", "clock-digital"])
|
||||||
|
assert_eq(current_module_id("tasks"), "dock")
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
test "a saved panel's 12-hour clock becomes the digital clock" {
|
test "a saved panel's 12-hour clock becomes the digital clock" {
|
||||||
assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["tasks", "clock-digital", "launcher"])
|
assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["dock", "clock-digital", "launcher"])
|
||||||
assert_eq(current_module_id("clock-digital12"), "clock-digital")
|
assert_eq(current_module_id("clock-digital12"), "clock-digital")
|
||||||
assert_eq(current_module_id("clock-binary"), "clock-binary")
|
assert_eq(current_module_id("clock-binary"), "clock-binary")
|
||||||
}
|
}
|
||||||
@@ -262,10 +284,10 @@ test "a saved panel's 12-hour clock becomes the digital clock" {
|
|||||||
test "a saved panel's Log out button folds into the launcher" {
|
test "a saved panel's Log out button folds into the launcher" {
|
||||||
// The launcher's session row has Log out now: the old button is dropped...
|
// The launcher's session row has Log out now: the old button is dropped...
|
||||||
assert_eq(migrate_panel(["launcher", "tasks", "session-settings", "logout"]), [
|
assert_eq(migrate_panel(["launcher", "tasks", "session-settings", "logout"]), [
|
||||||
"launcher", "tasks", "session-settings",
|
"launcher", "dock", "session-settings",
|
||||||
])
|
])
|
||||||
// ...or becomes the launcher on a panel without one, so Log out stays reachable.
|
// ...or becomes the launcher on a panel without one, so Log out stays reachable.
|
||||||
assert_eq(migrate_panel(["tasks", "logout"]), ["tasks", "launcher"])
|
assert_eq(migrate_panel(["tasks", "logout"]), ["dock", "launcher"])
|
||||||
assert_eq(migrate_panel(["logout", "launcher"]), ["launcher"])
|
assert_eq(migrate_panel(["logout", "launcher"]), ["launcher"])
|
||||||
assert_false(default_panel.contains("logout"))
|
assert_false(default_panel.contains("logout"))
|
||||||
}
|
}
|
||||||
@@ -945,8 +967,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 window's pill in the task manager that window's menu (Minimize or Restore,
|
///| Right-click: on an app in the open Applications menu its Open / Pin to dock menu; on an app in
|
||||||
/// Maximize, Quit); on a module its menu (Module settings, System settings, replace, remove); on
|
/// the dock its menu (dock.mbt); 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()
|
||||||
@@ -955,12 +977,16 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool
|
|||||||
}
|
}
|
||||||
let was_open = self.menu_open
|
let was_open = self.menu_open
|
||||||
self.menu_open = false
|
self.menu_open = false
|
||||||
|
// An app in the open Applications menu: Open, Pin to dock. The menu stays open behind it.
|
||||||
|
match self.launcher_app_at(x, y) {
|
||||||
|
Some(app) => {
|
||||||
|
self.open_app_menu(app, x)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
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) if self.dock_item_at(w, x, y) is Some((items, i)) => {
|
Some(w) if self.dock_item_at(w, x, y) is Some((items, i)) => {
|
||||||
self.open_dock_menu(w, items, i, x)
|
self.open_dock_menu(w, items, i, x)
|
||||||
true
|
true
|
||||||
@@ -1002,43 +1028,6 @@ 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] {
|
||||||
|
|||||||
@@ -122,72 +122,6 @@ test "a module's own settings (module-config) are listed and set through wasmer"
|
|||||||
l.unload()
|
l.unload()
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
|
||||||
test "task list module draws the host's windows and asks to focus one" {
|
|
||||||
let p = load_module("tasks")
|
|
||||||
assert_true(p.stretch)
|
|
||||||
assert_true(p.imports().contains("windows") && p.imports().contains("theme"))
|
|
||||||
let t = Table::new()
|
|
||||||
t.int(7)
|
|
||||||
t.str("Kate — notes")
|
|
||||||
t.int(1)
|
|
||||||
t.int(0)
|
|
||||||
t.end_row()
|
|
||||||
t.int(9)
|
|
||||||
t.str("foot")
|
|
||||||
t.int(0)
|
|
||||||
t.int(1)
|
|
||||||
t.end_row()
|
|
||||||
publish(Windows, t)
|
|
||||||
// Icons come from each window's app id (served by `windows.all`); without one, from the title.
|
|
||||||
set_windows([{ id: 9UL, title: "foot", app_id: "org.chandra.term", focused: false }])
|
|
||||||
let ops = p.render(400, 36, test_tokens())
|
|
||||||
// each pill: the app icon's glyph, then the title
|
|
||||||
assert_eq(texts_of(ops), ["K", "Kate — notes", "T", "foot"])
|
|
||||||
set_windows([])
|
|
||||||
assert_true(p.on_event(false, PointerDown(146 + 10, 10)) || true)
|
|
||||||
assert_eq(drain(), [FocusWindow(9)])
|
|
||||||
p.unload()
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
|
||||||
test "task list draws the host's icon for an app it has one for, the letter tile otherwise" {
|
|
||||||
let p = load_module("tasks")
|
|
||||||
assert_true(p.imports().contains("icons"))
|
|
||||||
let t = Table::new()
|
|
||||||
for w in [(3, "Firefox"), (4, "foot")] {
|
|
||||||
t.int(w.0)
|
|
||||||
t.str(w.1)
|
|
||||||
t.int(0)
|
|
||||||
t.int(0)
|
|
||||||
t.end_row()
|
|
||||||
}
|
|
||||||
publish(Windows, t)
|
|
||||||
set_windows([
|
|
||||||
{ id: 3UL, title: "Firefox", app_id: "firefox", focused: false },
|
|
||||||
{ id: 4UL, title: "foot", app_id: "foot", focused: false },
|
|
||||||
])
|
|
||||||
let icons = Table::new()
|
|
||||||
icons.str("firefox")
|
|
||||||
icons.int(42)
|
|
||||||
icons.end_row()
|
|
||||||
publish(Icons, icons)
|
|
||||||
let ops = p.render(400, 36, test_tokens())
|
|
||||||
let images = ops.filter_map(op => match op {
|
|
||||||
Image(i) => Some(i)
|
|
||||||
_ => None
|
|
||||||
})
|
|
||||||
// Firefox: the icon (handle 42, a 22px square centred in the bar), no glyph; foot: the tile.
|
|
||||||
assert_eq(images.length(), 1)
|
|
||||||
assert_eq(images[0].image, 42U)
|
|
||||||
assert_eq((images[0].rect.w, images[0].rect.h), (22U, 22U))
|
|
||||||
assert_eq(images[0].rect.y, 7)
|
|
||||||
assert_eq(texts_of(ops), ["Firefox", "F", "foot"])
|
|
||||||
publish(Icons, Table::new())
|
|
||||||
set_windows([])
|
|
||||||
p.unload()
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
///|
|
||||||
test "layout module is a tile/float toggle" {
|
test "layout module is a tile/float toggle" {
|
||||||
let p = load_module("layout")
|
let p = load_module("layout")
|
||||||
|
|||||||
@@ -953,38 +953,6 @@ mod tests {
|
|||||||
rt.unload(h);
|
rt.unload(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn task_list_draws_the_published_icon_handle_else_the_letter_tile() {
|
|
||||||
let mut rt = runtime();
|
|
||||||
let l = rt.load(&module("tasks")).expect("tasks loads");
|
|
||||||
assert!(l.imports.contains(&"icons".to_string()));
|
|
||||||
// windows table (isii: id title focused minimized) and the richer windows.all view
|
|
||||||
let mut t = 2u32.to_le_bytes().to_vec();
|
|
||||||
for (id, title) in [(3i32, "Firefox"), (4, "foot")] {
|
|
||||||
t.extend(id.to_le_bytes());
|
|
||||||
t.extend((title.len() as u32).to_le_bytes());
|
|
||||||
t.extend(title.as_bytes());
|
|
||||||
t.extend(0i32.to_le_bytes());
|
|
||||||
t.extend(0i32.to_le_bytes());
|
|
||||||
}
|
|
||||||
// icons table (si: app id, image handle): only Firefox has one
|
|
||||||
let mut ic = 1u32.to_le_bytes().to_vec();
|
|
||||||
ic.extend(7u32.to_le_bytes());
|
|
||||||
ic.extend(b"firefox");
|
|
||||||
ic.extend(42i32.to_le_bytes());
|
|
||||||
{
|
|
||||||
let mut sh = rt.shared.borrow_mut();
|
|
||||||
sh.tables[T_WINDOWS] = t;
|
|
||||||
sh.tables[T_ICONS] = ic;
|
|
||||||
sh.windows = vec![(3, "Firefox".into(), "firefox".into(), false), (4, "foot".into(), "foot".into(), false)];
|
|
||||||
}
|
|
||||||
let ops = rt.render(l.handle, Size { w: 400, h: 36 });
|
|
||||||
let images: Vec<u32> =
|
|
||||||
ops.iter().filter_map(|o| if let d::types::DrawOp::Image(i) = o { Some(i.image) } else { None }).collect();
|
|
||||||
assert_eq!(images, [42]);
|
|
||||||
assert_eq!(texts(&ops), ["Firefox", "F", "foot"]);
|
|
||||||
rt.unload(l.handle);
|
|
||||||
}
|
|
||||||
#[test]
|
#[test]
|
||||||
fn screenshot_module_offers_the_modes_and_asks_for_them() {
|
fn screenshot_module_offers_the_modes_and_asks_for_them() {
|
||||||
let mut rt = runtime();
|
let mut rt = runtime();
|
||||||
|
|||||||
+217
-52
@@ -36,11 +36,13 @@ pub(all) struct DockConfig {
|
|||||||
mut magnify : Bool
|
mut magnify : Bool
|
||||||
/// Show apps that run but aren't pinned.
|
/// Show apps that run but aren't pinned.
|
||||||
mut running : Bool
|
mut running : Bool
|
||||||
|
/// Draw apps that have windows as pills with a title, like a task list, when there is room.
|
||||||
|
mut titles : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
pub fn DockConfig::new() -> DockConfig {
|
pub fn DockConfig::new() -> DockConfig {
|
||||||
{ pinned: None, size: "Medium", magnify: true, running: true }
|
{ pinned: None, size: "Medium", magnify: true, running: true, titles: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
///| A config built from saved key/value pairs (what the shell reads back from the module).
|
///| A config built from saved key/value pairs (what the shell reads back from the module).
|
||||||
@@ -94,6 +96,7 @@ pub fn DockConfig::items(self : DockConfig) -> Array[ConfigEntry] {
|
|||||||
{ key: "icon-size", label: "Icon size", choices: size_choices, value: self.size },
|
{ key: "icon-size", label: "Icon size", choices: size_choices, value: self.size },
|
||||||
{ key: "magnify", label: "Magnify icons under the pointer", choices: [], value: on_off(self.magnify) },
|
{ key: "magnify", label: "Magnify icons under the pointer", choices: [], value: on_off(self.magnify) },
|
||||||
{ key: "running", label: "Show running apps that aren't pinned", choices: [], value: on_off(self.running) },
|
{ key: "running", label: "Show running apps that aren't pinned", choices: [], value: on_off(self.running) },
|
||||||
|
{ key: "titles", label: "Show window titles", choices: [], value: on_off(self.titles) },
|
||||||
{
|
{
|
||||||
key: "pinned",
|
key: "pinned",
|
||||||
label: "",
|
label: "",
|
||||||
@@ -131,6 +134,7 @@ pub fn DockConfig::set(self : DockConfig, key : String, value : String) -> Bool
|
|||||||
}
|
}
|
||||||
"magnify" => flag(self.magnify, b => self.magnify = b)
|
"magnify" => flag(self.magnify, b => self.magnify = b)
|
||||||
"running" => flag(self.running, b => self.running = b)
|
"running" => flag(self.running, b => self.running = b)
|
||||||
|
"titles" => flag(self.titles, b => self.titles = b)
|
||||||
"pinned" => {
|
"pinned" => {
|
||||||
let p = decode_pins(value)
|
let p = decode_pins(value)
|
||||||
if p != self.pinned {
|
if p != self.pinned {
|
||||||
@@ -170,6 +174,8 @@ pub(all) struct DockWindow {
|
|||||||
id : UInt64
|
id : UInt64
|
||||||
app_id : String
|
app_id : String
|
||||||
focused : Bool
|
focused : Bool
|
||||||
|
title : String
|
||||||
|
minimized : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
///| One icon in the dock.
|
///| One icon in the dock.
|
||||||
@@ -184,6 +190,10 @@ pub(all) struct DockItem {
|
|||||||
windows : Array[UInt64]
|
windows : Array[UInt64]
|
||||||
/// One of its windows has focus.
|
/// One of its windows has focus.
|
||||||
focused : Bool
|
focused : Bool
|
||||||
|
/// The title of its newest window ("" without windows).
|
||||||
|
title : String
|
||||||
|
/// How many of its windows are minimized.
|
||||||
|
minimized : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The id among `ids` of the app whose windows carry `app_id`: the same id, the same ignoring
|
///| The id among `ids` of the app whose windows carry `app_id`: the same id, the same ignoring
|
||||||
@@ -237,6 +247,29 @@ pub fn match_name(app_id : String, apps : Array[@types.AppEntry]) -> String? {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| The dock id of the app whose windows carry `app_id`: a pinned app (`pins`), else a catalog
|
||||||
|
/// app, by id or by name, else `app_id` itself. None for windows without an app id. The shell
|
||||||
|
/// uses it to pin a window's app from the task list's menu.
|
||||||
|
pub fn owner_of(
|
||||||
|
app_id : String,
|
||||||
|
pins : Array[String],
|
||||||
|
apps : Array[@types.AppEntry],
|
||||||
|
catalog_ids? : Array[String] = apps.map(a => a.id),
|
||||||
|
) -> String? {
|
||||||
|
match match_app(app_id, pins) {
|
||||||
|
Some(id) => Some(id)
|
||||||
|
None =>
|
||||||
|
match match_app(app_id, catalog_ids) {
|
||||||
|
Some(id) => Some(id)
|
||||||
|
None =>
|
||||||
|
match match_name(app_id, apps) {
|
||||||
|
Some(id) => Some(id)
|
||||||
|
None => if app_id.length() > 0 { Some(app_id) } else { None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///| The dock's icons: the pinned apps in their order, then the other running apps in the order
|
///| The dock's icons: the pinned apps in their order, then the other running apps in the order
|
||||||
/// they first opened a window (when `cfg.running`). Windows without an app id aren't shown.
|
/// they first opened a window (when `cfg.running`). Windows without an app id aren't shown.
|
||||||
pub fn items(
|
pub fn items(
|
||||||
@@ -256,11 +289,11 @@ pub fn items(
|
|||||||
let index : Map[String, Int] = Map([])
|
let index : Map[String, Int] = Map([])
|
||||||
let make = fn(id : String, pinned : Bool) -> DockItem {
|
let make = fn(id : String, pinned : Bool) -> DockItem {
|
||||||
match by_id.get(id) {
|
match by_id.get(id) {
|
||||||
Some(a) => { id, name: a.name, glyph: a.glyph, pinned, windows: [], focused: false }
|
Some(a) => { id, name: a.name, glyph: a.glyph, pinned, windows: [], focused: false, title: "", minimized: 0 }
|
||||||
None => {
|
None => {
|
||||||
let parts = id.split(".").to_array()
|
let parts = id.split(".").to_array()
|
||||||
let name = parts[parts.length() - 1].to_string()
|
let name = parts[parts.length() - 1].to_string()
|
||||||
{ id, name, glyph: app_glyph(id, id), pinned, windows: [], focused: false }
|
{ id, name, glyph: app_glyph(id, id), pinned, windows: [], focused: false, title: "", minimized: 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,19 +304,7 @@ pub fn items(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for w in sorted {
|
for w in sorted {
|
||||||
let owner = match match_app(w.app_id, pins) {
|
match owner_of(w.app_id, pins, apps, catalog_ids~) {
|
||||||
Some(id) => Some(id)
|
|
||||||
None =>
|
|
||||||
match match_app(w.app_id, catalog_ids) {
|
|
||||||
Some(id) => Some(id)
|
|
||||||
None =>
|
|
||||||
match match_name(w.app_id, apps) {
|
|
||||||
Some(id) => Some(id)
|
|
||||||
None => if w.app_id.length() > 0 { Some(w.app_id) } else { None }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match owner {
|
|
||||||
None => ()
|
None => ()
|
||||||
Some(id) => {
|
Some(id) => {
|
||||||
let i = match index.get(id) {
|
let i = match index.get(id) {
|
||||||
@@ -299,8 +320,11 @@ pub fn items(
|
|||||||
}
|
}
|
||||||
let it = out[i]
|
let it = out[i]
|
||||||
it.windows.push(w.id)
|
it.windows.push(w.id)
|
||||||
if w.focused {
|
out[i] = {
|
||||||
out[i] = { ..it, focused: true }
|
..it,
|
||||||
|
focused: it.focused || w.focused,
|
||||||
|
title: w.title,
|
||||||
|
minimized: it.minimized + (if w.minimized { 1 } else { 0 }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,6 +342,10 @@ fn first_running(items : Array[DockItem]) -> Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- geometry
|
// ---------------------------------------------------------------- geometry
|
||||||
|
//
|
||||||
|
// Icons sit in a row. With window titles on, an app that has windows gets a pill: its icon and a
|
||||||
|
// title (its window's, or its name and window count), like the task list's pills. When the row
|
||||||
|
// doesn't fit the pills shrink, down to `label_min`, then drop their titles.
|
||||||
|
|
||||||
///| Side padding of the whole dock, and the room between two icons.
|
///| Side padding of the whole dock, and the room between two icons.
|
||||||
let pad : Int = 6
|
let pad : Int = 6
|
||||||
@@ -331,6 +359,12 @@ let divider_w : Int = 11
|
|||||||
///| Rows of pixels kept free under the icons for the window dots.
|
///| Rows of pixels kept free under the icons for the window dots.
|
||||||
let dots_h : Int = 6
|
let dots_h : Int = 6
|
||||||
|
|
||||||
|
///| Widest and narrowest a titled pill gets (narrower than that: just the icon).
|
||||||
|
pub let label_max : Int = 150
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let label_min : Int = 84
|
||||||
|
|
||||||
///| Icon edge for the chosen size in a dock `h` pixels tall.
|
///| Icon edge for the chosen size in a dock `h` pixels tall.
|
||||||
pub fn icon_size(cfg : DockConfig, h : Int) -> Int {
|
pub fn icon_size(cfg : DockConfig, h : Int) -> Int {
|
||||||
let want = match cfg.size {
|
let want = match cfg.size {
|
||||||
@@ -347,55 +381,106 @@ pub fn icon_size(cfg : DockConfig, h : Int) -> Int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///| Distance between icon centres.
|
///| Width of every item's slot in a dock `w` wide (`w` < 0: as wide as they like).
|
||||||
fn pitch(cfg : DockConfig, h : Int) -> Int {
|
fn widths(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int) -> Array[Int] {
|
||||||
icon_size(cfg, h) + gap
|
let base = icon_size(cfg, h)
|
||||||
|
let titled = items.map(it => cfg.titles && it.windows.length() > 0)
|
||||||
|
let n = items.length()
|
||||||
|
let split = first_running(items)
|
||||||
|
let fixed = 2 * pad + (if n > 1 { (n - 1) * gap } else { 0 }) +
|
||||||
|
(if split > 0 && split < n { divider_w } else { 0 })
|
||||||
|
let mut nt = 0
|
||||||
|
for t in titled {
|
||||||
|
if t {
|
||||||
|
nt = nt + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let icons_w = (n - nt) * base
|
||||||
|
let lw = if nt == 0 || w < 0 {
|
||||||
|
label_max
|
||||||
|
} else {
|
||||||
|
let fit = (w - fixed - icons_w) / nt
|
||||||
|
if fit > label_max {
|
||||||
|
label_max
|
||||||
|
} else {
|
||||||
|
fit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let lw = if lw < label_min { base } else { lw }
|
||||||
|
titled.map(t => if t { lw } else { base })
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Whether item `i` is drawn as a titled pill in a dock `w` wide (the shell then shows no
|
||||||
|
/// hover label over it: the pill already says what it is).
|
||||||
|
pub fn titled_at(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, i : Int) -> Bool {
|
||||||
|
widths(items, cfg, w, h)[i] > icon_size(cfg, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
///| Left edge of item `i`'s slot.
|
///| Left edge of item `i`'s slot.
|
||||||
fn slot_x(items : Array[DockItem], cfg : DockConfig, h : Int, i : Int) -> Int {
|
fn slot_x(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, i : Int) -> Int {
|
||||||
|
let ws = widths(items, cfg, w, h)
|
||||||
let split = first_running(items)
|
let split = first_running(items)
|
||||||
let extra = if i >= split && split > 0 { divider_w } else { 0 }
|
let mut x = pad
|
||||||
pad + i * pitch(cfg, h) + extra
|
for j = 0; j < i; j = j + 1 {
|
||||||
|
x = x + ws[j] + gap
|
||||||
|
}
|
||||||
|
if i >= split && split > 0 {
|
||||||
|
x = x + divider_w
|
||||||
|
}
|
||||||
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
///| Width that shows every item.
|
///| Width that shows every item (titles at their widest).
|
||||||
pub fn preferred_width(items : Array[DockItem], cfg : DockConfig, h : Int) -> Int {
|
pub fn preferred_width(items : Array[DockItem], cfg : DockConfig, h : Int) -> Int {
|
||||||
let n = items.length()
|
let n = items.length()
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return 80
|
return empty_width
|
||||||
}
|
}
|
||||||
slot_x(items, cfg, h, n - 1) + icon_size(cfg, h) + pad
|
slot_x(items, cfg, -1, h, n - 1) + widths(items, cfg, -1, h)[n - 1] + pad
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| Width of the empty dock: its "+" tile and hint.
|
||||||
|
let empty_width : Int = 150
|
||||||
|
|
||||||
///| How many items fit in a dock `w` wide.
|
///| How many items fit in a dock `w` wide.
|
||||||
fn visible(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int) -> Int {
|
fn visible(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int) -> Int {
|
||||||
|
let ws = widths(items, cfg, w, h)
|
||||||
let mut n = 0
|
let mut n = 0
|
||||||
while n < items.length() && slot_x(items, cfg, h, n) + icon_size(cfg, h) + pad <= w {
|
while n < items.length() && slot_x(items, cfg, w, h, n) + ws[n] + pad <= w {
|
||||||
n = n + 1
|
n = n + 1
|
||||||
}
|
}
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The item under dock-local (x, y), or -1. The gap after an icon belongs to it, so the pointer
|
///| The width the row of items takes in a dock `w` wide (its backing is drawn that wide).
|
||||||
|
fn used_width(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int) -> Int {
|
||||||
|
let n = visible(items, cfg, w, h)
|
||||||
|
if n == 0 {
|
||||||
|
return if items.length() == 0 { empty_width } else { 0 }
|
||||||
|
}
|
||||||
|
slot_x(items, cfg, w, h, n - 1) + widths(items, cfg, w, h)[n - 1] + pad
|
||||||
|
}
|
||||||
|
|
||||||
|
///| The item under dock-local (x, y), or -1. The gap after an item belongs to it, so the pointer
|
||||||
/// never drops off the dock between two icons.
|
/// never drops off the dock between two icons.
|
||||||
pub fn item_at(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, x : Int, y : Int) -> Int {
|
pub fn item_at(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, x : Int, y : Int) -> Int {
|
||||||
if y < 0 || y >= h || x < 0 || x >= w {
|
if y < 0 || y >= h || x < 0 || x >= w {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
let n = visible(items, cfg, w, h)
|
let n = visible(items, cfg, w, h)
|
||||||
|
let ws = widths(items, cfg, w, h)
|
||||||
for i = 0; i < n; i = i + 1 {
|
for i = 0; i < n; i = i + 1 {
|
||||||
let x0 = slot_x(items, cfg, h, i)
|
let x0 = slot_x(items, cfg, w, h, i)
|
||||||
if x >= x0 - gap / 2 && x < x0 + pitch(cfg, h) - gap / 2 {
|
if x >= x0 - gap / 2 && x < x0 + ws[i] + gap - gap / 2 {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
|
|
||||||
///| Centre x of item `i`, dock-local (for the shell's hover label and menu).
|
///| Centre x of item `i` in a dock `w` wide, dock-local (for the shell's hover label and menu).
|
||||||
pub fn item_center(items : Array[DockItem], cfg : DockConfig, h : Int, i : Int) -> Int {
|
pub fn item_center(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, i : Int) -> Int {
|
||||||
slot_x(items, cfg, h, i) + icon_size(cfg, h) / 2
|
slot_x(items, cfg, w, h, i) + widths(items, cfg, w, h)[i] / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
///| Edge of item `i`'s icon with `hover` the item under the pointer (-1: none): the hovered icon
|
///| Edge of item `i`'s icon with `hover` the item under the pointer (-1: none): the hovered icon
|
||||||
@@ -484,6 +569,26 @@ pub fn app_icon(
|
|||||||
|
|
||||||
// ---------------------------------------------------------------- drawing
|
// ---------------------------------------------------------------- drawing
|
||||||
|
|
||||||
|
///| What the empty dock shows: a "+" tile and a hint. A click on it opens the Applications menu
|
||||||
|
/// (the shell does that: modules can't open each other), whose right-click menu pins apps.
|
||||||
|
fn render_empty(t : @theme.Tokens, cfg : DockConfig, h : Int, hot : Bool) -> Array[@types.DrawOp] {
|
||||||
|
let s = icon_size(cfg, h)
|
||||||
|
let x = pad
|
||||||
|
let y = (h - s) / 2
|
||||||
|
let fg = if hot { t.palette.foreground } else { t.palette.foreground_muted }
|
||||||
|
let r = t.radius.reinterpret_as_int()
|
||||||
|
let cx = x + s / 2
|
||||||
|
let cy = y + s / 2
|
||||||
|
let arm = s / 4
|
||||||
|
[
|
||||||
|
@ui.fill_rect(@ui.rect(x, y, s, s), @ui.with_alpha(t.palette.foreground, if hot { 40 } else { 18 }), radius=r),
|
||||||
|
@ui.stroke_rect(@ui.rect(x, y, s, s), fg, radius=r),
|
||||||
|
@ui.line(cx - arm, cy, cx + arm, cy, fg, width=2),
|
||||||
|
@ui.line(cx, cy - arm, cx, cy + arm, fg, width=2),
|
||||||
|
@ui.text(x + s + 8, h / 2, "Add apps", t.font_size.reinterpret_as_int() - 2, fg),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
///| Draw the dock into `size`. `hover` is the item under the pointer or -1; `icon` gives an app
|
///| Draw the dock into `size`. `hover` is the item under the pointer or -1; `icon` gives an app
|
||||||
/// id's theme icon handle (0: none, a letter tile is drawn).
|
/// id's theme icon handle (0: none, a letter tile is drawn).
|
||||||
pub fn render(
|
pub fn render(
|
||||||
@@ -497,41 +602,68 @@ pub fn render(
|
|||||||
let w = size.w.reinterpret_as_int()
|
let w = size.w.reinterpret_as_int()
|
||||||
let h = size.h.reinterpret_as_int()
|
let h = size.h.reinterpret_as_int()
|
||||||
let r = t.radius.reinterpret_as_int()
|
let r = t.radius.reinterpret_as_int()
|
||||||
|
// The backing hugs the items, so the rest of the panel stays clear when the dock stretches.
|
||||||
|
let bw = used_width(items, cfg, w, h)
|
||||||
let ops : Array[@types.DrawOp] = [
|
let ops : Array[@types.DrawOp] = [
|
||||||
@ui.fill_rect(@ui.rect(0, 0, w, h), @ui.with_alpha(t.palette.surface_hover, 150), radius=r + 4),
|
@ui.fill_rect(@ui.rect(0, 0, if bw < w { bw } else { w }, h), @ui.with_alpha(t.palette.surface_hover, 150), radius=r + 4),
|
||||||
]
|
]
|
||||||
if items.length() == 0 {
|
if items.length() == 0 {
|
||||||
ops.push(
|
ops.append(render_empty(t, cfg, h, hover >= 0))
|
||||||
@ui.text(w / 2, h / 2, "No apps", t.font_size.reinterpret_as_int() - 2, t.palette.foreground_muted, align=CENTER),
|
|
||||||
)
|
|
||||||
return ops
|
return ops
|
||||||
}
|
}
|
||||||
let n = visible(items, cfg, w, h)
|
let n = visible(items, cfg, w, h)
|
||||||
|
let ws = widths(items, cfg, w, h)
|
||||||
let base = icon_size(cfg, h)
|
let base = icon_size(cfg, h)
|
||||||
let cy = (h - dots_h) / 2 + 2
|
let cy = (h - dots_h) / 2 + 2
|
||||||
|
let fs = t.font_size.reinterpret_as_int() - 3
|
||||||
let split = first_running(items)
|
let split = first_running(items)
|
||||||
if split > 0 && split < n {
|
if split > 0 && split < n {
|
||||||
let x = slot_x(items, cfg, h, split) - gap / 2 - divider_w / 2 - 1
|
let x = slot_x(items, cfg, w, h, split) - gap / 2 - divider_w / 2 - 1
|
||||||
ops.push(@ui.fill_rect(@ui.rect(x, 6, 1, h - 12), t.palette.border))
|
ops.push(@ui.fill_rect(@ui.rect(x, 6, 1, h - 12), t.palette.border))
|
||||||
}
|
}
|
||||||
for i = 0; i < n; i = i + 1 {
|
for i = 0; i < n; i = i + 1 {
|
||||||
let it = items[i]
|
let it = items[i]
|
||||||
let s = item_size(cfg, i, hover, h)
|
let x0 = slot_x(items, cfg, w, h, i)
|
||||||
let cx = slot_x(items, cfg, h, i) + base / 2
|
let titled = ws[i] > base
|
||||||
|
let all_min = it.windows.length() > 0 && it.minimized == it.windows.length()
|
||||||
|
let mut cx = x0 + base / 2
|
||||||
|
let mut icy = cy
|
||||||
|
let mut s = base
|
||||||
|
if titled {
|
||||||
|
// A pill like the task list's: lit when the app has focus, dim when all its windows are
|
||||||
|
// minimized. The icon doesn't grow in a pill.
|
||||||
|
let bg = if it.focused {
|
||||||
|
@ui.with_alpha(t.palette.accent, 90)
|
||||||
|
} else if i == hover {
|
||||||
|
@ui.with_alpha(t.palette.foreground, 36)
|
||||||
|
} else {
|
||||||
|
@ui.with_alpha(t.palette.foreground, 14)
|
||||||
|
}
|
||||||
|
ops.push(@ui.fill_rect(@ui.rect(x0, 3, ws[i], h - 6), bg, radius=r))
|
||||||
|
cx = x0 + 6 + base / 2
|
||||||
|
icy = h / 2
|
||||||
|
let s2 = h - 14
|
||||||
|
s = if s2 < base { s2 } else { base }
|
||||||
|
let tx = cx + s / 2 + 6
|
||||||
|
let col = if all_min { t.palette.foreground_muted } else { t.palette.foreground }
|
||||||
|
ops.push(@ui.text(tx, h / 2, fit_text(item_title(it), fs, x0 + ws[i] - 6 - tx), fs, col))
|
||||||
|
} else {
|
||||||
|
s = item_size(cfg, i, hover, h)
|
||||||
// Grow upwards from the icons' common baseline so the row doesn't wobble.
|
// Grow upwards from the icons' common baseline so the row doesn't wobble.
|
||||||
let icy = cy + base / 2 - s / 2
|
icy = cy + base / 2 - s / 2
|
||||||
if i == hover {
|
if i == hover {
|
||||||
ops.push(
|
ops.push(
|
||||||
@ui.fill_rect(@ui.rect(cx - s / 2 - 3, icy - s / 2 - 3, s + 6, s + 6), @ui.with_alpha(t.palette.foreground, 36), radius=r),
|
@ui.fill_rect(@ui.rect(cx - s / 2 - 3, icy - s / 2 - 3, s + 6, s + 6), @ui.with_alpha(t.palette.foreground, 36), radius=r),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let handle = icon(it.id)
|
let handle = icon(it.id)
|
||||||
if handle != 0U {
|
if handle != 0U {
|
||||||
ops.push(Image({ rect: @ui.rect(cx - s / 2, icy - s / 2, s, s), image: handle }))
|
ops.push(Image({ rect: @ui.rect(cx - s / 2, icy - s / 2, s, s), image: handle }))
|
||||||
} else {
|
} else {
|
||||||
ops.append(app_icon(cx, icy, s, it.id, it.glyph, hover=i == hover))
|
ops.append(app_icon(cx, icy, s, it.id, it.glyph, hover=i == hover))
|
||||||
}
|
}
|
||||||
// One dot per window, up to three; lit when the app has focus.
|
// One dot per window, up to three, under the icon; lit when the app has focus.
|
||||||
let dots = if it.windows.length() > 3 { 3 } else { it.windows.length() }
|
let dots = if it.windows.length() > 3 { 3 } else { it.windows.length() }
|
||||||
let col = if it.focused { t.palette.accent } else { t.palette.foreground_muted }
|
let col = if it.focused { t.palette.accent } else { t.palette.foreground_muted }
|
||||||
let dw = if it.focused && dots == 1 { 10 } else { 4 }
|
let dw = if it.focused && dots == 1 { 10 } else { 4 }
|
||||||
@@ -544,6 +676,30 @@ pub fn render(
|
|||||||
ops
|
ops
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| The title on an app's pill: its one window's title, else its name and how many windows.
|
||||||
|
pub fn item_title(it : DockItem) -> String {
|
||||||
|
if it.windows.length() == 1 && it.title.length() > 0 {
|
||||||
|
it.title
|
||||||
|
} else if it.windows.length() > 1 {
|
||||||
|
it.name + " (" + it.windows.length().to_string() + ")"
|
||||||
|
} else {
|
||||||
|
it.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| `s` shortened with an ellipsis until it fits `max_w` pixels (at about 0.55em a character).
|
||||||
|
fn fit_text(s : String, size : Int, max_w : Int) -> String {
|
||||||
|
let cw = (size * 11 + 19) / 20
|
||||||
|
if s.length() * cw <= max_w {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
let mut n = s.length()
|
||||||
|
while n > 1 && (n + 1) * cw > max_w {
|
||||||
|
n = n - 1
|
||||||
|
}
|
||||||
|
s[:n].to_string() + "…"
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- input
|
// ---------------------------------------------------------------- input
|
||||||
|
|
||||||
///| What a pointer event asks the host to do.
|
///| What a pointer event asks the host to do.
|
||||||
@@ -582,6 +738,19 @@ pub fn click_target(it : DockItem, focused_window : UInt64?) -> UInt64? {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| What clicking `it` (or its Super+number shortcut) does: start it when it has no windows,
|
||||||
|
/// else bring its newest window forward, or step to its next one when it already has focus.
|
||||||
|
pub fn activate(it : DockItem, focused_window : UInt64?) -> DockAction {
|
||||||
|
if it.windows.length() == 0 {
|
||||||
|
Launch(it.id)
|
||||||
|
} else {
|
||||||
|
match click_target(it, focused_window) {
|
||||||
|
Some(win) => Focus(win)
|
||||||
|
None => Nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///| Pointer events -> (new hover, redraw?, action). Pure so it can be tested. `focused_window`
|
///| Pointer events -> (new hover, redraw?, action). Pure so it can be tested. `focused_window`
|
||||||
/// is the window with keyboard focus, if any.
|
/// is the window with keyboard focus, if any.
|
||||||
pub fn handle(
|
pub fn handle(
|
||||||
@@ -595,7 +764,8 @@ pub fn handle(
|
|||||||
) -> (Int, Bool, DockAction) {
|
) -> (Int, Bool, DockAction) {
|
||||||
match event {
|
match event {
|
||||||
PointerMove(p) => {
|
PointerMove(p) => {
|
||||||
let i = item_at(items, cfg, w, h, p.x, p.y)
|
// The empty dock is one target, its "+" tile (hover 0).
|
||||||
|
let i = if items.length() == 0 { 0 } else { item_at(items, cfg, w, h, p.x, p.y) }
|
||||||
(i, i != hover, Nothing)
|
(i, i != hover, Nothing)
|
||||||
}
|
}
|
||||||
PointerLeave => (-1, hover != -1, Nothing)
|
PointerLeave => (-1, hover != -1, Nothing)
|
||||||
@@ -604,14 +774,9 @@ pub fn handle(
|
|||||||
if i < 0 {
|
if i < 0 {
|
||||||
return (hover, false, Nothing)
|
return (hover, false, Nothing)
|
||||||
}
|
}
|
||||||
let it = items[i]
|
match activate(items[i], focused_window) {
|
||||||
if it.windows.length() == 0 {
|
Nothing => (i, false, Nothing)
|
||||||
(i, true, Launch(it.id))
|
a => (i, true, a)
|
||||||
} else {
|
|
||||||
match click_target(it, focused_window) {
|
|
||||||
Some(win) => (i, true, Focus(win))
|
|
||||||
None => (i, false, Nothing)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (hover, false, Nothing)
|
_ => (hover, false, Nothing)
|
||||||
|
|||||||
+69
-14
@@ -10,8 +10,8 @@ fn apps() -> Array[@types.AppEntry] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn win(id : Int, app : String, focused? : Bool = false) -> DockWindow {
|
fn win(id : Int, app : String, focused? : Bool = false, minimized? : Bool = false) -> DockWindow {
|
||||||
{ id: id.to_uint64(), app_id: app, focused }
|
{ id: id.to_uint64(), app_id: app, focused, title: app + " window", minimized }
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -41,10 +41,10 @@ fn tokens() -> @theme.Tokens {
|
|||||||
test "without a choice the dock pins the catalog's first apps; the choice round-trips" {
|
test "without a choice the dock pins the catalog's first apps; the choice round-trips" {
|
||||||
let c = DockConfig::new()
|
let c = DockConfig::new()
|
||||||
assert_eq(c.pins(apps()), ["foot", "firefox", "org.gnome.Nautilus", "gimp", "org.kde.kate"])
|
assert_eq(c.pins(apps()), ["foot", "firefox", "org.gnome.Nautilus", "gimp", "org.kde.kate"])
|
||||||
assert_eq(c.items()[3].value, "")
|
assert_eq(c.items()[4].value, "")
|
||||||
assert_true(c.set("pinned", "vlc;foot"))
|
assert_true(c.set("pinned", "vlc;foot"))
|
||||||
assert_eq(c.pins(apps()), ["vlc", "foot"])
|
assert_eq(c.pins(apps()), ["vlc", "foot"])
|
||||||
assert_eq(c.items()[3], { key: "pinned", label: "", choices: [], value: "vlc;foot" })
|
assert_eq(c.items()[4], { key: "pinned", label: "", choices: [], value: "vlc;foot" })
|
||||||
// Unpinning everything is a choice too, not "back to the defaults".
|
// Unpinning everything is a choice too, not "back to the defaults".
|
||||||
assert_true(c.set("pinned", encode_pins([])))
|
assert_true(c.set("pinned", encode_pins([])))
|
||||||
assert_eq(c.pins(apps()), [])
|
assert_eq(c.pins(apps()), [])
|
||||||
@@ -102,7 +102,7 @@ test "pinned apps come first in their order, then running ones, with their windo
|
|||||||
|
|
||||||
///|
|
///|
|
||||||
test "items are hit-tested by slot, with a divider before the running apps" {
|
test "items are hit-tested by slot, with a divider before the running apps" {
|
||||||
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
|
let c = DockConfig::from_pairs([("pinned", "foot;firefox"), ("titles", "off")])
|
||||||
let its = items(c, apps(), [win(1, "vlc")])
|
let its = items(c, apps(), [win(1, "vlc")])
|
||||||
let h = 36
|
let h = 36
|
||||||
let w = preferred_width(its, c, h)
|
let w = preferred_width(its, c, h)
|
||||||
@@ -110,12 +110,12 @@ test "items are hit-tested by slot, with a divider before the running apps" {
|
|||||||
assert_eq(item_at(its, c, w, h, 6, 10), 0)
|
assert_eq(item_at(its, c, w, h, 6, 10), 0)
|
||||||
assert_eq(item_at(its, c, w, h, 6 + p, 10), 1)
|
assert_eq(item_at(its, c, w, h, 6 + p, 10), 1)
|
||||||
// The divider shifts the running app right.
|
// The divider shifts the running app right.
|
||||||
assert_eq(item_center(its, c, h, 2) - item_center(its, c, h, 1), p + 11)
|
assert_eq(item_center(its, c, w, h, 2) - item_center(its, c, w, h, 1), p + 11)
|
||||||
assert_eq(item_at(its, c, w, h, item_center(its, c, h, 2), 10), 2)
|
assert_eq(item_at(its, c, w, h, item_center(its, c, w, h, 2), 10), 2)
|
||||||
assert_eq(item_at(its, c, w, h, w + 5, 10), -1)
|
assert_eq(item_at(its, c, w, h, w + 5, 10), -1)
|
||||||
assert_eq(item_at(its, c, w, h, 6, -1), -1)
|
assert_eq(item_at(its, c, w, h, 6, -1), -1)
|
||||||
// Too narrow for all of them: the ones that don't fit can't be hit.
|
// Too narrow for all of them: the ones that don't fit can't be hit.
|
||||||
assert_eq(item_at(its, c, w - 10, h, item_center(its, c, h, 2), 10), -1)
|
assert_eq(item_at(its, c, w - 10, h, item_center(its, c, w, h, 2), 10), -1)
|
||||||
// Bigger icons, wider dock; magnification grows the hovered one most.
|
// Bigger icons, wider dock; magnification grows the hovered one most.
|
||||||
let big = DockConfig::from_pairs([("pinned", "foot;firefox"), ("icon-size", "Large")])
|
let big = DockConfig::from_pairs([("pinned", "foot;firefox"), ("icon-size", "Large")])
|
||||||
assert_true(preferred_width(items(big, apps(), []), big, 44) > preferred_width(items(c, apps(), []), c, 44))
|
assert_true(preferred_width(items(big, apps(), []), big, 44) > preferred_width(items(c, apps(), []), c, 44))
|
||||||
@@ -127,12 +127,12 @@ test "items are hit-tested by slot, with a divider before the running apps" {
|
|||||||
|
|
||||||
///|
|
///|
|
||||||
test "a click starts an app that isn't running and walks through a running app's windows" {
|
test "a click starts an app that isn't running and walks through a running app's windows" {
|
||||||
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
|
let c = DockConfig::from_pairs([("pinned", "foot;firefox"), ("titles", "off")])
|
||||||
let its = items(c, apps(), [win(3, "foot"), win(8, "foot")])
|
let its = items(c, apps(), [win(3, "foot"), win(8, "foot")])
|
||||||
let h = 36
|
let h = 36
|
||||||
let w = preferred_width(its, c, h)
|
let w = preferred_width(its, c, h)
|
||||||
let x0 = item_center(its, c, h, 0)
|
let x0 = item_center(its, c, w, h, 0)
|
||||||
let x1 = item_center(its, c, h, 1)
|
let x1 = item_center(its, c, w, h, 1)
|
||||||
let (hv, redraw, act) = handle(its, c, -1, w, h, None, PointerMove({ x: x1, y: 10 }))
|
let (hv, redraw, act) = handle(its, c, -1, w, h, None, PointerMove({ x: x1, y: 10 }))
|
||||||
assert_eq((hv, redraw, act), (1, true, Nothing))
|
assert_eq((hv, redraw, act), (1, true, Nothing))
|
||||||
assert_eq(handle(its, c, 1, w, h, None, PointerMove({ x: x1, y: 10 })).1, false)
|
assert_eq(handle(its, c, 1, w, h, None, PointerMove({ x: x1, y: 10 })).1, false)
|
||||||
@@ -150,7 +150,7 @@ test "a click starts an app that isn't running and walks through a running app's
|
|||||||
|
|
||||||
///|
|
///|
|
||||||
test "render draws each icon (theme image or letter tile), a dot per window and the divider" {
|
test "render draws each icon (theme image or letter tile), a dot per window and the divider" {
|
||||||
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
|
let c = DockConfig::from_pairs([("pinned", "foot;firefox"), ("titles", "off")])
|
||||||
let its = items(c, apps(), [win(3, "foot", focused=true), win(4, "vlc"), win(5, "vlc")])
|
let its = items(c, apps(), [win(3, "foot", focused=true), win(4, "vlc"), win(5, "vlc")])
|
||||||
let h = 36
|
let h = 36
|
||||||
let w = preferred_width(its, c, h)
|
let w = preferred_width(its, c, h)
|
||||||
@@ -161,9 +161,38 @@ test "render draws each icon (theme image or letter tile), a dot per window and
|
|||||||
assert_eq(texts.length(), 2) // foot's and vlc's letter tiles
|
assert_eq(texts.length(), 2) // foot's and vlc's letter tiles
|
||||||
// background + divider + foot (tile, glyph, 1 dot) + firefox (image) + vlc (tile, glyph, 2 dots)
|
// background + divider + foot (tile, glyph, 1 dot) + firefox (image) + vlc (tile, glyph, 2 dots)
|
||||||
assert_eq(ops.length(), 1 + 1 + 3 + 1 + 4)
|
assert_eq(ops.length(), 1 + 1 + 3 + 1 + 4)
|
||||||
// Nothing to show.
|
// Nothing to show: a "+" tile (fill, outline, two strokes) and its hint, after the background.
|
||||||
let none = DockConfig::from_pairs([("pinned", ";")])
|
let none = DockConfig::from_pairs([("pinned", ";")])
|
||||||
assert_eq(render(@ui.size(80, h), tokens(), none, [], -1, _ => 0U).length(), 2)
|
let empty = render(@ui.size(preferred_width([], none, h), h), tokens(), none, [], -1, _ => 0U)
|
||||||
|
assert_eq(empty.length(), 6)
|
||||||
|
assert_true(empty.iter().any(op => op is Text(t) && t.text == "Add apps"))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "the empty dock is one target: hovering it lights the + tile, a click is the shell's" {
|
||||||
|
let none = DockConfig::from_pairs([("pinned", ";")])
|
||||||
|
let (hv, redraw, act) = handle([], none, -1, 150, 36, None, PointerMove({ x: 10, y: 10 }))
|
||||||
|
assert_eq((hv, redraw, act), (0, true, Nothing))
|
||||||
|
let (_, _, act) = handle([], none, 0, 150, 36, None, PointerDown({ x: 10, y: 10 }))
|
||||||
|
assert_eq(act, Nothing)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "a window's app: a pin, a catalog app, or its own id" {
|
||||||
|
let a = apps()
|
||||||
|
assert_eq(owner_of("org.mozilla.firefox", [], a), Some("firefox"))
|
||||||
|
assert_eq(owner_of("vlc", ["vlc"], a), Some("vlc"))
|
||||||
|
assert_eq(owner_of("org.example.Notes", [], a), Some("org.example.Notes"))
|
||||||
|
assert_eq(owner_of("", [], a), None)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "activate starts an app without windows and brings one forward otherwise" {
|
||||||
|
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
|
||||||
|
let its = items(c, apps(), [win(3, "foot", focused=true), win(4, "foot")])
|
||||||
|
assert_eq(activate(its[1], Some(3UL)), Launch("firefox"))
|
||||||
|
assert_eq(activate(its[0], None), Focus(4UL))
|
||||||
|
assert_eq(activate(its[0], Some(3UL)), Focus(4UL))
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -196,3 +225,29 @@ test "an app's icon is its coloured tile plus glyph" {
|
|||||||
_ => fail("expected a tile")
|
_ => fail("expected a tile")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "apps with windows are titled pills that shrink, then drop their titles, as room runs out" {
|
||||||
|
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
|
||||||
|
let its = items(c, apps(), [win(3, "foot"), win(4, "vlc", minimized=true), win(5, "vlc")])
|
||||||
|
let h = 36
|
||||||
|
let base = icon_size(c, h)
|
||||||
|
// Room for all: foot and vlc get full pills, firefox (no windows) stays an icon.
|
||||||
|
assert_eq(widths(its, c, 1000, h), [label_max, base, label_max])
|
||||||
|
assert_eq(item_title(its[0]), "foot window")
|
||||||
|
assert_eq(item_title(its[2]), "vlc! (2)")
|
||||||
|
assert_eq(its[2].minimized, 1)
|
||||||
|
// Less room: the pills share what's left...
|
||||||
|
let ws = widths(its, c, 300, h)
|
||||||
|
assert_true(ws[0] < label_max && ws[0] >= label_min && ws[0] == ws[2])
|
||||||
|
assert_true(slot_x(its, c, 300, h, 2) + ws[2] + 6 <= 300)
|
||||||
|
// ...and below label_min they are icons again.
|
||||||
|
assert_eq(widths(its, c, 150, h), [base, base, base])
|
||||||
|
// A click anywhere on a pill is that app.
|
||||||
|
assert_eq(item_at(its, c, 1000, h, 6 + label_max - 10, 10), 0)
|
||||||
|
let ops = render(@ui.size(1000, h), tokens(), c, its, -1, _ => 0U)
|
||||||
|
assert_true(ops.iter().any(op => op is Text(t) && t.text == "foot window"))
|
||||||
|
// Off: icons only.
|
||||||
|
assert_true(c.set("titles", "off"))
|
||||||
|
assert_eq(widths(its, c, 1000, h), [base, base, base])
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@ import {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
pub fn activate(DockItem, UInt64?) -> DockAction
|
||||||
|
|
||||||
pub fn app_glyph(String, String) -> String
|
pub fn app_glyph(String, String) -> String
|
||||||
|
|
||||||
pub fn app_icon(Int32, Int32, Int32, String, String, hover? : Bool) -> Array[@types.DrawOp]
|
pub fn app_icon(Int32, Int32, Int32, String, String, hover? : Bool) -> Array[@types.DrawOp]
|
||||||
@@ -28,16 +30,26 @@ pub fn icon_size(DockConfig, Int32) -> Int32
|
|||||||
|
|
||||||
pub fn item_at(Array[DockItem], DockConfig, Int32, Int32, Int32, Int32) -> Int32
|
pub fn item_at(Array[DockItem], DockConfig, Int32, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
pub fn item_center(Array[DockItem], DockConfig, Int32, Int32) -> Int32
|
pub fn item_center(Array[DockItem], DockConfig, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
pub fn item_size(DockConfig, Int32, Int32, Int32) -> Int32
|
pub fn item_size(DockConfig, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
pub fn item_title(DockItem) -> String
|
||||||
|
|
||||||
pub fn items(DockConfig, Array[@types.AppEntry], Array[DockWindow]) -> Array[DockItem]
|
pub fn items(DockConfig, Array[@types.AppEntry], Array[DockWindow]) -> Array[DockItem]
|
||||||
|
|
||||||
|
pub let label_max : Int32
|
||||||
|
|
||||||
|
pub let label_min : Int32
|
||||||
|
|
||||||
pub fn match_app(String, Array[String]) -> String?
|
pub fn match_app(String, Array[String]) -> String?
|
||||||
|
|
||||||
|
pub fn match_name(String, Array[@types.AppEntry]) -> String?
|
||||||
|
|
||||||
pub fn move_pin(Array[String], String, Int32) -> Array[String]
|
pub fn move_pin(Array[String], String, Int32) -> Array[String]
|
||||||
|
|
||||||
|
pub fn owner_of(String, Array[String], Array[@types.AppEntry], catalog_ids? : Array[String]) -> String?
|
||||||
|
|
||||||
pub fn preferred_width(Array[DockItem], DockConfig, Int32) -> Int32
|
pub fn preferred_width(Array[DockItem], DockConfig, Int32) -> Int32
|
||||||
|
|
||||||
pub fn render(@types.Size, @theme.Tokens, DockConfig, Array[DockItem], Int32, (String) -> UInt32) -> Array[@types.DrawOp]
|
pub fn render(@types.Size, @theme.Tokens, DockConfig, Array[DockItem], Int32, (String) -> UInt32) -> Array[@types.DrawOp]
|
||||||
@@ -71,6 +83,7 @@ pub(all) struct DockConfig {
|
|||||||
mut size : String
|
mut size : String
|
||||||
mut magnify : Bool
|
mut magnify : Bool
|
||||||
mut running : Bool
|
mut running : Bool
|
||||||
|
mut titles : Bool
|
||||||
}
|
}
|
||||||
pub fn DockConfig::from_pairs(Array[(String, String)]) -> Self
|
pub fn DockConfig::from_pairs(Array[(String, String)]) -> Self
|
||||||
pub fn DockConfig::items(Self) -> Array[ConfigEntry]
|
pub fn DockConfig::items(Self) -> Array[ConfigEntry]
|
||||||
@@ -86,12 +99,16 @@ pub(all) struct DockItem {
|
|||||||
pinned : Bool
|
pinned : Bool
|
||||||
windows : Array[UInt64]
|
windows : Array[UInt64]
|
||||||
focused : Bool
|
focused : Bool
|
||||||
|
title : String
|
||||||
|
minimized : Int32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(all) struct DockWindow {
|
pub(all) struct DockWindow {
|
||||||
id : UInt64
|
id : UInt64
|
||||||
app_id : String
|
app_id : String
|
||||||
focused : Bool
|
focused : Bool
|
||||||
|
title : String
|
||||||
|
minimized : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type aliases
|
// Type aliases
|
||||||
|
|||||||
@@ -6,16 +6,6 @@ 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
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
///| 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
///|
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ clock-binary clock-widget
|
|||||||
launcher launcher-widget
|
launcher launcher-widget
|
||||||
dock dock-widget
|
dock dock-widget
|
||||||
shell shell
|
shell shell
|
||||||
tasks taskbar-widget
|
|
||||||
layout layout-widget
|
layout layout-widget
|
||||||
inspector inspector-widget
|
inspector inspector-widget
|
||||||
session-settings session-settings-widget
|
session-settings session-settings-widget
|
||||||
|
|||||||
@@ -60,13 +60,6 @@ world pulse-widget {
|
|||||||
import windows;
|
import windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Panel task list: needs the window list.
|
|
||||||
world taskbar-widget {
|
|
||||||
include widget;
|
|
||||||
import windows;
|
|
||||||
import icons;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Layout switcher.
|
/// Layout switcher.
|
||||||
world layout-widget {
|
world layout-widget {
|
||||||
include widget;
|
include widget;
|
||||||
|
|||||||
Reference in new issue
Block a user