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
@@ -16,9 +16,23 @@ pub fn encode_ppm(Pixmap) -> Bytes
|
||||
|
||||
pub fn render_scene(@scene.SceneGraph) -> Pixmap
|
||||
|
||||
pub fn set_glyph_source((Int32, Int32, Bool, Bool) -> Glyph) -> Unit
|
||||
|
||||
pub fn text_width(String, Int32, Bool, Bool) -> Int32
|
||||
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
pub(all) struct Glyph {
|
||||
w : Int32
|
||||
h : Int32
|
||||
xoff : Int32
|
||||
yoff : Int32
|
||||
advance : Int32
|
||||
coverage : Bytes
|
||||
embolden : Bool
|
||||
}
|
||||
|
||||
pub(all) struct Pixmap {
|
||||
width : Int32
|
||||
height : Int32
|
||||
|
||||
@@ -259,13 +259,22 @@ fn draw_circle(
|
||||
let cg = color.g.to_int()
|
||||
let cb = color.b.to_int()
|
||||
let ca = color.a.to_int()
|
||||
let r2 = radius * radius
|
||||
let inner_r2 = if radius > 1 { (radius - 1) * (radius - 1) } else { 0 }
|
||||
for dy = -radius; dy <= radius; dy = dy + 1 {
|
||||
for dx = -radius; dx <= radius; dx = dx + 1 {
|
||||
let d2 = dx * dx + dy * dy
|
||||
if d2 <= r2 && (filled || d2 >= inner_r2) {
|
||||
blend_pixel(dst, cx + dx, cy + dy, cr, cg, cb, ca, clip)
|
||||
// Antialiased: per-pixel coverage from the distance to the edge (1px wide ring when unfilled).
|
||||
let rad = radius.to_double()
|
||||
for dy = -radius - 1; dy <= radius + 1; dy = dy + 1 {
|
||||
for dx = -radius - 1; dx <= radius + 1; dx = dx + 1 {
|
||||
let d = (dx * dx + dy * dy).to_double().sqrt()
|
||||
let outer = rad + 0.5 - d
|
||||
let mut cov = if outer > 1.0 { 1.0 } else { outer }
|
||||
if !filled {
|
||||
let inner = d - (rad - 1.0 - 0.5)
|
||||
let ic = if inner > 1.0 { 1.0 } else { inner }
|
||||
if ic < cov {
|
||||
cov = ic
|
||||
}
|
||||
}
|
||||
if cov > 0.02 {
|
||||
blend_pixel(dst, cx + dx, cy + dy, cr, cg, cb, (ca.to_double() * cov).round().to_int(), clip)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -378,8 +387,98 @@ fn glyph_rows(ch : Int) -> Array[Int] {
|
||||
}
|
||||
}
|
||||
|
||||
///| A rasterised glyph: 8-bit coverage `w`x`h`, top-left at (xoff, yoff)
|
||||
/// relative to the pen position on the baseline.
|
||||
pub(all) struct Glyph {
|
||||
w : Int
|
||||
h : Int
|
||||
xoff : Int
|
||||
yoff : Int
|
||||
advance : Int
|
||||
coverage : Bytes
|
||||
/// Draw twice, 1px apart (faces without a real bold).
|
||||
embolden : Bool
|
||||
}
|
||||
|
||||
///| Optional real-font glyph source: (codepoint, pixel size, bold) -> glyph.
|
||||
/// Unset (e.g. in wasm builds), text uses the built-in 5x7 bitmap font.
|
||||
let glyph_source : Ref[((Int, Int, Bool, Bool) -> Glyph)?] = { val: None }
|
||||
|
||||
///|
|
||||
pub fn set_glyph_source(f : (Int, Int, Bool, Bool) -> Glyph) -> Unit {
|
||||
glyph_source.val = Some(f)
|
||||
}
|
||||
|
||||
///| Pixel width `text` would occupy when drawn with the given face.
|
||||
pub fn text_width(text : String, size : Int, bold : Bool, mono : Bool) -> Int {
|
||||
match glyph_source.val {
|
||||
Some(src) => {
|
||||
let mut w = 0
|
||||
for ch in text {
|
||||
let g = src(ch.to_int(), size, bold, mono)
|
||||
w = w + g.advance + (if g.embolden { 1 } else { 0 })
|
||||
}
|
||||
w
|
||||
}
|
||||
None => text.length() * (if size >= 14 { 12 } else { 6 })
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn draw_text_font(
|
||||
dst : Pixmap,
|
||||
src : (Int, Int, Bool, Bool) -> Glyph,
|
||||
mono : Bool,
|
||||
x : Int,
|
||||
y : Int,
|
||||
text : String,
|
||||
size : Int,
|
||||
color : @scene.Rgba,
|
||||
align : @scene.TextAlign,
|
||||
bold : Bool,
|
||||
clip : @scene.Rect?,
|
||||
) -> Unit {
|
||||
let glyphs : Array[Glyph] = []
|
||||
let mut total_w = 0
|
||||
for ch in text {
|
||||
let g = src(ch.to_int(), size, bold, mono)
|
||||
glyphs.push(g)
|
||||
total_w = total_w + g.advance + (if g.embolden { 1 } else { 0 })
|
||||
}
|
||||
let start_x = match align {
|
||||
Left => x
|
||||
Center => x - total_w / 2
|
||||
Right => x - total_w
|
||||
}
|
||||
// `y` is the vertical centre of the text; centre the capital height on it.
|
||||
let cap = src(72, size, false, mono) // 'H'
|
||||
let baseline = y + (-cap.yoff) / 2
|
||||
let cr = color.r.to_int()
|
||||
let cg = color.g.to_int()
|
||||
let cb = color.b.to_int()
|
||||
let ca = color.a.to_int()
|
||||
let mut pen = start_x
|
||||
for g in glyphs {
|
||||
for row = 0; row < g.h; row = row + 1 {
|
||||
for col = 0; col < g.w; col = col + 1 {
|
||||
let cov = g.coverage[row * g.w + col].to_int()
|
||||
if cov > 0 {
|
||||
let px = pen + g.xoff + col
|
||||
let py = baseline + g.yoff + row
|
||||
blend_pixel(dst, px, py, cr, cg, cb, ca * cov / 255, clip)
|
||||
if g.embolden {
|
||||
blend_pixel(dst, px + 1, py, cr, cg, cb, ca * cov / 255, clip)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pen = pen + g.advance + (if g.embolden { 1 } else { 0 })
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn draw_text(
|
||||
mono : Bool,
|
||||
dst : Pixmap,
|
||||
x : Int,
|
||||
y : Int,
|
||||
@@ -393,6 +492,13 @@ fn draw_text(
|
||||
if text.length() == 0 || color.a.to_int() == 0 {
|
||||
return
|
||||
}
|
||||
match glyph_source.val {
|
||||
Some(src) => {
|
||||
draw_text_font(dst, src, mono, x, y, text, size, color, align, bold, clip)
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
let scale = if size >= 14 { 2 } else { 1 }
|
||||
let char_w = 6 * scale
|
||||
let total_w = text.length() * char_w
|
||||
@@ -469,7 +575,9 @@ pub fn draw_ops(
|
||||
Circle(cx, cy, rad, col, filled) =>
|
||||
draw_circle(dst, cx + ox, cy + oy, rad, col, filled, cur_clip)
|
||||
Text(x, y, txt, sz, col, align, bold) =>
|
||||
draw_text(dst, x + ox, y + oy, txt, sz, col, align, bold, cur_clip)
|
||||
draw_text(false, dst, x + ox, y + oy, txt, sz, col, align, bold, cur_clip)
|
||||
MonoText(x, y, txt, sz, col, align, bold) =>
|
||||
draw_text(true, dst, x + ox, y + oy, txt, sz, col, align, bold, cur_clip)
|
||||
PushClip(r) =>
|
||||
clip_stack.push(@scene.Rect::new(r.x + ox, r.y + oy, r.w, r.h))
|
||||
PopClip => if clip_stack.length() > 0 { ignore(clip_stack.pop()) }
|
||||
@@ -486,6 +594,26 @@ pub fn blit_shm_surface(
|
||||
if buf.width <= 0 || buf.height <= 0 || dst_rect.w <= 0 || dst_rect.h <= 0 {
|
||||
return
|
||||
}
|
||||
// While the client catches up with a resize, its buffer is smaller than the window:
|
||||
// extend the buffer's bottom-right colour over the rest instead of showing the wallpaper.
|
||||
if (buf.width < dst_rect.w || buf.height < dst_rect.h) &&
|
||||
buf.stride * buf.height <= buf.bytes.length() &&
|
||||
buf.width > 0 {
|
||||
let o = (buf.height - 1) * buf.stride + (buf.width - 1) * 4
|
||||
let a = if buf.format == 1 { 255 } else { buf.bytes[o + 3].to_int() }
|
||||
fill_rounded_rect(
|
||||
dst,
|
||||
dst_rect,
|
||||
@scene.Rgba::new(
|
||||
buf.bytes[o + 2].to_int(),
|
||||
buf.bytes[o + 1].to_int(),
|
||||
buf.bytes[o].to_int(),
|
||||
a,
|
||||
),
|
||||
0,
|
||||
None,
|
||||
)
|
||||
}
|
||||
let copy_w = if buf.width < dst_rect.w { buf.width } else { dst_rect.w }
|
||||
let copy_h = if buf.height < dst_rect.h { buf.height } else { dst_rect.h }
|
||||
let is_xrgb = buf.format == 1
|
||||
|
||||
Reference in new issue
Block a user