54 Commits
Author SHA1 Message Date
admin fc1b843b97 Merge pull request #77 from Alpaq92/version-0.7.0
Version 0.7.0
2026-10-20 01:07:44 +02:00
adminandClaude Opus 5.5 99ba2bc560 Ask for 0.7 in the consumer example and the FAQ
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 00:12:05 +02:00
adminandClaude Opus 5.5 c6644330fe Version 0.7.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 23:58:50 +02:00
admin 119e12d777 Merge pull request #76 from Alpaq92/web-matchmedia
Web: call matchMedia through window so Closure accepts it
2026-10-19 22:51:27 +02:00
adminandClaude Opus 5.5 fc9c040aac Web: call matchMedia through window so Closure accepts it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 22:49:35 +02:00
admin 6ecb792982 Merge pull request #74 from Alpaq92/os-prefs
Follow the system's reduced motion and contrast; reload sheets on save
2026-10-19 22:42:41 +02:00
admin 65cefd79c3 Merge pull request #75 from Alpaq92/linux-no-skip
Linux CI: run the emulated builds on pull requests again
2026-10-19 22:41:20 +02:00
admin f209d531c9 Merge remote-tracking branch 'origin/master' into os-prefs
# Conflicts:
#	runtime/app.c
2026-10-19 22:41:07 +02:00
adminandClaude Opus 5.5 e795c30d43 Linux CI: run the emulated builds on pull requests again
Their job skipped pull requests, which no one asked for, and showed as an
unexpanded 'linux ${{ matrix.arch }}' check. They stay non-blocking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 22:39:26 +02:00
admin 2d5743df4e Merge pull request #73 from Alpaq92/single-instance
Single instance: a second launch hands its files to the running copy
2026-10-19 22:37:09 +02:00
adminandClaude Opus 5.5 6b5b05509e Single instance: a second launch hands its files to the running copy
.single_instance claims a named mutex and pipe on Windows, a Unix socket
elsewhere; a later launch sends its paths, made absolute, and exits.
--new-instance opts out, and shot and dump runs never claim. The showcase
demonstrates it on Diagnostics, and CI checks the hand-off on every platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 22:32:13 +02:00
adminandClaude Opus 5.5 1730c91bd2 Follow the system's reduced motion and contrast; reload sheets on save
@media (prefers-reduced-motion) and (prefers-contrast) are answered from the
OS (Windows settings, macOS accessibility, the desktop portal, the browser),
reduced motion makes every animation jump to its end, and reaktor.css
strengthens muted text and borders under more contrast. --motion and
--contrast override; --watch-css restyles when a sheet on disk is saved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 22:31:58 +02:00
admin 24b60c910a Merge pull request #72 from Alpaq92/code-polish
Shared test helpers, no MSVC warnings, Nuklear tree arrows; faster BSD and emulated Linux CI
2026-10-19 22:02:46 +02:00
adminandClaude Opus 5.5 9d0488f254 Linux CI: run the emulated builds as their own job, skipped on pull requests
The matrix exclude expression left no native jobs on pull requests, so the
required linux checks never reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 22:02:28 +02:00
adminandClaude Opus 5.5 62733fab33 Linux cross: install and pack libreaktor in the builder, not under emulation
Ninja keeps the cross compiler's own headers among each object's
dependencies; the emulated machine has none of them, so the libreaktor
check and the .deb rebuilt every object there, 14 and 17 minutes. The
builder installs libreaktor and packs the .deb (libreaktor-pkg.sh -a names
its architecture); the emulated machine links the consumer and runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 21:30:57 +02:00
adminandClaude Opus 5.5 5e97e1ab6f Linux cross: find the cross C library, libm among it, in /usr/<triple>
find_library(m) searched only the multiarch folders, where Debian's
cross toolchain does not put its C library, so nothing linked libm and
the armhf and riscv64 links failed on plutovg's maths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 21:04:15 +02:00
adminandClaude Opus 5.5 e625e496ad Shared test helpers, no MSVC warnings, Nuklear tree arrows; faster BSD and emulated Linux CI
Code: the tests' seven pass/fail helpers are one tests/test.h; the
showcase's doubled ROW_SMALL is the login card's ROW_NOTE, and vertex
alignment comes from a named struct rather than NK_ALIGNOF, which MSVC
warned about; Nuklear trees draw their expand arrows again.

CI: every BSD job keeps the packages it downloads between runs, and NetBSD
fetches them from its HTTPS CDN instead of ftp.NetBSD.org. Linux armhf and
riscv64 are cross-compiled in a native x86-64 Debian beside the emulated
one, which only runs what was built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 20:56:39 +02:00
admin 1745a202fc Merge pull request #71 from Alpaq92/pdfgen-netbsd
Build PDFGen on NetBSD
2026-10-19 19:51:18 +02:00
admin f686730bcf Merge pull request #70 from Alpaq92/showcase-api
Showcase the Nuklear aliases, fix three of them, name the cursors
2026-10-19 19:50:42 +02:00
admin dfd28cee10 Merge pull request #69 from Alpaq92/bridges-more
Notify, AT-SPI roles and window stubs said once; build.ps1 keeps -D off -Arch
2026-10-19 19:50:25 +02:00
adminandClaude Opus 5.5 d7a946964f Build PDFGen on NetBSD: compile it through a unit that renames its bswap32
NetBSD's <sys/types.h> declares bswap32 and wraps it in a macro, which
expanded inside PDFGen's own static bswap32 and stopped the build. The
unit includes the header first, drops the macro and renames PDFGen's
function; the submodule is untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 19:46:30 +02:00
adminandClaude Opus 5.5 9be8c1b032 Showcase the Nuklear aliases, fix three of them, name the cursors
A "Nuklear underneath" section on the Display tab uses a Nuklear menu,
tree node, selectable element and right-aligned checkbox, and reads the
style structs and the panel bounds. Writing it found reaktor_tree_element
naming a function Nuklear does not have (reaktor_tree_element_pop is what
was missing), and no REAKTOR_ names for the symbols or for TEXT_RIGHT.

Widgets passed cursors as bare numbers, which is why the text fields'
I-beam looked unused; they are named now. reaktor_style_darken and
reaktor_locale_start move to internal headers, and the two _is_open
queries are documented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 19:42:52 +02:00
adminandClaude Opus 5.5 cb8a79e133 Notify, AT-SPI roles and window stubs said once; build.ps1 keeps -D off -Arch
reaktor_notify checks its notification in one place before the platform
backend, and a build without D-Bus links the module's none twin instead
of a fourth copy of it. AT-SPI's role codes and names are one table, and
the per-window no-op stubs one file the none module, the web and the
non-Windows bridges share. build.ps1 passed a -D option after -Out to
-Arch, which rejected it; it now checks -Arch itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 19:42:35 +02:00
admin 4700ee1140 Merge pull request #68 from Alpaq92/ci-scripts
CI: shots, package and libreaktor checks as shared scripts
2026-10-19 18:34:02 +02:00
admin 0e17c22297 Merge pull request #67 from Alpaq92/a11y-shared
Accessibility bridges share their structural check, press roles and drain
2026-10-19 18:33:47 +02:00
admin 675dd04287 Merge pull request #66 from Alpaq92/cleanup
Drop unused renderer code, share small helpers, trim CI waits
2026-10-19 18:33:29 +02:00
adminandClaude Opus 5.5 7f712e8167 CI: shots, package and libreaktor checks as shared scripts
tools/ci/shots.sh, check-package.sh and check-libreaktor.sh hold what the
Linux, macOS and BSD workflows each spelled out; what differs, the Xvfb
path and the wrapper each program runs under, is a flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 18:26:12 +02:00
adminandClaude Opus 5.5 b9b384bdef Accessibility bridges share their structural check, press roles and drain
The Windows, macOS and AT-SPI bridges each scanned the changes for an
added or removed node, listed the roles a press activates, and wrapped
the snapshot drain; the snapshot code does each once now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 18:26:01 +02:00
adminandClaude Opus 5.5 d695dc3e24 Drop unused renderer code, share small helpers, and trim CI waits
The renderer header loses its debug font, userdata accessors and the
nk_sdl_render wrapper, none of which anything called. Text width, the
#rrggbb formatter, the clear-style push and pop and the end of a drag are
one helper each; ten functions only one file used are static there.

CI: the Windows ccache download draws no progress bar, the macOS embedded
check compiles through ccache, and the emulated Linux jobs run on master
and releases rather than on every pull request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 18:25:45 +02:00
admin ffac374773 Merge pull request #65 from Alpaq92/pdfgen
Print through PDFGen instead of libHaru
2026-10-19 17:52:31 +02:00
adminandClaude Opus 5.5 e027e832b4 Print through PDFGen instead of libHaru
The print module writes one JPEG per page and a title; PDFGen does that
from a single public-domain source file, where libHaru took 87 files, a
generated config header and a filter to leave its CJK encoders out. The
exported pages are byte-identical; showcase and notepad shrink by about
90 KB each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 17:47:21 +02:00
admin 2e56715320 Merge pull request #64 from Alpaq92/windows-ccache
Windows CI: ccache from its pinned release, uncached build as fallback
2026-10-19 16:57:29 +02:00
adminandClaude Opus 5.5 611a4ad5a3 Windows CI: ccache from its own pinned release, and build without it if that fails
Chocolatey's feed answered 503 and the arm64 job failed with no ccache.
The release zip is downloaded from GitHub with retries, checked against
its SHA-256, native for the arm64 runner; if it cannot be had, the build
runs uncached instead of failing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:51:47 +02:00
admin 48c0eb08c6 Merge pull request #63 from Alpaq92/openbsd-cross
BSD CI: cross-compile OpenBSD for arm64 too
2026-10-19 16:39:12 +02:00
adminandClaude Opus 5.5 e555c56851 BSD CI: OpenBSD's file(1) says AArch64
The cross-compile check looked for lowercase aarch64 and failed a build
that was right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:58:31 +02:00
adminandClaude Opus 5.5 fb0e56f044 BSD CI: cross-compile OpenBSD for arm64 too, with the ports LLVM
OpenBSD's base clang has no arm64 backend, so the x86-64 machine installs
llvm%21 and builds against a sysroot of the release's signed arm64 sets and
packages, unpacked by hand since pkg_add will not install another
architecture's. The arm64 machine then only runs the programs, as for
FreeBSD and NetBSD, and the emulated build job is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:41:48 +02:00
admin 7f8b2a5e29 Merge pull request #62 from Alpaq92/perf-small
Less work per frame, quieter accessibility updates, cached CI compiles
2026-10-19 15:41:27 +02:00
adminandClaude Opus 5.5 c0a505a138 Keep SDL's dummy video driver on Windows
The Windows jobs use it for their headless shot and both package checks,
which failed with 'dummy not available' once it was left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 14:40:46 +02:00
adminandClaude Opus 5.5 f0aca8505d build.ps1: CMake options never bind to -Out or -Source
With -Arch named, a third -D option became the source directory, which
the Windows jobs hit once they passed the ccache launchers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 14:30:38 +02:00
adminandClaude Opus 5.5 f756c889e9 Less work per frame, accessibility without needless churn, and cached CI compiles
Rendering skips work it repeated: an image is found by a hash before its
path is compared, an SVG that needs no recoloring is read without staging
copies, wrapped text is measured a word at a time, the software renderer
is told once, and an unchanged clip is not set again.

The accessibility tree interns into two pools that take turns, so a full
pool no longer reports every node as new; on Windows the copy a screen
reader reads is not made until one asks. The text-shaping cache keeps what
is on screen when it fills, and its shaper settings drop only the oldest.

color-mix() reads its colors through plutovg, which adds names and hsl().
SDL's dummy video driver is left out on Windows. Six copies of one hash
are one helper, and the icon calls share one path builder.

Linux, macOS, Windows and the web build keep a ccache between runs, with
SDL's precompiled header off so its compiles are cached too; the web job
also keeps its Emscripten SDK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 14:27:02 +02:00
admin 792f024407 Merge pull request #61 from Alpaq92/bsd-cross
BSD CI: cross-compile FreeBSD and NetBSD for arm64
2026-10-19 13:56:11 +02:00
adminandClaude Opus 5.5 5174b4df28 NetBSD cross: search the sysroot's X11 and package headers last
Given as -I flags they came before SDL's generated Wayland protocol
headers, so the arm64 package's older wayland-client-protocol.h won and
wl_fixes_ack_global_remove went undeclared. Natively pkg-config adds them
after SDL's own; standard include directories do the same here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:26:06 +02:00
adminandClaude Opus 5.5 8ba337b7cb Cross sysroot: NetBSD's arm64 repository from any host spelling, and check only library links
pkgin's line named amd64 over ftp://; the path's architecture is now swapped
whatever it says, on the CDN. The sysroot check flagged libxo's test encoder
and the X keyboard data, which nothing links; only shared libraries could
reach the host's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 12:57:20 +02:00
adminandClaude Opus 5.5 563aab7faa Cross sysroot: find FreeBSD's fetched packages wherever pkg puts them, and read NetBSD's arm64 repository
pkg fetch -o did not write them under All/, so the loop matched nothing.
pkgin's repository line names the architecture as $arch, which the swap
to aarch64 missed, so NetBSD fetched x86-64 packages; the script now
refuses a repository that is not aarch64's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 12:44:25 +02:00
adminandClaude Fable 5.1 404568b9a6 BSD CI: cross-compile FreeBSD and NetBSD for arm64, and cache the build sooner
The x86-64 machines, which run with hardware virtualization, now also build
the arm64 programs for FreeBSD and NetBSD against a sysroot gathered from
the release's sets and packages; an arm64 machine, under emulation, then
only runs them: the console tests, the shots, the package, and a program
linked against libreaktor with its own compiler. OpenBSD's base compiler
has no arm64 backend, so its arm64 job still builds under emulation, in a
job of its own.

reaktor_outside_links strips the sysroot from the link directories it
writes into reaktorConfig.cmake and reaktor.pc, so a program linked on the
target finds the libraries where they are there.

Every BSD job saves its build cache right after compiling, before the tests
and packaging, so the next run finds it sooner.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-19 12:13:31 +02:00
admin d9e7c80d64 Merge pull request #60 from Alpaq92/border-keywords
Border shorthands as longhands; Simple.css as the second sheet
2026-10-19 11:44:57 +02:00
adminandClaude Opus 5.5 a7d2c76c8c Simple.css replaces Bamboo as the Styling page's second sheet
The Styling page now swaps in Simple.css (external/simplecss/simple.css),
which looks clearly different from Water: navy in light, amber in dark.
csstest flattens it in both schemes; packaging, the web build's licenses
and the docs name it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 09:36:04 +02:00
admin 041b1ff6fe Merge pull request #59 from Alpaq92/optimize
Build trims, two cheaper runtime paths, and housekeeping from the audit
2026-10-19 09:35:12 +02:00
adminandClaude Opus 5.5 f6c1ad89a3 cssflat: border shorthands as longhands, and keyword widths as lengths
libcss's border shorthand parser reads three parsed parts whatever it got,
so a value that parses as one part crashed it: border: unset, initial,
inherit, revert, a lone red, dotted or thin, or junk. The converter now
writes border and border-top/-right/-bottom/-left out as their width,
style and colour longhands, with left-out parts at the values libcss
gave them (0px, none, transparent). unset, initial and revert are no
border; inherit, which the engine cannot express, drops the declaration,
as do invalid values; !important reaches every longhand.

In border and outline values, thin, medium and thick become 1px, 3px and
5px, the lengths CSS gives them; libcss reads a border width only as a
length.

Every showcase tab, simple, notepad and 24 runs with app sheets are
byte-identical to master; csstest gains checks for both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 14:28:56 +02:00
adminandClaude Opus 5.5 c7a7d77f83 Build trims, two cheaper runtime paths, and housekeeping from the audit
Build: Nuklear and its backend compile once, in reaktor_core, instead of
three times; libHaru's CJK encoders and fonts, never linked, are not
compiled; SDL's OpenGL drivers stay out of Windows builds unless
REAKTOR_SDL_GL is on (the benchmark's OpenGL arm passes it); GCC and
Clang builds collect unused sections. Windows executables lose 109 KB.

Runtime: a theme load skips its second CSS pass when the sheets' own
role tokens already say what the role sheet would. Printing renders a
page in four frames rather than seven when it settles.

Housekeeping: the backend keeps its vertex buffers across frames; a
label measures its text only when that sets its width; cssflat walks
rules through one splitter and drops a dead context; the Inspector
redraws only when the tree, a value or the sheets change; bench reads
process memory every 30 frames; apply_widget_style resolves the button
rule once; file_exists asks SDL_GetPathInfo; the layout reads direction
and declared size back from onlay instead of keeping copies.

Shots and dumps of every showcase tab, simple and notepad, 24 runs with
app sheets, and the printed PDF are byte-identical to master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 14:04:36 +02:00
admin 7d440511ee Merge pull request #58 from Alpaq92/bench-aa
Fill anti-aliasing on GPU renderers again, with .anti_aliasing to say otherwise
2026-10-18 13:41:51 +02:00
admin a4fc01d0e8 Merge pull request #57 from Alpaq92/bsd-mtime
BSD CI: cache SDL's compiles, skip the steps nothing changed
2026-10-18 13:41:38 +02:00
adminandClaude Fable 5.1 36b46c77d7 Fill anti-aliasing on GPU renderers again, with .anti_aliasing to say otherwise
Fill anti-aliasing went off on every renderer when rounded fills became
masks, which left the bench's rotated boxes jagged under --renderer
direct3d11. A GPU renderer anti-aliases fills again; the software one,
the default, still does not. .anti_aliasing (REAKTOR_AA_AUTO, _ON, _OFF)
and --aa <auto|on|off> decide, and the Diagnostics page reads it back.
The showcase's pixels do not change on either renderer; the bench
screenshot is retaken.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-18 13:00:34 +02:00
adminandClaude Fable 5.1 e11b7eb544 BSD CI: cache SDL's compiles, skip the steps nothing changed
SDL compiles through a precompiled header, which ccache refuses, so its
269 objects were rebuilt under emulation every run: 17 of OpenBSD
ARM64's 22 build minutes. CI now builds with precompiled headers off.

A checkout dates every source now, so ninja re-ran all 615 steps. The
sources are dated before the cached objects, and only what git says
changed since the commit the cache was built from after them; that
commit is noted in the cache. Commit times would not do: a branch older
than the cache would never rebuild its own changes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-18 12:35:55 +02:00
97 changed files with 2975 additions and 1157 deletions
+333 -96
View File
@@ -22,21 +22,20 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# The x86-64 machines run with hardware virtualization, and also
# cross-compile the arm64 programs here, for the arm64 machines below to run.
# OpenBSD's base compiler has no arm64 backend, so it uses the ports LLVM.
bsd:
name: ${{ matrix.os }} ${{ matrix.version }} ${{ matrix.arch }}
runs-on: ubuntu-latest
timeout-minutes: ${{ matrix.timeout }}
continue-on-error: ${{ matrix.arch == 'arm64' && !inputs.strict }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
include:
- { os: freebsd, version: '15.1', arch: x86-64, timeout: 60 }
- { os: freebsd, version: '15.1', arch: arm64, timeout: 240 }
- { os: openbsd, version: '7.9', arch: x86-64, timeout: 60 }
- { os: openbsd, version: '7.9', arch: arm64, timeout: 240 }
- { os: netbsd, version: '11.0', arch: x86-64, timeout: 60 }
- { os: netbsd, version: '11.0', arch: arm64, timeout: 240 }
- { os: freebsd, version: '15.1', arch: x86-64, cross: true }
- { os: openbsd, version: '7.9', arch: x86-64, cross: true }
- { os: netbsd, version: '11.0', arch: x86-64, cross: true }
defaults:
run:
shell: cpa.sh {0} --sync-files none
@@ -47,16 +46,48 @@ jobs:
submodules: recursive
persist-credentials: false
# The build folder keeps CMake's checks, which ccache cannot: they link.
# The build folders keep CMake's checks, which ccache cannot: they link.
- name: Restore the build cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
.ccache
build
build-arm64
key: build-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
restore-keys: build-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-
# ninja rebuilds by mtime, and a checkout dates every file now. Date them
# before the cached objects instead, and only what changed since the
# commit that build came from after them. Commit times would not do: a
# branch older than the cache would never rebuild its own changes.
- name: Date the sources against the cached build
shell: bash
run: |
old=$(cat build/.reaktor-cache-sha 2>/dev/null || true)
git ls-files -z --recurse-submodules | xargs -0 touch -h -d 2000-01-01T00:00:00Z
if [ -n "$old" ] &&
{ git cat-file -e "$old^{commit}" 2>/dev/null ||
git fetch -q --depth=1 origin "$old" 2>/dev/null; }; then
git diff --name-only -z "$old" HEAD | while IFS= read -r -d '' p; do
if [ -d "$p" ]; then find "$p" -type f -exec touch {} +
elif [ -e "$p" ]; then touch "$p"; fi
done
echo "cached build is from $old; $(git diff --name-only "$old" HEAD | wc -l) paths differ"
else
git ls-files -z --recurse-submodules | xargs -0 touch -h
echo "no cached build to diff against; every source is new"
fi
# The packages the machine downloads, kept so the next run installs without fetching them.
- name: Restore the package cache
id: pkgcache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .pkgcache
key: pkg-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
restore-keys: pkg-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-
- name: Start VM
id: vm
uses: cross-platform-actions/action@e0b9770014ba65d5e0815f15b74031c3a635f641 # v1.6.0
@@ -73,39 +104,133 @@ jobs:
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
mkdir -p .pkgcache
case "$(uname -s)" in
NetBSD)
sudo sed -i.orig 's#^ftp://ftp\.NetBSD\.org#https://cdn.NetBSD.org#' /usr/pkg/etc/pkgin/repositories.conf
sudo rm -rf /var/db/pkgin/cache
sudo ln -s "$PWD/.pkgcache" /var/db/pkgin/cache
;;
esac
case "$(uname -s)" in
FreeBSD)
sudo env IGNORE_OSVERSION=yes pkg install -y \
sudo env IGNORE_OSVERSION=yes PKG_CACHEDIR="$PWD/.pkgcache" pkg install -y \
cmake-core ninja ccache pkgconf dbus xorg-vfbserver xorgproto \
libX11 libXext libXcursor libXi libXfixes libXrandr libXrender libXtst \
libxkbcommon wayland wayland-protocols libglvnd </dev/null
;;
OpenBSD)
sudo pkg_add -I cmake-core ninja ccache dbus libxkbcommon wayland wayland-protocols </dev/null
sudo env PKG_CACHE="$PWD/.pkgcache/" PKG_PATH="$PWD/.pkgcache/:$(cat /etc/installurl)/%c/packages/%a/" pkg_add -I cmake-core ninja ccache dbus libxkbcommon wayland wayland-protocols llvm%21 </dev/null
;;
NetBSD)
sudo -E pkgin -y update </dev/null
sudo -E pkgin -y install cmake ninja-build ccache pkgconf dbus libxkbcommon wayland wayland-protocols </dev/null
sudo -E pkgin -y install cmake ninja-build ccache pkgconf dbus libxkbcommon wayland wayland-protocols \
clang lld llvm </dev/null
;;
esac
sudo chown -R "$(id -u)" .pkgcache
- name: Build
id: build
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
case "$(uname -s)" in
OpenBSD) ulimit -Sd "$(ulimit -Hd)" ;;
esac
uname -a
cc --version
cmake --version
CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=1G
CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=2G
export CCACHE_DIR CCACHE_BASEDIR CCACHE_MAXSIZE
ccache -z
./build.sh -- -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache </dev/null
# SDL compiles through a precompiled header, which ccache will not cache.
./build.sh -- -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
ccache -s
- name: Gather the arm64 sysroot
if: ${{ matrix.cross }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
sh tools/cross/sysroot.sh ${{ matrix.os }} ${{ matrix.version }} "$HOME/sysroot-arm64" </dev/null
- name: Cross-compile for arm64
id: cross
if: ${{ matrix.cross }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
sysroot=$HOME/sysroot-arm64
case "$(uname -s)" in
OpenBSD) ulimit -Sd "$(ulimit -Hd)" ;;
esac
CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=2G
export CCACHE_DIR CCACHE_BASEDIR CCACHE_MAXSIZE
REAKTOR_TARGET_RELEASE=${{ matrix.version }}
export REAKTOR_TARGET_RELEASE
ccache -z
cmake -S . -B build-arm64 -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$PWD/tools/cross/${{ matrix.os }}-aarch64.cmake" \
-DREAKTOR_SYSROOT="$sysroot" \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
cmake --build build-arm64 --parallel 4 </dev/null
cmake --build build-arm64 --target mkicon libreaktor </dev/null
ccache -s
file build-arm64/showcase
file build-arm64/showcase | grep -qi aarch64
if readelf -d build-arm64/showcase | grep -q "$sysroot"; then
echo "the program carries the sysroot's path"; exit 1
fi
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-${{ matrix.os }}-arm64"
cmake --install build-arm64 --prefix "dist/$name" --component libreaktor </dev/null
if grep -rq "$sysroot" "dist/$name/lib/cmake" "dist/$name/lib/pkgconfig"; then
echo "the package carries the sysroot's path"; exit 1
fi
tar -cf cross-${{ matrix.os }}-arm64.tar \
build-arm64/onlaytest build-arm64/keytest build-arm64/a11ytest build-arm64/animtest \
build-arm64/localetest build-arm64/laytest build-arm64/texttest build-arm64/csstest \
build-arm64/showcase build-arm64/notepad build-arm64/simple build-arm64/bench \
build-arm64/licenses build-arm64/CMakeCache.txt "dist/$name"
# Back to the runner now, so the next run finds this build in the cache
# while this one is still testing.
- name: Keep the build
if: ${{ always() && steps.build.outcome == 'success' }}
shell: cpa.sh {0} --sync-files vm-to-runner
run: ':'
- name: Note which commit the cached build is from
if: ${{ always() && steps.build.outcome == 'success' }}
shell: bash
run: git rev-parse HEAD > build/.reaktor-cache-sha
- name: Save the build cache
if: ${{ always() && steps.build.outcome == 'success' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
.ccache
build
build-arm64
key: build-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
- name: Save the package cache
if: ${{ always() && steps.vm.outcome == 'success' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .pkgcache
key: ${{ steps.pkgcache.outputs.cache-primary-key }}
- name: Upload the arm64 build
if: ${{ matrix.cross && steps.cross.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: cross-${{ matrix.os }}-arm64
path: cross-${{ matrix.os }}-arm64.tar
if-no-files-found: error
retention-days: 1
- name: Console tests
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
@@ -126,45 +251,14 @@ jobs:
OpenBSD) xvfb=/usr/X11R6/bin/Xvfb ;;
NetBSD) xvfb=/usr/X11R7/bin/Xvfb ;;
esac
rm -rf smoke
mkdir smoke
"$xvfb" :99 -screen 0 1280x1024x24 -nolisten tcp >smoke/xvfb.log 2>&1 &
xvfb_pid=$!
trap 'kill "$xvfb_pid" 2>/dev/null || :' EXIT
n=0
while [ ! -S /tmp/.X11-unix/X99 ]; do
n=$((n + 1))
if [ "$n" -gt 60 ] || ! kill -0 "$xvfb_pid" 2>/dev/null; then
echo "Xvfb did not start"
cat smoke/xvfb.log || :
exit 1
fi
sleep 1
done
fail=0
shot() {
name=$1
driver=$2
shift 2
if DISPLAY=:99 dbus-run-session -- \
timeout 600 "$@" --video "$driver" \
--shot "smoke/$name.bmp" --a11y-dump "smoke/$name.txt" \
</dev/null >"smoke/$name.log" 2>&1; then
if [ -s "smoke/$name.bmp" ] && [ -s "smoke/$name.txt" ]; then
echo "$name: ok"
return 0
fi
echo "$name: exited 0 without both a shot and a dump"
else
echo "$name: exit status $?"
fi
cat "smoke/$name.log" || :
fail=1
}
shot simple x11 ./build/simple --theme light
shot showcase x11 ./build/showcase --tab 7 --theme dark
shot simple-dummy dummy ./build/simple --theme light
exit "$fail"
sh tools/ci/shots.sh -x "$xvfb" -w "dbus-run-session -- timeout 600" build x11
- name: One copy at a time
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
sh tools/ci/instance.sh -w "dbus-run-session -- timeout 120" build
- name: Build mkicon
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
@@ -180,19 +274,7 @@ jobs:
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
version='${{ inputs.version || 'dev' }}'
name="reaktor-${version#v}-${{ matrix.os }}-${{ matrix.arch }}"
sh tools/package.sh build "dist/$name"
mkdir -p check
for from in "built build" "packed dist/$name"; do
set -- $from
dbus-run-session -- "$2/showcase" --tab 8 --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/built.$e" "check/packed.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
rm -rf "dist/$name"
sh tools/ci/check-package.sh -w "dbus-run-session --" build "reaktor-${version#v}-${{ matrix.os }}-${{ matrix.arch }}"
- name: Check and pack libreaktor
id: libcheck
@@ -201,26 +283,10 @@ jobs:
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-${{ matrix.os }}-${{ matrix.arch }}"
cmake --build build --target libreaktor </dev/null
cmake --install build --prefix "dist/$name" --component libreaktor </dev/null
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
cmake --build build-consumer </dev/null
mkdir -p check
for from in "lib-built build/simple" "lib-linked build-consumer/simple"; do
set -- $from
dbus-run-session -- "$2" --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/lib-built.$e" "check/lib-linked.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
rm -rf "dist/$name" build-consumer
sh tools/ci/check-libreaktor.sh -w "dbus-run-session --" build "libreaktor-${version#v}-${{ matrix.os }}-${{ matrix.arch }}"
- name: Check the libreaktor system package
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' && matrix.arch == 'x86-64' }}
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
@@ -241,15 +307,6 @@ jobs:
if [ -f "$f" ]; then cp "$f" smoke/; fi
done
- name: Save the build cache
if: ${{ always() && steps.build.outcome == 'success' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
.ccache
build
key: build-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
- name: Upload the package
if: ${{ !cancelled() && steps.package.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
@@ -276,3 +333,183 @@ jobs:
path: smoke/
if-no-files-found: warn
retention-days: 14
# The arm64 programs built above, run on an arm64 machine: the tests, the
# shots, the package, and a program linked against libreaktor with the
# machine's own compiler. Nothing is compiled from the tree here.
bsd-arm64:
name: ${{ matrix.os }} ${{ matrix.version }} arm64
needs: bsd
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
timeout-minutes: 60
continue-on-error: ${{ !inputs.strict }}
strategy:
fail-fast: false
matrix:
include:
- { os: freebsd, version: '15.1' }
- { os: openbsd, version: '7.9' }
- { os: netbsd, version: '11.0' }
defaults:
run:
shell: cpa.sh {0} --sync-files none
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: recursive
persist-credentials: false
- name: Download the arm64 build
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: cross-${{ matrix.os }}-arm64
# Unpacked on the runner, before the machine reads the tree.
- name: Unpack the arm64 build
shell: bash
run: |
tar -xf cross-${{ matrix.os }}-arm64.tar
rm cross-${{ matrix.os }}-arm64.tar
chmod +x build-arm64/*
ls -l build-arm64 dist
# The packages the machine downloads, kept so the next run installs without fetching them.
- name: Restore the package cache
id: pkgcache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .pkgcache
key: pkg-${{ matrix.os }}-${{ matrix.version }}-arm64-${{ github.run_id }}
restore-keys: pkg-${{ matrix.os }}-${{ matrix.version }}-arm64-
- name: Start VM
id: vm
uses: cross-platform-actions/action@e0b9770014ba65d5e0815f15b74031c3a635f641 # v1.6.0
with:
operating_system: ${{ matrix.os }}
version: ${{ matrix.version }}
architecture: arm64
shell: sh
cpu_count: 4
memory: 8G
sync_files: runner-to-vm
- name: Install packages
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
mkdir -p .pkgcache
case "$(uname -s)" in
NetBSD)
sudo sed -i.orig 's#^ftp://ftp\.NetBSD\.org#https://cdn.NetBSD.org#' /usr/pkg/etc/pkgin/repositories.conf
sudo rm -rf /var/db/pkgin/cache
sudo ln -s "$PWD/.pkgcache" /var/db/pkgin/cache
;;
esac
case "$(uname -s)" in
FreeBSD)
sudo env IGNORE_OSVERSION=yes PKG_CACHEDIR="$PWD/.pkgcache" pkg install -y \
cmake-core ninja pkgconf dbus xorg-vfbserver \
libX11 libXext libXcursor libXi libXfixes libXrandr libXrender libXtst \
libxkbcommon wayland libglvnd </dev/null
;;
NetBSD)
sudo -E pkgin -y update </dev/null
sudo -E pkgin -y install cmake ninja-build pkgconf dbus libxkbcommon wayland </dev/null
;;
OpenBSD)
sudo env PKG_CACHE="$PWD/.pkgcache/" PKG_PATH="$PWD/.pkgcache/:$(cat /etc/installurl)/%c/packages/%a/" pkg_add -I cmake-core ninja dbus libxkbcommon wayland </dev/null
;;
esac
sudo chown -R "$(id -u)" .pkgcache
uname -a
file build-arm64/showcase
- name: Keep the packages
if: ${{ always() && steps.vm.outcome == 'success' }}
shell: cpa.sh {0} --sync-files vm-to-runner
run: ':'
- name: Save the package cache
if: ${{ always() && steps.vm.outcome == 'success' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .pkgcache
key: ${{ steps.pkgcache.outputs.cache-primary-key }}
- name: Console tests
id: tests
run: |
fail=0
for t in onlaytest keytest a11ytest animtest localetest laytest texttest csstest; do
echo "== $t"
if ./build-arm64/$t </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
done
exit "$fail"
- name: Shots and dumps
if: ${{ !cancelled() && steps.vm.outcome == 'success' }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
case "$(uname -s)" in
FreeBSD) xvfb=/usr/local/bin/Xvfb ;;
OpenBSD) xvfb=/usr/X11R6/bin/Xvfb ;;
NetBSD) xvfb=/usr/X11R7/bin/Xvfb ;;
esac
sh tools/ci/shots.sh -x "$xvfb" -w "dbus-run-session -- timeout 600" build-arm64 x11
- name: Package
id: package
if: ${{ !cancelled() && steps.vm.outcome == 'success' }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
version='${{ inputs.version || 'dev' }}'
sh tools/ci/check-package.sh -w "dbus-run-session --" build-arm64 "reaktor-${version#v}-${{ matrix.os }}-arm64"
- name: Check and pack libreaktor
id: libcheck
if: ${{ !cancelled() && steps.vm.outcome == 'success' }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
version='${{ inputs.version || 'dev' }}'
sh tools/ci/check-libreaktor.sh -i -w "dbus-run-session --" build-arm64 "libreaktor-${version#v}-${{ matrix.os }}-arm64"
- name: Collect the shots
if: ${{ always() && steps.vm.outcome == 'success' }}
shell: cpa.sh {0} --sync-files vm-to-runner
run: |
mkdir -p smoke
if [ -f build-arm64/CMakeCache.txt ]; then cp build-arm64/CMakeCache.txt smoke/; fi
- name: Upload the package
if: ${{ !cancelled() && steps.package.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-${{ matrix.os }}-arm64
path: dist/reaktor-*.tar.gz
if-no-files-found: error
retention-days: 14
- name: Upload libreaktor
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-libreaktor-${{ matrix.os }}-arm64
path: dist/libreaktor-*.tar.gz
if-no-files-found: error
retention-days: 14
- name: Upload the shots
if: ${{ always() && steps.vm.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: bsd-${{ matrix.os }}-${{ matrix.version }}-arm64
path: smoke/
if-no-files-found: warn
retention-days: 14
+81 -84
View File
@@ -34,10 +34,8 @@ jobs:
- { arch: x86-64, platform: linux/amd64, image: 'debian:bookworm', runner: ubuntu-24.04, emulated: false, timeout: 60 }
- { arch: x86, platform: linux/386, image: 'debian:bookworm', runner: ubuntu-24.04, emulated: false, timeout: 60 }
- { arch: arm64, platform: linux/arm64, image: 'debian:bookworm', runner: ubuntu-24.04-arm, emulated: false, timeout: 60 }
- { arch: armhf, platform: linux/arm/v7, image: 'debian:bookworm', runner: ubuntu-24.04, emulated: true, timeout: 240 }
- { arch: riscv64, platform: linux/riscv64, image: 'debian:trixie', runner: ubuntu-24.04, emulated: true, timeout: 240 }
steps:
steps: &linux-steps
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: recursive
@@ -66,21 +64,68 @@ jobs:
libx11-dev libxext-dev libxcursor-dev libxi-dev libxfixes-dev \
libxrandr-dev libxrender-dev libxtst-dev libxkbcommon-dev \
libwayland-dev wayland-protocols libegl-dev libdbus-1-dev \
dbus xvfb xauth </dev/null
dbus xvfb xauth ccache </dev/null
EOF
# ccache only: the build folder is rebuilt, so a stale cache cannot hide a broken one.
- name: Restore the compiler cache
id: ccache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .ccache
key: ccache-linux-${{ matrix.arch }}-${{ matrix.image }}-${{ github.run_id }}
restore-keys: ccache-linux-${{ matrix.arch }}-${{ matrix.image }}-
# The emulated architectures are compiled by a native x86-64 Debian with
# Debian's cross compilers, in the same checkout; the emulated machine
# then only runs what was built.
- name: Start the cross builder
if: ${{ matrix.emulated }}
run: |
docker run -d --name builder --platform linux/amd64 -v "$PWD:/src" -w /src ${{ matrix.image }} sleep infinity
docker exec -i -e A=${{ matrix.debarch }} builder sh -eu <<'EOF'
export DEBIAN_FRONTEND=noninteractive
dpkg --add-architecture "$A"
apt-get update </dev/null
apt-get install -y --no-install-recommends cmake ninja-build pkgconf file ccache crossbuild-essential-"$A" libwayland-bin wayland-protocols libx11-dev:"$A" libxext-dev:"$A" libxcursor-dev:"$A" libxi-dev:"$A" libxfixes-dev:"$A" libxrandr-dev:"$A" libxrender-dev:"$A" libxtst-dev:"$A" libxkbcommon-dev:"$A" libwayland-dev:"$A" libegl-dev:"$A" libdbus-1-dev:"$A" </dev/null
EOF
- name: Build
id: build
run: |
docker exec -i debian sh -eu <<'EOF'
ctr=debian
cross=""
if [ "${{ matrix.emulated }}" = true ]; then
ctr=builder
cross="-DCMAKE_TOOLCHAIN_FILE=/src/tools/cross/linux-cross.cmake -DREAKTOR_CROSS_TRIPLE=${{ matrix.triple }}"
fi
version='${{ inputs.version || 'dev' }}'
docker exec -i -e CROSS="$cross" -e TRIPLE="${{ matrix.triple }}" -e LIBNAME="libreaktor-${version#v}-linux-${{ matrix.arch }}" "$ctr" sh -eu <<'EOF'
uname -a
cc --version
cmake --version
./build.sh </dev/null
export CCACHE_DIR=/src/.ccache CCACHE_BASEDIR=/src CCACHE_MAXSIZE=500M
ccache -z
./build.sh -- -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON $CROSS </dev/null
cmake --build build --target libreaktor </dev/null
ccache -s
file build/showcase
echo "needs $(objdump -T build/showcase | grep -o 'GLIBC_[0-9.]*' | sort -uV | tail -1)"
dump=objdump
if [ -n "$CROSS" ]; then
dump=$TRIPLE-objdump
# The emulated machine has none of the cross compiler's headers, so
# anything that builds stays here.
cmake --install build --prefix "dist/$LIBNAME" --component libreaktor </dev/null
fi
echo "needs $($dump -T build/showcase | grep -o 'GLIBC_[0-9.]*' | sort -uV | tail -1)"
EOF
- name: Save the compiler cache
if: ${{ always() && steps.build.outcome == 'success' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .ccache
key: ${{ steps.ccache.outputs.cache-primary-key }}
- name: Console tests
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
@@ -96,67 +141,18 @@ jobs:
- name: Shots and dumps
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
docker exec -i debian sh -u <<'EOF'
rm -rf smoke
mkdir smoke
Xvfb :99 -screen 0 1280x1024x24 -nolisten tcp </dev/null >smoke/xvfb.log 2>&1 &
xvfb_pid=$!
trap 'kill "$xvfb_pid" 2>/dev/null || :' EXIT
n=0
while [ ! -S /tmp/.X11-unix/X99 ]; do
n=$((n + 1))
if [ "$n" -gt 120 ] || ! kill -0 "$xvfb_pid" 2>/dev/null; then
echo "Xvfb did not start"
cat smoke/xvfb.log || :
exit 1
fi
sleep 1
done
fail=0
shot() {
name=$1
driver=$2
shift 2
if DISPLAY=:99 dbus-run-session -- \
timeout 600 "$@" --video "$driver" \
--shot "smoke/$name.bmp" --a11y-dump "smoke/$name.txt" \
</dev/null >"smoke/$name.log" 2>&1; then
if [ -s "smoke/$name.bmp" ] && [ -s "smoke/$name.txt" ]; then
echo "$name: ok"
return 0
fi
echo "$name: exited 0 without both a shot and a dump"
else
echo "$name: exit status $?"
fi
cat "smoke/$name.log" || :
fail=1
}
shot simple x11 ./build/simple --theme light
shot showcase x11 ./build/showcase --tab 7 --theme dark
shot simple-dummy dummy ./build/simple --theme light
exit "$fail"
EOF
docker exec -i debian sh -u tools/ci/shots.sh -x Xvfb -w "dbus-run-session -- timeout 600" build x11 </dev/null
- name: One copy at a time
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
run: docker exec -i debian sh tools/ci/instance.sh -w "dbus-run-session -- timeout 120" build </dev/null
- name: Package
id: package
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
version='${{ inputs.version || 'dev' }}'
name="reaktor-${version#v}-linux-${{ matrix.arch }}"
docker exec -i -e name="$name" debian sh -eu <<'EOF'
sh tools/package.sh build "dist/$name"
mkdir -p check
for from in "built build" "packed dist/$name"; do
set -- $from
timeout 600 "$2/showcase" --tab 8 --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/built.$e" "check/packed.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
EOF
docker exec -i debian sh -eu tools/ci/check-package.sh -w "timeout 600" build "reaktor-${version#v}-linux-${{ matrix.arch }}" </dev/null
- name: Upload the package
if: ${{ !cancelled() && steps.package.outcome == 'success' }}
@@ -172,32 +168,19 @@ jobs:
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-linux-${{ matrix.arch }}"
docker exec -i -e name="$name" debian sh -eu <<'EOF'
cmake --build build --target libreaktor </dev/null
cmake --install build --prefix "dist/$name" --component libreaktor </dev/null
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
cmake --build build-consumer </dev/null
mkdir -p check
for from in "lib-built build/simple" "lib-linked build-consumer/simple"; do
set -- $from
timeout 600 "$2" --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/lib-built.$e" "check/lib-linked.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
EOF
installed=""
if [ "${{ matrix.emulated }}" = true ]; then installed=-i; fi
docker exec -i debian sh -eu tools/ci/check-libreaktor.sh $installed -w "timeout 600" build "libreaktor-${version#v}-linux-${{ matrix.arch }}" </dev/null
- name: Pack libreaktor as a .deb
id: deb
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
run: |
docker exec -i debian sh -eu <<'EOF'
sh tools/libreaktor-pkg.sh -f deb -b build -o dist-pkg </dev/null
EOF
if [ "${{ matrix.emulated }}" = true ]; then
docker exec -i builder sh -eu tools/libreaktor-pkg.sh -f deb -b build -o dist-pkg -a ${{ matrix.debarch }} </dev/null
else
docker exec -i debian sh -eu tools/libreaktor-pkg.sh -f deb -b build -o dist-pkg </dev/null
fi
- name: Upload the .deb
if: ${{ !cancelled() && steps.deb.outcome == 'success' }}
@@ -267,6 +250,20 @@ jobs:
if-no-files-found: warn
retention-days: 14
linux-emulated:
name: linux ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
timeout-minutes: ${{ matrix.timeout }}
continue-on-error: ${{ matrix.emulated && !inputs.strict }}
strategy:
fail-fast: false
matrix:
include:
- { arch: armhf, platform: linux/arm/v7, image: 'debian:bookworm', runner: ubuntu-24.04, emulated: true, timeout: 240, triple: arm-linux-gnueabihf, debarch: armhf }
- { arch: riscv64, platform: linux/riscv64, image: 'debian:trixie', runner: ubuntu-24.04, emulated: true, timeout: 240, triple: riscv64-linux-gnu, debarch: riscv64 }
steps: *linux-steps
rpm:
name: linux rpm ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
+28 -29
View File
@@ -39,7 +39,16 @@ jobs:
- name: Install packages
env:
HOMEBREW_NO_AUTO_UPDATE: 1
run: brew install ninja
run: brew install ninja ccache
# ccache only: the build folder is rebuilt, so a stale cache cannot hide a broken one.
- name: Restore the compiler cache
id: ccache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .ccache
key: ccache-macos-${{ matrix.arch }}-${{ github.run_id }}
restore-keys: ccache-macos-${{ matrix.arch }}-
- name: Build
id: build
@@ -48,9 +57,19 @@ jobs:
sw_vers
cc --version
cmake --version
./build.sh </dev/null
export CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=500M
ccache -z
./build.sh -- -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
ccache -s
file build/showcase
- name: Save the compiler cache
if: ${{ always() && steps.build.outcome == 'success' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .ccache
key: ${{ steps.ccache.outputs.cache-primary-key }}
- name: Console tests
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
@@ -63,32 +82,11 @@ jobs:
- name: Shots and dumps
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
rm -rf smoke
mkdir smoke
fail=0
shot() {
name=$1
driver=$2
shift 2
if "$@" --video "$driver" \
--shot "smoke/$name.bmp" --a11y-dump "smoke/$name.txt" \
</dev/null >"smoke/$name.log" 2>&1; then
if [ -s "smoke/$name.bmp" ] && [ -s "smoke/$name.txt" ]; then
echo "$name: ok"
return 0
fi
echo "$name: exited 0 without both a shot and a dump"
else
echo "$name: exit status $?"
fi
cat "smoke/$name.log" || :
fail=1
}
shot simple cocoa ./build/simple --theme light
shot showcase cocoa ./build/showcase --tab 7 --theme dark
shot simple-dummy dummy ./build/simple --theme light
exit "$fail"
run: sh tools/ci/shots.sh build cocoa
- name: One copy at a time
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: sh tools/ci/instance.sh build
- name: Package
id: package
@@ -155,7 +153,8 @@ jobs:
- name: Check an app that embeds Reaktor
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
cmake -S examples/embedded -B build-embedded -G Ninja -DCMAKE_BUILD_TYPE=Release </dev/null
export CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=500M
cmake -S examples/embedded -B build-embedded -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
cmake --build build-embedded --target simple </dev/null
mkdir -p check
for from in "tree build/simple" "embedded build-embedded/simple"; do
+1 -1
View File
@@ -123,7 +123,7 @@ jobs:
systems and architectures, \`libreaktor-$v-<system>-<arch>\`, and
\`libreaktor-$v-wasm.tar.gz\`. Each holds one static library (\`reaktor.lib\`
on Windows, built against the DLL C runtime; \`libreaktor.a\` elsewhere)
with SDL, libcss, plutosvg, Onlay, NukAnim, mojibake and kb_text_shape
with SDL, libcss, plutosvg, Onlay, NukAnim, mojibake, kb_text_shape and PDFGen
inside it, the public headers (\`#include "reaktor/reaktor.h"\`, with
Nuklear's, NukAnim's and SDL's), a CMake package and a pkg-config file,
and the licenses.
+42 -5
View File
@@ -32,15 +32,52 @@ jobs:
submodules: recursive
persist-credentials: false
- name: Restore emsdk
id: emsdk
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/emsdk
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}
# ccache only: the build folder is rebuilt, so a stale cache cannot hide a broken one.
- name: Restore the compiler cache
id: ccache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .ccache
key: ccache-web-${{ env.EMSCRIPTEN_VERSION }}-${{ github.run_id }}
restore-keys: ccache-web-${{ env.EMSCRIPTEN_VERSION }}-
- name: Install emsdk
run: |
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
"$HOME/emsdk/emsdk" install "$EMSCRIPTEN_VERSION"
if [ ! -d "$HOME/emsdk" ]; then
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
"$HOME/emsdk/emsdk" install "$EMSCRIPTEN_VERSION"
fi
"$HOME/emsdk/emsdk" activate "$EMSCRIPTEN_VERSION"
sudo apt-get update && sudo apt-get install -y ninja-build
sudo apt-get update && sudo apt-get install -y ninja-build ccache
- name: Save emsdk
if: ${{ steps.emsdk.outputs.cache-hit != 'true' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/emsdk
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}
- name: Build
run: EMSDK="$HOME/emsdk" ./build-wasm.sh
id: build
run: |
export CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=500M
ccache -z
EMSDK="$HOME/emsdk" ./build-wasm.sh -- -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON
ccache -s
- name: Save the compiler cache
if: ${{ always() && steps.build.outcome == 'success' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .ccache
key: ${{ steps.ccache.outputs.cache-primary-key }}
- name: Package
run: |
@@ -54,7 +91,7 @@ jobs:
cp build-wasm/keylog.js build-wasm/reaktor-icon.svg build-wasm/reaktor-icon.png \
"dist/$name/"
cp build-wasm/licenses/*.txt "dist/$name/licenses/"
cp external/bamboocss/LICENSE "dist/$name/licenses/bamboocss.txt"
cp external/simplecss/LICENSE "dist/$name/licenses/simplecss.txt"
cp assets/fonts/Aileron-Notice.txt assets/fonts/MPLUS1p-Notice.txt \
"dist/$name/licenses/"
cp docs/NOTICE.md "dist/$name/"
+80 -2
View File
@@ -22,6 +22,10 @@ jobs:
windows:
name: windows ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
env:
CCACHE_DIR: ${{ github.workspace }}\.ccache
CCACHE_BASEDIR: ${{ github.workspace }}
CCACHE_MAXSIZE: 500M
timeout-minutes: 60
strategy:
fail-fast: false
@@ -40,9 +44,52 @@ jobs:
submodules: recursive
persist-credentials: false
# ccache's own release, pinned and checked; without it the build only runs uncached.
- name: Install ccache
id: ccache-tool
run: |
$ProgressPreference = 'SilentlyContinue'
$v = '4.14.1'
if ($env:RUNNER_ARCH -eq 'ARM64') {
$a = 'aarch64'; $sum = '28121851c8c2c8b76214cfc5e119d769fbc39e93d27862e4e3a556905ebd23b2'
} else {
$a = 'x86_64'; $sum = '6219f3865ca59aec41ee4b678df171d5d35855ecb2b6dbbbd20690b3a68af7b4'
}
$zip = Join-Path $env:RUNNER_TEMP "ccache.zip"
try {
Invoke-WebRequest -Uri "https://github.com/ccache/ccache/releases/download/v$v/ccache-$v-windows-$a.zip" `
-OutFile $zip -MaximumRetryCount 3 -RetryIntervalSec 5
if ((Get-FileHash -Algorithm SHA256 $zip).Hash -ne $sum) { throw "ccache-$v-windows-$a.zip: checksum mismatch" }
Expand-Archive $zip -DestinationPath $env:RUNNER_TEMP
$dir = Join-Path $env:RUNNER_TEMP "ccache-$v-windows-$a"
& "$dir/ccache.exe" --version | Select-Object -First 1
Add-Content $env:GITHUB_PATH $dir
"use=true" >> $env:GITHUB_OUTPUT
} catch {
Write-Host "::warning::ccache unavailable, building without it: $_"
"use=false" >> $env:GITHUB_OUTPUT
}
# ccache only: the build folder is rebuilt, so a stale cache cannot hide a broken one.
- name: Restore the compiler cache
id: ccache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .ccache
key: ccache-windows-${{ matrix.arch }}-${{ github.run_id }}
restore-keys: ccache-windows-${{ matrix.arch }}-
# Release objects carry no debug info, which is what lets ccache take MSVC's.
- name: Build
id: build
run: ./build.ps1 -Arch ${{ matrix.arch }} '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded'
run: |
$launch = @()
if ('${{ steps.ccache-tool.outputs.use }}' -eq 'true') {
ccache -z
$launch = '-DCMAKE_C_COMPILER_LAUNCHER=ccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache', '-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON'
}
./build.ps1 -Arch ${{ matrix.arch }} '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded' @launch
if ('${{ steps.ccache-tool.outputs.use }}' -eq 'true') { ccache -s }
- name: Console tests
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
@@ -86,6 +133,25 @@ jobs:
Shot simple-dummy dummy "./${{ matrix.out }}/simple.exe" @('--theme', 'light')
exit $script:fail
- name: One copy at a time
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
New-Item -ItemType Directory -Force smoke | Out-Null
$exe = "./${{ matrix.out }}/showcase.exe"
$first = Start-Process $exe -ArgumentList '--video', 'dummy', '--log', 'smoke/instance.log' -PassThru
Start-Sleep -Seconds 5
$second = Start-Process $exe -ArgumentList '--video', 'dummy', 'handed-over.txt' -PassThru
if (-not $second.WaitForExit(60000)) { $second.Kill(); throw "the second launch did not exit" }
if ($second.ExitCode -ne 0) { throw "the second launch exited with $($second.ExitCode)" }
Start-Sleep -Seconds 2
if ($first.HasExited) { throw "the running copy is gone" }
# The log is held open until the copy ends.
$first.Kill(); $first.WaitForExit()
if (-not (Select-String -Path smoke/instance.log -Pattern 'handed-over.txt' -Quiet)) {
Get-Content smoke/instance.log; throw "the running copy did not get the file"
}
Write-Host "second launch handed its file over: ok"
- name: Package
id: package
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
@@ -129,7 +195,19 @@ jobs:
- name: Build libreaktor
id: lib
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: ./build.ps1 -Arch ${{ matrix.arch }} -Out build-lib libreaktor
run: |
$launch = @()
if ('${{ steps.ccache-tool.outputs.use }}' -eq 'true') {
$launch = '-DCMAKE_C_COMPILER_LAUNCHER=ccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache', '-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON'
}
./build.ps1 -Arch ${{ matrix.arch }} -Out build-lib libreaktor @launch
- name: Save the compiler cache
if: ${{ always() && steps.build.outcome == 'success' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .ccache
key: ${{ steps.ccache.outputs.cache-primary-key }}
- name: Check and zip libreaktor
id: libcheck
+6 -6
View File
@@ -28,12 +28,12 @@
[submodule "external/mglibs"]
path = external/mglibs
url = https://github.com/mattiasgustavsson/libs.git
[submodule "external/libharu"]
path = external/libharu
url = https://github.com/libharu/libharu.git
[submodule "external/watercss"]
path = external/watercss
url = https://github.com/kognise/water.css
[submodule "external/bamboocss"]
path = external/bamboocss
url = https://github.com/rilwis/bamboo
[submodule "external/simplecss"]
path = external/simplecss
url = https://github.com/kevquirk/simple.css
[submodule "external/pdfgen"]
path = external/pdfgen
url = https://github.com/AndreRenaud/PDFGen
+3 -2
View File
@@ -61,7 +61,8 @@ regression oracle for every layout or style change.
corners, and its runs cut from the mask's middle texels, which hold a
straight band so a run is sharp and as thick as its corners at any scale.
- **A rounded fill is jagged unless it is a mask.** Fill anti-aliasing is off
on every renderer, so a fill with corners goes through `reaktor_fill_round`,
on the software renderer, the default (`.anti_aliasing` and `--aa` decide;
a GPU renderer has it on), so a fill with corners goes through `reaktor_fill_round`,
and `reaktor_render` swaps each one Nuklear drew itself for masks, relinking
the built command list — whose end is wherever a `next` reaches
`ctx->memory.allocated`.
@@ -113,7 +114,7 @@ regression oracle for every layout or style change.
and its `src/parts/`, and the seven Ionicons the widgets draw (three chevrons, three discs, the
toast's close cross) are compiled in byte for byte, beside the Aileron
fonts, the mark and reaktor.css. Nothing else from a submodule is — not the
rest of Ionicons, not Bamboo.
rest of Ionicons, not Simple.css.
- Applications see only `include/reaktor/`. The samples include
`reaktor/reaktor.h` and `reaktor/main.h`, nothing from `core/`, and
`App` is opaque to them; what a sample needs becomes a public call there.
+45 -23
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(reaktor VERSION 0.6.0 LANGUAGES C CXX)
project(reaktor VERSION 0.7.0 LANGUAGES C CXX)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(_reaktor_top ON)
@@ -37,8 +37,8 @@ foreach(drv RENDER_D3D RENDER_D3D12 RENDER_VULKAN VULKAN)
set(SDL_${drv} OFF CACHE BOOL "" FORCE)
endforeach()
option(REAKTOR_SDL_GL "Build SDL's OpenGL/GLES drivers on Linux and the BSDs" OFF)
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT REAKTOR_SDL_GL)
option(REAKTOR_SDL_GL "Build SDL's OpenGL/GLES drivers on Windows, Linux and the BSDs" OFF)
if((WIN32 OR (UNIX AND NOT APPLE)) AND NOT EMSCRIPTEN AND NOT REAKTOR_SDL_GL)
set(SDL_OPENGL OFF CACHE BOOL "" FORCE)
set(SDL_OPENGLES OFF CACHE BOOL "" FORCE)
endif()
@@ -53,6 +53,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
set(SDL_DEPS_SHARED OFF CACHE BOOL "" FORCE)
endif()
# A static program keeps only the functions it calls; MSVC's Release does this already.
if(NOT MSVC AND NOT EMSCRIPTEN)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
add_subdirectory("${TP}/SDL" EXCLUDE_FROM_ALL)
set(LC "${TP}/lcui/lib")
@@ -193,6 +197,7 @@ target_include_directories(reaktor_headers INTERFACE include "${TP}/nuklear" "${
add_library(reaktor_core STATIC
core/base/util.c
core/render/nk_impl.c
core/render/svg.c
"${_builtins}")
target_include_directories(reaktor_core PUBLIC core/base core/render)
@@ -226,7 +231,7 @@ if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
endif()
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(animtest tests/animtest.c core/anim/anim.c core/render/nk_impl.c)
add_executable(animtest tests/animtest.c core/anim/anim.c)
target_include_directories(animtest PRIVATE core/anim core/render
"${TP}/nuklear/demo/sdl3_renderer")
target_link_libraries(animtest PRIVATE reaktor_core SDL3::SDL3-static)
@@ -251,6 +256,7 @@ if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(csstest tests/csstest.c core/css/cssflat.c)
target_include_directories(csstest PRIVATE core/css core/base)
target_link_libraries(csstest PRIVATE plutovg)
target_compile_definitions(csstest PRIVATE _CRT_SECURE_NO_WARNINGS)
set_target_properties(csstest PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
@@ -295,14 +301,14 @@ option(REAKTOR_A11Y
set(_a11y "${CMAKE_CURRENT_SOURCE_DIR}/platform/a11y")
add_library(reaktor_a11y_none INTERFACE)
target_sources(reaktor_a11y_none INTERFACE "${_a11y}/a11y_none.c")
target_sources(reaktor_a11y_none INTERFACE "${_a11y}/a11y_none.c" "${_a11y}/a11y_window_none.c")
add_library(reaktor_a11y INTERFACE)
if(NOT REAKTOR_A11Y)
target_link_libraries(reaktor_a11y INTERFACE reaktor_a11y_none)
message(STATUS "a11y: off; the tree is built and served to nothing")
elseif(EMSCRIPTEN)
target_sources(reaktor_a11y INTERFACE "${_a11y}/a11y_web.c")
target_sources(reaktor_a11y INTERFACE "${_a11y}/a11y_web.c" "${_a11y}/a11y_window_none.c")
elseif(WIN32)
target_sources(reaktor_a11y INTERFACE
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_win32.c")
@@ -315,7 +321,8 @@ elseif(APPLE)
target_compile_definitions(reaktor_a11y_macos PRIVATE REAKTOR_HAVE_NSACCESSIBILITY)
target_link_libraries(reaktor_a11y_macos PRIVATE reaktor_runtime)
target_sources(reaktor_a11y INTERFACE
"${_a11y}/a11y_snapshot.c" "$<TARGET_OBJECTS:reaktor_a11y_macos>")
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_window_none.c"
"$<TARGET_OBJECTS:reaktor_a11y_macos>")
target_compile_definitions(reaktor_a11y INTERFACE REAKTOR_HAVE_NSACCESSIBILITY)
target_link_libraries(reaktor_a11y INTERFACE "-framework Cocoa")
else()
@@ -325,7 +332,7 @@ else()
endif()
if(REAKTOR_DBUS_FOUND)
target_sources(reaktor_a11y INTERFACE
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_atspi.c")
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_window_none.c" "${_a11y}/a11y_atspi.c")
target_compile_definitions(reaktor_a11y INTERFACE REAKTOR_HAVE_ATSPI)
target_link_libraries(reaktor_a11y INTERFACE PkgConfig::REAKTOR_DBUS)
message(STATUS "a11y: AT-SPI over libdbus ${REAKTOR_DBUS_VERSION}")
@@ -421,7 +428,7 @@ else()
message(STATUS "text: shaping by kb_text_shape; direction and line breaking by mojibake")
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(texttest tests/texttest.c core/render/nk_impl.c)
add_executable(texttest tests/texttest.c)
target_link_libraries(texttest PRIVATE reaktor_headers)
target_include_directories(texttest PRIVATE core/render core/text)
target_link_libraries(texttest PRIVATE reaktor_text reaktor_core
@@ -491,12 +498,13 @@ else()
target_compile_definitions(reaktor_notify INTERFACE REAKTOR_HAVE_DBUS)
target_link_libraries(reaktor_notify INTERFACE PkgConfig::REAKTOR_DBUS)
else()
target_link_libraries(reaktor_notify INTERFACE reaktor_notify_none)
message(STATUS "notify: no dbus-1; notifications are not sent")
endif()
endif()
endif()
option(REAKTOR_PRINT "Printing and PDF export, through libHaru" ON)
option(REAKTOR_PRINT "Printing and PDF export, through PDFGen" ON)
add_library(reaktor_print_none INTERFACE)
target_sources(reaktor_print_none INTERFACE
@@ -506,20 +514,17 @@ if(NOT REAKTOR_PRINT OR EMSCRIPTEN)
target_link_libraries(reaktor_print INTERFACE reaktor_print_none)
message(STATUS "print: off")
else()
file(GLOB _hpdf_src CONFIGURE_DEPENDS "${TP}/libharu/src/hpdf_*.c")
configure_file("${TP}/libharu/include/hpdf_config.h.cmake"
"${CMAKE_BINARY_DIR}/hpdf/hpdf_config.h")
add_library(hpdf STATIC ${_hpdf_src})
target_include_directories(hpdf PUBLIC "${TP}/libharu/include" "${CMAKE_BINARY_DIR}/hpdf")
add_library(pdfgen STATIC "${CMAKE_CURRENT_SOURCE_DIR}/runtime/pdfgen_unit.c")
target_include_directories(pdfgen PUBLIC "${TP}/pdfgen")
if(MSVC)
target_compile_options(hpdf PRIVATE /w)
target_compile_definitions(hpdf PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_options(pdfgen PRIVATE /w)
target_compile_definitions(pdfgen PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(hpdf PRIVATE -w)
target_link_libraries(hpdf PUBLIC m)
target_compile_options(pdfgen PRIVATE -w)
target_link_libraries(pdfgen PUBLIC m)
endif()
target_sources(reaktor_print INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/runtime/print.c")
target_link_libraries(reaktor_print INTERFACE hpdf plutovg)
target_link_libraries(reaktor_print INTERFACE pdfgen plutovg)
if(WIN32)
target_link_libraries(reaktor_print INTERFACE comdlg32 gdi32)
elseif(APPLE)
@@ -537,7 +542,6 @@ add_library(reaktor_runtime STATIC
core/base/metrics.c
core/css/style.c
core/css/cssflat.c
core/render/nk_impl.c
core/render/draw.c
core/ui/declare.c
core/ui/controls.c
@@ -554,6 +558,7 @@ add_library(reaktor_runtime STATIC
platform/lifecycle.c
runtime/app.c
runtime/input.c
runtime/instance.c
runtime/services.c
runtime/undo.c
runtime/window.c)
@@ -595,7 +600,7 @@ set(REAKTOR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "")
foreach(_lic SDL/LICENSE.txt lcui/LICENSE.TXT plutosvg/LICENSE nuklear/LICENSE
nukanim/LICENSE onlay/LICENSE watercss/LICENSE.md ionicons/LICENSE mojibake/LICENSE
kb/LICENSE libharu/LICENSE)
kb/LICENSE pdfgen/LICENSE)
string(REGEX REPLACE "/.*" "" _who "${_lic}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/${_lic}"
"${CMAKE_BINARY_DIR}/licenses/${_who}.txt" COPYONLY)
@@ -629,6 +634,10 @@ function(reaktor_add_app name)
target_link_libraries(${name} PRIVATE reaktor_runtime ${_mods})
if(MSVC)
target_compile_options(${name} PRIVATE /we4013)
elseif(APPLE)
target_link_options(${name} PRIVATE -Wl,-dead_strip)
elseif(NOT EMSCRIPTEN)
target_link_options(${name} PRIVATE -Wl,--gc-sections)
endif()
set_target_properties(${name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
@@ -829,7 +838,7 @@ target_link_libraries(reaktor_modules PRIVATE reaktor_runtime reaktor_a11y reakt
set_target_properties(reaktor_modules PROPERTIES EXCLUDE_FROM_ALL ON)
set(_parts reaktor_runtime reaktor_core reaktor_modules plutosvg plutovg lcui onlay SDL3-static)
foreach(_t mojibake_lib kb_text_shape hpdf)
foreach(_t mojibake_lib kb_text_shape pdfgen)
if(TARGET ${_t})
list(APPEND _parts ${_t})
endif()
@@ -959,6 +968,19 @@ function(reaktor_outside_links)
endif()
endforeach()
list(REMOVE_DUPLICATES _named)
# A cross build found them under the sysroot; the package names where they are on the target.
if(CMAKE_SYSROOT)
set(_stripped "")
foreach(_d IN LISTS _dirs)
string(FIND "${_d}" "${CMAKE_SYSROOT}" _in_sysroot)
if(_in_sysroot EQUAL 0)
string(LENGTH "${CMAKE_SYSROOT}" _n)
string(SUBSTRING "${_d}" ${_n} -1 _d)
endif()
list(APPEND _stripped "${_d}")
endforeach()
set(_dirs ${_stripped})
endif()
list(REMOVE_DUPLICATES _dirs)
foreach(_d IN LISTS CMAKE_C_IMPLICIT_LINK_DIRECTORIES CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
list(REMOVE_ITEM _dirs "${_d}")
+10
View File
@@ -5,6 +5,16 @@
--table-bg-alt: var(--background-alt);
}
@media (prefers-contrast: more) {
:root {
--text-main: var(--text-bright);
--text-muted: var(--text-bright);
--form-placeholder: var(--text-bright);
--border: var(--text-bright);
--focus: var(--links);
}
}
h4 {
font-size: 19px;
font-weight: 700;
Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 53 KiB

+2 -1
View File
@@ -28,7 +28,8 @@ the command that builds it.
Reaktor runs three times — `reaktor-software`, its default, and
`reaktor-d3d11` and `reaktor-opengl`, the same binary on SDL's GPU drivers
(`run.sh` adds `reaktor-metal` on macOS). The others draw on the GPU, so those
two are the like-for-like comparison.
two are the like-for-like comparison. SDL's OpenGL driver is built only with
`-DREAKTOR_SDL_GL=ON`, which the `reaktor-opengl` arm's build passes.
## What every arm draws
+1 -1
View File
@@ -32,7 +32,7 @@ function Get-Arm([string]$name) {
@{ exe = Join-Path $root "build\bench.exe"
args = @("--renderer", "opengl")
dir = $root
make = "./build.ps1 bench" }
make = "./build.ps1 bench -DREAKTOR_SDL_GL=ON" }
}
"shaft" {
@{ exe = Join-Path $here "shaft-bench\.build\release\ShaftBench.exe"
+6 -2
View File
@@ -1,8 +1,12 @@
param([string]$Target = "", [ValidateSet("", "x64", "x86", "arm64")][string]$Arch = "",
[string]$Out = "", [string]$Source = "")
param([string]$Target = "", [string]$Arch = "", [string]$Out = "", [string]$Source = "")
$extra = @($args)
# CMake options bind to whichever positional parameters are left.
if ($Source -like '-*') { $extra = @($Source) + $extra; $Source = "" }
if ($Out -like '-*') { $extra = @($Out) + $extra; $Out = "" }
if ($Arch -like '-*') { $extra = @($Arch) + $extra; $Arch = "" }
if ($Target -like '-*') { $extra = @($Target) + $extra; $Target = "" }
if ($Arch -notin @("", "x64", "x86", "arm64")) { throw "-Arch must be x64, x86 or arm64, not '$Arch'" }
$ErrorActionPreference = "Stop"
$root = $PSScriptRoot
$hostArch = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) {
+11 -15
View File
@@ -1,6 +1,7 @@
#include <string.h>
#include "a11y.h"
#include "../base/util.h"
static const char *const g_role_names[REAKTOR_A11Y_ROLE_COUNT] = {
"none", "window", "group", "tablist", "tab", "button", "link",
@@ -18,12 +19,7 @@ reaktor_a11y_role_name(unsigned char role)
static unsigned
hash_str(unsigned h, const char *s)
{
if (!s) return h * 16777619u;
while (*s) {
h ^= (unsigned char)*s++;
h *= 16777619u;
}
return h;
return s ? reaktor_fnv(h, s) : h * 16777619u;
}
static const char *
@@ -42,21 +38,21 @@ intern(reaktor_a11y *a, const char *s, unsigned h)
a->pool_used + (int)n > REAKTOR_A11Y_POOL) {
return NULL;
}
memcpy(a->pool + a->pool_used, s, n);
memcpy(a->pool[a->pool_side] + a->pool_used, s, n);
sl->gen = a->pool_gen;
sl->key = h;
sl->val = a->pool_used;
a->pool_used += (int)n;
a->pool_entries++;
return a->pool + sl->val;
return a->pool[a->pool_side] + sl->val;
}
if (sl->key == h && strcmp(a->pool + sl->val, s) == 0)
return a->pool + sl->val;
if (sl->key == h && strcmp(a->pool[a->pool_side] + sl->val, s) == 0)
return a->pool[a->pool_side] + sl->val;
i = (i + 1) & mask;
}
}
#define same_str(x, y) ((x) == (y))
#define same_str(x, y) ((x) == (y) || ((x) && (y) && strcmp((x), (y)) == 0))
static reaktor_a11y_slot *
slot_of(reaktor_a11y_slot *tab, unsigned gen, unsigned key)
@@ -112,7 +108,7 @@ emit(reaktor_a11y *a, unsigned char role, const char *name, const char *value,
parent = a->depth > 0 ? a->parent[a->depth - 1] : 0u;
nh = hash_str(2166136261u, name);
nh = hash_str(REAKTOR_FNV, name);
base = nh ^ ((unsigned)role * 0x9e3779b9u);
base ^= parent + 0x9e3779b9u + (base << 6) + (base >> 2);
@@ -132,7 +128,7 @@ emit(reaktor_a11y *a, unsigned char role, const char *name, const char *value,
n->level = (unsigned char)a->depth;
n->state = state;
n->name = intern(a, name, nh);
n->value = intern(a, value, hash_str(2166136261u, value));
n->value = intern(a, value, hash_str(REAKTOR_FNV, value));
n->keys = NULL;
n->bounds = bounds;
n->num = n->lo = n->hi = n->step = 0.0f;
@@ -153,7 +149,7 @@ node_of(reaktor_a11y *a, unsigned id)
static const char *
intern_str(reaktor_a11y *a, const char *s)
{
return (s && *s) ? intern(a, s, hash_str(2166136261u, s)) : NULL;
return (s && *s) ? intern(a, s, hash_str(REAKTOR_FNV, s)) : NULL;
}
void
@@ -211,10 +207,10 @@ reaktor_a11y_begin(reaktor_a11y *a, const char *window_name,
if (a->pool_used > REAKTOR_A11Y_POOL - REAKTOR_A11Y_POOL / 4 ||
a->pool_entries >= REAKTOR_A11Y_SLOTS) {
a->pool_side ^= 1;
a->pool_used = 0;
a->pool_entries = 0;
a->pool_gen++;
a->count[0] = a->count[1] = 0;
}
reaktor_a11y_push(a, REAKTOR_A11Y_WINDOW, window_name, NULL, 0, bounds);
+2 -1
View File
@@ -49,7 +49,8 @@ typedef struct reaktor_a11y {
int count[2];
int front;
char pool[REAKTOR_A11Y_POOL];
char pool[2][REAKTOR_A11Y_POOL];
int pool_side;
int pool_used;
int pool_entries;
unsigned pool_gen;
+9 -1
View File
@@ -88,11 +88,19 @@ reaktor_ease_name(unsigned char curve)
return curve < REAKTOR_EASE_COUNT ? n[curve] : "?";
}
static int g_reduce;
void
reaktor_anim_reduce(int on)
{
g_reduce = on;
}
float
reaktor_animate(unsigned id, unsigned channel, float to, float ms,
unsigned char curve)
{
if (ms <= 0.0f || !g_anim) return to;
if (ms <= 0.0f || g_reduce || !g_anim) return to;
return nka_tween_float(g_anim, id, channel, to, ms / 1000.0f,
nka_ease(curve), NKA_POLICY_CROSSFADE, to);
}
+1
View File
@@ -9,5 +9,6 @@ void reaktor_anim_destroy(struct nka_context *a);
void reaktor_anim_frame(struct nka_context *a, float dt_ms);
int reaktor_anim_settle(void);
void reaktor_anim_reduce(int on);
#endif
+3 -10
View File
@@ -44,18 +44,11 @@ FILE *reaktor_fopen(const char *path, const char *mode)
#endif
}
static FILE *open_rb(const char *path)
{
return reaktor_fopen(path, "rb");
}
static int file_exists(const char *path)
{
FILE *f = open_rb(path);
SDL_PathInfo info;
if (!f) return 0;
fclose(f);
return 1;
return SDL_GetPathInfo(path, &info) && info.type == SDL_PATHTYPE_FILE;
}
static int copy_out(char *out, size_t cap, const char *src)
@@ -66,7 +59,7 @@ static int copy_out(char *out, size_t cap, const char *src)
return 1;
}
int reaktor_root(char *out, size_t cap)
static int reaktor_root(char *out, size_t cap)
{
static char cached[REAKTOR_PATH_CAP];
static int resolved;
+19 -1
View File
@@ -4,7 +4,6 @@
#include <stddef.h>
#include <stdio.h>
int reaktor_root(char *out, size_t cap);
int reaktor_path(char *out, size_t cap, const char *rel);
@@ -37,6 +36,25 @@ void reaktor_free(void *p);
void reaktor_release_free_memory(void);
#define REAKTOR_FNV 2166136261u
static inline unsigned
reaktor_fnv(unsigned h, const char *s)
{
if (s)
while (*s) h = (h ^ (unsigned char)*s++) * 16777619u;
return h;
}
static inline unsigned
reaktor_fnv_n(unsigned h, const void *p, size_t n)
{
const unsigned char *b = (const unsigned char *)p;
while (n--) h = (h ^ *b++) * 16777619u;
return h;
}
#define REAKTOR_MARK "assets/icons/reaktor-icon.svg"
#endif
+299 -89
View File
@@ -1,4 +1,5 @@
#include "cssflat.h"
#include <plutovg.h>
#include "util.h"
#include <stdio.h>
@@ -89,7 +90,7 @@ static int vars_set(reaktor_cssvars *m, const char *name, size_t nlen,
return 1;
}
const char *reaktor_cssvars_get(const reaktor_cssvars *m, const char *name)
static const char *reaktor_cssvars_get(const reaktor_cssvars *m, const char *name)
{
size_t i;
@@ -99,14 +100,6 @@ const char *reaktor_cssvars_get(const reaktor_cssvars *m, const char *name)
return NULL;
}
static int hex1(int c)
{
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
return -1;
}
/* Not strtod, which reads the locale's decimal mark. */
static float css_number(const char *p, const char **end)
{
@@ -142,48 +135,39 @@ static void color_text(char *out, size_t cap, const float c[4])
(int)(c[1] + 0.5f), (int)(c[2] + 0.5f), a / 1000, a % 1000);
}
/* plutovg reads only the comma form of rgb() and hsl(), so a space or a '/'
between arguments becomes a comma first. */
static int parse_color(const char *s, size_t n, float c[4])
{
char tmp[64];
float v[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
const char *p, *end;
int h[8], i, k;
const char *open;
plutovg_color_t col;
size_t i, k = 0;
int depth = 0, gap = 0;
while (n && isspace((unsigned char)*s)) { s++; n--; }
while (n && isspace((unsigned char)s[n - 1])) n--;
if (n == 0 || n >= sizeof(tmp)) return 0;
memcpy(tmp, s, n);
tmp[n] = 0;
if (strcmp(tmp, "transparent") == 0) {
c[0] = c[1] = c[2] = c[3] = 0.0f;
return 1;
}
if (tmp[0] == '#') {
for (k = 0; k < 8 && tmp[k + 1]; k++)
if ((h[k] = hex1((unsigned char)tmp[k + 1])) < 0) return 0;
if (tmp[k + 1] || (k != 3 && k != 4 && k != 6 && k != 8)) return 0;
for (i = 0; i < k / (k < 6 ? 1 : 2); i++)
v[i] = k < 6 ? (float)(h[i] * 17) : (float)(h[2 * i] * 16 + h[2 * i + 1]);
if (k == 4 || k == 8) v[3] /= 255.0f;
} else if (strncmp(tmp, "rgb", 3) == 0 && (p = strchr(tmp, '('))) {
for (i = 0, p++; i < 4; i++) {
while (*p == ' ' || *p == ',' || *p == '/') p++;
if (*p == ')') break;
v[i] = css_number(p, &end);
if (end == p) return 0;
if (*end == '%') { v[i] *= i < 3 ? 2.55f : 0.01f; end++; }
p = end;
}
while (*p == ' ') p++;
if (i < 3 || *p != ')' || p[1]) return 0;
} else {
return 0;
}
for (i = 0; i < 4; i++) {
float hi = i < 3 ? 255.0f : 1.0f;
open = memchr(s, '(', n);
for (i = 0; i < n; i++) {
char ch = s[i];
c[i] = v[i] > 0.0f ? (v[i] < hi ? v[i] : hi) : 0.0f;
if (open && depth == 1 && (isspace((unsigned char)ch) || ch == ',' || ch == '/')) {
gap = 1;
continue;
}
if (ch == '(') depth++;
if (ch == ')') { depth--; gap = 0; }
if (gap && tmp[k - 1] != '(') tmp[k++] = ',';
gap = 0;
tmp[k++] = ch;
}
tmp[k] = 0;
if (plutovg_color_parse(&col, tmp, (int)k) != (int)k) return 0;
c[0] = col.r * 255.0f;
c[1] = col.g * 255.0f;
c[2] = col.b * 255.0f;
c[3] = col.a;
return 1;
}
@@ -499,6 +483,156 @@ static int calc_sum(calc_in *c, calc_val *out)
}
}
/* libcss reads a border width only as a length, and its border shorthands
crash on the keywords; CSS gives them these lengths. */
static void line_width_keywords(buf *b)
{
static const struct { const char *word; const char *px; } kw[3] = {
{ "thin", "1px" }, { "medium", "3px" }, { "thick", "5px" }
};
size_t i = 0;
while (b->p && i < b->len) {
int k, hit = -1;
if (i > 0 && (isalnum((unsigned char)b->p[i - 1]) || b->p[i - 1] == '-')) { i++; continue; }
for (k = 0; k < 3; k++) {
size_t n = strlen(kw[k].word);
if (i + n <= b->len && strncmp(b->p + i, kw[k].word, n) == 0 &&
(i + n == b->len || !(isalnum((unsigned char)b->p[i + n]) || b->p[i + n] == '-'))) {
hit = k;
break;
}
}
if (hit < 0) { i++; continue; }
{
size_t n = strlen(kw[hit].word), m = strlen(kw[hit].px);
buf r;
memset(&r, 0, sizeof(r));
if (!buf_add(&r, b->p, i) || !buf_str(&r, kw[hit].px) ||
!buf_add(&r, b->p + i + n, b->len - i - n)) {
free(r.p);
return;
}
free(b->p);
*b = r;
i += m;
}
}
}
/* libcss's border shorthands read three parsed parts whatever they got, and
crash on a value that parses as one part ("red", "dotted", "unset"). The
shorthand is spelled out as longhands instead, with the parts it leaves
out at the values libcss gives them: 0px, none, transparent. */
static int border_side_of(const char *p, size_t plen, const char **side)
{
static const char *const sides[4] = { "top", "right", "bottom", "left" };
int k;
if (plen == 6 && strncmp(p, "border", 6) == 0) { *side = NULL; return 1; }
for (k = 0; k < 4; k++) {
size_t n = strlen(sides[k]);
if (plen == 7 + n && strncmp(p, "border-", 7) == 0 &&
strncmp(p + 7, sides[k], n) == 0) {
*side = sides[k];
return 1;
}
}
return 0;
}
static int word_is(const char *s, size_t n, const char *w)
{
size_t i;
if (strlen(w) != n) return 0;
for (i = 0; i < n; i++)
if (tolower((unsigned char)s[i]) != w[i]) return 0;
return 1;
}
static int is_line_style(const char *s, size_t n)
{
static const char *const styles[] = { "none", "hidden", "dotted", "dashed", "solid",
"double", "groove", "ridge", "inset", "outset" };
size_t k;
for (k = 0; k < sizeof(styles) / sizeof(styles[0]); k++)
if (word_is(s, n, styles[k])) return 1;
return 0;
}
static int is_length(const char *s, size_t n)
{
size_t i = (n && (s[0] == '-' || s[0] == '+')) ? 1 : 0;
return i < n && (isdigit((unsigned char)s[i]) || s[i] == '.');
}
/* 1 when written out, 0 to drop the declaration. */
static int expand_border(buf *out, const char *p, size_t plen, const char *v, size_t vlen)
{
static const char *const sides[4] = { "top", "right", "bottom", "left" };
const char *side, *part[3] = { "0px", "none", "transparent" };
size_t partn[3] = { 3, 4, 11 };
int have[3] = { 0, 0, 0 }, k, words = 0, important = 0, wide = 0;
size_t i = 0;
if (!border_side_of(p, plen, &side)) return -1;
while (i < vlen) {
size_t s, depth = 0;
int kind;
while (i < vlen && isspace((unsigned char)v[i])) i++;
if (i >= vlen) break;
s = i;
while (i < vlen && (depth || !isspace((unsigned char)v[i]))) {
if (v[i] == '(') depth++;
else if (v[i] == ')' && depth) depth--;
i++;
}
if (v[s] == '!') {
if (!word_is(v + s, i - s, "!important") || important) return 0;
important = 1;
continue;
}
words++;
if (word_is(v + s, i - s, "inherit")) return 0;
if (word_is(v + s, i - s, "unset") || word_is(v + s, i - s, "initial") ||
word_is(v + s, i - s, "revert") || word_is(v + s, i - s, "revert-layer")) {
wide = 1;
continue;
}
kind = is_length(v + s, i - s) ? 0 : is_line_style(v + s, i - s) ? 1 : 2;
if (have[kind]) return 0;
have[kind] = 1;
part[kind] = v + s;
partn[kind] = i - s;
}
if (!words || (wide && words > 1)) return 0;
for (k = 0; k < 4; k++) {
static const char *const what[3] = { "width", "style", "color" };
int w;
if (side && strcmp(side, sides[k]) != 0) continue;
for (w = 0; w < 3; w++) {
buf_str(out, "border-");
buf_str(out, sides[k]);
buf_ch(out, '-');
buf_str(out, what[w]);
buf_str(out, ": ");
buf_add(out, part[w], partn[w]);
if (important) buf_str(out, " !important");
buf_str(out, ";\n");
}
}
return 1;
}
static void resolve_pixel_calcs(buf *b)
{
static const char fn[] = "calc(";
@@ -823,6 +957,9 @@ static void emit_one(void *c, const char *p, size_t plen,
ctx->rem_px, ctx->em_px, &conv);
resolve_pixel_calcs(&conv);
}
if ((plen >= 6 && strncmp(p, "border", 6) == 0) ||
(plen >= 7 && strncmp(p, "outline", 7) == 0))
line_width_keywords(&conv);
/* The engine ends a value at any ';', even one inside url(). */
if (plen >= ctx->token_max || conv.len >= ctx->token_max ||
@@ -831,6 +968,16 @@ static void emit_one(void *c, const char *p, size_t plen,
free(conv.p);
return;
}
{
int done = expand_border(ctx->out, p, plen, conv.p ? conv.p : "", conv.len);
if (done >= 0) {
ctx->wrote |= done;
free(tmp.p);
free(conv.p);
return;
}
}
buf_add(ctx->out, p, plen);
buf_str(ctx->out, ": ");
buf_add(ctx->out, conv.p ? conv.p : "", conv.len);
@@ -840,8 +987,79 @@ static void emit_one(void *c, const char *p, size_t plen,
free(conv.p);
}
static int g_reduce_motion, g_more_contrast;
void reaktor_css_media(int reduce_motion, int more_contrast)
{
g_reduce_motion = reduce_motion;
g_more_contrast = more_contrast;
}
static int is_word(const char *s, size_t n, const char *w)
{
return strlen(w) == n && strncmp(s, w, n) == 0;
}
/* 1 or 0 for a feature this runtime answers, -1 for any other. */
static int media_feature(const char *s, size_t n, const char *theme)
{
const char *colon = (const char *)memchr(s, ':', n);
size_t nl = colon ? (size_t)(colon - s) : n, vl = 0;
const char *v = colon ? colon + 1 : s + n;
while (nl && isspace((unsigned char)s[nl - 1])) nl--;
if (colon) {
while (v < s + n && isspace((unsigned char)*v)) v++;
vl = (size_t)(s + n - v);
while (vl && isspace((unsigned char)v[vl - 1])) vl--;
}
if (is_word(s, nl, "prefers-color-scheme"))
return colon && is_word(v, vl, theme);
if (is_word(s, nl, "prefers-reduced-motion")) {
if (!colon || is_word(v, vl, "reduce")) return g_reduce_motion;
return is_word(v, vl, "no-preference") && !g_reduce_motion;
}
if (is_word(s, nl, "prefers-contrast")) {
if (!colon || is_word(v, vl, "more")) return g_more_contrast;
return is_word(v, vl, "no-preference") && !g_more_contrast;
}
return -1;
}
/* Whether a lowercased @media prelude holds: one of its comma-separated
queries names only features answered here, each true. */
static int media_matches(const char *q, const char *theme)
{
while (*q) {
int ok = 1, features = 0;
while (*q && *q != ',' && *q != '{') {
const char *s;
if (isspace((unsigned char)*q)) { q++; continue; }
if (*q == '(') {
s = ++q;
while (*q && *q != ')') q++;
if (media_feature(s, (size_t)(q - s), theme) != 1) ok = 0;
features++;
if (*q) q++;
continue;
}
s = q;
while (*q && !isspace((unsigned char)*q) && *q != '(' && *q != ',' && *q != '{') q++;
if (!is_word(s, (size_t)(q - s), "only") && !is_word(s, (size_t)(q - s), "and") &&
!is_word(s, (size_t)(q - s), "screen") && !is_word(s, (size_t)(q - s), "all"))
ok = 0;
}
if (ok && features) return 1;
if (*q != ',') return 0;
q++;
}
return 0;
}
static void
unwrap_color_scheme(char *src, const char *theme)
unwrap_media(char *src, const char *theme)
{
const char *want = (theme && *theme) ? theme : "light";
size_t i = 0, len = strlen(src);
@@ -869,8 +1087,7 @@ unwrap_color_scheme(char *src, const char *theme)
low[k] = (c >= 'A' && c <= 'Z') ? (char)(c - 'A' + 'a') : c;
}
low[n] = '\0';
keep = strstr(low, "prefers-color-scheme") != NULL &&
strstr(low, want) != NULL;
keep = media_matches(low + 6, want);
}
body_s = prelude_e + 1;
@@ -893,9 +1110,34 @@ unwrap_color_scheme(char *src, const char *theme)
}
}
/* The next rule at *i: its selector and body spans; 0 at the end. */
static int next_rule(const char *s, size_t len, size_t *i, size_t *sel_s,
size_t *sel_e, size_t *body_s, size_t *body_e)
{
for (;;) {
size_t depth = 1;
*sel_s = *i;
while (*i < len && s[*i] != '{' && s[*i] != '}') (*i)++;
if (*i >= len) return 0;
if (s[*i] == '}') { (*i)++; continue; }
*sel_e = (*i)++;
*body_s = *i;
while (*i < len && depth) {
if (s[*i] == '{') depth++;
else if (s[*i] == '}') depth--;
if (depth) (*i)++;
}
*body_e = *i;
if (*i < len) (*i)++;
return 1;
}
}
static char *flatten(char *src, const char *theme, size_t token_max,
reaktor_cssvars **out_vars)
{
size_t sel_s, sel_e, body_s, body_e;
reaktor_cssvars *m = (reaktor_cssvars *)calloc(1, sizeof(*m));
buf out;
size_t i, len, pass;
@@ -906,28 +1148,11 @@ static char *flatten(char *src, const char *theme, size_t token_max,
if (!m) { free(src); return NULL; }
strip_comments(src);
unwrap_color_scheme(src, theme);
unwrap_media(src, theme);
len = strlen(src);
i = 0;
while (i < len) {
size_t sel_s, sel_e, body_s, body_e, depth;
sel_s = i;
while (i < len && src[i] != '{' && src[i] != '}') i++;
if (i >= len) break;
if (src[i] == '}') { i++; continue; }
sel_e = i++;
body_s = i;
depth = 1;
while (i < len && depth) {
if (src[i] == '{') depth++;
else if (src[i] == '}') depth--;
if (depth) i++;
}
body_e = i;
if (i < len) i++;
while (next_rule(src, len, &i, &sel_s, &sel_e, &body_s, &body_e)) {
trim(src, &sel_s, &sel_e);
if (is_vars_selector(src + sel_s, sel_e - sel_s) ||
is_theme_selector(src + sel_s, sel_e - sel_s, theme)) {
@@ -965,24 +1190,8 @@ static char *flatten(char *src, const char *theme, size_t token_max,
" @media and unsupported selectors removed. */\n");
i = 0;
while (i < len) {
size_t sel_s, sel_e, body_s, body_e, depth, part, n_emitted;
emit_ctx ctx;
sel_s = i;
while (i < len && src[i] != '{' && src[i] != '}') i++;
if (i >= len) break;
if (src[i] == '}') { i++; continue; }
sel_e = i++;
body_s = i;
depth = 1;
while (i < len && depth) {
if (src[i] == '{') depth++;
else if (src[i] == '}') depth--;
if (depth) i++;
}
body_e = i;
if (i < len) i++;
while (next_rule(src, len, &i, &sel_s, &sel_e, &body_s, &body_e)) {
size_t part, n_emitted;
trim(src, &sel_s, &sel_e);
if (sel_e <= sel_s) continue;
@@ -1020,12 +1229,6 @@ static char *flatten(char *src, const char *theme, size_t token_max,
}
if (!n_emitted) { free(sel.p); continue; }
ctx.m = m;
ctx.out = &out;
ctx.token_max = token_max;
ctx.wrote = 0;
ctx.rem_px = root.px;
ctx.em_px = root.em;
{
buf body;
emit_ctx bctx;
@@ -1082,9 +1285,16 @@ static char *import_path(const char *from, const char *to, size_t n)
return p;
}
static void (*g_seen)(const char *path);
void reaktor_css_track(void (*seen)(const char *path)) { g_seen = seen; }
static int load_sheet(const char *path, int depth, buf *all)
{
char *t = reaktor_asset_load(path, NULL);
char *t;
if (g_seen) g_seen(path);
t = reaktor_asset_load(path, NULL);
size_t i = 0, from = 0, n;
int ok = 1;
+5 -1
View File
@@ -9,7 +9,11 @@ typedef struct reaktor_cssvars reaktor_cssvars;
char *reaktor_css_flatten(const char *const *paths, int count, const char *theme,
size_t token_max, reaktor_cssvars **out_vars);
const char *reaktor_cssvars_get(const reaktor_cssvars *vars, const char *name);
/* What @media (prefers-reduced-motion) and (prefers-contrast) answer. */
void reaktor_css_media(int reduce_motion, int more_contrast);
/* Told each sheet a flatten reads, @imports too, as the sheet names it. */
void reaktor_css_track(void (*seen)(const char *path));
int reaktor_cssvars_color(const reaktor_cssvars *vars, const char *name,
unsigned char rgba[4]);
+1 -4
View File
@@ -57,10 +57,7 @@ static void cache_clear(int release)
static unsigned hash_of(const char *s)
{
unsigned h = 2166136261u;
while (*s) h = (h ^ (unsigned char)*s++) * 16777619u;
return h;
return reaktor_fnv(REAKTOR_FNV, s);
}
static cache_entry *cache_slot(const char *selector, unsigned h)
+1
View File
@@ -7,5 +7,6 @@ int reaktor_style_init(const char *const *css_paths, int count,
const char *theme);
void reaktor_style_shutdown(void);
unsigned reaktor_style_loads(void);
void reaktor_style_darken(unsigned char rgba[4], float amount);
#endif
+20 -9
View File
@@ -44,7 +44,6 @@ enum {
extern size_t reaktor_rss[REAKTOR_RSS_STEPS];
extern size_t reaktor_priv[REAKTOR_RSS_STEPS];
void reaktor_rss_mark(int step);
#define GLYPH_STROKE 2.0f
@@ -62,9 +61,22 @@ struct tex_slot {
struct img_slot {
struct tex_slot s;
char src[192];
unsigned hash;
int px, w, h;
};
static inline float
reaktor_text_w(const struct nk_user_font *f, const char *s)
{
return s ? f->width(f->userdata, f->height, s, (int)SDL_strlen(s)) : 0.0f;
}
static inline void
reaktor_hex(struct nk_color c, char out[8])
{
SDL_snprintf(out, 8, "#%02x%02x%02x", c.r, c.g, c.b);
}
#define ROUND_CACHE_MAX 32
struct round_slot {
struct tex_slot s;
@@ -119,7 +131,7 @@ struct App {
const char *tip;
char render_mode[32];
int vsync_on, aa, redraw_always;
int vsync_on, aa_mode, redraw_always;
char frame_rate[16];
char drag_rate[16];
@@ -272,6 +284,8 @@ enum { HOLD_NONE, HOLD_ALL, HOLD_FRESH };
int focus_key(App *app, const SDL_Event *event);
void focus_ring(App *app, struct nk_context *ctx, struct nk_command_buffer *cv);
void reaktor_overlay(App *app, struct nk_context *ctx, int ring);
int reaktor_aa_lines(const App *app);
int reaktor_aa_fills(const App *app);
enum {
REAKTOR_WHY_INPUT = 1u << 0,
@@ -298,7 +312,6 @@ void focus_resolve(App *app);
void reaktor_key_click_ask(App *app);
int reaktor_focus_covered(App *app);
void reaktor_focus_take(App *app, unsigned id, struct nk_rect b);
float reaktor_cap_offset(const struct nk_user_font *f);
int reaktor_flyout_begin(struct nk_context *ctx, const char *name, struct nk_rect r);
void reaktor_flyout_end(struct nk_context *ctx);
int reaktor_window_popup(struct nk_rect r,
@@ -313,8 +326,6 @@ App *reaktor_window_app(int id);
extern Uint64 g_hover_gap_ms;
int renderer_is_software(SDL_Renderer *ren);
void load_theme(App *app);
void a11y_dump_once(App *app);
@@ -356,7 +367,6 @@ void reaktor_fade_since(struct nk_context *ctx, const struct nk_command_buffer *
App *reaktor_main_app(void);
bool reaktor_app_wake(const App *app);
void reaktor_hint(const char *name, const char *value);
void reaktor_hover_redraw(App *app);
int reaktor_key_hook(App *app, const SDL_Event *event);
void reaktor_take_event(App *app, SDL_Event *event);
void reaktor_input_event(App *app, SDL_Event *event);
@@ -375,10 +385,11 @@ void reaktor_settings_free(void);
void reaktor_window_restore(App *app);
void reaktor_window_remember(App *app);
const char *reaktor_asset_name(const reaktor_asset *a, const char *fallback);
int reaktor_hot_motion(App *app, float mx, float my);
SDL_Cursor *reaktor_cursor(int kind);
void reaktor_show_cursor(App *app);
void reaktor_place_ime(App *app);
int reaktor_instance_claim(int argc, char **argv);
void reaktor_instance_listen(App *app, void (*opened)(App *app, const char *path));
void reaktor_instance_stop(void);
void reaktor_render(App *app);
typedef void (*reaktor_page_fn)(App *app, struct nk_context *ctx, int w, int h,
+1
View File
@@ -4,5 +4,6 @@
#include "reaktor/locale.h"
unsigned *reaktor_locale_glyphs(const unsigned char *ttf);
void reaktor_locale_start(const char *lang);
#endif
+23 -4
View File
@@ -1,4 +1,5 @@
#include "internal.h"
#include "reaktor/launch.h"
#include "locale.h"
static const int g_font_px[FONT_STEPS] =
@@ -124,13 +125,16 @@ img_lookup(App *app, const char *src, int px)
SDL_Surface *sdlsurf;
SDL_Texture *tex;
struct img_slot *slot;
unsigned hash;
int i, w, h, stride;
if (px < 8) px = 8;
if (px > 512) px = 512;
hash = reaktor_fnv(REAKTOR_FNV ^ (unsigned)px, src);
for (i = 0; i < app->img_count; i++)
if (app->img[i].px == px && strcmp(app->img[i].src, src) == 0) {
if (app->img[i].hash == hash && app->img[i].px == px &&
strcmp(app->img[i].src, src) == 0) {
app->img[i].s.seen = app->ctx->seq;
return app->img[i].s.tex ? &app->img[i] : NULL;
}
@@ -166,6 +170,7 @@ img_lookup(App *app, const char *src, int px)
icol[0] ? icol : NULL, swk);
SDL_strlcpy(slot->src, src, sizeof(slot->src));
slot->hash = hash;
slot->px = px;
slot->s.tex = NULL;
slot->w = slot->h = 0;
@@ -375,6 +380,20 @@ mask_rounded_fills(App *app)
ctx->memory.allocated;
}
int
reaktor_aa_lines(const App *app)
{
return app->aa_mode != REAKTOR_AA_OFF && !(app->renderer_is_sw && app->sw_noaa);
}
/* Left to a GPU renderer by default; rounded fills are masks either way. */
int
reaktor_aa_fills(const App *app)
{
return app->aa_mode == REAKTOR_AA_ON ||
(app->aa_mode == REAKTOR_AA_AUTO && !app->renderer_is_sw);
}
void
reaktor_render(App *app)
{
@@ -382,9 +401,9 @@ reaktor_render(App *app)
app->clear.a);
SDL_RenderClear(app->ren);
mask_rounded_fills(app);
nk_sdl_render_ex(app->ctx, NK_ANTI_ALIASING_OFF,
app->aa && !(app->renderer_is_sw && app->sw_noaa)
? NK_ANTI_ALIASING_ON : NK_ANTI_ALIASING_OFF);
nk_sdl_render_ex(app->ctx,
reaktor_aa_fills(app) ? NK_ANTI_ALIASING_ON : NK_ANTI_ALIASING_OFF,
reaktor_aa_lines(app) ? NK_ANTI_ALIASING_ON : NK_ANTI_ALIASING_OFF);
}
nk_size
+27 -169
View File
@@ -39,14 +39,10 @@ NK_API struct nk_font_atlas* nk_sdl_font_stash_begin(struct nk_context* ctx);
NK_API void nk_sdl_font_stash_end(struct nk_context* ctx);
#endif
NK_API int nk_sdl_handle_event(struct nk_context* ctx, SDL_Event *evt);
NK_API void nk_sdl_render(struct nk_context* ctx, enum nk_anti_aliasing);
/* REAKTOR: fill and stroke feathering apart. */
NK_API void nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA, enum nk_anti_aliasing line_AA);
NK_API void nk_sdl_update_TextInput(struct nk_context* ctx);
NK_API void nk_sdl_shutdown(struct nk_context* ctx);
NK_API nk_handle nk_sdl_get_userdata(struct nk_context* ctx);
NK_API void nk_sdl_set_userdata(struct nk_context* ctx, nk_handle userdata);
NK_API void nk_sdl_style_set_debug_font(struct nk_context* ctx);
NK_API struct nk_allocator nk_sdl_allocator(void);
/* REAKTOR: exported for the Text module. */
NK_API bool nk_sdl_set_coverage_palette(SDL_Texture *tex);
@@ -70,6 +66,8 @@ NK_API bool nk_sdl_set_coverage_palette(SDL_Texture *tex);
struct nk_sdl_device {
struct nk_buffer cmds;
/* REAKTOR: kept across frames, as cmds is, so a frame allocates nothing. */
struct nk_buffer vbuf, ebuf;
struct nk_draw_null_texture tex_null;
SDL_Texture *font_tex;
/* REAKTOR: white texel for untextured geometry. */
@@ -82,40 +80,24 @@ struct nk_sdl_vertex {
float col[4];
};
/* NK_ALIGNOF declares its struct inside offsetof, which MSVC warns about. */
struct nk_sdl_vertex_align { char c; struct nk_sdl_vertex v; };
struct nk_sdl {
SDL_Window *win;
SDL_Renderer *renderer;
struct nk_user_font* debug_font;
struct nk_sdl_device ogl;
struct nk_context ctx;
#ifdef NK_INCLUDE_FONT_BAKING
struct nk_font_atlas atlas;
#endif
struct nk_allocator allocator;
nk_handle userdata;
Uint64 last_render;
bool insert_toggle;
bool edit_was_active;
bool is_sw;
};
NK_API nk_handle
nk_sdl_get_userdata(struct nk_context* ctx) {
struct nk_sdl* sdl;
NK_ASSERT(ctx);
sdl = (struct nk_sdl*)ctx->userdata.ptr;
NK_ASSERT(sdl);
return sdl->userdata;
}
NK_API void
nk_sdl_set_userdata(struct nk_context* ctx, nk_handle userdata) {
struct nk_sdl* sdl;
NK_ASSERT(ctx);
sdl = (struct nk_sdl*)ctx->userdata.ptr;
NK_ASSERT(sdl);
sdl->userdata = userdata;
}
NK_INTERN void *
nk_sdl_alloc(nk_handle user, void *old, nk_size size)
{
@@ -380,12 +362,6 @@ nk_sdl_quad_draw(SDL_Renderer *ren, SDL_Texture *tex, const struct nk_sdl_rect *
if (q->opaque) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
}
NK_API void
nk_sdl_render(struct nk_context* ctx, enum nk_anti_aliasing AA)
{
nk_sdl_render_ex(ctx, AA, AA);
}
/* REAKTOR: fill and stroke feathering apart. */
NK_API void
nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
@@ -406,7 +382,7 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
}
{
SDL_Rect saved_clip;
SDL_Rect saved_clip, last_clip = {0, 0, -1, -1};
SDL_BlendMode saved_blend;
float saved_r, saved_g, saved_b, saved_a;
bool clipping_enabled;
@@ -416,7 +392,6 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
/* convert from command queue into draw list and draw to screen */
const struct nk_draw_command *cmd;
const nk_draw_index *offset = NULL;
struct nk_buffer vbuf, ebuf;
/* fill converting configuration */
struct nk_convert_config config;
@@ -429,7 +404,7 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
NK_MEMSET(&config, 0, sizeof(config));
config.vertex_layout = vertex_layout;
config.vertex_size = sizeof(struct nk_sdl_vertex);
config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex);
config.vertex_alignment = offsetof(struct nk_sdl_vertex_align, v);
config.tex_null = sdl->ogl.tex_null;
/* REAKTOR: 22 upstream. */
config.circle_segment_count = 48;
@@ -440,18 +415,16 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
config.line_AA = line_AA;
/* convert shapes into vertices */
nk_buffer_init(&vbuf, &sdl->allocator, NK_BUFFER_DEFAULT_INITIAL_SIZE);
nk_buffer_init(&ebuf, &sdl->allocator, NK_BUFFER_DEFAULT_INITIAL_SIZE);
nk_convert(&sdl->ctx, &sdl->ogl.cmds, &vbuf, &ebuf, &config);
nk_convert(&sdl->ctx, &sdl->ogl.cmds, &sdl->ogl.vbuf, &sdl->ogl.ebuf, &config);
/* REAKTOR: software vertices on the device pixel grid. */
is_sw = SDL_strcmp(SDL_GetRendererName(sdl->renderer), "software") == 0;
is_sw = sdl->is_sw;
if (!SDL_GetRenderScale(sdl->renderer, &sx, &sy) || sx <= 0.0f ||
sy <= 0.0f)
sx = sy = 1.0f;
if (is_sw) {
nk_byte *v = (nk_byte *)nk_buffer_memory(&vbuf);
nk_size i, n = vbuf.needed / (nk_size)vs;
nk_byte *v = (nk_byte *)nk_buffer_memory(&sdl->ogl.vbuf);
nk_size i, n = sdl->ogl.vbuf.needed / (nk_size)vs;
for (i = 0; i < n; i++) {
float *pos = (float *)(v + i * (nk_size)vs + vp);
pos[0] = (SDL_floorf(pos[0] * sx + 0.5f) + 0.5f) / sx;
@@ -460,7 +433,7 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
}
/* iterate over and execute each draw command */
offset = (const nk_draw_index*)nk_buffer_memory_const(&ebuf);
offset = (const nk_draw_index*)nk_buffer_memory_const(&sdl->ogl.ebuf);
clipping_enabled = SDL_RenderClipEnabled(sdl->renderer);
SDL_GetRenderClipRect(sdl->renderer, &saved_clip);
@@ -479,7 +452,7 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
/* REAKTOR: glyph quads on the pixel grid. */
if (!is_sw && cmd->texture.ptr == (void *)sdl->ogl.font_tex) {
nk_byte *v = (nk_byte *)nk_buffer_memory(&vbuf);
nk_byte *v = (nk_byte *)nk_buffer_memory(&sdl->ogl.vbuf);
nk_uint k;
for (k = 0; k < cmd->elem_count; k++) {
float *pos = (float *)(v + (nk_size)offset[k] * (nk_size)vs
@@ -495,12 +468,15 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
r.y = cmd->clip_rect.y;
r.w = cmd->clip_rect.w;
r.h = cmd->clip_rect.h;
SDL_SetRenderClipRect(sdl->renderer, &r);
if (SDL_memcmp(&r, &last_clip, sizeof r) != 0) {
SDL_SetRenderClipRect(sdl->renderer, &r);
last_clip = r;
}
}
{
const void *vertices = nk_buffer_memory_const(&vbuf);
int n = (int)(vbuf.needed / (nk_size)vs);
const void *vertices = nk_buffer_memory_const(&sdl->ogl.vbuf);
int n = (int)(sdl->ogl.vbuf.needed / (nk_size)vs);
/* REAKTOR: shapes untextured. */
SDL_Texture *tex = (SDL_Texture *)cmd->texture.ptr;
@@ -555,8 +531,8 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
nk_clear(&sdl->ctx);
nk_buffer_clear(&sdl->ogl.cmds);
nk_buffer_free(&vbuf);
nk_buffer_free(&ebuf);
nk_buffer_clear(&sdl->ogl.vbuf);
nk_buffer_clear(&sdl->ogl.ebuf);
}
}
@@ -632,6 +608,7 @@ nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer, struct nk_allocator allocat
sdl->allocator.free = allocator.free;
sdl->win = win;
sdl->renderer = renderer;
sdl->is_sw = SDL_strcmp(SDL_GetRendererName(renderer), "software") == 0;
/* REAKTOR: UVs stay in [0, 1], so SDL need not scan them for wrapping. */
SDL_SetRenderTextureAddressMode(renderer, SDL_TEXTURE_ADDRESS_CLAMP,
SDL_TEXTURE_ADDRESS_CLAMP);
@@ -641,6 +618,8 @@ nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer, struct nk_allocator allocat
sdl->ctx.clip.paste = nk_sdl_clipboard_paste;
sdl->ctx.clip.userdata = nk_handle_ptr((void*)sdl);
nk_buffer_init(&sdl->ogl.cmds, &sdl->allocator, NK_BUFFER_DEFAULT_INITIAL_SIZE);
nk_buffer_init(&sdl->ogl.vbuf, &sdl->allocator, NK_BUFFER_DEFAULT_INITIAL_SIZE);
nk_buffer_init(&sdl->ogl.ebuf, &sdl->allocator, NK_BUFFER_DEFAULT_INITIAL_SIZE);
sdl->edit_was_active = false;
sdl->insert_toggle = false;
sdl->last_render = SDL_GetTicksNS();
@@ -858,6 +837,8 @@ void nk_sdl_shutdown(struct nk_context* ctx)
#endif
nk_buffer_free(&sdl->ogl.cmds);
nk_buffer_free(&sdl->ogl.vbuf);
nk_buffer_free(&sdl->ogl.ebuf);
if (sdl->ogl.font_tex != NULL) {
SDL_DestroyTexture(sdl->ogl.font_tex);
@@ -869,132 +850,9 @@ void nk_sdl_shutdown(struct nk_context* ctx)
}
nk_free(ctx);
sdl->allocator.free(sdl->allocator.userdata, sdl->debug_font);
sdl->allocator.free(sdl->allocator.userdata, sdl);
}
/* Debug Font Width/Height of internal texture atlas
* This is a result of: ceil(sqrt('~' - ' '))
* There is a sanity check for this value in nk_sdl_style_set_debug_font */
#define NK_SDL_DFWH (10)
NK_INTERN float
nk_sdl_query_debug_font_width(nk_handle handle, float height,
const char *text, int len)
{
NK_UNUSED(handle);
return nk_utf_len(text, len) * height;
}
NK_INTERN void
nk_sdl_query_debug_font_glypth(nk_handle handle, float height,
struct nk_user_font_glyph *glyph,
nk_rune codepoint, nk_rune next_codepoint)
{
char ascii;
int idx, x, y;
NK_UNUSED(next_codepoint);
NK_UNUSED(handle);
/* replace non-ASCII characters with question mark */
ascii = (codepoint < (nk_rune)' ' || codepoint > (nk_rune)'~')
? '?' : (char)codepoint;
NK_ASSERT(ascii >= ' ' && ascii <= '~');
idx = (int)(ascii - ' ');
x = idx / NK_SDL_DFWH;
y = idx % NK_SDL_DFWH;
NK_ASSERT(x >= 0 && x < NK_SDL_DFWH);
NK_ASSERT(y >= 0 && y < NK_SDL_DFWH);
glyph->height = height;
glyph->width = height;
glyph->xadvance = height;
glyph->uv[0].x = (float)(x + 0) / NK_SDL_DFWH;
glyph->uv[0].y = (float)(y + 0) / NK_SDL_DFWH;
glyph->uv[1].x = (float)(x + 1) / NK_SDL_DFWH;
glyph->uv[1].y = (float)(y + 1) / NK_SDL_DFWH;
glyph->offset.x = 0.0f;
glyph->offset.y = 0.0f;
}
NK_API void
nk_sdl_style_set_debug_font(struct nk_context* ctx)
{
struct nk_user_font* font;
struct nk_sdl* sdl;
SDL_Surface *surface;
SDL_Renderer *renderer;
char buf[2];
int x, y;
bool success;
NK_ASSERT(ctx);
sdl = (struct nk_sdl*)ctx->userdata.ptr;
NK_ASSERT(sdl);
if (sdl->debug_font) {
sdl->allocator.free(sdl->allocator.userdata, sdl->debug_font);
sdl->debug_font = 0;
}
/* sanity check: formal proof of NK_SDL_DFWH value (which is 10) */
NK_ASSERT(SDL_ceil(SDL_sqrt('~' - ' ')) == NK_SDL_DFWH);
/* We use another Software Renderer just to make sure
* that we won't mutate any state in the main Renderer. */
surface = SDL_CreateSurface(
NK_SDL_DFWH * SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE,
NK_SDL_DFWH * SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE,
SDL_PIXELFORMAT_RGBA32);
NK_ASSERT(surface);
renderer = SDL_CreateSoftwareRenderer(surface);
NK_ASSERT(renderer);
success = SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
NK_ASSERT(success);
/* SPACE is the first printable ASCII character */
NK_MEMCPY(buf, " ", sizeof(buf));
for (x = 0; x < NK_SDL_DFWH; x++)
{
for (y = 0; y < NK_SDL_DFWH; y++)
{
success = SDL_RenderDebugText(
renderer,
(float)(x * SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE),
(float)(y * SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE),
buf);
NK_ASSERT(success);
buf[0]++;
/* TILDE is the last printable ASCII character */
if (buf[0] > '~')
break;
}
}
success = SDL_RenderPresent(renderer);
NK_ASSERT(success);
font = (struct nk_user_font*)sdl->allocator.alloc(sdl->allocator.userdata, 0, sizeof(*font));
NK_ASSERT(font);
font->userdata.ptr = sdl;
font->height = SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE;
font->width = &nk_sdl_query_debug_font_width;
font->query = &nk_sdl_query_debug_font_glypth;
/* HACK: nk_sdl_device_upload_atlas turns pixels into SDL_Texture
* and sets said Texture into sdl->ogl.font_tex
* then nk_sdl_render expects same Texture at font->texture */
nk_sdl_device_upload_atlas(ctx, surface->pixels, surface->w, surface->h);
font->texture.ptr = sdl->ogl.font_tex;
sdl->debug_font = font;
nk_style_set_font(ctx, font);
SDL_DestroyRenderer(renderer);
SDL_DestroySurface(surface);
}
#endif /* NK_SDL3_RENDERER_IMPLEMENTATION_ONCE */
#endif /* NK_SDL3_RENDERER_IMPLEMENTATION */
+30 -28
View File
@@ -92,8 +92,9 @@ plutovg_surface_t *reaktor_svg_surface_path(const char *rel_path, int size,
char fill_decl[32], stroke_decl[32], stroke_attr[32], svg_open[48];
char *svg;
const char *src;
char *stage0 = NULL, *stage1 = NULL, *stage2 = NULL, *stage3 = NULL;
size_t cap;
char *buf[2] = { NULL, NULL };
int k = 0, scale;
size_t cap = 0;
plutosvg_document_t *doc = NULL;
plutovg_surface_t *surf = NULL;
@@ -113,34 +114,37 @@ plutovg_surface_t *reaktor_svg_surface_path(const char *rel_path, int size,
snprintf(svg_open, sizeof(svg_open), "<svg fill=\"%s\" ",
outline_hex);
cap = strlen(svg) * 4 + 1024;
stage0 = (char *)malloc(cap);
stage1 = (char *)malloc(cap);
stage2 = (char *)malloc(cap);
stage3 = (char *)malloc(cap);
if (!stage0 || !stage1 || !stage2 || !stage3) { fprintf(stderr, "svg: alloc failed\n"); goto done; }
src = svg;
if (stroke_scale > 0.0f && stroke_scale != 1.0f) {
if (!str_scale_stroke(src, stage0, cap, stroke_scale)) goto done;
src = stage0;
scale = stroke_scale > 0.0f && stroke_scale != 1.0f;
if (outline_color || inside_color || scale) {
cap = strlen(svg) * 4 + 1024;
buf[0] = (char *)malloc(cap);
buf[1] = (char *)malloc(cap);
if (!buf[0] || !buf[1]) { fprintf(stderr, "svg: alloc failed\n"); goto done; }
}
if (scale) {
if (!str_scale_stroke(src, buf[k], cap, stroke_scale)) goto done;
src = buf[k];
k ^= 1;
}
if (inside_color) {
if (!str_replace_all(src, stage1, cap, "fill:none", fill_decl))
goto done;
src = stage1;
if (!str_replace_all(src, buf[k], cap, "fill:none", fill_decl)) goto done;
src = buf[k];
k ^= 1;
}
if (outline_color) {
if (!str_replace_all(src, stage2, cap, "stroke:#000", stroke_decl))
goto done;
if (!str_replace_all(stage2, stage3, cap, "stroke=\"#000\"",
stroke_attr))
goto done;
if (!str_replace_all(stage3, stage2, cap, "<svg ", svg_open)) {
fprintf(stderr, "svg: replace overflow\n");
goto done;
static const char *const from[3] = { "stroke:#000", "stroke=\"#000\"", "<svg " };
const char *to[3] = { stroke_decl, stroke_attr, svg_open };
int i;
for (i = 0; i < 3; i++) {
if (!str_replace_all(src, buf[k], cap, from[i], to[i])) {
fprintf(stderr, "svg: replace overflow\n");
goto done;
}
src = buf[k];
k ^= 1;
}
src = stage2;
}
doc = plutosvg_document_load_from_data(src, (int)strlen(src),
@@ -153,10 +157,8 @@ plutovg_surface_t *reaktor_svg_surface_path(const char *rel_path, int size,
done:
if (doc) plutosvg_document_destroy(doc);
free(stage3);
free(stage2);
free(stage1);
free(stage0);
free(buf[1]);
free(buf[0]);
reaktor_free(svg);
return surf;
}
+41 -14
View File
@@ -55,6 +55,7 @@ typedef struct shape_entry {
int file, len, text;
int glyph, glyphs, next;
float width;
Uint32 used;
} shape_entry;
typedef struct text_char {
@@ -75,6 +76,7 @@ typedef struct kb_config {
kbts_shape_config *shape;
kbts_glyph_config *glyph;
kbts_shape_scratchpad *scratch;
Uint32 used;
} kb_config;
typedef struct glyph_slot {
@@ -112,6 +114,7 @@ static char *g_bytes;
static int g_entries, g_entry_cap, g_glyphs, g_glyph_cap;
static int g_byte_n, g_byte_cap;
static int g_bucket[BUCKETS];
static Uint32 g_stamp;
static text_char *g_ch;
static text_run *g_run;
@@ -451,13 +454,20 @@ config_for(int font, kbts_script script)
for (i = 0; i < g_configs && !c; i++)
if (g_config[i].font == font && g_config[i].script == script)
c = &g_config[i];
if (c) c->used = g_stamp;
if (c && c->scratch) return c;
if (!c) {
if (g_configs == CONFIGS_MAX) {
for (i = 0; i < g_configs; i++) config_free(&g_config[i]);
g_configs = 0;
int old = 0;
for (i = 1; i < g_configs; i++)
if (g_config[i].used < g_config[old].used) old = i;
config_free(&g_config[old]);
g_config[old] = g_config[--g_configs];
}
c = &g_config[g_configs];
SDL_zerop(c);
c->used = g_stamp;
c->font = font;
c->script = script;
c->shape = kbts_CreateShapeConfig(&g_font[font].kb, script,
@@ -517,17 +527,18 @@ static int
shape(int file, const char *s, int len)
{
shape_entry *e;
Uint32 hash = 2166136261u ^ (Uint32)file;
Uint32 hash = reaktor_fnv_n(REAKTOR_FNV ^ (Uint32)file, s, (size_t)(len > 0 ? len : 0));
void *p;
float pen = 0.0f;
int i, n, runs, first;
for (i = 0; i < len; i++) hash = (hash ^ (Uint8)s[i]) * 16777619u;
for (i = g_bucket[hash & (BUCKETS - 1)]; i > 0; i = g_entry[i - 1].next) {
e = &g_entry[i - 1];
if (e->hash == hash && e->file == file && e->len == len &&
SDL_memcmp(g_bytes + e->text, s, (size_t)len) == 0)
SDL_memcmp(g_bytes + e->text, s, (size_t)len) == 0) {
e->used = g_stamp;
return i - 1;
}
}
if (len <= 0 || !font_open(file) || (n = decode(s, len)) <= 0) return -1;
@@ -554,6 +565,7 @@ shape(int file, const char *s, int len)
e->glyph = first;
e->glyphs = g_glyphs - first;
e->width = pen;
e->used = g_stamp;
e->next = g_bucket[hash & (BUCKETS - 1)];
g_bucket[hash & (BUCKETS - 1)] = g_entries + 1;
SDL_memcpy(g_bytes + g_byte_n, s, (size_t)len);
@@ -561,17 +573,31 @@ shape(int file, const char *s, int len)
return g_entries++;
}
/* Keeps what the frame just measured, so a full cache does not reshape
everything on screen at once. */
static void
shapes_forget(void)
shapes_compact(void)
{
SDL_free(g_entry);
SDL_free(g_glyph);
SDL_free(g_bytes);
g_entry = NULL;
g_glyph = NULL;
g_bytes = NULL;
g_entries = g_entry_cap = g_glyphs = g_glyph_cap = g_byte_n = g_byte_cap = 0;
int i, n = 0, glyphs = 0, bytes = 0;
SDL_memset(g_bucket, 0, sizeof g_bucket);
for (i = 0; i < g_entries; i++) {
shape_entry e = g_entry[i];
if (e.used != g_stamp) continue;
SDL_memmove(g_glyph + glyphs, g_glyph + e.glyph, (size_t)e.glyphs * sizeof *g_glyph);
SDL_memmove(g_bytes + bytes, g_bytes + e.text, (size_t)e.len);
e.glyph = glyphs;
e.text = bytes;
e.next = g_bucket[e.hash & (BUCKETS - 1)];
g_bucket[e.hash & (BUCKETS - 1)] = n + 1;
glyphs += e.glyphs;
bytes += e.len;
g_entry[n++] = e;
}
g_entries = n;
g_glyphs = glyphs;
g_byte_n = bytes;
}
static int
@@ -830,7 +856,8 @@ reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
g_draws = 0;
if (!g_took) return;
g_took = 0;
if (g_glyphs > SHAPED_MAX) shapes_forget();
if (g_glyphs > SHAPED_MAX) shapes_compact();
g_stamp++;
if (g_full) glyphs_forget();
nk_foreach(cmd, ctx) {
+21 -14
View File
@@ -23,7 +23,7 @@ fit_button(reaktor_box *box, const reaktor_button_spec *s)
border = st.matched ? st.border : nb->border;
edge = border + (st.matched ? st.rounding : nb->rounding);
if (s->label)
text = f->width(f->userdata, f->height, s->label, (int)strlen(s->label));
text = reaktor_text_w(f, s->label);
w = text + 2.0f * (pad_x + (st.matched ? border : edge));
if (s->icon && s->label) {
@@ -142,9 +142,19 @@ wrap_guess(const struct nk_user_font *f, const char *s, int len, float space)
nk_rune cp;
while (at < len) {
int n = nk_utf_decode(s + at, &cp, len - at);
int n, e = at;
float g;
while (e < len && s[e] != ' ') e++;
if (e < len) e++;
g = f->width(f->userdata, f->height, s + at, e - at);
if (w + g <= space) {
w += g;
at = e;
continue;
}
n = nk_utf_decode(s + at, &cp, len - at);
if (n <= 0) return at ? at : len;
g = f->width(f->userdata, f->height, s + at, n);
if (w + g > space && at > 0) {
@@ -182,16 +192,14 @@ wrap_lines(unsigned id, const struct nk_user_font *f, const char *s,
float space, const wrapped **out)
{
wrapped *w = &g_wraps[id & 63];
unsigned h = 2166136261u, loads = reaktor_style_loads();
const char *p;
unsigned h = reaktor_fnv(REAKTOR_FNV, s), loads = reaktor_style_loads();
int len, done = 0, lines = 0;
for (p = s; *p; p++) h = (h ^ (unsigned char)*p) * 16777619u;
*out = w;
if (w->hash == h && w->f == f && w->space == space &&
w->height == f->height && w->loads == loads)
return w->lines > 0 ? w->lines : 1;
len = (int)(p - s);
len = (int)SDL_strlen(s);
while (done < len) {
done += wrap_fit(f, s + done, len - done, space);
if (lines < WRAP_LINES) w->end[lines] = done;
@@ -277,10 +285,10 @@ reaktor_label(const reaktor_label_spec *s)
if (!reaktor_layout_rect(&g_frame_app->lay, id, &prev) || prev.h != box.h)
g_frame_unsettled++;
} else {
decl_box_default(&box,
f->width(f->userdata, f->height, s->text,
(int)strlen(s->text)),
f->height);
float w = box.w > 0.0f || (box.flags & REAKTOR_LAY_FILL_X) ? 0.0f
: reaktor_text_w(f, s->text);
decl_box_default(&box, w, f->height);
}
if (!decl_emit(id, NULL, &box)) return;
@@ -487,8 +495,7 @@ reaktor_swatch(const reaktor_swatch_spec *s)
decl_box_default(&box, 40.0f, 0.0f);
decl_box_default(&box, 0.0f, box.w);
SDL_snprintf(hex, sizeof(hex), "#%02x%02x%02x",
s->fill.r, s->fill.g, s->fill.b);
reaktor_hex(s->fill, hex);
if (!decl_place(REAKTOR_A11Y_BUTTON, s->name, hex, 0u, NULL, &box, &id))
return 0;
@@ -798,7 +805,7 @@ reaktor_spinner(const reaktor_spinner_spec *s)
if (s->label)
nk_draw_text(cv, nk_rect(step[0].x + step[0].w + 8.0f, y, r.w * 0.5f, f->height),
s->label, (int)strlen(s->label), f, nk_rgba(0, 0, 0, 0), st->label_normal);
w = f->width(f->userdata, f->height, value, (int)strlen(value));
w = reaktor_text_w(f, value);
nk_draw_text(cv, nk_rect(step[1].x - 8.0f - w, y, w, f->height), value,
(int)strlen(value), f, nk_rgba(0, 0, 0, 0), st->label_normal);
if (nk_input_mouse_clicked(&ctx->input, NK_BUTTON_LEFT, step[0])) d = -1;
@@ -909,7 +916,7 @@ reaktor_color_pick(const reaktor_color_spec *s)
if (!g_frame_app || !s || !s->value) return;
c = nk_rgb_cf(*s->value);
SDL_snprintf(hex, sizeof(hex), "#%02x%02x%02x", c.r, c.g, c.b);
reaktor_hex(c, hex);
box = s->box;
decl_box_default(&box, 210.0f, 132.0f);
+1 -1
View File
@@ -319,7 +319,7 @@ decl_box_from_style(reaktor_box *box, const char *text, const char *selector,
if (box->w <= 0.0f && text && !(box->flags & REAKTOR_LAY_FILL_X)) {
float w = st.width > 0.0f
? st.width
: f->width(f->userdata, f->height, text, (int)strlen(text))
: reaktor_text_w(f, text)
+ extra_w;
if (w < st.min_width) w = st.min_width;
if (st.max_width > 0.0f && w > st.max_width) w = st.max_width;
+19 -9
View File
@@ -11,6 +11,17 @@ rect_of(float x, float y, float w, float h)
return r;
}
/* The direction a box was declared with, read back from onlay's own item. */
static unsigned char
dir_of(const reaktor_layout *l, lay_id it)
{
switch (lay_get_item(&l->ctx, it)->flags & 3u) {
case LAY_ROW: return REAKTOR_LAY_ROW;
case LAY_COLUMN: return REAKTOR_LAY_COLUMN;
default: return REAKTOR_LAY_FREE;
}
}
static uint32_t
contain_of(const reaktor_box *b)
{
@@ -60,9 +71,6 @@ declare(reaktor_layout *l, unsigned id, const reaktor_box *b)
it = lay_item(&l->ctx);
if (it < REAKTOR_LAY_MAX) {
l->flags[it] = b->flags;
l->dir[it] = b->dir;
l->w[it] = b->w;
l->h[it] = b->h;
}
lay_set_size_xy(&l->ctx, it, (lay_scalar)b->w, (lay_scalar)b->h);
lay_set_contain(&l->ctx, it, contain_of(b));
@@ -140,7 +148,7 @@ reaktor_layout_open_dir(const reaktor_layout *l)
if (l->depth <= 1 || l->depth > REAKTOR_LAY_DEPTH) return REAKTOR_LAY_COLUMN;
box = l->stack[l->depth - 1];
return box < REAKTOR_LAY_MAX ? l->dir[box] : REAKTOR_LAY_COLUMN;
return box < REAKTOR_LAY_MAX ? dir_of(l, box) : REAKTOR_LAY_COLUMN;
}
static reaktor_lay_slot *
@@ -182,8 +190,8 @@ part_neighbors(reaktor_layout *l, lay_id box)
lay_id c, prev = LAY_INVALID_ID;
int lead, trail;
if (box >= REAKTOR_LAY_MAX || l->dir[box] == REAKTOR_LAY_FREE) return;
lead = l->dir[box] == REAKTOR_LAY_ROW ? 0 : 1;
if (box >= REAKTOR_LAY_MAX || dir_of(l, box) == REAKTOR_LAY_FREE) return;
lead = dir_of(l, box) == REAKTOR_LAY_ROW ? 0 : 1;
trail = lead + 2;
for (c = lay_first_child(&l->ctx, box); c != LAY_INVALID_ID;
@@ -253,9 +261,11 @@ reaktor_layout_info(const reaktor_layout *l, unsigned id, unsigned *flags,
if (l->id[i] != id || it >= REAKTOR_LAY_MAX) continue;
*flags = l->flags[it];
*dir = l->dir[it];
*w = l->w[it];
*h = l->h[it];
lay_vec2 size = lay_get_size((lay_context *)&l->ctx, it);
*dir = dir_of(l, it);
*w = size.v[0];
*h = size.v[1];
return 1;
}
return 0;
-2
View File
@@ -31,8 +31,6 @@ typedef struct reaktor_layout {
int count;
unsigned flags[REAKTOR_LAY_MAX];
unsigned char dir[REAKTOR_LAY_MAX];
float w[REAKTOR_LAY_MAX], h[REAKTOR_LAY_MAX];
lay_id stack[REAKTOR_LAY_DEPTH];
int depth;
+5 -11
View File
@@ -31,12 +31,6 @@ tr_or(const char *key, const char *english)
return s && SDL_strcmp(s, key) != 0 ? s : english;
}
static float
text_w(const struct nk_user_font *f, const char *s)
{
return f->width(f->userdata, f->height, s, (int)SDL_strlen(s));
}
static const char *
pick_label(const pick_col *c, int v, char *buf, size_t cap)
{
@@ -122,7 +116,7 @@ pick_draw_wheels(App *app, struct nk_context *ctx, struct nk_rect body, float ro
struct nk_rect col = nk_rect(x, body.y, c->w, row * PICK_ROWS);
unsigned id;
reaktor_hot(app, col, 1, 1);
reaktor_hot(app, col, REAKTOR_CURSOR_POINTER, 1);
if (!g_pick.fresh && nk_input_is_mouse_hovering_rect(&ctx->input, col) &&
ctx->input.mouse.scroll_delta.y != 0.0f) {
c->at = pick_wrap(c, c->at - (ctx->input.mouse.scroll_delta.y > 0.0f ? 1 : -1));
@@ -142,7 +136,7 @@ pick_draw_wheels(App *app, struct nk_context *ctx, struct nk_rect body, float ro
g_pick.key = k;
}
t = pick_label(c, v, buf, sizeof buf);
w = f->width(f->userdata, f->height, t, (int)SDL_strlen(t));
w = reaktor_text_w(f, t);
nk_draw_text(cv, nk_rect(r.x + (r.w - w) * 0.5f,
(float)(int)(r.y + (r.h - f->height) * 0.5f), w, f->height),
t, (int)SDL_strlen(t), f, nk_rgba(0, 0, 0, 0),
@@ -195,7 +189,7 @@ pick_flyout(App *app, struct nk_context *ctx, float row)
float need;
reaktor_style_get("button", &btn);
need = 2.0f * (NK_MAX(text_w(ctx->style.font, no), text_w(ctx->style.font, ok)) +
need = 2.0f * (NK_MAX(reaktor_text_w(ctx->style.font, no), reaktor_text_w(ctx->style.font, ok)) +
2.0f * (btn.pad_x + btn.border)) + 3.0f * PICK_GAP;
for (k = 0; k < g_pick.n; k++) w += g_pick.col[k].w;
@@ -267,7 +261,7 @@ pick_field(const void *owner, const char *name, const reaktor_box *spec_box,
reaktor_style_frame_pop(ctx, sf);
decl_box_from_style(&box, NULL, "input.type-text", "input", 0.0f, 7.0f);
if (box.w <= 0.0f && !(box.flags & REAKTOR_LAY_FILL_X))
box.w = (float)(int)(text_w(f, value ? value : hint) + 2.0f * in.pad_x + 0.5f);
box.w = (float)(int)(reaktor_text_w(f, value ? value : hint) + 2.0f * in.pad_x + 0.5f);
if (!decl_place(REAKTOR_A11Y_BUTTON, name, value,
g_pick.owner == owner ? REAKTOR_A11Y_EXPANDED : 0u, NULL, &box, &id))
return 0;
@@ -295,7 +289,7 @@ pick_field(const void *owner, const char *name, const reaktor_box *spec_box,
float w = 0.0f;
for (v = cols[k].lo; v <= cols[k].hi; v++)
w = NK_MAX(w, text_w(f, pick_label(&cols[k], v, buf, sizeof buf)));
w = NK_MAX(w, reaktor_text_w(f, pick_label(&cols[k], v, buf, sizeof buf)));
g_pick.col[k].w = (float)(int)(w + 32.0f);
}
pick_days();
+10 -15
View File
@@ -259,7 +259,7 @@ reaktor_css_button_look(App *app, struct nk_context *ctx,
unsigned id;
int clicked;
hot_push(app, nk_widget_bounds(ctx), 1, 1);
hot_push(app, nk_widget_bounds(ctx), REAKTOR_CURSOR_POINTER, 1);
id = reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, label, 0);
f = push_button_look(app, ctx, k);
reaktor_button_arm(ctx);
@@ -332,7 +332,7 @@ css_button_accent(App *app, struct nk_context *ctx, const char *selector,
struct nk_color label_col;
int clicked;
hot_push(app, nk_widget_bounds(ctx), 1, 1);
hot_push(app, nk_widget_bounds(ctx), REAKTOR_CURSOR_POINTER, 1);
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, label, 0);
f = push_button_style(app, ctx, selector);
@@ -370,7 +370,7 @@ icon_place(struct nk_context *ctx, struct nk_rect b, float pad_x,
{
const struct nk_style_button *s = &ctx->style.button;
const struct nk_user_font *f = ctx->style.font;
float text = f->width(f->userdata, f->height, label, (int)SDL_strlen(label));
float text = reaktor_text_w(f, label);
at->x = b.x + 2.0f * pad_x + s->image_padding.x;
at->y = b.y + s->padding.y + s->image_padding.y;
@@ -391,7 +391,7 @@ css_button_icon(App *app, struct nk_context *ctx, const char *selector,
struct nk_rect b = nk_widget_bounds(ctx), at;
int clicked, drawn;
hot_push(app, b, 1, 1);
hot_push(app, b, REAKTOR_CURSOR_POINTER, 1);
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, label, 0);
reaktor_button_look_of(selector, &k);
f = push_button_look(app, ctx, &k);
@@ -444,7 +444,7 @@ reaktor_css_button_flat(App *app, struct nk_context *ctx, const char *icon,
float px = (float)(int)(b.h * 0.6f);
int clicked;
hot_push(app, b, 1, 1);
hot_push(app, b, REAKTOR_CURSOR_POINTER, 1);
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, name, 0);
nk_style_push_style_item(ctx, &ctx->style.button.normal,
nk_style_item_color(nk_rgba(0, 0, 0, 0)));
@@ -466,7 +466,7 @@ reaktor_css_button_image(App *app, struct nk_context *ctx, const char *selector,
reaktor_style_frame f;
int clicked;
hot_push(app, b, 1, 1);
hot_push(app, b, REAKTOR_CURSOR_POINTER, 1);
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, name, 0);
f = push_button_style(app, ctx, selector);
clicked = press_blank(ctx);
@@ -824,13 +824,8 @@ apply_widget_style(App *app)
st->progress.cursor_border_color = accent;
st->progress.border = 0.0f;
st->progress.cursor_border = 0.0f;
{
reaktor_style bs;
reaktor_style_get("button", &bs);
st->progress.rounding = bs.matched ? bs.rounding : 3.0f;
st->progress.cursor_rounding = st->progress.rounding;
}
st->progress.rounding = btn.matched ? btn.rounding : 3.0f;
st->progress.cursor_rounding = st->progress.rounding;
st->property.normal = i_base;
st->property.hover = i_hover;
@@ -883,8 +878,8 @@ apply_widget_style(App *app)
st->tab.rounding = det.rounding;
st->tab.padding = nk_vec2(det.pad_x, det.pad_y);
}
st->tab.sym_minimize = NK_SYMBOL_NONE;
st->tab.sym_maximize = NK_SYMBOL_NONE;
st->tab.sym_minimize = NK_SYMBOL_TRIANGLE_RIGHT;
st->tab.sym_maximize = NK_SYMBOL_TRIANGLE_DOWN;
st->property.sym_left = NK_SYMBOL_NONE;
st->property.sym_right = NK_SYMBOL_NONE;
+2 -8
View File
@@ -80,18 +80,12 @@ reaktor_toast_clear(void)
while (g_toast_n) drop(g_toast_n - 1);
}
static float
text_w(const struct nk_user_font *f, const char *s)
{
return s ? f->width(f->userdata, f->height, s, (int)SDL_strlen(s)) : 0.0f;
}
static float
action_w(const struct nk_context *ctx, const struct nk_user_font *f, const char *s)
{
const struct nk_style_button *b = &ctx->style.button;
return (float)(int)(text_w(f, s) + 2.0f * (b->padding.x + b->border + b->rounding) + 1.0f);
return (float)(int)(reaktor_text_w(f, s) + 2.0f * (b->padding.x + b->border + b->rounding) + 1.0f);
}
void
@@ -128,7 +122,7 @@ reaktor_toasts_draw(App *app, struct nk_context *ctx, int win_w, int win_h,
n = g_toast_n - first;
for (i = 0; i < n; i++) {
const toast *t = &g_toast[first + i];
float tw = pad_l + pad_r + text_w(font, t->text);
float tw = pad_l + pad_r + reaktor_text_w(font, t->text);
if (t->icon) tw += 20.0f + 8.0f;
if (t->spec.content) tw += t->spec.content_w + 8.0f;
+5 -11
View File
@@ -575,12 +575,6 @@ static struct {
int picked_k, picked_i;
} g_menu = { -1 };
static float
menu_text_w(const struct nk_user_font *f, const char *s)
{
return s ? f->width(f->userdata, f->height, s, (int)strlen(s)) : 0.0f;
}
static int
menu_rule(const reaktor_menu_entry *e)
{
@@ -627,8 +621,8 @@ menu_measure(menu_col *c, const struct nk_user_font *f, struct nk_vec2 pad)
if (i) h += REAKTOR_MENU_GAP;
h += menu_entry_h(e);
if (!e->custom && e->label)
iw = 28.0f + c->lead + menu_text_w(f, e->label) +
(e->keys ? 24.0f + menu_text_w(f, e->keys) : 0.0f) +
iw = 28.0f + c->lead + reaktor_text_w(f, e->label) +
(e->keys ? 24.0f + reaktor_text_w(f, e->keys) : 0.0f) +
(e->items ? 22.0f : 0.0f);
if (iw > w) w = iw;
}
@@ -724,7 +718,7 @@ menu_draw_entry(const reaktor_menu_entry *e, struct nk_rect b, float lead, int l
b.w - 16.0f - lead, f->height),
e->label, (int)strlen(e->label), f, nk_rgba(0, 0, 0, 0), fg);
if (e->keys) {
float w = menu_text_w(f, e->keys);
float w = reaktor_text_w(f, e->keys);
nk_draw_text(cv, nk_rect(b.x + b.w - w - 8.0f,
(float)(int)(b.y + (b.h - f->height) * 0.5f), w, f->height),
@@ -983,7 +977,7 @@ reaktor_menubar(const reaktor_menubar_spec *s)
struct nk_style_button st = *mb;
memset(&title, 0, sizeof(title));
title.w = (float)(int)(menu_text_w(f, label) +
title.w = (float)(int)(reaktor_text_w(f, label) +
2.0f * (mb->padding.x + mb->border + mb->rounding) + 2.5f);
title.h = h;
if (!decl_place(REAKTOR_A11Y_MENU, label, NULL,
@@ -992,7 +986,7 @@ reaktor_menubar(const reaktor_menubar_spec *s)
continue;
r = nk_widget_bounds(ctx);
g_menu.title[m] = r;
reaktor_hot(app, r, 1, 1);
reaktor_hot(app, r, REAKTOR_CURSOR_POINTER, 1);
if (g_menu.open == m) { st.normal = st.active; st.text_normal = st.text_active; }
nk_button_text_styled(ctx, &st, label, (int)strlen(label));
if (!nk_input_is_mouse_hovering_rect(&ctx->input, r)) continue;
+72 -72
View File
@@ -25,45 +25,57 @@ reaktor_font(App *app, int px, int bold)
#define ICON_HAIRLINE_BELOW 20
static const char *
icon_src(char out[192], const char *name, const char *hex, float sw)
{
if (sw < 0.0f)
SDL_snprintf(out, 192, "external/ionicons/src/svg/%s.svg?stroke=%s", name, hex);
else
SDL_snprintf(out, 192, "external/ionicons/src/svg/%s.svg?stroke=%s&sw=%.2f",
name, hex, (double)sw);
return out;
}
static void
push_clear(struct nk_context *ctx, struct nk_style_item *const *items, int n,
struct nk_style_item clear)
{
while (n--) nk_style_push_style_item(ctx, *items++, clear);
}
static void
pop_items(struct nk_context *ctx, int n)
{
while (n--) nk_style_pop_style_item(ctx);
}
struct nk_image
reaktor_ionicon(App *app, const char *name, int px)
{
char src[192];
if (px < ICON_HAIRLINE_BELOW)
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg?stroke=%s&sw=%.2f",
name, app->icon_hex, (double)GLYPH_STROKE);
else
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg?stroke=%s",
name, app->icon_hex);
return icon(app, src, px);
return icon(app, icon_src(src, name, app->icon_hex,
px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : -1.0f), px);
}
struct nk_image
reaktor_ionicon_exact(App *app, const char *name, int px,
struct nk_color stroke, float sw)
{
char src[192];
char hex[8], src[192];
if (sw <= 0.0f) sw = px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : 1.0f;
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg?stroke=#%02x%02x%02x"
"&sw=%.2f", name, stroke.r, stroke.g, stroke.b, (double)sw);
return icon_over(app, src, px, 1.0f);
reaktor_hex(stroke, hex);
return icon_over(app, icon_src(src, name, hex, sw), px, 1.0f);
}
struct nk_image
reaktor_ionicon_col(App *app, const char *name, int px, struct nk_color stroke)
{
char src[192];
char hex[8], src[192];
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg?stroke=#%02x%02x%02x"
"&sw=%.2f", name, stroke.r, stroke.g, stroke.b,
px < ICON_HAIRLINE_BELOW ? (double)GLYPH_STROKE : 1.0);
return icon(app, src, px);
reaktor_hex(stroke, hex);
return icon(app, icon_src(src, name, hex, px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : 1.0f), px);
}
struct nk_color
@@ -119,7 +131,7 @@ reaktor_link_label(App *app, struct nk_context *ctx, const char *label, int acti
{
struct nk_rect b = nk_widget_bounds(ctx);
hot_push(app, b, 1, 0);
hot_push(app, b, REAKTOR_CURSOR_POINTER, 0);
reaktor_note(app, REAKTOR_A11Y_LINK, label, NULL,
active ? REAKTOR_A11Y_SELECTED : 0u, b);
if (nk_input_is_mouse_click_in_rect(&ctx->input, NK_BUTTON_LEFT, b))
@@ -149,22 +161,19 @@ reaktor_radio_label(App *app, struct nk_context *ctx, const char *label,
int side, dot_px;
int clicked = 0;
nk_style_push_style_item(ctx, &ctx->style.option.normal, clear);
nk_style_push_style_item(ctx, &ctx->style.option.hover, clear);
nk_style_push_style_item(ctx, &ctx->style.option.active, clear);
nk_style_push_style_item(ctx, &ctx->style.option.cursor_normal, clear);
nk_style_push_style_item(ctx, &ctx->style.option.cursor_hover, clear);
push_clear(ctx, (struct nk_style_item *[]){
&ctx->style.option.normal,
&ctx->style.option.hover,
&ctx->style.option.active,
&ctx->style.option.cursor_normal,
&ctx->style.option.cursor_hover }, 5, clear);
nk_style_push_color(ctx, &ctx->style.option.border_color, clear.data.color);
nk_style_push_float(ctx, &ctx->style.option.border, 0.0f);
if (nk_option_label_align(ctx, label, on, NK_WIDGET_RIGHT, NK_TEXT_LEFT))
clicked = 1;
nk_style_pop_float(ctx);
nk_style_pop_color(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
pop_items(ctx, 5);
ring = nk_rect(r.x + r.w - h, r.y + r.h * 0.5f - h * 0.5f, h, h);
dot = nk_rect(ring.x + st->padding.x + st->border,
@@ -217,15 +226,14 @@ reaktor_slider_bar(App *app, struct nk_context *ctx, unsigned id, float *val,
nk_style_push_color(ctx, &ctx->style.slider.bar_hover, clear.data.color);
nk_style_push_color(ctx, &ctx->style.slider.bar_active, clear.data.color);
nk_style_push_color(ctx, &ctx->style.slider.bar_filled, clear.data.color);
nk_style_push_style_item(ctx, &ctx->style.slider.cursor_normal, clear);
nk_style_push_style_item(ctx, &ctx->style.slider.cursor_hover, clear);
nk_style_push_style_item(ctx, &ctx->style.slider.cursor_active, clear);
push_clear(ctx, (struct nk_style_item *[]){
&ctx->style.slider.cursor_normal,
&ctx->style.slider.cursor_hover,
&ctx->style.slider.cursor_active }, 3, clear);
nk_style_push_float(ctx, &ctx->style.slider.border, 0.0f);
nk_slider_float(ctx, lo, val, hi, step);
nk_style_pop_float(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
pop_items(ctx, 3);
nk_style_pop_color(ctx);
nk_style_pop_color(ctx);
nk_style_pop_color(ctx);
@@ -294,23 +302,19 @@ reaktor_progress_bar(App *app, struct nk_context *ctx, nk_size *cur, nk_size max
if (r < 0.0f) r = 0.0f;
hot_push(app, b, 0, 1);
nk_style_push_style_item(ctx, &ctx->style.progress.normal, clear);
nk_style_push_style_item(ctx, &ctx->style.progress.hover, clear);
nk_style_push_style_item(ctx, &ctx->style.progress.active, clear);
nk_style_push_style_item(ctx, &ctx->style.progress.cursor_normal, clear);
nk_style_push_style_item(ctx, &ctx->style.progress.cursor_hover, clear);
nk_style_push_style_item(ctx, &ctx->style.progress.cursor_active, clear);
push_clear(ctx, (struct nk_style_item *[]){
&ctx->style.progress.normal,
&ctx->style.progress.hover,
&ctx->style.progress.active,
&ctx->style.progress.cursor_normal,
&ctx->style.progress.cursor_hover,
&ctx->style.progress.cursor_active }, 6, clear);
nk_style_push_float(ctx, &ctx->style.progress.border, 0.0f);
nk_style_push_float(ctx, &ctx->style.progress.cursor_border, 0.0f);
nk_progress(ctx, cur, max, modifiable);
nk_style_pop_float(ctx);
nk_style_pop_float(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
pop_items(ctx, 6);
if (track_it.type == NK_STYLE_ITEM_COLOR)
reaktor_fill_round(app, cv, b, track_r, track_it.data.color);
@@ -344,9 +348,10 @@ reaktor_knob_dial(App *app, struct nk_context *ctx, float *val, float lo, float
cols[4] = &st->cursor_normal; cols[5] = &st->cursor_hover;
cols[6] = &st->cursor_active;
nk_style_push_style_item(ctx, &st->normal, clear);
nk_style_push_style_item(ctx, &st->hover, clear);
nk_style_push_style_item(ctx, &st->active, clear);
push_clear(ctx, (struct nk_style_item *[]){
&st->normal,
&st->hover,
&st->active }, 3, clear);
for (i = 0; i < 7; i++)
nk_style_push_color(ctx, cols[i], clear.data.color);
nk_style_push_float(ctx, &st->knob_border, 0.0f);
@@ -354,9 +359,7 @@ reaktor_knob_dial(App *app, struct nk_context *ctx, float *val, float lo, float
nk_style_pop_float(ctx);
for (i = 0; i < 7; i++)
nk_style_pop_color(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
pop_items(ctx, 3);
a = (hi > lo) ? (*val - lo) / (hi - lo) : 0.0f;
a = a * NK_PI * 2.0f + zero_rads[zero];
@@ -400,7 +403,7 @@ stepper_wash(App *app, struct nk_context *ctx, struct nk_rect sq)
}
/* How far below a centered line's middle its capitals' middle lies. */
float
static float
reaktor_cap_offset(const struct nk_user_font *f)
{
const struct nk_font *nf = f ? (const struct nk_font *)f->userdata.ptr : NULL;
@@ -438,19 +441,17 @@ reaktor_property_push(struct nk_context *ctx)
{
struct nk_style_item clear = nk_style_item_color(nk_rgba(0, 0, 0, 0));
nk_style_push_style_item(ctx, &ctx->style.property.dec_button.hover, clear);
nk_style_push_style_item(ctx, &ctx->style.property.dec_button.active, clear);
nk_style_push_style_item(ctx, &ctx->style.property.inc_button.hover, clear);
nk_style_push_style_item(ctx, &ctx->style.property.inc_button.active, clear);
push_clear(ctx, (struct nk_style_item *[]){
&ctx->style.property.dec_button.hover,
&ctx->style.property.dec_button.active,
&ctx->style.property.inc_button.hover,
&ctx->style.property.inc_button.active }, 4, clear);
}
void
reaktor_property_pop(struct nk_context *ctx)
{
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
pop_items(ctx, 4);
}
#define COMBO_MARGIN 12.0f
@@ -554,8 +555,8 @@ reaktor_css_button_color(App *app, struct nk_context *ctx, const char *name,
char hex[10];
int clicked;
hot_push(app, b, 1, 1);
SDL_snprintf(hex, sizeof(hex), "#%02x%02x%02x", fill.r, fill.g, fill.b);
hot_push(app, b, REAKTOR_CURSOR_POINTER, 1);
reaktor_hex(fill, hex);
reaktor_note(app, REAKTOR_A11Y_BUTTON, name, hex, 0, b);
hov[0] = fill.r; hov[1] = fill.g; hov[2] = fill.b; hov[3] = fill.a;
@@ -572,9 +573,7 @@ reaktor_css_button_color(App *app, struct nk_context *ctx, const char *name,
clicked = nk_button_label(ctx, "");
reaktor_chrome_disarm();
nk_style_pop_color(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
nk_style_pop_style_item(ctx);
pop_items(ctx, 3);
return clicked;
}
@@ -753,7 +752,7 @@ reaktor_field_text_as(App *app, struct nk_context *ctx, const char *sel,
struct nk_vec2 hint_pad;
note_field_rect(app, ctx, bounds);
hot_push(app, bounds, 2, 0);
hot_push(app, bounds, REAKTOR_CURSOR_TEXT, 0);
f = push_edit_style(ctx, &s, sel);
reaktor_edit_edge(app, ctx, bounds, &s);
@@ -1266,8 +1265,9 @@ reaktor_diagnostics(App *app, reaktor_diag *out)
out->font = drawn[0] ? line : app->font_status;
}
out->vsync = app->vsync_on;
out->aa = !app->aa ? "off"
: app->renderer_is_sw && app->sw_noaa ? "off (software renderer)"
out->aa = app->aa_mode == REAKTOR_AA_OFF ? "off"
: !reaktor_aa_lines(app) ? "off (software renderer)"
: reaktor_aa_fills(app) ? "strokes and fills"
: "strokes only";
out->dark = app->dark;
out->sheets = app->sheets;
+1 -1
View File
@@ -35,7 +35,7 @@ Animation, Styling, Translations, Diagnostics — with the color scheme and the
titlebar switch at its foot, and an icon in the tray. It is the reference for
what the library draws, and where its claims are tested rather than asserted:
- **Styling** lays Bamboo over Water.css at the flick of a checkbox, and
- **Styling** lays Simple.css over Water.css at the flick of a checkbox, and
prints what each rule resolved to beside the widgets it painted.
- **Translations** sets the opening of *The Ugly Duckling* in English, Polish
and Japanese from the catalogs, beside a date, a number, one amount in three
+69 -18
View File
@@ -54,7 +54,7 @@ errors, so an internal function cannot slip back in.
| `key(app, event)` | A key press in any window, with that window's App, before focus navigation; non-zero keeps the key and its text from everything else |
| `closing(app, reason)` | Before quitting; non-zero refuses a close button (`REAKTOR_QUIT_WINDOW`), `reaktor_request_quit` or macOS's Quit (`_APP`) and a first Ctrl+C (`_CONSOLE`). SIGTERM (`_SIGNAL`) and logoff (`_SESSION`) ask but cannot be refused |
| `stop(app)` | Once before teardown when `start` succeeded, at logoff and page unload too — the only place for cleanup |
| `file_opened(app, path)` | A file dropped on a window, with that window's App |
| `file_opened(app, path)` | A file dropped on a window, with that window's App; with `.single_instance`, also each file a later launch hands over |
| Call | Effect |
| --- | --- |
@@ -63,6 +63,7 @@ errors, so an internal function cannot slip back in.
| `reaktor_wake(app)` | Draw a frame of that App's window. Any thread |
| `reaktor_set_theme(app, theme)` | `REAKTOR_THEME_SYSTEM`, `_LIGHT` or `_DARK`, for every window |
| `reaktor_set_css(app, sheets, n)` | Replace the application's sheets; `--css` stays on top |
| `reaktor_reduced_motion()`, `reaktor_high_contrast()` | Whether the system asks for less motion or more contrast, after `--motion` and `--contrast` |
| `reaktor_set_title(app, title)` | Retitle that App's window |
| `reaktor_set_confirm_close(app, question)` | Ask `question` before quitting, or with `NULL` stop asking |
| `reaktor_user(app)` | The launch's `.user` |
@@ -72,7 +73,7 @@ errors, so an internal function cannot slip back in.
| `reaktor_lang_pref(app)` | The language `--lang` asked for, or `NULL` |
| `reaktor_set_borderless(app, on)`, `reaktor_borderless(app)` | Switch the main window's frame off for a titlebar of your own, drawn with `.window.hit_test` |
| `reaktor_set_visible(app, on)` | Show or hide that App's window; with `.window.hidden`, the main window waits for it |
| `reaktor_version()` | Reaktor's version, such as `"0.6.0"` |
| `reaktor_version()` | Reaktor's version, such as `"0.7.0"` |
The `set` calls are for the main thread, take effect at the next frame, and do
nothing when nothing changes.
@@ -122,6 +123,19 @@ save mode to last, and restores them at start. Under `--shot` and
`--a11y-dump` settings are neither read nor written, so a user's file cannot
change a test.
**One copy at a time.** With `.single_instance`, a launch that finds the
application already running does not open a window: it hands its arguments,
made absolute, to the running copy and exits with 0. The running copy gets
each as `file_opened`, on the main thread, and comes to the front, restored
if it was minimized. The copies find each other by `.id` (or `.name`), per
user: a named mutex and a named pipe on Windows, a Unix socket in the
application's preference folder on macOS, Linux and the BSDs, replaced if a
copy that crashed left it behind. Launches that race each other settle on
one. `--new-instance` starts a separate copy anyway, and so do `--shot` and
`--a11y-dump`, which are tests. On the web there is one page per tab and the
field is ignored. On macOS, Finder and the Dock already hand a running app
its files, through the same `file_opened`.
**Notifications.** `reaktor_notify(app, &(reaktor_notification){ .title,
.text })` tells the user something outside the window and answers 1 when it
was sent. On Windows it is a balloon from an icon of the app's own, which
@@ -140,7 +154,7 @@ when unset. Each page is laid out and drawn as on screen, in a hidden window
at `.dpi` (200 unset), so it carries the window's look: a page that should be
white paints itself white. Both calls answer 1 when the job is queued; it runs
between frames, and `.done(app, ok, user)` says how it went. A page is an
image in the PDF, through [libHaru](https://github.com/libharu/libharu) and
image in the PDF, through [PDFGen](https://github.com/AndreRenaud/PDFGen) and
plutovg's JPEG writer, so its text is not selectable. To print, Windows shows
its print dialog and draws the pages to the printer; macOS opens its print
dialog on the PDF; Linux and the BSDs open the PDF in the user's viewer, which
@@ -179,6 +193,11 @@ and category, appended; `--log <path>` overrides it.
terminal or a console of its own, plus SDL's debug log). A redirected stream
stays redirected. Ctrl+C reaches the app only from a console it owns.
**Anti-aliasing.** `.anti_aliasing` is `REAKTOR_AA_AUTO` (strokes on every
renderer, fills on a GPU one; the default), `_ON` (fills on the software
renderer too, which it pays for) or `_OFF`. `--aa <auto|on|off>` overrides it.
Rounded fills are masks and look the same under each.
**Assets.** `.css` adds up to four sheets after Water.css and reaktor.css
(`.no_reaktor_css` drops reaktor.css), `.font` and `.font_bold` replace
Aileron (which stands in for one that cannot be read, or that is cut short or
@@ -461,6 +480,7 @@ look, with the body's size; `.title` is its accessible name. A `.modal` one dims
earlier floaters — until it closes, and Tab stays with it and the floaters
opened after it. `reaktor_floater_close` closes one, from its own body too,
and runs `.closed`. `.body` and `.closed` get the main window's App.
`reaktor_floater_is_open` answers whether an id is still open.
```c
static void
@@ -511,7 +531,8 @@ it alone, and `reaktor_set_title` with its App retitles it. `.window.icon`
replaces the mark for it. A `.modal` one is the system's modal window: on
Windows and macOS the main window, close button included, takes no input
until it closes; on Linux the window manager decides. Its own close button or
`reaktor_window_close` runs `.closed`, with the main window's App. Closing the
`reaktor_window_close` runs `.closed`, with the main window's App;
`reaktor_window_is_open` answers whether an id is still open. Closing the
main window quits, and every window goes with it. The Text module stays in the
main window, and only UI Automation serves a window's tree to screen readers:
NSAccessibility and AT-SPI serve the main window's.
@@ -665,8 +686,9 @@ and the accent. An icon on a button takes its label's color.
`color-mix(in srgb, …)`, writes every `rgb()` as `rgba()` with four
arguments, clamped, turns `em` and `rem` into pixels, works out `calc()`
over pixels and plain numbers (one with a percentage is left, and dropped),
keeps the `@media (prefers-color-scheme)` branch for the active scheme and
drops width and print queries, rewrites `[type=range]` as `.type-range`
keeps an `@media` block whose queries are all `prefers-color-scheme`,
`prefers-reduced-motion` or `prefers-contrast` and hold now, and drops
width and print queries, rewrites `[type=range]` as `.type-range`
and `[disabled]` as `.disabled`, and drops `:enabled`, since every widget
that asks is enabled and a disabled one asks for `:disabled`. An operator
form like `[href^="http"]` cannot be expressed, and its rule is dropped, as
@@ -677,8 +699,23 @@ and the accent. An icon on a button takes its label's color.
reaktor.css uses the scheme branch to strengthen light hovers and tint the
current sidebar entry from `--links`.
**The system's settings.** Reduced motion and high contrast are read from the
system: Windows' animation and high-contrast settings, macOS's accessibility
display options, the desktop portal's `reduced-motion` and `contrast` (GNOME's
own keys where the portal lacks them), and the browser's media queries. They
reach the sheets as `@media (prefers-reduced-motion: reduce)` and
`(prefers-contrast: more)`; reaktor.css answers more contrast by drawing muted
text, placeholders and borders in `--text-bright`. Under reduced motion every
`reaktor_animate` returns its end value at once. Both are read again when the
system theme changes and when the window regains focus.
**Live reload.** With `--watch-css` the runtime looks at every sheet it read
from disk, `@import`s included, twice a second, and restyles when one is
saved. A sheet compiled in is not watched; one on disk is preferred to it, so
in a checkout the built-in sheets are watched too.
`reaktor_set_css` swaps the application's sheets at the next frame. The
showcase's Styling page lays Bamboo over Water.css that way, which is the
showcase's Styling page lays Simple.css over Water.css that way, which is the
test that the look is not in the code. reaktor.css is written in Water.css's
names, so once such a sheet is read, `--links`, `--background-body` and
`--text-main` are given its link, page and text colors in one more sheet read
@@ -850,7 +887,7 @@ close cross), `reaktor.css` and Water.css's palettes and parts, copied byte for
at configure time. `reaktor_asset_load` still tries the file under the
`.reaktor-root` marker first, so an edited sheet shows without a rebuild.
Nothing is read from the working directory, and a path a user hands over is
made absolute where it is taken. The rest of Ionicons, Bamboo and the
made absolute where it is taken. The rest of Ionicons, Simple.css and the
catalogs are read from files; an icon that is not there is drawn as nothing,
and the log names it.
@@ -902,11 +939,19 @@ repaint to make something update is the wrong fix** — mark what changed.
| NetBSD | x86-64, ARM64 | 11.0 |
| Web | WebAssembly | Chromium; emscripten 6.0.9 targets Chrome 85, Firefox 79 and Safari 15 |
Every pull request builds each native one, runs the seven console tests, and
Every pull request builds each native one, runs the eight console tests, and
writes a `--shot` and an `--a11y-dump` of `simple` and the showcase through
the system's video driver and SDL's `dummy` one: `.github/workflows/` holds a
workflow per system. The BSDs run in virtual machines, ARM64 among them under
emulation, and a job that emulates may fail without failing its run. The web
workflow per system. The BSDs run in virtual machines, and their ARM64
programs are cross-compiled in the x86-64 machine, against a sysroot
`tools/cross/sysroot.sh` gathers from the release's sets and packages, with
the toolchain file `tools/cross/<system>-aarch64.cmake` and
`-DREAKTOR_SYSROOT=<dir>`; OpenBSD's compiler has no ARM64 backend, so there
the ports LLVM builds them. An ARM64 machine, which runs under emulation, then
only runs the programs, and a job that emulates may fail without failing its
run. Linux on ARMv7 and RISC-V is cross-compiled in an x86-64 Debian with
`tools/cross/linux-cross.cmake` and run in an emulated one, on master and for
releases rather than on every pull request. The web
build is built and packed on every pull request too (`web.yml`), and checked
by hand in headless Edge, as desktop, Android and iOS.
@@ -963,7 +1008,7 @@ mojibake and kb_text_shape, merged with `lib.exe`, Apple's `libtool` or an
and SDL's, a CMake package, a pkg-config file and `share/reaktor/licenses`:
```cmake
find_package(reaktor 0.6 REQUIRED)
find_package(reaktor 0.7 REQUIRED)
add_executable(app WIN32 main.c)
target_link_libraries(app PRIVATE reaktor::reaktor)
```
@@ -1014,9 +1059,9 @@ Passed to CMake, through either script:
| `REAKTOR_TRAY` | `ON` | The tray icon |
| `REAKTOR_POPUP_WINDOWS` | `ON` | Menus in windows of their own |
| `REAKTOR_NOTIFY` | `ON` | System notifications |
| `REAKTOR_PRINT` | `ON` | Printing and PDF export, through libHaru |
| `REAKTOR_PRINT` | `ON` | Printing and PDF export, through PDFGen |
| `REAKTOR_INSPECTOR` | `ON` | The [Inspector](#inspector) |
| `REAKTOR_SDL_GL` | `OFF` | Build SDL's OpenGL and GLES drivers on Linux and the BSDs |
| `REAKTOR_SDL_GL` | `OFF` | Build SDL's OpenGL and GLES drivers on Windows, Linux and the BSDs |
| `REAKTOR_SAMPLES`, `REAKTOR_TESTS` | `ON` at the top | Build the samples, and the tests in `tests/` |
| `REAKTOR_INSTALL` | `ON` at the top | Install rules for libreaktor's files |
@@ -1056,7 +1101,7 @@ options a page needs; `ASSETS <file>@<path>` packs files beside it there.
`.remember_window` is ignored.
- **`REAKTOR_TRAY=OFF`** answers 0 from `reaktor_tray_open`, so AppIndicator
and GTK 3 are never loaded on Linux and the BSDs.
- **`REAKTOR_PRINT=OFF`** leaves libHaru out; `reaktor_print` and
- **`REAKTOR_PRINT=OFF`** leaves PDFGen out; `reaktor_print` and
`reaktor_print_pdf` answer 0.
- **`REAKTOR_INSPECTOR=OFF`** answers 0 from `reaktor_inspector_open` and
ignores `.inspector`, its shortcut and its flags.
@@ -1078,12 +1123,17 @@ removes them from `argv` before the application sees it:
| `--lang <code>` | Open in that catalog: `en`, `pl`, `ja` |
| `--font-fallback <path>` | A font for the Text module, before the application's; repeatable |
| `--renderer <name>` | `software` (default), `auto`, or a driver name |
| `--aa <auto\|on\|off>` | Override `.anti_aliasing` |
| `--video <name>` | SDL's video driver: `x11`, `wayland`, `dummy` |
| `--popups inline` | Menus inside the window, not in windows of their own |
| `--console <none\|parent\|debug>` | Override `.console` |
| `--log <path>` | Override `.log` |
| `--inspect`, `--no-inspector` | Open the [Inspector](#inspector) at start; detach it |
| `--new-instance` | Start a separate copy even with `.single_instance` |
| `--css <path>` | A sheet after the application's; up to four |
| `--watch-css` | Restyle when a sheet read from disk is saved |
| `--motion <reduce\|full>` | Override the system's reduced motion |
| `--contrast <more\|normal>` | Override the system's contrast |
| `--font <path>`, `--font-bold <path>` | Replace the UI face and its bold |
| `--icons <dir>` | Look for `<name>.svg` here first; up to four |
@@ -1126,7 +1176,7 @@ Built by default and run from `build/`:
| `animtest` | Curves, retargeting, a context a window |
| `keytest` | Chord parsing and formatting |
| `localetest` | Catalogs, lookup, plural rules, formatting |
| `csstest` | Flattening a sheet for libcss: what is rewritten, what is dropped, and Bamboo read through it |
| `csstest` | Flattening a sheet for libcss: what is rewritten, what is dropped, and Simple.css read through it |
| `texttest` | Line breaks, direction, measuring and glyph order, against `assets/fonts`; with the Text module |
| `launchtest` | Opt-in (`./build.ps1 launchtest`): `launchApp`'s hooks by mode (`start-fail`, `quit`, `veto`, `title`, `confirm`, `confirm-cancel`), the services (`ask`, `timer`, `post`, `settings`, `save-change`, `save-timer`, `settings-clear`, `list`, `list-keys`, `tree-keys`, `field-find`, `spin-keys`, `date-keys`, `undo`, `print-pdf`, `split-keys`, `split-vkeys`, `menu-keys`, `tip`; `dialog-open`, `dialog-many`, `dialog-save` and `dialog-folder` wait for someone to answer the system's dialog), what a floater, toast or popup holds and where keys go (the `hold-` modes), and a window beside the main one (`window-text` and the `win-` modes: keys, drops, animation, title, theme, wakes, a drag, one change a frame, the picker, memory, `win-hints`) |
@@ -1147,8 +1197,9 @@ about. `--renderer auto` lets SDL choose; a driver name pins one.
software renderer turns two triangles into a fill and truncates position and
size apart at fractional scales.
- **A one-pixel stroke is two half-alpha rows**, so borders are fills:
`reaktor_edge_round`. Fill anti-aliasing is off on every renderer, so rounded
fills are masks: `reaktor_fill_round`, and each rounded fill Nuklear draws
`reaktor_edge_round`. Fill anti-aliasing is off on the software renderer
and on under a GPU one unless `.anti_aliasing` says otherwise; rounded fills
do not depend on it, as they are masks: `reaktor_fill_round`, and each rounded fill Nuklear draws
itself — a scrollbar, a tree's header, a combo, a menu item — is swapped for
masks before the frame is drawn.
+1 -1
View File
@@ -206,7 +206,7 @@ the module drew. CMake keeps the option until you pass `=ON`. See
### How do I install libreaktor and link against it?
Take the release's archive or the `.deb` or `.rpm`, or run
`sh tools/libreaktor-pkg.sh -i`. Then `find_package(reaktor 0.6 REQUIRED)`
`sh tools/libreaktor-pkg.sh -i`. Then `find_package(reaktor 0.7 REQUIRED)`
and link `reaktor::reaktor`, or use `pkg-config --cflags --libs reaktor`. To
build it into your tree instead, `add_subdirectory` the checkout and call
`reaktor_add_app`. See [In your own project](DOCUMENTATION.md#in-your-own-project).
+5 -5
View File
@@ -13,14 +13,14 @@ from the project's own license file at the pinned revision.
| [LCUI](https://github.com/lc-soft/LCUI) | `libcss` (parse, match, cascade) and `yutil` | MIT |
| [Onlay](https://github.com/Alpaq92/Onlay) | The rectangles — a fork of [randrew/layout](https://github.com/randrew/layout) | MIT |
| [Water.css](https://github.com/kognise/water.css) | The stylesheet the look comes from, compiled in | MIT |
| [Bamboo](https://github.com/rilwis/bamboo) | The sheet the Styling page swaps in | MIT |
| [Simple.css](https://github.com/kevquirk/simple.css) | The sheet the Styling page swaps in | MIT |
| [Ionicons](https://github.com/ionic-team/ionicons) | Every icon, as SVG; the seven the widgets draw are compiled in | MIT |
| [plutosvg](https://github.com/sammycage/plutosvg) | Rasterizing the SVGs | MIT |
| [plutovg](https://github.com/sammycage/plutovg) | plutosvg's canvas (nested submodule) | MIT |
| [mojibake](https://github.com/zaerl/mojibake) | Bidirectional text (UAX #9) and line breaking (UAX #14), for the Text module | MIT |
| [kb_text_shape](https://github.com/JimmyLefevre/kb) | OpenType shaping, script segmentation and font coverage, for the Text module | zlib |
| [ini.h](https://github.com/mattiasgustavsson/libs) | Reading and writing `settings.conf` | MIT or public domain |
| [libHaru](https://github.com/libharu/libharu) | Writing PDFs, for the print module | zlib/libpng |
| [PDFGen](https://github.com/AndreRenaud/PDFGen) | Writing PDFs, for the print module | Unlicense |
Only LCUI's `libcss` and `yutil` are built, not the toolkit. SDL is built
static, without audio, joystick, haptic, HID, sensor, camera, power, GPU,
@@ -126,8 +126,8 @@ each toolchain fetches its own framework, and none is part of a Reaktor build.
A native build links SDL, libcss, yutil, plutosvg and plutovg statically, plus
mojibake and kb_text_shape with the Text module, and compiles in Nuklear,
NukAnim, Onlay and ini.h, and libHaru with the print module, so it carries the
zlib and MIT terms above. Each license
NukAnim, Onlay and ini.h, and PDFGen with the print module, so it carries the
zlib, MIT and Unlicense terms above. Each license
is copied unchanged into `licenses/` beside the programs (ini.h's sits at the
end of the header, so the header itself is `licenses/ini.h.txt`): ship that folder,
and this file, with a binary.
@@ -139,7 +139,7 @@ files in `src/parts/` (MIT); the seven Ionicons `chevron-down-outline`, `chevron
and `close-outline` (MIT); Aileron Regular and Bold (CC0); and the mark and
`assets/css/reaktor.css` (MIT). Their licenses are in `licenses/` too.
The rest of Ionicons, Bamboo, the Japanese font and the catalogs are not
The rest of Ionicons, Simple.css, the Japanese font and the catalogs are not
embedded (the catalogs are with `-DREAKTOR_LOCALE_EMBED=ON`); a build that uses
them ships them beside the binary, under the `.reaktor-root` marker. The
WebAssembly build packs the ones it uses into its `.data` bundle.
+1 -1
View File
@@ -183,7 +183,7 @@ fix). With a real GPU that reverses — see **Against the others**.
## What it needs to run
**No GPU**, and about **10 MB of RAM**. The default look is compiled in, so a
program needs no files beside it until it uses other Ionicons, Bamboo, the
program needs no files beside it until it uses other Ionicons, Simple.css, the
catalogs or the Japanese font, found by walking up to the `.reaktor-root`
marker. The web build packs those into its `.data` and needs an HTTP server,
since a `file://` page cannot fetch the `.wasm`.
+1 -1
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16)
project(consumer C)
find_package(reaktor 0.6 REQUIRED)
find_package(reaktor 0.7 REQUIRED)
add_executable(simple WIN32 ../../samples/simple/simple.c)
target_link_libraries(simple PRIVATE reaktor::reaktor)
Submodule external/bamboocss deleted from f7fdb9b800
-1
Submodule external/libharu deleted from 3467749fd1
Vendored Submodule
+1
Submodule external/pdfgen added at b3413daead
Vendored Submodule
+1
Submodule external/simplecss added at b6eab64c47
+10
View File
@@ -26,6 +26,12 @@ typedef enum reaktor_theme {
REAKTOR_THEME_DARK
} reaktor_theme;
typedef enum reaktor_aa {
REAKTOR_AA_AUTO = 0,
REAKTOR_AA_ON,
REAKTOR_AA_OFF
} reaktor_aa;
typedef enum reaktor_quit_reason {
REAKTOR_QUIT_WINDOW = 0,
REAKTOR_QUIT_APP,
@@ -77,6 +83,7 @@ typedef struct reaktor_launch {
const char *log;
reaktor_inspector_spec inspector;
reaktor_theme theme;
reaktor_aa anti_aliasing;
const char *confirm_close;
reaktor_asset css[REAKTOR_LAYER_MAX];
@@ -95,6 +102,7 @@ typedef struct reaktor_launch {
void (*file_opened)(App *app, const char *path);
void *user;
int remember_window;
int single_instance;
reaktor_save save_settings;
int save_ms;
} reaktor_launch;
@@ -137,6 +145,8 @@ void reaktor_request_quit(App *app);
void reaktor_wake(App *app);
void reaktor_set_theme(App *app, reaktor_theme theme);
void reaktor_set_css(App *app, const reaktor_asset *css, int count);
int reaktor_reduced_motion(void);
int reaktor_high_contrast(void);
void reaktor_set_title(App *app, const char *title);
void reaktor_set_confirm_close(App *app, const char *question);
void *reaktor_user(App *app);
-1
View File
@@ -3,7 +3,6 @@
#include <stddef.h>
void reaktor_locale_start(const char *lang);
int reaktor_locale_count(void);
const char *reaktor_locale_code(int index);
const char *reaktor_locale_name(int index);
+5 -1
View File
@@ -49,8 +49,12 @@
#define REAKTOR_POPUP_DYNAMIC NK_POPUP_DYNAMIC
#define REAKTOR_STATIC NK_STATIC
#define REAKTOR_STYLE_ITEM_COLOR NK_STYLE_ITEM_COLOR
#define REAKTOR_SYMBOL_CIRCLE_SOLID NK_SYMBOL_CIRCLE_SOLID
#define REAKTOR_SYMBOL_NONE NK_SYMBOL_NONE
#define REAKTOR_SYMBOL_RECT_SOLID NK_SYMBOL_RECT_SOLID
#define REAKTOR_TEXT_CENTERED NK_TEXT_CENTERED
#define REAKTOR_TEXT_LEFT NK_TEXT_LEFT
#define REAKTOR_TEXT_RIGHT NK_TEXT_RIGHT
#define REAKTOR_TREE_NODE NK_TREE_NODE
#define REAKTOR_TREE_TAB NK_TREE_TAB
#define REAKTOR_WIDGET_RIGHT NK_WIDGET_RIGHT
@@ -139,7 +143,7 @@
#define reaktor_style_push_style_item nk_style_push_style_item
#define reaktor_style_push_vec2 nk_style_push_vec2
#define reaktor_tooltip nk_tooltip
#define reaktor_tree_element nk_tree_element
#define reaktor_tree_element_pop nk_tree_element_pop
#define reaktor_tree_element_push nk_tree_element_push
#define reaktor_tree_pop nk_tree_pop
#define reaktor_tree_push nk_tree_push
-1
View File
@@ -31,7 +31,6 @@ typedef struct reaktor_style {
void reaktor_style_get(const char *selector, reaktor_style *out);
void reaktor_style_darken(unsigned char rgba[4], float amount);
int reaktor_style_token(const char *name, unsigned char rgba[4]);
+35 -81
View File
@@ -97,69 +97,43 @@ id_of(const char *path)
return (long)strtoul(tail, NULL, 10);
}
static const struct {
unsigned code;
const char *name;
} g_roles[REAKTOR_A11Y_ROLE_COUNT] = {
[REAKTOR_A11Y_WINDOW] = { ATSPI_ROLE_FRAME, "frame" },
[REAKTOR_A11Y_GROUP] = { ATSPI_ROLE_PANEL, "panel" },
[REAKTOR_A11Y_TABLIST] = { ATSPI_ROLE_PAGE_TAB_LIST, "page tab list" },
[REAKTOR_A11Y_TAB] = { ATSPI_ROLE_PAGE_TAB, "page tab" },
[REAKTOR_A11Y_BUTTON] = { ATSPI_ROLE_PUSH_BUTTON, "push button" },
[REAKTOR_A11Y_LINK] = { ATSPI_ROLE_LINK, "link" },
[REAKTOR_A11Y_CHECKBOX] = { ATSPI_ROLE_CHECK_BOX, "check box" },
[REAKTOR_A11Y_RADIO] = { ATSPI_ROLE_RADIO_BUTTON, "radio button" },
[REAKTOR_A11Y_TEXTBOX] = { ATSPI_ROLE_TEXT, "text" },
[REAKTOR_A11Y_SLIDER] = { ATSPI_ROLE_SLIDER, "slider" },
[REAKTOR_A11Y_SPINBUTTON] = { ATSPI_ROLE_SPIN_BUTTON, "spin button" },
[REAKTOR_A11Y_PROGRESS] = { ATSPI_ROLE_PROGRESS_BAR, "progress bar" },
[REAKTOR_A11Y_COMBOBOX] = { ATSPI_ROLE_COMBO_BOX, "combo box" },
[REAKTOR_A11Y_LISTITEM] = { ATSPI_ROLE_LIST_ITEM, "list item" },
[REAKTOR_A11Y_TREEITEM] = { ATSPI_ROLE_TREE_ITEM, "tree item" },
[REAKTOR_A11Y_MENUBAR] = { ATSPI_ROLE_MENU_BAR, "menu bar" },
[REAKTOR_A11Y_MENU] = { ATSPI_ROLE_MENU, "menu" },
[REAKTOR_A11Y_MENUITEM] = { ATSPI_ROLE_MENU_ITEM, "menu item" },
[REAKTOR_A11Y_DIALOG] = { ATSPI_ROLE_DIALOG, "dialog" },
[REAKTOR_A11Y_LABEL] = { ATSPI_ROLE_LABEL, "label" },
};
static unsigned
role_of(unsigned char role)
{
switch (role) {
case REAKTOR_A11Y_WINDOW: return ATSPI_ROLE_FRAME;
case REAKTOR_A11Y_GROUP: return ATSPI_ROLE_PANEL;
case REAKTOR_A11Y_TABLIST: return ATSPI_ROLE_PAGE_TAB_LIST;
case REAKTOR_A11Y_TAB: return ATSPI_ROLE_PAGE_TAB;
case REAKTOR_A11Y_BUTTON: return ATSPI_ROLE_PUSH_BUTTON;
case REAKTOR_A11Y_LINK: return ATSPI_ROLE_LINK;
case REAKTOR_A11Y_CHECKBOX: return ATSPI_ROLE_CHECK_BOX;
case REAKTOR_A11Y_RADIO: return ATSPI_ROLE_RADIO_BUTTON;
case REAKTOR_A11Y_TEXTBOX: return ATSPI_ROLE_TEXT;
case REAKTOR_A11Y_SLIDER: return ATSPI_ROLE_SLIDER;
case REAKTOR_A11Y_SPINBUTTON: return ATSPI_ROLE_SPIN_BUTTON;
case REAKTOR_A11Y_PROGRESS: return ATSPI_ROLE_PROGRESS_BAR;
case REAKTOR_A11Y_COMBOBOX: return ATSPI_ROLE_COMBO_BOX;
case REAKTOR_A11Y_LISTITEM: return ATSPI_ROLE_LIST_ITEM;
case REAKTOR_A11Y_TREEITEM: return ATSPI_ROLE_TREE_ITEM;
case REAKTOR_A11Y_MENUBAR: return ATSPI_ROLE_MENU_BAR;
case REAKTOR_A11Y_MENU: return ATSPI_ROLE_MENU;
case REAKTOR_A11Y_MENUITEM: return ATSPI_ROLE_MENU_ITEM;
case REAKTOR_A11Y_DIALOG: return ATSPI_ROLE_DIALOG;
case REAKTOR_A11Y_LABEL: return ATSPI_ROLE_LABEL;
default: return ATSPI_ROLE_FILLER;
}
return role < REAKTOR_A11Y_ROLE_COUNT && g_roles[role].name ? g_roles[role].code
: ATSPI_ROLE_FILLER;
}
static const char *
role_name(unsigned char role)
{
switch (role) {
case REAKTOR_A11Y_WINDOW: return "frame";
case REAKTOR_A11Y_GROUP: return "panel";
case REAKTOR_A11Y_TABLIST: return "page tab list";
case REAKTOR_A11Y_TAB: return "page tab";
case REAKTOR_A11Y_BUTTON: return "push button";
case REAKTOR_A11Y_LINK: return "link";
case REAKTOR_A11Y_CHECKBOX: return "check box";
case REAKTOR_A11Y_RADIO: return "radio button";
case REAKTOR_A11Y_TEXTBOX: return "text";
case REAKTOR_A11Y_SLIDER: return "slider";
case REAKTOR_A11Y_SPINBUTTON: return "spin button";
case REAKTOR_A11Y_PROGRESS: return "progress bar";
case REAKTOR_A11Y_COMBOBOX: return "combo box";
case REAKTOR_A11Y_LISTITEM: return "list item";
case REAKTOR_A11Y_TREEITEM: return "tree item";
case REAKTOR_A11Y_MENUBAR: return "menu bar";
case REAKTOR_A11Y_MENU: return "menu";
case REAKTOR_A11Y_MENUITEM: return "menu item";
case REAKTOR_A11Y_DIALOG: return "dialog";
case REAKTOR_A11Y_LABEL: return "label";
default: return "filler";
}
}
static int
has_action(unsigned char role)
{
return role == REAKTOR_A11Y_BUTTON || role == REAKTOR_A11Y_LINK ||
role == REAKTOR_A11Y_TAB || role == REAKTOR_A11Y_MENUITEM ||
role == REAKTOR_A11Y_CHECKBOX || role == REAKTOR_A11Y_RADIO ||
role == REAKTOR_A11Y_LISTITEM;
return role < REAKTOR_A11Y_ROLE_COUNT && g_roles[role].name ? g_roles[role].name : "filler";
}
static void
@@ -286,7 +260,7 @@ append_interfaces(DBusMessageIter *it, const reaktor_snap_node *n, int is_root)
} else {
s = IF_COMPONENT;
dbus_message_iter_append_basic(&arr, DBUS_TYPE_STRING, &s);
if (has_action(n->role)) {
if (reaktor_snap_pressable(n->role)) {
s = IF_ACTION;
dbus_message_iter_append_basic(&arr, DBUS_TYPE_STRING, &s);
}
@@ -448,7 +422,7 @@ handle_properties(DBusConnection *c, DBusMessage *m, unsigned id, int is_root,
}
} else if (strcmp(iface, IF_ACTION) == 0) {
if (strcmp(prop, "NActions") == 0)
append_variant_int(&it, has_action(n->role) ? 1 : 0);
append_variant_int(&it, reaktor_snap_pressable(n->role) ? 1 : 0);
else {
dbus_message_unref(r);
return reply_unknown(c, m);
@@ -619,10 +593,10 @@ handle_action(DBusConnection *c, DBusMessage *m, unsigned id,
dbus_message_iter_init_append(r, &it);
if (dbus_message_has_member(m, "GetNActions")) {
dbus_int32_t v = has_action(n->role) ? 1 : 0;
dbus_int32_t v = reaktor_snap_pressable(n->role) ? 1 : 0;
dbus_message_iter_append_basic(&it, DBUS_TYPE_INT32, &v);
} else if (dbus_message_has_member(m, "DoAction")) {
dbus_bool_t ok = has_action(n->role) ? TRUE : FALSE;
dbus_bool_t ok = reaktor_snap_pressable(n->role) ? TRUE : FALSE;
if (ok) reaktor_snap_request_activate(id);
dbus_message_iter_append_basic(&it, DBUS_TYPE_BOOLEAN, &ok);
@@ -637,7 +611,7 @@ handle_action(DBusConnection *c, DBusMessage *m, unsigned id,
} else if (dbus_message_has_member(m, "GetActions")) {
DBusMessageIter arr;
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY, "(sss)", &arr);
if (has_action(n->role)) {
if (reaktor_snap_pressable(n->role)) {
DBusMessageIter sub;
const char *a = "activate", *b = "", *k = "";
@@ -861,33 +835,13 @@ reaktor_a11y_platform_init(reaktor_a11y_action activate,
}
}
void
reaktor_a11y_platform_drain(void)
{
reaktor_snap_drain();
}
void
reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
{
int m;
if (!reaktor_snap_update(a, focus_id)) return;
if (!g.ready) return;
reaktor_a11y_changes(a, &m);
{
int i, structural = 0;
const reaktor_a11y_change *c = reaktor_a11y_changes(a, &m);
for (i = 0; i < m; i++)
if (c[i].kind == REAKTOR_A11Y_ADDED ||
c[i].kind == REAKTOR_A11Y_REMOVED) {
structural = 1;
break;
}
if (structural) emit_event("ChildrenChanged", "add", 0, 0, 0);
}
if (reaktor_snap_structural(a)) emit_event("ChildrenChanged", "add", 0, 0, 0);
if (focus_id != g.last_focus) {
if (g.last_focus)
+2 -28
View File
@@ -45,15 +45,6 @@ role_of(unsigned char role)
}
}
static BOOL
takes_press(unsigned char role)
{
return role == REAKTOR_A11Y_BUTTON || role == REAKTOR_A11Y_LINK ||
role == REAKTOR_A11Y_TAB || role == REAKTOR_A11Y_MENUITEM ||
role == REAKTOR_A11Y_CHECKBOX || role == REAKTOR_A11Y_RADIO ||
role == REAKTOR_A11Y_LISTITEM;
}
@interface ReaktorElement : NSAccessibilityElement
@property (nonatomic) unsigned nodeId;
@end
@@ -203,7 +194,7 @@ static ReaktorElement *element_for(unsigned id);
reaktor_snap_node n;
char buf[REAKTOR_SNAP_TEXT];
if (![self node:&n buffer:buf] || !takes_press(n.role)) return NO;
if (![self node:&n buffer:buf] || !reaktor_snap_pressable(n.role)) return NO;
reaktor_snap_request_activate(self.nodeId);
return YES;
}
@@ -277,31 +268,14 @@ reaktor_a11y_platform_init(reaktor_a11y_action activate,
g.ready = 1;
}
void
reaktor_a11y_platform_drain(void)
{
reaktor_snap_drain();
}
void
reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
{
static unsigned last_focus;
int m, i, structural = 0;
const reaktor_a11y_change *c;
if (!reaktor_snap_update(a, focus_id)) return;
if (!g.ready) return;
c = reaktor_a11y_changes(a, &m);
for (i = 0; i < m; i++)
if (c[i].kind == REAKTOR_A11Y_ADDED ||
c[i].kind == REAKTOR_A11Y_REMOVED) {
structural = 1;
break;
}
if (structural) {
if (reaktor_snap_structural(a)) {
[g.cache removeAllObjects];
g.cache[@0] = g.root;
g.shape++;
-20
View File
@@ -17,23 +17,3 @@ void
reaktor_a11y_platform_drain(void)
{
}
void
reaktor_a11y_platform_window_push(struct SDL_Window *win, const reaktor_a11y *a,
unsigned focus_id, reaktor_a11y_action activate,
reaktor_a11y_action focus, void *user)
{
(void)win; (void)a; (void)focus_id; (void)activate; (void)focus; (void)user;
}
void
reaktor_a11y_platform_window_drain(struct SDL_Window *win)
{
(void)win;
}
void
reaktor_a11y_platform_window_gone(struct SDL_Window *win)
{
(void)win;
}
+42 -24
View File
@@ -31,6 +31,7 @@ struct reaktor_snap {
char str[SNAP_POOL];
int str_used;
unsigned focus;
int stale;
unsigned want_focus, want_activate;
Uint32 window;
@@ -168,7 +169,7 @@ reaktor_snap_update_in(reaktor_snap *s, const reaktor_a11y *a, unsigned focus_id
if (!s || !s->ready) return 0;
reaktor_a11y_changes(a, &m);
t = reaktor_a11y_tree(a, &n);
if (m == 0 && focus_id == s->focus) return 0;
if (m == 0 && focus_id == s->focus && !s->stale) return 0;
SDL_LockMutex(s->lock);
s->str_used = 0;
@@ -191,6 +192,7 @@ reaktor_snap_update_in(reaktor_snap *s, const reaktor_a11y *a, unsigned focus_id
}
link_tree(s);
s->focus = focus_id;
s->stale = 0;
SDL_UnlockMutex(s->lock);
return 1;
}
@@ -319,6 +321,32 @@ reaktor_snap_focus_in(reaktor_snap *s)
return id;
}
int
reaktor_snap_pressable(unsigned char role)
{
return role == REAKTOR_A11Y_BUTTON || role == REAKTOR_A11Y_LINK ||
role == REAKTOR_A11Y_TAB || role == REAKTOR_A11Y_MENUITEM ||
role == REAKTOR_A11Y_CHECKBOX || role == REAKTOR_A11Y_RADIO ||
role == REAKTOR_A11Y_LISTITEM;
}
int
reaktor_snap_structural(const reaktor_a11y *a)
{
int m, i;
const reaktor_a11y_change *c = reaktor_a11y_changes(a, &m);
for (i = 0; i < m; i++)
if (c[i].kind == REAKTOR_A11Y_ADDED || c[i].kind == REAKTOR_A11Y_REMOVED) return 1;
return 0;
}
void
reaktor_a11y_platform_drain(void)
{
reaktor_snap_drain();
}
int
reaktor_snap_focusable(unsigned char role, unsigned state)
{
@@ -336,6 +364,12 @@ reaktor_snap_focusable(unsigned char role, unsigned state)
}
}
void
reaktor_snap_skip_in(reaktor_snap *s)
{
if (s) s->stale = 1;
}
static void
request(reaktor_snap *s, unsigned *slot, unsigned id)
{
@@ -345,12 +379,18 @@ request(reaktor_snap *s, unsigned *slot, unsigned id)
SDL_zero(e);
e.type = g_wake;
SDL_LockMutex(s->lock);
*slot = id;
if (slot) *slot = id;
e.user.windowID = s->window;
SDL_UnlockMutex(s->lock);
SDL_PushEvent(&e);
}
void
reaktor_snap_wake_in(reaktor_snap *s)
{
request(s, NULL, 0);
}
void
reaktor_snap_request_focus_in(reaktor_snap *s, unsigned id)
{
@@ -395,25 +435,3 @@ void reaktor_snap_request_focus(unsigned id)
void reaktor_snap_request_activate(unsigned id)
{ reaktor_snap_request_activate_in(&g, id); }
void reaktor_snap_drain(void) { reaktor_snap_drain_in(&g); }
#ifndef _WIN32
void
reaktor_a11y_platform_window_push(struct SDL_Window *win, const reaktor_a11y *a,
unsigned focus_id, reaktor_a11y_action activate,
reaktor_a11y_action focus, void *user)
{
(void)win; (void)a; (void)focus_id; (void)activate; (void)focus; (void)user;
}
void
reaktor_a11y_platform_window_drain(struct SDL_Window *win)
{
(void)win;
}
void
reaktor_a11y_platform_window_gone(struct SDL_Window *win)
{
(void)win;
}
#endif
+4
View File
@@ -38,6 +38,8 @@ unsigned reaktor_snap_sibling_in(reaktor_snap *s, unsigned id, int back);
unsigned reaktor_snap_parent_in(reaktor_snap *s, unsigned id);
unsigned reaktor_snap_hit_in(reaktor_snap *s, float x, float y);
unsigned reaktor_snap_focus_in(reaktor_snap *s);
void reaktor_snap_skip_in(reaktor_snap *s);
void reaktor_snap_wake_in(reaktor_snap *s);
void reaktor_snap_request_focus_in(reaktor_snap *s, unsigned id);
void reaktor_snap_request_activate_in(reaktor_snap *s, unsigned id);
void reaktor_snap_drain_in(reaktor_snap *s);
@@ -56,6 +58,8 @@ unsigned reaktor_snap_hit(float x, float y);
unsigned reaktor_snap_focus(void);
int reaktor_snap_focusable(unsigned char role, unsigned state);
int reaktor_snap_pressable(unsigned char role);
int reaktor_snap_structural(const reaktor_a11y *a);
void reaktor_snap_request_focus(unsigned id);
void reaktor_snap_request_activate(unsigned id);
-20
View File
@@ -168,23 +168,3 @@ reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
}
web_a11y_end(focus_id);
}
void
reaktor_a11y_platform_window_push(struct SDL_Window *win, const reaktor_a11y *a,
unsigned focus_id, reaktor_a11y_action activate,
reaktor_a11y_action focus, void *user)
{
(void)win; (void)a; (void)focus_id; (void)activate; (void)focus; (void)user;
}
void
reaktor_a11y_platform_window_drain(struct SDL_Window *win)
{
(void)win;
}
void
reaktor_a11y_platform_window_gone(struct SDL_Window *win)
{
(void)win;
}
+18 -28
View File
@@ -744,7 +744,10 @@ wnd_proc(HWND h, UINT msg, WPARAM wp, LPARAM lp)
LRESULT res;
if (!r) return 0;
b->wanted = 1;
if (!b->wanted) {
b->wanted = 1;
reaktor_snap_wake_in(b->snap);
}
res = UiaReturnRawElementProvider(h, wp, lp,
(IRawElementProviderSimple *)&r->simple);
IRawElementProviderSimple_Release(&r->simple);
@@ -762,7 +765,9 @@ attach(bridge *b, SDL_Window *win)
NULL);
if (!h) {
SDL_Log("a11y: no HWND; UI Automation is not served");
static int told;
if (!told++) SDL_Log("a11y: no HWND; UI Automation is not served");
return 0;
}
b->win = win;
@@ -792,37 +797,22 @@ reaktor_a11y_platform_init(reaktor_a11y_action activate,
SDL_free(wins);
}
void
reaktor_a11y_platform_drain(void)
{
reaktor_snap_drain();
}
static void
push_into(bridge *b, const reaktor_a11y *a, unsigned focus_id)
{
if (!b->wanted) {
reaktor_snap_skip_in(b->snap);
return;
}
if (!reaktor_snap_update_in(b->snap, a, focus_id)) return;
if (!UiaClientsAreListening()) return;
if (reaktor_snap_structural(a)) {
Provider *r = provider_new(b, 0);
if (!b->wanted || !UiaClientsAreListening()) return;
{
int m, i, structural = 0;
const reaktor_a11y_change *c = reaktor_a11y_changes(a, &m);
for (i = 0; i < m; i++)
if (c[i].kind == REAKTOR_A11Y_ADDED ||
c[i].kind == REAKTOR_A11Y_REMOVED) {
structural = 1;
break;
}
if (structural) {
Provider *r = provider_new(b, 0);
if (!r) return;
UiaRaiseStructureChangedEvent(
(IRawElementProviderSimple *)&r->simple,
StructureChangeType_ChildrenInvalidated, NULL, 0);
IRawElementProviderSimple_Release(&r->simple);
}
if (!r) return;
UiaRaiseStructureChangedEvent((IRawElementProviderSimple *)&r->simple,
StructureChangeType_ChildrenInvalidated, NULL, 0);
IRawElementProviderSimple_Release(&r->simple);
}
if (focus_id != b->last_focus) {
b->last_focus = focus_id;
+22
View File
@@ -0,0 +1,22 @@
/* Windows other than the main one, where only UI Automation serves them. */
#include "a11y.h"
void
reaktor_a11y_platform_window_push(struct SDL_Window *win, const reaktor_a11y *a,
unsigned focus_id, reaktor_a11y_action activate,
reaktor_a11y_action focus, void *user)
{
(void)win; (void)a; (void)focus_id; (void)activate; (void)focus; (void)user;
}
void
reaktor_a11y_platform_window_drain(struct SDL_Window *win)
{
(void)win;
}
void
reaktor_a11y_platform_window_gone(struct SDL_Window *win)
{
(void)win;
}
+22 -22
View File
@@ -12,12 +12,11 @@ EM_JS(void, notify_web, (const char *title, const char *text), {
});
});
int
reaktor_notify(App *app, const reaktor_notification *n)
static int
notify_os(App *app, const char *title, const char *text)
{
(void)app;
if (!n || !n->title) return 0;
notify_web(n->title, n->text ? n->text : "");
notify_web(title, text);
return 1;
}
@@ -58,15 +57,15 @@ notify_text(const char *s, WCHAR *out, int cap)
}
/* A balloon from an icon of our own, which Windows 10 and 11 show as a toast. */
int
reaktor_notify(App *app, const reaktor_notification *n)
static int
notify_os(App *app, const char *title, const char *text)
{
static unsigned gone;
static int watched;
HWND hwnd;
int added;
if (!app || !n || !n->title) return 0;
if (!app) return 0;
hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(app->win),
SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
if (!hwnd) return 0;
@@ -78,9 +77,9 @@ reaktor_notify(App *app, const reaktor_notification *n)
g_icon.uFlags = NIF_ICON | NIF_TIP | NIF_INFO;
g_icon.hIcon = (HICON)SendMessageW(hwnd, WM_GETICON, ICON_SMALL, 0);
if (!g_icon.hIcon) g_icon.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
notify_text(n->title, g_icon.szInfoTitle, (int)SDL_arraysize(g_icon.szInfoTitle));
notify_text(n->title, g_icon.szTip, (int)SDL_arraysize(g_icon.szTip));
notify_text(n->text ? n->text : "", g_icon.szInfo, (int)SDL_arraysize(g_icon.szInfo));
notify_text(title, g_icon.szInfoTitle, (int)SDL_arraysize(g_icon.szInfoTitle));
notify_text(title, g_icon.szTip, (int)SDL_arraysize(g_icon.szTip));
notify_text(text, g_icon.szInfo, (int)SDL_arraysize(g_icon.szInfo));
g_icon.dwInfoFlags = NIIF_USER | NIIF_RESPECT_QUIET_TIME;
if (!Shell_NotifyIconW(added ? NIM_MODIFY : NIM_ADD, &g_icon)) {
g_icon.hWnd = NULL;
@@ -96,29 +95,28 @@ reaktor_notify(App *app, const reaktor_notification *n)
#elif defined(REAKTOR_HAVE_DBUS)
#include <dbus/dbus.h>
int
reaktor_notify(App *app, const reaktor_notification *n)
static int
notify_os(App *app, const char *title, const char *body)
{
DBusConnection *c;
DBusMessage *m;
DBusMessageIter it, sub;
const char *name = reaktor_app_ident(), *icon = "", *body;
const char *name = reaktor_app_ident(), *icon = "";
dbus_uint32_t replaces = 0;
dbus_int32_t expire = -1;
int ok;
(void)app;
if (!n || !n->title || !(c = dbus_bus_get(DBUS_BUS_SESSION, NULL))) return 0;
if (!(c = dbus_bus_get(DBUS_BUS_SESSION, NULL))) return 0;
m = dbus_message_new_method_call("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications", "Notify");
if (!m) return 0;
body = n->text ? n->text : "";
dbus_message_iter_init_append(m, &it);
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &name);
dbus_message_iter_append_basic(&it, DBUS_TYPE_UINT32, &replaces);
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &icon);
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &n->title);
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &title);
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &body);
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY, "s", &sub);
dbus_message_iter_close_container(&it, &sub);
@@ -135,18 +133,20 @@ reaktor_notify(App *app, const reaktor_notification *n)
#elif defined(__APPLE__)
int reaktor_notify_macos(const char *title, const char *text);
int
reaktor_notify(App *app, const reaktor_notification *n)
static int
notify_os(App *app, const char *title, const char *text)
{
(void)app;
return n && n->title ? reaktor_notify_macos(n->title, n->text ? n->text : "") : 0;
return reaktor_notify_macos(title, text);
}
#endif
#else
/* Without a backend the module is notify_none.c instead. */
#if defined(__EMSCRIPTEN__) || defined(_WIN32) || defined(REAKTOR_HAVE_DBUS) || defined(__APPLE__)
int
reaktor_notify(App *app, const reaktor_notification *n)
{
(void)app; (void)n;
return 0;
if (!n || !n->title) return 0;
return notify_os(app, n->title, n->text ? n->text : "");
}
#endif
+154
View File
@@ -4,6 +4,11 @@
#ifdef _WIN32
#include <windows.h>
#elif defined(__EMSCRIPTEN__)
#include <emscripten.h>
#elif defined(__APPLE__)
#include <objc/message.h>
#include <objc/runtime.h>
#endif
int reaktor_prefers_dark(void)
@@ -15,6 +20,155 @@ int reaktor_prefers_dark(void)
}
}
#if defined(__APPLE__) && !defined(__EMSCRIPTEN__)
static int workspace_says(const char *what)
{
id (*send)(id, SEL) = (id (*)(id, SEL))objc_msgSend;
BOOL (*ask)(id, SEL) = (BOOL (*)(id, SEL))objc_msgSend;
Class c = objc_getClass("NSWorkspace");
id ws = c ? send((id)c, sel_registerName("sharedWorkspace")) : nil;
return ws && ask(ws, sel_registerName(what));
}
#elif !defined(_WIN32) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
/* The desktop portal's settings, through a libdbus loaded when first asked. */
typedef struct { void *a, *b; unsigned c; void *d; } dbus_error;
typedef union { void *p[16]; long long l[16]; } dbus_iter;
static struct {
int tried;
void *lib, *conn;
void (*error_init)(dbus_error *);
void (*error_free)(dbus_error *);
void *(*bus_get)(int, dbus_error *);
void *(*method_call)(const char *, const char *, const char *, const char *);
int (*append_args)(void *, int, ...);
void *(*send_block)(void *, void *, int, dbus_error *);
void (*message_unref)(void *);
int (*iter_init)(void *, dbus_iter *);
int (*iter_type)(dbus_iter *);
void (*iter_recurse)(dbus_iter *, dbus_iter *);
void (*iter_basic)(dbus_iter *, void *);
} g_dbus;
static int dbus_ready(void)
{
dbus_error e;
if (g_dbus.tried) return g_dbus.conn != NULL;
g_dbus.tried = 1;
if (!(g_dbus.lib = SDL_LoadObject("libdbus-1.so.3"))) return 0;
#define DBUS_FN(f, name) if (!(*(void **)&g_dbus.f = (void *)SDL_LoadFunction(g_dbus.lib, name))) return 0
DBUS_FN(error_init, "dbus_error_init");
DBUS_FN(error_free, "dbus_error_free");
DBUS_FN(bus_get, "dbus_bus_get");
DBUS_FN(method_call, "dbus_message_new_method_call");
DBUS_FN(append_args, "dbus_message_append_args");
DBUS_FN(send_block, "dbus_connection_send_with_reply_and_block");
DBUS_FN(message_unref, "dbus_message_unref");
DBUS_FN(iter_init, "dbus_message_iter_init");
DBUS_FN(iter_type, "dbus_message_iter_get_arg_type");
DBUS_FN(iter_recurse, "dbus_message_iter_recurse");
DBUS_FN(iter_basic, "dbus_message_iter_get_basic");
#undef DBUS_FN
g_dbus.error_init(&e);
g_dbus.conn = g_dbus.bus_get(0, &e);
g_dbus.error_free(&e);
return g_dbus.conn != NULL;
}
/* A setting as a number, or -1 when the portal does not have it. */
static int portal_read(const char *ns, const char *key)
{
static const char *const how[2] = { "ReadOne", "Read" };
int i, out = -1;
if (!dbus_ready()) return -1;
for (i = 0; i < 2 && out < 0; i++) {
void *msg, *reply;
dbus_error e;
dbus_iter it, in;
int type;
msg = g_dbus.method_call("org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.Settings", how[i]);
if (!msg) return -1;
if (!g_dbus.append_args(msg, 's', &ns, 's', &key, 0)) {
g_dbus.message_unref(msg);
return -1;
}
g_dbus.error_init(&e);
reply = g_dbus.send_block(g_dbus.conn, msg, 300, &e);
g_dbus.error_free(&e);
g_dbus.message_unref(msg);
if (!reply) continue;
if (g_dbus.iter_init(reply, &it)) {
while ((type = g_dbus.iter_type(&it)) == 'v') {
g_dbus.iter_recurse(&it, &in);
it = in;
}
if (type == 'u' || type == 'i' || type == 'b') {
Uint32 v = 0;
g_dbus.iter_basic(&it, &v);
out = (int)v;
}
}
g_dbus.message_unref(reply);
}
return out;
}
#endif
int reaktor_prefers_reduced_motion(void)
{
#if defined(_WIN32)
BOOL on = TRUE;
return SystemParametersInfoW(SPI_GETCLIENTAREAANIMATION, 0, &on, 0) && !on;
#elif defined(__EMSCRIPTEN__)
return EM_ASM_INT({
return window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 1 : 0;
});
#elif defined(__APPLE__)
return workspace_says("accessibilityDisplayShouldReduceMotion");
#elif !defined(__ANDROID__)
int v = portal_read("org.freedesktop.appearance", "reduced-motion");
if (v >= 0) return v == 1;
v = portal_read("org.gnome.desktop.interface", "enable-animations");
return v == 0;
#else
return 0;
#endif
}
int reaktor_prefers_contrast(void)
{
#if defined(_WIN32)
HIGHCONTRASTW hc;
hc.cbSize = sizeof hc;
return SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof hc, &hc, 0) &&
(hc.dwFlags & HCF_HIGHCONTRASTON);
#elif defined(__EMSCRIPTEN__)
return EM_ASM_INT({
return window.matchMedia && (window.matchMedia('(prefers-contrast: more)').matches ||
window.matchMedia('(forced-colors: active)').matches) ? 1 : 0;
});
#elif defined(__APPLE__)
return workspace_says("accessibilityDisplayShouldIncreaseContrast");
#elif !defined(__ANDROID__)
int v = portal_read("org.freedesktop.appearance", "contrast");
if (v >= 0) return v == 1;
return portal_read("org.gnome.desktop.a11y.interface", "high-contrast") == 1;
#else
return 0;
#endif
}
int reaktor_window_set_dark(SDL_Window *win, int dark)
{
#ifdef _WIN32
+2
View File
@@ -2,6 +2,8 @@
#define REAKTOR_THEME_H
int reaktor_prefers_dark(void);
int reaktor_prefers_reduced_motion(void);
int reaktor_prefers_contrast(void);
struct SDL_Window;
+169 -20
View File
@@ -6,6 +6,7 @@
#include "locale.h"
#include "reaktor/launch.h"
#include "lifecycle.h"
#include "cssflat.h"
#ifdef __EMSCRIPTEN__
#include "keyboard_web.h"
#endif
@@ -39,6 +40,8 @@ static const char *g_fallbacks[REAKTOR_LAYER_MAX];
static int g_fallback_n;
static const char *g_icon_dirs[REAKTOR_LAYER_MAX], *g_cli_icons[REAKTOR_LAYER_MAX];
static int g_inspect_flag;
static int g_motion_flag, g_contrast_flag, g_reduced, g_contrast, g_watch;
static int g_new_instance;
static SDL_IOStream *g_log;
static SDL_LogOutputFunction g_log_next;
static void *g_log_next_user;
@@ -160,7 +163,7 @@ reaktor_hint(const char *name, const char *value)
SDL_SetHintWithPriority(name, value, SDL_HINT_OVERRIDE);
}
void
static void
reaktor_rss_mark(int step)
{
reaktor_process_memory(&reaktor_rss[step], &reaktor_priv[step]);
@@ -258,6 +261,12 @@ take_flags(App *app, int argc, char **argv)
const char *v = (i + 1 < argc) ? argv[i + 1] : NULL;
if (v && SDL_strcmp(a, "--shot") == 0) { app->shot_path = v; i++; }
else if (v && SDL_strcmp(a, "--aa") == 0) {
g_launch.anti_aliasing = SDL_strcmp(v, "on") == 0 ? REAKTOR_AA_ON
: SDL_strcmp(v, "off") == 0 ? REAKTOR_AA_OFF
: REAKTOR_AA_AUTO;
i++;
}
else if (v && SDL_strcmp(a, "--console") == 0) {
g_launch.console = SDL_strcmp(v, "debug") == 0 ? REAKTOR_CONSOLE_DEBUG
: SDL_strcmp(v, "parent") == 0 ? REAKTOR_CONSOLE_PARENT
@@ -280,6 +289,16 @@ take_flags(App *app, int argc, char **argv)
else if (v && SDL_strcmp(a, "--log") == 0) { log_open(v); i++; }
else if (SDL_strcmp(a, "--inspect") == 0) g_inspect_flag = 1;
else if (SDL_strcmp(a, "--no-inspector") == 0) g_inspect_flag = -1;
else if (SDL_strcmp(a, "--watch-css") == 0) g_watch = 1;
else if (v && SDL_strcmp(a, "--motion") == 0) {
g_motion_flag = SDL_strcmp(v, "reduce") == 0 ? 1 : SDL_strcmp(v, "full") == 0 ? -1 : 0;
i++;
}
else if (v && SDL_strcmp(a, "--contrast") == 0) {
g_contrast_flag = SDL_strcmp(v, "more") == 0 ? 1 : SDL_strcmp(v, "normal") == 0 ? -1 : 0;
i++;
}
else if (SDL_strcmp(a, "--new-instance") == 0) g_new_instance = 1;
else if (v && SDL_strcmp(a, "--renderer") == 0) { app->renderer_pref = v; i++; }
else if (v && SDL_strcmp(a, "--video") == 0) { app->video_pref = v; i++; }
else if (v && SDL_strcmp(a, "--popups") == 0) {
@@ -316,6 +335,22 @@ read_roles(App *app)
: reaktor_token("--links", app->text);
}
/* Whether the sheets' own tokens already say what the role sheet would. */
static int
roles_hold(const App *app)
{
const struct nk_color *c[3] = { &app->accent, &app->page, &app->text };
static const char *const name[3] = { "--links", "--background-body", "--text-main" };
unsigned char t[4];
int i;
for (i = 0; i < 3; i++)
if (!reaktor_style_token(name[i], t) || c[i]->a != 255 || t[3] != 255 ||
t[0] != c[i]->r || t[1] != c[i]->g || t[2] != c[i]->b)
return 0;
return 1;
}
static const char *
role_sheet(const App *app)
{
@@ -340,7 +375,103 @@ theme_sheet(int dark)
: "external/watercss/src/variables-light.css";
}
void
/* Whether the system's reduced motion or contrast changed what applies. */
static int
read_prefs(void)
{
int r = g_motion_flag ? g_motion_flag > 0 : reaktor_prefers_reduced_motion();
int c = g_contrast_flag ? g_contrast_flag > 0 : reaktor_prefers_contrast();
int changed = r != g_reduced || c != g_contrast;
g_reduced = r;
g_contrast = c;
reaktor_css_media(r, c);
reaktor_anim_reduce(r);
return changed;
}
int reaktor_reduced_motion(void) { return g_reduced; }
int reaktor_high_contrast(void) { return g_contrast; }
#define WATCH_MAX 64
static struct {
SDL_Mutex *lock;
SDL_TimerID timer;
char *path[WATCH_MAX];
SDL_Time when[WATCH_MAX];
int n;
} g_watched;
static void
watch_reload(App *app, void *user)
{
(void)app; (void)user;
SDL_Log("css: a sheet changed on disk; restyling");
reaktor_restyle();
}
static Uint32 SDLCALL
watch_tick(void *user, SDL_TimerID id, Uint32 interval)
{
int i, changed = 0;
(void)user; (void)id;
SDL_LockMutex(g_watched.lock);
for (i = 0; i < g_watched.n; i++) {
SDL_PathInfo info;
if (SDL_GetPathInfo(g_watched.path[i], &info) && info.modify_time != g_watched.when[i]) {
g_watched.when[i] = info.modify_time;
changed = 1;
}
}
SDL_UnlockMutex(g_watched.lock);
if (changed && g_app) reaktor_post(g_app, watch_reload, NULL);
return interval;
}
static void
watch_seen(const char *name)
{
char full[1024];
SDL_PathInfo info;
int i;
if (reaktor_path_absolute(name)) SDL_strlcpy(full, name, sizeof full);
else if (!reaktor_path(full, sizeof full, name)) return;
if (!SDL_GetPathInfo(full, &info) || info.type != SDL_PATHTYPE_FILE) return;
SDL_LockMutex(g_watched.lock);
for (i = 0; i < g_watched.n && SDL_strcmp(g_watched.path[i], full) != 0; i++) {}
if (i == g_watched.n && g_watched.n < WATCH_MAX && (g_watched.path[i] = SDL_strdup(full))) {
g_watched.when[i] = info.modify_time;
g_watched.n++;
}
SDL_UnlockMutex(g_watched.lock);
}
static void
watch_begin(void)
{
if (!g_watched.lock && !(g_watched.lock = SDL_CreateMutex())) return;
SDL_LockMutex(g_watched.lock);
while (g_watched.n) SDL_free(g_watched.path[--g_watched.n]);
SDL_UnlockMutex(g_watched.lock);
reaktor_css_track(watch_seen);
if (!g_watched.timer) g_watched.timer = SDL_AddTimer(500, watch_tick, NULL);
}
static void
watch_stop(void)
{
if (g_watched.timer) SDL_RemoveTimer(g_watched.timer);
g_watched.timer = 0;
while (g_watched.n) SDL_free(g_watched.path[--g_watched.n]);
SDL_DestroyMutex(g_watched.lock);
g_watched.lock = NULL;
}
static void
load_theme(App *app)
{
const char *sheets[SHEET_MAX];
@@ -349,6 +480,8 @@ load_theme(App *app)
Uint64 t0, t1;
app->dark = effective_dark(app);
read_prefs();
if (g_watch) watch_begin();
sheets[n++] = theme_sheet(app->dark);
sheets[n++] = CORE_SHEET;
@@ -364,7 +497,7 @@ load_theme(App *app)
if (!reaktor_style_init(sheets, n, app->dark ? "dark" : "light"))
SDL_Log("stylesheets failed to load; Nuklear defaults apply");
read_roles(app);
if (n > base && n < SHEET_MAX) {
if (n > base && n < SHEET_MAX && !roles_hold(app)) {
sheets[n] = role_sheet(app);
if (reaktor_style_init(sheets, n + 1, app->dark ? "dark" : "light"))
read_roles(app);
@@ -430,7 +563,7 @@ web_on_resize(int type, const EmscriptenUiEvent *ev, void *user)
#if defined(_WIN32) && !defined(__EMSCRIPTEN__)
#define COBJMACROS
#include <dxgi.h>
int
static int
renderer_is_software(SDL_Renderer *ren)
{
IUnknown *dev;
@@ -457,7 +590,7 @@ renderer_is_software(SDL_Renderer *ren)
return software;
}
#else
int renderer_is_software(SDL_Renderer *ren) { (void)ren; return 0; }
static int renderer_is_software(SDL_Renderer *ren) { (void)ren; return 0; }
#endif
#define HOVER_GAP_MS 50
@@ -487,7 +620,7 @@ calibrate_hover_gap(App *app)
: HOVER_GAP_MS;
}
int
static int
reaktor_hot_motion(App *app, float mx, float my)
{
struct nk_rect nr;
@@ -534,7 +667,7 @@ reaktor_cursor(int kind)
return g_cursor[kind];
}
void
static void
reaktor_show_cursor(App *app)
{
SDL_Cursor *c;
@@ -545,7 +678,7 @@ reaktor_show_cursor(App *app)
app->cur_shown = app->want_cursor;
}
void
static void
reaktor_place_ime(App *app)
{
SDL_Window *keys = SDL_GetKeyboardFocus();
@@ -555,7 +688,7 @@ reaktor_place_ime(App *app)
app->ime_valid = 0;
}
void
static void
reaktor_hover_redraw(App *app)
{
if (app->dragging || SDL_GetTicks() - app->last_draw_ms >= g_hover_gap_ms) {
@@ -665,6 +798,11 @@ app_init(void **appstate, int argc, char *argv[])
if (g_launch.name || g_launch.version || g_launch.id)
SDL_SetAppMetadata(g_launch.name, g_launch.version, g_launch.id);
/* A later launch hands its files to the running copy and is done. */
/* A run for a shot or a dump is a test, and always its own copy. */
if (g_launch.single_instance && !g_new_instance && !app->shot_path && !app->dump_path &&
!reaktor_instance_claim(argc, argv))
return SDL_APP_SUCCESS;
reaktor_hint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
reaktor_hint(SDL_HINT_TIMER_RESOLUTION, "0");
reaktor_hint(SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE, "0");
@@ -773,7 +911,7 @@ app_init(void **appstate, int argc, char *argv[])
reaktor_a11y_platform_init(reader_activate, reader_focus, app);
app->vsync_on = SDL_SetRenderVSync(app->ren, 1) ? 1 : 0;
app->aa = 1;
app->aa_mode = (int)g_launch.anti_aliasing;
app->redraw_always = 0;
SDL_strlcpy(app->frame_rate, "waitevent", sizeof(app->frame_rate));
@@ -816,6 +954,7 @@ app_init(void **appstate, int argc, char *argv[])
take_pending(app);
load_theme(app);
reaktor_rss_mark(REAKTOR_RSS_STYLE);
if (g_launch.single_instance) reaktor_instance_listen(app, g_launch.file_opened);
app->dirty = 1;
@@ -829,6 +968,14 @@ app_init(void **appstate, int argc, char *argv[])
return SDL_APP_CONTINUE;
}
static void
drag_end(App *app)
{
app->dragging = 0;
app->drag_in_field = 0;
app->restore_rate = 2;
}
void
reaktor_take_event(App *app, SDL_Event *event)
{
@@ -885,18 +1032,20 @@ reaktor_take_event(App *app, SDL_Event *event)
reaktor_hint(SDL_HINT_MAIN_CALLBACK_RATE, app->drag_rate);
break;
/* Windows and most desktops send nothing when reduced motion or
contrast changes; coming back from their settings is the cue. */
case SDL_EVENT_WINDOW_FOCUS_GAINED:
if (!app->secondary && read_prefs()) load_theme(app);
break;
case SDL_EVENT_WINDOW_FOCUS_LOST:
if (app->dragging) {
app->dragging = 0;
app->drag_in_field = 0;
app->restore_rate = 2;
drag_end(app);
}
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
app->dragging = 0;
app->drag_in_field = 0;
app->restore_rate = 2;
drag_end(app);
break;
/* Nuklear scrolls a panel at its end, after drawing what it holds. */
@@ -911,7 +1060,7 @@ reaktor_take_event(App *app, SDL_Event *event)
break;
case SDL_EVENT_SYSTEM_THEME_CHANGED:
if (app->theme_mode == REAKTOR_THEME_SYSTEM) load_theme(app);
if (app->theme_mode == REAKTOR_THEME_SYSTEM || read_prefs()) load_theme(app);
break;
case SDL_EVENT_LOCALE_CHANGED:
@@ -1125,9 +1274,7 @@ reaktor_app_due(App *app, int w, int h)
!(SDL_GetGlobalMouseState(NULL, NULL) &
(SDL_BUTTON_LMASK | SDL_BUTTON_MMASK | SDL_BUTTON_RMASK |
SDL_BUTTON_X1MASK | SDL_BUTTON_X2MASK))) {
app->dragging = 0;
app->drag_in_field = 0;
app->restore_rate = 2;
drag_end(app);
app->dirty = 1;
}
@@ -1419,11 +1566,13 @@ app_quit(void *appstate, SDL_AppResult result)
(void)result;
SDL_SetAtomicInt(&g_running, 0);
reaktor_instance_stop();
if (!app) {
reaktor_process_end();
return;
}
reaktor_inspector_stop(app);
watch_stop();
run_stop(app);
if (remembers(app)) reaktor_window_remember(app);
reaktor_timers_drop(NULL);
+27 -1
View File
@@ -620,7 +620,33 @@ reaktor_inspector_frame(App *app)
g_frames++;
g_why = app->why;
app->why = 0;
if (shown()) redraw_window_only();
if (!shown()) return;
/* Only the Frame tab changes with every frame; the rest follow the tree. */
{
static unsigned last;
const reaktor_a11y_node *n;
unsigned h = REAKTOR_FNV;
int i, count;
n = reaktor_a11y_tree(&app->a11y, &count);
for (i = 0; i < count; i++) {
unsigned v[6];
int k;
v[0] = n[i].id;
v[1] = n[i].state;
v[2] = (unsigned)(int)n[i].bounds.x;
v[3] = (unsigned)(int)n[i].bounds.y;
v[4] = (unsigned)(int)n[i].bounds.w;
v[5] = (unsigned)(int)n[i].bounds.h;
h = reaktor_fnv_n(h, v, sizeof v);
h = reaktor_fnv(h, n[i].value);
}
h ^= reaktor_style_loads();
if (h == last && g_tab != TAB_FRAME) return;
last = h;
}
redraw_window_only();
}
int
+369
View File
@@ -0,0 +1,369 @@
/* One running copy per app when .single_instance asks for it: a later launch
hands its file arguments to the running copy and exits. Each message is a
count of paths, then each path as a length and its bytes. */
#include "internal.h"
#ifndef __EMSCRIPTEN__
#define INSTANCE_PATH_MAX 4096
#define INSTANCE_PATHS_MAX 64
static void (*g_opened)(App *app, const char *path);
static void
deliver_path(App *app, void *user)
{
if (g_opened) g_opened(app, (const char *)user);
SDL_free(user);
}
static void
deliver_raise(App *app, void *user)
{
(void)user;
if (!app || !app->win) return;
if (SDL_GetWindowFlags(app->win) & SDL_WINDOW_MINIMIZED) SDL_RestoreWindow(app->win);
SDL_RaiseWindow(app->win);
}
/* What a read gives back: the paths, posted to the main thread in order. */
typedef int (*instance_read)(void *conn, void *buf, Uint32 n);
static void
receive(App *app, instance_read rd, void *conn)
{
Uint32 count = 0, i, len;
char *path;
if (rd(conn, &count, sizeof count) && count <= INSTANCE_PATHS_MAX) {
for (i = 0; i < count; i++) {
if (!rd(conn, &len, sizeof len) || len == 0 || len >= INSTANCE_PATH_MAX) break;
if (!(path = (char *)SDL_malloc(len + 1))) break;
if (!rd(conn, path, len)) {
SDL_free(path);
break;
}
path[len] = 0;
reaktor_post(app, deliver_path, path);
}
}
reaktor_post(app, deliver_raise, NULL);
}
/* The message a later launch sends: its arguments, made absolute, since the
running copy's working folder is its own. */
static int
message(int argc, char **argv, char **out, Uint32 *out_len)
{
Uint32 count = 0, total = sizeof count, at;
char *abs[INSTANCE_PATHS_MAX];
int i;
for (i = 1; i < argc && count < INSTANCE_PATHS_MAX; i++) {
if (!argv[i] || !*argv[i]) continue;
if (reaktor_path_absolute(argv[i])) {
abs[count] = SDL_strdup(argv[i]);
} else {
char *cwd = SDL_GetCurrentDirectory();
abs[count] = NULL;
if (cwd && SDL_asprintf(&abs[count], "%s%s", cwd, argv[i]) < 0) abs[count] = NULL;
SDL_free(cwd);
}
if (!abs[count]) continue;
total += (Uint32)(sizeof(Uint32) + SDL_strlen(abs[count]));
count++;
}
*out = (char *)SDL_malloc(total);
if (*out) {
SDL_memcpy(*out, &count, sizeof count);
at = sizeof count;
for (i = 0; i < (int)count; i++) {
Uint32 len = (Uint32)SDL_strlen(abs[i]);
SDL_memcpy(*out + at, &len, sizeof len);
SDL_memcpy(*out + at + sizeof len, abs[i], len);
at += (Uint32)sizeof len + len;
}
}
for (i = 0; i < (int)count; i++) SDL_free(abs[i]);
*out_len = total;
return *out != NULL;
}
#endif
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
static HANDLE g_mutex;
static char g_pipe[256];
static SDL_Thread *g_thread;
static SDL_AtomicInt g_stop;
static int
pipe_read(void *conn, void *buf, Uint32 n)
{
DWORD got = 0;
char *p = (char *)buf;
while (n) {
if (!ReadFile((HANDLE)conn, p, n, &got, NULL) || !got) return 0;
p += got;
n -= got;
}
return 1;
}
static void
names(void)
{
DWORD session = 0;
unsigned h = reaktor_fnv(REAKTOR_FNV, reaktor_app_ident());
ProcessIdToSessionId(GetCurrentProcessId(), &session);
SDL_snprintf(g_pipe, sizeof g_pipe, "\\\\.\\pipe\\reaktor.%lu.%08x", (unsigned long)session, h);
}
int
reaktor_instance_claim(int argc, char **argv)
{
char mutex[96], *msg = NULL;
Uint32 len = 0;
HANDLE pipe = INVALID_HANDLE_VALUE;
ULONG server = 0;
DWORD wrote = 0;
int tries;
names();
SDL_snprintf(mutex, sizeof mutex, "Local\\reaktor.%08x",
reaktor_fnv(REAKTOR_FNV, reaktor_app_ident()));
g_mutex = CreateMutexA(NULL, TRUE, mutex);
if (g_mutex && GetLastError() != ERROR_ALREADY_EXISTS) return 1;
if (g_mutex) CloseHandle(g_mutex);
g_mutex = NULL;
/* The first copy may still be starting its listener. */
for (tries = 0; tries < 50; tries++) {
pipe = CreateFileA(g_pipe, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (pipe != INVALID_HANDLE_VALUE) break;
if (GetLastError() == ERROR_PIPE_BUSY) WaitNamedPipeA(g_pipe, 200);
else Sleep(100);
}
if (pipe == INVALID_HANDLE_VALUE) {
SDL_Log("single instance: the running copy did not answer; starting another");
return 1;
}
if (GetNamedPipeServerProcessId(pipe, &server)) AllowSetForegroundWindow(server);
if (message(argc, argv, &msg, &len)) WriteFile(pipe, msg, len, &wrote, NULL);
SDL_free(msg);
CloseHandle(pipe);
return 0;
}
static int SDLCALL
listen_thread(void *data)
{
App *app = (App *)data;
while (!SDL_GetAtomicInt(&g_stop)) {
HANDLE p = CreateNamedPipeA(g_pipe, PIPE_ACCESS_INBOUND,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT |
PIPE_REJECT_REMOTE_CLIENTS,
PIPE_UNLIMITED_INSTANCES, 0, 64 * 1024, 0, NULL);
if (p == INVALID_HANDLE_VALUE) return 0;
if (ConnectNamedPipe(p, NULL) || GetLastError() == ERROR_PIPE_CONNECTED) {
if (!SDL_GetAtomicInt(&g_stop)) receive(app, pipe_read, p);
}
DisconnectNamedPipe(p);
CloseHandle(p);
}
return 0;
}
void
reaktor_instance_listen(App *app, void (*opened)(App *app, const char *path))
{
g_opened = opened;
if (!g_mutex || g_thread) return;
g_thread = SDL_CreateThread(listen_thread, "reaktor-instance", app);
}
void
reaktor_instance_stop(void)
{
if (g_thread) {
HANDLE p;
SDL_SetAtomicInt(&g_stop, 1);
/* The listener waits in ConnectNamedPipe; one connection releases it. */
p = CreateFileA(g_pipe, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (p != INVALID_HANDLE_VALUE) CloseHandle(p);
SDL_WaitThread(g_thread, NULL);
g_thread = NULL;
}
if (g_mutex) {
ReleaseMutex(g_mutex);
CloseHandle(g_mutex);
g_mutex = NULL;
}
}
#elif !defined(__EMSCRIPTEN__)
#include <errno.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
static int g_listen = -1;
static char g_sock[sizeof(((struct sockaddr_un *)0)->sun_path)];
static SDL_Thread *g_thread;
static SDL_AtomicInt g_stop;
static int
sock_read(void *conn, void *buf, Uint32 n)
{
char *p = (char *)buf;
while (n) {
ssize_t got = read(*(int *)conn, p, n);
if (got < 0 && errno == EINTR) continue;
if (got <= 0) return 0;
p += got;
n -= (Uint32)got;
}
return 1;
}
/* Beside the app's settings when that fits a socket's path, in /tmp by user otherwise. */
static int
sock_path(void)
{
char *dir = SDL_GetPrefPath(NULL, reaktor_app_ident());
int n = -1;
if (dir) n = SDL_snprintf(g_sock, sizeof g_sock, "%sinstance.sock", dir);
SDL_free(dir);
if (n < 0 || (size_t)n >= sizeof g_sock)
n = SDL_snprintf(g_sock, sizeof g_sock, "/tmp/reaktor.%lu.%08x.sock",
(unsigned long)getuid(), reaktor_fnv(REAKTOR_FNV, reaktor_app_ident()));
return n > 0 && (size_t)n < sizeof g_sock;
}
static int
sock_connect(void)
{
struct sockaddr_un a;
int s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s < 0) return -1;
SDL_zero(a);
a.sun_family = AF_UNIX;
SDL_strlcpy(a.sun_path, g_sock, sizeof a.sun_path);
if (connect(s, (struct sockaddr *)&a, sizeof a) == 0) return s;
close(s);
return -1;
}
int
reaktor_instance_claim(int argc, char **argv)
{
struct sockaddr_un a;
char *msg = NULL;
Uint32 len = 0;
int s, tries;
if (!sock_path()) return 1;
for (tries = 0; tries < 3; tries++) {
g_listen = socket(AF_UNIX, SOCK_STREAM, 0);
if (g_listen < 0) return 1;
SDL_zero(a);
a.sun_family = AF_UNIX;
SDL_strlcpy(a.sun_path, g_sock, sizeof a.sun_path);
if (bind(g_listen, (struct sockaddr *)&a, sizeof a) == 0 && listen(g_listen, 8) == 0)
return 1;
close(g_listen);
g_listen = -1;
if (errno != EADDRINUSE) return 1;
s = sock_connect();
if (s >= 0) {
if (message(argc, argv, &msg, &len)) {
ssize_t put = write(s, msg, len);
(void)put;
}
SDL_free(msg);
close(s);
return 0;
}
/* Nobody listens: a copy that crashed left its socket behind. */
unlink(g_sock);
}
return 1;
}
static int SDLCALL
listen_thread(void *data)
{
App *app = (App *)data;
while (!SDL_GetAtomicInt(&g_stop)) {
int c = accept(g_listen, NULL, NULL);
if (c < 0) {
if (errno == EINTR) continue;
break;
}
if (!SDL_GetAtomicInt(&g_stop)) receive(app, sock_read, &c);
close(c);
}
return 0;
}
void
reaktor_instance_listen(App *app, void (*opened)(App *app, const char *path))
{
g_opened = opened;
if (g_listen < 0 || g_thread) return;
g_thread = SDL_CreateThread(listen_thread, "reaktor-instance", app);
}
void
reaktor_instance_stop(void)
{
if (g_listen < 0) return;
SDL_SetAtomicInt(&g_stop, 1);
/* The listener waits in accept; one connection releases it. */
if (g_thread) {
int s = sock_connect();
if (s >= 0) close(s);
SDL_WaitThread(g_thread, NULL);
g_thread = NULL;
}
close(g_listen);
g_listen = -1;
unlink(g_sock);
}
#else
int
reaktor_instance_claim(int argc, char **argv)
{
(void)argc; (void)argv;
return 1;
}
void
reaktor_instance_listen(App *app, void (*opened)(App *app, const char *path))
{
(void)app; (void)opened;
}
void
reaktor_instance_stop(void)
{
}
#endif
+8
View File
@@ -0,0 +1,8 @@
/* PDFGen as it ships, minus one clash: NetBSD's <sys/types.h> declares a
bswap32 and wraps it in a macro, and PDFGen defines a static function of
that name. PDFGen's is renamed; the header's guard keeps it from coming back. */
#include <sys/types.h>
#undef bswap32
#define bswap32 pdfgen_bswap32
#include "pdfgen.c"
+17 -14
View File
@@ -1,7 +1,7 @@
#include "internal.h"
#include "reaktor/launch.h"
#include "declare.h"
#include "hpdf.h"
#include "pdfgen.h"
#include "plutovg.h"
#define REAKTOR_PRINT_PAGES 64
@@ -105,7 +105,7 @@ print_run(App *app, void *user)
print_job *job = (print_job *)user;
float keep = reaktor_scale(), pt_w = job->spec.w, pt_h = job->spec.h;
SDL_Surface *page[REAKTOR_PRINT_PAGES];
HPDF_Doc doc = NULL;
struct pdf_doc *doc = NULL;
App *pa = NULL;
int id, i, n = 0, ok = 1;
@@ -120,7 +120,7 @@ print_run(App *app, void *user)
job->index = i;
reaktor_app_size(pa, &w, &h);
for (k = 0; k < 6 || (!reaktor_frame_settled(pa) && k < 24); k++)
for (k = 0; k < 3 || (!reaktor_frame_settled(pa) && k < 24); k++)
reaktor_app_frame(pa, w, h, "", print_page, job);
pa->want_capture = 1;
reaktor_app_frame(pa, w, h, "", print_page, job);
@@ -138,25 +138,28 @@ print_run(App *app, void *user)
ok = print_win32(app, page, n, job->spec.title ? job->spec.title : "Reaktor");
else
#endif
if (ok) doc = HPDF_New(NULL, NULL);
if (ok) {
struct pdf_info info;
SDL_zero(info);
SDL_strlcpy(info.creator, "Reaktor", sizeof info.creator);
if (job->spec.title) SDL_strlcpy(info.title, job->spec.title, sizeof info.title);
doc = pdf_create(pt_w, pt_h, &info);
}
for (i = 0; doc && ok && i < n; i++) {
plutovg_surface_t *s = plutovg_surface_create_for_data(page[i]->pixels, page[i]->w,
page[i]->h, page[i]->pitch);
jpeg_buf b = { NULL, 0, 0 };
HPDF_Page p = HPDF_AddPage(doc);
HPDF_Image im = NULL;
jpeg_buf b = { NULL, 0, 0 };
struct pdf_object *p = pdf_append_page(doc);
if (s) plutovg_surface_write_to_jpg_stream(s, jpeg_put, &b, 90);
plutovg_surface_destroy(s);
if (b.len) im = HPDF_LoadJpegImageFromMem(doc, b.bytes, (HPDF_UINT)b.len);
if (!p || !b.len ||
pdf_add_image_data(doc, p, 0, 0, pt_w, pt_h, b.bytes, b.len) < 0) ok = 0;
SDL_free(b.bytes);
HPDF_Page_SetWidth(p, pt_w);
HPDF_Page_SetHeight(p, pt_h);
if (!im || HPDF_Page_DrawImage(p, im, 0, 0, pt_w, pt_h) != HPDF_OK) ok = 0;
}
if (doc && job->spec.title) HPDF_SetInfoAttr(doc, HPDF_INFO_TITLE, job->spec.title);
if (doc && ok) ok = HPDF_SaveToFile(doc, job->path) == HPDF_OK;
if (doc) HPDF_Free(doc);
if (doc && ok) ok = pdf_save(doc, job->path) >= 0;
if (doc) pdf_destroy(doc);
#if defined(__APPLE__)
if (doc && ok && job->to_printer) ok = reaktor_print_macos(job->path);
#elif !defined(_WIN32)
+1 -1
View File
@@ -187,7 +187,7 @@ open_window(const reaktor_window *spec, const struct nk_rect *popup)
SDL_SetRenderVSync(a->ren, 1);
a->renderer_is_sw = SDL_strcmp(SDL_GetRendererName(a->ren), "software") == 0;
a->sw_noaa = m->sw_noaa;
a->aa = 1;
a->aa_mode = m->aa_mode;
a->font_face = m->font_face;
a->font_face_bold = m->font_face_bold;
for (i = 0; i < m->icon_dir_count; i++) a->icon_dirs[i] = m->icon_dirs[i];
+5 -2
View File
@@ -65,8 +65,11 @@ page_shell(App *app, struct reaktor_context *ctx, int win_w, int win_h)
{
size_t rss = 0, priv = 0;
reaktor_process_memory(&rss, &priv);
if (priv > g_priv_peak) g_priv_peak = priv;
/* On Linux and the BSDs a read walks /proc; not inside every timed frame. */
if (g_frames % 30 == 0) {
reaktor_process_memory(&rss, &priv);
if (priv > g_priv_peak) g_priv_peak = priv;
}
}
g_frames++;
+52 -1
View File
@@ -68,6 +68,49 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
reaktor_soak();
}
section(app, ctx, "One copy at a time",
"The showcase is launched with .single_instance, so starting it again "
"does not open a second window: the new copy hands its file arguments "
"to this one, which gets each through .file_opened and comes to the "
"front, and the new copy exits. --new-instance starts a separate copy "
"anyway.");
api(app, ctx, ".single_instance / .file_opened / --new-instance");
#ifndef __EMSCRIPTEN__
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
if (reaktor_button(&(reaktor_button_spec){
.label = "Launch the showcase again, with a file",
.name = "Launch again", .box = { .w = 340.0f } })) {
char exe[1024];
const char *base = SDL_GetBasePath();
const char *args[3];
SDL_Process *p;
SDL_snprintf(exe, sizeof exe, "%sshowcase%s", base ? base : "",
#ifdef _WIN32
".exe"
#else
""
#endif
);
args[0] = exe;
args[1] = exe;
args[2] = NULL;
p = SDL_CreateProcess(args, false);
if (p) SDL_DestroyProcess(p);
else SDL_Log("could not launch %s: %s", exe, SDL_GetError());
}
reaktor_soak();
}
#endif
SDL_snprintf(v, sizeof v, "%d, the last %s", st->handed,
st->handed ? st->file_pick : "none yet");
REAKTOR_ROW(.h = ROW_SMALL) {
reaktor_label(&(reaktor_label_spec){ .text = "Files handed over", .name = "Files handed over",
.box = { .w = 180.0f } });
reaktor_label(&(reaktor_label_spec){ .text = v, .name = "Handed over",
.box = { .flags = REAKTOR_LAY_FILL_X } });
}
section(app, ctx, "Rendering",
"Which backend SDL settled on. It is the software rasterizer "
"on every platform: this draws nothing at rest, so a GPU buys it "
@@ -136,7 +179,11 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
section(app, ctx, "Style and text",
"The stylesheets are parsed by LCUI's libcss on every theme "
"change, and the font atlas is baked per size at the display's "
"scale.");
"scale. The system's reduced motion and contrast reach the sheets as "
"@media queries, and with --watch-css a sheet saved on disk restyles "
"the window.");
api(app, ctx, "reaktor_reduced_motion / reaktor_high_contrast / "
"--motion, --contrast, --watch-css");
SDL_snprintf(v, sizeof(v), "%s", d.dark ? "dark" : "light");
DIAG_ROWS(ctx) {
@@ -147,6 +194,10 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
SDL_snprintf(v, sizeof(v), "%.2fx", (double)d.scale);
diag_row(app, ctx, "display scale", v);
diag_row(app, ctx, "font", d.font);
diag_row(app, ctx, "reduced motion",
reaktor_reduced_motion() ? "on: animations jump to their end" : "off");
diag_row(app, ctx, "contrast",
reaktor_high_contrast() ? "more: @media (prefers-contrast: more)" : "no preference");
}
section(app, ctx, "Memory",
+57
View File
@@ -320,4 +320,61 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
reaktor_layout_row_dynamic(ctx, 8.0f, 1);
reaktor_spacer(ctx);
section(app, ctx, "Nuklear underneath",
"Every widget here is drawn by Nuklear, and its own calls answer "
"to reaktor_ names for whatever the declared widgets leave out: a "
"tree node, a menu of its own, a checkbox with its box on the "
"right. Its style structs read the same way.");
api(app, ctx, "reaktor_tree_push / reaktor_menu_begin_label / "
"reaktor_checkbox_label_align");
{
struct reaktor_rect panel = reaktor_window_get_bounds(ctx);
const struct reaktor_style_button *btn = &ctx->style.button;
const struct reaktor_style_selectable *sel = &ctx->style.selectable;
struct reaktor_style_item fill = btn->normal;
char line[96];
reaktor_layout_row_dynamic(ctx, 28.0f, 4);
hot(app, ctx, REAKTOR_A11Y_MENU, "Nuklear menu", 0);
if (reaktor_menu_begin_label(ctx, "Nuklear menu", REAKTOR_TEXT_LEFT,
reaktor_vec2(170.0f, reaktor_menu_height(2)))) {
reaktor_layout_row_dynamic(ctx, REAKTOR_MENU_ROW, 1);
if (reaktor_menu_item_symbol_label(ctx, REAKTOR_SYMBOL_CIRCLE_SOLID, "Round",
REAKTOR_TEXT_RIGHT))
SDL_strlcpy(s->menu_pick, "Nuklear: Round", sizeof(s->menu_pick));
if (reaktor_menu_item_symbol_label(ctx, REAKTOR_SYMBOL_RECT_SOLID, "Square",
REAKTOR_TEXT_RIGHT))
SDL_strlcpy(s->menu_pick, "Nuklear: Square", sizeof(s->menu_pick));
reaktor_menu_end(ctx);
}
if (reaktor_tree_push(ctx, REAKTOR_TREE_NODE, "A Nuklear tree node",
REAKTOR_MINIMIZED)) {
reaktor_layout_row_dynamic(ctx, 26.0f, 1);
hot(app, ctx, REAKTOR_A11Y_CHECKBOX, "Box on the right",
s->raw_check ? REAKTOR_A11Y_CHECKED : 0u);
reaktor_checkbox_label_align(ctx, "Box on the right", &s->raw_check,
REAKTOR_WIDGET_RIGHT, REAKTOR_TEXT_LEFT);
if (reaktor_tree_element_push(ctx, REAKTOR_TREE_NODE, "A selectable element",
REAKTOR_MAXIMIZED, &s->raw_sel)) {
reaktor_layout_row_dynamic(ctx, 22.0f, 1);
reaktor_text_label(ctx, s->raw_sel ? "selected" : "not selected",
REAKTOR_TEXT_LEFT);
reaktor_tree_element_pop(ctx);
}
reaktor_tree_pop(ctx);
}
reaktor_layout_row_dynamic(ctx, 22.0f, 1);
SDL_snprintf(line, sizeof line, "This panel: %.0f x %.0f; a button pads %.0f x %.0f, "
"a selectable %.0f x %.0f; button fill %s",
panel.w, panel.h, btn->padding.x, btn->padding.y,
sel->padding.x, sel->padding.y,
fill.type == REAKTOR_STYLE_ITEM_COLOR ? "is a color" : "is not a color");
reaktor_text_label(ctx, line, REAKTOR_TEXT_LEFT);
}
reaktor_layout_row_dynamic(ctx, 8.0f, 1);
reaktor_spacer(ctx);
}
+6 -6
View File
@@ -44,8 +44,8 @@ rule_says(const char *selector)
void
page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
{
static const reaktor_asset bamboo_css = {
.path = "external/bamboocss/dist/bamboo.min.css" };
static const reaktor_asset simple_css = {
.path = "external/simplecss/simple.css" };
static reaktor_bool on;
section(app, ctx, "Change the stylesheet, change the application",
@@ -54,15 +54,15 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
"in the window follows - the buttons, the fields, the borders, "
"the corners. That is the only claim this library makes about "
"styling, and it is either true in front of you or it is not.");
api(app, ctx, "external/bamboocss");
api(app, ctx, "external/simplecss");
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
if (reaktor_check(&(reaktor_check_spec){
.label = "Read Bamboo over the top of Water.css",
.label = "Read Simple.css over the top of Water.css",
.name = "Override stylesheet",
.on = &on,
.box = { .w = 380.0f, .flags = REAKTOR_LAY_CENTER_Y } }))
reaktor_set_css(app, on ? &bamboo_css : NULL, on ? 1 : 0);
reaktor_set_css(app, on ? &simple_css : NULL, on ? 1 : 0);
reaktor_soak();
}
@@ -150,7 +150,7 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
.name = "Controls with no rule", .color = "--text-muted",
.wrap = 1, .box = { .flags = REAKTOR_LAY_FILL_X } });
reaktor_label(&(reaktor_label_spec){
.text = "Bamboo keeps its dark palette in "
.text = "Simple.css keeps its dark palette in "
"@media (prefers-color-scheme: dark), which this tree "
"used to drop along with every other at-rule - so a "
"sheet written that way loaded light-only. That branch "
+9 -8
View File
@@ -194,7 +194,7 @@ titlebar_button(App *app, struct reaktor_context *ctx, const char *glyph,
float pad_x, pad_y;
int clicked;
reaktor_hot(app, b, 1, 1);
reaktor_hot(app, b, REAKTOR_CURSOR_POINTER, 1);
reaktor_note(app, REAKTOR_A11Y_BUTTON, name, NULL, 0, b);
if (g_ctl_n < (int)(sizeof(g_ctl) / sizeof(g_ctl[0])))
g_ctl[g_ctl_n++] = b;
@@ -308,7 +308,7 @@ titlebar(App *app, struct reaktor_context *ctx, int win_w)
#define ROW_BRAND 28
#define ROW_FIELD 38
#define ROW_BUTTON 40
#define ROW_SMALL 18
#define ROW_NOTE 18
#define ROW_GAP 15
#define CONTACT_ROWS 3
@@ -320,10 +320,10 @@ card_height(int with_diag)
{
int rows = 7;
float h = (float)(ROW_BRAND + ROW_FIELD + ROW_BUTTON +
ROW_SMALL + ROW_BUTTON + ROW_BUTTON + ROW_SMALL);
ROW_NOTE + ROW_BUTTON + ROW_BUTTON + ROW_NOTE);
if (with_diag) {
rows += CONTACT_ROWS;
h += CONTACT_ROWS * ROW_SMALL;
h += CONTACT_ROWS * ROW_NOTE;
}
return h + (rows - 1) * ROW_GAP + 2.0f * CARD_PAD_Y + 6.0f;
}
@@ -398,7 +398,7 @@ login_card(App *app, struct reaktor_context *ctx, float body_x, float body_w,
reaktor_label(&(reaktor_label_spec){
.text = "or", .style = ".card-note", .align = REAKTOR_CENTER,
.box = { .h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
.box = { .h = ROW_NOTE, .flags = REAKTOR_LAY_FILL_X,
.ml = CARD_PAD_X, .mr = CARD_PAD_X } });
reaktor_button(&(reaktor_button_spec){
@@ -413,7 +413,7 @@ login_card(App *app, struct reaktor_context *ctx, float body_x, float body_w,
if (reaktor_link(&(reaktor_link_spec){
.text = g_show_contact ? "hide contact" : "contact",
.style = ".card-link",
.box = { .h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
.box = { .h = ROW_NOTE, .flags = REAKTOR_LAY_FILL_X,
.ml = CARD_PAD_X, .mr = CARD_PAD_X,
.mb = g_show_contact ? 0.0f : CARD_PAD_Y } }))
g_show_contact = !g_show_contact;
@@ -429,7 +429,7 @@ login_card(App *app, struct reaktor_context *ctx, float body_x, float body_w,
for (i = 0; i < CONTACT_ROWS; i++)
reaktor_label(&(reaktor_label_spec){
.text = lines[i], .style = ".card-link", .align = REAKTOR_CENTER,
.box = { .h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
.box = { .h = ROW_NOTE, .flags = REAKTOR_LAY_FILL_X,
.ml = CARD_PAD_X, .mr = CARD_PAD_X,
.mb = i == CONTACT_ROWS - 1 ? CARD_PAD_Y : 0.0f } });
}
@@ -487,7 +487,7 @@ sample_option(App *app, struct reaktor_context *ctx, const char *label, float w,
}
reaktor_layout_row_push(ctx, w);
b = reaktor_widget_bounds(ctx);
reaktor_hot(app, b, 1, 1);
reaktor_hot(app, b, REAKTOR_CURSOR_POINTER, 1);
look = push_strip_look(ctx, fg, strip_wash());
id = reaktor_note(app, REAKTOR_A11Y_RADIO, label, NULL,
@@ -808,6 +808,7 @@ main(int argc, char **argv)
.borderless = 1, .hit_test = window_hit_test },
.font_fallbacks = { { .path = "assets/fonts/MPLUS1p-Regular.ttf" } },
.confirm_close = SC_CLOSE_QUESTION,
.single_instance = 1,
.inspector = { .attach = 1 },
.page = page_shell,
.key = sample_key,
+3 -1
View File
@@ -179,7 +179,7 @@ hot(App *app, struct reaktor_context *ctx, unsigned char role, const char *name,
{
struct reaktor_rect b = reaktor_widget_bounds(ctx);
reaktor_hot(app, b, 1, 1);
reaktor_hot(app, b, REAKTOR_CURSOR_POINTER, 1);
if (role == REAKTOR_A11Y_NONE) return 0;
return reaktor_note(app, role, name, NULL, state, b);
}
@@ -253,6 +253,8 @@ sample_file_opened(App *app, const char *path)
(void)app;
SDL_strlcpy(g_show.file_pick, path ? path : "no file",
sizeof(g_show.file_pick));
g_show.handed++;
SDL_Log("file opened: %s", g_show.file_pick);
}
void
+2
View File
@@ -103,7 +103,9 @@ typedef struct showcase_state {
double trail_at;
char menu_pick[40];
reaktor_bool raw_check, raw_sel;
char file_pick[SC_PATH_CAP];
int handed;
int seeded;
} showcase_state;
+25 -15
View File
@@ -5,8 +5,9 @@
#include "a11y.h"
#include "a11y_snapshot.h"
#include "test.h"
static int failures;
#define check test_eq
static struct nk_rect
r(float x, float y, float w, float h)
@@ -16,14 +17,6 @@ r(float x, float y, float w, float h)
return v;
}
static void
check(const char *what, int got, int want)
{
if (got == want) return;
printf("FAIL %s: got %d, want %d\n", what, got, want);
failures++;
}
static void
dump_to(reaktor_a11y *a, char *out, size_t cap)
{
@@ -366,6 +359,28 @@ int main(int argc, char **argv)
check_snapshot(&a);
{
int frame, added_late = 0, swaps = 0, side = a.pool_side;
for (frame = 0; frame < 600; frame++) {
char value[32];
snprintf(value, sizeof value, "%d%%", frame);
reaktor_a11y_begin(&a, "w", r(0, 0, 10, 10));
reaktor_a11y_add(&a, REAKTOR_A11Y_BUTTON, "OK", NULL, 0, r(0, 0, 1, 1));
reaktor_a11y_add(&a, REAKTOR_A11Y_PROGRESS, "Copying", value, 0, r(0, 2, 1, 1));
reaktor_a11y_end(&a);
if (a.pool_side != side) { side = a.pool_side; swaps++; }
if (frame > 0) {
const reaktor_a11y_change *c = reaktor_a11y_changes(&a, &n);
for (i = 0; i < n; i++)
if (c[i].kind == REAKTOR_A11Y_ADDED) added_late++;
}
}
check("a changing value refills the string pool", swaps > 0, 1);
check("a refilled pool adds no node", added_late, 0);
}
a.overflow_nodes = 0;
reaktor_a11y_begin(&a, "w", r(0, 0, 10, 10));
for (i = 0; i < REAKTOR_A11Y_MAX_NODES + 64; i++)
@@ -375,10 +390,5 @@ int main(int argc, char **argv)
check("overflow clamps at the arena size", n, REAKTOR_A11Y_MAX_NODES);
check("overflow is counted", a.overflow_nodes > 0, 1);
if (failures) {
printf("\n%d check%s failed\n", failures, failures == 1 ? "" : "s");
return 1;
}
printf("a11y: all checks passed\n");
return 0;
return test_done("a11y");
}
+4 -10
View File
@@ -3,17 +3,12 @@
#include <SDL3/SDL.h>
#include "anim.h"
#include "test.h"
#define ok test_ok
static int g_fail;
static int g_moving;
static void
ok(const char *what, int cond)
{
printf(" %-56s %s\n", what, cond ? "ok" : "FAILED");
if (!cond) g_fail = 1;
}
static float
frame(struct nka_context *a, unsigned id, unsigned channel, float to, float ms,
unsigned char curve, float gap_ms)
@@ -209,6 +204,5 @@ main(void)
test_curves();
test_table();
printf("\n%s\n", g_fail ? "FAILED" : "anim: all checks passed");
return g_fail ? 1 : 0;
return test_done("anim");
}
+66 -17
View File
@@ -3,8 +3,9 @@
#include <string.h>
#include "cssflat.h"
#include "test.h"
static int g_fail;
#define ok test_ok
static const char g_sheet[] =
"input:not([type=\"a\"]):not([type=\"b\"]) { color: #ff0000; }\n"
@@ -17,7 +18,25 @@ static const char g_sheet[] =
"margin: calc(2 * (3px + 1px)); width: calc(100% - 2 * 8px); }\n"
"q { background-image: url(data:image/svg+xml;base64,AAAA); color: #010203; }\n"
"q.v { content: \"a value longer than the engine token\"; color: #040506; }\n"
".a-selector-longer-than-the-engines-token, u { color: #070809; }\n";
".a-selector-longer-than-the-engines-token, u { color: #070809; }\n"
"b { border: thin solid #010101; border-left: medium; border-top-width: thick; }\n"
"i { border-style: thin-ish; }\n"
"s { border: unset; }\n"
"u.x { border: inherit; color: #0a0b0c; }\n"
"a.y { border-top: 2px dotted #0d0e0f !important; }\n"
"em { color: color-mix(in srgb, rgb(255 0 0 / 50%) 50%, red); "
"background-color: color-mix(in srgb, hsl(120, 100%, 50%), black); "
"border-top-color: color-mix(in srgb, #ff000080, rgba(0, 0, 255, 1)); }\n";
static const char g_media[] =
"@media (prefers-color-scheme: dark) { h1 { color: #000001; } }\n"
"@media (prefers-reduced-motion: reduce) { h2 { color: #000002; } }\n"
"@media (prefers-reduced-motion: no-preference) { h3 { color: #000003; } }\n"
"@media (prefers-contrast: more) { h4 { color: #000004; } }\n"
"@media screen and (prefers-contrast) { h5 { color: #000005; } }\n"
"@media print, (prefers-reduced-motion) { h6 { color: #000006; } }\n"
"@media (prefers-contrast: more) and (max-width: 720px) { ol { color: #000007; } }\n"
"@media print { ul { color: #000008; } }\n";
char *
reaktor_asset_load(const char *name, size_t *len)
@@ -25,10 +44,12 @@ reaktor_asset_load(const char *name, size_t *len)
char *out = NULL;
long n = 0;
if (strcmp(name, "test.css") == 0) {
n = (long)strlen(g_sheet);
if (strcmp(name, "test.css") == 0 || strcmp(name, "media.css") == 0) {
const char *s = name[0] == 't' ? g_sheet : g_media;
n = (long)strlen(s);
out = malloc((size_t)n + 1);
if (out) memcpy(out, g_sheet, (size_t)n + 1);
if (out) memcpy(out, s, (size_t)n + 1);
} else {
FILE *f = fopen(name, "rb");
@@ -55,13 +76,6 @@ reaktor_free(void *p)
free(p);
}
static void
ok(const char *what, int got)
{
if (!got) g_fail++;
printf(" %-52s %s\n", what, got ? "ok" : "FAILED");
}
static int
not_twice(const char *css)
{
@@ -79,7 +93,8 @@ int
main(void)
{
static const char *const test[1] = { "test.css" };
static const char *const bamboo[1] = { "external/bamboocss/dist/bamboo.min.css" };
static const char *const media[1] = { "media.css" };
static const char *const simple[1] = { "external/simplecss/simple.css" };
char *out;
int i;
@@ -100,17 +115,51 @@ main(void)
ok("a value with a ';' is dropped", !strstr(out, "base64") && strstr(out, "#010203"));
ok("a value past the token is dropped", !strstr(out, "longer") && strstr(out, "#040506"));
ok("a selector past the token is dropped", !strstr(out, "a-selector") && strstr(out, "u {"));
ok("border keyword widths become lengths",
strstr(out, "border-right-width: 1px;") && strstr(out, "border-left-width: 3px;") &&
strstr(out, "border-top-width: 5px;"));
ok("a border shorthand is spelled out as longhands",
!strstr(out, "border: ") && !strstr(out, "border-left: ") &&
strstr(out, "border-bottom-style: solid;") &&
strstr(out, "border-bottom-color: #010101;"));
ok(" with what it leaves out at libcss's own values",
strstr(out, "border-left-style: none;") &&
strstr(out, "border-left-color: transparent;"));
ok("border: unset is no border", strstr(out, "border-top-width: 0px;") != NULL);
ok("border: inherit is dropped, the rest of its rule kept",
!strstr(out, "inherit") && strstr(out, "#0a0b0c"));
ok("!important reaches every longhand",
strstr(out, "border-top-style: dotted !important;") &&
strstr(out, "border-top-color: #0d0e0f !important;"));
ok(" but not inside another word", strstr(out, "thin-ish") != NULL);
ok("color-mix() takes the space form, hsl() and names",
!strstr(out, "color-mix") && !strstr(out, "hsl("));
ok(" and the comma form with a hex alpha", strstr(out, "border-top-color: rgba(") != NULL);
free(out);
}
out = reaktor_css_flatten(media, 1, "light", 0, NULL);
ok("with no preference, only no-preference queries apply",
out && strstr(out, "#000003") && !strstr(out, "#000001") && !strstr(out, "#000002") &&
!strstr(out, "#000004") && !strstr(out, "#000005") && !strstr(out, "#000006"));
free(out);
reaktor_css_media(1, 1);
out = reaktor_css_flatten(media, 1, "dark", 0, NULL);
ok("reduced motion and more contrast apply theirs",
out && strstr(out, "#000001") && strstr(out, "#000002") && !strstr(out, "#000003") &&
strstr(out, "#000004") && strstr(out, "#000005") && strstr(out, "#000006"));
ok(" but not with a feature not answered here, nor print",
out && !strstr(out, "#000007") && !strstr(out, "#000008"));
free(out);
reaktor_css_media(0, 0);
for (i = 0; i < 2; i++) {
out = reaktor_css_flatten(bamboo, 1, i ? "dark" : "light", 0, NULL);
ok(i ? "Bamboo flattens, dark" : "Bamboo flattens, light",
out = reaktor_css_flatten(simple, 1, i ? "dark" : "light", 0, NULL);
ok(i ? "Simple.css flattens, dark" : "Simple.css flattens, light",
out != NULL && strstr(out, "button") != NULL);
ok(" and no compound in it holds two :not()", out != NULL && !not_twice(out));
free(out);
}
printf("\n%s\n", g_fail ? "FAILED" : "css: all checks passed");
return g_fail ? 1 : 0;
return test_done("css");
}
+5 -16
View File
@@ -2,19 +2,9 @@
#include <string.h>
#include "keys.h"
#include "test.h"
static int g_fail;
static void
ok(const char *what, int got, int want)
{
if (got != want) {
g_fail++;
printf(" %-52s got %d, wanted %d FAILED\n", what, got, want);
} else {
printf(" %-52s ok\n", what);
}
}
#define ok test_eq
static SDL_Event
press(SDL_Keycode key, SDL_Keymod mod)
@@ -139,7 +129,7 @@ text(const char *what, unsigned mods, SDL_Keycode key, const char *want)
char buf[64];
reaktor_chord_text(mods, key, buf, (int)sizeof(buf));
if (strcmp(buf, want) != 0) {
g_fail++;
failures++;
printf(" %-52s got \"%s\", wanted \"%s\" FAILED\n", what, buf, want);
} else {
printf(" %-52s \"%s\"\n", what, buf);
@@ -192,7 +182,7 @@ list(const char *what, int action, int index, const char *want)
buf[0] = '\0';
reaktor_shortcut_text(LIST, LIST_N, action, index, buf, (int)sizeof(buf));
if (strcmp(buf, want) != 0) {
g_fail++;
failures++;
printf(" %-52s got \"%s\", wanted \"%s\" FAILED\n", what, buf, want);
} else {
printf(" %-52s \"%s\"\n", what, buf);
@@ -245,6 +235,5 @@ main(void)
test_table();
test_text();
test_list();
printf("\n%s\n", g_fail ? "FAILED" : "keys: all checks passed");
return g_fail ? 1 : 0;
return test_done("keys");
}
+3 -14
View File
@@ -2,8 +2,9 @@
#include <string.h>
#include "layout.h"
#include "test.h"
static int g_fail;
#define ok test_eq
static struct nk_rect
R(float x, float y, float w, float h)
@@ -14,17 +15,6 @@ R(float x, float y, float w, float h)
return r;
}
static void
ok(const char *what, int got, int want)
{
if (got != want) {
g_fail++;
printf(" %-52s got %d, wanted %d FAILED\n", what, got, want);
} else {
printf(" %-52s ok\n", what);
}
}
static void
frame(reaktor_layout *l, float gap)
{
@@ -373,6 +363,5 @@ main(void)
test_limits(&l);
reaktor_layout_free(&l);
printf("\n%s\n", g_fail ? "FAILED" : "layout: all checks passed");
return g_fail ? 1 : 0;
return test_done("layout");
}
+4 -15
View File
@@ -3,6 +3,9 @@
#include <time.h>
#include "locale_internal.h"
#include "test.h"
#define check test_eq
#define CATALOG(code, text) \
{ code, (const unsigned char *)(text), sizeof(text) - 1 }
@@ -55,7 +58,6 @@ const struct reaktor_locale_catalog reaktor_locale_catalogs[] = {
const int reaktor_locale_catalog_count =
(int)(sizeof reaktor_locale_catalogs / sizeof reaktor_locale_catalogs[0]);
static int failures;
/* locale_runtime.c asks SDL; the test answers for it. */
static const char *g_system_code = "en";
@@ -66,14 +68,6 @@ reaktor_locale_system_code(void)
return g_system_code;
}
static void
check(const char *what, long got, long want)
{
if (got == want) return;
printf("FAIL %s: got %ld, want %ld\n", what, got, want);
failures++;
}
static void
check_str(const char *what, const char *got, const char *want)
{
@@ -342,10 +336,5 @@ main(void)
catalogs();
formats();
if (failures) {
printf("\n%d check%s failed\n", failures, failures == 1 ? "" : "s");
return 1;
}
printf("locale: all checks passed\n");
return 0;
return test_done("locale");
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef REAKTOR_TEST_H
#define REAKTOR_TEST_H
#include <stdio.h>
static int failures;
static void
test_ok(const char *what, int cond)
{
if (!cond) failures++;
printf(" %-56s %s\n", what, cond ? "ok" : "FAILED");
}
static void
test_eq(const char *what, long got, long want)
{
if (got == want) {
printf(" %-56s ok\n", what);
return;
}
failures++;
printf(" %-56s got %ld, wanted %ld FAILED\n", what, got, want);
}
static int
test_done(const char *name)
{
if (failures) {
printf("\n%d check%s failed\n", failures, failures == 1 ? "" : "s");
return 1;
}
printf("\n%s: all checks passed\n", name);
return 0;
}
#endif
+6 -15
View File
@@ -6,6 +6,9 @@
#include "nk_common.h"
#include "util.h"
#include "text.h"
#include "test.h"
#define check test_eq
#define FONT_FILE "assets/fonts/Aileron-Regular.otf"
#define JAPANESE_FILE "assets/fonts/MPLUS1p-Regular.ttf"
@@ -23,15 +26,8 @@ struct vertex {
nk_byte col[4];
};
static int failures;
struct vertex_align { char c; struct vertex v; };
static void
check(const char *what, long got, long want)
{
if (got == want) return;
printf("FAIL %s: got %ld, want %ld\n", what, got, want);
failures++;
}
static void
check_near(const char *what, float got, float want)
@@ -92,7 +88,7 @@ frame(struct nk_context *ctx, SDL_Renderer *ren, const char *text,
memset(&cfg, 0, sizeof cfg);
cfg.vertex_layout = layout;
cfg.vertex_size = sizeof(struct vertex);
cfg.vertex_alignment = NK_ALIGNOF(struct vertex);
cfg.vertex_alignment = offsetof(struct vertex_align, v);
cfg.circle_segment_count = cfg.curve_segment_count = cfg.arc_segment_count = 22;
cfg.global_alpha = 1.0f;
nk_buffer_init_default(&cmds);
@@ -206,10 +202,5 @@ main(void)
directions();
drawing();
if (failures) {
printf("\n%d check%s failed\n", failures, failures == 1 ? "" : "s");
return 1;
}
printf("text: all checks passed\n");
return 0;
return test_done("text");
}
+1 -1
View File
@@ -10,7 +10,7 @@ copy() {
}
for f in assets/fonts/MPLUS1p-Regular.ttf assets/fonts/MPLUS1p-Notice.txt \
assets/fonts/Aileron-Notice.txt external/bamboocss/dist/bamboo.min.css; do
assets/fonts/Aileron-Notice.txt external/simplecss/simple.css; do
copy "$f"
done
for f in "$root"/assets/locale/*.txt; do
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
# Installs libreaktor from a build into dist/NAME, links examples/consumer
# against it, checks that program draws what the built simple does, and
# leaves dist/NAME.tar.gz.
# check-libreaktor.sh [-i] [-w WRAP] BUILD NAME
# -i: dist/NAME is installed already (a cross build ships it).
set -eu
wrap=""
installed=0
while getopts iw: opt; do
case $opt in
i) installed=1 ;;
w) wrap=$OPTARG ;;
*) echo "usage: check-libreaktor.sh [-i] [-w WRAP] BUILD NAME" >&2; exit 2 ;;
esac
done
shift $((OPTIND - 1))
build=$1
name=$2
if [ "$installed" = 0 ]; then
cmake --build "$build" --target libreaktor </dev/null
cmake --install "$build" --prefix "dist/$name" --component libreaktor </dev/null
fi
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
cmake --build build-consumer </dev/null
mkdir -p check
for from in "lib-built $build/simple" "lib-linked build-consumer/simple"; do
set -- $from
$wrap "$2" --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/lib-built.$e" "check/lib-linked.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
rm -rf "dist/$name" build-consumer
+29
View File
@@ -0,0 +1,29 @@
#!/bin/sh
# Packs a build with tools/package.sh, checks the packed showcase draws what
# the built one does, and leaves dist/NAME.tar.gz.
# check-package.sh [-w WRAP] BUILD NAME
set -eu
wrap=""
while getopts w: opt; do
case $opt in
w) wrap=$OPTARG ;;
*) echo "usage: check-package.sh [-w WRAP] BUILD NAME" >&2; exit 2 ;;
esac
done
shift $((OPTIND - 1))
build=$1
name=$2
sh tools/package.sh "$build" "dist/$name"
mkdir -p check
for from in "built $build" "packed dist/$name"; do
set -- $from
$wrap "$2/showcase" --tab 8 --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/built.$e" "check/packed.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
rm -rf "dist/$name"
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
# .single_instance end to end: a second showcase hands its file to the first
# and exits 0, and the first logs the file it was given.
# instance.sh [-w WRAP] BUILD
set -u
wrap=""
while getopts w: opt; do
case $opt in
w) wrap=$OPTARG ;;
*) echo "usage: instance.sh [-w WRAP] BUILD" >&2; exit 2 ;;
esac
done
shift $((OPTIND - 1))
build=$1
mkdir -p smoke
rm -f smoke/instance.log
$wrap "$build/showcase" --video dummy --log smoke/instance.log </dev/null >/dev/null 2>&1 &
first=$!
n=0
while [ ! -s smoke/instance.log ] && [ "$n" -lt 60 ]; do n=$((n + 1)); sleep 1; done
sleep 2
fail=0
$wrap "$build/showcase" --video dummy handed-over.txt </dev/null >smoke/instance-second.log 2>&1
rc=$?
if [ "$rc" -ne 0 ]; then echo "second launch: exit status $rc"; fail=1; fi
sleep 2
if grep -q "handed-over.txt" smoke/instance.log; then
echo "second launch handed its file over: ok"
else
echo "the running copy did not get the file"
fail=1
fi
if ! kill -0 "$first" 2>/dev/null; then echo "the running copy is gone"; fail=1; fi
kill "$first" 2>/dev/null || :
wait "$first" 2>/dev/null || :
[ "$fail" = 0 ] || { cat smoke/instance.log smoke/instance-second.log 2>/dev/null || :; }
exit "$fail"
+63
View File
@@ -0,0 +1,63 @@
#!/bin/sh
# The standard shots and dumps of a build, into smoke/: simple and the
# showcase through the system's video driver, and simple through SDL's dummy.
# shots.sh [-x XVFB] [-w WRAP] BUILD DRIVER
# -x starts that Xvfb on :99 first; -w runs each program under WRAP
# (for example "dbus-run-session -- timeout 600").
set -u
xvfb=""
wrap=""
while getopts x:w: opt; do
case $opt in
x) xvfb=$OPTARG ;;
w) wrap=$OPTARG ;;
*) echo "usage: shots.sh [-x XVFB] [-w WRAP] BUILD DRIVER" >&2; exit 2 ;;
esac
done
shift $((OPTIND - 1))
build=$1
driver=$2
rm -rf smoke
mkdir smoke
if [ -n "$xvfb" ]; then
"$xvfb" :99 -screen 0 1280x1024x24 -nolisten tcp </dev/null >smoke/xvfb.log 2>&1 &
xvfb_pid=$!
trap 'kill "$xvfb_pid" 2>/dev/null || :' EXIT
n=0
while [ ! -S /tmp/.X11-unix/X99 ]; do
n=$((n + 1))
if [ "$n" -gt 120 ] || ! kill -0 "$xvfb_pid" 2>/dev/null; then
echo "Xvfb did not start"
cat smoke/xvfb.log || :
exit 1
fi
sleep 1
done
DISPLAY=:99
export DISPLAY
fi
fail=0
shot() {
name=$1
drv=$2
shift 2
if $wrap "$@" --video "$drv" --shot "smoke/$name.bmp" --a11y-dump "smoke/$name.txt" \
</dev/null >"smoke/$name.log" 2>&1; then
if [ -s "smoke/$name.bmp" ] && [ -s "smoke/$name.txt" ]; then
echo "$name: ok"
return 0
fi
echo "$name: exited 0 without both a shot and a dump"
else
echo "$name: exit status $?"
fi
cat "smoke/$name.log" || :
fail=1
}
shot simple "$driver" "$build/simple" --theme light
shot showcase "$driver" "$build/showcase" --tab 7 --theme dark
shot simple-dummy dummy "$build/simple" --theme light
exit "$fail"
+29
View File
@@ -0,0 +1,29 @@
# Cross-compiling for FreeBSD on arm64 from a FreeBSD x86-64 host:
# cmake -DCMAKE_TOOLCHAIN_FILE=tools/cross/freebsd-aarch64.cmake -DREAKTOR_SYSROOT=<dir>
# The sysroot is the arm64 base set plus the packages tools/cross/sysroot.sh gathers.
set(CMAKE_SYSTEM_NAME FreeBSD)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES REAKTOR_SYSROOT)
set(CMAKE_SYSROOT "${REAKTOR_SYSROOT}")
set(CMAKE_C_COMPILER cc)
set(CMAKE_CXX_COMPILER c++)
string(REGEX MATCH "([0-9]+\\.[0-9]+)" _rel "$ENV{REAKTOR_TARGET_RELEASE}")
if(NOT _rel)
set(_rel 15.1)
endif()
set(CMAKE_C_COMPILER_TARGET aarch64-unknown-freebsd${_rel})
set(CMAKE_CXX_COMPILER_TARGET aarch64-unknown-freebsd${_rel})
# An archive of arm64 objects needs an archiver that reads them.
find_program(_llvm_ar NAMES llvm-ar llvm-ar19 llvm-ar18)
if(_llvm_ar)
set(CMAKE_AR "${_llvm_ar}")
endif()
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# pkgconf applies the sysroot only to .pc files found inside it.
set(ENV{PKG_CONFIG_SYSROOT_DIR} "${REAKTOR_SYSROOT}")
set(ENV{PKG_CONFIG_LIBDIR} "${REAKTOR_SYSROOT}/usr/local/libdata/pkgconfig:${REAKTOR_SYSROOT}/usr/libdata/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "")
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH OFF)
+14
View File
@@ -0,0 +1,14 @@
# Cross-compiling for another Debian architecture on an x86-64 Debian host,
# with the crossbuild-essential compilers and the target's multiarch libraries:
# cmake -DCMAKE_TOOLCHAIN_FILE=tools/cross/linux-cross.cmake -DREAKTOR_CROSS_TRIPLE=<triple>
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES REAKTOR_CROSS_TRIPLE)
string(REGEX MATCH "^[^-]+" CMAKE_SYSTEM_PROCESSOR "${REAKTOR_CROSS_TRIPLE}")
set(CMAKE_C_COMPILER ${REAKTOR_CROSS_TRIPLE}-gcc)
set(CMAKE_CXX_COMPILER ${REAKTOR_CROSS_TRIPLE}-g++)
set(CMAKE_LIBRARY_ARCHITECTURE ${REAKTOR_CROSS_TRIPLE})
# The cross C library (libm among it) sits in /usr/<triple>, beside the multiarch ones.
set(CMAKE_FIND_ROOT_PATH /usr/${REAKTOR_CROSS_TRIPLE})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/${REAKTOR_CROSS_TRIPLE}/pkgconfig:/usr/share/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "")
+37
View File
@@ -0,0 +1,37 @@
# Cross-compiling for NetBSD on arm64 from a NetBSD x86-64 host with pkgsrc clang and lld:
# cmake -DCMAKE_TOOLCHAIN_FILE=tools/cross/netbsd-aarch64.cmake -DREAKTOR_SYSROOT=<dir>
# The sysroot is the evbarm-aarch64 sets plus the packages tools/cross/sysroot.sh gathers.
set(CMAKE_SYSTEM_NAME NetBSD)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES REAKTOR_SYSROOT)
set(CMAKE_SYSROOT "${REAKTOR_SYSROOT}")
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_C_COMPILER_TARGET aarch64--netbsd)
set(CMAKE_CXX_COMPILER_TARGET aarch64--netbsd)
find_program(_llvm_ar NAMES llvm-ar)
find_program(_llvm_ranlib NAMES llvm-ranlib)
if(_llvm_ar)
set(CMAKE_AR "${_llvm_ar}")
endif()
if(_llvm_ranlib)
set(CMAKE_RANLIB "${_llvm_ranlib}")
endif()
# X11 lives under /usr/X11R7 and packages under /usr/pkg, and NetBSD links both
# directly, so the program carries their run paths.
# Searched last, as pkg-config's directories are natively: SDL's own protocol
# headers must win over the packages' older ones.
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "${REAKTOR_SYSROOT}/usr/X11R7/include" "${REAKTOR_SYSROOT}/usr/pkg/include")
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_STANDARD_INCLUDE_DIRECTORIES})
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld -L${REAKTOR_SYSROOT}/usr/X11R7/lib -L${REAKTOR_SYSROOT}/usr/pkg/lib -Wl,-rpath,/usr/X11R7/lib -Wl,-rpath,/usr/pkg/lib")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT}")
set(CMAKE_FIND_ROOT_PATH "${REAKTOR_SYSROOT}" "${REAKTOR_SYSROOT}/usr/pkg" "${REAKTOR_SYSROOT}/usr/X11R7")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(ENV{PKG_CONFIG} pkgconf)
set(ENV{PKG_CONFIG_SYSROOT_DIR} "${REAKTOR_SYSROOT}")
set(ENV{PKG_CONFIG_LIBDIR} "${REAKTOR_SYSROOT}/usr/pkg/lib/pkgconfig:${REAKTOR_SYSROOT}/usr/pkg/share/pkgconfig:${REAKTOR_SYSROOT}/usr/X11R7/lib/pkgconfig:${REAKTOR_SYSROOT}/usr/X11R7/share/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "")
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH OFF)
+29
View File
@@ -0,0 +1,29 @@
# Cross-compiling for OpenBSD on arm64 from an OpenBSD x86-64 host with the
# ports LLVM (base clang has no arm64 backend):
# cmake -DCMAKE_TOOLCHAIN_FILE=tools/cross/openbsd-aarch64.cmake -DREAKTOR_SYSROOT=<dir>
# The sysroot is the arm64 sets plus the packages tools/cross/sysroot.sh gathers.
set(CMAKE_SYSTEM_NAME OpenBSD)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES REAKTOR_SYSROOT)
set(CMAKE_SYSROOT "${REAKTOR_SYSROOT}")
set(CMAKE_C_COMPILER /usr/local/bin/clang-21)
set(CMAKE_CXX_COMPILER /usr/local/bin/clang++-21)
string(REGEX MATCH "([0-9]+\\.[0-9]+)" _rel "$ENV{REAKTOR_TARGET_RELEASE}")
if(NOT _rel)
set(_rel 7.9)
endif()
set(CMAKE_C_COMPILER_TARGET aarch64-unknown-openbsd${_rel})
set(CMAKE_CXX_COMPILER_TARGET aarch64-unknown-openbsd${_rel})
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld")
set(CMAKE_AR /usr/local/llvm21/bin/llvm-ar)
set(CMAKE_RANLIB /usr/local/llvm21/bin/llvm-ranlib)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# pkgconf applies the sysroot only to .pc files found inside it.
set(ENV{PKG_CONFIG_SYSROOT_DIR} "${REAKTOR_SYSROOT}")
set(ENV{PKG_CONFIG_LIBDIR} "${REAKTOR_SYSROOT}/usr/local/lib/pkgconfig:${REAKTOR_SYSROOT}/usr/X11R6/lib/pkgconfig:${REAKTOR_SYSROOT}/usr/lib/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "")
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH OFF)
+150
View File
@@ -0,0 +1,150 @@
#!/bin/sh
# Gathers an arm64 sysroot on a FreeBSD, OpenBSD or NetBSD x86-64 host: the release's
# sets for headers, libraries and start files, and the packages SDL and the
# modules link, unpacked where the toolchain files expect them.
# sysroot.sh <freebsd|openbsd|netbsd> <version> <dir>
set -eu
os=$1
version=$2
dir=$3
tmp=${TMPDIR:-/tmp}/sysroot-fetch
mkdir -p "$dir" "$tmp"
case "$os" in
freebsd)
url="https://download.freebsd.org/releases/arm64/aarch64/$version-RELEASE"
fetch -q -o "$tmp/base.txz" "$url/base.txz"
fetch -q -o "$tmp/MANIFEST" "$url/MANIFEST"
want=$(awk '$1 == "base.txz" { print $2 }' "$tmp/MANIFEST")
[ "$(sha256 -q "$tmp/base.txz")" = "$want" ] || { echo "base.txz: checksum mismatch" >&2; exit 1; }
# Not as root: tar would restore the sets' schg flags and the tree could not be removed.
tar -xf "$tmp/base.txz" -C "$dir" ./lib ./usr/lib ./usr/include ./usr/libdata/pkgconfig ./bin/sh
major=${version%%.*}
minor=${version#*.}
pkgs="libX11 libXext libXcursor libXi libXfixes libXrandr libXrender libXtst
libxkbcommon wayland libglvnd dbus xorgproto"
rm -rf "$tmp/pkgs"
# pkg's ABI override reads the arm64 catalog; the ELF note of the sysroot's sh is the fallback.
sudo pkg -o ABI="FreeBSD:$major:aarch64" -o OSVERSION="$((major * 100000 + minor * 1000))" \
-o IGNORE_OSVERSION=yes -o PKG_DBDIR=/var/db/pkg-aarch64 -o PKG_CACHEDIR=/var/cache/pkg-aarch64 \
fetch -y -d -o "$tmp/pkgs" $pkgs </dev/null ||
sudo pkg -o ABI_FILE="$dir/bin/sh" -o IGNORE_OSVERSION=yes \
-o PKG_DBDIR=/var/db/pkg-aarch64 -o PKG_CACHEDIR=/var/cache/pkg-aarch64 \
fetch -y -d -o "$tmp/pkgs" $pkgs </dev/null
find "$tmp/pkgs" -name '*.pkg' | while IFS= read -r p; do
tar -xf "$p" -C "$dir" --exclude '+*'
done
[ "$(find "$tmp/pkgs" -name '*.pkg' | wc -l)" -gt 0 ] || { echo "no packages were fetched" >&2; exit 1; }
;;
netbsd)
url="https://cdn.NetBSD.org/pub/NetBSD/NetBSD-$version/evbarm-aarch64/binary/sets"
ftp -V -o "$tmp/SHA512" "$url/SHA512"
for set in base comp xbase xcomp; do
ftp -V -o "$tmp/$set.tar.xz" "$url/$set.tar.xz"
want=$(awk -v f="$set.tar.xz" '$2 == "(" f ")" { print $4 }' "$tmp/SHA512")
got=$(cksum -a SHA512 "$tmp/$set.tar.xz" | awk '{ print $4 }')
[ "$got" = "$want" ] || { echo "$set.tar.xz: checksum mismatch" >&2; exit 1; }
tar -xJf "$tmp/$set.tar.xz" -C "$dir"
done
# The host's package repository, read for the same quarterly, with the architecture swapped.
repo=""
if [ -f /usr/pkg/etc/pkgin/repositories.conf ]; then
repo=$(grep -v '^#' /usr/pkg/etc/pkgin/repositories.conf | grep . | head -1 |
sed -e 's#^ftp://ftp\.NetBSD\.org#https://cdn.NetBSD.org#' -e 's#/NetBSD/[^/]*/#/NetBSD/aarch64/#')
fi
[ -n "$repo" ] || repo="https://cdn.NetBSD.org/pub/pkgsrc/packages/NetBSD/aarch64/$version/All"
repo=${repo%/}
case "$repo" in *aarch64*) ;; *) echo "sysroot: $repo is not an aarch64 repository" >&2; exit 1 ;; esac
echo "sysroot: packages from $repo"
rm -rf "$tmp/pkgs"
mkdir -p "$tmp/pkgs"
ftp -V -o "$tmp/pkgs/pkg_summary.gz" "$repo/pkg_summary.gz"
# The closure of what SDL and the modules link, resolved from the summary
# so no directory listing is read.
gunzip -c "$tmp/pkgs/pkg_summary.gz" | awk '
/^PKGNAME=/ { name = substr($0, 9); sub(/-[^-]*$/, "", name) }
/^FILE_NAME=/ { file[name] = substr($0, 11) }
/^DEPENDS=/ { d = substr($0, 9); sub(/[<>=\[{].*$/, "", d); sub(/-[0-9][^-]*$/, "", d); sub(/-$/, "", d); deps[name] = deps[name] " " d }
END {
n = split("dbus libxkbcommon wayland wayland-protocols", want, " ")
for (i = 1; i <= n; i++) queue[++q] = want[i]
for (i = 1; i <= q; i++) {
p = queue[i]
if (p in seen || !(p in file)) continue
seen[p] = 1
print file[p]
m = split(deps[p], ds, " ")
for (j = 1; j <= m; j++) if (ds[j] != "") queue[++q] = ds[j]
}
}' > "$tmp/pkgs/list"
while IFS= read -r f; do
ftp -V -o "$tmp/pkgs/$f" "$repo/$f"
done < "$tmp/pkgs/list"
mkdir -p "$dir/var/db/pkg"
while IFS= read -r f; do
PKG_PATH="$tmp/pkgs" pkg_add -m aarch64 -I -P "$dir" -K "$dir/var/db/pkg" "$tmp/pkgs/$f"
done < "$tmp/pkgs/list"
;;
openbsd)
v=$(echo "$version" | tr -d .)
url="https://cdn.openbsd.org/pub/OpenBSD/$version/arm64"
cd "$tmp"
for f in SHA256.sig base$v.tgz comp$v.tgz xbase$v.tgz xshare$v.tgz; do
curl -fsSLo "$f" "$url/$f"
done
signify -C -p "/etc/signify/openbsd-$v-base.pub" -x SHA256.sig \
base$v.tgz comp$v.tgz xbase$v.tgz xshare$v.tgz
tar -xzf base$v.tgz -C "$dir" ./usr/lib ./usr/libexec/ld.so
tar -xzf comp$v.tgz -C "$dir" ./usr/include ./usr/lib
tar -xzf xbase$v.tgz -C "$dir" ./usr/X11R6/lib ./usr/X11R6/include
tar -xzf xshare$v.tgz -C "$dir" ./usr/X11R6/include ./usr/X11R6/lib
# pkg_add will not install another architecture's packages, so they are
# unpacked by hand, their dependencies read from each +CONTENTS.
purl="https://cdn.openbsd.org/pub/OpenBSD/$version/packages/aarch64"
rm -rf "$tmp/pkgs"
mkdir -p "$tmp/pkgs" "$dir/usr/local"
cd "$tmp/pkgs"
curl -fsSLo SHA256.sig "$purl/SHA256.sig"
queue=""
for stem in dbus libxkbcommon wayland wayland-protocols; do
name=$(sed -n "s/^SHA256 (\($stem-[0-9][^)]*\)\.tgz).*/\1/p" SHA256.sig | head -1)
[ -n "$name" ] || { echo "sysroot: no $stem package for aarch64" >&2; exit 1; }
queue="$queue $name"
done
seen=" "
while [ -n "$(echo $queue)" ]; do
set -- $queue
p=$1
shift
queue="$*"
case "$seen" in *" $p "*) continue ;; esac
seen="$seen$p "
curl -fsSLo "$p.tgz" "$purl/$p.tgz"
signify -C -p "/etc/signify/openbsd-$v-pkg.pub" -x SHA256.sig "$p.tgz"
rm -rf meta
mkdir meta
tar -xzf "$p.tgz" -C meta +CONTENTS
for d in $(sed -n 's/^@depend [^:]*:[^:]*:\(.*\)$/\1/p' meta/+CONTENTS); do
queue="$queue $d"
done
tar -xzf "$p.tgz" -C "$dir/usr/local"
echo "sysroot: $p"
done
rm -f "$dir"/usr/local/+*
cd /
;;
*)
echo "sysroot.sh: unknown system $os" >&2
exit 2
;;
esac
# A library link to an absolute path would reach the host's own libraries.
escaped=$(find "$dir" -type l -lname '/*' -name 'lib*.so*' 2>/dev/null || true)
if [ -n "$escaped" ]; then
echo "sysroot: links reach outside it:" >&2
echo "$escaped" >&2
exit 1
fi
echo "sysroot: $dir ($(du -sh "$dir" | cut -f1))"
+6 -3
View File
@@ -5,13 +5,14 @@ set -eu
usage() {
cat <<'EOF'
usage: libreaktor-pkg.sh [-i] [-b BUILD] [-p PREFIX] [-o DIR] [-f FORMAT] [-m MAINTAINER]
usage: libreaktor-pkg.sh [-i] [-b BUILD] [-p PREFIX] [-o DIR] [-f FORMAT] [-m MAINTAINER] [-a ARCH]
-i install the package once it is built (through sudo or doas)
-b pack from this configured build instead of building one
-p where the files go (/opt/reaktor on Linux, /usr/local/reaktor on the BSDs)
-o where the package is written (dist)
-f deb, rpm, freebsd, openbsd, netbsd or tar (picked from the system)
-m the maintainer the package names
-a the .deb's architecture, for a cross build (dpkg's own otherwise)
EOF
}
@@ -23,8 +24,9 @@ out="$root/dist"
format=""
maintainer="Reaktor <reaktor@invalid>"
build=""
debarch=""
while getopts ib:p:o:f:m:h opt; do
while getopts ib:p:o:f:m:a:h opt; do
case $opt in
i) install=1 ;;
b) build=$OPTARG ;;
@@ -32,6 +34,7 @@ while getopts ib:p:o:f:m:h opt; do
o) out=$OPTARG ;;
f) format=$OPTARG ;;
m) maintainer=$OPTARG ;;
a) debarch=$OPTARG ;;
h) usage; exit 0 ;;
*) usage >&2; exit 2 ;;
esac
@@ -93,7 +96,7 @@ as_root() {
case $format in
deb)
arch=$(dpkg --print-architecture)
arch=${debarch:-$(dpkg --print-architecture)}
pkg="$out/libreaktor-dev_${version}_$arch.deb"
mkdir -p "$stage/DEBIAN"
cat >"$stage/DEBIAN/control" <<EOF
+1 -1
View File
@@ -19,6 +19,6 @@ fi
: >"$dest/.reaktor-root"
sh "$root/tools/assets.sh" "$root" "$dest"
cp "$build/licenses/"*.txt "$dest/licenses/"
cp "$root/external/bamboocss/LICENSE" "$dest/licenses/bamboocss.txt"
cp "$root/external/simplecss/LICENSE" "$dest/licenses/simplecss.txt"
cp "$root/docs/NOTICE.md" "$dest/"
echo "packaged: $dest"