M0: WIT package, MoonBit components, JS host, docs, CI #1
No files matched your search
@@ -0,0 +1,43 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
|
# Node (jco host + tests) and a recent glibc (the moon toolchain is dynamically linked).
|
||||||
|
container: node:20-bookworm
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install MoonBit
|
||||||
|
run: |
|
||||||
|
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
|
||||||
|
echo "$HOME/.moon/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Install wasm-tools, wit-bindgen, wasmtime
|
||||||
|
run: scripts/setup-toolchain.sh
|
||||||
|
|
||||||
|
- name: Install host dependencies (jco)
|
||||||
|
run: cd host && npm ci
|
||||||
|
|
||||||
|
- name: Versions
|
||||||
|
run: |
|
||||||
|
export PATH="$HOME/.moon/bin:$PWD/.tools/bin:$PATH"
|
||||||
|
moon version; wasm-tools --version; wit-bindgen --version; wasmtime --version
|
||||||
|
node --version; host/node_modules/.bin/jco --version
|
||||||
|
|
||||||
|
- name: Verify (bindings fresh, moon check/test, build, conformance, host tests)
|
||||||
|
run: |
|
||||||
|
export PATH="$HOME/.moon/bin:$PWD/.tools/bin:$PATH"
|
||||||
|
scripts/test.sh
|
||||||
|
|
||||||
|
- name: Headless render of the composed desktop
|
||||||
|
run: |
|
||||||
|
node host/src/cli.mjs --time 2026-11-24T14:07:00 --click-launcher | tail -n 45
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
_build/
|
||||||
|
build/
|
||||||
|
.tools/
|
||||||
|
node_modules/
|
||||||
|
.context/
|
||||||
|
.mooncakes/
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -1,3 +1,90 @@
|
|||||||
# moon-plasma
|
# moon-plasma
|
||||||
|
|
||||||
A modular KDE Plasma-like desktop shell in MoonBit where every part is a WebAssembly component
|
A modular, KDE-Plasma-inspired desktop environment where **every part is a
|
||||||
|
WebAssembly component** (Component Model, WIT interfaces) written in
|
||||||
|
[MoonBit](https://www.moonbitlang.com), on top of a deliberately tiny trusted host.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
*Headless-Chromium capture of the M0 browser host: the shell, the launcher and the clock
|
||||||
|
are three separate MoonBit components.*
|
||||||
|
|
||||||
|
## Vision
|
||||||
|
|
||||||
|
Plasma's strength is its decomposition (shell, widgets, window manager, runner,
|
||||||
|
settings modules, notifications, tray). moon-plasma keeps that decomposition and
|
||||||
|
makes each seam a **typed WIT interface** with **deny-by-default capabilities**:
|
||||||
|
|
||||||
|
* the **host** only owns engine/lifecycle, devices, the capability broker and the
|
||||||
|
render-list rasteriser;
|
||||||
|
* **everything else is a component**: swap the clock for another implementation,
|
||||||
|
swap the whole shell, change the theme, without rebuilding the rest;
|
||||||
|
* components draw by returning a **render-list** (`list<draw-op>`), never pixels;
|
||||||
|
* components can't touch anything their imports + the desktop config don't grant.
|
||||||
|
|
||||||
|
Read [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) (Plasma→component mapping, host
|
||||||
|
decision, rendering, input, permissions, versioning, roadmap M0–M8) and
|
||||||
|
[docs/TOOLCHAIN.md](docs/TOOLCHAIN.md) (what works today, exact versions).
|
||||||
|
|
||||||
|
## Status: M0 (proof of concept)
|
||||||
|
|
||||||
|
Works today:
|
||||||
|
|
||||||
|
* WIT package `moonplasma:desktop@0.1.0` (`wit/`): worlds `widget`, `clock-widget`,
|
||||||
|
`launcher-widget`, `panel`, `shell`.
|
||||||
|
* Four MoonBit components, each an independently built `.wasm` component of 24–33 KB:
|
||||||
|
`clock-digital`, `clock-binary` (drop-in replacement), `launcher` (kickoff-like with
|
||||||
|
keyboard search), `shell` (desktop background + bottom panel layout + theme tokens).
|
||||||
|
* Host (`host/`): Node + browser, jco-transpiled components, capability grants,
|
||||||
|
popup/focus input routing, hot-swap, fault isolation, Canvas2D + ASCII renderers.
|
||||||
|
* Tests: 16 MoonBit unit tests (pure logic), 13 host integration tests that
|
||||||
|
instantiate the real components, WIT conformance (`wasm-tools component targets`),
|
||||||
|
generated-bindings freshness check, `wasmtime compile` of every component.
|
||||||
|
|
||||||
|
Stubbed / not done (see ARCHITECTURE §10): no window manager/compositor, search runner,
|
||||||
|
notifications, settings, tray, session, shortcuts, clipboard, files; `launch` only logs;
|
||||||
|
host does input hit-testing; fixed-advance text metrics, no real fonts/icons; native
|
||||||
|
wasmtime host is M3; no CPU/fuel limits under jco.
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
|
Requirements: Linux x86_64, Node ≥ 20, [MoonBit](https://www.moonbitlang.com/download).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export PATH="$HOME/.moon/bin:$PATH"
|
||||||
|
scripts/setup-toolchain.sh # wasm-tools, wit-bindgen, wasmtime -> ./.tools (no root)
|
||||||
|
(cd host && npm ci) # jco
|
||||||
|
scripts/build.sh # MoonBit -> components -> build/components, build/jco
|
||||||
|
scripts/test.sh # everything CI runs
|
||||||
|
|
||||||
|
node host/src/cli.mjs --time 2026-11-24T14:07:00 --click-launcher # terminal render
|
||||||
|
node host/serve.mjs 8080 # browser host: http://127.0.0.1:8080/
|
||||||
|
node host/serve.mjs & # then try ?config=desktop.binary-clock.json or ?theme=moon-day
|
||||||
|
```
|
||||||
|
|
||||||
|
Swap the clock **without rebuilding anything else**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node host/src/cli.mjs --config config/desktop.binary-clock.json
|
||||||
|
scripts/build.sh clock-binary # builds just that component
|
||||||
|
# in the browser console: await moonPlasma.swap('clock', 'clock-binary')
|
||||||
|
```
|
||||||
|
|
||||||
|
Screenshots: see the end of [docs/TOOLCHAIN.md](docs/TOOLCHAIN.md).
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
```
|
||||||
|
wit/ the WIT package (host-agnostic API)
|
||||||
|
interface/ world/ generated shared MoonBit bindings (wit-bindgen; committed)
|
||||||
|
components/<n>/gen/ generated export bindings + hand-written thin stub.mbt
|
||||||
|
lib/ pure, unit-tested logic (ui helpers, panel layout, launcher state machine, ...)
|
||||||
|
host/ JS host: src/desktop.mjs (core), loaders, renderers, tests, web/ (browser)
|
||||||
|
config/ desktop configs (grants!), themes, static app list
|
||||||
|
scripts/ setup-toolchain, gen-bindings, build, test, screenshot
|
||||||
|
docs/ ARCHITECTURE, TOOLCHAIN, screenshots
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Apache-2.0 (see LICENSE).
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// 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 wasmExportInfo() -> Int {
|
||||||
|
@plasmoid.wasmExportInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
||||||
|
@plasmoid.wasmExportRender(p0, p1)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#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 wasmExportPopup() -> Int {
|
||||||
|
@plasmoid.wasmExportPopup()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#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)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
The widget (plasmoid) contract.
|
||||||
@@ -0,0 +1,409 @@
|
|||||||
|
// 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))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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 => ()
|
||||||
|
_ => 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))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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 => ()
|
||||||
|
_ => 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_load8_u(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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_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)
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/clock" @clock,
|
||||||
|
"moonplasma/desktop/lib/clock" @logic,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/clock-binary/gen/interface/moonplasma/desktop/plasmoid"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn info() -> PlasmoidInfo
|
||||||
|
|
||||||
|
pub fn on_event(Surface, @types.InputEvent) -> Bool
|
||||||
|
|
||||||
|
pub fn popup() -> PopupSurface?
|
||||||
|
|
||||||
|
pub fn render(@types.Size) -> Array[@types.DrawOp]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) struct PlasmoidInfo {
|
||||||
|
id : String
|
||||||
|
name : String
|
||||||
|
preferred : @types.Size
|
||||||
|
min_width : UInt32
|
||||||
|
stretch : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct PopupSurface {
|
||||||
|
size : @types.Size
|
||||||
|
ops : Array[@types.DrawOp]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum Surface {
|
||||||
|
WIDGET
|
||||||
|
POPUP
|
||||||
|
}
|
||||||
|
pub fn Surface::from(Int32) -> Self
|
||||||
|
pub fn Surface::ordinal(Self) -> Int32
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
///| Implementation of `moonplasma:desktop/plasmoid` for the binary clock.
|
||||||
|
/// All logic lives in lib/clock; this file only adapts host capabilities.
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn info() -> PlasmoidInfo {
|
||||||
|
let (id, name, w, h, min_w) = @logic.binary_info()
|
||||||
|
{
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() },
|
||||||
|
min_width: min_w.reinterpret_as_uint(),
|
||||||
|
stretch: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
|
||||||
|
@logic.render_binary(size, @theme.get_tokens(), @clock.now())
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn popup() -> PopupSurface? {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn on_event(_target : Surface, _event : @types.InputEvent) -> Bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/components/clock-binary/gen/interface/moonplasma/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:moonplasma:desktop/plasmoid@0.1.0#info",
|
||||||
|
"wasmExportInfoPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#info",
|
||||||
|
"wasmExportOnEvent:moonplasma:desktop/plasmoid@0.1.0#on-event",
|
||||||
|
"wasmExportPopup:moonplasma:desktop/plasmoid@0.1.0#popup",
|
||||||
|
"wasmExportPopupPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#popup",
|
||||||
|
"wasmExportRender:moonplasma:desktop/plasmoid@0.1.0#render",
|
||||||
|
"wasmExportRenderPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#render"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/clock-binary/gen"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// 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 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 wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
||||||
|
@plasmoid.wasmExportPopupPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportPopup() -> Int {
|
||||||
|
@plasmoid.wasmExportPopup()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
||||||
|
@plasmoid.wasmExportRender(p0, p1)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||||
|
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
The widget (plasmoid) contract.
|
||||||
@@ -0,0 +1,409 @@
|
|||||||
|
// 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))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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 => ()
|
||||||
|
_ => 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))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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 => ()
|
||||||
|
_ => 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_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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_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_store32(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||||
|
|
||||||
|
///|
|
||||||
|
#owned(str)
|
||||||
|
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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)
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/clock" @clock,
|
||||||
|
"moonplasma/desktop/lib/clock" @logic,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/clock-digital/gen/interface/moonplasma/desktop/plasmoid"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn info() -> PlasmoidInfo
|
||||||
|
|
||||||
|
pub fn on_event(Surface, @types.InputEvent) -> Bool
|
||||||
|
|
||||||
|
pub fn popup() -> PopupSurface?
|
||||||
|
|
||||||
|
pub fn render(@types.Size) -> Array[@types.DrawOp]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) struct PlasmoidInfo {
|
||||||
|
id : String
|
||||||
|
name : String
|
||||||
|
preferred : @types.Size
|
||||||
|
min_width : UInt32
|
||||||
|
stretch : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct PopupSurface {
|
||||||
|
size : @types.Size
|
||||||
|
ops : Array[@types.DrawOp]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum Surface {
|
||||||
|
WIDGET
|
||||||
|
POPUP
|
||||||
|
}
|
||||||
|
pub fn Surface::from(Int32) -> Self
|
||||||
|
pub fn Surface::ordinal(Self) -> Int32
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
///| Implementation of `moonplasma:desktop/plasmoid` for the digital clock.
|
||||||
|
/// All logic lives in lib/clock; this file only adapts host capabilities.
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn info() -> PlasmoidInfo {
|
||||||
|
let (id, name, w, h, min_w) = @logic.digital_info()
|
||||||
|
{
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() },
|
||||||
|
min_width: min_w.reinterpret_as_uint(),
|
||||||
|
stretch: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
|
||||||
|
@logic.render_digital(size, @theme.get_tokens(), @clock.now())
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn popup() -> PopupSurface? {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn on_event(_target : Surface, _event : @types.InputEvent) -> Bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/components/clock-digital/gen/interface/moonplasma/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:moonplasma:desktop/plasmoid@0.1.0#info",
|
||||||
|
"wasmExportInfoPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#info",
|
||||||
|
"wasmExportOnEvent:moonplasma:desktop/plasmoid@0.1.0#on-event",
|
||||||
|
"wasmExportPopup:moonplasma:desktop/plasmoid@0.1.0#popup",
|
||||||
|
"wasmExportPopupPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#popup",
|
||||||
|
"wasmExportRender:moonplasma:desktop/plasmoid@0.1.0#render",
|
||||||
|
"wasmExportRenderPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#render"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/clock-digital/gen"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// 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 wasmExportInfo() -> Int {
|
||||||
|
@plasmoid.wasmExportInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||||
|
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#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 wasmExportPopup() -> Int {
|
||||||
|
@plasmoid.wasmExportPopup()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
||||||
|
@plasmoid.wasmExportPopupPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
The widget (plasmoid) contract.
|
||||||
@@ -0,0 +1,409 @@
|
|||||||
|
// 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))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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 => ()
|
||||||
|
_ => 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))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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 => ()
|
||||||
|
_ => 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_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)
|
||||||
|
|
||||||
|
///|
|
||||||
|
#owned(str)
|
||||||
|
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||||
|
#|(func (param i32) (result i32) 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_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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_store32(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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)
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/app-catalog" @app_catalog,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/app-launch" @app_launch,
|
||||||
|
"moonplasma/desktop/lib/launcher" @logic,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/launcher/gen/interface/moonplasma/desktop/plasmoid"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn info() -> PlasmoidInfo
|
||||||
|
|
||||||
|
pub fn on_event(Surface, @types.InputEvent) -> Bool
|
||||||
|
|
||||||
|
pub fn popup() -> PopupSurface?
|
||||||
|
|
||||||
|
pub fn render(@types.Size) -> Array[@types.DrawOp]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) struct PlasmoidInfo {
|
||||||
|
id : String
|
||||||
|
name : String
|
||||||
|
preferred : @types.Size
|
||||||
|
min_width : UInt32
|
||||||
|
stretch : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct PopupSurface {
|
||||||
|
size : @types.Size
|
||||||
|
ops : Array[@types.DrawOp]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum Surface {
|
||||||
|
WIDGET
|
||||||
|
POPUP
|
||||||
|
}
|
||||||
|
pub fn Surface::from(Int32) -> Self
|
||||||
|
pub fn Surface::ordinal(Self) -> Int32
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
///| Implementation of `moonplasma:desktop/plasmoid` for the launcher.
|
||||||
|
/// The state machine lives in lib/launcher; this adapts host capabilities.
|
||||||
|
|
||||||
|
///|
|
||||||
|
let state : @logic.State = @logic.State::new()
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn info() -> PlasmoidInfo {
|
||||||
|
{
|
||||||
|
id: "org.moonplasma.launcher",
|
||||||
|
name: "Application Launcher",
|
||||||
|
preferred: { w: 150, h: 34 },
|
||||||
|
min_width: 60,
|
||||||
|
stretch: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
|
||||||
|
@logic.render_button(size, @theme.get_tokens(), state)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn popup() -> PopupSurface? {
|
||||||
|
if !state.open {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
let apps = @app_catalog.list_apps()
|
||||||
|
Some({
|
||||||
|
size: @logic.popup_size(apps, state),
|
||||||
|
ops: @logic.render_popup(apps, @theme.get_tokens(), state),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||||
|
let t : @logic.Target = match target {
|
||||||
|
WIDGET => Widget
|
||||||
|
POPUP => Popup
|
||||||
|
}
|
||||||
|
@logic.handle_event(@app_catalog.list_apps(), state, t, event, @app_launch.launch)
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/components/launcher/gen/interface/moonplasma/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:moonplasma:desktop/plasmoid@0.1.0#info",
|
||||||
|
"wasmExportInfoPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#info",
|
||||||
|
"wasmExportOnEvent:moonplasma:desktop/plasmoid@0.1.0#on-event",
|
||||||
|
"wasmExportPopup:moonplasma:desktop/plasmoid@0.1.0#popup",
|
||||||
|
"wasmExportPopupPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#popup",
|
||||||
|
"wasmExportRender:moonplasma:desktop/plasmoid@0.1.0#render",
|
||||||
|
"wasmExportRenderPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#render"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/launcher/gen"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// 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 wasmExportPopupPosition(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int, p9 : Int, p10 : Int, p11 : Int) -> Int {
|
||||||
|
@panel-layout.wasmExportPopupPosition(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRenderBackgroundPostReturn(p0 : Int) -> Unit {
|
||||||
|
@desktop-surface.wasmExportRenderBackgroundPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRenderPanelPostReturn(p0 : Int) -> Unit {
|
||||||
|
@panel-layout.wasmExportRenderPanelPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportComputeLayoutPostReturn(p0 : Int) -> Unit {
|
||||||
|
@panel-layout.wasmExportComputeLayoutPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportComputeLayout(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||||
|
@panel-layout.wasmExportComputeLayout(p0, p1, p2, p3)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRenderPanel(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) -> Int {
|
||||||
|
@panel-layout.wasmExportRenderPanel(p0, p1, p2, p3, p4, p5)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRenderBackground(p0 : Int, p1 : Int) -> Int {
|
||||||
|
@desktop-surface.wasmExportRenderBackground(p0, p1)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Desktop surface contract (wallpaper / desktop containment).
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRenderBackground(p0 : Int, p1 : Int) -> Int {
|
||||||
|
|
||||||
|
let (result) : (Array[@types.DrawOp]) = render_background(@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))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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 wasmExportRenderBackgroundPostReturn(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 => ()
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
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_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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)
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||||
|
"moonplasma/desktop/lib/shell" @logic,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/shell/gen/interface/moonplasma/desktop/desktop-surface"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn render_background(@types.Size) -> Array[@types.DrawOp]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
///| `moonplasma:desktop/desktop-surface` for the reference shell.
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn render_background(screen : @types.Size) -> Array[@types.DrawOp] {
|
||||||
|
@logic.render_background(screen, @theme.get_tokens())
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
declare pub fn render_background(screen : @types.Size) -> Array[@types.DrawOp]
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Panel layout/chrome contract (the plasmashell "containment" analogue).
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportComputeLayout(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||||
|
|
||||||
|
let array : Array[Slot] = [];
|
||||||
|
for index = 0; index < (p3); index = index + 1 {
|
||||||
|
let iter_base = (p2) + (index * 24)
|
||||||
|
|
||||||
|
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
|
||||||
|
|
||||||
|
array.push(Slot::{id : result, preferred : @types.Size::{w : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()}, min_width : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint(), stretch : (mbt_ffi_load8_u((iter_base) + 20) != 0), align : Edge::from(mbt_ffi_load8_u((iter_base) + 21))})
|
||||||
|
}
|
||||||
|
mbt_ffi_free(p2)
|
||||||
|
|
||||||
|
let (result0) : (Layout) = compute_layout(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()}, array);
|
||||||
|
let return_area = mbt_ffi_malloc(24)
|
||||||
|
mbt_ffi_store32((return_area) + 0, ((result0).panel).x)
|
||||||
|
mbt_ffi_store32((return_area) + 4, ((result0).panel).y)
|
||||||
|
mbt_ffi_store32((return_area) + 8, (((result0).panel).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 12, (((result0).panel).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc(((result0).placements).length() * 24);
|
||||||
|
for index1 = 0; index1 < ((result0).placements).length(); index1 = index1 + 1 {
|
||||||
|
let iter_elem : Placement = ((result0).placements)[(index1)]
|
||||||
|
let iter_base = address + (index1 * 24);
|
||||||
|
|
||||||
|
let ptr = mbt_ffi_str2ptr((iter_elem).id)
|
||||||
|
mbt_ffi_store32((iter_base) + 4, (iter_elem).id.length())
|
||||||
|
mbt_ffi_store32((iter_base) + 0, ptr)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, ((iter_elem).rect).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 12, ((iter_elem).rect).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 16, (((iter_elem).rect).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 20, (((iter_elem).rect).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 20, ((result0).placements).length())
|
||||||
|
mbt_ffi_store32((return_area) + 16, address)
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportComputeLayoutPostReturn(p0 : Int) -> Unit {
|
||||||
|
|
||||||
|
for index = 0; index < (mbt_ffi_load32((p0) + 20)); index = index + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((p0) + 16)) + (index * 24)
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((iter_base) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 16))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRenderPanel(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) -> Int {
|
||||||
|
|
||||||
|
let (result) : (Array[@types.DrawOp]) = render_panel(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()}, @types.Rect::{x : p2, y : p3, w : (p4).reinterpret_as_uint(), h : (p5).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))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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 wasmExportRenderPanelPostReturn(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 => ()
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportPopupPosition(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int, p9 : Int, p10 : Int, p11 : Int) -> Int {
|
||||||
|
|
||||||
|
let (result) : (@types.Rect) = popup_position(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()}, @types.Rect::{x : p2, y : p3, w : (p4).reinterpret_as_uint(), h : (p5).reinterpret_as_uint()}, @types.Rect::{x : p6, y : p7, w : (p8).reinterpret_as_uint(), h : (p9).reinterpret_as_uint()}, @types.Size::{w : (p10).reinterpret_as_uint(), h : (p11).reinterpret_as_uint()});
|
||||||
|
let return_area = mbt_ffi_malloc(16)
|
||||||
|
mbt_ffi_store32((return_area) + 0, (result).x)
|
||||||
|
mbt_ffi_store32((return_area) + 4, (result).y)
|
||||||
|
mbt_ffi_store32((return_area) + 8, ((result).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 12, ((result).h).reinterpret_as_int())
|
||||||
|
let ret = return_area
|
||||||
|
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_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_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_store32(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||||
|
|
||||||
|
///|
|
||||||
|
#owned(str)
|
||||||
|
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||||
|
"moonplasma/desktop/lib/shell" @shell,
|
||||||
|
"moonplasma/desktop/lib/panel" @panel,
|
||||||
|
"moonplasma/desktop/lib/ui" @ui,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/shell/gen/interface/moonplasma/desktop/panel-layout"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn compute_layout(@types.Size, Array[Slot]) -> Layout
|
||||||
|
|
||||||
|
pub fn popup_position(@types.Size, @types.Rect, @types.Rect, @types.Size) -> @types.Rect
|
||||||
|
|
||||||
|
pub fn render_panel(@types.Size, @types.Rect) -> Array[@types.DrawOp]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) enum Edge {
|
||||||
|
START
|
||||||
|
END
|
||||||
|
}
|
||||||
|
pub fn Edge::from(Int32) -> Self
|
||||||
|
pub fn Edge::ordinal(Self) -> Int32
|
||||||
|
|
||||||
|
pub(all) struct Layout {
|
||||||
|
panel : @types.Rect
|
||||||
|
placements : Array[Placement]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct Placement {
|
||||||
|
id : String
|
||||||
|
rect : @types.Rect
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct Slot {
|
||||||
|
id : String
|
||||||
|
preferred : @types.Size
|
||||||
|
min_width : UInt32
|
||||||
|
stretch : Bool
|
||||||
|
align : Edge
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
///| `moonplasma:desktop/panel-layout` for the reference shell. Geometry is in
|
||||||
|
/// lib/panel (pure, unit-tested); this adapts the WIT records.
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn compute_layout(screen : @types.Size, slots : Array[Slot]) -> Layout {
|
||||||
|
let t = @theme.get_tokens()
|
||||||
|
let margin = 5
|
||||||
|
let ins = slots.map(s => @panel.SlotIn::{
|
||||||
|
id: s.id,
|
||||||
|
pref_w: s.preferred.w.reinterpret_as_int(),
|
||||||
|
pref_h: s.preferred.h.reinterpret_as_int(),
|
||||||
|
min_w: s.min_width.reinterpret_as_int(),
|
||||||
|
stretch: s.stretch,
|
||||||
|
end_align: match s.align {
|
||||||
|
START => false
|
||||||
|
END => true
|
||||||
|
},
|
||||||
|
})
|
||||||
|
match @panel.layout(
|
||||||
|
screen.w.reinterpret_as_int(),
|
||||||
|
screen.h.reinterpret_as_int(),
|
||||||
|
t.panel_height.reinterpret_as_int(),
|
||||||
|
margin,
|
||||||
|
t.spacing.reinterpret_as_int(),
|
||||||
|
ins,
|
||||||
|
) {
|
||||||
|
// Fail loudly: a trap surfaces in the host as a component error.
|
||||||
|
Err(e) => abort("panel layout failed: " + e)
|
||||||
|
Ok(l) => {
|
||||||
|
panel: @ui.rect(l.x, l.y, l.w, l.h),
|
||||||
|
placements: l.placements.map(p => { id: p.id, rect: @ui.rect(p.x, p.y, p.w, p.h) }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn render_panel(_screen : @types.Size, panel : @types.Rect) -> Array[@types.DrawOp] {
|
||||||
|
@shell.render_panel(panel, @theme.get_tokens())
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn popup_position(
|
||||||
|
screen : @types.Size,
|
||||||
|
panel : @types.Rect,
|
||||||
|
anchor : @types.Rect,
|
||||||
|
popup : @types.Size,
|
||||||
|
) -> @types.Rect {
|
||||||
|
let (x, y) = @panel.popup_position(
|
||||||
|
screen.w.reinterpret_as_int(),
|
||||||
|
panel.y,
|
||||||
|
anchor.x,
|
||||||
|
popup.w.reinterpret_as_int(),
|
||||||
|
popup.h.reinterpret_as_int(),
|
||||||
|
8,
|
||||||
|
)
|
||||||
|
@ui.rect(x, y, popup.w.reinterpret_as_int(), popup.h.reinterpret_as_int())
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
pub(all) enum Edge {
|
||||||
|
START; END
|
||||||
|
} derive()
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn Edge::ordinal(self : Edge) -> Int {
|
||||||
|
match self {
|
||||||
|
START => 0
|
||||||
|
END => 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn Edge::from(self : Int) -> Edge {
|
||||||
|
match self {
|
||||||
|
0 => START
|
||||||
|
1 => END
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct Slot {
|
||||||
|
id : String; preferred : @types.Size; min_width : UInt; stretch : Bool; align : Edge
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct Placement {
|
||||||
|
id : String; rect : @types.Rect
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct Layout {
|
||||||
|
panel : @types.Rect; placements : Array[Placement]
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
/// Decide where the panel sits and where each widget goes.
|
||||||
|
declare pub fn compute_layout(screen : @types.Size, slots : Array[Slot]) -> Layout
|
||||||
|
///|
|
||||||
|
/// Panel background/frame (drawn beneath the widgets), in screen coords.
|
||||||
|
declare pub fn render_panel(screen : @types.Size, panel : @types.Rect) -> Array[@types.DrawOp]
|
||||||
|
///|
|
||||||
|
/// Place a popup of `popup` size for the widget at `anchor`.
|
||||||
|
declare pub fn popup_position(screen : @types.Size, panel : @types.Rect, anchor : @types.Rect, popup : @types.Size) -> @types.Rect
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/components/shell/gen/interface/moonplasma/desktop/desktop-surface" @desktop-surface,
|
||||||
|
"moonplasma/desktop/components/shell/gen/interface/moonplasma/desktop/panel-layout" @panel-layout,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
|
|
||||||
|
pkgtype(kind: "foreign_library")
|
||||||
|
|
||||||
|
options(
|
||||||
|
link: {
|
||||||
|
"wasm": {
|
||||||
|
"export-memory-name": "memory",
|
||||||
|
"heap-start-address": 16,
|
||||||
|
"exports": [
|
||||||
|
"mbt_ffi_cabi_realloc:cabi_realloc",
|
||||||
|
"wasmExportComputeLayout:moonplasma:desktop/panel-layout@0.1.0#compute-layout",
|
||||||
|
"wasmExportComputeLayoutPostReturn:cabi_post_moonplasma:desktop/panel-layout@0.1.0#compute-layout",
|
||||||
|
"wasmExportPopupPosition:moonplasma:desktop/panel-layout@0.1.0#popup-position",
|
||||||
|
"wasmExportRenderBackground:moonplasma:desktop/desktop-surface@0.1.0#render-background",
|
||||||
|
"wasmExportRenderBackgroundPostReturn:cabi_post_moonplasma:desktop/desktop-surface@0.1.0#render-background",
|
||||||
|
"wasmExportRenderPanel:moonplasma:desktop/panel-layout@0.1.0#render-panel",
|
||||||
|
"wasmExportRenderPanelPostReturn:cabi_post_moonplasma:desktop/panel-layout@0.1.0#render-panel"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/shell/gen"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[
|
||||||
|
{"id": "org.moonplasma.terminal", "name": "Terminal", "comment": "Command-line shell", "category": "System", "glyph": ">_"},
|
||||||
|
{"id": "org.moonplasma.files", "name": "Files", "comment": "Browse folders and files", "category": "Utilities", "glyph": "F"},
|
||||||
|
{"id": "org.moonplasma.browser", "name": "Web Browser", "comment": "Browse the web", "category": "Internet", "glyph": "W"},
|
||||||
|
{"id": "org.moonplasma.settings", "name": "System Settings", "comment": "Configure the desktop", "category": "System", "glyph": "S"},
|
||||||
|
{"id": "org.moonplasma.editor", "name": "Text Editor", "comment": "Edit plain text files", "category": "Utilities", "glyph": "T"},
|
||||||
|
{"id": "org.moonplasma.music", "name": "Music Player", "comment": "Play your music library", "category": "Multimedia", "glyph": "M"},
|
||||||
|
{"id": "org.moonplasma.calc", "name": "Calculator", "comment": "Do quick calculations", "category": "Utilities", "glyph": "="},
|
||||||
|
{"id": "org.moonplasma.monitor", "name": "System Monitor", "comment": "Processes and resources", "category": "System", "glyph": "%"},
|
||||||
|
{"id": "org.moonplasma.photos", "name": "Image Viewer", "comment": "View pictures", "category": "Graphics", "glyph": "I"},
|
||||||
|
{"id": "org.moonplasma.notes", "name": "Notes", "comment": "Sticky notes", "category": "Office", "glyph": "N"}
|
||||||
|
]
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"screen": {"w": 1280, "h": 720},
|
||||||
|
"theme": "moon-night",
|
||||||
|
"shell": {"component": "shell", "grants": ["theme"]},
|
||||||
|
"panel": [
|
||||||
|
{"id": "launcher", "component": "launcher", "align": "start", "grants": ["theme", "app-catalog", "app-launch"]},
|
||||||
|
{"id": "clock", "component": "clock-binary", "align": "end", "grants": ["theme", "clock"]}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"screen": {"w": 1280, "h": 720},
|
||||||
|
"theme": "moon-night",
|
||||||
|
"shell": {"component": "shell", "grants": ["theme"]},
|
||||||
|
"panel": [
|
||||||
|
{"id": "launcher", "component": "launcher", "align": "start", "grants": ["theme", "app-catalog", "app-launch"]},
|
||||||
|
{"id": "clock", "component": "clock-digital", "align": "end", "grants": ["theme", "clock"]}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "Moon Day",
|
||||||
|
"palette": {
|
||||||
|
"desktop-top": "#cfe3ff",
|
||||||
|
"desktop-bottom": "#8fb4e8",
|
||||||
|
"surface": "#f4f6fbf2",
|
||||||
|
"surface-hover": "#dde3f0",
|
||||||
|
"surface-popup": "#fbfcffF5",
|
||||||
|
"foreground": "#1b2233",
|
||||||
|
"foreground-muted": "#5b6577",
|
||||||
|
"accent": "#3b6bff",
|
||||||
|
"accent-foreground": "#ffffff",
|
||||||
|
"border": "#b9c3d6"
|
||||||
|
},
|
||||||
|
"font-size": 14,
|
||||||
|
"radius": 6,
|
||||||
|
"spacing": 6,
|
||||||
|
"panel-height": 44
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "Moon Night",
|
||||||
|
"palette": {
|
||||||
|
"desktop-top": "#16213e",
|
||||||
|
"desktop-bottom": "#0b1020",
|
||||||
|
"surface": "#1f2937f2",
|
||||||
|
"surface-hover": "#374151",
|
||||||
|
"surface-popup": "#111827f5",
|
||||||
|
"foreground": "#f3f4f6",
|
||||||
|
"foreground-muted": "#9ca3af",
|
||||||
|
"accent": "#7c9cff",
|
||||||
|
"accent-foreground": "#0b1020",
|
||||||
|
"border": "#3b4658"
|
||||||
|
},
|
||||||
|
"font-size": 14,
|
||||||
|
"radius": 6,
|
||||||
|
"spacing": 6,
|
||||||
|
"panel-height": 44
|
||||||
|
}
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
# moon-plasma architecture
|
||||||
|
|
||||||
|
> Status legend used throughout: **[M0]** implemented in this repository today,
|
||||||
|
> **[designed]** interface sketched here but not in `wit/` yet, **[open]** needs a decision.
|
||||||
|
|
||||||
|
moon-plasma is a KDE-Plasma-like desktop in which **every part is a WebAssembly
|
||||||
|
component** (Component Model, WIT-defined interfaces, written in MoonBit) running
|
||||||
|
on top of a deliberately tiny trusted **host**. The point is not to clone Plasma
|
||||||
|
pixel for pixel; it is to take Plasma's *decomposition* (shell / window manager /
|
||||||
|
runner / settings / notifications / tray / session …) and make each seam a typed,
|
||||||
|
versioned, permission-checked, hot-swappable interface.
|
||||||
|
|
||||||
|
## 1. Plasma → component-model map
|
||||||
|
|
||||||
|
| Plasma piece | What it does | moon-plasma counterpart | Component or host? |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `plasmashell` (containments, panels) | Hosts the desktop & panels, loads plasmoids | `shell` component exporting `desktop-surface` + `panel-layout` **[M0]** | component |
|
||||||
|
| Plasmoids / widgets (QML + C++/JS) | Clock, task manager, kickoff… | `widget` world exporting `plasmoid` **[M0]**: `digital-clock`, `binary-clock`, `launcher` | component, one instance per widget |
|
||||||
|
| Plasma Look-and-Feel, colour schemes, Breeze, Kirigami theme | Design tokens, icons, cursors, fonts | `theme` interface (`tokens`) **[M0]**; icon/cursor/font interfaces **[designed]**; a "look-and-feel" bundle = theme tokens + default layout + wallpaper | tokens served by a `theme-provider` component (M0: static JSON in host) |
|
||||||
|
| KWin (WM policy: stacking, focus, tiling, rules, virtual desktops) | Decides where windows go | `window-manager` world: exports `wm-policy` (place/resize/focus decisions), imports `window-registry` **[designed]** | component |
|
||||||
|
| KWin (compositing: scene graph, damage, scanout) | Draws windows to screen | Rasteriser/scanout of the **render-list** | **host** (only because it touches GPU/DRM) |
|
||||||
|
| KWin decorations (Aurorae etc.) | Titlebar/borders | `decoration` interface: returns draw-ops + hit regions for a window state **[designed]** | component |
|
||||||
|
| KWin effects / scripts | Overview, blur, wobbly… | `effect` interface: declarative per-frame transform of the scene (no raw shaders in M-early) **[designed]** | component (+ host primitives like blur) |
|
||||||
|
| KRunner / Kickoff search | Query many backends, ranked results | `search-provider` interface (`query(text) → list<match>`, `run(match)`); `runner` component fans out to providers **[designed]**. Launcher widget does substring search locally in M0 | components |
|
||||||
|
| System Settings + KCM modules | Config UIs per area | `settings-page` interface: a KCM is a component with grants only for its own config groups **[designed]** | components |
|
||||||
|
| KConfig / kconfig XT | Hierarchical typed config, cascading, immutable keys | `config-store` interface: `group/key → value` variant, change events, layered (system < user < activity) **[designed]** | store in **host** (needs durable FS), policy in components |
|
||||||
|
| KNotifications / `plasma-workspace` notification server | `org.freedesktop.Notifications`, history, DND | `notifications` interface (apps `notify`), `notification-center` component renders toasts + history **[designed]** | components |
|
||||||
|
| StatusNotifierItem / system tray | Tray icons + menus from apps | `tray-registry` (items register `tray-item` exports), `system-tray` widget **[designed]** | components |
|
||||||
|
| `ksmserver` / `startplasma` / systemd integration | Session start, restore, logout | `session` interface (logout, suspend, lock; power events) **[designed]**; **init sequence** = host reads `session.json`, starts a `session-manager` component which starts the rest | host (bootstrap only) + component |
|
||||||
|
| KGlobalAccel / KWin shortcuts | Global shortcuts | `shortcuts` interface: components register accelerators → action ids; host matches raw key events against the table **[designed]** | table in host (input path), policy in component |
|
||||||
|
| Activities (`kactivitymanagerd`) | Per-activity layouts/history | `activities` component holding current activity; `config-store` layering keys on it **[designed]** | component |
|
||||||
|
| KIO / Dolphin | URL-based VFS, file manager | `vfs` interface with URL schemes; `vfs-provider` components (`file`, `trash`, `sftp`…); Dolphin = a component app using `vfs` + `plasmoid`-style render lists **[designed]** | providers: components atop host `fs`/`net` capabilities |
|
||||||
|
| Klipper | Clipboard manager | `clipboard` interface (read/write typed MIME list; separate read/write grants) **[designed]** | host owns the system clipboard; history = component |
|
||||||
|
| Powerdevil, solid | Power & hardware | `power`/`devices` interfaces **[designed]** | host (hardware), policy = component |
|
||||||
|
| KScreen | Output config | `outputs` interface **[designed]** | host (display), UI = KCM component |
|
||||||
|
| KWallet | Secrets | `secrets` interface; separate trust level **[designed]** | component with a very narrow grant |
|
||||||
|
| Baloo | File index | `search-provider` over `vfs` **[designed]** | component |
|
||||||
|
| SDDM | Login | `login` world: a full shell variant that gets `auth` capability **[open]** | component |
|
||||||
|
|
||||||
|
## 2. What is in the host, and nothing else
|
||||||
|
|
||||||
|
The host is the trusted computing base. Rule of thumb: **if it can be expressed as
|
||||||
|
"a pure function of its inputs + capabilities we hand it", it is a component.**
|
||||||
|
The host only does what a component *cannot* do by construction:
|
||||||
|
|
||||||
|
1. **Engine & lifecycle** – compile/instantiate components, supervise them
|
||||||
|
(trap → visible fault + restart policy), enforce resource limits
|
||||||
|
(fuel/epoch deadlines on wasmtime; **not available under jco** — a looping
|
||||||
|
component can hang the M0 host, a known limitation), hot-swap instances.
|
||||||
|
2. **Capability broker** – owns the *only* path from components to the outside
|
||||||
|
world; wires each instance with exactly the interface implementations it is
|
||||||
|
granted (§6).
|
||||||
|
3. **Device ownership** – display/DRM/GPU, input devices (libinput), audio,
|
||||||
|
network sockets, real filesystem, clipboard, D-Bus/portal bridges. Components
|
||||||
|
see these only through narrow WIT interfaces.
|
||||||
|
4. **Render-list rasteriser / scanout** – turns the composed render-list into
|
||||||
|
pixels (Canvas2D in M0). It interprets a *closed vocabulary* of draw-ops; it
|
||||||
|
has no policy.
|
||||||
|
5. **Input demux & delivery** – reads raw events, applies the shortcut table,
|
||||||
|
delivers the rest to the focus/grab target the `window-manager`/shell
|
||||||
|
component names (§5).
|
||||||
|
6. **Bootstrap** – reads `session.json` (which components, which grants) and
|
||||||
|
starts the session-manager component.
|
||||||
|
|
||||||
|
Everything else – panel layout, window placement, focus policy, decorations,
|
||||||
|
theming, search, notifications, settings UIs, tray, the launcher – is a component
|
||||||
|
and can be replaced by a different `.wasm` that implements the same world.
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TB
|
||||||
|
subgraph host["host (trusted, small)"]
|
||||||
|
eng["engine + supervisor + hot-swap"]
|
||||||
|
cap["capability broker"]
|
||||||
|
ras["render-list rasteriser / scanout"]
|
||||||
|
inp["input demux"]
|
||||||
|
dev["devices: display, input, fs, net, clipboard"]
|
||||||
|
end
|
||||||
|
subgraph comps["components (sandboxed, swappable)"]
|
||||||
|
shell["shell (desktop-surface, panel-layout)"]
|
||||||
|
wm["window-manager policy"]
|
||||||
|
w1["widget: clock"]
|
||||||
|
w2["widget: launcher"]
|
||||||
|
run["runner + search providers"]
|
||||||
|
notif["notification-center"]
|
||||||
|
kcm["settings pages"]
|
||||||
|
end
|
||||||
|
comps -- "typed WIT calls\n(host-mediated)" --> host
|
||||||
|
host -- "render-list" --> ras --> dev
|
||||||
|
dev -- "raw input" --> inp --> comps
|
||||||
|
cap --- comps
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Component-to-component communication: host-mediated calls (decision)
|
||||||
|
|
||||||
|
Options considered:
|
||||||
|
|
||||||
|
| | static composition (`wasm-tools compose`/WAC) | dynamic linking / shared-everything | **host-mediated typed calls (chosen)** |
|
||||||
|
|---|---|---|---|
|
||||||
|
| Hot-swap one part | re-link and restart the composite | not available in toolchains yet | swap one instance; others keep state |
|
||||||
|
| Per-link capability attenuation | none (composed = same trust) | none | yes: each instance gets its own import wiring |
|
||||||
|
| Fault isolation | one trap kills the composite | n/a | per-instance |
|
||||||
|
| Third-party/untrusted widgets | no | no | yes |
|
||||||
|
| Cost | none (direct calls) | none | host call per hop (JS: ~µs; fine for UI-rate calls) |
|
||||||
|
| Maturity today | good (`wac`, `wasm-tools compose`) | immature | works now (what M0 does) |
|
||||||
|
|
||||||
|
**Decision:** components never call each other directly. The host holds the
|
||||||
|
instances and routes: today it is hub-and-spoke (host → shell for layout, host →
|
||||||
|
widget for render/events, as in `host/src/desktop.mjs`), later through a
|
||||||
|
**service registry**: a component *exports* a typed interface (e.g.
|
||||||
|
`search-provider`), the host lets *importers* with the matching grant call it,
|
||||||
|
via a host-owned `registry` interface (`lookup(interface-name) → handle`).
|
||||||
|
Messages stay typed WIT values (records/variants); no stringly-typed JSON bus.
|
||||||
|
Event broadcast (theme changed, activity changed) is a `subscribe/poll` pair
|
||||||
|
until component-model async (WASI p3) is usable in our hosts.
|
||||||
|
|
||||||
|
Static composition remains available as a **build-time optimisation inside one
|
||||||
|
trust domain** (e.g. fusing `shell` with a built-in tray into one `.wasm`), never
|
||||||
|
across grants.
|
||||||
|
|
||||||
|
## 4. Rendering: shared render-list, not per-component textures (decision)
|
||||||
|
|
||||||
|
Components return **render-lists** (`list<draw-op>`, see `wit/types.wit`) in
|
||||||
|
their own local coordinates; the host/compositor translates, clips, orders and
|
||||||
|
rasterises them. Components never receive pixels or GPU handles.
|
||||||
|
|
||||||
|
Why: it is sandbox-friendly (no shared memory, nothing to leak or overrun),
|
||||||
|
serialisable (record/replay, remote desktop, golden-file tests — the ASCII and
|
||||||
|
scene-JSON dumps in M0 are exactly this), host-agnostic (Canvas2D now,
|
||||||
|
Skia/wgpu/software later, all from the same WIT), and cheap for UI-sized scenes.
|
||||||
|
|
||||||
|
Costs and mitigations: (a) copying lists across the boundary each frame →
|
||||||
|
add a revision counter and let `render` return "unchanged" so the host reuses the
|
||||||
|
cached list; add damage rects; (b) text needs metrics → M0 uses a fixed 0.6 em
|
||||||
|
advance contract; a host `text` interface (`measure`, shaping, fonts) is the next
|
||||||
|
step; (c) content that is *not* vector (video, foreign Wayland/X clients, WebGL
|
||||||
|
canvases) → add a second surface kind: a WIT **resource** `buffer-surface`
|
||||||
|
(dmabuf/shm handle owned by the host, written by a granted producer) which the
|
||||||
|
render-list references via a `draw-surface` op **[designed, M5]**.
|
||||||
|
|
||||||
|
The UI toolkit question: components can link any MoonBit library into
|
||||||
|
themselves. `moon-gpui` (GPUI port) is a natural fit because its scene/geometry/
|
||||||
|
colour packages map almost 1:1 onto our draw-op vocabulary; in that arrangement
|
||||||
|
GPUI runs *inside each component* and its scene is flattened into
|
||||||
|
`list<draw-op>`. This is **[open]**: `/workspace/moon-gpui` currently only has a
|
||||||
|
README, so nothing was verified.
|
||||||
|
|
||||||
|
## 5. Input routing
|
||||||
|
|
||||||
|
* The host reads raw device events and (a) matches them against the global
|
||||||
|
shortcut table, (b) otherwise hands them to the **routing component**:
|
||||||
|
`window-manager`/`shell` returns the target (surface id, local coordinates,
|
||||||
|
grab/focus changes). This keeps focus-follows-mouse, click-to-raise, tiling
|
||||||
|
gestures, etc. as replaceable policy.
|
||||||
|
* **[M0 shortcut, stated honestly]** the host itself does hit-testing against the
|
||||||
|
placements the shell returned, and routes: popup > widget under pointer;
|
||||||
|
pointer-down outside an open popup sends `focus-lost` to the popup owner, then
|
||||||
|
falls through. Keyboard goes to the popup owner. This is ~60 lines of host code
|
||||||
|
and is the first thing to move into the shell component (M2).
|
||||||
|
* Events are values (`input-event` variant), delivered with surface-local
|
||||||
|
coordinates, so a component never learns screen geometry it was not given.
|
||||||
|
|
||||||
|
## 6. Permission / capability model
|
||||||
|
|
||||||
|
WASI-style, deny-by-default:
|
||||||
|
|
||||||
|
1. A component's **imports are its declared needs.** `scripts/build.sh` records
|
||||||
|
them in `build/components/<n>.meta.json` (derived from the binary).
|
||||||
|
2. The **desktop config** (`config/desktop.json`) *grants* capabilities per
|
||||||
|
component instance. **[M0]** The host refuses to start a component whose
|
||||||
|
imports are not all granted (`PermissionError`), rejects unknown capability
|
||||||
|
names, and wires only granted interfaces into the import object.
|
||||||
|
Tests: `host/test/desktop.test.mjs`.
|
||||||
|
3. **Attenuation, not just on/off [designed]:** a grant supplies the host's
|
||||||
|
implementation of the interface *for that instance*: a `vfs` granted to
|
||||||
|
System Settings is rooted at `~/.config`, the same interface granted to a
|
||||||
|
file manager is rooted at `$HOME`; `config-store` is scoped to named groups;
|
||||||
|
`net` carries a host allowlist.
|
||||||
|
4. **Unforgeable handles:** capabilities that are objects (an open file, a
|
||||||
|
`buffer-surface`, a notification handle) are WIT `resource`s — a component can
|
||||||
|
only use handles the host gave it.
|
||||||
|
5. **User consent [designed]:** requests outside the manifest go to a
|
||||||
|
`permission-prompt` component (itself heavily restricted); decisions persist in
|
||||||
|
`config-store`.
|
||||||
|
6. **Supervision [M0 partial]:** a trapping component becomes a *visible* error
|
||||||
|
tile + a recorded fault (never swallowed); the CLI exits non-zero when faults
|
||||||
|
exist. Automatic restart/backoff is **[designed]**.
|
||||||
|
|
||||||
|
## 7. Versioning WIT packages
|
||||||
|
|
||||||
|
* Packages are semver'd (`moonplasma:desktop@0.1.0`). While `0.x`, any minor may
|
||||||
|
break; components pin the exact package version in their world.
|
||||||
|
* From `1.0`: **additive-only minors** – new interfaces, new functions, new
|
||||||
|
worlds, new variant cases at the *end* only when consumers are required to
|
||||||
|
handle unknown cases. WIT records cannot grow compatibly, so anything likely to
|
||||||
|
grow (e.g. `plasmoid-info`, `tokens`) should become `record` + `option`/`list`
|
||||||
|
extension points before 1.0, or be replaced by a new interface version
|
||||||
|
(`plasmoid@1.1`) that the host serves alongside the old one.
|
||||||
|
* Split by domain so versions move independently: `moonplasma:desktop` (types,
|
||||||
|
theme, plasmoid, panel), later `moonplasma:wm`, `moonplasma:search`,
|
||||||
|
`moonplasma:notify`, `moonplasma:config`, `moonplasma:session`, `moonplasma:vfs`.
|
||||||
|
* The host advertises the set of interface versions it implements and may
|
||||||
|
serve N and N-1 side by side via adapters; a component declares what it
|
||||||
|
targets and fails to load otherwise (no silent downgrade).
|
||||||
|
* CI gate **[M0]**: every component must pass `wasm-tools component targets
|
||||||
|
--world <w> wit <component>`; generated bindings must match `wit/`
|
||||||
|
(`scripts/gen-bindings.sh --check`). Registry publication (OCI/warg) **[open]**.
|
||||||
|
|
||||||
|
## 8. Host strategy (decision and feasibility)
|
||||||
|
|
||||||
|
| Option | What it is | Time-to-pixels | Fits the "everything is a component" goal | Main risks |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| **(a) Browser/Node host with jco** | components transpiled to JS+core wasm; host in JS; Canvas2D now, WebGPU later | **hours — done in M0** | components yes; host = JS runtime (large TCB: browser) | no real windows/devices; JS can't pre-empt a looping component; browser is not a desktop session |
|
||||||
|
| **(b) Native host embedding wasmtime** | Rust host using `wasmtime::component` + `bindgen!`; software/GPU rendering into a window (winit/SDL) or DRM | days–weeks | best: small native TCB, fuel/epoch limits, real FS/net/devices | host is Rust, not MoonBit; wasmtime's C API cannot instantiate components with host imports as conveniently, so a MoonBit-native host via FFI is **unverified** and probably not worth it |
|
||||||
|
| **(c) Nested compositor in an existing session** | (b) running as a window/Wayland client first, later a real compositor (smithay) hosting foreign Wayland apps | weeks–months | needed to run real apps | scope; Wayland/EGL/input details |
|
||||||
|
|
||||||
|
**Recommendation:** (a) for M0–M2 (done: it is the fastest way to prove the WIT
|
||||||
|
design with real MoonBit components), then (b) as the *reference host* in M3–M4
|
||||||
|
using the **same WIT and the same build outputs** (the components are standard;
|
||||||
|
only `host/` changes), then (c) from M5 as the path to real windows. The WIT stays
|
||||||
|
host-agnostic: nothing in `wit/` mentions JS, a browser or a window system. What
|
||||||
|
does **not** transfer is `host/src/desktop.mjs`; it is intentionally small
|
||||||
|
(~200 lines) and is the executable spec for the Rust host.
|
||||||
|
|
||||||
|
## 9. Interface catalogue
|
||||||
|
|
||||||
|
Implemented in `wit/` (package `moonplasma:desktop@0.1.0`):
|
||||||
|
|
||||||
|
| Interface | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `types` | geometry, colour, `draw-op` render-list vocabulary, `input-event`, `datetime`, `app-entry` |
|
||||||
|
| `theme` | `get-tokens()` – palette + metrics (read per render so theme swaps are live) |
|
||||||
|
| `plasmoid` (export) | `info`, `render(size)`, `popup`, `on-event(surface, event)` |
|
||||||
|
| `panel-layout` (export) | `compute-layout`, `render-panel`, `popup-position` |
|
||||||
|
| `desktop-surface` (export) | `render-background` |
|
||||||
|
| `clock`, `app-catalog`, `app-launch` (imports) | host capabilities used by the PoC widgets |
|
||||||
|
|
||||||
|
Worlds: `widget` (theme + plasmoid), `clock-widget`, `launcher-widget`, `panel`, `shell`.
|
||||||
|
|
||||||
|
Designed next (no WIT yet): `window-registry`/`wm-policy`/`decoration`, `search-provider`,
|
||||||
|
`config-store`, `notifications`, `tray-registry`, `shortcuts`, `clipboard`, `session`/`power`,
|
||||||
|
`vfs`, `activities`, `settings-page`, `registry`, `buffer-surface`, `text`.
|
||||||
|
|
||||||
|
## 10. What is a PoC stub today
|
||||||
|
|
||||||
|
* Host does hit-testing/routing (see §5), time and app list are host-provided statics.
|
||||||
|
* `app-launch.launch` records the id and logs; it does not start anything.
|
||||||
|
* Text uses a fixed-advance contract; no font/shaping/icon interfaces (glyph letters stand in for icons).
|
||||||
|
* No window manager, compositor, notifications, settings, tray, session, shortcuts, clipboard, files.
|
||||||
|
* Theme is a JSON file read by the host, not a `theme-provider` component.
|
||||||
|
* No resource limits under jco; no hot reload on file change (swap is an API call).
|
||||||
|
|
||||||
|
## 11. Roadmap
|
||||||
|
|
||||||
|
| M | Goal | Status |
|
||||||
|
|---|---|---|
|
||||||
|
| **M0** | Toolchain proof, WIT v0.1 (`widget`/`panel`/`shell`), host (Node+browser), 4 components, tests, CI, swap/theme/permission demos | **done (this PR)** |
|
||||||
|
| M1 | `config-store` + `theme-provider` component; persisted settings; hot reload of `.wasm` on change; `text` interface (measure/fonts) and icon theme | next |
|
||||||
|
| M2 | Move input routing + focus policy into the shell/WM component; more widgets (task manager stub, system tray, notifications toasts); `search-provider` + KRunner component | |
|
||||||
|
| M3 | Native reference host: Rust + wasmtime (`bindgen!`), software rasteriser into a winit window, fuel/epoch limits, restart supervision; CI runs the *same* integration tests against both hosts | |
|
||||||
|
| M4 | Window-manager world with synthetic windows (no real apps yet): stacking/tiling policies as swappable components, decorations, virtual desktops, activities | |
|
||||||
|
| M5 | Nested compositor (smithay) hosting real Wayland clients; `buffer-surface` resource; GPU rasteriser | |
|
||||||
|
| M6 | Settings (KCM-style) framework, notifications daemon bridge (D-Bus portal), tray (SNI bridge), clipboard, power/session | |
|
||||||
|
| M7 | `vfs` + file manager component; search/indexer; look-and-feel packages | |
|
||||||
|
| M8 | Standalone session (DRM/KMS + libinput), login manager world, packaging/registry for components | |
|
||||||
|
|
||||||
|
## 12. Open design questions (with recommendations)
|
||||||
|
|
||||||
|
1. **Host language/long-term host** — Rust+wasmtime native host vs trying to keep even the host in MoonBit. *Recommend Rust+wasmtime for M3; revisit MoonBit-native host only if wasmtime's C API gains full component embedding.*
|
||||||
|
2. **Render-list vs textures** — *Recommend render-list as the default, `buffer-surface` resource only for non-vector content (§4).*
|
||||||
|
3. **UI toolkit inside components** — adopt `moon-gpui` or a tiny immediate-mode helper (`lib/ui`)? *Recommend `lib/ui` until moon-gpui has a stable scene package and a flatten-to-draw-op adapter, then migrate widget internals; keep the WIT draw-op vocabulary as the stable boundary.*
|
||||||
|
4. **Text and fonts** — host-provided shaping (`text` interface) vs components bundling a shaper. *Recommend host-provided: layout needs metrics from the same engine that rasterises.*
|
||||||
|
5. **Async** — wait for WASI p3 async in jco/wasmtime/wit-bindgen-moonbit or keep sync + poll. *Recommend sync + poll through M3; the backend support exists but hosts are not uniformly ready.*
|
||||||
|
6. **Who owns hit-testing** — move to the shell/WM component at M2 (§5). *Recommend yes, host only for grabs it must enforce (shortcuts, secure attention).*
|
||||||
|
7. **Config format & ownership** — KConfig-like INI layering vs structured store. *Recommend a typed `config-store` with layered scopes (system/user/activity) and change events; INI import/export as a component.*
|
||||||
|
8. **Packaging & trust** — signed component bundles with manifests (grants requested, WIT versions targeted) vs bare `.wasm` + config. *Recommend a manifest custom section in the `.wasm` + signature, host shows requested grants; M3+.*
|
||||||
|
9. **Foreign-app strategy** — nested Wayland (M5) vs only native components. *Recommend nested Wayland; otherwise the desktop is not usable day to day.*
|
||||||
|
10. **Plasma compatibility** — try to load real plasmoid QML/KPackages? *Recommend no; mimic concepts (containments, plasmoids, KCM, KRunner plugins) but not binary/QML compatibility.*
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
# Toolchain: what works today (verified 2026-11-24)
|
||||||
|
|
||||||
|
Everything here was run on x86_64 Linux (glibc 2.43 locally; CI uses
|
||||||
|
`node:20-bookworm`, glibc 2.36), without root.
|
||||||
|
|
||||||
|
## Verdict
|
||||||
|
|
||||||
|
**MoonBit can produce real WebAssembly Components today**, via the official
|
||||||
|
`wit-bindgen moonbit` backend plus `wasm-tools component new`. No MoonBit
|
||||||
|
compiler flag is needed: MoonBit emits a *core* wasm module (linear-memory
|
||||||
|
`wasm` target) that exports the canonical-ABI symbols `wit-bindgen` generated,
|
||||||
|
and `wasm-tools` wraps it into a component.
|
||||||
|
|
||||||
|
| Piece | Status | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| `moon build --target wasm` | works | Used for all components (linear memory, own GC/alloc). |
|
||||||
|
| `moon build --target wasm-gc` | not usable for components | The canonical ABI needs linear memory + `cabi_realloc`; wit-bindgen's MoonBit backend targets `wasm` only (`preferred_target = "wasm"` in the generated `moon.mod`). |
|
||||||
|
| `wit-bindgen moonbit` (0.63.0) | works | Generates guest bindings: types, imports, `declare pub fn` stubs for exports, `link.exports` config. Handles records, variants, enums, options, results, lists, strings. Resources/async/streams exist in the backend but are **not** used here. |
|
||||||
|
| `wasm-tools component embed/new` (1.263.0) | works | `--encoding utf16` (MoonBit strings are UTF-16). |
|
||||||
|
| `wasm-tools component targets` | works | Used as a **WIT conformance test**: asserts each component implements its declared world. |
|
||||||
|
| `jco transpile` (1.42.0) | works | Component → JS + core wasm. Used for the M0 host. `--instantiation async` lets the host pass a *per-instance* import object, which is how capability grants work. |
|
||||||
|
| `wasmtime` (51.0.0) | validates/compiles | `wasmtime compile` accepts every component. We do **not** run them under wasmtime yet: a component with host imports needs an embedder (Rust/C-API) to supply them — `wasmtime run` cannot. That is M4. |
|
||||||
|
| mooncakes packages | see below | Nothing needed at M0. |
|
||||||
|
|
||||||
|
### Pipeline
|
||||||
|
|
||||||
|
```
|
||||||
|
wit/*.wit ──wit-bindgen moonbit──▶ interface/ world/ components/<n>/gen/ (committed)
|
||||||
|
│ + stub.mbt (hand-written, thin) → lib/* (pure logic, unit-tested)
|
||||||
|
moon build --target wasm --release ──▶ _build/.../gen.wasm (core module)
|
||||||
|
wasm-tools component embed wit --world W --encoding utf16 ─▶ wasm-tools component new ─▶ build/components/<n>.wasm
|
||||||
|
wasm-tools component targets --world W wit <n>.wasm (conformance)
|
||||||
|
jco transpile --instantiation async ─▶ build/jco/<n>/ (host glue)
|
||||||
|
```
|
||||||
|
|
||||||
|
Component sizes are 24–33 KB each (release build, no wasm-opt).
|
||||||
|
|
||||||
|
### Workflow details / gotchas found
|
||||||
|
|
||||||
|
* `wit-bindgen moonbit` does **not** write a stub for exported functions in this
|
||||||
|
version; export packages contain `declare pub fn …` and you implement them in
|
||||||
|
a `stub.mbt` *in the same package*. We keep `stub.mbt` to adapters only; logic
|
||||||
|
lives in `lib/*` packages so `moon test` can cover it.
|
||||||
|
* Using one `--out-dir .` with a distinct `--gen-dir components/<n>/gen` per
|
||||||
|
component makes all components share **one** copy of the imported types
|
||||||
|
(`interface/…/types`), so `lib/*` helpers work across components.
|
||||||
|
* Generated helper functions are emitted in nondeterministic order, so
|
||||||
|
`scripts/gen-bindings.sh --check` compares sorted lines, not bytes.
|
||||||
|
* `moon.mod.json` is no longer accepted by this moon (0.1.20261119): use `moon.mod`.
|
||||||
|
* jco strips the `@version` from import keys (`moonplasma:desktop/clock`), and
|
||||||
|
maps WIT `variant` → `{tag, val}`, `enum` → string, `option` → value/`undefined`,
|
||||||
|
`result` import returns → `{tag:'ok'|'err', val}` (or throw).
|
||||||
|
* `moon test` runs on the wasm target through `moonrun`; packages that import the
|
||||||
|
generated `types` package are testable (the extern "wasm" helpers are only called
|
||||||
|
at the boundary).
|
||||||
|
* wit-bindgen 0.63 moonbit emits deprecation warnings under newer moon
|
||||||
|
(`#deprecated pub extend`); harmless.
|
||||||
|
|
||||||
|
### Packages surveyed on mooncakes.io (for later milestones)
|
||||||
|
|
||||||
|
| Package | Relevance | Backends / caveat |
|
||||||
|
|---|---|---|
|
||||||
|
| `mizchi/wit` 0.4.x | WIT parser/resolver in MoonBit | could power an in-MoonBit `moon-plasma` CLI that inspects worlds; not needed at M0 |
|
||||||
|
| `moonrockz/wit` | WIT scanner/CST/formatter | same |
|
||||||
|
| `mizchi/wite` 0.11 | component-aware analyzer/optimizer (`wite` can verify a component against WIT, compose WAC) | candidate replacement for `wasm-tools` size/verify steps |
|
||||||
|
| `moonbitlang/async` | async runtime (native/…); not a component-model async | the component-model async ABI (WASIp3) is in wit-bindgen's backend but out of scope until hosts support it |
|
||||||
|
| `moonbitlang/core/json` | JSON | core, all backends — for the settings store (M3) |
|
||||||
|
|
||||||
|
The `wasm2elf-mb`, `moonview`, `webby`, `curl-wasm`, `moon-mud` and `moon-gpui`
|
||||||
|
checkouts on this machine were consulted for conventions only; nothing is
|
||||||
|
imported from them. (`moon-gpui` currently contains only a README here — the
|
||||||
|
`docs/PORTING.md` referenced in the task is not present in `/workspace/moon-gpui`.)
|
||||||
|
|
||||||
|
## Exact setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. MoonBit (not installed by our scripts)
|
||||||
|
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash # moon 0.1.20261119
|
||||||
|
export PATH="$HOME/.moon/bin:$PATH"
|
||||||
|
|
||||||
|
# 2. wasm-tools, wit-bindgen, wasmtime → ./.tools/bin (versions in scripts/versions.env)
|
||||||
|
scripts/setup-toolchain.sh
|
||||||
|
|
||||||
|
# 3. jco + playwright-core → host/node_modules (Node ≥ 20)
|
||||||
|
(cd host && npm ci)
|
||||||
|
|
||||||
|
# 4. build every component, then test everything
|
||||||
|
scripts/build.sh # or: scripts/build.sh clock-binary (one component only)
|
||||||
|
scripts/test.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Pinned versions: moon 0.1.20261119 (moonc `738607b`), wasm-tools 1.263.0,
|
||||||
|
wit-bindgen 0.63.0, wasmtime 51.0.0, jco 1.42.0, Node 20/24.
|
||||||
|
|
||||||
|
### Hello-world proof (what `scripts/build.sh` does for `clock-digital`)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wit-bindgen moonbit wit --world clock-widget --out-dir . \
|
||||||
|
--gen-dir components/clock-digital/gen --project-name moonplasma/desktop --ignore-module-file
|
||||||
|
moon build --target wasm --release
|
||||||
|
wasm-tools component embed wit _build/wasm/release/build/components/clock-digital/gen/gen.wasm \
|
||||||
|
--world clock-widget --encoding utf16 -o e.wasm
|
||||||
|
wasm-tools component new e.wasm -o build/components/clock-digital.wasm
|
||||||
|
wasm-tools component wit build/components/clock-digital.wasm
|
||||||
|
# world root { import moonplasma:desktop/types@0.1.0;
|
||||||
|
# import moonplasma:desktop/clock@0.1.0;
|
||||||
|
# import moonplasma:desktop/theme@0.1.0;
|
||||||
|
# export moonplasma:desktop/plasmoid@0.1.0; }
|
||||||
|
jco transpile build/components/clock-digital.wasm -o build/jco/clock-digital --instantiation async
|
||||||
|
node host/src/cli.mjs --time 2026-11-24T14:07:00 # instantiates all components, prints the desktop
|
||||||
|
```
|
||||||
|
|
||||||
|
### Browser screenshots
|
||||||
|
|
||||||
|
`scripts/screenshot.mjs` drives the browser host in headless Chromium through
|
||||||
|
`playwright-core`. It needs a Chromium **headless shell** binary; locally:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export CHROME_PATH=$(ls ~/.cache/ms-playwright/chromium_headless_shell-*/*/chrome-headless-shell)
|
||||||
|
node scripts/screenshot.mjs docs/screenshots --tag m0
|
||||||
|
```
|
||||||
|
|
||||||
|
(The full `chrome` binary under `chromium-*/` hung on launch in this sandbox; the headless shell works.)
|
||||||
|
CI does not take screenshots (no browser in the job image); the Node host tests cover the same code path minus Canvas2D.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
Generated
+3141
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "moon-plasma-host",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"description": "Host runtime for moon-plasma (M0: Node/browser host over jco-transpiled components)",
|
||||||
|
"scripts": {
|
||||||
|
"test": "node --test test/*.test.mjs"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@bytecodealliance/jco": "1.42.0",
|
||||||
|
"playwright-core": "^1.50.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// Minimal static server for the browser host (serves host/, config/, build/ only).
|
||||||
|
// node host/serve.mjs [port] (default: $PORT or 8080)
|
||||||
|
import http from 'node:http';
|
||||||
|
import { readFile } from 'node:fs/promises';
|
||||||
|
import { join, extname, normalize } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const ROOT = join(fileURLToPath(import.meta.url), '..', '..');
|
||||||
|
const MIME = { '.html': 'text/html', '.mjs': 'text/javascript', '.js': 'text/javascript', '.json': 'application/json', '.wasm': 'application/wasm' };
|
||||||
|
const ALLOWED = ['host/', 'config/', 'build/'];
|
||||||
|
|
||||||
|
export function serve(port = 0) {
|
||||||
|
const srv = http.createServer(async (req, res) => {
|
||||||
|
try {
|
||||||
|
let p = decodeURIComponent(new URL(req.url, 'http://x').pathname);
|
||||||
|
if (p === '/') p = '/host/web/index.html';
|
||||||
|
const rel = normalize(p).replace(/^\/+/, '');
|
||||||
|
if (rel.includes('..') || !ALLOWED.some((a) => rel.startsWith(a)) || rel.startsWith('host/node_modules')) { res.writeHead(404).end('not found'); return; }
|
||||||
|
const body = await readFile(join(ROOT, rel));
|
||||||
|
res.writeHead(200, { 'content-type': MIME[extname(rel)] ?? 'application/octet-stream', 'cache-control': 'no-store' }).end(body);
|
||||||
|
} catch { res.writeHead(404).end('not found'); }
|
||||||
|
});
|
||||||
|
return new Promise((resolve) => srv.listen(port, '127.0.0.1', () => resolve(srv)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||||
|
const srv = await serve(Number(process.argv[2] ?? process.env.PORT ?? 8080));
|
||||||
|
console.log(`moon-plasma host: http://127.0.0.1:${srv.address().port}/`);
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// Terminal rasteriser: a coarse text-mode view of a render list, used for
|
||||||
|
// headless runs and CI logs. (Real pixels come from the Canvas2D backend.)
|
||||||
|
|
||||||
|
const SHADES = ' .:-=+*#%@';
|
||||||
|
const CW = 8, CH = 16;
|
||||||
|
|
||||||
|
export function renderAscii(ops, screen) {
|
||||||
|
const cols = Math.ceil(screen.w / CW), rows = Math.ceil(screen.h / CH);
|
||||||
|
const grid = Array.from({ length: rows }, () => Array(cols).fill(' '));
|
||||||
|
const clips = [{ x: 0, y: 0, w: screen.w, h: screen.h }];
|
||||||
|
const inClip = (px, py) => { const c = clips[clips.length - 1]; return px >= c.x && py >= c.y && px < c.x + c.w && py < c.y + c.h; };
|
||||||
|
const lum = (c) => (0.299 * c.r + 0.587 * c.g + 0.114 * c.b) / 255;
|
||||||
|
const shade = (c) => SHADES[Math.min(SHADES.length - 1, Math.floor(lum(c) * SHADES.length))];
|
||||||
|
const put = (cx, cy, ch) => { if (cx >= 0 && cy >= 0 && cx < cols && cy < rows && inClip(cx * CW + CW / 2, cy * CH + CH / 2)) grid[cy][cx] = ch; };
|
||||||
|
for (const op of ops) {
|
||||||
|
const v = op.val;
|
||||||
|
switch (op.tag) {
|
||||||
|
case 'push-clip': {
|
||||||
|
const c = clips[clips.length - 1];
|
||||||
|
const x0 = Math.max(c.x, v.x), y0 = Math.max(c.y, v.y);
|
||||||
|
const x1 = Math.min(c.x + c.w, v.x + v.w), y1 = Math.min(c.y + c.h, v.y + v.h);
|
||||||
|
clips.push({ x: x0, y: y0, w: Math.max(0, x1 - x0), h: Math.max(0, y1 - y0) });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'pop-clip': if (clips.length < 2) throw new Error('pop-clip without push-clip'); clips.pop(); break;
|
||||||
|
case 'fill-rect': {
|
||||||
|
if (v.color.a < 40) break;
|
||||||
|
for (let cy = Math.floor(v.rect.y / CH); cy <= Math.floor((v.rect.y + v.rect.h - 1) / CH); cy++)
|
||||||
|
for (let cx = Math.floor(v.rect.x / CW); cx <= Math.floor((v.rect.x + v.rect.w - 1) / CW); cx++) put(cx, cy, shade(v.color));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'circle': {
|
||||||
|
if (!v.filled || v.color.a < 120) break;
|
||||||
|
for (let cy = 0; cy < rows; cy++) for (let cx = 0; cx < cols; cx++) {
|
||||||
|
const dx = cx * CW + CW / 2 - v.center.x, dy = cy * CH + CH / 2 - v.center.y;
|
||||||
|
if (dx * dx + dy * dy <= v.radius * v.radius) put(cx, cy, shade(v.color));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'text': {
|
||||||
|
const w = v.text.length;
|
||||||
|
let x0 = v.origin.x;
|
||||||
|
if (v.style.align === 'center') x0 -= (w * CW) / 2; else if (v.style.align === 'right') x0 -= w * CW;
|
||||||
|
const cy = Math.floor(v.origin.y / CH);
|
||||||
|
for (let i = 0; i < w; i++) put(Math.floor(x0 / CW) + i, cy, v.text[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break; // stroke-rect / line: omitted in text mode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return grid.map((r) => r.join('').replace(/\s+$/, '')).join('\n');
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// Headless desktop: boots all components under the Node host and prints the
|
||||||
|
// composed desktop as text, optionally after a scripted interaction.
|
||||||
|
// node host/src/cli.mjs [--config file] [--time ISO] [--click-launcher] [--scene out.json]
|
||||||
|
import { writeFile } from 'node:fs/promises';
|
||||||
|
import { bootDesktop } from './headless.mjs';
|
||||||
|
import { renderAscii } from './ascii.mjs';
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const opt = (n) => { const i = args.indexOf(`--${n}`); return i < 0 ? undefined : args[i + 1]; };
|
||||||
|
const flag = (n) => args.includes(`--${n}`);
|
||||||
|
|
||||||
|
const fixed = opt('time') ? new Date(opt('time')) : undefined;
|
||||||
|
const { desktop, platform } = await bootDesktop({ configPath: opt('config'), now: fixed ? () => fixed : undefined });
|
||||||
|
|
||||||
|
let f = desktop.frame();
|
||||||
|
if (flag('click-launcher')) {
|
||||||
|
const e = desktop.hit.widgets.find((w) => w.widget.id === 'launcher');
|
||||||
|
desktop.pointer('down', e.rect.x + 10, e.rect.y + 10);
|
||||||
|
f = desktop.frame();
|
||||||
|
if (flag('type')) { for (const ch of opt('type')) desktop.key(ch); f = desktop.frame(); }
|
||||||
|
}
|
||||||
|
console.log(renderAscii(f.ops, f.screen));
|
||||||
|
console.log(`\n-- ${f.ops.length} draw-ops; widgets: ${desktop.widgets.map((w) => `${w.id}=${w.componentName}`).join(', ')}; theme=${platform.tokens.name}`);
|
||||||
|
if (opt('scene')) await writeFile(opt('scene'), JSON.stringify(f, null, 1));
|
||||||
|
if (desktop.faults.length) { console.error(`${desktop.faults.length} component fault(s)`); process.exit(1); }
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
// moon-plasma host core (platform-agnostic: runs in Node and the browser).
|
||||||
|
//
|
||||||
|
// Responsibilities (the *only* things that are not components):
|
||||||
|
// * instantiate components and broker capabilities (deny-by-default grants)
|
||||||
|
// * drive the frame loop: shell layout -> widget render -> render-list
|
||||||
|
// * route input to the component that owns the surface under the pointer
|
||||||
|
// * hot-swap a widget's implementation at runtime
|
||||||
|
// All policy (layout, look, behaviour) lives in components.
|
||||||
|
|
||||||
|
import { CAPABILITIES } from './platform.mjs';
|
||||||
|
import { place, translate } from './scene.mjs';
|
||||||
|
|
||||||
|
const PKG = 'moonplasma:desktop';
|
||||||
|
const PLASMOID = `${PKG}/plasmoid`;
|
||||||
|
const PANEL = `${PKG}/panel-layout`;
|
||||||
|
const DESKTOP = `${PKG}/desktop-surface`;
|
||||||
|
|
||||||
|
export class PermissionError extends Error {
|
||||||
|
constructor(msg) { super(msg); this.name = 'PermissionError'; }
|
||||||
|
}
|
||||||
|
export class ComponentFault extends Error {
|
||||||
|
constructor(component, fn, cause) {
|
||||||
|
super(`component "${component}" faulted in ${fn}: ${cause?.message ?? cause}`);
|
||||||
|
this.name = 'ComponentFault';
|
||||||
|
this.component = component;
|
||||||
|
this.fn = fn;
|
||||||
|
this.cause = cause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{meta: {name:string, world:string, imports:string[], exports:string[]},
|
||||||
|
* instantiate: (imports: object) => Promise<object>}} LoadedComponent
|
||||||
|
* @param {{config: any, loader: (name: string) => Promise<LoadedComponent>, platform: any}} opts
|
||||||
|
*/
|
||||||
|
export class Desktop {
|
||||||
|
constructor({ config, loader, platform }) {
|
||||||
|
this.config = config;
|
||||||
|
this.loader = loader;
|
||||||
|
this.platform = platform;
|
||||||
|
this.screen = { w: config.screen.w, h: config.screen.h };
|
||||||
|
this.shell = null;
|
||||||
|
this.widgets = []; // {id, align, componentName, grants, meta, plasmoid}
|
||||||
|
this.faults = []; // visible, never swallowed: also rendered as error tiles
|
||||||
|
this.hit = { widgets: [], popup: null };
|
||||||
|
this.hovered = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async start() {
|
||||||
|
this.shell = await this.#instantiate(this.config.shell.component, this.config.shell.grants, 'shell');
|
||||||
|
for (const w of this.config.panel) {
|
||||||
|
const inst = await this.#instantiate(w.component, w.grants, 'widget');
|
||||||
|
this.widgets.push({ id: w.id, align: w.align ?? 'start', grants: w.grants, ...inst });
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Replace the implementation behind panel widget `id` without touching others. */
|
||||||
|
async swap(id, componentName) {
|
||||||
|
const i = this.widgets.findIndex((w) => w.id === id);
|
||||||
|
if (i < 0) throw new Error(`swap: no widget with id "${id}"`);
|
||||||
|
const old = this.widgets[i];
|
||||||
|
const inst = await this.#instantiate(componentName, old.grants, 'widget');
|
||||||
|
this.widgets[i] = { id, align: old.align, grants: old.grants, ...inst };
|
||||||
|
this.hovered = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async #instantiate(componentName, grants, role) {
|
||||||
|
for (const g of grants) {
|
||||||
|
if (!CAPABILITIES.includes(g)) throw new PermissionError(`config grants unknown capability "${g}" to ${componentName}`);
|
||||||
|
}
|
||||||
|
const c = await this.loader(componentName);
|
||||||
|
const need = c.meta.imports;
|
||||||
|
const denied = need.filter((n) => !grants.includes(n));
|
||||||
|
if (denied.length) {
|
||||||
|
throw new PermissionError(
|
||||||
|
`component "${componentName}" imports [${denied.join(', ')}] which the desktop config does not grant ` +
|
||||||
|
`(granted: [${grants.join(', ')}])`);
|
||||||
|
}
|
||||||
|
const exp = c.meta.exports;
|
||||||
|
const wantExports = role === 'shell' ? ['panel-layout', 'desktop-surface'] : ['plasmoid'];
|
||||||
|
for (const e of wantExports) {
|
||||||
|
if (!exp.includes(e)) throw new Error(`component "${componentName}" does not export ${e}; cannot act as ${role}`);
|
||||||
|
}
|
||||||
|
// Only granted AND imported interfaces are wired; jco fails instantiation
|
||||||
|
// loudly if anything else is missing.
|
||||||
|
const imports = {};
|
||||||
|
for (const n of need) imports[`${PKG}/${n}`] = this.platform.interfaces[n]();
|
||||||
|
const instance = await c.instantiate(imports);
|
||||||
|
const get = (iface) => instance[`${iface}@0.1.0`] ?? instance[iface];
|
||||||
|
return role === 'shell'
|
||||||
|
? { componentName, meta: c.meta, panel: get(PANEL), desktop: get(DESKTOP) }
|
||||||
|
: { componentName, meta: c.meta, plasmoid: get(PLASMOID) };
|
||||||
|
}
|
||||||
|
|
||||||
|
#call(owner, fn, thunk) {
|
||||||
|
try {
|
||||||
|
return thunk();
|
||||||
|
} catch (e) {
|
||||||
|
const f = new ComponentFault(owner.componentName, fn, e);
|
||||||
|
this.faults.push(f);
|
||||||
|
console.error(`[host] ${f.message}`);
|
||||||
|
throw f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Compose one frame. Returns {ops, layout, screen}. */
|
||||||
|
frame() {
|
||||||
|
const screen = this.screen;
|
||||||
|
const ops = [];
|
||||||
|
ops.push(...this.#call(this.shell, 'desktop-surface.render-background', () => this.shell.desktop.renderBackground(screen)));
|
||||||
|
|
||||||
|
const slots = this.widgets.map((w) => {
|
||||||
|
const info = this.#call(w, 'plasmoid.info', () => w.plasmoid.info());
|
||||||
|
w.info = info;
|
||||||
|
return { id: w.id, preferred: info.preferred, minWidth: info.minWidth, stretch: info.stretch, align: w.align };
|
||||||
|
});
|
||||||
|
const layout = this.#call(this.shell, 'panel-layout.compute-layout', () => this.shell.panel.computeLayout(screen, slots));
|
||||||
|
ops.push(...this.#call(this.shell, 'panel-layout.render-panel', () => this.shell.panel.renderPanel(screen, layout.panel)));
|
||||||
|
|
||||||
|
this.hit = { widgets: [], popup: null };
|
||||||
|
const rects = new Map();
|
||||||
|
for (const p of layout.placements) rects.set(p.id, p.rect);
|
||||||
|
for (const w of this.widgets) {
|
||||||
|
const rect = rects.get(w.id);
|
||||||
|
if (!rect) throw new Error(`shell returned no placement for widget "${w.id}"`);
|
||||||
|
this.hit.widgets.push({ widget: w, rect });
|
||||||
|
let wops;
|
||||||
|
try {
|
||||||
|
wops = this.#call(w, 'plasmoid.render', () => w.plasmoid.render({ w: rect.w, h: rect.h }));
|
||||||
|
} catch {
|
||||||
|
wops = faultTile(rect, w.componentName);
|
||||||
|
}
|
||||||
|
ops.push(...place(wops, rect));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Popup layer (at most one popup open at a time).
|
||||||
|
for (const entry of this.hit.widgets) {
|
||||||
|
let pop;
|
||||||
|
try {
|
||||||
|
pop = this.#call(entry.widget, 'plasmoid.popup', () => entry.widget.plasmoid.popup());
|
||||||
|
} catch { continue; }
|
||||||
|
if (!pop) continue;
|
||||||
|
const prect = this.#call(this.shell, 'panel-layout.popup-position', () =>
|
||||||
|
this.shell.panel.popupPosition(screen, layout.panel, entry.rect, pop.size));
|
||||||
|
this.hit.popup = { widget: entry.widget, anchor: entry.rect, rect: prect };
|
||||||
|
ops.push(...place(pop.ops, prect));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return { ops, layout, screen };
|
||||||
|
}
|
||||||
|
|
||||||
|
#send(widget, target, event) {
|
||||||
|
return this.#call(widget, 'plasmoid.on-event', () => widget.plasmoid.onEvent(target, event));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {'move'|'down'|'up'} kind Returns true when a redraw is needed. */
|
||||||
|
pointer(kind, x, y) {
|
||||||
|
const pt = { x, y };
|
||||||
|
const inside = (r) => x >= r.x && y >= r.y && x < r.x + r.w && y < r.y + r.h;
|
||||||
|
const tag = { move: 'pointer-move', down: 'pointer-down', up: 'pointer-up' }[kind];
|
||||||
|
if (!tag) throw new Error(`unknown pointer kind ${kind}`);
|
||||||
|
let dirty = false;
|
||||||
|
const popup = this.hit.popup;
|
||||||
|
if (popup && inside(popup.rect)) {
|
||||||
|
return this.#send(popup.widget, 'popup', { tag, val: { x: x - popup.rect.x, y: y - popup.rect.y } });
|
||||||
|
}
|
||||||
|
if (popup && kind === 'down' && !inside(popup.anchor)) {
|
||||||
|
// Click outside the popup: tell its owner it lost focus, then let the
|
||||||
|
// click fall through to whatever is underneath.
|
||||||
|
dirty = this.#send(popup.widget, 'widget', { tag: 'focus-lost', val: undefined }) || dirty;
|
||||||
|
}
|
||||||
|
const target = this.hit.widgets.find((e) => inside(e.rect));
|
||||||
|
if (this.hovered && this.hovered !== target?.widget) {
|
||||||
|
dirty = this.#send(this.hovered, 'widget', { tag: 'pointer-leave', val: undefined }) || dirty;
|
||||||
|
}
|
||||||
|
this.hovered = target?.widget ?? null;
|
||||||
|
if (target) {
|
||||||
|
dirty = this.#send(target.widget, 'widget', { tag, val: { x: x - target.rect.x, y: y - target.rect.y } }) || dirty;
|
||||||
|
}
|
||||||
|
void pt;
|
||||||
|
return dirty;
|
||||||
|
}
|
||||||
|
|
||||||
|
key(k) {
|
||||||
|
const popup = this.hit.popup;
|
||||||
|
if (!popup) return false;
|
||||||
|
return this.#send(popup.widget, 'popup', { tag: 'key-down', val: k });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function faultTile(rect, name) {
|
||||||
|
const red = { r: 200, g: 40, b: 40, a: 255 };
|
||||||
|
return [
|
||||||
|
{ tag: 'fill-rect', val: { rect: { x: 0, y: 0, w: rect.w, h: rect.h }, color: red, radius: 4 } },
|
||||||
|
{ tag: 'text', val: { origin: { x: 6, y: Math.floor(rect.h / 2) }, text: `${name} crashed`,
|
||||||
|
style: { size: 12, color: { r: 255, g: 255, b: 255, a: 255 }, align: 'left', bold: true } } },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export { translate };
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Headless bring-up shared by the CLI and the tests.
|
||||||
|
import { readFile } from 'node:fs/promises';
|
||||||
|
import { join, dirname } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { Desktop } from './desktop.mjs';
|
||||||
|
import { createPlatform } from './platform.mjs';
|
||||||
|
import { tokensFromJson } from './theme.mjs';
|
||||||
|
import { nodeLoader } from './loader-node.mjs';
|
||||||
|
|
||||||
|
export const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
||||||
|
|
||||||
|
export async function bootDesktop({ configPath = join(ROOT, 'config', 'desktop.json'), now, buildDir = join(ROOT, 'build') } = {}) {
|
||||||
|
const config = JSON.parse(await readFile(configPath, 'utf8'));
|
||||||
|
const apps = JSON.parse(await readFile(join(ROOT, 'config', 'apps.json'), 'utf8'));
|
||||||
|
const themeJson = JSON.parse(await readFile(join(ROOT, 'config', 'themes', `${config.theme}.json`), 'utf8'));
|
||||||
|
const platform = createPlatform({ apps, tokens: tokensFromJson(themeJson), now });
|
||||||
|
const desktop = await new Desktop({ config, loader: nodeLoader(buildDir), platform }).start();
|
||||||
|
return { desktop, platform, config };
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { readFile } from 'node:fs/promises';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
import { pathToFileURL } from 'node:url';
|
||||||
|
|
||||||
|
/** Loader for Node: reads build/ produced by scripts/build.sh. */
|
||||||
|
export function nodeLoader(buildDir) {
|
||||||
|
return async (name) => {
|
||||||
|
const meta = JSON.parse(await readFile(join(buildDir, 'components', `${name}.meta.json`), 'utf8'));
|
||||||
|
const dir = join(buildDir, 'jco', name);
|
||||||
|
const mod = await import(pathToFileURL(join(dir, `${name}.js`)).href);
|
||||||
|
const getCoreModule = async (p) => WebAssembly.compile(await readFile(join(dir, p)));
|
||||||
|
return { meta, instantiate: (imports) => mod.instantiate(getCoreModule, imports) };
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/** Loader for browsers: fetches the jco output under <base>/build/. */
|
||||||
|
export function webLoader(base) {
|
||||||
|
return async (name) => {
|
||||||
|
const r = await fetch(`${base}/build/components/${name}.meta.json`);
|
||||||
|
if (!r.ok) throw new Error(`cannot load ${name}.meta.json: HTTP ${r.status}`);
|
||||||
|
const meta = await r.json();
|
||||||
|
const dir = `${base}/build/jco/${name}`;
|
||||||
|
const mod = await import(`${dir}/${name}.js`);
|
||||||
|
const getCoreModule = async (p) => {
|
||||||
|
const res = await fetch(`${dir}/${p}`);
|
||||||
|
if (!res.ok) throw new Error(`cannot fetch ${p}: HTTP ${res.status}`);
|
||||||
|
return WebAssembly.compile(await res.arrayBuffer());
|
||||||
|
};
|
||||||
|
return { meta, instantiate: (imports) => mod.instantiate(getCoreModule, imports) };
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// Host-side implementations of the capability interfaces components may import.
|
||||||
|
// This is where a native host would talk to the OS; here it is in-memory so the
|
||||||
|
// desktop is deterministic and testable.
|
||||||
|
|
||||||
|
/** @param {{now?: () => Date, apps: any[], tokens: any}} opts */
|
||||||
|
export function createPlatform({ now = () => new Date(), apps, tokens }) {
|
||||||
|
const p = {
|
||||||
|
tokens,
|
||||||
|
apps,
|
||||||
|
launches: [],
|
||||||
|
now,
|
||||||
|
launchable: new Set(apps.map((a) => a.id)),
|
||||||
|
};
|
||||||
|
/** Capability name -> WIT interface implementation (jco import shape). */
|
||||||
|
p.interfaces = {
|
||||||
|
theme: () => ({ getTokens: () => p.tokens }),
|
||||||
|
clock: () => ({
|
||||||
|
now() {
|
||||||
|
const d = p.now();
|
||||||
|
return {
|
||||||
|
year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDate(),
|
||||||
|
hour: d.getHours(), minute: d.getMinutes(), second: d.getSeconds(), weekday: d.getDay(),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
'app-catalog': () => ({ listApps: () => p.apps }),
|
||||||
|
'app-launch': () => ({
|
||||||
|
launch(id) {
|
||||||
|
if (!p.launchable.has(id)) return { tag: 'err', val: `unknown application: ${id}` };
|
||||||
|
p.launches.push(id);
|
||||||
|
console.log(`[host] launch ${id}`);
|
||||||
|
return { tag: 'ok', val: undefined };
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CAPABILITIES = ['theme', 'clock', 'app-catalog', 'app-launch'];
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Render-list helpers. A draw-op is a jco-lifted WIT variant: {tag, val}.
|
||||||
|
|
||||||
|
/** Translate a draw-op list by (dx, dy), returning new ops. */
|
||||||
|
export function translate(ops, dx, dy) {
|
||||||
|
return ops.map((op) => {
|
||||||
|
const v = op.val;
|
||||||
|
switch (op.tag) {
|
||||||
|
case 'fill-rect':
|
||||||
|
case 'stroke-rect':
|
||||||
|
return { tag: op.tag, val: { ...v, rect: { ...v.rect, x: v.rect.x + dx, y: v.rect.y + dy } } };
|
||||||
|
case 'line':
|
||||||
|
return { tag: op.tag, val: { ...v, start: { x: v.start.x + dx, y: v.start.y + dy }, end: { x: v.end.x + dx, y: v.end.y + dy } } };
|
||||||
|
case 'circle':
|
||||||
|
return { tag: op.tag, val: { ...v, center: { x: v.center.x + dx, y: v.center.y + dy } } };
|
||||||
|
case 'text':
|
||||||
|
return { tag: op.tag, val: { ...v, origin: { x: v.origin.x + dx, y: v.origin.y + dy } } };
|
||||||
|
case 'push-clip':
|
||||||
|
return { tag: op.tag, val: { ...v, x: v.x + dx, y: v.y + dy } };
|
||||||
|
case 'pop-clip':
|
||||||
|
return op;
|
||||||
|
default:
|
||||||
|
throw new Error(`unknown draw-op tag: ${op.tag}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Place a component's local-space ops at `rect`, clipped to it. */
|
||||||
|
export function place(ops, rect) {
|
||||||
|
return [
|
||||||
|
{ tag: 'push-clip', val: { ...rect } },
|
||||||
|
...translate(ops, rect.x, rect.y),
|
||||||
|
{ tag: 'pop-clip', val: undefined },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const colorCss = (c) => `rgba(${c.r},${c.g},${c.b},${(c.a / 255).toFixed(3)})`;
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// Theme files use kebab-case keys and #rrggbb[aa] colours; components see the
|
||||||
|
// WIT `theme.tokens` record (camelCase in jco).
|
||||||
|
|
||||||
|
const camel = (k) => k.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
||||||
|
|
||||||
|
export function parseColor(s) {
|
||||||
|
const m = /^#([0-9a-fA-F]{6})([0-9a-fA-F]{2})?$/.exec(s);
|
||||||
|
if (!m) throw new Error(`invalid colour "${s}" (expected #rrggbb or #rrggbbaa)`);
|
||||||
|
const n = parseInt(m[1], 16);
|
||||||
|
return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255, a: m[2] ? parseInt(m[2], 16) : 255 };
|
||||||
|
}
|
||||||
|
|
||||||
|
const PALETTE_KEYS = ['desktop-top', 'desktop-bottom', 'surface', 'surface-hover', 'surface-popup',
|
||||||
|
'foreground', 'foreground-muted', 'accent', 'accent-foreground', 'border'];
|
||||||
|
const NUM_KEYS = ['font-size', 'radius', 'spacing', 'panel-height'];
|
||||||
|
|
||||||
|
export function tokensFromJson(json) {
|
||||||
|
const palette = {};
|
||||||
|
for (const k of PALETTE_KEYS) {
|
||||||
|
if (!(k in (json.palette ?? {}))) throw new Error(`theme "${json.name}": missing palette.${k}`);
|
||||||
|
palette[camel(k)] = parseColor(json.palette[k]);
|
||||||
|
}
|
||||||
|
const out = { name: json.name, palette };
|
||||||
|
for (const k of NUM_KEYS) {
|
||||||
|
if (!Number.isInteger(json[k]) || json[k] < 0) throw new Error(`theme "${json.name}": ${k} must be a non-negative integer`);
|
||||||
|
out[camel(k)] = json[k];
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
// Host integration tests: instantiate the real MoonBit components (built by
|
||||||
|
// scripts/build.sh) under the Node host and exercise the desktop end to end.
|
||||||
|
import test from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { readFile, stat, writeFile, mkdtemp } from 'node:fs/promises';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
import { tmpdir } from 'node:os';
|
||||||
|
import { bootDesktop, ROOT } from '../src/headless.mjs';
|
||||||
|
import { PermissionError } from '../src/desktop.mjs';
|
||||||
|
import { tokensFromJson } from '../src/theme.mjs';
|
||||||
|
|
||||||
|
const NOW = new Date(2026, 10, 24, 14, 7, 37); // Tue 24 Nov 2026, local time
|
||||||
|
const fixed = () => NOW;
|
||||||
|
const texts = (ops) => ops.filter((o) => o.tag === 'text').map((o) => o.val.text);
|
||||||
|
const configWith = async (mutate) => {
|
||||||
|
const cfg = JSON.parse(await readFile(join(ROOT, 'config', 'desktop.json'), 'utf8'));
|
||||||
|
mutate(cfg);
|
||||||
|
const dir = await mkdtemp(join(tmpdir(), 'moonplasma-'));
|
||||||
|
const p = join(dir, 'desktop.json');
|
||||||
|
await writeFile(p, JSON.stringify(cfg));
|
||||||
|
return p;
|
||||||
|
};
|
||||||
|
|
||||||
|
test('boots shell + widgets and composes a frame', async () => {
|
||||||
|
const { desktop } = await bootDesktop({ now: fixed });
|
||||||
|
const f = desktop.frame();
|
||||||
|
assert.deepEqual(f.screen, { w: 1280, h: 720 });
|
||||||
|
assert.ok(f.ops.length > 50);
|
||||||
|
const t = texts(f.ops);
|
||||||
|
assert.ok(t.includes('14:07'), `clock text missing: ${t}`);
|
||||||
|
assert.ok(t.includes('Tue 24 Nov'));
|
||||||
|
assert.ok(t.includes('moon-plasma'));
|
||||||
|
assert.ok(t.includes('Applications'));
|
||||||
|
assert.equal(desktop.faults.length, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('shell lays the panel out at the bottom, launcher left, clock right', async () => {
|
||||||
|
const { desktop } = await bootDesktop({ now: fixed });
|
||||||
|
const { layout } = desktop.frame();
|
||||||
|
assert.deepEqual(layout.panel, { x: 0, y: 720 - 44, w: 1280, h: 44 });
|
||||||
|
const byId = Object.fromEntries(layout.placements.map((p) => [p.id, p.rect]));
|
||||||
|
assert.ok(byId.launcher.x < 20);
|
||||||
|
assert.equal(byId.clock.x + byId.clock.w, 1280 - 5);
|
||||||
|
for (const r of Object.values(byId)) {
|
||||||
|
assert.ok(r.y >= layout.panel.y && r.y + r.h <= 720, 'widget inside the panel');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('launcher: click opens popup, row click launches via host capability, popup closes', async () => {
|
||||||
|
const { desktop, platform } = await bootDesktop({ now: fixed });
|
||||||
|
desktop.frame();
|
||||||
|
const l = desktop.hit.widgets.find((w) => w.widget.id === 'launcher').rect;
|
||||||
|
assert.equal(desktop.hit.popup, null);
|
||||||
|
assert.equal(desktop.pointer('down', l.x + 5, l.y + 5), true);
|
||||||
|
const f = desktop.frame();
|
||||||
|
assert.ok(desktop.hit.popup, 'popup is open');
|
||||||
|
assert.ok(texts(f.ops).includes('Terminal'));
|
||||||
|
const pr = desktop.hit.popup.rect;
|
||||||
|
assert.ok(pr.y + pr.h <= 720 - 44, 'popup sits above the panel');
|
||||||
|
// second row (52px header + 46px rows)
|
||||||
|
desktop.pointer('move', pr.x + 20, pr.y + 52 + 46 + 5);
|
||||||
|
desktop.pointer('down', pr.x + 20, pr.y + 52 + 46 + 5);
|
||||||
|
assert.deepEqual(platform.launches, ['org.moonplasma.files']);
|
||||||
|
desktop.frame();
|
||||||
|
assert.equal(desktop.hit.popup, null, 'popup closed after launch');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('launcher: keyboard search narrows the list and Enter launches the first match', async () => {
|
||||||
|
const { desktop, platform } = await bootDesktop({ now: fixed });
|
||||||
|
desktop.frame();
|
||||||
|
const l = desktop.hit.widgets.find((w) => w.widget.id === 'launcher').rect;
|
||||||
|
desktop.pointer('down', l.x + 5, l.y + 5);
|
||||||
|
desktop.frame();
|
||||||
|
for (const ch of 'calc') desktop.key(ch);
|
||||||
|
const f = desktop.frame();
|
||||||
|
const t = texts(f.ops);
|
||||||
|
assert.ok(t.includes('Calculator') && !t.includes('Terminal'));
|
||||||
|
desktop.key('Enter');
|
||||||
|
assert.deepEqual(platform.launches, ['org.moonplasma.calc']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clicking outside the popup dismisses it (focus-lost)', async () => {
|
||||||
|
const { desktop } = await bootDesktop({ now: fixed });
|
||||||
|
desktop.frame();
|
||||||
|
const l = desktop.hit.widgets.find((w) => w.widget.id === 'launcher').rect;
|
||||||
|
desktop.pointer('down', l.x + 5, l.y + 5);
|
||||||
|
desktop.frame();
|
||||||
|
assert.ok(desktop.hit.popup);
|
||||||
|
desktop.pointer('down', 900, 200);
|
||||||
|
desktop.frame();
|
||||||
|
assert.equal(desktop.hit.popup, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('permissions: a component importing an ungranted capability is refused', async () => {
|
||||||
|
const cfg = await configWith((c) => { c.panel[1].grants = ['theme']; }); // clock needs "clock"
|
||||||
|
await assert.rejects(bootDesktop({ configPath: cfg }), (e) => {
|
||||||
|
assert.ok(e instanceof PermissionError);
|
||||||
|
assert.match(e.message, /clock-digital.*imports \[clock\]/);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('permissions: unknown capability names in config are rejected', async () => {
|
||||||
|
const cfg = await configWith((c) => { c.panel[1].grants.push('filesystem'); });
|
||||||
|
await assert.rejects(bootDesktop({ configPath: cfg }), /unknown capability "filesystem"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a component cannot act in a role it does not export', async () => {
|
||||||
|
const cfg = await configWith((c) => { c.panel[1].component = 'shell'; c.panel[1].grants = ['theme']; });
|
||||||
|
await assert.rejects(bootDesktop({ configPath: cfg }), /does not export plasmoid/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('hot-swap: clock-digital -> clock-binary at runtime, other components untouched', async () => {
|
||||||
|
const files = ['shell', 'launcher', 'clock-digital', 'clock-binary'].map((n) => join(ROOT, 'build', 'components', `${n}.wasm`));
|
||||||
|
const before = await Promise.all(files.map(async (f) => (await stat(f)).mtimeMs));
|
||||||
|
const { desktop } = await bootDesktop({ now: fixed });
|
||||||
|
const a = desktop.frame();
|
||||||
|
assert.ok(texts(a.ops).includes('14:07'));
|
||||||
|
const launcherInstance = desktop.widgets.find((w) => w.id === 'launcher').plasmoid;
|
||||||
|
await desktop.swap('clock', 'clock-binary');
|
||||||
|
const b = desktop.frame();
|
||||||
|
assert.ok(!texts(b.ops).includes('14:07'));
|
||||||
|
assert.ok(b.ops.filter((o) => o.tag === 'circle').length >= 20, 'binary clock dots drawn');
|
||||||
|
assert.equal(desktop.widgets.find((w) => w.id === 'launcher').plasmoid, launcherInstance, 'launcher instance reused');
|
||||||
|
const after = await Promise.all(files.map(async (f) => (await stat(f)).mtimeMs));
|
||||||
|
assert.deepEqual(after, before, 'no component binary was rebuilt');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('config-level swap (desktop.binary-clock.json) picks the other implementation', async () => {
|
||||||
|
const { desktop } = await bootDesktop({ configPath: join(ROOT, 'config', 'desktop.binary-clock.json'), now: fixed });
|
||||||
|
assert.equal(desktop.widgets.find((w) => w.id === 'clock').componentName, 'clock-binary');
|
||||||
|
assert.ok(desktop.frame().ops.some((o) => o.tag === 'circle' && o.val.filled));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('theme tokens flow through to components (live theme switch)', async () => {
|
||||||
|
const { desktop, platform } = await bootDesktop({ now: fixed });
|
||||||
|
const firstFill = (ops) => ops.find((o) => o.tag === 'fill-rect').val.color;
|
||||||
|
const night = firstFill(desktop.frame().ops);
|
||||||
|
const day = JSON.parse(await readFile(join(ROOT, 'config', 'themes', 'moon-day.json'), 'utf8'));
|
||||||
|
platform.tokens = tokensFromJson(day);
|
||||||
|
const light = firstFill(desktop.frame().ops);
|
||||||
|
assert.notDeepEqual(night, light);
|
||||||
|
assert.deepEqual(light, { r: 0xcf, g: 0xe3, b: 0xff, a: 255 }); // desktop-top of moon-day
|
||||||
|
});
|
||||||
|
|
||||||
|
test('component faults are surfaced loudly and isolated to the widget', async () => {
|
||||||
|
const { desktop, platform } = await bootDesktop({ now: fixed });
|
||||||
|
platform.now = () => { throw new Error('rtc exploded'); };
|
||||||
|
const f = desktop.frame(); // does not take the desktop down
|
||||||
|
assert.equal(desktop.faults.length, 1);
|
||||||
|
assert.match(desktop.faults[0].message, /clock-digital.*render/);
|
||||||
|
assert.ok(texts(f.ops).includes('clock-digital crashed'), 'visible error tile');
|
||||||
|
assert.ok(texts(f.ops).includes('Applications'), 'other widgets still render');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('build manifests match scripts/components.txt', async () => {
|
||||||
|
const lines = (await readFile(join(ROOT, 'scripts', 'components.txt'), 'utf8')).split('\n')
|
||||||
|
.filter((l) => l.trim() && !l.startsWith('#'));
|
||||||
|
for (const l of lines) {
|
||||||
|
const [name, world] = l.trim().split(/\s+/);
|
||||||
|
const meta = JSON.parse(await readFile(join(ROOT, 'build', 'components', `${name}.meta.json`), 'utf8'));
|
||||||
|
assert.equal(meta.world, world);
|
||||||
|
assert.ok(meta.imports.includes('theme'));
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Canvas2D backend: rasterises a render list (draw-ops in screen coordinates).
|
||||||
|
import { colorCss } from '../src/scene.mjs';
|
||||||
|
|
||||||
|
function roundRectPath(ctx, r, radius) {
|
||||||
|
ctx.beginPath();
|
||||||
|
const rad = Math.min(radius, r.w / 2, r.h / 2);
|
||||||
|
if (rad > 0) ctx.roundRect(r.x, r.y, r.w, r.h, rad); else ctx.rect(r.x, r.y, r.w, r.h);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function paint(ctx, ops, screen) {
|
||||||
|
ctx.clearRect(0, 0, screen.w, screen.h);
|
||||||
|
let depth = 0;
|
||||||
|
for (const op of ops) {
|
||||||
|
const v = op.val;
|
||||||
|
switch (op.tag) {
|
||||||
|
case 'push-clip':
|
||||||
|
ctx.save(); depth++;
|
||||||
|
ctx.beginPath(); ctx.rect(v.x, v.y, v.w, v.h); ctx.clip();
|
||||||
|
break;
|
||||||
|
case 'pop-clip':
|
||||||
|
if (depth === 0) throw new Error('pop-clip without push-clip');
|
||||||
|
ctx.restore(); depth--;
|
||||||
|
break;
|
||||||
|
case 'fill-rect':
|
||||||
|
ctx.fillStyle = colorCss(v.color); roundRectPath(ctx, v.rect, v.radius); ctx.fill();
|
||||||
|
break;
|
||||||
|
case 'stroke-rect':
|
||||||
|
ctx.strokeStyle = colorCss(v.color); ctx.lineWidth = v.width;
|
||||||
|
roundRectPath(ctx, { x: v.rect.x + 0.5, y: v.rect.y + 0.5, w: v.rect.w - 1, h: v.rect.h - 1 }, v.radius); ctx.stroke();
|
||||||
|
break;
|
||||||
|
case 'line':
|
||||||
|
ctx.strokeStyle = colorCss(v.color); ctx.lineWidth = v.width;
|
||||||
|
ctx.beginPath(); ctx.moveTo(v.start.x + 0.5, v.start.y + 0.5); ctx.lineTo(v.end.x + 0.5, v.end.y + 0.5); ctx.stroke();
|
||||||
|
break;
|
||||||
|
case 'circle':
|
||||||
|
ctx.beginPath(); ctx.arc(v.center.x, v.center.y, v.radius, 0, Math.PI * 2);
|
||||||
|
if (v.filled) { ctx.fillStyle = colorCss(v.color); ctx.fill(); }
|
||||||
|
else { ctx.strokeStyle = colorCss(v.color); ctx.lineWidth = 1.5; ctx.stroke(); }
|
||||||
|
break;
|
||||||
|
case 'text':
|
||||||
|
ctx.font = `${v.style.bold ? '600 ' : ''}${v.style.size}px system-ui, "DejaVu Sans", sans-serif`;
|
||||||
|
ctx.fillStyle = colorCss(v.style.color);
|
||||||
|
ctx.textAlign = v.style.align; ctx.textBaseline = 'middle';
|
||||||
|
ctx.fillText(v.text, v.origin.x, v.origin.y);
|
||||||
|
break;
|
||||||
|
default: throw new Error(`unknown draw-op ${op.tag}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (depth !== 0) throw new Error(`unbalanced clip stack (${depth})`);
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>moon-plasma</title>
|
||||||
|
<style>
|
||||||
|
html, body { margin: 0; background: #05070d; color: #aab; font: 12px/1.4 system-ui, sans-serif; }
|
||||||
|
#screen { display: block; margin: 0 auto; max-width: 100vw; }
|
||||||
|
#status { text-align: center; padding: 4px; font-family: monospace; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="screen" width="1280" height="720"></canvas>
|
||||||
|
<div id="status">loading components…</div>
|
||||||
|
<script type="module" src="./main.mjs"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { Desktop } from '../src/desktop.mjs';
|
||||||
|
import { createPlatform } from '../src/platform.mjs';
|
||||||
|
import { tokensFromJson } from '../src/theme.mjs';
|
||||||
|
import { webLoader } from '../src/loader-web.mjs';
|
||||||
|
import { paint } from './canvas.mjs';
|
||||||
|
|
||||||
|
const base = new URL('../../', import.meta.url).href.replace(/\/$/, '');
|
||||||
|
const q = new URLSearchParams(location.search);
|
||||||
|
const getJson = async (p) => {
|
||||||
|
const r = await fetch(`${base}/${p}`);
|
||||||
|
if (!r.ok) throw new Error(`GET ${p}: HTTP ${r.status}`);
|
||||||
|
return r.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const status = document.getElementById('status');
|
||||||
|
try {
|
||||||
|
const config = await getJson(`config/${q.get('config') ?? 'desktop.json'}`);
|
||||||
|
const apps = await getJson('config/apps.json');
|
||||||
|
const tokens = tokensFromJson(await getJson(`config/themes/${q.get('theme') ?? config.theme}.json`));
|
||||||
|
const fixed = q.get('time') ? new Date(q.get('time')) : null;
|
||||||
|
const platform = createPlatform({ apps, tokens, now: fixed ? () => fixed : undefined });
|
||||||
|
const desktop = await new Desktop({ config, loader: webLoader(base), platform }).start();
|
||||||
|
|
||||||
|
const canvas = document.getElementById('screen');
|
||||||
|
canvas.width = desktop.screen.w; canvas.height = desktop.screen.h;
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
const redraw = () => paint(ctx, desktop.frame().ops, desktop.screen);
|
||||||
|
const pos = (e) => { const r = canvas.getBoundingClientRect(); return [Math.round((e.clientX - r.left) * canvas.width / r.width), Math.round((e.clientY - r.top) * canvas.height / r.height)]; };
|
||||||
|
for (const [ev, kind] of [['pointermove', 'move'], ['pointerdown', 'down'], ['pointerup', 'up']]) {
|
||||||
|
canvas.addEventListener(ev, (e) => { const [x, y] = pos(e); if (desktop.pointer(kind, x, y)) redraw(); });
|
||||||
|
}
|
||||||
|
window.addEventListener('keydown', (e) => {
|
||||||
|
const k = e.key.length === 1 || ['Backspace', 'Enter', 'Escape'].includes(e.key) ? e.key : null;
|
||||||
|
if (k && desktop.key(k)) { e.preventDefault(); redraw(); }
|
||||||
|
});
|
||||||
|
redraw();
|
||||||
|
if (!fixed) setInterval(redraw, 1000);
|
||||||
|
status.textContent = `${desktop.widgets.map((w) => `${w.id}=${w.componentName}`).join(' ')} | theme: ${platform.tokens.name}`;
|
||||||
|
// Handle for automation / the browser console.
|
||||||
|
window.moonPlasma = { desktop, platform, redraw, swap: async (id, c) => { await desktop.swap(id, c); redraw(); }, ready: true };
|
||||||
|
} catch (e) {
|
||||||
|
status.textContent = `ERROR: ${e.message}`;
|
||||||
|
status.style.color = '#f66';
|
||||||
|
window.moonPlasmaError = String(e.stack ?? e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportListApps(p0 : Int) = "moonplasma:desktop/app-catalog@0.1.0" "list-apps"
|
||||||
|
|
||||||
|
///|
|
||||||
|
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_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)
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/interface/moonplasma/desktop/app-catalog"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn list_apps() -> Array[@types.AppEntry]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
/// Installed applications (static list in the PoC; .desktop files later).
|
||||||
|
pub fn list_apps() -> Array[@types.AppEntry] {
|
||||||
|
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
wasmImportListApps(return_area);
|
||||||
|
|
||||||
|
let array : Array[@types.AppEntry] = [];
|
||||||
|
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 40)
|
||||||
|
|
||||||
|
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
|
||||||
|
|
||||||
|
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
|
||||||
|
|
||||||
|
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20))
|
||||||
|
|
||||||
|
let result2 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 24), mbt_ffi_load32((iter_base) + 28))
|
||||||
|
|
||||||
|
let result3 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 32), mbt_ffi_load32((iter_base) + 36))
|
||||||
|
|
||||||
|
array.push(@types.AppEntry::{id : result, name : result0, comment : result1, category : result2, glyph : result3})
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||||
|
let ret = array
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportLaunch(p0 : Int, p1 : Int, p2 : Int) = "moonplasma:desktop/app-launch@0.1.0" "launch"
|
||||||
|
|
||||||
|
///|
|
||||||
|
#owned(str)
|
||||||
|
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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_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_load8_u(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/interface/moonplasma/desktop/app-launch"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn launch(String) -> Result[Unit, String]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
/// Ask the host to start an application by catalog id.
|
||||||
|
pub fn launch(id : String) -> Result[Unit, String] {
|
||||||
|
|
||||||
|
let ptr = mbt_ffi_str2ptr(id)
|
||||||
|
let return_area = mbt_ffi_malloc(12)
|
||||||
|
wasmImportLaunch(ptr, id.length(), return_area);
|
||||||
|
|
||||||
|
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
|
||||||
|
0 => {
|
||||||
|
|
||||||
|
Result::Ok(())
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8))
|
||||||
|
|
||||||
|
Result::Err(result)
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
let ret = lifted
|
||||||
|
mbt_ffi_free(ptr)
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Host-brokered capabilities. A component can only call what its world
|
||||||
|
imports AND what the host grants it in the desktop manifest.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportNow(p0 : Int) = "moonplasma:desktop/clock@0.1.0" "now"
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/interface/moonplasma/desktop/clock"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn now() -> @types.Datetime
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
/// Local wall-clock time (the host owns the time zone).
|
||||||
|
pub fn now() -> @types.Datetime {
|
||||||
|
|
||||||
|
let return_area = mbt_ffi_malloc(12)
|
||||||
|
wasmImportNow(return_area);
|
||||||
|
let ret = @types.Datetime::{year : (mbt_ffi_load32((return_area) + 0)).reinterpret_as_uint(), month : (mbt_ffi_load8_u((return_area) + 4)).to_byte(), day : (mbt_ffi_load8_u((return_area) + 5)).to_byte(), hour : (mbt_ffi_load8_u((return_area) + 6)).to_byte(), minute : (mbt_ffi_load8_u((return_area) + 7)).to_byte(), second : (mbt_ffi_load8_u((return_area) + 8)).to_byte(), weekday : (mbt_ffi_load8_u((return_area) + 9)).to_byte()}
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Look-and-feel design tokens (Plasma "Look and Feel"/colour scheme analogue).
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportGetTokens(p0 : Int) = "moonplasma:desktop/theme@0.1.0" "get-tokens"
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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)
|
||||||
|
|
||||||
|
///|
|
||||||
|
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)
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/interface/moonplasma/desktop/theme"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn get_tokens() -> Tokens
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) struct Palette {
|
||||||
|
desktop_top : @types.Color
|
||||||
|
desktop_bottom : @types.Color
|
||||||
|
surface : @types.Color
|
||||||
|
surface_hover : @types.Color
|
||||||
|
surface_popup : @types.Color
|
||||||
|
foreground : @types.Color
|
||||||
|
foreground_muted : @types.Color
|
||||||
|
accent : @types.Color
|
||||||
|
accent_foreground : @types.Color
|
||||||
|
border : @types.Color
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct Tokens {
|
||||||
|
name : String
|
||||||
|
palette : Palette
|
||||||
|
font_size : UInt32
|
||||||
|
radius : UInt32
|
||||||
|
spacing : UInt32
|
||||||
|
panel_height : UInt32
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
pub(all) struct Palette {
|
||||||
|
desktop_top : @types.Color; desktop_bottom : @types.Color; surface : @types.Color; surface_hover : @types.Color; surface_popup : @types.Color; foreground : @types.Color; foreground_muted : @types.Color; accent : @types.Color; accent_foreground : @types.Color; border : @types.Color
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct Tokens {
|
||||||
|
name : String; palette : Palette; font_size : UInt; radius : UInt; spacing : UInt; panel_height : UInt
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
/// Read on every render so a theme swap shows up on the next frame.
|
||||||
|
pub fn get_tokens() -> Tokens {
|
||||||
|
|
||||||
|
let return_area = mbt_ffi_malloc(64)
|
||||||
|
wasmImportGetTokens(return_area);
|
||||||
|
|
||||||
|
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
|
||||||
|
let ret = Tokens::{name : result, palette : Palette::{desktop_top : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 8)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 9)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 10)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 11)).to_byte()}, desktop_bottom : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 12)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 13)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 14)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 15)).to_byte()}, surface : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 16)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 17)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 18)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 19)).to_byte()}, surface_hover : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 20)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 21)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 22)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 23)).to_byte()}, surface_popup : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 24)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 25)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 26)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 27)).to_byte()}, foreground : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 28)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 29)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 30)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 31)).to_byte()}, foreground_muted : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 32)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 33)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 34)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 35)).to_byte()}, accent : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 36)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 37)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 38)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 39)).to_byte()}, accent_foreground : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 40)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 41)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 42)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 43)).to_byte()}, border : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 44)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 45)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 46)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 47)).to_byte()}}, font_size : (mbt_ffi_load32((return_area) + 48)).reinterpret_as_uint(), radius : (mbt_ffi_load32((return_area) + 52)).reinterpret_as_uint(), spacing : (mbt_ffi_load32((return_area) + 56)).reinterpret_as_uint(), panel_height : (mbt_ffi_load32((return_area) + 60)).reinterpret_as_uint()}
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Shared value types. Everything here is plain data (no resources) so that
|
||||||
|
it can cross any component boundary and any host implementation.
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/interface/moonplasma/desktop/types"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) struct AppEntry {
|
||||||
|
id : String
|
||||||
|
name : String
|
||||||
|
comment : String
|
||||||
|
category : String
|
||||||
|
glyph : String
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct CircleOp {
|
||||||
|
center : Point
|
||||||
|
radius : UInt32
|
||||||
|
color : Color
|
||||||
|
filled : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct Color {
|
||||||
|
r : Byte
|
||||||
|
g : Byte
|
||||||
|
b : Byte
|
||||||
|
a : Byte
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct Datetime {
|
||||||
|
year : UInt32
|
||||||
|
month : Byte
|
||||||
|
day : Byte
|
||||||
|
hour : Byte
|
||||||
|
minute : Byte
|
||||||
|
second : Byte
|
||||||
|
weekday : Byte
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum DrawOp {
|
||||||
|
FillRect(FillRectOp)
|
||||||
|
StrokeRect(StrokeRectOp)
|
||||||
|
Line(LineOp)
|
||||||
|
Circle(CircleOp)
|
||||||
|
Text(TextOp)
|
||||||
|
PushClip(Rect)
|
||||||
|
PopClip
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct FillRectOp {
|
||||||
|
rect : Rect
|
||||||
|
color : Color
|
||||||
|
radius : UInt32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum InputEvent {
|
||||||
|
PointerMove(Point)
|
||||||
|
PointerDown(Point)
|
||||||
|
PointerUp(Point)
|
||||||
|
PointerLeave
|
||||||
|
FocusLost
|
||||||
|
KeyDown(String)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct LineOp {
|
||||||
|
start : Point
|
||||||
|
end : Point
|
||||||
|
color : Color
|
||||||
|
width : UInt32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct Point {
|
||||||
|
x : Int32
|
||||||
|
y : Int32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct Rect {
|
||||||
|
x : Int32
|
||||||
|
y : Int32
|
||||||
|
w : UInt32
|
||||||
|
h : UInt32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct Size {
|
||||||
|
w : UInt32
|
||||||
|
h : UInt32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct StrokeRectOp {
|
||||||
|
rect : Rect
|
||||||
|
color : Color
|
||||||
|
width : UInt32
|
||||||
|
radius : UInt32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum TextAlign {
|
||||||
|
LEFT
|
||||||
|
CENTER
|
||||||
|
RIGHT
|
||||||
|
}
|
||||||
|
pub fn TextAlign::from(Int32) -> Self
|
||||||
|
pub fn TextAlign::ordinal(Self) -> Int32
|
||||||
|
|
||||||
|
pub(all) struct TextOp {
|
||||||
|
origin : Point
|
||||||
|
text : String
|
||||||
|
style : TextStyle
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct TextStyle {
|
||||||
|
size : UInt32
|
||||||
|
color : Color
|
||||||
|
align : TextAlign
|
||||||
|
bold : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
pub(all) struct Size {
|
||||||
|
w : UInt; h : UInt
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct Point {
|
||||||
|
x : Int; y : Int
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct Rect {
|
||||||
|
x : Int; y : Int; w : UInt; h : UInt
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
/// Non-premultiplied sRGB, 8 bits per channel.
|
||||||
|
pub(all) struct Color {
|
||||||
|
r : Byte; g : Byte; b : Byte; a : Byte
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum TextAlign {
|
||||||
|
LEFT; CENTER; RIGHT
|
||||||
|
} derive()
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn TextAlign::ordinal(self : TextAlign) -> Int {
|
||||||
|
match self {
|
||||||
|
LEFT => 0
|
||||||
|
CENTER => 1
|
||||||
|
RIGHT => 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn TextAlign::from(self : Int) -> TextAlign {
|
||||||
|
match self {
|
||||||
|
0 => LEFT
|
||||||
|
1 => CENTER
|
||||||
|
2 => RIGHT
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct TextStyle {
|
||||||
|
size : UInt; color : Color; align : TextAlign; bold : Bool
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct FillRectOp {
|
||||||
|
rect : Rect; color : Color; radius : UInt
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct StrokeRectOp {
|
||||||
|
rect : Rect; color : Color; width : UInt; radius : UInt
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct LineOp {
|
||||||
|
start : Point; end : Point; color : Color; width : UInt
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct CircleOp {
|
||||||
|
center : Point; radius : UInt; color : Color; filled : Bool
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
/// `origin` is the left edge (align=left), centre (center) or right edge
|
||||||
|
/// (right) of the text, at the vertical *middle* of the line box.
|
||||||
|
pub(all) struct TextOp {
|
||||||
|
origin : Point; text : String; style : TextStyle
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
/// The render-list vocabulary. Components never touch pixels: they return
|
||||||
|
/// a list of these in their own local coordinate space (origin top-left),
|
||||||
|
/// and the host/compositor translates, clips and rasterises them.
|
||||||
|
pub(all) enum DrawOp {
|
||||||
|
FillRect(FillRectOp)
|
||||||
|
StrokeRect(StrokeRectOp)
|
||||||
|
Line(LineOp)
|
||||||
|
Circle(CircleOp)
|
||||||
|
Text(TextOp)
|
||||||
|
PushClip(Rect)
|
||||||
|
PopClip
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum InputEvent {
|
||||||
|
PointerMove(Point)
|
||||||
|
PointerDown(Point)
|
||||||
|
PointerUp(Point)
|
||||||
|
PointerLeave
|
||||||
|
FocusLost
|
||||||
|
KeyDown(String)
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct Datetime {
|
||||||
|
year : UInt; month : Byte; day : Byte; hour : Byte; minute : Byte; second : Byte; weekday : Byte
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct AppEntry {
|
||||||
|
id : String; name : String; comment : String; category : String; glyph : String
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
///| Render logic for the clock widgets (pure: tokens + time in, ops out).
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn digital_info() -> (String, String, Int, Int, Int) {
|
||||||
|
// id, name, preferred w, preferred h, min w
|
||||||
|
("org.moonplasma.clock.digital", "Digital Clock", 120, 36, 80)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn render_digital(
|
||||||
|
size : @types.Size,
|
||||||
|
t : @theme.Tokens,
|
||||||
|
now : @types.Datetime,
|
||||||
|
) -> Array[@types.DrawOp] {
|
||||||
|
let w = size.w.reinterpret_as_int()
|
||||||
|
let h = size.h.reinterpret_as_int()
|
||||||
|
let fs = t.font_size.reinterpret_as_int()
|
||||||
|
let time = @timefmt.hhmm(now.hour.to_int(), now.minute.to_int())
|
||||||
|
let date = @timefmt.date_line(
|
||||||
|
now.weekday.to_int(),
|
||||||
|
now.day.to_int(),
|
||||||
|
now.month.to_int(),
|
||||||
|
)
|
||||||
|
[
|
||||||
|
@ui.text(w / 2, h / 2 - fs / 2 + 1, time, fs + 4, t.palette.foreground, align=CENTER, bold=true),
|
||||||
|
@ui.text(w / 2, h / 2 + fs / 2 + 4, date, fs - 3, t.palette.foreground_muted, align=CENTER),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn binary_info() -> (String, String, Int, Int, Int) {
|
||||||
|
("org.moonplasma.clock.binary", "Binary Clock", 96, 36, 96)
|
||||||
|
}
|
||||||
|
|
||||||
|
///| BCD binary clock: six columns (H H M M S S), four rows; lit bits use the
|
||||||
|
/// accent colour, unused high bits of the tens digits are not drawn.
|
||||||
|
pub fn render_binary(
|
||||||
|
size : @types.Size,
|
||||||
|
t : @theme.Tokens,
|
||||||
|
now : @types.Datetime,
|
||||||
|
) -> Array[@types.DrawOp] {
|
||||||
|
let w = size.w.reinterpret_as_int()
|
||||||
|
let h = size.h.reinterpret_as_int()
|
||||||
|
let digits = [
|
||||||
|
(now.hour.to_int() / 10, 2),
|
||||||
|
(now.hour.to_int() % 10, 4),
|
||||||
|
(now.minute.to_int() / 10, 3),
|
||||||
|
(now.minute.to_int() % 10, 4),
|
||||||
|
(now.second.to_int() / 10, 3),
|
||||||
|
(now.second.to_int() % 10, 4),
|
||||||
|
]
|
||||||
|
let ops = []
|
||||||
|
let cols = digits.length()
|
||||||
|
let step_x = w / cols
|
||||||
|
let step_y = h / 4
|
||||||
|
let r = (if step_x < step_y { step_x } else { step_y }) / 2 - 1
|
||||||
|
for c = 0; c < cols; c = c + 1 {
|
||||||
|
let (d, nbits) = digits[c]
|
||||||
|
let bits = @timefmt.bcd_bits(d, nbits)
|
||||||
|
for i = 0; i < nbits; i = i + 1 {
|
||||||
|
// Row 3 is the least significant bit.
|
||||||
|
let row = 4 - nbits + i
|
||||||
|
let cx = c * step_x + step_x / 2
|
||||||
|
let cy = row * step_y + step_y / 2
|
||||||
|
if bits[i] {
|
||||||
|
ops.push(@ui.circle(cx, cy, r, t.palette.accent))
|
||||||
|
} else {
|
||||||
|
ops.push(@ui.circle(cx, cy, r, t.palette.border, filled=false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ops
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn test_tokens() -> @theme.Tokens {
|
||||||
|
let c = @ui.color(10, 20, 30, 255)
|
||||||
|
{
|
||||||
|
name: "t",
|
||||||
|
palette: {
|
||||||
|
desktop_top: c,
|
||||||
|
desktop_bottom: c,
|
||||||
|
surface: c,
|
||||||
|
surface_hover: c,
|
||||||
|
surface_popup: c,
|
||||||
|
foreground: c,
|
||||||
|
foreground_muted: c,
|
||||||
|
accent: c,
|
||||||
|
accent_foreground: c,
|
||||||
|
border: c,
|
||||||
|
},
|
||||||
|
font_size: 14,
|
||||||
|
radius: 6,
|
||||||
|
spacing: 6,
|
||||||
|
panel_height: 44,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn test_time() -> @types.Datetime {
|
||||||
|
{
|
||||||
|
year: 2026,
|
||||||
|
month: b'\x0B',
|
||||||
|
day: b'\x18',
|
||||||
|
hour: b'\x0E',
|
||||||
|
minute: b'\x07',
|
||||||
|
second: b'\x25',
|
||||||
|
weekday: b'\x02',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "digital clock shows HH:MM and the date" {
|
||||||
|
let ops = render_digital(@ui.size(120, 36), test_tokens(), test_time())
|
||||||
|
assert_eq(ops.length(), 2)
|
||||||
|
match ops[0] {
|
||||||
|
Text(t) => assert_eq(t.text, "14:07")
|
||||||
|
_ => fail("expected text")
|
||||||
|
}
|
||||||
|
match ops[1] {
|
||||||
|
Text(t) => assert_eq(t.text, "Tue 24 Nov")
|
||||||
|
_ => fail("expected text")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "binary clock draws one dot per displayed bit" {
|
||||||
|
let ops = render_binary(@ui.size(96, 36), test_tokens(), test_time())
|
||||||
|
// 2+4+3+4+3+4 bits
|
||||||
|
assert_eq(ops.length(), 20)
|
||||||
|
let mut lit = 0
|
||||||
|
for op in ops {
|
||||||
|
match op {
|
||||||
|
Circle(c) => if c.filled { lit += 1 }
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 14:07:37 -> 1,4,0,7,3,7 -> popcount 1+1+0+3+2+3
|
||||||
|
assert_eq(lit, 10)
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||||
|
"moonplasma/desktop/lib/ui" @ui,
|
||||||
|
"moonplasma/desktop/lib/timefmt" @timefmt,
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/lib/clock"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme",
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn binary_info() -> (String, String, Int32, Int32, Int32)
|
||||||
|
|
||||||
|
pub fn digital_info() -> (String, String, Int32, Int32, Int32)
|
||||||
|
|
||||||
|
pub fn render_binary(@types.Size, @theme.Tokens, @types.Datetime) -> Array[@types.DrawOp]
|
||||||
|
|
||||||
|
pub fn render_digital(@types.Size, @theme.Tokens, @types.Datetime) -> Array[@types.DrawOp]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,320 @@
|
|||||||
|
///| Kickoff-style application launcher: state machine + render logic. Pure;
|
||||||
|
/// host capabilities (app list, launch) are passed in by the component stub.
|
||||||
|
|
||||||
|
///| Which surface an event is addressed to (mirrors the WIT `surface` enum).
|
||||||
|
pub(all) enum Target {
|
||||||
|
Widget
|
||||||
|
Popup
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub struct State {
|
||||||
|
mut open : Bool
|
||||||
|
mut query : String
|
||||||
|
mut hover : Int
|
||||||
|
mut error : String
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn State::new() -> State {
|
||||||
|
{ open: false, query: "", hover: -1, error: "" }
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let popup_w : Int = 340
|
||||||
|
|
||||||
|
///|
|
||||||
|
let header_h : Int = 52
|
||||||
|
|
||||||
|
///|
|
||||||
|
let row_h : Int = 46
|
||||||
|
|
||||||
|
///|
|
||||||
|
let max_rows : Int = 8
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn ascii_lower(s : String) -> String {
|
||||||
|
let sb = StringBuilder()
|
||||||
|
for c in s {
|
||||||
|
if c >= 'A' && c <= 'Z' {
|
||||||
|
sb.write_char(Int::unsafe_to_char(c.to_int() + 32))
|
||||||
|
} else {
|
||||||
|
sb.write_char(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn contains_ci(hay : String, needle : String) -> Bool {
|
||||||
|
if needle.length() == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
ascii_lower(hay).contains(ascii_lower(needle))
|
||||||
|
}
|
||||||
|
|
||||||
|
///| KRunner-ish filter: case-insensitive substring over name, comment and category.
|
||||||
|
pub fn filter(apps : Array[@types.AppEntry], query : String) -> Array[@types.AppEntry] {
|
||||||
|
apps.filter(a => {
|
||||||
|
contains_ci(a.name, query) ||
|
||||||
|
contains_ci(a.comment, query) ||
|
||||||
|
contains_ci(a.category, query)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn visible_rows(n : Int) -> Int {
|
||||||
|
if n > max_rows { max_rows } else { n }
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn close(st : State) -> Unit {
|
||||||
|
st.open = false
|
||||||
|
st.query = ""
|
||||||
|
st.hover = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
///| The panel button: a crescent moon plus a label.
|
||||||
|
pub fn render_button(
|
||||||
|
size : @types.Size,
|
||||||
|
t : @theme.Tokens,
|
||||||
|
st : State,
|
||||||
|
) -> Array[@types.DrawOp] {
|
||||||
|
let w = size.w.reinterpret_as_int()
|
||||||
|
let h = size.h.reinterpret_as_int()
|
||||||
|
let bg = if st.open { t.palette.accent } else { t.palette.surface_hover }
|
||||||
|
let fg = if st.open { t.palette.accent_foreground } else { t.palette.foreground }
|
||||||
|
let r = t.radius.reinterpret_as_int()
|
||||||
|
let cy = h / 2
|
||||||
|
[
|
||||||
|
@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r),
|
||||||
|
// Crescent: light disc with a button-coloured disc biting into it.
|
||||||
|
@ui.circle(18, cy, 9, fg),
|
||||||
|
@ui.circle(22, cy - 3, 8, bg),
|
||||||
|
@ui.text(36, cy, "Applications", t.font_size.reinterpret_as_int(), fg, bold=true),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn render_popup(
|
||||||
|
apps : Array[@types.AppEntry],
|
||||||
|
t : @theme.Tokens,
|
||||||
|
st : State,
|
||||||
|
) -> Array[@types.DrawOp] {
|
||||||
|
let size = popup_size(apps, st)
|
||||||
|
let w = size.w.reinterpret_as_int()
|
||||||
|
let h = size.h.reinterpret_as_int()
|
||||||
|
let fs = t.font_size.reinterpret_as_int()
|
||||||
|
let r = t.radius.reinterpret_as_int()
|
||||||
|
let p = t.palette
|
||||||
|
let ops = [
|
||||||
|
@ui.fill_rect(@ui.rect(0, 0, w, h), p.surface_popup, radius=r + 4),
|
||||||
|
@ui.stroke_rect(@ui.rect(0, 0, w, h), p.border, radius=r + 4),
|
||||||
|
// search field
|
||||||
|
@ui.fill_rect(@ui.rect(10, 10, w - 20, 32), p.surface, radius=r),
|
||||||
|
]
|
||||||
|
let q = if st.query.length() == 0 {
|
||||||
|
@ui.text(20, 26, "Type to search applications...", fs - 1, p.foreground_muted)
|
||||||
|
} else {
|
||||||
|
@ui.text(20, 26, st.query + "_", fs, p.foreground)
|
||||||
|
}
|
||||||
|
ops.push(q)
|
||||||
|
let shown = filter(apps, st.query)
|
||||||
|
if shown.length() == 0 {
|
||||||
|
ops.push(
|
||||||
|
@ui.text(w / 2, header_h + row_h / 2, "No matching applications", fs, p.foreground_muted, align=CENTER),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let n = visible_rows(shown.length())
|
||||||
|
for i = 0; i < n; i = i + 1 {
|
||||||
|
let a = shown[i]
|
||||||
|
let y = header_h + i * row_h
|
||||||
|
if i == st.hover {
|
||||||
|
ops.push(@ui.fill_rect(@ui.rect(6, y, w - 12, row_h - 2), p.accent, radius=r))
|
||||||
|
}
|
||||||
|
let fg = if i == st.hover { p.accent_foreground } else { p.foreground }
|
||||||
|
let sub = if i == st.hover { p.accent_foreground } else { p.foreground_muted }
|
||||||
|
ops.push(@ui.circle(30, y + row_h / 2 - 1, 15, p.surface_hover))
|
||||||
|
ops.push(@ui.text(30, y + row_h / 2 - 1, a.glyph, fs, fg, align=CENTER, bold=true))
|
||||||
|
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)))
|
||||||
|
}
|
||||||
|
ops
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Row index under a popup-local point, or -1.
|
||||||
|
pub fn row_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> Int {
|
||||||
|
if p.x < 6 || p.x >= popup_w - 6 || p.y < header_h {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
let i = (p.y - header_h) / row_h
|
||||||
|
if i < visible_rows(filter(apps, st.query).length()) { i } else { -1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Handle an event. `launch` is the host capability. Returns true on redraw.
|
||||||
|
pub fn handle_event(
|
||||||
|
apps : Array[@types.AppEntry],
|
||||||
|
st : State,
|
||||||
|
target : Target,
|
||||||
|
ev : @types.InputEvent,
|
||||||
|
launch : (String) -> Result[Unit, String],
|
||||||
|
) -> Bool {
|
||||||
|
match (target, ev) {
|
||||||
|
(Widget, PointerDown(_)) => {
|
||||||
|
if st.open {
|
||||||
|
close(st)
|
||||||
|
} else {
|
||||||
|
st.open = true
|
||||||
|
st.error = ""
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
(Popup, PointerMove(p)) => {
|
||||||
|
let i = row_at(apps, st, p)
|
||||||
|
if i != st.hover {
|
||||||
|
st.hover = i
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(Popup, PointerLeave) =>
|
||||||
|
if st.hover != -1 {
|
||||||
|
st.hover = -1
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
(Popup, PointerDown(p)) => {
|
||||||
|
let i = row_at(apps, st, p)
|
||||||
|
if i >= 0 {
|
||||||
|
activate(apps, st, i, launch)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
(_, FocusLost) =>
|
||||||
|
if st.open {
|
||||||
|
close(st)
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
(_, KeyDown(k)) =>
|
||||||
|
if !st.open {
|
||||||
|
false
|
||||||
|
} else if k == "Escape" {
|
||||||
|
close(st)
|
||||||
|
true
|
||||||
|
} else if k == "Backspace" {
|
||||||
|
if st.query.length() > 0 {
|
||||||
|
st.query = st.query[:st.query.length() - 1].to_owned()
|
||||||
|
}
|
||||||
|
st.hover = -1
|
||||||
|
true
|
||||||
|
} else if k == "Enter" {
|
||||||
|
if filter(apps, st.query).length() > 0 {
|
||||||
|
activate(apps, st, 0, launch)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} else if k.length() == 1 {
|
||||||
|
st.query = st.query + k
|
||||||
|
st.hover = -1
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Launch the i-th filtered app; a failure is shown in the popup (not hidden).
|
||||||
|
fn activate(
|
||||||
|
apps : Array[@types.AppEntry],
|
||||||
|
st : State,
|
||||||
|
i : Int,
|
||||||
|
launch : (String) -> Result[Unit, String],
|
||||||
|
) -> Unit {
|
||||||
|
let a = filter(apps, st.query)[i]
|
||||||
|
match launch(a.id) {
|
||||||
|
Ok(_) => close(st)
|
||||||
|
Err(e) => st.error = "Launch failed: " + e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn sample_apps() -> Array[@types.AppEntry] {
|
||||||
|
[
|
||||||
|
{ id: "a", name: "Terminal", comment: "Command line", category: "System", glyph: ">_" },
|
||||||
|
{ id: "b", name: "Files", comment: "Browse folders", category: "Utilities", glyph: "F" },
|
||||||
|
{ id: "c", name: "Web Browser", comment: "Browse the web", category: "Internet", glyph: "W" },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "filter is case-insensitive over name/comment/category" {
|
||||||
|
let apps = sample_apps()
|
||||||
|
assert_eq(filter(apps, "").length(), 3)
|
||||||
|
assert_eq(filter(apps, "TERM").length(), 1)
|
||||||
|
assert_eq(filter(apps, "folders")[0].id, "b")
|
||||||
|
assert_eq(filter(apps, "internet")[0].id, "c")
|
||||||
|
assert_eq(filter(apps, "zzz").length(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "open, type, launch via keyboard" {
|
||||||
|
let apps = sample_apps()
|
||||||
|
let st = State::new()
|
||||||
|
let launched : Array[String] = []
|
||||||
|
let launch = id => {
|
||||||
|
launched.push(id)
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
assert_true(handle_event(apps, st, Widget, PointerDown({ x: 1, y: 1 }), launch))
|
||||||
|
assert_true(st.open)
|
||||||
|
assert_true(handle_event(apps, st, Popup, KeyDown("f"), launch))
|
||||||
|
assert_true(handle_event(apps, st, Popup, KeyDown("i"), launch))
|
||||||
|
assert_eq(st.query, "fi")
|
||||||
|
assert_true(handle_event(apps, st, Popup, KeyDown("Enter"), launch))
|
||||||
|
assert_eq(launched, ["b"])
|
||||||
|
assert_false(st.open)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "click on a row launches; failure is surfaced and keeps the menu open" {
|
||||||
|
let apps = sample_apps()
|
||||||
|
let st = State::new()
|
||||||
|
st.open = true
|
||||||
|
let i = row_at(apps, st, { x: 20, y: 52 + 46 + 5 })
|
||||||
|
assert_eq(i, 1)
|
||||||
|
let _ = handle_event(
|
||||||
|
apps,
|
||||||
|
st,
|
||||||
|
Popup,
|
||||||
|
PointerDown({ x: 20, y: 52 + 46 + 5 }),
|
||||||
|
_ => Err("boom"),
|
||||||
|
)
|
||||||
|
assert_true(st.open)
|
||||||
|
assert_eq(st.error, "Launch failed: boom")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "focus loss closes and hover tracks the pointer" {
|
||||||
|
let apps = sample_apps()
|
||||||
|
let st = State::new()
|
||||||
|
st.open = true
|
||||||
|
assert_true(handle_event(apps, st, Popup, PointerMove({ x: 20, y: 60 }), _ => Ok(())))
|
||||||
|
assert_eq(st.hover, 0)
|
||||||
|
assert_false(handle_event(apps, st, Popup, PointerMove({ x: 21, y: 61 }), _ => Ok(())))
|
||||||
|
assert_true(handle_event(apps, st, Widget, FocusLost, _ => Ok(())))
|
||||||
|
assert_false(st.open)
|
||||||
|
}
|
||||||
Loaded 100 of 141 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user