Session settings panel module: switch session restore and window placement on or off
CI / test (push) Failing after 16s

- New 'session-settings' capability (wit/capabilities.wit: settings, is-on, set-setting) and
  'session-settings' panel module: a "Session" button whose popup lists the session settings,
  each with an on/off switch. Clicking a row flips it at once (the list stays open); Up/Down move
  the highlight, Enter or Space flips it, Escape or a click elsewhere closes. In the default
  panel, between Wallpaper and Log out.
- Two settings to start with, kept in state.edn and written only when off (absent means on):
  "Reopen windows at login" (:restore-session, the key session restore already read) and
  "Remember window positions" (:remember-windows; when off, floating windows aren't placed where
  their app was left and new places aren't recorded, but the saved ones are kept).
- Served by both hosts: wasmer stub (native; settings table 6, bit mask in host int 3,
  requests 10/11) and host-wasm (publish-session-settings, set-session-setting request).
- Tests: native end-to-end (open, click both rows, keyboard, Escape), a state.edn round trip
  that checks both settings take effect, and a host-wasm module test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgxf6exeYrDGcy4WW3
This commit is contained in:
Claude committed 2026-11-25 18:43:27 +00:00
1 parent c169489d44
commit a0b878af23
32 files changed
+1192 -44

No files matched your search

+82
View File
@@ -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 wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
}
///|
#doc(hidden)
pub fn wasmExportPopup() -> Int {
@plasmoid.wasmExportPopup()
}
///|
#doc(hidden)
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportInfoPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportRenderPostReturn(p0)
}
///|
#doc(hidden)
pub fn wasmExportInfo() -> Int {
@plasmoid.wasmExportInfo()
}
///|
#doc(hidden)
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
@plasmoid.wasmExportRender(p0, p1)
}
///|
#doc(hidden)
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
@plasmoid.wasmExportPopupPostReturn(p0)
}
@@ -0,0 +1 @@
The widget (plasmoid) contract.
@@ -0,0 +1,409 @@
// 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))
()
}
}
}
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 => ()
_ => 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))
()
}
}
}
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 => ()
_ => 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_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
#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)
@@ -0,0 +1,8 @@
import {
"chandra/desktop/interface/chandra/desktop/types" @types,
"chandra/desktop/interface/chandra/desktop/theme" @theme,
"chandra/desktop/interface/chandra/desktop/session-settings" @settings,
"chandra/desktop/lib/ui" @ui,
}
warnings = "-44"
@@ -0,0 +1,197 @@
///| Implementation of `chandra:desktop/plasmoid` for the session settings. The panel button opens
/// a popup listing the session settings the shell offers (`session-settings.settings`), each with
/// an on/off switch. Clicking a row (or Enter or Space on the highlighted one) flips it at once, and
/// the shell remembers it in state.edn; Up/Down move the highlight; Escape or a click elsewhere
/// closes the popup.
///| Popup geometry: a column of rows with a margin around them.
let popup_w : Int = 290
///|
let row_h : Int = 32
///|
let margin : Int = 6
///| The switch at the right end of a row.
let switch_w : Int = 34
///|
let switch_h : Int = 18
///| Whether the popup is open, and which row is highlighted (-1: none).
let open_ : Ref[Bool] = { val: false }
///|
let hover : Ref[Int] = { val: -1 }
///| The names, read when the popup opens (the list is fixed while it is open).
let names : Ref[Array[String]] = { val: [] }
///|
fn popup_h() -> Int {
margin * 2 + names.val.length() * row_h
}
///| Row under a popup-local point, or -1.
fn row_at(x : Int, y : Int) -> Int {
if x < margin || x >= popup_w - margin || y < margin {
return -1
}
let i = (y - margin) / row_h
if i < names.val.length() { i } else { -1 }
}
///|
fn open() -> Unit {
names.val = @settings.settings()
open_.val = true
hover.val = if names.val.length() > 0 { 0 } else { -1 }
}
///|
fn close() -> Unit {
open_.val = false
hover.val = -1
}
///| Flip setting `i` (ignored when out of range).
fn toggle(i : Int) -> Unit {
if i >= 0 && i < names.val.length() {
let idx = i.reinterpret_as_uint()
@settings.set_setting(idx, !@settings.is_on(idx))
}
}
///|
pub fn info() -> PlasmoidInfo {
{
id: "org.chandra.session-settings",
name: "Session",
preferred: { w: 86, 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 r = t.radius.reinterpret_as_int()
let fs = t.font_size.reinterpret_as_int()
let bg = if open_.val { t.palette.accent } else { t.palette.surface_hover }
let fg = if open_.val { t.palette.accent_foreground } else { t.palette.foreground }
// A small switch glyph (track and knob), then the label when there is room.
let gx = 8
let gy = h / 2
let ops = [
@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r),
@ui.stroke_rect(@ui.rect(gx, gy - 6, 20, 12), fg, width=1, radius=6),
@ui.circle(gx + 14, gy, 4, fg),
]
if w >= 70 {
ops.push(@ui.text(gx + 26, gy, "Session", fs - 2, fg))
}
ops
}
///|
pub fn popup() -> PopupSurface? {
if !open_.val {
return None
}
let t = @theme.get_tokens()
let w = popup_w
let h = popup_h()
let r = t.radius.reinterpret_as_int()
let fs = t.font_size.reinterpret_as_int()
let ops : Array[@types.DrawOp] = [
@ui.fill_rect(@ui.rect(0, 0, w, h), t.palette.surface_popup, radius=r),
@ui.stroke_rect(@ui.rect(0, 0, w, h), t.palette.border, width=1, radius=r),
]
for i = 0; i < names.val.length(); i = i + 1 {
let y = margin + i * row_h
let hot = i == hover.val
if hot {
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.surface_hover, radius=r))
}
let mid = y + (row_h - 2) / 2
ops.push(@ui.text(margin + 10, mid, names.val[i], fs - 1, t.palette.foreground))
// The switch: an accent track with the knob on the right when on, a muted outline when off.
let on = @settings.is_on(i.reinterpret_as_uint())
let sx = w - margin - 10 - switch_w
let sy = mid - switch_h / 2
let knob = switch_h / 2 - 3
if on {
ops.push(@ui.fill_rect(@ui.rect(sx, sy, switch_w, switch_h), t.palette.accent, radius=switch_h / 2))
ops.push(@ui.circle(sx + switch_w - switch_h / 2, mid, knob, t.palette.accent_foreground))
} else {
ops.push(@ui.stroke_rect(@ui.rect(sx, sy, switch_w, switch_h), t.palette.foreground_muted, width=1, radius=switch_h / 2))
ops.push(@ui.circle(sx + switch_h / 2, mid, knob, t.palette.foreground_muted))
}
}
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
}
///|
pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
match (target, event) {
(WIDGET, PointerDown(_)) => {
if open_.val {
close()
} else {
open()
}
true
}
(POPUP, PointerMove(p)) => {
let i = row_at(p.x, p.y)
if i != hover.val && i >= 0 {
hover.val = i
true
} else {
false
}
}
(POPUP, PointerDown(p)) => {
let i = row_at(p.x, p.y)
if i >= 0 {
toggle(i)
hover.val = i
}
true
}
(_, FocusLost) =>
if open_.val {
close()
true
} else {
false
}
(_, KeyDown(k)) =>
if !open_.val {
false
} else if k == "Escape" {
close()
true
} else if k == "Enter" || k == " " || k == "Space" {
toggle(hover.val)
true
} else if k == "ArrowDown" || k == "Down" {
if hover.val + 1 < names.val.length() {
hover.val = hover.val + 1
}
true
} else if k == "ArrowUp" || k == "Up" {
if hover.val > 0 {
hover.val = hover.val - 1
}
true
} else {
false
}
_ => false
}
}
@@ -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
+26
View File
@@ -0,0 +1,26 @@
import {
"chandra/desktop/components/session-settings/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"
],
},
},
)
+72
View File
@@ -1253,3 +1253,75 @@ test "the open windows are saved as the session and a restored app's window gets
assert_eq(b.shell.load_session().length(), 0) assert_eq(b.shell.load_session().length(), 0)
} }
} }
///|
test "the session settings module flips the session settings from its popup" {
let comp = new_comp("sessset")
let slot = comp.shell.slot_of("session-settings")
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
assert_true(comp.shell.restore_session)
assert_true(comp.shell.remember_windows)
// A click opens the list of switches; nothing changes yet.
click_module(comp, "session-settings", 1U)
let pr = comp.shell.slot_popup_rect(slot)
assert_true(pr.h >= 6 * 2 + 2 * 32) // one row per setting
assert_true(comp.shell.restore_session)
// First row: "Reopen windows at login" goes off, and on again with a second click.
click_at(comp, pr.x + 40, pr.y + 6 + 5, 5U)
assert_false(comp.shell.restore_session)
assert_true(comp.shell.remember_windows)
assert_true(comp.shell.slot_popup_rect(slot).w > 0) // the list stays open
click_at(comp, pr.x + 40, pr.y + 6 + 5, 10U)
assert_true(comp.shell.restore_session)
// Second row: "Remember window positions"; then Down and Enter flip it back from the keyboard.
click_at(comp, pr.x + 40, pr.y + 6 + 32 + 5, 15U)
assert_false(comp.shell.remember_windows)
comp.shell.key_down("Enter")
ignore(comp.compose_frame())
assert_true(comp.shell.remember_windows)
assert_true(comp.shell.restore_session)
comp.shell.key_down("Escape")
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
// Out-of-range settings are ignored.
comp.shell.set_session_setting(7, false)
assert_true(comp.shell.restore_session && comp.shell.remember_windows)
}
///|
test "session settings are saved to state.edn and restored, and take effect" {
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
write_state_edn("{:note \"keep\" :session [{:app \"foot\"}]}\n")
let a = new_comp("sess-a")
a.shell.persist = true
a.restore_state()
assert_true(a.shell.restore_session) // absent: on
assert_eq(a.shell.load_session().length(), 1)
a.shell.remember_window("foot", 10, 20, 300, 200)
assert_eq(a.shell.saved_window("foot"), Some((10, 20, 300, 200)))
// Turning them off writes them, keeps the other keys, and stops reopening and placing.
a.shell.set_session_setting(0, false)
a.shell.set_session_setting(1, false)
let text = read_state_edn()
assert_true(text.contains(":restore-session false"))
assert_true(text.contains(":remember-windows false"))
assert_true(text.contains(":note \"keep\""))
assert_true(text.contains(":session"))
assert_eq(a.shell.load_session().length(), 0)
assert_eq(a.shell.saved_window("foot"), None)
a.shell.remember_window("foot", 50, 60, 300, 200) // not recorded while off
let b = new_comp("sess-b")
b.shell.persist = true
b.restore_state()
assert_false(b.shell.restore_session)
assert_false(b.shell.remember_windows)
// On again: the keys go away (absent means on), and the old place is still known.
b.shell.set_session_setting(0, true)
b.shell.set_session_setting(1, true)
let text2 = read_state_edn()
assert_false(text2.contains(":restore-session"))
assert_false(text2.contains(":remember-windows"))
assert_eq(b.shell.load_session().length(), 1)
assert_eq(b.shell.saved_window("foot"), Some((10, 20, 300, 200)))
}
}
+6
View File
@@ -202,6 +202,10 @@ pub(all) struct DesktopShell {
mut wallpaper_len : Int mut wallpaper_len : Int
/// Which wallpaper is drawn (an index into `@libshell.wallpaper_names`); the wallpaper module sets it. /// Which wallpaper is drawn (an index into `@libshell.wallpaper_names`); the wallpaper module sets it.
mut wallpaper_sel : Int mut wallpaper_sel : Int
/// Session settings (the session settings module flips them; saved in state.edn): reopen the
/// last session's windows at the next start, and remember where floating windows were left.
mut restore_session : Bool
mut remember_windows : Bool
mut desk_set : Bool mut desk_set : Bool
mut desk_x : Int mut desk_x : Int
mut desk_y : Int mut desk_y : Int
@@ -286,6 +290,8 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
screen_w: 0, screen_w: 0,
wallpaper_len: 0, wallpaper_len: 0,
wallpaper_sel: 0, wallpaper_sel: 0,
restore_session: true,
remember_windows: true,
desk_set: false, desk_set: false,
desk_x: 0, desk_x: 0,
desk_y: 0, desk_y: 0,
+50 -6
View File
@@ -9,7 +9,9 @@
/// :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}] /// :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}]
/// ; the windows open when the last session ended, reopened at /// ; the windows open when the last session ended, reopened at
/// ; the next start (see session.mbt in compositor/host) /// ; the next start (see session.mbt in compositor/host)
/// :restore-session false} ; hand-written: don't reopen them (absent: reopen) /// :restore-session false ; don't reopen them (absent: reopen); the session settings module
/// ; or a hand edit sets it
/// :remember-windows false} ; don't place windows where they were left (absent: do)
/// ///
/// Saving merges into what is already in the file, so keys this build doesn't know (a future /// Saving merges into what is already in the file, so keys this build doesn't know (a future
/// widget's state, hand-written notes) survive. Everything is a no-op unless `persist` is on /// widget's state, hand-written notes) survive. Everything is a no-op unless `persist` is on
@@ -26,6 +28,9 @@ pub(all) struct SavedState {
windows : Map[String, (Int, Int, Int, Int)] windows : Map[String, (Int, Int, Int, Int)]
/// Index into `@libshell.wallpaper_names`. /// Index into `@libshell.wallpaper_names`.
wallpaper : Int? wallpaper : Int?
/// Session settings; None when the file doesn't say (both default to on).
restore_session : Bool?
remember_windows : Bool?
} }
///| ///|
@@ -37,7 +42,9 @@ fn state_path() -> String {
let layout_names : Array[String] = ["tiling", "monocle", "floating"] let layout_names : Array[String] = ["tiling", "monocle", "floating"]
///| The keys this build owns; everything else in the file is kept as it is. ///| The keys this build owns; everything else in the file is kept as it is.
let owned_keys : Array[String] = ["layout", "recent", "desktop-card", "windows", "wallpaper"] let owned_keys : Array[String] = [
"layout", "recent", "desktop-card", "windows", "wallpaper", "restore-session", "remember-windows",
]
///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order. ///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order.
let wallpaper_keys : Array[String] = ["plasma-glow", "aurora", "starfield", "dusk", "solid"] let wallpaper_keys : Array[String] = ["plasma-glow", "aurora", "starfield", "dusk", "solid"]
@@ -72,7 +79,15 @@ fn lookup_key(
///| Read state.edn. Without `persist` nothing is read. ///| Read state.edn. Without `persist` nothing is read.
pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState { pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
if !self.persist { if !self.persist {
return { layout: None, recent: None, desk: None, windows: {}, wallpaper: None } return {
layout: None,
recent: None,
desk: None,
windows: {},
wallpaper: None,
restore_session: None,
remember_windows: None,
}
} }
let entries = read_state_file() let entries = read_state_file()
let layout = match lookup_key(entries, "layout") { let layout = match lookup_key(entries, "layout") {
@@ -157,7 +172,21 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
} }
_ => None _ => None
} }
{ layout, recent, desk, windows, wallpaper } let flag = fn(k : String) -> Bool? {
match lookup_key(entries, k) {
Some(Bool(b)) => Some(b)
_ => None
}
}
{
layout,
recent,
desk,
windows,
wallpaper,
restore_session: flag("restore-session"),
remember_windows: flag("remember-windows"),
}
} }
///| Take the saved recents (the layout is the compositor's to apply). ///| Take the saved recents (the layout is the compositor's to apply).
@@ -169,6 +198,14 @@ pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
Some(i) => self.wallpaper_sel = i Some(i) => self.wallpaper_sel = i
None => () None => ()
} }
match st.restore_session {
Some(b) => self.restore_session = b
None => ()
}
match st.remember_windows {
Some(b) => self.remember_windows = b
None => ()
}
match st.desk { match st.desk {
Some((x, y)) => { Some((x, y)) => {
self.desk_set = true self.desk_set = true
@@ -240,6 +277,13 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
if self.wallpaper_sel > 0 && self.wallpaper_sel < wallpaper_keys.length() { if self.wallpaper_sel > 0 && self.wallpaper_sel < wallpaper_keys.length() {
entries.insert(2, (@edn.Value::Keyword("wallpaper"), @edn.Value::Keyword(wallpaper_keys[self.wallpaper_sel]))) entries.insert(2, (@edn.Value::Keyword("wallpaper"), @edn.Value::Keyword(wallpaper_keys[self.wallpaper_sel])))
} }
// Session settings are written only when off: absent means on, as for a hand-written file.
if !self.remember_windows {
entries.insert(2, (@edn.Value::Keyword("remember-windows"), @edn.Value::Bool(false)))
}
if !self.restore_session {
entries.insert(2, (@edn.Value::Keyword("restore-session"), @edn.Value::Bool(false)))
}
write_state_file(entries) write_state_file(entries)
} }
@@ -278,7 +322,7 @@ fn parse_int_str(s : String) -> Int? {
///| Remember where an app's window was left (a no-op without an app id) and save. ///| Remember where an app's window was left (a no-op without an app id) and save.
pub fn DesktopShell::remember_window(self : DesktopShell, app_id : String, x : Int, y : Int, w : Int, h : Int) -> Unit { pub fn DesktopShell::remember_window(self : DesktopShell, app_id : String, x : Int, y : Int, w : Int, h : Int) -> Unit {
if app_id.length() == 0 || w <= 0 || h <= 0 { if app_id.length() == 0 || w <= 0 || h <= 0 || !self.remember_windows {
return return
} }
self.win_geoms.set(app_id, (x, y, w, h)) self.win_geoms.set(app_id, (x, y, w, h))
@@ -287,7 +331,7 @@ pub fn DesktopShell::remember_window(self : DesktopShell, app_id : String, x : I
///| The saved place of an app's window, if persistence is on and one was saved. ///| The saved place of an app's window, if persistence is on and one was saved.
pub fn DesktopShell::saved_window(self : DesktopShell, app_id : String) -> (Int, Int, Int, Int)? { pub fn DesktopShell::saved_window(self : DesktopShell, app_id : String) -> (Int, Int, Int, Int)? {
if self.persist { self.win_geoms.get(app_id) } else { None } if self.persist && self.remember_windows { self.win_geoms.get(app_id) } else { None }
} }
///| One window of a saved session: the app id its window carried and how it was left. ///| One window of a saved session: the app id its window carried and how it was left.
+31 -1
View File
@@ -11,7 +11,8 @@
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right. ///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
let default_panel : Array[String] = [ let default_panel : Array[String] = [
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "wallpaper", "logout", "launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "wallpaper", "session-settings",
"logout",
] ]
///| The module whose popup is the wasm picker. ///| The module whose popup is the wasm picker.
@@ -391,6 +392,15 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
@wasm.publish(Wallpapers, pt) @wasm.publish(Wallpapers, pt)
@wasm.publish_wallpaper(self.wallpaper_sel) @wasm.publish_wallpaper(self.wallpaper_sel)
} }
if self.widgets.iter().any(w => w.has_cap("session-settings")) {
let st = @wasm.Table::new()
for n in session_setting_names {
st.str(n)
st.end_row()
}
@wasm.publish(SessionSettings, st)
@wasm.publish_session_settings(self.session_settings_bits())
}
let it = @wasm.Table::new() let it = @wasm.Table::new()
for w in self.widgets { for w in self.widgets {
it.str(w.slot) it.str(w.slot)
@@ -435,6 +445,25 @@ pub fn DesktopShell::set_wallpaper(self : DesktopShell, i : Int) -> Unit {
self.save_state() self.save_state()
} }
///| The session settings the session settings module lists, in index order.
let session_setting_names : Array[String] = ["Reopen windows at login", "Remember window positions"]
///| Which session settings are on: bit i for `session_setting_names[i]`.
fn DesktopShell::session_settings_bits(self : DesktopShell) -> Int {
(if self.restore_session { 1 } else { 0 }) | (if self.remember_windows { 2 } else { 0 })
}
///| Turn session setting `i` on or off (ignored when out of range) and remember it in state.edn.
pub fn DesktopShell::set_session_setting(self : DesktopShell, i : Int, on : Bool) -> Unit {
match i {
0 => self.restore_session = on
1 => self.remember_windows = on
_ => return
}
@wasm.publish_session_settings(self.session_settings_bits())
self.save_state()
}
///| Carry out what modules asked of the host during their last calls. ///| Carry out what modules asked of the host during their last calls.
fn DesktopShell::process_requests(self : DesktopShell) -> Unit { fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
while true { while true {
@@ -456,6 +485,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
Some(SetLayout(m)) => self.actions.push(SetLayout(m)) Some(SetLayout(m)) => self.actions.push(SetLayout(m))
Some(Logout) => self.actions.push(Logout) Some(Logout) => self.actions.push(Logout)
Some(SetWallpaper(i)) => self.set_wallpaper(i) Some(SetWallpaper(i)) => self.set_wallpaper(i)
Some(SetSessionSetting(i, on)) => self.set_session_setting(i, on)
Some(SetInspector(on)) => self.set_inspecting(on) Some(SetInspector(on)) => self.set_inspecting(on)
Some(LoadModule(path)) => { Some(LoadModule(path)) => {
match self.load_path(path) { match self.load_path(path) {
+10
View File
@@ -232,6 +232,7 @@ pub(all) enum HostTable {
Modules Modules
Instances Instances
Wallpapers Wallpapers
SessionSettings
} }
///| ///|
@@ -252,6 +253,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Modules => 3U Modules => 3U
Instances => 4U Instances => 4U
Wallpapers => 5U Wallpapers => 5U
SessionSettings => 6U
} }
@hostpl.publish_table(id, out) @hostpl.publish_table(id, out)
} }
@@ -266,6 +268,11 @@ pub fn publish_wallpaper(current : Int) -> Unit {
@hostpl.publish_wallpaper(current) @hostpl.publish_wallpaper(current)
} }
///| Which session settings are on: bit i for row i of the SessionSettings table.
pub fn publish_session_settings(on : Int) -> Unit {
@hostpl.publish_session_settings(on.reinterpret_as_uint())
}
///| Something a module asked the host to do during a call. ///| Something a module asked the host to do during a call.
pub(all) enum HostRequest { pub(all) enum HostRequest {
Launch(String) Launch(String)
@@ -277,6 +284,8 @@ pub(all) enum HostRequest {
Browse Browse
Logout Logout
SetWallpaper(Int) SetWallpaper(Int)
/// Turn session setting `index` on or off.
SetSessionSetting(Int, Bool)
} derive(Eq, Debug) } derive(Eq, Debug)
///| ///|
@@ -292,6 +301,7 @@ pub fn next_request() -> HostRequest? {
Some(Browse) => Some(Browse) Some(Browse) => Some(Browse)
Some(Logout) => Some(Logout) Some(Logout) => Some(Logout)
Some(SetWallpaper(i)) => Some(SetWallpaper(i)) Some(SetWallpaper(i)) => Some(SetWallpaper(i))
Some(SetSessionSetting(c)) => Some(SetSessionSetting(c.index, c.on))
} }
} }
+11
View File
@@ -608,6 +608,7 @@ pub(all) enum HostTable {
Modules Modules
Instances Instances
Wallpapers Wallpapers
SessionSettings
} }
///| Publish `t` as the data behind `which` for every module's next call. ///| Publish `t` as the data behind `which` for every module's next call.
@@ -619,6 +620,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Modules => 3 Modules => 3
Instances => 4 Instances => 4
Wallpapers => 5 Wallpapers => 5
SessionSettings => 6
} }
let out : Array[Byte] = [] let out : Array[Byte] = []
for k = 0; k < 4; k = k + 1 { for k = 0; k < 4; k = k + 1 {
@@ -641,6 +643,11 @@ pub fn publish_wallpaper(current : Int) -> Unit {
c_host_set_int(2, current) c_host_set_int(2, current)
} }
///| Publish which session settings are on: bit i for row i of the SessionSettings table.
pub fn publish_session_settings(on : Int) -> Unit {
c_host_set_int(3, on)
}
///| Something a module asked the host to do during a call. ///| Something a module asked the host to do during a call.
pub(all) enum HostRequest { pub(all) enum HostRequest {
Launch(String) Launch(String)
@@ -652,6 +659,8 @@ pub(all) enum HostRequest {
Browse Browse
Logout Logout
SetWallpaper(Int) SetWallpaper(Int)
/// Turn session setting `index` on or off.
SetSessionSetting(Int, Bool)
} derive(Eq, Debug) } derive(Eq, Debug)
///| ///|
@@ -673,6 +682,8 @@ pub fn next_request() -> HostRequest? {
7 => Some(Browse) 7 => Some(Browse)
8 => Some(Logout) 8 => Some(Logout)
9 => Some(SetWallpaper(c_host_req_int())) 9 => Some(SetWallpaper(c_host_req_int()))
10 => Some(SetSessionSetting(c_host_req_int(), false))
11 => Some(SetSessionSetting(c_host_req_int(), true))
_ => None _ => None
} }
} }
+13 -3
View File
@@ -47,16 +47,17 @@ static Inst insts[MAX_INST];
enum { enum {
K_OTHER, K_TOKENS, K_CLOCK, K_APPS, K_LAUNCH, K_WINDOWS, K_FOCUS, K_LAYOUTS, K_LAYOUT_CUR, K_SET_LAYOUT, K_OTHER, K_TOKENS, K_CLOCK, K_APPS, K_LAUNCH, K_WINDOWS, K_FOCUS, K_LAYOUTS, K_LAYOUT_CUR, K_SET_LAYOUT,
K_INSPECT_IS_ON, K_INSPECT_SET, K_MOD_AVAILABLE, K_MOD_LOADED, K_MOD_LOAD, K_MOD_UNLOAD, K_MOD_BROWSE, K_INSPECT_IS_ON, K_INSPECT_SET, K_MOD_AVAILABLE, K_MOD_LOADED, K_MOD_LOAD, K_MOD_UNLOAD, K_MOD_BROWSE,
K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT, K_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT, K_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER,
K_SESSION_SETTINGS, K_SESSION_IS_ON, K_SESSION_SET
}; };
typedef struct Env { Inst *inst; int kind; } Env; typedef struct Env { Inst *inst; int kind; } Env;
/* ---- host data the shell publishes before calling a guest ---- /* ---- host data the shell publishes before calling a guest ----
* A table is [u32 rows] then rows of fields, each field a LE i32 ('i') or a u32 byte length + UTF-8 ('s'). */ * A table is [u32 rows] then rows of fields, each field a LE i32 ('i') or a u32 byte length + UTF-8 ('s'). */
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_N }; enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SESSION_SETTINGS, T_N };
typedef struct { uint8_t *data; size_t len; } Blob; typedef struct { uint8_t *data; size_t len; } Blob;
static Blob tables[T_N]; static Blob tables[T_N];
static int32_t host_ints[4]; /* 0 layout mode, 1 inspector on, 2 current wallpaper */ static int32_t host_ints[4]; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i) */
/* ---- requests a guest made of the host (launch, focus, ...) ; drained by the shell after each call ---- */ /* ---- 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; typedef struct { int kind; int32_t n; char *s; } Req;
@@ -265,6 +266,7 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_WINDOWS: build_list(in, T_WINDOWS, "isii", a0); break; case K_WINDOWS: build_list(in, T_WINDOWS, "isii", a0); break;
case K_LAYOUTS: build_list(in, T_LAYOUTS, "s", a0); break; case K_LAYOUTS: build_list(in, T_LAYOUTS, "s", a0); break;
case K_WALLPAPERS: build_list(in, T_WALLPAPERS, "s", a0); break; case K_WALLPAPERS: build_list(in, T_WALLPAPERS, "s", a0); break;
case K_SESSION_SETTINGS: build_list(in, T_SESSION_SETTINGS, "s", a0); break;
case K_MOD_AVAILABLE: build_list(in, T_MODULES, "sssi", a0); break; case K_MOD_AVAILABLE: build_list(in, T_MODULES, "sssi", a0); break;
case K_MOD_LOADED: build_list(in, T_INSTANCES, "sss", a0); break; case K_MOD_LOADED: build_list(in, T_INSTANCES, "sss", a0); break;
case K_LAYOUT_CUR: case K_LAYOUT_CUR:
@@ -273,6 +275,10 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_WALLPAPER_CUR: case K_WALLPAPER_CUR:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[2]); if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[2]);
break; break;
case K_SESSION_IS_ON:
if (results->size >= 1)
results->data[0] = (wasm_val_t)WASM_I32_VAL(a0 >= 0 && a0 < 32 ? (int32_t)(((uint32_t)host_ints[3] >> a0) & 1u) : 0);
break;
case K_INSPECT_IS_ON: case K_INSPECT_IS_ON:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[1]); if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[1]);
break; break;
@@ -280,6 +286,7 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_FOCUS: push_req(2, a0, NULL); break; case K_FOCUS: push_req(2, a0, NULL); break;
case K_LOGOUT: push_req(8, 0, NULL); break; case K_LOGOUT: push_req(8, 0, NULL); break;
case K_SET_WALLPAPER: push_req(9, a0, NULL); break; case K_SET_WALLPAPER: push_req(9, a0, NULL); break;
case K_SESSION_SET: push_req(a1 ? 11 : 10, a0, NULL); break; /* 10 off, 11 on */
case K_INSPECT_SET: push_req(4, a0, NULL); break; case K_INSPECT_SET: push_req(4, a0, NULL); break;
case K_MOD_BROWSE: push_req(7, 0, 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_LOAD: { char *s = guest_str(in, a0, a1); push_req(5, 0, s); free(s); break; }
@@ -411,6 +418,9 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "wallpapers")) return K_WALLPAPERS; if (!strcmp(iface, "wallpaper") && !strcmp(fn, "wallpapers")) return K_WALLPAPERS;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-wallpaper")) return K_WALLPAPER_CUR; if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-wallpaper")) return K_WALLPAPER_CUR;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-wallpaper")) return K_SET_WALLPAPER; if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-wallpaper")) return K_SET_WALLPAPER;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "settings")) return K_SESSION_SETTINGS;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "is-on")) return K_SESSION_IS_ON;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "set-setting")) return K_SESSION_SET;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "layout-modes")) return K_LAYOUTS; if (!strcmp(iface, "layout-control") && !strcmp(fn, "layout-modes")) return K_LAYOUTS;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "current-layout")) return K_LAYOUT_CUR; if (!strcmp(iface, "layout-control") && !strcmp(fn, "current-layout")) return K_LAYOUT_CUR;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "set-layout")) return K_SET_LAYOUT; if (!strcmp(iface, "layout-control") && !strcmp(fn, "set-layout")) return K_SET_LAYOUT;
+7
View File
@@ -183,6 +183,10 @@ impl chandra::host::plasmoids::Host for State {
self.pl().shared.borrow_mut().wallpaper = current; self.pl().shared.borrow_mut().wallpaper = current;
} }
fn publish_session_settings(&mut self, on: u32) {
self.pl().shared.borrow_mut().session_settings = on;
}
fn publish_system(&mut self, s: chandra::host::plasmoids::SystemSnapshot) { fn publish_system(&mut self, s: chandra::host::plasmoids::SystemSnapshot) {
use plasmoid::ph::chandra::desktop::system::Snapshot; use plasmoid::ph::chandra::desktop::system::Snapshot;
self.pl().shared.borrow_mut().system = Some(Snapshot { self.pl().shared.borrow_mut().system = Some(Snapshot {
@@ -217,6 +221,9 @@ impl chandra::host::plasmoids::Host for State {
Req::Browse => R::Browse, Req::Browse => R::Browse,
Req::Logout => R::Logout, Req::Logout => R::Logout,
Req::SetWallpaper(n) => R::SetWallpaper(n), Req::SetWallpaper(n) => R::SetWallpaper(n),
Req::SetSessionSetting(index, on) => {
R::SetSessionSetting(chandra::host::plasmoids::SettingChange { index, on })
}
}) })
} }
+52 -1
View File
@@ -36,6 +36,7 @@ pub enum Req {
Browse, Browse,
Logout, Logout,
SetWallpaper(i32), SetWallpaper(i32),
SetSessionSetting(i32, bool),
} }
pub const T_APPS: usize = 0; pub const T_APPS: usize = 0;
@@ -44,13 +45,16 @@ pub const T_LAYOUTS: usize = 2;
pub const T_MODULES: usize = 3; pub const T_MODULES: usize = 3;
pub const T_INSTANCES: usize = 4; pub const T_INSTANCES: usize = 4;
pub const T_WALLPAPERS: usize = 5; pub const T_WALLPAPERS: usize = 5;
pub const T_SESSION_SETTINGS: usize = 6;
/// Host data every module reads from, shared by all loaded modules. /// Host data every module reads from, shared by all loaded modules.
#[derive(Default)] #[derive(Default)]
pub struct Shared { pub struct Shared {
pub tables: [Vec<u8>; 6], pub tables: [Vec<u8>; 7],
pub layout_mode: i32, pub layout_mode: i32,
pub wallpaper: i32, pub wallpaper: i32,
/// Which session settings are on: bit i for row i of the session settings table.
pub session_settings: u32,
pub inspector_on: bool, pub inspector_on: bool,
pub system: Option<d::system::Snapshot>, pub system: Option<d::system::Snapshot>,
/// (id, title, app id, focused) /// (id, title, app id, focused)
@@ -288,6 +292,18 @@ impl d::wallpaper::Host for PState {
} }
} }
impl d::session_settings::Host for PState {
fn settings(&mut self) -> Vec<String> {
self.rows(T_SESSION_SETTINGS, "s").iter().map(|r| s(&r[0])).collect()
}
fn is_on(&mut self, index: u32) -> bool {
index < 32 && (self.shared.borrow().session_settings >> index) & 1 == 1
}
fn set_setting(&mut self, index: u32, on: bool) {
self.shared.borrow_mut().requests.push_back(Req::SetSessionSetting(index as i32, on));
}
}
impl d::system::Host for PState { impl d::system::Host for PState {
fn read(&mut self) -> d::system::Snapshot { fn read(&mut self) -> d::system::Snapshot {
self.shared.borrow().system.clone().unwrap_or(d::system::Snapshot { self.shared.borrow().system.clone().unwrap_or(d::system::Snapshot {
@@ -611,4 +627,39 @@ mod tests {
assert!(rt.shared.borrow().requests.is_empty()); assert!(rt.shared.borrow().requests.is_empty());
rt.unload(h); rt.unload(h);
} }
#[test]
fn session_settings_module_shows_switches_and_requests_a_flip() {
let mut rt = runtime();
let l = rt.load(&module("session-settings")).expect("session-settings loads");
assert!(l.imports.contains(&"session-settings".to_string()));
let h = l.handle;
let names = ["Reopen windows at login", "Remember window positions"];
let mut t = (names.len() as u32).to_le_bytes().to_vec();
for n in names {
t.extend((n.len() as u32).to_le_bytes());
t.extend(n.as_bytes());
}
rt.shared.borrow_mut().tables[T_SESSION_SETTINGS] = t;
rt.shared.borrow_mut().session_settings = 0b01; // reopen on, remember off
assert!(texts(&rt.render(h, Size { w: 86, h: 34 })).contains(&"Session".to_string()));
// A click opens the list of every setting; nothing is requested yet.
assert!(rt.popup(h).is_none());
assert!(rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })));
let p = rt.popup(h).expect("popup open");
for n in names {
assert!(texts(&p.ops).contains(&n.to_string()), "{n} listed");
}
assert!(rt.shared.borrow().requests.is_empty());
// First row is on: a click asks to turn it off. Second row is off: a click asks for on.
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 5 })));
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(0, false))));
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 32 + 5 })));
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(1, true))));
// The list stays open; Escape closes it without another request.
assert!(rt.popup(h).is_some());
assert!(rt.on_event(h, true, InputEvent::KeyDown("Escape".to_string())));
assert!(rt.popup(h).is_none());
assert!(rt.shared.borrow().requests.is_empty());
rt.unload(h);
}
} }
@@ -0,0 +1,2 @@
Session settings: how the login session starts and what it remembers. The shell keeps them in
state.edn; a module with this capability lists them as on/off switches and flips them.
@@ -0,0 +1,33 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportSettings(p0 : Int) = "chandra:desktop/session-settings@0.1.0" "settings"
///|
fn wasmImportIsOn(p0 : Int) -> Int = "chandra:desktop/session-settings@0.1.0" "is-on"
///|
fn wasmImportSetSetting(p0 : Int, p1 : Int) = "chandra:desktop/session-settings@0.1.0" "set-setting"
///|
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_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_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)
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,39 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Display names, indexed by setting.
pub fn settings() -> Array[String] {
let return_area = mbt_ffi_malloc(8)
wasmImportSettings(return_area);
let array : Array[String] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 8)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
array.push(result)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Whether setting `index` is on (false for an out-of-range index).
pub fn is_on(index : UInt) -> Bool {
let result : Int = wasmImportIsOn((index).reinterpret_as_int());
let ret = (result != 0)
return ret
}
///|
/// Turn setting `index` on or off (out-of-range indices are ignored). The choice is remembered.
pub fn set_setting(index : UInt, on : Bool) -> Unit {
wasmImportSetSetting((index).reinterpret_as_int(), (if on { 1 } else { 0 }));
}
+34 -31
View File
@@ -27,6 +27,9 @@ fn wasmImportPublishState(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0"
///| ///|
fn wasmImportPublishWallpaper(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-wallpaper" fn wasmImportPublishWallpaper(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-wallpaper"
///|
fn wasmImportPublishSessionSettings(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-session-settings"
///| ///|
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" 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"
@@ -48,35 +51,14 @@ fn wasmImportPickerStart() -> Int = "chandra:host/plasmoids@0.1.0" "picker-start
///| ///|
fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll" fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll"
///|
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)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
#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 = extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
#|(func (param i32) (result i64) local.get 0 i64.load) #|(func (param i32) (result i64) local.get 0 i64.load)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///| ///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) = extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store) #|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
@@ -86,8 +68,33 @@ extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load) #|(func (param i32) (result i32) local.get 0 i32.load)
///| ///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int = #owned(str)
#|(func (param i32) (result i32) local.get 0 i32.load8_u) extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
#owned(bytes)
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
#|(func (param i32) (result i32) local.get 0)
///| ///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String = extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
@@ -96,7 +103,3 @@ extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#| local.get 1 call $moonbit.init_array16 #| local.get 1 call $moonbit.init_array16
#| local.get 0) #| 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)
@@ -45,6 +45,11 @@ fn wasmImportPublishWallpaper(p0 : Int) -> Unit {
abort("wasm-only host import") abort("wasm-only host import")
} }
///|
fn wasmImportPublishSessionSettings(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 { 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") abort("wasm-only host import")
@@ -21,6 +21,8 @@ pub fn picker_start() -> Bool
pub fn popup(UInt32) -> PopupSurface? pub fn popup(UInt32) -> PopupSurface?
pub fn publish_session_settings(UInt32) -> Unit
pub fn publish_state(Int32, Bool) -> Unit pub fn publish_state(Int32, Bool) -> Unit
pub fn publish_system(SystemSnapshot) -> Unit pub fn publish_system(SystemSnapshot) -> Unit
@@ -73,6 +75,12 @@ pub(all) enum Request {
Browse Browse
Logout Logout
SetWallpaper(Int32) SetWallpaper(Int32)
SetSessionSetting(SettingChange)
}
pub(all) struct SettingChange {
index : Int32
on : Bool
} }
pub(all) struct SystemSnapshot { pub(all) struct SystemSnapshot {
+18 -1
View File
@@ -18,6 +18,11 @@ pub(all) struct WindowEntry {
id : UInt64; title : String; app_id : String; focused : Bool id : UInt64; title : String; app_id : String; focused : Bool
} }
///| ///|
/// A module turning a session setting on or off.
pub(all) struct SettingChange {
index : Int; on : Bool
}
///|
/// ---- what modules asked of the host ---- /// ---- what modules asked of the host ----
pub(all) enum Request { pub(all) enum Request {
Launch(String) Launch(String)
@@ -29,6 +34,7 @@ pub(all) enum Request {
Browse Browse
Logout Logout
SetWallpaper(Int) SetWallpaper(Int)
SetSessionSetting(SettingChange)
} }
///| ///|
/// A native file-chooser dialog (zenity on the host session) for "Add widget". /// A native file-chooser dialog (zenity on the host session) for "Add widget".
@@ -301,7 +307,7 @@ pub fn on_event(handle : UInt, on_popup : Bool, event : @types.InputEvent) -> Bo
/// Row tables, as built by compositor/wasm: a LE u32 row count, then per row each field as a LE /// Row tables, as built by compositor/wasm: a LE u32 row count, then per row each field as a LE
/// i32 ('i') or a LE u32 byte length + UTF-8 ('s'). `which`: 0 apps (sssss: id name comment /// i32 ('i') or a LE u32 byte length + UTF-8 ('s'). `which`: 0 apps (sssss: id name comment
/// category glyph), 1 windows (isii: id title focused minimized), 2 layouts (s), 3 modules /// category glyph), 1 windows (isii: id title focused minimized), 2 layouts (s), 3 modules
/// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s). /// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s), 6 session settings (s).
pub fn publish_table(which : UInt, rows : FixedArray[Byte]) -> Unit { pub fn publish_table(which : UInt, rows : FixedArray[Byte]) -> Unit {
let ptr = mbt_ffi_bytes2ptr(rows) let ptr = mbt_ffi_bytes2ptr(rows)
@@ -323,6 +329,13 @@ pub fn publish_wallpaper(current : Int) -> Unit {
wasmImportPublishWallpaper(current); wasmImportPublishWallpaper(current);
}
///|
/// Which session settings are on: bit i for row i of the session settings table.
pub fn publish_session_settings(on : UInt) -> Unit {
wasmImportPublishSessionSettings((on).reinterpret_as_int());
} }
///| ///|
pub fn publish_system(s : SystemSnapshot) -> Unit { pub fn publish_system(s : SystemSnapshot) -> Unit {
@@ -412,6 +425,10 @@ pub fn next_request() -> Request? {
Request::SetWallpaper(mbt_ffi_load32((return_area) + 8)) Request::SetWallpaper(mbt_ffi_load32((return_area) + 8))
} }
9 => {
Request::SetSessionSetting(SettingChange::{index : mbt_ffi_load32((return_area) + 8), on : (mbt_ffi_load8_u((return_area) + 12) != 0)})
}
_ => panic() _ => panic()
} }
+1
View File
@@ -10,3 +10,4 @@ inspector inspector-widget
module-manager module-manager-widget module-manager module-manager-widget
logout logout-widget logout logout-widget
wallpaper wallpaper-widget wallpaper wallpaper-widget
session-settings session-settings-widget
+11
View File
@@ -126,3 +126,14 @@ interface wallpaper {
/// Show wallpaper `index` (out-of-range indices are ignored). The choice is remembered. /// Show wallpaper `index` (out-of-range indices are ignored). The choice is remembered.
set-wallpaper: func(index: u32); set-wallpaper: func(index: u32);
} }
/// Session settings: how the login session starts and what it remembers. The shell keeps them in
/// state.edn; a module with this capability lists them as on/off switches and flips them.
interface session-settings {
/// Display names, indexed by setting.
settings: func() -> list<string>;
/// Whether setting `index` is on (false for an out-of-range index).
is-on: func(index: u32) -> bool;
/// Turn setting `index` on or off (out-of-range indices are ignored). The choice is remembered.
set-setting: func(index: u32, on: bool);
}
+10 -1
View File
@@ -40,12 +40,14 @@ interface plasmoids {
/// Row tables, as built by compositor/wasm: a LE u32 row count, then per row each field as a LE /// Row tables, as built by compositor/wasm: a LE u32 row count, then per row each field as a LE
/// i32 ('i') or a LE u32 byte length + UTF-8 ('s'). `which`: 0 apps (sssss: id name comment /// i32 ('i') or a LE u32 byte length + UTF-8 ('s'). `which`: 0 apps (sssss: id name comment
/// category glyph), 1 windows (isii: id title focused minimized), 2 layouts (s), 3 modules /// category glyph), 1 windows (isii: id title focused minimized), 2 layouts (s), 3 modules
/// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s). /// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s), 6 session settings (s).
publish-table: func(which: u32, rows: list<u8>); publish-table: func(which: u32, rows: list<u8>);
/// Layout mode (0 tiling, 1 monocle, 2 floating) and whether the Interface Explorer is on. /// Layout mode (0 tiling, 1 monocle, 2 floating) and whether the Interface Explorer is on.
publish-state: func(layout-mode: s32, inspector-on: bool); publish-state: func(layout-mode: s32, inspector-on: bool);
/// The wallpaper on the desktop now (an index into the wallpapers table). /// The wallpaper on the desktop now (an index into the wallpapers table).
publish-wallpaper: func(current: s32); publish-wallpaper: func(current: s32);
/// Which session settings are on: bit i for row i of the session settings table.
publish-session-settings: func(on: u32);
record system-snapshot { record system-snapshot {
cpu-permille: u32, cpu-permille: u32,
@@ -68,6 +70,12 @@ interface plasmoids {
} }
publish-windows: func(wins: list<window-entry>); publish-windows: func(wins: list<window-entry>);
/// A module turning a session setting on or off.
record setting-change {
index: s32,
on: bool,
}
// ---- what modules asked of the host ---- // ---- what modules asked of the host ----
variant request { variant request {
@@ -80,6 +88,7 @@ interface plasmoids {
browse, browse,
logout, logout,
set-wallpaper(s32), set-wallpaper(s32),
set-session-setting(setting-change),
} }
/// The next pending request, oldest first. /// The next pending request, oldest first.
next-request: func() -> option<request>; next-request: func() -> option<request>;
+7
View File
@@ -75,6 +75,7 @@ world plasmoid-host {
import system; import system;
import session; import session;
import wallpaper; import wallpaper;
import session-settings;
export plasmoid; export plasmoid;
} }
@@ -89,3 +90,9 @@ world wallpaper-widget {
include widget; include widget;
import wallpaper; import wallpaper;
} }
/// Session settings switches.
world session-settings-widget {
include widget;
import session-settings;
}
+1
View File
@@ -0,0 +1 @@
Session settings switches.
@@ -0,0 +1,2 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
+2
View File
@@ -0,0 +1,2 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
+1
View File
@@ -0,0 +1 @@
warnings = "-44"