CI / test (push) Successful in 45s
- timefmt.hhmm12 + render_digital(hour12=); compositor panel shows '7:51 PM' (wasm clock component keeps 24h by default) - wp_cursor_shape_v1: server lets clients pick their cursor; nested window forwards the shape to the host. Launcher button/entries show a hand, the search field a text cursor, client windows what the client asked for. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
113 lines
3.1 KiB
MoonBit
113 lines
3.1 KiB
MoonBit
///| Standalone native MoonBit Wayland compositor entrypoint with wasi-gfx presentation.
|
|
|
|
///|
|
|
fn main {
|
|
let args = @env.args()
|
|
let mut socket_path = "/tmp/wayland-moon-0"
|
|
let mut theme_path = "config/themes/moon-night.json"
|
|
let mut gfx_out = ""
|
|
let mut windowed = false
|
|
let width = 1280
|
|
let height = 720
|
|
|
|
let mut i = 1
|
|
while i < args.length() {
|
|
let a = args[i]
|
|
if a == "--socket" && i + 1 < args.length() {
|
|
socket_path = args[i + 1]
|
|
i = i + 2
|
|
} else if a == "--theme" && i + 1 < args.length() {
|
|
theme_path = args[i + 1]
|
|
i = i + 2
|
|
} else if a == "--window" {
|
|
windowed = true
|
|
i = i + 1
|
|
} else if a == "--gfx-out" && i + 1 < args.length() {
|
|
gfx_out = args[i + 1]
|
|
i = i + 2
|
|
} else {
|
|
i = i + 1
|
|
}
|
|
}
|
|
|
|
let raw_theme = @sys.read_file_bytes(theme_path)
|
|
let theme = if raw_theme.length() > 0 {
|
|
let sb = StringBuilder()
|
|
for j = 0; j < raw_theme.length(); j = j + 1 {
|
|
sb.write_char(Int::unsafe_to_char(raw_theme[j].to_int()))
|
|
}
|
|
@scene.ThemeTokens::from_json_string(sb.to_string())
|
|
} else {
|
|
@scene.ThemeTokens::moon_night()
|
|
}
|
|
|
|
let gfx_surface = @gfx.Surface::new({
|
|
width: Some(width),
|
|
height: Some(height),
|
|
})
|
|
let gfx_ctx = @gfx.SurfaceFrameBufferContext::new(gfx_surface)
|
|
|
|
match @host.MoonPlasmaCompositor::new(socket_path, theme, width, height) {
|
|
Some(comp) => {
|
|
if gfx_out.length() > 0 {
|
|
let pixmap = comp.present_to_gfx(gfx_ctx)
|
|
let png = @renderer.encode_png(pixmap)
|
|
ignore(@sys.write_file_bytes(gfx_out, png))
|
|
comp.close()
|
|
println("wasi-gfx frame written to " + gfx_out)
|
|
return
|
|
}
|
|
let nested = if windowed {
|
|
let display = match @env.get_env_var("WAYLAND_DISPLAY") {
|
|
Some(d) => d
|
|
None => "wayland-0"
|
|
}
|
|
let rt = match @env.get_env_var("XDG_RUNTIME_DIR") {
|
|
Some(d) => d
|
|
None => "/tmp"
|
|
}
|
|
match @nested.NestedWindow::open(display, rt, "moon-plasma", "moon-plasma", width, height) {
|
|
Some(n) => Some(n)
|
|
None => {
|
|
println("failed to open a window on the host Wayland display")
|
|
comp.close()
|
|
return
|
|
}
|
|
}
|
|
} else {
|
|
None
|
|
}
|
|
println("moon-plasma compositor listening on " + socket_path + " (wasi-gfx surface active)")
|
|
while true {
|
|
comp.step()
|
|
match nested {
|
|
Some(n) => {
|
|
if !n.poll() {
|
|
break
|
|
}
|
|
if n.keymap.length() > 0 {
|
|
comp.server.set_keymap(n.keymap)
|
|
}
|
|
let now_ms = @env.now().to_uint()
|
|
for ev in n.take_input() {
|
|
comp.handle_input(ev, now_ms)
|
|
}
|
|
n.set_cursor_shape(comp.desired_cursor())
|
|
if n.frame_ready() {
|
|
n.present(comp.present_to_gfx(gfx_ctx))
|
|
}
|
|
}
|
|
None => {
|
|
comp.handle_gfx_events(gfx_surface)
|
|
ignore(comp.present_to_gfx(gfx_ctx))
|
|
}
|
|
}
|
|
@sys.sleep_ms(16)
|
|
}
|
|
}
|
|
None => {
|
|
println("failed to bind Wayland socket at " + socket_path)
|
|
}
|
|
}
|
|
}
|