AtlatestRepositorysigil-desktop
sigil-desktop / treeREADME.md
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-dx`, `mouse-dy`, `mouse-wheel`, `mouse-wheel-x`, `mouse-down?`,54
`mouse-pressed?`, `mouse-released?`, `set-cursor-captured!`,55
`cursor-captured?`, `key-down?`, `key-pressed?`, `key-released?`,56
`key-code`, `quit-requested?`, `request-quit`, `window-set-size!`,57
`fullscreen?`, `set-fullscreen!`, `monitor-size`, `window-width`,58
`window-height`, `window-focused?`.60
Sizes and positions are framebuffer pixels: on a scaled Wayland output a61
window asked for at 960x720 has a framebuffer of 1920x1440 at scale 2 (or62
1440x1080 at 1.5), `frame-width` says so, and `mouse-x`/`mouse-y` are in63
the same pixels. Key symbols: `a`..`z`, `0`..`9`, `space`, `return` (or64
`enter`), `escape` (or `esc`), `tab`, `backspace`, `left`, `right`, `up`,65
`down`, `shift`, `ctrl` (or `control`), `alt`. Mouse buttons: `left`,66
`right`, `middle`. `key-pressed?` is true for the one frame after the key67
went down (a held key repeating does not re-fire it); `key-down?` reports68
the state after that frame's events.70
**Mouse look.** `(set-cursor-captured! #t)` hides the cursor and holds it71
on the window, with raw (unaccelerated) motion where the platform offers72
it; `(mouse-dx)` and `(mouse-dy)` are then the motion since the last73
frame, in the same framebuffer pixels (+x right, +y down). They count74
whether or not the cursor is captured; the pointer entering the window is75
not motion (its position there is a jump from wherever it left). The capture ends with76
`(set-cursor-captured! #f)`, when the window loses the focus, and when the77
player presses Escape, unless it was asked for with78
`(set-cursor-captured! #t #f)` (the Escape key still reaches the game79
either way); `(cursor-captured?)` says whether it still holds (read from80
GLFW's input mode), so a game can capture again on the next click. On81
Wayland this uses the compositor's pointer constraints; a compositor82
without them leaves the cursor free and `set-cursor-captured!` answers83
`#f`.85
## Environment87
- `SIGIL_DESKTOP_PLATFORM=wayland|x11|win32|cocoa` forces the platform.88
Otherwise GLFW follows `XDG_SESSION_TYPE` and `WAYLAND_DISPLAY`/`DISPLAY`,89
trying Wayland before X11.90
- `SIGIL_DESKTOP_VERBOSE=1` prints the platform, window and framebuffer91
sizes and content scale on startup and on every resize, and which92
directory each runtime library was found in when the loader needed help.93
- `SIGIL_LIBRARY_PATH=dir:dir` adds directories the runtime loader looks in94
for the platform libraries (see below).96
## Guix and Nix98
GLFW loads its platform libraries by bare soname, and on Guix and Nix a99
profile's `lib/` is on no default loader path. `src/c/dl-search.c`100
defines `dlopen` in the executable: it tries the name as the loader would,101
and only when that fails looks under, in order, `SIGIL_LIBRARY_PATH`,102
`$GUIX_ENVIRONMENT/lib`, `$buildInputs`/`$nativeBuildInputs` (each `/lib`,103
inside a nix-shell), `$NIX_LD_LIBRARY_PATH`, `~/.guix-home/profile/lib`,104
`~/.guix-profile/lib`, `~/.nix-profile/lib`,105
`/etc/profiles/per-user/$USER/lib`, `/run/current-system/profile/lib`,106
`/run/current-system/sw/lib`. Every row is walked on every machine (Guix107
and Nix can coexist); the first hit wins and `SIGIL_DESKTOP_VERBOSE` says108
which. `test/dl-search-test.sh` exercises it against fake profiles.110
Manifests under `guix/`: `run-wayland.scm` (mesa, wayland, libxkbcommon)111
and `run-x11.scm` (mesa, libx11) are what a game needs at run time;112
`build.scm` is the headers a build needs. Keep `libglvnd` out of a run113
manifest: Guix's mesa is built without it and a vendorless `libGLX.so.0`114
breaks GLX.116
## Building118
```sh119
guix shell -m guix/build.scm -- sh -c 'CPATH=$GUIX_ENVIRONMENT/include sigil build'120
sigil build --config windows-amd64 # cross, through zig121
```123
The C surface other packages use is `include/sigil-desktop.h`124
(framebuffer size, GL proc loader, platform name).