Screenshot module after Spectacle (Super+Shift+S), with a screen recorder
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
- Super+Shift+S (or Super+Shift+Print) freezes the screen under a selection overlay, like Spectacle's Rectangular Region: drag a rectangle (size readout under it, magnifier while drawing), drag inside to move it, drag its handles to resize, or click a window to select it. Enter or a double-click takes it, Escape or right-click cancels; F full screen, W active window, arrows nudge (Shift+arrows resize). Print takes the full screen, Super+Print the active window, Super+Ctrl+Print the window under the pointer. - Saved as ~/Pictures/Screenshots/Screenshot_YYYYMMDD_HHMMSS.png (XDG_PICTURES_DIR honoured), put on the clipboard as image/png (compositor-owned wl_data selection, written to the paste pipe without blocking), and confirmed by a notification with a thumbnail. - Screen recording: Super+Shift+R picks a region on the same overlay, Super+Alt+R the screen, Super+Ctrl+R a window; the same shortcut or the REC pill (top centre) stops. Raw frames (<= 30 fps, wall-clock stamped) stream into ffmpeg over a unix socket; it writes H.264 MP4 to ~/Videos/Screencasts/Screencast_*.mp4. The pointer is drawn in unless switched off. - renderer: encode_png_compressed (per-row filters + LZ77/fixed-Huffman deflate): a 1280x720 desktop is ~90 KB instead of 3.7 MB. - New 'screenshot' capability and 'screenshot' panel module (in the default panel): Spectacle's modes and the recording modes with their shortcuts, and a pointer switch; the button becomes Stop while recording. Served by both hosts (wasmer stub request 12 / host int 4; host-wasm publish-screenshot and a screenshot request). Panel requests wait for a frame without the module's popup. - sys: pwrite with a negative offset is a non-blocking write (pipes, sockets), SIGPIPE ignored. - Tests: native overlay, shortcuts, window pick, module, recording (with ffmpeg); host-wasm module test; renderer compression test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjMGSLc5tHuzjsxGVa
This commit is contained in:
45 files changed
+3177
-57
No files matched your search
@@ -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 wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportRenderPostReturn(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 wasmExportInfo() -> Int {
|
||||
@plasmoid.wasmExportInfo()
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopup() -> Int {
|
||||
@plasmoid.wasmExportPopup()
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportPopupPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
||||
@plasmoid.wasmExportRender(p0, p1)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportInfoPostReturn(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_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
|
||||
///|
|
||||
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)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_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)
|
||||
|
||||
///|
|
||||
#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)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import {
|
||||
"chandra/desktop/interface/chandra/desktop/types" @types,
|
||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
||||
"chandra/desktop/interface/chandra/desktop/screenshot" @shot,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
|
||||
warnings = "-44"
|
||||
@@ -0,0 +1,260 @@
|
||||
///| Implementation of `chandra:desktop/plasmoid` for the screenshot launcher, after KDE Spectacle.
|
||||
/// The panel button opens a popup with Spectacle's capture modes (Rectangular Region, Full Screen,
|
||||
/// Active Window, Window Under Cursor), its recording modes (region, screen, window) and a switch
|
||||
/// for showing the pointer in recordings, each with its keyboard shortcut. Picking a mode closes
|
||||
/// the popup and asks the compositor (`screenshot` capability), which captures once the popup is
|
||||
/// gone. While a recording runs the button turns red and a click on it stops the recording.
|
||||
/// Up/Down move the highlight, Enter picks, Escape or a click elsewhere closes.
|
||||
|
||||
///| One popup row: a heading, an action (the request code the compositor knows), or the switch.
|
||||
priv enum Row {
|
||||
Heading(String)
|
||||
Action(String, String, Int)
|
||||
PointerSwitch
|
||||
}
|
||||
|
||||
///|
|
||||
let rows : Array[Row] = [
|
||||
Heading("Screenshot"),
|
||||
Action("Rectangular Region", "Meta+Shift+S", 0),
|
||||
Action("Full Screen", "Print", 1),
|
||||
Action("Active Window", "Meta+Print", 2),
|
||||
Action("Window Under Cursor", "Meta+Ctrl+Print", 3),
|
||||
Heading("Record"),
|
||||
Action("Record a Region", "Meta+Shift+R", 10),
|
||||
Action("Record the Screen", "Meta+Alt+R", 11),
|
||||
Action("Record a Window", "Meta+Ctrl+R", 12),
|
||||
PointerSwitch,
|
||||
]
|
||||
|
||||
///| Popup geometry.
|
||||
let popup_w : Int = 300
|
||||
|
||||
///|
|
||||
let row_h : Int = 30
|
||||
|
||||
///|
|
||||
let margin : Int = 6
|
||||
|
||||
///|
|
||||
let open_ : Ref[Bool] = { val: false }
|
||||
|
||||
///| Highlighted row (-1: none).
|
||||
let hover : Ref[Int] = { val: -1 }
|
||||
|
||||
///|
|
||||
fn popup_h() -> Int {
|
||||
margin * 2 + rows.length() * row_h
|
||||
}
|
||||
|
||||
///| Whether row `i` can be picked.
|
||||
fn pickable(i : Int) -> Bool {
|
||||
i >= 0 && i < rows.length() && !(rows[i] is Heading(_))
|
||||
}
|
||||
|
||||
///| 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 pickable(i) { i } else { -1 }
|
||||
}
|
||||
|
||||
///|
|
||||
fn close() -> Unit {
|
||||
open_.val = false
|
||||
hover.val = -1
|
||||
}
|
||||
|
||||
///| Carry out row `i`: an action closes the popup first so it isn't in the picture.
|
||||
fn pick(i : Int) -> Unit {
|
||||
if !pickable(i) {
|
||||
return
|
||||
}
|
||||
match rows[i] {
|
||||
Action(_, _, code) => {
|
||||
close()
|
||||
if code < 10 {
|
||||
@shot.take(code.reinterpret_as_uint())
|
||||
} else {
|
||||
@shot.start_recording((code - 10).reinterpret_as_uint())
|
||||
}
|
||||
}
|
||||
PointerSwitch => @shot.set_records_pointer(!@shot.records_pointer())
|
||||
Heading(_) => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| The next pickable row from `i` in direction `d`, or `i` when there is none.
|
||||
fn step(i : Int, d : Int) -> Int {
|
||||
let mut j = i + d
|
||||
while j >= 0 && j < rows.length() {
|
||||
if pickable(j) {
|
||||
return j
|
||||
}
|
||||
j = j + d
|
||||
}
|
||||
i
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn info() -> PlasmoidInfo {
|
||||
{
|
||||
id: "org.chandra.screenshot",
|
||||
name: "Screenshot",
|
||||
preferred: { w: 110, h: 34 },
|
||||
min_width: 34,
|
||||
stretch: false,
|
||||
}
|
||||
}
|
||||
|
||||
///| A small camera: body, lens and the bump on top.
|
||||
fn camera(cx : Int, cy : Int, c : @types.Color) -> Array[@types.DrawOp] {
|
||||
[
|
||||
@ui.stroke_rect(@ui.rect(cx - 9, cy - 5, 18, 12), c, width=1, radius=2),
|
||||
@ui.fill_rect(@ui.rect(cx - 4, cy - 8, 8, 3), c, radius=1),
|
||||
@ui.circle(cx, cy + 1, 3, c, filled=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 recording = @shot.is_recording()
|
||||
let red = @ui.color(235, 64, 52, 255)
|
||||
let bg = if recording { red } else if open_.val { t.palette.accent } else { t.palette.surface_hover }
|
||||
let fg = if recording {
|
||||
@ui.color(255, 255, 255, 255)
|
||||
} else if open_.val {
|
||||
t.palette.accent_foreground
|
||||
} else {
|
||||
t.palette.foreground
|
||||
}
|
||||
let ops = [@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r)]
|
||||
let gy = h / 2
|
||||
if recording {
|
||||
ops.push(@ui.fill_rect(@ui.rect(12, gy - 5, 10, 10), fg, radius=2)) // a stop square
|
||||
if w >= 70 {
|
||||
ops.push(@ui.text(30, gy, "Stop", fs - 2, fg))
|
||||
}
|
||||
} else {
|
||||
ops.append(camera(17, gy, fg))
|
||||
if w >= 90 {
|
||||
ops.push(@ui.text(32, gy, "Screenshot", 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 p = t.palette
|
||||
let ops : Array[@types.DrawOp] = [
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), p.surface_popup, radius=r),
|
||||
@ui.stroke_rect(@ui.rect(0, 0, w, h), p.border, width=1, radius=r),
|
||||
]
|
||||
for i = 0; i < rows.length(); i = i + 1 {
|
||||
let y = margin + i * row_h
|
||||
let mid = y + (row_h - 2) / 2
|
||||
if i == hover.val {
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), p.surface_hover, radius=r))
|
||||
}
|
||||
match rows[i] {
|
||||
Heading(s) => ops.push(@ui.text(margin + 8, mid + 2, s, fs - 3, p.foreground_muted, bold=true))
|
||||
Action(label, keys, _) => {
|
||||
ops.push(@ui.text(margin + 18, mid, label, fs - 1, p.foreground))
|
||||
ops.push(@ui.text(w - margin - 10, mid, keys, fs - 3, p.foreground_muted, align=RIGHT))
|
||||
}
|
||||
PointerSwitch => {
|
||||
ops.push(@ui.text(margin + 18, mid, "Show pointer in recordings", fs - 1, p.foreground))
|
||||
let sw = 34
|
||||
let sh = 18
|
||||
let sx = w - margin - 10 - sw
|
||||
let sy = mid - sh / 2
|
||||
let knob = sh / 2 - 3
|
||||
if @shot.records_pointer() {
|
||||
ops.push(@ui.fill_rect(@ui.rect(sx, sy, sw, sh), p.accent, radius=sh / 2))
|
||||
ops.push(@ui.circle(sx + sw - sh / 2, mid, knob, p.accent_foreground))
|
||||
} else {
|
||||
ops.push(@ui.stroke_rect(@ui.rect(sx, sy, sw, sh), p.foreground_muted, width=1, radius=sh / 2))
|
||||
ops.push(@ui.circle(sx + sh / 2, mid, knob, p.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 @shot.is_recording() {
|
||||
close()
|
||||
@shot.stop_recording()
|
||||
} else if open_.val {
|
||||
close()
|
||||
} else {
|
||||
open_.val = true
|
||||
hover.val = step(-1, 1)
|
||||
}
|
||||
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 {
|
||||
hover.val = i
|
||||
pick(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" {
|
||||
pick(hover.val)
|
||||
true
|
||||
} else if k == "ArrowDown" || k == "Down" {
|
||||
hover.val = step(hover.val, 1)
|
||||
true
|
||||
} else if k == "ArrowUp" || k == "Up" {
|
||||
hover.val = step(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
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
"chandra/desktop/components/screenshot/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"
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
Reference in new issue
Block a user