Launcher: Reload session, and Log out moves in from its own module
CI / test (push) Failing after 17s
CI / test (push) Failing after 17s
The Application Launcher's menu now ends in a session row: Reload, Log out, Suspend, Restart,
Power off. Log out, Restart and Power off take a second click on the same button (a status line
says "Click Log out again to confirm"); Reload and Suspend act at once.
- Reload calls the new session.reload, which reaches the shell as the ReloadSession request
(native stub: request 8 with n 1; host plasmoids.wit: reload-session; host-wasm: Req::ReloadSession)
and runs DesktopShell::reload_modules(""): every panel module again from disk, in place, with
its settings. Windows and apps keep running. The compositor redraws the whole frame after it.
- Suspend / Restart / Power off use the power capability, the same calls as Settings > Power.
- The standalone logout module is gone (component, world, components.txt). Saved panels drop
"logout", or get the launcher in its place when they had none; panel.edn is rewritten without
it. A stale logout.wasm is hidden from Settings > Panel (retired_modules).
- Tests: lib/launcher session row, shell migrate_panel, host input tests for Log out and Reload,
host-wasm launcher session row; control_test uses inspector.wasm instead of logout.wasm.
- README and docs/reloading.md describe the session row.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjKUnSS3D92ThigvJf
This commit is contained in:
37 files changed
+420
-827
No files matched your search
@@ -131,7 +131,10 @@ a recording shortcut again to stop.
|
||||
|
||||
**Panel modules** (each one a separate `.wasm` component in `components/`)
|
||||
|
||||
* **Launcher** (application menu with search) and **Dock**.
|
||||
* **Launcher** (application menu with search) and **Dock**. The launcher's menu ends in a
|
||||
session row: **Reload** (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 Power off ask for a second click.
|
||||
* **Task manager**: a pill per window with the app's real icon from its `.desktop` file;
|
||||
right-click a pill for Minimize, Maximize and Quit.
|
||||
* **Network**: Wi-Fi and wired status, connect to Wi-Fi networks (with passwords), Wi-Fi and
|
||||
@@ -140,7 +143,7 @@ a recording shortcut again to stop.
|
||||
with a battery).
|
||||
* **Clocks**: the Digital Clock (12-hour with AM/PM by default, 24-hour in its Module settings)
|
||||
and a binary clock.
|
||||
* **Screenshot**, **Layout** (Tile | Float), **Inspector** (interface explorer), **Log out**.
|
||||
* **Screenshot**, **Layout** (Tile | Float), **Inspector** (interface explorer).
|
||||
* **Settings**: tabs for Session (reopen windows at login, remember window positions, dark
|
||||
mode), Desktop (wallpapers), Panel (add, remove and replace modules) and Power (screen off and
|
||||
suspend when idle, battery, suspend / restart / power off). Dark mode also sets the system
|
||||
|
||||
@@ -3,6 +3,8 @@ import {
|
||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
||||
"chandra/desktop/interface/chandra/desktop/app-catalog" @app_catalog,
|
||||
"chandra/desktop/interface/chandra/desktop/app-launch" @app_launch,
|
||||
"chandra/desktop/interface/chandra/desktop/session" @session,
|
||||
"chandra/desktop/interface/chandra/desktop/power" @power,
|
||||
"chandra/desktop/lib/launcher" @logic,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
///| Implementation of `chandra:desktop/plasmoid` for the launcher.
|
||||
/// The state machine lives in lib/launcher; this adapts host capabilities.
|
||||
/// The state machine lives in lib/launcher; this adapts host capabilities: the app catalog and
|
||||
/// launch, and for the session row `session` (reload, log out) and `power` (suspend, restart,
|
||||
/// power off, the same calls as the Settings Power tab).
|
||||
|
||||
///|
|
||||
let state : @logic.State = @logic.State::new()
|
||||
@@ -38,5 +40,20 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
WIDGET => Widget
|
||||
POPUP => Popup
|
||||
}
|
||||
@logic.handle_event(@app_catalog.list_apps(), state, t, event, @app_launch.launch)
|
||||
@logic.handle_event(@app_catalog.list_apps(), state, t, event, @app_launch.launch, session=run_action)
|
||||
}
|
||||
|
||||
///| Carry out a (confirmed) session-row action.
|
||||
fn run_action(a : Int) -> Unit {
|
||||
if a == @logic.action_reload {
|
||||
@session.reload()
|
||||
} else if a == @logic.action_logout {
|
||||
@session.logout()
|
||||
} else if a == @logic.action_suspend {
|
||||
@power.suspend()
|
||||
} else if a == @logic.action_restart {
|
||||
@power.reboot()
|
||||
} else if a == @logic.action_power_off {
|
||||
@power.power_off()
|
||||
}
|
||||
}
|
||||
@@ -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 wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopup() -> Int {
|
||||
@plasmoid.wasmExportPopup()
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportInfo() -> Int {
|
||||
@plasmoid.wasmExportInfo()
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportRenderPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportInfoPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
||||
@plasmoid.wasmExportRender(p0, p1)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportPopupPostReturn(p0)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
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_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
///|
|
||||
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_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
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_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_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import {
|
||||
"chandra/desktop/interface/chandra/desktop/types" @types,
|
||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
||||
"chandra/desktop/interface/chandra/desktop/session" @session,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
|
||||
warnings = "-44"
|
||||
@@ -1,154 +0,0 @@
|
||||
///| Implementation of `chandra:desktop/plasmoid` for the logout button. A click on the panel
|
||||
/// button opens a small popup, "Log out | Cancel", so a stray click can't end the session; Enter
|
||||
/// confirms and Escape (or a click elsewhere) cancels. Confirming calls `session.logout`, which
|
||||
/// makes the host stop the compositor and hand the screen back to the display manager.
|
||||
|
||||
///| Popup geometry: a column of two rows with a margin around them.
|
||||
let popup_w : Int = 150
|
||||
|
||||
///|
|
||||
let row_h : Int = 30
|
||||
|
||||
///|
|
||||
let margin : Int = 6
|
||||
|
||||
///|
|
||||
let rows : Array[String] = ["Log out", "Cancel"]
|
||||
|
||||
///| Whether the popup is open, and which row the pointer is over (-1: none).
|
||||
let open_ : Ref[Bool] = { val: false }
|
||||
|
||||
///|
|
||||
let hover : Ref[Int] = { val: -1 }
|
||||
|
||||
///|
|
||||
fn popup_h() -> Int {
|
||||
margin * 2 + rows.length() * row_h
|
||||
}
|
||||
|
||||
///| Row under a popup-local y, or -1.
|
||||
fn row_at(x : Int, y : Int) -> Int {
|
||||
if x < margin || x >= popup_w - margin || y < margin {
|
||||
return -1
|
||||
}
|
||||
let i = (y - margin) / row_h
|
||||
if i < rows.length() { i } else { -1 }
|
||||
}
|
||||
|
||||
///|
|
||||
fn close() -> Unit {
|
||||
open_.val = false
|
||||
hover.val = -1
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn info() -> PlasmoidInfo {
|
||||
{
|
||||
id: "org.chandra.logout",
|
||||
name: "Log out",
|
||||
preferred: { w: 84, h: 34 },
|
||||
min_width: 70,
|
||||
stretch: false,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
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()
|
||||
let r = t.radius.reinterpret_as_int()
|
||||
let fs = t.font_size.reinterpret_as_int()
|
||||
let bg = if open_.val { t.palette.accent } else { t.palette.surface_hover }
|
||||
let fg = if open_.val { t.palette.accent_foreground } else { t.palette.foreground }
|
||||
[
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r),
|
||||
@ui.text(w / 2, h / 2, "Log out", fs - 2, fg, align=CENTER),
|
||||
]
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn popup() -> PopupSurface? {
|
||||
if !open_.val {
|
||||
return None
|
||||
}
|
||||
let t = @theme.get_tokens()
|
||||
let w = popup_w
|
||||
let h = popup_h()
|
||||
let r = t.radius.reinterpret_as_int()
|
||||
let fs = t.font_size.reinterpret_as_int()
|
||||
let ops : Array[@types.DrawOp] = [
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), t.palette.surface_popup, radius=r),
|
||||
@ui.stroke_rect(@ui.rect(0, 0, w, h), t.palette.border, width=1, radius=r),
|
||||
]
|
||||
for i = 0; i < rows.length(); i = i + 1 {
|
||||
let y = margin + i * row_h
|
||||
let hot = i == hover.val
|
||||
if hot {
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.accent, radius=r))
|
||||
}
|
||||
let fg = if hot { t.palette.accent_foreground } else { t.palette.foreground }
|
||||
ops.push(@ui.text(margin + 12, y + (row_h - 2) / 2, rows[i], fs - 1, fg, bold=i == 0))
|
||||
}
|
||||
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
match (target, event) {
|
||||
(WIDGET, PointerDown(_)) => {
|
||||
if open_.val {
|
||||
close()
|
||||
} else {
|
||||
open_.val = true
|
||||
hover.val = -1
|
||||
}
|
||||
true
|
||||
}
|
||||
(POPUP, PointerMove(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
if i != hover.val {
|
||||
hover.val = i
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
(POPUP, PointerLeave) =>
|
||||
if hover.val != -1 {
|
||||
hover.val = -1
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
(POPUP, PointerDown(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
close()
|
||||
if i == 0 {
|
||||
@session.logout()
|
||||
}
|
||||
true
|
||||
}
|
||||
(_, FocusLost) =>
|
||||
if open_.val {
|
||||
close()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
(_, KeyDown(k)) =>
|
||||
if !open_.val {
|
||||
false
|
||||
} else if k == "Escape" {
|
||||
close()
|
||||
true
|
||||
} else if k == "Enter" {
|
||||
close()
|
||||
@session.logout()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
_ => 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/logout/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"
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -133,7 +133,7 @@ let categories : Array[String] = ["Apps and windows", "System", "Clocks", "Other
|
||||
fn category_of(id : String) -> String {
|
||||
match id {
|
||||
"launcher" | "dock" | "tasks" | "layout" => "Apps and windows"
|
||||
"session-settings" | "network" | "battery" | "screenshot" | "logout" => "System"
|
||||
"session-settings" | "network" | "battery" | "screenshot" => "System"
|
||||
"clock-digital" | "clock-binary" | "moon-disc" => "Clocks"
|
||||
_ => "Other"
|
||||
}
|
||||
@@ -142,7 +142,7 @@ fn category_of(id : String) -> String {
|
||||
///| One line on what a module does ("" for modules we don't know).
|
||||
fn description_of(id : String) -> String {
|
||||
match id {
|
||||
"launcher" => "Search and start apps"
|
||||
"launcher" => "Start apps; reload, log out or power off"
|
||||
"dock" => "Pinned apps, one click away"
|
||||
"tasks" => "Your open windows"
|
||||
"layout" => "Switch tiling and floating"
|
||||
@@ -150,7 +150,6 @@ fn description_of(id : String) -> String {
|
||||
"network" => "Wi-Fi and wired network"
|
||||
"battery" => "Charge and time left"
|
||||
"screenshot" => "Capture or record the screen"
|
||||
"logout" => "End the session"
|
||||
"clock-digital" => "The time, 12 or 24-hour"
|
||||
"clock-binary" => "The time in binary"
|
||||
"moon-disc" => "Tonight's moon phase"
|
||||
|
||||
@@ -88,7 +88,7 @@ pub(all) struct ChandraCompositor {
|
||||
/// can restore them.
|
||||
mut desktop_hidden : Array[UInt64]
|
||||
mut layout_mode : @wm.LayoutMode
|
||||
/// Set when the user asked to end the session (the logout button); the main loop then exits.
|
||||
/// Set when the user asked to end the session (the launcher's Log out); the main loop then exits.
|
||||
mut quit_requested : Bool
|
||||
/// Alt+Tab switcher (switcher.mbt): whether it is up, its window list (most recent first) and selection.
|
||||
mut switcher_on : Bool
|
||||
@@ -1203,6 +1203,11 @@ fn ChandraCompositor::run_shell_actions(self : ChandraCompositor) -> Unit {
|
||||
@shell.ShellAction::Screenshot(code) => self.screenshot_request(code)
|
||||
@shell.ShellAction::SystemPower(a) => self.system_power(a)
|
||||
@shell.ShellAction::Window(wid, cmd) => self.window_command(wid, cmd)
|
||||
@shell.ShellAction::ModulesReloaded => {
|
||||
// The panel changed under the frame signature's feet (as after `chandra-ctl reload`).
|
||||
self.frame_changed = true
|
||||
self.damage.mark_full()
|
||||
}
|
||||
@shell.ShellAction::SetLayout(m) =>
|
||||
match m {
|
||||
0 => self.set_layout_mode(@wm.LayoutMode::Tiling)
|
||||
|
||||
@@ -126,9 +126,9 @@ test "a module that fails to reload stays loaded and the error is reported" {
|
||||
let (comp, path) = control_comp("fail")
|
||||
let dir = "/tmp/chandra-control-badmod-" + @sys.getpid().to_string()
|
||||
ignore(@sys.mkdir_p(dir))
|
||||
let good = @sys.read_file_bytes("build/components/logout.wasm")
|
||||
let good = @sys.read_file_bytes("build/components/inspector.wasm")
|
||||
assert_true(good.length() > 0)
|
||||
let copy = dir + "/logout.wasm"
|
||||
let copy = dir + "/inspector.wasm"
|
||||
ignore(@sys.write_file_bytes(copy, good))
|
||||
assert_true(comp.shell.load_module(copy))
|
||||
let before = panel_order(comp)
|
||||
|
||||
@@ -560,6 +560,8 @@ test "a panel saved with the old 12-hour clock gets the Digital Clock with the s
|
||||
assert_eq(a.module_setting("clock-digital12", "date"), None)
|
||||
let panel = @utf8.decode_lossy(@sys.read_file_bytes(dir + "/panel.edn"))
|
||||
assert_true(panel.contains("\"clock-digital\"") && !panel.contains("clock-digital12"))
|
||||
// The old Log out button became the launcher, which has Log out now.
|
||||
assert_true(panel.contains("\"launcher\"") && !panel.contains("logout"))
|
||||
assert_true(panel.contains(":version 2"))
|
||||
// Only once: a format chosen afterwards sticks across restarts.
|
||||
a.set_module_setting(a.slot_of("clock-digital"), "format", "24-hour")
|
||||
@@ -1040,31 +1042,56 @@ test "dragging a floating window's corner resizes it" {
|
||||
assert_eq(g1.h, g0.h - 40)
|
||||
}
|
||||
|
||||
///| Centre of session-row button `i` (0 Reload, 1 Log out, 2 Suspend, 3 Restart, 4 Power off)
|
||||
/// in the launcher's open popup (geometry from lib/launcher: 5 buttons in a 44 px row at the
|
||||
/// bottom, 8 px margins, 4 px gaps).
|
||||
fn launcher_button(comp : @host.ChandraCompositor, i : Int) -> (Int, Int) {
|
||||
let pr = comp.shell.slot_popup_rect(comp.shell.slot_of("launcher"))
|
||||
(pr.x + 8 + i * 65 + 30, pr.y + pr.h - 44 + 6 + 15)
|
||||
}
|
||||
|
||||
///|
|
||||
test "the logout button asks first, then ends the session" {
|
||||
let comp = new_comp("logout")
|
||||
let slot = comp.shell.slot_of("logout")
|
||||
test "the launcher's Log out asks first, then ends the session" {
|
||||
let comp = new_comp("launcher-logout")
|
||||
let slot = comp.shell.slot_of("launcher")
|
||||
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
||||
assert_false(comp.quit_requested)
|
||||
// A click opens the popup; nothing is requested yet.
|
||||
click_module(comp, "logout", 1U)
|
||||
let pr = comp.shell.slot_popup_rect(slot)
|
||||
assert_true(pr.w > 0)
|
||||
// The old Log out button is gone from the default panel.
|
||||
assert_false(comp.shell.slots().map(s => comp.shell.slot_module(s)).contains("logout"))
|
||||
click_module(comp, "launcher", 1U)
|
||||
assert_true(comp.shell.slot_popup_rect(slot).w > 0)
|
||||
ignore(comp.compose_frame())
|
||||
// The first click on Log out only arms it.
|
||||
let (x, y) = launcher_button(comp, 1)
|
||||
click_at(comp, x, y, 5U)
|
||||
ignore(comp.compose_frame())
|
||||
assert_false(comp.quit_requested)
|
||||
// Cancel (second row) closes it without logging out.
|
||||
click_at(comp, pr.x + 20, pr.y + 6 + 30 + 5, 5U)
|
||||
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
||||
assert_false(comp.quit_requested)
|
||||
// Open again and choose Log out (first row).
|
||||
click_module(comp, "logout", 10U)
|
||||
let pr2 = comp.shell.slot_popup_rect(slot)
|
||||
assert_true(pr2.w > 0)
|
||||
click_at(comp, pr2.x + 20, pr2.y + 6 + 5, 15U)
|
||||
assert_true(comp.shell.slot_popup_rect(slot).w > 0)
|
||||
assert_true(comp.shell.slot_popup_texts(slot).iter().any(t => t.0 == "Click Log out again to confirm"))
|
||||
// The second ends the session.
|
||||
let (x, y) = launcher_button(comp, 1)
|
||||
click_at(comp, x, y, 10U)
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(comp.quit_requested)
|
||||
}
|
||||
|
||||
///|
|
||||
test "the launcher's Reload reloads every panel module in place" {
|
||||
let comp = new_comp("launcher-reload")
|
||||
let before = comp.shell.slots().map(s => comp.shell.slot_module(s))
|
||||
let slots_before = comp.shell.slots()
|
||||
click_module(comp, "launcher", 1U)
|
||||
ignore(comp.compose_frame())
|
||||
let (x, y) = launcher_button(comp, 0)
|
||||
click_at(comp, x, y, 5U)
|
||||
ignore(comp.compose_frame())
|
||||
assert_false(comp.quit_requested)
|
||||
// Same modules in the same order, each a fresh instance (new slot ids).
|
||||
assert_eq(comp.shell.slots().map(s => comp.shell.slot_module(s)), before)
|
||||
for s in comp.shell.slots() {
|
||||
assert_false(slots_before.contains(s))
|
||||
}
|
||||
}
|
||||
|
||||
///| Contents of state.edn in the scratch config dir.
|
||||
fn read_state_edn() -> String {
|
||||
let dir = match @sys.getenv("XDG_CONFIG_HOME") {
|
||||
|
||||
@@ -151,7 +151,7 @@ pub(all) enum WindowCommand {
|
||||
pub(all) enum ShellAction {
|
||||
SetLayout(Int)
|
||||
FocusWindow(UInt64)
|
||||
/// A module (the logout button) asked to end the session.
|
||||
/// A module (the launcher's Log out) asked to end the session.
|
||||
Logout
|
||||
/// The Dark mode setting changed: the compositor swaps the theme (see `dark_mode`).
|
||||
ThemeChanged
|
||||
@@ -162,6 +162,8 @@ pub(all) enum ShellAction {
|
||||
SystemPower(Int)
|
||||
/// A row of a task-bar pill's right-click menu: do this to that window.
|
||||
Window(UInt64, WindowCommand)
|
||||
/// The launcher's Reload reloaded the panel modules: the whole frame needs drawing again.
|
||||
ModulesReloaded
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///| One wasm module loaded into the panel.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
|
||||
let default_panel : Array[String] = [
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital", "screenshot",
|
||||
"session-settings", "logout",
|
||||
"session-settings",
|
||||
]
|
||||
|
||||
///| A fresh panel's modules: the defaults, plus the battery before the clock on a machine that
|
||||
@@ -44,7 +44,13 @@ test "a fresh panel gets the battery module only on a machine with a battery" {
|
||||
/// works everywhere a module is named (saved panels, load_module), it is just never listed:
|
||||
/// a stale build/components/clock-digital12.wasm or an old installed copy stays out of the picker.
|
||||
/// - clock-digital12, the 12-hour clock, is the Digital Clock, which now starts in 12-hour mode.
|
||||
let retired_modules : Map[String, String] = { "clock-digital12": "clock-digital" }
|
||||
/// - 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
|
||||
/// it had none (migrate_panel).
|
||||
let retired_modules : Map[String, String] = {
|
||||
"clock-digital12": "clock-digital",
|
||||
"logout": "launcher",
|
||||
}
|
||||
|
||||
///| The id a module goes by now ("clock-digital12" -> "clock-digital").
|
||||
fn current_module_id(id : String) -> String {
|
||||
@@ -214,16 +220,22 @@ fn wall_secs() -> Int {
|
||||
|
||||
///| Panels saved before the wallpaper chooser and the module manager moved into the settings
|
||||
/// module list "wallpaper" or "module-manager": the settings module takes the first one's place
|
||||
/// (a panel that already has it just drops them). Retired modules (clock-digital12) become
|
||||
/// the module that replaced them.
|
||||
/// (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
|
||||
/// retired modules (clock-digital12) become the module that replaced them.
|
||||
fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||
let has_settings = entries.contains("session-settings")
|
||||
let has_launcher = entries.contains("launcher")
|
||||
let out : Array[String] = []
|
||||
for e in entries {
|
||||
if e == "wallpaper" || e == "module-manager" {
|
||||
if !has_settings && !out.contains("session-settings") {
|
||||
out.push("session-settings")
|
||||
}
|
||||
} else if e == "logout" {
|
||||
if !has_launcher && !out.contains("launcher") {
|
||||
out.push("launcher")
|
||||
}
|
||||
} else {
|
||||
out.push(current_module_id(e))
|
||||
}
|
||||
@@ -233,7 +245,7 @@ fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||
|
||||
///|
|
||||
test "a saved panel's wallpaper button becomes the settings module" {
|
||||
assert_eq(migrate_panel(["launcher", "wallpaper", "logout"]), ["launcher", "session-settings", "logout"])
|
||||
assert_eq(migrate_panel(["launcher", "wallpaper", "logout"]), ["launcher", "session-settings"])
|
||||
assert_eq(migrate_panel(["wallpaper", "session-settings"]), ["session-settings"])
|
||||
assert_eq(migrate_panel(["module-manager", "clock", "wallpaper"]), ["session-settings", "clock"])
|
||||
assert_eq(migrate_panel(["clock"]), ["clock"])
|
||||
@@ -241,11 +253,23 @@ test "a saved panel's wallpaper button becomes the settings module" {
|
||||
|
||||
///|
|
||||
test "a saved panel's 12-hour clock becomes the digital clock" {
|
||||
assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["tasks", "clock-digital", "logout"])
|
||||
assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["tasks", "clock-digital", "launcher"])
|
||||
assert_eq(current_module_id("clock-digital12"), "clock-digital")
|
||||
assert_eq(current_module_id("clock-binary"), "clock-binary")
|
||||
}
|
||||
|
||||
///|
|
||||
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...
|
||||
assert_eq(migrate_panel(["launcher", "tasks", "session-settings", "logout"]), [
|
||||
"launcher", "tasks", "session-settings",
|
||||
])
|
||||
// ...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(["logout", "launcher"]), ["launcher"])
|
||||
assert_false(default_panel.contains("logout"))
|
||||
}
|
||||
|
||||
///| Load the panel on first use: the saved layout if there is one, else the default modules.
|
||||
fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
if self.booted {
|
||||
@@ -265,6 +289,9 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
self.migrate_module_cfg(old)
|
||||
write_panel_file(entries)
|
||||
}
|
||||
// A renamed or folded module (the Log out button, now in the launcher): rewrite the file so
|
||||
// the old name is gone for good.
|
||||
Some(old) if old != entries => write_panel_file(entries)
|
||||
_ => ()
|
||||
}
|
||||
for e in entries {
|
||||
@@ -743,6 +770,11 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
|
||||
Some(FocusWindow(n)) => self.actions.push(FocusWindow(n.to_int64().to_uint64()))
|
||||
Some(SetLayout(m)) => self.actions.push(SetLayout(m))
|
||||
Some(Logout) => self.actions.push(Logout)
|
||||
// The launcher's Reload: every panel module again from disk, in place.
|
||||
Some(ReloadSession) => {
|
||||
ignore(self.reload_modules(""))
|
||||
self.actions.push(ModulesReloaded)
|
||||
}
|
||||
Some(SetWallpaper(i)) => self.set_wallpaper(i)
|
||||
Some(SetSessionSetting(i, on)) => self.set_session_setting(i, on)
|
||||
Some(Screenshot(code)) => self.actions.push(Screenshot(code))
|
||||
|
||||
@@ -365,6 +365,8 @@ pub(all) enum HostRequest {
|
||||
/// The shortcuts capability: action * 1000 + index (0 capture, 1 reset, 2 reset all, 3 cancel
|
||||
/// the capture).
|
||||
Shortcut(Int)
|
||||
/// The session capability's `reload`: reload every loaded panel module from disk.
|
||||
ReloadSession
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///|
|
||||
@@ -388,6 +390,7 @@ pub fn next_request() -> HostRequest? {
|
||||
Some(PowerAction(a)) => Some(PowerAction(a))
|
||||
Some(Network(r)) => Some(Network(r.action, r.ssid, r.password))
|
||||
Some(Shortcut(code)) => Some(Shortcut(code))
|
||||
Some(ReloadSession) => Some(ReloadSession)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -787,6 +787,8 @@ pub(all) enum HostRequest {
|
||||
/// The shortcuts capability: action * 1000 + index (0 capture, 1 reset, 2 reset all, 3 cancel
|
||||
/// the capture).
|
||||
Shortcut(Int)
|
||||
/// The session capability's `reload`: reload every loaded panel module from disk.
|
||||
ReloadSession
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///|
|
||||
@@ -810,7 +812,7 @@ pub fn next_request() -> HostRequest? {
|
||||
Some(MoveInstance(req_str(), delta))
|
||||
}
|
||||
7 => Some(Browse)
|
||||
8 => Some(Logout)
|
||||
8 => if c_host_req_int() == 1 { Some(ReloadSession) } else { Some(Logout) }
|
||||
9 => Some(SetWallpaper(c_host_req_int()))
|
||||
10 => Some(SetSessionSetting(c_host_req_int(), false))
|
||||
11 => Some(SetSessionSetting(c_host_req_int(), true))
|
||||
|
||||
@@ -52,7 +52,7 @@ static Inst insts[MAX_INST];
|
||||
enum {
|
||||
K_OTHER, K_TOKENS, K_CLOCK, K_APPS, K_LAUNCH, K_WINDOWS, K_FOCUS, K_LAYOUTS, K_LAYOUT_CUR, K_SET_LAYOUT,
|
||||
K_INSPECT_IS_ON, K_INSPECT_SET, K_MOD_AVAILABLE, K_MOD_LOADED, K_MOD_LOAD, K_MOD_UNLOAD, K_MOD_MOVE, K_MOD_BROWSE,
|
||||
K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT, K_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER,
|
||||
K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT, K_RELOAD, K_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER,
|
||||
K_SESSION_SETTINGS, K_SESSION_IS_ON, K_SESSION_SET,
|
||||
K_APP_ICON,
|
||||
K_SHOT_TAKE, K_SHOT_RECORD, K_SHOT_STOP, K_SHOT_IS_REC, K_SHOT_PTR, K_SHOT_SET_PTR,
|
||||
@@ -372,6 +372,7 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
|
||||
case K_SET_LAYOUT: push_req(3, a0, NULL); break;
|
||||
case K_FOCUS: push_req(2, a0, NULL); break;
|
||||
case K_LOGOUT: push_req(8, 0, NULL); break;
|
||||
case K_RELOAD: push_req(8, 1, NULL); break; /* 8: session; n 0 log out, 1 reload */
|
||||
case K_SET_WALLPAPER: push_req(9, a0, NULL); break;
|
||||
case K_SESSION_SET: push_req(a1 ? 11 : 10, a0, NULL); break; /* 10 off, 11 on */
|
||||
/* Request 12 carries the screenshot code: 0-3 take, 10-12 record, 20 stop, 30/31 pointer. */
|
||||
@@ -577,6 +578,7 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
|
||||
if (!strcmp(iface, "battery") && !strcmp(fn, "read")) return K_BAT_READ;
|
||||
if (!strcmp(iface, "icons") && !strcmp(fn, "app-icon")) return K_APP_ICON;
|
||||
if (!strcmp(iface, "session") && !strcmp(fn, "logout")) return K_LOGOUT;
|
||||
if (!strcmp(iface, "session") && !strcmp(fn, "reload")) return K_RELOAD;
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "wallpapers")) return K_WALLPAPERS;
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-wallpaper")) return K_WALLPAPER_CUR;
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-wallpaper")) return K_SET_WALLPAPER;
|
||||
|
||||
+10
-1
@@ -5,7 +5,7 @@ what it loaded at startup. What can be swapped without logging out:
|
||||
|
||||
| Part | Reload without logout? | How |
|
||||
|---|---|---|
|
||||
| Panel modules (`/usr/local/share/chandra/modules/*.wasm`) | yes | `just reload` / `chandra-ctl reload`, `kill -USR1`, or Settings → Panel (remove, add again) |
|
||||
| Panel modules (`/usr/local/share/chandra/modules/*.wasm`) | yes | Applications → **Reload**, `just reload` / `chandra-ctl reload`, `kill -USR1`, or Settings → Panel (remove, add again) |
|
||||
| `compositor.wasm` (shell, WM, portal backend) | no | restart the session |
|
||||
| `chandra-host` (`wasmhost`) | no | restart the session |
|
||||
| `config/`, themes, assets | not checked | restart the session to be sure |
|
||||
@@ -60,6 +60,15 @@ and `replace_slot` in `compositor/shell/widgets.mbt`), so a module that imports
|
||||
capability needs nothing else. A module that needs a host interface the running host lacks fails
|
||||
to load and stays as it was: that needs a new session.
|
||||
|
||||
### From the launcher
|
||||
|
||||
The Application Launcher's menu ends in a session row (Reload, Log out, Suspend, Restart, Power
|
||||
off). **Reload** does `chandra-ctl reload` from the desktop: the launcher calls `session.reload`
|
||||
(wit/capabilities.wit), which reaches the shell as the `ReloadSession` request, and
|
||||
`DesktopShell::process_requests` calls `reload_modules("")`. Same result and notice; windows and
|
||||
running apps are untouched, and it acts on the first click (Log out, Restart and Power off take a
|
||||
second one). Its own menu closes, and the launcher itself is reloaded with the rest.
|
||||
|
||||
### SIGUSR1
|
||||
|
||||
Sending SIGUSR1 to the host process reloads every module, like `chandra-ctl reload`:
|
||||
|
||||
@@ -264,6 +264,7 @@ impl chandra::host::plasmoids::Host for State {
|
||||
}
|
||||
Req::Browse => R::Browse,
|
||||
Req::Logout => R::Logout,
|
||||
Req::ReloadSession => R::ReloadSession,
|
||||
Req::SetWallpaper(n) => R::SetWallpaper(n),
|
||||
Req::SetSessionSetting(index, on) => {
|
||||
R::SetSessionSetting(chandra::host::plasmoids::SettingChange { index, on })
|
||||
|
||||
+33
-21
@@ -46,6 +46,8 @@ pub enum Req {
|
||||
MoveInstance(String, i32),
|
||||
Browse,
|
||||
Logout,
|
||||
/// `session.reload`: reload every loaded panel module from disk.
|
||||
ReloadSession,
|
||||
SetWallpaper(i32),
|
||||
SetSessionSetting(i32, bool),
|
||||
/// The screenshot capability: 0-3 take, 10-12 record, 20 stop, 30/31 pointer off/on.
|
||||
@@ -318,6 +320,9 @@ impl d::session::Host for PState {
|
||||
fn logout(&mut self) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::Logout);
|
||||
}
|
||||
fn reload(&mut self) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::ReloadSession);
|
||||
}
|
||||
}
|
||||
|
||||
impl d::wallpaper::Host for PState {
|
||||
@@ -746,7 +751,7 @@ mod tests {
|
||||
// Its capability grant is what the binary imports (the MoonBit side drops the base `theme`).
|
||||
let mut imports = l.imports.clone();
|
||||
imports.sort();
|
||||
assert_eq!(imports, ["app-catalog", "app-launch", "theme"]);
|
||||
assert_eq!(imports, ["app-catalog", "app-launch", "power", "session", "theme"]);
|
||||
let h = l.handle;
|
||||
// It draws its button.
|
||||
assert!(!rt.render(h, Size { w: 190, h: 36 }).is_empty());
|
||||
@@ -814,35 +819,42 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logout_asks_for_confirmation_then_requests_it() {
|
||||
fn launcher_session_row_reloads_and_logs_out_after_confirming() {
|
||||
let mut rt = runtime();
|
||||
let l = rt.load(&module("logout")).expect("logout loads");
|
||||
let l = rt.load(&module("launcher")).expect("launcher loads");
|
||||
assert!(l.imports.contains(&"session".to_string()));
|
||||
assert!(l.imports.contains(&"power".to_string()));
|
||||
let h = l.handle;
|
||||
assert!(!rt.render(h, Size { w: 84, h: 34 }).is_empty());
|
||||
// Closed: no popup. A click opens it; nothing is requested yet.
|
||||
assert!(rt.popup(h).is_none());
|
||||
// Open the menu; its last row is the session row.
|
||||
assert!(rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })));
|
||||
let p = rt.popup(h).expect("popup open");
|
||||
assert!(texts(&p.ops).contains(&"Log out".to_string()) && texts(&p.ops).contains(&"Cancel".to_string()));
|
||||
let t = texts(&p.ops);
|
||||
for b in ["Reload", "Log out", "Suspend", "Restart", "Power off"] {
|
||||
assert!(t.contains(&b.to_string()), "{b} missing from {t:?}");
|
||||
}
|
||||
// Button i's centre: 5 buttons across 340 px with 8 px margins and 4 px gaps, in a
|
||||
// 44 px row at the bottom (lib/launcher).
|
||||
let button = |i: i32, ph: i32| Point { x: 8 + i * 65 + 30, y: ph - 44 + 6 + 15 };
|
||||
let ph = p.size.h as i32;
|
||||
// Log out: the first click only arms it, the second requests it.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(button(1, ph))));
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
// Cancel row (second): closes without logging out.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 30 + 5 })));
|
||||
assert!(rt.popup(h).is_none());
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
// Escape also cancels.
|
||||
rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 }));
|
||||
assert!(rt.on_event(h, true, InputEvent::KeyDown("Escape".to_string())));
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
// Open again and click the first row: that is the logout request.
|
||||
rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 }));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 5 })));
|
||||
let p = rt.popup(h).expect("still open");
|
||||
assert!(texts(&p.ops).contains(&"Click Log out again to confirm".to_string()));
|
||||
let ph = p.size.h as i32;
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(button(1, ph))));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::Logout)));
|
||||
assert!(rt.popup(h).is_none());
|
||||
// Enter confirms too.
|
||||
// Reload acts at once.
|
||||
rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 }));
|
||||
rt.on_event(h, true, InputEvent::KeyDown("Enter".to_string()));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::Logout)));
|
||||
let ph = rt.popup(h).expect("open").size.h as i32;
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(button(0, ph))));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::ReloadSession)));
|
||||
// Suspend acts at once too, through the power capability.
|
||||
rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 }));
|
||||
let ph = rt.popup(h).expect("open").size.h as i32;
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(button(2, ph))));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::PowerAction(0))));
|
||||
rt.unload(h);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
Ending the login session. A module with this capability is a logout button: the host stops the
|
||||
compositor, and the display manager takes the screen back.
|
||||
The login session. `logout` ends it: the host stops the compositor, and the display manager
|
||||
takes the screen back. `reload` reloads it in place: every loaded panel module is read from
|
||||
disk again (same order, same module settings) and the module list is rescanned; windows and
|
||||
running apps are untouched. The Application Launcher's session row uses both.
|
||||
@@ -3,3 +3,6 @@
|
||||
///|
|
||||
fn wasmImportLogout() = "chandra:desktop/session@0.1.0" "logout"
|
||||
|
||||
///|
|
||||
fn wasmImportReload() = "chandra:desktop/session@0.1.0" "reload"
|
||||
|
||||
@@ -5,4 +5,10 @@ pub fn logout() -> Unit {
|
||||
wasmImportLogout();
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn reload() -> Unit {
|
||||
|
||||
wasmImportReload();
|
||||
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ pub(all) enum Request {
|
||||
Network(NetworkRequest)
|
||||
MoveInstance(InstanceMove)
|
||||
Shortcut(Int32)
|
||||
ReloadSession
|
||||
}
|
||||
|
||||
pub(all) struct SettingChange {
|
||||
|
||||
@@ -59,6 +59,7 @@ pub(all) enum Request {
|
||||
Network(NetworkRequest)
|
||||
MoveInstance(InstanceMove)
|
||||
Shortcut(Int)
|
||||
ReloadSession
|
||||
}
|
||||
///|
|
||||
/// A native file-chooser dialog (zenity on the host session) for "Add widget".
|
||||
@@ -570,6 +571,10 @@ pub fn next_request() -> Request? {
|
||||
|
||||
Request::Shortcut(mbt_ffi_load32((return_area) + 8))
|
||||
}
|
||||
17 => {
|
||||
|
||||
Request::ReloadSession
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
|
||||
+215
-8
@@ -1,5 +1,10 @@
|
||||
///| Kickoff-style application launcher: state machine + render logic. Pure;
|
||||
/// host capabilities (app list, launch) are passed in by the component stub.
|
||||
/// host capabilities (app list, launch, session and power actions) are passed in by the
|
||||
/// component stub.
|
||||
///
|
||||
/// The popup ends in a session row: Reload (reload the session's modules from disk), Log out,
|
||||
/// Suspend, Restart and Power off. Log out, Restart and Power off take a second click on the same
|
||||
/// button, like the Settings Power tab; Reload and Suspend act at once.
|
||||
|
||||
///| Which surface an event is addressed to (mirrors the WIT `surface` enum).
|
||||
pub(all) enum Target {
|
||||
@@ -13,11 +18,45 @@ pub struct State {
|
||||
mut query : String
|
||||
mut hover : Int
|
||||
mut error : String
|
||||
/// Session button under the pointer (-1: none).
|
||||
mut hover_action : Int
|
||||
/// Session button waiting for its confirming second click (-1: none).
|
||||
mut armed : Int
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn State::new() -> State {
|
||||
{ open: false, query: "", hover: -1, error: "" }
|
||||
{ open: false, query: "", hover: -1, error: "", hover_action: -1, armed: -1 }
|
||||
}
|
||||
|
||||
///| The session row's buttons, in order. `handle_event`'s `session` callback gets the index.
|
||||
pub let session_actions : Array[String] = [
|
||||
"Reload", "Log out", "Suspend", "Restart", "Power off",
|
||||
]
|
||||
|
||||
///| Index of each session action.
|
||||
pub let action_reload : Int = 0
|
||||
|
||||
///|
|
||||
pub let action_logout : Int = 1
|
||||
|
||||
///|
|
||||
pub let action_suspend : Int = 2
|
||||
|
||||
///|
|
||||
pub let action_restart : Int = 3
|
||||
|
||||
///|
|
||||
pub let action_power_off : Int = 4
|
||||
|
||||
///| Whether an action ends or interrupts the session and so takes a second click.
|
||||
pub fn needs_confirm(action : Int) -> Bool {
|
||||
action == action_logout || action == action_restart || action == action_power_off
|
||||
}
|
||||
|
||||
///| What the status line says while `action` is armed.
|
||||
fn confirm_hint(action : Int) -> String {
|
||||
"Click " + session_actions[action] + " again to confirm"
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -32,6 +71,19 @@ let row_h : Int = 46
|
||||
///|
|
||||
let max_rows : Int = 8
|
||||
|
||||
///| The session row at the bottom of the popup, and the status line above it (shown only when
|
||||
/// there is something to say: a launch error, or which button is waiting to be confirmed).
|
||||
let footer_h : Int = 44
|
||||
|
||||
///|
|
||||
let status_h : Int = 22
|
||||
|
||||
///|
|
||||
let footer_margin : Int = 8
|
||||
|
||||
///|
|
||||
let button_gap : Int = 4
|
||||
|
||||
///|
|
||||
fn ascii_lower(s : String) -> String {
|
||||
let sb = StringBuilder()
|
||||
@@ -75,7 +127,43 @@ fn visible_rows(n : Int) -> Int {
|
||||
pub fn popup_size(apps : Array[@types.AppEntry], st : State) -> @types.Size {
|
||||
let rows = visible_rows(filter(apps, st.query).length())
|
||||
let rows = if rows == 0 { 1 } else { rows }
|
||||
@ui.size(popup_w, header_h + rows * row_h + 8)
|
||||
let status = if status_text(st) == "" { 0 } else { status_h }
|
||||
@ui.size(popup_w, header_h + rows * row_h + 8 + status + footer_h)
|
||||
}
|
||||
|
||||
///| The status line's text: the launch error, else the confirm hint, else "".
|
||||
fn status_text(st : State) -> String {
|
||||
if st.error.length() > 0 {
|
||||
st.error
|
||||
} else if st.armed >= 0 {
|
||||
confirm_hint(st.armed)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
///| Width of each session button.
|
||||
fn button_w() -> Int {
|
||||
let n = session_actions.length()
|
||||
(popup_w - 2 * footer_margin - (n - 1) * button_gap) / n
|
||||
}
|
||||
|
||||
///| Popup-local rectangle (x, y, w, h) of session button `i` in a popup of height `h`.
|
||||
fn button_rect(i : Int, h : Int) -> (Int, Int, Int, Int) {
|
||||
let bw = button_w()
|
||||
(footer_margin + i * (bw + button_gap), h - footer_h + 6, bw, footer_h - 14)
|
||||
}
|
||||
|
||||
///| Session button under a popup-local point, or -1.
|
||||
pub fn action_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> Int {
|
||||
let h = popup_size(apps, st).h.reinterpret_as_int()
|
||||
for i = 0; i < session_actions.length(); i = i + 1 {
|
||||
let (x, y, w, bh) = button_rect(i, h)
|
||||
if p.x >= x && p.x < x + w && p.y >= y && p.y < y + bh {
|
||||
return i
|
||||
}
|
||||
}
|
||||
-1
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -83,6 +171,8 @@ pub fn close(st : State) -> Unit {
|
||||
st.open = false
|
||||
st.query = ""
|
||||
st.hover = -1
|
||||
st.hover_action = -1
|
||||
st.armed = -1
|
||||
}
|
||||
|
||||
///| The panel button: a crescent moon plus a label.
|
||||
@@ -150,8 +240,30 @@ pub fn render_popup(
|
||||
ops.push(@ui.text(56, y + 14, a.name, fs, fg, bold=true))
|
||||
ops.push(@ui.text(56, y + 31, a.comment, fs - 3, sub))
|
||||
}
|
||||
if st.error.length() > 0 {
|
||||
ops.push(@ui.text(14, h - 12, st.error, fs - 3, @ui.color(240, 90, 90, 255)))
|
||||
let status = status_text(st)
|
||||
if status != "" {
|
||||
let color = if st.error.length() > 0 { @ui.color(240, 90, 90, 255) } else { p.accent }
|
||||
ops.push(@ui.text(14, h - footer_h - status_h / 2, status, fs - 3, color, bold=st.error == ""))
|
||||
}
|
||||
// The session row, under a divider.
|
||||
ops.push(@ui.fill_rect(@ui.rect(footer_margin, h - footer_h, w - 2 * footer_margin, 1), p.border))
|
||||
for i = 0; i < session_actions.length(); i = i + 1 {
|
||||
let (bx, by, bw, bh) = button_rect(i, h)
|
||||
let armed = st.armed == i
|
||||
let hot = st.hover_action == i
|
||||
if armed {
|
||||
ops.push(@ui.fill_rect(@ui.rect(bx, by, bw, bh), p.accent, radius=r))
|
||||
} else if hot {
|
||||
ops.push(@ui.fill_rect(@ui.rect(bx, by, bw, bh), p.surface_hover, radius=r))
|
||||
}
|
||||
let fg = if armed {
|
||||
p.accent_foreground
|
||||
} else if hot {
|
||||
p.foreground
|
||||
} else {
|
||||
p.foreground_muted
|
||||
}
|
||||
ops.push(@ui.text(bx + bw / 2, by + bh / 2, session_actions[i], fs - 3, fg, align=CENTER, bold=armed))
|
||||
}
|
||||
ops
|
||||
}
|
||||
@@ -165,13 +277,15 @@ pub fn row_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> In
|
||||
if i < visible_rows(filter(apps, st.query).length()) { i } else { -1 }
|
||||
}
|
||||
|
||||
///| Handle an event. `launch` is the host capability. Returns true on redraw.
|
||||
///| Handle an event. `launch` is the host capability; `session` carries out a session-row action
|
||||
/// (an index into `session_actions`) once it is confirmed. Returns true on redraw.
|
||||
pub fn handle_event(
|
||||
apps : Array[@types.AppEntry],
|
||||
st : State,
|
||||
target : Target,
|
||||
ev : @types.InputEvent,
|
||||
launch : (String) -> Result[Unit, String],
|
||||
session~ : (Int) -> Unit = _ => (),
|
||||
) -> Bool {
|
||||
match (target, ev) {
|
||||
(Widget, PointerDown(_)) => {
|
||||
@@ -185,21 +299,30 @@ pub fn handle_event(
|
||||
}
|
||||
(Popup, PointerMove(p)) => {
|
||||
let i = row_at(apps, st, p)
|
||||
if i != st.hover {
|
||||
let a = action_at(apps, st, p)
|
||||
if i != st.hover || a != st.hover_action {
|
||||
st.hover = i
|
||||
st.hover_action = a
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
(Popup, PointerLeave) =>
|
||||
if st.hover != -1 {
|
||||
if st.hover != -1 || st.hover_action != -1 {
|
||||
st.hover = -1
|
||||
st.hover_action = -1
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
(Popup, PointerDown(p)) => {
|
||||
let a = action_at(apps, st, p)
|
||||
if a >= 0 {
|
||||
session_click(st, a, session)
|
||||
return true
|
||||
}
|
||||
st.armed = -1
|
||||
let i = row_at(apps, st, p)
|
||||
if i >= 0 {
|
||||
activate(apps, st, i, launch)
|
||||
@@ -241,6 +364,17 @@ pub fn handle_event(
|
||||
}
|
||||
}
|
||||
|
||||
///| A click on session button `a`: act now, or arm it and act on a second click.
|
||||
fn session_click(st : State, a : Int, session : (Int) -> Unit) -> Unit {
|
||||
if needs_confirm(a) && st.armed != a {
|
||||
st.armed = a
|
||||
st.error = ""
|
||||
return
|
||||
}
|
||||
close(st)
|
||||
session(a)
|
||||
}
|
||||
|
||||
///| Launch the i-th filtered app; a failure is shown in the popup (not hidden).
|
||||
fn activate(
|
||||
apps : Array[@types.AppEntry],
|
||||
@@ -332,3 +466,76 @@ test "search matches the app id and ranks name matches first" {
|
||||
let r = filter(apps, "kate")
|
||||
assert_eq(r.map(a => a.id), ["x.pad", "org.kde.kate"])
|
||||
}
|
||||
|
||||
///| Popup-local centre of session button `a` for the apps and state given.
|
||||
fn button_centre(apps : Array[@types.AppEntry], st : State, a : Int) -> @types.Point {
|
||||
let h = popup_size(apps, st).h.reinterpret_as_int()
|
||||
let (x, y, w, bh) = button_rect(a, h)
|
||||
{ x: x + w / 2, y: y + bh / 2 }
|
||||
}
|
||||
|
||||
///|
|
||||
test "session row: Reload and Suspend act at once, closing the menu" {
|
||||
let apps = sample_apps()
|
||||
let st = State::new()
|
||||
st.open = true
|
||||
let done : Array[Int] = []
|
||||
let p = button_centre(apps, st, action_reload)
|
||||
assert_eq(action_at(apps, st, p), action_reload)
|
||||
assert_true(handle_event(apps, st, Popup, PointerDown(p), _ => Ok(()), session=a => done.push(a)))
|
||||
assert_eq(done, [action_reload])
|
||||
assert_false(st.open)
|
||||
st.open = true
|
||||
let p = button_centre(apps, st, action_suspend)
|
||||
let _ = handle_event(apps, st, Popup, PointerDown(p), _ => Ok(()), session=a => done.push(a))
|
||||
assert_eq(done, [action_reload, action_suspend])
|
||||
}
|
||||
|
||||
///|
|
||||
test "session row: Log out, Restart and Power off take a second click" {
|
||||
let apps = sample_apps()
|
||||
let st = State::new()
|
||||
st.open = true
|
||||
let done : Array[Int] = []
|
||||
let session = a => done.push(a)
|
||||
let click = a => {
|
||||
let p = button_centre(apps, st, a)
|
||||
ignore(handle_event(apps, st, Popup, PointerDown(p), _ => Ok(()), session~))
|
||||
}
|
||||
click(action_logout)
|
||||
assert_eq(done, [])
|
||||
assert_eq(st.armed, action_logout)
|
||||
assert_true(st.open)
|
||||
// The popup grew a status line; the hint names the button.
|
||||
assert_eq(status_text(st), "Click Log out again to confirm")
|
||||
// Another armed button takes over; nothing runs.
|
||||
click(action_power_off)
|
||||
assert_eq(st.armed, action_power_off)
|
||||
assert_eq(done, [])
|
||||
click(action_power_off)
|
||||
assert_eq(done, [action_power_off])
|
||||
assert_false(st.open)
|
||||
assert_eq(st.armed, -1)
|
||||
// Closing the menu disarms: reopening and clicking once does nothing yet.
|
||||
st.open = true
|
||||
click(action_restart)
|
||||
ignore(handle_event(apps, st, Widget, FocusLost, _ => Ok(()), session~))
|
||||
st.open = true
|
||||
click(action_restart)
|
||||
assert_eq(done, [action_power_off])
|
||||
click(action_restart)
|
||||
assert_eq(done, [action_power_off, action_restart])
|
||||
}
|
||||
|
||||
///|
|
||||
test "session row: a click on an app disarms, and app rows don't reach the row" {
|
||||
let apps = sample_apps()
|
||||
let st = State::new()
|
||||
st.open = true
|
||||
let p = button_centre(apps, st, action_logout)
|
||||
assert_eq(row_at(apps, st, p), -1)
|
||||
ignore(handle_event(apps, st, Popup, PointerDown(p), _ => Ok(())))
|
||||
assert_eq(st.armed, action_logout)
|
||||
ignore(handle_event(apps, st, Popup, PointerDown({ x: 20, y: 60 }), _ => Ok(())))
|
||||
assert_eq(st.armed, -1)
|
||||
}
|
||||
@@ -7,7 +7,6 @@ shell shell
|
||||
tasks taskbar-widget
|
||||
layout layout-widget
|
||||
inspector inspector-widget
|
||||
logout logout-widget
|
||||
session-settings session-settings-widget
|
||||
screenshot screenshot-widget
|
||||
battery battery-widget
|
||||
|
||||
@@ -260,6 +260,7 @@ fn request_val(r : @wasm.HostRequest) -> @wt.Val {
|
||||
Some(Record([("action", S32(action)), ("ssid", Str(ssid)), ("password", Str(password))])),
|
||||
)
|
||||
Shortcut(n) => Variant("shortcut", Some(S32(n)))
|
||||
ReloadSession => Variant("reload-session", None)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,10 +122,13 @@ interface modules {
|
||||
browse: func();
|
||||
}
|
||||
|
||||
/// Ending the login session. A module with this capability is a logout button: the host stops the
|
||||
/// compositor, and the display manager takes the screen back.
|
||||
/// The login session. `logout` ends it: the host stops the compositor, and the display manager
|
||||
/// takes the screen back. `reload` reloads it in place: every loaded panel module is read from
|
||||
/// disk again (same order, same module settings) and the module list is rescanned; windows and
|
||||
/// running apps are untouched. The Application Launcher's session row uses both.
|
||||
interface session {
|
||||
logout: func();
|
||||
reload: func();
|
||||
}
|
||||
|
||||
/// The desktop wallpaper. The shell draws a fixed set of wallpapers (from draw ops, coloured by the
|
||||
|
||||
@@ -140,6 +140,8 @@ interface plasmoids {
|
||||
/// The shortcuts capability: action * 1000 + index (0 capture, 1 reset, 2 reset all,
|
||||
/// 3 cancel the capture).
|
||||
shortcut(s32),
|
||||
/// The session capability's `reload`: reload every loaded panel module from disk.
|
||||
reload-session,
|
||||
}
|
||||
/// The next pending request, oldest first.
|
||||
next-request: func() -> option<request>;
|
||||
|
||||
+4
-6
@@ -18,10 +18,14 @@ world configurable {
|
||||
export module-config;
|
||||
}
|
||||
|
||||
/// The application launcher (and the dock, which uses only the first two). The launcher's popup
|
||||
/// also ends in a session row: Reload, Log out, Suspend, Restart, Power off.
|
||||
world launcher-widget {
|
||||
include widget;
|
||||
import app-catalog;
|
||||
import app-launch;
|
||||
import session;
|
||||
import power;
|
||||
}
|
||||
|
||||
world panel {
|
||||
@@ -87,12 +91,6 @@ world plasmoid-host {
|
||||
export plasmoid;
|
||||
}
|
||||
|
||||
/// Logout button.
|
||||
world logout-widget {
|
||||
include widget;
|
||||
import session;
|
||||
}
|
||||
|
||||
/// The settings module: session switches (restore, window places, dark mode), the wallpaper, the
|
||||
/// panel's modules (load, unload, browse; the panel menu's "Modules..." opens that tab), and power
|
||||
/// (idle timeouts, battery, suspend / restart / power off) and keyboard shortcuts (rebind, reset).
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Logout button.
|
||||
@@ -1,2 +0,0 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
warnings = "-44"
|
||||
Reference in new issue
Block a user