AtlatestRepositorysigil-desktop
1# sigil-desktop
2
3The desktop host layer for Sigil games and interactive programs: a window
4with an OpenGL context, keyboard and mouse state, a frame clock, and a
5quit request, behind the `(sigil desktop)` library. Drawing is
6[sigil-graphics](https://codeberg.org/sigil/sigil-graphics), which builds
7on this package; sound is
8[sigil-audio](https://codeberg.org/sigil/sigil-audio).
9
10The window comes from [GLFW](https://www.glfw.org) 3.5.1, vendored as
11source under `vendor/glfw` (no local patches; see `vendor/glfw/VENDOR.md`).
12On Linux one binary runs as a native Wayland client or under X11, picked
13when the program starts; on Windows it is a Win32 window; the macOS files
14are vendored and not yet built. Every platform library (libwayland-client,
15libxkbcommon, libX11, libEGL, libGL, ...) is loaded at run time by GLFW,
16so a game links none of them.
18This package was `sigil-app` through 0.9.x, when the window was sokol_app
19(X11 only on Linux); the Codeberg repository is `sigil/sigil-desktop`
20since 2026-09-20 (renamed in place, the old URL redirects). The
21`(sigil app)` library still exists in 0.10 as a re-export of
22`(sigil desktop)` so a consumer can relock first and rename its imports
23second; it goes away in 0.11.
25## Use
27```scheme
28(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 with
37 (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 the
47host and returns the frame's delta time in seconds when the next frame
48starts. Below it, `app-run` takes init, frame and cleanup procedures
49directly.
51The 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?`.
60Sizes and positions are framebuffer pixels: on a scaled Wayland output a
61window asked for at 960x720 has a framebuffer of 1920x1440 at scale 2 (or
621440x1080 at 1.5), `frame-width` says so, and `mouse-x`/`mouse-y` are in
63the same pixels. Key symbols: `a`..`z`, `0`..`9`, `space`, `return` (or
64`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 key
67went down (a held key repeating does not re-fire it); `key-down?` reports
68the state after that frame's events.
70**Mouse look.** `(set-cursor-captured! #t)` hides the cursor and holds it
71on the window, with raw (unaccelerated) motion where the platform offers
72it; `(mouse-dx)` and `(mouse-dy)` are then the motion since the last
73frame, in the same framebuffer pixels (+x right, +y down). They count
74whether or not the cursor is captured; the pointer entering the window is
75not motion (its position there is a jump from wherever it left). The capture ends with
76`(set-cursor-captured! #f)`, when the window loses the focus, and when the
77player presses Escape, unless it was asked for with
78`(set-cursor-captured! #t #f)` (the Escape key still reaches the game
79either way); `(cursor-captured?)` says whether it still holds (read from
80GLFW's input mode), so a game can capture again on the next click. On
81Wayland this uses the compositor's pointer constraints; a compositor
82without them leaves the cursor free and `set-cursor-captured!` answers
83`#f`.
85## Environment
87- `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 framebuffer
91 sizes and content scale on startup and on every resize, and which
92 directory each runtime library was found in when the loader needed help.
93- `SIGIL_LIBRARY_PATH=dir:dir` adds directories the runtime loader looks in
94 for the platform libraries (see below).
96## Guix and Nix
98GLFW loads its platform libraries by bare soname, and on Guix and Nix a
99profile's `lib/` is on no default loader path. `src/c/dl-search.c`
100defines `dlopen` in the executable: it tries the name as the loader would,
101and only when that fails looks under, in order, `SIGIL_LIBRARY_PATH`,
102`$GUIX_ENVIRONMENT/lib`, `$buildInputs`/`$nativeBuildInputs` (each `/lib`,
103inside 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 (Guix
107and Nix can coexist); the first hit wins and `SIGIL_DESKTOP_VERBOSE` says
108which. `test/dl-search-test.sh` exercises it against fake profiles.
110Manifests under `guix/`: `run-wayland.scm` (mesa, wayland, libxkbcommon)
111and `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 run
113manifest: Guix's mesa is built without it and a vendorless `libGLX.so.0`
114breaks GLX.
116## Building
118```sh
119guix shell -m guix/build.scm -- sh -c 'CPATH=$GUIX_ENVIRONMENT/include sigil build'
120sigil build --config windows-amd64 # cross, through zig
121```
123The C surface other packages use is `include/sigil-desktop.h`
124(framebuffer size, GL proc loader, platform name).