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
+15
-7
@@ -56,21 +56,29 @@ pub fn render_binary(
|
||||
]
|
||||
let ops = []
|
||||
let cols = digits.length()
|
||||
let step_x = w / cols
|
||||
// Columns are grouped HH MM SS with a wider gap between groups.
|
||||
let group_gap = 8
|
||||
let step_x = (w - 2 * group_gap) / cols
|
||||
let step_y = h / 4
|
||||
let r = (if step_x < step_y { step_x } else { step_y }) / 2 - 1
|
||||
let lit = t.palette.accent
|
||||
let off = @ui.with_alpha(t.palette.foreground_muted, 70)
|
||||
for c = 0; c < cols; c = c + 1 {
|
||||
let (d, nbits) = digits[c]
|
||||
let bits = @timefmt.bcd_bits(d, nbits)
|
||||
let secs = c >= 4
|
||||
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 cx = c * step_x + step_x / 2 + (c / 2) * group_gap
|
||||
let cy = row * step_y + step_y / 2
|
||||
if bits[i] {
|
||||
ops.push(@ui.circle(cx, cy, r, t.palette.accent))
|
||||
// Soft halo + solid dot; seconds are quieter so hours/minutes read first.
|
||||
let col = if secs { @ui.with_alpha(lit, 150) } else { lit }
|
||||
ops.push(@ui.circle(cx, cy, r + 2, @ui.with_alpha(lit, if secs { 28 } else { 55 })))
|
||||
ops.push(@ui.circle(cx, cy, r, col))
|
||||
} else {
|
||||
ops.push(@ui.circle(cx, cy, r, t.palette.border, filled=false))
|
||||
ops.push(@ui.circle(cx, cy, r - 1, off))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,12 +148,12 @@ test "digital clock shows HH:MM and the date" {
|
||||
///|
|
||||
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)
|
||||
// 2+4+3+4+3+4 bits; lit bits draw a halo and a dot
|
||||
assert_eq(ops.length(), 20 + 10)
|
||||
let mut lit = 0
|
||||
for op in ops {
|
||||
match op {
|
||||
Circle(c) => if c.filled { lit += 1 }
|
||||
Circle(c) => if c.filled && c.color.a >= 150 { lit += 1 }
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ 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]
|
||||
pub fn render_digital(@types.Size, @theme.Tokens, @types.Datetime, hour12? : Bool) -> Array[@types.DrawOp]
|
||||
|
||||
// Errors
|
||||
|
||||
|
||||
@@ -53,13 +53,17 @@ fn contains_ci(hay : String, needle : String) -> Bool {
|
||||
ascii_lower(hay).contains(ascii_lower(needle))
|
||||
}
|
||||
|
||||
///| KRunner-ish filter: case-insensitive substring over name, comment and category.
|
||||
///| KRunner-ish filter: case-insensitive substring over name, id, comment and
|
||||
/// category. Name matches come first, then the rest; each group keeps its order.
|
||||
pub fn filter(apps : Array[@types.AppEntry], query : String) -> Array[@types.AppEntry] {
|
||||
apps.filter(a => {
|
||||
contains_ci(a.name, query) ||
|
||||
let by_name = apps.filter(a => contains_ci(a.name, query))
|
||||
let others = apps.filter(a => {
|
||||
!contains_ci(a.name, query) &&
|
||||
(contains_ci(a.id, query) ||
|
||||
contains_ci(a.comment, query) ||
|
||||
contains_ci(a.category, query)
|
||||
contains_ci(a.category, query))
|
||||
})
|
||||
by_name + others
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -318,3 +322,13 @@ test "focus loss closes and hover tracks the pointer" {
|
||||
assert_true(handle_event(apps, st, Widget, FocusLost, _ => Ok(())))
|
||||
assert_false(st.open)
|
||||
}
|
||||
|
||||
///|
|
||||
test "search matches the app id and ranks name matches first" {
|
||||
let apps : Array[@types.AppEntry] = [
|
||||
{ id: "org.kde.kate", name: "Text Editor", comment: "", category: "Utility", glyph: "T" },
|
||||
{ id: "x.pad", name: "Kate Pad", comment: "", category: "Utility", glyph: "K" },
|
||||
]
|
||||
let r = filter(apps, "kate")
|
||||
assert_eq(r.map(a => a.id), ["x.pad", "org.kde.kate"])
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
///| Moon-phase "toy" widget: a pure example plasmoid (tokens + date in, ops out)
|
||||
/// with two interchangeable renderings, so the shell can offer them as
|
||||
/// alternatives of one another.
|
||||
|
||||
///| Julian day number of a Gregorian calendar date (noon).
|
||||
pub fn julian_day(year : Int, month : Int, day : Int) -> Int {
|
||||
let a = (14 - month) / 12
|
||||
let y = year + 4800 - a
|
||||
let m = month + 12 * a - 3
|
||||
day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045
|
||||
}
|
||||
|
||||
///| Phase in [0, 1): 0 = new moon, 0.25 = first quarter, 0.5 = full, 0.75 = last quarter.
|
||||
/// Mean synodic month from the new moon of 2000-01-06; good to about a day.
|
||||
pub fn phase(year : Int, month : Int, day : Int) -> Double {
|
||||
let days = (julian_day(year, month, day) - 2451550).to_double() - 0.1
|
||||
let p = days / 29.530588853
|
||||
let f = p - p.floor()
|
||||
if f < 0.0 { f + 1.0 } else { f }
|
||||
}
|
||||
|
||||
///| Percent of the disc that is lit, 0..100.
|
||||
pub fn illumination(p : Double) -> Int {
|
||||
((1.0 - @math.cos(2.0 * @math.pi * p)) / 2.0 * 100.0).round().to_int()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn phase_name(p : Double) -> String {
|
||||
let i = ((p * 8.0) + 0.5).floor().to_int() % 8
|
||||
["New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous", "Full Moon", "Waning Gibbous", "Last Quarter", "Waning Crescent"][i]
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn disc_info() -> (String, String, Int, Int, Int) {
|
||||
// id, name, preferred w, preferred h, min w
|
||||
("org.moonplasma.moon.disc", "Moon Phase (disc)", 36, 36, 36)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn text_info() -> (String, String, Int, Int, Int) {
|
||||
("org.moonplasma.moon.text", "Moon Phase (text)", 110, 36, 90)
|
||||
}
|
||||
|
||||
///| The moon drawn as a disc with its lit part shaded row by row.
|
||||
pub fn render_disc(
|
||||
size : @types.Size,
|
||||
t : @theme.Tokens,
|
||||
p : Double,
|
||||
) -> Array[@types.DrawOp] {
|
||||
let w = size.w.reinterpret_as_int()
|
||||
let h = size.h.reinterpret_as_int()
|
||||
let r = (if w < h { w } else { h }) / 2 - 4
|
||||
let cx = w / 2
|
||||
let cy = h / 2
|
||||
let lit = @ui.color(244, 236, 206, 255)
|
||||
let shade = @ui.lerp_color(t.palette.surface_hover, @ui.color(10, 14, 28, 255), 1, 2)
|
||||
// Glow grows with illumination, then the dark side (faint earthshine).
|
||||
let glow = 10 + illumination(p) / 4
|
||||
let ops = [
|
||||
@ui.circle(cx, cy, r + 3, @ui.with_alpha(lit, glow / 2)),
|
||||
@ui.circle(cx, cy, r + 2, @ui.with_alpha(lit, glow)),
|
||||
@ui.circle(cx, cy, r, shade),
|
||||
]
|
||||
let k = @math.cos(2.0 * @math.pi * p)
|
||||
let waxing = p < 0.5
|
||||
// Lit area as 1px rows with fractional end pixels, so both the limb and the terminator are smooth.
|
||||
for dy = -r; dy <= r; dy = dy + 1 {
|
||||
let hw = (r * r - dy * dy).to_double().sqrt()
|
||||
let term = hw * k
|
||||
let (x0, x1) = if waxing { (term, hw) } else { (-hw, -term) }
|
||||
if x1 - x0 > 0.05 {
|
||||
let xl = x0.floor().to_int()
|
||||
let xr = x1.ceil().to_int()
|
||||
for x = xl; x < xr; x = x + 1 {
|
||||
let a = (if x1 < (x + 1).to_double() { x1 } else { (x + 1).to_double() }) -
|
||||
(if x0 > x.to_double() { x0 } else { x.to_double() })
|
||||
if a > 0.04 {
|
||||
// Slight shading toward the limb gives the disc some roundness.
|
||||
let edge = (x.to_double() + 0.5).abs() / (r.to_double() + 0.001)
|
||||
let tone = @ui.lerp_color(lit, @ui.color(214, 204, 172, 255), (edge * 100.0).to_int(), 220)
|
||||
ops.push(@ui.fill_rect(@ui.rect(cx + x, cy + dy, 1, 1), @ui.with_alpha(tone, (a * 255.0).to_int())))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ops.push(@ui.circle(cx, cy, r, @ui.with_alpha(t.palette.border, 160), filled=false))
|
||||
ops
|
||||
}
|
||||
|
||||
///| Phase name over illumination percent.
|
||||
pub fn render_text(
|
||||
size : @types.Size,
|
||||
t : @theme.Tokens,
|
||||
p : Double,
|
||||
) -> 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()
|
||||
[
|
||||
@ui.text(w / 2, h / 2 - fs / 2 + 1, phase_name(p), fs - 2, t.palette.foreground, align=CENTER, bold=true),
|
||||
@ui.text(w / 2, h / 2 + fs / 2 + 4, illumination(p).to_string() + "% lit", fs - 3, t.palette.foreground_muted, align=CENTER),
|
||||
]
|
||||
}
|
||||
|
||||
///|
|
||||
test "known dates" {
|
||||
// New moon 2000-01-06, full moon 2000-01-21, new moon 2024-01-11.
|
||||
assert_true(phase(2000, 1, 6) < 0.05 || phase(2000, 1, 6) > 0.95)
|
||||
assert_eq(phase_name(phase(2000, 1, 21)), "Full Moon")
|
||||
assert_eq(illumination(phase(2024, 1, 11)) < 5, true)
|
||||
assert_eq(julian_day(2000, 1, 1), 2451545)
|
||||
}
|
||||
|
||||
///|
|
||||
test "illumination extremes" {
|
||||
assert_eq(illumination(0.0), 0)
|
||||
assert_eq(illumination(0.5), 100)
|
||||
assert_eq(illumination(0.25), 50)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import {
|
||||
"moonbitlang/core/math" @math,
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||
"moonplasma/desktop/lib/ui" @ui,
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "moonplasma/desktop/lib/moon"
|
||||
|
||||
import {
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/theme",
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||
}
|
||||
|
||||
// Values
|
||||
pub fn disc_info() -> (String, String, Int32, Int32, Int32)
|
||||
|
||||
pub fn illumination(Double) -> Int32
|
||||
|
||||
pub fn julian_day(Int32, Int32, Int32) -> Int32
|
||||
|
||||
pub fn phase(Int32, Int32, Int32) -> Double
|
||||
|
||||
pub fn phase_name(Double) -> String
|
||||
|
||||
pub fn render_disc(@types.Size, @theme.Tokens, Double) -> Array[@types.DrawOp]
|
||||
|
||||
pub fn render_text(@types.Size, @theme.Tokens, Double) -> Array[@types.DrawOp]
|
||||
|
||||
pub fn text_info() -> (String, String, Int32, Int32, Int32)
|
||||
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
@@ -8,6 +8,8 @@ pub fn date_line(Int32, Int32, Int32) -> String
|
||||
|
||||
pub fn hhmm(Int32, Int32) -> String
|
||||
|
||||
pub fn hhmm12(Int32, Int32) -> String
|
||||
|
||||
pub fn hhmmss(Int32, Int32, Int32) -> String
|
||||
|
||||
pub fn month_short(Int32) -> String
|
||||
|
||||
@@ -8,7 +8,9 @@ import {
|
||||
// Values
|
||||
pub fn clamp_int(Int32, Int32, Int32) -> Int32
|
||||
|
||||
pub fn compute_bsp_rects(BspNode, Rect, Int32) -> Array[(UInt64, Rect)]
|
||||
pub fn compute_bsp_rects(BspNode, Rect, Int32, vgap? : Int32) -> Array[(UInt64, Rect)]
|
||||
|
||||
pub fn compute_split_handles(BspNode, Rect, Int32, Int32) -> Array[SplitHandle]
|
||||
|
||||
pub fn compute_work_area(Rect, excl_top? : Int32, excl_right? : Int32, excl_bottom? : Int32, excl_left? : Int32) -> Rect
|
||||
|
||||
@@ -76,6 +78,13 @@ pub(all) struct Size {
|
||||
h : Int32
|
||||
}
|
||||
|
||||
pub(all) struct SplitHandle {
|
||||
path : Array[Bool]
|
||||
horizontal : Bool
|
||||
rect : Rect
|
||||
area : Rect
|
||||
}
|
||||
|
||||
pub(all) struct WindowRecord {
|
||||
id : UInt64
|
||||
app_id : String
|
||||
@@ -131,6 +140,7 @@ pub(all) struct WmState {
|
||||
mut drag : DragSession?
|
||||
}
|
||||
pub fn WmState::close_window(Self, UInt64, Rect) -> Array[WmAction]
|
||||
pub fn WmState::drag_split(Self, SplitHandle, Int32, Int32, Rect) -> Array[WmAction]
|
||||
pub fn WmState::end_drag(Self) -> Unit
|
||||
pub fn WmState::handle_request(Self, UInt64, WindowRequest, Rect) -> Array[WmAction]
|
||||
pub fn WmState::hit_test(Self, Int32, Int32, Rect?) -> InputHit
|
||||
@@ -138,6 +148,7 @@ pub fn WmState::new(inner_gap? : Int32, outer_gap? : Int32, titlebar_h? : Int32,
|
||||
pub fn WmState::open_window(Self, WindowRecord, Rect) -> Array[WmAction]
|
||||
pub fn WmState::relayout(Self, UInt32, Rect) -> Array[WmAction]
|
||||
pub fn WmState::set_layout_mode(Self, LayoutMode, Rect) -> Array[WmAction]
|
||||
pub fn WmState::split_handles(Self, Rect) -> Array[SplitHandle]
|
||||
pub fn WmState::stacking_order(Self) -> Array[UInt64]
|
||||
pub fn WmState::start_drag(Self, UInt64, DragMode, Int32, Int32) -> Bool
|
||||
pub fn WmState::sync_windows(Self, Rect, Array[WindowRecord]) -> Array[WmAction]
|
||||
|
||||
+16
-2
@@ -457,8 +457,10 @@ pub fn WmState::relayout(
|
||||
w: if rect.w < min_w { min_w } else { rect.w },
|
||||
h: if rect.h < min_h { min_h } else { rect.h },
|
||||
}
|
||||
win.geometry = clamped
|
||||
actions.push(SetGeometry(id, clamped))
|
||||
// A maximized tiled window covers the whole padded work area.
|
||||
let g = if win.maximized { padded } else { clamped }
|
||||
win.geometry = g
|
||||
actions.push(SetGeometry(id, g))
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@@ -801,6 +803,18 @@ pub fn WmState::stacking_order(self : WmState) -> Array[UInt64] {
|
||||
}
|
||||
|
||||
collect_tree(ws.tree, order, ws.fullscreen, self.windows)
|
||||
// Maximized tiled windows are drawn above their neighbours.
|
||||
let below : Array[UInt64] = []
|
||||
let above : Array[UInt64] = []
|
||||
for id in order {
|
||||
match self.windows.get(id) {
|
||||
Some(w) => if w.maximized { above.push(id) } else { below.push(id) }
|
||||
None => below.push(id)
|
||||
}
|
||||
}
|
||||
order.clear()
|
||||
order.append(below)
|
||||
order.append(above)
|
||||
for id in ws.floating {
|
||||
if ws.fullscreen != Some(id) {
|
||||
match self.windows.get(id) {
|
||||
|
||||
Reference in new issue
Block a user