AtlatestRepositorysigil-app
1
# sigil-desktop3
The desktop host layer for Sigil games and interactive programs: a window4
with an OpenGL context, keyboard and mouse state, a frame clock, and a5
quit request, behind the `(sigil desktop)` library. Drawing is6
[sigil-graphics](https://codeberg.org/sigil/sigil-graphics), which builds7
on this package; sound is8
[sigil-audio](https://codeberg.org/sigil/sigil-audio).10
The window comes from [GLFW](https://www.glfw.org) 3.5.1, vendored as11
source under `vendor/glfw` (no local patches; see `vendor/glfw/VENDOR.md`).12
On Linux one binary runs as a native Wayland client or under X11, picked13
when the program starts; on Windows it is a Win32 window; the macOS files14
are vendored and not yet built. Every platform library (libwayland-client,15
libxkbcommon, libX11, libEGL, libGL, ...) is loaded at run time by GLFW,16
so a game links none of them.18
This package was `sigil-app` through 0.9.x, when the window was sokol_app19
(X11 only on Linux); the Codeberg repository is `sigil/sigil-desktop`20
since 2026-09-20 (renamed in place, the old URL redirects). The21
`(sigil app)` library still exists in 0.10 as a re-export of22
`(sigil desktop)` so a consumer can relock first and rename its imports23
second; it goes away in 0.11.25
## Use27
```scheme28
(import (sigil desktop) (sigil graphics))30
(define (game)31
(gfx-setup)32
(let loop ()33
(let ((dt (wait-frame)))34
(begin-frame)35
(clear-screen 0.0 0.0 0.0)36
;; draw with (frame-width) x (frame-height) pixels to work with37
(end-frame)38
(cond ((key-pressed? 'escape) (request-quit))39
((quit-requested?) #t)40
(else (loop)))))41
(gfx-shutdown))43
(run-game "My Game" 960 720 game)44
```46
`run-game` runs the thunk in a coroutine; `(wait-frame)` yields to the47
host and returns the frame's delta time in seconds when the next frame48
starts. Below it, `app-run` takes init, frame and cleanup procedures49
directly.51
The exports: `app-run`, `run-game`, `wait-frame`, `frame-width`,52
`frame-height`, `frame-time`, `time-elapsed`, `mouse-x`, `mouse-y`,53
`mouse-down?`, `mouse-pressed?`, `mouse-released?`, `key-down?`,54
`key-pressed?`, `key-released?`, `quit-requested?`, `request-quit`.56
Sizes and positions are framebuffer pixels: on a scaled Wayland output a57
window asked for at 960x720 has a framebuffer of 1920x1440 at scale 2 (or58
1440x1080 at 1.5), `frame-width` says so, and `mouse-x`/`mouse-y` are in59
the same pixels. Key symbols: `a`..`z`, `0`..`9`, `space`, `return` (or60
`enter`), `escape` (or `esc`), `tab`, `backspace`, `left`, `right`, `up`,61
`down`, `shift`, `ctrl` (or `control`), `alt`. Mouse buttons: `left`,62
`right`, `middle`. `key-pressed?` is true for the one frame after the key63
went down (a held key repeating does not re-fire it); `key-down?` reports64
the state after that frame's events.66
## Environment68
- `SIGIL_DESKTOP_PLATFORM=wayland|x11|win32|cocoa` forces the platform.69
Otherwise GLFW follows `XDG_SESSION_TYPE` and `WAYLAND_DISPLAY`/`DISPLAY`,70
trying Wayland before X11.71
- `SIGIL_DESKTOP_VERBOSE=1` prints the platform, window and framebuffer72
sizes and content scale on startup and on every resize, and which73
directory each runtime library was found in when the loader needed help.74
- `SIGIL_LIBRARY_PATH=dir:dir` adds directories the runtime loader looks in75
for the platform libraries (see below).77
## Guix and Nix79
GLFW loads its platform libraries by bare soname, and on Guix and Nix a80
profile's `lib/` is on no default loader path. `src/c/dl-search.c`81
defines `dlopen` in the executable: it tries the name as the loader would,82
and only when that fails looks under, in order, `SIGIL_LIBRARY_PATH`,83
`$GUIX_ENVIRONMENT/lib`, `$buildInputs`/`$nativeBuildInputs` (each `/lib`,84
inside a nix-shell), `$NIX_LD_LIBRARY_PATH`, `~/.guix-home/profile/lib`,85
`~/.guix-profile/lib`, `~/.nix-profile/lib`,86
`/etc/profiles/per-user/$USER/lib`, `/run/current-system/profile/lib`,87
`/run/current-system/sw/lib`. Every row is walked on every machine (Guix88
and Nix can coexist); the first hit wins and `SIGIL_DESKTOP_VERBOSE` says89
which. `test/dl-search-test.sh` exercises it against fake profiles.91
Manifests under `guix/`: `run-wayland.scm` (mesa, wayland, libxkbcommon)92
and `run-x11.scm` (mesa, libx11) are what a game needs at run time;93
`build.scm` is the headers a build needs. Keep `libglvnd` out of a run94
manifest: Guix's mesa is built without it and a vendorless `libGLX.so.0`95
breaks GLX.97
## Building99
```sh100
guix shell -m guix/build.scm -- sh -c 'CPATH=$GUIX_ENVIRONMENT/include sigil build'101
sigil build --config windows-amd64 # cross, through zig102
```104
The C surface other packages use is `include/sigil-desktop.h`105
(framebuffer size, GL proc loader, platform name).