AtlatestRepositorysigil-ui
1
;;; Live tests for (sigil ui wayland), run by test/wayland/run against a2
;;; headless sway it starts itself. Input comes from a virtual keyboard and3
;;; pointer (test/wayland/input-driver.c); what reached the screen is read4
;;; back with grim and compared with the canvas byte for byte.5
;;;6
;;; The compositor is shared by every test, in order. Each test leaves the7
;;; output at scale 1 with no surface open.9
(import (sigil test) (sigil process) (sigil io) (sigil fs) (sigil string) (sigil time)10
(sigil ui raster) (sigil ui wayland))12
(define (need name)13
(or (getenv name)14
(error (string-append name " is not set: run these tests with test/wayland/run"))))16
(define output (need "SIGIL_UI_TEST_OUTPUT"))17
(define shots (need "SIGIL_UI_TEST_SHOTS"))18
(define original-cursor-library (getenv "SIGIL_UI_LIBWAYLAND_CURSOR"))19
(define original-cursor-path (getenv "XCURSOR_PATH"))20
(define original-cursor-theme (getenv "XCURSOR_THEME"))21
(define original-cursor-size (getenv "XCURSOR_SIZE"))23
;; ------------------------------------------------------------ tools25
(define (now-ms) (quotient (* 1000 (current-jiffy)) (jiffies-per-second)))27
(define (sway . words) (process-output->string "swaymsg" (string-join words " ")))29
(define (set-scale! s) (sway "output" output "scale" s))31
;; The input driver: one command, then wait for its ACK. Its ports are32
;; taken once and held here.33
(define driver34
(process-spawn "sh" "-c" (string-append "exec " (need "SIGIL_UI_TEST_DRIVER")) die-with-parent: #t))35
(define driver-in (process-stdin driver))36
(define driver-out (process-stdout driver))37
(let ((first (read-line driver-out)))38
(unless (and (string? first) (string-starts-with? first "INPUT-READY"))39
(error "the input driver did not start" first)))41
(define (drive! . words)42
(let ((line (string-join words " ")))43
(trace "drive " line)44
(display line driver-in)45
(newline driver-in)46
(flush-output-port driver-in)47
(let ((ack (read-line driver-out)))48
(unless (and (string? ack) (string-starts-with? ack "ACK "))49
(error "input driver did not acknowledge" line ack)))))51
(define (n->s n) (number->string n))53
;; assert-equal, printing both values when they differ.54
(define (expect expected actual)55
(unless (equal? expected actual)56
(display " expected ") (write expected) (newline)57
(display " actual ") (write actual) (newline))58
(assert-equal expected actual))60
;; SIGIL_UI_TEST_TRACE=1 prints every event and driver command.61
(define trace? (let ((v (getenv "SIGIL_UI_TEST_TRACE"))) (and v (not (string=? v "")))))62
(define (trace . xs) (when trace? (for-each display xs) (newline)))64
;; Events read by show! that it was not waiting for stay here for the next65
;; pump, so a resize that arrives with a frame is not lost.66
(define inbox '())68
(define (dispatch s ms)69
(let ((events (wayland-dispatch s ms)))70
(for-each (lambda (e) (trace " event " e)) events)71
events))73
;; Dispatch until an event satisfies ok?, or until ms pass; return every74
;; event, in order.75
(define (pump-until s ok? ms)76
(let ((end (+ (now-ms) ms)) (held inbox))77
(set! inbox '())78
(let loop ((acc held))79
(let ((left (- end (now-ms))))80
(if (or (<= left 0) (any? ok? acc))81
acc82
(loop (append acc (dispatch s left))))))))84
;; Dispatch for ms milliseconds and return every event, in order.85
(define (pump s ms) (pump-until s (lambda (e) #f) ms))87
(define (any? ok? xs) (and (pair? xs) (or (ok? (car xs)) (any? ok? (cdr xs)))))88
(define (kind? k) (lambda (e) (eq? (car e) k)))89
(define (only k events) (filter (kind? k) events))90
(define (last xs) (if (null? (cdr xs)) (car xs) (last (cdr xs))))91
(define (state s key) (cdr (assq key (wayland-surface-buffer-state s))))93
;; A canvas whose every device pixel matters: a one-pixel checkerboard94
;; across the top-left corner (any resampling blurs it), blocks of color95
;; from seed, and a frame on the edges.96
(define (pattern w h seed)97
(let ((c (make-canvas w h #x101418)))98
(let loop ((y 0))99
(when (< y (min h 48))100
(let row ((x 0))101
(when (< x (min w 96))102
(when (= 0 (modulo (+ x y) 2)) (canvas-fill! c x y 1 1 #xF0E0D0))103
(row (+ x 1))))104
(loop (+ y 1))))105
(canvas-fill! c (quotient w 4) (quotient h 4) (quotient w 3) (quotient h 5) (+ #x203000 seed))106
(canvas-fill! c (quotient w 2) (quotient h 2) (quotient w 5) (quotient h 4) (+ #x600020 (* 3 seed)))107
(canvas-fill! c 0 0 w 1 #xEDBB45)108
(canvas-fill! c 0 (- h 1) w 1 #xEDBB45)109
(canvas-fill! c 0 0 1 h #xEDBB45)110
(canvas-fill! c (- w 1) 0 1 h #xEDBB45)111
c))113
;; Present, then wait until the compositor has shown it.114
(define (show! s c . rects)115
(let ((done (apply wayland-present! s c rects)))116
(set! inbox (filter (lambda (e) (not (eq? (car e) 'frame))) (pump-until s (kind? 'frame) 2000)))117
done))119
;; The output as the compositor composited it: (width height rgb-bytes).120
(define shot-count 0)121
(define (screenshot)122
(set! shot-count (+ shot-count 1))123
(let ((path (string-append shots "/shot-" (n->s shot-count) ".ppm")))124
(process-output->string "grim" "-t" "ppm" "-o" output path)125
(parse-ppm (read-file-bytes path))))127
(define (cursor-screenshot)128
(set! shot-count (+ shot-count 1))129
(let ((path (string-append shots "/cursor-" (n->s shot-count) ".ppm")))130
(process-output->string "grim" "-c" "-t" "ppm" "-o" output path)131
(process-output->string "grim" "-c" "-t" "png" "-o" output132
(string-append shots "/cursor-" (n->s shot-count) ".png"))133
(parse-ppm (read-file-bytes path))))135
(define (expect-cursor s color extent)136
(pump s 100)137
(let ((expected (make-canvas 1280 800 #x111111)))138
(when color (canvas-fill! expected 300 200 extent extent color))139
(let ((matches? (region-matches? (cursor-screenshot) 290 190 96 96 expected 290 190)))140
(unless matches?141
(display "Cursor capture mismatch (color extent): ")142
(write (list color extent)) (newline))143
(assert-true matches?))))145
(define (parse-ppm bv)146
;; P6, then width, height and maxval separated by whitespace, then one147
;; whitespace byte and the pixels.148
(let loop ((i 2) (fields '()) (cur #f))149
(let ((b (bytevector-u8-ref bv i)))150
(cond ((and (>= b 48) (<= b 57)) (loop (+ i 1) fields (+ (* 10 (or cur 0)) (- b 48))))151
(cur (if (= (length fields) 2)152
(list (car fields) (cadr fields)153
(bytevector-copy bv (+ i 1) (bytevector-length bv)))154
(loop (+ i 1) (append fields (list cur)) #f)))155
(else (loop (+ i 1) fields #f))))))157
;; The rectangle (x y w h) of a screenshot equals the same rectangle of158
;; canvas c taken at (cx, cy).159
(define (region-matches? shot x y w h c cx cy)160
(let ((sw (car shot)) (px (caddr shot)) (rgb (canvas->rgb c)) (cw (canvas-width c)))161
(let loop ((j 0))162
(or (= j h)163
(and (equal? (bytevector-copy px (* 3 (+ x (* sw (+ y j)))) (* 3 (+ x w (* sw (+ y j)))))164
(bytevector-copy rgb (* 3 (+ cx (* cw (+ cy j)))) (* 3 (+ cx w (* cw (+ cy j))))))165
(loop (+ j 1)))))))167
(define (whole-output-matches? c)168
(let ((shot (screenshot)))169
(or (and (= (car shot) (canvas-width c)) (= (cadr shot) (canvas-height c))170
(equal? (caddr shot) (canvas->rgb c)))171
(begin (report-mismatch shot c) #f))))173
;; Say where a screenshot first differs from the canvas, for the log.174
(define (report-mismatch shot c)175
(display (string-append " screenshot " (n->s (car shot)) "x" (n->s (cadr shot))176
", canvas " (n->s (canvas-width c)) "x" (n->s (canvas-height c))))177
(when (and (= (car shot) (canvas-width c)) (= (cadr shot) (canvas-height c)))178
(let ((a (caddr shot)) (b (canvas->rgb c)) (w (car shot)))179
(let loop ((i 0) (first #f) (count 0))180
(if (< i (bytevector-length a))181
(if (= (bytevector-u8-ref a i) (bytevector-u8-ref b i))182
(loop (+ i 3) first count)183
(loop (+ i 3) (or first i) (+ count 1)))184
(when first185
(let ((p (quotient first 3)))186
(display (string-append ", " (n->s count) " pixels differ, first at "187
(n->s (modulo p w)) "," (n->s (quotient p w)) ": "188
(n->s (bytevector-u8-ref a first)) " "189
(n->s (bytevector-u8-ref a (+ first 1))) " "190
(n->s (bytevector-u8-ref a (+ first 2))) " vs "191
(n->s (bytevector-u8-ref b first)) " "192
(n->s (bytevector-u8-ref b (+ first 1))) " "193
(n->s (bytevector-u8-ref b (+ first 2)))))))))))194
(newline))196
;; Every surface a test opens is tracked, so a test that fails half way197
;; does not leave a window behind to change the layout for the next one.198
(define live '())199
(define (track! s) (set! live (cons s live)) s)200
(define-syntax open-surface201
(syntax-rules () ((_ arg ...) (track! (open-wayland-surface arg ...)))))203
(define (open-toplevel)204
(let ((s (open-surface role: 'toplevel title: "live test" app-id: "sigil-ui-live"205
width: 300 height: 200)))206
;; sway maps the window, then tiles it to the whole output. Until a207
;; buffer of the tiled size is committed (which acks that configure),208
;; sway holds the layout back and input goes nowhere.209
(show! s (pattern (wayland-surface-device-width s) (wayland-surface-device-height s) 0))210
(pump-until s (kind? 'resize) 2000)211
(show! s (pattern (wayland-surface-device-width s) (wayland-surface-device-height s) 0))212
s))214
(define (close! s)215
(wayland-surface-close! s)216
(set! live (filter (lambda (x) (not (eq? x s))) live))217
(set! inbox '())218
(sway "nop"))220
;; Undo whatever an earlier, failed test may have left.221
(define (cleanup!)222
(for-each wayland-surface-close! live)223
(set! live '())224
(set! inbox '())225
(setenv! "SIGIL_UI_WAYLAND_IGNORE" "")226
(setenv! "SIGIL_UI_LIBWAYLAND_CURSOR" original-cursor-library)227
(setenv! "XCURSOR_PATH" original-cursor-path)228
(setenv! "XCURSOR_THEME" original-cursor-theme)229
(setenv! "XCURSOR_SIZE" original-cursor-size)230
(set-scale! "1")231
(sway "input type:keyboard repeat_delay 600")232
(sway "input type:keyboard repeat_rate 25")233
;; No key, modifier or button left down, and the us layout.234
(drive! "keymap" "us")235
(drive! "mods" "0")236
(drive! "release" "30")237
(drive! "release" "42")238
(drive! "button" "272" "0"))240
;; The message of the error thunk raises, or #f.241
(define (error-text thunk)242
(guard (e (#t (if (error-object? e) (error-object-message e) "?")))243
(thunk)244
#f))246
(define-syntax live-test247
(syntax-rules () ((_ name body ...) (test name (cleanup!) body ...))))249
;; ------------------------------------------------------------ tests251
(test-group "toplevel"252
(live-test "opens configured, with the requested size until the compositor tiles it"253
(let ((s (open-surface role: 'toplevel title: "live test" app-id: "sigil-ui-live"254
width: 300 height: 200)))255
(expect 'toplevel (wayland-surface-role s))256
(expect '(300 200 1) (list (wayland-surface-width s) (wayland-surface-height s)257
(wayland-surface-scale s)))258
(show! s (pattern 300 200 0))259
(let ((events (pump-until s (kind? 'resize) 2000)))260
(expect '(resize 1280 800 1) (car (only 'resize events))))261
(expect '(1280 800) (list (wayland-surface-device-width s) (wayland-surface-device-height s)))262
(close! s)))264
(live-test "scale 1: the output shows the canvas byte for byte"265
(let* ((s (open-toplevel)) (c (pattern 1280 800 7)))266
(show! s c)267
(assert-true (whole-output-matches? c))268
(close! s)))270
(live-test "exact damage, carried into the other buffer"271
;; The compositor may read any part of a committed buffer, so a buffer272
;; must hold the whole picture: a change damaged into one buffer has to273
;; be copied into the other before that one is shown. sway composites274
;; whole buffers, so a missed copy shows on screen.275
(let* ((s (open-toplevel)) (c (pattern 1280 800 1)))276
(show! s c)277
(show! s c '((0 0 1 1))) ; both buffers hold c now278
(canvas-fill! c 600 40 100 30 #x3070F0)279
(show! s c '((600 40 100 30)))280
(expect 1 (state s 'last-damage-count))281
(expect '(600 40 100 30) (state s 'last-damage-box))282
(canvas-fill! c 900 600 120 40 #xF03030)283
(canvas-fill! c 20 700 10 10 #x30F030)284
(show! s c '((900 600 120 40) (20 700 10 10)))285
(expect 2 (state s 'last-damage-count))286
(expect '(20 600 1000 110) (state s 'last-damage-box))287
(assert-true (whole-output-matches? c))288
;; Damage outside the buffer is clipped to it.289
(canvas-fill! c 1270 790 10 10 #x777777)290
(show! s c '((1270 790 50 50)))291
(expect '(1270 790 10 10) (state s 'last-damage-box))292
(assert-true (whole-output-matches? c))293
(close! s)))295
(live-test "a present waits for the last frame even when a buffer is free"296
;; A new surface has one buffer once it has presented, and the other297
;; slot empty, so only the frame callback can hold the second present.298
(let* ((s (open-surface role: 'toplevel title: "live test" app-id: "sigil-ui-live"299
width: 300 height: 200))300
(c (pattern 300 200 12)))301
(assert-true (wayland-present! s c))302
(expect 1 (state s 'busy))303
(assert-true (state s 'frame-pending?))304
(canvas-fill! c 0 0 10 10 #xFFFFFF)305
(assert-false (wayland-present! s c '((0 0 10 10))))306
(expect 1 (state s 'busy))307
(pump-until s (kind? 'frame) 2000)308
(close! s)))310
(live-test "presents at one size reuse the two buffers; one held by the compositor defers the next"311
(let* ((s (open-toplevel)) (c (pattern 1280 800 2)))312
(show! s c)313
(let loop ((i 0))314
(when (< i 12)315
(canvas-fill! c (* i 20) 300 20 20 (+ #x102030 (* i 4096)))316
(assert-true (wayland-present! s c (list (list (* i 20) 300 20 20))))317
(pump-until s (kind? 'frame) 2000)318
(loop (+ i 1))))319
;; Two presents back to back: the second waits for the first frame.320
(canvas-fill! c 10 500 40 40 #x00FF00)321
(assert-true (wayland-present! s c '((10 500 40 40))))322
(canvas-fill! c 60 500 40 40 #xFF00FF)323
(assert-false (wayland-present! s c '((60 500 40 40))))324
(assert-true (state s 'deferred?))325
(pump-until s (kind? 'frame) 2000)326
(assert-false (state s 'deferred?))327
(pump-until s (kind? 'frame) 2000)328
(assert-true (whole-output-matches? c))329
(expect 0 (state s 'retired))330
(close! s)))332
(live-test "resize while a buffer is in flight: the old buffer is retired, then freed"333
(let* ((s (open-toplevel)) (c (pattern 1280 800 3)))334
(show! s c)335
(sway "[app_id=sigil-ui-live]" "floating" "enable" ","336
"resize" "set" "400" "300" "," "move" "position" "0" "0")337
;; Present the old size again so a buffer of it is in flight, then338
;; take the resize.339
(canvas-fill! c 0 0 50 50 #x445566)340
(wayland-present! s c '((0 0 50 50)))341
(let ((resize (car (only 'resize (pump-until s (kind? 'resize) 2000)))))342
(expect '(resize 400 300 1) resize))343
(let ((small (pattern 400 300 4)))344
(assert-error (wayland-present! s c)) ; the old size is refused345
(wayland-present! s small)346
;; The compositor still shows an old-size buffer until this commit347
;; is applied, so at least one is retired, not freed.348
(assert-true (>= (state s 'retired) 1))349
(pump-until s (kind? 'frame) 2000)350
(pump s 200)351
(expect 0 (state s 'retired))352
(let ((shot (screenshot)))353
(assert-true (region-matches? shot 0 0 400 300 small 0 0))))354
(close! s)))356
(live-test "close: the compositor's request arrives as an event"357
(let ((s (open-toplevel)))358
(sway "[app_id=sigil-ui-live]" "kill")359
(assert-true (any? (kind? 'close) (pump-until s (kind? 'close) 2000)))360
(close! s)361
;; A closed surface still answers questions about itself.362
(assert-true (wayland-surface-closed? s))363
(expect '(1280 800 toplevel) (list (wayland-surface-width s) (wayland-surface-height s)364
(wayland-surface-role s))))))366
(test-group "keyboard"367
(live-test "focus, text, names and modifiers"368
(let ((s (open-toplevel)))369
(pump s 100)370
(assert-true (wayland-surface-focused? s))371
(drive! "key" "30")372
(drive! "mods" "1") (drive! "key" "30") (drive! "mods" "0")373
(drive! "key" "28")374
(drive! "mods" "4") (drive! "key" "30") (drive! "mods" "0")375
(drive! "key" "14")376
(let ((keys (only 'key (pump s 300))))377
(expect '((key press "a" "a" () 30)378
(key release "a" "" () 30)379
(key press "A" "A" (shift) 30)380
(key release "A" "" (shift) 30)381
(key press "Return" "" () 28)382
(key release "Return" "" () 28)383
(key press "a" "" (control) 30)384
(key release "a" "" (control) 30)385
(key press "BackSpace" "" () 14)386
(key release "BackSpace" "" () 14))387
keys))388
(close! s)))390
(live-test "key repeat follows the compositor's rate, survives a modifier, stops on release"391
;; Not sway's defaults (600 ms, 25/s), so a client that ignored the392
;; compositor's rate would be caught.393
(sway "input type:keyboard repeat_delay 200")394
(sway "input type:keyboard repeat_rate 50")395
(let ((s (open-toplevel))396
(repeats (lambda (es) (filter (lambda (e) (and (eq? (car e) 'key) (eq? (cadr e) 'repeat))) es))))397
(pump s 100)398
(drive! "press" "30")399
(let* ((held (pump s 1000))400
(_ (drive! "press" "42")) ; left shift, which does not repeat401
(with-shift (pump s 300))402
(_ (drive! "release" "42"))403
(_ (drive! "release" "30"))404
(after (pump s 300)))405
;; 200 ms, then one every 20 ms: 40 in the first second.406
(trace "repeats in 1 s: " (length (repeats held)) ", with shift down: " (length (repeats with-shift)))407
(assert-true (>= (length (repeats held)) 34))408
(assert-true (<= (length (repeats held)) 44))409
(expect '(key repeat "a" "a" () 30) (car (repeats held)))410
(assert-true (>= (length (repeats with-shift)) 10))411
(expect '() (repeats after)))412
(close! s)))414
(live-test "a dead key composes with the next key"415
(let ((s (open-toplevel)))416
(pump s 100)417
(drive! "keymap" "us" "intl")418
(drive! "key" "40") ; dead_acute419
(drive! "key" "18") ; e420
(drive! "keymap" "us")421
(let ((texts (map (lambda (e) (list-ref e 3))422
(filter (lambda (e) (eq? (cadr e) 'press)) (only 'key (pump s 300))))))423
(expect '("" "é") texts))424
(close! s)))426
(live-test "focus moves to a new window and back"427
(let* ((s (open-toplevel)) (t (open-toplevel)))428
(pump s 100)429
(assert-false (wayland-surface-focused? s))430
(assert-true (wayland-surface-focused? t))431
(close! t)432
(assert-true (any? (lambda (e) (equal? e '(keyboard-focus #t)))433
(pump-until s (lambda (e) (equal? e '(keyboard-focus #t))) 2000)))434
(close! s))))436
(test-group "pointer"437
(live-test "motion, buttons and wheel in logical coordinates"438
(let ((s (open-toplevel)))439
(pump s 100)440
(drive! "move" "100" "50")441
(drive! "button" "272" "1")442
(drive! "button" "272" "0")443
(drive! "scroll" "15" "1")444
(let ((events (filter (lambda (e) (memq (car e) '(pointer-enter pointer-motion pointer-button scroll)))445
(pump s 300))))446
(expect '(100 50)447
(cdr (last (filter (lambda (e) (memq (car e) '(pointer-enter pointer-motion))) events))))448
(expect '((pointer-button press left 100 50) (pointer-button release left 100 50))449
(only 'pointer-button events))450
(expect '((scroll 0.0 15.0 0 1 100 50)) (only 'scroll events)))451
;; The compositor supplies value120 only to seat v8+ clients. Check452
;; the actual decoder as well as the legacy seven-item contract.453
(drive! "scroll-x" "15" "1")454
(let ((end (+ (now-ms) 300)))455
(let loop ((events '()))456
(let ((left (- end (now-ms))))457
(if (<= left 0)458
(expect '((scroll 15.0 0.0 1 0 100 50 (wheel 120 0 0)))459
(only 'scroll events))460
(loop (append events (wayland-window-dispatch s left)))))))461
(close! s))))463
(test-group "cursor"464
(live-test "explicit theme, named and copied image cursors render at both scales and survive re-entry"465
(setenv! "SIGIL_UI_WAYLAND_IGNORE" "wp_cursor_shape_manager_v1")466
(setenv! "XCURSOR_PATH" (need "SIGIL_UI_TEST_CURSOR_ROOT"))467
(for-each (lambda (scale)468
(set-scale! (n->s scale))469
(let ((s (open-toplevel)))470
(define (reenter!)471
(let ((other (open-toplevel)))472
(drive! "move" "1000" "200")473
(pump other 100)474
(pump s 100)475
(expect 'unavailable (wayland-cursor-backend s))476
(close! other))477
(pump s 100)478
(show! s (make-canvas (wayland-surface-device-width s) (wayland-surface-device-height s) #x111111))479
(drive! "move" "300" "200")480
(pump s 100))481
(assert-true (wayland-cursor-configure! s theme: "Fixture" size: 16))482
(show! s (make-canvas 1280 800 #x111111))483
(drive! "move" "300" "200")484
(pump s 100)485
(for-each (lambda (entry)486
(assert-true (wayland-set-cursor! s (car entry)))487
(expect 'theme (wayland-cursor-backend s))488
(expect-cursor s (cdr entry) (* 16 scale)))489
'(("default" . #x0000ff) ("pointer" . #xff0000) ("text" . #x00ff00)))490
;; Copy now: later mutation of the caller's pixels cannot change it.491
(let* ((side (* 8 scale)) (pixels (make-bytevector (* side side 4) 255)))492
(define (fill-color! red green blue)493
(let fill ((i 0))494
(when (< i (bytevector-length pixels))495
(bytevector-u8-set! pixels i blue)496
(bytevector-u8-set! pixels (+ i 1) green)497
(bytevector-u8-set! pixels (+ i 2) red)498
(fill (+ i 4)))))499
;; Match the output's device scale so the compositor does not500
;; resample a lower-resolution source at the cursor's edges.501
;; Three updates without dispatch fill both slots, then retain502
;; only the latest yellow image until a buffer release arrives.503
(fill-color! 0 0 255)504
(assert-true (wayland-set-cursor-image! s pixels side side scale: scale))505
(fill-color! 255 0 0)506
(assert-true (wayland-set-cursor-image! s pixels side side scale: scale))507
(fill-color! 255 255 0)508
(assert-true (wayland-set-cursor-image! s pixels side side scale: scale))509
(bytevector-u8-set! pixels 1 0)510
(expect 'image (wayland-cursor-backend s))511
(expect-cursor s #xffff00 (* 8 scale)))512
(reenter!)513
(expect 'image (wayland-cursor-backend s))514
(expect-cursor s #xffff00 (* 8 scale))515
(assert-true (wayland-set-cursor! s "none"))516
(expect 'hidden (wayland-cursor-backend s))517
(expect-cursor s #f 0)518
(assert-true (wayland-set-cursor! s "text"))519
(reenter!)520
(expect 'theme (wayland-cursor-backend s))521
(expect-cursor s #x00ff00 (* 16 scale))522
(assert-error (wayland-set-cursor! s ""))523
(assert-error (wayland-set-cursor! s (string #\a (integer->char 0) #\b)))524
(assert-error (wayland-cursor-configure! s size: 129))525
(assert-error (wayland-set-cursor-image! s (make-bytevector 4 0) 2 2))526
(close! s)527
(assert-error (wayland-set-cursor! s "pointer")))) '(1 2))528
(set-scale! "1"))530
(live-test "cursor policy selects compositor shapes, explicit themes and inherited default images"531
(setenv! "XCURSOR_PATH" (need "SIGIL_UI_TEST_CURSOR_ROOT"))532
(setenv! "XCURSOR_THEME" "Fixture")533
(setenv! "XCURSOR_SIZE" "16")534
(let ((s (open-toplevel)))535
(show! s (make-canvas 1280 800 #x111111))536
(drive! "move" "300" "200")537
(pump s 100)538
(assert-true (wayland-set-cursor! s "pointer"))539
(expect 'shape (wayland-cursor-backend s))540
(assert-true (wayland-cursor-configure! s theme: "Fixture" size: 16))541
(expect 'theme (wayland-cursor-backend s))542
(expect-cursor s #xff0000 16)543
(assert-true (wayland-cursor-configure! s))544
(expect 'shape (wayland-cursor-backend s))545
(assert-true (wayland-set-cursor! s "unmapped-fixture"))546
(expect 'theme (wayland-cursor-backend s))547
(expect-cursor s #xff00ff 16)548
(assert-false (wayland-set-cursor! s "missing-fixture-cursor"))549
(expect 'unavailable (wayland-cursor-backend s))550
(close! s))551
(setenv! "SIGIL_UI_WAYLAND_IGNORE" "wp_cursor_shape_manager_v1")552
(let ((s (open-toplevel)))553
(show! s (make-canvas 1280 800 #x111111))554
(drive! "move" "300" "200")555
(pump s 100)556
(assert-true (wayland-set-cursor! s "text"))557
(expect 'theme (wayland-cursor-backend s))558
(expect-cursor s #x00ff00 16)559
(close! s)))561
(live-test "missing optional cursor library preserves compositor pointer and text shapes"562
(setenv! "SIGIL_UI_LIBWAYLAND_CURSOR" "/nonexistent-cursor-library")563
(let ((s (open-toplevel)))564
(drive! "move" "300" "200")565
(pump s 100)566
(assert-true (wayland-set-cursor! s "pointer"))567
(expect 'shape (wayland-cursor-backend s))568
(assert-true (wayland-set-cursor! s "text"))569
(expect 'shape (wayland-cursor-backend s))570
(pump s 100)571
(assert-false (wayland-surface-closed? s))572
(close! s))))574
(test-group "scale"575
(live-test "scale 2: buffer scale follows the output, logical size halves, pixels are exact"576
(let ((s (open-toplevel)))577
(set-scale! "2")578
(let ((resize (last (only 'resize (pump-until s (kind? 'resize) 2000)))))579
(expect '(resize 640 400 2) resize))580
(let ((c (pattern 1280 800 5)))581
(show! s c)582
(assert-true (whole-output-matches? c)))583
;; The pointer still reports logical pixels.584
(drive! "move" "200" "100")585
(expect '(100 50) (cdr (last (filter (lambda (e) (memq (car e) '(pointer-enter pointer-motion)))586
(pump s 300)))))587
(set-scale! "1")588
(expect '(resize 1280 800 1) (last (only 'resize (pump-until s (kind? 'resize) 2000))))589
(close! s)))591
(live-test "fractional scale 1.5: rendered at 2, the compositor scales down"592
(let ((s (open-toplevel)))593
(set-scale! "1.5")594
(pump s 300)595
(expect 2 (wayland-surface-scale s))596
(let ((w (wayland-surface-width s)) (h (wayland-surface-height s)))597
(expect '(853 533) (list w h))598
(show! s (pattern (* 2 w) (* 2 h) 6)))599
(set-scale! "1")600
(pump s 300)601
(close! s))))603
(test-group "fullscreen"604
(live-test "layer-shell at scale 1 and 2 covers the output exactly"605
(let ((s (open-surface role: 'fullscreen app-id: "sigil-ui-live" output: output)))606
(expect 'layer (wayland-surface-role s))607
(expect '(1280 800 1) (list (wayland-surface-width s) (wayland-surface-height s)608
(wayland-surface-scale s)))609
(let ((c (pattern 1280 800 8)))610
(show! s c)611
(pump s 100)612
(assert-true (wayland-surface-focused? s))613
(assert-true (whole-output-matches? c)))614
(set-scale! "2")615
(expect '(resize 640 400 2) (last (only 'resize (pump-until s (kind? 'resize) 2000))))616
(let ((c (pattern 1280 800 9)))617
(show! s c)618
(assert-true (whole-output-matches? c)))619
(set-scale! "1")620
(pump-until s (kind? 'resize) 2000)621
(close! s)))623
(live-test "without layer-shell: a fullscreen toplevel on the output"624
(setenv! "SIGIL_UI_WAYLAND_IGNORE" "zwlr_layer_shell_v1")625
(let ((s (open-surface role: 'fullscreen app-id: "sigil-ui-live" output: output)))626
(setenv! "SIGIL_UI_WAYLAND_IGNORE" "")627
(expect 'fullscreen (wayland-surface-role s))628
(show! s (pattern (wayland-surface-device-width s) (wayland-surface-device-height s) 10))629
(pump-until s (kind? 'resize) 1000)630
(expect '(1280 800) (list (wayland-surface-width s) (wayland-surface-height s)))631
(let ((c (pattern 1280 800 11)))632
(show! s c)633
(assert-true (whole-output-matches? c)))634
(close! s)))636
(live-test "an unknown output is refused, naming the outputs there are"637
(let ((m (error-text (lambda () (open-surface role: 'fullscreen output: "NO-SUCH-OUTPUT")))))638
(expect "wayland-open: no output named NO-SUCH-OUTPUT (outputs: HEADLESS-1)" m))))