diff --git a/README.md b/README.md index 0249df2..f5d53fc 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,8 @@ Face unlock, in the style of Howdy, comes with `just install`: then Settings > S add a face and use it for the password dialog and sudo (a PAM module; the password always still works). See [docs/face-unlock.md](docs/face-unlock.md), including what 2D face recognition can't protect against. Fingerprint unlock on the OnePlus 6T is an open investigation, not yet working: -[docs/fingerprint.md](docs/fingerprint.md). +[docs/fingerprint.md](docs/fingerprint.md). The session can lock (power button or `chandra-ctl +lock`), unlocking with a face or password: [docs/lock.md](docs/lock.md). ## What works diff --git a/components/compositor/gen/pkg.generated.mbti b/components/compositor/gen/pkg.generated.mbti new file mode 100644 index 0000000..f4458a6 --- /dev/null +++ b/components/compositor/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/compositor/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/compositor/gen/world/compositor/pkg.generated.mbti b/components/compositor/gen/world/compositor/pkg.generated.mbti new file mode 100644 index 0000000..95c78cc --- /dev/null +++ b/components/compositor/gen/world/compositor/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/compositor/gen/world/compositor" + +// Values +pub fn run(Array[String]) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/gamerig-library/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti b/components/gamerig-library/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti new file mode 100644 index 0000000..b4e2db9 --- /dev/null +++ b/components/gamerig-library/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti @@ -0,0 +1,27 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/gamerig-library/gen/interface/chandra/desktop/desktop-module" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn backdrop() -> WallpaperMode + +pub fn on_scroll(@types.Point, Int32, Int32) -> Bool + +pub fn tick(UInt32) -> UInt32 + +// Errors + +// Types and methods +pub(all) enum WallpaperMode { + OVER_WALLPAPER + REPLACE_WALLPAPER +} +pub fn WallpaperMode::from(Int32) -> Self +pub fn WallpaperMode::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/gamerig-library/gen/interface/chandra/desktop/module-config/pkg.generated.mbti b/components/gamerig-library/gen/interface/chandra/desktop/module-config/pkg.generated.mbti new file mode 100644 index 0000000..58df266 --- /dev/null +++ b/components/gamerig-library/gen/interface/chandra/desktop/module-config/pkg.generated.mbti @@ -0,0 +1,21 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/gamerig-library/gen/interface/chandra/desktop/module-config" + +// Values +pub fn config_items() -> Array[ConfigItem] + +pub fn set_config(String, String) -> Bool + +// Errors + +// Types and methods +pub(all) struct ConfigItem { + key : String + label : String + choices : Array[String] + value : String +} + +// Type aliases + +// Traits diff --git a/components/gamerig-library/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/gamerig-library/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..b5b1417 --- /dev/null +++ b/components/gamerig-library/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/gamerig-library/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/gamerig-library/gen/pkg.generated.mbti b/components/gamerig-library/gen/pkg.generated.mbti new file mode 100644 index 0000000..aab5709 --- /dev/null +++ b/components/gamerig-library/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/gamerig-library/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/icon-desktop/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti b/components/icon-desktop/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti new file mode 100644 index 0000000..7049a20 --- /dev/null +++ b/components/icon-desktop/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti @@ -0,0 +1,27 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/icon-desktop/gen/interface/chandra/desktop/desktop-module" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn backdrop() -> WallpaperMode + +pub fn on_scroll(@types.Point, Int32, Int32) -> Bool + +pub fn tick(UInt32) -> UInt32 + +// Errors + +// Types and methods +pub(all) enum WallpaperMode { + OVER_WALLPAPER + REPLACE_WALLPAPER +} +pub fn WallpaperMode::from(Int32) -> Self +pub fn WallpaperMode::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/icon-desktop/gen/interface/chandra/desktop/module-config/pkg.generated.mbti b/components/icon-desktop/gen/interface/chandra/desktop/module-config/pkg.generated.mbti new file mode 100644 index 0000000..72512e9 --- /dev/null +++ b/components/icon-desktop/gen/interface/chandra/desktop/module-config/pkg.generated.mbti @@ -0,0 +1,21 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/icon-desktop/gen/interface/chandra/desktop/module-config" + +// Values +pub fn config_items() -> Array[ConfigItem] + +pub fn set_config(String, String) -> Bool + +// Errors + +// Types and methods +pub(all) struct ConfigItem { + key : String + label : String + choices : Array[String] + value : String +} + +// Type aliases + +// Traits diff --git a/components/icon-desktop/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/icon-desktop/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..23d74c7 --- /dev/null +++ b/components/icon-desktop/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/icon-desktop/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/icon-desktop/gen/pkg.generated.mbti b/components/icon-desktop/gen/pkg.generated.mbti new file mode 100644 index 0000000..8814b03 --- /dev/null +++ b/components/icon-desktop/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/icon-desktop/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/inspector/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/inspector/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..a60b73d --- /dev/null +++ b/components/inspector/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/inspector/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/inspector/gen/pkg.generated.mbti b/components/inspector/gen/pkg.generated.mbti new file mode 100644 index 0000000..9473769 --- /dev/null +++ b/components/inspector/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/inspector/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/layout/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/layout/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..b7c59b4 --- /dev/null +++ b/components/layout/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/layout/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/layout/gen/pkg.generated.mbti b/components/layout/gen/pkg.generated.mbti new file mode 100644 index 0000000..db27747 --- /dev/null +++ b/components/layout/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/layout/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/network/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/network/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..d1d9d59 --- /dev/null +++ b/components/network/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/network/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/osk/gen/ffi.mbt b/components/osk/gen/ffi.mbt new file mode 100644 index 0000000..1de6a41 --- /dev/null +++ b/components/osk/gen/ffi.mbt @@ -0,0 +1,82 @@ +// 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 wasmExportPopupPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportPopupPostReturn(p0) +} + +///| +#doc(hidden) +pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { + @plasmoid.wasmExportOnEvent(p0, p1, p2, p3) +} + +///| +#doc(hidden) +pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int { + @plasmoid.wasmExportRender(p0, p1) +} + +///| +#doc(hidden) +pub fn wasmExportInfo() -> Int { + @plasmoid.wasmExportInfo() +} + +///| +#doc(hidden) +pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportRenderPostReturn(p0) +} + +///| +#doc(hidden) +pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportInfoPostReturn(p0) +} + +///| +#doc(hidden) +pub fn wasmExportPopup() -> Int { + @plasmoid.wasmExportPopup() +} + diff --git a/components/osk/gen/interface/chandra/desktop/plasmoid/README.md b/components/osk/gen/interface/chandra/desktop/plasmoid/README.md new file mode 100644 index 0000000..53ecf69 --- /dev/null +++ b/components/osk/gen/interface/chandra/desktop/plasmoid/README.md @@ -0,0 +1 @@ +The widget (plasmoid) contract. \ No newline at end of file diff --git a/components/osk/gen/interface/chandra/desktop/plasmoid/ffi.mbt b/components/osk/gen/interface/chandra/desktop/plasmoid/ffi.mbt new file mode 100644 index 0000000..1318cbb --- /dev/null +++ b/components/osk/gen/interface/chandra/desktop/plasmoid/ffi.mbt @@ -0,0 +1,431 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + +///| +#doc(hidden) +pub fn wasmExportInfo() -> Int { + + let (result) : (PlasmoidInfo) = info(); + let return_area = mbt_ffi_malloc(32) + + let ptr = mbt_ffi_str2ptr((result).id) + mbt_ffi_store32((return_area) + 4, (result).id.length()) + mbt_ffi_store32((return_area) + 0, ptr) + + let ptr0 = mbt_ffi_str2ptr((result).name) + mbt_ffi_store32((return_area) + 12, (result).name.length()) + mbt_ffi_store32((return_area) + 8, ptr0) + mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int()) + mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 })) + let ret = return_area + return ret + +} + +///| +#doc(hidden) +pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit { + mbt_ffi_free(mbt_ffi_load32((p0) + 0)) + mbt_ffi_free(mbt_ffi_load32((p0) + 8)) + +} + +///| +#doc(hidden) +pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int { + + let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).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 : @types.DrawOp = (result)[(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(payload0) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int()) + + () + } + Line(payload1) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store32((iter_base) + 4, ((payload1).start).x) + mbt_ffi_store32((iter_base) + 8, ((payload1).start).y) + mbt_ffi_store32((iter_base) + 12, ((payload1).end).x) + mbt_ffi_store32((iter_base) + 16, ((payload1).end).y) + mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int()) + + () + } + Circle(payload2) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 4, ((payload2).center).x) + mbt_ffi_store32((iter_base) + 8, ((payload2).center).y) + mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int()) + mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int()) + mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int()) + mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int()) + mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 })) + + () + } + Text(payload3) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x) + mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y) + + let ptr = mbt_ffi_str2ptr((payload3).text) + mbt_ffi_store32((iter_base) + 16, (payload3).text.length()) + mbt_ffi_store32((iter_base) + 12, ptr) + mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int()) + mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int()) + mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int()) + mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int()) + mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal()) + mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 })) + + () + } + PushClip(payload4) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store32((iter_base) + 4, (payload4).x) + mbt_ffi_store32((iter_base) + 8, (payload4).y) + mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int()) + + () + } + PopClip => { + mbt_ffi_store8((iter_base) + 0, (6)) + + () + } + Image(payload6) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 4, ((payload6).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload6).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload6).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload6).rect).h).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 20, ((payload6).image).reinterpret_as_int()) + + () + } + } + + } + 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 wasmExportRenderPostReturn(p0 : Int) -> Unit { + + for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 { + let iter_base = (mbt_ffi_load32((p0) + 0)) + (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 => () + 7 => () + _ => panic() + } + + } + mbt_ffi_free(mbt_ffi_load32((p0) + 0)) + +} + +///| +#doc(hidden) +pub fn wasmExportPopup() -> Int { + + let (result) : (PopupSurface?) = popup(); + let return_area = mbt_ffi_malloc(20) + + match (result) { + None => { + mbt_ffi_store8((return_area) + 0, (0)) + + () + } + Some(payload0) => { + mbt_ffi_store8((return_area) + 0, (1)) + mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int()) + + let address = mbt_ffi_malloc(((payload0).ops).length() * 32); + for index = 0; index < ((payload0).ops).length(); index = index + 1 { + let iter_elem : @types.DrawOp = ((payload0).ops)[(index)] + let iter_base = address + (index * 32); + + match iter_elem { + FillRect(payload1) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload1).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)) + + () + } + Image(payload8) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 4, ((payload8).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload8).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload8).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload8).rect).h).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 20, ((payload8).image).reinterpret_as_int()) + + () + } + } + + } + mbt_ffi_store32((return_area) + 16, ((payload0).ops).length()) + mbt_ffi_store32((return_area) + 12, address) + + () + } + } + let ret = return_area + return ret + +} + +///| +#doc(hidden) +pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit { + + match (mbt_ffi_load8_u((p0) + 0)) { + 0 => () + 1 => { + + for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 { + let iter_base = (mbt_ffi_load32((p0) + 12)) + (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 => () + 7 => () + _ => panic() + } + + } + mbt_ffi_free(mbt_ffi_load32((p0) + 12)) + + } + _ => panic() + } + +} + +///| +#doc(hidden) +pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { + + let lifted = match (p1) { + 0 => { + + @types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3}) + } + 1 => { + + @types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3}) + } + 2 => { + + @types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3}) + } + 3 => { + + @types.InputEvent::PointerLeave + } + 4 => { + + @types.InputEvent::FocusLost + } + 5 => { + + let result = mbt_ffi_ptr2str(p2, p3) + + @types.InputEvent::KeyDown(result) + } + _ => panic() + } + + let (result0) : (Bool) = on_event(Surface::from(p0), lifted); + let ret = (if result0 { 1 } else { 0 }) + return ret + +} + +///| +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) + +///| +#owned(str) +extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = +#|(func (param i32) (result i32) local.get 0) + +///| +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_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) + diff --git a/components/osk/gen/interface/chandra/desktop/plasmoid/moon.pkg b/components/osk/gen/interface/chandra/desktop/plasmoid/moon.pkg new file mode 100644 index 0000000..59ccfe9 --- /dev/null +++ b/components/osk/gen/interface/chandra/desktop/plasmoid/moon.pkg @@ -0,0 +1,8 @@ +import { + "chandra/desktop/interface/chandra/desktop/types" @types, + "chandra/desktop/interface/chandra/desktop/theme" @theme, + "chandra/desktop/interface/chandra/desktop/osk" @osk, + "chandra/desktop/lib/ui" @ui, +} + +warnings = "-44" diff --git a/components/osk/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/osk/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..0bb9681 --- /dev/null +++ b/components/osk/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/osk/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/osk/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/osk/gen/interface/chandra/desktop/plasmoid/stub.mbt new file mode 100644 index 0000000..2d77e78 --- /dev/null +++ b/components/osk/gen/interface/chandra/desktop/plasmoid/stub.mbt @@ -0,0 +1,45 @@ +///| Implementation of `chandra:desktop/plasmoid` for the on-screen keyboard toggle ("KB"): +/// a compact panel button that shows or hides the built-in OSK. + +///| +pub fn info() -> PlasmoidInfo { + { + id: "org.chandra.osk", + name: "Keyboard", + preferred: { w: 44, h: 34 }, + min_width: 34, + stretch: false, + } +} + +///| +pub fn render(size : @types.Size) -> Array[@types.DrawOp] { + let t = @theme.get_tokens() + let w = size.w.reinterpret_as_int() + let h = size.h.reinterpret_as_int() + let on = @osk.is_visible() + let bg = if on { t.palette.accent } else { t.palette.surface_hover } + let fg = if on { t.palette.accent_foreground } else { t.palette.foreground } + let fs = t.font_size.reinterpret_as_int() + let kfs = if fs - 2 < 10 { 10 } else { fs - 2 } + [ + @ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=t.radius.reinterpret_as_int()), + @ui.text(w / 2, h / 2, "KB", kfs, fg, align=CENTER, bold=true), + ] +} + +///| +pub fn popup() -> PopupSurface? { + None +} + +///| +pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { + match (target, event) { + (WIDGET, PointerDown(_)) => { + @osk.set_visible(!@osk.is_visible()) + true + } + _ => false + } +} diff --git a/components/osk/gen/interface/chandra/desktop/plasmoid/top.mbt b/components/osk/gen/interface/chandra/desktop/plasmoid/top.mbt new file mode 100644 index 0000000..24d7d0e --- /dev/null +++ b/components/osk/gen/interface/chandra/desktop/plasmoid/top.mbt @@ -0,0 +1,42 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! +///| +pub(all) struct PlasmoidInfo { + id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool +} +///| +pub(all) struct PopupSurface { + size : @types.Size; ops : Array[@types.DrawOp] +} +///| +pub(all) enum Surface { + WIDGET; POPUP +} derive() + +///| +pub fn Surface::ordinal(self : Surface) -> Int { + match self { + WIDGET => 0 + POPUP => 1 + } +} + +///| +pub fn Surface::from(self : Int) -> Surface { + match self { + 0 => WIDGET + 1 => POPUP + _ => panic() + } +} +///| +declare pub fn info() -> PlasmoidInfo +///| +/// Draw the widget into a `size` box (local coordinates). +declare pub fn render(size : @types.Size) -> Array[@types.DrawOp] +///| +/// Present when the widget wants a popup surface (e.g. a launcher menu). +declare pub fn popup() -> PopupSurface? +///| +/// Returns true when the widget's visuals changed and a redraw is needed. +declare pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool + diff --git a/components/osk/gen/moon.pkg b/components/osk/gen/moon.pkg new file mode 100644 index 0000000..5b1a87d --- /dev/null +++ b/components/osk/gen/moon.pkg @@ -0,0 +1,26 @@ +import { + "chandra/desktop/components/osk/gen/interface/chandra/desktop/plasmoid" @plasmoid, +} + +warnings = "-44" + +pkgtype(kind: "foreign_library") + +options( + link: { + "wasm": { + "export-memory-name": "memory", + "heap-start-address": 16, + "exports": [ + "mbt_ffi_cabi_realloc:cabi_realloc", + "wasmExportInfo:chandra:desktop/plasmoid@0.1.0#info", + "wasmExportInfoPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#info", + "wasmExportOnEvent:chandra:desktop/plasmoid@0.1.0#on-event", + "wasmExportPopup:chandra:desktop/plasmoid@0.1.0#popup", + "wasmExportPopupPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#popup", + "wasmExportRender:chandra:desktop/plasmoid@0.1.0#render", + "wasmExportRenderPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#render" + ], + }, + }, +) diff --git a/components/osk/gen/pkg.generated.mbti b/components/osk/gen/pkg.generated.mbti new file mode 100644 index 0000000..9771d85 --- /dev/null +++ b/components/osk/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/osk/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/rotate/gen/ffi.mbt b/components/rotate/gen/ffi.mbt new file mode 100644 index 0000000..cd9bad7 --- /dev/null +++ b/components/rotate/gen/ffi.mbt @@ -0,0 +1,82 @@ +// 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 wasmExportPopupPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportPopupPostReturn(p0) +} + +///| +#doc(hidden) +pub fn wasmExportPopup() -> Int { + @plasmoid.wasmExportPopup() +} + +///| +#doc(hidden) +pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { + @plasmoid.wasmExportOnEvent(p0, p1, p2, p3) +} + +///| +#doc(hidden) +pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int { + @plasmoid.wasmExportRender(p0, p1) +} + +///| +#doc(hidden) +pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportRenderPostReturn(p0) +} + +///| +#doc(hidden) +pub fn wasmExportInfo() -> Int { + @plasmoid.wasmExportInfo() +} + +///| +#doc(hidden) +pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportInfoPostReturn(p0) +} + diff --git a/components/rotate/gen/interface/chandra/desktop/plasmoid/README.md b/components/rotate/gen/interface/chandra/desktop/plasmoid/README.md new file mode 100644 index 0000000..53ecf69 --- /dev/null +++ b/components/rotate/gen/interface/chandra/desktop/plasmoid/README.md @@ -0,0 +1 @@ +The widget (plasmoid) contract. \ No newline at end of file diff --git a/components/rotate/gen/interface/chandra/desktop/plasmoid/ffi.mbt b/components/rotate/gen/interface/chandra/desktop/plasmoid/ffi.mbt new file mode 100644 index 0000000..282530f --- /dev/null +++ b/components/rotate/gen/interface/chandra/desktop/plasmoid/ffi.mbt @@ -0,0 +1,431 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + +///| +#doc(hidden) +pub fn wasmExportInfo() -> Int { + + let (result) : (PlasmoidInfo) = info(); + let return_area = mbt_ffi_malloc(32) + + let ptr = mbt_ffi_str2ptr((result).id) + mbt_ffi_store32((return_area) + 4, (result).id.length()) + mbt_ffi_store32((return_area) + 0, ptr) + + let ptr0 = mbt_ffi_str2ptr((result).name) + mbt_ffi_store32((return_area) + 12, (result).name.length()) + mbt_ffi_store32((return_area) + 8, ptr0) + mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int()) + mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 })) + let ret = return_area + return ret + +} + +///| +#doc(hidden) +pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit { + mbt_ffi_free(mbt_ffi_load32((p0) + 0)) + mbt_ffi_free(mbt_ffi_load32((p0) + 8)) + +} + +///| +#doc(hidden) +pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int { + + let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).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 : @types.DrawOp = (result)[(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(payload0) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int()) + + () + } + Line(payload1) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store32((iter_base) + 4, ((payload1).start).x) + mbt_ffi_store32((iter_base) + 8, ((payload1).start).y) + mbt_ffi_store32((iter_base) + 12, ((payload1).end).x) + mbt_ffi_store32((iter_base) + 16, ((payload1).end).y) + mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int()) + + () + } + Circle(payload2) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 4, ((payload2).center).x) + mbt_ffi_store32((iter_base) + 8, ((payload2).center).y) + mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int()) + mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int()) + mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int()) + mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int()) + mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 })) + + () + } + Text(payload3) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x) + mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y) + + let ptr = mbt_ffi_str2ptr((payload3).text) + mbt_ffi_store32((iter_base) + 16, (payload3).text.length()) + mbt_ffi_store32((iter_base) + 12, ptr) + mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int()) + mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int()) + mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int()) + mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int()) + mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal()) + mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 })) + + () + } + PushClip(payload4) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store32((iter_base) + 4, (payload4).x) + mbt_ffi_store32((iter_base) + 8, (payload4).y) + mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int()) + + () + } + PopClip => { + mbt_ffi_store8((iter_base) + 0, (6)) + + () + } + Image(payload6) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 4, ((payload6).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload6).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload6).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload6).rect).h).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 20, ((payload6).image).reinterpret_as_int()) + + () + } + } + + } + 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 wasmExportRenderPostReturn(p0 : Int) -> Unit { + + for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 { + let iter_base = (mbt_ffi_load32((p0) + 0)) + (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 => () + 7 => () + _ => panic() + } + + } + mbt_ffi_free(mbt_ffi_load32((p0) + 0)) + +} + +///| +#doc(hidden) +pub fn wasmExportPopup() -> Int { + + let (result) : (PopupSurface?) = popup(); + let return_area = mbt_ffi_malloc(20) + + match (result) { + None => { + mbt_ffi_store8((return_area) + 0, (0)) + + () + } + Some(payload0) => { + mbt_ffi_store8((return_area) + 0, (1)) + mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int()) + + let address = mbt_ffi_malloc(((payload0).ops).length() * 32); + for index = 0; index < ((payload0).ops).length(); index = index + 1 { + let iter_elem : @types.DrawOp = ((payload0).ops)[(index)] + let iter_base = address + (index * 32); + + match iter_elem { + FillRect(payload1) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload1).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)) + + () + } + Image(payload8) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 4, ((payload8).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload8).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload8).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload8).rect).h).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 20, ((payload8).image).reinterpret_as_int()) + + () + } + } + + } + mbt_ffi_store32((return_area) + 16, ((payload0).ops).length()) + mbt_ffi_store32((return_area) + 12, address) + + () + } + } + let ret = return_area + return ret + +} + +///| +#doc(hidden) +pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit { + + match (mbt_ffi_load8_u((p0) + 0)) { + 0 => () + 1 => { + + for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 { + let iter_base = (mbt_ffi_load32((p0) + 12)) + (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 => () + 7 => () + _ => panic() + } + + } + mbt_ffi_free(mbt_ffi_load32((p0) + 12)) + + } + _ => panic() + } + +} + +///| +#doc(hidden) +pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { + + let lifted = match (p1) { + 0 => { + + @types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3}) + } + 1 => { + + @types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3}) + } + 2 => { + + @types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3}) + } + 3 => { + + @types.InputEvent::PointerLeave + } + 4 => { + + @types.InputEvent::FocusLost + } + 5 => { + + let result = mbt_ffi_ptr2str(p2, p3) + + @types.InputEvent::KeyDown(result) + } + _ => panic() + } + + let (result0) : (Bool) = on_event(Surface::from(p0), lifted); + let ret = (if result0 { 1 } else { 0 }) + return ret + +} + +///| +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_free(position : Int) = +#|(func (param i32) local.get 0 call $moonbit.decref) + +///| +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_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_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) + +///| +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) + diff --git a/components/rotate/gen/interface/chandra/desktop/plasmoid/moon.pkg b/components/rotate/gen/interface/chandra/desktop/plasmoid/moon.pkg new file mode 100644 index 0000000..591a56e --- /dev/null +++ b/components/rotate/gen/interface/chandra/desktop/plasmoid/moon.pkg @@ -0,0 +1,8 @@ +import { + "chandra/desktop/interface/chandra/desktop/types" @types, + "chandra/desktop/interface/chandra/desktop/theme" @theme, + "chandra/desktop/interface/chandra/desktop/rotation" @rotation, + "chandra/desktop/lib/ui" @ui, +} + +warnings = "-44" diff --git a/components/rotate/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/rotate/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..10fbb9a --- /dev/null +++ b/components/rotate/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/rotate/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/rotate/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/rotate/gen/interface/chandra/desktop/plasmoid/stub.mbt new file mode 100644 index 0000000..0e394cd --- /dev/null +++ b/components/rotate/gen/interface/chandra/desktop/plasmoid/stub.mbt @@ -0,0 +1,45 @@ +///| Implementation of `chandra:desktop/plasmoid` for display rotation ("Rot"): +/// a compact panel button that rotates the output 90° clockwise on click. + +///| +pub fn info() -> PlasmoidInfo { + { + id: "org.chandra.rotate", + name: "Rotate", + preferred: { w: 44, h: 34 }, + min_width: 34, + stretch: false, + } +} + +///| +pub fn render(size : @types.Size) -> Array[@types.DrawOp] { + let t = @theme.get_tokens() + let w = size.w.reinterpret_as_int() + let h = size.h.reinterpret_as_int() + let on = @rotation.current() != 0U + let bg = if on { t.palette.accent } else { t.palette.surface_hover } + let fg = if on { t.palette.accent_foreground } else { t.palette.foreground } + let fs = t.font_size.reinterpret_as_int() + let rfs = if fs - 2 < 10 { 10 } else { fs - 2 } + [ + @ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=t.radius.reinterpret_as_int()), + @ui.text(w / 2, h / 2, "Rot", rfs, fg, align=CENTER, bold=true), + ] +} + +///| +pub fn popup() -> PopupSurface? { + None +} + +///| +pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { + match (target, event) { + (WIDGET, PointerDown(_)) => { + @rotation.set_rotation((@rotation.current() + 1U) % 4U) + true + } + _ => false + } +} diff --git a/components/rotate/gen/interface/chandra/desktop/plasmoid/top.mbt b/components/rotate/gen/interface/chandra/desktop/plasmoid/top.mbt new file mode 100644 index 0000000..24d7d0e --- /dev/null +++ b/components/rotate/gen/interface/chandra/desktop/plasmoid/top.mbt @@ -0,0 +1,42 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! +///| +pub(all) struct PlasmoidInfo { + id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool +} +///| +pub(all) struct PopupSurface { + size : @types.Size; ops : Array[@types.DrawOp] +} +///| +pub(all) enum Surface { + WIDGET; POPUP +} derive() + +///| +pub fn Surface::ordinal(self : Surface) -> Int { + match self { + WIDGET => 0 + POPUP => 1 + } +} + +///| +pub fn Surface::from(self : Int) -> Surface { + match self { + 0 => WIDGET + 1 => POPUP + _ => panic() + } +} +///| +declare pub fn info() -> PlasmoidInfo +///| +/// Draw the widget into a `size` box (local coordinates). +declare pub fn render(size : @types.Size) -> Array[@types.DrawOp] +///| +/// Present when the widget wants a popup surface (e.g. a launcher menu). +declare pub fn popup() -> PopupSurface? +///| +/// Returns true when the widget's visuals changed and a redraw is needed. +declare pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool + diff --git a/components/rotate/gen/moon.pkg b/components/rotate/gen/moon.pkg new file mode 100644 index 0000000..f601e94 --- /dev/null +++ b/components/rotate/gen/moon.pkg @@ -0,0 +1,26 @@ +import { + "chandra/desktop/components/rotate/gen/interface/chandra/desktop/plasmoid" @plasmoid, +} + +warnings = "-44" + +pkgtype(kind: "foreign_library") + +options( + link: { + "wasm": { + "export-memory-name": "memory", + "heap-start-address": 16, + "exports": [ + "mbt_ffi_cabi_realloc:cabi_realloc", + "wasmExportInfo:chandra:desktop/plasmoid@0.1.0#info", + "wasmExportInfoPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#info", + "wasmExportOnEvent:chandra:desktop/plasmoid@0.1.0#on-event", + "wasmExportPopup:chandra:desktop/plasmoid@0.1.0#popup", + "wasmExportPopupPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#popup", + "wasmExportRender:chandra:desktop/plasmoid@0.1.0#render", + "wasmExportRenderPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#render" + ], + }, + }, +) diff --git a/components/rotate/gen/pkg.generated.mbti b/components/rotate/gen/pkg.generated.mbti new file mode 100644 index 0000000..f798482 --- /dev/null +++ b/components/rotate/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/rotate/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/screenshot/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/screenshot/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..dfa9ead --- /dev/null +++ b/components/screenshot/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/screenshot/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/screenshot/gen/pkg.generated.mbti b/components/screenshot/gen/pkg.generated.mbti new file mode 100644 index 0000000..10466e0 --- /dev/null +++ b/components/screenshot/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/screenshot/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/session-settings/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/session-settings/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..f80e612 --- /dev/null +++ b/components/session-settings/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,44 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/session-settings/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +type Row + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt index 962dd4d..9532a60 100644 --- a/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt +++ b/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt @@ -174,7 +174,7 @@ let categories : Array[String] = ["Apps and windows", "System", "Clocks", "Other fn category_of(id : String) -> String { match id { "launcher" | "dock" | "layout" => "Apps and windows" - "session-settings" | "network" | "battery" | "screenshot" => "System" + "session-settings" | "network" | "battery" | "screenshot" | "rotate" | "osk" => "System" "clock-digital" | "clock-binary" | "moon-disc" => "Clocks" _ => "Other" } @@ -190,6 +190,8 @@ fn description_of(id : String) -> String { "network" => "Wi-Fi and wired network" "battery" => "Charge and time left" "screenshot" => "Capture or record the screen" + "rotate" => "Rotate the display 90° clockwise" + "osk" => "Show or hide the on-screen keyboard" "clock-digital" => "The time, 12 or 24-hour" "clock-binary" => "The time in binary" "moon-disc" => "Tonight's moon phase" diff --git a/components/session-settings/gen/pkg.generated.mbti b/components/session-settings/gen/pkg.generated.mbti new file mode 100644 index 0000000..bf5f419 --- /dev/null +++ b/components/session-settings/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/session-settings/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/components/starfield/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti b/components/starfield/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti new file mode 100644 index 0000000..f757de9 --- /dev/null +++ b/components/starfield/gen/interface/chandra/desktop/desktop-module/pkg.generated.mbti @@ -0,0 +1,27 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/starfield/gen/interface/chandra/desktop/desktop-module" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn backdrop() -> WallpaperMode + +pub fn on_scroll(@types.Point, Int32, Int32) -> Bool + +pub fn tick(UInt32) -> UInt32 + +// Errors + +// Types and methods +pub(all) enum WallpaperMode { + OVER_WALLPAPER + REPLACE_WALLPAPER +} +pub fn WallpaperMode::from(Int32) -> Self +pub fn WallpaperMode::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/starfield/gen/interface/chandra/desktop/module-config/pkg.generated.mbti b/components/starfield/gen/interface/chandra/desktop/module-config/pkg.generated.mbti new file mode 100644 index 0000000..7bbc6d1 --- /dev/null +++ b/components/starfield/gen/interface/chandra/desktop/module-config/pkg.generated.mbti @@ -0,0 +1,21 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/starfield/gen/interface/chandra/desktop/module-config" + +// Values +pub fn config_items() -> Array[ConfigItem] + +pub fn set_config(String, String) -> Bool + +// Errors + +// Types and methods +pub(all) struct ConfigItem { + key : String + label : String + choices : Array[String] + value : String +} + +// Type aliases + +// Traits diff --git a/components/starfield/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/starfield/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti new file mode 100644 index 0000000..497c897 --- /dev/null +++ b/components/starfield/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti @@ -0,0 +1,42 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/starfield/gen/interface/chandra/desktop/plasmoid" + +import { + "chandra/desktop/interface/chandra/desktop/types", +} + +// Values +pub fn info() -> PlasmoidInfo + +pub fn on_event(Surface, @types.InputEvent) -> Bool + +pub fn popup() -> PopupSurface? + +pub fn render(@types.Size) -> Array[@types.DrawOp] + +// Errors + +// Types and methods +pub(all) struct PlasmoidInfo { + id : String + name : String + preferred : @types.Size + min_width : UInt32 + stretch : Bool +} + +pub(all) struct PopupSurface { + size : @types.Size + ops : Array[@types.DrawOp] +} + +pub(all) enum Surface { + WIDGET + POPUP +} +pub fn Surface::from(Int32) -> Self +pub fn Surface::ordinal(Self) -> Int32 + +// Type aliases + +// Traits diff --git a/components/starfield/gen/pkg.generated.mbti b/components/starfield/gen/pkg.generated.mbti new file mode 100644 index 0000000..eb5bb90 --- /dev/null +++ b/components/starfield/gen/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/components/starfield/gen" + +// Values +pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/compositor/host/auth.mbt b/compositor/host/auth.mbt index 58b8103..770635e 100644 --- a/compositor/host/auth.mbt +++ b/compositor/host/auth.mbt @@ -184,6 +184,10 @@ fn ChandraCompositor::auth_drop_link(self : ChandraCompositor, l : AuthLink) -> Some(ui) if physical_equal(ui.link, l) => self.close_auth(false) _ => () } + match self.auth_agent { + Some(a) if physical_equal(a, l) => self.unlock_pending = false + _ => () + } l.conn.close() } @@ -207,6 +211,7 @@ fn ChandraCompositor::auth_tick(self : ChandraCompositor) -> Unit { Some(l) => if !self.auth_serve(l) { self.auth_agent = None + self.unlock_pending = false let why = if l.error != "" { l.error } else { @@ -264,6 +269,9 @@ fn ChandraCompositor::auth_serve(self : ChandraCompositor, l : AuthLink) -> Bool if !l.demo { @sys.log("chandra: chandra-polkit-agent registered with polkit") self.auth_slow_said = false + if self.locked && !self.manual_screen_off && !self.screen_off { + self.request_unlock() + } } } "error" => { @@ -271,6 +279,9 @@ fn ChandraCompositor::auth_serve(self : ChandraCompositor, l : AuthLink) -> Bool @sys.log("chandra: chandra-polkit-agent: " + l.error) } "request" => l.view = Some(@polkit.AuthView::from_request(f)) + // Session unlock (lock.mbt): the agent's org.chandra.unlock authorization resolved. + "unlocked" => if !l.demo { self.unlocked() } + "unlock-failed" => if !l.demo { self.unlock_failed() } "close" => { match self.auth { Some(ui) if physical_equal(ui.link, l) && ui.view.id == f.get(1).unwrap_or("") => self.close_auth(false) @@ -327,9 +338,11 @@ fn ChandraCompositor::close_auth(self : ChandraCompositor, dismiss : Bool) -> Un ui.view.wipe() self.auth = None ui.link.view = None - match ui.prev_kbd { - Some(w) => if self.windows.contains(w) { self.set_kbd_focus(Some(w)) } - None => () + if !self.locked { + match ui.prev_kbd { + Some(w) => if self.windows.contains(w) { self.set_kbd_focus(Some(w)) } + None => () + } } self.osk_sync() self.damage.mark_full() diff --git a/compositor/host/auth_test.mbt b/compositor/host/auth_test.mbt index e9ee39d..e4a4ba6 100644 --- a/compositor/host/auth_test.mbt +++ b/compositor/host/auth_test.mbt @@ -29,7 +29,8 @@ fn auth_bus(tag : String) -> String? { } ///| The mock polkitd: owns org.freedesktop.PolicyKit1, records the agent that registers, and -/// collects answers to the BeginAuthentication calls it makes. +/// collects answers to the BeginAuthentication calls it makes. Also handles CheckAuthorization / +/// CancelCheckAuthorization for org.chandra.unlock using `unix-process`. struct MockAuthority { bus : @network.DBus mut agent : String @@ -37,6 +38,14 @@ struct MockAuthority { mut refuse : String /// Answers to BeginAuthentication: "ok" or the error name. answers : Array[String] + /// Subjects passed to CheckAuthorization. + check_subjects : Array[@network.DValue] + /// Cancel ids passed to CancelCheckAuthorization. + cancelled_ids : Array[String] + /// Monotonic cookie counter for CheckAuthorization -> BeginAuthentication. + mut check_seq : Int + /// In-flight CheckAuthorization calls: (cookie, cancel_id, call_msg). + pending_checks : Array[(String, String, @network.DMessage)] } ///| @@ -50,7 +59,16 @@ fn MockAuthority::new(path : String) -> MockAuthority { 1000, ) guard r is Some({ body: [U32(1U)], .. }) else { abort("could not own org.freedesktop.PolicyKit1") } - let a = { bus, agent: "", refuse: "", answers: [] } + let a = { + bus, + agent: "", + refuse: "", + answers: [], + check_subjects: [], + cancelled_ids: [], + check_seq: 0, + pending_checks: [], + } bus.set_on_call(fn(m) { match m.meth { "RegisterAuthenticationAgent" => @@ -66,6 +84,68 @@ fn MockAuthority::new(path : String) -> MockAuthority { } } "UnregisterAuthenticationAgent" => bus.reply(m, []) + "CheckAuthorization" => + match m.body { + [Struct([Str("unix-process"), Arr(_, _)]) as subj, Str(action_id), _, U32(_), Str(cancel_id)] => { + a.check_subjects.push(subj) + a.check_seq = a.check_seq + 1 + let cookie = "unlock-cookie-" + a.check_seq.to_string() + a.pending_checks.push((cookie, cancel_id, m)) + let ids : Array[@network.DValue] = [ + Struct([ + Str("unix-user"), + @network.dict("v", [("uid", Variant(U32(@polkit.own_uid().reinterpret_as_uint())))]), + ]), + ] + ignore( + bus.call( + @network.DMessage::call(a.agent, @polkit.agent_path, @polkit.agent_iface, "BeginAuthentication", [ + Str(action_id), + Str("Authentication is required to unlock the screen"), + Str(""), + @network.DValue::Arr("{ss}", []), + Str(cookie), + Arr("(sa{sv})", ids), + ]), + on_reply=fn(rm) { + let ok = rm.mtype == @network.method_return + a.answers.push(if ok { "ok" } else { rm.error_name }) + match a.pending_checks.search_by(c => c.0 == cookie) { + Some(idx) => { + let (_, _, req_msg) = a.pending_checks.remove(idx) + bus.reply(req_msg, [Struct([Bool(ok), Bool(false), @network.dict("s", [])])]) + } + None => () + } + }, + ), + ) + } + _ => bus.reply_error(m, "org.freedesktop.DBus.Error.InvalidArgs", "bad CheckAuthorization args") + } + "CancelCheckAuthorization" => + match m.body { + [Str(cancel_id)] => { + a.cancelled_ids.push(cancel_id) + match a.pending_checks.search_by(c => c.1 == cancel_id) { + Some(idx) => { + let (cookie, _, req_msg) = a.pending_checks.remove(idx) + ignore( + bus.call( + @network.DMessage::call(a.agent, @polkit.agent_path, @polkit.agent_iface, "CancelAuthentication", [ + Str(cookie), + ]), + on_reply=fn(_) { () }, + ), + ) + bus.reply(req_msg, [Struct([Bool(false), Bool(false), @network.dict("s", [])])]) + } + None => () + } + bus.reply(m, []) + } + _ => bus.reply_error(m, "org.freedesktop.DBus.Error.InvalidArgs", "bad CancelCheckAuthorization args") + } _ => bus.reply_error(m, "org.freedesktop.DBus.Error.UnknownMethod", m.meth) } }) diff --git a/compositor/host/compositor.mbt b/compositor/host/compositor.mbt index 747b2d1..d2875c0 100644 --- a/compositor/host/compositor.mbt +++ b/compositor/host/compositor.mbt @@ -153,6 +153,14 @@ pub(all) struct ChandraCompositor { mut screen_off : Bool mut manual_screen_off : Bool mut idle_suspended : Bool + /// The session is locked (lock.mbt): the desktop is hidden and input only reaches the unlock + /// dialog until a face or password unlocks it. + mut locked : Bool + /// Whether turning the screen off (power button) also locks the session. `chandra-ctl lock` + /// locks regardless. Off by default; CHANDRA_LOCK=1 or the setting turns it on. + mut lock_on_blank : Bool + /// An unlock request is out to the agent and we are waiting (don't ask again every wake). + mut unlock_pending : Bool mut output_w : Int mut output_h : Int mut work_area : @wm.Rect @@ -367,6 +375,8 @@ pub fn ChandraCompositor::new( ) let work_area = work_area_for(output_w, output_h, theme) let shell = @shell.DesktopShell::new(socket_path) + let init_rot = initial_rotation_from_env() + shell.rotation = init_rot shell.set_output(theme, output_w, output_h) let comp : ChandraCompositor = { server, @@ -400,6 +410,9 @@ pub fn ChandraCompositor::new( screen_off: false, manual_screen_off: false, idle_suspended: false, + locked: false, + lock_on_blank: @sys.getenv("CHANDRA_LOCK") == "1", + unlock_pending: false, output_w, output_h, work_area, @@ -493,7 +506,7 @@ pub fn ChandraCompositor::new( osk_pressed: None, osk_hover: None, osk_pointer_grab: false, - rotation: initial_rotation_from_env(), + rotation: init_rot, pending_rotation: None, vol_run: None, vol_queue: [], @@ -568,6 +581,7 @@ fn initial_rotation_from_env() -> Int { pub fn ChandraCompositor::request_rotation(self : ChandraCompositor, rot : Int) -> Unit { let r = (rot % 4 + 4) % 4 self.pending_rotation = Some(r) + self.shell.rotation = r self.damage.mark_full() } @@ -1235,8 +1249,9 @@ fn ChandraCompositor::build_scene( self.overview_sync() let scene = @scene.SceneGraph::new(self.output_w, self.output_h) let order = self.wm.stacking_order() - // The overview draws the windows itself, as previews. - let shown = if self.overview is Some(_) { [] } else { order } + // The overview draws the windows itself, as previews. A locked session hides every window + // behind the unlock dialog (lock.mbt). + let shown = if self.overview is Some(_) || self.locked { [] } else { order } for wid in shown { self.push_window_node(scene, wid) @@ -1266,17 +1281,19 @@ fn ChandraCompositor::build_scene( } } - // Client menus would draw above the auth dialog: none while it is up. - for p in (if self.auth is Some(_) { [] } else { self.popups }) { + // Client menus would draw above the auth dialog: none while it is up or the session is locked. + for p in (if self.auth is Some(_) || self.locked { [] } else { self.popups }) { match p.surface { Some(snap) => if self.overview is None { scene.popups.push((self.popup_rect(p), snap)) } None => () } } // The drag icon, over every window and menu. - match self.dnd_icon_node() { - Some(n) => scene.popups.push(n) - None => () + if !self.locked { + match self.dnd_icon_node() { + Some(n) => scene.popups.push(n) + None => () + } } self.shell.layout_sel = match self.layout_mode { @@ -1287,6 +1304,8 @@ fn ChandraCompositor::build_scene( self.sync_shell_windows() self.shell.screenshot_state = (if self.rec is Some(_) { 1 } else { 0 }) | (if self.rec_pointer { 2 } else { 0 }) + self.shell.osk_visible = self.osk_visible + self.shell.rotation = self.pending_rotation.unwrap_or(self.rotation) // A window over the whole desktop (maximized, fullscreen, monocle) pauses a desktop module's // animation: nobody can see it. self.shell.set_desktop_covered(self.desktop_covered()) @@ -1294,24 +1313,34 @@ fn ChandraCompositor::build_scene( let (bg_ops, shell_ops) = self.shell.render(self.output_w, self.output_h, self.theme) // The overview goes under the panel and the launcher. self.overview_sync() - let panel_ops = self.overview_ops() - panel_ops.append(shell_ops) - if self.switcher_on { - panel_ops.append(self.switcher_ops()) + let panel_ops = if self.locked { + let ops = self.lock_ops() + ops.append(self.auth_ops()) + ops.append(self.auth_notice_ops()) + ops.append(self.osk_ops()) + ops.append(self.volume_ops()) + ops + } else { + let ops = self.overview_ops() + ops.append(shell_ops) + if self.switcher_on { + ops.append(self.switcher_ops()) + } + ops.append(self.screenshot_ops()) + ops.append(self.emoji_ops()) + ops.append(self.face_window_ops()) + ops.append(self.auth_ops()) + ops.append(self.auth_notice_ops()) + ops.append(self.osk_ops()) + ops.append(self.volume_ops()) + ops } - panel_ops.append(self.screenshot_ops()) - panel_ops.append(self.emoji_ops()) - panel_ops.append(self.face_window_ops()) - panel_ops.append(self.auth_ops()) - panel_ops.append(self.auth_notice_ops()) - panel_ops.append(self.osk_ops()) - panel_ops.append(self.volume_ops()) self.frames_built = self.frames_built + 1 self.run_shell_actions() // The wallpaper (the first ops) is cached by the renderer; the desktop card after it changes. let n_wall = if self.shell.wallpaper_len <= bg_ops.length() { self.shell.wallpaper_len } else { 0 } scene.wallpaper_ops = Array::makei(n_wall, i => bg_ops[i]) - scene.background_ops = Array::makei(bg_ops.length() - n_wall, i => bg_ops[n_wall + i]) + scene.background_ops = if self.locked { [] } else { Array::makei(bg_ops.length() - n_wall, i => bg_ops[n_wall + i]) } scene.panel_ops = panel_ops let damaged = self.damage.take_damage(self.output_w, self.output_h).length() > 0 let sig : FrameSig = { @@ -1964,6 +1993,8 @@ fn ChandraCompositor::run_shell_actions(self : ChandraCompositor) -> Unit { self.frame_changed = true self.damage.mark_full() } + @shell.ShellAction::SetOskVisible(v) => self.osk_set_manual_visible(v) + @shell.ShellAction::SetRotation(r) => self.request_rotation(r) @shell.ShellAction::SetLayout(m) => match m { 0 => self.set_layout_mode(@wm.LayoutMode::Tiling) @@ -2231,11 +2262,10 @@ fn ChandraCompositor::handle_input_inner( Key(116U, pressed) => { if pressed { if self.screen_off || self.manual_screen_off { - self.manual_screen_off = false - self.note_activity(@sys.monotonic_ms()) + self.set_manual_screen_off(false) } else { - self.manual_screen_off = true self.stop_volume_repeat() + self.set_manual_screen_off(true) } } return @@ -2256,6 +2286,20 @@ fn ChandraCompositor::handle_input_inner( } if self.screen_off { self.note_activity(@sys.monotonic_ms()) + if self.locked { + self.request_unlock() + } + return + } + // Locked: input only reaches the unlock dialog (dispatch_input_inner -> grab_input -> auth). + // Before the dialog is up, swallow everything so nothing leaks to the desktop or apps, and + // take the chance to (re-)raise the prompt only on a key or button press (not hover or release). + if self.locked && self.auth is None { + self.note_activity(@sys.monotonic_ms()) + match ev { + Key(_, true) | PointerButton(_, true) => self.request_unlock() + _ => () + } return } self.note_activity(@sys.monotonic_ms()) diff --git a/compositor/host/control.mbt b/compositor/host/control.mbt index 3a1c3cc..63d7ed8 100644 --- a/compositor/host/control.mbt +++ b/compositor/host/control.mbt @@ -301,6 +301,7 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin "screenshot [PATH] save a full-screen PNG directly (without opening the editor)", "rotate [cw|ccw|flip|0|90|180|270|status] rotate or flip the display", "screen [on|off|toggle|status] blank or wake the display", + "lock [lock|status|on-blank [on|off|status]] lock the session or configure lock-on-blank", "brightness [PCT|status] read or set display backlight percent (5..100)", "volume [up|down|mute|unmute|toggle|PCT|status] read or adjust audio volume", "osk [on|off|toggle|status] enable, disable, or query the on-screen keyboard", @@ -491,6 +492,44 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin _ => (["error usage: rotate [cw|ccw|flip|0|90|180|270|status]"], false) } } + "lock" => { + let arg = if words.length() >= 2 { words[1] } else { "lock" } + let usage = "error usage: lock [lock|status|on-blank [on|off|status]]" + match arg { + "status" => + if words.length() > 2 { + ([usage], false) + } else { + (["ok " + (if self.locked { "locked" } else { "unlocked" })], true) + } + "lock" => + if words.length() > 2 { + ([usage], false) + } else { + self.lock_now() + (["ok locked"], true) + } + "on-blank" => { + if words.length() > 3 { + return ([usage], false) + } + let sub = if words.length() >= 3 { words[2] } else { "status" } + match sub { + "status" => (["ok " + (if self.lock_on_blank { "on" } else { "off" })], true) + "on" => { + self.lock_on_blank = true + (["ok on"], true) + } + "off" => { + self.lock_on_blank = false + (["ok off"], true) + } + _ => ([usage], false) + } + } + _ => ([usage], false) + } + } "screen" => { let arg = if words.length() >= 2 { words[1] } else { "status" } if words.length() > 2 { diff --git a/compositor/host/lock.mbt b/compositor/host/lock.mbt new file mode 100644 index 0000000..cbf768b --- /dev/null +++ b/compositor/host/lock.mbt @@ -0,0 +1,121 @@ +///| Session lock (docs/lock.md): the compositor hides the desktop and only lets a face or +/// password bring it back. Locking is driven from the power button (when CHANDRA_LOCK=1 / +/// Settings turns on lock-on-blank) or `chandra-ctl lock`; unlocking reuses the password dialog. +/// +/// The unlock check runs in chandra-polkit-agent as a real polkit authorization of the +/// `org.chandra.unlock` action (compositor/polkit/agent_loop.mbt): the agent asks polkit, polkit +/// drives the agent's own dialog, and because the `polkit-1` PAM stack carries +/// `pam_chandra_face.so` (docs/face-unlock.md) the camera is tried first, with the password as +/// the fallback. The compositor only sends `unlock` and waits for `unlocked`. +/// +/// lock_now ──► request_unlock ──"unlock"──► agent ──► polkit ──► dialog (face, then password) +/// ▲ │ +/// │ success: "unlocked" ───┘──► unlocked +/// └── power off / chandra-ctl lock cancel: "unlock-failed" ──► stay locked + +///| Whether the session is locked right now. +pub fn ChandraCompositor::is_locked(self : ChandraCompositor) -> Bool { + self.locked +} + +///| Lock the session: hide the desktop and demand a face or password to return. Safe to call +/// when already locked. If the screen is on, the unlock prompt comes up at once; if it is off +/// (locked at blank), it comes up when the power button wakes the screen. +pub fn ChandraCompositor::lock_now(self : ChandraCompositor) -> Unit { + if self.locked { + return + } + // Dismiss any unrelated auth prompt before locking the session. + if self.auth is Some(_) { + self.close_auth(true) + } + self.locked = true + self.unlock_pending = false + // Nothing on the desktop keeps the keyboard or the pointer while locked. + self.set_kbd_focus(None) + self.leave_pointer() + self.osk_manual_show = false + self.osk_sync() + self.damage.mark_full() + self.frame_changed = true + if !self.manual_screen_off && !self.screen_off { + self.request_unlock() + } +} + +///| Ask the agent to run an unlock check. No-op if not locked, already asked, or no agent runs +/// (then the session simply stays locked until an agent is available and input re-raises it). +pub fn ChandraCompositor::request_unlock(self : ChandraCompositor) -> Unit { + if !self.locked || self.unlock_pending { + return + } + match self.auth_agent { + Some(l) => { + ignore(l.conn.send(["unlock"])) + self.unlock_pending = true + self.damage.mark_full() + self.frame_changed = true + } + None => () + } +} + +///| Cancel any active or pending unlock dialog (used when turning the screen off while locked). +pub fn ChandraCompositor::cancel_unlock(self : ChandraCompositor) -> Unit { + if self.auth is Some(_) { + self.close_auth(true) + } + if self.unlock_pending { + match self.auth_agent { + Some(l) => ignore(l.conn.send(["cancel-unlock"])) + None => () + } + self.unlock_pending = false + self.damage.mark_full() + self.frame_changed = true + } +} + +///| The agent said the unlock succeeded: return to the desktop. +pub fn ChandraCompositor::unlocked(self : ChandraCompositor) -> Unit { + if !self.locked { + return + } + self.locked = false + self.unlock_pending = false + self.note_activity(@sys.monotonic_ms()) + self.damage.mark_full() + self.frame_changed = true +} + +///| The unlock attempt ended without success (the user cancelled, or it failed): stay locked. +/// The prompt is raised again by the next key/button press or wake, not in a tight loop here. +pub fn ChandraCompositor::unlock_failed(self : ChandraCompositor) -> Unit { + self.unlock_pending = false + self.damage.mark_full() + self.frame_changed = true +} + +///| Draw the locked-screen backdrop and idle prompt when no auth card is open. +fn ChandraCompositor::lock_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] { + let ops : Array[@scene.DrawOp] = [] + if !self.locked { + return ops + } + let sw = self.output_w + let sh = self.output_h + let bg = @scene.Rgba::new(10, 12, 18, 225) + ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, sw, sh), bg, 0)) + if self.auth is None { + let p = self.theme.palette + let fs = self.theme.font_size + let s = 44 + let cx = sw / 2 + let cy = sh / 2 - 20 + lock_glyph(cx - s / 2, cy - s - 12, s, p.accent, bg, ops) + ops.push(@scene.DrawOp::Text(cx, cy + 8, "Screen locked", fs + 4, p.foreground, @scene.TextAlign::Center, true)) + let sub = if self.unlock_pending { "Starting unlock…" } else { "Tap or press any key to unlock" } + ops.push(@scene.DrawOp::Text(cx, cy + 36, sub, fs - 1, p.foreground_muted, @scene.TextAlign::Center, false)) + } + ops +} diff --git a/compositor/host/lock_test.mbt b/compositor/host/lock_test.mbt new file mode 100644 index 0000000..e7208ad --- /dev/null +++ b/compositor/host/lock_test.mbt @@ -0,0 +1,327 @@ +///| Session lock (lock.mbt): the compositor state machine, the `lock` control command, power +/// button / `screen` blanking, lock-screen hiding/backdrop, input gating, and end-to-end +/// polkit `unix-process` unlock + cancel/power-off/agent-restart flows. + +///| Whether any draw op renders `text`. +fn lock_has_text(ops : Array[@scene.DrawOp], text : String) -> Bool { + ops.iter().any(op => match op { + Text(_, _, t, _, _, _, _) | MonoText(_, _, t, _, _, _, _) => t == text + _ => false + }) +} + +///| Drain all lines currently queued on a test link. +fn lock_drain_lines(conn : @polkit.LineConn) -> Array[Array[String]] { + let out : Array[Array[String]] = [] + for line in conn.read_lines() { + out.push(@polkit.decode_line(line)) + } + out +} + +///| 1. Control commands: `lock`, `lock status`, `lock on-blank [on|off|status]`, invalid args. +test "lock: chandra-ctl lock, status, and on-blank toggles" { + let comp = new_comp("lock-cmd") + assert_false(comp.is_locked()) + assert_eq(comp.control_command("lock status").0, ["ok unlocked"]) + assert_eq(comp.control_command("lock on-blank status").0, ["ok off"]) + assert_eq(comp.control_command("lock on-blank").0, ["ok off"]) + assert_eq(comp.control_command("lock on-blank on").0, ["ok on"]) + assert_true(comp.lock_on_blank) + assert_eq(comp.control_command("lock on-blank status").0, ["ok on"]) + assert_eq(comp.control_command("lock on-blank off").0, ["ok off"]) + assert_false(comp.lock_on_blank) + let (out, ok) = comp.control_command("lock") + assert_true(ok) + assert_eq(out, ["ok locked"]) + assert_true(comp.is_locked()) + assert_eq(comp.control_command("lock status").0, ["ok locked"]) + // Locking again while already locked is a harmless no-op. + assert_true(comp.control_command("lock lock").1) + assert_true(comp.is_locked()) + comp.unlocked() + assert_false(comp.is_locked()) + // Bad arguments are rejected. + assert_false(comp.control_command("lock bogus").1) + assert_false(comp.control_command("lock status extra").1) + assert_false(comp.control_command("lock on-blank maybe").1) + assert_false(comp.control_command("lock on-blank on extra").1) + comp.close() +} + +///| 2. Power button and `screen off/on` consistency. +test "lock: power button and screen off/on respect lock_on_blank and wake locked" { + let comp = new_comp("lock-power") + // Off by default: blanking does not lock. + assert_false(comp.lock_on_blank) + comp.handle_input(@nested.InputEvent::Key(116U, true), 10U) + assert_true(comp.manual_screen_off) + assert_false(comp.is_locked()) + comp.handle_input(@nested.InputEvent::Key(116U, true), 20U) + assert_false(comp.manual_screen_off) + assert_false(comp.is_locked()) + + // Enabled via on-blank: both power button and `screen off` lock, and waking requests unlock. + assert_eq(comp.control_command("lock on-blank on").0, ["ok on"]) + comp.handle_input(@nested.InputEvent::Key(116U, true), 30U) + assert_true(comp.manual_screen_off) + assert_true(comp.is_locked()) + comp.handle_input(@nested.InputEvent::Key(116U, true), 40U) + assert_false(comp.manual_screen_off) + assert_true(comp.is_locked()) + comp.unlocked() + assert_false(comp.is_locked()) + + assert_eq(comp.control_command("screen off").0, ["ok off"]) + assert_true(comp.manual_screen_off) + assert_true(comp.is_locked()) + assert_eq(comp.control_command("screen on").0, ["ok on"]) + assert_false(comp.manual_screen_off) + assert_true(comp.is_locked()) + comp.close() +} + +///| 3. Locked scene hides windows, popups, desktop widgets, and panel while drawing lock backdrop. +test "lock: locked scene hides desktop, windows, popups and panel behind lock backdrop" { + let sock = "/tmp/wayland-moon-lock-scene-" + @sys.getpid().to_string() + ".sock" + let theme = @scene.ThemeTokens::moon_night() + let comp = @host.ChandraCompositor::new(sock, theme, 1280, 720).unwrap() + let (c, shm, surf, xdg, _tl, _deco) = open_and_configure_client(comp, sock, "Secret Notes", "notes") + commit_shm_frame(comp, c, shm, surf, xdg, 1UL) + match comp.compose_scene() { + Some(unlocked_scene) => { + assert_true(unlocked_scene.windows.length() >= 1) + assert_true(unlocked_scene.panel_ops.length() > 0) + } + None => fail("expected initial unlocked scene") + } + comp.lock_now() + assert_true(comp.is_locked()) + assert_true(comp.kbd_win is None) + match comp.compose_scene() { + Some(locked_scene) => { + assert_eq(locked_scene.windows.length(), 0) + assert_eq(locked_scene.popups.length(), 0) + assert_eq(locked_scene.background_ops.length(), 0) + assert_true(lock_has_text(locked_scene.panel_ops, "Screen locked")) + assert_true(lock_has_text(locked_scene.panel_ops, "Tap or press any key to unlock")) + } + None => fail("expected locked scene") + } + comp.close() +} + +///| 4. Input gating when locked with no dialog open: only presses re-trigger unlock. +test "lock: pointer move and key release do not re-trigger unlock; key/button press does" { + let comp = new_comp("lock-input") + let (mine, theirs) = sock_pair("lock-input") + let peer = @polkit.LineConn::new(theirs) + comp.auth_agent = Some({ + conn: @polkit.LineConn::new(mine), + demo: false, + ready: true, + error: "", + started: 0UL, + view: None, + }) + comp.lock_now() + assert_true(comp.unlock_pending) + assert_eq(lock_drain_lines(peer), [["unlock"]]) + + // Simulate previous unlock attempt failed -> dialog dismissed, prompt hidden. + comp.unlock_failed() + assert_false(comp.unlock_pending) + + // Pointer motion and releases must be swallowed WITHOUT sending `unlock`. + comp.handle_input(@nested.InputEvent::PointerMove(50.0, 60.0), 10U) + comp.handle_input(@nested.InputEvent::Key(28U, false), 11U) + comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 12U) + assert_false(comp.unlock_pending) + assert_eq(lock_drain_lines(peer), []) + + // Key press triggers unlock once. + comp.handle_input(@nested.InputEvent::Key(28U, true), 13U) + assert_true(comp.unlock_pending) + assert_eq(lock_drain_lines(peer), [["unlock"]]) + + // Simulate another failed attempt, then button press triggers unlock. + comp.unlock_failed() + assert_false(comp.unlock_pending) + comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 14U) + assert_true(comp.unlock_pending) + assert_eq(lock_drain_lines(peer), [["unlock"]]) + peer.close() + comp.close() +} + +///| 5. Demo agent cannot unlock a locked session. +test "lock: demo link unlocked message is ignored" { + let comp = new_comp("lock-demo-ignore") + let (mine, theirs) = sock_pair("lock-demo-ignore") + let peer = @polkit.LineConn::new(theirs) + comp.auth_demos.push({ + conn: @polkit.LineConn::new(mine), + demo: true, + ready: true, + error: "", + started: 0UL, + view: None, + }) + comp.lock_now() + assert_true(comp.is_locked()) + ignore(peer.send(["unlocked"])) + comp.step() + assert_true(comp.is_locked()) + peer.close() + comp.close() +} + +///| 6. End-to-end lock -> unix-process CheckAuthorization -> password & face unlock -> desktop restored. +test "lock: e2e unlock through mock polkitd (unix-process) succeeds and restores desktop" { + let bus = match auth_bus("lock-e2e") { + Some(b) => b + None => return + } + let (hpath, listen) = helper_socket("lock-e2e") + let r = rig("lock-e2e", Some(bus), hpath) + r.comp.start_auth_agent() + assert_true(r.settle(fn() { r.ready() })) + let a = r.authority() + + r.comp.lock_now() + assert_true(r.comp.is_locked()) + assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.phase == Asking || v.phase == Starting).unwrap_or(false) })) + assert_eq(a.check_subjects.length(), 1) + match a.check_subjects[0] { + Struct([Str(kind), _]) => assert_eq(kind, "unix-process") + _ => fail("expected unix-process subject") + } + assert_eq(r.view().title, "Screen locked") + + let (h, _) = r.helper_accept(listen) + helper_say(h, "PAM_TEXT_INFO Face unlock: looking for nandi…") + helper_say(h, "PAM_TEXT_INFO Face unlock: recognized nandi") + helper_say(h, "SUCCESS") + assert_true(r.settle(fn() { !r.comp.is_locked() && r.comp.auth_view() is None })) + assert_false(r.comp.unlock_pending) + @sys.close_fd(h) + @sys.close_fd(listen) + @sys.unlink(hpath) + r.comp.close() +} + +///| 7. Cancel unlock stays locked, ignores pointer release, then tap re-prompts and succeeds. +test "lock: cancelling unlock keeps session locked until next tap raises it again" { + let bus = match auth_bus("lock-cancel") { + Some(b) => b + None => return + } + let (hpath, listen) = helper_socket("lock-cancel") + let r = rig("lock-cancel", Some(bus), hpath) + r.comp.start_auth_agent() + assert_true(r.settle(fn() { r.ready() })) + let a = r.authority() + + r.comp.lock_now() + assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) })) + let (h1, _) = r.helper_accept(listen) + helper_say(h1, "PAM_PROMPT_ECHO_OFF Password: ") + assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.phase == Asking).unwrap_or(false) })) + + // Dismiss via Cancel button -> agent says unlock-failed -> session stays locked. + auth_click(r.comp, Cancel) + assert_true(r.settle(fn() { r.comp.auth_view() is None && !r.comp.unlock_pending && a.answers.length() == 1 })) + assert_true(r.comp.is_locked()) + @sys.close_fd(h1) + + // Moving pointer / releasing does not immediately re-open the dialog. + r.comp.handle_input(@nested.InputEvent::PointerMove(20.0, 20.0), 10U) + r.comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 11U) + r.pass() + assert_false(r.comp.unlock_pending) + assert_true(r.comp.auth_view() is None) + + // Tapping wakes a new unlock attempt and succeeds. + r.comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 12U) + r.comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 13U) + assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) })) + let (h2, _) = r.helper_accept(listen) + helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ") + assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.phase == Asking).unwrap_or(false) })) + auth_type(r.comp, "Right1") + auth_press(r.comp, 28U) + assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.phase == Checking).unwrap_or(false) })) + assert_eq(helper_lines(h2, 1), "Right1") + helper_say(h2, "SUCCESS") + assert_true(r.settle(fn() { !r.comp.is_locked() && r.comp.auth_view() is None })) + @sys.close_fd(h2) + @sys.close_fd(listen) + @sys.unlink(hpath) + r.comp.close() +} + +///| 8. Power off while unlock is in-flight cancels CheckAuthorization and re-prompts cleanly on wake. +test "lock: power off cancels in-flight unlock via CancelCheckAuthorization" { + let bus = match auth_bus("lock-pwrcancel") { + Some(b) => b + None => return + } + let (hpath, listen) = helper_socket("lock-pwrcancel") + let r = rig("lock-pwrcancel", Some(bus), hpath) + r.comp.start_auth_agent() + assert_true(r.settle(fn() { r.ready() })) + let a = r.authority() + + r.comp.lock_now() + assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) })) + let (h1, _) = r.helper_accept(listen) + + // Power button blanks screen -> cancels unlock & calls CancelCheckAuthorization. + r.comp.handle_input(@nested.InputEvent::Key(116U, true), 20U) + assert_true(r.comp.manual_screen_off) + assert_true(r.comp.is_locked()) + assert_false(r.comp.unlock_pending) + assert_true(r.settle(fn() { a.cancelled_ids.length() == 1 && r.comp.auth_view() is None })) + @sys.close_fd(h1) + + // Wake screen -> starts fresh unlock request cleanly. + r.comp.handle_input(@nested.InputEvent::Key(116U, true), 30U) + assert_false(r.comp.manual_screen_off) + assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) })) + let (h2, _) = r.helper_accept(listen) + helper_say(h2, "SUCCESS") + assert_true(r.settle(fn() { !r.comp.is_locked() && r.comp.auth_view() is None })) + @sys.close_fd(h2) + @sys.close_fd(listen) + @sys.unlink(hpath) + r.comp.close() +} + +///| 9. Agent disconnect/restart while locked clears unlock_pending and re-requests on ready. +test "lock: agent drop clears unlock_pending and restarted agent resumes unlock on ready" { + let bus = match auth_bus("lock-restart") { + Some(b) => b + None => return + } + let (hpath, listen) = helper_socket("lock-restart") + let r = rig("lock-restart", Some(bus), hpath) + r.comp.start_auth_agent() + assert_true(r.settle(fn() { r.ready() })) + + r.comp.lock_now() + assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) })) + let (h1, _) = r.helper_accept(listen) + + // Drop the first agent while locked -> auth_tick clears unlock_pending and restarts a new agent. + r.agents[0].shutdown() + assert_true(r.settle(fn() { r.agents.length() >= 2 && r.comp.auth_view() is Some(_) })) + @sys.close_fd(h1) + + let (h2, _) = r.helper_accept(listen) + helper_say(h2, "SUCCESS") + assert_true(r.settle(fn() { !r.comp.is_locked() && r.comp.auth_view() is None })) + @sys.close_fd(h2) + @sys.close_fd(listen) + @sys.unlink(hpath) + r.comp.close() +} diff --git a/compositor/host/osk.mbt b/compositor/host/osk.mbt index 3ba1134..56440d9 100644 --- a/compositor/host/osk.mbt +++ b/compositor/host/osk.mbt @@ -95,9 +95,9 @@ pub fn ChandraCompositor::osk_key_center(self : ChandraCompositor, label : Strin None } -///| Room kept below the keyboard for the panel (none in a strict kiosk, which has no panel). +///| Room kept below the keyboard for the panel (none in a strict kiosk or locked session, which have no panel). fn ChandraCompositor::osk_panel_room(self : ChandraCompositor) -> Int { - if self.kiosk_strict() { 0 } else { self.theme.panel_height } + if self.kiosk_strict() || self.locked { 0 } else { self.theme.panel_height } } ///| Height of the on-screen keyboard when shown. @@ -121,26 +121,10 @@ pub fn ChandraCompositor::osk_rect(self : ChandraCompositor) -> @scene.Rect { @scene.Rect::new(0, self.output_h - self.osk_panel_room() - h, self.output_w, h) } -///| Compact "KB" pill above the bottom-right corner of the panel when the OSK is enabled but -/// currently hidden, letting users summon the keyboard anywhere manually. -pub fn ChandraCompositor::osk_toggle_rect(self : ChandraCompositor) -> @scene.Rect { - let w = 44 - let h = 28 - let x = (self.output_w - w - 6).max(4) - let y = (self.output_h - self.theme.panel_height - h - 6).max(4) - @scene.Rect::new(x, y, w, h) -} - -///| Compact "Rot" pill beside the "KB" pill: tap rotates 90 deg CW, long-press/right-click flips 180 deg. -pub fn ChandraCompositor::osk_rotate_rect(self : ChandraCompositor) -> @scene.Rect { - let kb = self.osk_toggle_rect() - let w = 44 - @scene.Rect::new((kb.x - w - 6).max(4), kb.y, w, kb.h) -} - ///| Show or hide the OSK, resizing `work_area` and lifting panel popups so focused content stays /// above the keyboard. fn ChandraCompositor::osk_set_visible(self : ChandraCompositor, want : Bool) -> Unit { + self.shell.osk_visible = want if self.osk_visible == want { return } @@ -160,17 +144,32 @@ fn ChandraCompositor::osk_set_visible(self : ChandraCompositor, want : Bool) -> } } +///| Manually show or hide the OSK (called by the Keyboard panel module). +pub fn ChandraCompositor::osk_set_manual_visible(self : ChandraCompositor, want : Bool) -> Unit { + if want { + self.osk_manual_hide = false + self.osk_manual_show = true + self.osk_sync() + } else { + self.osk_manual_hide = true + self.osk_manual_show = false + self.osk_set_visible(false) + } + self.damage.mark_full() +} + ///| Synchronize OSK visibility with the active focus target (auth dialog, emoji picker, open /// shell popup, active text-input-v3 or terminal window). pub fn ChandraCompositor::osk_sync(self : ChandraCompositor) -> Unit { if !self.osk_enabled { - if self.osk_visible { - self.osk_set_visible(false) - } + let want = self.osk_manual_show && !self.osk_manual_hide && !(self.locked && self.auth is None) + self.osk_set_visible(want) return } let (target, auto_want) : (String, Bool) = if self.auth is Some(_) { ("auth", true) + } else if self.locked { + ("locked", false) } else if self.emoji_ui is Some(_) { ("emoji", true) } else if self.shell.popup_open() { @@ -223,7 +222,10 @@ fn ChandraCompositor::osk_on_shell_click(self : ChandraCompositor, xi : Int, yi } let mid = self.shell.open_popup_module_id() if mid == "launcher" { - self.osk_manual_hide = false + match self.shell.open_popup_rect() { + Some(r) if r.contains(xi, yi) => self.osk_manual_hide = false + _ => () + } } else if mid == "network" { match self.shell.open_popup_rect() { Some(r) if r.contains(xi, yi) => { @@ -449,17 +451,9 @@ fn ChandraCompositor::osk_key_at(self : ChandraCompositor, x : Int, y : Int) -> None } -///| Whether `(x, y)` hits either the open OSK or its compact corner pills ("Rot" / "KB"). +///| Whether `(x, y)` hits the open OSK. fn ChandraCompositor::osk_hit_any(self : ChandraCompositor, x : Int, y : Int) -> Bool { - if !self.osk_enabled { - return false - } - if self.osk_visible { - self.osk_rect().contains(x, y) - } else { - !self.kiosk_strict() && - (self.osk_toggle_rect().contains(x, y) || self.osk_rotate_rect().contains(x, y)) - } + self.osk_visible && self.osk_rect().contains(x, y) } ///| Route one virtual key press+release to the active target (auth dialog, emoji picker, open @@ -569,13 +563,13 @@ fn ChandraCompositor::osk_activate_key( self.damage.mark_full() } -///| Handle host input when over the OSK or its toggle pill. True if consumed. +///| Handle host input when over the visible OSK. True if consumed. fn ChandraCompositor::osk_input( self : ChandraCompositor, ev : @nested.InputEvent, time_ms : UInt, ) -> Bool { - if !self.osk_enabled { + if !self.osk_visible { return false } match ev { @@ -584,46 +578,17 @@ fn ChandraCompositor::osk_input( self.ptr_y = y let xi = x.to_int() let yi = y.to_int() - if self.osk_visible { - if self.osk_pointer_grab || self.osk_rect().contains(xi, yi) { - let h = self.osk_key_at(xi, yi) - if h != self.osk_hover { - self.osk_hover = h - self.damage.mark_full() - } - return true - } - if self.osk_hover is Some(_) { - self.osk_hover = None + if self.osk_pointer_grab || self.osk_rect().contains(xi, yi) { + let h = self.osk_key_at(xi, yi) + if h != self.osk_hover { + self.osk_hover = h self.damage.mark_full() } - return false + return true } - if !self.kiosk_strict() { - let hover = if self.osk_toggle_rect().contains(xi, yi) { - Some(-1) - } else if self.osk_rotate_rect().contains(xi, yi) { - Some(-2) - } else { - None - } - match hover { - Some(id) => { - if self.osk_hover != Some(id) { - self.osk_hover = Some(id) - self.damage.mark_full() - } - return true - } - None => - if self.osk_hover == Some(-1) || self.osk_hover == Some(-2) { - self.osk_hover = None - self.damage.mark_full() - } - } - if self.osk_pointer_grab { - return true - } + if self.osk_hover is Some(_) { + self.osk_hover = None + self.damage.mark_full() } false } @@ -636,18 +601,8 @@ fn ChandraCompositor::osk_input( self.osk_pressed = None self.damage.mark_full() match idx_opt { - Some(-1) => - if !self.osk_visible && !self.kiosk_strict() && self.osk_toggle_rect().contains(xi, yi) { - self.osk_manual_hide = false - self.osk_manual_show = true - self.osk_sync() - } - Some(-2) => - if !self.osk_visible && !self.kiosk_strict() && self.osk_rotate_rect().contains(xi, yi) { - self.rotate_cw() - } Some(idx) => - if self.osk_visible && self.osk_key_at(xi, yi) == Some(idx) { + if self.osk_key_at(xi, yi) == Some(idx) { self.osk_activate_key(idx, time_ms) self.osk_sync() } @@ -655,7 +610,7 @@ fn ChandraCompositor::osk_input( } return true } - if self.osk_visible && self.osk_rect().contains(xi, yi) { + if self.osk_rect().contains(xi, yi) { if button == 272U && pressed { self.osk_pointer_grab = true self.osk_pressed = self.osk_key_at(xi, yi) @@ -663,75 +618,26 @@ fn ChandraCompositor::osk_input( } return true } - if !self.osk_visible && !self.kiosk_strict() { - let pill = if self.osk_toggle_rect().contains(xi, yi) { - Some(-1) - } else if self.osk_rotate_rect().contains(xi, yi) { - Some(-2) - } else { - None - } - match pill { - Some(id) => { - if pressed { - if button == 272U { - self.osk_pointer_grab = true - self.osk_pressed = Some(id) - self.damage.mark_full() - } else if button == 273U && id == -2 { - // Long-press / right-click on Rot flips 180 degrees. - self.rotate_flip() - } - } - return true - } - None => () - } - } false } Scroll(_, _, _) => { let xi = self.ptr_x.to_int() let yi = self.ptr_y.to_int() - if (self.osk_visible && self.osk_rect().contains(xi, yi)) || self.osk_pointer_grab { - return true - } - false + self.osk_rect().contains(xi, yi) || self.osk_pointer_grab } _ => false } } -///| Draw the OSK or its compact summon pill when enabled. +///| Draw the OSK when visible. fn ChandraCompositor::osk_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] { let ops : Array[@scene.DrawOp] = [] - if !self.osk_enabled { + if !self.osk_visible { return ops } let pal = self.theme.palette let fs = self.theme.font_size let rad = self.theme.radius - if !self.osk_visible { - if self.kiosk_strict() { - return ops - } - let pills = [(self.osk_rotate_rect(), -2, "Rot"), (self.osk_toggle_rect(), -1, "KB")] - for pill in pills { - let (tr, id, label) = pill - let bg = if self.osk_pressed == Some(id) { - pal.accent - } else if self.osk_hover == Some(id) { - pal.surface_hover - } else { - @scene.Rgba::new(pal.surface_popup.r.to_int(), pal.surface_popup.g.to_int(), pal.surface_popup.b.to_int(), 230) - } - let fg = if self.osk_pressed == Some(id) { pal.accent_foreground } else { pal.foreground } - ops.push(@scene.DrawOp::FillRect(tr, bg, rad + 4)) - ops.push(@scene.DrawOp::StrokeRect(tr, pal.border, 1, rad + 4)) - ops.push(@scene.DrawOp::Text(tr.x + tr.w / 2, tr.y + tr.h / 2, label, (fs - 2).max(10), fg, @scene.TextAlign::Center, true)) - } - return ops - } let r = self.osk_rect() let panel_bg = @scene.Rgba::new(pal.surface_popup.r.to_int(), pal.surface_popup.g.to_int(), pal.surface_popup.b.to_int(), 248) ops.push(@scene.DrawOp::FillRect(r, panel_bg, 0)) diff --git a/compositor/host/osk_test.mbt b/compositor/host/osk_test.mbt index 1b6cfae..bde6827 100644 --- a/compositor/host/osk_test.mbt +++ b/compositor/host/osk_test.mbt @@ -12,6 +12,20 @@ fn osk_comp(tag : String, enable_osk? : Bool = true) -> @host.ChandraCompositor comp } +///| Replace the panel with the compact 9-module handset set (`rotate` and `osk` included). +fn load_handset_modules(comp : @host.ChandraCompositor) -> Unit raise { + for slot in comp.shell.slots() { + ignore(comp.shell.unload_slot(slot)) + } + for id in [ + "launcher", "dock", "session-settings", "network", "battery", "clock-digital", "screenshot", + "rotate", "osk", + ] { + assert_true(comp.shell.load_module(id)) + } + ignore(comp.compose_frame()) +} + ///| test "OSK stays disabled under CHANDRA_TEST_CONFIG=1 unless explicitly enabled" { let socket_path = "/tmp/wayland-moon-osk-disabled-" + @sys.getpid().to_string() + ".sock" @@ -89,10 +103,15 @@ test "OSK delivers evdev keys and one-shot Shift modifier to focused Wayland cli } ///| -test "OSK Hide button dismisses keyboard and KB pill or client tap reopens it" { +test "OSK Hide button dismisses keyboard and KB panel module or client tap reopens it" { let socket_path = "/tmp/wayland-moon-osk-hide-" + @sys.getpid().to_string() + ".sock" let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap() comp.set_osk_enabled(true) + ignore(comp.compose_frame()) + load_handset_modules(comp) + let kr = rect_of(comp, "osk") + assert_true(kr.w > 0 && kr.y >= comp.output_h - comp.theme.panel_height) + let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Notes", "notes") commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL) let (ti, _) = text_input_for(comp, a) @@ -104,15 +123,24 @@ test "OSK Hide button dismisses keyboard and KB pill or client tap reopens it" { click_at(comp, hx, hy, 20U) assert_false(comp.osk_is_visible()) - // Tapping the compact "KB" toggle pill reopens it. - let tr = comp.osk_toggle_rect() - click_at(comp, tr.x + tr.w / 2, tr.y + tr.h / 2, 30U) - assert_true(comp.osk_is_visible()) + // No floating "KB" or "Rot" pills are drawn above the panel when hidden. + comp.damage.mark_full() + let scene = comp.compose_scene().unwrap() + for op in scene.panel_ops { + match op { + @scene.DrawOp::Text(_, y, text, _, _, _, _) if text == "KB" || text == "Rot" => + assert_true(y >= comp.output_h - comp.theme.panel_height) + _ => () + } + } - // Hide again, then tap inside the client window with active text input -> reopens. - let (hx2, hy2) = comp.osk_key_center("Hide").unwrap() - click_at(comp, hx2, hy2, 40U) + // Tapping the "KB" panel module reopens the keyboard, and tapping it again hides it. + click_module(comp, "osk", 30U) + assert_true(comp.osk_is_visible()) + click_module(comp, "osk", 35U) assert_false(comp.osk_is_visible()) + + // Tap inside the client window with active text input -> reopens. let g = comp.windows.get(1UL).unwrap().geometry click_at(comp, g.x + g.w / 2, g.y + g.h / 2, 50U) assert_true(comp.osk_is_visible()) @@ -160,24 +188,24 @@ test "OSK reaches the bottom edge in a strict kiosk, which has no panel" { } ///| -test "Rot pill tap rotates CW, right-click flips 180 deg, and rotate control commands update size" { +test "Rotate panel module rotates CW and rotate control commands update size" { let comp = osk_comp("rotate") - let rr = comp.osk_rotate_rect() - let rx = rr.x + rr.w / 2 - let ry = rr.y + rr.h / 2 + load_handset_modules(comp) + let rr = rect_of(comp, "rotate") + assert_true(rr.w > 0 && rr.y >= comp.output_h - comp.theme.panel_height) - // Tap Rot pill -> queues 90 deg CW rotation. - click_at(comp, rx, ry, 10U) + // Tap Rotate panel module -> queues 90 deg CW rotation. + click_module(comp, "rotate", 10U) assert_eq(comp.take_pending_rotation(), Some(1)) assert_eq(comp.current_rotation(), 1) comp.apply_rotated_size(1170, 540) assert_eq((comp.output_w, comp.output_h), (1170, 540)) - // Right-click / long-press Rot pill -> queues 180 deg flip (1 -> 3 = 270 deg). - let rr2 = comp.osk_rotate_rect() - click_at(comp, rr2.x + rr2.w / 2, rr2.y + rr2.h / 2, 20U, btn=273U) - assert_eq(comp.take_pending_rotation(), Some(3)) - assert_eq(comp.current_rotation(), 3) + // Tap Rotate panel module again -> queues 180 deg rotation. + click_module(comp, "rotate", 20U) + assert_eq(comp.take_pending_rotation(), Some(2)) + assert_eq(comp.current_rotation(), 2) + comp.apply_rotated_size(540, 1170) // chandra-ctl rotate 0 / flip / status. let (out0, ok0) = comp.control_command("rotate 0") @@ -198,3 +226,86 @@ test "Rot pill tap rotates CW, right-click flips 180 deg, and rotate control com assert_eq(out_st, ["ok 180 540x1170"]) comp.close() } + +///| +test "handset panel loads all 9 modules including rotate and osk inside 540px width" { + let comp = osk_comp("handset-fit") + load_handset_modules(comp) + let ids = comp.shell.loaded_modules().filter(m => m.0 != "desktop").map(m => m.1) + assert_eq(ids, [ + "launcher", "dock", "session-settings", "network", "battery", "clock-digital", "screenshot", + "rotate", "osk", + ]) + for id in ids { + let r = rect_of(comp, id) + assert_true(r.w > 0 && r.x >= 0 && r.x + r.w <= comp.output_w) + assert_true(r.y >= comp.output_h - comp.theme.panel_height) + } + comp.damage.mark_full() + let scene = comp.compose_scene().unwrap() + for op in scene.panel_ops { + match op { + @scene.DrawOp::Text(_, y, text, _, _, _, _) if text == "KB" || text == "Rot" => + assert_true(y >= comp.output_h - comp.theme.panel_height) + _ => () + } + } + comp.close() +} + +///| +test "KB panel module toggles OSK manually even when auto-OSK is disabled" { + let socket_path = "/tmp/wayland-moon-osk-manual-" + @sys.getpid().to_string() + ".sock" + let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap() + ignore(comp.compose_frame()) + load_handset_modules(comp) + let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Notes", "notes") + commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL) + let (ti, kbd) = text_input_for(comp, a) + text_input_state(comp, a, ti, true, 50, 50, 16) + // Auto-OSK is off, so text-input-v3 does not pop it open on its own. + assert_false(comp.osk_is_visible()) + ignore(drain_args(a)) + + // Clicking the KB panel module opens the OSK manually and typing reaches the client. + click_module(comp, "osk", 20U) + assert_true(comp.osk_is_visible()) + let (ax, ay) = comp.osk_key_center("a").unwrap() + click_at(comp, ax, ay, 30U) + let keys = drain_args(a).filter(m => m.0 == kbd && m.1 == 3U) + assert_eq(keys.length(), 2) + assert_eq((keys[0].2[2], keys[0].2[3]), (30U, 1U)) + + // Clicking KB again closes the manually opened OSK. + click_module(comp, "osk", 40U) + assert_false(comp.osk_is_visible()) + comp.close() +} + +///| +test "clicking KB or Rotate panel modules keeps the launcher popup open" { + let comp = osk_comp("launcher-keep") + load_handset_modules(comp) + click_module(comp, "launcher", 10U) + assert_true(comp.shell.popup_open()) + assert_true(comp.osk_is_visible()) + + let (hx, hy) = comp.osk_key_center("Hide").unwrap() + click_at(comp, hx, hy, 20U) + assert_false(comp.osk_is_visible()) + assert_true(comp.shell.popup_open()) + + // Tapping Rotate leaves the Launcher popup open and does not accidentally reopen the OSK. + click_module(comp, "rotate", 30U) + assert_true(comp.shell.popup_open()) + assert_false(comp.osk_is_visible()) + assert_eq(comp.take_pending_rotation(), Some(1)) + + // Tapping KB opens the OSK while keeping the Launcher popup open above it. + click_module(comp, "osk", 40U) + assert_true(comp.shell.popup_open()) + assert_true(comp.osk_is_visible()) + let pr = comp.shell.open_popup_rect().unwrap() + assert_true(pr.y + pr.h <= comp.osk_rect().y) + comp.close() +} diff --git a/compositor/host/power.mbt b/compositor/host/power.mbt index 18204da..170faa9 100644 --- a/compositor/host/power.mbt +++ b/compositor/host/power.mbt @@ -27,8 +27,17 @@ pub fn ChandraCompositor::set_manual_screen_off( off : Bool, ) -> Unit { self.manual_screen_off = off - if !off { + if off { + if self.locked { + self.cancel_unlock() + } else if self.lock_on_blank { + self.lock_now() + } + } else { self.note_activity(@sys.monotonic_ms()) + if self.locked { + self.request_unlock() + } } } diff --git a/compositor/polkit/agent.mbt b/compositor/polkit/agent.mbt index e5950b0..18bec54 100644 --- a/compositor/polkit/agent.mbt +++ b/compositor/polkit/agent.mbt @@ -277,6 +277,115 @@ pub fn PolkitAgent::registered(self : PolkitAgent) -> Bool { self.registered } +///| Parse an unsigned 64-bit decimal integer (returns None if empty, >20 chars, or non-digit). +fn parse_u64(s : String) -> UInt64? { + if s.length() == 0 || s.length() > 20 { + return None + } + let mut v = 0UL + for c in s { + if c < '0' || c > '9' { + return None + } + v = v * 10UL + (c.to_int() - '0'.to_int()).to_uint64() + } + Some(v) +} + +///| Build a polkit `unix-process` subject from `/proc//stat` and `/proc//status` text. +pub fn process_subject_for(pid : Int, stat : String, status : String) -> @network.DValue { + let start_time = match stat.rev_find(")") { + Some(i) => { + let parts = stat[i + 1:].to_string().trim(chars=" \t\n").to_string().split(" ").map(v => v.to_string()).filter(v => v != "").to_array() + if parts.length() > 19 { + parse_u64(parts[19]).unwrap_or(0UL) + } else { + 0UL + } + } + None => 0UL + } + let uid = uid_from_status(status) + Struct([ + Str("unix-process"), + @network.dict("v", [ + ("pid", Variant(U32(pid.reinterpret_as_uint()))), + ("start-time", Variant(U64(start_time))), + ("uid", Variant(I32(uid))), + ]), + ]) +} + +///| The polkit subject representing the current agent process (`unix-process`). +fn process_subject() -> @network.DValue { + let pid = @sys.getpid() + let stat = @utf8.decode_lossy(@sys.read_proc_bytes("/proc/" + pid.to_string() + "/stat")) + let status = @utf8.decode_lossy(@sys.read_proc_bytes("/proc/" + pid.to_string() + "/status")) + process_subject_for(pid, stat, status) +} + +///| Ask polkit to authorize `action_id` for the agent process, allowing user interaction: polkit +/// then drives this same agent's dialog (face via PAM, then password), and the reply says whether +/// it succeeded. Used for session unlock (org.chandra.unlock). False before registration or without a bus. +pub fn PolkitAgent::check_unlock( + self : PolkitAgent, + action_id : String, + cancel_id : String, + on_result : (Bool) -> Unit, +) -> Bool { + if !self.registered { + return false + } + match self.bus { + Some(bus) => { + let serial = bus.call( + @network.DMessage::call(authority_name, authority_path, authority_iface, "CheckAuthorization", [ + process_subject(), + Str(action_id), + @network.dict("s", []), + U32(1U), // AllowUserInteraction + Str(cancel_id), + ]), + on_reply=fn(m) { + let ok = match m { + { mtype: 2, body: [Struct([Bool(a), ..]), ..], .. } => a + { mtype: 2, .. } => { + alog("unlock: unexpected CheckAuthorization reply") + false + } + _ => { + alog("unlock: CheckAuthorization error: " + m.error_text()) + false + } + } + on_result(ok) + }, + ) + serial != 0 + } + None => false + } +} + +///| Cancel an in-flight CheckAuthorization call identified by `cancel_id`. +pub fn PolkitAgent::cancel_unlock(self : PolkitAgent, cancel_id : String) -> Unit { + if cancel_id == "" { + return + } + match self.bus { + Some(bus) => + ignore( + bus.call( + @network.DMessage::call(authority_name, authority_path, authority_iface, "CancelCheckAuthorization", [ + Str(cancel_id), + ]), + on_reply=fn(_) { () }, + ), + ) + None => () + } +} + ///| Why the last start failed ("" when it didn't). pub fn PolkitAgent::error(self : PolkitAgent) -> String { self.error diff --git a/compositor/polkit/agent_loop.mbt b/compositor/polkit/agent_loop.mbt index 0d920c1..4600b4b 100644 --- a/compositor/polkit/agent_loop.mbt +++ b/compositor/polkit/agent_loop.mbt @@ -28,6 +28,12 @@ pub struct AgentLoop { mut id : String mut next_id : Int mut was_registered : Bool + /// An unlock authorization (org.chandra.unlock) is out to polkit; ignore further `unlock`s. + mut unlocking : Bool + /// Cancellation id passed to polkit's CheckAuthorization / CancelCheckAuthorization. + mut unlock_cancel_id : String + /// Monotonic counter so stale CheckAuthorization replies after cancel are ignored. + mut unlock_seq : Int /// Done: the main loop exits. mut finished : Bool } @@ -56,6 +62,9 @@ pub fn AgentLoop::new( id: "", next_id: 1, was_registered: false, + unlocking: false, + unlock_cancel_id: "", + unlock_seq: 0, finished: false, } } @@ -73,6 +82,9 @@ pub fn AgentLoop::new_demo(link_fd : Int, mode : String) -> AgentLoop { id: "", next_id: 1, was_registered: false, + unlocking: false, + unlock_cancel_id: "", + unlock_seq: 0, finished: false, } } @@ -160,10 +172,78 @@ fn AgentLoop::close_request(self : AgentLoop, result : Result[Unit, String]?) -> } } +///| Unlock the session: ask polkit to authorize org.chandra.unlock. polkit drives this agent's +/// dialog (face via the polkit-1 PAM stack, then password); the reply tells the compositor +/// `unlocked` or `unlock-failed`. Without polkit (demo) there is nothing to check. +fn AgentLoop::begin_unlock(self : AgentLoop) -> Unit { + match self.polkit { + Some(p) => { + if self.unlocking { + return + } + self.unlock_seq = self.unlock_seq + 1 + let seq = self.unlock_seq + let cid = "chandra-unlock-" + seq.to_string() + self.unlocking = true + self.unlock_cancel_id = cid + let started = p.check_unlock("org.chandra.unlock", cid, fn(ok) { + if self.unlock_seq != seq { + return + } + self.unlocking = false + self.unlock_cancel_id = "" + ignore(self.link.send([if ok { "unlocked" } else { "unlock-failed" }])) + }) + if !started { + self.unlocking = false + self.unlock_cancel_id = "" + alog("unlock: polkit is not ready") + ignore(self.link.send(["unlock-failed"])) + } + } + None => ignore(self.link.send(["unlock-failed"])) + } +} + +///| Cancel an in-flight unlock authorization (e.g., screen blanked again before completion). +fn AgentLoop::cancel_unlock(self : AgentLoop) -> Unit { + if !self.unlocking { + return + } + let cid = self.unlock_cancel_id + self.unlock_seq = self.unlock_seq + 1 + self.unlocking = false + self.unlock_cancel_id = "" + match self.machine { + Some(m) if m.req.action_id == "org.chandra.unlock" => + self.close_request(Some(Err("The unlock request was cancelled"))) + _ => () + } + match self.polkit { + Some(p) => p.cancel_unlock(cid) + None => () + } +} + ///| A message from the compositor. fn AgentLoop::on_link(self : AgentLoop, line : FixedArray[Byte]) -> Unit { let f = split_fields(line) zero(line) + // Session unlock (lock.mbt) is a one-field message, independent of any request/dialog id. + if f.length() >= 1 && field_text(f[0]) == "unlock" { + for b in f { + zero(b) + } + self.begin_unlock() + return + } + if f.length() >= 1 && field_text(f[0]) == "cancel-unlock" { + for b in f { + zero(b) + } + self.cancel_unlock() + return + } if f.length() < 2 { return } diff --git a/compositor/polkit/describe.mbt b/compositor/polkit/describe.mbt index cd696ae..312e682 100644 --- a/compositor/polkit/describe.mbt +++ b/compositor/polkit/describe.mbt @@ -234,6 +234,17 @@ pub fn describe(req : AuthRequest, cmdline? : (Int) -> Array[String] = proc_cmdl details, } } + // Session unlock: clear lock-screen wording instead of the generic system-action fallback. + if req.action_id == "org.chandra.unlock" { + add("Action", req.action_id) + return { + title: "Screen locked", + subtitle: "Look at the camera or enter your password to unlock.", + command: "", + program: "", + details, + } + } // Anything else: polkit's message is the best we have. add("Requested by", who(if subject > 0 { subject } else { caller })) add("Unit", req.detail("unit")) diff --git a/compositor/polkit/org.chandra.unlock.policy b/compositor/polkit/org.chandra.unlock.policy new file mode 100644 index 0000000..0e4a7bd --- /dev/null +++ b/compositor/polkit/org.chandra.unlock.policy @@ -0,0 +1,22 @@ + + + + + Chandra + + Unlock the session + Authenticate to unlock the screen + + auth_self + auth_self + auth_self + + + diff --git a/compositor/polkit/polkit_test.mbt b/compositor/polkit/polkit_test.mbt index 6ea0301..c480eca 100644 --- a/compositor/polkit/polkit_test.mbt +++ b/compositor/polkit/polkit_test.mbt @@ -594,3 +594,38 @@ test "face unlock: Chandra's and Howdy's PAM messages" { assert_eq(@polkit.face_message("Place your finger on the fingerprint reader", false), None) assert_eq(@polkit.face_message("The account is locked due to 3 failed logins.", true), None) } + +///| +test "process_subject_for parses /proc//stat with spaces/parens and /proc//status Uid" { + let stat = "4210 (chandra (polkit) agent) S 1 4210 4210 0 -1 4194304 100 0 0 0 1 0 0 0 20 0 1 0 987654321 12345 100" + let status = "Name:\tchandra-polkit\nState:\tS (sleeping)\nUid:\t1000\t1000\t1000\t1000\nGid:\t1000\t1000\t1000\t1000\n" + let subj = @polkit.process_subject_for(4210, stat, status) + assert_eq( + subj, + @network.DValue::Struct([ + Str("unix-process"), + @network.dict("v", [ + ("pid", Variant(U32(4210U))), + ("start-time", Variant(U64(987654321UL))), + ("uid", Variant(I32(1000))), + ]), + ]), + ) +} + +///| +test "describe: org.chandra.unlock uses clear lock-screen wording" { + let req : @polkit.AuthRequest = { + action_id: "org.chandra.unlock", + message: "Authenticate to unlock the screen", + icon_name: "", + details: {}, + cookie: "c-unlock", + users: [{ uid: 1000, name: "nandi", real_name: "Nandi" }], + } + let desc = @polkit.describe(req, cmdline=_ => [], who=_ => "") + assert_eq(desc.title, "Screen locked") + assert_eq(desc.subtitle, "Look at the camera or enter your password to unlock.") + assert_eq(desc.command, "") + assert_eq(desc.details, [("Action", "org.chandra.unlock")]) +} diff --git a/compositor/polkit/request.mbt b/compositor/polkit/request.mbt index 98f22bf..3b3fd95 100644 --- a/compositor/polkit/request.mbt +++ b/compositor/polkit/request.mbt @@ -172,21 +172,26 @@ pub fn string_dict(v : @network.DValue) -> Map[String, String] { out } -///| Our uid, from /proc/self/status ("Uid:\treal\teffective..."); -1 when unknown. -pub fn own_uid() -> Int { - let text = @utf8.decode_lossy(@sys.read_proc_bytes("/proc/self/status")) +///| Parse real UID from `/proc//status` ("Uid:\treal\teffective..."); -1 when unknown. +pub fn uid_from_status(text : String) -> Int { for line in text.split("\n") { let l = line.to_string() if l.has_prefix("Uid:") { - let parts = l[4:].to_string().trim(chars=" \t").to_string().split("\t").to_array() + let rest = l[4:].to_string().replace_all(old="\t", new=" ") + let parts = rest.split(" ").map(v => v.to_string()).filter(v => v != "").to_array() if parts.length() > 0 { - return parse_uint(parts[0].to_string().trim(chars=" ").to_string()).unwrap_or(-1) + return parse_uint(parts[0]).unwrap_or(-1) } } } -1 } +///| Our uid, from /proc/self/status ("Uid:\treal\teffective..."); -1 when unknown. +pub fn own_uid() -> Int { + uid_from_status(@utf8.decode_lossy(@sys.read_proc_bytes("/proc/self/status"))) +} + ///| The request BeginAuthentication's arguments describe (s s s a{ss} s a(sa{sv})); None when /// they don't match. Users come from /etc/passwd and /etc/group. pub fn AuthRequest::from_args(args : Array[@network.DValue]) -> AuthRequest? { diff --git a/compositor/shell/shell.mbt b/compositor/shell/shell.mbt index e40bf1a..896c713 100644 --- a/compositor/shell/shell.mbt +++ b/compositor/shell/shell.mbt @@ -168,6 +168,10 @@ pub(all) enum ShellAction { Window(UInt64, WindowCommand) /// The launcher's Reload reloaded the panel modules: the whole frame needs drawing again. ModulesReloaded + /// The Keyboard panel module asked to show (true) or hide (false) the built-in OSK. + SetOskVisible(Bool) + /// The Rotate panel module asked to set display rotation (0..3). + SetRotation(Int) } derive(Eq, Debug) ///| One wasm module loaded into the panel. @@ -281,6 +285,10 @@ pub(all) struct DesktopShell { /// What the screenshot module is told (the compositor sets it every frame): bit 0 a /// recording is running, bit 1 recordings show the pointer. mut screenshot_state : Int + /// Whether the built-in on-screen keyboard is currently visible (published to `osk`). + mut osk_visible : Bool + /// Current display rotation 0..3 (published to `rotation`). + mut rotation : Int /// The network service (network.mbt), while a module imports `network`. mut net : @network.NetService? mut remember_windows : Bool @@ -458,6 +466,8 @@ pub fn DesktopShell::new(display : String) -> DesktopShell { bg_key: None, restore_session: true, screenshot_state: 2, + osk_visible: false, + rotation: 0, net: None, remember_windows: true, native_auth_agent: true, @@ -906,8 +916,8 @@ pub fn DesktopShell::pointer_down(self : DesktopShell, x : Int, y : Int) -> Bool match self.widget_at(x, y) { Some(w) => { // A click (delivered on release) or the start of a drag that reorders the panel. - // The Interface Explorer toggle leaves open popups alone. - if !w.has_cap("inspector") { + // The Interface Explorer, Keyboard, and Rotate buttons leave open popups alone. + if !w.has_cap("inspector") && !w.has_cap("osk") && !w.has_cap("rotation") { self.dismiss_popups(w.slot) } self.drag_slot = w.slot diff --git a/compositor/shell/widgets.mbt b/compositor/shell/widgets.mbt index 022c3d1..e568669 100644 --- a/compositor/shell/widgets.mbt +++ b/compositor/shell/widgets.mbt @@ -35,9 +35,10 @@ fn fresh_panel(has_battery : Bool) -> Array[String] { } ///| Compact default panel for handsets (omits desktop-only inspector, tiling toggle, and moon -/// disc so the dock, launcher, settings, Wi-Fi, battery, clock, and screenshot have room). +/// disc so the dock, launcher, settings, Wi-Fi, battery, clock, screenshot, rotate, and osk have room). let handset_panel : Array[String] = [ "launcher", "dock", "session-settings", "network", "battery", "clock-digital", "screenshot", + "rotate", "osk", ] ///| Whether a fresh session runs on a handset chassis (tests keep the desktop layout). @@ -55,6 +56,24 @@ test "a fresh panel gets the battery module only on a machine with a battery" { assert_eq(p.search("battery").unwrap() + 1, p.search("clock-digital").unwrap()) } +///| +test "handset panel includes rotate and osk and v2 handset migration appends them once" { + assert_eq(handset_panel[handset_panel.length() - 2], "rotate") + assert_eq(handset_panel[handset_panel.length() - 1], "osk") + assert_eq( + migrate_handset_panel(["launcher", "dock", "clock-digital"]), + ["launcher", "dock", "clock-digital", "rotate", "osk"], + ) + assert_eq( + migrate_handset_panel(["launcher", "osk", "dock"]), + ["launcher", "osk", "dock", "rotate"], + ) + assert_eq( + migrate_handset_panel(["launcher", "rotate", "osk"]), + ["launcher", "rotate", "osk"], + ) +} + ///| Modules folded into another one: old id -> the module that took over. The old id still /// works everywhere a module is named (saved panels, load_module), it is just never listed: /// a stale build/components/clock-digital12.wasm or an old installed copy stays out of the picker. @@ -217,7 +236,9 @@ fn DesktopShell::panel_slots(self : DesktopShell) -> Array[@panel.SlotIn] { (w.module_id == "launcher" || w.module_id == "session-settings" || w.module_id == "network" || - w.module_id == "screenshot") { + w.module_id == "screenshot" || + w.module_id == "rotate" || + w.module_id == "osk") { 36 } else { base_w @@ -357,6 +378,19 @@ test "a saved panel's Log out button folds into the launcher" { assert_false(default_panel.contains("logout")) } +///| Append the Rotate and Keyboard panel modules when migrating a handset panel saved before +/// panel.edn version 3 (when those controls moved from floating pills into the panel). +fn migrate_handset_panel(entries : Array[String]) -> Array[String] { + let out = entries.copy() + if !out.contains("rotate") { + out.push("rotate") + } + if !out.contains("osk") { + out.push("osk") + } + out +} + ///| Load the panel on first use: the saved layout if there is one, else the default modules. fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit { if self.booted { @@ -365,8 +399,16 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit { self.booted = true self.scan_catalog() let saved = self.load_panel_config() + let saved_ver = if saved is Some(_) { saved_panel_version() } else { panel_version } let entries = match saved { - Some(e) => migrate_panel(e) + Some(e) => { + let migrated = migrate_panel(e) + if saved_ver < 3 && is_handset_panel() { + migrate_handset_panel(migrated) + } else { + migrated + } + } None => if is_handset_panel() { handset_panel @@ -375,10 +417,12 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit { } } match saved { - Some(old) if saved_panel_version() < panel_version => { + Some(old) if saved_ver < panel_version => { // Once, before the modules load so they pick up the moved settings; then the file is // rewritten with the new names and version (also keeping modules that fail to load). - self.migrate_module_cfg(old) + if saved_ver < 2 { + self.migrate_module_cfg(old) + } write_panel_file(entries) } // A renamed or folded module (the Log out button, now in the launcher): rewrite the file so @@ -803,6 +847,12 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit { if self.any_cap("screenshot") { @wasm.publish_screenshot(self.screenshot_state) } + if self.any_cap("osk") { + @wasm.publish_osk(self.osk_visible) + } + if self.any_cap("rotation") { + @wasm.publish_rotation(self.rotation) + } if self.any_cap("battery") { let b = self.battery.refresh() @wasm.publish_battery(b.percent, b.state, b.secs_left) @@ -979,6 +1029,8 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit { Some(DefaultApp(code)) => self.default_app_request(code) Some(FaceUnlock(code)) => self.face.request(code) Some(GameLibrary(code, game, mode)) => self.gamelib.request(code, game, mode) + Some(SetOskVisible(v)) => self.actions.push(SetOskVisible(v)) + Some(SetRotation(r)) => self.actions.push(SetRotation(r)) Some(PowerAction(a)) => if a >= 0 && a <= 2 { self.actions.push(SystemPower(a)) } Some(Network(code, ssid, password)) => self.network_request(code, ssid, password) Some(SetInspector(on)) => self.set_inspecting(on) @@ -1447,7 +1499,8 @@ pub fn DesktopShell::save_panel_config(self : DesktopShell) -> Unit { ///| panel.edn's format version (`:version`; files without one are 1). 2: written after the /// 12-hour clock (clock-digital12) became part of the Digital Clock, whose default went from /// 24-hour to 12-hour; an older file gets its clock settings moved over once (migrate_module_cfg). -let panel_version : Int = 2 +/// 3: handset panels move Rotate (`rotate`) and Keyboard (`osk`) into the panel. +let panel_version : Int = 3 ///| fn write_panel_file(names : Array[String]) -> Unit { diff --git a/compositor/wasm/wasm_host.mbt b/compositor/wasm/wasm_host.mbt index f90db3b..9e2ce9c 100644 --- a/compositor/wasm/wasm_host.mbt +++ b/compositor/wasm/wasm_host.mbt @@ -417,6 +417,16 @@ pub fn publish_screenshot(state : Int) -> Unit { @hostpl.publish_screenshot(state.reinterpret_as_uint()) } +///| Publish whether the built-in on-screen keyboard is currently visible. +pub fn publish_osk(visible : Bool) -> Unit { + @hostpl.publish_osk(visible) +} + +///| Publish the current display rotation (0=0, 1=90 CW, 2=180, 3=270 CW). +pub fn publish_rotation(rot : Int) -> Unit { + @hostpl.publish_rotation(rot.reinterpret_as_uint()) +} + ///| The power timeouts, in minutes (0: never). pub fn publish_power(screen_off : Int, suspend : Int) -> Unit { @hostpl.publish_power(screen_off.reinterpret_as_uint(), suspend.reinterpret_as_uint()) @@ -473,6 +483,10 @@ pub(all) enum HostRequest { FaceUnlock(Int) /// The game-library capability: 0 launch (game, mode), 1 stop, 2 focus (game), 3 refresh. GameLibrary(Int, String, String) + /// The osk capability: show (true) or hide (false) the on-screen keyboard. + SetOskVisible(Bool) + /// The rotation capability: set display orientation (0..3). + SetRotation(Int) } derive(Eq, Debug) ///| @@ -502,6 +516,8 @@ pub fn next_request() -> HostRequest? { Some(SetDesktop(i)) => Some(SetDesktop(i)) Some(FaceUnlock(i)) => Some(FaceUnlock(i)) Some(GameLibrary(r)) => Some(GameLibrary(r.action, r.game, r.mode)) + Some(SetOskVisible(v)) => Some(SetOskVisible(v)) + Some(SetRotation(r)) => Some(SetRotation(r)) } } diff --git a/compositor/wasm/wasm_native.mbt b/compositor/wasm/wasm_native.mbt index cc57952..03a60d5 100644 --- a/compositor/wasm/wasm_native.mbt +++ b/compositor/wasm/wasm_native.mbt @@ -831,6 +831,16 @@ pub fn publish_screenshot(state : Int) -> Unit { c_host_set_int(4, state) } +///| Publish whether the built-in on-screen keyboard is currently visible. +pub fn publish_osk(visible : Bool) -> Unit { + c_host_set_int(11, if visible { 1 } else { 0 }) +} + +///| Publish the current display rotation (0=0, 1=90 CW, 2=180, 3=270 CW). +pub fn publish_rotation(rot : Int) -> Unit { + c_host_set_int(12, rot) +} + ///| Publish the power timeouts, in minutes (0: never). pub fn publish_power(screen_off : Int, suspend : Int) -> Unit { c_host_set_int(5, screen_off) @@ -891,6 +901,10 @@ pub(all) enum HostRequest { FaceUnlock(Int) /// The game-library capability: 0 launch (game, mode), 1 stop, 2 focus (game), 3 refresh. GameLibrary(Int, String, String) + /// The osk capability: show (true) or hide (false) the on-screen keyboard. + SetOskVisible(Bool) + /// The rotation capability: set display orientation (0..3). + SetRotation(Int) } derive(Eq, Debug) ///| @@ -933,6 +947,8 @@ pub fn next_request() -> HostRequest? { 18 => Some(Shortcut(c_host_req_int())) 19 => Some(DefaultApp(c_host_req_int())) 20 => Some(SetBrightness(c_host_req_int())) + 21 => Some(SetOskVisible(c_host_req_int() != 0)) + 22 => Some(SetRotation(c_host_req_int())) 40 => Some(SetDesktop(c_host_req_int())) 44 => Some(FaceUnlock(c_host_req_int())) 45 => { diff --git a/compositor/wasm/wasm_stub.c b/compositor/wasm/wasm_stub.c index 7b35031..5b9eb91 100644 --- a/compositor/wasm/wasm_stub.c +++ b/compositor/wasm/wasm_stub.c @@ -68,7 +68,8 @@ enum { K_DA_CATS, K_DA_APPS, K_DA_SET, K_DA_REFRESH, K_DESKTOPS, K_DESKTOP_CUR, K_SET_DESKTOP, K_FU_STATUS, K_FU_FACES, K_FU_ENROLL, K_FU_REMOVE, K_FU_SET_IN_USE, K_FU_REFRESH, - K_GL_STATUS, K_GL_GAMES, K_GL_MODES, K_GL_LAUNCH, K_GL_STOP, K_GL_FOCUS, K_GL_REFRESH + K_GL_STATUS, K_GL_GAMES, K_GL_MODES, K_GL_LAUNCH, K_GL_STOP, K_GL_FOCUS, K_GL_REFRESH, + K_OSK_IS_VISIBLE, K_OSK_SET_VISIBLE, K_ROT_CURRENT, K_ROT_SET }; typedef struct Env { Inst *inst; int kind; } Env; @@ -85,7 +86,8 @@ static int32_t host_ints[24] = {[7] = -1, [10] = -1}; /* 0 layout mode, 1 inspec 4 screenshot state (bit 0 recording, bit 1 pointer in recordings), 5 screen-off minutes, 6 suspend minutes (0: never), 7 battery percent (-1: none), 8 battery charge-state, 9 battery seconds left, - 10 backlight brightness percent (-1: none) */ + 10 backlight brightness percent (-1: none), 11 osk visible (0/1), + 12 display rotation (0..3) */ /* ---- requests a guest made of the host (launch, focus, ...) ; drained by the shell after each call ---- */ typedef struct { int kind; int32_t n; char *s; } Req; @@ -493,6 +495,14 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_ if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL((host_ints[4] >> 1) & 1); break; case K_INSPECT_SET: push_req(4, a0, NULL); break; + case K_OSK_IS_VISIBLE: + if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[11] != 0); + break; + case K_OSK_SET_VISIBLE: push_req(21, a0 != 0, NULL); break; + case K_ROT_CURRENT: + if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[12]); + break; + case K_ROT_SET: push_req(22, a0, NULL); break; case K_MOD_BROWSE: push_req(7, 0, NULL); break; case K_MOD_LOAD: { char *s = guest_str(in, a0, a1); push_req(5, 0, s); free(s); break; } case K_MOD_UNLOAD: { char *s = guest_str(in, a0, a1); push_req(6, 0, s); free(s); break; } @@ -702,6 +712,10 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) { if (!strcmp(iface, "layout-control") && !strcmp(fn, "set-layout")) return K_SET_LAYOUT; if (!strcmp(iface, "inspector") && !strcmp(fn, "is-on")) return K_INSPECT_IS_ON; if (!strcmp(iface, "inspector") && !strcmp(fn, "set-on")) return K_INSPECT_SET; + if (!strcmp(iface, "osk") && !strcmp(fn, "is-visible")) return K_OSK_IS_VISIBLE; + if (!strcmp(iface, "osk") && !strcmp(fn, "set-visible")) return K_OSK_SET_VISIBLE; + if (!strcmp(iface, "rotation") && !strcmp(fn, "current")) return K_ROT_CURRENT; + if (!strcmp(iface, "rotation") && !strcmp(fn, "set-rotation")) return K_ROT_SET; if (!strcmp(iface, "modules") && !strcmp(fn, "available")) return K_MOD_AVAILABLE; if (!strcmp(iface, "modules") && !strcmp(fn, "loaded")) return K_MOD_LOADED; if (!strcmp(iface, "modules") && !strcmp(fn, "load-module")) return K_MOD_LOAD; diff --git a/compositor/wasm/wasm_test.mbt b/compositor/wasm/wasm_test.mbt index cd64270..724f2d1 100644 --- a/compositor/wasm/wasm_test.mbt +++ b/compositor/wasm/wasm_test.mbt @@ -278,3 +278,33 @@ test "moon and digital clock modules render from the clock capability" { assert_true(ts[0].has_suffix("AM") || ts[0].has_suffix("PM")) // 12-hour by default c.unload() } + +///| +test "osk module toggles through the osk capability" { + let p = load_module("osk") + assert_true(p.imports().contains("osk")) + publish_osk(false) + assert_true(texts_of(p.render(44, 34, test_tokens())).contains("KB")) + assert_true(p.popup() is None) + assert_true(p.on_event(false, PointerDown(5, 5))) + assert_eq(drain(), [SetOskVisible(true)]) + publish_osk(true) + assert_true(p.on_event(false, PointerDown(5, 5))) + assert_eq(drain(), [SetOskVisible(false)]) + p.unload() +} + +///| +test "rotate module cycles orientation through the rotation capability" { + let p = load_module("rotate") + assert_true(p.imports().contains("rotation")) + publish_rotation(0) + assert_true(texts_of(p.render(44, 34, test_tokens())).contains("Rot")) + assert_true(p.popup() is None) + assert_true(p.on_event(false, PointerDown(5, 5))) + assert_eq(drain(), [SetRotation(1)]) + publish_rotation(3) + assert_true(p.on_event(false, PointerDown(5, 5))) + assert_eq(drain(), [SetRotation(0)]) + p.unload() +} diff --git a/docs/handset.md b/docs/handset.md index fd7547e..2e535fa 100644 --- a/docs/handset.md +++ b/docs/handset.md @@ -10,19 +10,17 @@ Chandra includes KMS/libinput/compositor adaptations tailored for mainline Linux ## Icon Desktop & Compact Panel - **Icon desktop default:** Portrait handset layouts prioritize the touch-friendly icon desktop launcher aesthetic. -- **Compact panel layout:** Panel items (`launcher`, `dock`, `session-settings`, `network`, `battery`, `clock-digital`, `screenshot`) size compactly so all controls fit cleanly within `540px` portrait width without clipping, with fuel-gauge support (e.g. `bq27411-0`). +- **Compact panel layout:** Panel items (`launcher`, `dock`, `session-settings`, `network`, `battery`, `clock-digital`, `screenshot`, `rotate`, `osk`) size compactly so all controls fit cleanly within `540px` portrait width without clipping, with fuel-gauge support (e.g. `bq27411-0`). ## Touch Input & On-Screen Keyboard - **Long-press right-click:** In [`compositor/kms/kms_stub.c`](../compositor/kms/kms_stub.c), a stationary touch held for `500 ms` converts to a synthetic right-click (`BTN_RIGHT`) via a `timerfd`, allowing context menus and secondary actions without a mouse. -- **Built-in OSK:** [`compositor/host/osk.mbt`](../compositor/host/osk.mbt) provides a 5-row virtual keyboard that opens automatically when Wayland text input (`zwp_text_input_v3`) gains focus and can also be toggled manually from the bottom-right **`KB`** pill. It sits directly above the panel, so the panel stays visible and usable while typing (a strict kiosk has no panel: there it reaches the bottom edge). +- **Built-in OSK:** [`compositor/host/osk.mbt`](../compositor/host/osk.mbt) provides a 5-row virtual keyboard that opens automatically when Wayland text input (`zwp_text_input_v3`) gains focus and can also be toggled manually from the **`KB`** (`osk`) panel module. It sits directly above the panel, so the panel stays visible and usable while typing (a strict kiosk has no panel: there it reaches the bottom edge). ## Display Rotation, Flip, and Auto-Rotate - **4-way transform (`0°`, `90° CW`, `180°`, `270° CW`):** Handled end-to-end across [`compositor/kms/kms_stub.c`](../compositor/kms/kms_stub.c), [`wit/host/display.wit`](../wit/host/display.wit), [`wasmhost/bin/display.mbt`](../wasmhost/bin/display.mbt), and the compositor event loop (`CHANDRA_ROTATE` sets the initial orientation). Both scanout rows and libinput touch/pointer coordinates transform to match the active orientation. -- **Touch `Rot` pill:** Sitting left of the `KB` pill in [`compositor/host/osk.mbt`](../compositor/host/osk.mbt): - - **Tap:** rotate `90°` clockwise (`0 -> 90 -> 180 -> 270 -> 0`). - - **Long-press / right-click:** flip `180°` (`0 <-> 180`, `90 <-> 270`). +- **Touch `Rot` (`rotate`) panel module:** Sits in the panel beside `KB` (`osk`) and rotates `90°` clockwise on tap (`0 -> 90 -> 180 -> 270 -> 0`). Both `rotate` and `osk` are ordinary panel modules that can be reordered, removed, or added on any desktop from **Settings > Panel**. - **CLI control:** `chandra-ctl rotate [cw|ccw|flip|0|90|180|270|status]` queries or changes rotation live (`0` portrait, `90` / `270` landscape, `180` inverted). - **Sensor auto-rotate:** When running on the DRM backend (`chandra-session`) with `monitor-sensor` (`iio-sensor-proxy`) installed, [`session/chandra-auto-rotate`](../session/chandra-auto-rotate) runs inside the active `seat0` session and applies orientation change events (`normal -> 0`, `right-up -> 90`, `bottom-up -> 180`, `left-up -> 270`) without fighting manual `Rot` taps while stationary. Set `CHANDRA_AUTO_ROTATE=0` in the session environment to disable auto-rotate. diff --git a/docs/lock.md b/docs/lock.md new file mode 100644 index 0000000..5b39eaa --- /dev/null +++ b/docs/lock.md @@ -0,0 +1,74 @@ +# Locking the screen + +Chandra can lock the session: the desktop is hidden and nothing but the unlock prompt gets +input until a **face** (or, as the fallback, your **password**) lets you back in. It reuses the +password dialog ([auth-dialog.md](auth-dialog.md)) and face unlock ([face-unlock.md](face-unlock.md)), +so there is no second lock UI to configure. + +## Turn it on + +Locking on screen-off is **off by default** so a half-set-up machine can't lock you out. Turn it +on by setting `CHANDRA_LOCK=1` in the session environment or toggling it at runtime via +`chandra-ctl lock on-blank on`; then pressing the **power button** (or `chandra-ctl screen off`) to +blank the screen also locks it, and waking the screen asks for your face or password. + +`chandra-ctl lock` locks immediately, regardless of the setting (handy to bind to a key or a +panel button). + +```sh +chandra-ctl lock # lock now +chandra-ctl lock status # locked | unlocked +chandra-ctl lock on-blank on # arm lock-on-blank at runtime (on | off | status) +``` + +**Before you enable it, make sure you can get back in:** enroll a face +(`chandra-face enroll`, or Settings > Session > Face unlock) and/or confirm your login password +works, and that face unlock is in the `polkit-1` PAM stack (`chandra-face pam enable polkit-1`, +which `just install --pam` does). If neither the camera nor the password can authenticate, the +session stays locked and only an SSH login can recover it. + +## How it works + +``` + power off / chandra-ctl lock + │ + ▼ + compositor: locked ──"unlock"──► chandra-polkit-agent + • hides windows/panel │ CheckAuthorization(unix-process, org.chandra.unlock) + • swallows input ▼ + • dark lock backdrop polkit ──► this agent's dialog: face (PAM), then password + • draws the unlock dialog │ + ▲ │ + └────────── "unlocked" ◄──────┘ (success) "unlock-failed" ◄── (cancel / fail) +``` + +- **Locking** is in [`compositor/host/lock.mbt`](../compositor/host/lock.mbt). The power button + ([`compositor/host/compositor.mbt`](../compositor/host/compositor.mbt), `handle_input_inner`, + key `116`) and `chandra-ctl screen` route through `set_manual_screen_off` in + [`compositor/host/power.mbt`](../compositor/host/power.mbt); `lock_on_blank` (from `CHANDRA_LOCK` + or `chandra-ctl lock on-blank`) decides whether blanking also locks. Blanked again while unlock + is in flight, the compositor sends `cancel-unlock` so polkit and the camera stop immediately. + While locked, `build_scene` hides windows, popups, desktop widgets, and the panel behind a dark + `"Screen locked"` backdrop, and `handle_input_inner` swallows input (re-raising unlock only on + a key or button press when no dialog is up). +- **Unlocking** runs in the polkit agent + ([`compositor/polkit/agent_loop.mbt`](../compositor/polkit/agent_loop.mbt), + [`agent.mbt`](../compositor/polkit/agent.mbt)): once registered with polkit, on an `unlock` + message it passes a `unix-process` subject (`pid`, `start-time`, `uid` from `/proc`) to + `CheckAuthorization` for **`org.chandra.unlock`** with `AllowUserInteraction` (and cancels via + `CancelCheckAuthorization` on `cancel-unlock`). polkit then drives the agent's own dialog, and + because the `polkit-1` PAM stack carries `pam_chandra_face.so` the camera is tried first, with + the password as the fallback. The action is `auth_self` (never `_keep`), so it prompts every + time and nothing is cached. +- The policy file is + [`compositor/polkit/org.chandra.unlock.policy`](../compositor/polkit/org.chandra.unlock.policy), + installed to `/usr/share/polkit-1/actions/` by `session/install.py`. + +## Limits (today) + +- Lock-on-idle isn't wired yet — only the power button, `chandra-ctl screen off`, and + `chandra-ctl lock` lock. (The idle timeout still blanks the screen without locking.) +- The idle lock backdrop is a minimal padlock card ("Screen locked") rather than a custom clock or + wallpaper clock widget. +- Cancelling the unlock prompt keeps you locked (the desktop stays hidden); the next key press or + screen tap raises the prompt again. diff --git a/interface/chandra/desktop/default-apps/pkg.generated.mbti b/interface/chandra/desktop/default-apps/pkg.generated.mbti new file mode 100644 index 0000000..38f8e6c --- /dev/null +++ b/interface/chandra/desktop/default-apps/pkg.generated.mbti @@ -0,0 +1,32 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/default-apps" + +// Values +pub fn apps() -> Array[AppChoice] + +pub fn categories() -> Array[AppCategory] + +pub fn refresh() -> Unit + +pub fn set_default(UInt32, UInt32) -> Unit + +// Errors + +// Types and methods +pub(all) struct AppCategory { + name : String + current : String + missing : String +} + +pub(all) struct AppChoice { + category : UInt32 + id : String + name : String + icon : UInt32 + current : Bool +} + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/game-library/pkg.generated.mbti b/interface/chandra/desktop/game-library/pkg.generated.mbti new file mode 100644 index 0000000..4c1dec2 --- /dev/null +++ b/interface/chandra/desktop/game-library/pkg.generated.mbti @@ -0,0 +1,53 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/game-library" + +// Values +pub fn focus(String) -> Unit + +pub fn games() -> Array[Game] + +pub fn launch(String, String) -> Unit + +pub fn launch_modes() -> Array[LaunchMode] + +pub fn refresh() -> Unit + +pub fn status() -> RigStatus + +pub fn stop(String) -> Unit + +// Errors + +// Types and methods +pub(all) struct Game { + id : String + name : String + category : String + description : String + icon : String + install_hint : String + featured : Bool + installed : Bool + running : Bool +} + +pub(all) struct LaunchMode { + game : String + id : String + label : String +} + +pub(all) struct RigStatus { + error : String + gpu : String + resolution : String + display : String + audio : String + hostname : String + connected : Bool + audio_ok : Bool +} + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/icons/pkg.generated.mbti b/interface/chandra/desktop/icons/pkg.generated.mbti new file mode 100644 index 0000000..ecb771d --- /dev/null +++ b/interface/chandra/desktop/icons/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/icons" + +// Values +pub fn app_icon(String) -> UInt32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/inspector/pkg.generated.mbti b/interface/chandra/desktop/inspector/pkg.generated.mbti new file mode 100644 index 0000000..7c6e747 --- /dev/null +++ b/interface/chandra/desktop/inspector/pkg.generated.mbti @@ -0,0 +1,15 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/inspector" + +// Values +pub fn is_on() -> Bool + +pub fn set_on(Bool) -> Unit + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/layout-control/pkg.generated.mbti b/interface/chandra/desktop/layout-control/pkg.generated.mbti new file mode 100644 index 0000000..701af1c --- /dev/null +++ b/interface/chandra/desktop/layout-control/pkg.generated.mbti @@ -0,0 +1,17 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/layout-control" + +// Values +pub fn current_layout() -> UInt32 + +pub fn layout_modes() -> Array[String] + +pub fn set_layout(UInt32) -> Unit + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/modules/pkg.generated.mbti b/interface/chandra/desktop/modules/pkg.generated.mbti new file mode 100644 index 0000000..fa448cd --- /dev/null +++ b/interface/chandra/desktop/modules/pkg.generated.mbti @@ -0,0 +1,35 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/modules" + +// Values +pub fn available() -> Array[ModuleInfo] + +pub fn browse() -> Unit + +pub fn load_module(String) -> Unit + +pub fn loaded() -> Array[InstanceInfo] + +pub fn move_instance(String, Int32) -> Unit + +pub fn unload_instance(String) -> Unit + +// Errors + +// Types and methods +pub(all) struct InstanceInfo { + slot : String + module_ : String + name : String +} + +pub(all) struct ModuleInfo { + id : String + name : String + path : String + loaded : UInt32 +} + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/network/pkg.generated.mbti b/interface/chandra/desktop/network/pkg.generated.mbti new file mode 100644 index 0000000..76df8fd --- /dev/null +++ b/interface/chandra/desktop/network/pkg.generated.mbti @@ -0,0 +1,45 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/network" + +// Values +pub fn connect(String, String) -> Unit + +pub fn disconnect() -> Unit + +pub fn forget(String) -> Unit + +pub fn scan() -> Unit + +pub fn set_airplane_mode(Bool) -> Unit + +pub fn set_wifi_enabled(Bool) -> Unit + +pub fn status() -> NetStatus + +pub fn wifi_networks() -> Array[WifiNetwork] + +// Errors + +// Types and methods +pub(all) struct NetStatus { + state : UInt32 + signal : UInt32 + name : String + message : String + wifi_enabled : Bool + airplane : Bool + can_manage : Bool + has_wifi : Bool +} + +pub(all) struct WifiNetwork { + ssid : String + signal : UInt32 + secured : Bool + active : Bool + saved : Bool +} + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/osk/README.md b/interface/chandra/desktop/osk/README.md new file mode 100644 index 0000000..a4baec2 --- /dev/null +++ b/interface/chandra/desktop/osk/README.md @@ -0,0 +1,3 @@ +Built-in on-screen keyboard (OSK). The compositor draws the keyboard above the panel and routes +keystrokes to focused Wayland clients, panel popups and dialogs; a module with this capability +reads whether the keyboard is showing and opens or hides it. \ No newline at end of file diff --git a/interface/chandra/desktop/osk/ffi.mbt b/interface/chandra/desktop/osk/ffi.mbt new file mode 100644 index 0000000..29565b9 --- /dev/null +++ b/interface/chandra/desktop/osk/ffi.mbt @@ -0,0 +1,8 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + +///| +fn wasmImportIsVisible() -> Int = "chandra:desktop/osk@0.1.0" "is-visible" + +///| +fn wasmImportSetVisible(p0 : Int) = "chandra:desktop/osk@0.1.0" "set-visible" + diff --git a/interface/chandra/desktop/osk/moon.pkg b/interface/chandra/desktop/osk/moon.pkg new file mode 100644 index 0000000..e2a6033 --- /dev/null +++ b/interface/chandra/desktop/osk/moon.pkg @@ -0,0 +1 @@ +warnings = "-44" diff --git a/interface/chandra/desktop/osk/pkg.generated.mbti b/interface/chandra/desktop/osk/pkg.generated.mbti new file mode 100644 index 0000000..ffa16d6 --- /dev/null +++ b/interface/chandra/desktop/osk/pkg.generated.mbti @@ -0,0 +1,15 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/osk" + +// Values +pub fn is_visible() -> Bool + +pub fn set_visible(Bool) -> Unit + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/osk/top.mbt b/interface/chandra/desktop/osk/top.mbt new file mode 100644 index 0000000..2dfa801 --- /dev/null +++ b/interface/chandra/desktop/osk/top.mbt @@ -0,0 +1,18 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! +///| +/// Whether the on-screen keyboard is currently visible. +pub fn is_visible() -> Bool { + + let result : Int = wasmImportIsVisible(); + let ret = (result != 0) + return ret + +} +///| +/// Show (true) or hide (false) the on-screen keyboard. +pub fn set_visible(visible : Bool) -> Unit { + + wasmImportSetVisible((if visible { 1 } else { 0 })); + +} + diff --git a/interface/chandra/desktop/power/pkg.generated.mbti b/interface/chandra/desktop/power/pkg.generated.mbti new file mode 100644 index 0000000..3542793 --- /dev/null +++ b/interface/chandra/desktop/power/pkg.generated.mbti @@ -0,0 +1,29 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/power" + +// Values +pub fn brightness() -> Int32 + +pub fn power_off() -> Unit + +pub fn reboot() -> Unit + +pub fn screen_off_minutes() -> UInt32 + +pub fn set_brightness(UInt32) -> Unit + +pub fn set_screen_off_minutes(UInt32) -> Unit + +pub fn set_suspend_minutes(UInt32) -> Unit + +pub fn suspend() -> Unit + +pub fn suspend_minutes() -> UInt32 + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/rotation/README.md b/interface/chandra/desktop/rotation/README.md new file mode 100644 index 0000000..b51a31a --- /dev/null +++ b/interface/chandra/desktop/rotation/README.md @@ -0,0 +1,2 @@ +Display orientation (0°, 90° CW, 180°, 270° CW). The host rotates scanout and input +coordinates; a module with this capability reads the current orientation and rotates it. \ No newline at end of file diff --git a/interface/chandra/desktop/rotation/ffi.mbt b/interface/chandra/desktop/rotation/ffi.mbt new file mode 100644 index 0000000..6dfe300 --- /dev/null +++ b/interface/chandra/desktop/rotation/ffi.mbt @@ -0,0 +1,8 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + +///| +fn wasmImportCurrent() -> Int = "chandra:desktop/rotation@0.1.0" "current" + +///| +fn wasmImportSetRotation(p0 : Int) = "chandra:desktop/rotation@0.1.0" "set-rotation" + diff --git a/interface/chandra/desktop/rotation/moon.pkg b/interface/chandra/desktop/rotation/moon.pkg new file mode 100644 index 0000000..e2a6033 --- /dev/null +++ b/interface/chandra/desktop/rotation/moon.pkg @@ -0,0 +1 @@ +warnings = "-44" diff --git a/interface/chandra/desktop/rotation/pkg.generated.mbti b/interface/chandra/desktop/rotation/pkg.generated.mbti new file mode 100644 index 0000000..cb96184 --- /dev/null +++ b/interface/chandra/desktop/rotation/pkg.generated.mbti @@ -0,0 +1,15 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/rotation" + +// Values +pub fn current() -> UInt32 + +pub fn set_rotation(UInt32) -> Unit + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/rotation/top.mbt b/interface/chandra/desktop/rotation/top.mbt new file mode 100644 index 0000000..54bf665 --- /dev/null +++ b/interface/chandra/desktop/rotation/top.mbt @@ -0,0 +1,18 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! +///| +/// Current orientation: 0 = 0°, 1 = 90° CW, 2 = 180°, 3 = 270° CW. +pub fn current() -> UInt { + + let result : Int = wasmImportCurrent(); + let ret = (result).reinterpret_as_uint() + return ret + +} +///| +/// Set the orientation (0..3, wrapped modulo 4). +pub fn set_rotation(rot : UInt) -> Unit { + + wasmImportSetRotation((rot).reinterpret_as_int()); + +} + diff --git a/interface/chandra/desktop/screenshot/pkg.generated.mbti b/interface/chandra/desktop/screenshot/pkg.generated.mbti new file mode 100644 index 0000000..7f671f5 --- /dev/null +++ b/interface/chandra/desktop/screenshot/pkg.generated.mbti @@ -0,0 +1,23 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/screenshot" + +// Values +pub fn is_recording() -> Bool + +pub fn records_pointer() -> Bool + +pub fn set_records_pointer(Bool) -> Unit + +pub fn start_recording(UInt32) -> Unit + +pub fn stop_recording() -> Unit + +pub fn take(UInt32) -> Unit + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/session-settings/pkg.generated.mbti b/interface/chandra/desktop/session-settings/pkg.generated.mbti new file mode 100644 index 0000000..40af3d0 --- /dev/null +++ b/interface/chandra/desktop/session-settings/pkg.generated.mbti @@ -0,0 +1,17 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/session-settings" + +// Values +pub fn is_on(UInt32) -> Bool + +pub fn set_setting(UInt32, Bool) -> Unit + +pub fn settings() -> Array[String] + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/session/pkg.generated.mbti b/interface/chandra/desktop/session/pkg.generated.mbti new file mode 100644 index 0000000..292dcaf --- /dev/null +++ b/interface/chandra/desktop/session/pkg.generated.mbti @@ -0,0 +1,15 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/session" + +// Values +pub fn logout() -> Unit + +pub fn reload() -> Unit + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/shortcuts/pkg.generated.mbti b/interface/chandra/desktop/shortcuts/pkg.generated.mbti new file mode 100644 index 0000000..6f38347 --- /dev/null +++ b/interface/chandra/desktop/shortcuts/pkg.generated.mbti @@ -0,0 +1,28 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/shortcuts" + +// Values +pub fn cancel_capture() -> Unit + +pub fn capture(UInt32) -> Unit + +pub fn reset(UInt32) -> Unit + +pub fn reset_all() -> Unit + +pub fn shortcuts() -> Array[Shortcut] + +// Errors + +// Types and methods +pub(all) struct Shortcut { + name : String + binding : String + default_binding : String + conflict : String + capturing : Bool +} + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/system/pkg.generated.mbti b/interface/chandra/desktop/system/pkg.generated.mbti new file mode 100644 index 0000000..ac45c72 --- /dev/null +++ b/interface/chandra/desktop/system/pkg.generated.mbti @@ -0,0 +1,24 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/system" + +// Values +pub fn read() -> Snapshot + +// Errors + +// Types and methods +pub(all) struct Snapshot { + cpu_permille : UInt32 + mem_used_kib : UInt64 + mem_total_kib : UInt64 + battery_percent : Int32 + charging : Bool + uptime_secs : UInt64 + net_rx_bytes_per_sec : UInt64 + net_tx_bytes_per_sec : UInt64 + load_centi : UInt32 +} + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/wallpaper/pkg.generated.mbti b/interface/chandra/desktop/wallpaper/pkg.generated.mbti new file mode 100644 index 0000000..a6ab8eb --- /dev/null +++ b/interface/chandra/desktop/wallpaper/pkg.generated.mbti @@ -0,0 +1,23 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/wallpaper" + +// Values +pub fn current_desktop() -> UInt32 + +pub fn current_wallpaper() -> UInt32 + +pub fn desktops() -> Array[String] + +pub fn set_desktop(UInt32) -> Unit + +pub fn set_wallpaper(UInt32) -> Unit + +pub fn wallpapers() -> Array[String] + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/interface/chandra/desktop/windows/pkg.generated.mbti b/interface/chandra/desktop/windows/pkg.generated.mbti new file mode 100644 index 0000000..5fb8621 --- /dev/null +++ b/interface/chandra/desktop/windows/pkg.generated.mbti @@ -0,0 +1,32 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/desktop/windows" + +// Values +pub fn all() -> Array[WindowDetail] + +pub fn focus(UInt64) -> Unit + +pub fn focus_window(UInt32) -> Unit + +pub fn list_windows() -> Array[WindowInfo] + +// Errors + +// Types and methods +pub(all) struct WindowDetail { + id : UInt64 + title : String + app_id : String + focused : Bool +} + +pub(all) struct WindowInfo { + id : UInt32 + title : String + focused : UInt32 + minimized : UInt32 +} + +// Type aliases + +// Traits diff --git a/interface/chandra/host/font/pkg.generated.mbti b/interface/chandra/host/font/pkg.generated.mbti new file mode 100644 index 0000000..0a82328 --- /dev/null +++ b/interface/chandra/host/font/pkg.generated.mbti @@ -0,0 +1,23 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/host/font" + +// Values +pub fn load(UInt32, String) -> Bool + +pub fn rasterise(UInt32, UInt32, UInt32) -> Glyph + +// Errors + +// Types and methods +pub(all) struct Glyph { + width : Int32 + height : Int32 + xoff : Int32 + yoff : Int32 + advance : Int32 + coverage : FixedArray[Byte] +} + +// Type aliases + +// Traits diff --git a/interface/chandra/host/plasmoids/ffi.mbt b/interface/chandra/host/plasmoids/ffi.mbt index f3927bf..a17d92a 100644 --- a/interface/chandra/host/plasmoids/ffi.mbt +++ b/interface/chandra/host/plasmoids/ffi.mbt @@ -60,6 +60,12 @@ fn wasmImportPublishBattery(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/plasm ///| fn wasmImportPublishScreenshot(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-screenshot" +///| +fn wasmImportPublishOsk(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-osk" + +///| +fn wasmImportPublishRotation(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-rotation" + ///| fn wasmImportPublishSystem(p0 : Int, p1 : Int64, p2 : Int64, p3 : Int, p4 : Int, p5 : Int64, p6 : Int64, p7 : Int64, p8 : Int) = "chandra:host/plasmoids@0.1.0" "publish-system" @@ -82,39 +88,17 @@ fn wasmImportPickerStart() -> Int = "chandra:host/plasmoids@0.1.0" "picker-start fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll" ///| -#owned(bytes) -extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int = -#|(func (param i32) (result i32) 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_free(position : Int) = +#|(func (param i32) local.get 0 call $moonbit.decref) ///| 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_load8_u(offset : Int) -> Int = -#|(func (param i32) (result i32) local.get 0 i32.load8_u) - -///| -#owned(str) -extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = -#|(func (param i32) (result i32) local.get 0) - -///| -extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 = -#|(func (param i32) (result i64) local.get 0 i64.load) - -///| -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_store64(offset : Int, value : Int64) = -#|(func (param i32) (param i64) local.get 0 local.get 1 i64.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_ptr2str(ptr : Int, len : Int) -> String = #|(func (param i32) (param i32) (result i32) @@ -130,6 +114,28 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int = #| local.get 1) ///| -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) + +///| +#owned(bytes) +extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int = +#|(func (param i32) (result i32) local.get 0) + +///| +extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 = +#|(func (param i32) (result i64) local.get 0 i64.load) + +///| +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_load8_u(offset : Int) -> Int = +#|(func (param i32) (result i32) local.get 0 i32.load8_u) diff --git a/interface/chandra/host/plasmoids/native_stub.mbt b/interface/chandra/host/plasmoids/native_stub.mbt index 818fc9e..43d74f1 100644 --- a/interface/chandra/host/plasmoids/native_stub.mbt +++ b/interface/chandra/host/plasmoids/native_stub.mbt @@ -100,6 +100,16 @@ fn wasmImportPublishScreenshot(p0 : Int) -> Unit { abort("wasm-only host import") } +///| +fn wasmImportPublishOsk(p0 : Int) -> Unit { + abort("wasm-only host import") +} + +///| +fn wasmImportPublishRotation(p0 : Int) -> Unit { + abort("wasm-only host import") +} + ///| fn wasmImportPublishSystem(p0 : Int, p1 : Int64, p2 : Int64, p3 : Int, p4 : Int, p5 : Int64, p6 : Int64, p7 : Int64, p8 : Int) -> Unit { abort("wasm-only host import") @@ -136,7 +146,12 @@ fn wasmImportPickerPoll(p0 : Int) -> Unit { } ///| -fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { +fn mbt_ffi_load32(offset : Int) -> Int { + abort("wasm-only") +} + +///| +fn mbt_ffi_free(position : Int) -> Unit { abort("wasm-only") } @@ -145,36 +160,6 @@ fn mbt_ffi_store32(offset : Int, value : Int) -> Unit { abort("wasm-only") } -///| -fn mbt_ffi_load8_u(offset : Int) -> Int { - abort("wasm-only") -} - -///| -fn mbt_ffi_str2ptr(str : String) -> Int { - abort("wasm-only") -} - -///| -fn mbt_ffi_load64(offset : Int) -> Int64 { - abort("wasm-only") -} - -///| -fn mbt_ffi_store8(offset : Int, value : Int) -> Unit { - abort("wasm-only") -} - -///| -fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit { - abort("wasm-only") -} - -///| -fn mbt_ffi_load32(offset : Int) -> Int { - abort("wasm-only") -} - ///| fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String { abort("wasm-only") @@ -186,6 +171,31 @@ fn mbt_ffi_malloc(size : Int) -> Int { } ///| -fn mbt_ffi_free(position : Int) -> Unit { +fn mbt_ffi_str2ptr(str : String) -> Int { + abort("wasm-only") +} + +///| +fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit { + abort("wasm-only") +} + +///| +fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { + abort("wasm-only") +} + +///| +fn mbt_ffi_load64(offset : Int) -> Int64 { + abort("wasm-only") +} + +///| +fn mbt_ffi_store8(offset : Int, value : Int) -> Unit { + abort("wasm-only") +} + +///| +fn mbt_ffi_load8_u(offset : Int) -> Int { abort("wasm-only") } diff --git a/interface/chandra/host/plasmoids/pkg.generated.mbti b/interface/chandra/host/plasmoids/pkg.generated.mbti index a31da8d..d60949f 100644 --- a/interface/chandra/host/plasmoids/pkg.generated.mbti +++ b/interface/chandra/host/plasmoids/pkg.generated.mbti @@ -31,11 +31,15 @@ pub fn popup(UInt32) -> PopupSurface? pub fn publish_battery(Int32, UInt32, UInt32) -> Unit +pub fn publish_brightness(Int32) -> Unit + pub fn publish_desktop(Int32) -> Unit +pub fn publish_osk(Bool) -> Unit + pub fn publish_power(UInt32, UInt32) -> Unit -pub fn publish_brightness(Int) -> Unit +pub fn publish_rotation(UInt32) -> Unit pub fn publish_screenshot(UInt32) -> Unit @@ -133,6 +137,8 @@ pub(all) enum Request { FaceUnlock(Int32) GameLibrary(GameRequest) SetBrightness(Int32) + SetOskVisible(Bool) + SetRotation(Int32) } pub(all) struct SettingChange { diff --git a/interface/chandra/host/plasmoids/top.mbt b/interface/chandra/host/plasmoids/top.mbt index 1c3a5ef..93a9dba 100644 --- a/interface/chandra/host/plasmoids/top.mbt +++ b/interface/chandra/host/plasmoids/top.mbt @@ -70,6 +70,8 @@ pub(all) enum Request { FaceUnlock(Int) GameLibrary(GameRequest) SetBrightness(Int) + SetOskVisible(Bool) + SetRotation(Int) } ///| /// A native file-chooser dialog (zenity on the host session) for "Add widget". @@ -504,6 +506,20 @@ pub fn publish_screenshot(state : UInt) -> Unit { wasmImportPublishScreenshot((state).reinterpret_as_int()); +} +///| +/// Whether the built-in on-screen keyboard is currently visible. +pub fn publish_osk(visible : Bool) -> Unit { + + wasmImportPublishOsk((if visible { 1 } else { 0 })); + +} +///| +/// Current display orientation (0 = 0°, 1 = 90° CW, 2 = 180°, 3 = 270° CW). +pub fn publish_rotation(rot : UInt) -> Unit { + + wasmImportPublishRotation((rot).reinterpret_as_int()); + } ///| pub fn publish_system(s : SystemSnapshot) -> Unit { @@ -659,6 +675,14 @@ pub fn next_request() -> Request? { Request::SetBrightness(mbt_ffi_load32((return_area) + 8)) } + 23 => { + + Request::SetOskVisible((mbt_ffi_load8_u((return_area) + 8) != 0)) + } + 24 => { + + Request::SetRotation(mbt_ffi_load32((return_area) + 8)) + } _ => panic() } diff --git a/interface/chandra/host/raster/pkg.generated.mbti b/interface/chandra/host/raster/pkg.generated.mbti new file mode 100644 index 0000000..a78fea8 --- /dev/null +++ b/interface/chandra/host/raster/pkg.generated.mbti @@ -0,0 +1,141 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/interface/chandra/host/raster" + +// Values +pub fn capture(Int32, Int32, Int32, Int32, Int32, Int32) -> UInt32 + +pub fn emoji_font() -> Result[String, String] + +pub fn emoji_has(Array[String]) -> Array[Bool] + +pub fn emoji_image(String, Int32) -> UInt32 + +pub fn export_memfd() -> Int32 + +pub fn grab_recording_frame(Int32, Int32, Int32, Int32, Bool, Int32, Int32) -> Bool + +pub fn image_pixels(Int32, Int32, FixedArray[Byte], UInt32) -> UInt32 + +pub fn load_image(String) -> UInt32 + +pub fn read_frame() -> FixedArray[Byte] + +pub fn release(UInt32) -> Unit + +pub fn send_recording_frame(Int32) -> Int32 + +pub fn snapshot_frame() -> Bool + +pub fn snapshot_pixels(Int32, Int32, Int32, Int32, Int32, Int32) -> FixedArray[Byte] + +pub fn snapshot_png(Int32, Int32, Int32, Int32) -> FixedArray[Byte] + +pub fn submit(Frame) -> Unit + +pub fn thumbnail(UInt32, Int32, Int32, UInt32) -> UInt32 + +pub fn write_frame_png(String) -> Bool + +// Errors + +// Types and methods +pub(all) struct Color { + r : Byte + g : Byte + b : Byte + a : Byte +} + +pub(all) struct Disc { + cx : Int32 + cy : Int32 + radius : Int32 + color : Color + filled : Bool +} + +pub(all) struct Fill { + area : Rect + color : Color + radius : Int32 +} + +pub(all) struct Frame { + width : Int32 + height : Int32 + wallpaper : Array[Op]? + background : Array[Op] + windows : Array[Window] + panel : Array[Op] + popups : Array[Popup] +} + +pub(all) struct Label { + x : Int32 + y : Int32 + text : String + size : Int32 + color : Color + align : Byte + bold : Bool + mono : Bool +} + +pub(all) enum Op { + FillRect(Fill) + StrokeRect(Stroke) + DrawLine(Segment) + DrawCircle(Disc) + DrawText(Label) + PushClip(Rect) + PopClip + DrawImage(Picture) +} + +pub(all) struct Picture { + area : Rect + image : UInt32 +} + +pub(all) struct Popup { + area : Rect + surface : UInt32 +} + +pub(all) struct Rect { + x : Int32 + y : Int32 + w : Int32 + h : Int32 +} + +pub(all) struct Segment { + x0 : Int32 + y0 : Int32 + x1 : Int32 + y1 : Int32 + color : Color + width : Int32 +} + +pub(all) struct Stroke { + area : Rect + color : Color + width : Int32 + radius : Int32 +} + +pub(all) struct Window { + geometry : Rect + inset_top : Int32 + inset_right : Int32 + inset_bottom : Int32 + inset_left : Int32 + deco : Array[Op] + fullscreen : Bool + surface : UInt32 +} + +// Type aliases + +// Traits diff --git a/interface/chandra/host/sys/pkg.generated.mbti b/interface/chandra/host/sys/pkg.generated.mbti index 9283518..62e4f72 100644 --- a/interface/chandra/host/sys/pkg.generated.mbti +++ b/interface/chandra/host/sys/pkg.generated.mbti @@ -42,9 +42,9 @@ pub fn sleep_ms(Int32) -> Unit pub fn spawn(String, String) -> Bool -pub fn spawn_socket(String) -> Int +pub fn spawn_socket(String) -> Int32 -pub fn spawn_watch(String, String) -> Int +pub fn spawn_watch(String, String) -> Int32 pub fn take_fd(Int32) -> Int32 diff --git a/lib/clock/pkg.generated.mbti b/lib/clock/pkg.generated.mbti index e2a58cb..3a45473 100644 --- a/lib/clock/pkg.generated.mbti +++ b/lib/clock/pkg.generated.mbti @@ -12,22 +12,60 @@ pub let binary_config : ClockConfig pub fn binary_info() -> (String, String, Int32, Int32, Int32) +pub fn days_in_month(Int32, Int32) -> Int32 + pub let digital_config : ClockConfig pub fn digital_info() -> (String, String, Int32, Int32, Int32) +pub fn is_leap(Int32) -> Bool + +pub fn iso_week(Int32, Int32, Int32) -> Int32 + +pub fn long_date(@types.Datetime) -> String + +pub fn month_grid(Int32, Int32, Bool) -> Array[DayCell] + pub fn render_binary(@types.Size, @theme.Tokens, @types.Datetime, seconds? : Bool) -> Array[@types.DrawOp] pub fn render_digital(@types.Size, @theme.Tokens, @types.Datetime, hour12? : Bool, show_date? : Bool, ampm? : Bool) -> Array[@types.DrawOp] +pub fn weekday_of(Int32, Int32, Int32) -> Int32 + // Errors // Types and methods +pub(all) struct Calendar { + mut open : Bool + mut year : Int32 + mut month : Int32 + mut monday_first : Bool + mut week_numbers : Bool + mut hover : CalendarHit +} +pub fn Calendar::go_today(Self, @types.Datetime) -> Unit +pub fn Calendar::handle(Self, Bool, @types.InputEvent, @types.Datetime) -> Bool +pub fn Calendar::hit(Self, Int32, Int32) -> CalendarHit +pub fn Calendar::new() -> Self +pub fn Calendar::render(Self, @theme.Tokens, @types.Datetime, hour12? : Bool, ampm? : Bool) -> Array[@types.DrawOp] +pub fn Calendar::shift(Self, Int32) -> Unit +pub fn Calendar::size(Self) -> (Int32, Int32) +pub fn Calendar::toggle(Self, @types.Datetime) -> Unit + +#derive(Eq, @debug.Debug) +pub(all) enum CalendarHit { + Prev + Next + Today + Nothing +} + pub(all) struct ClockConfig { mut hour12 : Bool mut show_date : Bool mut seconds : Bool mut ampm : Bool + cal : Calendar } pub fn ClockConfig::binary_items(Self) -> Array[ConfigEntry] pub fn ClockConfig::digital_items(Self) -> Array[ConfigEntry] @@ -42,6 +80,14 @@ pub(all) struct ConfigEntry { value : String } +#derive(Eq, @debug.Debug) +pub(all) struct DayCell { + year : Int32 + month : Int32 + day : Int32 + in_month : Bool +} + // Type aliases // Traits diff --git a/lib/dock/pkg.generated.mbti b/lib/dock/pkg.generated.mbti index 80ae808..810dcf3 100644 --- a/lib/dock/pkg.generated.mbti +++ b/lib/dock/pkg.generated.mbti @@ -58,6 +58,8 @@ pub let size_choices : Array[String] pub fn tile_color(String) -> @types.Color +pub fn titled_at(Array[DockItem], DockConfig, Int32, Int32, Int32) -> Bool + pub fn toggle_pin(Array[String], String) -> Array[String] // Errors diff --git a/lib/gamelib/pkg.generated.mbti b/lib/gamelib/pkg.generated.mbti new file mode 100644 index 0000000..2977835 --- /dev/null +++ b/lib/gamelib/pkg.generated.mbti @@ -0,0 +1,190 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/lib/gamelib" + +import { + "chandra/desktop/interface/chandra/desktop/theme", + "chandra/desktop/interface/chandra/desktop/types", + "moonbitlang/core/debug", +} + +// Values +pub fn approx_width(String, Int32) -> Int32 + +pub let background_choices : Array[String] + +pub let categories : Array[Category] + +pub fn category_badge(String) -> String + +pub let colors_choices : Array[String] + +pub fn count_in(Array[Game], Category) -> Int32 + +pub fn draw_glyph(Array[@types.DrawOp], String, Int32, Int32, Int32, @types.Color, letter? : String) -> Unit + +pub fn ellipsize(String, Int32, Int32) -> String + +pub fn error_message(String) -> String + +pub fn filter_games(Array[Game], Category, String) -> Array[Game] + +pub fn grid_fit(Array[Game], Int32, Int32) -> (Array[(Int32, Int32, Int32, Int32, Int32)], Int32, Int32, Int32) + +pub fn grid_layout(Array[Game], Int32, lv? : Int32, min_w? : Int32) -> (Array[(Int32, Int32, Int32, Int32, Int32)], Int32, Int32) + +pub fn modes_of(Array[Mode], String) -> Array[Mode] + +pub fn parse_int(String) -> Int32 + +pub fn parse_state(String) -> Result[State, String] + +pub let state : Library + +pub fn wrap(String, Int32, Int32, Int32) -> Array[String] + +// Errors + +// Types and methods +#derive(Eq, @debug.Debug) +pub(all) enum Action { + NoAction + Launch(String, String) + Stop(String) + Focus(String) + Refresh +} + +#derive(Eq, @debug.Debug) +pub(all) enum Category { + All + Games + Launchers + Tools + Running +} +pub fn Category::key(Self) -> String +pub fn Category::label(Self) -> String +pub fn Category::parse(String) -> Self +pub fn Category::title(Self) -> String + +#derive(Eq, @debug.Debug) +pub(all) struct ConfigEntry { + key : String + label : String + choices : Array[String] + value : String +} + +#derive(Eq, @debug.Debug) +pub(all) struct Game { + id : String + name : String + category : String + description : String + icon : String + install_hint : String + featured : Bool + installed : Bool + running : Bool +} +pub fn Game::status(Self) -> Status + +#derive(Eq, @debug.Debug) +pub(all) enum Hit { + NoHit + Cat(Category) + Search + ClearSearch + RefreshButton + Card(String) + Button(String, String) + StopButton(String) + FocusButton(String) + RunningRow(String) + RunningStop(String) +} + +pub(all) struct Library { + mut category : Category + mut query : String + mut scroll : Int32 + mut hover : Hit + mut press : Hit + mut selected : String + mut focused : Bool + mut colors : String + mut background : String + regions : Array[(@types.Rect, Hit)] + mut shown : Array[(String, Int32, Int32)] + mut content_h : Int32 + mut view_h : Int32 + mut games : Array[Game] +} +pub fn Library::config_items(Self) -> Array[ConfigEntry] +pub fn Library::handle(Self, @types.InputEvent) -> (Bool, Action) +pub fn Library::hit(Self, @types.Point) -> Hit +pub fn Library::new() -> Self +pub fn Library::render(Self, Array[Game], Array[Mode], Rig, @types.Size, @theme.Tokens) -> Array[@types.DrawOp] +pub fn Library::scroll_by(Self, Int32) -> Bool +pub fn Library::set_config(Self, String, String) -> Bool + +#derive(Eq, @debug.Debug) +pub(all) struct Mode { + game : String + id : String + label : String +} + +pub(all) struct Pal { + bg : @types.Color + panel : @types.Color + card : @types.Color + card_hover : @types.Color + row_sel : @types.Color + border : @types.Color + fg : @types.Color + muted : @types.Color + faint : @types.Color + accent : @types.Color + accent_fg : @types.Color + ok : @types.Color + ok_bg : @types.Color + badge_bg : @types.Color + badge_fg : @types.Color + warn : @types.Color + dark : Bool +} +pub fn Pal::dark() -> Self +pub fn Pal::light() -> Self + +#derive(Eq, @debug.Debug) +pub(all) struct Rig { + connected : Bool + error : String + gpu : String + resolution : String + display : String + audio : String + audio_ok : Bool + hostname : String +} +pub fn Rig::unknown() -> Self + +#derive(Eq, @debug.Debug) +pub(all) struct State { + rig : Rig + games : Array[Game] + modes : Array[Mode] +} + +#derive(Eq, @debug.Debug) +pub(all) enum Status { + Running + Ready + NotInstalled +} +pub fn Status::label(Self) -> String + +// Type aliases + +// Traits diff --git a/lib/icondesk/pkg.generated.mbti b/lib/icondesk/pkg.generated.mbti new file mode 100644 index 0000000..a0cc49d --- /dev/null +++ b/lib/icondesk/pkg.generated.mbti @@ -0,0 +1,70 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/lib/icondesk" + +import { + "chandra/desktop/interface/chandra/desktop/theme", + "chandra/desktop/interface/chandra/desktop/types", + "moonbitlang/core/debug", +} + +// Values +pub let count_choices : Array[String] + +pub let size_choices : Array[String] + +pub let state : Desk + +// Errors + +// Types and methods +#derive(Eq, @debug.Debug) +pub(all) enum Action { + NoAction + Launch(String) +} + +#derive(Eq, @debug.Debug) +pub(all) struct ConfigEntry { + key : String + label : String + choices : Array[String] + value : String +} + +pub(all) struct Desk { + mut count : String + mut size : String + places : Map[String, (Int32, Int32)] + seen : Map[String, Int32] + mut next_seen : Int32 + mut w : Int32 + mut h : Int32 + mut bottom : Int32 + mut hover : String + mut selected : String + mut focused : Bool + mut press_id : String + mut press_x : Int32 + mut press_y : Int32 + mut dragging : Bool + mut ptr_x : Int32 + mut ptr_y : Int32 +} +pub fn Desk::app_at(Self, Array[@types.AppEntry], Int32, Int32) -> String +pub fn Desk::cell(Self) -> (Int32, Int32, Int32) +pub fn Desk::cell_at(Self, Int32, Int32) -> (Int32, Int32) +pub fn Desk::cell_origin(Self, Int32, Int32) -> (Int32, Int32) +pub fn Desk::config_items(Self) -> Array[ConfigEntry] +pub fn Desk::decode_places(Self, String) -> Unit +pub fn Desk::encode_places(Self) -> String +pub fn Desk::grid(Self) -> (Int32, Int32) +pub fn Desk::handle(Self, Array[@types.AppEntry], @types.InputEvent) -> (Bool, Action) +pub fn Desk::layout(Self, Array[@types.AppEntry]) -> Array[(Int32, Int32)] +pub fn Desk::new() -> Self +pub fn Desk::render(Self, Array[@types.AppEntry], @types.Size, @theme.Tokens, (String) -> UInt32) -> Array[@types.DrawOp] +pub fn Desk::set_config(Self, String, String) -> Bool +pub fn Desk::shown(Self, Array[@types.AppEntry]) -> Array[@types.AppEntry] + +// Type aliases + +// Traits diff --git a/lib/launcher/pkg.generated.mbti b/lib/launcher/pkg.generated.mbti index 190af00..5646ded 100644 --- a/lib/launcher/pkg.generated.mbti +++ b/lib/launcher/pkg.generated.mbti @@ -7,11 +7,29 @@ import { } // Values +pub fn action_at(Array[@types.AppEntry], State, @types.Point) -> Int32 + +pub let action_logout : Int32 + +pub let action_power_off : Int32 + +pub let action_reload : Int32 + +pub let action_restart : Int32 + +pub let action_suspend : Int32 + +pub fn categories(Array[@types.AppEntry]) -> Array[String] + pub fn close(State) -> Unit pub fn filter(Array[@types.AppEntry], String) -> Array[@types.AppEntry] -pub fn handle_event(Array[@types.AppEntry], State, Target, @types.InputEvent, (String) -> Result[Unit, String]) -> Bool +pub fn handle_event(Array[@types.AppEntry], State, Target, @types.InputEvent, (String) -> Result[Unit, String], session? : (Int32) -> Unit) -> Bool + +pub fn listed(Array[@types.AppEntry], State) -> Array[@types.AppEntry] + +pub fn needs_confirm(Int32) -> Bool pub fn popup_size(Array[@types.AppEntry], State) -> @types.Size @@ -19,10 +37,12 @@ pub let popup_w : Int32 pub fn render_button(@types.Size, @theme.Tokens, State) -> Array[@types.DrawOp] -pub fn render_popup(Array[@types.AppEntry], @theme.Tokens, State, icon? : (String) -> UInt) -> Array[@types.DrawOp] +pub fn render_popup(Array[@types.AppEntry], @theme.Tokens, State, icon? : (String) -> UInt32) -> Array[@types.DrawOp] pub fn row_at(Array[@types.AppEntry], State, @types.Point) -> Int32 +pub let session_actions : Array[String] + pub fn shown_rows(Array[@types.AppEntry], State) -> Array[@types.AppEntry] // Errors @@ -33,6 +53,11 @@ pub struct State { mut query : String mut hover : Int32 mut error : String + mut hover_action : Int32 + mut armed : Int32 + mut category : String + mut scroll : Int32 + mut hover_category : Int32 } pub fn State::new() -> Self diff --git a/lib/starfield/pkg.generated.mbti b/lib/starfield/pkg.generated.mbti new file mode 100644 index 0000000..dc6b113 --- /dev/null +++ b/lib/starfield/pkg.generated.mbti @@ -0,0 +1,63 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/lib/starfield" + +import { + "chandra/desktop/interface/chandra/desktop/theme", + "chandra/desktop/interface/chandra/desktop/types", + "moonbitlang/core/debug", +} + +// Values +pub let density_choices : Array[String] + +pub let frame_ms : UInt32 + +pub let motion_choices : Array[String] + +pub let speed_choices : Array[String] + +pub let state : Field + +// Errors + +// Types and methods +#derive(Eq, @debug.Debug) +pub(all) struct ConfigEntry { + key : String + label : String + choices : Array[String] + value : String +} + +pub(all) struct Field { + stars : Array[Star] + mut seed : UInt32 + mut speed : String + mut density : String + mut motion : String + mut boost : Double + mut pulse : Double + mut cx : Double + mut cy : Double + mut tx : Double + mut ty : Double + mut w : Int32 + mut h : Int32 + mut last : Int32 + mut frames : Int32 +} +pub fn Field::animating(Self) -> Bool +pub fn Field::config_items(Self) -> Array[ConfigEntry] +pub fn Field::handle(Self, @types.InputEvent) -> Bool +pub fn Field::new() -> Self +pub fn Field::render(Self, @types.Size, @theme.Tokens) -> Array[@types.DrawOp] +pub fn Field::scroll(Self, Int32) -> Bool +pub fn Field::set_config(Self, String, String) -> Bool +pub fn Field::step(Self, Double) -> Unit +pub fn Field::tick(Self, UInt32) -> UInt32 + +type Star + +// Type aliases + +// Traits diff --git a/scripts/components.txt b/scripts/components.txt index 7ab7d79..8b3153e 100644 --- a/scripts/components.txt +++ b/scripts/components.txt @@ -13,3 +13,5 @@ network network-widget icon-desktop icon-desktop-widget starfield starfield-widget gamerig-library gamerig-library-widget +osk osk-widget +rotate rotate-widget diff --git a/session/chandra-ctl b/session/chandra-ctl index 27e2c56..8e456dd 100755 --- a/session/chandra-ctl +++ b/session/chandra-ctl @@ -12,6 +12,7 @@ chandra-ctl screenshot [PATH] save a full-screen PNG directly without opening the editor chandra-ctl rotate [ARG] rotate/flip display (cw, ccw, flip, 0, 90, 180, 270, status) chandra-ctl screen [ARG] turn display off/on (on, off, toggle, status) + chandra-ctl lock [ARG] lock session or configure lock-on-blank (lock, status, on-blank [on|off|status]) chandra-ctl brightness [ARG] get/set backlight brightness percent (5..100, status) chandra-ctl volume [ARG] get/set audio volume (up, down, mute, unmute, toggle, PCT, status) chandra-ctl osk [ARG] enable/disable/query on-screen keyboard (on, off, toggle, status) @@ -33,7 +34,7 @@ import os import socket import sys -USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | kiosk [lock|unlock|status] | launch ID | windows | screenshot [PATH] | rotate [ARG] | screen [ARG] | brightness [ARG] | volume [ARG] | osk [ARG] | status | refresh | settings [TAB] | auth-demo [MODE] | auth-status | help}" +USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | kiosk [lock|unlock|status] | launch ID | windows | screenshot [PATH] | rotate [ARG] | screen [ARG] | lock [ARG] | brightness [ARG] | volume [ARG] | osk [ARG] | status | refresh | settings [TAB] | auth-demo [MODE] | auth-status | help}" def runtime_dir(): diff --git a/session/install.py b/session/install.py index fc4f104..0860bda 100755 --- a/session/install.py +++ b/session/install.py @@ -85,6 +85,7 @@ targets = [ "/usr/share/xsessions/chandra-x11.desktop", "/usr/share/xdg-desktop-portal/portals/chandra.portal", "/usr/share/xdg-desktop-portal/chandra-portals.conf", + "/usr/share/polkit-1/actions/org.chandra.unlock.policy", ] if os.geteuid() != 0: @@ -225,6 +226,7 @@ if os.path.isdir(cam_ipa_src): for fn in sorted(os.listdir(cam_ipa_src)): if fn.endswith(".yaml"): put(os.path.join(cam_ipa_src, fn), os.path.join(cam_ipa_dst, fn), 0o644) +put(os.path.join(root, "compositor/polkit/org.chandra.unlock.policy"), "/usr/share/polkit-1/actions/org.chandra.unlock.policy", 0o644) put(os.path.join(root, "camera/chandra-camera.desktop"), "/usr/share/applications/chandra-camera.desktop", 0o644) put(os.path.join(root, "camera/chandra-camera.svg"), "/usr/share/icons/hicolor/scalable/apps/chandra-camera.svg", 0o644) remote_srcs = [ diff --git a/wasmhost/bin/plasmoids.mbt b/wasmhost/bin/plasmoids.mbt index 8564ae1..9b527a6 100644 --- a/wasmhost/bin/plasmoids.mbt +++ b/wasmhost/bin/plasmoids.mbt @@ -270,6 +270,8 @@ fn request_val(r : @wasm.HostRequest) -> @wt.Val { "game-library", Some(Record([("action", S32(action)), ("game", Str(game)), ("mode", Str(mode))])), ) + SetOskVisible(b) => Variant("set-osk-visible", Some(Bool(b))) + SetRotation(n) => Variant("set-rotation", Some(S32(n))) } } @@ -488,6 +490,20 @@ fn plasmoid_funcs() -> Array[(String, (Array[@wt.Val]) -> Array[@wt.Val])] { none }, ), + ( + "publish-osk", + a => { + @wasm.publish_osk(a[0].to_bool()) + none + }, + ), + ( + "publish-rotation", + a => { + @wasm.publish_rotation(a[0].to_uint().reinterpret_as_int()) + none + }, + ), ( "publish-system", a => { diff --git a/wit/capabilities.wit b/wit/capabilities.wit index 0bb059e..2ab7cec 100644 --- a/wit/capabilities.wit +++ b/wit/capabilities.wit @@ -431,3 +431,22 @@ interface game-library { /// Poll the daemon again now. refresh: func(); } + +/// Built-in on-screen keyboard (OSK). The compositor draws the keyboard above the panel and routes +/// keystrokes to focused Wayland clients, panel popups and dialogs; a module with this capability +/// reads whether the keyboard is showing and opens or hides it. +interface osk { + /// Whether the on-screen keyboard is currently visible. + is-visible: func() -> bool; + /// Show (true) or hide (false) the on-screen keyboard. + set-visible: func(visible: bool); +} + +/// Display orientation (0°, 90° CW, 180°, 270° CW). The host rotates scanout and input +/// coordinates; a module with this capability reads the current orientation and rotates it. +interface rotation { + /// Current orientation: 0 = 0°, 1 = 90° CW, 2 = 180°, 3 = 270° CW. + current: func() -> u32; + /// Set the orientation (0..3, wrapped modulo 4). + set-rotation: func(rot: u32); +} diff --git a/wit/host/plasmoids.wit b/wit/host/plasmoids.wit index c9850fc..918bef7 100644 --- a/wit/host/plasmoids.wit +++ b/wit/host/plasmoids.wit @@ -92,6 +92,10 @@ interface plasmoids { publish-battery: func(percent: s32, state: u32, secs-left: u32); /// Screenshot state: bit 0 a recording is running, bit 1 recordings show the pointer. publish-screenshot: func(state: u32); + /// Whether the built-in on-screen keyboard is currently visible. + publish-osk: func(visible: bool); + /// Current display orientation (0 = 0°, 1 = 90° CW, 2 = 180°, 3 = 270° CW). + publish-rotation: func(rot: u32); record system-snapshot { cpu-permille: u32, @@ -181,6 +185,10 @@ interface plasmoids { game-library(game-request), /// Power: display backlight brightness percentage (5..100). set-brightness(s32), + /// The osk capability: show (true) or hide (false) the on-screen keyboard. + set-osk-visible(bool), + /// The rotation capability: set display orientation (0..3). + set-rotation(s32), } /// The next pending request, oldest first. next-request: func() -> option; diff --git a/wit/worlds.wit b/wit/worlds.wit index e25eda3..64547c0 100644 --- a/wit/worlds.wit +++ b/wit/worlds.wit @@ -104,6 +104,8 @@ world plasmoid-host { import default-apps; import face-unlock; import game-library; + import osk; + import rotation; export plasmoid; } @@ -178,3 +180,15 @@ world gamerig-library-widget { import game-library; export module-config; } + +/// On-screen keyboard toggle button ("KB"). +world osk-widget { + include widget; + import osk; +} + +/// Display rotation button ("Rot"): rotates 90° clockwise on click. +world rotate-widget { + include widget; + import rotation; +} diff --git a/world/compositor/pkg.generated.mbti b/world/compositor/pkg.generated.mbti new file mode 100644 index 0000000..f567ea9 --- /dev/null +++ b/world/compositor/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/compositor" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/gamerig-library-widget/pkg.generated.mbti b/world/gamerig-library-widget/pkg.generated.mbti new file mode 100644 index 0000000..49a6430 --- /dev/null +++ b/world/gamerig-library-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/gamerig-library-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/icon-desktop-widget/pkg.generated.mbti b/world/icon-desktop-widget/pkg.generated.mbti new file mode 100644 index 0000000..0fb5c32 --- /dev/null +++ b/world/icon-desktop-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/icon-desktop-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/inspector-widget/pkg.generated.mbti b/world/inspector-widget/pkg.generated.mbti new file mode 100644 index 0000000..de80b68 --- /dev/null +++ b/world/inspector-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/inspector-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/layout-widget/pkg.generated.mbti b/world/layout-widget/pkg.generated.mbti new file mode 100644 index 0000000..0129424 --- /dev/null +++ b/world/layout-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/layout-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/network-widget/pkg.generated.mbti b/world/network-widget/pkg.generated.mbti new file mode 100644 index 0000000..011a472 --- /dev/null +++ b/world/network-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/network-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/osk-widget/README.md b/world/osk-widget/README.md new file mode 100644 index 0000000..6833fc5 --- /dev/null +++ b/world/osk-widget/README.md @@ -0,0 +1 @@ +On-screen keyboard toggle button ("KB"). \ No newline at end of file diff --git a/world/osk-widget/ffi_import.mbt b/world/osk-widget/ffi_import.mbt new file mode 100644 index 0000000..cdedbce --- /dev/null +++ b/world/osk-widget/ffi_import.mbt @@ -0,0 +1,2 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + diff --git a/world/osk-widget/import.mbt b/world/osk-widget/import.mbt new file mode 100644 index 0000000..cdedbce --- /dev/null +++ b/world/osk-widget/import.mbt @@ -0,0 +1,2 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + diff --git a/world/osk-widget/moon.pkg b/world/osk-widget/moon.pkg new file mode 100644 index 0000000..e2a6033 --- /dev/null +++ b/world/osk-widget/moon.pkg @@ -0,0 +1 @@ +warnings = "-44" diff --git a/world/osk-widget/pkg.generated.mbti b/world/osk-widget/pkg.generated.mbti new file mode 100644 index 0000000..4d74297 --- /dev/null +++ b/world/osk-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/osk-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/rotate-widget/README.md b/world/rotate-widget/README.md new file mode 100644 index 0000000..3f6e66c --- /dev/null +++ b/world/rotate-widget/README.md @@ -0,0 +1 @@ +Display rotation button ("Rot"): rotates 90° clockwise on click. \ No newline at end of file diff --git a/world/rotate-widget/ffi_import.mbt b/world/rotate-widget/ffi_import.mbt new file mode 100644 index 0000000..cdedbce --- /dev/null +++ b/world/rotate-widget/ffi_import.mbt @@ -0,0 +1,2 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + diff --git a/world/rotate-widget/import.mbt b/world/rotate-widget/import.mbt new file mode 100644 index 0000000..cdedbce --- /dev/null +++ b/world/rotate-widget/import.mbt @@ -0,0 +1,2 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + diff --git a/world/rotate-widget/moon.pkg b/world/rotate-widget/moon.pkg new file mode 100644 index 0000000..e2a6033 --- /dev/null +++ b/world/rotate-widget/moon.pkg @@ -0,0 +1 @@ +warnings = "-44" diff --git a/world/rotate-widget/pkg.generated.mbti b/world/rotate-widget/pkg.generated.mbti new file mode 100644 index 0000000..d314a8f --- /dev/null +++ b/world/rotate-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/rotate-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/screenshot-widget/pkg.generated.mbti b/world/screenshot-widget/pkg.generated.mbti new file mode 100644 index 0000000..8d68f52 --- /dev/null +++ b/world/screenshot-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/screenshot-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/session-settings-widget/pkg.generated.mbti b/world/session-settings-widget/pkg.generated.mbti new file mode 100644 index 0000000..b602dc3 --- /dev/null +++ b/world/session-settings-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/session-settings-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/starfield-widget/pkg.generated.mbti b/world/starfield-widget/pkg.generated.mbti new file mode 100644 index 0000000..99551ba --- /dev/null +++ b/world/starfield-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/starfield-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits diff --git a/world/taskbar-widget/pkg.generated.mbti b/world/taskbar-widget/pkg.generated.mbti new file mode 100644 index 0000000..a887cf0 --- /dev/null +++ b/world/taskbar-widget/pkg.generated.mbti @@ -0,0 +1,12 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chandra/desktop/world/taskbar-widget" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits