Commitf6eaeffaRecorded5 Dec 2026Repositorysigil-ui
Address Wayland activation API and fixture review
Changed
README.md | 7 +++++++
native/window-wayland-services.inc | 3 ++-
scripts/check-configure-peer.sgl | 24 ++++++++++++++++++++----
src/sigil/ui/wayland.sgl | 11 ++++++++---
test/wayland/configure-peer.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
test/wayland/services-native.c | 14 ++++++++++++--
6 files changed, 117 insertions(+), 25 deletions(-)Diff
README.mdmodified
@@ -222,6 +222,13 @@ before allowing a buffer. `wayland-decoration-mode` reports the compositor's
222
chosen `server-side`/`client-side` mode, or false when not negotiated. Ordinary 223
opens do not bind xdg-decoration. The owned `test/wayland/decoration.sgl` covers 224
server mode, unchanged defaults, protocol absence and preference validation.+225
+226
`(wayland-activate! surface (getenv "XDG_ACTIVATION_TOKEN"))` submits a+227
compositor-issued token for a live toplevel. It returns `#t` when the request+228
is submitted. The compositor decides whether to focus the window. An omitted,+229
`#f`, empty, or invalid token returns `#f`, as does an unavailable activation+230
protocol. Tokens must be valid UTF-8, at most 1024 bytes, and contain no NUL.+231
232
`wayland-set-fullscreen!` sends an asynchronous xdg-toplevel request. Its true 233
result means sent; `wayland-surface-fullscreen?` and `(fullscreen on?)` events 234
change only after the compositor's configure. Child/layer roles refuse thenative/window-wayland-services.incmodified
@@ -239,7 +239,8 @@ static Value native_wl_activate(SigilVM *vm, int argc, Value *args)
239
240
size_t length = ((SigilString *)sigil_as_ptr(args[1]))->byte_length; 241
const char *token = sigil_string_bytes(args[1]);−242
if (!length || length > 1024 || memchr(token, 0, length)) return SIGIL_FALSE;+242
if (!length || length > 1024 || memchr(token, 0, length) ||+243
!clipboard_utf8((const uint8_t *)token, length)) return SIGIL_FALSE; 244
if (!window_service_live(w) || w->parent || !w->toplevel || !w->surface || !w->activation || 245
w->connection_depth) return SIGIL_FALSE; 246
scripts/check-configure-peer.sglmodified
@@ -1,6 +1,7 @@
1
#!/usr/bin/env sigil 2
;; Usage: HEADERS ARCHIVE EVIDENCE [PRIOR-WAYLAND-C]. The optional prior 3
;; source must fail early-close, close/configure and expired-pending checks.+4
;; Run the bytecode suite first to build the wrapper's font and FFI dependencies. 5
(import (sigil shell prelude)) 6
(define root (realpath (path (script-dir) ".."))) 7
(define headers (arg 1))@@ -16,12 +17,25 @@
17
(str "-I" headers) (str "-I" (path root "native")) 18
(str "-I" (path root "native/wayland")) (str "-I" (path root "native/wayland/include")))) 19
(define fixture (path root "test/wayland/configure-peer.c"))+20
(define sources (map (lambda (file) (path root "native" file))+21
'("raster.c" "png.c" "surface-unavailable.c")))+22
(define font-archives+23
(map (lambda (file) (path root "build/dev/native" file))+24
'("libsigil-font.a" "libsigil-ffi.a")))+25
(unless (every file? font-archives)+26
(error "Run sigil test --backend bytecode to build the font and FFI archives"))+27
(define source-root (path root "src"))+28
(define wayland-module (path source-root "sigil/ui/wayland.sgl"))+29
(define font-paths+30
(map (lambda (name) (path root ".sigil/deps/sigil" name "src"))+31
'("sigil-font" "sigil-freetype" "sigil-fontconfig" "sigil-ffi"))) 32
(define fixed (path evidence "configure-peer"))−20
($ ,compiler ,@flags ,fixture ,archive -lm -ldl -lpthread -o ,fixed+33
($ ,compiler ,@flags ,fixture ,@sources ,@font-archives ,archive -lm -ldl -lpthread -o ,fixed 34
out: ,(path evidence "configure-compile.log") err: 'merge timeout: 40)−22
(each case '("early-close" "close-configure" "traffic" "expired-pending" "activation")+35
(each case '("early-close" "close-configure" "traffic" "expired-pending" "activation" "activation-removed") 36
(define log (path evidence (str "configure-" case ".log")))−24
($ ,fixed ,case out: ,log err: 'merge timeout: 15)+37
($ ,fixed ,case ,wayland-module ,source-root ,@font-paths ,@(library-paths)+38
out: ,log err: 'merge timeout: 15) 39
(display (read-text log)) 40
(unless (contains? (read-text log) (str "PASS: configure peer " case)) 41
(error "Configure control did not report its intended result" case)))@@ -31,7 +45,9 @@
45
(define source (path evidence "configure-peer-prior.c")) 46
(write-text source (string-replace text "../../native/wayland.c" (realpath prior-source))) 47
(define prior (path evidence "configure-peer-prior"))−34
($ ,compiler ,@flags ,(str "-I" (path root "test/wayland")) ,source ,archive -lm -ldl -lpthread -o ,prior+48
($ ,compiler ,@flags ,(str "-I" (path root "test/wayland"))+49
-include xdg-activation-v1-client-protocol.h ,source+50
,@sources ,@font-archives ,archive -lm -ldl -lpthread -o ,prior 51
out: ,(path evidence "configure-prior-compile.log") err: 'merge timeout: 40) 52
(each case '("early-close" "close-configure" "expired-pending") 53
(define log (path evidence (str "configure-baseline-" case ".log")))src/sigil/ui/wayland.sglmodified
@@ -181,9 +181,14 @@
181
(%wl-title! (wayland-surface-handle surface) title)) 182
183
;;; Submit a compositor-issued token on this toplevel's connection.−184
;;; Tokens may contain up to 1024 bytes and may not contain NUL.−185
;;; Return true if submitted. The compositor decides whether to focus the window.−186
(define (wayland-activate! surface token)+184
;;; Return #t if submitted. The compositor decides whether to focus the window.+185
;;; A missing or #f token returns #f, including when+186
;;; (getenv "XDG_ACTIVATION_TOKEN") returns #f. Empty tokens, invalid UTF-8,+187
;;; embedded NUL, and tokens over 1024 bytes also return #f.+188
;;; Return #f for a subsurface, a layer surface, a closed window, a missing+189
;;; activation protocol, a call from another thread or during dispatch,+190
;;; or a compositor connection failure.+191
(define (wayland-activate! surface (opts: (token #f))) 192
(%wl-activate! (wayland-surface-handle surface) token)) 193
194
;; Portable host services keep legacy Wayland behavior above unchanged.test/wayland/configure-peer.cmodified
@@ -12,10 +12,13 @@ static int count_dispatch_polls, dispatch_polls;
12
static int observed_poll(struct pollfd *fds, nfds_t count, int timeout); 13
#define poll observed_poll 14
#include "../../native/wayland.c"−15
#include "xdg-activation-v1-client-protocol.h" 15
#include "standalone-protocols.h" 16
#undef poll 17
+18
void sigil__init_sigil_ui_native(SigilVM *vm);+19
void sigil__init_sigil_ffi_module(SigilVM *vm);+20
void sigil__init_sigil_font_native(SigilVM *vm);+21
22
/* Observe real polling without changing its result, timeout or clock. */ 23
static int observed_poll(struct pollfd *fds, nfds_t count, int timeout) 24
{@@ -25,7 +28,7 @@ static int observed_poll(struct pollfd *fds, nfds_t count, int timeout)
28
29
enum Object { DISPLAY = 1, REGISTRY, COMPOSITOR, SHM, WM_BASE, SURFACE, 30
XDG_SURFACE, TOPLEVEL, ACTIVATION };−28
typedef struct { unsigned pings, pongs, activations; int committed; } PeerStats;+31
typedef struct { unsigned pings, pongs, activations, activation_destroys; int committed; } PeerStats; 32
static const char activation_token[] = "owned-activation-token"; 33
34
static int send_words(int fd, const uint32_t *words, size_t count)@@ -61,8 +64,9 @@ static int serve(int fd, const char *mode, PeerStats *stats)
64
{ 65
enum Object objects[4096] = {0}; 66
objects[1] = DISPLAY;−64
uint32_t wm_base = 0, surface = 0, xdg_surface = 0, toplevel = 0;−65
int activation = !strcmp(mode, "activation");+67
uint32_t registry = 0, wm_base = 0, surface = 0, xdg_surface = 0, toplevel = 0;+68
int remove_activation = !strcmp(mode, "activation-removed");+69
int activation = !strcmp(mode, "activation") || remove_activation; 70
uint32_t input[16384], output[12288]; 71
size_t used = 0, sent = 0, output_size = 0; 72
uint32_t serial = 1;@@ -89,7 +93,7 @@ static int serve(int fd, const char *mode, PeerStats *stats)
93
switch (objects[id]) { 94
case DISPLAY: 95
if (opcode == 1) {−92
uint32_t registry = message[2];+96
registry = message[2]; 97
if (registry >= 4096) return 3; 98
objects[registry] = REGISTRY; 99
if (!peer_global(fd, registry, 1, "wl_compositor", 4) ||@@ -173,6 +177,12 @@ static int serve(int fd, const char *mode, PeerStats *stats)
177
memcmp(&message[3], activation_token, sizeof activation_token) || 178
message[count - 1] != surface) return 3; 179
stats->activations++;+180
if (remove_activation && stats->activations == 1) {+181
uint32_t removed[] = {registry, (12u << 16) | 1, 4}; /* global_remove */+182
if (!send_words(fd, removed, 3)) return 2;+183
}+184
} else if (opcode == XDG_ACTIVATION_V1_DESTROY) {+185
stats->activation_destroys++; 186
} 187
break; 188
default: break;@@ -253,12 +263,50 @@ static int check_expired_pending(pid_t peer, PeerStats *stats)
263
return passed ? 0 : 1; 264
} 265
+266
static void check_activation(SigilVM *vm, int remove_activation, const PeerStats *stats)+267
{+268
sigil_eval_string(vm, "(import (sigil ui wayland)) "+269
"(define configure-peer "+270
" (open-wayland-surface title: \"Configure peer\" app-id: \"ui-configure-test\")) "+271
"(when (or (wayland-activate! configure-peer) "+272
" (wayland-activate! configure-peer #f)) "+273
" (error \"Accepted a missing activation token\"))");+274
if (sigil_error_message(vm)) return;+275
+276
char expression[192];+277
snprintf(expression, sizeof expression,+278
"(unless (wayland-activate! configure-peer \"%s\") (error \"Activation refused\"))",+279
activation_token);+280
sigil_eval_string(vm, expression);+281
if (sigil_error_message(vm)) return;+282
+283
if (remove_activation) {+284
Value handle = sigil_eval_string(vm, "(wayland-native-handle configure-peer)");+285
assert(!sigil_error_message(vm) && sigil_is_foreign(handle));+286
Wl *window = sigil_foreign_data(handle);+287
assert(window && window->display);+288
/* The peer sends global_remove before answering this round trip. */+289
assert(wl_display_roundtrip(window->display) >= 0);+290
assert(window->display && !window->closed && !window->dead);+291
snprintf(expression, sizeof expression,+292
"(when (wayland-activate! configure-peer \"%s\") (error \"Accepted a removed activation global\"))",+293
activation_token);+294
sigil_eval_string(vm, expression);+295
if (sigil_error_message(vm)) return;+296
/* Deliver the destroy request before closing the connection. */+297
assert(wl_display_roundtrip(window->display) >= 0);+298
assert(stats->activation_destroys == 1);+299
}+300
sigil_eval_string(vm, "(wayland-surface-close! configure-peer)");+301
}+302
303
int main(int argc, char **argv) 304
{ 305
struct rlimit no_core = {0, 0}; 306
assert(setrlimit(RLIMIT_CORE, &no_core) == 0); 307
const char *mode = argc > 1 ? argv[1] : "early-close";−261
int activation = !strcmp(mode, "activation");+308
int remove_activation = !strcmp(mode, "activation-removed");+309
int activation = !strcmp(mode, "activation") || remove_activation; 310
if (strcmp(mode, "early-close") && strcmp(mode, "close-configure") && strcmp(mode, "traffic") && 311
strcmp(mode, "expired-pending") && !activation) return 2; 312
signal(SIGPIPE, SIG_IGN);@@ -288,15 +336,19 @@ int main(int argc, char **argv)
336
} 337
SigilVM *vm = sigil_vm_create(); 338
assert(vm);−291
sigil__register_sigil_ui_wayland(vm); 339
int64_t start = now_ms();−293
sigil_eval_string(vm, "(import (sigil ui wayland)) "−294
"(define configure-peer (%wl-open #f 0 \"Configure peer\" \"ui-configure-test\" #f 640 480 #f))");−295
if (activation && !sigil_error_message(vm)) {−296
char expression[160];−297
snprintf(expression, sizeof expression,−298
"(if (%%wl-activate! configure-peer \"%s\") #t (error \"Activation refused\"))", activation_token);−299
sigil_eval_string(vm, expression);+340
if (activation) {+341
assert(argc >= 4);+342
sigil__init_sigil_ui_native(vm);+343
sigil__init_sigil_ffi_module(vm);+344
sigil__init_sigil_font_native(vm);+345
for (int i = 3; i < argc; i++) sigil_vm_add_load_path(vm, argv[i]);+346
sigil_eval_file(vm, argv[2]);+347
if (!sigil_error_message(vm)) check_activation(vm, remove_activation, stats);+348
} else {+349
sigil__register_sigil_ui_wayland(vm);+350
sigil_eval_string(vm, "(import (sigil ui wayland)) "+351
"(define configure-peer (%wl-open #f 0 \"Configure peer\" \"ui-configure-test\" #f 640 480 #f))"); 352
} 353
int64_t elapsed = now_ms() - start; 354
char problem[1024];@@ -309,7 +361,8 @@ int main(int argc, char **argv)
361
assert(waitpid(peer, &status, 0) == peer); 362
int traffic = !strcmp(mode, "traffic"); 363
int passed = WIFEXITED(status) && WEXITSTATUS(status) == 0 && stats->committed;−312
if (activation) passed = passed && !*problem && stats->activations == 1;+364
if (activation) passed = passed && !*problem && stats->activations == 1 &&+365
(!remove_activation || stats->activation_destroys == 1); 366
else passed = passed && strstr(problem, traffic ? "within five seconds" : "closed the surface before showing it") && 367
(traffic ? elapsed >= 4900 && elapsed < 6200 && stats->pongs > 1000 : elapsed < 1500); 368
printf("%s: configure peer %s elapsed_ms=%lld pings=%u pongs=%u peer_status=%d: %s\n",test/wayland/services-native.cmodified
@@ -34,7 +34,8 @@ static void check_activation_guards(SigilVM *vm)
34
Value handle = sigil_make_foreign(vm, wl_tag, &window, NULL, sizeof window); 35
Value rejected[] = {SIGIL_FALSE, sigil_make_string(vm, "", 0), 36
sigil_make_string(vm, oversized, sizeof oversized),−37
sigil_make_string(vm, "a\0b", 3)};+37
sigil_make_string(vm, "a\0b", 3),+38
sigil_make_string(vm, "\xed\xa0\x80", 3)}; 39
for (size_t i = 0; i < sizeof rejected / sizeof rejected[0]; i++) { 40
Value args[] = {handle, rejected[i]}; 41
assert(native_wl_activate(vm, 2, args) == SIGIL_FALSE);@@ -49,11 +50,20 @@ static void check_activation_guards(SigilVM *vm)
50
window.parent = &parent; 51
assert(native_wl_activate(vm, 2, args) == SIGIL_FALSE); 52
window.parent = NULL;+53
window.toplevel = NULL;+54
window.layer = (struct zwlr_layer_surface_v1 *)(uintptr_t)1;+55
assert(native_wl_activate(vm, 2, args) == SIGIL_FALSE);+56
window.layer = NULL;+57
window.toplevel = (struct xdg_toplevel *)(uintptr_t)1;+58
window.connection_depth = 1;+59
assert(native_wl_activate(vm, 2, args) == SIGIL_FALSE);+60
window.connection_depth = 0; 61
window.closed = 1; 62
window.display = NULL; 63
assert(native_wl_activate(vm, 2, args) == SIGIL_FALSE); 64
assert(!sigil_error_message(vm));−56
puts("PASS: activation refuses invalid tokens, missing globals, subsurfaces and closed windows");+65
puts("PASS: activation refuses invalid UTF-8 and other invalid tokens, missing globals, "+66
"subsurfaces, layer surfaces, dispatch reentry and closed windows"); 67
} 68
69
static void *wrong_thread(void *data)