Wasm panel modules, widget host, merged plasmoid host design, and shell/UI work
Panel and wasm host - The panel is built from wasm plasmoid modules (compositor/wasm: wasmer-backed host). Modules get capabilities by importing host interfaces; the host publishes data tables and serves a request queue (launch, focus window, set layout, inspector, load/unload modules). New WIT: windows, layout-control, inspector, modules, system. - Merged two competing host designs: generic tables + requests are the base; the `system` snapshot and the id-stable `windows.all/focus` (Desktop Pulse) run on top of it. - Panel widgets: load a .wasm from a path or file chooser, reorder by dragging, right-click replace/remove/add, saved to panel.edn. - Desktop widget, system sampler (sysinfo), app catalog/humanised names, Interface Explorer (inspector), real font rendering (compositor/font, assets/fonts). Compositor - Drag the divider between tiled windows; lower tiled rows leave room for the title bar. - Title-bar buttons, 12-hour clock, truncated titles, task-list/layout menus. - DRM/KMS session, tcc debug builds (vendored tinycc incl. conftest.c), justfile recipes (modules, run, test), pixi.toml. Known gaps - The sources for the pulse, tasks, layout, inspector, module-manager, moon-* and clock-digital12 modules are not in the tree yet, so `just modules` stops at pulse and the host tests that load those modules fail until they land. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
080377fd79
commit
0145981c6a
57 files changed
+11461
-221
No files matched your search
@@ -0,0 +1,142 @@
|
||||
///| Real text rendering for the native compositor: Adwaita Mono rasterised with
|
||||
/// stb_truetype, plugged into the renderer's glyph hook. The pure-MoonBit
|
||||
/// renderer (also built for wasm) keeps its bitmap font when no hook is set.
|
||||
|
||||
///|
|
||||
#borrow(path)
|
||||
extern "C" fn c_font_load(slot : Int, path : Bytes) -> Int = "mp_font_load"
|
||||
|
||||
///|
|
||||
extern "C" fn c_font_metrics(
|
||||
slot : Int,
|
||||
cp : Int,
|
||||
size : Int,
|
||||
info : FixedArray[Int],
|
||||
) = "mp_font_metrics"
|
||||
|
||||
///|
|
||||
#borrow(buf)
|
||||
extern "C" fn c_font_bitmap(
|
||||
slot : Int,
|
||||
cp : Int,
|
||||
size : Int,
|
||||
w : Int,
|
||||
h : Int,
|
||||
buf : Bytes,
|
||||
) = "mp_font_bitmap"
|
||||
|
||||
///|
|
||||
fn utf8(s : String) -> Bytes {
|
||||
let out : Array[Byte] = []
|
||||
for ch in s {
|
||||
let c = ch.to_int()
|
||||
if c < 0x80 {
|
||||
out.push(c.to_byte())
|
||||
} else if c < 0x800 {
|
||||
out.push((0xC0 | (c >> 6)).to_byte())
|
||||
out.push((0x80 | (c & 0x3F)).to_byte())
|
||||
} else if c < 0x10000 {
|
||||
out.push((0xE0 | (c >> 12)).to_byte())
|
||||
out.push((0x80 | ((c >> 6) & 0x3F)).to_byte())
|
||||
out.push((0x80 | (c & 0x3F)).to_byte())
|
||||
} else {
|
||||
out.push((0xF0 | (c >> 18)).to_byte())
|
||||
out.push((0x80 | ((c >> 12) & 0x3F)).to_byte())
|
||||
out.push((0x80 | ((c >> 6) & 0x3F)).to_byte())
|
||||
out.push((0x80 | (c & 0x3F)).to_byte())
|
||||
}
|
||||
}
|
||||
Bytes::from_array(out)
|
||||
}
|
||||
|
||||
///| Where to look for each face: bundled copy first, then the system one.
|
||||
let regular_paths : Array[String] = [
|
||||
"assets/fonts/AdwaitaMono-Regular.ttf",
|
||||
"/usr/share/fonts/Adwaita/AdwaitaMono-Regular.ttf",
|
||||
]
|
||||
|
||||
///|
|
||||
let sans_paths : Array[String] = [
|
||||
"assets/fonts/AlloVariable.ttf",
|
||||
"/usr/local/share/fonts/a/AlloVariable.ttf",
|
||||
"assets/fonts/AdwaitaSans-Regular.ttf",
|
||||
"/usr/share/fonts/Adwaita/AdwaitaSans-Regular.ttf",
|
||||
]
|
||||
|
||||
///|
|
||||
let bold_paths : Array[String] = [
|
||||
"assets/fonts/AdwaitaMono-Bold.ttf",
|
||||
"/usr/share/fonts/Adwaita/AdwaitaMono-Bold.ttf",
|
||||
]
|
||||
|
||||
///|
|
||||
fn load_first(slot : Int, paths : Array[String]) -> Bool {
|
||||
for p in paths {
|
||||
if c_font_load(slot, utf8(p)) == 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
///|
|
||||
let cache : Map[Int, @renderer.Glyph] = {}
|
||||
|
||||
///|
|
||||
fn rasterise(slot : Int, cp : Int, size : Int, embolden : Bool) -> @renderer.Glyph {
|
||||
let key = cp + 0x110000 * (size + 256 * (slot * 2 + (if embolden { 1 } else { 0 })))
|
||||
match cache.get(key) {
|
||||
Some(g) => g
|
||||
None => {
|
||||
let info : FixedArray[Int] = FixedArray::make(5, 0)
|
||||
c_font_metrics(slot, cp, size, info)
|
||||
let w = info[0]
|
||||
let h = info[1]
|
||||
let buf = if w > 0 && h > 0 {
|
||||
let b = Bytes::make(w * h, b'\x00')
|
||||
c_font_bitmap(slot, cp, size, w, h, b)
|
||||
b
|
||||
} else {
|
||||
Bytes::make(0, b'\x00')
|
||||
}
|
||||
let g : @renderer.Glyph = {
|
||||
w,
|
||||
h,
|
||||
xoff: info[2],
|
||||
yoff: info[3],
|
||||
advance: info[4],
|
||||
coverage: buf,
|
||||
embolden,
|
||||
}
|
||||
cache.set(key, g)
|
||||
g
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Install Allo Variable (UI text, falling back to Adwaita Sans) and Adwaita Mono (code) as the renderer's
|
||||
/// faces. Returns false (keeping the bitmap font) when no face can be found.
|
||||
/// Slots: 0 mono, 1 mono bold, 2 sans. Sans is a variable font whose bold
|
||||
/// instance stb_truetype can't select, so bold sans is emboldened.
|
||||
pub fn install() -> Bool {
|
||||
let has_mono = load_first(0, regular_paths)
|
||||
let has_sans = load_first(2, sans_paths)
|
||||
if !has_mono && !has_sans {
|
||||
return false
|
||||
}
|
||||
let has_bold = has_mono && load_first(1, bold_paths)
|
||||
@renderer.set_glyph_source(fn(cp, size, bold, mono) {
|
||||
if mono && has_mono {
|
||||
if bold && has_bold {
|
||||
rasterise(1, cp, size, false)
|
||||
} else {
|
||||
rasterise(0, cp, size, bold)
|
||||
}
|
||||
} else if has_sans {
|
||||
rasterise(2, cp, size, bold)
|
||||
} else {
|
||||
rasterise(0, cp, size, bold)
|
||||
}
|
||||
})
|
||||
true
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "moonbit.h"
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STBTT_STATIC
|
||||
#include "stb_truetype.h"
|
||||
|
||||
#define MAX_SLOTS 4
|
||||
static stbtt_fontinfo fonts[MAX_SLOTS];
|
||||
static unsigned char *font_data[MAX_SLOTS];
|
||||
|
||||
/* Load a TTF file into `slot`. Returns 0 on success. */
|
||||
MOONBIT_FFI_EXPORT
|
||||
int32_t mp_font_load(int32_t slot, moonbit_bytes_t path_bytes) {
|
||||
char path[512];
|
||||
int32_t len = Moonbit_array_length(path_bytes);
|
||||
size_t n = (size_t)len < sizeof(path) - 1 ? (size_t)len : sizeof(path) - 1;
|
||||
memcpy(path, path_bytes, n);
|
||||
path[n] = '\0';
|
||||
if (slot < 0 || slot >= MAX_SLOTS) return -1;
|
||||
FILE *f = fopen(path, "rb");
|
||||
if (!f) return -1;
|
||||
fseek(f, 0, SEEK_END);
|
||||
long sz = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
if (sz <= 0) { fclose(f); return -1; }
|
||||
unsigned char *buf = (unsigned char *)malloc((size_t)sz);
|
||||
if (!buf || fread(buf, 1, (size_t)sz, f) != (size_t)sz) { fclose(f); free(buf); return -1; }
|
||||
fclose(f);
|
||||
if (!stbtt_InitFont(&fonts[slot], buf, stbtt_GetFontOffsetForIndex(buf, 0))) { free(buf); return -1; }
|
||||
free(font_data[slot]);
|
||||
font_data[slot] = buf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* info = [w, h, xoff, yoff (top-left of bitmap relative to pen/baseline), advance] in pixels. */
|
||||
MOONBIT_FFI_EXPORT
|
||||
void mp_font_metrics(int32_t slot, int32_t cp, int32_t size, int32_t *info) {
|
||||
stbtt_fontinfo *fi = &fonts[slot];
|
||||
float scale = stbtt_ScaleForMappingEmToPixels(fi, (float)size);
|
||||
int adv, lsb, x0, y0, x1, y1;
|
||||
int g = stbtt_FindGlyphIndex(fi, cp);
|
||||
stbtt_GetGlyphHMetrics(fi, g, &adv, &lsb);
|
||||
stbtt_GetGlyphBitmapBox(fi, g, scale, scale, &x0, &y0, &x1, &y1);
|
||||
info[0] = x1 - x0;
|
||||
info[1] = y1 - y0;
|
||||
info[2] = x0;
|
||||
info[3] = y0;
|
||||
info[4] = (int32_t)(adv * scale + 0.5f);
|
||||
}
|
||||
|
||||
/* Render the 8-bit coverage bitmap (w*h bytes, w/h from mp_font_metrics) into buf. */
|
||||
MOONBIT_FFI_EXPORT
|
||||
void mp_font_bitmap(int32_t slot, int32_t cp, int32_t size, int32_t w, int32_t h, moonbit_bytes_t buf) {
|
||||
stbtt_fontinfo *fi = &fonts[slot];
|
||||
float scale = stbtt_ScaleForMappingEmToPixels(fi, (float)size);
|
||||
if (w <= 0 || h <= 0 || Moonbit_array_length(buf) < w * h) return;
|
||||
stbtt_MakeGlyphBitmap(fi, (unsigned char *)buf, w, h, w, scale, scale, stbtt_FindGlyphIndex(fi, cp));
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import {
|
||||
"moonbitlang/core/builtin",
|
||||
"moonplasma/desktop/compositor/renderer" @renderer,
|
||||
}
|
||||
|
||||
supported_targets = "-all+native"
|
||||
|
||||
options(
|
||||
"native-stub": [ "font_stub.c" ],
|
||||
)
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user