Spike Wayland compositor, hybrid MoonBit WM, SSD decorations, and wasmtime native host
This commit is contained in:
1 parent
880ecd4102
commit
17a8a46cfd
56 files changed
+8924
-11
No files matched your search
@@ -5,3 +5,4 @@ node_modules/
|
|||||||
.context/
|
.context/
|
||||||
.mooncakes/
|
.mooncakes/
|
||||||
*.log
|
*.log
|
||||||
|
host-native/target/
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn mbt_ffi_cabi_realloc(
|
||||||
|
src_offset : Int,
|
||||||
|
src_size : Int,
|
||||||
|
_dst_alignment : Int,
|
||||||
|
dst_size : Int,
|
||||||
|
) -> Int {
|
||||||
|
// malloc
|
||||||
|
if src_offset == 0 && src_size == 0 {
|
||||||
|
return mbt_ffi_malloc(dst_size)
|
||||||
|
}
|
||||||
|
// free
|
||||||
|
if dst_size == 0 {
|
||||||
|
mbt_ffi_free(src_offset)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
// realloc
|
||||||
|
let dst = mbt_ffi_malloc(dst_size)
|
||||||
|
mbt_ffi_copy(dst, src_offset, if src_size < dst_size { src_size } else { dst_size })
|
||||||
|
mbt_ffi_free(src_offset)
|
||||||
|
dst
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_copy(dest : Int, src : Int, len : Int) =
|
||||||
|
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) (local i32)
|
||||||
|
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||||
|
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||||
|
#| local.get 1)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRender(p0 : Int) -> Int {
|
||||||
|
@decoration.wasmExportRender(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
||||||
|
@decoration.wasmExportRenderPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRender(p0 : Int) -> Int {
|
||||||
|
|
||||||
|
let result = mbt_ffi_ptr2str(mbt_ffi_load32((p0) + 8), mbt_ffi_load32((p0) + 12))
|
||||||
|
|
||||||
|
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((p0) + 16), mbt_ffi_load32((p0) + 20))
|
||||||
|
|
||||||
|
let lifted : @types.Size? = match mbt_ffi_load8_u((p0) + 48) {
|
||||||
|
0 => Option::None
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
Option::Some(@types.Size::{w : (mbt_ffi_load32((p0) + 52)).reinterpret_as_uint(), h : (mbt_ffi_load32((p0) + 56)).reinterpret_as_uint()})
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
let (result1) : (DecorationFrame) = render(@policy.WindowState::{id : (mbt_ffi_load64((p0) + 0)).reinterpret_as_uint64(), app_id : result, title : result0, geometry : @types.Rect::{x : mbt_ffi_load32((p0) + 24), y : mbt_ffi_load32((p0) + 28), w : (mbt_ffi_load32((p0) + 32)).reinterpret_as_uint(), h : (mbt_ffi_load32((p0) + 36)).reinterpret_as_uint()}, min_size : @types.Size::{w : (mbt_ffi_load32((p0) + 40)).reinterpret_as_uint(), h : (mbt_ffi_load32((p0) + 44)).reinterpret_as_uint()}, max_size : lifted, focused : (mbt_ffi_load8_u((p0) + 60) != 0), maximized : (mbt_ffi_load8_u((p0) + 61) != 0), fullscreen : (mbt_ffi_load8_u((p0) + 62) != 0), workspace : (mbt_ffi_load32((p0) + 64)).reinterpret_as_uint(), caps : @policy.WindowCaps(mbt_ffi_load8_u((p0) + 68).to_byte())}, @types.Size::{w : (mbt_ffi_load32((p0) + 72)).reinterpret_as_uint(), h : (mbt_ffi_load32((p0) + 76)).reinterpret_as_uint()});
|
||||||
|
mbt_ffi_free(p0)
|
||||||
|
let return_area = mbt_ffi_malloc(32)
|
||||||
|
mbt_ffi_store32((return_area) + 0, (((result1).insets).0).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 4, (((result1).insets).1).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 8, (((result1).insets).2).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 12, (((result1).insets).3).reinterpret_as_int())
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc(((result1).ops).length() * 32);
|
||||||
|
for index = 0; index < ((result1).ops).length(); index = index + 1 {
|
||||||
|
let iter_elem : @types.DrawOp = ((result1).ops)[(index)]
|
||||||
|
let iter_base = address + (index * 32);
|
||||||
|
|
||||||
|
match iter_elem {
|
||||||
|
FillRect(payload) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (0))
|
||||||
|
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
StrokeRect(payload2) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (1))
|
||||||
|
mbt_ffi_store32((iter_base) + 4, ((payload2).rect).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, ((payload2).rect).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 12, (((payload2).rect).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, (((payload2).rect).h).reinterpret_as_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 20, (((payload2).color).r).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 21, (((payload2).color).g).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 22, (((payload2).color).b).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 23, (((payload2).color).a).to_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 24, ((payload2).width).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 28, ((payload2).radius).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Line(payload3) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (2))
|
||||||
|
mbt_ffi_store32((iter_base) + 4, ((payload3).start).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, ((payload3).start).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 12, ((payload3).end).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 16, ((payload3).end).y)
|
||||||
|
mbt_ffi_store8((iter_base) + 20, (((payload3).color).r).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 21, (((payload3).color).g).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 22, (((payload3).color).b).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 23, (((payload3).color).a).to_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 24, ((payload3).width).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Circle(payload4) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (3))
|
||||||
|
mbt_ffi_store32((iter_base) + 4, ((payload4).center).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, ((payload4).center).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 12, ((payload4).radius).reinterpret_as_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (((payload4).color).r).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 17, (((payload4).color).g).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 18, (((payload4).color).b).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 19, (((payload4).color).a).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 20, (if (payload4).filled { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Text(payload5) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (4))
|
||||||
|
mbt_ffi_store32((iter_base) + 4, ((payload5).origin).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, ((payload5).origin).y)
|
||||||
|
|
||||||
|
let ptr = mbt_ffi_str2ptr((payload5).text)
|
||||||
|
mbt_ffi_store32((iter_base) + 16, (payload5).text.length())
|
||||||
|
mbt_ffi_store32((iter_base) + 12, ptr)
|
||||||
|
mbt_ffi_store32((iter_base) + 20, (((payload5).style).size).reinterpret_as_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 24, ((((payload5).style).color).r).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 25, ((((payload5).style).color).g).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 26, ((((payload5).style).color).b).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 27, ((((payload5).style).color).a).to_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 28, ((payload5).style).align.ordinal())
|
||||||
|
mbt_ffi_store8((iter_base) + 29, (if ((payload5).style).bold { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
PushClip(payload6) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (5))
|
||||||
|
mbt_ffi_store32((iter_base) + 4, (payload6).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, (payload6).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 12, ((payload6).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, ((payload6).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
PopClip => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (6))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 20, ((result1).ops).length())
|
||||||
|
mbt_ffi_store32((return_area) + 16, address)
|
||||||
|
|
||||||
|
let address8 = mbt_ffi_malloc(((result1).hit_regions).length() * 20);
|
||||||
|
for index9 = 0; index9 < ((result1).hit_regions).length(); index9 = index9 + 1 {
|
||||||
|
let iter_elem : HitRegion = ((result1).hit_regions)[(index9)]
|
||||||
|
let iter_base = address8 + (index9 * 20);
|
||||||
|
mbt_ffi_store32((iter_base) + 0, ((iter_elem).rect).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 4, ((iter_elem).rect).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, (((iter_elem).rect).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 12, (((iter_elem).rect).h).reinterpret_as_int())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (iter_elem).role.ordinal())
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 28, ((result1).hit_regions).length())
|
||||||
|
mbt_ffi_store32((return_area) + 24, address8)
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
||||||
|
|
||||||
|
for index = 0; index < (mbt_ffi_load32((p0) + 20)); index = index + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((p0) + 16)) + (index * 32)
|
||||||
|
|
||||||
|
match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||||
|
0 => ()
|
||||||
|
1 => ()
|
||||||
|
2 => ()
|
||||||
|
3 => ()
|
||||||
|
4 => {
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
|
||||||
|
|
||||||
|
}
|
||||||
|
5 => ()
|
||||||
|
6 => ()
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 16))
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 24))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) (local i32)
|
||||||
|
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||||
|
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||||
|
#| local.get 1)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||||
|
#|(func (param i32) (param i32) (result i32)
|
||||||
|
#| local.get 0
|
||||||
|
#| local.get 1 call $moonbit.init_array16
|
||||||
|
#| local.get 0)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||||
|
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
#owned(str)
|
||||||
|
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0)
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/wm/policy" @policy,
|
||||||
|
"moonplasma/desktop/lib/ui" @ui,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/decoration-breeze/gen/interface/moonplasma/wm/decoration"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
"moonplasma/desktop/interface/moonplasma/wm/policy",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn render(@policy.WindowState, @types.Size) -> DecorationFrame
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) struct DecorationFrame {
|
||||||
|
insets : (UInt32, UInt32, UInt32, UInt32)
|
||||||
|
ops : Array[@types.DrawOp]
|
||||||
|
hit_regions : Array[HitRegion]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct HitRegion {
|
||||||
|
rect : @types.Rect
|
||||||
|
role : HitRole
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum HitRole {
|
||||||
|
NONE
|
||||||
|
TITLEBAR
|
||||||
|
CLOSE
|
||||||
|
MAXIMIZE
|
||||||
|
MINIMIZE
|
||||||
|
RESIZE_N
|
||||||
|
RESIZE_S
|
||||||
|
RESIZE_E
|
||||||
|
RESIZE_W
|
||||||
|
RESIZE_NW
|
||||||
|
RESIZE_NE
|
||||||
|
RESIZE_SW
|
||||||
|
RESIZE_SE
|
||||||
|
}
|
||||||
|
pub fn HitRole::from(Int32) -> Self
|
||||||
|
pub fn HitRole::ordinal(Self) -> Int32
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
///| `moonplasma:wm/decoration` Breeze-inspired server-side decoration component.
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn render(
|
||||||
|
win : @policy.WindowState,
|
||||||
|
outer_size : @types.Size,
|
||||||
|
) -> DecorationFrame {
|
||||||
|
if win.fullscreen {
|
||||||
|
return { insets: (0U, 0U, 0U, 0U), ops: [], hit_regions: [] }
|
||||||
|
}
|
||||||
|
let t = @theme.get_tokens()
|
||||||
|
let p = t.palette
|
||||||
|
let w = outer_size.w.reinterpret_as_int()
|
||||||
|
let h = outer_size.h.reinterpret_as_int()
|
||||||
|
let title_h = 32
|
||||||
|
let border = 2
|
||||||
|
let radius = t.radius.reinterpret_as_int()
|
||||||
|
|
||||||
|
let title_bg = if win.focused { p.surface } else { @ui.with_alpha(p.surface, 210) }
|
||||||
|
let border_col = if win.focused { p.accent } else { p.border }
|
||||||
|
let title_fg = if win.focused { p.foreground } else { p.foreground_muted }
|
||||||
|
|
||||||
|
let ops : Array[@types.DrawOp] = [
|
||||||
|
// Titlebar + outer frame background
|
||||||
|
@ui.fill_rect(@ui.rect(0, 0, w, title_h), title_bg, radius=radius),
|
||||||
|
@ui.stroke_rect(@ui.rect(0, 0, w, h), border_col, width=border, radius=radius),
|
||||||
|
// Subtle separator under titlebar
|
||||||
|
@ui.line(border, title_h - 1, w - border, title_h - 1, p.border, width=1),
|
||||||
|
]
|
||||||
|
|
||||||
|
let label = if win.title.length() > 0 { win.title } else { win.app_id }
|
||||||
|
ops.push(
|
||||||
|
@ui.text(
|
||||||
|
14,
|
||||||
|
title_h / 2,
|
||||||
|
label,
|
||||||
|
t.font_size.reinterpret_as_int(),
|
||||||
|
title_fg,
|
||||||
|
align=LEFT,
|
||||||
|
bold=win.focused,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Window control buttons on the right: [ _ ] [ [] ] [ X ]
|
||||||
|
let btn_size = 18
|
||||||
|
let btn_y = (title_h - btn_size) / 2
|
||||||
|
let close_x = w - 10 - btn_size
|
||||||
|
let max_x = close_x - 8 - btn_size
|
||||||
|
let min_x = max_x - 8 - btn_size
|
||||||
|
|
||||||
|
let close_bg = if win.focused { @ui.color(218, 68, 83, 255) } else { p.surface_hover }
|
||||||
|
let btn_bg = p.surface_hover
|
||||||
|
|
||||||
|
ops.push(@ui.fill_rect(@ui.rect(min_x, btn_y, btn_size, btn_size), btn_bg, radius=9))
|
||||||
|
ops.push(@ui.line(min_x + 5, btn_y + btn_size - 6, min_x + btn_size - 5, btn_y + btn_size - 6, title_fg, width=2))
|
||||||
|
|
||||||
|
ops.push(@ui.fill_rect(@ui.rect(max_x, btn_y, btn_size, btn_size), btn_bg, radius=9))
|
||||||
|
ops.push(@ui.stroke_rect(@ui.rect(max_x + 5, btn_y + 5, btn_size - 10, btn_size - 10), title_fg, width=1))
|
||||||
|
|
||||||
|
ops.push(@ui.fill_rect(@ui.rect(close_x, btn_y, btn_size, btn_size), close_bg, radius=9))
|
||||||
|
ops.push(@ui.line(close_x + 5, btn_y + 5, close_x + btn_size - 5, btn_y + btn_size - 5, p.accent_foreground, width=2))
|
||||||
|
ops.push(@ui.line(close_x + btn_size - 5, btn_y + 5, close_x + 5, btn_y + btn_size - 5, p.accent_foreground, width=2))
|
||||||
|
|
||||||
|
let hit_regions : Array[HitRegion] = [
|
||||||
|
{ rect: @ui.rect(close_x, btn_y, btn_size, btn_size), role: CLOSE },
|
||||||
|
{ rect: @ui.rect(max_x, btn_y, btn_size, btn_size), role: MAXIMIZE },
|
||||||
|
{ rect: @ui.rect(min_x, btn_y, btn_size, btn_size), role: MINIMIZE },
|
||||||
|
{ rect: @ui.rect(border, border, w - 2 * border, title_h - border), role: TITLEBAR },
|
||||||
|
{ rect: @ui.rect(0, 0, 8, 8), role: RESIZE_NW },
|
||||||
|
{ rect: @ui.rect(w - 8, 0, 8, 8), role: RESIZE_NE },
|
||||||
|
{ rect: @ui.rect(0, h - 8, 8, 8), role: RESIZE_SW },
|
||||||
|
{ rect: @ui.rect(w - 8, h - 8, 8, 8), role: RESIZE_SE },
|
||||||
|
{ rect: @ui.rect(8, 0, w - 16, 4), role: RESIZE_N },
|
||||||
|
{ rect: @ui.rect(8, h - 4, w - 16, 4), role: RESIZE_S },
|
||||||
|
{ rect: @ui.rect(0, 8, 4, h - 16), role: RESIZE_W },
|
||||||
|
{ rect: @ui.rect(w - 4, 8, 4, h - 16), role: RESIZE_E },
|
||||||
|
]
|
||||||
|
|
||||||
|
{
|
||||||
|
insets: (title_h.reinterpret_as_uint(), border.reinterpret_as_uint(), border.reinterpret_as_uint(), border.reinterpret_as_uint()),
|
||||||
|
ops,
|
||||||
|
hit_regions,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
pub(all) enum HitRole {
|
||||||
|
NONE; TITLEBAR; CLOSE; MAXIMIZE; MINIMIZE; RESIZE_N; RESIZE_S; RESIZE_E; RESIZE_W; RESIZE_NW; RESIZE_NE; RESIZE_SW; RESIZE_SE
|
||||||
|
} derive()
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn HitRole::ordinal(self : HitRole) -> Int {
|
||||||
|
match self {
|
||||||
|
NONE => 0
|
||||||
|
TITLEBAR => 1
|
||||||
|
CLOSE => 2
|
||||||
|
MAXIMIZE => 3
|
||||||
|
MINIMIZE => 4
|
||||||
|
RESIZE_N => 5
|
||||||
|
RESIZE_S => 6
|
||||||
|
RESIZE_E => 7
|
||||||
|
RESIZE_W => 8
|
||||||
|
RESIZE_NW => 9
|
||||||
|
RESIZE_NE => 10
|
||||||
|
RESIZE_SW => 11
|
||||||
|
RESIZE_SE => 12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn HitRole::from(self : Int) -> HitRole {
|
||||||
|
match self {
|
||||||
|
0 => NONE
|
||||||
|
1 => TITLEBAR
|
||||||
|
2 => CLOSE
|
||||||
|
3 => MAXIMIZE
|
||||||
|
4 => MINIMIZE
|
||||||
|
5 => RESIZE_N
|
||||||
|
6 => RESIZE_S
|
||||||
|
7 => RESIZE_E
|
||||||
|
8 => RESIZE_W
|
||||||
|
9 => RESIZE_NW
|
||||||
|
10 => RESIZE_NE
|
||||||
|
11 => RESIZE_SW
|
||||||
|
12 => RESIZE_SE
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct HitRegion {
|
||||||
|
rect : @types.Rect; role : HitRole
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct DecorationFrame {
|
||||||
|
insets : (UInt, UInt, UInt, UInt); ops : Array[@types.DrawOp]; hit_regions : Array[HitRegion]
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
declare pub fn render(win : @policy.WindowState, outer_size : @types.Size) -> DecorationFrame
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/components/decoration-breeze/gen/interface/moonplasma/wm/decoration" @decoration,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
|
|
||||||
|
pkgtype(kind: "foreign_library")
|
||||||
|
|
||||||
|
options(
|
||||||
|
link: {
|
||||||
|
"wasm": {
|
||||||
|
"export-memory-name": "memory",
|
||||||
|
"heap-start-address": 16,
|
||||||
|
"exports": [
|
||||||
|
"mbt_ffi_cabi_realloc:cabi_realloc",
|
||||||
|
"wasmExportRender:moonplasma:wm/decoration@0.2.0#render",
|
||||||
|
"wasmExportRenderPostReturn:cabi_post_moonplasma:wm/decoration@0.2.0#render"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/decoration-breeze/gen"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn mbt_ffi_cabi_realloc(
|
||||||
|
src_offset : Int,
|
||||||
|
src_size : Int,
|
||||||
|
_dst_alignment : Int,
|
||||||
|
dst_size : Int,
|
||||||
|
) -> Int {
|
||||||
|
// malloc
|
||||||
|
if src_offset == 0 && src_size == 0 {
|
||||||
|
return mbt_ffi_malloc(dst_size)
|
||||||
|
}
|
||||||
|
// free
|
||||||
|
if dst_size == 0 {
|
||||||
|
mbt_ffi_free(src_offset)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
// realloc
|
||||||
|
let dst = mbt_ffi_malloc(dst_size)
|
||||||
|
mbt_ffi_copy(dst, src_offset, if src_size < dst_size { src_size } else { dst_size })
|
||||||
|
mbt_ffi_free(src_offset)
|
||||||
|
dst
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_copy(dest : Int, src : Int, len : Int) =
|
||||||
|
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) (local i32)
|
||||||
|
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||||
|
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||||
|
#| local.get 1)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowRequestPostReturn(p0 : Int) -> Unit {
|
||||||
|
@policy.wasmExportOnWindowRequestPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportSetLayoutModePostReturn(p0 : Int) -> Unit {
|
||||||
|
@policy.wasmExportSetLayoutModePostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowOpen(p0 : Int) -> Int {
|
||||||
|
@policy.wasmExportOnWindowOpen(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportStackingOrder() -> Int {
|
||||||
|
@policy.wasmExportStackingOrder()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportSyncWindowsPostReturn(p0 : Int) -> Unit {
|
||||||
|
@policy.wasmExportSyncWindowsPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportStackingOrderPostReturn(p0 : Int) -> Unit {
|
||||||
|
@policy.wasmExportStackingOrderPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowClosePostReturn(p0 : Int) -> Unit {
|
||||||
|
@policy.wasmExportOnWindowClosePostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowRequest(p0 : Int64, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int) -> Int {
|
||||||
|
@policy.wasmExportOnWindowRequest(p0, p1, p2, p3, p4, p5, p6, p7)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnPointer(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
|
||||||
|
@policy.wasmExportOnPointer(p0, p1, p2, p3, p4)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowOpenPostReturn(p0 : Int) -> Unit {
|
||||||
|
@policy.wasmExportOnWindowOpenPostReturn(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportSetLayoutMode(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
|
||||||
|
@policy.wasmExportSetLayoutMode(p0, p1, p2, p3, p4)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportSyncWindows(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||||
|
@policy.wasmExportSyncWindows(p0, p1, p2, p3)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowClose(p0 : Int64) -> Int {
|
||||||
|
@policy.wasmExportOnWindowClose(p0)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,558 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportSyncWindows(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||||
|
|
||||||
|
let array : Array[@types.Rect] = [];
|
||||||
|
for index = 0; index < (p1); index = index + 1 {
|
||||||
|
let iter_base = (p0) + (index * 16)
|
||||||
|
|
||||||
|
array.push(@types.Rect::{x : mbt_ffi_load32((iter_base) + 0), y : mbt_ffi_load32((iter_base) + 4), w : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint()})
|
||||||
|
}
|
||||||
|
mbt_ffi_free(p0)
|
||||||
|
|
||||||
|
let array1 : Array[WindowState] = [];
|
||||||
|
for index2 = 0; index2 < (p3); index2 = index2 + 1 {
|
||||||
|
let iter_base = (p2) + (index2 * 72)
|
||||||
|
|
||||||
|
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
|
||||||
|
|
||||||
|
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20))
|
||||||
|
|
||||||
|
let lifted : @types.Size? = match mbt_ffi_load8_u((iter_base) + 48) {
|
||||||
|
0 => Option::None
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
Option::Some(@types.Size::{w : (mbt_ffi_load32((iter_base) + 52)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 56)).reinterpret_as_uint()})
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
array1.push(WindowState::{id : (mbt_ffi_load64((iter_base) + 0)).reinterpret_as_uint64(), app_id : result, title : result0, geometry : @types.Rect::{x : mbt_ffi_load32((iter_base) + 24), y : mbt_ffi_load32((iter_base) + 28), w : (mbt_ffi_load32((iter_base) + 32)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 36)).reinterpret_as_uint()}, min_size : @types.Size::{w : (mbt_ffi_load32((iter_base) + 40)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 44)).reinterpret_as_uint()}, max_size : lifted, focused : (mbt_ffi_load8_u((iter_base) + 60) != 0), maximized : (mbt_ffi_load8_u((iter_base) + 61) != 0), fullscreen : (mbt_ffi_load8_u((iter_base) + 62) != 0), workspace : (mbt_ffi_load32((iter_base) + 64)).reinterpret_as_uint(), caps : WindowCaps(mbt_ffi_load8_u((iter_base) + 68).to_byte())})
|
||||||
|
}
|
||||||
|
mbt_ffi_free(p2)
|
||||||
|
|
||||||
|
let (result3) : (Array[WmAction]) = sync_windows(array, array1);
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc((result3).length() * 32);
|
||||||
|
for index9 = 0; index9 < (result3).length(); index9 = index9 + 1 {
|
||||||
|
let iter_elem : WmAction = (result3)[(index9)]
|
||||||
|
let iter_base = address + (index9 * 32);
|
||||||
|
|
||||||
|
match iter_elem {
|
||||||
|
SetGeometry(payload) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (0))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, ((payload).1).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 20, ((payload).1).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 24, (((payload).1).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 28, (((payload).1).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Focus(payload4) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (1))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload4).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Raise(payload5) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (2))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload5).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Close(payload6) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (3))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload6).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetMaximized(payload7) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (4))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload7).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload7).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetFullscreen(payload8) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (5))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload8).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload8).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 4, (result3).length())
|
||||||
|
mbt_ffi_store32((return_area) + 0, address)
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportSyncWindowsPostReturn(p0 : Int) -> Unit {
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowOpen(p0 : Int) -> Int {
|
||||||
|
|
||||||
|
let result = mbt_ffi_ptr2str(mbt_ffi_load32((p0) + 8), mbt_ffi_load32((p0) + 12))
|
||||||
|
|
||||||
|
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((p0) + 16), mbt_ffi_load32((p0) + 20))
|
||||||
|
|
||||||
|
let lifted : @types.Size? = match mbt_ffi_load8_u((p0) + 48) {
|
||||||
|
0 => Option::None
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
Option::Some(@types.Size::{w : (mbt_ffi_load32((p0) + 52)).reinterpret_as_uint(), h : (mbt_ffi_load32((p0) + 56)).reinterpret_as_uint()})
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
let (result1) : (Array[WmAction]) = on_window_open(WindowState::{id : (mbt_ffi_load64((p0) + 0)).reinterpret_as_uint64(), app_id : result, title : result0, geometry : @types.Rect::{x : mbt_ffi_load32((p0) + 24), y : mbt_ffi_load32((p0) + 28), w : (mbt_ffi_load32((p0) + 32)).reinterpret_as_uint(), h : (mbt_ffi_load32((p0) + 36)).reinterpret_as_uint()}, min_size : @types.Size::{w : (mbt_ffi_load32((p0) + 40)).reinterpret_as_uint(), h : (mbt_ffi_load32((p0) + 44)).reinterpret_as_uint()}, max_size : lifted, focused : (mbt_ffi_load8_u((p0) + 60) != 0), maximized : (mbt_ffi_load8_u((p0) + 61) != 0), fullscreen : (mbt_ffi_load8_u((p0) + 62) != 0), workspace : (mbt_ffi_load32((p0) + 64)).reinterpret_as_uint(), caps : WindowCaps(mbt_ffi_load8_u((p0) + 68).to_byte())}, @types.Rect::{x : mbt_ffi_load32((p0) + 72), y : mbt_ffi_load32((p0) + 76), w : (mbt_ffi_load32((p0) + 80)).reinterpret_as_uint(), h : (mbt_ffi_load32((p0) + 84)).reinterpret_as_uint()});
|
||||||
|
mbt_ffi_free(p0)
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc((result1).length() * 32);
|
||||||
|
for index = 0; index < (result1).length(); index = index + 1 {
|
||||||
|
let iter_elem : WmAction = (result1)[(index)]
|
||||||
|
let iter_base = address + (index * 32);
|
||||||
|
|
||||||
|
match iter_elem {
|
||||||
|
SetGeometry(payload) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (0))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, ((payload).1).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 20, ((payload).1).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 24, (((payload).1).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 28, (((payload).1).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Focus(payload2) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (1))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload2).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Raise(payload3) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (2))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload3).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Close(payload4) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (3))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload4).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetMaximized(payload5) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (4))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload5).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload5).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetFullscreen(payload6) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (5))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload6).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload6).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 4, (result1).length())
|
||||||
|
mbt_ffi_store32((return_area) + 0, address)
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowOpenPostReturn(p0 : Int) -> Unit {
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowClose(p0 : Int64) -> Int {
|
||||||
|
|
||||||
|
let (result) : (Array[WmAction]) = on_window_close((p0).reinterpret_as_uint64());
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc((result).length() * 32);
|
||||||
|
for index = 0; index < (result).length(); index = index + 1 {
|
||||||
|
let iter_elem : WmAction = (result)[(index)]
|
||||||
|
let iter_base = address + (index * 32);
|
||||||
|
|
||||||
|
match iter_elem {
|
||||||
|
SetGeometry(payload) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (0))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, ((payload).1).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 20, ((payload).1).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 24, (((payload).1).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 28, (((payload).1).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Focus(payload0) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (1))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload0).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Raise(payload1) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (2))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload1).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Close(payload2) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (3))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload2).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetMaximized(payload3) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (4))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload3).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload3).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetFullscreen(payload4) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (5))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload4).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload4).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 4, (result).length())
|
||||||
|
mbt_ffi_store32((return_area) + 0, address)
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowClosePostReturn(p0 : Int) -> Unit {
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowRequest(p0 : Int64, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int) -> Int {
|
||||||
|
|
||||||
|
let lifted = match (p1) {
|
||||||
|
0 => {
|
||||||
|
|
||||||
|
WindowRequest::Maximize((p2 != 0))
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
WindowRequest::Fullscreen((p2 != 0))
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
|
||||||
|
WindowRequest::Minimize((p2 != 0))
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
|
||||||
|
WindowRequest::Close
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
|
||||||
|
WindowRequest::Activate
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
|
||||||
|
WindowRequest::MoveTo(@types.Point::{x : p2, y : p3})
|
||||||
|
}
|
||||||
|
6 => {
|
||||||
|
|
||||||
|
WindowRequest::ResizeTo(@types.Size::{w : (p2).reinterpret_as_uint(), h : (p3).reinterpret_as_uint()})
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
let (result) : (Array[WmAction]) = on_window_request((p0).reinterpret_as_uint64(), lifted, @types.Rect::{x : p4, y : p5, w : (p6).reinterpret_as_uint(), h : (p7).reinterpret_as_uint()});
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc((result).length() * 32);
|
||||||
|
for index = 0; index < (result).length(); index = index + 1 {
|
||||||
|
let iter_elem : WmAction = (result)[(index)]
|
||||||
|
let iter_base = address + (index * 32);
|
||||||
|
|
||||||
|
match iter_elem {
|
||||||
|
SetGeometry(payload) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (0))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, ((payload).1).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 20, ((payload).1).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 24, (((payload).1).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 28, (((payload).1).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Focus(payload0) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (1))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload0).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Raise(payload1) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (2))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload1).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Close(payload2) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (3))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload2).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetMaximized(payload3) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (4))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload3).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload3).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetFullscreen(payload4) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (5))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload4).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload4).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 4, (result).length())
|
||||||
|
mbt_ffi_store32((return_area) + 0, address)
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnWindowRequestPostReturn(p0 : Int) -> Unit {
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportOnPointer(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
|
||||||
|
|
||||||
|
let lifted : UInt? = match p2 {
|
||||||
|
0 => Option::None
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
Option::Some((p3).reinterpret_as_uint())
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
let (result) : (InputTarget) = on_pointer(@types.Point::{x : p0, y : p1}, lifted, (p4 != 0));
|
||||||
|
let return_area = mbt_ffi_malloc(24)
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Client(payload) => {
|
||||||
|
mbt_ffi_store8((return_area) + 0, (0))
|
||||||
|
mbt_ffi_store64((return_area) + 8, ((payload).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store32((return_area) + 16, ((payload).1).x)
|
||||||
|
mbt_ffi_store32((return_area) + 20, ((payload).1).y)
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Decoration(payload0) => {
|
||||||
|
mbt_ffi_store8((return_area) + 0, (1))
|
||||||
|
mbt_ffi_store64((return_area) + 8, ((payload0).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store32((return_area) + 16, ((payload0).1).x)
|
||||||
|
mbt_ffi_store32((return_area) + 20, ((payload0).1).y)
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
ShellPanel(payload1) => {
|
||||||
|
mbt_ffi_store8((return_area) + 0, (2))
|
||||||
|
mbt_ffi_store32((return_area) + 8, (payload1).x)
|
||||||
|
mbt_ffi_store32((return_area) + 12, (payload1).y)
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
mbt_ffi_store8((return_area) + 0, (3))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportSetLayoutMode(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
|
||||||
|
|
||||||
|
let (result) : (Array[WmAction]) = set_layout_mode(LayoutMode::from(p0), @types.Rect::{x : p1, y : p2, w : (p3).reinterpret_as_uint(), h : (p4).reinterpret_as_uint()});
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc((result).length() * 32);
|
||||||
|
for index = 0; index < (result).length(); index = index + 1 {
|
||||||
|
let iter_elem : WmAction = (result)[(index)]
|
||||||
|
let iter_base = address + (index * 32);
|
||||||
|
|
||||||
|
match iter_elem {
|
||||||
|
SetGeometry(payload) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (0))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, ((payload).1).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 20, ((payload).1).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 24, (((payload).1).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 28, (((payload).1).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Focus(payload0) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (1))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload0).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Raise(payload1) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (2))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload1).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Close(payload2) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (3))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, (payload2).reinterpret_as_int64())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetMaximized(payload3) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (4))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload3).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload3).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
SetFullscreen(payload4) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 0, (5))
|
||||||
|
mbt_ffi_store64((iter_base) + 8, ((payload4).0).reinterpret_as_int64())
|
||||||
|
mbt_ffi_store8((iter_base) + 16, (if (payload4).1 { 1 } else { 0 }))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 4, (result).length())
|
||||||
|
mbt_ffi_store32((return_area) + 0, address)
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportSetLayoutModePostReturn(p0 : Int) -> Unit {
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportStackingOrder() -> Int {
|
||||||
|
|
||||||
|
let (result) : (Array[UInt64]) = stacking_order();
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc((result).length() * 8);
|
||||||
|
for index = 0; index < (result).length(); index = index + 1 {
|
||||||
|
let iter_elem : UInt64 = (result)[(index)]
|
||||||
|
let iter_base = address + (index * 8);
|
||||||
|
mbt_ffi_store64((iter_base) + 0, (iter_elem).reinterpret_as_int64())
|
||||||
|
|
||||||
|
}
|
||||||
|
mbt_ffi_store32((return_area) + 4, (result).length())
|
||||||
|
mbt_ffi_store32((return_area) + 0, address)
|
||||||
|
let ret = return_area
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
#doc(hidden)
|
||||||
|
pub fn wasmExportStackingOrderPostReturn(p0 : Int) -> Unit {
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||||
|
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) (local i32)
|
||||||
|
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||||
|
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||||
|
#| local.get 1)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
|
||||||
|
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||||
|
#|(func (param i32) (param i32) (result i32)
|
||||||
|
#| local.get 0
|
||||||
|
#| local.get 1 call $moonbit.init_array16
|
||||||
|
#| local.get 0)
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||||
|
"moonplasma/desktop/lib/wm" @wm,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/wm-hybrid/gen/interface/moonplasma/wm/policy"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn on_pointer(@types.Point, UInt32?, Bool) -> InputTarget
|
||||||
|
|
||||||
|
pub fn on_window_close(UInt64) -> Array[WmAction]
|
||||||
|
|
||||||
|
pub fn on_window_open(WindowState, @types.Rect) -> Array[WmAction]
|
||||||
|
|
||||||
|
pub fn on_window_request(UInt64, WindowRequest, @types.Rect) -> Array[WmAction]
|
||||||
|
|
||||||
|
pub fn set_layout_mode(LayoutMode, @types.Rect) -> Array[WmAction]
|
||||||
|
|
||||||
|
pub fn stacking_order() -> Array[UInt64]
|
||||||
|
|
||||||
|
pub fn sync_windows(Array[@types.Rect], Array[WindowState]) -> Array[WmAction]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) enum InputTarget {
|
||||||
|
Client((UInt64, @types.Point))
|
||||||
|
Decoration((UInt64, @types.Point))
|
||||||
|
ShellPanel(@types.Point)
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum LayoutMode {
|
||||||
|
FLOATING
|
||||||
|
TILING
|
||||||
|
MONOCLE
|
||||||
|
}
|
||||||
|
pub fn LayoutMode::from(Int32) -> Self
|
||||||
|
pub fn LayoutMode::ordinal(Self) -> Int32
|
||||||
|
|
||||||
|
pub(all) struct WindowCaps(Byte)
|
||||||
|
pub fn WindowCaps::default() -> Self
|
||||||
|
pub fn WindowCaps::is_set(Self, WindowCapsFlag) -> Bool
|
||||||
|
pub fn WindowCaps::set(Self, WindowCapsFlag) -> Self
|
||||||
|
pub fn WindowCaps::unset(Self, WindowCapsFlag) -> Self
|
||||||
|
|
||||||
|
pub(all) enum WindowCapsFlag {
|
||||||
|
CAN_MOVE
|
||||||
|
CAN_RESIZE
|
||||||
|
CAN_MAXIMIZE
|
||||||
|
CAN_MINIMIZE
|
||||||
|
CAN_FULLSCREEN
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum WindowRequest {
|
||||||
|
Maximize(Bool)
|
||||||
|
Fullscreen(Bool)
|
||||||
|
Minimize(Bool)
|
||||||
|
Close
|
||||||
|
Activate
|
||||||
|
MoveTo(@types.Point)
|
||||||
|
ResizeTo(@types.Size)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct WindowState {
|
||||||
|
id : UInt64
|
||||||
|
app_id : String
|
||||||
|
title : String
|
||||||
|
geometry : @types.Rect
|
||||||
|
min_size : @types.Size
|
||||||
|
max_size : @types.Size?
|
||||||
|
focused : Bool
|
||||||
|
maximized : Bool
|
||||||
|
fullscreen : Bool
|
||||||
|
workspace : UInt32
|
||||||
|
caps : WindowCaps
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum WmAction {
|
||||||
|
SetGeometry((UInt64, @types.Rect))
|
||||||
|
Focus(UInt64)
|
||||||
|
Raise(UInt64)
|
||||||
|
Close(UInt64)
|
||||||
|
SetMaximized((UInt64, Bool))
|
||||||
|
SetFullscreen((UInt64, Bool))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
///| `moonplasma:wm/policy` hybrid WM component backed by `lib/wm`.
|
||||||
|
|
||||||
|
///|
|
||||||
|
let state : @wm.WmState = @wm.WmState::new()
|
||||||
|
|
||||||
|
///|
|
||||||
|
let last_work_area : Ref[@wm.Rect] = { val: { x: 0, y: 0, w: 1280, h: 672 } }
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn to_wm_rect(r : @types.Rect) -> @wm.Rect {
|
||||||
|
{ x: r.x, y: r.y, w: r.w.reinterpret_as_int(), h: r.h.reinterpret_as_int() }
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn to_wit_rect(r : @wm.Rect) -> @types.Rect {
|
||||||
|
{ x: r.x, y: r.y, w: r.w.reinterpret_as_uint(), h: r.h.reinterpret_as_uint() }
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn to_wm_record(w : WindowState) -> @wm.WindowRecord {
|
||||||
|
let g = to_wm_rect(w.geometry)
|
||||||
|
{
|
||||||
|
id: w.id,
|
||||||
|
app_id: w.app_id,
|
||||||
|
title: w.title,
|
||||||
|
geometry: g,
|
||||||
|
floating_geometry: g,
|
||||||
|
min_size: { w: w.min_size.w.reinterpret_as_int(), h: w.min_size.h.reinterpret_as_int() },
|
||||||
|
max_size: match w.max_size {
|
||||||
|
Some(ms) => Some({ w: ms.w.reinterpret_as_int(), h: ms.h.reinterpret_as_int() })
|
||||||
|
None => None
|
||||||
|
},
|
||||||
|
focused: w.focused,
|
||||||
|
maximized: w.maximized,
|
||||||
|
fullscreen: w.fullscreen,
|
||||||
|
minimized: false,
|
||||||
|
is_floating: false,
|
||||||
|
workspace: w.workspace,
|
||||||
|
can_move: w.caps.is_set(CAN_MOVE),
|
||||||
|
can_resize: w.caps.is_set(CAN_RESIZE),
|
||||||
|
can_maximize: w.caps.is_set(CAN_MAXIMIZE),
|
||||||
|
can_minimize: w.caps.is_set(CAN_MINIMIZE),
|
||||||
|
can_fullscreen: w.caps.is_set(CAN_FULLSCREEN),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn to_wit_actions(actions : Array[@wm.WmAction]) -> Array[WmAction] {
|
||||||
|
actions.map(a => match a {
|
||||||
|
SetGeometry(id, r) => SetGeometry((id, to_wit_rect(r)))
|
||||||
|
Focus(id) => Focus(id)
|
||||||
|
Raise(id) => Raise(id)
|
||||||
|
Close(id) => Close(id)
|
||||||
|
SetMaximized(id, b) => SetMaximized((id, b))
|
||||||
|
SetFullscreen(id, b) => SetFullscreen((id, b))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn sync_theme() -> Unit {
|
||||||
|
let t = @theme.get_tokens()
|
||||||
|
let gap = t.spacing.reinterpret_as_int()
|
||||||
|
state.inner_gap = gap
|
||||||
|
state.outer_gap = gap
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn sync_windows(
|
||||||
|
outputs : Array[@types.Rect],
|
||||||
|
windows : Array[WindowState],
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
sync_theme()
|
||||||
|
let wa = if outputs.length() > 0 {
|
||||||
|
to_wm_rect(outputs[0])
|
||||||
|
} else {
|
||||||
|
last_work_area.val
|
||||||
|
}
|
||||||
|
last_work_area.val = wa
|
||||||
|
let recs = windows.map(to_wm_record)
|
||||||
|
to_wit_actions(state.sync_windows(wa, recs))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn on_window_open(
|
||||||
|
win : WindowState,
|
||||||
|
work_area : @types.Rect,
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
sync_theme()
|
||||||
|
let wa = to_wm_rect(work_area)
|
||||||
|
last_work_area.val = wa
|
||||||
|
to_wit_actions(state.open_window(to_wm_record(win), wa))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn on_window_close(id : UInt64) -> Array[WmAction] {
|
||||||
|
sync_theme()
|
||||||
|
to_wit_actions(state.close_window(id, last_work_area.val))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn on_window_request(
|
||||||
|
id : UInt64,
|
||||||
|
req : WindowRequest,
|
||||||
|
work_area : @types.Rect,
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
sync_theme()
|
||||||
|
let wa = to_wm_rect(work_area)
|
||||||
|
last_work_area.val = wa
|
||||||
|
let wm_req : @wm.WindowRequest = match req {
|
||||||
|
Maximize(b) => Maximize(b)
|
||||||
|
Fullscreen(b) => Fullscreen(b)
|
||||||
|
Minimize(b) => Minimize(b)
|
||||||
|
Close => Close
|
||||||
|
Activate => Activate
|
||||||
|
MoveTo(p) => MoveTo(p.x, p.y)
|
||||||
|
ResizeTo(s) => ResizeTo(s.w.reinterpret_as_int(), s.h.reinterpret_as_int())
|
||||||
|
}
|
||||||
|
to_wit_actions(state.handle_request(id, wm_req, wa))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn on_pointer(
|
||||||
|
pos : @types.Point,
|
||||||
|
_button : UInt?,
|
||||||
|
_pressed : Bool,
|
||||||
|
) -> InputTarget {
|
||||||
|
match state.hit_test(pos.x, pos.y, None) {
|
||||||
|
Client(id, lx, ly) => Client((id, { x: lx, y: ly }))
|
||||||
|
Decoration(id, lx, ly) => Decoration((id, { x: lx, y: ly }))
|
||||||
|
ShellPanel(lx, ly) => ShellPanel({ x: lx, y: ly })
|
||||||
|
HitNone => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn set_layout_mode(
|
||||||
|
mode : LayoutMode,
|
||||||
|
work_area : @types.Rect,
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
sync_theme()
|
||||||
|
let wa = to_wm_rect(work_area)
|
||||||
|
last_work_area.val = wa
|
||||||
|
let wm_mode : @wm.LayoutMode = match mode {
|
||||||
|
FLOATING => Floating
|
||||||
|
TILING => Tiling
|
||||||
|
MONOCLE => Monocle
|
||||||
|
}
|
||||||
|
to_wit_actions(state.set_layout_mode(wm_mode, wa))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn stacking_order() -> Array[UInt64] {
|
||||||
|
state.stacking_order()
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
pub(all) struct WindowCaps(Byte) derive()
|
||||||
|
///|
|
||||||
|
pub fn WindowCaps::default() -> WindowCaps {
|
||||||
|
WindowCaps(b'\x00')
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum WindowCapsFlag {
|
||||||
|
CAN_MOVE; CAN_RESIZE; CAN_MAXIMIZE; CAN_MINIMIZE; CAN_FULLSCREEN
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
fn WindowCapsFlag::value(self : WindowCapsFlag) -> Byte {
|
||||||
|
match self {
|
||||||
|
CAN_MOVE => ((1U << 0).to_byte())
|
||||||
|
CAN_RESIZE => ((1U << 1).to_byte())
|
||||||
|
CAN_MAXIMIZE => ((1U << 2).to_byte())
|
||||||
|
CAN_MINIMIZE => ((1U << 3).to_byte())
|
||||||
|
CAN_FULLSCREEN => ((1U << 4).to_byte())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn WindowCaps::set(self : Self, other: WindowCapsFlag) -> WindowCaps {
|
||||||
|
let WindowCaps(flag) = self
|
||||||
|
WindowCaps(flag.lor(other.value()))
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn WindowCaps::unset(self : Self, other: WindowCapsFlag) -> WindowCaps {
|
||||||
|
let WindowCaps(flag) = self
|
||||||
|
WindowCaps(flag.land(other.value().lnot()))
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn WindowCaps::is_set(self : Self, other: WindowCapsFlag) -> Bool {
|
||||||
|
let WindowCaps(flag) = self
|
||||||
|
(flag.land(other.value()) == other.value())
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum LayoutMode {
|
||||||
|
FLOATING; TILING; MONOCLE
|
||||||
|
} derive()
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn LayoutMode::ordinal(self : LayoutMode) -> Int {
|
||||||
|
match self {
|
||||||
|
FLOATING => 0
|
||||||
|
TILING => 1
|
||||||
|
MONOCLE => 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn LayoutMode::from(self : Int) -> LayoutMode {
|
||||||
|
match self {
|
||||||
|
0 => FLOATING
|
||||||
|
1 => TILING
|
||||||
|
2 => MONOCLE
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct WindowState {
|
||||||
|
id : UInt64; app_id : String; title : String; geometry : @types.Rect; min_size : @types.Size; max_size : @types.Size?; focused : Bool; maximized : Bool; fullscreen : Bool; workspace : UInt; caps : WindowCaps
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum WindowRequest {
|
||||||
|
Maximize(Bool)
|
||||||
|
Fullscreen(Bool)
|
||||||
|
Minimize(Bool)
|
||||||
|
Close
|
||||||
|
Activate
|
||||||
|
MoveTo(@types.Point)
|
||||||
|
ResizeTo(@types.Size)
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum WmAction {
|
||||||
|
SetGeometry((UInt64, @types.Rect))
|
||||||
|
Focus(UInt64)
|
||||||
|
Raise(UInt64)
|
||||||
|
Close(UInt64)
|
||||||
|
SetMaximized((UInt64, Bool))
|
||||||
|
SetFullscreen((UInt64, Bool))
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum InputTarget {
|
||||||
|
Client((UInt64, @types.Point))
|
||||||
|
Decoration((UInt64, @types.Point))
|
||||||
|
ShellPanel(@types.Point)
|
||||||
|
None
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
/// Called on startup or WM hot-swap to synchronize existing windows.
|
||||||
|
declare pub fn sync_windows(outputs : Array[@types.Rect], windows : Array[WindowState]) -> Array[WmAction]
|
||||||
|
///|
|
||||||
|
declare pub fn on_window_open(win : WindowState, work_area : @types.Rect) -> Array[WmAction]
|
||||||
|
///|
|
||||||
|
declare pub fn on_window_close(id : UInt64) -> Array[WmAction]
|
||||||
|
///|
|
||||||
|
declare pub fn on_window_request(id : UInt64, req : WindowRequest, work_area : @types.Rect) -> Array[WmAction]
|
||||||
|
///|
|
||||||
|
declare pub fn on_pointer(pos : @types.Point, button : UInt?, pressed : Bool) -> InputTarget
|
||||||
|
///|
|
||||||
|
declare pub fn set_layout_mode(mode : LayoutMode, work_area : @types.Rect) -> Array[WmAction]
|
||||||
|
///|
|
||||||
|
/// Returns window IDs in bottom-to-top Z-order.
|
||||||
|
declare pub fn stacking_order() -> Array[UInt64]
|
||||||
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/components/wm-hybrid/gen/interface/moonplasma/wm/policy" @policy,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
|
|
||||||
|
pkgtype(kind: "foreign_library")
|
||||||
|
|
||||||
|
options(
|
||||||
|
link: {
|
||||||
|
"wasm": {
|
||||||
|
"export-memory-name": "memory",
|
||||||
|
"heap-start-address": 16,
|
||||||
|
"exports": [
|
||||||
|
"mbt_ffi_cabi_realloc:cabi_realloc",
|
||||||
|
"wasmExportOnPointer:moonplasma:wm/policy@0.2.0#on-pointer",
|
||||||
|
"wasmExportOnWindowClose:moonplasma:wm/policy@0.2.0#on-window-close",
|
||||||
|
"wasmExportOnWindowClosePostReturn:cabi_post_moonplasma:wm/policy@0.2.0#on-window-close",
|
||||||
|
"wasmExportOnWindowOpen:moonplasma:wm/policy@0.2.0#on-window-open",
|
||||||
|
"wasmExportOnWindowOpenPostReturn:cabi_post_moonplasma:wm/policy@0.2.0#on-window-open",
|
||||||
|
"wasmExportOnWindowRequest:moonplasma:wm/policy@0.2.0#on-window-request",
|
||||||
|
"wasmExportOnWindowRequestPostReturn:cabi_post_moonplasma:wm/policy@0.2.0#on-window-request",
|
||||||
|
"wasmExportSetLayoutMode:moonplasma:wm/policy@0.2.0#set-layout-mode",
|
||||||
|
"wasmExportSetLayoutModePostReturn:cabi_post_moonplasma:wm/policy@0.2.0#set-layout-mode",
|
||||||
|
"wasmExportStackingOrder:moonplasma:wm/policy@0.2.0#stacking-order",
|
||||||
|
"wasmExportStackingOrderPostReturn:cabi_post_moonplasma:wm/policy@0.2.0#stacking-order",
|
||||||
|
"wasmExportSyncWindows:moonplasma:wm/policy@0.2.0#sync-windows",
|
||||||
|
"wasmExportSyncWindowsPostReturn:cabi_post_moonplasma:wm/policy@0.2.0#sync-windows"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/components/wm-hybrid/gen"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,412 @@
|
|||||||
|
# `moon-plasma` Compositor & Window Manager Architecture
|
||||||
|
|
||||||
|
> **Target repository:** [experiments/moon-plasma](https://git.site.latha.org/experiments/moon-plasma)
|
||||||
|
> **Scope:** Architectural design for evolving `moon-plasma` from its M0 JS/Canvas2D proof-of-concept into a native Wayland compositor and hot-swappable Window Manager (M3–M8), preserving its core invariant: **every policy is a sandboxed MoonBit WebAssembly component; the host only owns mechanism, devices, and scanout.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Architectural Thesis: Split Mechanism vs. Policy
|
||||||
|
|
||||||
|
Traditional Wayland compositors (KWin, Sway, Mutter) bundle device management, Wayland protocol state, GPU compositing, window management policy, decorations, and shell UI into a single privileged process. A crash or logic bug in a decoration or tiling script can bring down the entire display server.
|
||||||
|
|
||||||
|
`moon-plasma` inverts this by splitting the compositor along a **typed WebAssembly Component Model (WIT) boundary**:
|
||||||
|
|
||||||
|
| Layer | Responsibility | Implementation | Trust Level |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| **Host (Mechanism)** | `calloop` event loop, Wayland protocol server (Smithay), DRM/KMS & `libinput` (or nested `winit`), SHM/DMA-BUF memory, render-list & surface rasterizer, `wasmtime` engine + epoch/fuel supervision, capability broker | **Rust** (`host-native/`) | Trusted Computing Base (TCB) |
|
||||||
|
| **Components (Policy)** | Window placement, tiling/stacking, focus policy, hit-testing/input routing, window decorations, panel layout, desktop background, widgets, declarative scene effects | **MoonBit** (`wasm` linear-memory components via `wit-bindgen moonbit`) | Untrusted, capability-attenuated, hot-swappable |
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TB
|
||||||
|
subgraph clients["Foreign Wayland / XWayland Clients"]
|
||||||
|
c1["App A (xdg_toplevel, wl_shm / dmabuf)"]
|
||||||
|
c2["App B (xdg_toplevel + xdg_popup)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph host["Trusted Host (Rust: smithay + wasmtime + calloop)"]
|
||||||
|
wl["Wayland Server (wl_compositor, xdg_wm_base, dmabuf, seat)"]
|
||||||
|
loop["calloop Event Loop + Epoch Watchdog"]
|
||||||
|
broker["Capability Broker & Component Supervisor"]
|
||||||
|
scene["Retained Scene Graph & Damage Tracker"]
|
||||||
|
ras["Dual-Path Rasterizer (GLES/wgpu + tiny-skia fallback)"]
|
||||||
|
be["Backend (Nested winit / DRM+KMS+libinput)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph comps["Sandboxed MoonBit Components (.wasm)"]
|
||||||
|
wm["window-manager (wm-policy, input-router)"]
|
||||||
|
deco["decoration (titlebars, hit-regions)"]
|
||||||
|
shell["shell (desktop-surface, panel-layout)"]
|
||||||
|
widgets["plasmoids (launcher, clock, tray)"]
|
||||||
|
fx["effects (declarative transforms)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
clients -- "Wayland UNIX socket + fds" --> wl
|
||||||
|
wl -- "buffer-surface handles & events" --> loop
|
||||||
|
loop -- "bounded sync WIT calls" --> broker
|
||||||
|
broker <--> wm & deco & shell & widgets & fx
|
||||||
|
wm & deco & shell & widgets & fx -- "list<draw-op> + revision + actions" --> scene
|
||||||
|
wl -- "committed wl_surface buffers" --> scene
|
||||||
|
scene -- "damaged rects" --> ras --> be
|
||||||
|
```
|
||||||
|
|
||||||
|
### Design Invariants Carried Forward from M0
|
||||||
|
1. **Components never touch raw pixels or GPU handles:** UI components emit `list<draw-op>` in local coordinates. Foreign Wayland clients write to host-owned `buffer-surface` resources; components only reference those opaque handles.
|
||||||
|
2. **Deny-by-default capabilities:** A component only receives the WIT imports declared in its world *and* explicitly granted in the session/desktop config.
|
||||||
|
3. **Fault isolation:** If `window-manager` or `decoration` traps or exceeds its frame time budget, `wasmtime` unwinds the call, the host logs a `ComponentFault`, renders a fallback tile / server-side border, and keeps scanning out at 60/120 Hz.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Core Compositor Responsibilities
|
||||||
|
|
||||||
|
### 2.1 Wayland Protocol Handling (Host: `smithay`)
|
||||||
|
The host embeds Smithay to expose standard Wayland globals on `$XDG_RUNTIME_DIR/wayland-N`:
|
||||||
|
- **Core:** `wl_compositor` (v5+), `wl_subcompositor`, `wl_shm`, `wl_output`, `wl_seat` (pointer, keyboard, touch), `wl_data_device_manager` (clipboard & drag-and-drop).
|
||||||
|
- **Desktop Shells:**
|
||||||
|
- `xdg_wm_base` (`xdg_surface`, `xdg_toplevel`, `xdg_popup`) for application windows.
|
||||||
|
- `zxdg_decoration_manager_v1` (server-side decoration negotiation, defaulting to SSD via the `decoration` component).
|
||||||
|
- `zwlr_layer_shell_v1` (optional for external bars/lockscreens, though native `moon-plasma` panels are MoonBit components).
|
||||||
|
- **Buffers & Sync:** `zwp_linux_dmabuf_v1` (v4 with scanout/renderer tranche feedback), `wp_viewporter`, `wp_presentation_time`.
|
||||||
|
- **XWayland (M6+):** Rootless `Xwayland` managed by the host, mapping X11 windows into the exact same `WindowRegistry` so the MoonBit WM treats them identically to native Wayland clients.
|
||||||
|
|
||||||
|
### 2.2 Window & Surface Management (Split Host/WM)
|
||||||
|
- **Host (`WindowRegistry`):** Owns the authoritative lifecycle of every `xdg_toplevel`, `xdg_popup`, and `Subsurface`, its committed `wl_buffer` (wrapped in a `buffer-surface` resource), its PID/app-id, and its pending `configure` serials.
|
||||||
|
- **WM Component (`wm-policy`):** Holds pure state (workspaces/virtual desktops, tiling tree or floating geometry, MRU focus stack, window rules). On `window-opened`, `window-closed`, or `window-request` (maximize, fullscreen, interactive move/resize), the host calls `wm-policy`, which returns a list of `wm-action` commands (`set-geometry`, `focus`, `raise`, `set-state`).
|
||||||
|
- **Hot-Swap Support:** Because `WindowRegistry` lives in the host, the user can hot-swap a floating WM component for a tiling WM component at runtime; the host replays the current `list<window-state>` into the new component's `sync-windows` entrypoint.
|
||||||
|
|
||||||
|
### 2.3 Input Handling & Routing (M2 → M5)
|
||||||
|
In M0 (`host/src/desktop.mjs`), the host hardcodes hit-testing. In the compositor design:
|
||||||
|
1. **Global Grabs (Host):** Secure attention keys (e.g., `Ctrl+Alt+Fn` VT switch), global shortcut table (`shortcuts` interface), and active compositor grabs (interactive window move/resize drag) are handled first by the host.
|
||||||
|
2. **Routing (WM / Shell Component):** Remaining pointer/keyboard events are passed to the routing component (`route-input`), which inspects its stacking order, panel rects, and popup grabs, returning an `input-target`:
|
||||||
|
- `client-surface(window-id, surface-local-point)` → Host translates to `wl_pointer` / `wl_keyboard` events for that Wayland client.
|
||||||
|
- `decoration(window-id, hit-region)` → Host forwards to `decoration` component (or initiates WM move/resize).
|
||||||
|
- `plasmoid(widget-id, surface, local-point)` → Host calls `plasmoid.on-event` (existing M0 contract).
|
||||||
|
- `wm-consumed` → Event handled by WM (e.g., click-to-focus without passing through, or alt-drag).
|
||||||
|
|
||||||
|
### 2.4 Output & Backend Management
|
||||||
|
- **Nested Backend (M5):** Runs inside a `winit` window on an existing Wayland/X11 host. Outputs are virtual; resizing the `winit` window emits `output-resized` to `shell` and `wm-policy`.
|
||||||
|
- **Standalone DRM/KMS Backend (M8):** Uses `udev` for GPU/input discovery, `libseat` for unprivileged TTY/DRM master access, `drm` + `gbm` for atomic modesetting, and `libinput` for raw pointer/keyboard/touch/gesture events. Exposes an `outputs` WIT interface (mode, scale, transform, logical position) so a KScreen-like KCM component can configure multi-monitor layouts.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. WIT Interface Design (`wit/` Extensions)
|
||||||
|
|
||||||
|
Building on `moonplasma:desktop@0.1.0` (`wit/types.wit`, `wit/plasmoid.wit`, `wit/shell.wit`), the compositor introduces two new domain packages (per `docs/ARCHITECTURE.md` §7 versioning rules) while remaining compatible with `wit-bindgen moonbit` 0.63.0 (`--encoding utf16`).
|
||||||
|
|
||||||
|
### 3.1 `moonplasma:compositor/surface@0.2.0`
|
||||||
|
```wit
|
||||||
|
package moonplasma:compositor@0.2.0;
|
||||||
|
|
||||||
|
interface surface {
|
||||||
|
use moonplasma:desktop/types@0.1.0.{size, rect};
|
||||||
|
|
||||||
|
/// Unforgeable host handle to a committed client buffer (SHM or DMA-BUF).
|
||||||
|
/// Components cannot read pixels; they can only inspect metadata and
|
||||||
|
/// reference the handle in a `draw-surface` op.
|
||||||
|
resource buffer-surface {
|
||||||
|
id: func() -> u64;
|
||||||
|
size: func() -> size;
|
||||||
|
/// True if the buffer contains an alpha channel requiring blending.
|
||||||
|
has-alpha: func() -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extended render-list op for compositing foreign surfaces & cached layers.
|
||||||
|
variant composite-op {
|
||||||
|
draw(moonplasma:desktop/types@0.1.0.draw-op),
|
||||||
|
draw-surface(surface-draw),
|
||||||
|
push-opacity(u8),
|
||||||
|
pop-opacity,
|
||||||
|
}
|
||||||
|
|
||||||
|
record surface-draw {
|
||||||
|
surface: borrow<buffer-surface>,
|
||||||
|
dst: rect,
|
||||||
|
src: option<rect>,
|
||||||
|
radius: u32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2 `moonplasma:wm/policy@0.2.0`
|
||||||
|
```wit
|
||||||
|
package moonplasma:wm@0.2.0;
|
||||||
|
|
||||||
|
interface policy {
|
||||||
|
use moonplasma:desktop/types@0.1.0.{rect, size, point, input-event};
|
||||||
|
use moonplasma:compositor/surface@0.2.0.{buffer-surface, composite-op};
|
||||||
|
|
||||||
|
type window-id = u64;
|
||||||
|
|
||||||
|
flags window-caps {
|
||||||
|
can-move,
|
||||||
|
can-resize,
|
||||||
|
can-maximize,
|
||||||
|
can-minimize,
|
||||||
|
can-fullscreen,
|
||||||
|
}
|
||||||
|
|
||||||
|
record window-state {
|
||||||
|
id: window-id,
|
||||||
|
app-id: string,
|
||||||
|
title: string,
|
||||||
|
geometry: rect,
|
||||||
|
min-size: size,
|
||||||
|
max-size: option<size>,
|
||||||
|
focused: bool,
|
||||||
|
maximized: bool,
|
||||||
|
fullscreen: bool,
|
||||||
|
workspace: u32,
|
||||||
|
caps: window-caps,
|
||||||
|
}
|
||||||
|
|
||||||
|
variant wm-action {
|
||||||
|
set-geometry(tuple<window-id, rect>),
|
||||||
|
focus(window-id),
|
||||||
|
raise(window-id),
|
||||||
|
close(window-id),
|
||||||
|
set-maximized(tuple<window-id, bool>),
|
||||||
|
set-fullscreen(tuple<window-id, bool>),
|
||||||
|
}
|
||||||
|
|
||||||
|
variant input-target {
|
||||||
|
client(tuple<window-id, point>),
|
||||||
|
decoration(tuple<window-id, point>),
|
||||||
|
shell-panel(point),
|
||||||
|
none,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called on startup or WM hot-swap to synchronize existing windows.
|
||||||
|
sync-windows: func(outputs: list<rect>, windows: list<window-state>) -> list<wm-action>;
|
||||||
|
on-window-open: func(win: window-state, work-area: rect) -> list<wm-action>;
|
||||||
|
on-window-close: func(id: window-id) -> list<wm-action>;
|
||||||
|
on-pointer: func(pos: point, button: option<u32>, pressed: bool) -> input-target;
|
||||||
|
/// Returns window IDs in bottom-to-top Z-order.
|
||||||
|
stacking-order: func() -> list<window-id>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.3 Revision-Based Caching for `render`
|
||||||
|
To avoid copying unchanged `list<draw-op>` across the WASM linear-memory boundary every frame (mitigating `docs/ARCHITECTURE.md` §4a):
|
||||||
|
```wit
|
||||||
|
record render-frame {
|
||||||
|
revision: u64,
|
||||||
|
/// `none` means identical to `revision` — host reuses cached display list.
|
||||||
|
ops: option<list<draw-op>>,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
The host passes `last-known-revision: u64` into `render(size, last-rev)`. Static widgets (like a digital clock between second ticks) return `none` in O(1).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Module Breakdown & Key Data Structures
|
||||||
|
|
||||||
|
### 4.1 Native Host (`host-native/` in Rust)
|
||||||
|
```
|
||||||
|
host-native/
|
||||||
|
├── Cargo.toml
|
||||||
|
└── src/
|
||||||
|
├── main.rs # CLI, session.json bootstrap, backend selection
|
||||||
|
├── event_loop.rs # calloop integration (Wayland, input, vblank, timers)
|
||||||
|
├── wayland/
|
||||||
|
│ ├── mod.rs # Smithay State struct + delegate_*! macros
|
||||||
|
│ ├── xdg.rs # xdg_wm_base, toplevel/popup configure lifecycle
|
||||||
|
│ ├── dmabuf.rs # zwp_linux_dmabuf_v1 + EGL/wgpu import
|
||||||
|
│ └── seat.rs # wl_seat keyboard/pointer/clipboard forwarding
|
||||||
|
├── wasm/
|
||||||
|
│ ├── engine.rs # wasmtime::Engine (epoch interruption enabled)
|
||||||
|
│ ├── supervisor.rs # ComponentInstance, fault tracking, backoff restart
|
||||||
|
│ ├── broker.rs # Capability grants & WIT host trait impls
|
||||||
|
│ └── bindings.rs # wasmtime::component::bindgen! for moonplasma:*
|
||||||
|
├── scene/
|
||||||
|
│ ├── graph.rs # Layered SceneNode tree (BG -> Windows -> Panel -> Overlay)
|
||||||
|
│ ├── cache.rs # Revision-keyed compiled draw-op cache
|
||||||
|
│ └── damage.rs # Per-output dirty-region tracker
|
||||||
|
├── renderer/
|
||||||
|
│ ├── mod.rs # Renderer trait (render_scene, import_dmabuf, import_shm)
|
||||||
|
│ ├── gpu.rs # wgpu / Smithay GlowRenderer + vello/skia draw-op backend
|
||||||
|
│ └── software.rs # tiny-skia CPU fallback (CI / headless / dumb buffers)
|
||||||
|
└── backend/
|
||||||
|
├── nested.rs # winit window + EGL/software surface
|
||||||
|
└── drm.rs # udev + libseat + drm/gbm + libinput (M8)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 MoonBit Components & Pure Libraries
|
||||||
|
Following the existing `lib/*` + `components/*/gen/stub.mbt` split:
|
||||||
|
- `lib/wm/`: Pure MoonBit tiling/stacking/focus state machines (unit-tested with `moon test` using synthetic `WindowState`s, zero host dependencies).
|
||||||
|
- `lib/decoration/`: Pure MoonBit titlebar/border layout + hit-region math driven by `@theme.Tokens`.
|
||||||
|
- `components/wm-floating/` & `components/wm-tiling/`: Hot-swappable WM components implementing `moonplasma:wm/policy`.
|
||||||
|
- `components/decoration-breeze/`: Default server-side decoration component.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Event Loop & Async Model
|
||||||
|
|
||||||
|
As documented in `docs/TOOLCHAIN.md`, `moonbitlang/async` targets native/JS runtimes and is **not** WASI P3 component-model async; moreover, `jco` and `wit-bindgen-moonbit` do not yet share a uniform async ABI.
|
||||||
|
|
||||||
|
Therefore, the compositor uses a **host-driven `calloop` event loop with epoch-bounded synchronous WIT calls**:
|
||||||
|
|
||||||
|
1. **Single-Threaded `calloop` Reactor:**
|
||||||
|
- **Wayland source:** Reads client requests, processes `wl_surface.commit`, updates `WindowRegistry` and surface damage regions.
|
||||||
|
- **Input source:** `winit` events (nested) or `libinput` fd (DRM).
|
||||||
|
- **VBlank / Frame timer:** Fires on output refresh (or on-demand when dirty).
|
||||||
|
- **Component tick source:** Periodic 1 Hz / animation-rate timer that polls components for state changes (e.g., clock second rollover) without busy-spinning.
|
||||||
|
2. **Watchdog Thread (Epoch Interruption):**
|
||||||
|
- A lightweight background thread increments `wasmtime::Engine::increment_epoch()` every 1 ms.
|
||||||
|
- Before every WIT call (`wm.on_pointer`, `plasmoid.render`, `shell.compute_layout`), the host sets `store.set_epoch_deadline(4)` (4 ms budget).
|
||||||
|
- If a buggy component loops infinitely, `wasmtime` traps with `Interrupt`, the supervisor records a `ComponentFault`, and the compositor continues rendering the frame.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Scene Graph, Damage Tracking & Rendering
|
||||||
|
|
||||||
|
### 6.1 Layered Scene Graph
|
||||||
|
Each output renders a 6-layer tree evaluated bottom-to-top:
|
||||||
|
1. **`Background`**: `shell.desktop-surface.render-background(output_size)` (cached by revision).
|
||||||
|
2. **`Bottom`**: `zwlr_layer_shell_v1` bottom-layer surfaces.
|
||||||
|
3. **`Windows`**: Iterated in `wm-policy.stacking-order()` order. Each window node composes:
|
||||||
|
- Drop shadow / focus ring (`draw-op`s)
|
||||||
|
- `decoration` component `list<draw-op>` (titlebar + borders)
|
||||||
|
- `buffer-surface` (main `xdg_toplevel` surface, clipped to geometry + corner radius)
|
||||||
|
- Child `wl_subsurface`s and `xdg_popup`s
|
||||||
|
4. **`Panel`**: `shell.panel-layout.render-panel` + each `plasmoid.render` placed at its `layout.placements` rect.
|
||||||
|
5. **`Overlay`**: Active widget popups (`plasmoid.popup`), notification toasts, launcher overlay, lock screen.
|
||||||
|
6. **`Cursor`**: Hardware DRM cursor plane (when available) or software cursor `draw-op`.
|
||||||
|
|
||||||
|
### 6.2 Damage Tracking
|
||||||
|
- **Client Surface Damage:** `wl_surface.damage_buffer` regions are transformed into output-logical coordinates and unioned into `OutputDamage`.
|
||||||
|
- **Component Damage:** When a component returns `ops: some(...)` with a new `revision`, the host diffs the node's bounding box (old rect ∪ new rect) and adds it to `OutputDamage`. If `ops: none`, zero damage is emitted.
|
||||||
|
- **Scanout / Present:** The renderer clips drawing to `OutputDamage` and passes damaged rects to `eglSwapBuffersWithDamageKHR` (nested) or `DRM_MODE_PAGE_FLIP` with `FB_DAMAGE_CLIPS` (standalone).
|
||||||
|
|
||||||
|
### 6.3 Buffer Management & Rasterization
|
||||||
|
| Buffer / Op Kind | GPU Path (`GlowRenderer` / `wgpu`) | Software Fallback (`tiny-skia`) |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `wl_shm` (`ARGB8888` / `XRGB8888`) | Uploaded to cached `GlesTexture` on commit (partial upload via damage rect) | Direct zero-copy slice read in CPU memory |
|
||||||
|
| `zwp_linux_dmabuf_v1` | Imported as `EGLImage` / `wgpu::Texture` (zero-copy); **direct scanout** on fullscreen opaque windows in M8 | Not advertised in `wl_drm`/`dmabuf` globals (clients fall back to `wl_shm`) |
|
||||||
|
| `list<draw-op>` (`fill-rect`, `stroke-rect`, `line`, `circle`, `text`, `push-clip`) | Compiled to GPU path/SDF/glyph-atlas draw calls (cached per revision) | Rasterized via `tiny-skia` + `cosmic-text` / `fontdue` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Phased Implementation Roadmap
|
||||||
|
|
||||||
|
Aligned directly with `docs/ARCHITECTURE.md` §11 (M3–M8):
|
||||||
|
|
||||||
|
| Phase | Milestone | Deliverable | Verification Gate |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| **Phase 1** | **M3** | **Native Reference Host** (`host-native/` with `wasmtime` + `winit` + `tiny-skia`, fuel/epoch limits, supervisor). | Runs existing M0 components (`shell`, `launcher`, `clock-*`) and passes the same integration tests as `host/test/desktop.test.mjs`. |
|
||||||
|
| **Phase 2** | **M4** | **WM World & Synthetic Windows** (`moonplasma:wm/policy`, `decoration`, input routing in `wm`/`shell`). | Pure MoonBit `lib/wm` tests (`moon test`); hot-swap floating ↔ tiling WM on synthetic windows in both JS and Rust hosts. |
|
||||||
|
| **Phase 3** | **M5** | **Nested Wayland Compositor** (`smithay` `wl_shm` + `xdg_wm_base`, `buffer-surface` WIT resource, `composite-op`). | Launch real Wayland clients (`foot`, `weston-terminal`, `firefox`) inside nested `moon-plasma` window; verify focus, resize, popups, and fault isolation. |
|
||||||
|
| **Phase 4** | **M6–M7** | **GPU Rasterizer, DMA-BUF & Desktop Bridges** (`zwp_linux_dmabuf_v1`, damage-clipped GPU rendering, XWayland, `text` shaping interface, clipboard/D-Bus notification/tray bridges). | Hardware-accelerated video/WebGL clients at 60+ fps with zero-copy DMA-BUF; partial-damage redraws verified. |
|
||||||
|
| **Phase 5** | **M8** | **Standalone DRM/KMS Session** (`udev`, `libseat`, `drm`/`gbm`, `libinput`, `outputs` WIT interface, direct scanout, `login` world). | Boot directly from TTY into `moon-plasma`; multi-monitor hotplug and fullscreen direct scanout. |
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. Window Manager (WM) Architecture
|
||||||
|
|
||||||
|
In `moon-plasma`, the **Window Manager is a pure policy component** (`world window-manager`) written in MoonBit, completely decoupled from Wayland wire serialization and GPU/DRM state. Because the host owns `WindowRegistry` and `SeatState`, the entire WM can be **hot-swapped at runtime** (e.g., `wm-floating` ↔ `wm-tiling`) without closing any running Wayland applications.
|
||||||
|
|
||||||
|
### 8.1 Integration with the Compositor & Wayland Protocols
|
||||||
|
The host translates Wayland protocol events into typed `moonplasma:wm` calls and applies the returned `list<wm-action>` back to Smithay:
|
||||||
|
|
||||||
|
| Wayland / Shell Event | Host (`smithay`) Action | WM (`wm-policy`) Role |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `xdg_toplevel` first commit (mapped) | Creates `WindowId`, reads `app_id`, `title`, `min/max_size`, `parent` | `on-window-open(win, work_area)` → assigns workspace/output, computes initial geometry, sets focus |
|
||||||
|
| `xdg_toplevel` `set_maximized` / `set_fullscreen` / `move` / `resize` | Forwards request to WM | `on-window-request(id, req)` → approves/denies, updates state, emits `set-geometry` + `configure` |
|
||||||
|
| `xdg_popup` creation & grab | Host tracks `xdg_popup` parent chain & Wayland popup grab | WM stays unaware of transient popups; host clips/places them relative to parent window |
|
||||||
|
| `zwlr_layer_shell_v1` / `shell.panel-layout` | Host computes reserved `exclusive_zone`s per output | Host passes `work_area: rect` (output minus panels/layer-shell margins) to WM |
|
||||||
|
| `xdg_toplevel` unmap / destroy | Removes from `WindowRegistry` | `on-window-close(id)` → reflows tiling tree, promotes next MRU window to focus |
|
||||||
|
|
||||||
|
### 8.2 Hybrid Layout Engine (Tiling + Floating + Monocle)
|
||||||
|
The reference WM (`lib/wm/`) implements a **per-workspace hybrid layout engine** so a single component supports both KDE-style floating windows and Sway/Hyprland-style tiling:
|
||||||
|
|
||||||
|
```
|
||||||
|
Workspace
|
||||||
|
├── layout_mode: Tiling(BinarySpacePartition) | Floating | Monocle
|
||||||
|
├── tiled_tree: Option[BspNode] // Split(Horizontal|Vertical, ratio, left, right) | Leaf(WindowId)
|
||||||
|
├── floating: Array[WindowId] // Ordered bottom-to-top; always rendered above tiled_tree
|
||||||
|
└── fullscreen: Option[WindowId] // Overrides output work_area; hides panel/decorations
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Work Area Computation:** For each `Output`, `work_area = output.logical_rect - panel_exclusive_zones`. Tiled windows fill `work_area` with configurable `inner_gap` and `outer_gap` (read from `theme.tokens.spacing`).
|
||||||
|
- **Window Rules (`app_id` / `title` matching):** Evaluated in `on-window-open` before layout insertion:
|
||||||
|
- Dialogs (`parent != None` or `min_size == max_size`) automatically enter `floating` and center over their parent.
|
||||||
|
- User rules (from `config-store`) can pin an `app_id` to a specific workspace, force floating, or disable decorations.
|
||||||
|
- **Interactive Move & Resize State Machine:**
|
||||||
|
- Triggered by `decoration` hit-test (`TitlebarDrag`, `ResizeEdge(N|S|E|W|NE|...)`) or `Mod + Left/Right Drag`.
|
||||||
|
- Host enters an active pointer grab (`DragSession { win_id, mode, start_ptr, start_rect }`) and streams delta updates to `wm.on-drag(delta)` at pointer rate, throttling `xdg_toplevel.configure` to once per VBlank.
|
||||||
|
|
||||||
|
### 8.3 Focus, Seat & Stacking Management
|
||||||
|
- **Focus Policy (Configurable):** `ClickToFocus` (default) or `FocusFollowsMouse` (sloppy focus).
|
||||||
|
- **MRU Focus Stack:** Each workspace maintains an MRU `Array[WindowId]`. Closing or minimizing the focused window automatically focuses `mru[0]`.
|
||||||
|
- **Seat Integration:** When `wm-policy` emits `wm-action::focus(id)`, the host:
|
||||||
|
1. Sends `wl_keyboard.leave` to the previous surface and `wl_keyboard.enter` to the new `wl_surface`.
|
||||||
|
2. Updates `window-state.focused` and triggers a `decoration` redraw (active vs. inactive titlebar colors).
|
||||||
|
3. Notifies the `task-manager` plasmoid via `window-list-changed`.
|
||||||
|
- **Z-Order (`stacking-order()`):** Strictly layered bottom-to-top:
|
||||||
|
`TiledWindows` → `FloatingWindows` (MRU order) → `AlwaysOnTop / PictureInPicture` → `Fullscreen`.
|
||||||
|
|
||||||
|
### 8.4 Decorations (SSD vs. CSD via `zxdg_decoration_manager_v1`)
|
||||||
|
- **Negotiation:** On `xdg_toplevel` creation, the host advertises `zxdg_decoration_manager_v1` with default mode `ServerSide`.
|
||||||
|
- Clients that accept SSD (most Qt/GTK/terminal apps) omit client shadows/titlebars; the host invokes the `decoration` MoonBit component.
|
||||||
|
- Clients that insist on CSD (e.g., GTK4/libadwaita apps requesting `ClientSide`) are honored and wrapped in a minimal `0px` decoration node (only focus ring if configured).
|
||||||
|
- **`moonplasma:wm/decoration@0.2.0` Interface:**
|
||||||
|
```wit
|
||||||
|
interface decoration {
|
||||||
|
use moonplasma:desktop/types@0.1.0.{rect, size, draw-op};
|
||||||
|
use policy.{window-state};
|
||||||
|
|
||||||
|
enum hit-role { none, titlebar, close, maximize, minimize, resize-n, resize-s, resize-e, resize-w, resize-nw, resize-ne, resize-sw, resize-se }
|
||||||
|
|
||||||
|
record hit-region { rect: rect, role: hit-role }
|
||||||
|
|
||||||
|
record decoration-frame {
|
||||||
|
/// Insets reserved around the client surface: (top, right, bottom, left)
|
||||||
|
insets: tuple<u32, u32, u32, u32>,
|
||||||
|
ops: list<draw-op>,
|
||||||
|
hit-regions: list<hit-region>,
|
||||||
|
}
|
||||||
|
|
||||||
|
render: func(win: window-state, outer-size: size) -> decoration-frame;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.5 Keybindings & IPC for Panels, Taskbars & Launchers
|
||||||
|
- **Global Shortcuts (`shortcuts` WIT capability):**
|
||||||
|
- On startup, `wm-policy` registers bindings (e.g., `Super+Return` → launch terminal, `Super+Q` → close focused, `Super+1..9` → switch workspace, `Super+Space` → toggle floating/tiled, `Alt+Tab` → cycle MRU).
|
||||||
|
- The host matches raw `xkbcommon` keysyms + modifiers in the input hot-path *before* forwarding to the focused Wayland client, invoking `wm.on-action(action_id)` on match.
|
||||||
|
- **Host-Mediated Shell/Taskbar IPC (`window-registry` read-only grant):**
|
||||||
|
- Instead of an ad-hoc UNIX socket protocol (`plasma-shell` / `hyprctl`), `moon-plasma` panels, taskbars, and pager plasmoids import a **capability-attenuated `window-registry` WIT interface**:
|
||||||
|
- `list-windows() -> list<window-summary>` (id, title, app-id, workspace, focused, minimized — *never* raw buffers or input).
|
||||||
|
- `activate(id)` / `minimize(id)` / `close(id)` → routed by the host to `wm-policy.on-window-request(...)`.
|
||||||
|
- A `task-manager` plasmoid on the panel can thus render live window buttons, show urgent badges, and switch focus using the exact same `plasmoid` + `draw-op` model as `clock-digital` and `launcher`.
|
||||||
|
|
||||||
|
### 8.6 MoonBit Data Structures (`lib/wm/wm.mbt`)
|
||||||
|
```moonbit
|
||||||
|
pub enum LayoutMode {
|
||||||
|
Floating
|
||||||
|
Tiling
|
||||||
|
Monocle
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum BspNode {
|
||||||
|
Leaf(UInt64) // WindowId
|
||||||
|
Split(horizontal~ : Bool, ratio~ : Double, left~ : BspNode, right~ : BspNode)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Workspace {
|
||||||
|
id : UInt
|
||||||
|
mode : LayoutMode
|
||||||
|
mut tree : BspNode?
|
||||||
|
floating : Array[UInt64]
|
||||||
|
mru : Array[UInt64]
|
||||||
|
mut fullscreen : UInt64?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WmState {
|
||||||
|
outputs : Array[OutputInfo]
|
||||||
|
workspaces : Array[Workspace]
|
||||||
|
windows : Map[UInt64, WindowRecord]
|
||||||
|
mut active_workspace : UInt
|
||||||
|
mut focused : UInt64?
|
||||||
|
}
|
||||||
|
```
|
||||||
|
All layout math (`compute_bsp_rects`, `insert_leaf`, `remove_leaf`, `focus_direction`, `hit_test_stack`) lives in `lib/wm/` as pure functions over `WmState`, unit-tested via `moon test` before any Rust host integration.
|
||||||
Generated
+2012
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,23 @@
|
|||||||
|
[package]
|
||||||
|
name = "moon-plasma-host"
|
||||||
|
version = "0.2.0"
|
||||||
|
edition = "2021"
|
||||||
|
description = "Native Rust Wayland compositor & wasmtime host for moon-plasma"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
|
chrono = "0.4"
|
||||||
|
fontdue = "0.9"
|
||||||
|
memmap2 = "0.9"
|
||||||
|
png = "0.17"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
tiny-skia = "0.11"
|
||||||
|
wasmtime = { version = "51.0", features = ["component-model"] }
|
||||||
|
wayland-server = "0.31"
|
||||||
|
wayland-protocols = { version = "0.32", features = ["server", "staging", "unstable"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = "3.14"
|
||||||
|
wayland-client = "0.31"
|
||||||
|
wayland-protocols = { version = "0.32", features = ["client", "server", "staging", "unstable"] }
|
||||||
@@ -0,0 +1,516 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use tiny_skia::Pixmap;
|
||||||
|
|
||||||
|
use crate::renderer::SoftwareRenderer;
|
||||||
|
use crate::scene::{
|
||||||
|
DamageTracker, DrawOp, PanelWidgetNode, Rect, SceneGraph, ShmBufferSnapshot, TextAlign,
|
||||||
|
WindowSceneNode,
|
||||||
|
};
|
||||||
|
use crate::theme::{Rgba, ThemeTokens};
|
||||||
|
use crate::wasm::{clock_wit, deco_wit, desktop_wit, launcher_wit, wm_wit, WasmSupervisor};
|
||||||
|
use crate::wayland::{WaylandEvent, WaylandServer};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct HostWindow {
|
||||||
|
pub id: u64,
|
||||||
|
pub app_id: String,
|
||||||
|
pub title: String,
|
||||||
|
pub geometry: Rect,
|
||||||
|
pub min_size: (u32, u32),
|
||||||
|
pub max_size: Option<(u32, u32)>,
|
||||||
|
pub focused: bool,
|
||||||
|
pub maximized: bool,
|
||||||
|
pub fullscreen: bool,
|
||||||
|
pub workspace: u32,
|
||||||
|
pub surface: Option<ShmBufferSnapshot>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MoonPlasmaCompositor {
|
||||||
|
pub output_size: (u32, u32),
|
||||||
|
pub wayland: WaylandServer,
|
||||||
|
pub wasm: WasmSupervisor,
|
||||||
|
pub renderer: SoftwareRenderer,
|
||||||
|
pub damage: DamageTracker,
|
||||||
|
pub windows: HashMap<u64, HostWindow>,
|
||||||
|
pub panel_rect: Rect,
|
||||||
|
pub work_area: Rect,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MoonPlasmaCompositor {
|
||||||
|
pub fn new(
|
||||||
|
socket_path: &Path,
|
||||||
|
components_dir: &Path,
|
||||||
|
theme: ThemeTokens,
|
||||||
|
output_w: u32,
|
||||||
|
output_h: u32,
|
||||||
|
) -> anyhow::Result<Self> {
|
||||||
|
let wayland = WaylandServer::bind(socket_path, output_w, output_h)?;
|
||||||
|
let wasm = WasmSupervisor::load_from_dir(components_dir, theme)?;
|
||||||
|
let renderer = SoftwareRenderer::new();
|
||||||
|
let mut damage = DamageTracker::default();
|
||||||
|
damage.mark_full();
|
||||||
|
|
||||||
|
let panel_h = 44;
|
||||||
|
let panel_rect = Rect::new(0, (output_h - panel_h) as i32, output_w, panel_h);
|
||||||
|
let work_area = Rect::new(0, 0, output_w, output_h - panel_h);
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
output_size: (output_w, output_h),
|
||||||
|
wayland,
|
||||||
|
wasm,
|
||||||
|
renderer,
|
||||||
|
damage,
|
||||||
|
windows: HashMap::new(),
|
||||||
|
panel_rect,
|
||||||
|
work_area,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn step(&mut self) -> anyhow::Result<()> {
|
||||||
|
self.wayland.dispatch()?;
|
||||||
|
let events: Vec<WaylandEvent> = self.wayland.state.events.drain(..).collect();
|
||||||
|
for evt in events {
|
||||||
|
match evt {
|
||||||
|
WaylandEvent::ToplevelOpened {
|
||||||
|
window_id,
|
||||||
|
app_id,
|
||||||
|
title,
|
||||||
|
min_w,
|
||||||
|
min_h,
|
||||||
|
max_w,
|
||||||
|
max_h,
|
||||||
|
} => {
|
||||||
|
let hw = HostWindow {
|
||||||
|
id: window_id,
|
||||||
|
app_id: app_id.clone(),
|
||||||
|
title: title.clone(),
|
||||||
|
geometry: Rect::new(0, 0, 0, 0),
|
||||||
|
min_size: (min_w, min_h),
|
||||||
|
max_size: max_w.zip(max_h),
|
||||||
|
focused: true,
|
||||||
|
maximized: false,
|
||||||
|
fullscreen: false,
|
||||||
|
workspace: 0,
|
||||||
|
surface: None,
|
||||||
|
};
|
||||||
|
self.windows.insert(window_id, hw.clone());
|
||||||
|
let wit_win = to_wm_window(&hw);
|
||||||
|
let wa = to_wm_rect(self.work_area);
|
||||||
|
self.wasm.wm_store.set_epoch_deadline(20);
|
||||||
|
match self
|
||||||
|
.wasm
|
||||||
|
.wm
|
||||||
|
.moonplasma_wm_policy()
|
||||||
|
.call_on_window_open(&mut self.wasm.wm_store, &wit_win, wa)
|
||||||
|
{
|
||||||
|
Ok(actions) => self.apply_wm_actions(&actions),
|
||||||
|
Err(e) => self.wasm.record_fault("wm-hybrid", "on_window_open", e),
|
||||||
|
}
|
||||||
|
self.damage.mark_full();
|
||||||
|
}
|
||||||
|
WaylandEvent::ToplevelClosed { window_id } => {
|
||||||
|
self.windows.remove(&window_id);
|
||||||
|
self.wasm.wm_store.set_epoch_deadline(20);
|
||||||
|
match self
|
||||||
|
.wasm
|
||||||
|
.wm
|
||||||
|
.moonplasma_wm_policy()
|
||||||
|
.call_on_window_close(&mut self.wasm.wm_store, window_id)
|
||||||
|
{
|
||||||
|
Ok(actions) => self.apply_wm_actions(&actions),
|
||||||
|
Err(e) => self.wasm.record_fault("wm-hybrid", "on_window_close", e),
|
||||||
|
}
|
||||||
|
self.damage.mark_full();
|
||||||
|
}
|
||||||
|
WaylandEvent::SurfaceCommitted { window_id, buffer } => {
|
||||||
|
if let Some(hw) = self.windows.get_mut(&window_id) {
|
||||||
|
hw.surface = buffer;
|
||||||
|
self.damage.add_rect(hw.geometry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WaylandEvent::ToplevelRequest {
|
||||||
|
window_id,
|
||||||
|
maximize,
|
||||||
|
fullscreen,
|
||||||
|
} => {
|
||||||
|
let req = if let Some(m) = maximize {
|
||||||
|
Some(wm_wit::exports::moonplasma::wm::policy::WindowRequest::Maximize(m))
|
||||||
|
} else {
|
||||||
|
fullscreen.map(wm_wit::exports::moonplasma::wm::policy::WindowRequest::Fullscreen)
|
||||||
|
};
|
||||||
|
if let Some(r) = req {
|
||||||
|
let wa = to_wm_rect(self.work_area);
|
||||||
|
self.wasm.wm_store.set_epoch_deadline(20);
|
||||||
|
match self.wasm.wm.moonplasma_wm_policy().call_on_window_request(
|
||||||
|
&mut self.wasm.wm_store,
|
||||||
|
window_id,
|
||||||
|
r,
|
||||||
|
wa,
|
||||||
|
) {
|
||||||
|
Ok(actions) => self.apply_wm_actions(&actions),
|
||||||
|
Err(e) => self.wasm.record_fault("wm-hybrid", "on_window_request", e),
|
||||||
|
}
|
||||||
|
self.damage.mark_full();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_layout_mode(&mut self, mode: wm_wit::exports::moonplasma::wm::policy::LayoutMode) {
|
||||||
|
let wa = to_wm_rect(self.work_area);
|
||||||
|
self.wasm.wm_store.set_epoch_deadline(20);
|
||||||
|
match self.wasm.wm.moonplasma_wm_policy().call_set_layout_mode(
|
||||||
|
&mut self.wasm.wm_store,
|
||||||
|
mode,
|
||||||
|
wa,
|
||||||
|
) {
|
||||||
|
Ok(actions) => self.apply_wm_actions(&actions),
|
||||||
|
Err(e) => self.wasm.record_fault("wm-hybrid", "set_layout_mode", e),
|
||||||
|
}
|
||||||
|
self.damage.mark_full();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_wm_actions(&mut self, actions: &[wm_wit::exports::moonplasma::wm::policy::WmAction]) {
|
||||||
|
use wm_wit::exports::moonplasma::wm::policy::WmAction;
|
||||||
|
for action in actions {
|
||||||
|
match action {
|
||||||
|
WmAction::SetGeometry((id, r)) => {
|
||||||
|
let rect = Rect::new(r.x, r.y, r.w, r.h);
|
||||||
|
let mut focused = false;
|
||||||
|
if let Some(hw) = self.windows.get_mut(id) {
|
||||||
|
hw.geometry = rect;
|
||||||
|
focused = hw.focused;
|
||||||
|
}
|
||||||
|
self.wayland
|
||||||
|
.state
|
||||||
|
.configure_toplevel(*id, r.w, r.h, focused);
|
||||||
|
}
|
||||||
|
WmAction::Focus(id) => {
|
||||||
|
for (wid, hw) in self.windows.iter_mut() {
|
||||||
|
hw.focused = *wid == *id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WmAction::Close(id) => {
|
||||||
|
self.wayland.state.close_toplevel(*id);
|
||||||
|
}
|
||||||
|
WmAction::SetMaximized((id, m)) => {
|
||||||
|
if let Some(hw) = self.windows.get_mut(id) {
|
||||||
|
hw.maximized = *m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WmAction::SetFullscreen((id, fs)) => {
|
||||||
|
if let Some(hw) = self.windows.get_mut(id) {
|
||||||
|
hw.fullscreen = *fs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WmAction::Raise(_) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compose_frame(&mut self) -> anyhow::Result<Pixmap> {
|
||||||
|
let (sw, sh) = self.output_size;
|
||||||
|
let screen_desktop = desktop_wit::moonplasma::desktop::types::Size { w: sw, h: sh };
|
||||||
|
let mut scene = SceneGraph::new(sw, sh);
|
||||||
|
|
||||||
|
// 1. Background
|
||||||
|
self.wasm.shell_store.set_epoch_deadline(20);
|
||||||
|
match self
|
||||||
|
.wasm
|
||||||
|
.shell
|
||||||
|
.moonplasma_desktop_desktop_surface()
|
||||||
|
.call_render_background(&mut self.wasm.shell_store, screen_desktop)
|
||||||
|
{
|
||||||
|
Ok(ops) => scene.background_ops = ops.into_iter().map(from_desktop_op).collect(),
|
||||||
|
Err(e) => self.wasm.record_fault("shell", "render_background", e),
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Panel layout + widgets
|
||||||
|
self.wasm.launcher_store.set_epoch_deadline(20);
|
||||||
|
let launcher_info = self
|
||||||
|
.wasm
|
||||||
|
.launcher
|
||||||
|
.moonplasma_desktop_plasmoid()
|
||||||
|
.call_info(&mut self.wasm.launcher_store)?;
|
||||||
|
self.wasm.clock_store.set_epoch_deadline(20);
|
||||||
|
let clock_info = self
|
||||||
|
.wasm
|
||||||
|
.clock
|
||||||
|
.moonplasma_desktop_plasmoid()
|
||||||
|
.call_info(&mut self.wasm.clock_store)?;
|
||||||
|
|
||||||
|
let slots = vec![
|
||||||
|
desktop_wit::exports::moonplasma::desktop::panel_layout::Slot {
|
||||||
|
id: "launcher".into(),
|
||||||
|
preferred: desktop_wit::moonplasma::desktop::types::Size {
|
||||||
|
w: launcher_info.preferred.w,
|
||||||
|
h: launcher_info.preferred.h,
|
||||||
|
},
|
||||||
|
min_width: launcher_info.min_width,
|
||||||
|
stretch: launcher_info.stretch,
|
||||||
|
align: desktop_wit::exports::moonplasma::desktop::panel_layout::Edge::Start,
|
||||||
|
},
|
||||||
|
desktop_wit::exports::moonplasma::desktop::panel_layout::Slot {
|
||||||
|
id: "clock".into(),
|
||||||
|
preferred: desktop_wit::moonplasma::desktop::types::Size {
|
||||||
|
w: clock_info.preferred.w,
|
||||||
|
h: clock_info.preferred.h,
|
||||||
|
},
|
||||||
|
min_width: clock_info.min_width,
|
||||||
|
stretch: clock_info.stretch,
|
||||||
|
align: desktop_wit::exports::moonplasma::desktop::panel_layout::Edge::End,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
self.wasm.shell_store.set_epoch_deadline(20);
|
||||||
|
let layout = self
|
||||||
|
.wasm
|
||||||
|
.shell
|
||||||
|
.moonplasma_desktop_panel_layout()
|
||||||
|
.call_compute_layout(&mut self.wasm.shell_store, screen_desktop, &slots)?;
|
||||||
|
|
||||||
|
let panel_rect = Rect::new(layout.panel.x, layout.panel.y, layout.panel.w, layout.panel.h);
|
||||||
|
scene.panel_rect = panel_rect;
|
||||||
|
self.panel_rect = panel_rect;
|
||||||
|
self.work_area = Rect::new(0, 0, sw, (layout.panel.y.max(0)) as u32);
|
||||||
|
|
||||||
|
self.wasm.shell_store.set_epoch_deadline(20);
|
||||||
|
let panel_ops = self
|
||||||
|
.wasm
|
||||||
|
.shell
|
||||||
|
.moonplasma_desktop_panel_layout()
|
||||||
|
.call_render_panel(&mut self.wasm.shell_store, screen_desktop, layout.panel)?;
|
||||||
|
scene.panel_ops = panel_ops.into_iter().map(from_desktop_op).collect();
|
||||||
|
|
||||||
|
for placement in &layout.placements {
|
||||||
|
let r = Rect::new(placement.rect.x, placement.rect.y, placement.rect.w, placement.rect.h);
|
||||||
|
match placement.id.as_str() {
|
||||||
|
"launcher" => {
|
||||||
|
self.wasm.launcher_store.set_epoch_deadline(20);
|
||||||
|
let ops = self
|
||||||
|
.wasm
|
||||||
|
.launcher
|
||||||
|
.moonplasma_desktop_plasmoid()
|
||||||
|
.call_render(
|
||||||
|
&mut self.wasm.launcher_store,
|
||||||
|
launcher_wit::moonplasma::desktop::types::Size { w: r.w, h: r.h },
|
||||||
|
)?;
|
||||||
|
scene.widgets.push(PanelWidgetNode {
|
||||||
|
id: placement.id.clone(),
|
||||||
|
rect: r,
|
||||||
|
ops: ops.into_iter().map(from_launcher_op).collect(),
|
||||||
|
popup: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"clock" => {
|
||||||
|
self.wasm.clock_store.set_epoch_deadline(20);
|
||||||
|
let ops = self
|
||||||
|
.wasm
|
||||||
|
.clock
|
||||||
|
.moonplasma_desktop_plasmoid()
|
||||||
|
.call_render(
|
||||||
|
&mut self.wasm.clock_store,
|
||||||
|
clock_wit::moonplasma::desktop::types::Size { w: r.w, h: r.h },
|
||||||
|
)?;
|
||||||
|
scene.widgets.push(PanelWidgetNode {
|
||||||
|
id: placement.id.clone(),
|
||||||
|
rect: r,
|
||||||
|
ops: ops.into_iter().map(from_clock_op).collect(),
|
||||||
|
popup: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Windows in WM stacking order + decoration-breeze
|
||||||
|
self.wasm.wm_store.set_epoch_deadline(20);
|
||||||
|
let order = self
|
||||||
|
.wasm
|
||||||
|
.wm
|
||||||
|
.moonplasma_wm_policy()
|
||||||
|
.call_stacking_order(&mut self.wasm.wm_store)
|
||||||
|
.unwrap_or_else(|_| self.windows.keys().copied().collect());
|
||||||
|
|
||||||
|
for wid in order {
|
||||||
|
if let Some(hw) = self.windows.get(&wid) {
|
||||||
|
let outer_size = deco_wit::moonplasma::desktop::types::Size {
|
||||||
|
w: hw.geometry.w + 4,
|
||||||
|
h: hw.geometry.h + 34,
|
||||||
|
};
|
||||||
|
let deco_win = to_deco_window(hw);
|
||||||
|
self.wasm.deco_store.set_epoch_deadline(20);
|
||||||
|
let (insets, deco_ops) = match self
|
||||||
|
.wasm
|
||||||
|
.deco
|
||||||
|
.moonplasma_wm_decoration()
|
||||||
|
.call_render(&mut self.wasm.deco_store, &deco_win, outer_size)
|
||||||
|
{
|
||||||
|
Ok(frame) => (
|
||||||
|
frame.insets,
|
||||||
|
frame.ops.into_iter().map(from_deco_op).collect(),
|
||||||
|
),
|
||||||
|
Err(e) => {
|
||||||
|
self.wasm.record_fault("decoration-breeze", "render", e);
|
||||||
|
((32, 2, 2, 2), Vec::new())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
scene.windows.push(WindowSceneNode {
|
||||||
|
id: hw.id,
|
||||||
|
title: hw.title.clone(),
|
||||||
|
app_id: hw.app_id.clone(),
|
||||||
|
focused: hw.focused,
|
||||||
|
fullscreen: hw.fullscreen,
|
||||||
|
geometry: hw.geometry,
|
||||||
|
deco_insets: insets,
|
||||||
|
deco_ops,
|
||||||
|
surface: hw.surface.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pixmap = self.renderer.render_scene(&scene)?;
|
||||||
|
self.wayland.state.flush_frame_callbacks(0);
|
||||||
|
self.wayland.display.flush_clients()?;
|
||||||
|
self.damage.clear();
|
||||||
|
Ok(pixmap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_wm_rect(r: Rect) -> wm_wit::moonplasma::desktop::types::Rect {
|
||||||
|
wm_wit::moonplasma::desktop::types::Rect {
|
||||||
|
x: r.x,
|
||||||
|
y: r.y,
|
||||||
|
w: r.w,
|
||||||
|
h: r.h,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_wm_window(hw: &HostWindow) -> wm_wit::exports::moonplasma::wm::policy::WindowState {
|
||||||
|
use wm_wit::exports::moonplasma::wm::policy::WindowCaps;
|
||||||
|
wm_wit::exports::moonplasma::wm::policy::WindowState {
|
||||||
|
id: hw.id,
|
||||||
|
app_id: hw.app_id.clone(),
|
||||||
|
title: hw.title.clone(),
|
||||||
|
geometry: to_wm_rect(hw.geometry),
|
||||||
|
min_size: wm_wit::moonplasma::desktop::types::Size {
|
||||||
|
w: hw.min_size.0,
|
||||||
|
h: hw.min_size.1,
|
||||||
|
},
|
||||||
|
max_size: hw
|
||||||
|
.max_size
|
||||||
|
.map(|(w, h)| wm_wit::moonplasma::desktop::types::Size { w, h }),
|
||||||
|
focused: hw.focused,
|
||||||
|
maximized: hw.maximized,
|
||||||
|
fullscreen: hw.fullscreen,
|
||||||
|
workspace: hw.workspace,
|
||||||
|
caps: WindowCaps::CAN_MOVE
|
||||||
|
| WindowCaps::CAN_RESIZE
|
||||||
|
| WindowCaps::CAN_MAXIMIZE
|
||||||
|
| WindowCaps::CAN_MINIMIZE
|
||||||
|
| WindowCaps::CAN_FULLSCREEN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_deco_window(hw: &HostWindow) -> deco_wit::moonplasma::wm::policy::WindowState {
|
||||||
|
use deco_wit::moonplasma::wm::policy::WindowCaps;
|
||||||
|
deco_wit::moonplasma::wm::policy::WindowState {
|
||||||
|
id: hw.id,
|
||||||
|
app_id: hw.app_id.clone(),
|
||||||
|
title: hw.title.clone(),
|
||||||
|
geometry: deco_wit::moonplasma::desktop::types::Rect {
|
||||||
|
x: hw.geometry.x,
|
||||||
|
y: hw.geometry.y,
|
||||||
|
w: hw.geometry.w,
|
||||||
|
h: hw.geometry.h,
|
||||||
|
},
|
||||||
|
min_size: deco_wit::moonplasma::desktop::types::Size {
|
||||||
|
w: hw.min_size.0,
|
||||||
|
h: hw.min_size.1,
|
||||||
|
},
|
||||||
|
max_size: hw
|
||||||
|
.max_size
|
||||||
|
.map(|(w, h)| deco_wit::moonplasma::desktop::types::Size { w, h }),
|
||||||
|
focused: hw.focused,
|
||||||
|
maximized: hw.maximized,
|
||||||
|
fullscreen: hw.fullscreen,
|
||||||
|
workspace: hw.workspace,
|
||||||
|
caps: WindowCaps::CAN_MOVE
|
||||||
|
| WindowCaps::CAN_RESIZE
|
||||||
|
| WindowCaps::CAN_MAXIMIZE
|
||||||
|
| WindowCaps::CAN_MINIMIZE
|
||||||
|
| WindowCaps::CAN_FULLSCREEN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! impl_from_op {
|
||||||
|
($fn_name:ident, $mod_path:ident) => {
|
||||||
|
fn $fn_name(op: $mod_path::moonplasma::desktop::types::DrawOp) -> DrawOp {
|
||||||
|
use $mod_path::moonplasma::desktop::types::{DrawOp as WOp, TextAlign as WAlign};
|
||||||
|
let cvt_color = |c: $mod_path::moonplasma::desktop::types::Color| Rgba {
|
||||||
|
r: c.r,
|
||||||
|
g: c.g,
|
||||||
|
b: c.b,
|
||||||
|
a: c.a,
|
||||||
|
};
|
||||||
|
let cvt_rect = |r: $mod_path::moonplasma::desktop::types::Rect| Rect {
|
||||||
|
x: r.x,
|
||||||
|
y: r.y,
|
||||||
|
w: r.w,
|
||||||
|
h: r.h,
|
||||||
|
};
|
||||||
|
match op {
|
||||||
|
WOp::FillRect(o) => DrawOp::FillRect {
|
||||||
|
rect: cvt_rect(o.rect),
|
||||||
|
color: cvt_color(o.color),
|
||||||
|
radius: o.radius,
|
||||||
|
},
|
||||||
|
WOp::StrokeRect(o) => DrawOp::StrokeRect {
|
||||||
|
rect: cvt_rect(o.rect),
|
||||||
|
color: cvt_color(o.color),
|
||||||
|
width: o.width,
|
||||||
|
radius: o.radius,
|
||||||
|
},
|
||||||
|
WOp::Line(o) => DrawOp::Line {
|
||||||
|
x0: o.start.x,
|
||||||
|
y0: o.start.y,
|
||||||
|
x1: o.end.x,
|
||||||
|
y1: o.end.y,
|
||||||
|
color: cvt_color(o.color),
|
||||||
|
width: o.width,
|
||||||
|
},
|
||||||
|
WOp::Circle(o) => DrawOp::Circle {
|
||||||
|
cx: o.center.x,
|
||||||
|
cy: o.center.y,
|
||||||
|
radius: o.radius,
|
||||||
|
color: cvt_color(o.color),
|
||||||
|
filled: o.filled,
|
||||||
|
},
|
||||||
|
WOp::Text(o) => DrawOp::Text {
|
||||||
|
x: o.origin.x,
|
||||||
|
y: o.origin.y,
|
||||||
|
text: o.text,
|
||||||
|
size: o.style.size,
|
||||||
|
color: cvt_color(o.style.color),
|
||||||
|
align: match o.style.align {
|
||||||
|
WAlign::Left => TextAlign::Left,
|
||||||
|
WAlign::Center => TextAlign::Center,
|
||||||
|
WAlign::Right => TextAlign::Right,
|
||||||
|
},
|
||||||
|
bold: o.style.bold,
|
||||||
|
},
|
||||||
|
WOp::PushClip(r) => DrawOp::PushClip(cvt_rect(r)),
|
||||||
|
WOp::PopClip => DrawOp::PopClip,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_from_op!(from_desktop_op, desktop_wit);
|
||||||
|
impl_from_op!(from_launcher_op, launcher_wit);
|
||||||
|
impl_from_op!(from_clock_op, clock_wit);
|
||||||
|
impl_from_op!(from_deco_op, deco_wit);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
pub mod compositor;
|
||||||
|
pub mod renderer;
|
||||||
|
pub mod scene;
|
||||||
|
pub mod theme;
|
||||||
|
pub mod wasm;
|
||||||
|
pub mod wayland;
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use moon_plasma_host::compositor::MoonPlasmaCompositor;
|
||||||
|
use moon_plasma_host::renderer::SoftwareRenderer;
|
||||||
|
use moon_plasma_host::theme::ThemeTokens;
|
||||||
|
|
||||||
|
fn main() -> anyhow::Result<()> {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
let mut out_path = PathBuf::from("frame.png");
|
||||||
|
let mut socket_path = PathBuf::from("/tmp/moon-plasma-wayland-0");
|
||||||
|
let mut components_dir = PathBuf::from("../build/components");
|
||||||
|
let mut theme_path = PathBuf::from("../config/themes/moon-night.json");
|
||||||
|
|
||||||
|
let mut i = 1;
|
||||||
|
while i < args.len() {
|
||||||
|
match args[i].as_str() {
|
||||||
|
"--out" if i + 1 < args.len() => {
|
||||||
|
out_path = PathBuf::from(&args[i + 1]);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
"--socket" if i + 1 < args.len() => {
|
||||||
|
socket_path = PathBuf::from(&args[i + 1]);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
"--components" if i + 1 < args.len() => {
|
||||||
|
components_dir = PathBuf::from(&args[i + 1]);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
"--theme" if i + 1 < args.len() => {
|
||||||
|
theme_path = PathBuf::from(&args[i + 1]);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
_ => i += 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let theme = if theme_path.exists() {
|
||||||
|
ThemeTokens::load_file(&theme_path)?
|
||||||
|
} else {
|
||||||
|
ThemeTokens::moon_night_default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut compositor = MoonPlasmaCompositor::new(&socket_path, &components_dir, theme, 1280, 720)?;
|
||||||
|
compositor.step()?;
|
||||||
|
let pixmap = compositor.compose_frame()?;
|
||||||
|
SoftwareRenderer::save_png(&pixmap, &out_path)?;
|
||||||
|
println!(
|
||||||
|
"moon-plasma-host: Wayland socket={}, rendered {}x{} frame to {}",
|
||||||
|
socket_path.display(),
|
||||||
|
pixmap.width(),
|
||||||
|
pixmap.height(),
|
||||||
|
out_path.display()
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,409 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use fontdue::{Font, FontSettings};
|
||||||
|
use tiny_skia::{
|
||||||
|
Color, FillRule, LineCap, Mask, Paint, PathBuilder, Pixmap, PixmapPaint, Rect as SkRect,
|
||||||
|
Stroke, Transform,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::scene::{DrawOp, Rect, SceneGraph, ShmBufferSnapshot, TextAlign};
|
||||||
|
use crate::theme::Rgba;
|
||||||
|
|
||||||
|
pub struct SoftwareRenderer {
|
||||||
|
font_regular: Option<Font>,
|
||||||
|
font_bold: Option<Font>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SoftwareRenderer {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let load_font = |path: &str| -> Option<Font> {
|
||||||
|
let bytes = std::fs::read(path).ok()?;
|
||||||
|
Font::from_bytes(bytes, FontSettings::default()).ok()
|
||||||
|
};
|
||||||
|
Self {
|
||||||
|
font_regular: load_font("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"),
|
||||||
|
font_bold: load_font("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf")
|
||||||
|
.or_else(|| load_font("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render_scene(&self, scene: &SceneGraph) -> anyhow::Result<Pixmap> {
|
||||||
|
let (w, h) = scene.output_size;
|
||||||
|
let mut pixmap = Pixmap::new(w.max(1), h.max(1))
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("failed to create pixmap {w}x{h}"))?;
|
||||||
|
|
||||||
|
// 1. Background layer
|
||||||
|
self.draw_ops(&mut pixmap, &scene.background_ops, 0, 0);
|
||||||
|
|
||||||
|
// 2. Windows layer (bottom-to-top)
|
||||||
|
for win in &scene.windows {
|
||||||
|
if !win.fullscreen {
|
||||||
|
let (top, right, bottom, left) = win.deco_insets;
|
||||||
|
let outer_x = win.geometry.x - left as i32;
|
||||||
|
let outer_y = win.geometry.y - top as i32;
|
||||||
|
let outer_w = win.geometry.w + left + right;
|
||||||
|
let outer_h = win.geometry.h + top + bottom;
|
||||||
|
|
||||||
|
// Subtle drop shadow under window
|
||||||
|
let shadow_rect = Rect::new(outer_x + 4, outer_y + 6, outer_w, outer_h);
|
||||||
|
self.fill_rounded_rect(
|
||||||
|
&mut pixmap,
|
||||||
|
shadow_rect,
|
||||||
|
Rgba { r: 0, g: 0, b: 0, a: 80 },
|
||||||
|
8,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Decoration draw-ops (local to outer_x, outer_y)
|
||||||
|
self.draw_ops(&mut pixmap, &win.deco_ops, outer_x, outer_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client buffer-surface
|
||||||
|
if let Some(buf) = &win.surface {
|
||||||
|
self.blit_shm_surface(&mut pixmap, buf, win.geometry);
|
||||||
|
} else {
|
||||||
|
// Fallback placeholder until client commits first buffer
|
||||||
|
self.fill_rounded_rect(
|
||||||
|
&mut pixmap,
|
||||||
|
win.geometry,
|
||||||
|
Rgba { r: 0x1e, g: 0x29, b: 0x3b, a: 0xff },
|
||||||
|
0,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Panel layer
|
||||||
|
self.draw_ops(&mut pixmap, &scene.panel_ops, 0, 0);
|
||||||
|
for widget in &scene.widgets {
|
||||||
|
self.draw_ops(&mut pixmap, &widget.ops, widget.rect.x, widget.rect.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Overlay layer (popups)
|
||||||
|
for widget in &scene.widgets {
|
||||||
|
if let Some((popup_rect, popup_ops)) = &widget.popup {
|
||||||
|
self.draw_ops(&mut pixmap, popup_ops, popup_rect.x, popup_rect.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(pixmap)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save_png(pixmap: &Pixmap, path: &Path) -> anyhow::Result<()> {
|
||||||
|
pixmap.save_png(path)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn blit_shm_surface(&self, dst: &mut Pixmap, buf: &ShmBufferSnapshot, dst_rect: Rect) {
|
||||||
|
if buf.width == 0 || buf.height == 0 || dst_rect.w == 0 || dst_rect.h == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut src_pix = match Pixmap::new(buf.width, buf.height) {
|
||||||
|
Some(p) => p,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
let dst_data = src_pix.data_mut();
|
||||||
|
let copy_w = buf.width as usize;
|
||||||
|
let copy_h = buf.height as usize;
|
||||||
|
let stride = buf.stride as usize;
|
||||||
|
let is_xrgb = buf.format == 1; // WL_SHM_FORMAT_XRGB8888 = 1, ARGB8888 = 0
|
||||||
|
|
||||||
|
for y in 0..copy_h {
|
||||||
|
let row_off = y * stride;
|
||||||
|
if row_off + copy_w * 4 > buf.bytes.len() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for x in 0..copy_w {
|
||||||
|
let s = row_off + x * 4;
|
||||||
|
// Wayland little-endian ARGB8888/XRGB8888 is [B, G, R, A] in memory.
|
||||||
|
let b = buf.bytes[s];
|
||||||
|
let g = buf.bytes[s + 1];
|
||||||
|
let r = buf.bytes[s + 2];
|
||||||
|
let a = if is_xrgb { 255 } else { buf.bytes[s + 3] };
|
||||||
|
// Premultiply for tiny-skia RGBA
|
||||||
|
let d = (y * copy_w + x) * 4;
|
||||||
|
if a == 255 {
|
||||||
|
dst_data[d] = r;
|
||||||
|
dst_data[d + 1] = g;
|
||||||
|
dst_data[d + 2] = b;
|
||||||
|
dst_data[d + 3] = 255;
|
||||||
|
} else if a == 0 {
|
||||||
|
dst_data[d..d + 4].fill(0);
|
||||||
|
} else {
|
||||||
|
let af = a as f32 / 255.0;
|
||||||
|
dst_data[d] = (r as f32 * af) as u8;
|
||||||
|
dst_data[d + 1] = (g as f32 * af) as u8;
|
||||||
|
dst_data[d + 2] = (b as f32 * af) as u8;
|
||||||
|
dst_data[d + 3] = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut clip_mask = Mask::new(dst.width(), dst.height());
|
||||||
|
if let Some(mask) = clip_mask.as_mut() {
|
||||||
|
if let Some(sk_r) = SkRect::from_xywh(
|
||||||
|
dst_rect.x as f32,
|
||||||
|
dst_rect.y as f32,
|
||||||
|
dst_rect.w as f32,
|
||||||
|
dst_rect.h as f32,
|
||||||
|
) {
|
||||||
|
let path = PathBuilder::from_rect(sk_r);
|
||||||
|
mask.fill_path(&path, FillRule::Winding, false, Transform::identity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dst.draw_pixmap(
|
||||||
|
dst_rect.x,
|
||||||
|
dst_rect.y,
|
||||||
|
src_pix.as_ref(),
|
||||||
|
&PixmapPaint::default(),
|
||||||
|
Transform::identity(),
|
||||||
|
clip_mask.as_ref(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_ops(&self, pixmap: &mut Pixmap, ops: &[DrawOp], ox: i32, oy: i32) {
|
||||||
|
let mut clip_stack: Vec<Mask> = Vec::new();
|
||||||
|
for op in ops {
|
||||||
|
let mask_ref = clip_stack.last();
|
||||||
|
match op {
|
||||||
|
DrawOp::PushClip(r) => {
|
||||||
|
if let Some(mut m) = Mask::new(pixmap.width(), pixmap.height()) {
|
||||||
|
if let Some(sk_r) = SkRect::from_xywh(
|
||||||
|
(r.x + ox) as f32,
|
||||||
|
(r.y + oy) as f32,
|
||||||
|
r.w as f32,
|
||||||
|
r.h as f32,
|
||||||
|
) {
|
||||||
|
let path = PathBuilder::from_rect(sk_r);
|
||||||
|
m.fill_path(&path, FillRule::Winding, false, Transform::identity());
|
||||||
|
clip_stack.push(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DrawOp::PopClip => {
|
||||||
|
clip_stack.pop();
|
||||||
|
}
|
||||||
|
DrawOp::FillRect { rect, color, radius } => {
|
||||||
|
let r = Rect::new(rect.x + ox, rect.y + oy, rect.w, rect.h);
|
||||||
|
self.fill_rounded_rect(pixmap, r, *color, *radius, mask_ref);
|
||||||
|
}
|
||||||
|
DrawOp::StrokeRect {
|
||||||
|
rect,
|
||||||
|
color,
|
||||||
|
width,
|
||||||
|
radius,
|
||||||
|
} => {
|
||||||
|
let r = Rect::new(rect.x + ox, rect.y + oy, rect.w, rect.h);
|
||||||
|
self.stroke_rounded_rect(pixmap, r, *color, *width, *radius, mask_ref);
|
||||||
|
}
|
||||||
|
DrawOp::Line {
|
||||||
|
x0,
|
||||||
|
y0,
|
||||||
|
x1,
|
||||||
|
y1,
|
||||||
|
color,
|
||||||
|
width,
|
||||||
|
} => {
|
||||||
|
let mut pb = PathBuilder::new();
|
||||||
|
pb.move_to((x0 + ox) as f32, (y0 + oy) as f32);
|
||||||
|
pb.line_to((x1 + ox) as f32, (y1 + oy) as f32);
|
||||||
|
if let Some(path) = pb.finish() {
|
||||||
|
let mut paint = Paint::default();
|
||||||
|
paint.set_color(Color::from_rgba8(color.r, color.g, color.b, color.a));
|
||||||
|
paint.anti_alias = true;
|
||||||
|
let stroke = Stroke {
|
||||||
|
width: (*width).max(1) as f32,
|
||||||
|
line_cap: LineCap::Round,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), mask_ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DrawOp::Circle {
|
||||||
|
cx,
|
||||||
|
cy,
|
||||||
|
radius,
|
||||||
|
color,
|
||||||
|
filled,
|
||||||
|
} => {
|
||||||
|
if let Some(path) = PathBuilder::from_circle((cx + ox) as f32, (cy + oy) as f32, *radius as f32) {
|
||||||
|
let mut paint = Paint::default();
|
||||||
|
paint.set_color(Color::from_rgba8(color.r, color.g, color.b, color.a));
|
||||||
|
paint.anti_alias = true;
|
||||||
|
if *filled {
|
||||||
|
pixmap.fill_path(&path, &paint, FillRule::Winding, Transform::identity(), mask_ref);
|
||||||
|
} else {
|
||||||
|
let stroke = Stroke {
|
||||||
|
width: 1.5,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), mask_ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DrawOp::Text {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
text,
|
||||||
|
size,
|
||||||
|
color,
|
||||||
|
align,
|
||||||
|
bold,
|
||||||
|
} => {
|
||||||
|
self.draw_text(
|
||||||
|
pixmap,
|
||||||
|
x + ox,
|
||||||
|
y + oy,
|
||||||
|
text,
|
||||||
|
*size,
|
||||||
|
*color,
|
||||||
|
*align,
|
||||||
|
*bold,
|
||||||
|
mask_ref,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_rounded_rect_path(&self, r: Rect, radius: u32) -> Option<tiny_skia::Path> {
|
||||||
|
if r.w == 0 || r.h == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let x = r.x as f32;
|
||||||
|
let y = r.y as f32;
|
||||||
|
let w = r.w as f32;
|
||||||
|
let h = r.h as f32;
|
||||||
|
let rad = (radius as f32).min(w * 0.5).min(h * 0.5);
|
||||||
|
if rad <= 0.5 {
|
||||||
|
return SkRect::from_xywh(x, y, w, h).map(PathBuilder::from_rect);
|
||||||
|
}
|
||||||
|
let k = rad * 0.5522848;
|
||||||
|
let mut pb = PathBuilder::new();
|
||||||
|
pb.move_to(x + rad, y);
|
||||||
|
pb.line_to(x + w - rad, y);
|
||||||
|
pb.cubic_to(x + w - rad + k, y, x + w, y + rad - k, x + w, y + rad);
|
||||||
|
pb.line_to(x + w, y + h - rad);
|
||||||
|
pb.cubic_to(x + w, y + h - rad + k, x + w - rad + k, y + h, x + w - rad, y + h);
|
||||||
|
pb.line_to(x + rad, y + h);
|
||||||
|
pb.cubic_to(x + rad - k, y + h, x, y + h - rad + k, x, y + h - rad);
|
||||||
|
pb.line_to(x, y + rad);
|
||||||
|
pb.cubic_to(x, y + rad - k, x + rad - k, y, x + rad, y);
|
||||||
|
pb.close();
|
||||||
|
pb.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill_rounded_rect(&self, pixmap: &mut Pixmap, r: Rect, color: Rgba, radius: u32, mask: Option<&Mask>) {
|
||||||
|
if let Some(path) = self.build_rounded_rect_path(r, radius) {
|
||||||
|
let mut paint = Paint::default();
|
||||||
|
paint.set_color(Color::from_rgba8(color.r, color.g, color.b, color.a));
|
||||||
|
paint.anti_alias = true;
|
||||||
|
pixmap.fill_path(&path, &paint, FillRule::Winding, Transform::identity(), mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stroke_rounded_rect(
|
||||||
|
&self,
|
||||||
|
pixmap: &mut Pixmap,
|
||||||
|
r: Rect,
|
||||||
|
color: Rgba,
|
||||||
|
width: u32,
|
||||||
|
radius: u32,
|
||||||
|
mask: Option<&Mask>,
|
||||||
|
) {
|
||||||
|
if let Some(path) = self.build_rounded_rect_path(r, radius) {
|
||||||
|
let mut paint = Paint::default();
|
||||||
|
paint.set_color(Color::from_rgba8(color.r, color.g, color.b, color.a));
|
||||||
|
paint.anti_alias = true;
|
||||||
|
let stroke = Stroke {
|
||||||
|
width: width.max(1) as f32,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn draw_text(
|
||||||
|
&self,
|
||||||
|
pixmap: &mut Pixmap,
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
text: &str,
|
||||||
|
size: u32,
|
||||||
|
color: Rgba,
|
||||||
|
align: TextAlign,
|
||||||
|
bold: bool,
|
||||||
|
mask: Option<&Mask>,
|
||||||
|
) {
|
||||||
|
let font = match if bold { &self.font_bold } else { &self.font_regular } {
|
||||||
|
Some(f) => f,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
let px_size = size.max(8) as f32;
|
||||||
|
|
||||||
|
let mut total_w = 0.0f32;
|
||||||
|
let mut glyphs = Vec::with_capacity(text.len());
|
||||||
|
for ch in text.chars() {
|
||||||
|
let (metrics, bitmap) = font.rasterize(ch, px_size);
|
||||||
|
total_w += metrics.advance_width;
|
||||||
|
glyphs.push((metrics, bitmap));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut pen_x = match align {
|
||||||
|
TextAlign::Left => x as f32,
|
||||||
|
TextAlign::Center => x as f32 - total_w * 0.5,
|
||||||
|
TextAlign::Right => x as f32 - total_w,
|
||||||
|
};
|
||||||
|
// `y` is vertical middle of the line box per WIT spec.
|
||||||
|
let baseline_y = y as f32 + px_size * 0.35;
|
||||||
|
|
||||||
|
let pw = pixmap.width() as i32;
|
||||||
|
let ph = pixmap.height() as i32;
|
||||||
|
let data = pixmap.data_mut();
|
||||||
|
|
||||||
|
for (metrics, bitmap) in glyphs {
|
||||||
|
let gx0 = (pen_x + metrics.xmin as f32).round() as i32;
|
||||||
|
let gy0 = (baseline_y - metrics.height as f32 - metrics.ymin as f32).round() as i32;
|
||||||
|
for row in 0..metrics.height {
|
||||||
|
let py = gy0 + row as i32;
|
||||||
|
if py < 0 || py >= ph {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for col in 0..metrics.width {
|
||||||
|
let px = gx0 + col as i32;
|
||||||
|
if px < 0 || px >= pw {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(m) = mask {
|
||||||
|
let midx = py as usize * m.width() as usize + px as usize;
|
||||||
|
if m.data().get(midx).copied().unwrap_or(0) == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let cov = bitmap[row * metrics.width + col];
|
||||||
|
if cov == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let alpha = (cov as u32 * color.a as u32) / 255;
|
||||||
|
if alpha == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let sa = alpha as f32 / 255.0;
|
||||||
|
let inv = 1.0 - sa;
|
||||||
|
let idx = (py as usize * pw as usize + px as usize) * 4;
|
||||||
|
// Pixmap is premultiplied RGBA
|
||||||
|
let sr = color.r as f32 * sa;
|
||||||
|
let sg = color.g as f32 * sa;
|
||||||
|
let sb = color.b as f32 * sa;
|
||||||
|
data[idx] = (sr + data[idx] as f32 * inv).min(255.0) as u8;
|
||||||
|
data[idx + 1] = (sg + data[idx + 1] as f32 * inv).min(255.0) as u8;
|
||||||
|
data[idx + 2] = (sb + data[idx + 2] as f32 * inv).min(255.0) as u8;
|
||||||
|
data[idx + 3] = (alpha as f32 + data[idx + 3] as f32 * inv).min(255.0) as u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pen_x += metrics.advance_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
use crate::theme::Rgba;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub struct Rect {
|
||||||
|
pub x: i32,
|
||||||
|
pub y: i32,
|
||||||
|
pub w: u32,
|
||||||
|
pub h: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rect {
|
||||||
|
pub fn new(x: i32, y: i32, w: u32, h: u32) -> Self {
|
||||||
|
Self { x, y, w, h }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn union(self, other: Self) -> Self {
|
||||||
|
let x0 = self.x.min(other.x);
|
||||||
|
let y0 = self.y.min(other.y);
|
||||||
|
let x1 = (self.x + self.w as i32).max(other.x + other.w as i32);
|
||||||
|
let y1 = (self.y + self.h as i32).max(other.y + other.h as i32);
|
||||||
|
Self {
|
||||||
|
x: x0,
|
||||||
|
y: y0,
|
||||||
|
w: (x1 - x0).max(0) as u32,
|
||||||
|
h: (y1 - y0).max(0) as u32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum TextAlign {
|
||||||
|
Left,
|
||||||
|
Center,
|
||||||
|
Right,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum DrawOp {
|
||||||
|
FillRect {
|
||||||
|
rect: Rect,
|
||||||
|
color: Rgba,
|
||||||
|
radius: u32,
|
||||||
|
},
|
||||||
|
StrokeRect {
|
||||||
|
rect: Rect,
|
||||||
|
color: Rgba,
|
||||||
|
width: u32,
|
||||||
|
radius: u32,
|
||||||
|
},
|
||||||
|
Line {
|
||||||
|
x0: i32,
|
||||||
|
y0: i32,
|
||||||
|
x1: i32,
|
||||||
|
y1: i32,
|
||||||
|
color: Rgba,
|
||||||
|
width: u32,
|
||||||
|
},
|
||||||
|
Circle {
|
||||||
|
cx: i32,
|
||||||
|
cy: i32,
|
||||||
|
radius: u32,
|
||||||
|
color: Rgba,
|
||||||
|
filled: bool,
|
||||||
|
},
|
||||||
|
Text {
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
text: String,
|
||||||
|
size: u32,
|
||||||
|
color: Rgba,
|
||||||
|
align: TextAlign,
|
||||||
|
bold: bool,
|
||||||
|
},
|
||||||
|
PushClip(Rect),
|
||||||
|
PopClip,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ShmBufferSnapshot {
|
||||||
|
pub width: u32,
|
||||||
|
pub height: u32,
|
||||||
|
pub stride: u32,
|
||||||
|
/// Wayland wl_shm format (0 = ARGB8888, 1 = XRGB8888)
|
||||||
|
pub format: u32,
|
||||||
|
pub bytes: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct WindowSceneNode {
|
||||||
|
pub id: u64,
|
||||||
|
pub title: String,
|
||||||
|
pub app_id: String,
|
||||||
|
pub focused: bool,
|
||||||
|
pub fullscreen: bool,
|
||||||
|
pub geometry: Rect,
|
||||||
|
pub deco_insets: (u32, u32, u32, u32),
|
||||||
|
pub deco_ops: Vec<DrawOp>,
|
||||||
|
pub surface: Option<ShmBufferSnapshot>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct PanelWidgetNode {
|
||||||
|
pub id: String,
|
||||||
|
pub rect: Rect,
|
||||||
|
pub ops: Vec<DrawOp>,
|
||||||
|
pub popup: Option<(Rect, Vec<DrawOp>)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
pub struct DamageTracker {
|
||||||
|
pub regions: Vec<Rect>,
|
||||||
|
pub full_damage: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DamageTracker {
|
||||||
|
pub fn mark_full(&mut self) {
|
||||||
|
self.full_damage = true;
|
||||||
|
self.regions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_rect(&mut self, r: Rect) {
|
||||||
|
if !self.full_damage && r.w > 0 && r.h > 0 {
|
||||||
|
self.regions.push(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear(&mut self) {
|
||||||
|
self.full_damage = false;
|
||||||
|
self.regions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_dirty(&self) -> bool {
|
||||||
|
self.full_damage || !self.regions.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct SceneGraph {
|
||||||
|
pub output_size: (u32, u32),
|
||||||
|
pub background_ops: Vec<DrawOp>,
|
||||||
|
pub windows: Vec<WindowSceneNode>,
|
||||||
|
pub panel_rect: Rect,
|
||||||
|
pub panel_ops: Vec<DrawOp>,
|
||||||
|
pub widgets: Vec<PanelWidgetNode>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SceneGraph {
|
||||||
|
pub fn new(w: u32, h: u32) -> Self {
|
||||||
|
Self {
|
||||||
|
output_size: (w, h),
|
||||||
|
background_ops: Vec::new(),
|
||||||
|
windows: Vec::new(),
|
||||||
|
panel_rect: Rect::new(0, 0, 0, 0),
|
||||||
|
panel_ops: Vec::new(),
|
||||||
|
widgets: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct Rgba {
|
||||||
|
pub r: u8,
|
||||||
|
pub g: u8,
|
||||||
|
pub b: u8,
|
||||||
|
pub a: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rgba {
|
||||||
|
pub fn from_hex(s: &str) -> anyhow::Result<Self> {
|
||||||
|
let hex = s.strip_prefix('#').unwrap_or(s);
|
||||||
|
let bytes = hex.as_bytes();
|
||||||
|
let parse_byte = |i: usize| -> anyhow::Result<u8> {
|
||||||
|
let sub = std::str::from_utf8(&bytes[i..i + 2])?;
|
||||||
|
Ok(u8::from_str_radix(sub, 16)?)
|
||||||
|
};
|
||||||
|
match bytes.len() {
|
||||||
|
6 => Ok(Self {
|
||||||
|
r: parse_byte(0)?,
|
||||||
|
g: parse_byte(2)?,
|
||||||
|
b: parse_byte(4)?,
|
||||||
|
a: 255,
|
||||||
|
}),
|
||||||
|
8 => Ok(Self {
|
||||||
|
r: parse_byte(0)?,
|
||||||
|
g: parse_byte(2)?,
|
||||||
|
b: parse_byte(4)?,
|
||||||
|
a: parse_byte(6)?,
|
||||||
|
}),
|
||||||
|
_ => anyhow::bail!("invalid hex color: {s}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ThemePalette {
|
||||||
|
pub desktop_top: Rgba,
|
||||||
|
pub desktop_bottom: Rgba,
|
||||||
|
pub surface: Rgba,
|
||||||
|
pub surface_hover: Rgba,
|
||||||
|
pub surface_popup: Rgba,
|
||||||
|
pub foreground: Rgba,
|
||||||
|
pub foreground_muted: Rgba,
|
||||||
|
pub accent: Rgba,
|
||||||
|
pub accent_foreground: Rgba,
|
||||||
|
pub border: Rgba,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ThemeTokens {
|
||||||
|
pub name: String,
|
||||||
|
pub palette: ThemePalette,
|
||||||
|
pub font_size: u32,
|
||||||
|
pub radius: u32,
|
||||||
|
pub spacing: u32,
|
||||||
|
pub panel_height: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct RawPalette {
|
||||||
|
#[serde(rename = "desktop-top")]
|
||||||
|
desktop_top: String,
|
||||||
|
#[serde(rename = "desktop-bottom")]
|
||||||
|
desktop_bottom: String,
|
||||||
|
surface: String,
|
||||||
|
#[serde(rename = "surface-hover")]
|
||||||
|
surface_hover: String,
|
||||||
|
#[serde(rename = "surface-popup")]
|
||||||
|
surface_popup: String,
|
||||||
|
foreground: String,
|
||||||
|
#[serde(rename = "foreground-muted")]
|
||||||
|
foreground_muted: String,
|
||||||
|
accent: String,
|
||||||
|
#[serde(rename = "accent-foreground")]
|
||||||
|
accent_foreground: String,
|
||||||
|
border: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct RawTheme {
|
||||||
|
name: String,
|
||||||
|
palette: RawPalette,
|
||||||
|
#[serde(rename = "font-size")]
|
||||||
|
font_size: u32,
|
||||||
|
radius: u32,
|
||||||
|
spacing: u32,
|
||||||
|
#[serde(rename = "panel-height")]
|
||||||
|
panel_height: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThemeTokens {
|
||||||
|
pub fn load_file(path: &Path) -> anyhow::Result<Self> {
|
||||||
|
let text = std::fs::read_to_string(path)?;
|
||||||
|
let raw: RawTheme = serde_json::from_str(&text)?;
|
||||||
|
Ok(Self {
|
||||||
|
name: raw.name,
|
||||||
|
palette: ThemePalette {
|
||||||
|
desktop_top: Rgba::from_hex(&raw.palette.desktop_top)?,
|
||||||
|
desktop_bottom: Rgba::from_hex(&raw.palette.desktop_bottom)?,
|
||||||
|
surface: Rgba::from_hex(&raw.palette.surface)?,
|
||||||
|
surface_hover: Rgba::from_hex(&raw.palette.surface_hover)?,
|
||||||
|
surface_popup: Rgba::from_hex(&raw.palette.surface_popup)?,
|
||||||
|
foreground: Rgba::from_hex(&raw.palette.foreground)?,
|
||||||
|
foreground_muted: Rgba::from_hex(&raw.palette.foreground_muted)?,
|
||||||
|
accent: Rgba::from_hex(&raw.palette.accent)?,
|
||||||
|
accent_foreground: Rgba::from_hex(&raw.palette.accent_foreground)?,
|
||||||
|
border: Rgba::from_hex(&raw.palette.border)?,
|
||||||
|
},
|
||||||
|
font_size: raw.font_size,
|
||||||
|
radius: raw.radius,
|
||||||
|
spacing: raw.spacing,
|
||||||
|
panel_height: raw.panel_height,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn moon_night_default() -> Self {
|
||||||
|
Self {
|
||||||
|
name: "Moon Night".to_string(),
|
||||||
|
palette: ThemePalette {
|
||||||
|
desktop_top: Rgba { r: 0x16, g: 0x21, b: 0x3e, a: 0xff },
|
||||||
|
desktop_bottom: Rgba { r: 0x0b, g: 0x10, b: 0x20, a: 0xff },
|
||||||
|
surface: Rgba { r: 0x1f, g: 0x29, b: 0x37, a: 0xf2 },
|
||||||
|
surface_hover: Rgba { r: 0x37, g: 0x41, b: 0x51, a: 0xff },
|
||||||
|
surface_popup: Rgba { r: 0x11, g: 0x18, b: 0x27, a: 0xf5 },
|
||||||
|
foreground: Rgba { r: 0xf3, g: 0xf4, b: 0xf6, a: 0xff },
|
||||||
|
foreground_muted: Rgba { r: 0x9c, g: 0xa3, b: 0xaf, a: 0xff },
|
||||||
|
accent: Rgba { r: 0x7c, g: 0x9c, b: 0xff, a: 0xff },
|
||||||
|
accent_foreground: Rgba { r: 0x0b, g: 0x10, b: 0x20, a: 0xff },
|
||||||
|
border: Rgba { r: 0x3b, g: 0x46, b: 0x58, a: 0xff },
|
||||||
|
},
|
||||||
|
font_size: 14,
|
||||||
|
radius: 6,
|
||||||
|
spacing: 6,
|
||||||
|
panel_height: 44,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,471 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use chrono::{Datelike, Timelike};
|
||||||
|
use wasmtime::component::{Component, Linker};
|
||||||
|
use wasmtime::{Config, Engine, Store};
|
||||||
|
|
||||||
|
use crate::theme::ThemeTokens;
|
||||||
|
|
||||||
|
pub mod desktop_wit {
|
||||||
|
wasmtime::component::bindgen!({
|
||||||
|
path: "../wit",
|
||||||
|
world: "shell",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod clock_wit {
|
||||||
|
wasmtime::component::bindgen!({
|
||||||
|
path: "../wit",
|
||||||
|
world: "clock-widget",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod launcher_wit {
|
||||||
|
wasmtime::component::bindgen!({
|
||||||
|
path: "../wit",
|
||||||
|
world: "launcher-widget",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod wm_wit {
|
||||||
|
wasmtime::component::bindgen!({
|
||||||
|
path: "../wit/wm",
|
||||||
|
world: "window-manager",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod deco_wit {
|
||||||
|
wasmtime::component::bindgen!({
|
||||||
|
path: "../wit/wm",
|
||||||
|
world: "decoration-provider",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ComponentFault {
|
||||||
|
pub component: String,
|
||||||
|
pub phase: String,
|
||||||
|
pub message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct SharedHostState {
|
||||||
|
pub theme: Arc<Mutex<ThemeTokens>>,
|
||||||
|
pub launched_apps: Arc<Mutex<Vec<String>>>,
|
||||||
|
pub apps: Arc<Vec<desktop_wit::moonplasma::desktop::types::AppEntry>>,
|
||||||
|
pub faults: Arc<Mutex<Vec<ComponentFault>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SharedHostState {
|
||||||
|
pub fn new(theme: ThemeTokens) -> Self {
|
||||||
|
use desktop_wit::moonplasma::desktop::types::AppEntry;
|
||||||
|
Self {
|
||||||
|
theme: Arc::new(Mutex::new(theme)),
|
||||||
|
launched_apps: Arc::new(Mutex::new(Vec::new())),
|
||||||
|
apps: Arc::new(vec![
|
||||||
|
AppEntry {
|
||||||
|
id: "org.moonplasma.term".into(),
|
||||||
|
name: "MoonTerm".into(),
|
||||||
|
comment: "Terminal emulator".into(),
|
||||||
|
category: "System".into(),
|
||||||
|
glyph: ">_".into(),
|
||||||
|
},
|
||||||
|
AppEntry {
|
||||||
|
id: "org.moonplasma.files".into(),
|
||||||
|
name: "Files".into(),
|
||||||
|
comment: "File manager".into(),
|
||||||
|
category: "System".into(),
|
||||||
|
glyph: "[]".into(),
|
||||||
|
},
|
||||||
|
AppEntry {
|
||||||
|
id: "org.moonplasma.calc".into(),
|
||||||
|
name: "Calculator".into(),
|
||||||
|
comment: "Scientific calculator".into(),
|
||||||
|
category: "Utilities".into(),
|
||||||
|
glyph: "+=".into(),
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
faults: Arc::new(Mutex::new(Vec::new())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ComponentCtx {
|
||||||
|
pub name: String,
|
||||||
|
pub grants: HashSet<String>,
|
||||||
|
pub shared: SharedHostState,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_desktop_color(c: crate::theme::Rgba) -> desktop_wit::moonplasma::desktop::types::Color {
|
||||||
|
desktop_wit::moonplasma::desktop::types::Color { r: c.r, g: c.g, b: c.b, a: c.a }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_wm_color(c: crate::theme::Rgba) -> wm_wit::moonplasma::desktop::types::Color {
|
||||||
|
wm_wit::moonplasma::desktop::types::Color { r: c.r, g: c.g, b: c.b, a: c.a }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_deco_color(c: crate::theme::Rgba) -> deco_wit::moonplasma::desktop::types::Color {
|
||||||
|
deco_wit::moonplasma::desktop::types::Color { r: c.r, g: c.g, b: c.b, a: c.a }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_clock_color(c: crate::theme::Rgba) -> clock_wit::moonplasma::desktop::types::Color {
|
||||||
|
clock_wit::moonplasma::desktop::types::Color { r: c.r, g: c.g, b: c.b, a: c.a }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_launcher_color(c: crate::theme::Rgba) -> launcher_wit::moonplasma::desktop::types::Color {
|
||||||
|
launcher_wit::moonplasma::desktop::types::Color { r: c.r, g: c.g, b: c.b, a: c.a }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement theme::Host for each generated bindgen module so every component world links cleanly.
|
||||||
|
impl desktop_wit::moonplasma::desktop::types::Host for ComponentCtx {}
|
||||||
|
impl desktop_wit::moonplasma::desktop::theme::Host for ComponentCtx {
|
||||||
|
fn get_tokens(&mut self) -> desktop_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
let t = self.shared.theme.lock().unwrap();
|
||||||
|
desktop_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
name: t.name.clone(),
|
||||||
|
palette: desktop_wit::moonplasma::desktop::theme::Palette {
|
||||||
|
desktop_top: to_desktop_color(t.palette.desktop_top),
|
||||||
|
desktop_bottom: to_desktop_color(t.palette.desktop_bottom),
|
||||||
|
surface: to_desktop_color(t.palette.surface),
|
||||||
|
surface_hover: to_desktop_color(t.palette.surface_hover),
|
||||||
|
surface_popup: to_desktop_color(t.palette.surface_popup),
|
||||||
|
foreground: to_desktop_color(t.palette.foreground),
|
||||||
|
foreground_muted: to_desktop_color(t.palette.foreground_muted),
|
||||||
|
accent: to_desktop_color(t.palette.accent),
|
||||||
|
accent_foreground: to_desktop_color(t.palette.accent_foreground),
|
||||||
|
border: to_desktop_color(t.palette.border),
|
||||||
|
},
|
||||||
|
font_size: t.font_size,
|
||||||
|
radius: t.radius,
|
||||||
|
spacing: t.spacing,
|
||||||
|
panel_height: t.panel_height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl clock_wit::moonplasma::desktop::types::Host for ComponentCtx {}
|
||||||
|
impl clock_wit::moonplasma::desktop::theme::Host for ComponentCtx {
|
||||||
|
fn get_tokens(&mut self) -> clock_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
let t = self.shared.theme.lock().unwrap();
|
||||||
|
clock_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
name: t.name.clone(),
|
||||||
|
palette: clock_wit::moonplasma::desktop::theme::Palette {
|
||||||
|
desktop_top: to_clock_color(t.palette.desktop_top),
|
||||||
|
desktop_bottom: to_clock_color(t.palette.desktop_bottom),
|
||||||
|
surface: to_clock_color(t.palette.surface),
|
||||||
|
surface_hover: to_clock_color(t.palette.surface_hover),
|
||||||
|
surface_popup: to_clock_color(t.palette.surface_popup),
|
||||||
|
foreground: to_clock_color(t.palette.foreground),
|
||||||
|
foreground_muted: to_clock_color(t.palette.foreground_muted),
|
||||||
|
accent: to_clock_color(t.palette.accent),
|
||||||
|
accent_foreground: to_clock_color(t.palette.accent_foreground),
|
||||||
|
border: to_clock_color(t.palette.border),
|
||||||
|
},
|
||||||
|
font_size: t.font_size,
|
||||||
|
radius: t.radius,
|
||||||
|
spacing: t.spacing,
|
||||||
|
panel_height: t.panel_height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl clock_wit::moonplasma::desktop::clock::Host for ComponentCtx {
|
||||||
|
fn now(&mut self) -> clock_wit::moonplasma::desktop::types::Datetime {
|
||||||
|
let dt = chrono::Local::now();
|
||||||
|
clock_wit::moonplasma::desktop::types::Datetime {
|
||||||
|
year: dt.year() as u32,
|
||||||
|
month: dt.month() as u8,
|
||||||
|
day: dt.day() as u8,
|
||||||
|
hour: dt.hour() as u8,
|
||||||
|
minute: dt.minute() as u8,
|
||||||
|
second: dt.second() as u8,
|
||||||
|
weekday: dt.weekday().num_days_from_sunday() as u8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl launcher_wit::moonplasma::desktop::types::Host for ComponentCtx {}
|
||||||
|
impl launcher_wit::moonplasma::desktop::theme::Host for ComponentCtx {
|
||||||
|
fn get_tokens(&mut self) -> launcher_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
let t = self.shared.theme.lock().unwrap();
|
||||||
|
launcher_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
name: t.name.clone(),
|
||||||
|
palette: launcher_wit::moonplasma::desktop::theme::Palette {
|
||||||
|
desktop_top: to_launcher_color(t.palette.desktop_top),
|
||||||
|
desktop_bottom: to_launcher_color(t.palette.desktop_bottom),
|
||||||
|
surface: to_launcher_color(t.palette.surface),
|
||||||
|
surface_hover: to_launcher_color(t.palette.surface_hover),
|
||||||
|
surface_popup: to_launcher_color(t.palette.surface_popup),
|
||||||
|
foreground: to_launcher_color(t.palette.foreground),
|
||||||
|
foreground_muted: to_launcher_color(t.palette.foreground_muted),
|
||||||
|
accent: to_launcher_color(t.palette.accent),
|
||||||
|
accent_foreground: to_launcher_color(t.palette.accent_foreground),
|
||||||
|
border: to_launcher_color(t.palette.border),
|
||||||
|
},
|
||||||
|
font_size: t.font_size,
|
||||||
|
radius: t.radius,
|
||||||
|
spacing: t.spacing,
|
||||||
|
panel_height: t.panel_height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl launcher_wit::moonplasma::desktop::app_catalog::Host for ComponentCtx {
|
||||||
|
fn list_apps(&mut self) -> Vec<launcher_wit::moonplasma::desktop::types::AppEntry> {
|
||||||
|
if !self.grants.contains("app-catalog") {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
self.shared
|
||||||
|
.apps
|
||||||
|
.iter()
|
||||||
|
.map(|a| launcher_wit::moonplasma::desktop::types::AppEntry {
|
||||||
|
id: a.id.clone(),
|
||||||
|
name: a.name.clone(),
|
||||||
|
comment: a.comment.clone(),
|
||||||
|
category: a.category.clone(),
|
||||||
|
glyph: a.glyph.clone(),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl launcher_wit::moonplasma::desktop::app_launch::Host for ComponentCtx {
|
||||||
|
fn launch(&mut self, id: String) -> Result<(), String> {
|
||||||
|
if !self.grants.contains("app-launch") {
|
||||||
|
return Err("capability app-launch not granted".into());
|
||||||
|
}
|
||||||
|
self.shared.launched_apps.lock().unwrap().push(id);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl wm_wit::moonplasma::desktop::types::Host for ComponentCtx {}
|
||||||
|
impl wm_wit::moonplasma::desktop::theme::Host for ComponentCtx {
|
||||||
|
fn get_tokens(&mut self) -> wm_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
let t = self.shared.theme.lock().unwrap();
|
||||||
|
wm_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
name: t.name.clone(),
|
||||||
|
palette: wm_wit::moonplasma::desktop::theme::Palette {
|
||||||
|
desktop_top: to_wm_color(t.palette.desktop_top),
|
||||||
|
desktop_bottom: to_wm_color(t.palette.desktop_bottom),
|
||||||
|
surface: to_wm_color(t.palette.surface),
|
||||||
|
surface_hover: to_wm_color(t.palette.surface_hover),
|
||||||
|
surface_popup: to_wm_color(t.palette.surface_popup),
|
||||||
|
foreground: to_wm_color(t.palette.foreground),
|
||||||
|
foreground_muted: to_wm_color(t.palette.foreground_muted),
|
||||||
|
accent: to_wm_color(t.palette.accent),
|
||||||
|
accent_foreground: to_wm_color(t.palette.accent_foreground),
|
||||||
|
border: to_wm_color(t.palette.border),
|
||||||
|
},
|
||||||
|
font_size: t.font_size,
|
||||||
|
radius: t.radius,
|
||||||
|
spacing: t.spacing,
|
||||||
|
panel_height: t.panel_height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl deco_wit::moonplasma::desktop::types::Host for ComponentCtx {}
|
||||||
|
impl deco_wit::moonplasma::wm::policy::Host for ComponentCtx {
|
||||||
|
fn sync_windows(
|
||||||
|
&mut self,
|
||||||
|
_outputs: Vec<deco_wit::moonplasma::desktop::types::Rect>,
|
||||||
|
_windows: Vec<deco_wit::moonplasma::wm::policy::WindowState>,
|
||||||
|
) -> Vec<deco_wit::moonplasma::wm::policy::WmAction> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
fn on_window_open(
|
||||||
|
&mut self,
|
||||||
|
_win: deco_wit::moonplasma::wm::policy::WindowState,
|
||||||
|
_work_area: deco_wit::moonplasma::desktop::types::Rect,
|
||||||
|
) -> Vec<deco_wit::moonplasma::wm::policy::WmAction> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
fn on_window_close(&mut self, _id: u64) -> Vec<deco_wit::moonplasma::wm::policy::WmAction> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
fn on_window_request(
|
||||||
|
&mut self,
|
||||||
|
_id: u64,
|
||||||
|
_req: deco_wit::moonplasma::wm::policy::WindowRequest,
|
||||||
|
_work_area: deco_wit::moonplasma::desktop::types::Rect,
|
||||||
|
) -> Vec<deco_wit::moonplasma::wm::policy::WmAction> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
fn on_pointer(
|
||||||
|
&mut self,
|
||||||
|
_pos: deco_wit::moonplasma::desktop::types::Point,
|
||||||
|
_button: Option<u32>,
|
||||||
|
_pressed: bool,
|
||||||
|
) -> deco_wit::moonplasma::wm::policy::InputTarget {
|
||||||
|
deco_wit::moonplasma::wm::policy::InputTarget::None
|
||||||
|
}
|
||||||
|
fn set_layout_mode(
|
||||||
|
&mut self,
|
||||||
|
_mode: deco_wit::moonplasma::wm::policy::LayoutMode,
|
||||||
|
_work_area: deco_wit::moonplasma::desktop::types::Rect,
|
||||||
|
) -> Vec<deco_wit::moonplasma::wm::policy::WmAction> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
fn stacking_order(&mut self) -> Vec<u64> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl deco_wit::moonplasma::desktop::theme::Host for ComponentCtx {
|
||||||
|
fn get_tokens(&mut self) -> deco_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
let t = self.shared.theme.lock().unwrap();
|
||||||
|
deco_wit::moonplasma::desktop::theme::Tokens {
|
||||||
|
name: t.name.clone(),
|
||||||
|
palette: deco_wit::moonplasma::desktop::theme::Palette {
|
||||||
|
desktop_top: to_deco_color(t.palette.desktop_top),
|
||||||
|
desktop_bottom: to_deco_color(t.palette.desktop_bottom),
|
||||||
|
surface: to_deco_color(t.palette.surface),
|
||||||
|
surface_hover: to_deco_color(t.palette.surface_hover),
|
||||||
|
surface_popup: to_deco_color(t.palette.surface_popup),
|
||||||
|
foreground: to_deco_color(t.palette.foreground),
|
||||||
|
foreground_muted: to_deco_color(t.palette.foreground_muted),
|
||||||
|
accent: to_deco_color(t.palette.accent),
|
||||||
|
accent_foreground: to_deco_color(t.palette.accent_foreground),
|
||||||
|
border: to_deco_color(t.palette.border),
|
||||||
|
},
|
||||||
|
font_size: t.font_size,
|
||||||
|
radius: t.radius,
|
||||||
|
spacing: t.spacing,
|
||||||
|
panel_height: t.panel_height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WasmSupervisor {
|
||||||
|
pub engine: Engine,
|
||||||
|
pub shared: SharedHostState,
|
||||||
|
pub shell_store: Store<ComponentCtx>,
|
||||||
|
pub shell: desktop_wit::Shell,
|
||||||
|
pub launcher_store: Store<ComponentCtx>,
|
||||||
|
pub launcher: launcher_wit::LauncherWidget,
|
||||||
|
pub clock_store: Store<ComponentCtx>,
|
||||||
|
pub clock: clock_wit::ClockWidget,
|
||||||
|
pub wm_store: Store<ComponentCtx>,
|
||||||
|
pub wm: wm_wit::WindowManager,
|
||||||
|
pub deco_store: Store<ComponentCtx>,
|
||||||
|
pub deco: deco_wit::DecorationProvider,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WasmSupervisor {
|
||||||
|
pub fn load_from_dir(components_dir: &Path, theme: ThemeTokens) -> anyhow::Result<Self> {
|
||||||
|
let mut config = Config::new();
|
||||||
|
config.wasm_component_model(true);
|
||||||
|
config.epoch_interruption(true);
|
||||||
|
let engine = Engine::new(&config)?;
|
||||||
|
|
||||||
|
// Spawn 1ms epoch watchdog thread.
|
||||||
|
let engine_weak = engine.clone();
|
||||||
|
std::thread::spawn(move || loop {
|
||||||
|
std::thread::sleep(Duration::from_millis(1));
|
||||||
|
engine_weak.increment_epoch();
|
||||||
|
});
|
||||||
|
|
||||||
|
let shared = SharedHostState::new(theme);
|
||||||
|
|
||||||
|
// Shell
|
||||||
|
let mut shell_linker = Linker::new(&engine);
|
||||||
|
desktop_wit::Shell::add_to_linker::<_, wasmtime::component::HasSelf<ComponentCtx>>(&mut shell_linker, |s| s)?;
|
||||||
|
let shell_comp = Component::from_file(&engine, components_dir.join("shell.wasm"))?;
|
||||||
|
let mut shell_store = Store::new(
|
||||||
|
&engine,
|
||||||
|
ComponentCtx {
|
||||||
|
name: "shell".into(),
|
||||||
|
grants: ["theme"].into_iter().map(String::from).collect(),
|
||||||
|
shared: shared.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
shell_store.set_epoch_deadline(50);
|
||||||
|
let shell = desktop_wit::Shell::instantiate(&mut shell_store, &shell_comp, &shell_linker)?;
|
||||||
|
|
||||||
|
// Launcher
|
||||||
|
let mut launcher_linker = Linker::new(&engine);
|
||||||
|
launcher_wit::LauncherWidget::add_to_linker::<_, wasmtime::component::HasSelf<ComponentCtx>>(&mut launcher_linker, |s| s)?;
|
||||||
|
let launcher_comp = Component::from_file(&engine, components_dir.join("launcher.wasm"))?;
|
||||||
|
let mut launcher_store = Store::new(
|
||||||
|
&engine,
|
||||||
|
ComponentCtx {
|
||||||
|
name: "launcher".into(),
|
||||||
|
grants: ["theme", "app-catalog", "app-launch"].into_iter().map(String::from).collect(),
|
||||||
|
shared: shared.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
launcher_store.set_epoch_deadline(50);
|
||||||
|
let launcher = launcher_wit::LauncherWidget::instantiate(&mut launcher_store, &launcher_comp, &launcher_linker)?;
|
||||||
|
|
||||||
|
// Clock
|
||||||
|
let mut clock_linker = Linker::new(&engine);
|
||||||
|
clock_wit::ClockWidget::add_to_linker::<_, wasmtime::component::HasSelf<ComponentCtx>>(&mut clock_linker, |s| s)?;
|
||||||
|
let clock_comp = Component::from_file(&engine, components_dir.join("clock-digital.wasm"))?;
|
||||||
|
let mut clock_store = Store::new(
|
||||||
|
&engine,
|
||||||
|
ComponentCtx {
|
||||||
|
name: "clock-digital".into(),
|
||||||
|
grants: ["theme", "clock"].into_iter().map(String::from).collect(),
|
||||||
|
shared: shared.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
clock_store.set_epoch_deadline(50);
|
||||||
|
let clock = clock_wit::ClockWidget::instantiate(&mut clock_store, &clock_comp, &clock_linker)?;
|
||||||
|
|
||||||
|
// WM
|
||||||
|
let mut wm_linker = Linker::new(&engine);
|
||||||
|
wm_wit::WindowManager::add_to_linker::<_, wasmtime::component::HasSelf<ComponentCtx>>(&mut wm_linker, |s| s)?;
|
||||||
|
let wm_comp = Component::from_file(&engine, components_dir.join("wm-hybrid.wasm"))?;
|
||||||
|
let mut wm_store = Store::new(
|
||||||
|
&engine,
|
||||||
|
ComponentCtx {
|
||||||
|
name: "wm-hybrid".into(),
|
||||||
|
grants: ["theme"].into_iter().map(String::from).collect(),
|
||||||
|
shared: shared.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
wm_store.set_epoch_deadline(50);
|
||||||
|
let wm = wm_wit::WindowManager::instantiate(&mut wm_store, &wm_comp, &wm_linker)?;
|
||||||
|
|
||||||
|
// Decoration
|
||||||
|
let mut deco_linker = Linker::new(&engine);
|
||||||
|
deco_wit::DecorationProvider::add_to_linker::<_, wasmtime::component::HasSelf<ComponentCtx>>(&mut deco_linker, |s| s)?;
|
||||||
|
let deco_comp = Component::from_file(&engine, components_dir.join("decoration-breeze.wasm"))?;
|
||||||
|
let mut deco_store = Store::new(
|
||||||
|
&engine,
|
||||||
|
ComponentCtx {
|
||||||
|
name: "decoration-breeze".into(),
|
||||||
|
grants: ["theme"].into_iter().map(String::from).collect(),
|
||||||
|
shared: shared.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
deco_store.set_epoch_deadline(50);
|
||||||
|
let deco = deco_wit::DecorationProvider::instantiate(&mut deco_store, &deco_comp, &deco_linker)?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
engine,
|
||||||
|
shared,
|
||||||
|
shell_store,
|
||||||
|
shell,
|
||||||
|
launcher_store,
|
||||||
|
launcher,
|
||||||
|
clock_store,
|
||||||
|
clock,
|
||||||
|
wm_store,
|
||||||
|
wm,
|
||||||
|
deco_store,
|
||||||
|
deco,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn record_fault(&self, component: &str, phase: &str, err: impl std::fmt::Display) {
|
||||||
|
self.shared.faults.lock().unwrap().push(ComponentFault {
|
||||||
|
component: component.to_string(),
|
||||||
|
phase: phase.to_string(),
|
||||||
|
message: err.to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,739 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::os::unix::net::UnixListener;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use memmap2::Mmap;
|
||||||
|
use wayland_protocols::xdg::decoration::zv1::server::{
|
||||||
|
zxdg_decoration_manager_v1::{self, ZxdgDecorationManagerV1},
|
||||||
|
zxdg_toplevel_decoration_v1::{self, Mode as DecoMode, ZxdgToplevelDecorationV1},
|
||||||
|
};
|
||||||
|
use wayland_protocols::xdg::shell::server::{
|
||||||
|
xdg_surface::{self, XdgSurface},
|
||||||
|
xdg_toplevel::{self, XdgToplevel},
|
||||||
|
xdg_wm_base::{self, XdgWmBase},
|
||||||
|
};
|
||||||
|
use wayland_server::protocol::{
|
||||||
|
wl_buffer::{self, WlBuffer},
|
||||||
|
wl_callback::WlCallback,
|
||||||
|
wl_compositor::{self, WlCompositor},
|
||||||
|
wl_keyboard::{self, WlKeyboard},
|
||||||
|
wl_output::{self, WlOutput},
|
||||||
|
wl_pointer::{self, WlPointer},
|
||||||
|
wl_seat::{self, Capability, WlSeat},
|
||||||
|
wl_shm::{self, Format as ShmFormat, WlShm},
|
||||||
|
wl_shm_pool::{self, WlShmPool},
|
||||||
|
wl_surface::{self, WlSurface},
|
||||||
|
};
|
||||||
|
use wayland_server::{
|
||||||
|
Client, DataInit, Dispatch, Display, DisplayHandle, GlobalDispatch, New, Resource,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::scene::ShmBufferSnapshot;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum WaylandEvent {
|
||||||
|
ToplevelOpened {
|
||||||
|
window_id: u64,
|
||||||
|
app_id: String,
|
||||||
|
title: String,
|
||||||
|
min_w: u32,
|
||||||
|
min_h: u32,
|
||||||
|
max_w: Option<u32>,
|
||||||
|
max_h: Option<u32>,
|
||||||
|
},
|
||||||
|
ToplevelClosed {
|
||||||
|
window_id: u64,
|
||||||
|
},
|
||||||
|
SurfaceCommitted {
|
||||||
|
window_id: u64,
|
||||||
|
buffer: Option<ShmBufferSnapshot>,
|
||||||
|
},
|
||||||
|
ToplevelRequest {
|
||||||
|
window_id: u64,
|
||||||
|
maximize: Option<bool>,
|
||||||
|
fullscreen: Option<bool>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ShmPoolData {
|
||||||
|
pub mmap: Arc<Mutex<Mmap>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct BufferData {
|
||||||
|
pub mmap: Arc<Mutex<Mmap>>,
|
||||||
|
pub offset: i32,
|
||||||
|
pub width: i32,
|
||||||
|
pub height: i32,
|
||||||
|
pub stride: i32,
|
||||||
|
pub format: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct SurfaceState {
|
||||||
|
pub pending_buffer: Option<BufferData>,
|
||||||
|
pub current_buffer: Option<BufferData>,
|
||||||
|
pub frame_callbacks: Vec<WlCallback>,
|
||||||
|
pub window_id: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ToplevelRecord {
|
||||||
|
pub window_id: u64,
|
||||||
|
pub surface: WlSurface,
|
||||||
|
pub xdg_surface: XdgSurface,
|
||||||
|
pub toplevel: XdgToplevel,
|
||||||
|
pub app_id: String,
|
||||||
|
pub title: String,
|
||||||
|
pub min_w: u32,
|
||||||
|
pub min_h: u32,
|
||||||
|
pub max_w: Option<u32>,
|
||||||
|
pub max_h: Option<u32>,
|
||||||
|
pub mapped: bool,
|
||||||
|
pub configured_once: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WaylandState {
|
||||||
|
pub next_window_id: u64,
|
||||||
|
pub next_serial: u32,
|
||||||
|
pub surfaces: HashMap<u32, SurfaceState>,
|
||||||
|
pub xdg_surface_to_wl: HashMap<u32, u32>,
|
||||||
|
pub toplevels: HashMap<u64, ToplevelRecord>,
|
||||||
|
pub xdg_toplevel_to_win: HashMap<u32, u64>,
|
||||||
|
pub pointers: Vec<WlPointer>,
|
||||||
|
pub keyboards: Vec<WlKeyboard>,
|
||||||
|
pub events: Vec<WaylandEvent>,
|
||||||
|
pub output_size: (u32, u32),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WaylandState {
|
||||||
|
pub fn new(output_w: u32, output_h: u32) -> Self {
|
||||||
|
Self {
|
||||||
|
next_window_id: 1,
|
||||||
|
next_serial: 1,
|
||||||
|
surfaces: HashMap::new(),
|
||||||
|
xdg_surface_to_wl: HashMap::new(),
|
||||||
|
toplevels: HashMap::new(),
|
||||||
|
xdg_toplevel_to_win: HashMap::new(),
|
||||||
|
pointers: Vec::new(),
|
||||||
|
keyboards: Vec::new(),
|
||||||
|
events: Vec::new(),
|
||||||
|
output_size: (output_w, output_h),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_serial(&mut self) -> u32 {
|
||||||
|
let s = self.next_serial;
|
||||||
|
self.next_serial = self.next_serial.wrapping_add(1);
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn configure_toplevel(&mut self, window_id: u64, w: u32, h: u32, focused: bool) {
|
||||||
|
let serial = self.next_serial();
|
||||||
|
if let Some(rec) = self.toplevels.get(&window_id) {
|
||||||
|
let mut states = Vec::new();
|
||||||
|
if focused {
|
||||||
|
states.push(xdg_toplevel::State::Activated as u8);
|
||||||
|
}
|
||||||
|
// wayland-protocols expects native-endian u32 bytes for states array
|
||||||
|
let state_bytes: Vec<u8> = if focused {
|
||||||
|
(xdg_toplevel::State::Activated as u32).to_ne_bytes().to_vec()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
let _ = states;
|
||||||
|
rec.toplevel.configure(w as i32, h as i32, state_bytes);
|
||||||
|
rec.xdg_surface.configure(serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn close_toplevel(&self, window_id: u64) {
|
||||||
|
if let Some(rec) = self.toplevels.get(&window_id) {
|
||||||
|
rec.toplevel.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn flush_frame_callbacks(&mut self, time_ms: u32) {
|
||||||
|
for surf in self.surfaces.values_mut() {
|
||||||
|
for cb in surf.frame_callbacks.drain(..) {
|
||||||
|
cb.done(time_ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ClientState;
|
||||||
|
impl wayland_server::backend::ClientData for ClientState {
|
||||||
|
fn initialized(&self, _client_id: wayland_server::backend::ClientId) {}
|
||||||
|
fn disconnected(
|
||||||
|
&self,
|
||||||
|
_client_id: wayland_server::backend::ClientId,
|
||||||
|
_reason: wayland_server::backend::DisconnectReason,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Globals & Dispatchers ---
|
||||||
|
|
||||||
|
impl GlobalDispatch<WlCompositor, ()> for WaylandState {
|
||||||
|
fn bind(
|
||||||
|
_state: &mut Self,
|
||||||
|
_handle: &DisplayHandle,
|
||||||
|
_client: &Client,
|
||||||
|
resource: New<WlCompositor>,
|
||||||
|
_global_data: &(),
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
data_init.init(resource, ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlCompositor, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlCompositor,
|
||||||
|
request: wl_compositor::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
if let wl_compositor::Request::CreateSurface { id } = request {
|
||||||
|
let surf = data_init.init(id, ());
|
||||||
|
state.surfaces.insert(surf.id().protocol_id(), SurfaceState::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlSurface, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
resource: &WlSurface,
|
||||||
|
request: wl_surface::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
let sid = resource.id().protocol_id();
|
||||||
|
match request {
|
||||||
|
wl_surface::Request::Attach { buffer, .. } => {
|
||||||
|
if let Some(surf) = state.surfaces.get_mut(&sid) {
|
||||||
|
surf.pending_buffer = buffer.and_then(|b| b.data::<BufferData>().cloned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wl_surface::Request::Frame { callback } => {
|
||||||
|
let cb = data_init.init(callback, ());
|
||||||
|
if let Some(surf) = state.surfaces.get_mut(&sid) {
|
||||||
|
surf.frame_callbacks.push(cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wl_surface::Request::Commit => {
|
||||||
|
let (win_id, snapshot) = {
|
||||||
|
let surf = match state.surfaces.get_mut(&sid) {
|
||||||
|
Some(s) => s,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
if let Some(pending) = surf.pending_buffer.take() {
|
||||||
|
surf.current_buffer = Some(pending);
|
||||||
|
}
|
||||||
|
let snap = surf.current_buffer.as_ref().map(|b| {
|
||||||
|
let guard = b.mmap.lock().unwrap();
|
||||||
|
let start = b.offset.max(0) as usize;
|
||||||
|
let len = (b.stride.max(0) as usize) * (b.height.max(0) as usize);
|
||||||
|
let end = (start + len).min(guard.len());
|
||||||
|
ShmBufferSnapshot {
|
||||||
|
width: b.width.max(0) as u32,
|
||||||
|
height: b.height.max(0) as u32,
|
||||||
|
stride: b.stride.max(0) as u32,
|
||||||
|
format: b.format,
|
||||||
|
bytes: if start <= end {
|
||||||
|
guard[start..end].to_vec()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
(surf.window_id, snap)
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(wid) = win_id {
|
||||||
|
let mut open_evt = None;
|
||||||
|
if let Some(rec) = state.toplevels.get_mut(&wid) {
|
||||||
|
if !rec.mapped {
|
||||||
|
rec.mapped = true;
|
||||||
|
open_evt = Some(WaylandEvent::ToplevelOpened {
|
||||||
|
window_id: wid,
|
||||||
|
app_id: rec.app_id.clone(),
|
||||||
|
title: rec.title.clone(),
|
||||||
|
min_w: rec.min_w,
|
||||||
|
min_h: rec.min_h,
|
||||||
|
max_w: rec.max_w,
|
||||||
|
max_h: rec.max_h,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(evt) = open_evt {
|
||||||
|
state.events.push(evt);
|
||||||
|
}
|
||||||
|
if snapshot.is_some() {
|
||||||
|
state.events.push(WaylandEvent::SurfaceCommitted {
|
||||||
|
window_id: wid,
|
||||||
|
buffer: snapshot,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wl_surface::Request::Destroy => {
|
||||||
|
state.surfaces.remove(&sid);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlCallback, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlCallback,
|
||||||
|
_request: wayland_server::protocol::wl_callback::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
_data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GlobalDispatch<WlShm, ()> for WaylandState {
|
||||||
|
fn bind(
|
||||||
|
_state: &mut Self,
|
||||||
|
_handle: &DisplayHandle,
|
||||||
|
_client: &Client,
|
||||||
|
resource: New<WlShm>,
|
||||||
|
_global_data: &(),
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
let shm = data_init.init(resource, ());
|
||||||
|
shm.format(ShmFormat::Argb8888);
|
||||||
|
shm.format(ShmFormat::Xrgb8888);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlShm, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlShm,
|
||||||
|
request: wl_shm::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
if let wl_shm::Request::CreatePool { id, fd, size } = request {
|
||||||
|
let mmap = unsafe {
|
||||||
|
Mmap::map(&fd).expect("failed to mmap wl_shm_pool fd")
|
||||||
|
};
|
||||||
|
let _ = size;
|
||||||
|
data_init.init(
|
||||||
|
id,
|
||||||
|
ShmPoolData {
|
||||||
|
mmap: Arc::new(Mutex::new(mmap)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlShmPool, ShmPoolData> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlShmPool,
|
||||||
|
request: wl_shm_pool::Request,
|
||||||
|
data: &ShmPoolData,
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
if let wl_shm_pool::Request::CreateBuffer {
|
||||||
|
id,
|
||||||
|
offset,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
stride,
|
||||||
|
format,
|
||||||
|
} = request
|
||||||
|
{
|
||||||
|
let fmt_u32 = match format {
|
||||||
|
wayland_server::WEnum::Value(f) => f as u32,
|
||||||
|
wayland_server::WEnum::Unknown(v) => v,
|
||||||
|
};
|
||||||
|
data_init.init(
|
||||||
|
id,
|
||||||
|
BufferData {
|
||||||
|
mmap: data.mmap.clone(),
|
||||||
|
offset,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
stride,
|
||||||
|
format: fmt_u32,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlBuffer, BufferData> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlBuffer,
|
||||||
|
_request: wl_buffer::Request,
|
||||||
|
_data: &BufferData,
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
_data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GlobalDispatch<XdgWmBase, ()> for WaylandState {
|
||||||
|
fn bind(
|
||||||
|
_state: &mut Self,
|
||||||
|
_handle: &DisplayHandle,
|
||||||
|
_client: &Client,
|
||||||
|
resource: New<XdgWmBase>,
|
||||||
|
_global_data: &(),
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
data_init.init(resource, ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<XdgWmBase, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &XdgWmBase,
|
||||||
|
request: xdg_wm_base::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
if let xdg_wm_base::Request::GetXdgSurface { id, surface } = request {
|
||||||
|
let sid = surface.id().protocol_id();
|
||||||
|
let xdg_surf = data_init.init(id, surface);
|
||||||
|
state.xdg_surface_to_wl.insert(xdg_surf.id().protocol_id(), sid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<XdgSurface, WlSurface> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
resource: &XdgSurface,
|
||||||
|
request: xdg_surface::Request,
|
||||||
|
wl_surface: &WlSurface,
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
if let xdg_surface::Request::GetToplevel { id } = request {
|
||||||
|
let wid = state.next_window_id;
|
||||||
|
state.next_window_id += 1;
|
||||||
|
let toplevel = data_init.init(id, wid);
|
||||||
|
let sid = wl_surface.id().protocol_id();
|
||||||
|
if let Some(s) = state.surfaces.get_mut(&sid) {
|
||||||
|
s.window_id = Some(wid);
|
||||||
|
}
|
||||||
|
state.xdg_toplevel_to_win.insert(toplevel.id().protocol_id(), wid);
|
||||||
|
state.toplevels.insert(
|
||||||
|
wid,
|
||||||
|
ToplevelRecord {
|
||||||
|
window_id: wid,
|
||||||
|
surface: wl_surface.clone(),
|
||||||
|
xdg_surface: resource.clone(),
|
||||||
|
toplevel: toplevel.clone(),
|
||||||
|
app_id: String::new(),
|
||||||
|
title: String::new(),
|
||||||
|
min_w: 120,
|
||||||
|
min_h: 80,
|
||||||
|
max_w: None,
|
||||||
|
max_h: None,
|
||||||
|
mapped: false,
|
||||||
|
configured_once: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<XdgToplevel, u64> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &XdgToplevel,
|
||||||
|
request: xdg_toplevel::Request,
|
||||||
|
wid: &u64,
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
_data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
let wid = *wid;
|
||||||
|
match request {
|
||||||
|
xdg_toplevel::Request::SetTitle { title } => {
|
||||||
|
if let Some(rec) = state.toplevels.get_mut(&wid) {
|
||||||
|
rec.title = title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::SetAppId { app_id } => {
|
||||||
|
if let Some(rec) = state.toplevels.get_mut(&wid) {
|
||||||
|
rec.app_id = app_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::SetMinSize { width, height } => {
|
||||||
|
if let Some(rec) = state.toplevels.get_mut(&wid) {
|
||||||
|
rec.min_w = width.max(0) as u32;
|
||||||
|
rec.min_h = height.max(0) as u32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::SetMaxSize { width, height } => {
|
||||||
|
if let Some(rec) = state.toplevels.get_mut(&wid) {
|
||||||
|
rec.max_w = if width > 0 { Some(width as u32) } else { None };
|
||||||
|
rec.max_h = if height > 0 { Some(height as u32) } else { None };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::SetMaximized => {
|
||||||
|
state.events.push(WaylandEvent::ToplevelRequest {
|
||||||
|
window_id: wid,
|
||||||
|
maximize: Some(true),
|
||||||
|
fullscreen: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::UnsetMaximized => {
|
||||||
|
state.events.push(WaylandEvent::ToplevelRequest {
|
||||||
|
window_id: wid,
|
||||||
|
maximize: Some(false),
|
||||||
|
fullscreen: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::SetFullscreen { .. } => {
|
||||||
|
state.events.push(WaylandEvent::ToplevelRequest {
|
||||||
|
window_id: wid,
|
||||||
|
maximize: None,
|
||||||
|
fullscreen: Some(true),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::UnsetFullscreen => {
|
||||||
|
state.events.push(WaylandEvent::ToplevelRequest {
|
||||||
|
window_id: wid,
|
||||||
|
maximize: None,
|
||||||
|
fullscreen: Some(false),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::Destroy => {
|
||||||
|
state.toplevels.remove(&wid);
|
||||||
|
state.events.push(WaylandEvent::ToplevelClosed { window_id: wid });
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GlobalDispatch<ZxdgDecorationManagerV1, ()> for WaylandState {
|
||||||
|
fn bind(
|
||||||
|
_state: &mut Self,
|
||||||
|
_handle: &DisplayHandle,
|
||||||
|
_client: &Client,
|
||||||
|
resource: New<ZxdgDecorationManagerV1>,
|
||||||
|
_global_data: &(),
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
data_init.init(resource, ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<ZxdgDecorationManagerV1, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &ZxdgDecorationManagerV1,
|
||||||
|
request: zxdg_decoration_manager_v1::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
if let zxdg_decoration_manager_v1::Request::GetToplevelDecoration { id, .. } = request {
|
||||||
|
let deco = data_init.init(id, ());
|
||||||
|
// Default to Server-Side Decoration (rendered by decoration-breeze.wasm)
|
||||||
|
deco.configure(DecoMode::ServerSide);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<ZxdgToplevelDecorationV1, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
resource: &ZxdgToplevelDecorationV1,
|
||||||
|
request: zxdg_toplevel_decoration_v1::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
_data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
if let zxdg_toplevel_decoration_v1::Request::SetMode { .. } = request {
|
||||||
|
resource.configure(DecoMode::ServerSide);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GlobalDispatch<WlSeat, ()> for WaylandState {
|
||||||
|
fn bind(
|
||||||
|
_state: &mut Self,
|
||||||
|
_handle: &DisplayHandle,
|
||||||
|
_client: &Client,
|
||||||
|
resource: New<WlSeat>,
|
||||||
|
_global_data: &(),
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
let seat = data_init.init(resource, ());
|
||||||
|
seat.capabilities(Capability::Pointer | Capability::Keyboard);
|
||||||
|
seat.name("seat0".into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlSeat, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlSeat,
|
||||||
|
request: wl_seat::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
match request {
|
||||||
|
wl_seat::Request::GetPointer { id } => {
|
||||||
|
state.pointers.push(data_init.init(id, ()));
|
||||||
|
}
|
||||||
|
wl_seat::Request::GetKeyboard { id } => {
|
||||||
|
state.keyboards.push(data_init.init(id, ()));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlPointer, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlPointer,
|
||||||
|
_request: wl_pointer::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
_data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlKeyboard, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlKeyboard,
|
||||||
|
_request: wl_keyboard::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
_data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GlobalDispatch<WlOutput, ()> for WaylandState {
|
||||||
|
fn bind(
|
||||||
|
state: &mut Self,
|
||||||
|
_handle: &DisplayHandle,
|
||||||
|
_client: &Client,
|
||||||
|
resource: New<WlOutput>,
|
||||||
|
_global_data: &(),
|
||||||
|
data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
let out = data_init.init(resource, ());
|
||||||
|
let (w, h) = state.output_size;
|
||||||
|
out.geometry(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
w as i32 / 4,
|
||||||
|
h as i32 / 4,
|
||||||
|
wl_output::Subpixel::Unknown,
|
||||||
|
"moon-plasma".into(),
|
||||||
|
"virtual-output".into(),
|
||||||
|
wl_output::Transform::Normal,
|
||||||
|
);
|
||||||
|
out.mode(wl_output::Mode::Current | wl_output::Mode::Preferred, w as i32, h as i32, 60000);
|
||||||
|
out.scale(1);
|
||||||
|
out.done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlOutput, ()> for WaylandState {
|
||||||
|
fn request(
|
||||||
|
_state: &mut Self,
|
||||||
|
_client: &Client,
|
||||||
|
_resource: &WlOutput,
|
||||||
|
_request: wl_output::Request,
|
||||||
|
_data: &(),
|
||||||
|
_dhandle: &DisplayHandle,
|
||||||
|
_data_init: &mut DataInit<'_, Self>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WaylandServer {
|
||||||
|
pub display: Display<WaylandState>,
|
||||||
|
pub state: WaylandState,
|
||||||
|
pub listener: UnixListener,
|
||||||
|
pub socket_path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WaylandServer {
|
||||||
|
pub fn bind(socket_path: &Path, output_w: u32, output_h: u32) -> anyhow::Result<Self> {
|
||||||
|
if socket_path.exists() {
|
||||||
|
let _ = std::fs::remove_file(socket_path);
|
||||||
|
}
|
||||||
|
let listener = UnixListener::bind(socket_path)?;
|
||||||
|
listener.set_nonblocking(true)?;
|
||||||
|
|
||||||
|
let display: Display<WaylandState> = Display::new()?;
|
||||||
|
let dh = display.handle();
|
||||||
|
dh.create_global::<WaylandState, WlCompositor, _>(5, ());
|
||||||
|
dh.create_global::<WaylandState, WlShm, _>(1, ());
|
||||||
|
dh.create_global::<WaylandState, XdgWmBase, _>(5, ());
|
||||||
|
dh.create_global::<WaylandState, ZxdgDecorationManagerV1, _>(1, ());
|
||||||
|
dh.create_global::<WaylandState, WlSeat, _>(7, ());
|
||||||
|
dh.create_global::<WaylandState, WlOutput, _>(4, ());
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
display,
|
||||||
|
state: WaylandState::new(output_w, output_h),
|
||||||
|
listener,
|
||||||
|
socket_path: socket_path.to_path_buf(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dispatch(&mut self) -> anyhow::Result<()> {
|
||||||
|
loop {
|
||||||
|
match self.listener.accept() {
|
||||||
|
Ok((stream, _)) => {
|
||||||
|
self.display
|
||||||
|
.handle()
|
||||||
|
.insert_client(stream, Arc::new(ClientState))?;
|
||||||
|
}
|
||||||
|
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => break,
|
||||||
|
Err(e) => return Err(e.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.display.dispatch_clients(&mut self.state)?;
|
||||||
|
self.display.flush_clients()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::os::fd::AsFd;
|
||||||
|
use std::os::unix::net::UnixStream;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use moon_plasma_host::compositor::MoonPlasmaCompositor;
|
||||||
|
use moon_plasma_host::renderer::SoftwareRenderer;
|
||||||
|
use moon_plasma_host::theme::ThemeTokens;
|
||||||
|
use moon_plasma_host::wasm::wm_wit::exports::moonplasma::wm::policy::LayoutMode;
|
||||||
|
|
||||||
|
use wayland_client::protocol::{
|
||||||
|
wl_buffer::WlBuffer,
|
||||||
|
wl_compositor::WlCompositor,
|
||||||
|
wl_registry::{self, WlRegistry},
|
||||||
|
wl_shm::{self, WlShm},
|
||||||
|
wl_shm_pool::WlShmPool,
|
||||||
|
wl_surface::WlSurface,
|
||||||
|
};
|
||||||
|
use wayland_client::{Connection, Dispatch, QueueHandle, WEnum};
|
||||||
|
use wayland_protocols::xdg::decoration::zv1::client::{
|
||||||
|
zxdg_decoration_manager_v1::ZxdgDecorationManagerV1,
|
||||||
|
zxdg_toplevel_decoration_v1::{self, Mode as DecoMode, ZxdgToplevelDecorationV1},
|
||||||
|
};
|
||||||
|
use wayland_protocols::xdg::shell::client::{
|
||||||
|
xdg_surface::{self, XdgSurface},
|
||||||
|
xdg_toplevel::{self, XdgToplevel},
|
||||||
|
xdg_wm_base::{self, XdgWmBase},
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ClientData {
|
||||||
|
compositor: Option<WlCompositor>,
|
||||||
|
shm: Option<WlShm>,
|
||||||
|
xdg_wm_base: Option<XdgWmBase>,
|
||||||
|
deco_mgr: Option<ZxdgDecorationManagerV1>,
|
||||||
|
configured_size: Arc<Mutex<Option<(i32, i32)>>>,
|
||||||
|
deco_mode: Arc<Mutex<Option<DecoMode>>>,
|
||||||
|
acked_serial: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlRegistry, ()> for ClientData {
|
||||||
|
fn event(
|
||||||
|
state: &mut Self,
|
||||||
|
registry: &WlRegistry,
|
||||||
|
event: wl_registry::Event,
|
||||||
|
_: &(),
|
||||||
|
_: &Connection,
|
||||||
|
qh: &QueueHandle<Self>,
|
||||||
|
) {
|
||||||
|
if let wl_registry::Event::Global { name, interface, version } = event {
|
||||||
|
match interface.as_str() {
|
||||||
|
"wl_compositor" => {
|
||||||
|
state.compositor = Some(registry.bind::<WlCompositor, _, _>(name, version.min(5), qh, ()));
|
||||||
|
}
|
||||||
|
"wl_shm" => {
|
||||||
|
state.shm = Some(registry.bind::<WlShm, _, _>(name, 1, qh, ()));
|
||||||
|
}
|
||||||
|
"xdg_wm_base" => {
|
||||||
|
state.xdg_wm_base = Some(registry.bind::<XdgWmBase, _, _>(name, version.min(5), qh, ()));
|
||||||
|
}
|
||||||
|
"zxdg_decoration_manager_v1" => {
|
||||||
|
state.deco_mgr = Some(registry.bind::<ZxdgDecorationManagerV1, _, _>(name, 1, qh, ()));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<WlCompositor, ()> for ClientData {
|
||||||
|
fn event(_: &mut Self, _: &WlCompositor, _: wayland_client::protocol::wl_compositor::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {}
|
||||||
|
}
|
||||||
|
impl Dispatch<WlSurface, ()> for ClientData {
|
||||||
|
fn event(_: &mut Self, _: &WlSurface, _: wayland_client::protocol::wl_surface::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {}
|
||||||
|
}
|
||||||
|
impl Dispatch<WlShm, ()> for ClientData {
|
||||||
|
fn event(_: &mut Self, _: &WlShm, _: wl_shm::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {}
|
||||||
|
}
|
||||||
|
impl Dispatch<WlShmPool, ()> for ClientData {
|
||||||
|
fn event(_: &mut Self, _: &WlShmPool, _: wayland_client::protocol::wl_shm_pool::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {}
|
||||||
|
}
|
||||||
|
impl Dispatch<WlBuffer, ()> for ClientData {
|
||||||
|
fn event(_: &mut Self, _: &WlBuffer, _: wayland_client::protocol::wl_buffer::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {}
|
||||||
|
}
|
||||||
|
impl Dispatch<XdgWmBase, ()> for ClientData {
|
||||||
|
fn event(_: &mut Self, wm: &XdgWmBase, event: xdg_wm_base::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {
|
||||||
|
if let xdg_wm_base::Event::Ping { serial } = event {
|
||||||
|
wm.pong(serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Dispatch<XdgSurface, ()> for ClientData {
|
||||||
|
fn event(state: &mut Self, surf: &XdgSurface, event: xdg_surface::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {
|
||||||
|
if let xdg_surface::Event::Configure { serial } = event {
|
||||||
|
surf.ack_configure(serial);
|
||||||
|
state.acked_serial = Some(serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Dispatch<XdgToplevel, ()> for ClientData {
|
||||||
|
fn event(state: &mut Self, _: &XdgToplevel, event: xdg_toplevel::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {
|
||||||
|
if let xdg_toplevel::Event::Configure { width, height, .. } = event {
|
||||||
|
if width > 0 && height > 0 {
|
||||||
|
*state.configured_size.lock().unwrap() = Some((width, height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Dispatch<ZxdgDecorationManagerV1, ()> for ClientData {
|
||||||
|
fn event(_: &mut Self, _: &ZxdgDecorationManagerV1, _: wayland_protocols::xdg::decoration::zv1::client::zxdg_decoration_manager_v1::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {}
|
||||||
|
}
|
||||||
|
impl Dispatch<ZxdgToplevelDecorationV1, ()> for ClientData {
|
||||||
|
fn event(state: &mut Self, _: &ZxdgToplevelDecorationV1, event: zxdg_toplevel_decoration_v1::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {
|
||||||
|
if let zxdg_toplevel_decoration_v1::Event::Configure { mode } = event {
|
||||||
|
if let WEnum::Value(m) = mode {
|
||||||
|
*state.deco_mode.lock().unwrap() = Some(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_wayland_test_client(
|
||||||
|
socket_path: PathBuf,
|
||||||
|
title: &'static str,
|
||||||
|
app_id: &'static str,
|
||||||
|
shm_dir: PathBuf,
|
||||||
|
idx: usize,
|
||||||
|
) -> (
|
||||||
|
std::thread::JoinHandle<()>,
|
||||||
|
Arc<Mutex<Option<(i32, i32)>>>,
|
||||||
|
Arc<Mutex<Option<DecoMode>>>,
|
||||||
|
) {
|
||||||
|
let configured_size = Arc::new(Mutex::new(None));
|
||||||
|
let deco_mode = Arc::new(Mutex::new(None));
|
||||||
|
let cfg_clone = configured_size.clone();
|
||||||
|
let deco_clone = deco_mode.clone();
|
||||||
|
|
||||||
|
let handle = std::thread::spawn(move || {
|
||||||
|
let stream = UnixStream::connect(&socket_path).expect("connect to wayland socket");
|
||||||
|
let conn = Connection::from_socket(stream).expect("wayland Connection::from_socket");
|
||||||
|
let mut queue = conn.new_event_queue();
|
||||||
|
let qh = queue.handle();
|
||||||
|
let display = conn.display();
|
||||||
|
let mut data = ClientData {
|
||||||
|
compositor: None,
|
||||||
|
shm: None,
|
||||||
|
xdg_wm_base: None,
|
||||||
|
deco_mgr: None,
|
||||||
|
configured_size: cfg_clone.clone(),
|
||||||
|
deco_mode: deco_clone,
|
||||||
|
acked_serial: None,
|
||||||
|
};
|
||||||
|
let _reg = display.get_registry(&qh, ());
|
||||||
|
queue.roundtrip(&mut data).expect("roundtrip 1");
|
||||||
|
|
||||||
|
let comp = data.compositor.as_ref().expect("wl_compositor").clone();
|
||||||
|
let shm = data.shm.as_ref().expect("wl_shm").clone();
|
||||||
|
let wm_base = data.xdg_wm_base.as_ref().expect("xdg_wm_base").clone();
|
||||||
|
let deco_mgr = data.deco_mgr.as_ref().expect("zxdg_decoration_manager_v1").clone();
|
||||||
|
|
||||||
|
let surface = comp.create_surface(&qh, ());
|
||||||
|
let xdg_surf = wm_base.get_xdg_surface(&surface, &qh, ());
|
||||||
|
let toplevel = xdg_surf.get_toplevel(&qh, ());
|
||||||
|
toplevel.set_title(title.into());
|
||||||
|
toplevel.set_app_id(app_id.into());
|
||||||
|
let _deco = deco_mgr.get_toplevel_decoration(&toplevel, &qh, ());
|
||||||
|
|
||||||
|
// Initial commit triggers ToplevelOpened -> WM configure
|
||||||
|
surface.commit();
|
||||||
|
conn.flush().unwrap();
|
||||||
|
|
||||||
|
let deadline = Instant::now() + Duration::from_secs(3);
|
||||||
|
while cfg_clone.lock().unwrap().is_none() && Instant::now() < deadline {
|
||||||
|
let _ = queue.dispatch_pending(&mut data);
|
||||||
|
if let Some(guard) = conn.prepare_read() {
|
||||||
|
let _ = guard.read();
|
||||||
|
}
|
||||||
|
let _ = queue.dispatch_pending(&mut data);
|
||||||
|
std::thread::sleep(Duration::from_millis(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (w, h) = cfg_clone.lock().unwrap().expect("received WM configure size");
|
||||||
|
|
||||||
|
// Create backing SHM file and fill with slate #1e293b + cyan #38bdf8 center square
|
||||||
|
let stride = w * 4;
|
||||||
|
let byte_len = (stride * h) as usize;
|
||||||
|
let shm_file_path = shm_dir.join(format!("client-{idx}.shm"));
|
||||||
|
let file = File::options()
|
||||||
|
.read(true)
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(&shm_file_path)
|
||||||
|
.unwrap();
|
||||||
|
file.set_len(byte_len as u64).unwrap();
|
||||||
|
let mut pixels = vec![0u8; byte_len];
|
||||||
|
for y in 0..h {
|
||||||
|
for x in 0..w {
|
||||||
|
let off = ((y * w + x) * 4) as usize;
|
||||||
|
let in_center = (x - w / 2).abs() < 40 && (y - h / 2).abs() < 40;
|
||||||
|
// Little-endian ARGB8888: [B, G, R, A]
|
||||||
|
if in_center {
|
||||||
|
pixels[off] = 0xf8;
|
||||||
|
pixels[off + 1] = 0xbd;
|
||||||
|
pixels[off + 2] = 0x38;
|
||||||
|
pixels[off + 3] = 0xff;
|
||||||
|
} else {
|
||||||
|
pixels[off] = 0x3b;
|
||||||
|
pixels[off + 1] = 0x29;
|
||||||
|
pixels[off + 2] = 0x1e;
|
||||||
|
pixels[off + 3] = 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
use std::io::Write;
|
||||||
|
(&file).write_all(&pixels).unwrap();
|
||||||
|
|
||||||
|
let pool = shm.create_pool(file.as_fd(), byte_len as i32, &qh, ());
|
||||||
|
let buffer = pool.create_buffer(0, w, h, stride, wl_shm::Format::Argb8888, &qh, ());
|
||||||
|
surface.attach(Some(&buffer), 0, 0);
|
||||||
|
surface.damage_buffer(0, 0, w, h);
|
||||||
|
surface.commit();
|
||||||
|
conn.flush().unwrap();
|
||||||
|
|
||||||
|
std::thread::sleep(Duration::from_millis(150));
|
||||||
|
});
|
||||||
|
|
||||||
|
(handle, configured_size, deco_mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn e2e_wayland_client_with_moonbit_wm_and_ssd_decorations() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let socket_path = tmp.path().join("wayland-moon-0");
|
||||||
|
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).parent().unwrap().to_path_buf();
|
||||||
|
let components_dir = root.join("build/components");
|
||||||
|
let theme = ThemeTokens::load_file(&root.join("config/themes/moon-night.json")).unwrap();
|
||||||
|
|
||||||
|
let mut comp = MoonPlasmaCompositor::new(&socket_path, &components_dir, theme, 1280, 720)
|
||||||
|
.expect("boot compositor");
|
||||||
|
|
||||||
|
let (c1, cfg1, deco1) = spawn_wayland_test_client(
|
||||||
|
socket_path.clone(),
|
||||||
|
"MoonTerm",
|
||||||
|
"org.moonplasma.term",
|
||||||
|
tmp.path().to_path_buf(),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
|
let deadline = Instant::now() + Duration::from_secs(3);
|
||||||
|
while Instant::now() < deadline {
|
||||||
|
comp.step().unwrap();
|
||||||
|
if comp.windows.get(&1).and_then(|w| w.surface.as_ref()).is_some() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::thread::sleep(Duration::from_millis(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(*deco1.lock().unwrap(), Some(DecoMode::ServerSide));
|
||||||
|
let (cw, ch) = cfg1.lock().unwrap().expect("client 1 configured");
|
||||||
|
assert!(cw > 1200 && ch > 600, "unexpected tiled size: {cw}x{ch}");
|
||||||
|
|
||||||
|
let pixmap = comp.compose_frame().expect("compose frame");
|
||||||
|
let out_png = root.join("host-native/target/e2e_frame.png");
|
||||||
|
SoftwareRenderer::save_png(&pixmap, &out_png).unwrap();
|
||||||
|
|
||||||
|
// Verify client surface center pixel (#38bdf8) landed inside the WM-assigned geometry!
|
||||||
|
let win = comp.windows.get(&1).unwrap();
|
||||||
|
let cx = win.geometry.x + (win.geometry.w as i32) / 2;
|
||||||
|
let cy = win.geometry.y + (win.geometry.h as i32) / 2;
|
||||||
|
let px = pixmap.pixel(cx as u32, cy as u32).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
(px.red(), px.green(), px.blue(), px.alpha()),
|
||||||
|
(0x38, 0xbd, 0xf8, 0xff),
|
||||||
|
"expected cyan client pixel at ({cx}, {cy})"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify 0 component faults
|
||||||
|
assert!(
|
||||||
|
comp.wasm.shared.faults.lock().unwrap().is_empty(),
|
||||||
|
"unexpected faults: {:?}",
|
||||||
|
comp.wasm.shared.faults.lock().unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Now open a 2nd Wayland client and verify BSP tiling splits the screen!
|
||||||
|
let (c2, cfg2, _) = spawn_wayland_test_client(
|
||||||
|
socket_path.clone(),
|
||||||
|
"Files",
|
||||||
|
"org.moonplasma.files",
|
||||||
|
tmp.path().to_path_buf(),
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
|
||||||
|
let deadline2 = Instant::now() + Duration::from_secs(3);
|
||||||
|
while Instant::now() < deadline2 {
|
||||||
|
comp.step().unwrap();
|
||||||
|
if comp.windows.get(&2).and_then(|w| w.surface.as_ref()).is_some() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::thread::sleep(Duration::from_millis(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (cw2, _) = cfg2.lock().unwrap().expect("client 2 configured");
|
||||||
|
assert!(cw2 < 700, "expected BSP split width < 700, got {cw2}");
|
||||||
|
|
||||||
|
// Test layout mode switch to Floating
|
||||||
|
comp.set_layout_mode(LayoutMode::Floating);
|
||||||
|
let _ = comp.compose_frame().unwrap();
|
||||||
|
|
||||||
|
let _ = c1.join();
|
||||||
|
let _ = c2.join();
|
||||||
|
}
|
||||||
@@ -3,17 +3,20 @@
|
|||||||
///|
|
///|
|
||||||
fn wasmImportGetTokens(p0 : Int) = "moonplasma:desktop/theme@0.1.0" "get-tokens"
|
fn wasmImportGetTokens(p0 : Int) = "moonplasma:desktop/theme@0.1.0" "get-tokens"
|
||||||
|
|
||||||
///|
|
|
||||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
|
||||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
|
||||||
|
|
||||||
///|
|
///|
|
||||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
///|
|
///|
|
||||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
#|(func (param i32) (param i32) (result i32)
|
||||||
|
#| local.get 0
|
||||||
|
#| local.get 1 call $moonbit.init_array16
|
||||||
|
#| local.get 0)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
///|
|
///|
|
||||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||||
@@ -23,9 +26,6 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
|||||||
#| local.get 1)
|
#| local.get 1)
|
||||||
|
|
||||||
///|
|
///|
|
||||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||||
#|(func (param i32) (param i32) (result i32)
|
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||||
#| local.get 0
|
|
||||||
#| local.get 1 call $moonbit.init_array16
|
|
||||||
#| local.get 0)
|
|
||||||
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportSyncWindows(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) = "moonplasma:wm/policy@0.2.0" "sync-windows"
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportOnWindowOpen(p0 : Int, p1 : Int) = "moonplasma:wm/policy@0.2.0" "on-window-open"
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportOnWindowClose(p0 : Int64, p1 : Int) = "moonplasma:wm/policy@0.2.0" "on-window-close"
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportOnWindowRequest(p0 : Int64, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int) = "moonplasma:wm/policy@0.2.0" "on-window-request"
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportOnPointer(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) = "moonplasma:wm/policy@0.2.0" "on-pointer"
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportSetLayoutMode(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) = "moonplasma:wm/policy@0.2.0" "set-layout-mode"
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn wasmImportStackingOrder(p0 : Int) = "moonplasma:wm/policy@0.2.0" "stacking-order"
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||||
|
#|(func (param i32) (result i32) (local i32)
|
||||||
|
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||||
|
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||||
|
#| local.get 1)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||||
|
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||||
|
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||||
|
|
||||||
|
///|
|
||||||
|
#owned(str)
|
||||||
|
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||||
|
#|(func (param i32) (result i32) local.get 0)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
|
||||||
|
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||||
|
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/interface/moonplasma/wm/policy"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn on_pointer(@types.Point, UInt32?, Bool) -> InputTarget
|
||||||
|
|
||||||
|
pub fn on_window_close(UInt64) -> Array[WmAction]
|
||||||
|
|
||||||
|
pub fn on_window_open(WindowState, @types.Rect) -> Array[WmAction]
|
||||||
|
|
||||||
|
pub fn on_window_request(UInt64, WindowRequest, @types.Rect) -> Array[WmAction]
|
||||||
|
|
||||||
|
pub fn set_layout_mode(LayoutMode, @types.Rect) -> Array[WmAction]
|
||||||
|
|
||||||
|
pub fn stacking_order() -> Array[UInt64]
|
||||||
|
|
||||||
|
pub fn sync_windows(Array[@types.Rect], Array[WindowState]) -> Array[WmAction]
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
pub(all) enum InputTarget {
|
||||||
|
Client((UInt64, @types.Point))
|
||||||
|
Decoration((UInt64, @types.Point))
|
||||||
|
ShellPanel(@types.Point)
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum LayoutMode {
|
||||||
|
FLOATING
|
||||||
|
TILING
|
||||||
|
MONOCLE
|
||||||
|
}
|
||||||
|
pub fn LayoutMode::from(Int32) -> Self
|
||||||
|
pub fn LayoutMode::ordinal(Self) -> Int32
|
||||||
|
|
||||||
|
pub(all) struct WindowCaps(Byte)
|
||||||
|
pub fn WindowCaps::default() -> Self
|
||||||
|
pub fn WindowCaps::is_set(Self, WindowCapsFlag) -> Bool
|
||||||
|
pub fn WindowCaps::set(Self, WindowCapsFlag) -> Self
|
||||||
|
pub fn WindowCaps::unset(Self, WindowCapsFlag) -> Self
|
||||||
|
|
||||||
|
pub(all) enum WindowCapsFlag {
|
||||||
|
CAN_MOVE
|
||||||
|
CAN_RESIZE
|
||||||
|
CAN_MAXIMIZE
|
||||||
|
CAN_MINIMIZE
|
||||||
|
CAN_FULLSCREEN
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum WindowRequest {
|
||||||
|
Maximize(Bool)
|
||||||
|
Fullscreen(Bool)
|
||||||
|
Minimize(Bool)
|
||||||
|
Close
|
||||||
|
Activate
|
||||||
|
MoveTo(@types.Point)
|
||||||
|
ResizeTo(@types.Size)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct WindowState {
|
||||||
|
id : UInt64
|
||||||
|
app_id : String
|
||||||
|
title : String
|
||||||
|
geometry : @types.Rect
|
||||||
|
min_size : @types.Size
|
||||||
|
max_size : @types.Size?
|
||||||
|
focused : Bool
|
||||||
|
maximized : Bool
|
||||||
|
fullscreen : Bool
|
||||||
|
workspace : UInt32
|
||||||
|
caps : WindowCaps
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) enum WmAction {
|
||||||
|
SetGeometry((UInt64, @types.Rect))
|
||||||
|
Focus(UInt64)
|
||||||
|
Raise(UInt64)
|
||||||
|
Close(UInt64)
|
||||||
|
SetMaximized((UInt64, Bool))
|
||||||
|
SetFullscreen((UInt64, Bool))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,518 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
///|
|
||||||
|
pub(all) struct WindowCaps(Byte) derive()
|
||||||
|
///|
|
||||||
|
pub fn WindowCaps::default() -> WindowCaps {
|
||||||
|
WindowCaps(b'\x00')
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum WindowCapsFlag {
|
||||||
|
CAN_MOVE; CAN_RESIZE; CAN_MAXIMIZE; CAN_MINIMIZE; CAN_FULLSCREEN
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
fn WindowCapsFlag::value(self : WindowCapsFlag) -> Byte {
|
||||||
|
match self {
|
||||||
|
CAN_MOVE => ((1U << 0).to_byte())
|
||||||
|
CAN_RESIZE => ((1U << 1).to_byte())
|
||||||
|
CAN_MAXIMIZE => ((1U << 2).to_byte())
|
||||||
|
CAN_MINIMIZE => ((1U << 3).to_byte())
|
||||||
|
CAN_FULLSCREEN => ((1U << 4).to_byte())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn WindowCaps::set(self : Self, other: WindowCapsFlag) -> WindowCaps {
|
||||||
|
let WindowCaps(flag) = self
|
||||||
|
WindowCaps(flag.lor(other.value()))
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn WindowCaps::unset(self : Self, other: WindowCapsFlag) -> WindowCaps {
|
||||||
|
let WindowCaps(flag) = self
|
||||||
|
WindowCaps(flag.land(other.value().lnot()))
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn WindowCaps::is_set(self : Self, other: WindowCapsFlag) -> Bool {
|
||||||
|
let WindowCaps(flag) = self
|
||||||
|
(flag.land(other.value()) == other.value())
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum LayoutMode {
|
||||||
|
FLOATING; TILING; MONOCLE
|
||||||
|
} derive()
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn LayoutMode::ordinal(self : LayoutMode) -> Int {
|
||||||
|
match self {
|
||||||
|
FLOATING => 0
|
||||||
|
TILING => 1
|
||||||
|
MONOCLE => 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn LayoutMode::from(self : Int) -> LayoutMode {
|
||||||
|
match self {
|
||||||
|
0 => FLOATING
|
||||||
|
1 => TILING
|
||||||
|
2 => MONOCLE
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) struct WindowState {
|
||||||
|
id : UInt64; app_id : String; title : String; geometry : @types.Rect; min_size : @types.Size; max_size : @types.Size?; focused : Bool; maximized : Bool; fullscreen : Bool; workspace : UInt; caps : WindowCaps
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum WindowRequest {
|
||||||
|
Maximize(Bool)
|
||||||
|
Fullscreen(Bool)
|
||||||
|
Minimize(Bool)
|
||||||
|
Close
|
||||||
|
Activate
|
||||||
|
MoveTo(@types.Point)
|
||||||
|
ResizeTo(@types.Size)
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum WmAction {
|
||||||
|
SetGeometry((UInt64, @types.Rect))
|
||||||
|
Focus(UInt64)
|
||||||
|
Raise(UInt64)
|
||||||
|
Close(UInt64)
|
||||||
|
SetMaximized((UInt64, Bool))
|
||||||
|
SetFullscreen((UInt64, Bool))
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub(all) enum InputTarget {
|
||||||
|
Client((UInt64, @types.Point))
|
||||||
|
Decoration((UInt64, @types.Point))
|
||||||
|
ShellPanel(@types.Point)
|
||||||
|
None
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
/// Called on startup or WM hot-swap to synchronize existing windows.
|
||||||
|
pub fn sync_windows(outputs : Array[@types.Rect], windows : Array[WindowState]) -> Array[WmAction] {
|
||||||
|
let cleanup_list : Array[Int] = []
|
||||||
|
|
||||||
|
let address = mbt_ffi_malloc((outputs).length() * 16);
|
||||||
|
for index = 0; index < (outputs).length(); index = index + 1 {
|
||||||
|
let iter_elem : @types.Rect = (outputs)[(index)]
|
||||||
|
let iter_base = address + (index * 16);
|
||||||
|
mbt_ffi_store32((iter_base) + 0, (iter_elem).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 4, (iter_elem).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 8, ((iter_elem).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 12, ((iter_elem).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let address2 = mbt_ffi_malloc((windows).length() * 72);
|
||||||
|
for index3 = 0; index3 < (windows).length(); index3 = index3 + 1 {
|
||||||
|
let iter_elem : WindowState = (windows)[(index3)]
|
||||||
|
let iter_base = address2 + (index3 * 72);
|
||||||
|
mbt_ffi_store64((iter_base) + 0, ((iter_elem).id).reinterpret_as_int64())
|
||||||
|
|
||||||
|
let ptr = mbt_ffi_str2ptr((iter_elem).app_id)
|
||||||
|
mbt_ffi_store32((iter_base) + 12, (iter_elem).app_id.length())
|
||||||
|
mbt_ffi_store32((iter_base) + 8, ptr)
|
||||||
|
|
||||||
|
let ptr0 = mbt_ffi_str2ptr((iter_elem).title)
|
||||||
|
mbt_ffi_store32((iter_base) + 20, (iter_elem).title.length())
|
||||||
|
mbt_ffi_store32((iter_base) + 16, ptr0)
|
||||||
|
mbt_ffi_store32((iter_base) + 24, ((iter_elem).geometry).x)
|
||||||
|
mbt_ffi_store32((iter_base) + 28, ((iter_elem).geometry).y)
|
||||||
|
mbt_ffi_store32((iter_base) + 32, (((iter_elem).geometry).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 36, (((iter_elem).geometry).h).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 40, (((iter_elem).min_size).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 44, (((iter_elem).min_size).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
match ((iter_elem).max_size) {
|
||||||
|
None => {
|
||||||
|
mbt_ffi_store8((iter_base) + 48, (0))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Some(payload1) => {
|
||||||
|
mbt_ffi_store8((iter_base) + 48, (1))
|
||||||
|
mbt_ffi_store32((iter_base) + 52, ((payload1).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((iter_base) + 56, ((payload1).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mbt_ffi_store8((iter_base) + 60, (if (iter_elem).focused { 1 } else { 0 }))
|
||||||
|
mbt_ffi_store8((iter_base) + 61, (if (iter_elem).maximized { 1 } else { 0 }))
|
||||||
|
mbt_ffi_store8((iter_base) + 62, (if (iter_elem).fullscreen { 1 } else { 0 }))
|
||||||
|
mbt_ffi_store32((iter_base) + 64, ((iter_elem).workspace).reinterpret_as_int())
|
||||||
|
|
||||||
|
let WindowCaps(flag) = (iter_elem).caps
|
||||||
|
|
||||||
|
mbt_ffi_store8((iter_base) + 68, flag.to_int())
|
||||||
|
cleanup_list.push(ptr)
|
||||||
|
cleanup_list.push(ptr0)
|
||||||
|
|
||||||
|
}
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
wasmImportSyncWindows(address, (outputs).length(), address2, (windows).length(), return_area);
|
||||||
|
|
||||||
|
let array : Array[WmAction] = [];
|
||||||
|
for index4 = 0; index4 < (mbt_ffi_load32((return_area) + 4)); index4 = index4 + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index4 * 32)
|
||||||
|
|
||||||
|
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||||
|
0 => {
|
||||||
|
|
||||||
|
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
|
||||||
|
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
|
||||||
|
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
|
||||||
|
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
|
||||||
|
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
array.push(lifted)
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||||
|
let ret = array
|
||||||
|
mbt_ffi_free(address)
|
||||||
|
mbt_ffi_free(address2)
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
|
||||||
|
cleanup_list.each(mbt_ffi_free)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn on_window_open(win : WindowState, work_area : @types.Rect) -> Array[WmAction] {
|
||||||
|
|
||||||
|
let return_area = mbt_ffi_malloc(88)
|
||||||
|
mbt_ffi_store64((return_area) + 0, ((win).id).reinterpret_as_int64())
|
||||||
|
|
||||||
|
let ptr = mbt_ffi_str2ptr((win).app_id)
|
||||||
|
mbt_ffi_store32((return_area) + 12, (win).app_id.length())
|
||||||
|
mbt_ffi_store32((return_area) + 8, ptr)
|
||||||
|
|
||||||
|
let ptr0 = mbt_ffi_str2ptr((win).title)
|
||||||
|
mbt_ffi_store32((return_area) + 20, (win).title.length())
|
||||||
|
mbt_ffi_store32((return_area) + 16, ptr0)
|
||||||
|
mbt_ffi_store32((return_area) + 24, ((win).geometry).x)
|
||||||
|
mbt_ffi_store32((return_area) + 28, ((win).geometry).y)
|
||||||
|
mbt_ffi_store32((return_area) + 32, (((win).geometry).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 36, (((win).geometry).h).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 40, (((win).min_size).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 44, (((win).min_size).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
match ((win).max_size) {
|
||||||
|
None => {
|
||||||
|
mbt_ffi_store8((return_area) + 48, (0))
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Some(payload1) => {
|
||||||
|
mbt_ffi_store8((return_area) + 48, (1))
|
||||||
|
mbt_ffi_store32((return_area) + 52, ((payload1).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 56, ((payload1).h).reinterpret_as_int())
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mbt_ffi_store8((return_area) + 60, (if (win).focused { 1 } else { 0 }))
|
||||||
|
mbt_ffi_store8((return_area) + 61, (if (win).maximized { 1 } else { 0 }))
|
||||||
|
mbt_ffi_store8((return_area) + 62, (if (win).fullscreen { 1 } else { 0 }))
|
||||||
|
mbt_ffi_store32((return_area) + 64, ((win).workspace).reinterpret_as_int())
|
||||||
|
|
||||||
|
let WindowCaps(flag) = (win).caps
|
||||||
|
|
||||||
|
mbt_ffi_store8((return_area) + 68, flag.to_int())
|
||||||
|
mbt_ffi_store32((return_area) + 72, (work_area).x)
|
||||||
|
mbt_ffi_store32((return_area) + 76, (work_area).y)
|
||||||
|
mbt_ffi_store32((return_area) + 80, ((work_area).w).reinterpret_as_int())
|
||||||
|
mbt_ffi_store32((return_area) + 84, ((work_area).h).reinterpret_as_int())
|
||||||
|
let return_area2 = mbt_ffi_malloc(8)
|
||||||
|
wasmImportOnWindowOpen(return_area, return_area2);
|
||||||
|
|
||||||
|
let array : Array[WmAction] = [];
|
||||||
|
for index = 0; index < (mbt_ffi_load32((return_area2) + 4)); index = index + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((return_area2) + 0)) + (index * 32)
|
||||||
|
|
||||||
|
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||||
|
0 => {
|
||||||
|
|
||||||
|
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
|
||||||
|
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
|
||||||
|
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
|
||||||
|
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
|
||||||
|
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
array.push(lifted)
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((return_area2) + 0))
|
||||||
|
let ret = array
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
mbt_ffi_free(ptr)
|
||||||
|
mbt_ffi_free(ptr0)
|
||||||
|
mbt_ffi_free(return_area2)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn on_window_close(id : UInt64) -> Array[WmAction] {
|
||||||
|
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
wasmImportOnWindowClose((id).reinterpret_as_int64(), return_area);
|
||||||
|
|
||||||
|
let array : Array[WmAction] = [];
|
||||||
|
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 32)
|
||||||
|
|
||||||
|
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||||
|
0 => {
|
||||||
|
|
||||||
|
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
|
||||||
|
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
|
||||||
|
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
|
||||||
|
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
|
||||||
|
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
array.push(lifted)
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||||
|
let ret = array
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn on_window_request(id : UInt64, req : WindowRequest, work_area : @types.Rect) -> Array[WmAction] {
|
||||||
|
|
||||||
|
let (lowered,lowered6,lowered7) = match req {
|
||||||
|
Maximize(payload) => {
|
||||||
|
|
||||||
|
((0), (if payload { 1 } else { 0 }), 0)
|
||||||
|
}
|
||||||
|
Fullscreen(payload0) => {
|
||||||
|
|
||||||
|
((1), (if payload0 { 1 } else { 0 }), 0)
|
||||||
|
}
|
||||||
|
Minimize(payload1) => {
|
||||||
|
|
||||||
|
((2), (if payload1 { 1 } else { 0 }), 0)
|
||||||
|
}
|
||||||
|
Close => {
|
||||||
|
|
||||||
|
((3), 0, 0)
|
||||||
|
}
|
||||||
|
Activate => {
|
||||||
|
|
||||||
|
((4), 0, 0)
|
||||||
|
}
|
||||||
|
MoveTo(payload4) => {
|
||||||
|
|
||||||
|
((5), (payload4).x, (payload4).y)
|
||||||
|
}
|
||||||
|
ResizeTo(payload5) => {
|
||||||
|
|
||||||
|
((6), ((payload5).w).reinterpret_as_int(), ((payload5).h).reinterpret_as_int())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
wasmImportOnWindowRequest((id).reinterpret_as_int64(), lowered, lowered6, lowered7, (work_area).x, (work_area).y, ((work_area).w).reinterpret_as_int(), ((work_area).h).reinterpret_as_int(), return_area);
|
||||||
|
|
||||||
|
let array : Array[WmAction] = [];
|
||||||
|
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 32)
|
||||||
|
|
||||||
|
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||||
|
0 => {
|
||||||
|
|
||||||
|
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
|
||||||
|
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
|
||||||
|
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
|
||||||
|
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
|
||||||
|
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
array.push(lifted)
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||||
|
let ret = array
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn on_pointer(pos : @types.Point, button : UInt?, pressed : Bool) -> InputTarget {
|
||||||
|
|
||||||
|
let (lowered, lowered1) = match (button) {
|
||||||
|
None => {
|
||||||
|
|
||||||
|
((0), 0)
|
||||||
|
}
|
||||||
|
Some(payload0) => {
|
||||||
|
|
||||||
|
((1), (payload0).reinterpret_as_int())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let return_area = mbt_ffi_malloc(24)
|
||||||
|
wasmImportOnPointer((pos).x, (pos).y, lowered, lowered1, (if pressed { 1 } else { 0 }), return_area);
|
||||||
|
|
||||||
|
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
|
||||||
|
0 => {
|
||||||
|
|
||||||
|
InputTarget::Client(((mbt_ffi_load64((return_area) + 8)).reinterpret_as_uint64(), @types.Point::{x : mbt_ffi_load32((return_area) + 16), y : mbt_ffi_load32((return_area) + 20)}))
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
InputTarget::Decoration(((mbt_ffi_load64((return_area) + 8)).reinterpret_as_uint64(), @types.Point::{x : mbt_ffi_load32((return_area) + 16), y : mbt_ffi_load32((return_area) + 20)}))
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
|
||||||
|
InputTarget::ShellPanel(@types.Point::{x : mbt_ffi_load32((return_area) + 8), y : mbt_ffi_load32((return_area) + 12)})
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
|
||||||
|
InputTarget::None
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
let ret = lifted
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
pub fn set_layout_mode(mode : LayoutMode, work_area : @types.Rect) -> Array[WmAction] {
|
||||||
|
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
wasmImportSetLayoutMode(mode.ordinal(), (work_area).x, (work_area).y, ((work_area).w).reinterpret_as_int(), ((work_area).h).reinterpret_as_int(), return_area);
|
||||||
|
|
||||||
|
let array : Array[WmAction] = [];
|
||||||
|
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 32)
|
||||||
|
|
||||||
|
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||||
|
0 => {
|
||||||
|
|
||||||
|
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
|
||||||
|
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
|
||||||
|
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
|
||||||
|
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
|
||||||
|
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
|
||||||
|
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
|
||||||
|
}
|
||||||
|
_ => panic()
|
||||||
|
}
|
||||||
|
|
||||||
|
array.push(lifted)
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||||
|
let ret = array
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
///|
|
||||||
|
/// Returns window IDs in bottom-to-top Z-order.
|
||||||
|
pub fn stacking_order() -> Array[UInt64] {
|
||||||
|
|
||||||
|
let return_area = mbt_ffi_malloc(8)
|
||||||
|
wasmImportStackingOrder(return_area);
|
||||||
|
|
||||||
|
let array : Array[UInt64] = [];
|
||||||
|
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
|
||||||
|
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 8)
|
||||||
|
|
||||||
|
array.push((mbt_ffi_load64((iter_base) + 0)).reinterpret_as_uint64())
|
||||||
|
}
|
||||||
|
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||||
|
let ret = array
|
||||||
|
mbt_ffi_free(return_area)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/lib/wm"
|
||||||
|
|
||||||
|
import {
|
||||||
|
"moonbitlang/core/debug",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values
|
||||||
|
pub fn clamp_int(Int32, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
pub fn compute_bsp_rects(BspNode, Rect, Int32) -> Array[(UInt64, Rect)]
|
||||||
|
|
||||||
|
pub fn compute_work_area(Rect, excl_top? : Int32, excl_right? : Int32, excl_bottom? : Int32, excl_left? : Int32) -> Rect
|
||||||
|
|
||||||
|
pub fn insert_leaf(BspNode?, UInt64, horizontal? : Bool) -> BspNode
|
||||||
|
|
||||||
|
pub fn remove_leaf(BspNode?, UInt64) -> BspNode?
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
#derive(Eq, Show, @debug.Debug)
|
||||||
|
pub(all) enum BspNode {
|
||||||
|
Leaf(UInt64)
|
||||||
|
Split(horizontal~ : Bool, ratio~ : Double, left~ : BspNode, right~ : BspNode)
|
||||||
|
}
|
||||||
|
|
||||||
|
#derive(Eq, Show)
|
||||||
|
pub(all) enum DragMode {
|
||||||
|
Move
|
||||||
|
ResizeN
|
||||||
|
ResizeS
|
||||||
|
ResizeE
|
||||||
|
ResizeW
|
||||||
|
ResizeNW
|
||||||
|
ResizeNE
|
||||||
|
ResizeSW
|
||||||
|
ResizeSE
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct DragSession {
|
||||||
|
win_id : UInt64
|
||||||
|
mode : DragMode
|
||||||
|
start_ptr_x : Int32
|
||||||
|
start_ptr_y : Int32
|
||||||
|
start_rect : Rect
|
||||||
|
}
|
||||||
|
|
||||||
|
#derive(Eq, Show, @debug.Debug)
|
||||||
|
pub(all) enum InputHit {
|
||||||
|
Client(UInt64, Int32, Int32)
|
||||||
|
Decoration(UInt64, Int32, Int32)
|
||||||
|
ShellPanel(Int32, Int32)
|
||||||
|
HitNone
|
||||||
|
}
|
||||||
|
|
||||||
|
#derive(Eq, Show, @debug.Debug)
|
||||||
|
pub(all) enum LayoutMode {
|
||||||
|
Floating
|
||||||
|
Tiling
|
||||||
|
Monocle
|
||||||
|
}
|
||||||
|
|
||||||
|
#derive(Eq, Show, @debug.Debug)
|
||||||
|
pub(all) struct Rect {
|
||||||
|
x : Int32
|
||||||
|
y : Int32
|
||||||
|
w : Int32
|
||||||
|
h : Int32
|
||||||
|
}
|
||||||
|
pub fn Rect::contains(Self, Int32, Int32) -> Bool
|
||||||
|
|
||||||
|
#derive(Eq, Show, @debug.Debug)
|
||||||
|
pub(all) struct Size {
|
||||||
|
w : Int32
|
||||||
|
h : Int32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct WindowRecord {
|
||||||
|
id : UInt64
|
||||||
|
app_id : String
|
||||||
|
title : String
|
||||||
|
mut geometry : Rect
|
||||||
|
mut floating_geometry : Rect
|
||||||
|
min_size : Size
|
||||||
|
max_size : Size?
|
||||||
|
mut focused : Bool
|
||||||
|
mut maximized : Bool
|
||||||
|
mut fullscreen : Bool
|
||||||
|
mut minimized : Bool
|
||||||
|
mut is_floating : Bool
|
||||||
|
workspace : UInt32
|
||||||
|
can_move : Bool
|
||||||
|
can_resize : Bool
|
||||||
|
can_maximize : Bool
|
||||||
|
can_minimize : Bool
|
||||||
|
can_fullscreen : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
#derive(Eq, Show, @debug.Debug)
|
||||||
|
pub(all) enum WindowRequest {
|
||||||
|
Maximize(Bool)
|
||||||
|
Fullscreen(Bool)
|
||||||
|
Minimize(Bool)
|
||||||
|
Close
|
||||||
|
Activate
|
||||||
|
MoveTo(Int32, Int32)
|
||||||
|
ResizeTo(Int32, Int32)
|
||||||
|
}
|
||||||
|
|
||||||
|
#derive(Eq, Show, @debug.Debug)
|
||||||
|
pub(all) enum WmAction {
|
||||||
|
SetGeometry(UInt64, Rect)
|
||||||
|
Focus(UInt64)
|
||||||
|
Raise(UInt64)
|
||||||
|
Close(UInt64)
|
||||||
|
SetMaximized(UInt64, Bool)
|
||||||
|
SetFullscreen(UInt64, Bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(all) struct WmState {
|
||||||
|
workspaces : Array[Workspace]
|
||||||
|
windows : Map[UInt64, WindowRecord]
|
||||||
|
mut active_workspace : UInt32
|
||||||
|
mut focused : UInt64?
|
||||||
|
mut inner_gap : Int32
|
||||||
|
mut outer_gap : Int32
|
||||||
|
mut titlebar_h : Int32
|
||||||
|
mut border_w : Int32
|
||||||
|
mut cascade_step : Int32
|
||||||
|
mut drag : DragSession?
|
||||||
|
}
|
||||||
|
pub fn WmState::close_window(Self, UInt64, 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
|
||||||
|
pub fn WmState::new(inner_gap? : Int32, outer_gap? : Int32, titlebar_h? : Int32, border_w? : Int32) -> Self
|
||||||
|
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::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]
|
||||||
|
pub fn WmState::update_drag(Self, Int32, Int32) -> WmAction?
|
||||||
|
|
||||||
|
pub(all) struct Workspace {
|
||||||
|
id : UInt32
|
||||||
|
mut mode : LayoutMode
|
||||||
|
mut tree : BspNode?
|
||||||
|
floating : Array[UInt64]
|
||||||
|
mru : Array[UInt64]
|
||||||
|
mut fullscreen : UInt64?
|
||||||
|
}
|
||||||
|
pub fn Workspace::new(UInt32, mode? : LayoutMode) -> Self
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
+889
@@ -0,0 +1,889 @@
|
|||||||
|
///| Pure MoonBit Window Manager & hybrid layout engine (no WIT dependencies).
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) struct Rect {
|
||||||
|
x : Int
|
||||||
|
y : Int
|
||||||
|
w : Int
|
||||||
|
h : Int
|
||||||
|
} derive(Eq, Show, Debug)
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) struct Size {
|
||||||
|
w : Int
|
||||||
|
h : Int
|
||||||
|
} derive(Eq, Show, Debug)
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn Rect::contains(self : Rect, px : Int, py : Int) -> Bool {
|
||||||
|
px >= self.x && py >= self.y && px < self.x + self.w && py < self.y + self.h
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn clamp_int(v : Int, lo : Int, hi : Int) -> Int {
|
||||||
|
if v < lo {
|
||||||
|
lo
|
||||||
|
} else if v > hi {
|
||||||
|
hi
|
||||||
|
} else {
|
||||||
|
v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) enum LayoutMode {
|
||||||
|
Floating
|
||||||
|
Tiling
|
||||||
|
Monocle
|
||||||
|
} derive(Eq, Show, Debug)
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) enum BspNode {
|
||||||
|
Leaf(UInt64)
|
||||||
|
Split(horizontal~ : Bool, ratio~ : Double, left~ : BspNode, right~ : BspNode)
|
||||||
|
} derive(Eq, Show, Debug)
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) struct WindowRecord {
|
||||||
|
id : UInt64
|
||||||
|
app_id : String
|
||||||
|
title : String
|
||||||
|
mut geometry : Rect
|
||||||
|
mut floating_geometry : Rect
|
||||||
|
min_size : Size
|
||||||
|
max_size : Size?
|
||||||
|
mut focused : Bool
|
||||||
|
mut maximized : Bool
|
||||||
|
mut fullscreen : Bool
|
||||||
|
mut minimized : Bool
|
||||||
|
mut is_floating : Bool
|
||||||
|
workspace : UInt
|
||||||
|
can_move : Bool
|
||||||
|
can_resize : Bool
|
||||||
|
can_maximize : Bool
|
||||||
|
can_minimize : Bool
|
||||||
|
can_fullscreen : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) enum WindowRequest {
|
||||||
|
Maximize(Bool)
|
||||||
|
Fullscreen(Bool)
|
||||||
|
Minimize(Bool)
|
||||||
|
Close
|
||||||
|
Activate
|
||||||
|
MoveTo(Int, Int)
|
||||||
|
ResizeTo(Int, Int)
|
||||||
|
} derive(Eq, Show, Debug)
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) enum WmAction {
|
||||||
|
SetGeometry(UInt64, Rect)
|
||||||
|
Focus(UInt64)
|
||||||
|
Raise(UInt64)
|
||||||
|
Close(UInt64)
|
||||||
|
SetMaximized(UInt64, Bool)
|
||||||
|
SetFullscreen(UInt64, Bool)
|
||||||
|
} derive(Eq, Show, Debug)
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) enum InputHit {
|
||||||
|
Client(UInt64, Int, Int)
|
||||||
|
Decoration(UInt64, Int, Int)
|
||||||
|
ShellPanel(Int, Int)
|
||||||
|
HitNone
|
||||||
|
} derive(Eq, Show, Debug)
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) enum DragMode {
|
||||||
|
Move
|
||||||
|
ResizeN
|
||||||
|
ResizeS
|
||||||
|
ResizeE
|
||||||
|
ResizeW
|
||||||
|
ResizeNW
|
||||||
|
ResizeNE
|
||||||
|
ResizeSW
|
||||||
|
ResizeSE
|
||||||
|
} derive(Eq, Show)
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) struct DragSession {
|
||||||
|
win_id : UInt64
|
||||||
|
mode : DragMode
|
||||||
|
start_ptr_x : Int
|
||||||
|
start_ptr_y : Int
|
||||||
|
start_rect : Rect
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) struct Workspace {
|
||||||
|
id : UInt
|
||||||
|
mut mode : LayoutMode
|
||||||
|
mut tree : BspNode?
|
||||||
|
floating : Array[UInt64]
|
||||||
|
mru : Array[UInt64]
|
||||||
|
mut fullscreen : UInt64?
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn Workspace::new(id : UInt, mode~ : LayoutMode = Tiling) -> Workspace {
|
||||||
|
{ id, mode, tree: None, floating: [], mru: [], fullscreen: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub(all) struct WmState {
|
||||||
|
workspaces : Array[Workspace]
|
||||||
|
windows : Map[UInt64, WindowRecord]
|
||||||
|
mut active_workspace : UInt
|
||||||
|
mut focused : UInt64?
|
||||||
|
mut inner_gap : Int
|
||||||
|
mut outer_gap : Int
|
||||||
|
mut titlebar_h : Int
|
||||||
|
mut border_w : Int
|
||||||
|
mut cascade_step : Int
|
||||||
|
mut drag : DragSession?
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn WmState::new(
|
||||||
|
inner_gap~ : Int = 8,
|
||||||
|
outer_gap~ : Int = 8,
|
||||||
|
titlebar_h~ : Int = 32,
|
||||||
|
border_w~ : Int = 2,
|
||||||
|
) -> WmState {
|
||||||
|
{
|
||||||
|
workspaces: [Workspace::new(0U, mode=Tiling)],
|
||||||
|
windows: {},
|
||||||
|
active_workspace: 0U,
|
||||||
|
focused: None,
|
||||||
|
inner_gap,
|
||||||
|
outer_gap,
|
||||||
|
titlebar_h,
|
||||||
|
border_w,
|
||||||
|
cascade_step: 0,
|
||||||
|
drag: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Compute usable work area by subtracting exclusive zones (e.g. top/bottom panel).
|
||||||
|
pub fn compute_work_area(
|
||||||
|
output : Rect,
|
||||||
|
excl_top~ : Int = 0,
|
||||||
|
excl_right~ : Int = 0,
|
||||||
|
excl_bottom~ : Int = 0,
|
||||||
|
excl_left~ : Int = 0,
|
||||||
|
) -> Rect {
|
||||||
|
let x = output.x + excl_left
|
||||||
|
let y = output.y + excl_top
|
||||||
|
let w = if output.w > excl_left + excl_right {
|
||||||
|
output.w - excl_left - excl_right
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
let h = if output.h > excl_top + excl_bottom {
|
||||||
|
output.h - excl_top - excl_bottom
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
{ x, y, w, h }
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Insert a window leaf into a BSP tree, splitting at the deepest rightmost leaf
|
||||||
|
/// (alternating horizontal/vertical split).
|
||||||
|
pub fn insert_leaf(
|
||||||
|
tree : BspNode?,
|
||||||
|
id : UInt64,
|
||||||
|
horizontal~ : Bool = true,
|
||||||
|
) -> BspNode {
|
||||||
|
match tree {
|
||||||
|
None => Leaf(id)
|
||||||
|
Some(Leaf(existing)) =>
|
||||||
|
Split(horizontal~, ratio=0.5, left=Leaf(existing), right=Leaf(id))
|
||||||
|
Some(Split(horizontal=h, ratio=r, left=l, right=rt)) =>
|
||||||
|
Split(
|
||||||
|
horizontal=h,
|
||||||
|
ratio=r,
|
||||||
|
left=l,
|
||||||
|
right=insert_leaf(Some(rt), id, horizontal=!h),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Remove a window leaf from a BSP tree, collapsing its parent split.
|
||||||
|
pub fn remove_leaf(tree : BspNode?, id : UInt64) -> BspNode? {
|
||||||
|
match tree {
|
||||||
|
None => None
|
||||||
|
Some(Leaf(leaf_id)) => if leaf_id == id { None } else { Some(Leaf(leaf_id)) }
|
||||||
|
Some(Split(horizontal=h, ratio=r, left=l, right=rt)) => {
|
||||||
|
let nl = remove_leaf(Some(l), id)
|
||||||
|
let nr = remove_leaf(Some(rt), id)
|
||||||
|
match (nl, nr) {
|
||||||
|
(None, None) => None
|
||||||
|
(Some(only), None) => Some(only)
|
||||||
|
(None, Some(only)) => Some(only)
|
||||||
|
(Some(new_l), Some(new_r)) =>
|
||||||
|
Some(Split(horizontal=h, ratio=r, left=new_l, right=new_r))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Compute tiled rectangles for every leaf in a BSP tree within `area`.
|
||||||
|
pub fn compute_bsp_rects(
|
||||||
|
node : BspNode,
|
||||||
|
area : Rect,
|
||||||
|
inner_gap : Int,
|
||||||
|
) -> Array[(UInt64, Rect)] {
|
||||||
|
let out : Array[(UInt64, Rect)] = []
|
||||||
|
fn walk(n : BspNode, r : Rect, gap : Int, acc : Array[(UInt64, Rect)]) -> Unit {
|
||||||
|
match n {
|
||||||
|
Leaf(id) => acc.push((id, r))
|
||||||
|
Split(horizontal=horiz, ratio=ratio, left=l, right=rt) =>
|
||||||
|
if horiz {
|
||||||
|
let avail = r.w - gap
|
||||||
|
let lw = if avail > 2 {
|
||||||
|
clamp_int((avail.to_double() * ratio).to_int(), 1, avail - 1)
|
||||||
|
} else {
|
||||||
|
r.w / 2
|
||||||
|
}
|
||||||
|
let rw = if avail > lw { avail - lw } else { 1 }
|
||||||
|
walk(l, { x: r.x, y: r.y, w: lw, h: r.h }, gap, acc)
|
||||||
|
walk(rt, { x: r.x + lw + gap, y: r.y, w: rw, h: r.h }, gap, acc)
|
||||||
|
} else {
|
||||||
|
let avail = r.h - gap
|
||||||
|
let lh = if avail > 2 {
|
||||||
|
clamp_int((avail.to_double() * ratio).to_int(), 1, avail - 1)
|
||||||
|
} else {
|
||||||
|
r.h / 2
|
||||||
|
}
|
||||||
|
let rh = if avail > lh { avail - lh } else { 1 }
|
||||||
|
walk(l, { x: r.x, y: r.y, w: r.w, h: lh }, gap, acc)
|
||||||
|
walk(rt, { x: r.x, y: r.y + lh + gap, w: r.w, h: rh }, gap, acc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
walk(node, area, inner_gap, out)
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn WmState::ensure_workspace(self : WmState, ws_id : UInt) -> Workspace {
|
||||||
|
for ws in self.workspaces {
|
||||||
|
if ws.id == ws_id {
|
||||||
|
return ws
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ws = Workspace::new(ws_id, mode=Tiling)
|
||||||
|
self.workspaces.push(ws)
|
||||||
|
ws
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn remove_id(arr : Array[UInt64], id : UInt64) -> Unit {
|
||||||
|
let mut idx = -1
|
||||||
|
for i = 0; i < arr.length(); i = i + 1 {
|
||||||
|
if arr[i] == id {
|
||||||
|
idx = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if idx >= 0 {
|
||||||
|
ignore(arr.remove(idx))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn push_mru_front(mru : Array[UInt64], id : UInt64) -> Unit {
|
||||||
|
remove_id(mru, id)
|
||||||
|
mru.insert(0, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn push_top(arr : Array[UInt64], id : UInt64) -> Unit {
|
||||||
|
remove_id(arr, id)
|
||||||
|
arr.push(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn WmState::inner_work_area(self : WmState, work_area : Rect) -> Rect {
|
||||||
|
let g = self.outer_gap
|
||||||
|
let w = if work_area.w > 2 * g { work_area.w - 2 * g } else { work_area.w }
|
||||||
|
let h = if work_area.h > 2 * g { work_area.h - 2 * g } else { work_area.h }
|
||||||
|
{ x: work_area.x + g, y: work_area.y + g, w, h }
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Reflow tiled/monocle/fullscreen windows on a workspace and emit geometry actions.
|
||||||
|
pub fn WmState::relayout(
|
||||||
|
self : WmState,
|
||||||
|
ws_id : UInt,
|
||||||
|
work_area : Rect,
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
let ws = self.ensure_workspace(ws_id)
|
||||||
|
let actions : Array[WmAction] = []
|
||||||
|
// Fullscreen window overrides work_area.
|
||||||
|
match ws.fullscreen {
|
||||||
|
Some(fs_id) =>
|
||||||
|
match self.windows.get(fs_id) {
|
||||||
|
Some(win) =>
|
||||||
|
if !win.minimized {
|
||||||
|
win.geometry = work_area
|
||||||
|
actions.push(SetGeometry(fs_id, work_area))
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
let padded = self.inner_work_area(work_area)
|
||||||
|
match ws.mode {
|
||||||
|
Floating => ()
|
||||||
|
Monocle =>
|
||||||
|
match ws.tree {
|
||||||
|
Some(t) => {
|
||||||
|
let rects = compute_bsp_rects(t, padded, self.inner_gap)
|
||||||
|
for pair in rects {
|
||||||
|
let (id, _) = pair
|
||||||
|
if ws.fullscreen == Some(id) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
match self.windows.get(id) {
|
||||||
|
Some(win) =>
|
||||||
|
if !win.minimized {
|
||||||
|
win.geometry = padded
|
||||||
|
actions.push(SetGeometry(id, padded))
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
Tiling =>
|
||||||
|
match ws.tree {
|
||||||
|
Some(t) => {
|
||||||
|
let rects = compute_bsp_rects(t, padded, self.inner_gap)
|
||||||
|
for pair in rects {
|
||||||
|
let (id, rect) = pair
|
||||||
|
if ws.fullscreen == Some(id) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
match self.windows.get(id) {
|
||||||
|
Some(win) =>
|
||||||
|
if !win.minimized {
|
||||||
|
let min_w = if win.min_size.w > 0 { win.min_size.w } else { 64 }
|
||||||
|
let min_h = if win.min_size.h > 0 { win.min_size.h } else { 48 }
|
||||||
|
let clamped : Rect = {
|
||||||
|
x: rect.x,
|
||||||
|
y: rect.y,
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Maximized floating windows also fill padded work_area.
|
||||||
|
for id in ws.floating {
|
||||||
|
if ws.fullscreen == Some(id) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
match self.windows.get(id) {
|
||||||
|
Some(win) =>
|
||||||
|
if win.maximized && !win.minimized {
|
||||||
|
win.geometry = padded
|
||||||
|
actions.push(SetGeometry(id, padded))
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actions
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn WmState::set_focus(self : WmState, id : UInt64?) -> Array[WmAction] {
|
||||||
|
let actions : Array[WmAction] = []
|
||||||
|
match self.focused {
|
||||||
|
Some(prev) =>
|
||||||
|
if Some(prev) != id {
|
||||||
|
match self.windows.get(prev) {
|
||||||
|
Some(w) => w.focused = false
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
self.focused = id
|
||||||
|
match id {
|
||||||
|
Some(nid) =>
|
||||||
|
match self.windows.get(nid) {
|
||||||
|
Some(w) => {
|
||||||
|
w.focused = true
|
||||||
|
let ws = self.ensure_workspace(w.workspace)
|
||||||
|
push_mru_front(ws.mru, nid)
|
||||||
|
if w.is_floating {
|
||||||
|
push_top(ws.floating, nid)
|
||||||
|
}
|
||||||
|
actions.push(Focus(nid))
|
||||||
|
actions.push(Raise(nid))
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
actions
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn should_auto_float(win : WindowRecord) -> Bool {
|
||||||
|
if !win.can_resize {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
match win.max_size {
|
||||||
|
Some(mx) => mx.w == win.min_size.w && mx.h == win.min_size.h
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn WmState::open_window(
|
||||||
|
self : WmState,
|
||||||
|
win : WindowRecord,
|
||||||
|
work_area : Rect,
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
let ws = self.ensure_workspace(win.workspace)
|
||||||
|
let auto_float = win.is_floating || ws.mode == Floating || should_auto_float(win)
|
||||||
|
win.is_floating = auto_float
|
||||||
|
if auto_float && (win.geometry.w == 0 || win.geometry.h == 0) {
|
||||||
|
let dw = clamp_int(work_area.w * 2 / 3, 240, work_area.w - 2 * self.outer_gap)
|
||||||
|
let dh = clamp_int(work_area.h * 2 / 3, 180, work_area.h - 2 * self.outer_gap)
|
||||||
|
let offset = (self.cascade_step % 6) * 28
|
||||||
|
self.cascade_step += 1
|
||||||
|
let gx = work_area.x + self.outer_gap + 32 + offset
|
||||||
|
let gy = work_area.y + self.outer_gap + 24 + offset
|
||||||
|
let r : Rect = { x: gx, y: gy, w: dw, h: dh }
|
||||||
|
win.geometry = r
|
||||||
|
win.floating_geometry = r
|
||||||
|
} else if auto_float {
|
||||||
|
win.floating_geometry = win.geometry
|
||||||
|
}
|
||||||
|
self.windows[win.id] = win
|
||||||
|
if auto_float {
|
||||||
|
push_top(ws.floating, win.id)
|
||||||
|
} else {
|
||||||
|
ws.tree = Some(insert_leaf(ws.tree, win.id))
|
||||||
|
}
|
||||||
|
push_mru_front(ws.mru, win.id)
|
||||||
|
let actions : Array[WmAction] = []
|
||||||
|
if auto_float {
|
||||||
|
actions.push(SetGeometry(win.id, win.geometry))
|
||||||
|
}
|
||||||
|
for a in self.relayout(win.workspace, work_area) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
for a in self.set_focus(Some(win.id)) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
actions
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn WmState::close_window(
|
||||||
|
self : WmState,
|
||||||
|
id : UInt64,
|
||||||
|
work_area : Rect,
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
let actions : Array[WmAction] = []
|
||||||
|
match self.windows.get(id) {
|
||||||
|
None => return actions
|
||||||
|
Some(win) => {
|
||||||
|
let ws_id = win.workspace
|
||||||
|
let ws = self.ensure_workspace(ws_id)
|
||||||
|
ignore(self.windows.remove(id))
|
||||||
|
ws.tree = remove_leaf(ws.tree, id)
|
||||||
|
remove_id(ws.floating, id)
|
||||||
|
remove_id(ws.mru, id)
|
||||||
|
if ws.fullscreen == Some(id) {
|
||||||
|
ws.fullscreen = None
|
||||||
|
}
|
||||||
|
for a in self.relayout(ws_id, work_area) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
if self.focused == Some(id) {
|
||||||
|
let next_focus : UInt64? = if ws.mru.length() > 0 {
|
||||||
|
Some(ws.mru[0])
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
for a in self.set_focus(next_focus) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actions
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Synchronize state on startup or WM hot-swap.
|
||||||
|
pub fn WmState::sync_windows(
|
||||||
|
self : WmState,
|
||||||
|
work_area : Rect,
|
||||||
|
wins : Array[WindowRecord],
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
self.workspaces.clear()
|
||||||
|
ignore(self.workspaces.push(Workspace::new(0U, mode=Tiling)))
|
||||||
|
self.windows.clear()
|
||||||
|
self.focused = None
|
||||||
|
let actions : Array[WmAction] = []
|
||||||
|
let mut last_focused : UInt64? = None
|
||||||
|
for w in wins {
|
||||||
|
if w.focused {
|
||||||
|
last_focused = Some(w.id)
|
||||||
|
}
|
||||||
|
for a in self.open_window(w, work_area) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match last_focused {
|
||||||
|
Some(fid) =>
|
||||||
|
for a in self.set_focus(Some(fid)) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
actions
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn WmState::set_layout_mode(
|
||||||
|
self : WmState,
|
||||||
|
mode : LayoutMode,
|
||||||
|
work_area : Rect,
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
let ws = self.ensure_workspace(self.active_workspace)
|
||||||
|
if ws.mode == mode {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
ws.mode = mode
|
||||||
|
if mode == Floating {
|
||||||
|
// Move all tiled leaves into floating list preserving geometry.
|
||||||
|
match ws.tree {
|
||||||
|
Some(t) => {
|
||||||
|
let rects = compute_bsp_rects(t, self.inner_work_area(work_area), self.inner_gap)
|
||||||
|
for pair in rects {
|
||||||
|
let (id, _) = pair
|
||||||
|
match self.windows.get(id) {
|
||||||
|
Some(win) => {
|
||||||
|
win.is_floating = true
|
||||||
|
win.floating_geometry = win.geometry
|
||||||
|
push_top(ws.floating, id)
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ws.tree = None
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Re-insert floating windows (except fixed-size dialogs) into BSP tree.
|
||||||
|
let keep_floating : Array[UInt64] = []
|
||||||
|
for id in ws.floating {
|
||||||
|
match self.windows.get(id) {
|
||||||
|
Some(win) =>
|
||||||
|
if should_auto_float(win) {
|
||||||
|
keep_floating.push(id)
|
||||||
|
} else {
|
||||||
|
win.is_floating = false
|
||||||
|
ws.tree = Some(insert_leaf(ws.tree, id))
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ws.floating.clear()
|
||||||
|
for id in keep_floating {
|
||||||
|
ws.floating.push(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.relayout(self.active_workspace, work_area)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn WmState::handle_request(
|
||||||
|
self : WmState,
|
||||||
|
id : UInt64,
|
||||||
|
req : WindowRequest,
|
||||||
|
work_area : Rect,
|
||||||
|
) -> Array[WmAction] {
|
||||||
|
let actions : Array[WmAction] = []
|
||||||
|
match self.windows.get(id) {
|
||||||
|
None => return actions
|
||||||
|
Some(win) => {
|
||||||
|
let ws = self.ensure_workspace(win.workspace)
|
||||||
|
match req {
|
||||||
|
Activate =>
|
||||||
|
for a in self.set_focus(Some(id)) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
Close => actions.push(Close(id))
|
||||||
|
Maximize(max) =>
|
||||||
|
if win.can_maximize {
|
||||||
|
win.maximized = max
|
||||||
|
actions.push(SetMaximized(id, max))
|
||||||
|
if !max && win.is_floating {
|
||||||
|
win.geometry = win.floating_geometry
|
||||||
|
actions.push(SetGeometry(id, win.geometry))
|
||||||
|
}
|
||||||
|
for a in self.relayout(win.workspace, work_area) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Fullscreen(fs) =>
|
||||||
|
if win.can_fullscreen {
|
||||||
|
win.fullscreen = fs
|
||||||
|
if fs {
|
||||||
|
ws.fullscreen = Some(id)
|
||||||
|
} else if ws.fullscreen == Some(id) {
|
||||||
|
ws.fullscreen = None
|
||||||
|
}
|
||||||
|
actions.push(SetFullscreen(id, fs))
|
||||||
|
if !fs && win.is_floating && !win.maximized {
|
||||||
|
win.geometry = win.floating_geometry
|
||||||
|
actions.push(SetGeometry(id, win.geometry))
|
||||||
|
}
|
||||||
|
for a in self.relayout(win.workspace, work_area) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Minimize(min) =>
|
||||||
|
if win.can_minimize {
|
||||||
|
win.minimized = min
|
||||||
|
for a in self.relayout(win.workspace, work_area) {
|
||||||
|
actions.push(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MoveTo(nx, ny) =>
|
||||||
|
if win.can_move {
|
||||||
|
let r : Rect = { x: nx, y: ny, w: win.geometry.w, h: win.geometry.h }
|
||||||
|
win.geometry = r
|
||||||
|
if win.is_floating {
|
||||||
|
win.floating_geometry = r
|
||||||
|
}
|
||||||
|
actions.push(SetGeometry(id, r))
|
||||||
|
}
|
||||||
|
ResizeTo(nw, nh) =>
|
||||||
|
if win.can_resize {
|
||||||
|
let min_w = if win.min_size.w > 0 { win.min_size.w } else { 64 }
|
||||||
|
let min_h = if win.min_size.h > 0 { win.min_size.h } else { 48 }
|
||||||
|
let cw = if nw < min_w { min_w } else { nw }
|
||||||
|
let ch = if nh < min_h { min_h } else { nh }
|
||||||
|
let r : Rect = { x: win.geometry.x, y: win.geometry.y, w: cw, h: ch }
|
||||||
|
win.geometry = r
|
||||||
|
if win.is_floating {
|
||||||
|
win.floating_geometry = r
|
||||||
|
}
|
||||||
|
actions.push(SetGeometry(id, r))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actions
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Bottom-to-top Z-order: Tiled -> Floating -> Fullscreen.
|
||||||
|
pub fn WmState::stacking_order(self : WmState) -> Array[UInt64] {
|
||||||
|
let ws = self.ensure_workspace(self.active_workspace)
|
||||||
|
let order : Array[UInt64] = []
|
||||||
|
fn collect_tree(n : BspNode?, acc : Array[UInt64], fs : UInt64?, wins : Map[UInt64, WindowRecord]) -> Unit {
|
||||||
|
match n {
|
||||||
|
None => ()
|
||||||
|
Some(Leaf(id)) =>
|
||||||
|
if fs != Some(id) {
|
||||||
|
match wins.get(id) {
|
||||||
|
Some(w) => if !w.minimized { acc.push(id) }
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(Split(horizontal=_, ratio=_, left=l, right=rt)) => {
|
||||||
|
collect_tree(Some(l), acc, fs, wins)
|
||||||
|
collect_tree(Some(rt), acc, fs, wins)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
collect_tree(ws.tree, order, ws.fullscreen, self.windows)
|
||||||
|
for id in ws.floating {
|
||||||
|
if ws.fullscreen != Some(id) {
|
||||||
|
match self.windows.get(id) {
|
||||||
|
Some(w) => if !w.minimized { order.push(id) }
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match ws.fullscreen {
|
||||||
|
Some(fs_id) =>
|
||||||
|
match self.windows.get(fs_id) {
|
||||||
|
Some(w) => if !w.minimized { order.push(fs_id) }
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
order
|
||||||
|
}
|
||||||
|
|
||||||
|
///| Hit-test pointer position against panel, decorations, and client surfaces.
|
||||||
|
pub fn WmState::hit_test(
|
||||||
|
self : WmState,
|
||||||
|
px : Int,
|
||||||
|
py : Int,
|
||||||
|
panel_rect : Rect?,
|
||||||
|
) -> InputHit {
|
||||||
|
match panel_rect {
|
||||||
|
Some(pr) =>
|
||||||
|
if pr.contains(px, py) {
|
||||||
|
return ShellPanel(px - pr.x, py - pr.y)
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
let order = self.stacking_order()
|
||||||
|
for i = order.length() - 1; i >= 0; i = i - 1 {
|
||||||
|
let id = order[i]
|
||||||
|
match self.windows.get(id) {
|
||||||
|
Some(win) => {
|
||||||
|
let g = win.geometry
|
||||||
|
if win.fullscreen {
|
||||||
|
if g.contains(px, py) {
|
||||||
|
return Client(id, px - g.x, py - g.y)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Outer decoration rect surrounds client geometry by titlebar_h on top, border_w on sides/bottom.
|
||||||
|
let outer : Rect = {
|
||||||
|
x: g.x - self.border_w,
|
||||||
|
y: g.y - self.titlebar_h,
|
||||||
|
w: g.w + 2 * self.border_w,
|
||||||
|
h: g.h + self.titlebar_h + self.border_w,
|
||||||
|
}
|
||||||
|
if g.contains(px, py) {
|
||||||
|
return Client(id, px - g.x, py - g.y)
|
||||||
|
}
|
||||||
|
if outer.contains(px, py) {
|
||||||
|
return Decoration(id, px - outer.x, py - outer.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HitNone
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn WmState::start_drag(
|
||||||
|
self : WmState,
|
||||||
|
win_id : UInt64,
|
||||||
|
mode : DragMode,
|
||||||
|
ptr_x : Int,
|
||||||
|
ptr_y : Int,
|
||||||
|
) -> Bool {
|
||||||
|
match self.windows.get(win_id) {
|
||||||
|
Some(win) =>
|
||||||
|
if !win.fullscreen {
|
||||||
|
self.drag = Some({
|
||||||
|
win_id,
|
||||||
|
mode,
|
||||||
|
start_ptr_x: ptr_x,
|
||||||
|
start_ptr_y: ptr_y,
|
||||||
|
start_rect: win.geometry,
|
||||||
|
})
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn WmState::update_drag(
|
||||||
|
self : WmState,
|
||||||
|
ptr_x : Int,
|
||||||
|
ptr_y : Int,
|
||||||
|
) -> WmAction? {
|
||||||
|
match self.drag {
|
||||||
|
None => None
|
||||||
|
Some(d) =>
|
||||||
|
match self.windows.get(d.win_id) {
|
||||||
|
None => {
|
||||||
|
self.drag = None
|
||||||
|
None
|
||||||
|
}
|
||||||
|
Some(win) => {
|
||||||
|
let dx = ptr_x - d.start_ptr_x
|
||||||
|
let dy = ptr_y - d.start_ptr_y
|
||||||
|
let min_w = if win.min_size.w > 0 { win.min_size.w } else { 120 }
|
||||||
|
let min_h = if win.min_size.h > 0 { win.min_size.h } else { 80 }
|
||||||
|
let sr = d.start_rect
|
||||||
|
let next : Rect = match d.mode {
|
||||||
|
Move => { x: sr.x + dx, y: sr.y + dy, w: sr.w, h: sr.h }
|
||||||
|
ResizeE => {
|
||||||
|
x: sr.x,
|
||||||
|
y: sr.y,
|
||||||
|
w: if sr.w + dx < min_w { min_w } else { sr.w + dx },
|
||||||
|
h: sr.h,
|
||||||
|
}
|
||||||
|
ResizeS => {
|
||||||
|
x: sr.x,
|
||||||
|
y: sr.y,
|
||||||
|
w: sr.w,
|
||||||
|
h: if sr.h + dy < min_h { min_h } else { sr.h + dy },
|
||||||
|
}
|
||||||
|
ResizeSE => {
|
||||||
|
x: sr.x,
|
||||||
|
y: sr.y,
|
||||||
|
w: if sr.w + dx < min_w { min_w } else { sr.w + dx },
|
||||||
|
h: if sr.h + dy < min_h { min_h } else { sr.h + dy },
|
||||||
|
}
|
||||||
|
ResizeW => {
|
||||||
|
let nw = if sr.w - dx < min_w { min_w } else { sr.w - dx }
|
||||||
|
{ x: sr.x + (sr.w - nw), y: sr.y, w: nw, h: sr.h }
|
||||||
|
}
|
||||||
|
ResizeN => {
|
||||||
|
let nh = if sr.h - dy < min_h { min_h } else { sr.h - dy }
|
||||||
|
{ x: sr.x, y: sr.y + (sr.h - nh), w: sr.w, h: nh }
|
||||||
|
}
|
||||||
|
ResizeNW => {
|
||||||
|
let nw = if sr.w - dx < min_w { min_w } else { sr.w - dx }
|
||||||
|
let nh = if sr.h - dy < min_h { min_h } else { sr.h - dy }
|
||||||
|
{ x: sr.x + (sr.w - nw), y: sr.y + (sr.h - nh), w: nw, h: nh }
|
||||||
|
}
|
||||||
|
ResizeNE => {
|
||||||
|
let nw = if sr.w + dx < min_w { min_w } else { sr.w + dx }
|
||||||
|
let nh = if sr.h - dy < min_h { min_h } else { sr.h - dy }
|
||||||
|
{ x: sr.x, y: sr.y + (sr.h - nh), w: nw, h: nh }
|
||||||
|
}
|
||||||
|
ResizeSW => {
|
||||||
|
let nw = if sr.w - dx < min_w { min_w } else { sr.w - dx }
|
||||||
|
let nh = if sr.h + dy < min_h { min_h } else { sr.h + dy }
|
||||||
|
{ x: sr.x + (sr.w - nw), y: sr.y, w: nw, h: nh }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
win.geometry = next
|
||||||
|
if win.is_floating {
|
||||||
|
win.floating_geometry = next
|
||||||
|
}
|
||||||
|
Some(SetGeometry(d.win_id, next))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn WmState::end_drag(self : WmState) -> Unit {
|
||||||
|
self.drag = None
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
///| Unit tests for the pure MoonBit Window Manager engine.
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn mk_win(
|
||||||
|
id : UInt64,
|
||||||
|
floating~ : Bool = false,
|
||||||
|
min_w~ : Int = 100,
|
||||||
|
min_h~ : Int = 80,
|
||||||
|
) -> WindowRecord {
|
||||||
|
{
|
||||||
|
id,
|
||||||
|
app_id: "org.example.app\{id}",
|
||||||
|
title: "App \{id}",
|
||||||
|
geometry: { x: 0, y: 0, w: 400, h: 300 },
|
||||||
|
floating_geometry: { x: 0, y: 0, w: 400, h: 300 },
|
||||||
|
min_size: { w: min_w, h: min_h },
|
||||||
|
max_size: None,
|
||||||
|
focused: false,
|
||||||
|
maximized: false,
|
||||||
|
fullscreen: false,
|
||||||
|
minimized: false,
|
||||||
|
is_floating: floating,
|
||||||
|
workspace: 0U,
|
||||||
|
can_move: true,
|
||||||
|
can_resize: true,
|
||||||
|
can_maximize: true,
|
||||||
|
can_minimize: true,
|
||||||
|
can_fullscreen: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "work area subtracts panel exclusive zones" {
|
||||||
|
let out : Rect = { x: 0, y: 0, w: 1280, h: 720 }
|
||||||
|
let wa = compute_work_area(out, excl_bottom=48)
|
||||||
|
assert_eq(wa, { x: 0, y: 0, w: 1280, h: 672 })
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "bsp tiling splits 2 and 3 windows with gaps" {
|
||||||
|
let wm = WmState::new(inner_gap=10, outer_gap=10)
|
||||||
|
let wa : Rect = { x: 0, y: 0, w: 1020, h: 700 }
|
||||||
|
ignore(wm.open_window(mk_win(1UL), wa))
|
||||||
|
assert_eq(wm.windows[1UL].geometry, { x: 10, y: 10, w: 1000, h: 680 })
|
||||||
|
|
||||||
|
ignore(wm.open_window(mk_win(2UL), wa))
|
||||||
|
// 1000 - 10 gap = 990 -> 495 + 495
|
||||||
|
assert_eq(wm.windows[1UL].geometry, { x: 10, y: 10, w: 495, h: 680 })
|
||||||
|
assert_eq(wm.windows[2UL].geometry, { x: 515, y: 10, w: 495, h: 680 })
|
||||||
|
|
||||||
|
ignore(wm.open_window(mk_win(3UL), wa))
|
||||||
|
// Right half splits vertically: 680 - 10 = 670 -> 335 + 335
|
||||||
|
assert_eq(wm.windows[2UL].geometry, { x: 515, y: 10, w: 495, h: 335 })
|
||||||
|
assert_eq(wm.windows[3UL].geometry, { x: 515, y: 355, w: 495, h: 335 })
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "closing focused window promotes MRU focus and reflows BSP" {
|
||||||
|
let wm = WmState::new(inner_gap=10, outer_gap=10)
|
||||||
|
let wa : Rect = { x: 0, y: 0, w: 1020, h: 700 }
|
||||||
|
ignore(wm.open_window(mk_win(1UL), wa))
|
||||||
|
ignore(wm.open_window(mk_win(2UL), wa))
|
||||||
|
assert_eq(wm.focused, Some(2UL))
|
||||||
|
|
||||||
|
let actions = wm.close_window(2UL, wa)
|
||||||
|
assert_eq(wm.focused, Some(1UL))
|
||||||
|
assert_eq(wm.windows[1UL].geometry, { x: 10, y: 10, w: 1000, h: 680 })
|
||||||
|
assert_true(actions.contains(Focus(1UL)))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "hybrid stacking order: tiled < floating < fullscreen" {
|
||||||
|
let wm = WmState::new(inner_gap=8, outer_gap=8)
|
||||||
|
let wa : Rect = { x: 0, y: 0, w: 1280, h: 672 }
|
||||||
|
ignore(wm.open_window(mk_win(1UL, floating=false), wa))
|
||||||
|
ignore(wm.open_window(mk_win(2UL, floating=true), wa))
|
||||||
|
ignore(wm.open_window(mk_win(3UL, floating=false), wa))
|
||||||
|
|
||||||
|
let order = wm.stacking_order()
|
||||||
|
// Tiled (1, 3) then floating (2)
|
||||||
|
assert_eq(order, [1UL, 3UL, 2UL])
|
||||||
|
|
||||||
|
// Fullscreen window 1 overrides order to top and fills work_area
|
||||||
|
ignore(wm.handle_request(1UL, Fullscreen(true), wa))
|
||||||
|
assert_eq(wm.stacking_order(), [3UL, 2UL, 1UL])
|
||||||
|
assert_eq(wm.windows[1UL].geometry, wa)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "monocle mode gives every tiled window the full padded work area" {
|
||||||
|
let wm = WmState::new(inner_gap=8, outer_gap=12)
|
||||||
|
let wa : Rect = { x: 0, y: 0, w: 1000, h: 600 }
|
||||||
|
ignore(wm.open_window(mk_win(1UL), wa))
|
||||||
|
ignore(wm.open_window(mk_win(2UL), wa))
|
||||||
|
ignore(wm.set_layout_mode(Monocle, wa))
|
||||||
|
let expected : Rect = { x: 12, y: 12, w: 976, h: 576 }
|
||||||
|
assert_eq(wm.windows[1UL].geometry, expected)
|
||||||
|
assert_eq(wm.windows[2UL].geometry, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "hit_test distinguishes panel, client, and decoration" {
|
||||||
|
let wm = WmState::new(inner_gap=0, outer_gap=0, titlebar_h=30, border_w=4)
|
||||||
|
let wa : Rect = { x: 0, y: 0, w: 1280, h: 672 }
|
||||||
|
let panel : Rect = { x: 0, y: 672, w: 1280, h: 48 }
|
||||||
|
let w = mk_win(10UL, floating=true)
|
||||||
|
w.geometry = { x: 100, y: 100, w: 400, h: 300 }
|
||||||
|
ignore(wm.open_window(w, wa))
|
||||||
|
|
||||||
|
// Inside client
|
||||||
|
assert_eq(wm.hit_test(150, 150, Some(panel)), Client(10UL, 50, 50))
|
||||||
|
// Inside titlebar decoration (outer y = 100 - 30 = 70, outer x = 96)
|
||||||
|
assert_eq(wm.hit_test(110, 80, Some(panel)), Decoration(10UL, 14, 10))
|
||||||
|
// Inside panel
|
||||||
|
assert_eq(wm.hit_test(20, 690, Some(panel)), ShellPanel(20, 18))
|
||||||
|
// Outside everything
|
||||||
|
assert_eq(wm.hit_test(10, 10, Some(panel)), HitNone)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "interactive drag move and resize clamps to min_size" {
|
||||||
|
let wm = WmState::new()
|
||||||
|
let wa : Rect = { x: 0, y: 0, w: 1280, h: 720 }
|
||||||
|
let w = mk_win(5UL, floating=true, min_w=200, min_h=150)
|
||||||
|
w.geometry = { x: 100, y: 100, w: 400, h: 300 }
|
||||||
|
ignore(wm.open_window(w, wa))
|
||||||
|
|
||||||
|
assert_true(wm.start_drag(5UL, Move, 120, 90))
|
||||||
|
assert_eq(wm.update_drag(170, 130), Some(SetGeometry(5UL, { x: 150, y: 140, w: 400, h: 300 })))
|
||||||
|
wm.end_drag()
|
||||||
|
|
||||||
|
assert_true(wm.start_drag(5UL, ResizeSE, 550, 440))
|
||||||
|
// Shrink by -300 -> clamped to min_w=200, min_h=150
|
||||||
|
assert_eq(wm.update_drag(250, 140), Some(SetGeometry(5UL, { x: 150, y: 140, w: 200, h: 150 })))
|
||||||
|
wm.end_drag()
|
||||||
|
}
|
||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Build WM and decoration MoonBit components from wit/wm/.
|
||||||
|
set -euo pipefail
|
||||||
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT"
|
||||||
|
export PATH="$ROOT/.tools/bin:$HOME/.moon/bin:$PATH"
|
||||||
|
|
||||||
|
wasm-tools component wit wit/wm >/dev/null
|
||||||
|
moon build --target wasm --release 2>&1 | grep -v -E 'Warning|^\s*$|[│╭╰─]' || true
|
||||||
|
[ "${PIPESTATUS[0]}" -eq 0 ] || { echo "error: moon build failed" >&2; exit 1; }
|
||||||
|
|
||||||
|
mkdir -p build/components
|
||||||
|
for pair in "wm-hybrid:window-manager" "decoration-breeze:decoration-provider"; do
|
||||||
|
name="${pair%%:*}"
|
||||||
|
world="${pair#*:}"
|
||||||
|
core="_build/wasm/release/build/components/$name/gen/gen.wasm"
|
||||||
|
[ -f "$core" ] || { echo "error: $core missing" >&2; exit 1; }
|
||||||
|
out="build/components/$name.wasm"
|
||||||
|
wasm-tools component embed wit/wm "$core" --world "$world" --encoding utf16 -o "build/components/$name.embed.wasm"
|
||||||
|
wasm-tools component new "build/components/$name.embed.wasm" -o "$out"
|
||||||
|
rm -f "build/components/$name.embed.wasm"
|
||||||
|
wasm-tools validate --features component-model "$out"
|
||||||
|
wasm-tools component targets --world "$world" wit/wm "$out" >/dev/null
|
||||||
|
printf ' %-18s %-20s %7s bytes\n' "$name" "$world" "$(stat -c %s "$out")"
|
||||||
|
done
|
||||||
|
echo "ok (wm)"
|
||||||
@@ -19,6 +19,9 @@ moon test
|
|||||||
step "build components"
|
step "build components"
|
||||||
scripts/build.sh
|
scripts/build.sh
|
||||||
|
|
||||||
|
step "build wm & decoration components"
|
||||||
|
scripts/build-wm.sh
|
||||||
|
|
||||||
if command -v wasmtime >/dev/null; then
|
if command -v wasmtime >/dev/null; then
|
||||||
step "wasmtime accepts every component (compile only; hosts supply the imports)"
|
step "wasmtime accepts every component (compile only; hosts supply the imports)"
|
||||||
for f in build/components/*.wasm; do
|
for f in build/components/*.wasm; do
|
||||||
@@ -28,3 +31,8 @@ fi
|
|||||||
|
|
||||||
step "host integration tests (jco + Node)"
|
step "host integration tests (jco + Node)"
|
||||||
(cd host && npm test)
|
(cd host && npm test)
|
||||||
|
|
||||||
|
if command -v cargo >/dev/null; then
|
||||||
|
step "native Wayland compositor + wasmtime tests (host-native)"
|
||||||
|
(cd host-native && cargo test)
|
||||||
|
fi
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../theme.wit
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../types.wit
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package moonplasma:compositor@0.2.0;
|
||||||
|
|
||||||
|
interface surface {
|
||||||
|
use moonplasma:desktop/types@0.1.0.{size, rect, draw-op};
|
||||||
|
|
||||||
|
/// Unforgeable host handle to a committed client buffer (SHM or DMA-BUF).
|
||||||
|
/// Components cannot read pixels; they can only inspect metadata and
|
||||||
|
/// reference the handle in a `draw-surface` op.
|
||||||
|
resource buffer-surface {
|
||||||
|
id: func() -> u64;
|
||||||
|
size: func() -> size;
|
||||||
|
/// True if the buffer contains an alpha channel requiring blending.
|
||||||
|
has-alpha: func() -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
record surface-draw {
|
||||||
|
surface: borrow<buffer-surface>,
|
||||||
|
dst: rect,
|
||||||
|
src: option<rect>,
|
||||||
|
radius: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extended render-list op for compositing foreign surfaces & cached layers.
|
||||||
|
variant composite-op {
|
||||||
|
draw(draw-op),
|
||||||
|
draw-surface(surface-draw),
|
||||||
|
push-opacity(u8),
|
||||||
|
pop-opacity,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Revision-keyed display list to avoid copying unchanged draw-ops across WIT.
|
||||||
|
record render-frame {
|
||||||
|
revision: u64,
|
||||||
|
/// `none` means identical to `revision` — host reuses cached display list.
|
||||||
|
ops: option<list<draw-op>>,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package moonplasma:wm@0.2.0;
|
||||||
|
|
||||||
|
interface decoration {
|
||||||
|
use moonplasma:desktop/types@0.1.0.{rect, size, draw-op};
|
||||||
|
use policy.{window-state};
|
||||||
|
|
||||||
|
enum hit-role {
|
||||||
|
none,
|
||||||
|
titlebar,
|
||||||
|
close,
|
||||||
|
maximize,
|
||||||
|
minimize,
|
||||||
|
resize-n,
|
||||||
|
resize-s,
|
||||||
|
resize-e,
|
||||||
|
resize-w,
|
||||||
|
resize-nw,
|
||||||
|
resize-ne,
|
||||||
|
resize-sw,
|
||||||
|
resize-se,
|
||||||
|
}
|
||||||
|
|
||||||
|
record hit-region {
|
||||||
|
rect: rect,
|
||||||
|
role: hit-role,
|
||||||
|
}
|
||||||
|
|
||||||
|
record decoration-frame {
|
||||||
|
/// Insets reserved around the client surface: (top, right, bottom, left)
|
||||||
|
insets: tuple<u32, u32, u32, u32>,
|
||||||
|
ops: list<draw-op>,
|
||||||
|
hit-regions: list<hit-region>,
|
||||||
|
}
|
||||||
|
|
||||||
|
render: func(win: window-state, outer-size: size) -> decoration-frame;
|
||||||
|
}
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../theme.wit
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../types.wit
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package moonplasma:wm@0.2.0;
|
||||||
|
|
||||||
|
interface policy {
|
||||||
|
use moonplasma:desktop/types@0.1.0.{rect, size, point};
|
||||||
|
|
||||||
|
type window-id = u64;
|
||||||
|
|
||||||
|
flags window-caps {
|
||||||
|
can-move,
|
||||||
|
can-resize,
|
||||||
|
can-maximize,
|
||||||
|
can-minimize,
|
||||||
|
can-fullscreen,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum layout-mode {
|
||||||
|
floating,
|
||||||
|
tiling,
|
||||||
|
monocle,
|
||||||
|
}
|
||||||
|
|
||||||
|
record window-state {
|
||||||
|
id: window-id,
|
||||||
|
app-id: string,
|
||||||
|
title: string,
|
||||||
|
geometry: rect,
|
||||||
|
min-size: size,
|
||||||
|
max-size: option<size>,
|
||||||
|
focused: bool,
|
||||||
|
maximized: bool,
|
||||||
|
fullscreen: bool,
|
||||||
|
workspace: u32,
|
||||||
|
caps: window-caps,
|
||||||
|
}
|
||||||
|
|
||||||
|
variant window-request {
|
||||||
|
maximize(bool),
|
||||||
|
fullscreen(bool),
|
||||||
|
minimize(bool),
|
||||||
|
close,
|
||||||
|
activate,
|
||||||
|
move-to(point),
|
||||||
|
resize-to(size),
|
||||||
|
}
|
||||||
|
|
||||||
|
variant wm-action {
|
||||||
|
set-geometry(tuple<window-id, rect>),
|
||||||
|
focus(window-id),
|
||||||
|
raise(window-id),
|
||||||
|
close(window-id),
|
||||||
|
set-maximized(tuple<window-id, bool>),
|
||||||
|
set-fullscreen(tuple<window-id, bool>),
|
||||||
|
}
|
||||||
|
|
||||||
|
variant input-target {
|
||||||
|
client(tuple<window-id, point>),
|
||||||
|
decoration(tuple<window-id, point>),
|
||||||
|
shell-panel(point),
|
||||||
|
none,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called on startup or WM hot-swap to synchronize existing windows.
|
||||||
|
sync-windows: func(outputs: list<rect>, windows: list<window-state>) -> list<wm-action>;
|
||||||
|
on-window-open: func(win: window-state, work-area: rect) -> list<wm-action>;
|
||||||
|
on-window-close: func(id: window-id) -> list<wm-action>;
|
||||||
|
on-window-request: func(id: window-id, req: window-request, work-area: rect) -> list<wm-action>;
|
||||||
|
on-pointer: func(pos: point, button: option<u32>, pressed: bool) -> input-target;
|
||||||
|
set-layout-mode: func(mode: layout-mode, work-area: rect) -> list<wm-action>;
|
||||||
|
/// Returns window IDs in bottom-to-top Z-order.
|
||||||
|
stacking-order: func() -> list<window-id>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package moonplasma:wm@0.2.0;
|
||||||
|
|
||||||
|
world window-manager {
|
||||||
|
import moonplasma:desktop/theme@0.1.0;
|
||||||
|
export policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
world decoration-provider {
|
||||||
|
import moonplasma:desktop/theme@0.1.0;
|
||||||
|
export decoration;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/world/decoration-provider"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
warnings = "-44"
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// Generated using `moon info`, DON'T EDIT IT
|
||||||
|
package "moonplasma/desktop/world/window-manager"
|
||||||
|
|
||||||
|
// Values
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
// Types and methods
|
||||||
|
|
||||||
|
// Type aliases
|
||||||
|
|
||||||
|
// Traits
|
||||||
Reference in new issue
Block a user