CI / test (push) Failing after 16s
moon-plasma / moonplasma / MoonPlasma / Moon Plasma become chandra / Chandra everywhere: the WIT package (chandra:desktop, chandra:host, chandra:wm), the MoonBit module (chandra/desktop) and generated bindings, the Rust host, identifiers (ChandraCompositor), the session script (chandra-session) and desktop entry (chandra.desktop), config and data paths ($XDG_CONFIG_HOME/chandra, share/chandra/modules), env vars (CHANDRA_*), UI strings, docs and tests. The test fixture components are rebuilt against the renamed WIT. Saved panel.edn and state.edn are still read from the old $XDG_CONFIG_HOME/moon-plasma until the first save writes the new copy. The remote repository keeps its experiments/moon-plasma name for now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hi3L9oVBoRd373Qr4n
165 lines
4.1 KiB
MoonBit
165 lines
4.1 KiB
MoonBit
///| Chandra GUI loader component backed by wasi-gfx (surface + frame-buffer).
|
|
|
|
priv struct GfxGuiState {
|
|
mut surface : @surface.Surface?
|
|
mut context : @sfb.Context?
|
|
mut width : Int
|
|
mut height : Int
|
|
mut launcher_open : Bool
|
|
mut pointer_x : Double
|
|
mut pointer_y : Double
|
|
mut last_key : String
|
|
mut frame_count : Int
|
|
}
|
|
|
|
let state : GfxGuiState = {
|
|
surface: None,
|
|
context: None,
|
|
width: 640,
|
|
height: 360,
|
|
launcher_open: false,
|
|
pointer_x: 0.0,
|
|
pointer_y: 0.0,
|
|
last_key: "",
|
|
frame_count: 0,
|
|
}
|
|
|
|
///|
|
|
pub fn init_gui(width : UInt, height : UInt) -> Unit {
|
|
let w = if width < 1U { 1U } else { width }
|
|
let h = if height < 1U { 1U } else { height }
|
|
state.width = w.reinterpret_as_int()
|
|
state.height = h.reinterpret_as_int()
|
|
let surf = @surface.Surface::surface({
|
|
height: Some(h),
|
|
width: Some(w),
|
|
})
|
|
let ctx = @sfb.Context::context(surf)
|
|
state.surface = Some(surf)
|
|
state.context = Some(ctx)
|
|
render_frame()
|
|
}
|
|
|
|
///|
|
|
pub fn render_frame() -> Unit {
|
|
match state.context {
|
|
None => ()
|
|
Some(ctx) => {
|
|
state.frame_count = state.frame_count + 1
|
|
let w = state.width
|
|
let h = state.height
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let sg = @scene.SceneGraph::new(w, h)
|
|
let titles : Array[String] = ["wasi-gfx Desktop"]
|
|
let (bg_ops, panel_ops) = @scene.build_shell_ops(
|
|
w,
|
|
h,
|
|
theme,
|
|
"wasi-gfx",
|
|
titles,
|
|
)
|
|
sg.background_ops = bg_ops
|
|
sg.panel_ops = panel_ops
|
|
|
|
// Add a sample Breeze-decorated window so the GUI surface is rich and verifiable.
|
|
let win_w = if w > 320 { w / 2 } else { w - 32 }
|
|
let win_h = if h > 220 { h / 2 } else { h - 64 }
|
|
let (insets, deco_ops) = @scene.build_breeze_decoration(
|
|
"chandra (wasi-gfx)",
|
|
"org.chandra.gfx",
|
|
true,
|
|
false,
|
|
win_w + 4,
|
|
win_h + 34,
|
|
theme,
|
|
)
|
|
sg.windows.push({
|
|
id: 1UL,
|
|
title: "chandra (wasi-gfx)",
|
|
app_id: "org.chandra.gfx",
|
|
focused: true,
|
|
fullscreen: false,
|
|
geometry: @scene.Rect::new(24, 24, win_w, win_h),
|
|
deco_insets: insets,
|
|
deco_ops,
|
|
surface: None,
|
|
})
|
|
|
|
if state.launcher_open {
|
|
sg.widgets.push({
|
|
id: "launcher",
|
|
rect: @scene.Rect::new(8, h - theme.panel_height - 168, 220, 160),
|
|
ops: [
|
|
@scene.DrawOp::FillRect(
|
|
@scene.Rect::new(0, 0, 220, 160),
|
|
theme.palette.surface_popup,
|
|
theme.radius,
|
|
),
|
|
@scene.DrawOp::StrokeRect(
|
|
@scene.Rect::new(0, 0, 220, 160),
|
|
theme.palette.border,
|
|
theme.radius,
|
|
1,
|
|
),
|
|
@scene.DrawOp::Text(
|
|
14,
|
|
24,
|
|
"Applications (wasi-gfx)",
|
|
theme.font_size,
|
|
theme.palette.foreground,
|
|
@scene.TextAlign::Left,
|
|
true,
|
|
),
|
|
],
|
|
popup: None,
|
|
})
|
|
}
|
|
|
|
let pixmap = @renderer.render_scene(sg)
|
|
let buf = ctx.get_current_buffer()
|
|
buf.set_with_copy(pixmap.data)
|
|
ctx.present()
|
|
}
|
|
}
|
|
}
|
|
|
|
///|
|
|
pub fn on_resize(width : UInt, height : UInt) -> Unit {
|
|
let w = if width < 1U { 1U } else { width }
|
|
let h = if height < 1U { 1U } else { height }
|
|
state.width = w.reinterpret_as_int()
|
|
state.height = h.reinterpret_as_int()
|
|
match state.surface {
|
|
Some(surf) => surf.request_set_size(Some(h), Some(w))
|
|
None => ()
|
|
}
|
|
render_frame()
|
|
}
|
|
|
|
///|
|
|
pub fn on_pointer(kind : Byte, x : Double, y : Double) -> Unit {
|
|
state.pointer_x = x
|
|
state.pointer_y = y
|
|
// kind == 1: pointer down
|
|
if kind == b'\x01' {
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
if y.to_int() >= state.height - theme.panel_height && x.to_int() <= 120 {
|
|
state.launcher_open = !state.launcher_open
|
|
}
|
|
render_frame()
|
|
}
|
|
}
|
|
|
|
///|
|
|
pub fn on_key(pressed : Bool, text : String) -> Unit {
|
|
if pressed {
|
|
state.last_key = text
|
|
if text == "Escape" {
|
|
state.launcher_open = false
|
|
} else if text == "Super" || text == "Meta" {
|
|
state.launcher_open = !state.launcher_open
|
|
}
|
|
render_frame()
|
|
}
|
|
}
|