AtlatestRepositorysigil-ui

sigil-ui / tree / scriptsmake-cursor-fixture.sgl

1#!/usr/bin/env sigil
2;;; Usage: sigil scripts/make-cursor-fixture.sgl DIRECTORY
3;;; Generates owned opaque test cursors; no installed theme is read or changed.
4(import (sigil shell prelude) (sigil fs))
5(define root (arg 1))
6(define destination (path root "Fixture/cursors"))
7(when (or (file-exists? (path root "Fixture")) (file-exists? (path root "default")))
8 (error "Refusing to replace cursor fixture"))
9(ensure-directory destination)
10(ensure-directory (path root "default"))
11(write-text (path root "default/index.theme") "[Icon Theme]\nInherits=Fixture\n")
12(define (u32! bytes offset value)
13 (each i '(0 1 2 3)
14 (bytevector-u8-set! bytes (+ offset i) (modulo (quotient value (expt 256 i)) 256))))
15(each entry '(("left_ptr" . 4278190335) ("hand2" . 4294901760) ("xterm" . 4278255360)
16 ("unmapped-fixture" . 4294902015))
17 (define lengths (map (lambda (size) (+ 36 (* size size 4))) '(16 32)))
18 (define bytes (make-bytevector (+ 40 (apply + lengths)) 0))
19 (u32! bytes 0 #x72756358)
20 (u32! bytes 4 16)
21 (u32! bytes 8 #x10000)
22 (u32! bytes 12 2)
23 (let draw ((sizes '(16 32)) (toc 16) (chunk 40))
24 (unless (null? sizes)
25 (define size (car sizes))
26 (u32! bytes toc #xfffd0002)
27 (u32! bytes (+ toc 4) size)
28 (u32! bytes (+ toc 8) chunk)
29 (each pair (list (cons 0 36) (cons 4 #xfffd0002) (cons 8 size) (cons 12 1)
30 (cons 16 size) (cons 20 size))
31 (u32! bytes (+ chunk (car pair)) (cdr pair)))
32 (let paint ((i 0))
33 (when (< i (* size size))
34 (u32! bytes (+ chunk 36 (* i 4)) (cdr entry))
35 (paint (+ i 1))))
36 (draw (cdr sizes) (+ toc 12) (+ chunk 36 (* size size 4)))))
37 (write-file-bytes (path destination (car entry)) bytes))
38(println "Created owned cursor fixture ~a" root)