Compare commits
@@ -54,13 +54,13 @@ jobs:
|
||||
.ccache
|
||||
build
|
||||
build-arm64
|
||||
key: build-v2-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
restore-keys: build-v2-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-
|
||||
key: build-v3-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
restore-keys: build-v3-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-
|
||||
|
||||
- name: Build a release from scratch, keeping only ccache
|
||||
if: ${{ inputs.version != '' }}
|
||||
shell: bash
|
||||
run: rm -rf build build-arm64
|
||||
run: rm -rf build build-arm64 build-arm64-shared
|
||||
|
||||
# ninja rebuilds by mtime, and a checkout dates every file now. Date them
|
||||
# before the cached objects instead, and only what changed since the
|
||||
@@ -192,10 +192,23 @@ jobs:
|
||||
if grep -rq "$sysroot" "dist/$name/lib/cmake" "dist/$name/lib/pkgconfig"; then
|
||||
echo "the package carries the sysroot's path"; exit 1
|
||||
fi
|
||||
# The shared libreaktor too; the arm64 machine checks it below.
|
||||
cmake -S . -B build-arm64-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE="$PWD/tools/cross/${{ matrix.os }}-aarch64.cmake" \
|
||||
-DREAKTOR_SYSROOT="$sysroot" -DREAKTOR_SHARED=ON \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
|
||||
cmake --build build-arm64-shared --parallel 4 --target libreaktor </dev/null
|
||||
shared="libreaktor-shared-${version}-${{ matrix.os }}-arm64"
|
||||
cmake --install build-arm64-shared --prefix "dist/$shared" --component libreaktor --strip </dev/null
|
||||
file "dist/$shared"/lib/libreaktor.so.0.* | grep -qi aarch64
|
||||
if grep -rq "$sysroot" "dist/$shared/lib/cmake" "dist/$shared/lib/pkgconfig"; then
|
||||
echo "the shared package carries the sysroot's path"; exit 1
|
||||
fi
|
||||
tar -cf cross-${{ matrix.os }}-arm64.tar \
|
||||
$(sed 's|^|build-arm64/|' tools/ci/tests.txt) \
|
||||
build-arm64/showcase build-arm64/notepad build-arm64/simple build-arm64/bench \
|
||||
build-arm64/licenses build-arm64/CMakeCache.txt "dist/$name"
|
||||
build-arm64/licenses build-arm64/CMakeCache.txt "dist/$name" "dist/$shared"
|
||||
|
||||
# Back to the runner now, so the next run finds this build in the cache
|
||||
# while this one is still testing.
|
||||
@@ -209,7 +222,7 @@ jobs:
|
||||
- name: Drop an unfinished cross build
|
||||
if: ${{ always() && steps.cross.outcome == 'failure' }}
|
||||
shell: bash
|
||||
run: rm -rf build-arm64
|
||||
run: rm -rf build-arm64 build-arm64-shared
|
||||
|
||||
- name: Note which commit the cached build is from
|
||||
if: ${{ always() && steps.build.outcome == 'success' }}
|
||||
@@ -224,7 +237,7 @@ jobs:
|
||||
.ccache
|
||||
build
|
||||
build-arm64
|
||||
key: build-v2-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
key: build-v3-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
|
||||
- name: Save the package cache
|
||||
if: ${{ always() && steps.vm.outcome == 'success' }}
|
||||
@@ -316,6 +329,34 @@ jobs:
|
||||
--shot check/lib-packaged.bmp --a11y-dump check/lib-packaged.txt </dev/null
|
||||
for e in bmp txt; do cmp "check/lib-built.$e" "check/lib-packaged.$e"; done
|
||||
|
||||
# The split packages. The app must run on the two runtime packages
|
||||
# alone once the development one is gone.
|
||||
- name: Pack and check the shared libreaktor packages
|
||||
id: shared
|
||||
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
|
||||
run: |
|
||||
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
|
||||
export PATH
|
||||
case ${{ matrix.os }} in
|
||||
freebsd) remove() { sudo pkg delete -y "$@"; } ;;
|
||||
*) remove() { sudo pkg_delete "$@"; } ;;
|
||||
esac
|
||||
remove libreaktor </dev/null
|
||||
rm -rf build-pkg
|
||||
sh tools/libreaktor-pkg.sh -s -i -o dist-pkg-shared </dev/null
|
||||
cmake -S examples/consumer -B build-pkg-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/usr/local/reaktor -DCONSUMER_SHARED=ON </dev/null
|
||||
cmake --build build-pkg-shared </dev/null
|
||||
remove libreaktor-shared </dev/null
|
||||
dbus-run-session -- build-pkg-shared/simple --theme light --video dummy \
|
||||
--shot check/lib-packaged-shared.bmp --a11y-dump check/lib-packaged-shared.txt </dev/null
|
||||
for e in bmp txt; do cmp "check/lib-built.$e" "check/lib-packaged-shared.$e"; done
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
name="libreaktor-shared-${version}-${{ matrix.os }}-${{ matrix.arch }}"
|
||||
cmake --install build-pkg/build --prefix "dist/$name" --component libreaktor --strip </dev/null
|
||||
tar -C dist -czf "dist/$name.tar.gz" "$name"
|
||||
rm -rf "dist/$name"
|
||||
|
||||
- name: Collect the shots
|
||||
if: ${{ always() && steps.vm.outcome == 'success' }}
|
||||
shell: cpa.sh {0} --sync-files vm-to-runner
|
||||
@@ -339,7 +380,19 @@ jobs:
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-${{ matrix.os }}-${{ matrix.arch }}
|
||||
path: dist/libreaktor-*.tar.gz
|
||||
path: |
|
||||
dist/libreaktor-*.tar.gz
|
||||
!dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
- name: Upload the shared libreaktor
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-${{ matrix.os }}-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
@@ -497,6 +550,15 @@ jobs:
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
sh tools/ci/check-libreaktor.sh -i -w "dbus-run-session --" build-arm64 "libreaktor-${version}-${{ matrix.os }}-arm64"
|
||||
|
||||
- name: Check the shared libreaktor
|
||||
id: shared
|
||||
if: ${{ !cancelled() && steps.libcheck.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-shared-${version}-${{ matrix.os }}-arm64"
|
||||
|
||||
- name: Collect the shots
|
||||
if: ${{ always() && steps.vm.outcome == 'success' }}
|
||||
shell: cpa.sh {0} --sync-files vm-to-runner
|
||||
@@ -518,7 +580,19 @@ jobs:
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-${{ matrix.os }}-arm64
|
||||
path: dist/libreaktor-*.tar.gz
|
||||
path: |
|
||||
dist/libreaktor-*.tar.gz
|
||||
!dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
- name: Upload the shared libreaktor
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-${{ matrix.os }}-arm64
|
||||
path: |
|
||||
dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
|
||||
+128
-5
@@ -64,7 +64,7 @@ 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 ccache </dev/null
|
||||
dbus xvfb xauth ccache gdb </dev/null
|
||||
EOF
|
||||
|
||||
# ccache only: the build folder is rebuilt, so a stale cache cannot hide a broken one.
|
||||
@@ -151,6 +151,77 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
run: docker exec -i debian sh tools/ci/uitest.sh -w "dbus-run-session -- timeout 120" build </dev/null
|
||||
|
||||
- name: What a shared libreaktor would save
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
continue-on-error: true
|
||||
run: docker exec -i debian sh tools/ci/pss.sh -x Xvfb -w "dbus-run-session -- timeout 120" build </dev/null
|
||||
|
||||
- name: What a shared libreaktor would save, page by page
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
continue-on-error: true
|
||||
run: docker exec -i debian sh tools/ci/pss-pages.sh -x Xvfb -w "dbus-run-session -- timeout 120" </dev/null
|
||||
|
||||
# libreaktor.so beside the static library, on every architecture, and
|
||||
# released as libreaktor-shared-VERSION-linux-ARCH.tar.gz; the static one is
|
||||
# libreaktor-VERSION-linux-ARCH.tar.gz. An emulated
|
||||
# machine has none of the cross compiler's headers, so it is built and
|
||||
# installed on the builder and only checked on the emulated machine.
|
||||
- name: Shared libreaktor
|
||||
id: shared
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
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' }}'
|
||||
name="libreaktor-shared-${version}-linux-${{ matrix.arch }}"
|
||||
docker exec -i -e CROSS="$cross" -e LIBNAME="$name" "$ctr" sh -eu <<'EOF'
|
||||
export CCACHE_DIR=/src/.ccache CCACHE_BASEDIR=/src CCACHE_MAXSIZE=500M
|
||||
cmake -S . -B build-shared -G Ninja -DCMAKE_BUILD_TYPE=Release -DREAKTOR_SHARED=ON \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON $CROSS </dev/null
|
||||
cmake --build build-shared --target all libreaktor </dev/null
|
||||
if [ -n "$CROSS" ]; then
|
||||
cmake --install build-shared --prefix "dist/$LIBNAME" --component libreaktor --strip </dev/null
|
||||
else
|
||||
sh tools/ci/check-exports.sh build-shared </dev/null
|
||||
fi
|
||||
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-shared "$name" </dev/null
|
||||
|
||||
- name: Upload the shared libreaktor
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-linux-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
# Every native job, so each architecture's table comes from a machine
|
||||
# like CI's. One not written yet is a warning, and the upload has it.
|
||||
- name: ABI table
|
||||
id: abi
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && !matrix.emulated }}
|
||||
run: |
|
||||
rc=0
|
||||
docker exec -i debian sh tools/ci/check-abi.sh </dev/null || rc=$?
|
||||
if [ "$rc" = 3 ]; then echo "::warning::no ABI table for linux ${{ matrix.arch }} yet; see the abi artifact"; rc=0; fi
|
||||
exit "$rc"
|
||||
|
||||
- name: Upload the ABI table
|
||||
if: ${{ !cancelled() && hashFiles('smoke/abi/*.abi') != '' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: abi-linux-${{ matrix.arch }}
|
||||
path: smoke/abi/
|
||||
|
||||
- name: Package
|
||||
id: package
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
@@ -200,7 +271,7 @@ jobs:
|
||||
run: |
|
||||
docker exec -i debian sh -eu <<'EOF'
|
||||
dpkg -i dist-pkg/*.deb </dev/null
|
||||
dpkg -s libreaktor-dev | grep -q '^Status: install ok installed'
|
||||
dpkg -s libreaktor | grep -q '^Status: install ok installed'
|
||||
cmake -S examples/consumer -B build-pkg-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/opt/reaktor </dev/null
|
||||
cmake --build build-pkg-consumer </dev/null
|
||||
@@ -209,6 +280,45 @@ jobs:
|
||||
for e in bmp txt; do cmp "check/lib-built.$e" "check/lib-packaged.$e"; done
|
||||
EOF
|
||||
|
||||
# The shared build splits in three: libreaktor-sdl3-0, libreaktor0 and
|
||||
# libreaktor-shared, on every architecture.
|
||||
- name: Pack the shared libreaktor as .debs
|
||||
id: shareddeb
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
run: |
|
||||
if [ "${{ matrix.emulated }}" = true ]; then
|
||||
docker exec -i builder sh -eu tools/libreaktor-pkg.sh -f deb -b build-shared -o dist-pkg-shared -a ${{ matrix.debarch }} </dev/null
|
||||
else
|
||||
docker exec -i debian sh -eu tools/libreaktor-pkg.sh -f deb -b build-shared -o dist-pkg-shared </dev/null
|
||||
fi
|
||||
|
||||
- name: Upload the shared .debs
|
||||
if: ${{ !cancelled() && steps.shareddeb.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-deb-shared-linux-${{ matrix.arch }}
|
||||
path: dist-pkg-shared/*.deb
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
# An app linked against them must still run, and draw the same, with only
|
||||
# the two runtime packages left.
|
||||
- name: Check the shared libreaktor .debs
|
||||
if: ${{ !cancelled() && steps.shareddeb.outcome == 'success' && steps.libcheck.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
run: |
|
||||
docker exec -i debian sh -eu <<'EOF'
|
||||
dpkg -r libreaktor </dev/null
|
||||
dpkg -i dist-pkg-shared/*.deb </dev/null
|
||||
cmake -S examples/consumer -B build-pkg-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/opt/reaktor -DCONSUMER_SHARED=ON </dev/null
|
||||
cmake --build build-pkg-shared </dev/null
|
||||
dpkg -r libreaktor-shared </dev/null
|
||||
dpkg -s libreaktor0 libreaktor-sdl3-0 | grep -c '^Status: install ok installed' | grep -q 2
|
||||
timeout 600 build-pkg-shared/simple --theme light --video dummy \
|
||||
--shot check/lib-packaged-shared.bmp --a11y-dump check/lib-packaged-shared.txt </dev/null
|
||||
for e in bmp txt; do cmp "check/lib-built.$e" "check/lib-packaged-shared.$e"; done
|
||||
EOF
|
||||
|
||||
- name: Check an app that embeds Reaktor
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
run: |
|
||||
@@ -231,7 +341,9 @@ jobs:
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-linux-${{ matrix.arch }}
|
||||
path: dist/libreaktor-*.tar.gz
|
||||
path: |
|
||||
dist/libreaktor-*.tar.gz
|
||||
!dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
@@ -292,16 +404,27 @@ jobs:
|
||||
libXrandr-devel libXrender-devel libXtst-devel libxkbcommon-devel \
|
||||
wayland-devel wayland-protocols-devel libglvnd-devel dbus-devel </dev/null
|
||||
sh tools/libreaktor-pkg.sh -i -o dist-pkg </dev/null
|
||||
rpm -q libreaktor-devel
|
||||
rpm -q libreaktor
|
||||
cmake -S examples/consumer -B build-pkg-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/opt/reaktor </dev/null
|
||||
cmake --build build-pkg-consumer </dev/null
|
||||
rpm -e libreaktor
|
||||
rm -rf build-pkg
|
||||
sh tools/libreaktor-pkg.sh -s -i -o dist-pkg-shared </dev/null
|
||||
rpm -q libreaktor0 libreaktor-sdl3-0 libreaktor-shared
|
||||
cmake -S examples/consumer -B build-pkg-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/opt/reaktor -DCONSUMER_SHARED=ON </dev/null
|
||||
cmake --build build-pkg-shared </dev/null
|
||||
rpm -e libreaktor-shared
|
||||
build-pkg-shared/simple --theme light --video dummy --shot check-shared.bmp </dev/null
|
||||
EOF
|
||||
|
||||
- name: Upload the .rpm
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-rpm-linux-${{ matrix.arch }}
|
||||
path: dist-pkg/*.rpm
|
||||
path: |
|
||||
dist-pkg/*.rpm
|
||||
dist-pkg-shared/*.rpm
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
+102
-1
@@ -154,6 +154,36 @@ jobs:
|
||||
done
|
||||
ditto -c -k --keepParent "dist/$name" "dist/$name.zip"
|
||||
|
||||
# Reaktor.framework, with SDL inside, beside the static library: built,
|
||||
# linked from an outside app, and drawn the same; released as
|
||||
# libreaktor-shared-VERSION-macos-ARCH.zip.
|
||||
- name: Shared libreaktor
|
||||
id: shared
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
export CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=500M
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
name="libreaktor-shared-${version}-macos-${{ matrix.arch }}"
|
||||
cmake -S . -B build-shared -G Ninja -DCMAKE_BUILD_TYPE=Release -DREAKTOR_SHARED=ON \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
|
||||
cmake --build build-shared </dev/null
|
||||
sh tools/ci/check-libreaktor.sh build-shared "$name" </dev/null
|
||||
tar -C dist -xzf "dist/$name.tar.gz"
|
||||
rm "dist/$name.tar.gz"
|
||||
ditto -c -k --keepParent "dist/$name" "dist/$name.zip"
|
||||
rm -rf "dist/$name"
|
||||
|
||||
- name: Upload the shared libreaktor
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-macos-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-shared-*.zip
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
- name: Check an app that embeds Reaktor
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
@@ -175,7 +205,9 @@ jobs:
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-macos-${{ matrix.arch }}
|
||||
path: dist/libreaktor-*.zip
|
||||
path: |
|
||||
dist/libreaktor-*.zip
|
||||
!dist/libreaktor-shared-*.zip
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
@@ -187,3 +219,72 @@ jobs:
|
||||
path: smoke/
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
|
||||
# One framework for both: the two per-architecture shared builds joined with
|
||||
# lipo, released as libreaktor-VERSION-macos-universal.zip beside them.
|
||||
universal:
|
||||
name: macos universal
|
||||
needs: macos
|
||||
if: ${{ !cancelled() }}
|
||||
runs-on: macos-15
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install packages
|
||||
env:
|
||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||
run: brew install ninja
|
||||
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-macos-arm64
|
||||
path: dl/arm64
|
||||
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-macos-x86_64
|
||||
path: dl/x86_64
|
||||
|
||||
- name: Join and check the universal libreaktor
|
||||
run: |
|
||||
v='${{ inputs.version || 'dev' }}'
|
||||
for a in arm64 x86_64; do ditto -x -k "dl/$a/libreaktor-shared-$v-macos-$a.zip" "u/$a"; done
|
||||
A="u/arm64/libreaktor-shared-$v-macos-arm64"
|
||||
X="u/x86_64/libreaktor-shared-$v-macos-x86_64"
|
||||
U="dist/libreaktor-shared-$v-macos-universal"
|
||||
mkdir -p dist
|
||||
ditto "$A" "$U"
|
||||
# Every Mach-O file and archive becomes one with both; anything else
|
||||
# must already be the same in the two.
|
||||
(cd "$A" && find . -type f) | while read -r f; do
|
||||
if file -b "$A/$f" | grep -q -E 'Mach-O|ar archive'; then
|
||||
lipo -create "$A/$f" "$X/$f" -output "$U/$f"
|
||||
else
|
||||
cmp "$A/$f" "$X/$f"
|
||||
fi
|
||||
done
|
||||
codesign --force --sign - "$U/Frameworks/Reaktor.framework"
|
||||
lipo -info "$U/Frameworks/Reaktor.framework/Reaktor"
|
||||
lipo "$U/Frameworks/Reaktor.framework/Reaktor" -verify_arch arm64 x86_64
|
||||
lipo "$U/lib/libreaktor-modules.a" -verify_arch arm64 x86_64
|
||||
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
"-DCMAKE_PREFIX_PATH=$PWD/$U" -DCONSUMER_SHARED=ON \
|
||||
"-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" </dev/null
|
||||
cmake --build build-consumer </dev/null
|
||||
lipo build-consumer/simple -verify_arch arm64 x86_64
|
||||
mkdir -p check
|
||||
build-consumer/simple --theme light --video dummy \
|
||||
--shot check/universal.bmp --a11y-dump check/universal.txt </dev/null
|
||||
ditto -c -k --keepParent "$U" "$U.zip"
|
||||
|
||||
- name: Upload the universal libreaktor
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-macos-universal
|
||||
path: dist/libreaktor-shared-*-macos-universal.zip
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
@@ -135,10 +135,11 @@ jobs:
|
||||
### libreaktor
|
||||
|
||||
The library itself, for building your own applications: the same
|
||||
systems and architectures, \`libreaktor-$v-<system>-<arch>\`, and
|
||||
systems and architectures, \`libreaktor-$v-<system>-<arch>\` (a
|
||||
\`.zip\` on Windows and macOS, a \`.tar.gz\` elsewhere), 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, FreeType, plutosvg, Onlay, NukAnim, mojibake and kb_text_shape
|
||||
with SDL, FreeType, plutosvg, Onlay, NukAnim, mojibake, kb_text_shape and toml-c
|
||||
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.
|
||||
@@ -153,10 +154,40 @@ jobs:
|
||||
\`PKG_CONFIG_PATH\` at its \`lib/pkgconfig\`.
|
||||
|
||||
On Linux it also comes as a system package that installs into
|
||||
\`/opt/reaktor\`: \`libreaktor-dev_${v}_<arch>.deb\` for Debian and Ubuntu
|
||||
(amd64, i386, arm64, armhf, riscv64) and \`libreaktor-devel-${v}-1.<arch>.rpm\`
|
||||
\`/opt/reaktor\`: \`libreaktor_${v}_<arch>.deb\` for Debian and Ubuntu
|
||||
(amd64, i386, arm64, armhf, riscv64) and \`libreaktor-${v}-1.<arch>.rpm\`
|
||||
for Fedora and RHEL (x86_64, aarch64).
|
||||
|
||||
#### Shared
|
||||
|
||||
On macOS it also comes as \`Reaktor.framework\`, with SDL inside, in
|
||||
\`libreaktor-shared-$v-macos-<arch>.zip\` (arm64, x86_64, or \`universal\` with
|
||||
both in every binary) beside \`libreaktor-modules.a\` and the static
|
||||
files: link \`reaktor::shared\`. Apps share it from
|
||||
\`/Library/Frameworks\`, which their rpath searches. It is signed ad
|
||||
hoc and not notarized, like everything here, so an app that turns on
|
||||
the hardened runtime cannot load it, and a downloaded copy needs
|
||||
\`xattr -dr com.apple.quarantine Reaktor.framework\` once.
|
||||
|
||||
On Linux and the BSDs the library also comes shared, so
|
||||
several apps can share one copy in memory:
|
||||
\`libreaktor-shared-$v-<system>-<arch>.tar.gz\` holds \`libreaktor.so.0\`,
|
||||
our own SDL as \`libreaktor-sdl3.so.0\`, \`libreaktor-modules.a\` (the
|
||||
modules, which go into each app), everything the static one has, and
|
||||
\`reaktor-shared.pc\`. Link with \`reaktor::shared\` in CMake or
|
||||
\`pkg-config --cflags --libs reaktor-shared\`; the app records where the
|
||||
libraries are. As system packages it splits in three:
|
||||
\`libreaktor-sdl3-0\` and \`libreaktor0\`, all an app needs to run, and
|
||||
\`libreaktor-shared\` to build one:
|
||||
\`libreaktor0_${v}_<arch>.deb\`, \`libreaktor-sdl3-0_${v}_<arch>.deb\` and
|
||||
the \`.rpm\`s beside them. The static library stays the default.
|
||||
|
||||
**Upgrading:** the static package was \`libreaktor-dev\` as a \`.deb\`
|
||||
and \`libreaktor-devel\` as an \`.rpm\`; it is \`libreaktor\` now, as it
|
||||
was already on the BSDs. Remove the old one first, since both install
|
||||
the headers. \`libreaktor-shared\` is the shared one and conflicts with
|
||||
it the same way.
|
||||
|
||||
\`SHA256SUMS\` lists every download's checksum. GitHub's own source
|
||||
archives below leave the submodules out; the \`-source.tar.gz\` above has
|
||||
them.
|
||||
|
||||
@@ -12,6 +12,9 @@ build-arm64/
|
||||
build-lib/
|
||||
build-consumer/
|
||||
build-embedded/
|
||||
build-map/
|
||||
build-proto*/
|
||||
build-shared/
|
||||
.claude/settings.local.json
|
||||
.dart_tool/
|
||||
.gradle/
|
||||
@@ -31,5 +34,8 @@ benchmarks/flutter-bench/.idea/
|
||||
benchmarks/flutter-bench/*.iml
|
||||
build-pkg/
|
||||
build-pkg-consumer/
|
||||
build-pkg-shared/
|
||||
dist-pkg*/
|
||||
dist/
|
||||
smoke/
|
||||
build-static/
|
||||
|
||||
+3
-3
@@ -22,9 +22,6 @@
|
||||
[submodule "external/nukanim"]
|
||||
path = external/nukanim
|
||||
url = https://github.com/Alpaq92/NukAnim.git
|
||||
[submodule "external/mglibs"]
|
||||
path = external/mglibs
|
||||
url = https://github.com/mattiasgustavsson/libs.git
|
||||
[submodule "external/watercss"]
|
||||
path = external/watercss
|
||||
url = https://github.com/kognise/water.css
|
||||
@@ -34,3 +31,6 @@
|
||||
[submodule "external/freetype"]
|
||||
path = external/freetype
|
||||
url = https://github.com/freetype/freetype
|
||||
[submodule "external/toml-c"]
|
||||
path = external/toml-c
|
||||
url = https://github.com/arp242/toml-c.git
|
||||
|
||||
@@ -4,130 +4,102 @@ C99. Widgets are declared; the look comes from CSS read at runtime.
|
||||
|
||||
## Build and run
|
||||
|
||||
`./build.ps1` on Windows, `./build.sh` elsewhere — `cmake` is not on PATH, the
|
||||
script finds MSVC's. `./build.ps1 <target>` or `./build.sh <target>` builds one. Targets: `showcase`,
|
||||
`notepad`, `simple`, `bench`, plus the tests in `tests/`. `-Arch x86` (or
|
||||
`arm64`) builds that architecture into `build-<arch>`; ARM64 needs Visual
|
||||
Studio's ARM64 tools, which this machine lacks, so CI is its only check.
|
||||
`tools/package.sh <build> <folder> [.exe]` packs what a release ships; a
|
||||
version tag such as `1.2.3` publishes one through `release.yml`.
|
||||
`./build.sh [target]` (`./build.ps1` on Windows; `cmake` is not on PATH, the
|
||||
script finds it). Targets: `showcase`, `notepad`, `simple`, `bench`, the tests
|
||||
in `tests/`, and `libreaktor`. `-Arch x86|arm64` builds into `build-<arch>`;
|
||||
ARM64 is checked only by CI.
|
||||
|
||||
CMake options pass straight through: `./build.ps1 -DREAKTOR_A11Y=OFF`,
|
||||
`./build.sh -- -DREAKTOR_A11Y=OFF`. The cache keeps an option, so a later build
|
||||
without the flag does not reset it — pass `=ON` to switch back.
|
||||
CMake options pass through: `./build.ps1 -DREAKTOR_A11Y=OFF`,
|
||||
`./build.sh -- -DREAKTOR_A11Y=OFF`. The cache keeps them, so pass `=OFF` or
|
||||
`=ON` again to switch back. Check `build/CMakeCache.txt` before measuring:
|
||||
`REAKTOR_SHARED=ON` left in `build/` makes every sample a shared one.
|
||||
|
||||
Shipping: `tools/package.sh` packs a release folder, `tools/libreaktor-pkg.sh`
|
||||
a system package (`libreaktor` static; with `-s`, `libreaktor0`,
|
||||
`libreaktor-sdl3-0` and `libreaktor-shared`). A version tag such as `1.2.3`
|
||||
publishes through `release.yml`.
|
||||
|
||||
## Verify against pixels, not source
|
||||
|
||||
Reasoning from a dependency's source about what it will draw has been wrong
|
||||
often enough to be a rule. Take the screenshot, diff the dump, read the
|
||||
framebuffer.
|
||||
Reasoning about what a dependency will draw has been wrong too often. Take the
|
||||
screenshot and diff the dump:
|
||||
|
||||
```bash
|
||||
./build/showcase --tab 7 --theme dark --shot a.bmp --a11y-dump a.txt
|
||||
```
|
||||
|
||||
`--a11y-dump` writes one line per node with role, name, value, state and
|
||||
**bounds**. Diff two and anything that moved by a pixel says so. It is the
|
||||
regression oracle for every layout or style change.
|
||||
The dump has one line per node with role, name, value, state and bounds, so
|
||||
a one-pixel move shows. Lines marked `volatile` (Diagnostics timings) differ
|
||||
on every run.
|
||||
|
||||
## Traps that have cost real time
|
||||
|
||||
- **A rule cannot resize a box the page already sized.** Any `.box = { .h = N }`
|
||||
in a page locks CSS out of that axis. This is the usual reason a stylesheet
|
||||
"only changes the color".
|
||||
- **`core/ui/style_map.c` is the only writer of `nk_style`.** Setting a widget
|
||||
style anywhere else works until the next theme change reloads the sheets.
|
||||
- **A box is placed one frame late**, and found again by its **name**. A widget
|
||||
whose label changes every frame needs a stable `.name` or it never gets a
|
||||
rectangle.
|
||||
- **Hover is drawn only across a hot rectangle.** Pointer motion runs a frame
|
||||
only when it crosses a rectangle `hot_push` registered the frame before, so a
|
||||
widget that looks different under the pointer and registers none keeps its
|
||||
old look until some other input.
|
||||
- **A percentage is not a length to the CSS engine.** `core/css/css.c` has no
|
||||
box to resolve one against, so `width: 100%` is dropped and a lower rule's
|
||||
value shows through. An attribute selector reads as a class: `[type=range]`
|
||||
answers `input.type-range`.
|
||||
- **The renderer snaps every vertex to whole pixels.** Sub-pixel corrections
|
||||
are discarded, and rects that abut can round apart into a visible seam.
|
||||
- **SDL redraws a software rectangle its own way.** Its software renderer
|
||||
turns two triangles that make a rectangle into a fill or a copy, and
|
||||
truncates the scaled position and size apart, so at a fractional scale a run
|
||||
a whole number of device pixels wide loses one. `nk_sdl_quad` draws every
|
||||
such rectangle from device pixels before SDL sees it.
|
||||
- **A one-pixel stroke is two pixels here.** `nk_stroke_rect` casts its rect to
|
||||
`short`, so a half-pixel inset never reaches the draw list, and with line
|
||||
anti-aliasing on a stroke of thickness one is always two half-alpha rows.
|
||||
A border is `reaktor_edge_round`, inside the box: a ring mask for its
|
||||
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 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`.
|
||||
- **Measure the present, not the draw.** On a machine with no GPU, most of a
|
||||
frame is `SDL_RenderPresent`. `build/render/present` split is on the
|
||||
Diagnostics page and in `bench --no-vsync`.
|
||||
- **Text the atlas cannot draw is not Nuklear's to draw.** A string with any
|
||||
character the atlas lacks — Japanese, Arabic — is measured by
|
||||
`core/text/text.c` and drawn from the custom command it swaps in for
|
||||
Nuklear's text command, so a change to how Nuklear or the renderer places
|
||||
glyphs does not reach it. Its bidi levels are matched to mojibake's by order:
|
||||
mojibake 0.5.0 records `byte_offset` at a character's last byte.
|
||||
- **Only Nuklear's active window gets input.** Every other window carries a
|
||||
sticky `NK_WINDOW_ROM` until a click or hover activates it inside
|
||||
`nk_begin`. A layer that must not take input is begun
|
||||
`NK_WINDOW_NOT_INTERACTIVE` with `ctx->input` blanked — `reaktor_layer_begin`
|
||||
with `HOLD_ALL` — and focus is handed back with `reaktor_layer_focus`.
|
||||
- **A field's keys are its own, wherever it was declared.** Nuklear keeps
|
||||
edit-active state on the window a widget sits in, so the page's window misses
|
||||
every field inside a group; `app->editing` is what navigation asks before it
|
||||
gives up the arrows, Home, End, Enter and Space. Home and End also scroll the
|
||||
panel out from under the edit, so the runtime keeps those two.
|
||||
- **A field's value is not its buffer, and its length is the caller's.**
|
||||
`nk_edit_string` leaves the bytes past the length alone, so the buffer read as
|
||||
a string is the last, longer value; a length from anywhere but the field's own
|
||||
last frame reseeds it empty every frame.
|
||||
- **An empty edit has no text pointer.** `nk_str_get_const` answers NULL while
|
||||
`nk_str_len_char` still answers bytes, so that pair measures a null pointer
|
||||
with a positive length.
|
||||
- **A tap focuses the canvas by itself.** The canvas is focusable, so a
|
||||
touch's compatibility `mousedown` moves focus to it as its default action,
|
||||
with no script involved. Only canceling the touch `pointerdown` stops it.
|
||||
- **SDL hands the app its events a frame late.** Its web handlers queue them
|
||||
as they happen, but the app sees them only when the next iteration pumps, so
|
||||
anything the page keeps in a queue of its own overtakes them. The page's
|
||||
typing goes onto SDL's queue for that reason.
|
||||
- **A hidden web page runs no frames.** The web build's main loop waits on
|
||||
`requestAnimationFrame`, which never fires in a background tab, a minimized
|
||||
window or a browser pane that is not on screen. `#a11y` is made in `main()`,
|
||||
so the root is there, but the canvas stays blank and the tree empty until
|
||||
the page renders — and a scripted click or screenshot makes it render, so
|
||||
it looks as if the tree waits for input. Check `document.visibilityState`.
|
||||
- **A rule cannot resize a box the page sized.** `.box = { .h = N }` locks CSS
|
||||
out of that axis; usually why a stylesheet "only changes the color".
|
||||
- **`core/ui/style_map.c` is the only writer of `nk_style`.** Anything set
|
||||
elsewhere is lost on the next theme change.
|
||||
- **A box is placed one frame late and found by its name.** A widget whose
|
||||
label changes every frame needs a stable `.name`.
|
||||
- **Hover redraws only across a hot rectangle.** Motion runs a frame only when
|
||||
it crosses a rectangle `hot_push` registered the frame before.
|
||||
- **A percentage is not a length to `core/css/css.c`.** `width: 100%` is
|
||||
dropped and a lower rule shows through. `[type=range]` reads as
|
||||
`input.type-range`.
|
||||
- **Vertices snap to whole pixels.** Sub-pixel corrections vanish; abutting
|
||||
rects can round apart into a seam.
|
||||
- **SDL's software renderer redraws rectangles its own way**, truncating
|
||||
position and size apart at fractional scales. `nk_sdl_quad` draws them from
|
||||
device pixels first.
|
||||
- **A one-pixel stroke is two pixels.** `nk_stroke_rect` casts to `short` and
|
||||
anti-aliasing splits it. Borders are `reaktor_edge_round`: a ring mask for
|
||||
corners, runs cut from its middle texels.
|
||||
- **Rounded fills are masks.** Fill anti-aliasing is off on the software
|
||||
renderer, so `reaktor_render` swaps each rounded fill for
|
||||
`reaktor_fill_round`, relinking the command list (it ends where a `next`
|
||||
reaches `ctx->memory.allocated`).
|
||||
- **Measure the present, not the draw.** Without a GPU most of a frame is
|
||||
`SDL_RenderPresent`; the Diagnostics page and `bench --no-vsync` split it.
|
||||
- **Text the atlas lacks is not Nuklear's.** Strings with Japanese, Arabic and
|
||||
the like are measured and drawn by `core/text/text.c` through a custom
|
||||
command. mojibake 0.5.0 records `byte_offset` at a character's last byte.
|
||||
- **Only Nuklear's active window gets input.** Others carry a sticky
|
||||
`NK_WINDOW_ROM`. A layer that must not take input uses `reaktor_layer_begin`
|
||||
with `HOLD_ALL`; `reaktor_layer_focus` hands focus back.
|
||||
- **A field's keys are its own.** Edit state lives on the widget's window, so
|
||||
navigation asks `app->editing` before taking arrows, Home, End, Enter or
|
||||
Space. The runtime keeps Home and End, which would scroll the panel.
|
||||
- **A field's value is not its buffer.** `nk_edit_string` leaves bytes past
|
||||
the length; a length not from the field's own last frame reseeds it empty.
|
||||
- **An empty edit has no text pointer.** `nk_str_get_const` is NULL while
|
||||
`nk_str_len_char` is positive.
|
||||
- **Web: a tap focuses the canvas.** Only canceling the touch `pointerdown`
|
||||
stops it.
|
||||
- **Web: SDL delivers events a frame late**, so the page's own typing goes
|
||||
through SDL's queue to keep its order.
|
||||
- **Web: a hidden page runs no frames.** No `requestAnimationFrame` in a
|
||||
background tab, so the canvas and a11y tree stay empty. Check
|
||||
`document.visibilityState`.
|
||||
- **The shared library exports only `tools/reaktor.map`.** A new public call
|
||||
goes in the map, or `check-exports.sh` fails; a struct an app sees that
|
||||
changes needs a new SOVERSION and `check-abi.sh -u`. OpenBSD installs no
|
||||
unversioned `libreaktor.so`.
|
||||
|
||||
## House rules
|
||||
|
||||
- Dependencies are git submodules under `external/`, read as they ship. Never
|
||||
transcribe a value out of one, and never generate a header from one. The one
|
||||
exception is `REAKTOR_BUILTINS` in CMakeLists.txt: Water.css's two palettes
|
||||
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 Simple.css. SDL is built with `core/sdl/no_dynapi.h`
|
||||
forced in, which turns its dynamic API off; NOTICE.md says why.
|
||||
- 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.
|
||||
MSVC builds apps with implicit declarations as errors, which catches a miss.
|
||||
- American English, in code and prose.
|
||||
- No environment variables. Anything worth overriding is a command-line flag
|
||||
the runtime strips from `argv`.
|
||||
- `docs/DOCUMENTATION.md` is the whole of it; `PERFORMANCE.md` holds measured
|
||||
- Dependencies are submodules under `external/`, used as they ship. Never
|
||||
copy a value out of one or generate a header from one. The exception is
|
||||
`REAKTOR_BUILTINS` in CMakeLists.txt: Water.css's palettes and `src/parts/`,
|
||||
the seven Ionicons the widgets draw, the Aileron fonts, the mark and
|
||||
reaktor.css, compiled in byte for byte. SDL is built with
|
||||
`core/sdl/no_dynapi.h`; NOTICE.md says why.
|
||||
- Applications see only `include/reaktor/`; `App` is opaque. What a sample
|
||||
needs becomes a public call. MSVC treats implicit declarations as errors.
|
||||
- American English.
|
||||
- No environment variables: overrides are command-line flags the runtime
|
||||
strips from `argv`.
|
||||
- `docs/DOCUMENTATION.md` is the only manual; `PERFORMANCE.md` holds measured
|
||||
numbers only, with the machine named.
|
||||
- An optional module is an interface library plus a `_none` twin defining the
|
||||
same functions, and an application links one of the two; its
|
||||
`REAKTOR_<NAME>` option, default `ON`, swaps in the twin. Localization and
|
||||
text shaping are two modules, not one. A module that is off must leave pixels
|
||||
and `--a11y-dump` byte-identical except for what the module itself produces.
|
||||
- An optional module is an interface library plus a `_none` twin, switched by
|
||||
`REAKTOR_<NAME>` (default `ON`). Off, pixels and `--a11y-dump` must not
|
||||
change beyond what the module draws. Localization and text shaping are
|
||||
separate modules.
|
||||
|
||||
+302
-27
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(reaktor VERSION 0.8.0 LANGUAGES C CXX)
|
||||
project(reaktor VERSION 0.9.0 LANGUAGES C CXX)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
set(_reaktor_top ON)
|
||||
@@ -22,29 +22,123 @@ endif()
|
||||
|
||||
set(TP "${CMAKE_CURRENT_SOURCE_DIR}/external")
|
||||
|
||||
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
|
||||
# A shared libreaktor beside libreaktor.a, so several apps share one copy:
|
||||
# libreaktor.so, with SDL as libreaktor-sdl3.so, on Linux and the BSDs, and
|
||||
# Reaktor.framework, with SDL inside, on macOS. The samples link it.
|
||||
option(REAKTOR_SHARED "Also build a shared libreaktor, and link the samples to it" OFF)
|
||||
set(REAKTOR_SHARED_SDL OFF)
|
||||
if(REAKTOR_SHARED)
|
||||
if(NOT UNIX OR EMSCRIPTEN)
|
||||
message(FATAL_ERROR "REAKTOR_SHARED is for Linux, the BSDs and macOS")
|
||||
endif()
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
if(NOT APPLE)
|
||||
set(REAKTOR_SHARED_SDL ON)
|
||||
endif()
|
||||
endif()
|
||||
if(REAKTOR_SHARED_SDL)
|
||||
set(REAKTOR_SDL SDL3::SDL3-shared)
|
||||
else()
|
||||
set(REAKTOR_SDL SDL3::SDL3-static)
|
||||
endif()
|
||||
set(SDL_SHARED ${REAKTOR_SHARED_SDL} CACHE BOOL "" FORCE)
|
||||
set(SDL_STATIC ON CACHE BOOL "" FORCE)
|
||||
set(SDL_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(SDL_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
|
||||
set(SDL_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
foreach(sub AUDIO JOYSTICK HAPTIC HIDAPI SENSOR CAMERA POWER GPU OFFSCREEN)
|
||||
foreach(sub AUDIO JOYSTICK HAPTIC HIDAPI SENSOR CAMERA POWER OFFSCREEN)
|
||||
set(SDL_${sub} OFF CACHE BOOL "" FORCE)
|
||||
endforeach()
|
||||
# Off: the software renderer is the default, and with the GPU API built in,
|
||||
# SDL loads Vulkan and its drivers even for that renderer (PERFORMANCE.md).
|
||||
# An application that runs its own shaders turns it on.
|
||||
option(REAKTOR_SHADERS "An application's own shaders: SDL's GPU API and its renderer, --renderer sdl-gpu" OFF)
|
||||
set(SDL_GPU ${REAKTOR_SHADERS} CACHE BOOL "" FORCE)
|
||||
set(SDL_TRAY ON CACHE BOOL "" FORCE)
|
||||
|
||||
foreach(drv RENDER_D3D RENDER_VULKAN VULKAN)
|
||||
set(SDL_${drv} OFF CACHE BOOL "" FORCE)
|
||||
endforeach()
|
||||
# SDL's GPU API runs on Vulkan where there is no Direct3D 12 or Metal.
|
||||
if(REAKTOR_SHADERS AND UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
set(SDL_VULKAN ON CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
# The renderers built beside software, in the words --renderer takes. Empty
|
||||
# is the platform's default; `none` is software only. macOS builds metal and
|
||||
# opengl either way and the web opengles2, so the list means nothing there.
|
||||
set(_renderers_all direct3d11 direct3d12 opengl opengles2)
|
||||
if(WIN32)
|
||||
set(SDL_RENDER_D3D12 ON CACHE BOOL "" FORCE)
|
||||
set(_renderers_default direct3d11 direct3d12)
|
||||
set(_renderers_here ${_renderers_all})
|
||||
elseif(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
set(_renderers_default "")
|
||||
set(_renderers_here opengl opengles2)
|
||||
else()
|
||||
set(_renderers_default "")
|
||||
set(_renderers_here "")
|
||||
endif()
|
||||
set(REAKTOR_RENDERERS "" CACHE STRING
|
||||
"Renderers built beside software, as --renderer names them: direct3d11, direct3d12, opengl, opengles2; empty for the platform's default, none for software only")
|
||||
set_property(CACHE REAKTOR_RENDERERS PROPERTY STRINGS "" none ${_renderers_all})
|
||||
|
||||
# A build directory from before the list keeps the renderers its two
|
||||
# switches, REAKTOR_SDL_D3D and REAKTOR_SDL_GL, had chosen.
|
||||
if(NOT REAKTOR_RENDERERS AND (DEFINED REAKTOR_SDL_D3D OR DEFINED REAKTOR_SDL_GL))
|
||||
set(_old "")
|
||||
if(NOT DEFINED REAKTOR_SDL_D3D OR REAKTOR_SDL_D3D)
|
||||
list(APPEND _old direct3d11 direct3d12)
|
||||
endif()
|
||||
if(REAKTOR_SDL_GL)
|
||||
list(APPEND _old opengl opengles2)
|
||||
endif()
|
||||
if(NOT _old)
|
||||
set(_old none)
|
||||
endif()
|
||||
unset(REAKTOR_SDL_D3D CACHE)
|
||||
unset(REAKTOR_SDL_GL CACHE)
|
||||
string(REPLACE ";" "," _old_shown "${_old}")
|
||||
if(_old STREQUAL "none" OR NOT _old STREQUAL "${_renderers_default}")
|
||||
set(REAKTOR_RENDERERS "${_old}" CACHE STRING "" FORCE)
|
||||
message(WARNING "REAKTOR_SDL_D3D and REAKTOR_SDL_GL are now REAKTOR_RENDERERS; this build keeps REAKTOR_RENDERERS=${_old_shown}")
|
||||
else()
|
||||
message(STATUS "REAKTOR_SDL_D3D and REAKTOR_SDL_GL are now REAKTOR_RENDERERS; this build has the default")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
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)
|
||||
set(SDL_OPENGL ${REAKTOR_SDL_GL} CACHE BOOL "" FORCE)
|
||||
set(SDL_OPENGLES ${REAKTOR_SDL_GL} CACHE BOOL "" FORCE)
|
||||
string(REPLACE "," ";" _renderers "${REAKTOR_RENDERERS}")
|
||||
string(REPLACE "," ", " _renderers_shown "${REAKTOR_RENDERERS}")
|
||||
if(_renderers MATCHES "^(ON|OFF|TRUE|FALSE|YES|NO|Y|N|1|0)$")
|
||||
message(FATAL_ERROR "REAKTOR_RENDERERS lists renderers, it is not a switch: direct3d11, direct3d12, opengl, opengles2, or none for software only")
|
||||
elseif(NOT _renderers)
|
||||
set(_renderers ${_renderers_default})
|
||||
elseif(_renderers STREQUAL "none")
|
||||
set(_renderers "")
|
||||
else()
|
||||
foreach(r ${_renderers})
|
||||
if(NOT r IN_LIST _renderers_all)
|
||||
message(FATAL_ERROR "REAKTOR_RENDERERS=${_renderers_shown}: ${r} is not a renderer; the choices are direct3d11, direct3d12, opengl, opengles2, or none")
|
||||
elseif(NOT r IN_LIST _renderers_here)
|
||||
message(STATUS "REAKTOR_RENDERERS: ${r} is not a choice on ${CMAKE_SYSTEM_NAME}, ignored")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
foreach(r ${_renderers_here})
|
||||
if(r IN_LIST _renderers)
|
||||
set(_on ON)
|
||||
else()
|
||||
set(_on OFF)
|
||||
endif()
|
||||
if(r STREQUAL direct3d11)
|
||||
set(SDL_RENDER_D3D11 ${_on} CACHE BOOL "" FORCE)
|
||||
elseif(r STREQUAL direct3d12)
|
||||
set(SDL_RENDER_D3D12 ${_on} CACHE BOOL "" FORCE)
|
||||
elseif(r STREQUAL opengl)
|
||||
set(SDL_OPENGL ${_on} CACHE BOOL "" FORCE)
|
||||
elseif(r STREQUAL opengles2)
|
||||
set(SDL_OPENGLES ${_on} CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(SDL_X11_XSCRNSAVER OFF CACHE BOOL "" FORCE)
|
||||
# Linux packaging notes; OpenBSD refuses a program whose note segment passes 1 KB.
|
||||
@@ -56,8 +150,11 @@ 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)
|
||||
# A static program keeps only the functions and data it uses. MSVC's Release
|
||||
# already splits functions; /Gw splits data.
|
||||
if(MSVC)
|
||||
add_compile_options(/Gw)
|
||||
elseif(NOT EMSCRIPTEN)
|
||||
add_compile_options(-ffunction-sections -fdata-sections)
|
||||
endif()
|
||||
add_subdirectory("${TP}/SDL" EXCLUDE_FROM_ALL)
|
||||
@@ -88,6 +185,13 @@ else()
|
||||
target_compile_options(SDL3-static PRIVATE
|
||||
-include "${CMAKE_CURRENT_SOURCE_DIR}/core/sdl/no_dynapi.h")
|
||||
endif()
|
||||
if(REAKTOR_SHARED_SDL)
|
||||
target_compile_options(SDL3-shared PRIVATE
|
||||
-include "${CMAKE_CURRENT_SOURCE_DIR}/core/sdl/no_dynapi.h")
|
||||
# Our own SDL under its own name, never the distro's libSDL3.
|
||||
set_target_properties(SDL3-shared PROPERTIES OUTPUT_NAME reaktor-sdl3
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
if(UNIX AND NOT EMSCRIPTEN)
|
||||
find_library(REAKTOR_LIBM m)
|
||||
@@ -183,7 +287,11 @@ add_library(reaktor_core STATIC
|
||||
core/render/svg.c
|
||||
"${_builtins}")
|
||||
target_include_directories(reaktor_core PUBLIC core/base core/render)
|
||||
target_link_libraries(reaktor_core PUBLIC plutosvg freetype reaktor_headers SDL3::SDL3-static)
|
||||
target_link_libraries(reaktor_core PUBLIC plutosvg freetype reaktor_headers ${REAKTOR_SDL})
|
||||
# Nuklear built for size: 139 KB less of the library, at no measurable cost a
|
||||
# frame (PERFORMANCE.md). A debug build keeps its own -O0.
|
||||
set_property(SOURCE core/render/nk_impl.c APPEND PROPERTY COMPILE_OPTIONS
|
||||
"$<$<NOT:$<CONFIG:Debug>>:$<IF:$<C_COMPILER_ID:MSVC>,/O1,-Os>>")
|
||||
|
||||
set(APP_ICON assets/icons/reaktor-icon.ico)
|
||||
set(APP_RESOURCES "")
|
||||
@@ -195,23 +303,23 @@ if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
|
||||
add_executable(keytest tests/keytest.c core/ui/keys.c)
|
||||
target_link_libraries(keytest PRIVATE reaktor_headers)
|
||||
target_include_directories(keytest PRIVATE core/ui)
|
||||
target_link_libraries(keytest PRIVATE SDL3::SDL3-static)
|
||||
target_link_libraries(keytest PRIVATE ${REAKTOR_SDL})
|
||||
|
||||
add_executable(a11ytest tests/a11ytest.c core/a11y/a11y.c
|
||||
platform/a11y/a11y_snapshot.c core/base/utf8.c)
|
||||
target_link_libraries(a11ytest PRIVATE reaktor_headers SDL3::SDL3-static)
|
||||
target_link_libraries(a11ytest PRIVATE reaktor_headers ${REAKTOR_SDL})
|
||||
target_include_directories(a11ytest PRIVATE core/a11y core/render
|
||||
platform/a11y core/base)
|
||||
|
||||
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)
|
||||
target_link_libraries(animtest PRIVATE reaktor_core ${REAKTOR_SDL})
|
||||
|
||||
add_executable(localetest tests/localetest.c
|
||||
core/locale/locale.c core/locale/plural.c
|
||||
core/locale/format.c)
|
||||
target_link_libraries(localetest PRIVATE reaktor_headers SDL3::SDL3-static)
|
||||
target_link_libraries(localetest PRIVATE reaktor_headers ${REAKTOR_SDL})
|
||||
target_include_directories(localetest PRIVATE core/locale)
|
||||
target_compile_definitions(localetest PRIVATE REAKTOR_LOCALE_EMBEDDED)
|
||||
|
||||
@@ -228,10 +336,16 @@ if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
|
||||
|
||||
add_executable(basetest tests/basetest.c core/base/url.c core/base/utf8.c)
|
||||
target_include_directories(basetest PRIVATE core/base)
|
||||
target_link_libraries(basetest PRIVATE SDL3::SDL3-static)
|
||||
target_link_libraries(basetest PRIVATE ${REAKTOR_SDL})
|
||||
|
||||
add_executable(imagetest tests/imagetest.c)
|
||||
target_link_libraries(imagetest PRIVATE plutovg)
|
||||
|
||||
if(MSVC)
|
||||
foreach(_t keytest a11ytest animtest localetest laytest csstest basetest imagetest)
|
||||
target_compile_options(${_t} PRIVATE /we4013)
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
@@ -391,11 +505,11 @@ else()
|
||||
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
|
||||
SDL3::SDL3-static)
|
||||
${REAKTOR_SDL})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(REAKTOR_SETTINGS "Settings kept between runs, in settings.conf" ON)
|
||||
option(REAKTOR_SETTINGS "Settings kept between runs, in settings.toml" ON)
|
||||
option(REAKTOR_TRAY "A tray icon with a menu" ON)
|
||||
option(REAKTOR_POPUP_WINDOWS "Menus in windows of their own, past the main window's edge" ON)
|
||||
option(REAKTOR_INSPECTOR "The Inspector: tree, box, style, frame and log of a running app" ON)
|
||||
@@ -419,12 +533,28 @@ foreach(_m settings:REAKTOR_SETTINGS:settings tray:REAKTOR_TRAY:tray
|
||||
endif()
|
||||
endforeach()
|
||||
if(REAKTOR_SETTINGS)
|
||||
target_include_directories(reaktor_settings INTERFACE "${TP}/mglibs")
|
||||
target_sources(reaktor_settings INTERFACE "${TP}/toml-c/toml.c")
|
||||
target_include_directories(reaktor_settings INTERFACE "${TP}/toml-c")
|
||||
if(EMSCRIPTEN)
|
||||
target_link_options(reaktor_settings INTERFACE -lidbfs.js
|
||||
"SHELL:--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/tools/web-pre.js")
|
||||
endif()
|
||||
endif()
|
||||
# Linux and the BSDs speak StatusNotifierItem over libdbus rather than take
|
||||
# SDL's tray, which loads GTK; without dbus-1 they have none.
|
||||
if(REAKTOR_TRAY AND NOT WIN32 AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID)
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND AND NOT TARGET PkgConfig::REAKTOR_DBUS)
|
||||
pkg_check_modules(REAKTOR_DBUS QUIET IMPORTED_TARGET dbus-1)
|
||||
endif()
|
||||
if(TARGET PkgConfig::REAKTOR_DBUS)
|
||||
target_compile_definitions(reaktor_tray INTERFACE REAKTOR_TRAY_DBUS)
|
||||
target_link_libraries(reaktor_tray INTERFACE PkgConfig::REAKTOR_DBUS)
|
||||
message(STATUS "tray: StatusNotifierItem over libdbus")
|
||||
else()
|
||||
message(STATUS "tray: no dbus-1; reaktor_tray_open answers 0")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(REAKTOR_NOTIFY "System notifications: a toast, a D-Bus notification, the browser's" ON)
|
||||
|
||||
@@ -537,7 +667,7 @@ target_include_directories(reaktor_runtime PUBLIC
|
||||
|
||||
target_link_libraries(reaktor_runtime PUBLIC
|
||||
reaktor_core
|
||||
SDL3::SDL3-static
|
||||
${REAKTOR_SDL}
|
||||
onlay)
|
||||
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
@@ -557,14 +687,84 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/plutosvg/plutovg/LICENSE"
|
||||
"${CMAKE_BINARY_DIR}/licenses/plutovg.txt" COPYONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/freetype/docs/FTL.TXT"
|
||||
"${CMAKE_BINARY_DIR}/licenses/freetype.txt" COPYONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/mglibs/ini.h"
|
||||
"${CMAKE_BINARY_DIR}/licenses/ini.h.txt" COPYONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/toml-c/LICENSE"
|
||||
"${CMAKE_BINARY_DIR}/licenses/toml-c.txt" COPYONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
|
||||
"${CMAKE_BINARY_DIR}/licenses/reaktor.txt" COPYONLY)
|
||||
set(REAKTOR_APP_RESOURCES "${APP_RESOURCES}" CACHE INTERNAL "")
|
||||
|
||||
if(REAKTOR_SHARED)
|
||||
# The runtime, the core and the libraries under them; reaktor.map says
|
||||
# what they export. The modules stay in each app, which exports them back.
|
||||
# On macOS SDL goes in too, and ld64 takes the map as a list of names.
|
||||
set(_so_parts reaktor_runtime reaktor_core plutosvg plutovg freetype onlay)
|
||||
set(_so_files "")
|
||||
foreach(_t IN LISTS _so_parts)
|
||||
target_compile_options(${_t} PRIVATE -fno-semantic-interposition)
|
||||
endforeach()
|
||||
if(APPLE)
|
||||
list(APPEND _so_parts SDL3-static)
|
||||
endif()
|
||||
foreach(_t IN LISTS _so_parts)
|
||||
list(APPEND _so_files "$<TARGET_FILE:${_t}>")
|
||||
endforeach()
|
||||
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/reaktor_so.c" CONTENT "")
|
||||
add_library(reaktor_shared SHARED "${CMAKE_BINARY_DIR}/reaktor_so.c")
|
||||
set_target_properties(reaktor_shared PROPERTIES
|
||||
VERSION ${PROJECT_VERSION} SOVERSION 0
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/reaktor.map")
|
||||
add_dependencies(reaktor_shared ${_so_parts})
|
||||
if(APPLE)
|
||||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/tools/reaktor.map" _map_lines)
|
||||
set(_exp "")
|
||||
foreach(_l IN LISTS _map_lines)
|
||||
if(_l MATCHES "^ *#" OR _l MATCHES "[{}:]")
|
||||
continue()
|
||||
endif()
|
||||
string(REGEX MATCHALL "[A-Za-z_][A-Za-z0-9_*]*" _names "${_l}")
|
||||
foreach(_n IN LISTS _names)
|
||||
string(APPEND _exp "_${_n}\n")
|
||||
endforeach()
|
||||
endforeach()
|
||||
# SDL is linked in here rather than beside the framework, and apps
|
||||
# and their modules call it directly.
|
||||
string(APPEND _exp "_SDL_*\n")
|
||||
file(WRITE "${CMAKE_BINARY_DIR}/reaktor.exp" "${_exp}")
|
||||
set(_force "")
|
||||
foreach(_f IN LISTS _so_files)
|
||||
list(APPEND _force "-Wl,-force_load,${_f}")
|
||||
endforeach()
|
||||
set_target_properties(reaktor_shared PROPERTIES OUTPUT_NAME Reaktor
|
||||
FRAMEWORK TRUE FRAMEWORK_VERSION A
|
||||
MACOSX_FRAMEWORK_IDENTIFIER io.github.alpaq92.reaktor
|
||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
|
||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
INSTALL_NAME_DIR "@rpath"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Frameworks")
|
||||
target_link_libraries(reaktor_shared PRIVATE ${_force}
|
||||
$<TARGET_PROPERTY:reaktor_runtime,INTERFACE_LINK_LIBRARIES>)
|
||||
target_link_options(reaktor_shared PRIVATE
|
||||
"-Wl,-exported_symbols_list,${CMAKE_BINARY_DIR}/reaktor.exp"
|
||||
"-Wl,-undefined,dynamic_lookup")
|
||||
target_link_libraries(reaktor_shared INTERFACE SDL3::Headers)
|
||||
else()
|
||||
set_target_properties(reaktor_shared PROPERTIES OUTPUT_NAME reaktor)
|
||||
target_link_libraries(reaktor_shared PRIVATE
|
||||
-Wl,--whole-archive ${_so_files} -Wl,--no-whole-archive
|
||||
$<TARGET_PROPERTY:reaktor_runtime,INTERFACE_LINK_LIBRARIES>)
|
||||
target_link_options(reaktor_shared PRIVATE
|
||||
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/tools/reaktor.map")
|
||||
target_link_libraries(reaktor_shared INTERFACE ${REAKTOR_SDL})
|
||||
endif()
|
||||
target_include_directories(reaktor_shared INTERFACE
|
||||
$<TARGET_PROPERTY:reaktor_runtime,INTERFACE_INCLUDE_DIRECTORIES>)
|
||||
target_compile_definitions(reaktor_shared INTERFACE
|
||||
$<TARGET_PROPERTY:reaktor_runtime,INTERFACE_COMPILE_DEFINITIONS>)
|
||||
endif()
|
||||
|
||||
function(reaktor_add_app name)
|
||||
cmake_parse_arguments(RA "CONSOLE" "" "SOURCES;MODULES;ASSETS" ${ARGN})
|
||||
cmake_parse_arguments(RA "CONSOLE;STATIC" "" "SOURCES;MODULES;ASSETS" ${ARGN})
|
||||
if(RA_CONSOLE)
|
||||
add_executable(${name} ${RA_SOURCES} ${REAKTOR_APP_RESOURCES})
|
||||
else()
|
||||
@@ -581,7 +781,19 @@ function(reaktor_add_app name)
|
||||
list(APPEND _mods reaktor_${_m}_none)
|
||||
endif()
|
||||
endforeach()
|
||||
target_link_libraries(${name} PRIVATE reaktor_runtime ${_mods})
|
||||
# STATIC: a test that reaches past include/reaktor/ links the archives even
|
||||
# in a shared build, so libreaktor.so need not export what it reaches.
|
||||
if(REAKTOR_SHARED AND NOT RA_STATIC)
|
||||
# The modules stay in the app; the shared core calls them back.
|
||||
target_link_libraries(${name} PRIVATE ${_mods} reaktor_shared)
|
||||
set_target_properties(${name} PROPERTIES ENABLE_EXPORTS ON)
|
||||
if(APPLE)
|
||||
# Kept through -dead_strip and visible to the framework's lookups.
|
||||
target_link_options(${name} PRIVATE -Wl,-export_dynamic)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(${name} PRIVATE reaktor_runtime ${_mods})
|
||||
endif()
|
||||
if(MSVC)
|
||||
target_compile_options(${name} PRIVATE /we4013)
|
||||
elseif(APPLE)
|
||||
@@ -645,7 +857,7 @@ reaktor_add_app(simple MODULES none SOURCES samples/simple/simple.c)
|
||||
reaktor_add_app(notepad MODULES settings popups print SOURCES samples/notepad/notepad.c)
|
||||
if(NOT EMSCRIPTEN)
|
||||
reaktor_add_app(bench MODULES none SOURCES samples/bench/bench.c)
|
||||
reaktor_add_app(launchtest MODULES settings popups print SOURCES tests/launchtest.c)
|
||||
reaktor_add_app(launchtest STATIC MODULES settings popups print SOURCES tests/launchtest.c)
|
||||
reaktor_add_app(uitest MODULES none SOURCES tests/uitest.c)
|
||||
set_target_properties(launchtest PROPERTIES EXCLUDE_FROM_ALL ON)
|
||||
endif()
|
||||
@@ -761,7 +973,7 @@ endif()
|
||||
|
||||
if(MSVC)
|
||||
# Nuklear's NK_ALIGNOF takes the offset of a member of an unnamed struct.
|
||||
set_source_files_properties(core/render/nk_impl.c PROPERTIES COMPILE_OPTIONS /wd4116)
|
||||
set_property(SOURCE core/render/nk_impl.c APPEND PROPERTY COMPILE_OPTIONS /wd4116)
|
||||
# nuklear.h combines constants of different enums in its own declarations.
|
||||
target_compile_options(reaktor_headers INTERFACE /wd5287)
|
||||
target_compile_options(showcase PRIVATE /wd4101)
|
||||
@@ -821,7 +1033,8 @@ function(reaktor_outside_links)
|
||||
if(_real)
|
||||
set(_t ${_real})
|
||||
endif()
|
||||
if(_t IN_LIST _seen)
|
||||
# libreaktor.a carries SDL3-static in the shared SDL's place.
|
||||
if(_t IN_LIST _seen OR _t STREQUAL "SDL3-shared")
|
||||
continue()
|
||||
endif()
|
||||
list(APPEND _seen ${_t})
|
||||
@@ -1017,6 +1230,54 @@ add_custom_command(OUTPUT "${_lib}"
|
||||
VERBATIM)
|
||||
add_custom_target(libreaktor DEPENDS "${_lib}")
|
||||
|
||||
# Beside libreaktor.so, the modules as libreaktor-modules.a for apps built
|
||||
# outside the tree: an app links them in and exports them back to the library.
|
||||
if(REAKTOR_SHARED)
|
||||
set(_mod_parts reaktor_modules)
|
||||
foreach(_t mojibake_lib kb_text_shape)
|
||||
if(TARGET ${_t})
|
||||
list(APPEND _mod_parts ${_t})
|
||||
endif()
|
||||
endforeach()
|
||||
set(_mod_lib "${CMAKE_BINARY_DIR}/lib/libreaktor-modules.a")
|
||||
if(APPLE)
|
||||
set(_mod_files "")
|
||||
foreach(_t IN LISTS _mod_parts)
|
||||
list(APPEND _mod_files "$<TARGET_FILE:${_t}>")
|
||||
endforeach()
|
||||
set(_mod_merge "${REAKTOR_LIBTOOL}" -static -o "${_mod_lib}" ${_mod_files})
|
||||
else()
|
||||
set(_mri "CREATE ${_mod_lib}\n")
|
||||
foreach(_t IN LISTS _mod_parts)
|
||||
string(APPEND _mri "ADDLIB $<TARGET_FILE:${_t}>\n")
|
||||
endforeach()
|
||||
string(APPEND _mri "SAVE\nEND\n")
|
||||
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/reaktor-modules.mri" CONTENT "${_mri}")
|
||||
set(_mod_merge "${CMAKE_COMMAND}" "-DAR=${CMAKE_AR}"
|
||||
"-DMRI=${CMAKE_BINARY_DIR}/reaktor-modules.mri"
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/tools/merge-lib.cmake")
|
||||
endif()
|
||||
add_custom_command(OUTPUT "${_mod_lib}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_BINARY_DIR}/lib"
|
||||
COMMAND "${CMAKE_COMMAND}" -E remove -f "${_mod_lib}"
|
||||
COMMAND ${_mod_merge}
|
||||
DEPENDS ${_mod_parts}
|
||||
COMMENT "Merging libreaktor-modules"
|
||||
VERBATIM)
|
||||
add_custom_target(libreaktor_modules DEPENDS "${_mod_lib}")
|
||||
add_dependencies(libreaktor reaktor_shared libreaktor_modules)
|
||||
if(REAKTOR_SHARED_SDL)
|
||||
add_dependencies(libreaktor SDL3-shared)
|
||||
# Both archives and libraries sit in one lib/: -l would pick the .so.
|
||||
set(REAKTOR_PC_LINK "-l:libreaktor.a")
|
||||
else()
|
||||
# A framework is not found by -l, so libreaktor.a still is.
|
||||
set(REAKTOR_PC_LINK "-lreaktor")
|
||||
endif()
|
||||
else()
|
||||
set(REAKTOR_PC_LINK "-lreaktor")
|
||||
endif()
|
||||
|
||||
option(REAKTOR_INSTALL "Install libreaktor's files" ${_reaktor_top})
|
||||
if(REAKTOR_INSTALL)
|
||||
include(CMakePackageConfigHelpers)
|
||||
@@ -1024,6 +1285,15 @@ if(REAKTOR_INSTALL)
|
||||
write_basic_package_version_file("${CMAKE_BINARY_DIR}/reaktorConfigVersion.cmake"
|
||||
COMPATIBILITY SameMinorVersion)
|
||||
install(FILES "${_lib}" DESTINATION lib COMPONENT libreaktor OPTIONAL)
|
||||
if(REAKTOR_SHARED)
|
||||
if(APPLE)
|
||||
install(TARGETS reaktor_shared FRAMEWORK DESTINATION Frameworks COMPONENT libreaktor)
|
||||
else()
|
||||
install(TARGETS reaktor_shared SDL3-shared
|
||||
LIBRARY DESTINATION lib COMPONENT libreaktor NAMELINK_COMPONENT libreaktor)
|
||||
endif()
|
||||
install(FILES "${_mod_lib}" DESTINATION lib COMPONENT libreaktor OPTIONAL)
|
||||
endif()
|
||||
install(DIRECTORY include/reaktor DESTINATION include COMPONENT libreaktor)
|
||||
install(FILES "${TP}/nuklear/nuklear.h" DESTINATION include COMPONENT libreaktor)
|
||||
install(FILES "${TP}/nukanim/nukanim.h" DESTINATION include COMPONENT libreaktor)
|
||||
@@ -1035,6 +1305,11 @@ if(REAKTOR_INSTALL)
|
||||
configure_file(tools/reaktor.pc.in "${CMAKE_BINARY_DIR}/reaktor.pc" @ONLY)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/reaktor.pc" DESTINATION lib/pkgconfig
|
||||
COMPONENT libreaktor)
|
||||
if(REAKTOR_SHARED_SDL)
|
||||
configure_file(tools/reaktor-shared.pc.in "${CMAKE_BINARY_DIR}/reaktor-shared.pc" @ONLY)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/reaktor-shared.pc" DESTINATION lib/pkgconfig
|
||||
COMPONENT libreaktor)
|
||||
endif()
|
||||
endif()
|
||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/licenses/" DESTINATION share/reaktor/licenses
|
||||
COMPONENT libreaktor)
|
||||
|
||||
@@ -0,0 +1,518 @@
|
||||
# Plan: libreaktor as a shared library
|
||||
|
||||
**Decision (2026-11-02): go.** Three apps together save 14.8%, under the 20%
|
||||
threshold, but four save 20.4% and five 24.2% (Phase 0d), and Reaktor apps
|
||||
are expected to run four or more at a time. Phase 1 starts. Static stays the
|
||||
default.
|
||||
|
||||
## Where things stand
|
||||
|
||||
- **libreaktor is static only.** CMake merges its parts into `libreaktor.a`
|
||||
(`CMakeLists.txt`, the `libreaktor` target), and `tools/libreaktor-pkg.sh`
|
||||
packs it with the headers as a .deb, .rpm, BSD package or .tar.gz.
|
||||
`tools/ci/check-libreaktor.sh` links `examples/consumer` against it.
|
||||
- **No shared-library code exists yet.** No `.so`, no soname, no shared SDL.
|
||||
- **Static stays the default** whatever this plan decides. A shared library is
|
||||
offered beside it, not instead of it.
|
||||
|
||||
## Why consider it at all
|
||||
|
||||
An app is a few MB (stripped Linux showcase: 3.97 MB; 4.3 MB private and
|
||||
11.4 MB resident at run time). On Windows and macOS each app ships alone, so
|
||||
sharing buys little there. The gain is in Linux and BSD packages, where several
|
||||
Reaktor apps could install one copy of the library and share its code pages in
|
||||
memory.
|
||||
|
||||
Two copies of the *same* app already share their code, static or not. A shared
|
||||
library only saves when *different* apps run together, and at most it saves
|
||||
libreaktor's resident code per extra app. Heap, glyph atlases and stylesheets
|
||||
stay private either way. So the saving may be small, and that is why Phase 0
|
||||
measures it before anything is built.
|
||||
|
||||
## Decisions already made (2026-10-24)
|
||||
|
||||
1. **SDL: our own build, shared, under its own name** (option B), for example
|
||||
`libreaktor-sdl3.so`. Built as now: GL out, dynamic API off. Not the
|
||||
distro's SDL, because that:
|
||||
- can load Mesa and LLVM again (the 123.6 MB Linux start in
|
||||
`docs/PERFORMANCE.md`);
|
||||
- sets a minimum SDL version on every distro;
|
||||
- can draw different pixels per distro;
|
||||
- brings `SDL3_DYNAMIC_API` back.
|
||||
2. **Nuklear's struct layouts are part of the ABI.** Apps reach them through
|
||||
the `reaktor/nuklear.h` macros and by reading `ctx->style`, `ctx->input`,
|
||||
`ctx->current` and `ctx->last_widget_state`. Hiding all of that would be a
|
||||
large job for no real gain, since Nuklear is a pinned submodule whose
|
||||
layout changes only when we bump it. Instead, a CI table of `sizeof` and
|
||||
`offsetof` values forces a new soname whenever a layout changes.
|
||||
3. **Style access is settled.** Apps keep `ctx->style`. Three public calls
|
||||
cover the most common reads for clarity: `reaktor_item_spacing`,
|
||||
`reaktor_text_color`, `reaktor_current_font`. Done and merged (`5a8b7f3`).
|
||||
4. **Platforms, in order:** Linux and the BSDs first. Windows was dropped
|
||||
(2026-11-03; see *Later*). macOS (same Team ID, or Homebrew only, since
|
||||
hardened-runtime library validation refuses other developers' dylibs) is
|
||||
in scope at lower priority.
|
||||
|
||||
## Phase 0: measure (go / no-go)
|
||||
|
||||
Goal: know what sharing would save before writing any of it. Needs no new
|
||||
library code.
|
||||
|
||||
1. Build `showcase`, `notepad` and `simple` statically on Linux, as now.
|
||||
2. Run the three together. For each process record, from
|
||||
`/proc/<pid>/smaps_rollup` and `/proc/<pid>/smaps`:
|
||||
- total `Pss`;
|
||||
- `Shared_Clean` and `Private_Clean` of the app's own binary mapping,
|
||||
which is roughly libreaktor's resident code.
|
||||
3. Estimate the shared case: summed PSS minus the libreaktor code that the
|
||||
second and third app would no longer carry.
|
||||
4. Ten launches, medians, as elsewhere in `docs/PERFORMANCE.md`. The numbers
|
||||
go there, with the machine named.
|
||||
5. Put it in a script, `tools/ci/pss.sh`, run in the Debian container that
|
||||
`linux.yml` already uses, so it can be repeated.
|
||||
|
||||
**Go / no-go threshold (agreed 2026-10-30):** go if three different
|
||||
apps running together save at least **20% of their summed PSS**. Disk space
|
||||
does not count toward it; smaller packages would be a separate argument.
|
||||
|
||||
## Phase 0 results (CI, 2026-10-30)
|
||||
|
||||
**What was measured.** `showcase`, `notepad` and `simple` run together, idle,
|
||||
for 10 seconds; ten launches, medians. For each app:
|
||||
|
||||
- **PSS** from `/proc/<pid>/smaps_rollup`: memory it has to itself in full,
|
||||
plus its share of pages it shares with other processes.
|
||||
- **Library pages**: the resident pages of its own binary that hold libreaktor
|
||||
or SDL. Today each app links them statically, so each carries a copy.
|
||||
|
||||
A shared `libreaktor.so` would hold one copy for all three. The saving is the
|
||||
three apps' library pages minus the largest app's, as a share of their summed
|
||||
PSS.
|
||||
|
||||
**Machine.** GitHub `ubuntu-24.04` runner, x86_64, Debian 12 container, GCC
|
||||
Release, Xvfb, no GPU.
|
||||
|
||||
**Two estimates.**
|
||||
|
||||
1. `tools/ci/pss.sh` counts every clean page of each binary as library, so it
|
||||
overcounts by the apps' own code: **21.3%**.
|
||||
|
||||
| | PSS | Clean pages of its binary |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | 9,180 KB | 2,796 KB |
|
||||
| `notepad` | 5,957 KB | 2,208 KB |
|
||||
| `simple` | 5,251 KB | 2,164 KB |
|
||||
|
||||
Summed PSS 20,433 KB; sharing saves 4,366 KB.
|
||||
|
||||
2. `tools/ci/pss-pages.sh` links the three with linker maps and sorts each
|
||||
resident, file-backed page of a binary (from `/proc/<pid>/pagemap`) by the
|
||||
object it came from. Only a page holding nothing but libreaktor or SDL
|
||||
counts: **20.2%**.
|
||||
|
||||
| | PSS | lib | app | mixed | other |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| `showcase` | 9,105 KB | 2,386 KB | 170 KB | 32 KB | 144 KB |
|
||||
| `notepad` | 6,028 KB | 2,090 KB | 16 KB | 24 KB | 132 KB |
|
||||
| `simple` | 5,217 KB | 2,018 KB | 0 KB | 28 KB | 128 KB |
|
||||
|
||||
Summed PSS 20,423 KB; sharing saves 4,120 KB.
|
||||
|
||||
**Still an upper bound.** It assumes the smaller apps use no library page the
|
||||
showcase does not, and leaves out what the dynamic linker costs each app at
|
||||
start (relocations, private GOT pages). Both pull the real figure down, most
|
||||
likely under 20%.
|
||||
|
||||
**Reading.** About 4 MB saved across three apps, on the line. Recommendation
|
||||
so far: no-go, pending a run on a real Linux desktop.
|
||||
|
||||
## Phase 0 results (Linux desktop, 2026-11-02)
|
||||
|
||||
**Machine.** Linux Mint 22.3, Cinnamon on X11, Mesa llvmpipe (no GPU), a KVM
|
||||
guest on an AMD Ryzen 5 4600H with 4 cores, kernel 7.0, GCC Release. Same
|
||||
three apps, ten launches, medians.
|
||||
|
||||
1. `pss.sh`: **19.0%**. Summed PSS 24,157 KB; sharing saves 4,602 KB.
|
||||
|
||||
| | PSS | Clean pages of its binary |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | 14,224 KB | 2,898 KB |
|
||||
| `notepad` | 5,386 KB | 2,322 KB |
|
||||
| `simple` | 4,553 KB | 2,262 KB |
|
||||
|
||||
2. `pss-pages.sh`: **17.3%**. Summed PSS 24,200 KB; sharing saves 4,176 KB.
|
||||
|
||||
| | PSS | lib | app | mixed | other |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| `showcase` | 14,282 KB | 2,606 KB | 232 KB | 32 KB | 148 KB |
|
||||
| `notepad` | 5,382 KB | 2,124 KB | 80 KB | 24 KB | 136 KB |
|
||||
| `simple` | 4,516 KB | 2,064 KB | 36 KB | 24 KB | 132 KB |
|
||||
|
||||
**Reading.** As expected, the desktop stacks grow the showcase's PSS by about
|
||||
5 MB, while the library pages stay at about 4 MB. Both estimates are upper
|
||||
bounds, and both are under 20%. **No-go**, unless a run on real GPU hardware
|
||||
differs.
|
||||
|
||||
## Phase 0b: a real shared build, measured (2026-11-02)
|
||||
|
||||
The estimates above are upper bounds, so a working prototype was built to
|
||||
measure the real difference. `-DREAKTOR_SHARED_PROTO=ON` (with
|
||||
`-DCMAKE_POSITION_INDEPENDENT_CODE=ON`) links the runtime, the core, SDL,
|
||||
FreeType, plutosvg, plutovg and onlay into `libreaktor-proto.so`; each sample
|
||||
keeps its modules (or their `_none` twins) and exports their symbols back to
|
||||
the library. No soname, no hidden symbols: everything is exported, which is
|
||||
the worst case for relocations and calls.
|
||||
|
||||
Same desktop as above; ten launches, medians, static and shared measured in
|
||||
the same session.
|
||||
|
||||
**Memory** (`pss.sh`, the three apps together, idle):
|
||||
|
||||
| | static | shared | saved |
|
||||
| --- | --- | --- | --- |
|
||||
| `showcase` | 14,261 KB | 13,007 KB | 1,254 KB |
|
||||
| `notepad` | 5,370 KB | 4,239 KB | 1,131 KB |
|
||||
| `simple` | 4,501 KB | 3,453 KB | 1,048 KB |
|
||||
| **summed** | **24,152 KB** | **20,698 KB** | **3,454 KB (14.3%)** |
|
||||
|
||||
The library's pages that each app dirties (GOT, relocated data) are about
|
||||
124 KB per app in `simple`.
|
||||
|
||||
**Disk:** 11.4 MB for the three static binaries, against 6.2 MB shared
|
||||
(`libreaktor-proto.so` 5.0 MB, unstripped, plus 1.16 MB of apps).
|
||||
|
||||
**Start:** the dynamic loader takes 0.1 to 0.2 ms for either build;
|
||||
`showcase` goes from 19,525 to 21,709 relocations. CPU in the first 3
|
||||
seconds: `simple` 40 ms both, `showcase` 220 ms static and 230 ms shared.
|
||||
|
||||
**Frame cost** (`bench --no-vsync`, five runs):
|
||||
|
||||
| | build | render | whole frame |
|
||||
| --- | --- | --- | --- |
|
||||
| static | 0.04 ms | 0.05 ms | 1.46 to 1.63 ms |
|
||||
| shared | 0.05 ms | 0.10 ms | 1.48 to 1.53 ms |
|
||||
| shared, `-fno-semantic-interposition` | 0.04 ms | 0.08 ms | 1.40 to 1.61 ms |
|
||||
| shared, that and `-Wl,-Bsymbolic-functions` | 0.04 ms | 0.06 ms | as static |
|
||||
|
||||
Present (llvmpipe) dominates the frame, so fps does not change.
|
||||
|
||||
**Why the shared build was slower** (`perf`, both builds):
|
||||
|
||||
- **Frame.** The extra render time is in `nk_sdl_render_ex`, Nuklear's
|
||||
SDL drawing loop. With every symbol exported and interposable, GCC stops
|
||||
inlining and specialising small functions inside SDL and Nuklear:
|
||||
`SDL_floorf`, `SDL_roundf`, `SDL_memcmp`, `nk_buffer_memory`, `nk_vec2`
|
||||
become real calls, and the `.constprop`/`.isra` clones go. Calls between
|
||||
files then go through the PLT. `-fno-semantic-interposition` restores the
|
||||
inlining (build back to static); `-Bsymbolic-functions` binds the calls
|
||||
inside the library directly (render back to static). Hidden symbols
|
||||
(Phase 1, item 2) do both, so Phase 1 needs no extra flags.
|
||||
- **Start.** `showcase` uses about 10 ms more CPU in its first 3 s
|
||||
(`perf stat -r 10`: 222 against 232 ms), split about evenly between user
|
||||
and kernel time, with the same page faults (4,170 against 4,199). Lazy
|
||||
binding in the dynamic loader (`_dl_fixup`, `_dl_lookup_symbol_x`) is
|
||||
about 0.3 ms of it; the rest is the slower code above running during start
|
||||
(font rasterising, the first frames) and the kernel mapping one more
|
||||
library. With both flags the difference falls inside run-to-run noise
|
||||
(225 against 234 ms in one pass).
|
||||
|
||||
**Reading.** The real saving is 14.3%, under the 20% threshold and under the
|
||||
17.3% estimate. As built first it cost about 10 ms of start CPU in the showcase
|
||||
and twice Reaktor's render time; with hidden or directly bound symbols both
|
||||
costs go away. The disk saving
|
||||
(46%) is the stronger argument, but it was agreed not to count toward the
|
||||
threshold.
|
||||
|
||||
## Phase 0c: the same, with hidden symbols (2026-11-02)
|
||||
|
||||
`-DREAKTOR_SHARED_PROTO_HIDE=ON` adds a version script that exports only
|
||||
`reaktor_*`, `nk_*`, `nka_*`, `SDL_*` and the five FreeType and plutovg
|
||||
symbols the modules call, and compiles the library's parts with
|
||||
`-fno-semantic-interposition`. Everything else (X11 and Wayland glue,
|
||||
FreeType's and plutovg's insides) binds inside the library. Exports fall from
|
||||
4,653 to 3,365; SDL's own API is 1,961 of them, as it would be as
|
||||
`libreaktor-sdl3.so`. Every sample starts with `LD_BIND_NOW=1`, so nothing
|
||||
it needs is hidden.
|
||||
|
||||
| | static | shared | shared, hidden |
|
||||
| --- | --- | --- | --- |
|
||||
| summed PSS, three apps | 24,152 KB | 20,698 KB | 20,617 KB |
|
||||
| saving against static | | 14.3% | 14.6% |
|
||||
| library pages each app dirties (`simple`) | | 124 KB | 116 KB |
|
||||
| `showcase` relocations | 19,525 | 21,709 | 20,559 |
|
||||
| `bench` build / render | 0.04 / 0.06 ms | 0.05 / 0.10 ms | 0.04 / 0.08 ms |
|
||||
| `showcase` CPU, first 3 s | 216 to 222 ms | 225 to 232 ms | 224 to 230 ms |
|
||||
|
||||
**Reading.** Hiding symbols does not move memory: 81 KB of 20.7 MB. The
|
||||
saving stays at about 14.5%. It does recover build time, and half the render
|
||||
time. The rest of render is the calls into SDL, which go through the PLT
|
||||
because SDL's API stays exported. With SDL as its own library, as decided,
|
||||
that cost stays. Binding SDL inside libreaktor (`-Bsymbolic-functions`,
|
||||
Phase 0b) removes it, but then an app cannot have SDL from anywhere else.
|
||||
|
||||
**Seen and not explained:** in three of six early runs of `pss.sh` on this
|
||||
build, `notepad` had exited by the time it was measured, with nothing in its
|
||||
log. A signal, a closed window, Ctrl+Q and the menu's Quit all end it exactly
|
||||
so: status 0, empty log; a crash would have left a core dump and a kernel
|
||||
line, and there was neither. Since then the runtime logs one `quitting:` line
|
||||
with the reason, and `pss.sh` prints how each app ended. A soak of 15 rounds
|
||||
of ten launches for the hidden build and 15 for the static one, alternating,
|
||||
ran clean (300 launches each of the three apps). Not reproduced; most likely
|
||||
something on the live desktop asked notepad to quit.
|
||||
|
||||
## Phase 0d: more apps at once (2026-11-02)
|
||||
|
||||
The saving grows with each extra app, since each one stops carrying its own
|
||||
copy of the library. `pss.sh -a` takes the list of apps. The fourth and fifth
|
||||
apps are copies of `notepad` and `simple` under new names (`notepad2`,
|
||||
`simple2`): a copy is another file, so statically it shares nothing with the
|
||||
original, as a different app would not. Hidden-symbol shared build against
|
||||
static, same desktop, ten launches, medians.
|
||||
|
||||
| apps together | static | shared | saved | saving |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 3 (`showcase`, `notepad`, `simple`) | 24,200 KB | 20,630 KB | 3,570 KB | 14.8% |
|
||||
| 4 (+ `notepad2`) | 29,802 KB | 23,726 KB | 6,076 KB | **20.4%** |
|
||||
| 5 (+ `simple2`) | 34,437 KB | 26,087 KB | 8,350 KB | **24.2%** |
|
||||
|
||||
Each extra app saves about 2.3 to 2.5 MB: its own library pages, and a
|
||||
little of everyone else's PSS as the shared pages split one more way.
|
||||
|
||||
**Reading.** With four different Reaktor apps running together, sharing
|
||||
crosses the 20% threshold; with five it saves about a quarter. With three it
|
||||
does not. Real different apps carry a little more code of their own than
|
||||
these copies, which pulls the figures down slightly. Whether to go now turns
|
||||
on how many Reaktor apps a user would really run at once.
|
||||
|
||||
## Running Phase 0 on a Linux desktop
|
||||
|
||||
Needs GCC with GNU ld from binutils 2.38 or later (`-Map=DIR/` writes one map
|
||||
per program; not lld or gold), CMake, Ninja, `readelf`, GNU `dd` and `od`, a
|
||||
kernel with `smaps_rollup` (4.14+). No root needed: an unprivileged
|
||||
`pagemap` read still has the present and file-page bits.
|
||||
|
||||
From the checkout, on branch `shared-phase0`:
|
||||
|
||||
```sh
|
||||
git submodule update --init --recursive
|
||||
./build.sh # build/showcase, build/notepad, build/simple
|
||||
sh tools/ci/pss.sh build # estimate 1, on the desktop's own display
|
||||
sh tools/ci/pss-pages.sh # estimate 2; builds build-map with maps first
|
||||
```
|
||||
|
||||
Without `-x` both run on the current `DISPLAY` (or Wayland), which is the
|
||||
point of a desktop run. `-x Xvfb` starts a virtual display instead, as CI does;
|
||||
`-n RUNS` changes the ten launches; `-w WRAP` runs each app under a wrapper.
|
||||
Close any running Reaktor app first: the showcase is single instance, so a
|
||||
running copy would take its launch, and another app's pages would skew PSS.
|
||||
|
||||
Output lands in `smoke/pss/` and `smoke/pss-pages/`: `runs.txt` holds each
|
||||
launch's raw numbers (kB), `saving.txt` the per-launch saving, and each app's
|
||||
`.log` its output. The last lines printed are the medians and the saving
|
||||
against 20%.
|
||||
|
||||
Worth noting with the result: distribution, desktop (X11 or Wayland), GPU or
|
||||
not, and whether the numbers differ from CI's. A desktop run loads the real
|
||||
input-method, accessibility and tray stacks, so PSS grows and the percentage is
|
||||
likely to fall.
|
||||
|
||||
## Phase 1: the shared build (started 2026-11-02)
|
||||
|
||||
**Status.** Items 1 to 4 are in: `-DREAKTOR_SHARED=ON` builds
|
||||
`lib/libreaktor.so.0` (2.0 MB) and `libreaktor-sdl3.so.0` (2.9 MB, SDL 3.4.18
|
||||
with `core/sdl/no_dynapi.h` as for the static build) beside `libreaktor.a`,
|
||||
and links the samples and tests to them. Exports come from a version script,
|
||||
`tools/reaktor.map`, not an export macro: 1,185 symbols, all `reaktor_`, `nk_`,
|
||||
`nka_` and the five FreeType and plutovg calls the modules make. The modules
|
||||
reach some `reaktor_` functions that are not in `include/reaktor/`, so for now
|
||||
the `reaktor_*` glob exports those too; Phase 2's symbol check will draw the
|
||||
line. The measurement prototype (`REAKTOR_SHARED_PROTO`, commit `0948611`) is
|
||||
gone.
|
||||
|
||||
Measured as in Phase 0d: three apps 24,200 KB static against 20,659 KB
|
||||
shared (14.6%), four 29,802 KB against 23,810 KB (20.1%). `bench` build and
|
||||
render 0.05 and 0.08 ms; `showcase` CPU in its first 3 s 232 ms, static 231 ms.
|
||||
All unit tests pass in both builds.
|
||||
|
||||
Item 5 is in too. With `REAKTOR_SHARED`, `cmake --install` adds to the
|
||||
static files `libreaktor.so*`, `libreaktor-sdl3.so*` and
|
||||
`libreaktor-modules.a`, the modules (and mojibake and kb_text_shape) for apps
|
||||
built outside the tree. Such an app links `libreaktor.so`, then the modules
|
||||
archive, which fills in what the library calls, then `libreaktor-sdl3.so`,
|
||||
and exports the modules back with `-Wl,--export-dynamic`. That is what
|
||||
`reaktor-shared.pc` and the CMake target `reaktor::shared` give it; in CMake,
|
||||
`reaktor::reaktor` stays the static one. Since the `.a` and the `.so` share a
|
||||
`lib/`, `reaktor.pc` then names `-l:libreaktor.a`, so it stays static.
|
||||
|
||||
Checked by hand: `examples/consumer` linked statically, linked with
|
||||
`-DCONSUMER_SHARED=ON`, and `simple.c` built with `pkg-config reaktor` and
|
||||
`reaktor-shared` all draw the same pixels and the same accessibility tree as
|
||||
the tree's own `simple`. Phase 2, item 3 puts that into `check-libreaktor.sh`.
|
||||
|
||||
|
||||
1. A `REAKTOR_SHARED` option, default `OFF`, building `libreaktor.so` with a
|
||||
soname (`libreaktor.so.0`) beside the static archive.
|
||||
2. Only the `include/reaktor/` API exported; everything else hidden
|
||||
(`-fvisibility=hidden` and an export macro on the public declarations).
|
||||
3. SDL built as `libreaktor-sdl3.so`, which `libreaktor.so` links.
|
||||
4. Optional modules keep working: an app still links a module or its `_none`
|
||||
twin, so each module's code stays out of the shared core.
|
||||
5. `reaktor.pc` and `reaktorConfig.cmake` learn the shared variant.
|
||||
|
||||
## Phase 2: keeping the ABI honest (in, 2026-11-02)
|
||||
|
||||
**Status.** All three items are in, and CI's x86-64 job runs them in a step
|
||||
of its own (`Shared libreaktor`) on a `-DREAKTOR_SHARED=ON` build:
|
||||
|
||||
- `tools/ci/check-abi.sh` compiles `tools/abi/abi.c` (just `reaktor.h`) with
|
||||
debug types and has gdb print, with `ptype /o`, every `reaktor_` struct,
|
||||
union and enum in `include/reaktor/`, `nk_window` and `nk_input`, every
|
||||
Nuklear type `reaktor/nuklear.h` renames, and the value of every `NK_`
|
||||
constant it renames. Nothing is copied out of Nuklear by hand. The output
|
||||
must match `tools/abi/libreaktor.so.0-ARCH.abi`, ARCH being the compiler's
|
||||
target (`cc -dumpmachine`); otherwise the soname must go up and the table be
|
||||
rewritten with `-u`. Adding one field to `reaktor_shortcut` fails it. Only
|
||||
x86_64 has a table so far (12,266 lines, made here). Every native Linux job
|
||||
(x86-64, x86, arm64) runs the check in a step of its own and uploads what it
|
||||
wrote to `smoke/abi/`; a missing table is a warning, exit status 3, so the
|
||||
x86 and arm64 tables, and the x86_64 one if CI's older gdb lays it out
|
||||
differently, come from CI's artifact.
|
||||
- `tools/ci/check-exports.sh` holds the built library to `tools/reaktor.map`,
|
||||
which lists Reaktor's names instead of `reaktor_*`. Two symbol versions:
|
||||
`LIBREAKTOR_0` holds the 149 public functions the library defines and
|
||||
Nuklear's and nukanim's APIs; `LIBREAKTOR_PRIVATE_0` the 34 non-public calls
|
||||
the modules make and five FreeType and plutovg ones. It fails on a name
|
||||
exported but not listed, listed but not exported, public but in neither the
|
||||
library nor the modules, under `LIBREAKTOR_0` without being public, private
|
||||
and no longer called by the modules, private and called by an app's own
|
||||
code (samples and tests linked to the library), or under the wrong version.
|
||||
`tests/launchtest.c`, which reaches past `include/reaktor/`, links the
|
||||
archives in a shared build (`reaktor_add_app(... STATIC ...)`), so nothing
|
||||
is exported for a test. Exports fell from 1,185 to 1,030.
|
||||
- `check-libreaktor.sh` links `examples/consumer` against `libreaktor.so`
|
||||
too, where the install has it, checks the program needs it, and requires
|
||||
the same pixels and accessibility tree as the built `simple`.
|
||||
|
||||
|
||||
1. The CI `sizeof` / `offsetof` table for the Nuklear structs apps can see,
|
||||
and for Reaktor's own public structs. A change fails CI until the soname
|
||||
is bumped and the table regenerated.
|
||||
2. A check that the exported symbol list matches `include/reaktor/`, so
|
||||
nothing internal leaks out and nothing public is missing.
|
||||
3. `check-libreaktor.sh` gains a shared run: `examples/consumer` linked
|
||||
against the `.so` must draw the same pixels as the static `simple`.
|
||||
|
||||
## Phase 3: packages (in, 2026-11-02)
|
||||
|
||||
**Status.** `tools/libreaktor-pkg.sh -s` builds with `REAKTOR_SHARED` (and
|
||||
`-b` takes a shared build as it is). When the install holds `libreaktor.so`,
|
||||
the package splits in three: `libreaktor-sdl3-0` (`libreaktor-sdl3.so.0*`
|
||||
and SDL's license), `libreaktor0` (`libreaktor.so.0*`, the other licenses,
|
||||
`NOTICE.md`; needs the first) and the development package under its old
|
||||
name (`libreaktor-dev`, `libreaktor-devel`, `libreaktor` on the BSDs) with
|
||||
the headers, both archives, the `.so` links, `reaktor.pc`,
|
||||
`reaktor-shared.pc` and the CMake files; it needs both. Each file is in one
|
||||
package. A static build packs one package, renamed `libreaktor-static` in
|
||||
every format (2026-11-03), so a release can carry both; it and the split's
|
||||
development package install the same headers and conflict with each other
|
||||
in every format. `/opt/reaktor/lib` is
|
||||
not on the loader's path, so `reaktor-shared.pc` and `reaktor::shared` add
|
||||
an rpath to the install's `lib/`.
|
||||
|
||||
Checked here: the three `.deb`s, their dependencies and files, and
|
||||
`examples/consumer -DCONSUMER_SHARED=ON` built against them, unpacked, which
|
||||
draws the same as the built `simple`; a static build still packs one
|
||||
`libreaktor-dev`; `-f tar` writes three tarballs. CI now packs the shared
|
||||
build as `.deb`s on x86-64, installs them, builds the shared consumer,
|
||||
removes `libreaktor-dev` and runs it on the two runtime packages alone; the
|
||||
rpm job does the same with `-s`. The rpm, FreeBSD, OpenBSD and NetBSD
|
||||
branches are written but have not run: rpmbuild and the BSD tools are not on
|
||||
this machine. `bsd.yml` packs the shared build on each BSD and runs the shared
|
||||
consumer on the runtime packages alone, in a step that warns rather than
|
||||
fails until it has passed there.
|
||||
|
||||
|
||||
1. `tools/libreaktor-pkg.sh` packs the shared library and SDL as their own
|
||||
packages (`libreaktor0`, `libreaktor-sdl3-0` or the distro's spelling) and
|
||||
the headers as a `-dev` package.
|
||||
2. The samples get a shared-linked variant to prove a package installs and
|
||||
runs as intended.
|
||||
3. BSD packages follow the same split.
|
||||
|
||||
## In releases (2026-11-03)
|
||||
|
||||
CI builds the shared library next to the static one, and a release carries
|
||||
both. Every Linux job (x86-64, x86, arm64, and armhf and riscv64 cross-built)
|
||||
builds `-DREAKTOR_SHARED=ON`, checks it with `check-libreaktor.sh` (natively,
|
||||
or on the emulated machine after the builder installs it) and uploads
|
||||
`libreaktor-VERSION-linux-ARCH.tar.gz` and the three split `.deb`s;
|
||||
the rpm job adds the split rpms; the x86-64 BSD jobs add
|
||||
`libreaktor-VERSION-OS-x86-64.tar.gz`. The static tarballs beside them, on
|
||||
Linux and the BSDs, are now `libreaktor-static-VERSION-OS-ARCH.tar.gz`,
|
||||
matching the `libreaktor-static` package; Windows, macOS and the web, which
|
||||
have only the static library, are named `libreaktor-static-` too. Installs
|
||||
that ship (`check-libreaktor.sh`, `libreaktor-pkg.sh`, CI's own) pass
|
||||
`--strip`, which strips the two shared libraries and leaves the archives:
|
||||
`libreaktor.so.0` 2.04 to 1.87 MB, `libreaktor-sdl3.so.0` 2.92 to 2.66 MB,
|
||||
exports unchanged. All of them are `package-*`
|
||||
artifacts, so `release.yml` publishes them with the rest, and its notes say
|
||||
how to use them. Not covered: the BSDs' arm64 (cross-built in `bsd-arm64`),
|
||||
Windows, macOS and the web.
|
||||
|
||||
## Later, lower priority
|
||||
|
||||
- ~~**Windows:** an MSIX framework package carrying `reaktor.dll` and SDL, which
|
||||
packaged apps declare as a dependency.~~ Dropped (2026-11-03): each Windows
|
||||
app ships alone, so sharing buys little, and a framework package serves only
|
||||
MSIX-packaged apps while needing a signing certificate, an export macro on
|
||||
every public declaration and the DLL C runtime. Windows stays static.
|
||||
- **macOS:** a framework signed with the app's Team ID, or a Homebrew formula,
|
||||
since apps from other developers cannot load it under the hardened runtime.
|
||||
Homebrew is ruled out (2026-11-03: no access), which leaves only the
|
||||
framework, shared by apps under one Team ID. Kept in scope (2026-11-03).
|
||||
It saves memory only when several of those apps run at once and the
|
||||
framework is installed once, in `/Library/Frameworks`, not inside each
|
||||
`.app`. Still open: an Apple Developer ID to sign and notarize it, and a
|
||||
universal binary or one per architecture. It cannot be built or checked on
|
||||
the Linux machine this plan was worked on; `macos.yml` would be its check.
|
||||
|
||||
**Written, not yet run (2026-11-03).** `-DREAKTOR_SHARED=ON` on macOS builds
|
||||
`Frameworks/Reaktor.framework` (`Versions/A`, install name
|
||||
`@rpath/Reaktor.framework/...`, identifier `io.github.alpaq92.reaktor`)
|
||||
from the same parts plus SDL, linked in with `-force_load`, so there is no
|
||||
`libreaktor-sdl3`: no system SDL stands to be confused with ours. ld64 has
|
||||
no version script, so CMake turns `tools/reaktor.map` into an exported
|
||||
symbol list (190 names, checked here with `cmake -P`); the framework binds
|
||||
its calls into the modules at load (`-undefined dynamic_lookup`) and apps
|
||||
link with `-export_dynamic`, which also keeps those functions through
|
||||
`-dead_strip`. `reaktor::shared` links the framework and
|
||||
`libreaktor-modules.a`, with an rpath to the install and to
|
||||
`/Library/Frameworks`. `macos.yml` builds it on both runners, runs
|
||||
`check-libreaktor.sh` on it and uploads `libreaktor-VERSION-macos-ARCH.zip`.
|
||||
Per architecture, signed ad hoc, as today.
|
||||
|
||||
**Universal too (2026-11-03).** A third job in `macos.yml` takes the two
|
||||
per-architecture zips, joins every Mach-O file and archive in them with
|
||||
`lipo` (the framework, `libreaktor-modules.a`, `libreaktor.a`), requires
|
||||
every other file to be the same in both, signs the framework again ad hoc,
|
||||
builds the shared consumer for `arm64;x86_64` against it, runs it, and
|
||||
uploads `libreaktor-VERSION-macos-universal.zip`. If CMake writes a path
|
||||
that differs between the two runners into the config or `.pc` files, that
|
||||
check fails and the file needs one form for both.
|
||||
|
||||
**No Developer ID (2026-11-03), and none soon.** So the framework stays
|
||||
signed ad hoc and is not notarized, like the rest of the macOS release.
|
||||
Without a Team ID, "apps under one Team ID" means apps that do not turn on
|
||||
the hardened runtime: its library validation is what refuses a framework
|
||||
from another signer, and an ad hoc one has no signer to match. Reaktor's
|
||||
own apps do not turn it on. A framework downloaded from the release carries
|
||||
the quarantine flag, so the person installing it clears that once
|
||||
(`xattr -dr com.apple.quarantine`) before apps can load it.
|
||||
|
||||
## Open questions
|
||||
|
||||
1. ~~Go or no-go.~~ Go (2026-11-02), on four or more apps. The threshold is 20% (agreed 2026-10-30). CI says 20.2% at
|
||||
most, and a Linux desktop says 17.3% (2026-11-02). That points to no-go;
|
||||
a run on a desktop with a real GPU would confirm it. A real shared
|
||||
build (Phase 0b) saves 14.3%, and 14.6% with hidden symbols (Phase 0c),
|
||||
with three apps. Four apps save 20.4%, five 24.2% (Phase 0d).
|
||||
@@ -11,7 +11,7 @@ Tired of C having no cross-platform GUI — nothing like
|
||||
[Shaft](https://github.com/ShaftUI/Shaft) or
|
||||
[Freya](https://github.com/marc2332/freya) — and of toolkits that want hundreds
|
||||
of megabytes to put a dialog on screen? No? But I was, so I wrote Reaktor:
|
||||
complete without being big. A 2.2 MB binary, 7–13 MB of RAM, and no GPU
|
||||
complete without being big. A 2.1 MB binary, 7–13 MB of RAM, and no GPU
|
||||
required.
|
||||
|
||||
**[Try the showcase in your browser](https://alpaq92.github.io/Reaktor/)** — the
|
||||
@@ -23,7 +23,7 @@ yourself.
|
||||
> ⚠️ **Reaktor is in active development**, and breaking changes might occur.
|
||||
|
||||
<p align="center">
|
||||
<a href="docs/PERFORMANCE.md"><img src="docs/benchmark.svg" alt="Two bar charts of drawing 64 rotating boxes at 60 fps in an 800x600 window. Memory: Reaktor 8.9 MB, the same binary on D3D11 58.2 MB, on D3D12 121.3 MB and on OpenGL 69.3 MB, Flutter 90.8 MB, Electron 157.6 MB, Kotlin Multiplatform 667.4 MB. Steady-state CPU as a percent of one core: Reaktor 7.0%, D3D11 13.0%, D3D12 6.0%, OpenGL 6.4%, Flutter 15.6%, Electron 26.1%, Kotlin Multiplatform 33.5%"></a>
|
||||
<a href="docs/PERFORMANCE.md"><img src="docs/benchmark.svg" alt="Two bar charts of drawing 64 rotating boxes at 60 fps in an 800x600 window. Memory: Reaktor 9.1 MB, the same binary on D3D12 120.8 MB and on OpenGL 69.0 MB, Flutter 132.7 MB, Electron 156.3 MB, Kotlin Multiplatform 668.7 MB. Steady-state CPU as a percent of one core: Reaktor 7.1%, D3D12 4.1%, OpenGL 6.4%, Flutter 15.3%, Electron 19.6%, Kotlin Multiplatform 29.4%"></a>
|
||||
</p>
|
||||
|
||||
How, and on what, is in [PERFORMANCE.md](docs/PERFORMANCE.md).
|
||||
@@ -34,8 +34,8 @@ How, and on what, is in [PERFORMANCE.md](docs/PERFORMANCE.md).
|
||||
spinners, combos, a color picker, date and time pickers, sidebar, tabs, a
|
||||
menu bar, tables, trees and a splitter, with tooltips; rows drag between
|
||||
lists; all of Nuklear underneath, under Reaktor's names.
|
||||
- **Layers** — menus in windows of their own, in-window dialogs, questions,
|
||||
toasts, more windows, and a tray icon with a menu.
|
||||
- **Layers** — menus in windows of their own, in-window dialogs, modal
|
||||
questions, toasts, more native windows, and a tray icon with its own menu.
|
||||
- **Services** — system open, save and folder pickers, timers, main-thread
|
||||
posting, settings that persist, an undo stack, system notifications, and
|
||||
printing and PDF export.
|
||||
@@ -52,8 +52,9 @@ How, and on what, is in [PERFORMANCE.md](docs/PERFORMANCE.md).
|
||||
oscillators, noise and shakes; colors blended in five spaces; and text
|
||||
that arrives a glyph at a time, idle once everything settles.
|
||||
- **Modular** — accessibility, localization, text shaping, settings, the tray,
|
||||
popup windows, notifications and printing each swap for a stub at build
|
||||
time, and only what they drew stops being drawn; every other pixel stays.
|
||||
popup windows, notifications, printing and the Inspector each swap for a
|
||||
stub at build time, and only what they drew stops being drawn; every other
|
||||
pixel stays.
|
||||
- **Windows, macOS, Linux, the BSDs and WebAssembly** from one set of sources,
|
||||
on one software rasterizer, at any display scale: x86 and ARM everywhere,
|
||||
and RISC-V on Linux ([Platforms](docs/DOCUMENTATION.md#platforms)).
|
||||
@@ -92,8 +93,11 @@ sh tools/libreaktor-pkg.sh -i
|
||||
It lands in `/opt/reaktor` (`/usr/local/reaktor` on the BSDs); build against it
|
||||
with `-DCMAKE_PREFIX_PATH=/opt/reaktor`, or `pkg-config` with
|
||||
`PKG_CONFIG_PATH=/opt/reaktor/lib/pkgconfig`. Remove it with the system's
|
||||
package manager: `libreaktor-dev` on Debian, `libreaktor-devel` on Fedora,
|
||||
`libreaktor` on the BSDs.
|
||||
package manager: it is `libreaktor` everywhere. With `-s` it also
|
||||
builds `libreaktor.so` and packs three packages instead: `libreaktor-sdl3-0`
|
||||
and `libreaktor0`, which an app needs to run, and `libreaktor-shared` to
|
||||
build one. `libreaktor` and `libreaktor-shared` conflict; install one or the
|
||||
other.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -119,8 +123,10 @@ value and position.
|
||||
## Made of
|
||||
|
||||
[Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) draws the widgets.
|
||||
[SDL3](https://github.com/libsdl-org/SDL) supplies the window, input, tray and
|
||||
software renderer. Reaktor's own CSS engine reads the stylesheets, and
|
||||
[SDL3](https://github.com/libsdl-org/SDL) supplies the window, input and
|
||||
software renderer, and the tray on Windows and macOS; on Linux and the BSDs
|
||||
the tray is Reaktor's, over libdbus. Reaktor's own CSS engine reads the
|
||||
stylesheets, and
|
||||
[Onlay](https://github.com/Alpaq92/Onlay), a fork of
|
||||
[randrew/layout](https://github.com/randrew/layout), computes the rectangles.
|
||||
[NukAnim](https://github.com/Alpaq92/NukAnim), a port of ImAnim, moves them.
|
||||
|
||||
+11
-10
@@ -32,9 +32,10 @@ Reaktor runs four times — `reaktor-software`, its default, and
|
||||
`reaktor-d3d11`, `reaktor-d3d12` 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 three 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. An arm whose renderer would not start is skipped, not measured
|
||||
under another renderer's name.
|
||||
is built only when `REAKTOR_RENDERERS` names it, which the `reaktor-opengl`
|
||||
arm's build does. An arm whose renderer would not start is skipped, not measured
|
||||
under another renderer's name. The chart dates its arms: Reaktor's three are
|
||||
re-measured for a release, the others last on 2026-10-24.
|
||||
|
||||
## What every arm draws
|
||||
|
||||
@@ -150,14 +151,14 @@ MSVC 14.44 Release, the C runtime linked in:
|
||||
|
||||
| Program | Bytes |
|
||||
| --- | --- |
|
||||
| `bench.exe` | 2,395,136 |
|
||||
| `simple.exe` | 2,404,864 |
|
||||
| `notepad.exe` | 2,518,016 |
|
||||
| `showcase.exe` | 3,585,536 |
|
||||
| `bench.exe` | 2,352,640 |
|
||||
| `simple.exe` | 2,362,880 |
|
||||
| `notepad.exe` | 2,497,536 |
|
||||
| `showcase.exe` | 3,438,592 |
|
||||
|
||||
The C runtime is 220–260 KB of each; a default `./build.ps1` links its DLL
|
||||
instead. Only the showcase links the three optional modules, and Text is
|
||||
0.7 MB of the difference ([Modules](../docs/PERFORMANCE.md#modules)).
|
||||
The C runtime is about 220 KB of each; a default `./build.ps1` links its DLL
|
||||
instead. The showcase links every module and `notepad` three, and Text is
|
||||
0.6 MB of the difference ([Modules](../docs/PERFORMANCE.md#modules)).
|
||||
|
||||
The v0.2.0 downloads, as GitHub Actions built and published them:
|
||||
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ function Get-Arm([string]$name) {
|
||||
@{ exe = Join-Path $root "build\bench.exe"
|
||||
args = @("--renderer", "opengl")
|
||||
dir = $root
|
||||
make = "./build.ps1 bench -DREAKTOR_SDL_GL=ON" }
|
||||
make = "./build.ps1 bench -DREAKTOR_RENDERERS=direct3d11,direct3d12,opengl" }
|
||||
}
|
||||
"shaft" {
|
||||
@{ exe = Join-Path $here "shaft-bench\.build\release\ShaftBench.exe"
|
||||
|
||||
+5
-8
@@ -117,6 +117,7 @@ reaktor_a11y_add(reaktor_a11y *a, unsigned char role, const char *name,
|
||||
|
||||
if (id == a->focus_id) state |= REAKTOR_A11Y_FOCUSED;
|
||||
|
||||
if ((sl = probe(a->index, a->index_gen, id, 1))) sl->val = a->count[f] + 1;
|
||||
n = &a->node[f][a->count[f]++];
|
||||
n->id = id;
|
||||
n->parent = parent;
|
||||
@@ -134,12 +135,11 @@ reaktor_a11y_add(reaktor_a11y *a, unsigned char role, const char *name,
|
||||
static reaktor_a11y_node *
|
||||
node_of(reaktor_a11y *a, unsigned id)
|
||||
{
|
||||
int f = a->front, i;
|
||||
int i;
|
||||
|
||||
if (!a->building || !id) return NULL;
|
||||
for (i = a->count[f] - 1; i >= 0; i--)
|
||||
if (a->node[f][i].id == id) return &a->node[f][i];
|
||||
return NULL;
|
||||
i = slot_get(a->index, a->index_gen, id) - 1;
|
||||
return i >= 0 ? &a->node[a->front][i] : NULL;
|
||||
}
|
||||
|
||||
static const char *
|
||||
@@ -199,6 +199,7 @@ reaktor_a11y_begin(reaktor_a11y *a, const char *window_name,
|
||||
a->change_count = 0;
|
||||
a->building = 1;
|
||||
a->bucket_gen++;
|
||||
a->index_gen++;
|
||||
if (a->pool_gen == 0) a->pool_gen = 1;
|
||||
|
||||
if (a->pool_used > REAKTOR_A11Y_POOL - REAKTOR_A11Y_POOL / 4 ||
|
||||
@@ -252,10 +253,6 @@ reaktor_a11y_end(reaktor_a11y *a)
|
||||
a->building = 0;
|
||||
a->depth = 0;
|
||||
|
||||
a->index_gen++;
|
||||
for (i = 0; i < ncur; i++)
|
||||
if ((sl = probe(a->index, a->index_gen, cur[i].id, 1))) sl->val = i + 1;
|
||||
|
||||
for (i = 1; i < ncur; i++) {
|
||||
struct nk_rect b = cur[i].bounds;
|
||||
unsigned up = cur[i].parent;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -166,22 +165,6 @@ const char *reaktor_path_leaf(const char *path)
|
||||
return leaf;
|
||||
}
|
||||
|
||||
char *reaktor_c_locale_keep(int numeric)
|
||||
{
|
||||
const char *now = setlocale(numeric ? LC_NUMERIC : LC_ALL, NULL);
|
||||
size_t n = now ? strlen(now) + 1 : 0;
|
||||
char *kept = n ? (char *)malloc(n) : NULL;
|
||||
|
||||
if (kept) memcpy(kept, now, n);
|
||||
return kept;
|
||||
}
|
||||
|
||||
void reaktor_c_locale_put(int numeric, char *kept)
|
||||
{
|
||||
setlocale(numeric ? LC_NUMERIC : LC_ALL, kept ? kept : "C");
|
||||
free(kept);
|
||||
}
|
||||
|
||||
#define REGISTERED_MAX 64
|
||||
|
||||
static reaktor_builtin g_registered[REGISTERED_MAX];
|
||||
|
||||
@@ -15,9 +15,6 @@ char *reaktor_path_from_cwd(const char *path);
|
||||
int reaktor_grow(void **p, int *cap, int need, size_t size);
|
||||
const char *reaktor_path_leaf(const char *path);
|
||||
|
||||
char *reaktor_c_locale_keep(int numeric);
|
||||
void reaktor_c_locale_put(int numeric, char *kept);
|
||||
|
||||
char *reaktor_asset_load(const char *name, size_t *len);
|
||||
int reaktor_asset_exists(const char *name);
|
||||
int reaktor_asset_register(const char *name, const void *data, size_t size);
|
||||
|
||||
+231
-129
@@ -27,7 +27,7 @@ enum {
|
||||
P_BG, P_FG, P_BC,
|
||||
P_BW, P_BS = P_BW + 4, P_RAD = P_BS + 4, P_PAD = P_RAD + 4, P_MAR = P_PAD + 4,
|
||||
P_W = P_MAR + 4, P_H, P_MINW, P_MINH, P_MAXW, P_MAXH,
|
||||
P_FS, P_FW, P_LH, P_OP, P_COUNT
|
||||
P_FS, P_FW, P_LH, P_OP, P_GFROM, P_GTO, P_COUNT
|
||||
};
|
||||
|
||||
enum { F_IMPORTANT = 1, F_INITIAL = 2, F_CURRENT = 4, F_NUMBER = 8 };
|
||||
@@ -58,7 +58,7 @@ typedef struct decl {
|
||||
} decl;
|
||||
|
||||
typedef struct rule {
|
||||
unsigned c0, d0, nd, order, spec, next;
|
||||
unsigned c0, spec, next, blk;
|
||||
unsigned char n;
|
||||
} rule;
|
||||
|
||||
@@ -67,7 +67,13 @@ typedef struct bucket { unsigned key, first; } bucket;
|
||||
|
||||
typedef struct var { char *name, *value; size_t n; unsigned h; } var;
|
||||
|
||||
typedef struct raw { size_t ss, se, bs, be; } raw;
|
||||
/* A rule's selector list and body in the sheet's text; the body is read into
|
||||
declarations when a query first matches one of its selectors. */
|
||||
typedef struct block {
|
||||
size_t ss, se, bs, be;
|
||||
unsigned d0, nd;
|
||||
unsigned char read;
|
||||
} block;
|
||||
|
||||
struct reaktor_sheet {
|
||||
rule *rule; unsigned nrule, caprule;
|
||||
@@ -78,17 +84,15 @@ struct reaktor_sheet {
|
||||
var *var; unsigned nvar, capvar;
|
||||
unsigned *slot; unsigned capslot;
|
||||
bucket *bucket; unsigned capbucket, any;
|
||||
block *blk; unsigned nblk, capblk;
|
||||
buf src, tmp;
|
||||
char theme[16];
|
||||
float rem, em;
|
||||
};
|
||||
|
||||
typedef struct ctx {
|
||||
reaktor_sheet *s;
|
||||
const char *src, *theme;
|
||||
raw *raw;
|
||||
unsigned nraw, capraw;
|
||||
struct item *item;
|
||||
unsigned nitem, capitem;
|
||||
buf tmp;
|
||||
buf *tmp;
|
||||
unsigned char flags;
|
||||
uint64_t key, best;
|
||||
float rel, size;
|
||||
@@ -632,6 +636,60 @@ static int color(const char *s, size_t n, unsigned char rgba[4], unsigned char *
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int direction(const char *s, size_t n, int *axis, int *flip)
|
||||
{
|
||||
const char *end;
|
||||
double deg;
|
||||
size_t a = 2, e = n;
|
||||
|
||||
if (n > 3 && word(s, 2, "to") && space(s[2])) {
|
||||
int left, right, top, bottom;
|
||||
|
||||
trim(s, &a, &e);
|
||||
left = word(s + a, e - a, "left");
|
||||
right = word(s + a, e - a, "right");
|
||||
top = word(s + a, e - a, "top");
|
||||
bottom = word(s + a, e - a, "bottom");
|
||||
*flip = left || top;
|
||||
*axis = left || right ? REAKTOR_GRADIENT_ACROSS
|
||||
: top || bottom ? REAKTOR_GRADIENT_DOWN : REAKTOR_GRADIENT_NONE;
|
||||
return *axis != REAKTOR_GRADIENT_NONE;
|
||||
}
|
||||
deg = number(s, &end);
|
||||
if (end == s || !word(end, n - (size_t)(end - s), "deg") || deg != (double)(long)deg)
|
||||
return 0;
|
||||
switch ((((long)deg % 360) + 360) % 360) {
|
||||
case 0: *axis = REAKTOR_GRADIENT_DOWN; *flip = 1; return 1;
|
||||
case 90: *axis = REAKTOR_GRADIENT_ACROSS; *flip = 0; return 1;
|
||||
case 180: *axis = REAKTOR_GRADIENT_DOWN; *flip = 0; return 1;
|
||||
case 270: *axis = REAKTOR_GRADIENT_ACROSS; *flip = 1; return 1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* linear-gradient([to <side> | <n>deg,] a, b), turned to run left to right or
|
||||
top to bottom. Two stops and the four sides are all that is drawn. */
|
||||
static int gradient(const char *s, size_t n, unsigned char from[4], unsigned char to[4],
|
||||
int *axis)
|
||||
{
|
||||
size_t i = 16, item[3][2];
|
||||
unsigned char flags = 0;
|
||||
int k = 0, flip = 0, way = REAKTOR_GRADIENT_DOWN;
|
||||
|
||||
if (n < 18 || !word(s, 16, "linear-gradient(") || s[n - 1] != ')') return 0;
|
||||
n--;
|
||||
while (k < 3 && next_item(s, &i, n, &item[k][0], &item[k][1])) k++;
|
||||
if (i < n || k < 2) return 0;
|
||||
if (k == 3 && !direction(s + item[0][0], item[0][1] - item[0][0], &way, &flip))
|
||||
return 0;
|
||||
if (!color(s + item[k - 2][0], item[k - 2][1] - item[k - 2][0], flip ? to : from, &flags) ||
|
||||
!color(s + item[k - 1][0], item[k - 1][1] - item[k - 1][0], flip ? from : to, &flags) ||
|
||||
flags)
|
||||
return 0;
|
||||
*axis = way;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int line_style(const char *s, size_t n, float *v)
|
||||
{
|
||||
static const char *const styles[] = { "none", "hidden", "dotted", "dashed", "solid",
|
||||
@@ -671,7 +729,15 @@ static void emit(ctx *x, int prop, float v, const unsigned char *rgba, unsigned
|
||||
else memset(d->rgba, 0, 4);
|
||||
}
|
||||
|
||||
enum { K_COLOR, K_BG, K_LEN, K_FS, K_FW, K_LH, K_OP, K_BOX, K_RADIUS, K_BSTYLE, K_BCOLOR, K_BORDER };
|
||||
static void emit_gradient(ctx *x, int axis, const unsigned char from[4],
|
||||
const unsigned char to[4])
|
||||
{
|
||||
emit(x, P_GFROM, 0.0f, from, 0);
|
||||
emit(x, P_GTO, (float)axis, to, 0);
|
||||
}
|
||||
|
||||
enum { K_COLOR, K_BG, K_BGIMG, K_LEN, K_FS, K_FW, K_LH, K_OP, K_BOX, K_RADIUS, K_BSTYLE,
|
||||
K_BCOLOR, K_BORDER };
|
||||
|
||||
static const struct prop {
|
||||
const char *name;
|
||||
@@ -684,7 +750,7 @@ static const struct prop {
|
||||
{ "min-height", K_LEN, P_MINH, 0 }, { "max-width", K_LEN, P_MAXW, 0 },
|
||||
{ "max-height", K_LEN, P_MAXH, 0 }, { "font-size", K_FS, P_FS, 0 },
|
||||
{ "font-weight", K_FW, P_FW, 0 }, { "line-height", K_LH, P_LH, 0 },
|
||||
{ "opacity", K_OP, P_OP, 0 },
|
||||
{ "opacity", K_OP, P_OP, 0 }, { "background-image", K_BGIMG, P_GTO, 0 },
|
||||
{ "padding", K_BOX, P_PAD, -1 }, { "padding-top", K_BOX, P_PAD, 0 },
|
||||
{ "padding-right", K_BOX, P_PAD, 1 }, { "padding-bottom", K_BOX, P_PAD, 2 },
|
||||
{ "padding-left", K_BOX, P_PAD, 3 }, { "margin", K_BOX, P_MAR, -1 },
|
||||
@@ -760,8 +826,10 @@ static void box(ctx *x, const struct prop *p, const char *v, size_t n, int reset
|
||||
static void apply(ctx *x, const struct prop *p, const char *v, size_t n)
|
||||
{
|
||||
unsigned char rgba[4] = { 0, 0, 0, 0 }, flags = 0;
|
||||
unsigned char from[4] = { 0, 0, 0, 0 }, to[4] = { 0, 0, 0, 0 };
|
||||
float f;
|
||||
size_t i = 0, a, b;
|
||||
int axis = REAKTOR_GRADIENT_NONE, painted = 0;
|
||||
int pct, reset = word(v, n, "inherit") || word(v, n, "initial") ||
|
||||
word(v, n, "unset") || word(v, n, "revert") ||
|
||||
word(v, n, "revert-layer");
|
||||
@@ -776,7 +844,11 @@ static void apply(ctx *x, const struct prop *p, const char *v, size_t n)
|
||||
return;
|
||||
default: break;
|
||||
}
|
||||
if (reset) { emit(x, p->base, 0.0f, NULL, F_INITIAL); return; }
|
||||
if (reset) {
|
||||
if (p->kind == K_BG) emit(x, P_GTO, 0.0f, NULL, F_INITIAL);
|
||||
emit(x, p->base, 0.0f, NULL, F_INITIAL);
|
||||
return;
|
||||
}
|
||||
switch (p->kind) {
|
||||
case K_COLOR:
|
||||
if (color(v, n, rgba, &flags)) emit(x, p->base, 0.0f, rgba, flags);
|
||||
@@ -784,9 +856,18 @@ static void apply(ctx *x, const struct prop *p, const char *v, size_t n)
|
||||
case K_BG:
|
||||
for (;;) {
|
||||
while (i < n && (space(v[i]) || v[i] == '/')) i++;
|
||||
if (!part(v, &i, n, &a, &b) || color(v + a, b - a, rgba, &flags)) break;
|
||||
if (!part(v, &i, n, &a, &b)) break;
|
||||
if (!axis && gradient(v + a, b - a, from, to, &axis)) continue;
|
||||
if (color(v + a, b - a, rgba, &flags)) { painted = 1; break; }
|
||||
}
|
||||
/* Where the gradient is not drawn, its first stop stands for it. */
|
||||
if (axis && !painted) memcpy(rgba, from, 4);
|
||||
emit(x, P_BG, 0.0f, rgba, flags);
|
||||
emit_gradient(x, axis, from, to);
|
||||
break;
|
||||
case K_BGIMG:
|
||||
if (word(v, n, "none") || gradient(v, n, from, to, &axis))
|
||||
emit_gradient(x, axis, from, to);
|
||||
break;
|
||||
case K_LEN:
|
||||
if (length(x, v, n, &f)) emit(x, p->base, f, NULL, 0);
|
||||
@@ -874,7 +955,7 @@ static void declare(ctx *x, const char *p, size_t pn, const char *v, size_t vn,
|
||||
|
||||
if (!(prop = prop_of(p, pn))) return;
|
||||
x->flags = important ? F_IMPORTANT : 0;
|
||||
if (resolve_vars(x->s, &v, &vn, &x->tmp)) apply(x, prop, v, vn);
|
||||
if (resolve_vars(x->s, &v, &vn, x->tmp)) apply(x, prop, v, vn);
|
||||
else apply(x, prop, "unset", 5);
|
||||
x->flags = 0;
|
||||
}
|
||||
@@ -893,7 +974,7 @@ static void font_size(ctx *x, const char *p, size_t pn, const char *v, size_t vn
|
||||
int pct;
|
||||
|
||||
if (!word(p, pn, "font-size") || key < x->best) return;
|
||||
if (resolve_vars(x->s, &v, &vn, &x->tmp) &&
|
||||
if (resolve_vars(x->s, &v, &vn, x->tmp) &&
|
||||
((number_of(v, vn, &f, &pct) && pct && (f *= x->rel / 100.0f, 1)) ||
|
||||
length_em(x->s, v, vn, x->rel, &f)) &&
|
||||
f > 0.0f) {
|
||||
@@ -1149,22 +1230,19 @@ static int matches(const selector *r, const selector *q)
|
||||
return chain(&p, r->c, (int)r->n - 1, q, (int)q->n - 1);
|
||||
}
|
||||
|
||||
static void add_rule(ctx *x, const selector *q, unsigned d0, unsigned nd, unsigned order)
|
||||
static void add_rule(reaktor_sheet *s, const selector *q, unsigned blk)
|
||||
{
|
||||
reaktor_sheet *s = x->s;
|
||||
unsigned k;
|
||||
unsigned k;
|
||||
rule *r;
|
||||
|
||||
if (!ROOM(s, rule, nrule, caprule, 1) || !ROOM(s, cmp, ncmp, capcmp, q->n) ||
|
||||
!ROOM(s, neg, nneg, capneg, q->nneg) || !ROOM(s, nm, nnm, capnm, q->nnm))
|
||||
return;
|
||||
r = &s->rule[s->nrule++];
|
||||
r->c0 = s->ncmp;
|
||||
r->n = (unsigned char)q->n;
|
||||
r->d0 = d0;
|
||||
r->nd = nd;
|
||||
r->order = order;
|
||||
r->spec = q->spec;
|
||||
r->c0 = s->ncmp;
|
||||
r->n = (unsigned char)q->n;
|
||||
r->blk = blk;
|
||||
r->spec = q->spec;
|
||||
for (k = 0; k < q->n; k++) {
|
||||
compound c = q->c[k];
|
||||
|
||||
@@ -1238,7 +1316,7 @@ static int media_matches(const char *q, size_t n, const char *theme)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void blocks(ctx *x, const char *s, size_t i, size_t n, int depth)
|
||||
static void blocks(reaktor_sheet *sh, const char *s, size_t i, size_t n, int depth)
|
||||
{
|
||||
while (i < n) {
|
||||
size_t a, open, close;
|
||||
@@ -1252,16 +1330,17 @@ static void blocks(ctx *x, const char *s, size_t i, size_t n, int depth)
|
||||
close = block_end(s, open + 1, n);
|
||||
if (s[a] == '@') {
|
||||
if (depth < BLOCK_DEPTH && open - a > 6 && word(s + a, 6, "@media") &&
|
||||
media_matches(s + a + 6, open - a - 6, x->theme))
|
||||
blocks(x, s, open + 1, close, depth + 1);
|
||||
} else if (ROOM(x, raw, nraw, capraw, 1)) {
|
||||
raw *r = &x->raw[x->nraw++];
|
||||
media_matches(s + a + 6, open - a - 6, sh->theme))
|
||||
blocks(sh, s, open + 1, close, depth + 1);
|
||||
} else if (ROOM(sh, blk, nblk, capblk, 1)) {
|
||||
block *b = &sh->blk[sh->nblk++];
|
||||
|
||||
r->ss = a;
|
||||
r->se = open;
|
||||
r->bs = open + 1;
|
||||
r->be = close;
|
||||
trim(s, &r->ss, &r->se);
|
||||
memset(b, 0, sizeof *b);
|
||||
b->ss = a;
|
||||
b->se = open;
|
||||
b->bs = open + 1;
|
||||
b->be = close;
|
||||
trim(s, &b->ss, &b->se);
|
||||
}
|
||||
i = close + 1;
|
||||
}
|
||||
@@ -1298,7 +1377,7 @@ static char *import_path(const char *from, const char *to, size_t n)
|
||||
typedef struct loader {
|
||||
const char *chain[IMPORT_DEPTH + 1];
|
||||
int loads;
|
||||
buf all;
|
||||
buf *all;
|
||||
} loader;
|
||||
|
||||
static int in_chain(const loader *l, int depth, const char *path)
|
||||
@@ -1384,69 +1463,57 @@ static int load_sheet(loader *l, const char *path, int depth)
|
||||
if (t[q_s] == ')') q_s++;
|
||||
}
|
||||
q_e = i = scan(t, q_s, n, ";");
|
||||
if (depth >= IMPORT_DEPTH || e == s || l->all.len > IMPORT_BUDGET ||
|
||||
if (depth >= IMPORT_DEPTH || e == s || l->all->len > IMPORT_BUDGET ||
|
||||
++l->loads > IMPORT_LOADS)
|
||||
continue;
|
||||
if (!(to = import_path(path, t + s, e - s))) { ok = 0; break; }
|
||||
if (!in_chain(l, depth, to)) {
|
||||
trim(t, &q_s, &q_e);
|
||||
if (q_e > q_s)
|
||||
ok = buf_str(&l->all, "@media ") && buf_add(&l->all, t + q_s, q_e - q_s) &&
|
||||
buf_str(&l->all, " {\n") && load_sheet(l, to, depth + 1) &&
|
||||
buf_str(&l->all, "}\n");
|
||||
ok = buf_str(l->all, "@media ") && buf_add(l->all, t + q_s, q_e - q_s) &&
|
||||
buf_str(l->all, " {\n") && load_sheet(l, to, depth + 1) &&
|
||||
buf_str(l->all, "}\n");
|
||||
else
|
||||
ok = load_sheet(l, to, depth + 1);
|
||||
}
|
||||
free(to);
|
||||
if (!ok) break;
|
||||
}
|
||||
ok = ok && add_closed(&l->all, t, i, n);
|
||||
ok = ok && add_closed(l->all, t, i, n);
|
||||
reaktor_free(t);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* One selector of a rule's list, parsed once for every pass. */
|
||||
typedef struct item {
|
||||
selector q;
|
||||
unsigned raw;
|
||||
unsigned char ok, backdrop;
|
||||
} item;
|
||||
|
||||
static void parse_items(ctx *x)
|
||||
static ctx context(reaktor_sheet *s)
|
||||
{
|
||||
unsigned k;
|
||||
size_t a, ps, pe;
|
||||
ctx x;
|
||||
|
||||
for (k = 0; k < x->nraw; k++) {
|
||||
a = x->raw[k].ss;
|
||||
while (next_item(x->src, &a, x->raw[k].se, &ps, &pe) && ROOM(x, item, nitem, capitem, 1)) {
|
||||
item *it = &x->item[x->nitem++];
|
||||
|
||||
it->raw = k;
|
||||
it->backdrop = (unsigned char)holds(x->src + ps, pe - ps, "::backdrop");
|
||||
it->ok = (unsigned char)parse_selector(&it->q, x->src + ps, pe - ps);
|
||||
}
|
||||
}
|
||||
memset(&x, 0, sizeof x);
|
||||
x.s = s;
|
||||
x.tmp = &s->tmp;
|
||||
return x;
|
||||
}
|
||||
|
||||
/* The font size of the element `who` names, against `rel`, or `fallback`. */
|
||||
static float root_font(ctx *x, const char *who, float rel, float fallback)
|
||||
static float root_font(reaktor_sheet *s, const char *who, float rel, float fallback)
|
||||
{
|
||||
ctx x = context(s);
|
||||
pool p = { s->cmp, s->neg, s->nm };
|
||||
selector q;
|
||||
unsigned k;
|
||||
|
||||
parse_selector(&q, who, strlen(who));
|
||||
x->best = 0;
|
||||
x->size = fallback;
|
||||
x->rel = rel;
|
||||
for (k = 0; k < x->nitem; k++) {
|
||||
const item *it = &x->item[k];
|
||||
x.size = fallback;
|
||||
x.rel = rel;
|
||||
for (k = 0; k < s->nrule; k++) {
|
||||
const rule *r = &s->rule[k];
|
||||
const block *b = &s->blk[r->blk];
|
||||
|
||||
if (!it->ok || !matches(&it->q, &q)) continue;
|
||||
x->key = (uint64_t)it->q.spec << 32 | it->raw;
|
||||
each_decl(x, x->src, x->raw[it->raw].bs, x->raw[it->raw].be, font_size);
|
||||
if (!chain(&p, s->cmp + r->c0, r->n - 1, &q, (int)q.n - 1)) continue;
|
||||
x.key = (uint64_t)r->spec << 32 | r->blk;
|
||||
each_decl(&x, s->src.p, b->bs, b->be, font_size);
|
||||
}
|
||||
return x->size;
|
||||
return x.size;
|
||||
}
|
||||
|
||||
static bucket *bucket_of(const reaktor_sheet *s, unsigned key)
|
||||
@@ -1462,6 +1529,9 @@ static void index_rules(reaktor_sheet *s)
|
||||
{
|
||||
unsigned cap = 16, i;
|
||||
|
||||
free(s->bucket);
|
||||
s->bucket = NULL;
|
||||
s->capbucket = s->any = 0;
|
||||
while (cap < 2 * s->nrule) cap *= 2;
|
||||
if ((s->bucket = (bucket *)calloc(cap, sizeof *s->bucket)) != NULL) s->capbucket = cap;
|
||||
for (i = s->nrule; i-- > 0;) {
|
||||
@@ -1480,74 +1550,79 @@ static void index_rules(reaktor_sheet *s)
|
||||
}
|
||||
}
|
||||
|
||||
static void build(ctx *x)
|
||||
/* One more sheet read into s: its blocks, its rules, and the custom
|
||||
properties of the root. */
|
||||
static int ingest(reaktor_sheet *s, const char *path)
|
||||
{
|
||||
const char *s = x->src;
|
||||
char who[96];
|
||||
selector root;
|
||||
unsigned k, j, last = UINT_MAX;
|
||||
loader l;
|
||||
ctx x = context(s);
|
||||
selector q, root;
|
||||
char who[96];
|
||||
unsigned k, first = s->nblk;
|
||||
size_t a, ps, pe, from = s->src.len;
|
||||
|
||||
parse_items(x);
|
||||
snprintf(who, sizeof who, "html:root.data-theme-%s", x->theme);
|
||||
memset(&l, 0, sizeof l);
|
||||
l.all = &s->src;
|
||||
if (!load_sheet(&l, path, 0)) return 0;
|
||||
if (!s->src.p) return 1;
|
||||
blocks(s, s->src.p, from, s->src.len, 0);
|
||||
snprintf(who, sizeof who, "html:root.data-theme-%s", s->theme);
|
||||
parse_selector(&root, who, strlen(who));
|
||||
for (k = 0; k < x->nitem; k++) {
|
||||
const item *it = &x->item[k];
|
||||
for (k = first; k < s->nblk; k++) {
|
||||
int vars = 0;
|
||||
|
||||
if (it->raw != last && (it->backdrop || (it->ok && matches(&it->q, &root)))) {
|
||||
last = it->raw;
|
||||
each_decl(x, s, x->raw[it->raw].bs, x->raw[it->raw].be, collect_var);
|
||||
a = s->blk[k].ss;
|
||||
while (next_item(s->src.p, &a, s->blk[k].se, &ps, &pe)) {
|
||||
if (holds(s->src.p + ps, pe - ps, "::backdrop")) vars = 1;
|
||||
if (!parse_selector(&q, s->src.p + ps, pe - ps)) continue;
|
||||
if (matches(&q, &root)) vars = 1;
|
||||
add_rule(s, &q, k);
|
||||
}
|
||||
if (vars) each_decl(&x, s->src.p, s->blk[k].bs, s->blk[k].be, collect_var);
|
||||
}
|
||||
x->s->rem = root_font(x, who, 16.0f, 16.0f);
|
||||
snprintf(who, sizeof who, "html:root.data-theme-%s body", x->theme);
|
||||
x->s->em = root_font(x, who, x->s->rem, x->s->rem);
|
||||
for (k = j = 0; k < x->nraw; k++) {
|
||||
unsigned d0 = x->s->ndecl, nd;
|
||||
return 1;
|
||||
}
|
||||
|
||||
each_decl(x, s, x->raw[k].bs, x->raw[k].be, declare);
|
||||
nd = x->s->ndecl - d0;
|
||||
for (; j < x->nitem && x->item[j].raw == k; j++)
|
||||
if (nd && x->item[j].ok) add_rule(x, &x->item[j].q, d0, nd, k);
|
||||
}
|
||||
index_rules(x->s);
|
||||
/* After a sheet is read: the root's sizes, the index, and every body to be
|
||||
read again, since a custom property may have changed under it. */
|
||||
static void settle(reaktor_sheet *s)
|
||||
{
|
||||
char who[96];
|
||||
unsigned k;
|
||||
|
||||
for (k = 0; k < s->nblk; k++) s->blk[k].read = 0;
|
||||
s->ndecl = 0;
|
||||
s->rem = s->em = 16.0f;
|
||||
snprintf(who, sizeof who, "html:root.data-theme-%s", s->theme);
|
||||
s->rem = root_font(s, who, 16.0f, 16.0f);
|
||||
snprintf(who, sizeof who, "html:root.data-theme-%s body", s->theme);
|
||||
s->em = root_font(s, who, s->rem, s->rem);
|
||||
index_rules(s);
|
||||
}
|
||||
|
||||
reaktor_sheet *reaktor_sheet_load(const char *const *paths, int count, const char *theme)
|
||||
{
|
||||
reaktor_sheet *s = (reaktor_sheet *)calloc(1, sizeof *s);
|
||||
loader *l = (loader *)calloc(1, sizeof *l);
|
||||
ctx x;
|
||||
int i;
|
||||
|
||||
if (!s || !l) {
|
||||
free(l);
|
||||
free(s);
|
||||
return NULL;
|
||||
}
|
||||
s->rem = s->em = 16.0f;
|
||||
if (!s) return NULL;
|
||||
snprintf(s->theme, sizeof s->theme, "%s", theme && *theme ? theme : "light");
|
||||
for (i = 0; i < count; i++)
|
||||
if (!load_sheet(l, paths[i], 0)) {
|
||||
free(l->all.p);
|
||||
free(l);
|
||||
if (!ingest(s, paths[i])) {
|
||||
reaktor_sheet_free(s);
|
||||
return NULL;
|
||||
}
|
||||
if (l->all.p) {
|
||||
memset(&x, 0, sizeof x);
|
||||
x.s = s;
|
||||
x.src = l->all.p;
|
||||
x.theme = theme && *theme ? theme : "light";
|
||||
blocks(&x, l->all.p, 0, l->all.len, 0);
|
||||
build(&x);
|
||||
free(x.item);
|
||||
free(x.raw);
|
||||
free(x.tmp.p);
|
||||
free(l->all.p);
|
||||
}
|
||||
free(l);
|
||||
settle(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
int reaktor_sheet_add(reaktor_sheet *s, const char *path)
|
||||
{
|
||||
if (!s || !path || !ingest(s, path)) return 0;
|
||||
settle(s);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void reaktor_sheet_free(reaktor_sheet *s)
|
||||
{
|
||||
unsigned i;
|
||||
@@ -1565,6 +1640,9 @@ void reaktor_sheet_free(reaktor_sheet *s)
|
||||
free(s->neg);
|
||||
free(s->nm);
|
||||
free(s->decl);
|
||||
free(s->blk);
|
||||
free(s->src.p);
|
||||
free(s->tmp.p);
|
||||
free(s);
|
||||
}
|
||||
|
||||
@@ -1585,6 +1663,11 @@ static void resolve(const reaktor_sheet *s, const decl *const *w, reaktor_style
|
||||
o->fg[3] = 255;
|
||||
paint(w[P_FG], o->fg, o->fg);
|
||||
paint(w[P_BG], o->fg, o->bg);
|
||||
if (set(w[P_GTO]) && set(w[P_GFROM]) && w[P_GTO]->v > 0.0f) {
|
||||
o->gradient = (int)w[P_GTO]->v;
|
||||
memcpy(o->gradient_from, w[P_GFROM]->rgba, 4);
|
||||
memcpy(o->gradient_to, w[P_GTO]->rgba, 4);
|
||||
}
|
||||
memcpy(o->border_col, o->fg, 4);
|
||||
paint(w[P_BC], o->fg, o->border_col);
|
||||
for (k = 0; k < 4; k++) {
|
||||
@@ -1615,38 +1698,56 @@ static void resolve(const reaktor_sheet *s, const decl *const *w, reaktor_style
|
||||
o->line_height *= fs > 0.0f ? fs : s->em;
|
||||
}
|
||||
|
||||
/* The rules chained from `first` that match q, cascaded into win. */
|
||||
static void cascade(const reaktor_sheet *s, unsigned first, const selector *q,
|
||||
const decl **win, uint64_t *key, reaktor_style *out)
|
||||
static const block *read_block(reaktor_sheet *s, unsigned k)
|
||||
{
|
||||
block *b = &s->blk[k];
|
||||
|
||||
if (!b->read) {
|
||||
ctx x = context(s);
|
||||
|
||||
b->read = 1;
|
||||
b->d0 = s->ndecl;
|
||||
each_decl(&x, s->src.p, b->bs, b->be, declare);
|
||||
b->nd = s->ndecl - b->d0;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/* The rules chained from `first` that match q, cascaded into win as indices,
|
||||
since reading a body may move the declarations. */
|
||||
static void cascade(reaktor_sheet *s, unsigned first, const selector *q,
|
||||
unsigned *win, uint64_t *key, reaktor_style *out)
|
||||
{
|
||||
pool p = { s->cmp, s->neg, s->nm };
|
||||
unsigned i, k;
|
||||
|
||||
for (i = first; i; i = s->rule[i - 1].next) {
|
||||
const rule *r = &s->rule[i - 1];
|
||||
const rule *r = &s->rule[i - 1];
|
||||
const block *b;
|
||||
|
||||
if (!chain(&p, s->cmp + r->c0, r->n - 1, q, (int)q->n - 1)) continue;
|
||||
out->matched = 1;
|
||||
for (k = r->d0; k < r->d0 + r->nd; k++) {
|
||||
b = read_block(s, r->blk);
|
||||
if (b->nd) out->matched = 1;
|
||||
for (k = b->d0; k < b->d0 + b->nd; k++) {
|
||||
const decl *d = &s->decl[k];
|
||||
uint64_t w = (uint64_t)(d->flags & F_IMPORTANT) << 63 |
|
||||
(uint64_t)r->spec << 32 | r->order;
|
||||
(uint64_t)r->spec << 32 | r->blk;
|
||||
|
||||
if (!win[d->prop] || w >= key[d->prop]) {
|
||||
win[d->prop] = d;
|
||||
win[d->prop] = k + 1;
|
||||
key[d->prop] = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void reaktor_sheet_style(const reaktor_sheet *s, const char *sel, reaktor_style *out)
|
||||
void reaktor_sheet_style(reaktor_sheet *s, const char *sel, reaktor_style *out)
|
||||
{
|
||||
const decl *win[P_COUNT] = { 0 };
|
||||
unsigned win[P_COUNT] = { 0 }, k;
|
||||
uint64_t key[P_COUNT];
|
||||
const decl *w[P_COUNT];
|
||||
const compound *c;
|
||||
selector q;
|
||||
unsigned k;
|
||||
|
||||
memset(out, 0, sizeof *out);
|
||||
out->opacity = 1.0f;
|
||||
@@ -1658,7 +1759,8 @@ void reaktor_sheet_style(const reaktor_sheet *s, const char *sel, reaktor_style
|
||||
for (k = 0; k < c->n; k++)
|
||||
cascade(s, bucket_of(s, q.nm[c->name + k])->first, &q, win, key, out);
|
||||
}
|
||||
resolve(s, win, out);
|
||||
for (k = 0; k < P_COUNT; k++) w[k] = win[k] ? &s->decl[win[k] - 1] : NULL;
|
||||
resolve(s, w, out);
|
||||
}
|
||||
|
||||
int reaktor_sheet_color(const reaktor_sheet *s, const char *name, unsigned char rgba[4])
|
||||
|
||||
+4
-1
@@ -7,7 +7,10 @@ typedef struct reaktor_sheet reaktor_sheet;
|
||||
|
||||
reaktor_sheet *reaktor_sheet_load(const char *const *paths, int count, const char *theme);
|
||||
void reaktor_sheet_free(reaktor_sheet *s);
|
||||
void reaktor_sheet_style(const reaktor_sheet *s, const char *selector, reaktor_style *out);
|
||||
void reaktor_sheet_style(reaktor_sheet *s, const char *selector, reaktor_style *out);
|
||||
|
||||
/* One more sheet read after the others, as if it had been listed last. */
|
||||
int reaktor_sheet_add(reaktor_sheet *s, const char *path);
|
||||
int reaktor_sheet_color(const reaktor_sheet *s, const char *name, unsigned char rgba[4]);
|
||||
|
||||
/* What @media (prefers-reduced-motion) and (prefers-contrast) answer. */
|
||||
|
||||
@@ -71,6 +71,14 @@ int reaktor_style_init(const char *const *css_paths, int count,
|
||||
return sheet != NULL;
|
||||
}
|
||||
|
||||
int reaktor_style_add(const char *path)
|
||||
{
|
||||
if (!reaktor_sheet_add(g.sheet, path)) return 0;
|
||||
cache_clear(0);
|
||||
g.generation++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void reaktor_style_shutdown(void)
|
||||
{
|
||||
cache_clear(1);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
int reaktor_style_init(const char *const *css_paths, int count,
|
||||
const char *theme);
|
||||
int reaktor_style_add(const char *path);
|
||||
void reaktor_style_shutdown(void);
|
||||
unsigned reaktor_style_loads(void);
|
||||
void reaktor_style_darken(unsigned char rgba[4], float amount);
|
||||
|
||||
+14
-2
@@ -239,6 +239,7 @@ struct App {
|
||||
int popup_open, popups_inline;
|
||||
undo_stack undo;
|
||||
int want_capture;
|
||||
int build_only;
|
||||
SDL_Surface *capture;
|
||||
struct { const char *buf; int from, to, asked; } field_pick;
|
||||
struct { char kind[32], from[64], label[96]; int item, armed, active; struct nk_vec2 at; } drag;
|
||||
@@ -254,7 +255,8 @@ struct App {
|
||||
Uint64 last_frame_ms;
|
||||
float frame_gap_ms;
|
||||
struct nka_context *anim;
|
||||
int style_ms_x100;
|
||||
int style_ms_x100, window_ms_x100, atlas_ms_x100, first_ms_x100;
|
||||
Uint64 started;
|
||||
int sheets;
|
||||
const char *font_face, *font_face_bold;
|
||||
const char *icon_dirs[8];
|
||||
@@ -274,6 +276,7 @@ struct nk_image icon_ink(App *app, const char *src, int px, float *left, float *
|
||||
const struct nk_user_font *pick_font(App *app, int px, int bold);
|
||||
const struct nk_user_font *base_font(App *app);
|
||||
void rebuild_font(App *app);
|
||||
void atlas_forget(void);
|
||||
void apply_render_scale(App *app);
|
||||
void reaktor_set_window_icon(SDL_Window *win, const char *name);
|
||||
|
||||
@@ -298,6 +301,9 @@ enum {
|
||||
REAKTOR_WHY_STYLE = 1u << 3
|
||||
};
|
||||
|
||||
/* The Tray module, or its _none twin. */
|
||||
void reaktor_tray_event(App *app, const SDL_Event *e);
|
||||
|
||||
/* The Inspector module, or its _none twin. */
|
||||
struct reaktor_inspector_spec;
|
||||
void reaktor_inspector_early(void);
|
||||
@@ -370,6 +376,8 @@ typedef struct reaktor_surface {
|
||||
} reaktor_surface;
|
||||
|
||||
reaktor_surface reaktor_rule_surface(const reaktor_style *s, float radius);
|
||||
void reaktor_fill_style(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
float rounding, const reaktor_style *s);
|
||||
void reaktor_paint_surface(App *app, struct nk_command_buffer *cv, struct nk_rect r,
|
||||
const reaktor_surface *s);
|
||||
struct nk_rect reaktor_rect_trunc(struct nk_rect b);
|
||||
@@ -379,6 +387,7 @@ 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);
|
||||
SDL_Renderer *reaktor_renderer_for(SDL_Window *win, const char *name, int hdr);
|
||||
void reaktor_hint(const char *name, const char *value);
|
||||
int reaktor_key_hook(App *app, const SDL_Event *event);
|
||||
void reaktor_take_event(App *app, SDL_Event *event);
|
||||
@@ -478,8 +487,11 @@ void reaktor_unfit_label(struct nk_context *ctx, int fitted);
|
||||
int reaktor_radio_label(App *app, struct nk_context *ctx, const char *label,
|
||||
int on);
|
||||
|
||||
void reaktor_slider_ramp(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
float lo, float hi, float step, const reaktor_style *fill);
|
||||
void reaktor_slider_bar_int(App *app, struct nk_context *ctx, unsigned id,
|
||||
int *val, int lo, int hi, int step);
|
||||
int *val, int lo, int hi, int step,
|
||||
const reaktor_style *fill);
|
||||
void reaktor_knob_dial(App *app, struct nk_context *ctx, float *val,
|
||||
float lo, float hi, enum nk_heading zero);
|
||||
|
||||
|
||||
+10
-9
@@ -295,7 +295,7 @@ scan(const char *text, unsigned **set, int *n, int *cap)
|
||||
if (cp <= 0xFF || cp == SDL_INVALID_UNICODE_CODEPOINT) continue;
|
||||
if (*n == *cap) {
|
||||
int grow = *cap ? *cap * 2 : 256;
|
||||
unsigned *more = realloc(*set, (size_t)grow * sizeof **set);
|
||||
unsigned *more = SDL_realloc(*set, (size_t)grow * sizeof **set);
|
||||
|
||||
if (!more) return;
|
||||
*set = more;
|
||||
@@ -305,8 +305,8 @@ scan(const char *text, unsigned **set, int *n, int *cap)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_locale_codepoints(unsigned *out, int cap)
|
||||
unsigned *
|
||||
reaktor_locale_codepoints(int *count)
|
||||
{
|
||||
unsigned *set = NULL;
|
||||
int n = 0, room = 0, unique = 0, i, j;
|
||||
@@ -318,11 +318,12 @@ reaktor_locale_codepoints(unsigned *out, int cap)
|
||||
}
|
||||
|
||||
if (n) qsort(set, (size_t)n, sizeof *set, by_codepoint);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (unique && set[i] == set[i - 1]) continue;
|
||||
if (out && unique < cap) out[unique] = set[i];
|
||||
unique++;
|
||||
for (i = 0; i < n; i++)
|
||||
if (!unique || set[i] != set[unique - 1]) set[unique++] = set[i];
|
||||
*count = unique;
|
||||
if (!unique) {
|
||||
SDL_free(set);
|
||||
return NULL;
|
||||
}
|
||||
free(set);
|
||||
return unique;
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
int reaktor_locale_init(void);
|
||||
int reaktor_locale_find(const char *code);
|
||||
const char *reaktor_locale_system_code(void);
|
||||
int reaktor_locale_codepoints(unsigned *out, int cap);
|
||||
unsigned *reaktor_locale_codepoints(int *count);
|
||||
long reaktor_plural_eval(const char *expr, unsigned long n);
|
||||
|
||||
#ifdef REAKTOR_LOCALE_EMBEDDED
|
||||
|
||||
@@ -32,12 +32,11 @@ unsigned *
|
||||
reaktor_locale_glyphs(void)
|
||||
{
|
||||
unsigned *cp, *out;
|
||||
int n = reaktor_locale_codepoints(NULL, 0), i, at = 0;
|
||||
int n = 0, i, at = 0;
|
||||
|
||||
if (n <= 0 || !(cp = SDL_malloc((size_t)n * sizeof *cp))) return NULL;
|
||||
if (!(cp = reaktor_locale_codepoints(&n))) return NULL;
|
||||
out = SDL_malloc(((size_t)n * 2 + 3) * sizeof *out);
|
||||
if (out) {
|
||||
reaktor_locale_codepoints(cp, n);
|
||||
out[at++] = 0x0020;
|
||||
out[at++] = 0x00FF;
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
+234
-33
@@ -549,36 +549,189 @@ draw_corners(struct nk_command_buffer *cv, struct nk_image mask, int m,
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct ramp {
|
||||
struct nk_rect b;
|
||||
struct nk_color from, to;
|
||||
int across, flat;
|
||||
} ramp;
|
||||
|
||||
static struct nk_color
|
||||
ramp_at(const ramp *g, float at)
|
||||
{
|
||||
float span = g->across ? g->b.w : g->b.h;
|
||||
float t = (at - (g->across ? g->b.x : g->b.y)) / span;
|
||||
|
||||
if (t < 0.0f) t = 0.0f;
|
||||
if (t > 1.0f) t = 1.0f;
|
||||
return nk_rgba((int)(g->from.r + (g->to.r - g->from.r) * t + 0.5f),
|
||||
(int)(g->from.g + (g->to.g - g->from.g) * t + 0.5f),
|
||||
(int)(g->from.b + (g->to.b - g->from.b) * t + 0.5f),
|
||||
(int)(g->from.a + (g->to.a - g->from.a) * t + 0.5f));
|
||||
}
|
||||
|
||||
/* The largest step, in levels of one channel, between the ramp's two ends. */
|
||||
static int
|
||||
ramp_levels(const ramp *g)
|
||||
{
|
||||
int d[4] = { g->to.r - g->from.r, g->to.g - g->from.g, g->to.b - g->from.b,
|
||||
g->to.a - g->from.a };
|
||||
int i, most = 0;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
if (SDL_abs(d[i]) > most) most = SDL_abs(d[i]);
|
||||
return most;
|
||||
}
|
||||
|
||||
/* A run in solid bands, one per level the ramp changes by across it: SDL fills
|
||||
a solid rectangle far faster than it shades one from its corners. */
|
||||
static void
|
||||
ramp_rect(struct nk_command_buffer *cv, const ramp *g, struct nk_rect r)
|
||||
{
|
||||
float at = g->across ? r.x : r.y, len = g->across ? r.w : r.h;
|
||||
int n, j;
|
||||
|
||||
if (g->flat) { nk_fill_rect(cv, r, 0.0f, g->from); return; }
|
||||
n = (int)SDL_ceilf((float)ramp_levels(g) * len / (g->across ? g->b.w : g->b.h));
|
||||
if (n > (int)len) n = (int)len;
|
||||
if (n < 1) n = 1;
|
||||
/* Whole pixels, so neighbors share an edge the renderer cannot round apart. */
|
||||
for (j = 0; j < n; j++) {
|
||||
float s0 = at + (float)(int)(len * (float)j / (float)n + 0.5f);
|
||||
float s1 = at + (float)(int)(len * (float)(j + 1) / (float)n + 0.5f);
|
||||
struct nk_color c = ramp_at(g, (s0 + s1) * 0.5f);
|
||||
|
||||
if (s1 <= s0) continue;
|
||||
|
||||
nk_fill_rect(cv, g->across ? nk_rect(s0, r.y, s1 - s0, r.h)
|
||||
: nk_rect(r.x, s0, r.w, s1 - s0), 0.0f, c);
|
||||
}
|
||||
}
|
||||
|
||||
/* A corner is cut into texel-wide strips along the ramp, each tinted where it sits. */
|
||||
static void
|
||||
ramp_corners(struct nk_command_buffer *cv, const ramp *g, struct nk_image mask, int m,
|
||||
int r)
|
||||
{
|
||||
float M = (float)m, D = (float)(2 * m + 1), R = (float)r;
|
||||
int i, k;
|
||||
|
||||
if (g->flat) { draw_corners(cv, mask, m, g->b, r, g->from); return; }
|
||||
for (i = 0; i < 4; i++) {
|
||||
float x = (i & 1) ? g->b.x + g->b.w - R : g->b.x;
|
||||
float y = (i & 2) ? g->b.y + g->b.h - R : g->b.y;
|
||||
float u = (i & 1) ? M + 1.0f : 0.0f;
|
||||
float v = (i & 2) ? M + 1.0f : 0.0f;
|
||||
|
||||
for (k = 0; k < m; k++) {
|
||||
float s0 = R * (float)k / M, s1 = R * (float)(k + 1) / M;
|
||||
struct nk_rect at = g->across ? nk_rect(x + s0, y, s1 - s0, R)
|
||||
: nk_rect(x, y + s0, R, s1 - s0);
|
||||
struct nk_rect src = g->across ? nk_rect(u + (float)k, v, 1.0f, M)
|
||||
: nk_rect(u, v + (float)k, M, 1.0f);
|
||||
struct nk_image q = nk_subimage_handle(mask.handle, (nk_ushort)D,
|
||||
(nk_ushort)D, src);
|
||||
|
||||
nk_draw_image(cv, at, &q,
|
||||
ramp_at(g, g->across ? at.x + at.w * 0.5f
|
||||
: at.y + at.h * 0.5f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Four corner masks and the three runs between them, over whole pixels. */
|
||||
static void
|
||||
fill_shape(App *app, struct nk_command_buffer *cv, float rounding, const ramp *g)
|
||||
{
|
||||
struct nk_rect b = g->b;
|
||||
struct nk_image disc;
|
||||
float R, D;
|
||||
int r, m;
|
||||
|
||||
r = corner_px(b, rounding);
|
||||
if (r < 1) { ramp_rect(cv, g, b); return; }
|
||||
m = mask_px((float)r);
|
||||
disc = round_mask(app, m, 0);
|
||||
if (!disc.handle.ptr) {
|
||||
if (g->flat) nk_fill_rect(cv, b, (float)r, g->from);
|
||||
else ramp_rect(cv, g, b);
|
||||
return;
|
||||
}
|
||||
|
||||
ramp_corners(cv, g, disc, m, r);
|
||||
R = (float)r;
|
||||
D = 2.0f * R;
|
||||
/* The long run lies across the ramp, so each band is drawn once. */
|
||||
if (!g->flat && g->across) {
|
||||
if (b.w > D)
|
||||
ramp_rect(cv, g, nk_rect(b.x + R, b.y, b.w - D, b.h));
|
||||
if (b.h > D) {
|
||||
ramp_rect(cv, g, nk_rect(b.x, b.y + R, R, b.h - D));
|
||||
ramp_rect(cv, g, nk_rect(b.x + b.w - R, b.y + R, R, b.h - D));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (b.h > D)
|
||||
ramp_rect(cv, g, nk_rect(b.x, b.y + R, b.w, b.h - D));
|
||||
if (b.w > D) {
|
||||
ramp_rect(cv, g, nk_rect(b.x + R, b.y, b.w - D, R));
|
||||
ramp_rect(cv, g, nk_rect(b.x + R, b.y + b.h - R, b.w - D, R));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_fill_round(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
float rounding, struct nk_color col)
|
||||
{
|
||||
struct nk_image disc;
|
||||
float R, D;
|
||||
int r, m;
|
||||
ramp g;
|
||||
|
||||
if (b.w <= 0.0f || b.h <= 0.0f || !col.a) return;
|
||||
if (app) {
|
||||
app->surface_at = b;
|
||||
app->surface = col;
|
||||
}
|
||||
b = whole_px(b);
|
||||
if (b.w <= 0.0f || b.h <= 0.0f) return;
|
||||
r = corner_px(b, rounding);
|
||||
if (r < 1) { nk_fill_rect(cv, b, 0.0f, col); return; }
|
||||
m = mask_px((float)r);
|
||||
disc = round_mask(app, m, 0);
|
||||
if (!disc.handle.ptr) { nk_fill_rect(cv, b, (float)r, col); return; }
|
||||
g.b = whole_px(b);
|
||||
g.from = g.to = col;
|
||||
g.across = 1;
|
||||
g.flat = 1;
|
||||
if (g.b.w <= 0.0f || g.b.h <= 0.0f) return;
|
||||
fill_shape(app, cv, rounding, &g);
|
||||
}
|
||||
|
||||
draw_corners(cv, disc, m, b, r, col);
|
||||
R = (float)r;
|
||||
D = 2.0f * R;
|
||||
if (b.h > D)
|
||||
nk_fill_rect(cv, nk_rect(b.x, b.y + R, b.w, b.h - D), 0.0f, col);
|
||||
if (b.w > D) {
|
||||
nk_fill_rect(cv, nk_rect(b.x + R, b.y, b.w - D, R), 0.0f, col);
|
||||
nk_fill_rect(cv, nk_rect(b.x + R, b.y + b.h - R, b.w - D, R), 0.0f, col);
|
||||
void
|
||||
reaktor_fill_gradient(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
float rounding, struct nk_color from, struct nk_color to,
|
||||
int axis)
|
||||
{
|
||||
ramp g;
|
||||
|
||||
if (axis == REAKTOR_GRADIENT_NONE || !memcmp(&from, &to, sizeof from)) {
|
||||
reaktor_fill_round(app, cv, b, rounding, from);
|
||||
return;
|
||||
}
|
||||
if (b.w <= 0.0f || b.h <= 0.0f || (!from.a && !to.a)) return;
|
||||
g.b = whole_px(b);
|
||||
g.from = from;
|
||||
g.to = to;
|
||||
g.across = axis == REAKTOR_GRADIENT_ACROSS;
|
||||
g.flat = 0;
|
||||
if (g.b.w <= 0.0f || g.b.h <= 0.0f) return;
|
||||
if (app) {
|
||||
app->surface_at = b;
|
||||
app->surface = ramp_at(&g, g.across ? g.b.x + g.b.w * 0.5f
|
||||
: g.b.y + g.b.h * 0.5f);
|
||||
}
|
||||
fill_shape(app, cv, rounding, &g);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_fill_style(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
float rounding, const reaktor_style *s)
|
||||
{
|
||||
if (s->gradient)
|
||||
reaktor_fill_gradient(app, cv, b, rounding, nk_rgba_bv(s->gradient_from),
|
||||
nk_rgba_bv(s->gradient_to), s->gradient);
|
||||
else
|
||||
reaktor_fill_round(app, cv, b, rounding, nk_rgba_bv(s->bg));
|
||||
}
|
||||
|
||||
|
||||
@@ -612,12 +765,14 @@ nbsp_as_space(struct reaktor_font *f)
|
||||
}
|
||||
|
||||
static void
|
||||
finish_face(struct reaktor_font *f, float height, const char *path)
|
||||
finish_face(struct reaktor_font *f, float height, const char *path, int fresh)
|
||||
{
|
||||
if (!f) return;
|
||||
f->handle.height = height;
|
||||
center_glyphs_optically(f);
|
||||
nbsp_as_space(f);
|
||||
if (fresh) {
|
||||
center_glyphs_optically(f);
|
||||
nbsp_as_space(f);
|
||||
}
|
||||
/* After centering: the Text module reads the baseline. */
|
||||
reaktor_text_attach_font(f, path);
|
||||
}
|
||||
@@ -677,17 +832,36 @@ load_face(const char **name, const char *stand_in, size_t *size)
|
||||
return take_face(*name, size);
|
||||
}
|
||||
|
||||
/* The atlas image, kept from the first window after the main one, so later
|
||||
windows upload it instead of baking their own. */
|
||||
static struct {
|
||||
struct reaktor_fontset set;
|
||||
const char *face, *bold;
|
||||
} g_kept;
|
||||
|
||||
void
|
||||
rebuild_font(App *app)
|
||||
atlas_forget(void)
|
||||
{
|
||||
reaktor_fontset_free(&g_kept.set);
|
||||
SDL_zero(g_kept);
|
||||
}
|
||||
|
||||
static int
|
||||
keeps(const App *app)
|
||||
{
|
||||
return g_kept.set.pixels && app->font_face == g_kept.face && app->font_face_bold == g_kept.bold;
|
||||
}
|
||||
|
||||
static int
|
||||
bake(App *app, struct reaktor_fontset *set, int *bold)
|
||||
{
|
||||
static const nk_rune latin[] = { 0x0020, 0x00FF, 0 };
|
||||
struct reaktor_face_src src[2 * FONT_STEPS];
|
||||
struct reaktor_fontset set;
|
||||
struct reaktor_font *font = NULL;
|
||||
size_t size = 0, bsize = 0;
|
||||
char *ttf, *bttf = NULL;
|
||||
unsigned *ranges;
|
||||
int n = 0, bold, ok, i;
|
||||
Uint64 t0;
|
||||
int n = 0, ok, i;
|
||||
|
||||
ttf = load_face(&app->font_face, FONT_FILE, &size);
|
||||
if (ttf) bttf = load_face(&app->font_face_bold, FONT_BOLD_FILE, &bsize);
|
||||
@@ -701,9 +875,12 @@ rebuild_font(App *app)
|
||||
src[n].size = bsize;
|
||||
src[n++].px = (float)reaktor_px(g_font_px[i]);
|
||||
}
|
||||
bold = bttf != NULL;
|
||||
*bold = bttf != NULL;
|
||||
ranges = reaktor_locale_glyphs();
|
||||
ok = n > 0 && reaktor_fontset_bake(&set, src, n, ranges ? ranges : latin);
|
||||
t0 = SDL_GetPerformanceCounter();
|
||||
ok = n > 0 && reaktor_fontset_bake(set, src, n, ranges ? ranges : latin);
|
||||
app->atlas_ms_x100 = (int)(100000.0 * (double)(SDL_GetPerformanceCounter() - t0) /
|
||||
(double)SDL_GetPerformanceFrequency());
|
||||
SDL_free(ranges);
|
||||
reaktor_free(ttf);
|
||||
reaktor_free(bttf);
|
||||
@@ -712,14 +889,30 @@ rebuild_font(App *app)
|
||||
if (!app->fonts.count)
|
||||
SDL_snprintf(app->font_status, sizeof(app->font_status),
|
||||
"FALLBACK - could not load %s", app->font_face);
|
||||
return;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
if (!app->secondary) reaktor_text_attach_font(NULL, NULL);
|
||||
void
|
||||
rebuild_font(App *app)
|
||||
{
|
||||
struct reaktor_fontset set;
|
||||
struct reaktor_font *font = NULL;
|
||||
unsigned char *pixels;
|
||||
int bold, shared, i;
|
||||
|
||||
shared = app->secondary && keeps(app) && reaktor_fontset_copy(&set, &g_kept.set);
|
||||
if (shared) bold = set.count > FONT_STEPS;
|
||||
else if (!bake(app, &set, &bold)) return;
|
||||
|
||||
if (!app->secondary) {
|
||||
reaktor_text_attach_font(NULL, NULL);
|
||||
atlas_forget();
|
||||
}
|
||||
reaktor_fontset_free(&app->fonts);
|
||||
app->fonts = set;
|
||||
reaktor_fontset_bind(&app->fonts, nk_sdl_font_upload(app->ctx, set.pixels, set.w, set.h));
|
||||
SDL_free(app->fonts.pixels);
|
||||
pixels = shared ? g_kept.set.pixels : set.pixels;
|
||||
reaktor_fontset_bind(&app->fonts, nk_sdl_font_upload(app->ctx, pixels, set.w, set.h));
|
||||
app->fonts.pixels = NULL;
|
||||
for (i = 0; i < FONT_STEPS; i++) {
|
||||
app->faces[i] = &app->fonts.fonts[i];
|
||||
@@ -734,9 +927,17 @@ rebuild_font(App *app)
|
||||
|
||||
for (i = 0; i < FONT_STEPS; i++) {
|
||||
finish_face(app->faces[i], (float)g_font_px[i],
|
||||
app->secondary ? NULL : app->font_face);
|
||||
app->secondary ? NULL : app->font_face, !shared);
|
||||
finish_face(app->bolds[i], (float)g_font_px[i],
|
||||
app->secondary ? NULL : app->font_face_bold);
|
||||
app->secondary ? NULL : app->font_face_bold, !shared);
|
||||
}
|
||||
if (app->secondary && !shared && !g_kept.set.pixels &&
|
||||
reaktor_fontset_copy(&g_kept.set, &app->fonts)) {
|
||||
g_kept.set.pixels = pixels;
|
||||
g_kept.face = app->font_face;
|
||||
g_kept.bold = app->font_face_bold;
|
||||
} else if (!shared) {
|
||||
SDL_free(pixels);
|
||||
}
|
||||
|
||||
app->atlas_w = app->atlas_h = app->atlas_bpp = 0;
|
||||
|
||||
+34
-5
@@ -243,6 +243,7 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
int n, const nk_rune *ranges)
|
||||
{
|
||||
nk_rune *cp;
|
||||
FT_Face face = NULL;
|
||||
baked *b = NULL;
|
||||
unsigned char *bits = NULL;
|
||||
int ncp = 0, nb = 0, cap_b = 0, cap_bits = 0, used = 0, i, k, ok = 0;
|
||||
@@ -255,9 +256,12 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
set->count = n;
|
||||
for (i = 0; i < n; i++) {
|
||||
struct reaktor_font *f = &set->fonts[i];
|
||||
FT_Face face = reaktor_ft_open(src[i].ttf, src[i].size);
|
||||
float scale;
|
||||
|
||||
if (!i || src[i].ttf != src[i - 1].ttf) {
|
||||
if (face) FT_Done_Face(face);
|
||||
face = reaktor_ft_open(src[i].ttf, src[i].size);
|
||||
}
|
||||
f->glyphs = set->glyphs + nb;
|
||||
f->height = src[i].px;
|
||||
if (!face) continue;
|
||||
@@ -278,10 +282,8 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
continue;
|
||||
bm = &face->glyph->bitmap;
|
||||
if (!reaktor_grow((void **)&b, &cap_b, nb + 1, sizeof *b) ||
|
||||
!reaktor_grow((void **)&bits, &cap_bits, used + (int)(bm->width * bm->rows), 1)) {
|
||||
FT_Done_Face(face);
|
||||
!reaktor_grow((void **)&bits, &cap_bits, used + (int)(bm->width * bm->rows), 1))
|
||||
goto done;
|
||||
}
|
||||
d = &b[nb];
|
||||
d->w = (int)bm->width;
|
||||
d->h = (int)bm->rows;
|
||||
@@ -302,7 +304,6 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
g->y1 = g->y0 + (float)d->h;
|
||||
f->glyph_count++;
|
||||
}
|
||||
FT_Done_Face(face);
|
||||
f->fallback = reaktor_font_glyph(f, '?');
|
||||
if (!f->fallback && f->glyph_count) f->fallback = &f->glyphs[0];
|
||||
}
|
||||
@@ -324,6 +325,7 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
}
|
||||
ok = 1;
|
||||
done:
|
||||
if (face) FT_Done_Face(face);
|
||||
SDL_free(cp);
|
||||
SDL_free(b);
|
||||
SDL_free(bits);
|
||||
@@ -331,6 +333,33 @@ done:
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_fontset_copy(struct reaktor_fontset *to, const struct reaktor_fontset *from)
|
||||
{
|
||||
int glyphs = 0, i;
|
||||
|
||||
SDL_zerop(to);
|
||||
for (i = 0; i < from->count; i++) glyphs += from->fonts[i].glyph_count;
|
||||
if (!(to->fonts = SDL_malloc((size_t)(from->count ? from->count : 1) * sizeof *to->fonts)) ||
|
||||
!(to->glyphs = SDL_malloc((size_t)(glyphs ? glyphs : 1) * sizeof *to->glyphs))) {
|
||||
reaktor_fontset_free(to);
|
||||
return 0;
|
||||
}
|
||||
SDL_memcpy(to->fonts, from->fonts, (size_t)from->count * sizeof *to->fonts);
|
||||
SDL_memcpy(to->glyphs, from->glyphs, (size_t)glyphs * sizeof *to->glyphs);
|
||||
for (i = 0; i < from->count; i++) {
|
||||
struct reaktor_font *f = &to->fonts[i];
|
||||
const struct reaktor_font *s = &from->fonts[i];
|
||||
|
||||
f->glyphs = to->glyphs + (s->glyphs - from->glyphs);
|
||||
if (s->fallback) f->fallback = to->glyphs + (s->fallback - from->glyphs);
|
||||
}
|
||||
to->count = from->count;
|
||||
to->w = from->w;
|
||||
to->h = from->h;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_fontset_bind(struct reaktor_fontset *set, nk_handle texture)
|
||||
{
|
||||
|
||||
@@ -44,6 +44,7 @@ void reaktor_ft_size(FT_Face face, float px);
|
||||
|
||||
int reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src *src,
|
||||
int n, const nk_rune *ranges);
|
||||
int reaktor_fontset_copy(struct reaktor_fontset *to, const struct reaktor_fontset *from);
|
||||
void reaktor_fontset_bind(struct reaktor_fontset *set, nk_handle texture);
|
||||
void reaktor_fontset_free(struct reaktor_fontset *set);
|
||||
|
||||
|
||||
@@ -285,10 +285,16 @@ struct nk_sdl_rect {
|
||||
int opaque;
|
||||
};
|
||||
|
||||
/* REAKTOR: what a run of rectangles left set, put back before triangles. */
|
||||
struct nk_sdl_sw {
|
||||
float tint[4];
|
||||
int tinted, unblended;
|
||||
};
|
||||
|
||||
/* REAKTOR: whether the six indices at ix are one rectangle. */
|
||||
NK_INTERN int
|
||||
nk_sdl_quad(const void *vertices, const nk_draw_index *ix, SDL_Texture *tex,
|
||||
float sx, float sy, struct nk_sdl_rect *q)
|
||||
float tw, float th, float sx, float sy, struct nk_sdl_rect *q)
|
||||
{
|
||||
const struct nk_sdl_vertex *v[6];
|
||||
float x0, x1, y0, y1, u[2] = {0, 0}, w[2] = {0, 0};
|
||||
@@ -339,9 +345,7 @@ nk_sdl_quad(const void *vertices, const nk_draw_index *ix, SDL_Texture *tex,
|
||||
d.y = (d.y + (d.y < 0.0f ? -0.25f : 0.25f)) / sy;
|
||||
|
||||
if (tex) {
|
||||
float tw, th;
|
||||
|
||||
if (!SDL_GetTextureSize(tex, &tw, &th)) return 0;
|
||||
if (!(tw > 0.0f && th > 0.0f)) return 0;
|
||||
/* REAKTOR: a sub-image ends on whole texels, but u * size comes back a
|
||||
* hair under one, and SDL's software copy truncates it a texel short. */
|
||||
q->src.x = SDL_roundf(u[0] * tw);
|
||||
@@ -358,20 +362,36 @@ nk_sdl_quad(const void *vertices, const nk_draw_index *ix, SDL_Texture *tex,
|
||||
|
||||
/* REAKTOR: SDL truncates a scaled rectangle's position and size apart. */
|
||||
NK_INTERN void
|
||||
nk_sdl_quad_draw(SDL_Renderer *ren, SDL_Texture *tex, const struct nk_sdl_rect *q)
|
||||
nk_sdl_quad_draw(SDL_Renderer *ren, SDL_Texture *tex, const struct nk_sdl_rect *q,
|
||||
struct nk_sdl_sw *st)
|
||||
{
|
||||
if (tex) {
|
||||
SDL_SetTextureColorModFloat(tex, q->col[0], q->col[1], q->col[2]);
|
||||
SDL_SetTextureAlphaModFloat(tex, q->col[3]);
|
||||
if (!st->tinted || SDL_memcmp(st->tint, q->col, sizeof st->tint) != 0) {
|
||||
SDL_SetTextureColorModFloat(tex, q->col[0], q->col[1], q->col[2]);
|
||||
SDL_SetTextureAlphaModFloat(tex, q->col[3]);
|
||||
SDL_memcpy(st->tint, q->col, sizeof st->tint);
|
||||
st->tinted = 1;
|
||||
}
|
||||
SDL_RenderTexture(ren, tex, &q->src, &q->d);
|
||||
SDL_SetTextureColorModFloat(tex, 1.0f, 1.0f, 1.0f);
|
||||
SDL_SetTextureAlphaModFloat(tex, 1.0f);
|
||||
return;
|
||||
}
|
||||
if (q->opaque) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE);
|
||||
if (q->opaque != st->unblended) {
|
||||
SDL_SetRenderDrawBlendMode(ren, q->opaque ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND);
|
||||
st->unblended = q->opaque;
|
||||
}
|
||||
SDL_SetRenderDrawColorFloat(ren, q->col[0], q->col[1], q->col[2], q->col[3]);
|
||||
SDL_RenderFillRect(ren, &q->d);
|
||||
if (q->opaque) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
NK_INTERN void
|
||||
nk_sdl_sw_restore(SDL_Renderer *ren, SDL_Texture *tex, struct nk_sdl_sw *st)
|
||||
{
|
||||
if (st->tinted) {
|
||||
SDL_SetTextureColorModFloat(tex, 1.0f, 1.0f, 1.0f);
|
||||
SDL_SetTextureAlphaModFloat(tex, 1.0f);
|
||||
}
|
||||
if (st->unblended) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
|
||||
st->tinted = st->unblended = 0;
|
||||
}
|
||||
|
||||
/* REAKTOR: fill and stroke feathering apart. */
|
||||
@@ -497,23 +517,30 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
|
||||
/* REAKTOR: software rectangles from device pixels. */
|
||||
if (is_sw) {
|
||||
struct nk_sdl_sw st;
|
||||
nk_uint k = 0, from = 0;
|
||||
float tw = 0.0f, th = 0.0f;
|
||||
|
||||
SDL_zero(st);
|
||||
if (tex && !SDL_GetTextureSize(tex, &tw, &th)) tw = th = 0.0f;
|
||||
while (k + 6 <= cmd->elem_count) {
|
||||
struct nk_sdl_rect q;
|
||||
|
||||
if (!nk_sdl_quad(vertices, offset + k, tex, sx, sy, &q)) {
|
||||
if (!nk_sdl_quad(vertices, offset + k, tex, tw, th, sx, sy, &q)) {
|
||||
k += 3;
|
||||
continue;
|
||||
}
|
||||
/* What came before it in the list is drawn before it. */
|
||||
if (k > from)
|
||||
if (k > from) {
|
||||
nk_sdl_sw_restore(sdl->renderer, tex, &st);
|
||||
nk_sdl_geometry_sw(sdl->renderer, tex, vertices, n,
|
||||
offset + from, (int)(k - from));
|
||||
nk_sdl_quad_draw(sdl->renderer, tex, &q);
|
||||
}
|
||||
nk_sdl_quad_draw(sdl->renderer, tex, &q, &st);
|
||||
k += 6;
|
||||
from = k;
|
||||
}
|
||||
nk_sdl_sw_restore(sdl->renderer, tex, &st);
|
||||
if (cmd->elem_count > from)
|
||||
nk_sdl_geometry_sw(sdl->renderer, tex, vertices, n,
|
||||
offset + from,
|
||||
|
||||
+9
-6
@@ -636,10 +636,11 @@ reaktor_select(const reaktor_select_spec *s)
|
||||
void
|
||||
reaktor_slider(const reaktor_slider_spec *s)
|
||||
{
|
||||
reaktor_box box;
|
||||
char text[32];
|
||||
unsigned id = 0;
|
||||
float now;
|
||||
reaktor_box box;
|
||||
reaktor_style fill;
|
||||
char text[32];
|
||||
unsigned id = 0;
|
||||
float now;
|
||||
|
||||
if (!g_frame_app || !s || (!s->value && !s->ivalue)) return;
|
||||
now = s->value ? *s->value : (float)*s->ivalue;
|
||||
@@ -656,12 +657,14 @@ reaktor_slider(const reaktor_slider_spec *s)
|
||||
if (!decl_place(REAKTOR_A11Y_SLIDER, s->name, text, 0u, NULL, &box, &id))
|
||||
return;
|
||||
|
||||
reaktor_style_get(s->style ? s->style : "input.type-range", &fill);
|
||||
reaktor_note_mute(g_frame_app, 1);
|
||||
if (s->value)
|
||||
reaktor_slider_bar(g_frame_app, g_frame_ctx, id, s->value, s->lo, s->hi, s->step);
|
||||
reaktor_slider_ramp(g_frame_app, g_frame_ctx, id, s->value, s->lo, s->hi, s->step,
|
||||
&fill);
|
||||
else
|
||||
reaktor_slider_bar_int(g_frame_app, g_frame_ctx, id, s->ivalue, (int)s->lo,
|
||||
(int)s->hi, (int)s->step);
|
||||
(int)s->hi, (int)s->step, &fill);
|
||||
reaktor_note_mute(g_frame_app, 0);
|
||||
}
|
||||
|
||||
|
||||
+12
-9
@@ -282,17 +282,21 @@ decl_place(unsigned char role, const char *name, const char *value, unsigned sta
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct nk_user_font *
|
||||
style_font(const reaktor_style *st)
|
||||
{
|
||||
return st->matched && st->font_px > 0 ? pick_font(g_frame_app, st->font_px, st->bold)
|
||||
: g_frame_ctx->style.font;
|
||||
}
|
||||
|
||||
const struct nk_user_font *
|
||||
decl_style_font(const char *selector)
|
||||
{
|
||||
reaktor_style st;
|
||||
|
||||
if (selector) {
|
||||
reaktor_style_get(selector, &st);
|
||||
if (st.matched && st.font_px > 0)
|
||||
return pick_font(g_frame_app, st.font_px, st.bold);
|
||||
}
|
||||
return g_frame_ctx->style.font;
|
||||
if (!selector) return g_frame_ctx->style.font;
|
||||
reaktor_style_get(selector, &st);
|
||||
return style_font(&st);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -342,23 +346,22 @@ void
|
||||
decl_box_from_style(reaktor_box *box, const char *text, const char *selector,
|
||||
const char *element, float pad_x, float pad_y)
|
||||
{
|
||||
const char *sel = element ? element : selector;
|
||||
const struct nk_user_font *f;
|
||||
reaktor_style st;
|
||||
float extra_w, extra_h;
|
||||
|
||||
memset(&st, 0, sizeof(st));
|
||||
if (element) reaktor_style_get(element, &st);
|
||||
f = style_font(&st);
|
||||
if (selector) {
|
||||
reaktor_style narrow;
|
||||
|
||||
reaktor_style_get(selector, &narrow);
|
||||
if (narrow.matched) {
|
||||
sel = selector;
|
||||
f = style_font(&narrow);
|
||||
overlay(&st, &narrow);
|
||||
}
|
||||
}
|
||||
f = decl_style_font(sel);
|
||||
|
||||
if (st.matched) {
|
||||
extra_w = st.pad[REAKTOR_SIDE_LEFT] + st.pad[REAKTOR_SIDE_RIGHT]
|
||||
|
||||
+59
-18
@@ -48,6 +48,7 @@ static struct {
|
||||
float *border, border_was;
|
||||
int edges;
|
||||
struct nk_color edge_hover, edge_active;
|
||||
struct { struct nk_color from, to; int axis; } ramp[3];
|
||||
} g_chrome;
|
||||
|
||||
static void
|
||||
@@ -76,6 +77,7 @@ reaktor_chrome_disarm(void)
|
||||
{
|
||||
g_chrome.armed = 0;
|
||||
g_chrome.edges = 0;
|
||||
g_chrome.ramp[0].axis = g_chrome.ramp[1].axis = g_chrome.ramp[2].axis = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -97,19 +99,25 @@ button_chrome_begin(struct nk_command_buffer *out, nk_handle user)
|
||||
struct nk_style_button *st = &app->ctx->style.button;
|
||||
nk_flags state = app->ctx->last_widget_state;
|
||||
struct nk_color col, edge = st->border_color;
|
||||
float k = st->color_factor_background;
|
||||
int at = (state & NK_WIDGET_STATE_HOVER) ? 1 : (state & NK_WIDGET_STATE_ACTIVED) ? 2 : 0;
|
||||
|
||||
if (!g_chrome.armed ||
|
||||
!chrome_take((state & NK_WIDGET_STATE_HOVER) ? &st->hover
|
||||
: (state & NK_WIDGET_STATE_ACTIVED) ? &st->active
|
||||
: &st->normal, &col))
|
||||
!chrome_take(at == 1 ? &st->hover : at == 2 ? &st->active : &st->normal, &col))
|
||||
return;
|
||||
if (g_chrome.edges)
|
||||
edge = (state & NK_WIDGET_STATE_HOVER) ? g_chrome.edge_hover
|
||||
: (state & NK_WIDGET_STATE_ACTIVED) ? g_chrome.edge_active : edge;
|
||||
reaktor_paint_surface(app, out, g_chrome.b, &(reaktor_surface){
|
||||
nk_rgb_factor(col, st->color_factor_background),
|
||||
nk_rgb_factor(edge, st->color_factor_background),
|
||||
st->border, st->rounding });
|
||||
edge = at == 1 ? g_chrome.edge_hover : at == 2 ? g_chrome.edge_active : edge;
|
||||
if (g_chrome.ramp[at].axis) {
|
||||
reaktor_fill_gradient(app, out, g_chrome.b, st->rounding,
|
||||
nk_rgb_factor(g_chrome.ramp[at].from, k),
|
||||
nk_rgb_factor(g_chrome.ramp[at].to, k),
|
||||
g_chrome.ramp[at].axis);
|
||||
reaktor_edge_round(app, out, g_chrome.b, st->rounding, st->border,
|
||||
nk_rgb_factor(edge, k));
|
||||
} else {
|
||||
reaktor_paint_surface(app, out, g_chrome.b, &(reaktor_surface){
|
||||
nk_rgb_factor(col, k), nk_rgb_factor(edge, k), st->border, st->rounding });
|
||||
}
|
||||
g_chrome.border = &st->border;
|
||||
g_chrome.border_was = st->border;
|
||||
st->border = 0.0f;
|
||||
@@ -181,6 +189,28 @@ push_button_look(App *app, struct nk_context *ctx, const reaktor_button_look *k)
|
||||
g_chrome.edges = 1;
|
||||
g_chrome.edge_hover = nk_rgba_bv(hov->matched ? hov->border_col : s.border_col);
|
||||
g_chrome.edge_active = nk_rgba_bv(act->matched ? act->border_col : s.border_col);
|
||||
{
|
||||
const reaktor_style *by[3];
|
||||
int i;
|
||||
|
||||
by[0] = &s;
|
||||
by[1] = hov->matched ? hov : &s;
|
||||
by[2] = act->matched ? act : by[1];
|
||||
for (i = 0; i < 3; i++) {
|
||||
unsigned char from[4], to[4];
|
||||
|
||||
g_chrome.ramp[i].axis = by[i]->gradient;
|
||||
if (!by[i]->gradient) continue;
|
||||
memcpy(from, by[i]->gradient_from, 4);
|
||||
memcpy(to, by[i]->gradient_to, 4);
|
||||
if (i == 2 && !act->matched) {
|
||||
reaktor_style_darken(from, 0.10f);
|
||||
reaktor_style_darken(to, 0.10f);
|
||||
}
|
||||
g_chrome.ramp[i].from = nk_rgba_bv(from);
|
||||
g_chrome.ramp[i].to = nk_rgba_bv(to);
|
||||
}
|
||||
}
|
||||
|
||||
nk_style_push_float(ctx, &ctx->style.button.rounding, s.rounding);
|
||||
nk_style_push_float(ctx, &ctx->style.button.border, s.border);
|
||||
@@ -270,18 +300,29 @@ reaktor_css_button_look(App *app, struct nk_context *ctx,
|
||||
return clicked;
|
||||
}
|
||||
|
||||
static float
|
||||
linear(unsigned char c)
|
||||
{
|
||||
static float table[256];
|
||||
static int filled;
|
||||
|
||||
if (!filled) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
float v = i / 255.0f;
|
||||
table[i] = v <= 0.04045f ? v / 12.92f
|
||||
: powf((v + 0.055f) / 1.055f, 2.4f);
|
||||
}
|
||||
filled = 1;
|
||||
}
|
||||
return table[c];
|
||||
}
|
||||
|
||||
static float
|
||||
luminance(const unsigned char c[4])
|
||||
{
|
||||
float ch[3];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
float v = c[i] / 255.0f;
|
||||
ch[i] = v <= 0.04045f ? v / 12.92f
|
||||
: powf((v + 0.055f) / 1.055f, 2.4f);
|
||||
}
|
||||
return 0.2126f * ch[0] + 0.7152f * ch[1] + 0.0722f * ch[2];
|
||||
return 0.2126f * linear(c[0]) + 0.7152f * linear(c[1]) + 0.0722f * linear(c[2]);
|
||||
}
|
||||
|
||||
static float
|
||||
|
||||
+5
-8
@@ -194,14 +194,13 @@ list_follow(const reaktor_list_spec *s, int focused, struct nk_rect area, float
|
||||
|
||||
/* Row r's first column in a tree; 1 when the selection should move to t->jump. */
|
||||
static int
|
||||
tree_first(tree_rows *t, int r, unsigned id, struct nk_color fg, float pad)
|
||||
tree_first(tree_rows *t, int r, const char *label, unsigned id, struct nk_color fg, float pad)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
const reaktor_tree_spec *s = t->s;
|
||||
int node = t->node[r], branch = tree_branch(t, node), step, up;
|
||||
struct nk_rect b, chev;
|
||||
const char *label = s->label(node, s->user);
|
||||
const char *icon = s->icon ? s->icon(node, s->user) : NULL;
|
||||
float x;
|
||||
|
||||
@@ -377,9 +376,6 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
even = reaktor_token("--table-bg-alt", odd);
|
||||
head_bg = thead.matched && thead.bg[3] ? reaktor_col(thead.bg)
|
||||
: reaktor_token("--table", g_frame_app->accent);
|
||||
head_bg = reaktor_visible(reaktor_visible(head_bg, reaktor_page_color(g_frame_app),
|
||||
g_frame_app->accent),
|
||||
odd, g_frame_app->accent);
|
||||
|
||||
box = s->box;
|
||||
if (!box.name) box.name = s->name;
|
||||
@@ -433,6 +429,7 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
struct nk_color fg = g_frame_ctx->style.text.color;
|
||||
int on = s->selected && *s->selected == r;
|
||||
struct nk_rect row;
|
||||
const char *first = s->cell(r, 0, s->user);
|
||||
unsigned id;
|
||||
|
||||
nk_layout_row(g_frame_ctx, NK_DYNAMIC, row_h, cols, ratio);
|
||||
@@ -442,7 +439,7 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
if (s->selected) reaktor_hot(g_frame_app, row, REAKTOR_CURSOR_DEFAULT, 1);
|
||||
id = reaktor_note(g_frame_app,
|
||||
t ? REAKTOR_A11Y_TREEITEM : REAKTOR_A11Y_LISTITEM,
|
||||
s->cell(r, 0, s->user), NULL,
|
||||
first, NULL,
|
||||
(on ? REAKTOR_A11Y_SELECTED : 0u) |
|
||||
(t && tree_branch(t, t->node[r]) && t->s->open[t->node[r]]
|
||||
? REAKTOR_A11Y_EXPANDED : 0u), row);
|
||||
@@ -456,10 +453,10 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
reaktor_token("--background-hover", nk_rgba(128, 128, 128, 60)));
|
||||
}
|
||||
for (c = 0; c < cols; c++) {
|
||||
const char *cell = s->cell(r, c, s->user);
|
||||
const char *cell = c ? s->cell(r, c, s->user) : first;
|
||||
|
||||
if (t && c == 0) {
|
||||
if (tree_first(t, r, id, fg, pad) && s->selected) {
|
||||
if (tree_first(t, r, cell, id, fg, pad) && s->selected) {
|
||||
int k = t->row[t->jump];
|
||||
|
||||
if (k >= 0 && *s->selected != k) {
|
||||
|
||||
+35
-3
@@ -23,6 +23,24 @@ reaktor_font(App *app, int px, int bold)
|
||||
return pick_font(app, px, bold);
|
||||
}
|
||||
|
||||
struct nk_vec2
|
||||
reaktor_item_spacing(struct nk_context *ctx)
|
||||
{
|
||||
return ctx->style.window.spacing;
|
||||
}
|
||||
|
||||
struct nk_color
|
||||
reaktor_text_color(struct nk_context *ctx)
|
||||
{
|
||||
return ctx->style.text.color;
|
||||
}
|
||||
|
||||
const struct nk_user_font *
|
||||
reaktor_current_font(struct nk_context *ctx)
|
||||
{
|
||||
return ctx->style.font;
|
||||
}
|
||||
|
||||
#define ICON_HAIRLINE_BELOW 20
|
||||
|
||||
const char *
|
||||
@@ -206,6 +224,14 @@ shaded(struct nk_color c, float amount)
|
||||
void
|
||||
reaktor_slider_bar(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
float lo, float hi, float step)
|
||||
{
|
||||
reaktor_slider_ramp(app, ctx, id, val, lo, hi, step, NULL);
|
||||
}
|
||||
|
||||
/* With a rule that has a gradient, the filled part is that gradient. */
|
||||
void
|
||||
reaktor_slider_ramp(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
float lo, float hi, float step, const reaktor_style *fill)
|
||||
{
|
||||
const struct nk_style_slider *st = &ctx->style.slider;
|
||||
struct nk_style_item clear = nk_style_item_color(nk_rgba(0, 0, 0, 0));
|
||||
@@ -263,7 +289,10 @@ reaktor_slider_bar(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
st->cursor_size.x, st->cursor_size.y);
|
||||
|
||||
reaktor_fill_round(app, cv, bar, cap, track);
|
||||
if (fl.w >= 1.0f) reaktor_fill_round(app, cv, fl, cap, filled);
|
||||
if (fl.w >= 1.0f) {
|
||||
if (fill && fill->gradient) reaktor_fill_style(app, cv, fl, cap, fill);
|
||||
else reaktor_fill_round(app, cv, fl, cap, filled);
|
||||
}
|
||||
reaktor_glyph_at(app, ctx, kn, REAKTOR_DISC_ROUND, knob,
|
||||
(int)(st->cursor_size.x < st->cursor_size.y ? st->cursor_size.x
|
||||
: st->cursor_size.y),
|
||||
@@ -272,11 +301,11 @@ reaktor_slider_bar(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
|
||||
void
|
||||
reaktor_slider_bar_int(App *app, struct nk_context *ctx, unsigned id, int *val,
|
||||
int lo, int hi, int step)
|
||||
int lo, int hi, int step, const reaktor_style *fill)
|
||||
{
|
||||
float f = (float)*val;
|
||||
|
||||
reaktor_slider_bar(app, ctx, id, &f, (float)lo, (float)hi, (float)step);
|
||||
reaktor_slider_ramp(app, ctx, id, &f, (float)lo, (float)hi, (float)step, fill);
|
||||
*val = (int)(f + (f < 0.0f ? -0.5f : 0.5f));
|
||||
}
|
||||
|
||||
@@ -1297,6 +1326,9 @@ reaktor_diagnostics(App *app, reaktor_diag *out)
|
||||
out->sheets = app->sheets;
|
||||
out->scale = reaktor_scale();
|
||||
out->style_ms = app->style_ms_x100 / 100.0f;
|
||||
out->window_ms = app->window_ms_x100 / 100.0f;
|
||||
out->atlas_ms = app->atlas_ms_x100 / 100.0f;
|
||||
out->first_frame_ms = app->first_ms_x100 / 100.0f;
|
||||
out->frame_gap_ms = app->frame_gap_ms;
|
||||
out->cpu_ms_per_frame = app->cpu_ms_per_frame;
|
||||
out->hover_gap_ms = (int)g_hover_gap_ms;
|
||||
|
||||
+127
-48
@@ -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; with `.single_instance`, also each file a later launch hands over |
|
||||
| `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. Unset, no window is a drop target, which on Windows spares COM's drag-and-drop: three DLLs and three threads |
|
||||
|
||||
| Call | Effect |
|
||||
| --- | --- |
|
||||
@@ -73,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.8.0"` |
|
||||
| `reaktor_version()` | Reaktor's version, such as `"0.9.0"` |
|
||||
|
||||
The `set` calls are for the main thread, take effect at the next frame, and do
|
||||
nothing when nothing changes.
|
||||
@@ -98,12 +98,14 @@ followed by a frame.
|
||||
| `reaktor_timer(app, ms, repeat, fn, user)` | `fn(app, user)` after `ms`, every `ms` with `repeat`; answers an id. Stops when the window closes |
|
||||
| `reaktor_timer_stop(id)` | Stop one |
|
||||
| `reaktor_post(app, fn, user)` | `fn(app, user)` on the main thread. Any thread; immediate on the main one |
|
||||
| `reaktor_setting(key)`, `reaktor_setting_set(key, value)` | A string kept between runs; `NULL` removes it. `window.maximized` is key `maximized` in section `[window]`. No newlines; no `=`, `[` or `]` in a key |
|
||||
| `reaktor_setting(key)`, `reaktor_setting_set(key, value)` | A string kept between runs; `NULL` removes it. A key is any non-empty string; `window` and `window.maximized` are two keys |
|
||||
| `reaktor_settings_save()`, `reaktor_settings_clear()` | Write the settings now, whatever the mode; empty them and delete the file |
|
||||
|
||||
Settings are an INI file, `settings.conf` in SDL's preference folder for `.id`
|
||||
(or `.name`), read and written by [`ini.h`](https://github.com/mattiasgustavsson/libs);
|
||||
names match case-insensitively. `.save_settings` says when it is written:
|
||||
Settings are a TOML file, `settings.toml` in SDL's preference folder for `.id`
|
||||
(or `.name`), read by [toml-c](https://github.com/arp242/toml-c) and written by
|
||||
the runtime: one quoted key and string per line, `"window.maximized" = "1"`.
|
||||
A hand-written table reads as dotted keys, so `[window]` with `maximized = 1`
|
||||
is the same setting; names match case-sensitively. `.save_settings` says when it is written:
|
||||
|
||||
| `.save_settings` | Written |
|
||||
| --- | --- |
|
||||
@@ -113,7 +115,7 @@ names match case-insensitively. `.save_settings` says when it is written:
|
||||
| `REAKTOR_SAVE_ON_TIMER` | `.save_ms` (1000) after a change, and on quit |
|
||||
|
||||
Each write goes to a new file renamed over the old, so a crash mid-write
|
||||
leaves the last one whole. On the web the same `settings.conf` lives in the
|
||||
leaves the last one whole. On the web the same `settings.toml` lives in the
|
||||
browser's IndexedDB: `tools/web-pre.js` mounts it with Emscripten's IDBFS and
|
||||
loads it before `main` runs, every write is synced back, and saving on quit
|
||||
means saving on change. Clearing site data, or a private window closing,
|
||||
@@ -299,8 +301,9 @@ first column names the row. With `.selected`, a click picks a row and the
|
||||
selection follows keyboard focus; the arrow keys move it, scrolling the row
|
||||
into view. Without it the rows are plain text. Unsized, a list shows up to
|
||||
eight rows and fills its row. Colors come from `thead`, `th`, `td`,
|
||||
`--table-bg` and `--table-bg-alt`, which reaktor.css takes from Water.css's
|
||||
`--links`, `--background-body` and `--background-alt`.
|
||||
`--table`, `--table-bg` and `--table-bg-alt`, which reaktor.css takes from
|
||||
Water.css's `--links`, `--background-body` and `--background-alt`. The header
|
||||
row is `thead`'s background, or `--table` without one, as the sheet writes it.
|
||||
|
||||
**A row can be dragged** out of a list that names a `.drag` kind, a string.
|
||||
Its first column follows the pointer as a tooltip would, and any list of the
|
||||
@@ -529,7 +532,10 @@ popup, toasts are drawn but take no input.
|
||||
### Windows
|
||||
|
||||
`reaktor_window_open` opens a real window with its own renderer, atlas and
|
||||
Nuklear context, and answers its id, or 0 on the web. `.page` draws it with
|
||||
Nuklear context, and answers its id, or 0 on the web. The first such window
|
||||
bakes its atlas and keeps the image, and every later one uploads that copy
|
||||
instead of baking, so the image stays in memory once a second window, or a
|
||||
menu in a window of its own, has opened. `.page` draws it with
|
||||
that window's App, so the same widgets and sheets work, and it follows the
|
||||
main window's theme and scale. It takes its input the way the main window
|
||||
does: focus navigation, the `key` hook and dropped files with its App, one
|
||||
@@ -579,6 +585,14 @@ before `.chosen` runs, so set checkboxes from your state with
|
||||
`reaktor_tray_check(app, index, on)` each frame. `reaktor_tray_close` removes
|
||||
the icon. There is one tray, of up to sixteen entries.
|
||||
|
||||
`reaktor_tray_hide_on_minimize(app, 1)` makes minimizing the main window hide
|
||||
it while the icon is there, so it leaves the taskbar; `reaktor_set_visible(app,
|
||||
1)` brings it back, unminimized. Closing the tray leaves a hidden window
|
||||
hidden, so show it first. The tray has no click of its own, so a Show entry
|
||||
in the menu is the way back. Wayland tells a window nothing when it is minimized, so
|
||||
there it stays in the taskbar. To close to the tray instead, have `closing`
|
||||
hide the window and refuse `REAKTOR_QUIT_WINDOW`.
|
||||
|
||||
```c
|
||||
static const reaktor_tray_item items[] = {
|
||||
{ .label = "Show", .chosen = show },
|
||||
@@ -590,10 +604,20 @@ reaktor_tray_open(app, &(reaktor_tray){
|
||||
.tooltip = "Notes", .items = items, .count = 3 });
|
||||
```
|
||||
|
||||
On Linux and the BSDs, SDL loads AppIndicator (Ayatana's or the original)
|
||||
and GTK 3 when the tray opens; nothing links them, and without them there is
|
||||
no tray. GTK sets the user's locale as it starts, and the runtime puts the C
|
||||
library's back.
|
||||
On Linux, FreeBSD, OpenBSD and NetBSD the tray is Reaktor's own, spoken over
|
||||
libdbus rather than SDL's, which loads AppIndicator and GTK 3. The icon is a
|
||||
StatusNotifierItem (`org.kde.StatusNotifierItem`) registered with the
|
||||
session's `org.kde.StatusNotifierWatcher`, its image the app's SVG icon as
|
||||
`IconPixmap` at 22, 32, 48 and 64 pixels, its tooltip `.tooltip`; the menu is
|
||||
`com.canonical.dbusmenu`, with the entries as labels, separators and
|
||||
checkmark items. The item sets `ItemIsMenu`, so a host opens the menu itself
|
||||
and a left click chooses nothing. KDE Plasma, Cinnamon and MATE (through
|
||||
xapp-sn-watcher), Xfce, LXQt, Budgie and GNOME with the AppIndicator extension
|
||||
show it; a desktop with no watcher on the bus, plain GNOME among them, gets
|
||||
none, and `reaktor_tray_open` answers 0. A watcher that starts or restarts
|
||||
later is told about the item again. One thread waits on the bus's socket and
|
||||
wakes the frame loop, which reads and answers the calls, so `.chosen` still
|
||||
runs on the main thread. Built without dbus-1, they have no tray, and Windows and macOS keep SDL's.
|
||||
|
||||
### Inspector
|
||||
|
||||
@@ -646,7 +670,7 @@ Nuklear's default:
|
||||
```c
|
||||
reaktor_style s;
|
||||
reaktor_style_get("button", &s);
|
||||
if (s.matched) { /* s.bg, s.fg, s.border, s.rounding, s.pad[4], s.font_px */ }
|
||||
if (s.matched) { /* s.bg, s.fg, s.border, s.rounding, s.pad[4], s.font_px, s.gradient */ }
|
||||
```
|
||||
|
||||
| Widget | Reads |
|
||||
@@ -661,7 +685,7 @@ if (s.matched) { /* s.bg, s.fg, s.border, s.rounding, s.pad[4], s.font_px */ }
|
||||
| Floater | `dialog` |
|
||||
| Toast | `.toast`, `.toast-button`, `.toast-close` |
|
||||
| Tooltip | `.tooltip` |
|
||||
| List | `thead`, `th`, `td`; `--table-bg`, `--table-bg-alt` |
|
||||
| List | `thead`, `th`, `td`; `--table`, `--table-bg`, `--table-bg-alt` |
|
||||
| Sidebar, tabs | `.sidebar-item`, `.sidebar-current`, `.sidebar-edge`; `.tab`, `.tab-current`, `.tab-edge` |
|
||||
|
||||
With `:hover` and `:active` where a widget has those states, a button's
|
||||
@@ -688,9 +712,10 @@ and the accent. An icon on a button takes its label's color.
|
||||
row of buttons starts and ends where the field below it does, and each line
|
||||
of a row that wraps starts at the edge. A margin set in code always counts,
|
||||
and a `REAKTOR_FREE` box keeps all four.
|
||||
- **The engine is Reaktor's own, and small.** `core/css/css.c` reads the
|
||||
sheets once into typed values; [What the engine reads](#what-the-engine-reads)
|
||||
lists all of it. reaktor.css uses the scheme branch to strengthen light
|
||||
- **The engine is Reaktor's own, and small.** `core/css/css.c` parses every
|
||||
selector when the sheets load and a rule's declarations the first time a
|
||||
widget's query matches it, so rules nothing asks for cost almost nothing.
|
||||
[What the engine reads](#what-the-engine-reads) lists all of it. 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
|
||||
@@ -701,7 +726,9 @@ 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.
|
||||
system theme changes and when the window regains focus. The portal is asked
|
||||
for all four settings in one call, and a desktop without one is not asked
|
||||
again.
|
||||
|
||||
**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
|
||||
@@ -760,7 +787,8 @@ open at its end, in a comment, string or block, is closed there.
|
||||
| Property | Notes |
|
||||
| --- | --- |
|
||||
| `color`, `background-color` | |
|
||||
| `background` | Its color, wherever it stands among the layers; one with none is transparent |
|
||||
| `background` | Its color, wherever it stands among the layers, and a `linear-gradient()` among them; one with neither is transparent, and a gradient alone stands in as its first stop where a color is read |
|
||||
| `background-image` | `linear-gradient()` or `none`. Two stops, run `to right`, `to left`, `to top`, `to bottom` or a multiple of `90deg`; any other gradient is not drawn. It fills a button (in each state) and a slider's filled part when that slider's rule has one; `background-color` leaves it in place, as in CSS |
|
||||
| `border`, `border-top`, `-right`, `-bottom`, `-left` | Width, style and color in any order. A side with no style has no width; one with no color takes the text's |
|
||||
| `border-width`, `border-style`, and each side's | One to four values; `thin`, `medium` and `thick` are 1, 3 and 5 px |
|
||||
| `border-color`, `border-top-color` | The top color is the one a widget draws |
|
||||
@@ -867,11 +895,12 @@ out by hand inside a declared page. [`include/reaktor/ui.h`](../include/reaktor/
|
||||
| --- | --- |
|
||||
| `reaktor_token`, `reaktor_col`, `reaktor_on`, `reaktor_visible`, `reaktor_page_color`, `reaktor_accent_color` | Colors from the sheet; readable text on a background; the page and the accent |
|
||||
| `reaktor_font`, `reaktor_style_font` | A baked face, by size or by selector |
|
||||
| `reaktor_item_spacing`, `reaktor_text_color`, `reaktor_current_font` | The gap between widgets, the text color and the font in effect now, pushes included |
|
||||
| `reaktor_ionicon`, `reaktor_ionicon_exact`, `reaktor_glyph_at` | An Ionicon as a `reaktor_image`, in any color, or drawn into a rectangle |
|
||||
| `reaktor_image_file`, `REAKTOR_MARK` | Any image asset: an SVG, recolored by `?stroke=#rrggbb&fill=&sw=`, or a PNG or JPEG; the mark's name |
|
||||
| `reaktor_image_centered` | An image at its own size, centered in the next widget slot |
|
||||
| `reaktor_style_frame`, `reaktor_style_frame_pop` | Counts of style pushes, popped together |
|
||||
| `reaktor_fill_round`, `reaktor_edge_round` | Rounded fills and borders, smooth on the software renderer |
|
||||
| `reaktor_fill_round`, `reaktor_fill_gradient`, `reaktor_edge_round` | Rounded fills, two-stop gradients (`REAKTOR_GRADIENT_ACROSS` left to right, `_DOWN` top to bottom) and borders, smooth on the software renderer |
|
||||
| `reaktor_hot`, `reaktor_hot_top`, `reaktor_hot_follow` | A rectangle that redraws on hover ([the frame loop](#the-frame-loop)), with a `REAKTOR_CURSOR_*` over it: default, pointer, text, or a horizontal or vertical resize |
|
||||
| `reaktor_tip(app, rect, text)` | A tooltip over a rectangle you drew yourself, such as a bar of a chart; the text is copied, and the rectangle redraws as the pointer crosses it |
|
||||
| `reaktor_button_label`, `reaktor_button_icon`, `reaktor_button_accent`, `reaktor_button_accent_icon`, `reaktor_field_text`, `reaktor_slider_bar`, `reaktor_progress_bar`, `reaktor_chevron_at` | Styled controls inside hand-laid rows |
|
||||
@@ -898,7 +927,7 @@ flowchart TB
|
||||
rt["<b>runtime/</b><br/>the windows, the event loop, the tray"]
|
||||
ui["<b>core/ui</b><br/>specs, layout, widgets, layers, keys, focus"]
|
||||
ren["<b>core/render</b><br/>Nuklear, then the SDL3 software rasterizer"]
|
||||
sdl["<b>SDL3</b><br/>window, input, surface, dialogs, tray"]
|
||||
sdl["<b>SDL3</b><br/>window, input, surface, dialogs, the tray on Windows and macOS"]
|
||||
|
||||
css["<b>core/css</b><br/>the CSS engine, style_map"]
|
||||
tree["<b>core/a11y + core/anim</b><br/>the shadow tree, eased values"]
|
||||
@@ -922,20 +951,22 @@ core/a11y the shadow tree and its diff
|
||||
core/anim NukAnim, a context a window
|
||||
core/locale the Locale module
|
||||
core/text the Text module
|
||||
platform/ theme, process lifecycle, the accessibility bridges, the web keyboard
|
||||
platform/ theme, process lifecycle, the accessibility bridges, notifications,
|
||||
the web keyboard
|
||||
runtime/ the main window's lifecycle and frame (app.c), input, services,
|
||||
other windows, the tray
|
||||
samples/ showcase, notepad, simple, bench
|
||||
tests/ the console tests and launchtest
|
||||
tools/ packaging, the icon compiler, vmwalk
|
||||
benchmarks/ bench in four other frameworks, and the sampler
|
||||
external/ thirteen submodules, read as they ship
|
||||
external/ twelve submodules, read as they ship
|
||||
```
|
||||
|
||||
`runtime/` and `core/` build `reaktor_runtime`, a static library every
|
||||
program links. `core/locale`, `core/text` and the bridges are
|
||||
[modules](#build-options), compiled into the programs that take them. Nothing
|
||||
in `core/` knows which application it is in.
|
||||
program links. The nine [modules](#build-options) — the bridges,
|
||||
`core/locale`, `core/text`, `platform/notify`, and settings, the tray, popup
|
||||
windows, printing and the Inspector in `runtime/` — are compiled into the
|
||||
programs that take them. Nothing in `core/` knows which application it is in.
|
||||
|
||||
**The default look is compiled in**: Aileron in both weights, the mark, the
|
||||
seven Ionicons the widgets draw (three chevrons, three discs and the toast's
|
||||
@@ -1070,12 +1101,12 @@ cmake --install build --prefix libreaktor --component libreaktor
|
||||
|
||||
It is one static library — `reaktor.lib` with MSVC, `libreaktor.a` elsewhere
|
||||
— holding Reaktor, every module, SDL, FreeType, plutosvg, Onlay, NukAnim,
|
||||
mojibake and kb_text_shape, merged with `lib.exe`, Apple's `libtool` or an
|
||||
mojibake, kb_text_shape and toml-c, merged with `lib.exe`, Apple's `libtool` or an
|
||||
`ar` MRI script. Beside it go the public headers with Nuklear's, NukAnim's
|
||||
and SDL's, a CMake package, a pkg-config file and `share/reaktor/licenses`:
|
||||
|
||||
```cmake
|
||||
find_package(reaktor 0.8 REQUIRED)
|
||||
find_package(reaktor 0.9 REQUIRED)
|
||||
add_executable(app WIN32 main.c)
|
||||
target_link_libraries(app PRIVATE reaktor::reaktor)
|
||||
```
|
||||
@@ -1089,10 +1120,27 @@ the emscripten toolchain searches only its own sysroot.
|
||||
against an installed package: every CI job does, and checks it draws as the
|
||||
in-tree build does.
|
||||
|
||||
**Shared.** On Linux, the BSDs and macOS, `-DREAKTOR_SHARED=ON` also builds
|
||||
the library shared, so several apps map one copy: `libreaktor.so` with SDL as
|
||||
`libreaktor-sdl3.so`, or `Reaktor.framework` with SDL inside. The modules
|
||||
stay in each app, from `libreaktor-modules.a`. Link `reaktor::shared`, or on
|
||||
Linux and the BSDs `pkg-config --cflags --libs reaktor-shared`; the framework
|
||||
has no `.pc`. Releases carry it as
|
||||
`libreaktor-shared-<version>-<system>-<arch>`. Its soname is `libreaktor.so.0`
|
||||
(OpenBSD installs no unversioned `libreaktor.so`), and it exports only what
|
||||
`tools/reaktor.map` names: the public calls, with Nuklear's and NukAnim's,
|
||||
under `LIBREAKTOR_0`, and what the modules call under `LIBREAKTOR_PRIVATE_0`,
|
||||
which an application must not reach.
|
||||
|
||||
**As a system package.** `tools/libreaktor-pkg.sh` builds libreaktor and packs
|
||||
it for the system it runs on: a `.deb` where `dpkg-deb` exists, an `.rpm`
|
||||
where `rpmbuild` does, a FreeBSD, OpenBSD or NetBSD package, or a `.tar.gz`.
|
||||
`-i` installs it, `-p` sets the prefix, `-o` the output folder, `-b` packs
|
||||
`-i` installs it, `-s` builds the shared library too and splits the package
|
||||
in three: `libreaktor0` and `libreaktor-sdl3-0` to run an app
|
||||
(`libreaktor-sdl3` on OpenBSD, whose package names read a dash before a digit
|
||||
as the version) and `libreaktor-shared`, with the headers and both
|
||||
libraries, to build one,
|
||||
`-p` sets the prefix, `-o` the output folder, `-b` packs
|
||||
from an existing build. On Linux the `deb` and `rpm` targets do the same from
|
||||
the current build, into `build/dist`; each release carries both, built by CI.
|
||||
|
||||
@@ -1104,8 +1152,11 @@ sh tools/libreaktor-pkg.sh -i
|
||||
The prefix is `/opt/reaktor` on Linux and `/usr/local/reaktor` on the BSDs,
|
||||
apart from the system's include directory, because the package carries SDL's
|
||||
and Nuklear's headers. Point `CMAKE_PREFIX_PATH` or `PKG_CONFIG_PATH` (its
|
||||
`lib/pkgconfig`) there. The package lists no dependencies: link the system
|
||||
libraries `pkg-config --libs reaktor` names.
|
||||
`lib/pkgconfig`) there. No package depends on a system library — link the
|
||||
ones `pkg-config --libs reaktor` names — only on the others of a split:
|
||||
`libreaktor0` needs `libreaktor-sdl3-0`, and `libreaktor-shared` both.
|
||||
`libreaktor` and `libreaktor-shared` install the same headers, so each
|
||||
conflicts with the other.
|
||||
|
||||
## Build options
|
||||
|
||||
@@ -1122,13 +1173,15 @@ Passed to CMake, through either script:
|
||||
| `REAKTOR_LOCALE` | `ON` | Translations and formatting — [Localization](#localization) |
|
||||
| `REAKTOR_LOCALE_EMBED` | `OFF` | Compile the catalogs in rather than read them at startup |
|
||||
| `REAKTOR_TEXT` | `ON` | Direction, shaping, fallback glyphs and Unicode line breaks — [Text](#text) |
|
||||
| `REAKTOR_SETTINGS` | `ON` | Settings kept between runs, in `settings.conf` |
|
||||
| `REAKTOR_SETTINGS` | `ON` | Settings kept between runs, in `settings.toml` |
|
||||
| `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 |
|
||||
| `REAKTOR_INSPECTOR` | `ON` | The [Inspector](#inspector) |
|
||||
| `REAKTOR_SDL_GL` | `OFF` | Build SDL's OpenGL and GLES drivers on Windows, Linux and the BSDs |
|
||||
| `REAKTOR_RENDERERS` | empty | The renderers built beside `software`, in `--renderer`'s words, with commas or semicolons between: `direct3d11`, `direct3d12`, `opengl`, `opengles2`. Empty is the platform's default, `direct3d11,direct3d12` on Windows and nothing on Linux and the BSDs; `none` is software only, and a Windows program is then 105 KB smaller. macOS builds `metal` and `opengl` either way, the web `opengles2` |
|
||||
| `REAKTOR_SHADERS` | `OFF` | Build SDL's GPU API and its renderer, `--renderer sdl-gpu`, for an application's own shaders: Direct3D 12 on Windows, Metal on macOS, Vulkan on Linux and the BSDs; on, a program is 184 KB larger on Windows, and on Linux loads the Vulkan drivers even to draw in software |
|
||||
| `REAKTOR_SHARED` | `OFF` | Also build the [shared library](#in-your-own-project), and link the samples to it; Linux, the BSDs and macOS |
|
||||
| `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 |
|
||||
|
||||
@@ -1153,9 +1206,10 @@ windowed program unless `CONSOLE` is given, and on the web adds the link
|
||||
options a page needs; `ASSETS <file>@<path>` packs files beside it there.
|
||||
|
||||
- **`REAKTOR_A11Y=OFF`** drops the bridges and the libraries only they need:
|
||||
`uiautomationcore`, `ole32` and `oleaut32` on Windows, `dbus-1` on Linux and
|
||||
the BSDs. It saves few bytes ([PERFORMANCE.md](PERFORMANCE.md#modules)); the
|
||||
reason to use it is not needing `dbus-1`.
|
||||
`uiautomationcore`, `ole32` and `oleaut32` on Windows. It saves few bytes
|
||||
([PERFORMANCE.md](PERFORMANCE.md#modules)). On Linux and the BSDs `dbus-1`
|
||||
stays linked for the tray and notifications; a program that links no
|
||||
`dbus-1` turns `REAKTOR_TRAY` and `REAKTOR_NOTIFY` off too.
|
||||
- **`REAKTOR_LOCALE=OFF`** leaves every string as its key, bakes Latin-1
|
||||
alone, and stops the web build packing the catalogs and the Japanese font.
|
||||
- **`REAKTOR_LOCALE_EMBED=ON`** reads `assets/locale/*.txt` into the program
|
||||
@@ -1163,11 +1217,12 @@ options a page needs; `ASSETS <file>@<path>` packs files beside it there.
|
||||
- **`REAKTOR_TEXT=OFF`** leaves mojibake and kb_text_shape out. Nothing is
|
||||
reordered, shaped or taken from another font, and a line breaks after a
|
||||
space: Polish is untouched, Japanese comes out as boxes.
|
||||
- **`REAKTOR_SETTINGS=OFF`** leaves `ini.h` and the web's IndexedDB out:
|
||||
- **`REAKTOR_SETTINGS=OFF`** leaves toml-c and the web's IndexedDB out:
|
||||
`reaktor_setting` answers `NULL`, saving and clearing do nothing, and
|
||||
`.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_TRAY=OFF`** answers 0 from `reaktor_tray_open`, links no
|
||||
`dbus-1` for the tray on Linux and the BSDs, and minimizing never hides
|
||||
the window.
|
||||
- **`REAKTOR_PRINT=OFF`** leaves the print module out; `reaktor_print` and
|
||||
`reaktor_print_pdf` answer 0.
|
||||
- **`REAKTOR_INSPECTOR=OFF`** answers 0 from `reaktor_inspector_open` and
|
||||
@@ -1189,7 +1244,8 @@ removes them from `argv` before the application sees it:
|
||||
| `--theme <system\|light\|dark>` | Open in that scheme; on OpenBSD `system` reads as light |
|
||||
| `--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`, `directx`, or a driver name; see [The renderer](#the-renderer) |
|
||||
| `--renderer <name>` | `software` (default), `auto`, `gpu`, `sdl-gpu`, `directx`, or a driver name; see [The renderer](#the-renderer) |
|
||||
| `--hdr <on\|off>` | Make the renderer with an HDR output, as `.hdr` does; see [The renderer](#the-renderer) |
|
||||
| `--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 |
|
||||
@@ -1298,9 +1354,9 @@ command line names one, and `--new-instance` is passed for it.
|
||||
`software` is the default on every platform:
|
||||
|
||||
- **It needs no GPU.** Without one, Direct3D falls back to Microsoft's WARP
|
||||
emulation: drawing `bench` flat out, SDL's software renderer took 0.72 ms
|
||||
of CPU a frame where Direct3D on WARP took 1.65.
|
||||
- **It uses the least memory**, 8.9 MB in `bench` against 58–121 MB on a GPU
|
||||
emulation: drawing `bench` flat out, SDL's software renderer took 0.75 ms
|
||||
of CPU a frame where Direct3D on WARP took 1.78.
|
||||
- **It uses the least memory**, 9.1 MB in `bench` against 57–121 MB on a GPU
|
||||
renderer, most of that the graphics driver's.
|
||||
- **It starts fastest, and its cost does not depend on other programs** using
|
||||
the GPU.
|
||||
@@ -1311,14 +1367,37 @@ command line names one, and `--new-instance` is passed for it.
|
||||
|
||||
| Name | Where | For | Against |
|
||||
| --- | --- | --- | --- |
|
||||
| `gpu` | Everywhere | `metal` on macOS; `opengl`, else `direct3d12`, else `direct3d11` on Windows; `opengl`, else `opengles2` on Linux and the BSDs; `opengles2` on the web | A driver left out of the build is skipped, so without `opengl` in `REAKTOR_RENDERERS` it is `directx` on Windows; on Linux with no GPU, `opengl` runs on the CPU through Mesa |
|
||||
| `directx` | Windows | Direct3D 12 where it starts, else 11 | As below |
|
||||
| `direct3d12` | Windows 10 and later | Least CPU once running | Most memory, slowest start |
|
||||
| `direct3d11` | Windows | Any Windows GPU | Most CPU of the GPU renderers measured |
|
||||
| `opengl` | Windows, Linux, BSDs | Little CPU once running | Built only with `-DREAKTOR_SDL_GL=ON`; on Linux without a GPU it loads Mesa and LLVM |
|
||||
| `opengles2` | Where the driver offers it | | Built only with `-DREAKTOR_SDL_GL=ON`; not measured |
|
||||
| `direct3d11` | Windows | Any Windows GPU | Most CPU of the GPU renderers measured; neither Direct3D renderer is built with `-DREAKTOR_RENDERERS=none` |
|
||||
| `opengl` | Windows, Linux, BSDs, macOS | Little CPU once running | Built only with `opengl` in `REAKTOR_RENDERERS`, except on macOS; on Linux without a GPU it loads Mesa and LLVM; macOS deprecates it in favor of Metal |
|
||||
| `opengles2` | Where the driver offers it | | Built only with `opengles2` in `REAKTOR_RENDERERS`; not measured |
|
||||
| `metal` | macOS | | |
|
||||
| `sdl-gpu` | Windows, macOS, Linux, BSDs | SDL's GPU API: Direct3D 12, Metal or Vulkan, and an application's own shaders through `SDL_CreateGPURenderState` | Built only with `-DREAKTOR_SHADERS=ON`; not measured |
|
||||
| `auto` | Everywhere | SDL chooses | |
|
||||
|
||||
**An application names its renderer** with the launch's `.renderer`, read as
|
||||
`--renderer` is when the flag is not given, so `"sdl-gpu"`, in a build with
|
||||
`-DREAKTOR_SHADERS=ON`, lets it draw with its own shaders:
|
||||
`reaktor_sdl_renderer(app)` hands it the renderer, and the renderer's
|
||||
`SDL_PROP_RENDERER_GPU_DEVICE_POINTER` the device they are made for.
|
||||
|
||||
**HDR output** is the launch's `.hdr`, or `--hdr on`. The renderer is then made
|
||||
with a linear (scRGB) output, which SDL scales so sRGB drawing looks as before
|
||||
while an HDR texture can go past white. The colorspace is fixed when the
|
||||
renderer is made, so the software renderer, a display without HDR under
|
||||
`sdl-gpu`, or a renderer that refuses it gets an SDR one as before, and turning
|
||||
the system's HDR on or off takes effect at the next launch. On an SDR display a
|
||||
GPU renderer other than `sdl-gpu` keeps the linear output, which blends in
|
||||
linear light: edges and text come out slightly different from an SDR renderer.
|
||||
|
||||
**Prefer `directx` or `direct3d12` to `direct3d11`.** Once running,
|
||||
`direct3d11` took 13.4% of a core where `direct3d12` and `opengl` took 5.6%,
|
||||
and turning vsync off did not change it: the cost is in SDL's Direct3D 11
|
||||
renderer or the driver, not in Reaktor's frame. Pick it only where Direct3D 12
|
||||
will not start; `directx` does that by itself.
|
||||
|
||||
A GPU renderer smooths the edges of fills unless `.anti_aliasing` says
|
||||
otherwise, and keeps the CPU free during long animations. It costs six to
|
||||
thirteen times the memory and more CPU to start, and it shares the GPU: with
|
||||
|
||||
+9
-7
@@ -78,7 +78,7 @@ directly. See [An application](DOCUMENTATION.md#an-application).
|
||||
|
||||
### Why C99 and an immediate-mode core instead of a retained toolkit like GTK or Qt?
|
||||
|
||||
To stay small: a 2.2 MB binary, 7–13 MB of RAM, no GPU, and nothing to
|
||||
To stay small: a 2.1 MB binary, 7–13 MB of RAM, no GPU, and nothing to
|
||||
install beside it. A frame is drawn only when something changes, so the app
|
||||
idles at 0% of a core. See [The frame loop](DOCUMENTATION.md#the-frame-loop)
|
||||
and [PERFORMANCE.md](PERFORMANCE.md).
|
||||
@@ -152,7 +152,7 @@ sheet, rounded fills and borders, a hot rectangle so hover redraws, and a
|
||||
|
||||
### Where are settings stored, and when are they saved?
|
||||
|
||||
In `settings.conf`, an INI file in SDL's preference folder for the app.
|
||||
In `settings.toml`, a TOML file in SDL's preference folder for the app.
|
||||
`.save_settings` picks when: never (the default), on quit, on every change,
|
||||
or `.save_ms` after a change. `reaktor_settings_save` writes now and
|
||||
`reaktor_settings_clear` empties them and deletes the file. See
|
||||
@@ -160,7 +160,7 @@ or `.save_ms` after a change. `reaktor_settings_save` writes now and
|
||||
|
||||
### How do settings work on the web?
|
||||
|
||||
The same `settings.conf` lives in the browser's IndexedDB, loaded before
|
||||
The same `settings.toml` lives in the browser's IndexedDB, loaded before
|
||||
`main` and synced after each write; saving on quit means saving on change
|
||||
there. Clearing site data or closing a private window loses it.
|
||||
|
||||
@@ -207,7 +207,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.8 REQUIRED)`
|
||||
`sh tools/libreaktor-pkg.sh -i`. Then `find_package(reaktor 0.9 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).
|
||||
@@ -241,9 +241,11 @@ See [Command-line flags](DOCUMENTATION.md#command-line-flags).
|
||||
|
||||
Usually not. `software`, the default, needs no GPU, uses about a tenth of the
|
||||
memory and starts fastest. A GPU
|
||||
renderer pays off in long, continuous animation: `--renderer directx` takes
|
||||
Direct3D 12 on Windows where it starts, else 11, and `opengl` needs a build
|
||||
with `-DREAKTOR_SDL_GL=ON`. Expect six to thirteen times the memory. See
|
||||
renderer pays off in long, continuous animation: `--renderer gpu` takes
|
||||
Metal on macOS; on Windows OpenGL where the build has it, else Direct3D 12,
|
||||
else 11, so `directx` on a default build; on Linux and the BSDs OpenGL, else
|
||||
OpenGL ES 2, neither built unless `REAKTOR_RENDERERS` names it. Expect six
|
||||
to thirteen times the memory. See
|
||||
[The renderer](DOCUMENTATION.md#the-renderer).
|
||||
|
||||
### Why is the frame time high on a machine with no GPU?
|
||||
|
||||
+16
-12
@@ -19,13 +19,16 @@ from the project's own license file at the pinned revision.
|
||||
| [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 |
|
||||
| [toml-c](https://github.com/arp242/toml-c) | Reading `settings.toml`; a fork of [tomlc99](https://github.com/cktan/tomlc99), whose copyright notice it keeps | MIT |
|
||||
|
||||
SDL is built static, without audio, joystick, haptic, HID, sensor, camera,
|
||||
power, GPU, offscreen, the render backends Reaktor never selects, or its
|
||||
dynamic API (see below). Its tray is built: on
|
||||
Linux and the BSDs it loads AppIndicator and GTK 3 when a tray opens, and
|
||||
nothing links them. mojibake is built without its collation, IDNA, security
|
||||
SDL is built static — and, in a `REAKTOR_SHARED` build on Linux and the BSDs,
|
||||
shared too, as `libreaktor-sdl3.so` — without audio, joystick, haptic, HID,
|
||||
sensor, camera, power, GPU, offscreen, the render backends Reaktor never
|
||||
selects, or its dynamic API (see below). Its tray is built, and opened on
|
||||
Windows and macOS; on Linux and the BSDs Reaktor's own tray speaks
|
||||
StatusNotifierItem and dbusmenu over libdbus, so SDL's, which would load
|
||||
AppIndicator and GTK 3, never opens there and nothing links them. mojibake is
|
||||
built without its collation, IDNA, security
|
||||
and character-name tables. NukAnim is one header, compiled in
|
||||
`core/anim/anim.c`; its own Nuklear submodule, which only its tests use, comes
|
||||
with a recursive checkout and is not built. kb_text_shape is one header, compiled in
|
||||
@@ -42,9 +45,11 @@ Portions of this software are copyright © 2026 The FreeType Project
|
||||
|
||||
## The one dependency that is not a submodule
|
||||
|
||||
`libdbus`, on Linux and the BSDs, when present: the AT-SPI bridge speaks
|
||||
D-Bus. CMake asks pkg-config for `dbus-1`; without it the bridge is not built,
|
||||
as on a desktop with no accessibility bus.
|
||||
`libdbus`, on Linux and the BSDs, when present: the AT-SPI bridge, the tray
|
||||
(StatusNotifierItem and dbusmenu) and notifications speak D-Bus. CMake asks
|
||||
pkg-config for `dbus-1`; without it the bridge is not built, as on a desktop
|
||||
with no accessibility bus, `reaktor_tray_open` answers 0 and notifications
|
||||
are not sent.
|
||||
|
||||
| Component | License |
|
||||
| --- | --- |
|
||||
@@ -141,10 +146,9 @@ each toolchain fetches its own framework, and none is part of a Reaktor build.
|
||||
|
||||
A native build links SDL, plutosvg, plutovg and FreeType
|
||||
statically, plus mojibake and kb_text_shape with the Text module, and compiles
|
||||
in Nuklear, NukAnim, Onlay and ini.h, so it carries the zlib, MIT and FreeType
|
||||
in Nuklear, NukAnim, Onlay and toml-c, so it carries the zlib, MIT and FreeType
|
||||
License 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,
|
||||
is copied unchanged into `licenses/` beside the programs: ship that folder,
|
||||
and this file, with a binary.
|
||||
|
||||
The binary also carries the default assets in `REAKTOR_BUILTINS`, byte for
|
||||
|
||||
+147
-36
@@ -11,9 +11,10 @@ queue and builds a frame only when the picture would differ. So **CPU is a
|
||||
count of frames, not a load**, and **memory is a floor, not a curve**: once the
|
||||
atlas and icons are baked, nothing grows.
|
||||
|
||||
On Windows today, `showcase.exe` is 3,327,488 bytes, `notepad.exe` 2,294,784,
|
||||
`simple.exe` 2,181,632 and `bench.exe` 2,171,904. The showcase links all three
|
||||
optional modules and the others none; each carries the default look —
|
||||
On Windows today, `showcase.exe` is 3,215,360 bytes, `notepad.exe` 2,274,304,
|
||||
`simple.exe` 2,140,672 and `bench.exe` 2,130,944. The showcase links all nine
|
||||
optional modules, `notepad` three (settings, popup windows, printing) and the
|
||||
other two none; each carries the default look —
|
||||
Aileron, the mark, the sheets and seven icons, 73,123 bytes — compiled in. The
|
||||
four-platform figures below come from an older build that shipped one
|
||||
executable, at 1.00× scale in a 960×680 window; the runtime they measure is
|
||||
@@ -22,10 +23,10 @@ the one all four programs share.
|
||||
## Against the others
|
||||
|
||||

|
||||
|
||||
The workload is [ShaftUI/Shaft](https://github.com/ShaftUI/Shaft)'s: 64 boxes
|
||||
@@ -34,28 +35,40 @@ Lenovo laptop with a 6-core Ryzen 5 4600H, a GeForce RTX 2060 and a 1920×1080
|
||||
120 Hz display, on Windows 11 Pro. Each arm is its own app, built with its
|
||||
framework's toolchain; one script launches it and samples its whole process
|
||||
tree from outside. [`benchmarks/`](../benchmarks/BENCHMARKS.md) has the
|
||||
projects and the runner. Reaktor appears once per `--renderer`. Shaft is not
|
||||
plotted: it does not link on Windows.
|
||||
projects and the runner. Reaktor appears once per `--renderer`; its arms are
|
||||
0.9.0, measured on 2026-11-04, the others from the pass of 2026-10-24. Shaft
|
||||
is not plotted: it does not link on Windows.
|
||||
|
||||
| Arm | Memory | CPU, with startup | CPU, steady state |
|
||||
| --- | --- | --- | --- |
|
||||
| **Reaktor**, `software` | 8.5 MB | 8.0% | 6.7% |
|
||||
| **Reaktor**, `direct3d11` | 57.6 MB | 14.4% | 13.4% |
|
||||
| **Reaktor**, `direct3d12` | 121.4 MB | 10.8% | 5.6% |
|
||||
| **Reaktor**, `opengl` | 69.7 MB | 11.0% | 5.6% |
|
||||
| **Reaktor**, `software` | 9.1 MB | 8.1% | 7.1% |
|
||||
| **Reaktor**, `direct3d11` | 57.3 MB | 13.3% | 11.4% |
|
||||
| **Reaktor**, `direct3d12` | 120.8 MB | 8.5% | 4.1% |
|
||||
| **Reaktor**, `opengl` | 69.0 MB | 10.2% | 6.4% |
|
||||
| Flutter | 132.7 MB | 38.8% | 15.3% |
|
||||
| Electron | 156.3 MB | 36.5% | 19.6% |
|
||||
| Kotlin Multiplatform | 668.7 MB | 51.5% | 29.4% |
|
||||
|
||||
- **About a fifteenth of Flutter's memory and less than half its CPU**, with
|
||||
startup or without, and nearly an eightieth of Kotlin Multiplatform's
|
||||
startup or without, and about a seventy-fifth of Kotlin Multiplatform's
|
||||
memory.
|
||||
- **Every Reaktor renderer takes less CPU than every other framework.** On a
|
||||
GPU renderer its memory is mostly the graphics driver's: 58–121 MB, below
|
||||
GPU renderer its memory is mostly the graphics driver's: 57–121 MB, below
|
||||
Flutter's 133.
|
||||
- **Startup counts.** A run that draws for only 0.2 s takes 0.14 s of CPU on
|
||||
`software` and 0.38–0.50 s on a GPU renderer. Once running, `direct3d12` and
|
||||
`opengl` take about a point less than `software`.
|
||||
- **Startup counts.** A run that draws for only 0.2 s takes 0.16 s of CPU on
|
||||
`software` and 0.41–0.47 s on a GPU renderer (medians of five runs). Once running, `direct3d12`
|
||||
takes three points less than `software`, `opengl` under one.
|
||||
- **About 2.2 MB of Reaktor's 9.1 is the antivirus.** Bitdefender puts two
|
||||
components into every process on this machine, so every arm carries them.
|
||||
Walked with VirtualQueryEx and a heap ledger on `bench`, they come to two
|
||||
private heaps of 776 KB each (one the hook module's, one holding a 642 KB
|
||||
table of the other's), 74 code pages patched with hooks (303 KB) and 56
|
||||
more copied unchanged (229 KB), 53 KB of trampolines and about 180 KB of
|
||||
pages beside. Subtract that to compare with a machine without it. The rest
|
||||
of the 9.3 MB walked is 1.9 MB of window framebuffer, 1.75 MB of system DLL
|
||||
data made private, about 0.9 MB of page tables and other commit a walk
|
||||
cannot see, and 1.1 MB allocated by Reaktor, SDL, Nuklear and FreeType —
|
||||
the glyph atlas, 537 KB, and its table, 143 KB, the largest.
|
||||
- **A GPU renderer's CPU depends on what else uses the GPU.** With another
|
||||
program keeping it busy, `direct3d11` and `opengl` missed 60 fps and took
|
||||
16–28% of a core. These runs had the GeForce RTX 2060 idle.
|
||||
@@ -78,7 +91,8 @@ median of ten runs, the steady-state ones taken in turn across arms; passes
|
||||
differ by up to three points of CPU. Memory is peak private bytes, and CPU the
|
||||
sum, across each app's process tree. `-PinClock` runs on a copy of the power
|
||||
plan that holds the processor at full speed, and restores the plan after.
|
||||
Every row was measured on 2026-10-24 in one pass, with the GPU idle: Flutter
|
||||
Every row was measured on 2026-10-24 with the GPU idle, the other frameworks in
|
||||
one pass and Reaktor's again later that day: Flutter
|
||||
3.47.8, Electron 44.3.0, and Kotlin 2.4.20 with Compose 1.12.0 on JDK 21. The
|
||||
Flutter arm took 91 MB and 19% of a core with startup on the Flutter release
|
||||
used before; 3.47.8 takes more of both. The sampler counts what an app's own timers miss: `bench` times
|
||||
@@ -109,6 +123,34 @@ stylesheets with its own engine in place of libcss. The Windows
|
||||
binary's icon is a 125 KB resource of nine sizes, built from the SVG by
|
||||
`tools/mkicon.c`.
|
||||
|
||||
Nuklear is compiled with `-Os` (`/O1` with MSVC): the stripped shared
|
||||
libreaktor on Linux x86-64 goes from 1,880,624 bytes at `-O3` to 1,737,264,
|
||||
and Nuklear's own code from 306,649 to 168,042. `bench --no-vsync --video
|
||||
dummy` on the Linux desktop below, median of seven runs, CPU time a frame:
|
||||
|
||||
| Build | `-O3` | `-Os`, three rounds |
|
||||
| --- | --- | --- |
|
||||
| shared | 563 µs | 574, 563, 528 µs |
|
||||
| static | 527 µs | 548, 523, 511 µs |
|
||||
|
||||
The rounds spread wider than the change. Every showcase tab in both themes,
|
||||
`notepad` and `simple` draw and dump byte for byte as they did at `-O3`.
|
||||
|
||||
SDL's GPU API is left out unless `REAKTOR_SHADERS` is on. Built in, it costs
|
||||
the software renderer too: SDL then loads the Vulkan loader, every installed
|
||||
Vulkan driver and LLVM, and the Diagnostics page's "window and renderer" step
|
||||
goes from +0.2 MB private to +34.4 MB. On the Linux desktop below, the shared
|
||||
build, `bench --no-vsync`, five runs each, both on the software backend:
|
||||
|
||||
| `REAKTOR_SHADERS` | A frame on the display | Private |
|
||||
| --- | --- | --- |
|
||||
| `OFF` | 2.08–2.35 ms | 5.0 MB |
|
||||
| `ON` | 13.59–16.31 ms | 63.1 MB |
|
||||
|
||||
The stripped `libreaktor-sdl3.so` is 2,659,344 bytes without it and 2,950,704
|
||||
with it. With `--video dummy`, where nothing reaches a display, the frame costs
|
||||
563–622 µs of CPU without it and 588–740 µs with it.
|
||||
|
||||
### Modules
|
||||
|
||||
`showcase`, each module off in turn; native on the Windows machine below, web
|
||||
@@ -117,9 +159,9 @@ replaced libcss.
|
||||
|
||||
| `showcase` | Default | Module off | Saved |
|
||||
| --- | --- | --- | --- |
|
||||
| `.exe`, accessibility bridges | 3,327,488 | 3,311,104 | 16,384 (0.49%) |
|
||||
| `.exe`, Locale | 3,327,488 | 3,312,640 | 14,848 (0.45%) |
|
||||
| `.exe`, Text | 3,327,488 | 2,620,928 | 706,560 (21.2%) |
|
||||
| `.exe`, accessibility bridges | 3,215,360 | 3,200,000 | 15,360 (0.48%) |
|
||||
| `.exe`, Locale | 3,215,360 | 3,200,000 | 15,360 (0.48%) |
|
||||
| `.exe`, Text | 3,215,360 | 2,591,232 | 624,128 (19.4%) |
|
||||
| `.wasm` + `.js`, accessibility bridges | 2,308,781 | 2,305,843 | 2,938 (0.13%) |
|
||||
| `.wasm` + `.js`, Locale | 2,308,781 | 2,295,269 | 13,512 (0.59%) |
|
||||
| `.wasm` + `.js`, Text | 2,308,781 | 1,824,708 | 484,073 (21.0%) |
|
||||
@@ -135,14 +177,14 @@ them.
|
||||
391 KB of tables, and mojibake 19 KB of code and 180 KB of line-breaking and
|
||||
bidirectional data; the `.data` it saves is M PLUS 1p, 1,758,688 bytes.
|
||||
Locale is 15 KB of the executable and 7,581 bytes of catalogs; compiled in
|
||||
(`-DREAKTOR_LOCALE_EMBED=ON`), `showcase.exe` is 3,335,168 bytes.
|
||||
(`-DREAKTOR_LOCALE_EMBED=ON`), `showcase.exe` is 3,222,528 bytes.
|
||||
|
||||
**Text costs memory once it draws.** Medians of private bytes over ten
|
||||
launches: Diagnostics is 12.5 MB with every module, 12.3 MB without Locale and
|
||||
launches: Diagnostics is 12.6 MB with every module, 12.6 MB without Locale and
|
||||
12.1 MB without Text — kb_text_shape's tables are not `const`, so they are
|
||||
committed untouched. Translations is 14.9 MB against 12.3 MB without Text: M PLUS 1p
|
||||
held open, what kb_text_shape parses from it, the glyph texture and the
|
||||
caches.
|
||||
committed untouched. Translations, in Japanese, is 12.3 MB against 11.8 MB
|
||||
without Text: M PLUS 1p held open, what kb_text_shape parses from it, the
|
||||
glyph texture and the caches.
|
||||
|
||||
## Memory
|
||||
|
||||
@@ -150,24 +192,30 @@ Idle on the Login page.
|
||||
|
||||
| | Windows | Linux | macOS | GhostBSD |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| Committed / private / footprint | **12.2 MB** | **4.3 MB** | **~30 MB** | **5.1 MB** |
|
||||
| Resident / working set | **29.4 MB** | **11.4 MB** | **33–36 MB** | **11.9 MB** |
|
||||
| Committed / private / footprint | **12.3 MB** | **4.3 MB** | **~30 MB** | **5.1 MB** |
|
||||
| Resident / working set | **29.3 MB** | **11.4 MB** | **33–36 MB** | **11.9 MB** |
|
||||
|
||||
Committed is what the process asked the system to back; resident is what is
|
||||
in RAM, shared library pages included. Windows is today's `showcase`, with
|
||||
every module; the others are the older single-executable build. Idle on
|
||||
Windows, `notepad` is 9.0 MB and `simple`, which links no module, 6.9 MB.
|
||||
every module, medians of ten launches; the others are the older
|
||||
single-executable build. Idle on Windows, `notepad` is 8.9 MB and `simple`,
|
||||
which links no module, 7.4 MB. The
|
||||
showcase's figure includes a second copy of the glyph atlas: its splash is a
|
||||
window of its own, and the first such window keeps its atlas for the next.
|
||||
|
||||
- **Windows is mostly the system's.** Split before the CSS engine replaced
|
||||
libcss, 1.7 MB of the showcase's 12.6 MB was Reaktor's own allocations, the largest the glyph atlas (548 KB) and its
|
||||
table (281 KB) for eight sizes in two weights. Most of the rest is the heaps
|
||||
of the Windows components it loads: UI Automation, the shell, the input
|
||||
method.
|
||||
- **Bitdefender is in every Windows figure here**, about 2.2 MB of each;
|
||||
[the chart's note](#against-the-others) has the split, measured on `bench`.
|
||||
In the showcase its two heaps are the 776 KB pair among the heap segments.
|
||||
|
||||
- **Linux started at 123.6 MB, almost none of it Reaktor's.** SDL's X11 driver
|
||||
set up OpenGL whatever the renderer, and with no GPU that loads Mesa's
|
||||
software OpenGL and LLVM: 53 MB of libLLVM, 10 of Mesa, 30 of heap.
|
||||
Compiling SDL's GL drivers out brought it to 4.3 MB; `-DREAKTOR_SDL_GL=ON`
|
||||
Compiling SDL's GL drivers out brought it to 4.3 MB; `-DREAKTOR_RENDERERS=opengl`
|
||||
puts them back.
|
||||
- **GhostBSD lands beside Linux.** Of its 5.1 MB, 2.5 MB is SDL's framebuffer
|
||||
(960×680×4), shared with the X server. Its figures come from `ps` and
|
||||
@@ -183,6 +231,64 @@ launches.
|
||||
`tools/vmwalk.c` (`cmake --build build --target vmwalk`) splits another
|
||||
process's private bytes into named buckets.
|
||||
|
||||
**Three apps share 21% at most.** `tools/ci/pss.sh` runs `showcase`,
|
||||
`notepad` and `simple` together, idle; medians of ten launches. Each carries
|
||||
its own copy of libreaktor and SDL, which a shared library would map once.
|
||||
|
||||
| | PSS | Clean pages of its binary |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | 9,180 KB | 2,796 KB |
|
||||
| `notepad` | 5,957 KB | 2,208 KB |
|
||||
| `simple` | 5,251 KB | 2,164 KB |
|
||||
|
||||
Of the 20,433 KB together, one copy instead of three would save 4,366 KB, or
|
||||
21.3%. That counts each app's own code as library code, so it is an upper
|
||||
bound.
|
||||
|
||||
Counted page by page, it is 20.2%. `tools/ci/pss-pages.sh` links the three
|
||||
with maps and sorts each resident page of a binary by the object it came from:
|
||||
2,386 KB of `showcase`'s is libreaktor and SDL, 2,090 KB of `notepad`'s and
|
||||
2,018 KB of `simple`'s. Sharing would save 4,120 KB of the 20,423. That is still
|
||||
an upper bound: it takes the largest app's library pages as all three's, and
|
||||
leaves out what the dynamic linker costs each app.
|
||||
|
||||
On a Linux desktop it falls under 20%: Linux Mint 22.3, Cinnamon on X11,
|
||||
llvmpipe (no GPU passthrough), a KVM guest on an AMD Ryzen 5 4600H with 4
|
||||
cores. `showcase` grows to 14,224 KB there, while the library pages barely
|
||||
move. Counting every clean page of a binary, sharing saves 4,602 KB of
|
||||
24,157 KB, or 19.0%; counted page by page, 4,176 KB of 24,200 KB, or 17.3%.
|
||||
|
||||
**Shared, it saves 19%.** The same three on that desktop, five launches each,
|
||||
static and then linked to `libreaktor.so` (`-DREAKTOR_SHARED=ON`):
|
||||
|
||||
| | Static PSS | Shared PSS |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | 8,528 KB | 7,323 KB |
|
||||
| `notepad` | 5,480 KB | 4,280 KB |
|
||||
| `simple` | 4,473 KB | 3,379 KB |
|
||||
| Together | 18,544 KB | 14,941 KB |
|
||||
|
||||
3,603 KB less, 19.4%, near the estimate above. One app on its own pays for
|
||||
the split instead: its resident set is 0.6–0.9 MB larger shared (`simple`
|
||||
8.2 MB against 7.3, `showcase` 18.7 against 18.0), the library's relocations
|
||||
and a second SDL image that no other app is there to share.
|
||||
|
||||
### The tray on Linux
|
||||
|
||||
The same Linux Mint desktop, `showcase` idle on the Login page, five to eight
|
||||
launches each, before and after the tray moved from SDL's to libdbus:
|
||||
|
||||
| | SDL's tray | Over libdbus | No tray |
|
||||
| --- | --- | --- | --- |
|
||||
| Shared libraries mapped | 110 | 57 | 57 |
|
||||
| GTK, GDK, ATK, dbusmenu-gtk3, AppIndicator | mapped | none | none |
|
||||
| `reaktor_tray_open` | 79–133 ms | 7–23 ms | |
|
||||
| First frame, Diagnostics "startup" | 762–963 ms | 794–950 ms | 740–861 ms |
|
||||
| Private dirty | 68.9–72.0 MB | 68.1–76.8 MB | 65.0–73.0 MB |
|
||||
|
||||
`simple` maps 57 too. The first frame and private memory vary more between
|
||||
launches than the tray moves them; the open itself is the measured saving.
|
||||
|
||||
## CPU
|
||||
|
||||
**At rest: 0% of a core** on Windows, Linux and GhostBSD, on every page; macOS
|
||||
@@ -201,12 +307,15 @@ Metal texture to present it. On GhostBSD most of a frame is the present, a
|
||||
software blit into VMware's framebuffer: 6.7 ms of Login's 7.1 ms, 11.1 ms of
|
||||
Buttons' 14.8.
|
||||
|
||||
Today's Windows build, at its default 1100×680: Login takes **1.2–1.4 ms** a
|
||||
frame and Buttons **2.7–3.3 ms**; `direct3d11` takes 0.3–0.6 ms and 0.7–1.1 ms.
|
||||
The Windows build of 2026-10-24, at its default 1100×680, redrawing
|
||||
continuously with vsync off, build, render and present, p10–p90 of 31 frames after 9 to warm up,
|
||||
over three launches: Login takes **1.3–1.8 ms** a frame and Buttons
|
||||
**2.7–3.4 ms**; `direct3d11` takes 0.4–0.8 ms and 0.8–1.3 ms. In software the
|
||||
present is most of it: 1.08 ms of Login's frame.
|
||||
Without a GPU, `direct3d11` falls back to WARP, which rasterizes on threads of
|
||||
its own: drawing `bench` flat out, the process spends **1.65 ms** of CPU a
|
||||
frame on WARP against 0.72 ms on `software`, which made software the
|
||||
default.
|
||||
its own: drawing `bench` flat out, the process spends **1.78 ms** of CPU a
|
||||
frame on WARP against 0.75 ms on `software` (medians of five runs), which
|
||||
made software the default.
|
||||
|
||||
The accessibility tree adds **3.3 µs** to a drawn frame (82 nodes). With a
|
||||
GPU, `direct3d12` and `opengl` take less CPU; see **Against the others**.
|
||||
@@ -231,6 +340,8 @@ since a `file://` page cannot fetch the `.wasm`.
|
||||
- **macOS** — 11.7 Big Sur, Intel iMac, Apple Clang 12, 1024×768 non-Retina,
|
||||
built with `-DCMAKE_OSX_SYSROOT=…/MacOSX11.3.sdk`.
|
||||
- **GhostBSD** — 26.1-R15.0p2, x86_64, Clang 19.1.7, X11, VMware, no 3D.
|
||||
- **Sharing** — GitHub `ubuntu-24.04` runner, x86_64, Debian 12 container,
|
||||
GCC Release, Xvfb, no GPU.
|
||||
|
||||
The **Diagnostics** page shows the renderer, the frame breakdown and the
|
||||
resident set live; reproduce any of this there.
|
||||
|
||||
+29
-35
@@ -3,24 +3,21 @@
|
||||
<rect x="30" y="30" width="715" height="500" rx="14" fill="#353535"/>
|
||||
<text x="70" y="90" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="31" font-weight="600" fill="#ffffff">Memory</text>
|
||||
<text x="70" y="116" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="14" fill="#8e8e8e">private bytes, peak, whole process tree</text>
|
||||
<rect x="99.5" y="448.993" width="46" height="3.00748" fill="#56c7ff"/>
|
||||
<text x="122.5" y="418.993" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">8.5 MB</text>
|
||||
<rect x="99.5" y="448.761" width="46" height="3.23882" fill="#56c7ff"/>
|
||||
<text x="122.5" y="418.761" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">9.1 MB</text>
|
||||
<text x="122.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">Software</text>
|
||||
<path d="M187.833 452 v-14.4829 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v14.4829 z" fill="#56c7ff"/>
|
||||
<text x="210.833" y="401.517" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">57.6 MB</text>
|
||||
<text x="210.833" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D11</text>
|
||||
<path d="M276.167 452 v-37.1902 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v37.1902 z" fill="#56c7ff"/>
|
||||
<text x="299.167" y="378.81" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">121.4 MB</text>
|
||||
<text x="299.167" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D12</text>
|
||||
<path d="M364.5 452 v-18.7894 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v18.7894 z" fill="#56c7ff"/>
|
||||
<text x="387.5" y="397.211" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">69.7 MB</text>
|
||||
<text x="387.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">OpenGL</text>
|
||||
<path d="M452.833 452 v-41.2121 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v41.2121 z" fill="#6e7a82"/>
|
||||
<text x="475.833" y="374.788" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">132.7 MB</text>
|
||||
<text x="475.833" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Flutter</text>
|
||||
<path d="M541.167 452 v-49.6116 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v49.6116 z" fill="#6e7a82"/>
|
||||
<text x="564.167" y="366.388" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">156.3 MB</text>
|
||||
<text x="564.167" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Electron</text>
|
||||
<path d="M205.5 452 v-36.9945 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v36.9945 z" fill="#56c7ff"/>
|
||||
<text x="228.5" y="379.006" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">120.8 MB</text>
|
||||
<text x="228.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D12</text>
|
||||
<path d="M311.5 452 v-18.5581 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v18.5581 z" fill="#56c7ff"/>
|
||||
<text x="334.5" y="397.442" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">69.0 MB</text>
|
||||
<text x="334.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">OpenGL</text>
|
||||
<path d="M417.5 452 v-41.2298 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v41.2298 z" fill="#6e7a82"/>
|
||||
<text x="440.5" y="374.77" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">132.7 MB</text>
|
||||
<text x="440.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Flutter</text>
|
||||
<path d="M523.5 452 v-49.6294 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v49.6294 z" fill="#6e7a82"/>
|
||||
<text x="546.5" y="366.371" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">156.3 MB</text>
|
||||
<text x="546.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Electron</text>
|
||||
<path d="M629.5 452 v-232 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v232 z" fill="#6e7a82"/>
|
||||
<text x="652.5" y="184" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">668.7 MB</text>
|
||||
<text x="652.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">KMP</text>
|
||||
@@ -28,28 +25,25 @@
|
||||
<rect x="755" y="30" width="715" height="500" rx="14" fill="#353535"/>
|
||||
<text x="795" y="90" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="31" font-weight="600" fill="#ffffff">CPU at 60 fps</text>
|
||||
<text x="795" y="116" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="14" fill="#8e8e8e">percent of one core, steady state (3 s to 8 s)</text>
|
||||
<path d="M824.5 452 v-48.3305 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v48.3305 z" fill="#56c7ff"/>
|
||||
<text x="847.5" y="367.67" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">6.7%</text>
|
||||
<path d="M824.5 452 v-51.4762 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v51.4762 z" fill="#56c7ff"/>
|
||||
<text x="847.5" y="364.524" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">7.1%</text>
|
||||
<text x="847.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">Software</text>
|
||||
<path d="M912.833 452 v-102.255 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v102.255 z" fill="#56c7ff"/>
|
||||
<text x="935.833" y="313.744" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">13.4%</text>
|
||||
<text x="935.833" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D11</text>
|
||||
<path d="M1001.17 452 v-39.4106 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v39.4106 z" fill="#56c7ff"/>
|
||||
<text x="1024.17" y="376.589" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">5.6%</text>
|
||||
<text x="1024.17" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D12</text>
|
||||
<path d="M1089.5 452 v-39.0051 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v39.0051 z" fill="#56c7ff"/>
|
||||
<text x="1112.5" y="376.995" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">5.6%</text>
|
||||
<text x="1112.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">OpenGL</text>
|
||||
<path d="M1177.83 452 v-118.068 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v118.068 z" fill="#6e7a82"/>
|
||||
<text x="1200.83" y="297.932" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">15.3%</text>
|
||||
<text x="1200.83" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Flutter</text>
|
||||
<path d="M1266.17 452 v-152.937 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v152.937 z" fill="#6e7a82"/>
|
||||
<text x="1289.17" y="263.063" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">19.6%</text>
|
||||
<text x="1289.17" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Electron</text>
|
||||
<path d="M930.5 452 v-27.1905 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v27.1905 z" fill="#56c7ff"/>
|
||||
<text x="953.5" y="388.81" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">4.1%</text>
|
||||
<text x="953.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D12</text>
|
||||
<path d="M1036.5 452 v-45.8095 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v45.8095 z" fill="#56c7ff"/>
|
||||
<text x="1059.5" y="370.19" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">6.4%</text>
|
||||
<text x="1059.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">OpenGL</text>
|
||||
<path d="M1142.5 452 v-117.857 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v117.857 z" fill="#6e7a82"/>
|
||||
<text x="1165.5" y="298.143" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">15.3%</text>
|
||||
<text x="1165.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Flutter</text>
|
||||
<path d="M1248.5 452 v-152.667 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v152.667 z" fill="#6e7a82"/>
|
||||
<text x="1271.5" y="263.333" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">19.6%</text>
|
||||
<text x="1271.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Electron</text>
|
||||
<path d="M1354.5 452 v-232 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v232 z" fill="#6e7a82"/>
|
||||
<text x="1377.5" y="184" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">29.4%</text>
|
||||
<text x="1377.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">KMP</text>
|
||||
<line x1="785" y1="452.5" x2="1440" y2="452.5" stroke="#4a4a4a" stroke-width="1"/>
|
||||
<text x="40" y="562" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" fill="#b9b9b9">Drawing 64 rotating boxes at 60 fps in an 800×600 window. Lower is better in both panels.</text>
|
||||
<text x="40" y="586" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="13" fill="#8e8e8e">Four Reaktor renderers against the alternatives from other tech stacks, on the same machine — details in benchmarks/BENCHMARKS.md.</text>
|
||||
<text x="40" y="586" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="13" fill="#8e8e8e">Three Reaktor renderers (0.9.0, measured 2026-11-04) against the alternatives from other tech stacks (2026-10-24), on the same machine — details in benchmarks/BENCHMARKS.md.</text>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.0 KiB |
@@ -0,0 +1,314 @@
|
||||
# Requests from PapayaPlayer
|
||||
|
||||
What PapayaPlayer (a media player built on Reaktor) needs from Reaktor,
|
||||
checked against revision `5a8b7f3`. Each section says what is missing, why the
|
||||
app cannot do it on its own, a suggested shape and how to check it. No
|
||||
Reaktor code is changed here; this file is the request.
|
||||
|
||||
Contents:
|
||||
|
||||
1. [Linear gradients in CSS](#1-linear-gradients-in-css)
|
||||
2. [An option for HDR output](#2-an-option-for-hdr-output)
|
||||
3. [SDL's GPU renderer, for app shaders](#3-sdls-gpu-renderer-for-app-shaders)
|
||||
4. [The layout stays stale after a resize](#4-the-layout-stays-stale-after-a-resize)
|
||||
5. [A quiet list header](#5-a-quiet-list-header)
|
||||
|
||||
## 1. Linear gradients in CSS
|
||||
|
||||
**What PapayaPlayer needs:** `linear-gradient()` as a background in Reaktor
|
||||
stylesheets, so the "accent" controls style can be written in CSS. Decided
|
||||
2026-10-30 (TECH-STACK.md, UI direction): gradients come from Reaktor's CSS,
|
||||
not from PapayaPlayer drawing them itself.
|
||||
|
||||
Reaktor revision checked: `5a8b7f3` (the submodule in PapayaPlayer).
|
||||
|
||||
### Where it is used
|
||||
|
||||
From `design/mockups.html`, screen 02 (video, accent) and the audio bars:
|
||||
|
||||
| Element | Gradient |
|
||||
|---|---|
|
||||
| Seek bar fill, volume fill | horizontal / vertical, guava `#ff3d6e` to papaya `#ff7a45` |
|
||||
| Play button (pill), folder and file pills | horizontal, same colours, with `border-radius` |
|
||||
| Chosen row of the settings menu | horizontal, the same colours at 25 % / 18 % alpha |
|
||||
| Shade behind the control bars (both styles) | vertical, black at 55 - 75 % to transparent |
|
||||
|
||||
So: two colour stops are enough for all of it; angles `to right`, `to top`
|
||||
and `to bottom`; colours with alpha; rounded corners.
|
||||
|
||||
### What Reaktor has today
|
||||
|
||||
- `background` and `background-color` take a colour only (`core/css/css.c`,
|
||||
`K_BG`, around line 788: it takes the last colour in the value).
|
||||
- Boxes are filled with one colour by `reaktor_fill_round()`
|
||||
(`core/render/draw.c`, around line 553), called from `core/ui/declare.c`
|
||||
around line 478 with `s.bg`.
|
||||
- Nuklear already has `nk_fill_rect_multi_color()` (a colour per corner),
|
||||
which draws a two-stop gradient on a square rectangle.
|
||||
|
||||
### Suggested shape
|
||||
|
||||
1. **Parse** `background: linear-gradient(<angle>, <colour> [<pos>], <colour> [<pos>], ...)`
|
||||
with `to right | to left | to top | to bottom` and `<n>deg`. Store it in the
|
||||
style next to `bg` (say `bg2[4]` plus an angle, or a small stop list).
|
||||
Falling back to the first stop where a gradient is not drawable keeps old
|
||||
code paths working.
|
||||
2. **Draw** in `reaktor_fill_round()` (or a sibling): for square corners,
|
||||
`nk_fill_rect_multi_color()`; for rounded corners, the rounded shape's
|
||||
vertices coloured by their position along the gradient axis (the corner
|
||||
fans already exist for the solid fill).
|
||||
3. **Hover / active states** take gradients the same way (`core/ui/style_map.c`
|
||||
copies `bg` today).
|
||||
4. **Inspector:** show the gradient in the background row (`runtime/inspector.c`).
|
||||
|
||||
More than two stops and other angles are nice to have; PapayaPlayer's design
|
||||
needs only two stops and the four directions.
|
||||
|
||||
### Checks
|
||||
|
||||
- `tests/csstest.c`: the parse of each form above, and that a plain colour still
|
||||
parses as before.
|
||||
- The showcase with a gradient button, pill and progress bar, rounded and
|
||||
square, in `--shot` output: the colours at both ends match the stops, no seam
|
||||
at the corners.
|
||||
- Colours with alpha over another fill blend as solid ones do.
|
||||
|
||||
### In PapayaPlayer once it exists
|
||||
|
||||
`app/main.c`'s stylesheet gets the accent classes (`.accent .seek-fill`,
|
||||
`.accent .play`, ...); the control code itself does not change.
|
||||
|
||||
## 2. An option for HDR output
|
||||
|
||||
**What PapayaPlayer needs:** a launch option that creates Reaktor's renderer
|
||||
with an HDR output colorspace, so HDR10 video can light up an HDR screen.
|
||||
Today HDR video is tone-mapped down to SDR on every screen.
|
||||
|
||||
Reaktor revision checked: `5a8b7f3` (the submodule in PapayaPlayer).
|
||||
|
||||
### Why it has to be Reaktor
|
||||
|
||||
SDL fixes a renderer's output colorspace when the renderer is created
|
||||
(`SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER`). Nothing can change
|
||||
it afterwards. Reaktor creates the window and renderer itself, in
|
||||
`runtime/app.c` (around line 842) with `SDL_CreateWindowAndRenderer()`, which
|
||||
takes no properties. The app never sees renderer creation, so it cannot ask
|
||||
for HDR. Secondary windows (`runtime/window.c` around line 184) are created
|
||||
the same way.
|
||||
|
||||
This was found in PapayaPlayer's phase 0 spike S3 (`spikes/RESULTS.md`).
|
||||
|
||||
### What already works without it
|
||||
|
||||
- SDL's Direct3D / Metal renderers take P010 textures with a BT.2020 / PQ
|
||||
colorspace, convert YUV themselves, and tone-map HDR10 to the SDR output.
|
||||
- PapayaPlayer now gives each HDR10 texture a white point (203 cd/m²,
|
||||
BT.2408) and a headroom from the content's MaxCLL or mastering peak
|
||||
(`SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT`,
|
||||
`SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT`). Without a headroom, SDL clips
|
||||
everything brighter than white.
|
||||
|
||||
So SDR screens are handled. Only real HDR output is missing.
|
||||
|
||||
### Suggested option
|
||||
|
||||
```c
|
||||
/* in reaktor_launch */
|
||||
int hdr; /* 1: ask for an HDR output where the display and renderer have one */
|
||||
```
|
||||
|
||||
When it is set and the renderer is not software:
|
||||
|
||||
1. Create the window first, then the renderer with properties:
|
||||
```c
|
||||
SDL_PropertiesID p = SDL_CreateProperties();
|
||||
SDL_SetPointerProperty(p, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, win);
|
||||
SDL_SetStringProperty(p, SDL_PROP_RENDERER_CREATE_NAME_STRING, name); /* the --renderer choice */
|
||||
SDL_SetNumberProperty(p, SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER,
|
||||
SDL_COLORSPACE_SRGB_LINEAR); /* scRGB; SDL_COLORSPACE_HDR10 also works on D3D */
|
||||
ren = SDL_CreateRendererWithProperties(p);
|
||||
```
|
||||
If that fails, fall back to the normal SDR renderer as today.
|
||||
2. `SDL_COLORSPACE_SRGB_LINEAR` is the simplest choice for the UI. SDL converts
|
||||
sRGB draw colours and textures into it, scaled by the display's SDR white
|
||||
level (`SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT`). Reaktor's widgets
|
||||
should then look as they do now, but this needs checking against
|
||||
Reaktor's own pixels (`--shot`).
|
||||
3. Follow the display: Windows lets the user switch HDR on and off at any
|
||||
time, and a window can move between an HDR and an SDR monitor. SDL reports
|
||||
both with `SDL_EVENT_WINDOW_HDR_STATE_CHANGED`; the renderer's
|
||||
`SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN` and `..._HDR_HEADROOM_FLOAT` give
|
||||
the current state. On an SDR display a linear output still works: SDL
|
||||
tone-maps into it as it does now.
|
||||
4. The same for secondary windows (`runtime/window.c`).
|
||||
|
||||
The software renderer has no HDR output, so the option does nothing there.
|
||||
|
||||
### Checks
|
||||
|
||||
- `--shot` / `--a11y-dump` of the showcase with the option on and off, on an
|
||||
SDR display: the pixels should match within rounding. The linear output
|
||||
path changes how blending is done, which may show in anti-aliased edges and
|
||||
in alpha.
|
||||
- On an HDR display (Windows with HDR on, or a Mac with an XDR screen): the UI
|
||||
at normal brightness, and an HDR10 P010 texture brighter than white.
|
||||
- Toggle HDR in Windows settings while running: the window keeps drawing.
|
||||
|
||||
### In PapayaPlayer once it exists
|
||||
|
||||
`app/main.c` sets `.hdr = 1` in its `reaktor_launch`. Nothing else changes:
|
||||
the HDR10 textures already carry their colorspace, white point and headroom.
|
||||
|
||||
|
||||
## 3. SDL's GPU renderer, for app shaders
|
||||
|
||||
**What PapayaPlayer needs:** a way to run its own fragment shaders when
|
||||
drawing video: BT.2390 tone mapping on SDR screens (SDL's built-in operator
|
||||
is not BT.2390), full chroma for 4:2:2 / 4:4:4 (SDL has no planar
|
||||
4:2:2 / 4:4:4 textures, so PapayaPlayer averages the chroma down to 4:2:0
|
||||
today), and later Lanczos scaling and deinterlacing.
|
||||
|
||||
**Why it has to be Reaktor:** `SDL_CreateGPURenderState()` (SDL 3.4) only
|
||||
works on a renderer backed by an SDL GPU device, that is SDL's `gpu`
|
||||
renderer. Reaktor builds SDL with `SDL_GPU` off, so the renderer is always
|
||||
the native Direct3D / Metal / OpenGL one (PapayaPlayer spike S4,
|
||||
`spikes/RESULTS.md`).
|
||||
|
||||
**Suggested option:** build SDL with `SDL_GPU` on, and a launch field such as
|
||||
`const char *renderer; /* NULL: as now; "gpu": SDL's GPU renderer */` passed
|
||||
as `SDL_HINT_RENDER_DRIVER` (or as the renderer name) before the window and
|
||||
renderer are created. With it, PapayaPlayer would create a
|
||||
`SDL_GPURenderState` with its shaders (built from HLSL with SDL_shadercross)
|
||||
and set it while drawing the video texture.
|
||||
|
||||
**Checks:** the showcase under the `gpu` renderer on Windows (D3D12 / Vulkan),
|
||||
macOS (Metal) and Linux (Vulkan) matches the default renderer within
|
||||
rounding; the software fallback still works where no GPU device exists.
|
||||
|
||||
## 4. The layout stays stale after a resize
|
||||
|
||||
**Status:** suspected, not yet confirmed by watching a real window. Found in
|
||||
PapayaPlayer on Windows; worked around there in `eafbafb`.
|
||||
|
||||
### What the user saw
|
||||
|
||||
After resizing PapayaPlayer's window, the window took "several seconds to
|
||||
update". PapayaPlayer was idle at the time (paused, or no file open), so
|
||||
nothing was animating.
|
||||
|
||||
### Why it happens
|
||||
|
||||
Three parts of Reaktor combine:
|
||||
|
||||
1. **Boxes are placed a frame late.** A box gets its rectangle from the
|
||||
previous frame and is found again by its `.name` (CLAUDE.md, "Traps that
|
||||
have cost real time"). The first frame at a new size is therefore laid out
|
||||
against the old sizes.
|
||||
|
||||
2. **A resize asks for exactly one frame.** `SDL_EVENT_WINDOW_RESIZED`,
|
||||
`PIXEL_SIZE_CHANGED`, `EXPOSED`, `MAXIMIZED` and the others set
|
||||
`app->dirty` and `app->must_draw` (`runtime/app.c`, the event switch around
|
||||
lines 981-1010). `must_draw` only stops the frame-hash check
|
||||
(`runtime/app.c` around 1431) from skipping that one frame. Nothing asks
|
||||
for a second one.
|
||||
|
||||
3. **An idle app draws nothing more.** `app_iterate` returns early while
|
||||
`!app->dirty` (`runtime/app.c` around 1690). The stale layout stays on
|
||||
screen until something else marks the window dirty: mouse motion over a
|
||||
hot rectangle, a key, a timer or a wake.
|
||||
|
||||
In PapayaPlayer the next wake is the control bar's auto-hide timer, 2.5 s
|
||||
later. That matches "several seconds". Any Reaktor app with nothing animating
|
||||
should show the same stale frame after a resize, until the next input.
|
||||
|
||||
### Reaktor already handles the same case elsewhere
|
||||
|
||||
The "settle" mechanism exists, but a resize never starts it:
|
||||
|
||||
| Event | What Reaktor does (`runtime/app.c`) |
|
||||
|---|---|
|
||||
| Mouse drag ends | `drag_end()` sets `restore_rate = 2` (around 961) |
|
||||
| Mouse wheel | `restore_rate = 2`, because "Nuklear scrolls a panel at its end, after drawing what it holds" (around 1055) |
|
||||
| Hover redraw | `restore_rate` at least 1 (around 1273) |
|
||||
| Keyboard click release | `restore_rate = 2` (around 1486) |
|
||||
| Window resize | `must_draw = 1` only: **no follow-up frame** |
|
||||
|
||||
At the end of a frame, `restore_rate > 0` counts down, sets `dirty` and calls
|
||||
`reaktor_app_wake()` (around 1637-1645). That is exactly the extra frame a
|
||||
resize needs.
|
||||
|
||||
### Suggested fix in Reaktor
|
||||
|
||||
In the second event switch (the `must_draw` one, around 1000-1010), also
|
||||
schedule a settle frame for the size-changing events:
|
||||
|
||||
```c
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_MAXIMIZED:
|
||||
case SDL_EVENT_WINDOW_RESTORED:
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
if (!app->dragging && app->restore_rate < 2) app->restore_rate = 2;
|
||||
break;
|
||||
```
|
||||
|
||||
(`app->must_draw = 1` stays as it is.)
|
||||
|
||||
A more general fix: keep drawing while the layout still moves. After a frame,
|
||||
compare the boxes' rectangles with the previous frame's, and draw again
|
||||
(bounded, e.g. at most 3 frames) while any changed. That would also cover
|
||||
other one-frame-late cases, not just resizes.
|
||||
|
||||
#### How to check it
|
||||
|
||||
- Run a sample (e.g. `showcase`) with nothing animating, resize the window,
|
||||
and stop moving the mouse. Before the fix, boxes that depend on the window
|
||||
size should sit at their old place until the next input; after it, they
|
||||
should settle at once.
|
||||
- The regression oracle: a `--shot` / `--a11y-dump` taken after a scripted
|
||||
`SDL_SetWindowSize` should give the same bounds as one taken from a fresh
|
||||
start at that size.
|
||||
|
||||
### Not covered by this
|
||||
|
||||
- **Lag during the drag itself.** On Windows, the move/size loop is modal.
|
||||
If the window doesn't update *while* the edge is being dragged, that is a
|
||||
separate issue: whether SDL's live-resize callback runs `SDL_AppIterate`
|
||||
under Reaktor's `SDL_HINT_MAIN_CALLBACK_RATE` settings.
|
||||
- Whether Reaktor's own samples show the stale frame has not been checked yet.
|
||||
|
||||
### PapayaPlayer's workaround (remove once Reaktor is fixed)
|
||||
|
||||
`app/main.c`, at the top of `page()`:
|
||||
|
||||
```c
|
||||
/* Reaktor places boxes a frame late, so a new size needs a second frame;
|
||||
* when paused nothing else would draw it until the bar hides. */
|
||||
if (win_w != activity.win_w || win_h != activity.win_h) {
|
||||
activity.win_w = win_w;
|
||||
activity.win_h = win_h;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
```
|
||||
|
||||
Reaktor revision checked: `5a8b7f3` (the submodule in PapayaPlayer).
|
||||
|
||||
## 5. A quiet list header
|
||||
|
||||
**What PapayaPlayer needs:** a `reaktor_list` header row in a dark, low-contrast
|
||||
colour of its own choosing (its playlist uses `--table: #232027` over rows of
|
||||
`#18161b` / `#1d1b21`).
|
||||
|
||||
**What happens today:** `core/ui/views.c` (`reaktor_list`, around line 377)
|
||||
takes `thead`'s background or `--table`, then passes it through
|
||||
`reaktor_visible()` against the page colour and the odd-row colour. A colour
|
||||
that close to the rows counts as not visible, so the header falls back to the
|
||||
accent: PapayaPlayer's playlist gets a bright papaya-orange header row.
|
||||
|
||||
**Suggested shape:** when the stylesheet sets the header colour explicitly
|
||||
(`thead { background-color: ... }` or `--table`), use it as written and keep
|
||||
the visibility fallback only for the built-in default. Or a flag on the spec,
|
||||
such as `.plain_header = 1`, or `.header = 0` to hide the row.
|
||||
|
||||
**Checks:** the showcase's list with `--table` set close to the rows shows that
|
||||
colour in `--shot`; with nothing set, the header looks as it does now.
|
||||
@@ -1,10 +1,15 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(consumer C)
|
||||
|
||||
find_package(reaktor 0.8 REQUIRED)
|
||||
find_package(reaktor 0.9 REQUIRED)
|
||||
|
||||
add_executable(simple WIN32 ../../samples/simple/simple.c)
|
||||
target_link_libraries(simple PRIVATE reaktor::reaktor)
|
||||
option(CONSUMER_SHARED "Link libreaktor.so instead of libreaktor.a" OFF)
|
||||
if(CONSUMER_SHARED)
|
||||
target_link_libraries(simple PRIVATE reaktor::shared)
|
||||
else()
|
||||
target_link_libraries(simple PRIVATE reaktor::reaktor)
|
||||
endif()
|
||||
if(EMSCRIPTEN)
|
||||
set_target_properties(simple PROPERTIES SUFFIX ".html")
|
||||
endif()
|
||||
|
||||
Vendored
-1
Submodule external/mglibs deleted from 64b57a7275
Vendored
+1
-1
Submodule external/onlay updated: 877047c09d...1e57179742
+1
Submodule external/toml-c added at 6a38d40418
@@ -106,6 +106,8 @@ typedef struct reaktor_launch {
|
||||
int skip_same_frames;
|
||||
reaktor_save save_settings;
|
||||
int save_ms;
|
||||
const char *renderer;
|
||||
int hdr;
|
||||
} reaktor_launch;
|
||||
|
||||
typedef struct reaktor_window {
|
||||
@@ -174,6 +176,7 @@ int reaktor_floater_is_open(App *app, int id);
|
||||
int reaktor_tray_open(App *app, const reaktor_tray *tray);
|
||||
void reaktor_tray_check(App *app, int item, int checked);
|
||||
void reaktor_tray_close(App *app);
|
||||
void reaktor_tray_hide_on_minimize(App *app, int on);
|
||||
|
||||
int reaktor_inspector_open(App *app);
|
||||
void reaktor_inspector_close(App *app);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
enum { REAKTOR_SIDE_TOP = 0, REAKTOR_SIDE_RIGHT, REAKTOR_SIDE_BOTTOM, REAKTOR_SIDE_LEFT };
|
||||
enum { REAKTOR_CORNER_TL = 0, REAKTOR_CORNER_TR, REAKTOR_CORNER_BR, REAKTOR_CORNER_BL };
|
||||
enum { REAKTOR_GRADIENT_NONE = 0, REAKTOR_GRADIENT_ACROSS, REAKTOR_GRADIENT_DOWN };
|
||||
|
||||
typedef struct reaktor_style {
|
||||
unsigned char bg[4];
|
||||
@@ -27,6 +28,10 @@ typedef struct reaktor_style {
|
||||
int font_px;
|
||||
int bold;
|
||||
int matched;
|
||||
|
||||
unsigned char gradient_from[4];
|
||||
unsigned char gradient_to[4];
|
||||
int gradient;
|
||||
} reaktor_style;
|
||||
|
||||
void reaktor_style_get(const char *selector, reaktor_style *out);
|
||||
|
||||
@@ -33,6 +33,9 @@ struct reaktor_color reaktor_visible(struct reaktor_color want,
|
||||
struct reaktor_color reaktor_page_color(App *app);
|
||||
struct reaktor_color reaktor_accent_color(App *app);
|
||||
const struct reaktor_user_font *reaktor_font(App *app, int px, int bold);
|
||||
struct reaktor_vec2 reaktor_item_spacing(struct reaktor_context *ctx);
|
||||
struct reaktor_color reaktor_text_color(struct reaktor_context *ctx);
|
||||
const struct reaktor_user_font *reaktor_current_font(struct reaktor_context *ctx);
|
||||
|
||||
struct reaktor_image reaktor_ionicon(App *app, const char *name, int px);
|
||||
struct reaktor_image reaktor_ionicon_exact(App *app, const char *name, int px,
|
||||
@@ -56,6 +59,10 @@ void reaktor_style_frame_pop(struct reaktor_context *ctx, reaktor_style_frame f)
|
||||
void reaktor_fill_round(App *app, struct reaktor_command_buffer *cv,
|
||||
struct reaktor_rect b, float rounding,
|
||||
struct reaktor_color col);
|
||||
void reaktor_fill_gradient(App *app, struct reaktor_command_buffer *cv,
|
||||
struct reaktor_rect b, float rounding,
|
||||
struct reaktor_color from, struct reaktor_color to,
|
||||
int axis);
|
||||
void reaktor_edge_round(App *app, struct reaktor_command_buffer *cv,
|
||||
struct reaktor_rect b, float rounding, float width,
|
||||
struct reaktor_color col);
|
||||
@@ -238,6 +245,7 @@ typedef struct reaktor_diag {
|
||||
int vsync, dark, sheets;
|
||||
const char *aa;
|
||||
float scale, style_ms, build_ms, render_ms, present_ms;
|
||||
float window_ms, atlas_ms, first_frame_ms;
|
||||
float frame_gap_ms;
|
||||
float cpu_ms_per_frame;
|
||||
int hover_gap_ms;
|
||||
|
||||
+102
-72
@@ -32,7 +32,7 @@ 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;
|
||||
int tried, gone;
|
||||
void *lib, *conn;
|
||||
void (*error_init)(dbus_error *);
|
||||
void (*error_free)(dbus_error *);
|
||||
@@ -45,6 +45,9 @@ static struct {
|
||||
int (*iter_type)(dbus_iter *);
|
||||
void (*iter_recurse)(dbus_iter *, dbus_iter *);
|
||||
void (*iter_basic)(dbus_iter *, void *);
|
||||
int (*iter_next)(dbus_iter *);
|
||||
int (*error_has_name)(const dbus_error *, const char *);
|
||||
int (*has_signature)(void *, const char *);
|
||||
} g_dbus;
|
||||
|
||||
static int dbus_ready(void)
|
||||
@@ -66,6 +69,9 @@ static int dbus_ready(void)
|
||||
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");
|
||||
DBUS_FN(iter_next, "dbus_message_iter_next");
|
||||
DBUS_FN(error_has_name, "dbus_error_has_name");
|
||||
DBUS_FN(has_signature, "dbus_message_has_signature");
|
||||
#undef DBUS_FN
|
||||
g_dbus.error_init(&e);
|
||||
g_dbus.conn = g_dbus.bus_get(0, &e);
|
||||
@@ -73,95 +79,119 @@ static int dbus_ready(void)
|
||||
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)
|
||||
/* A setting's value as a number, or -1 when it is not one. */
|
||||
static int portal_value(dbus_iter *it)
|
||||
{
|
||||
static const char *const how[2] = { "ReadOne", "Read" };
|
||||
int i, out = -1;
|
||||
dbus_iter in;
|
||||
int type;
|
||||
|
||||
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);
|
||||
while ((type = g_dbus.iter_type(it)) == 'v') {
|
||||
g_dbus.iter_recurse(it, &in);
|
||||
*it = in;
|
||||
}
|
||||
return out;
|
||||
if (type == 'u' || type == 'i' || type == 'b') {
|
||||
Uint32 v = 0;
|
||||
|
||||
g_dbus.iter_basic(it, &v);
|
||||
return (int)v;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* The settings below in one round trip, -1 for each the portal does not
|
||||
have. A desktop with no portal, or one without ReadAll, is not asked again;
|
||||
one slow to start is. */
|
||||
static const char *const g_portal[][2] = {
|
||||
{ "org.freedesktop.appearance", "reduced-motion" },
|
||||
{ "org.gnome.desktop.interface", "enable-animations" },
|
||||
{ "org.freedesktop.appearance", "contrast" },
|
||||
{ "org.gnome.desktop.a11y.interface", "high-contrast" },
|
||||
};
|
||||
#define PORTAL_N ((int)(sizeof g_portal / sizeof g_portal[0]))
|
||||
|
||||
static void portal_read(int out[PORTAL_N])
|
||||
{
|
||||
static const char *const ns[] = { "org.freedesktop.appearance",
|
||||
"org.gnome.desktop.interface",
|
||||
"org.gnome.desktop.a11y.interface" };
|
||||
const char *const *names = ns;
|
||||
void *msg, *reply;
|
||||
dbus_error e;
|
||||
dbus_iter top, all, one, keys, kv;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < PORTAL_N; i++) out[i] = -1;
|
||||
if (g_dbus.gone || !dbus_ready()) return;
|
||||
msg = g_dbus.method_call("org.freedesktop.portal.Desktop",
|
||||
"/org/freedesktop/portal/desktop",
|
||||
"org.freedesktop.portal.Settings", "ReadAll");
|
||||
if (!msg) return;
|
||||
if (!g_dbus.append_args(msg, 'a', 's', &names, (int)SDL_arraysize(ns), 0)) {
|
||||
g_dbus.message_unref(msg);
|
||||
return;
|
||||
}
|
||||
g_dbus.error_init(&e);
|
||||
reply = g_dbus.send_block(g_dbus.conn, msg, 300, &e);
|
||||
if (!reply)
|
||||
g_dbus.gone = g_dbus.error_has_name(&e, "org.freedesktop.DBus.Error.ServiceUnknown") ||
|
||||
g_dbus.error_has_name(&e, "org.freedesktop.DBus.Error.UnknownMethod");
|
||||
g_dbus.error_free(&e);
|
||||
g_dbus.message_unref(msg);
|
||||
if (!reply) return;
|
||||
if (g_dbus.has_signature(reply, "a{sa{sv}}") && g_dbus.iter_init(reply, &top)) {
|
||||
for (g_dbus.iter_recurse(&top, &all); g_dbus.iter_type(&all) == 'e'; g_dbus.iter_next(&all)) {
|
||||
const char *n = NULL;
|
||||
|
||||
g_dbus.iter_recurse(&all, &one);
|
||||
g_dbus.iter_basic(&one, &n);
|
||||
g_dbus.iter_next(&one);
|
||||
for (g_dbus.iter_recurse(&one, &keys); g_dbus.iter_type(&keys) == 'e';
|
||||
g_dbus.iter_next(&keys)) {
|
||||
const char *k = NULL;
|
||||
|
||||
g_dbus.iter_recurse(&keys, &kv);
|
||||
g_dbus.iter_basic(&kv, &k);
|
||||
g_dbus.iter_next(&kv);
|
||||
for (i = 0; i < PORTAL_N; i++)
|
||||
if (SDL_strcmp(n, g_portal[i][0]) == 0 && SDL_strcmp(k, g_portal[i][1]) == 0)
|
||||
out[i] = portal_value(&kv);
|
||||
}
|
||||
}
|
||||
}
|
||||
g_dbus.message_unref(reply);
|
||||
}
|
||||
#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)
|
||||
void reaktor_prefers(int *reduced_motion, int *contrast)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
BOOL on = TRUE;
|
||||
HIGHCONTRASTW hc;
|
||||
|
||||
hc.cbSize = sizeof hc;
|
||||
return SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof hc, &hc, 0) &&
|
||||
(hc.dwFlags & HCF_HIGHCONTRASTON);
|
||||
hc.cbSize = sizeof hc;
|
||||
*reduced_motion = SystemParametersInfoW(SPI_GETCLIENTAREAANIMATION, 0, &on, 0) && !on;
|
||||
*contrast = SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof hc, &hc, 0) &&
|
||||
(hc.dwFlags & HCF_HIGHCONTRASTON);
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
return EM_ASM_INT({
|
||||
*reduced_motion = EM_ASM_INT({
|
||||
return window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 1 : 0;
|
||||
});
|
||||
*contrast = 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");
|
||||
*reduced_motion = workspace_says("accessibilityDisplayShouldReduceMotion");
|
||||
*contrast = workspace_says("accessibilityDisplayShouldIncreaseContrast");
|
||||
#elif !defined(__ANDROID__)
|
||||
int v = portal_read("org.freedesktop.appearance", "contrast");
|
||||
int v[PORTAL_N];
|
||||
|
||||
if (v >= 0) return v == 1;
|
||||
return portal_read("org.gnome.desktop.a11y.interface", "high-contrast") == 1;
|
||||
portal_read(v);
|
||||
*reduced_motion = v[0] >= 0 ? v[0] == 1 : v[1] == 0;
|
||||
*contrast = v[2] >= 0 ? v[2] == 1 : v[3] == 1;
|
||||
#else
|
||||
return 0;
|
||||
*reduced_motion = 0;
|
||||
*contrast = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -2,8 +2,7 @@
|
||||
#define REAKTOR_THEME_H
|
||||
|
||||
int reaktor_prefers_dark(void);
|
||||
int reaktor_prefers_reduced_motion(void);
|
||||
int reaktor_prefers_contrast(void);
|
||||
void reaktor_prefers(int *reduced_motion, int *contrast);
|
||||
|
||||
struct SDL_Window;
|
||||
|
||||
|
||||
+113
-24
@@ -97,6 +97,67 @@ reaktor_asset_name(const reaktor_asset *a, const char *fallback)
|
||||
#define ON_WEB 0
|
||||
#endif
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#define GPU_DRIVERS "opengles2"
|
||||
#elif defined(__APPLE__)
|
||||
#define GPU_DRIVERS "metal"
|
||||
#elif defined(_WIN32)
|
||||
#define GPU_DRIVERS "opengl,direct3d12,direct3d11"
|
||||
#else
|
||||
#define GPU_DRIVERS "opengl,opengles2"
|
||||
#endif
|
||||
|
||||
/* An output colorspace is fixed when the renderer is made. scRGB is the HDR one
|
||||
SDL scales sRGB drawing into; a renderer without it, software among them, is
|
||||
made SDR as before. */
|
||||
SDL_Renderer *
|
||||
reaktor_renderer_for(SDL_Window *win, const char *name, int hdr)
|
||||
{
|
||||
SDL_Renderer *ren = NULL;
|
||||
|
||||
if (hdr) {
|
||||
SDL_PropertiesID p = SDL_CreateProperties();
|
||||
|
||||
SDL_SetPointerProperty(p, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, win);
|
||||
if (name) SDL_SetStringProperty(p, SDL_PROP_RENDERER_CREATE_NAME_STRING, name);
|
||||
SDL_SetNumberProperty(p, SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER,
|
||||
SDL_COLORSPACE_SRGB_LINEAR);
|
||||
ren = SDL_CreateRendererWithProperties(p);
|
||||
SDL_DestroyProperties(p);
|
||||
}
|
||||
/* SDL's gpu renderer keeps a linear output on a swapchain that cannot show
|
||||
one, and draws everything dark there. */
|
||||
if (ren) {
|
||||
SDL_GPUDevice *dev = (SDL_GPUDevice *)SDL_GetPointerProperty(
|
||||
SDL_GetRendererProperties(ren), SDL_PROP_RENDERER_GPU_DEVICE_POINTER, NULL);
|
||||
|
||||
if (dev && !SDL_WindowSupportsGPUSwapchainComposition(
|
||||
dev, win, SDL_GPU_SWAPCHAINCOMPOSITION_HDR_EXTENDED_LINEAR)) {
|
||||
SDL_DestroyRenderer(ren);
|
||||
ren = NULL;
|
||||
}
|
||||
}
|
||||
return ren ? ren : SDL_CreateRenderer(win, name);
|
||||
}
|
||||
|
||||
static const char *launch_title(void);
|
||||
|
||||
/* SDL_CreateWindowAndRenderer, with the renderer made by the call above. */
|
||||
static bool
|
||||
open_window(App *app, int w, int h, SDL_WindowFlags flags)
|
||||
{
|
||||
app->win = SDL_CreateWindow(launch_title(), w, h, flags | SDL_WINDOW_HIDDEN);
|
||||
if (!app->win) return false;
|
||||
app->ren = reaktor_renderer_for(app->win, NULL, g_launch.hdr);
|
||||
if (!app->ren) {
|
||||
SDL_DestroyWindow(app->win);
|
||||
app->win = NULL;
|
||||
return false;
|
||||
}
|
||||
if (!(flags & SDL_WINDOW_HIDDEN)) SDL_ShowWindow(app->win);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
capturing(const App *app)
|
||||
{
|
||||
@@ -288,6 +349,10 @@ take_flags(App *app, int argc, char **argv)
|
||||
else if (v && SDL_strcmp(a, "--contrast") == 0) { g_contrast_flag = pick(v, "more", 1, "normal", -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, "--hdr") == 0) {
|
||||
g_launch.hdr = pick(v, "on", 1, "off", 0, g_launch.hdr);
|
||||
i++;
|
||||
}
|
||||
else if (v && SDL_strcmp(a, "--video") == 0) { app->video_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--popups") == 0) {
|
||||
app->popups_inline = SDL_strcmp(v, "inline") == 0;
|
||||
@@ -366,9 +431,12 @@ theme_sheet(int dark)
|
||||
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;
|
||||
int r = 0, c = 0, changed;
|
||||
|
||||
if (!g_motion_flag || !g_contrast_flag) reaktor_prefers(&r, &c);
|
||||
if (g_motion_flag) r = g_motion_flag > 0;
|
||||
if (g_contrast_flag) c = g_contrast_flag > 0;
|
||||
changed = r != g_reduced || c != g_contrast;
|
||||
|
||||
g_reduced = r;
|
||||
g_contrast = c;
|
||||
@@ -467,7 +535,6 @@ 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);
|
||||
@@ -484,11 +551,8 @@ 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 && !roles_hold(app)) {
|
||||
sheets[n] = role_sheet(app);
|
||||
if (reaktor_style_init(sheets, n + 1, app->dark ? "dark" : "light"))
|
||||
read_roles(app);
|
||||
}
|
||||
if (n > base && !roles_hold(app) && reaktor_style_add(role_sheet(app)))
|
||||
read_roles(app);
|
||||
t1 = SDL_GetPerformanceCounter();
|
||||
app->style_ms_x100 = ms_x100(t0, t1);
|
||||
app->card_bg = reaktor_style_token("--background", c)
|
||||
@@ -765,6 +829,7 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
reaktor_rss_mark(REAKTOR_RSS_ENTRY);
|
||||
app = (App *)SDL_calloc(1, sizeof(App));
|
||||
if (!app) return SDL_APP_FAILURE;
|
||||
app->started = SDL_GetPerformanceCounter();
|
||||
*appstate = app;
|
||||
g_app = app;
|
||||
|
||||
@@ -794,6 +859,12 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) return fail(app, "SDL could not start");
|
||||
/* SDL gives the first registration SDL_EVENT_USER, the type wakes push. */
|
||||
SDL_RegisterEvents(1);
|
||||
/* SDL makes every window a drop target while a drop event is enabled; on
|
||||
Windows that is COM's drag-and-drop, three DLLs and three threads. */
|
||||
if (!g_launch.file_opened) {
|
||||
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, false);
|
||||
SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, false);
|
||||
}
|
||||
reaktor_signal_watch();
|
||||
if (g_launch.console == REAKTOR_CONSOLE_DEBUG)
|
||||
SDL_SetLogPriorities(SDL_LOG_PRIORITY_DEBUG);
|
||||
@@ -801,11 +872,16 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
reaktor_rss_mark(REAKTOR_RSS_SDL);
|
||||
take_assets(app);
|
||||
|
||||
if (!app->renderer_pref) app->renderer_pref = g_launch.renderer;
|
||||
if (app->renderer_pref && SDL_strcmp(app->renderer_pref, "software") != 0) {
|
||||
SDL_strlcpy(app->render_mode, app->renderer_pref,
|
||||
sizeof(app->render_mode));
|
||||
if (SDL_strcasecmp(app->renderer_pref, "directx") == 0)
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, "direct3d12,direct3d11");
|
||||
else if (SDL_strcasecmp(app->renderer_pref, "gpu") == 0)
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, GPU_DRIVERS);
|
||||
else if (SDL_strcasecmp(app->renderer_pref, "sdl-gpu") == 0)
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, "gpu");
|
||||
else if (SDL_strcmp(app->renderer_pref, "auto") != 0)
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, app->renderer_pref);
|
||||
} else {
|
||||
@@ -821,11 +897,12 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
{
|
||||
float pre = reaktor_dpi_query_scale(NULL);
|
||||
int win_w = (int)((g_launch.window.w > 0 ? g_launch.window.w : WINDOW_WIDTH)
|
||||
* pre + 0.5f);
|
||||
int win_h = (int)((g_launch.window.h > 0 ? g_launch.window.h : WINDOW_HEIGHT)
|
||||
* pre + 0.5f);
|
||||
float pre = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
|
||||
int win_w, win_h;
|
||||
|
||||
if (pre <= 0.0f) pre = 1.0f;
|
||||
win_w = (int)((g_launch.window.w > 0 ? g_launch.window.w : WINDOW_WIDTH) * pre + 0.5f);
|
||||
win_h = (int)((g_launch.window.h > 0 ? g_launch.window.h : WINDOW_HEIGHT) * pre + 0.5f);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
web_page_size(&win_w, &win_h);
|
||||
@@ -836,15 +913,14 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
(g_launch.window.skip_taskbar ? SDL_WINDOW_UTILITY : 0) |
|
||||
(placed(app) || starts_hidden(app) ? SDL_WINDOW_HIDDEN : 0);
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer(launch_title(), win_w, win_h, flags,
|
||||
&app->win, &app->ren)) {
|
||||
Uint64 t0 = SDL_GetPerformanceCounter();
|
||||
|
||||
if (!open_window(app, win_w, win_h, flags)) {
|
||||
SDL_Log("renderer '%s' would not start (%s); falling back",
|
||||
app->render_mode, SDL_GetError());
|
||||
if (app->win) { SDL_DestroyWindow(app->win); app->win = NULL; }
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, NULL);
|
||||
SDL_strlcpy(app->render_mode, "auto", sizeof(app->render_mode));
|
||||
if (!SDL_CreateWindowAndRenderer(launch_title(), win_w, win_h, flags,
|
||||
&app->win, &app->ren))
|
||||
if (!open_window(app, win_w, win_h, flags))
|
||||
return fail(app, "The window could not be opened");
|
||||
}
|
||||
|
||||
@@ -869,6 +945,7 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
}
|
||||
app->renderer_is_sw =
|
||||
SDL_strcmp(SDL_GetRendererName(app->ren), "software") == 0;
|
||||
app->window_ms_x100 = ms_x100(t0, SDL_GetPerformanceCounter());
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (g_launch.window.min_w > 0 || g_launch.window.min_h > 0)
|
||||
SDL_SetWindowMinimumSize(app->win,
|
||||
@@ -932,6 +1009,7 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
reaktor_rss_mark(REAKTOR_RSS_START);
|
||||
|
||||
take_pending(app);
|
||||
read_prefs();
|
||||
load_theme(app);
|
||||
reaktor_rss_mark(REAKTOR_RSS_STYLE);
|
||||
if (g_launch.single_instance) reaktor_instance_listen(app, g_launch.file_opened);
|
||||
@@ -983,6 +1061,7 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
case SDL_EVENT_SYSTEM_THEME_CHANGED:
|
||||
case SDL_EVENT_LOCALE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_HDR_STATE_CHANGED:
|
||||
app->dirty = 1;
|
||||
app->why |= REAKTOR_WHY_INPUT;
|
||||
break;
|
||||
@@ -990,15 +1069,19 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
break;
|
||||
}
|
||||
|
||||
/* What the window shows may be gone, whatever the frame would draw. */
|
||||
/* What the window shows may be gone, whatever the frame would draw; and a
|
||||
box is placed a frame late, so a new size needs a second frame. */
|
||||
switch (event->type) {
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_EXPOSED:
|
||||
case SDL_EVENT_WINDOW_SHOWN:
|
||||
case SDL_EVENT_WINDOW_RESTORED:
|
||||
case SDL_EVENT_WINDOW_MAXIMIZED:
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
if (!app->dragging && app->restore_rate < 2) app->restore_rate = 2;
|
||||
/* fall through */
|
||||
case SDL_EVENT_WINDOW_EXPOSED:
|
||||
case SDL_EVENT_WINDOW_SHOWN:
|
||||
case SDL_EVENT_WINDOW_HDR_STATE_CHANGED:
|
||||
case SDL_EVENT_RENDER_TARGETS_RESET:
|
||||
case SDL_EVENT_RENDER_DEVICE_RESET:
|
||||
app->must_draw = 1;
|
||||
@@ -1057,7 +1140,7 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
break;
|
||||
|
||||
case SDL_EVENT_SYSTEM_THEME_CHANGED:
|
||||
if (app->theme_mode == REAKTOR_THEME_SYSTEM || read_prefs()) load_theme(app);
|
||||
if (read_prefs() || app->theme_mode == REAKTOR_THEME_SYSTEM) load_theme(app);
|
||||
break;
|
||||
|
||||
case SDL_EVENT_LOCALE_CHANGED:
|
||||
@@ -1202,6 +1285,7 @@ app_event(void *appstate, SDL_Event *event)
|
||||
}
|
||||
if (!(to = app)) return SDL_APP_CONTINUE;
|
||||
}
|
||||
if (!to->secondary) reaktor_tray_event(to, event);
|
||||
reaktor_input_event(to, event);
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
@@ -1601,7 +1685,7 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
nk_style_pop_vec2(ctx);
|
||||
|
||||
t_render0 = SDL_GetPerformanceCounter();
|
||||
if (same_frame(app, ctx)) {
|
||||
if (app->build_only || same_frame(app, ctx)) {
|
||||
t_present0 = t_end = t_render0;
|
||||
app->frames_skipped++;
|
||||
} else {
|
||||
@@ -1655,6 +1739,7 @@ app_iterate(void *appstate)
|
||||
}
|
||||
if (g_css_pending || app->theme_pending) {
|
||||
take_pending(app);
|
||||
read_prefs();
|
||||
load_theme(app);
|
||||
}
|
||||
reaktor_windows_draw();
|
||||
@@ -1687,6 +1772,7 @@ app_iterate(void *appstate)
|
||||
|
||||
if (!app->first_frame_done) {
|
||||
app->first_frame_done = 1;
|
||||
app->first_ms_x100 = ms_x100(app->started, SDL_GetPerformanceCounter());
|
||||
reaktor_hint(SDL_HINT_MAIN_CALLBACK_RATE, app->frame_rate);
|
||||
reaktor_release_free_memory();
|
||||
}
|
||||
@@ -1737,6 +1823,7 @@ app_quit(void *appstate, SDL_AppResult result)
|
||||
if (app->ren) img_cache_free(app);
|
||||
if (app->ctx) nk_sdl_shutdown(app->ctx);
|
||||
reaktor_fontset_free(&app->fonts);
|
||||
atlas_forget();
|
||||
if (app->ren) SDL_DestroyRenderer(app->ren);
|
||||
if (app->win) SDL_DestroyWindow(app->win);
|
||||
reaktor_anim_destroy(app->anim);
|
||||
@@ -2019,6 +2106,8 @@ reaktor_set_visible(App *app, int on)
|
||||
if (!app || !app->win) return;
|
||||
if (on) {
|
||||
SDL_ShowWindow(app->win);
|
||||
if (SDL_GetWindowFlags(app->win) & SDL_WINDOW_MINIMIZED)
|
||||
SDL_RestoreWindow(app->win);
|
||||
SDL_RaiseWindow(app->win);
|
||||
} else {
|
||||
SDL_HideWindow(app->win);
|
||||
|
||||
@@ -299,6 +299,12 @@ tab_style(void)
|
||||
row("Selector", "%s%s", sel, st.matched ? "" : " (no rule matches)");
|
||||
color_row("color", st.fg);
|
||||
color_row("background", st.bg);
|
||||
if (st.gradient)
|
||||
row("background-image", "%s #%02x%02x%02x%02x to #%02x%02x%02x%02x",
|
||||
st.gradient == REAKTOR_GRADIENT_ACROSS ? "across" : "down",
|
||||
st.gradient_from[0], st.gradient_from[1], st.gradient_from[2],
|
||||
st.gradient_from[3], st.gradient_to[0], st.gradient_to[1],
|
||||
st.gradient_to[2], st.gradient_to[3]);
|
||||
color_row("border-color", st.border_col);
|
||||
row("border-width", "%.0f %.0f %.0f %.0f", st.border_w[0], st.border_w[1],
|
||||
st.border_w[2], st.border_w[3]);
|
||||
@@ -351,6 +357,8 @@ tab_frame(void)
|
||||
row("Present", "%.2f ms", d.present_ms);
|
||||
row("Since the previous frame", "%.1f ms", d.frame_gap_ms);
|
||||
row("Stylesheets", "%d, loaded in %.2f ms", d.sheets, d.style_ms);
|
||||
row("Startup", "window %.1f ms, atlas %.1f ms, first frame at %.0f ms",
|
||||
d.window_ms, d.atlas_ms, d.first_frame_ms);
|
||||
row("Renderer", "%s, %s", d.renderer ? d.renderer : "", d.mode ? d.mode : "");
|
||||
row("Scale", "%.2f", d.scale);
|
||||
row("Process memory", "%lu KiB", d.rss_bytes / 1024ul);
|
||||
|
||||
@@ -235,8 +235,10 @@ print_run(App *app, void *user)
|
||||
|
||||
job->index = i;
|
||||
reaktor_app_size(pa, &w, &h);
|
||||
pa->build_only = 1;
|
||||
for (k = 0; k < 3 || (!reaktor_frame_settled(pa) && k < 24); k++)
|
||||
reaktor_app_frame(pa, w, h, "", print_page, job);
|
||||
pa->build_only = 0;
|
||||
pa->want_capture = 1;
|
||||
reaktor_app_frame(pa, w, h, "", print_page, job);
|
||||
page[i] = pa->capture ? SDL_ConvertSurface(pa->capture, SDL_PIXELFORMAT_ARGB8888) : NULL;
|
||||
|
||||
+170
-88
@@ -1,19 +1,19 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define INI_IMPLEMENTATION
|
||||
#define INI_MALLOC(ctx, size) ((void)(ctx), SDL_malloc(size))
|
||||
#define INI_FREE(ctx, ptr) ((void)(ctx), SDL_free(ptr))
|
||||
#define INI_MEMCPY(dst, src, cnt) SDL_memcpy(dst, src, cnt)
|
||||
#define INI_STRLEN(s) SDL_strlen(s)
|
||||
#define INI_STRNICMP(s1, s2, cnt) SDL_strncasecmp(s1, s2, cnt)
|
||||
#include "ini.h"
|
||||
#include "toml.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
static ini_t *g_ini;
|
||||
static int g_ini_dirty;
|
||||
/* Settings live here as flat dotted keys, in the order they were added; the
|
||||
file is TOML, every key quoted at the top level, so `window` and
|
||||
`window.maximized` can both be strings. */
|
||||
typedef struct { char *key, *value; } setting;
|
||||
|
||||
static setting *g_set;
|
||||
static int g_count, g_cap, g_loaded;
|
||||
static int g_dirty;
|
||||
static unsigned g_save_timer;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@@ -30,70 +30,139 @@ settings_path(void)
|
||||
char *dir = SDL_GetPrefPath(NULL, reaktor_app_ident());
|
||||
char *path = NULL;
|
||||
|
||||
if (dir) SDL_asprintf(&path, "%ssettings.conf", dir);
|
||||
if (dir) SDL_asprintf(&path, "%ssettings.toml", dir);
|
||||
SDL_free(dir);
|
||||
return path;
|
||||
}
|
||||
|
||||
static ini_t *
|
||||
settings(void)
|
||||
static int
|
||||
setting_index(const char *key)
|
||||
{
|
||||
char *text;
|
||||
int i;
|
||||
|
||||
if (g_ini) return g_ini;
|
||||
if (reaktor_capturing()) return g_ini = ini_create(NULL);
|
||||
{
|
||||
char *path = settings_path();
|
||||
|
||||
text = path ? (char *)SDL_LoadFile(path, NULL) : NULL;
|
||||
SDL_free(path);
|
||||
}
|
||||
g_ini = text ? ini_load(text, NULL) : ini_create(NULL);
|
||||
SDL_free(text);
|
||||
return g_ini;
|
||||
for (i = 0; i < g_count; i++)
|
||||
if (SDL_strcmp(g_set[i].key, key) == 0) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
setting_find(const char *key, int *section, int add)
|
||||
static void
|
||||
setting_put(char *key, char *value)
|
||||
{
|
||||
const char *dot = SDL_strrchr(key, '.');
|
||||
ini_t *ini = settings();
|
||||
int i = setting_index(key);
|
||||
|
||||
*section = INI_GLOBAL_SECTION;
|
||||
if (!ini) return INI_NOT_FOUND;
|
||||
if (dot) {
|
||||
*section = ini_find_section(ini, key, (int)(dot - key));
|
||||
if (*section == INI_NOT_FOUND && add)
|
||||
*section = ini_section_add(ini, key, (int)(dot - key));
|
||||
if (*section == INI_NOT_FOUND) return INI_NOT_FOUND;
|
||||
key = dot + 1;
|
||||
if (i >= 0) {
|
||||
SDL_free(key);
|
||||
SDL_free(g_set[i].value);
|
||||
g_set[i].value = value;
|
||||
return;
|
||||
}
|
||||
return ini_find_property(ini, *section, key, 0);
|
||||
if (!reaktor_grow((void **)&g_set, &g_cap, g_count + 1, sizeof *g_set)) {
|
||||
SDL_free(key);
|
||||
SDL_free(value);
|
||||
return;
|
||||
}
|
||||
g_set[g_count].key = key;
|
||||
g_set[g_count++].value = value;
|
||||
}
|
||||
|
||||
/* A table nested in a hand-written file reads as dotted keys, and a number or
|
||||
a boolean as its text, so `maximized = 1` reads as "1"; an array is skipped. */
|
||||
static void
|
||||
settings_take(const toml_table_t *t, const char *prefix)
|
||||
{
|
||||
int i, len, n = toml_table_len(t);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
const char *name = toml_table_key(t, i, &len);
|
||||
toml_value_t v;
|
||||
toml_table_t *sub;
|
||||
char *key = NULL, *value = NULL;
|
||||
|
||||
SDL_asprintf(&key, "%s%s", prefix, name);
|
||||
if (!key) continue;
|
||||
if ((sub = toml_table_table(t, name)) != NULL) {
|
||||
SDL_asprintf(&value, "%s.", key);
|
||||
if (value) settings_take(sub, value);
|
||||
SDL_free(value);
|
||||
SDL_free(key);
|
||||
continue;
|
||||
}
|
||||
if ((v = toml_table_string(t, name)).ok) {
|
||||
value = SDL_strdup(v.u.s);
|
||||
free(v.u.s);
|
||||
} else if ((v = toml_table_int(t, name)).ok) {
|
||||
SDL_asprintf(&value, "%lld", (long long)v.u.i);
|
||||
} else if ((v = toml_table_double(t, name)).ok) {
|
||||
SDL_asprintf(&value, "%g", v.u.d);
|
||||
} else if ((v = toml_table_bool(t, name)).ok) {
|
||||
value = SDL_strdup(v.u.b ? "true" : "false");
|
||||
}
|
||||
if (value) setting_put(key, value);
|
||||
else SDL_free(key);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
settings_load(void)
|
||||
{
|
||||
char *text, *path;
|
||||
|
||||
if (g_loaded) return;
|
||||
g_loaded = 1;
|
||||
if (reaktor_capturing()) return;
|
||||
path = settings_path();
|
||||
text = path ? (char *)SDL_LoadFile(path, NULL) : NULL;
|
||||
SDL_free(path);
|
||||
if (text) {
|
||||
char err[200];
|
||||
toml_table_t *root = toml_parse(text, err, sizeof err);
|
||||
|
||||
if (root) settings_take(root, "");
|
||||
else SDL_Log("settings not read: %s", err);
|
||||
toml_free(root);
|
||||
}
|
||||
SDL_free(text);
|
||||
}
|
||||
|
||||
static void
|
||||
put_string(SDL_IOStream *out, const char *s)
|
||||
{
|
||||
SDL_WriteU8(out, '"');
|
||||
for (; *s; s++) {
|
||||
unsigned char c = (unsigned char)*s;
|
||||
|
||||
if (c == '"' || c == '\\') SDL_IOprintf(out, "\\%c", c);
|
||||
else if (c == '\n') SDL_IOprintf(out, "\\n");
|
||||
else if (c == '\t') SDL_IOprintf(out, "\\t");
|
||||
else if (c < 0x20 || c == 0x7f) SDL_IOprintf(out, "\\u%04X", c);
|
||||
else SDL_WriteU8(out, c);
|
||||
}
|
||||
SDL_WriteU8(out, '"');
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_save(void)
|
||||
{
|
||||
int size;
|
||||
char *text;
|
||||
char *path, *tmp = NULL;
|
||||
SDL_IOStream *out;
|
||||
int i, ok;
|
||||
|
||||
if (!g_ini_dirty || !g_ini || reaktor_capturing()) return;
|
||||
size = ini_save(g_ini, NULL, 0);
|
||||
text = (char *)SDL_malloc((size_t)size);
|
||||
if (!text) return;
|
||||
ini_save(g_ini, text, size);
|
||||
{
|
||||
char *path = settings_path(), *tmp = NULL;
|
||||
|
||||
if (path) SDL_asprintf(&tmp, "%s.new", path);
|
||||
if (!tmp || !SDL_SaveFile(tmp, text, (size_t)size - 1) || !SDL_RenamePath(tmp, path))
|
||||
SDL_Log("settings not saved: %s", SDL_GetError());
|
||||
SDL_free(tmp);
|
||||
SDL_free(path);
|
||||
if (!g_dirty || reaktor_capturing()) return;
|
||||
path = settings_path();
|
||||
if (path) SDL_asprintf(&tmp, "%s.new", path);
|
||||
out = tmp ? SDL_IOFromFile(tmp, "wb") : NULL;
|
||||
for (i = 0; out && i < g_count; i++) {
|
||||
put_string(out, g_set[i].key);
|
||||
SDL_IOprintf(out, " = ");
|
||||
put_string(out, g_set[i].value);
|
||||
SDL_WriteU8(out, '\n');
|
||||
}
|
||||
ok = out && SDL_CloseIO(out) && SDL_RenamePath(tmp, path);
|
||||
if (!ok) SDL_Log("settings not saved: %s", SDL_GetError());
|
||||
SDL_free(tmp);
|
||||
SDL_free(path);
|
||||
settings_persist();
|
||||
SDL_free(text);
|
||||
g_ini_dirty = 0;
|
||||
g_dirty = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -110,7 +179,7 @@ settings_changed(void)
|
||||
int ms;
|
||||
reaktor_save mode = reaktor_save_mode(&ms);
|
||||
|
||||
g_ini_dirty = 1;
|
||||
g_dirty = 1;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (mode == REAKTOR_SAVE_ON_QUIT) mode = REAKTOR_SAVE_ON_CHANGE;
|
||||
#endif
|
||||
@@ -123,61 +192,74 @@ settings_changed(void)
|
||||
const char *
|
||||
reaktor_setting(const char *key)
|
||||
{
|
||||
int section, property = key ? setting_find(key, §ion, 0) : INI_NOT_FOUND;
|
||||
int i;
|
||||
|
||||
return property == INI_NOT_FOUND ? NULL
|
||||
: ini_property_value(g_ini, section, property);
|
||||
if (!key) return NULL;
|
||||
settings_load();
|
||||
i = setting_index(key);
|
||||
return i < 0 ? NULL : g_set[i].value;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_setting_set(const char *key, const char *value)
|
||||
{
|
||||
const char *name;
|
||||
int section, property;
|
||||
int i;
|
||||
|
||||
if (!key || !*key || SDL_strpbrk(key, "=[]\n") || (value && SDL_strchr(value, '\n')))
|
||||
return;
|
||||
property = setting_find(key, §ion, value != NULL);
|
||||
name = SDL_strrchr(key, '.') ? SDL_strrchr(key, '.') + 1 : key;
|
||||
if (property != INI_NOT_FOUND && value &&
|
||||
SDL_strcmp(ini_property_value(g_ini, section, property), value) == 0)
|
||||
return;
|
||||
if (!value && property == INI_NOT_FOUND) return;
|
||||
if (!value)
|
||||
ini_property_remove(g_ini, section, property);
|
||||
else if (property != INI_NOT_FOUND)
|
||||
ini_property_value_set(g_ini, section, property, value, 0);
|
||||
else if (section != INI_NOT_FOUND)
|
||||
ini_property_add(g_ini, section, name, 0, value, 0);
|
||||
else
|
||||
return;
|
||||
if (!key || !*key) return;
|
||||
settings_load();
|
||||
i = setting_index(key);
|
||||
if (i < 0 && !value) return;
|
||||
if (i >= 0 && value && SDL_strcmp(g_set[i].value, value) == 0) return;
|
||||
if (i >= 0 && value) {
|
||||
SDL_free(g_set[i].value);
|
||||
g_set[i].value = SDL_strdup(value);
|
||||
} else if (value) {
|
||||
setting_put(SDL_strdup(key), SDL_strdup(value));
|
||||
} else {
|
||||
SDL_free(g_set[i].key);
|
||||
SDL_free(g_set[i].value);
|
||||
SDL_memmove(&g_set[i], &g_set[i + 1], (size_t)(g_count - i - 1) * sizeof *g_set);
|
||||
g_count--;
|
||||
}
|
||||
settings_changed();
|
||||
}
|
||||
|
||||
static void
|
||||
settings_empty(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_count; i++) {
|
||||
SDL_free(g_set[i].key);
|
||||
SDL_free(g_set[i].value);
|
||||
}
|
||||
SDL_free(g_set);
|
||||
g_set = NULL;
|
||||
g_count = g_cap = 0;
|
||||
g_dirty = 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_clear(void)
|
||||
{
|
||||
ini_destroy(g_ini);
|
||||
g_ini = ini_create(NULL);
|
||||
g_ini_dirty = 0;
|
||||
char *path;
|
||||
|
||||
settings_empty();
|
||||
g_loaded = 1;
|
||||
if (g_save_timer) reaktor_timer_stop(g_save_timer);
|
||||
g_save_timer = 0;
|
||||
if (reaktor_capturing()) return;
|
||||
{
|
||||
char *path = settings_path();
|
||||
|
||||
if (path) SDL_RemovePath(path);
|
||||
SDL_free(path);
|
||||
}
|
||||
path = settings_path();
|
||||
if (path) SDL_RemovePath(path);
|
||||
SDL_free(path);
|
||||
settings_persist();
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_free(void)
|
||||
{
|
||||
ini_destroy(g_ini);
|
||||
g_ini = NULL;
|
||||
g_ini_dirty = 0;
|
||||
settings_empty();
|
||||
g_loaded = 0;
|
||||
g_save_timer = 0;
|
||||
}
|
||||
|
||||
|
||||
+802
-9
@@ -3,10 +3,793 @@
|
||||
|
||||
#define TRAY_ITEMS 16
|
||||
|
||||
#ifdef REAKTOR_TRAY_DBUS
|
||||
/* Linux and the BSDs: a StatusNotifierItem with a com.canonical.dbusmenu menu,
|
||||
spoken over libdbus. SDL's tray there builds its menu from GTK widgets, and
|
||||
loading GTK cost the showcase hundreds of libraries and half a second. */
|
||||
#include <dbus/dbus.h>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SNI_PATH "/StatusNotifierItem"
|
||||
#define SNI_IFACE "org.kde.StatusNotifierItem"
|
||||
#define MENU_PATH "/MenuBar"
|
||||
#define MENU_IFACE "com.canonical.dbusmenu"
|
||||
#define WATCHER "org.kde.StatusNotifierWatcher"
|
||||
#define PROPS_IFACE "org.freedesktop.DBus.Properties"
|
||||
|
||||
static DBusConnection *g_bus;
|
||||
static reaktor_tray_item g_item[TRAY_ITEMS];
|
||||
static int g_on[TRAY_ITEMS];
|
||||
static char *g_label[TRAY_ITEMS];
|
||||
static char *g_tip;
|
||||
static char g_name[64];
|
||||
static int g_n, g_hide_on_minimize, g_tag;
|
||||
static Uint8 *g_icon[4];
|
||||
static int g_icon_px[4], g_icons;
|
||||
|
||||
/* SDL has no way to wait on another descriptor, so one thread sleeps in
|
||||
poll() on the bus and wakes the frame loop, which reads and answers. It
|
||||
never touches libdbus; it waits for the main thread to drain the bus. */
|
||||
static SDL_Thread *g_thread;
|
||||
static SDL_Semaphore *g_drained;
|
||||
static SDL_AtomicInt g_running;
|
||||
static int g_stop[2] = { -1, -1 };
|
||||
|
||||
static int SDLCALL
|
||||
watch_bus(void *fdp)
|
||||
{
|
||||
struct pollfd p[2];
|
||||
|
||||
p[0].fd = (int)(intptr_t)fdp;
|
||||
p[0].events = POLLIN;
|
||||
p[1].fd = g_stop[0];
|
||||
p[1].events = POLLIN;
|
||||
while (SDL_GetAtomicInt(&g_running)) {
|
||||
SDL_Event e;
|
||||
|
||||
if (poll(p, 2, -1) < 0) continue;
|
||||
if (p[1].revents || !SDL_GetAtomicInt(&g_running)) break;
|
||||
if (!p[0].revents) continue;
|
||||
SDL_zero(e);
|
||||
e.type = SDL_EVENT_USER;
|
||||
e.user.data1 = &g_tag;
|
||||
if (!SDL_PushEvent(&e)) break;
|
||||
SDL_WaitSemaphore(g_drained);
|
||||
/* A hung-up bus would wake us forever. */
|
||||
if (p[0].revents & (POLLHUP | POLLERR)) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
put_variant(DBusMessageIter *it, int type, const char *sig, const void *v)
|
||||
{
|
||||
DBusMessageIter var;
|
||||
|
||||
dbus_message_iter_open_container(it, DBUS_TYPE_VARIANT, sig, &var);
|
||||
dbus_message_iter_append_basic(&var, type, v);
|
||||
dbus_message_iter_close_container(it, &var);
|
||||
}
|
||||
|
||||
static void
|
||||
put_entry(DBusMessageIter *dict, const char *key, int type, const char *sig,
|
||||
const void *v)
|
||||
{
|
||||
DBusMessageIter e;
|
||||
|
||||
dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, NULL, &e);
|
||||
dbus_message_iter_append_basic(&e, DBUS_TYPE_STRING, &key);
|
||||
put_variant(&e, type, sig, v);
|
||||
dbus_message_iter_close_container(dict, &e);
|
||||
}
|
||||
|
||||
static void
|
||||
put_empty(DBusMessageIter *it, const char *sig)
|
||||
{
|
||||
DBusMessageIter arr;
|
||||
|
||||
dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, sig, &arr);
|
||||
dbus_message_iter_close_container(it, &arr);
|
||||
}
|
||||
|
||||
/* a(iiay): each size, ARGB32 in network byte order. */
|
||||
static void
|
||||
put_pixmaps(DBusMessageIter *it, int all)
|
||||
{
|
||||
DBusMessageIter arr, st, bytes;
|
||||
int i;
|
||||
|
||||
dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, "(iiay)", &arr);
|
||||
for (i = 0; all && i < g_icons; i++) {
|
||||
dbus_int32_t px = g_icon_px[i];
|
||||
const Uint8 *b = g_icon[i];
|
||||
|
||||
dbus_message_iter_open_container(&arr, DBUS_TYPE_STRUCT, NULL, &st);
|
||||
dbus_message_iter_append_basic(&st, DBUS_TYPE_INT32, &px);
|
||||
dbus_message_iter_append_basic(&st, DBUS_TYPE_INT32, &px);
|
||||
dbus_message_iter_open_container(&st, DBUS_TYPE_ARRAY, "y", &bytes);
|
||||
dbus_message_iter_append_fixed_array(&bytes, DBUS_TYPE_BYTE, &b, px * px * 4);
|
||||
dbus_message_iter_close_container(&st, &bytes);
|
||||
dbus_message_iter_close_container(&arr, &st);
|
||||
}
|
||||
dbus_message_iter_close_container(it, &arr);
|
||||
}
|
||||
|
||||
/* (sa(iiay)ss): icon name, pixmaps, title, text. */
|
||||
static void
|
||||
put_tooltip(DBusMessageIter *it)
|
||||
{
|
||||
DBusMessageIter var, st;
|
||||
const char *none = "", *tip = g_tip ? g_tip : "";
|
||||
|
||||
dbus_message_iter_open_container(it, DBUS_TYPE_VARIANT, "(sa(iiay)ss)", &var);
|
||||
dbus_message_iter_open_container(&var, DBUS_TYPE_STRUCT, NULL, &st);
|
||||
dbus_message_iter_append_basic(&st, DBUS_TYPE_STRING, &none);
|
||||
put_pixmaps(&st, 0);
|
||||
dbus_message_iter_append_basic(&st, DBUS_TYPE_STRING, &tip);
|
||||
dbus_message_iter_append_basic(&st, DBUS_TYPE_STRING, &none);
|
||||
dbus_message_iter_close_container(&var, &st);
|
||||
dbus_message_iter_close_container(it, &var);
|
||||
}
|
||||
|
||||
/* One property of the item into a variant; 0 when there is no such name. */
|
||||
static int
|
||||
sni_prop(DBusMessageIter *it, const char *name)
|
||||
{
|
||||
const char *none = "", *menu = MENU_PATH, *id = reaktor_app_ident();
|
||||
const char *cat = "ApplicationStatus", *status = "Active";
|
||||
const char *title = g_tip ? g_tip : id;
|
||||
dbus_bool_t yes = 1;
|
||||
dbus_int32_t zero = 0;
|
||||
DBusMessageIter var;
|
||||
|
||||
if (!SDL_strcmp(name, "Category")) put_variant(it, DBUS_TYPE_STRING, "s", &cat);
|
||||
else if (!SDL_strcmp(name, "Id")) put_variant(it, DBUS_TYPE_STRING, "s", &id);
|
||||
else if (!SDL_strcmp(name, "Title")) put_variant(it, DBUS_TYPE_STRING, "s", &title);
|
||||
else if (!SDL_strcmp(name, "Status")) put_variant(it, DBUS_TYPE_STRING, "s", &status);
|
||||
else if (!SDL_strcmp(name, "WindowId")) put_variant(it, DBUS_TYPE_INT32, "i", &zero);
|
||||
else if (!SDL_strcmp(name, "IconName") || !SDL_strcmp(name, "OverlayIconName") ||
|
||||
!SDL_strcmp(name, "AttentionIconName") ||
|
||||
!SDL_strcmp(name, "AttentionMovieName"))
|
||||
put_variant(it, DBUS_TYPE_STRING, "s", &none);
|
||||
else if (!SDL_strcmp(name, "IconPixmap") || !SDL_strcmp(name, "OverlayIconPixmap") ||
|
||||
!SDL_strcmp(name, "AttentionIconPixmap")) {
|
||||
dbus_message_iter_open_container(it, DBUS_TYPE_VARIANT, "a(iiay)", &var);
|
||||
put_pixmaps(&var, name[0] == 'I');
|
||||
dbus_message_iter_close_container(it, &var);
|
||||
} else if (!SDL_strcmp(name, "ToolTip")) put_tooltip(it);
|
||||
else if (!SDL_strcmp(name, "ItemIsMenu")) put_variant(it, DBUS_TYPE_BOOLEAN, "b", &yes);
|
||||
else if (!SDL_strcmp(name, "Menu")) put_variant(it, DBUS_TYPE_OBJECT_PATH, "o", &menu);
|
||||
else return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *const sni_props[] = {
|
||||
"Category", "Id", "Title", "Status", "WindowId", "IconName", "IconPixmap",
|
||||
"OverlayIconName", "OverlayIconPixmap", "AttentionIconName",
|
||||
"AttentionIconPixmap", "AttentionMovieName", "ToolTip", "ItemIsMenu", "Menu"
|
||||
};
|
||||
|
||||
static int
|
||||
menu_prop(DBusMessageIter *it, const char *name)
|
||||
{
|
||||
const char *dir = "ltr", *status = "normal";
|
||||
dbus_uint32_t version = 3;
|
||||
DBusMessageIter var;
|
||||
|
||||
if (!SDL_strcmp(name, "Version")) put_variant(it, DBUS_TYPE_UINT32, "u", &version);
|
||||
else if (!SDL_strcmp(name, "TextDirection")) put_variant(it, DBUS_TYPE_STRING, "s", &dir);
|
||||
else if (!SDL_strcmp(name, "Status")) put_variant(it, DBUS_TYPE_STRING, "s", &status);
|
||||
else if (!SDL_strcmp(name, "IconThemePath")) {
|
||||
dbus_message_iter_open_container(it, DBUS_TYPE_VARIANT, "as", &var);
|
||||
put_empty(&var, "s");
|
||||
dbus_message_iter_close_container(it, &var);
|
||||
} else return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *const menu_props[] = { "Version", "TextDirection", "Status", "IconThemePath" };
|
||||
|
||||
/* An item's a{sv}; id 0 is the root, item i is id i + 1. */
|
||||
static void
|
||||
put_item_props(DBusMessageIter *it, int id)
|
||||
{
|
||||
DBusMessageIter dict;
|
||||
const reaktor_tray_item *t = id > 0 ? &g_item[id - 1] : NULL;
|
||||
|
||||
dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, "{sv}", &dict);
|
||||
if (!t) {
|
||||
const char *sub = "submenu";
|
||||
|
||||
put_entry(&dict, "children-display", DBUS_TYPE_STRING, "s", &sub);
|
||||
} else if (!t->label) {
|
||||
const char *sep = "separator";
|
||||
|
||||
put_entry(&dict, "type", DBUS_TYPE_STRING, "s", &sep);
|
||||
} else {
|
||||
const char *label = g_label[id - 1] ? g_label[id - 1] : "";
|
||||
dbus_bool_t on = !t->disabled;
|
||||
|
||||
put_entry(&dict, "label", DBUS_TYPE_STRING, "s", &label);
|
||||
put_entry(&dict, "enabled", DBUS_TYPE_BOOLEAN, "b", &on);
|
||||
if (t->checkbox) {
|
||||
const char *mark = "checkmark";
|
||||
dbus_int32_t state = g_on[id - 1];
|
||||
|
||||
put_entry(&dict, "toggle-type", DBUS_TYPE_STRING, "s", &mark);
|
||||
put_entry(&dict, "toggle-state", DBUS_TYPE_INT32, "i", &state);
|
||||
}
|
||||
}
|
||||
dbus_message_iter_close_container(it, &dict);
|
||||
}
|
||||
|
||||
/* (ia{sv}av), the root holding every item when depth allows. */
|
||||
static void
|
||||
put_layout(DBusMessageIter *it, int id, int depth)
|
||||
{
|
||||
DBusMessageIter st, kids, var;
|
||||
dbus_int32_t i32 = id;
|
||||
int i;
|
||||
|
||||
dbus_message_iter_open_container(it, DBUS_TYPE_STRUCT, NULL, &st);
|
||||
dbus_message_iter_append_basic(&st, DBUS_TYPE_INT32, &i32);
|
||||
put_item_props(&st, id);
|
||||
dbus_message_iter_open_container(&st, DBUS_TYPE_ARRAY, "v", &kids);
|
||||
for (i = 0; id == 0 && depth != 0 && i < g_n; i++) {
|
||||
dbus_message_iter_open_container(&kids, DBUS_TYPE_VARIANT, "(ia{sv}av)", &var);
|
||||
put_layout(&var, i + 1, depth - 1);
|
||||
dbus_message_iter_close_container(&kids, &var);
|
||||
}
|
||||
dbus_message_iter_close_container(&st, &kids);
|
||||
dbus_message_iter_close_container(it, &st);
|
||||
}
|
||||
|
||||
/* (ia{sv}): an item with its properties. */
|
||||
static void
|
||||
put_item(DBusMessageIter *arr, dbus_int32_t id)
|
||||
{
|
||||
DBusMessageIter st;
|
||||
|
||||
dbus_message_iter_open_container(arr, DBUS_TYPE_STRUCT, NULL, &st);
|
||||
dbus_message_iter_append_basic(&st, DBUS_TYPE_INT32, &id);
|
||||
put_item_props(&st, id);
|
||||
dbus_message_iter_close_container(arr, &st);
|
||||
}
|
||||
|
||||
static void
|
||||
send_and_free(DBusMessage *m)
|
||||
{
|
||||
if (!m) return;
|
||||
dbus_connection_send(g_bus, m, NULL);
|
||||
dbus_message_unref(m);
|
||||
dbus_connection_flush(g_bus);
|
||||
}
|
||||
|
||||
static void
|
||||
items_updated(int id)
|
||||
{
|
||||
DBusMessage *m = dbus_message_new_signal(MENU_PATH, MENU_IFACE, "ItemsPropertiesUpdated");
|
||||
DBusMessageIter it, arr;
|
||||
|
||||
if (!m) return;
|
||||
dbus_message_iter_init_append(m, &it);
|
||||
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY, "(ia{sv})", &arr);
|
||||
put_item(&arr, id);
|
||||
dbus_message_iter_close_container(&it, &arr);
|
||||
put_empty(&it, "(ias)");
|
||||
send_and_free(m);
|
||||
}
|
||||
|
||||
static void
|
||||
clicked(int id)
|
||||
{
|
||||
const reaktor_tray_item *it;
|
||||
App *app = reaktor_main_app();
|
||||
|
||||
if (id < 1 || id > g_n) return;
|
||||
it = &g_item[id - 1];
|
||||
if (!it->label || it->disabled) return;
|
||||
/* A check item flips as it is chosen, as GTK's did under SDL's tray. */
|
||||
if (it->checkbox) {
|
||||
g_on[id - 1] = !g_on[id - 1];
|
||||
items_updated(id);
|
||||
}
|
||||
if (app && it->chosen) {
|
||||
it->chosen(app, it->checkbox && g_on[id - 1], it->user);
|
||||
reaktor_wake(app);
|
||||
}
|
||||
}
|
||||
|
||||
static const char sni_xml[] =
|
||||
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
|
||||
"<node><interface name=\"" SNI_IFACE "\">"
|
||||
"<method name=\"Activate\"><arg type=\"i\" direction=\"in\"/><arg type=\"i\" direction=\"in\"/></method>"
|
||||
"<method name=\"SecondaryActivate\"><arg type=\"i\" direction=\"in\"/><arg type=\"i\" direction=\"in\"/></method>"
|
||||
"<method name=\"ContextMenu\"><arg type=\"i\" direction=\"in\"/><arg type=\"i\" direction=\"in\"/></method>"
|
||||
"<method name=\"Scroll\"><arg type=\"i\" direction=\"in\"/><arg type=\"s\" direction=\"in\"/></method>"
|
||||
"<property name=\"Category\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"Id\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"Title\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"Status\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"WindowId\" type=\"i\" access=\"read\"/>"
|
||||
"<property name=\"IconName\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"IconPixmap\" type=\"a(iiay)\" access=\"read\"/>"
|
||||
"<property name=\"OverlayIconName\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"OverlayIconPixmap\" type=\"a(iiay)\" access=\"read\"/>"
|
||||
"<property name=\"AttentionIconName\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"AttentionIconPixmap\" type=\"a(iiay)\" access=\"read\"/>"
|
||||
"<property name=\"AttentionMovieName\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"ToolTip\" type=\"(sa(iiay)ss)\" access=\"read\"/>"
|
||||
"<property name=\"ItemIsMenu\" type=\"b\" access=\"read\"/>"
|
||||
"<property name=\"Menu\" type=\"o\" access=\"read\"/>"
|
||||
"<signal name=\"NewTitle\"/><signal name=\"NewIcon\"/><signal name=\"NewToolTip\"/>"
|
||||
"<signal name=\"NewStatus\"><arg type=\"s\"/></signal>"
|
||||
"</interface></node>";
|
||||
|
||||
static const char menu_xml[] =
|
||||
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
|
||||
"<node><interface name=\"" MENU_IFACE "\">"
|
||||
"<method name=\"GetLayout\"><arg type=\"i\" direction=\"in\"/><arg type=\"i\" direction=\"in\"/>"
|
||||
"<arg type=\"as\" direction=\"in\"/><arg type=\"u\" direction=\"out\"/>"
|
||||
"<arg type=\"(ia{sv}av)\" direction=\"out\"/></method>"
|
||||
"<method name=\"GetGroupProperties\"><arg type=\"ai\" direction=\"in\"/>"
|
||||
"<arg type=\"as\" direction=\"in\"/><arg type=\"a(ia{sv})\" direction=\"out\"/></method>"
|
||||
"<method name=\"GetProperty\"><arg type=\"i\" direction=\"in\"/><arg type=\"s\" direction=\"in\"/>"
|
||||
"<arg type=\"v\" direction=\"out\"/></method>"
|
||||
"<method name=\"Event\"><arg type=\"i\" direction=\"in\"/><arg type=\"s\" direction=\"in\"/>"
|
||||
"<arg type=\"v\" direction=\"in\"/><arg type=\"u\" direction=\"in\"/></method>"
|
||||
"<method name=\"EventGroup\"><arg type=\"a(isvu)\" direction=\"in\"/>"
|
||||
"<arg type=\"ai\" direction=\"out\"/></method>"
|
||||
"<method name=\"AboutToShow\"><arg type=\"i\" direction=\"in\"/><arg type=\"b\" direction=\"out\"/></method>"
|
||||
"<method name=\"AboutToShowGroup\"><arg type=\"ai\" direction=\"in\"/>"
|
||||
"<arg type=\"ai\" direction=\"out\"/><arg type=\"ai\" direction=\"out\"/></method>"
|
||||
"<property name=\"Version\" type=\"u\" access=\"read\"/>"
|
||||
"<property name=\"TextDirection\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"Status\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"IconThemePath\" type=\"as\" access=\"read\"/>"
|
||||
"<signal name=\"ItemsPropertiesUpdated\"><arg type=\"a(ia{sv})\"/><arg type=\"a(ias)\"/></signal>"
|
||||
"<signal name=\"LayoutUpdated\"><arg type=\"u\"/><arg type=\"i\"/></signal>"
|
||||
"<signal name=\"ItemActivationRequested\"><arg type=\"i\"/><arg type=\"u\"/></signal>"
|
||||
"</interface></node>";
|
||||
|
||||
/* Properties.Get and GetAll, for either object. */
|
||||
static DBusMessage *
|
||||
properties(DBusMessage *m, int menu)
|
||||
{
|
||||
int (*prop)(DBusMessageIter *, const char *) = menu ? menu_prop : sni_prop;
|
||||
const char *const *names = menu ? menu_props : sni_props;
|
||||
int count = menu ? (int)SDL_arraysize(menu_props) : (int)SDL_arraysize(sni_props);
|
||||
const char *iface = NULL, *name = NULL;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter it, dict, e;
|
||||
int i;
|
||||
|
||||
if (dbus_message_is_method_call(m, PROPS_IFACE, "GetAll")) {
|
||||
if (!dbus_message_get_args(m, NULL, DBUS_TYPE_STRING, &iface, DBUS_TYPE_INVALID))
|
||||
return dbus_message_new_error(m, DBUS_ERROR_INVALID_ARGS, "GetAll(s)");
|
||||
if (!(r = dbus_message_new_method_return(m))) return NULL;
|
||||
dbus_message_iter_init_append(r, &it);
|
||||
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY, "{sv}", &dict);
|
||||
for (i = 0; i < count; i++) {
|
||||
dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &e);
|
||||
dbus_message_iter_append_basic(&e, DBUS_TYPE_STRING, &names[i]);
|
||||
prop(&e, names[i]);
|
||||
dbus_message_iter_close_container(&dict, &e);
|
||||
}
|
||||
dbus_message_iter_close_container(&it, &dict);
|
||||
return r;
|
||||
}
|
||||
if (dbus_message_is_method_call(m, PROPS_IFACE, "Get")) {
|
||||
if (!dbus_message_get_args(m, NULL, DBUS_TYPE_STRING, &iface,
|
||||
DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
|
||||
return dbus_message_new_error(m, DBUS_ERROR_INVALID_ARGS, "Get(ss)");
|
||||
if (!(r = dbus_message_new_method_return(m))) return NULL;
|
||||
dbus_message_iter_init_append(r, &it);
|
||||
if (prop(&it, name)) return r;
|
||||
dbus_message_unref(r);
|
||||
return dbus_message_new_error(m, DBUS_ERROR_UNKNOWN_PROPERTY, name);
|
||||
}
|
||||
return dbus_message_new_error(m, DBUS_ERROR_PROPERTY_READ_ONLY, "read only");
|
||||
}
|
||||
|
||||
static DBusMessage *
|
||||
menu_call(DBusMessage *m, const char *member)
|
||||
{
|
||||
DBusMessage *r = NULL;
|
||||
DBusMessageIter in, out, arr;
|
||||
dbus_int32_t id = 0, depth = -1;
|
||||
int i;
|
||||
|
||||
if (!SDL_strcmp(member, "GetLayout")) {
|
||||
if (!dbus_message_get_args(m, NULL, DBUS_TYPE_INT32, &id, DBUS_TYPE_INT32, &depth,
|
||||
DBUS_TYPE_INVALID) || id < 0 || id > g_n)
|
||||
return dbus_message_new_error(m, DBUS_ERROR_INVALID_ARGS, "no such item");
|
||||
if (!(r = dbus_message_new_method_return(m))) return NULL;
|
||||
dbus_uint32_t revision = 1;
|
||||
|
||||
dbus_message_iter_init_append(r, &out);
|
||||
dbus_message_iter_append_basic(&out, DBUS_TYPE_UINT32, &revision);
|
||||
put_layout(&out, id, depth);
|
||||
} else if (!SDL_strcmp(member, "GetGroupProperties")) {
|
||||
dbus_int32_t *ids = NULL;
|
||||
int n = 0;
|
||||
|
||||
if (!dbus_message_get_args(m, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &ids, &n,
|
||||
DBUS_TYPE_INVALID))
|
||||
n = 0;
|
||||
if (!(r = dbus_message_new_method_return(m))) return NULL;
|
||||
dbus_message_iter_init_append(r, &out);
|
||||
dbus_message_iter_open_container(&out, DBUS_TYPE_ARRAY, "(ia{sv})", &arr);
|
||||
/* No ids asks for every item. */
|
||||
for (i = 0; i < (n ? n : g_n + 1); i++) {
|
||||
id = n ? ids[i] : i;
|
||||
if (id >= 0 && id <= g_n) put_item(&arr, id);
|
||||
}
|
||||
dbus_message_iter_close_container(&out, &arr);
|
||||
} else if (!SDL_strcmp(member, "GetProperty")) {
|
||||
const char *name = NULL;
|
||||
DBusMessageIter props, e;
|
||||
|
||||
if (!dbus_message_get_args(m, NULL, DBUS_TYPE_INT32, &id, DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_INVALID) || id < 0 || id > g_n)
|
||||
return dbus_message_new_error(m, DBUS_ERROR_INVALID_ARGS, "no such item");
|
||||
/* Built as a dict, then the one value copied out. */
|
||||
{
|
||||
DBusMessage *tmp = dbus_message_new_method_return(m);
|
||||
DBusMessageIter t;
|
||||
|
||||
if (!tmp) return NULL;
|
||||
dbus_message_iter_init_append(tmp, &t);
|
||||
put_item_props(&t, id);
|
||||
dbus_message_iter_init(tmp, &t);
|
||||
dbus_message_iter_recurse(&t, &props);
|
||||
while (dbus_message_iter_get_arg_type(&props) == DBUS_TYPE_DICT_ENTRY) {
|
||||
const char *key;
|
||||
|
||||
dbus_message_iter_recurse(&props, &e);
|
||||
dbus_message_iter_get_basic(&e, &key);
|
||||
if (!SDL_strcmp(key, name)) {
|
||||
DBusMessageIter v, inner;
|
||||
int type;
|
||||
union { const char *s; dbus_int32_t i; dbus_bool_t b; } val;
|
||||
char sig[2];
|
||||
|
||||
dbus_message_iter_next(&e);
|
||||
dbus_message_iter_recurse(&e, &v);
|
||||
type = dbus_message_iter_get_arg_type(&v);
|
||||
dbus_message_iter_get_basic(&v, &val);
|
||||
sig[0] = (char)type;
|
||||
sig[1] = 0;
|
||||
if ((r = dbus_message_new_method_return(m))) {
|
||||
dbus_message_iter_init_append(r, &out);
|
||||
dbus_message_iter_open_container(&out, DBUS_TYPE_VARIANT, sig, &inner);
|
||||
dbus_message_iter_append_basic(&inner, type, &val);
|
||||
dbus_message_iter_close_container(&out, &inner);
|
||||
}
|
||||
break;
|
||||
}
|
||||
dbus_message_iter_next(&props);
|
||||
}
|
||||
dbus_message_unref(tmp);
|
||||
}
|
||||
if (!r) return dbus_message_new_error(m, DBUS_ERROR_INVALID_ARGS, "no such property");
|
||||
} else if (!SDL_strcmp(member, "Event")) {
|
||||
const char *what = NULL;
|
||||
|
||||
if (!dbus_message_get_args(m, NULL, DBUS_TYPE_INT32, &id, DBUS_TYPE_STRING, &what,
|
||||
DBUS_TYPE_INVALID))
|
||||
what = NULL;
|
||||
r = dbus_message_new_method_return(m);
|
||||
if (what && !SDL_strcmp(what, "clicked")) {
|
||||
send_and_free(r);
|
||||
clicked(id);
|
||||
return NULL;
|
||||
}
|
||||
} else if (!SDL_strcmp(member, "EventGroup")) {
|
||||
DBusMessageIter evs, ev;
|
||||
int n = 0, chosen[TRAY_ITEMS];
|
||||
|
||||
if (dbus_message_has_signature(m, "a(isvu)") && dbus_message_iter_init(m, &in)) {
|
||||
dbus_message_iter_recurse(&in, &evs);
|
||||
while (dbus_message_iter_get_arg_type(&evs) == DBUS_TYPE_STRUCT) {
|
||||
const char *what = NULL;
|
||||
|
||||
dbus_message_iter_recurse(&evs, &ev);
|
||||
dbus_message_iter_get_basic(&ev, &id);
|
||||
dbus_message_iter_next(&ev);
|
||||
if (dbus_message_iter_get_arg_type(&ev) == DBUS_TYPE_STRING)
|
||||
dbus_message_iter_get_basic(&ev, &what);
|
||||
if (what && !SDL_strcmp(what, "clicked") && n < TRAY_ITEMS) chosen[n++] = id;
|
||||
dbus_message_iter_next(&evs);
|
||||
}
|
||||
}
|
||||
if ((r = dbus_message_new_method_return(m))) {
|
||||
dbus_message_iter_init_append(r, &out);
|
||||
put_empty(&out, "i");
|
||||
send_and_free(r);
|
||||
}
|
||||
for (i = 0; i < n; i++) clicked(chosen[i]);
|
||||
return NULL;
|
||||
} else if (!SDL_strcmp(member, "AboutToShow")) {
|
||||
dbus_bool_t no = 0;
|
||||
|
||||
if ((r = dbus_message_new_method_return(m)))
|
||||
dbus_message_append_args(r, DBUS_TYPE_BOOLEAN, &no, DBUS_TYPE_INVALID);
|
||||
} else if (!SDL_strcmp(member, "AboutToShowGroup")) {
|
||||
if ((r = dbus_message_new_method_return(m))) {
|
||||
dbus_message_iter_init_append(r, &out);
|
||||
put_empty(&out, "i");
|
||||
put_empty(&out, "i");
|
||||
}
|
||||
} else {
|
||||
r = dbus_message_new_error(m, DBUS_ERROR_UNKNOWN_METHOD, member);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static DBusHandlerResult
|
||||
on_message(DBusConnection *c, DBusMessage *m, void *menup)
|
||||
{
|
||||
int menu = menup != NULL;
|
||||
const char *iface = dbus_message_get_interface(m);
|
||||
const char *member = dbus_message_get_member(m);
|
||||
DBusMessage *r = NULL;
|
||||
|
||||
(void)c;
|
||||
if (dbus_message_get_type(m) != DBUS_MESSAGE_TYPE_METHOD_CALL || !member)
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
if (iface && !SDL_strcmp(iface, DBUS_INTERFACE_INTROSPECTABLE)) {
|
||||
const char *xml = menu ? menu_xml : sni_xml;
|
||||
|
||||
if ((r = dbus_message_new_method_return(m)))
|
||||
dbus_message_append_args(r, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID);
|
||||
} else if (iface && !SDL_strcmp(iface, PROPS_IFACE)) {
|
||||
r = properties(m, menu);
|
||||
} else if (menu) {
|
||||
r = menu_call(m, member);
|
||||
} else if (!SDL_strcmp(member, "Activate") || !SDL_strcmp(member, "SecondaryActivate") ||
|
||||
!SDL_strcmp(member, "ContextMenu") || !SDL_strcmp(member, "Scroll")) {
|
||||
/* ItemIsMenu: the host opens the menu itself on a click. */
|
||||
r = dbus_message_new_method_return(m);
|
||||
} else {
|
||||
r = dbus_message_new_error(m, DBUS_ERROR_UNKNOWN_METHOD, member);
|
||||
}
|
||||
send_and_free(r);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
static int
|
||||
register_item(int block)
|
||||
{
|
||||
DBusMessage *m = dbus_message_new_method_call(WATCHER, "/StatusNotifierWatcher", WATCHER,
|
||||
"RegisterStatusNotifierItem");
|
||||
const char *name = g_name;
|
||||
DBusMessage *r;
|
||||
DBusError err;
|
||||
|
||||
if (!m) return 0;
|
||||
dbus_message_append_args(m, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
|
||||
if (!block) {
|
||||
send_and_free(m);
|
||||
return 1;
|
||||
}
|
||||
dbus_error_init(&err);
|
||||
r = dbus_connection_send_with_reply_and_block(g_bus, m, 2000, &err);
|
||||
dbus_message_unref(m);
|
||||
if (!r) {
|
||||
SDL_Log("tray: no StatusNotifierWatcher (%s)", err.message ? err.message : "");
|
||||
dbus_error_free(&err);
|
||||
return 0;
|
||||
}
|
||||
dbus_message_unref(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* A watcher that starts after us, or restarts, is told about the item again. */
|
||||
static DBusHandlerResult
|
||||
on_signal(DBusConnection *c, DBusMessage *m, void *user)
|
||||
{
|
||||
const char *name = NULL, *was = NULL, *now = NULL;
|
||||
|
||||
(void)c; (void)user;
|
||||
if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameOwnerChanged") &&
|
||||
dbus_message_get_args(m, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &was,
|
||||
DBUS_TYPE_STRING, &now, DBUS_TYPE_INVALID) &&
|
||||
!SDL_strcmp(name, WATCHER) && now && now[0])
|
||||
register_item(0);
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
}
|
||||
|
||||
static void
|
||||
pump(void)
|
||||
{
|
||||
dbus_connection_read_write(g_bus, 0);
|
||||
while (dbus_connection_dispatch(g_bus) == DBUS_DISPATCH_DATA_REMAINS)
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
icons_make(void)
|
||||
{
|
||||
static const int sizes[] = { 22, 32, 48, 64 };
|
||||
int i, x, y;
|
||||
|
||||
for (i = g_icons = 0; i < (int)SDL_arraysize(sizes); i++) {
|
||||
SDL_Surface *s = reaktor_icon_surface(reaktor_launch_icon(), sizes[i]);
|
||||
Uint8 *out;
|
||||
|
||||
if (!s) continue;
|
||||
if (s->w != sizes[i] || s->h != sizes[i] ||
|
||||
!(out = (Uint8 *)SDL_malloc((size_t)s->w * (size_t)s->h * 4))) {
|
||||
SDL_DestroySurface(s);
|
||||
continue;
|
||||
}
|
||||
for (y = 0; y < s->h; y++) {
|
||||
const Uint32 *row = (const Uint32 *)((const Uint8 *)s->pixels + y * s->pitch);
|
||||
|
||||
for (x = 0; x < s->w; x++) {
|
||||
Uint32 p = row[x];
|
||||
Uint8 *o = out + (y * s->w + x) * 4;
|
||||
|
||||
o[0] = (Uint8)(p >> 24);
|
||||
o[1] = (Uint8)(p >> 16);
|
||||
o[2] = (Uint8)(p >> 8);
|
||||
o[3] = (Uint8)p;
|
||||
}
|
||||
}
|
||||
g_icon[g_icons] = out;
|
||||
g_icon_px[g_icons++] = sizes[i];
|
||||
SDL_DestroySurface(s);
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
clean_dup(const char *s, int mnemonic)
|
||||
{
|
||||
size_t n = SDL_strlen(s) * 3 + 1, i, j;
|
||||
char *c = (char *)SDL_malloc(n), *out;
|
||||
|
||||
if (!c) return NULL;
|
||||
reaktor_utf8_clean(c, s, n);
|
||||
if (!mnemonic || !(out = (char *)SDL_malloc(SDL_strlen(c) * 2 + 1))) return c;
|
||||
/* dbusmenu reads an underscore as a mnemonic; GTK's label under SDL did not. */
|
||||
for (i = j = 0; c[i]; i++) {
|
||||
if (c[i] == '_') out[j++] = '_';
|
||||
out[j++] = c[i];
|
||||
}
|
||||
out[j] = 0;
|
||||
SDL_free(c);
|
||||
return out;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_tray_open(App *app, const reaktor_tray *spec)
|
||||
{
|
||||
static const DBusObjectPathVTable vt = { NULL, on_message, NULL, NULL, NULL, NULL };
|
||||
const char *drv = SDL_GetCurrentVideoDriver();
|
||||
DBusError err;
|
||||
int i, fd = -1;
|
||||
|
||||
reaktor_tray_close(app);
|
||||
if (!spec) return 0;
|
||||
if (!drv || SDL_strcmp(drv, "dummy") == 0 || SDL_strcmp(drv, "offscreen") == 0)
|
||||
return 0;
|
||||
dbus_error_init(&err);
|
||||
if (!(g_bus = dbus_bus_get_private(DBUS_BUS_SESSION, &err))) {
|
||||
SDL_Log("tray: %s", err.message ? err.message : "no session bus");
|
||||
dbus_error_free(&err);
|
||||
return 0;
|
||||
}
|
||||
dbus_connection_set_exit_on_disconnect(g_bus, 0);
|
||||
g_n = spec->count < 0 ? 0 : spec->count < TRAY_ITEMS ? spec->count : TRAY_ITEMS;
|
||||
for (i = 0; i < g_n; i++) {
|
||||
g_item[i] = spec->items[i];
|
||||
g_on[i] = spec->items[i].checkbox && spec->items[i].checked;
|
||||
g_label[i] = spec->items[i].label ? clean_dup(spec->items[i].label, 1) : NULL;
|
||||
}
|
||||
g_tip = spec->tooltip ? clean_dup(spec->tooltip, 0) : NULL;
|
||||
icons_make();
|
||||
SDL_snprintf(g_name, sizeof g_name, "org.kde.StatusNotifierItem-%d-1", (int)getpid());
|
||||
if (!dbus_connection_register_object_path(g_bus, SNI_PATH, &vt, NULL) ||
|
||||
!dbus_connection_register_object_path(g_bus, MENU_PATH, &vt, (void *)1) ||
|
||||
dbus_bus_request_name(g_bus, g_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL) !=
|
||||
DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ||
|
||||
!register_item(1)) {
|
||||
reaktor_tray_close(app);
|
||||
return 0;
|
||||
}
|
||||
dbus_connection_add_filter(g_bus, on_signal, NULL, NULL);
|
||||
dbus_bus_add_match(g_bus, "type='signal',sender='" DBUS_SERVICE_DBUS "',"
|
||||
"interface='" DBUS_INTERFACE_DBUS "',member='NameOwnerChanged',"
|
||||
"arg0='" WATCHER "'", NULL);
|
||||
dbus_connection_flush(g_bus);
|
||||
if (dbus_connection_get_unix_fd(g_bus, &fd) && pipe(g_stop) == 0 &&
|
||||
(g_drained = SDL_CreateSemaphore(0))) {
|
||||
SDL_SetAtomicInt(&g_running, 1);
|
||||
g_thread = SDL_CreateThread(watch_bus, "reaktor-tray", (void *)(intptr_t)fd);
|
||||
}
|
||||
if (!g_thread) {
|
||||
reaktor_tray_close(app);
|
||||
return 0;
|
||||
}
|
||||
/* Whatever arrived during setup is read now; the thread sees only what is new. */
|
||||
pump();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_check(App *app, int item, int checked)
|
||||
{
|
||||
(void)app;
|
||||
if (!g_bus || item < 0 || item >= g_n || !g_item[item].checkbox) return;
|
||||
if (g_on[item] == (checked != 0)) return;
|
||||
g_on[item] = checked != 0;
|
||||
items_updated(item + 1);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_close(App *app)
|
||||
{
|
||||
int i;
|
||||
|
||||
(void)app;
|
||||
if (g_thread) {
|
||||
SDL_SetAtomicInt(&g_running, 0);
|
||||
if (write(g_stop[1], "", 1) < 0) { /* the thread also checks the flag */ }
|
||||
SDL_SignalSemaphore(g_drained);
|
||||
SDL_WaitThread(g_thread, NULL);
|
||||
g_thread = NULL;
|
||||
}
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (g_stop[i] >= 0) close(g_stop[i]);
|
||||
g_stop[i] = -1;
|
||||
}
|
||||
if (g_drained) SDL_DestroySemaphore(g_drained);
|
||||
g_drained = NULL;
|
||||
if (g_bus) {
|
||||
dbus_connection_close(g_bus);
|
||||
dbus_connection_unref(g_bus);
|
||||
}
|
||||
g_bus = NULL;
|
||||
for (i = 0; i < g_n; i++) {
|
||||
SDL_free(g_label[i]);
|
||||
g_label[i] = NULL;
|
||||
}
|
||||
for (i = 0; i < g_icons; i++) SDL_free(g_icon[i]);
|
||||
g_icons = 0;
|
||||
SDL_free(g_tip);
|
||||
g_tip = NULL;
|
||||
g_n = 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_hide_on_minimize(App *app, int on)
|
||||
{
|
||||
(void)app;
|
||||
g_hide_on_minimize = on != 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_event(App *app, const SDL_Event *e)
|
||||
{
|
||||
if (e->type == SDL_EVENT_USER && e->user.data1 == &g_tag) {
|
||||
if (g_bus) {
|
||||
pump();
|
||||
SDL_SignalSemaphore(g_drained);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (e->type == SDL_EVENT_WINDOW_MINIMIZED && g_hide_on_minimize && g_bus)
|
||||
reaktor_set_visible(app, 0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static SDL_Tray *g_tray;
|
||||
static SDL_TrayEntry *g_entry[TRAY_ITEMS];
|
||||
static reaktor_tray_item g_item[TRAY_ITEMS];
|
||||
static int g_n;
|
||||
static int g_n, g_hide_on_minimize;
|
||||
|
||||
static void SDLCALL
|
||||
chosen(void *userdata, SDL_TrayEntry *entry)
|
||||
@@ -22,7 +805,8 @@ chosen(void *userdata, SDL_TrayEntry *entry)
|
||||
int
|
||||
reaktor_tray_open(App *app, const reaktor_tray *spec)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#if defined(__EMSCRIPTEN__) || (defined(__unix__) && !defined(__APPLE__) && !defined(__ANDROID__))
|
||||
/* Linux and the BSDs built without dbus-1: no tray, rather than SDL's and GTK. */
|
||||
(void)app; (void)spec;
|
||||
return 0;
|
||||
#else
|
||||
@@ -37,13 +821,7 @@ reaktor_tray_open(App *app, const reaktor_tray *spec)
|
||||
if (!drv || SDL_strcmp(drv, "dummy") == 0 || SDL_strcmp(drv, "offscreen") == 0)
|
||||
return 0;
|
||||
icon = reaktor_icon_surface(reaktor_launch_icon(), 32);
|
||||
{
|
||||
/* GTK, under the tray on Linux and the BSDs, sets the user's locale. */
|
||||
char *was = reaktor_c_locale_keep(0);
|
||||
|
||||
g_tray = SDL_CreateTray(icon, spec->tooltip);
|
||||
reaktor_c_locale_put(0, was);
|
||||
}
|
||||
g_tray = SDL_CreateTray(icon, spec->tooltip);
|
||||
if (icon) SDL_DestroySurface(icon);
|
||||
if (!g_tray) {
|
||||
SDL_Log("tray: %s", SDL_GetError());
|
||||
@@ -83,3 +861,18 @@ reaktor_tray_close(App *app)
|
||||
g_tray = NULL;
|
||||
g_n = 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_hide_on_minimize(App *app, int on)
|
||||
{
|
||||
(void)app;
|
||||
g_hide_on_minimize = on != 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_event(App *app, const SDL_Event *e)
|
||||
{
|
||||
if (e->type == SDL_EVENT_WINDOW_MINIMIZED && g_hide_on_minimize && g_tray)
|
||||
reaktor_set_visible(app, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4,3 +4,5 @@
|
||||
int reaktor_tray_open(App *app, const reaktor_tray *spec) { (void)app; (void)spec; return 0; }
|
||||
void reaktor_tray_check(App *app, int item, int checked) { (void)app; (void)item; (void)checked; }
|
||||
void reaktor_tray_close(App *app) { (void)app; }
|
||||
void reaktor_tray_hide_on_minimize(App *app, int on) { (void)app; (void)on; }
|
||||
void reaktor_tray_event(App *app, const SDL_Event *e) { (void)app; (void)e; }
|
||||
|
||||
+19
-13
@@ -143,6 +143,7 @@ reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
#else
|
||||
App *m = reaktor_main_app(), *a;
|
||||
rwin *w;
|
||||
float k;
|
||||
int i;
|
||||
|
||||
if (!m || !spec || !spec->page || g_win_n == WINDOW_MAX) return 0;
|
||||
@@ -150,21 +151,21 @@ reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
a->secondary = 1;
|
||||
a->hot_last = -1;
|
||||
a->queue.moved_ok = 1;
|
||||
k = to_points(m);
|
||||
if (popup) {
|
||||
float k = to_points(m);
|
||||
|
||||
a->win = SDL_CreatePopupWindow(m->win, (int)(popup->x * k), (int)(popup->y * k),
|
||||
(int)(popup->w * k + 0.5f), (int)(popup->h * k + 0.5f),
|
||||
SDL_WINDOW_POPUP_MENU | SDL_WINDOW_NOT_FOCUSABLE |
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_HIDDEN);
|
||||
} else
|
||||
a->win = SDL_CreateWindow(spec->window.title ? spec->window.title : "",
|
||||
reaktor_px(spec->window.w > 0 ? (float)spec->window.w : 420.0f),
|
||||
reaktor_px(spec->window.h > 0 ? (float)spec->window.h : 280.0f),
|
||||
SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY |
|
||||
SDL_WINDOW_HIDDEN |
|
||||
(spec->window.borderless ? SDL_WINDOW_BORDERLESS : 0) |
|
||||
(spec->window.skip_taskbar ? SDL_WINDOW_UTILITY : 0));
|
||||
} else {
|
||||
a->win = SDL_CreateWindow(spec->window.title ? spec->window.title : "",
|
||||
(int)((spec->window.w > 0 ? (float)spec->window.w : 420.0f) * k + 0.5f),
|
||||
(int)((spec->window.h > 0 ? (float)spec->window.h : 280.0f) * k + 0.5f),
|
||||
SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY |
|
||||
SDL_WINDOW_HIDDEN |
|
||||
(spec->window.borderless ? SDL_WINDOW_BORDERLESS : 0) |
|
||||
(spec->window.skip_taskbar ? SDL_WINDOW_UTILITY : 0));
|
||||
}
|
||||
if (a->win && spec->window.centered) {
|
||||
SDL_DisplayID d = SDL_GetDisplayForWindow(m->win);
|
||||
|
||||
@@ -172,15 +173,20 @@ reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
SDL_WINDOWPOS_CENTERED_DISPLAY(d));
|
||||
}
|
||||
if (a->win && (spec->window.min_w > 0 || spec->window.min_h > 0))
|
||||
SDL_SetWindowMinimumSize(a->win, reaktor_px((float)spec->window.min_w),
|
||||
reaktor_px((float)spec->window.min_h));
|
||||
SDL_SetWindowMinimumSize(a->win, (int)((float)spec->window.min_w * k + 0.5f),
|
||||
(int)((float)spec->window.min_h * k + 0.5f));
|
||||
if (a->win && spec->window.borderless && spec->window.hit_test)
|
||||
SDL_SetWindowHitTest(a->win, spec->window.hit_test, a);
|
||||
if (a->win && spec->modal) {
|
||||
SDL_SetWindowParent(a->win, m->win);
|
||||
SDL_SetWindowModal(a->win, true);
|
||||
}
|
||||
if (a->win) a->ren = SDL_CreateRenderer(a->win, SDL_GetRendererName(m->ren));
|
||||
if (a->win)
|
||||
a->ren = reaktor_renderer_for(
|
||||
a->win, SDL_GetRendererName(m->ren),
|
||||
SDL_GetNumberProperty(SDL_GetRendererProperties(m->ren),
|
||||
SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER,
|
||||
SDL_COLORSPACE_SRGB) == SDL_COLORSPACE_SRGB_LINEAR);
|
||||
if (a->ren) a->ctx = nk_sdl_init(a->win, a->ren, nk_sdl_allocator());
|
||||
if (!a->ctx) {
|
||||
SDL_Log("window: %s", SDL_GetError());
|
||||
|
||||
@@ -89,7 +89,7 @@ static void
|
||||
well_caption(struct reaktor_context *ctx, struct reaktor_rect r,
|
||||
const char *text)
|
||||
{
|
||||
const struct reaktor_user_font *f = ctx->style.font;
|
||||
const struct reaktor_user_font *f = reaktor_current_font(ctx);
|
||||
int len = (int)strlen(text);
|
||||
float w = f->width(f->userdata, f->height, text, len);
|
||||
|
||||
@@ -437,7 +437,7 @@ fx_demo(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
}
|
||||
}
|
||||
|
||||
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 40.0f, .gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 40.0f, .gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
REAKTOR_ROW(.name = "Password", .flags = REAKTOR_LAY_FILL) {
|
||||
float dx = reaktor_anim_shake(a, shake, 26.0f, 22.0f, 0.6f);
|
||||
@@ -588,7 +588,7 @@ text_demo(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
float y1 = r.y + r.h < keep.y + keep.h ? r.y + r.h : keep.y + keep.h;
|
||||
|
||||
reaktor_fill_round(app, cv, r, 6.0f, well_color());
|
||||
o.pos = reaktor_vec2(r.x + 12.0f, r.y + (r.h - ctx->style.font->height) * 0.5f);
|
||||
o.pos = reaktor_vec2(r.x + 12.0f, r.y + (r.h - reaktor_current_font(ctx)->height) * 0.5f);
|
||||
reaktor_push_scissor(cv, reaktor_rect(x0, y0, x1 > x0 ? x1 - x0 : 0.0f, y1 > y0 ? y1 - y0 : 0.0f));
|
||||
reaktor_anim_text_stagger(a, ctx, line, t, &o);
|
||||
reaktor_push_scissor(cv, keep);
|
||||
@@ -630,7 +630,7 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"reaktor_anim_tween_float(reaktor_anim(app), id, 0, to, 0.6f, "
|
||||
"reaktor_anim_ease_spring(1, 170, 16, 0), ...)");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
for (i = 0; i < 3; i++)
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = stop_name[i],
|
||||
@@ -696,7 +696,7 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"chose, which is the value arriving.");
|
||||
api(app, ctx, "reaktor_ease_at(curve, t) / REAKTOR_EASE_*");
|
||||
|
||||
REAKTOR_ROW(.gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_ROW(.gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_PACK_CENTER | REAKTOR_LAY_WRAP) {
|
||||
unsigned id = reaktor_box_id();
|
||||
|
||||
@@ -761,7 +761,7 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
static const char *const word[4] = { "Home", "Search", "Library", "Profile" };
|
||||
struct reaktor_anim_context *anim = reaktor_anim(app);
|
||||
struct reaktor_command_buffer *cv = reaktor_window_get_canvas(ctx);
|
||||
const struct reaktor_user_font *f = ctx->style.font;
|
||||
const struct reaktor_user_font *f = reaktor_current_font(ctx);
|
||||
struct reaktor_colorf rest = reaktor_color_cf(reaktor_token("--background-alt", reaktor_rgb(48, 48, 48)));
|
||||
struct reaktor_colorf lit = reaktor_color_cf(reaktor_accent_color(app));
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = 38.0f,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Default",
|
||||
.box = { .flags = REAKTOR_LAY_FILL } })) s->presses++;
|
||||
@@ -99,7 +99,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
{ "menu-outline", "Menu" }
|
||||
};
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_WRAP,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
for (i = 0; i < ICON_N; i++)
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = g_icons[i].label, .icon = g_icons[i].icon,
|
||||
@@ -131,7 +131,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
for (m = 0; m < 4; m++) {
|
||||
REAKTOR_ROW(.h = 38.0f, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_label(&(reaktor_label_spec){ .text = how[m],
|
||||
.box = { .w = 110.0f, .flags = REAKTOR_LAY_FILL_Y } });
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
@@ -157,7 +157,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"text color for the button's state. Its name is what a reader hears.");
|
||||
api(app, ctx, ".paint / .paint_user / reaktor_button_custom(app, ctx, name, paint, user)");
|
||||
REAKTOR_ROW(.h = 52.0f, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Inbox, 12 new", .paint = paint_inbox, .paint_user = "12",
|
||||
.box = { .w = 180.0f, .flags = REAKTOR_LAY_FILL_Y } }))
|
||||
@@ -210,7 +210,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = 40.0f,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
compact_push(ctx);
|
||||
if (reaktor_swatch(&(reaktor_swatch_spec){
|
||||
.name = "Tint swatch", .fill = reaktor_rgb_cf(s->tint),
|
||||
@@ -237,7 +237,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
s->presses, s->repeats);
|
||||
reaktor_style_push_font(ctx, reaktor_style_font(app, ".small", 13, 0));
|
||||
reaktor_label_colored(ctx, line, REAKTOR_TEXT_LEFT,
|
||||
reaktor_token("--text-muted", ctx->style.text.color));
|
||||
reaktor_token("--text-muted", reaktor_text_color(ctx)));
|
||||
reaktor_style_pop_font(ctx);
|
||||
|
||||
section(app, ctx, "Checkboxes and radios",
|
||||
@@ -256,9 +256,9 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
{ "read", 1u }, { "write", 2u }, { "execute", 4u }
|
||||
};
|
||||
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_check(&(reaktor_check_spec){
|
||||
.label = "Wrap long lines", .on = &s->check_wrap,
|
||||
.box_right = 1,
|
||||
@@ -275,7 +275,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
}
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
reaktor_check(&(reaktor_check_spec){
|
||||
.label = perms[i].label, .flags = &s->flags,
|
||||
@@ -293,14 +293,14 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
SDL_snprintf(line, sizeof(line), "flags = 0x%02x", s->flags);
|
||||
reaktor_style_push_font(ctx, reaktor_style_font(app, ".small", 13, 0));
|
||||
reaktor_label_colored(ctx, line, REAKTOR_TEXT_LEFT,
|
||||
reaktor_token("--text-muted", ctx->style.text.color));
|
||||
reaktor_token("--text-muted", reaktor_text_color(ctx)));
|
||||
reaktor_style_pop_font(ctx);
|
||||
|
||||
{
|
||||
static const char *const names[3] = { "Never", "On Wi-Fi", "Always" };
|
||||
|
||||
REAKTOR_ROW(.h = ROW,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
reaktor_radio(&(reaktor_radio_spec){
|
||||
.label = names[i], .choice = &s->radio, .value = i,
|
||||
@@ -321,7 +321,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = 32.0f,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
char lab[16];
|
||||
|
||||
@@ -335,7 +335,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = 32.0f,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_select(&(reaktor_select_spec){
|
||||
.label = "With a symbol", .on = &s->sel_row,
|
||||
.disc = 1, .centered = 1,
|
||||
|
||||
@@ -10,7 +10,7 @@ static void
|
||||
diag_row(App *app, struct reaktor_context *ctx, const char *name,
|
||||
const char *value)
|
||||
{
|
||||
REAKTOR_ROW(.h = 24.0f, .gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_ROW(.h = 24.0f, .gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
struct reaktor_rect r;
|
||||
unsigned id;
|
||||
@@ -38,7 +38,7 @@ diag_row(App *app, struct reaktor_context *ctx, const char *name,
|
||||
|
||||
#define DIAG_ROWS(ctx) \
|
||||
REAKTOR_COLUMN(.w = reaktor_widget_bounds(ctx).w, \
|
||||
.gap = (ctx)->style.window.spacing.y)
|
||||
.gap = reaktor_item_spacing(ctx).y)
|
||||
|
||||
void
|
||||
page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
@@ -55,7 +55,7 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
"page; Pick, then a click here, finds the widget under the "
|
||||
"pointer.");
|
||||
api(app, ctx, ".inspector = { .attach = 1 } / reaktor_inspector_open");
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
int shown = reaktor_inspector_shown(app);
|
||||
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
@@ -167,6 +167,9 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
SDL_snprintf(v, sizeof(v), "%d, parsed in %.2f ms", d.sheets,
|
||||
(double)d.style_ms);
|
||||
diag_row(app, ctx, "stylesheets", v);
|
||||
SDL_snprintf(v, sizeof(v), "window %.1f ms, atlas %.1f ms, first frame at %.0f ms",
|
||||
(double)d.window_ms, (double)d.atlas_ms, (double)d.first_frame_ms);
|
||||
diag_row(app, ctx, "startup", v);
|
||||
SDL_snprintf(v, sizeof(v), "%.2fx", (double)d.scale);
|
||||
diag_row(app, ctx, "display scale", v);
|
||||
diag_row(app, ctx, "font", d.font);
|
||||
|
||||
@@ -189,16 +189,16 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
};
|
||||
int i;
|
||||
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_ROW(.h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
for (i = 0; i < 3; i++)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = edges[i], .align = (unsigned char)i,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
for (i = 0; i < 3; i++)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = tokens[i], .color = tokens[i],
|
||||
@@ -236,7 +236,7 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
static const int accent = 5;
|
||||
|
||||
REAKTOR_ROW(.h = 30.0f,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
for (k = 0; k < 8; k++)
|
||||
reaktor_icon(&(reaktor_icon_spec){
|
||||
.name = names[k],
|
||||
@@ -329,7 +329,7 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
api(app, ctx, "reaktor_list .drag / .dropped / reaktor_undo_push");
|
||||
g_lane_app = app;
|
||||
|
||||
REAKTOR_ROW(.h = 200.0f, .gap = ctx->style.window.spacing.x, .flags = REAKTOR_LAY_FILL_X) {
|
||||
REAKTOR_ROW(.h = 200.0f, .gap = reaktor_item_spacing(ctx).x, .flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = "To do", .count = g_lane_n[0], .cell = lane_cell, .user = (void *)0,
|
||||
.drag = "task", .dropped = lane_dropped, .columns = (const char *const[]){ "To do" },
|
||||
@@ -339,7 +339,7 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.drag = "task", .dropped = lane_dropped, .columns = (const char *const[]){ "Done" },
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
char undo[48], redo[48];
|
||||
|
||||
SDL_snprintf(undo, sizeof undo, "Undo %s", reaktor_undo_label(app) ? reaktor_undo_label(app) : "");
|
||||
|
||||
@@ -18,14 +18,14 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
api(app, ctx, "reaktor_field with .filter = reaktor_filter_default / _decimal / _hex");
|
||||
|
||||
{
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
.buf = s->name, .len = &s->name_len, .cap = SC_TEXT_CAP,
|
||||
.hint = "Full name", .filter = reaktor_filter_default,
|
||||
.box = { .h = 36.0f, .flags = REAKTOR_LAY_FILL_X } });
|
||||
|
||||
REAKTOR_ROW(.h = 36.0f, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
.buf = s->digits, .len = &s->digits_len,
|
||||
.cap = SC_TEXT_CAP, .hint = "Digits only",
|
||||
@@ -66,9 +66,9 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
SDL_snprintf(fv, sizeof(fv), "%.2f", (double)s->slider_f);
|
||||
SDL_snprintf(iv, sizeof(iv), "%d", s->slider_i);
|
||||
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_slider(&(reaktor_slider_spec){
|
||||
.name = "Float", .value = &s->slider_f,
|
||||
.lo = 0.0f, .hi = 1.0f, .step = 0.01f,
|
||||
@@ -78,7 +78,7 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_slider(&(reaktor_slider_spec){
|
||||
.name = "Integer", .ivalue = &s->slider_i,
|
||||
.lo = 0.0f, .hi = 100.0f, .step = 1.0f,
|
||||
@@ -88,7 +88,7 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_progress(&(reaktor_progress_spec){
|
||||
.name = "Progress", .value = &s->progress, .max = 100,
|
||||
.modifiable = 1,
|
||||
@@ -98,7 +98,7 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
}
|
||||
REAKTOR_ROW(.h = 62.0f, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_knob(&(reaktor_knob_spec){
|
||||
.name = "Knob", .value = &s->knob, .lo = 0.0f, .hi = 1.0f,
|
||||
.box = { .w = 62.0f, .h = 62.0f } });
|
||||
@@ -115,7 +115,7 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = ROW,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_property(&(reaktor_property_spec){
|
||||
.label = "Columns:", .ivalue = &s->prop_i,
|
||||
.lo = 1, .hi = 24, .step = 1, .grain = 0.25f,
|
||||
@@ -129,7 +129,7 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.lo = 0.0, .hi = 100.0, .step = 0.25, .grain = 0.05f,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
static const char *const quality[] = { "Low", "Medium", "High", "Best" };
|
||||
static const char *const days[] = { "Monday", "Tuesday", "Wednesday",
|
||||
"Thursday", "Friday", "Saturday",
|
||||
@@ -153,7 +153,7 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"wheels. Enter or OK sets the value, Escape or Cancel leaves it.");
|
||||
api(app, ctx, "reaktor_date_pick / reaktor_time_pick");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_date_pick(&(reaktor_date_spec){
|
||||
.name = "Date", .year = &s->date_y, .month = &s->date_m, .day = &s->date_d,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
@@ -176,8 +176,8 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_ROW(.h = ROW_TALL, .gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_ROW(.h = ROW_TALL, .gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
REAKTOR_COMBO(.label = sizes[s->combo_size], .name = "Size",
|
||||
.body_h = 130.0f,
|
||||
@@ -197,7 +197,7 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
s->combo_symbol = i;
|
||||
}
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW_TALL, .gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_ROW(.h = ROW_TALL, .gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
struct reaktor_color tint = reaktor_rgb_cf(s->tint);
|
||||
|
||||
@@ -245,13 +245,13 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
SDL_snprintf(line, sizeof(line), "#%02x%02x%02x", c.r, c.g, c.b);
|
||||
|
||||
REAKTOR_ROW(.h = 132.0f,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_color_pick(&(reaktor_color_spec){
|
||||
.name = "Color picker", .value = &s->tint,
|
||||
.box = { .w = 210.0f, .h = 132.0f } });
|
||||
|
||||
REAKTOR_COLUMN(.w = 210.0f,
|
||||
.gap = ctx->style.window.spacing.y) {
|
||||
.gap = reaktor_item_spacing(ctx).y) {
|
||||
reaktor_swatch(&(reaktor_swatch_spec){
|
||||
.name = "Chosen color", .fill = c,
|
||||
.box = { .h = 44.0f, .flags = REAKTOR_LAY_FILL_X } });
|
||||
|
||||
@@ -42,20 +42,20 @@ page_layout(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
api(app, ctx, "REAKTOR_ROW / REAKTOR_COLUMN / .gap");
|
||||
|
||||
{
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X)
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
.label = "one child, filling",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X)
|
||||
for (i = 0; i < 3; i++)
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
.label = "an equal share",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X)
|
||||
for (i = 0; i < 4; i++)
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
@@ -95,8 +95,8 @@ page_layout(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
static const float share[3] = { 2.0f, 5.0f, 3.0f };
|
||||
static const char *const share_lab[3] = { "20%", "50%", "30%" };
|
||||
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X)
|
||||
for (i = 0; i < 3; i++) {
|
||||
char lab[16];
|
||||
@@ -105,7 +105,7 @@ page_layout(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.label = lab, .box = { .w = w[i] } });
|
||||
}
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X)
|
||||
for (i = 0; i < 3; i++)
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
@@ -149,7 +149,7 @@ page_layout(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
api(app, ctx, ".w alone / .w with FILL_X / FILL_X alone");
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
.label = "fixed 80", .box = { .w = 80.0f } });
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
|
||||
@@ -18,7 +18,7 @@ floater_text(App *app, struct reaktor_context *ctx, const char *title,
|
||||
reaktor_style_font(app, ".popup-title", 16, 1));
|
||||
reaktor_label_colored(ctx, title, REAKTOR_TEXT_LEFT,
|
||||
reaktor_token("--text-bright",
|
||||
ctx->style.text.color));
|
||||
reaktor_text_color(ctx)));
|
||||
reaktor_style_pop_font(ctx);
|
||||
|
||||
reaktor_layout_row_dynamic(ctx, 8.0f, 1);
|
||||
@@ -28,7 +28,7 @@ floater_text(App *app, struct reaktor_context *ctx, const char *title,
|
||||
reaktor_style_push_font(ctx, reaktor_style_font(app, ".small", 13, 0));
|
||||
reaktor_label_colored_wrap(ctx, text,
|
||||
reaktor_token("--text-muted",
|
||||
ctx->style.text.color));
|
||||
reaktor_text_color(ctx)));
|
||||
reaktor_style_pop_font(ctx);
|
||||
|
||||
reaktor_layout_row_dynamic(ctx, 12.0f, 1);
|
||||
@@ -90,7 +90,7 @@ floater_demos(App *app, struct reaktor_context *ctx)
|
||||
"the page live under it.");
|
||||
api(app, ctx, "reaktor_floater_open / reaktor_floater_close");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Open a floater",
|
||||
.disabled = (unsigned char)(g_plain_floater != 0),
|
||||
@@ -170,7 +170,7 @@ window_demos(App *app, struct reaktor_context *ctx)
|
||||
"until it closes.");
|
||||
api(app, ctx, "reaktor_window_open / reaktor_window_close");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Open a window",
|
||||
.disabled = (unsigned char)(none || g_plain_win),
|
||||
@@ -187,19 +187,27 @@ window_demos(App *app, struct reaktor_context *ctx)
|
||||
static void
|
||||
tray_demo(App *app, struct reaktor_context *ctx)
|
||||
{
|
||||
static reaktor_bool hide;
|
||||
reaktor_bool on = (reaktor_bool)showcase_tray_on();
|
||||
|
||||
section(app, ctx, "Tray",
|
||||
on ? "The window's icon in the system's tray, with a menu: show "
|
||||
"the window, send a toast, pick the theme, quit."
|
||||
"the window, send a toast, pick the theme, quit. Minimizing "
|
||||
"can hide the window there instead of in the taskbar."
|
||||
: "The window's icon in the system's tray, with a menu. It is "
|
||||
"off here, or the system has no tray.");
|
||||
api(app, ctx, "reaktor_tray_open / reaktor_tray_check / reaktor_tray_close");
|
||||
api(app, ctx, "reaktor_tray_open / reaktor_tray_check / reaktor_tray_close"
|
||||
" / reaktor_tray_hide_on_minimize");
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X) {
|
||||
if (reaktor_check(&(reaktor_check_spec){ .label = "Icon in the tray",
|
||||
.on = &on }))
|
||||
showcase_tray_show(app, on);
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X) {
|
||||
if (reaktor_check(&(reaktor_check_spec){
|
||||
.label = "Minimize to the tray", .on = &hide }))
|
||||
reaktor_tray_hide_on_minimize(app, hide);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -306,7 +314,7 @@ toast_demos(App *app, struct reaktor_context *ctx)
|
||||
"own on Linux, macOS and the BSDs, the browser's on the web.");
|
||||
api(app, ctx, "reaktor_toast / reaktor_notify");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Simple toast",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }))
|
||||
@@ -321,7 +329,7 @@ toast_demos(App *app, struct reaktor_context *ctx)
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }))
|
||||
reaktor_toast(app, &g_toast_icon);
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "With custom controls",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }))
|
||||
@@ -338,7 +346,7 @@ toast_demos(App *app, struct reaktor_context *ctx)
|
||||
reaktor_toast(app, &(reaktor_toast_spec){
|
||||
.text = "This one stays until it is closed" });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "System notification",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }) &&
|
||||
@@ -359,7 +367,7 @@ print_demos(App *app, struct reaktor_context *ctx)
|
||||
"be written to a PDF file instead.");
|
||||
api(app, ctx, "reaktor_print / reaktor_print_pdf");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Print a page",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }) &&
|
||||
@@ -421,7 +429,7 @@ ask_demo(App *app, struct reaktor_context *ctx)
|
||||
"same for a call made on any other thread.");
|
||||
api(app, ctx, "reaktor_ask / reaktor_timer / reaktor_post");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Ask a question",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }))
|
||||
@@ -448,7 +456,7 @@ settings_demo(App *app, struct reaktor_context *ctx)
|
||||
if (note_len >= (int)sizeof note) note_len = (int)sizeof note - 1;
|
||||
}
|
||||
section(app, ctx, "Settings",
|
||||
"A setting is a string kept between runs in settings.conf, an INI "
|
||||
"A setting is a string kept between runs in settings.toml, a TOML "
|
||||
"file in the user's preference folder; on the web the same file "
|
||||
"lives in the browser's IndexedDB. The application picks when it is written - never, on quit, "
|
||||
"on every change or after a delay - and can save or clear it at "
|
||||
@@ -456,8 +464,8 @@ settings_demo(App *app, struct reaktor_context *ctx)
|
||||
api(app, ctx, "reaktor_setting_set / reaktor_settings_save / reaktor_settings_clear");
|
||||
|
||||
REAKTOR_COLUMN(.name = "Settings", .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X, .gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X, .gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
.buf = note, .len = ¬e_len, .cap = (int)sizeof note,
|
||||
.hint = "A note to keep", .name = "Note",
|
||||
@@ -473,7 +481,7 @@ settings_demo(App *app, struct reaktor_context *ctx)
|
||||
.box = { .w = 96 } })) {
|
||||
reaktor_settings_clear();
|
||||
note_len = 0;
|
||||
SDL_strlcpy(said, "Cleared: settings.conf is gone.", sizeof said);
|
||||
SDL_strlcpy(said, "Cleared: settings.toml is gone.", sizeof said);
|
||||
}
|
||||
}
|
||||
reaktor_label(&(reaktor_label_spec){ .text = said, .name = "Settings status",
|
||||
@@ -574,7 +582,7 @@ page_popups(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
reaktor_style_push_font(ctx, reaktor_style_font(app, ".small", 13, 0));
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
SDL_snprintf(line, sizeof(line), "last chosen: %s", s->menu_pick);
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = line,
|
||||
@@ -650,7 +658,7 @@ page_popups(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
struct reaktor_rect b;
|
||||
|
||||
REAKTOR_ROW(.h = 34.0f,
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Hover for a plain tooltip",
|
||||
.tooltip = "A one-line tooltip.",
|
||||
|
||||
@@ -57,7 +57,7 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"styling, and it is either true in front of you or it is not.");
|
||||
api(app, ctx, "external/simplecss");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
if (reaktor_check(&(reaktor_check_spec){
|
||||
.label = "Read Simple.css over the top of Water.css",
|
||||
.name = "Override stylesheet",
|
||||
@@ -74,7 +74,7 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
api(app, ctx, "the same widgets as everywhere else");
|
||||
|
||||
REAKTOR_COLUMN(.gap = 10.0f) {
|
||||
REAKTOR_ROW(.gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_ROW(.gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
.label = "A button",
|
||||
@@ -87,7 +87,7 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
}
|
||||
|
||||
REAKTOR_ROW(.gap = ctx->style.window.spacing.x,
|
||||
REAKTOR_ROW(.gap = reaktor_item_spacing(ctx).x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
.name = "Name", .hint = "a text field",
|
||||
@@ -140,7 +140,7 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"widget on Nuklear's own default.");
|
||||
api(app, ctx, "reaktor_style_init(sheets, n, theme)");
|
||||
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = "Two controls here have no rule in either sheet - a "
|
||||
"slider and a progress bar are not things a document "
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
static void
|
||||
format_row(struct reaktor_context *ctx, const char *label, const char *value)
|
||||
{
|
||||
REAKTOR_ROW(.gap = ctx->style.window.spacing.x, .flags = REAKTOR_LAY_FILL_X) {
|
||||
REAKTOR_ROW(.gap = reaktor_item_spacing(ctx).x, .flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = label, .color = "--text-muted", .box = { .w = 110.0f } });
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
@@ -36,7 +36,7 @@ page_translations_formats(struct reaktor_context *ctx)
|
||||
reaktor_trn("locale.count", 5, b, sizeof b),
|
||||
reaktor_trn("locale.count", 22, c, sizeof c));
|
||||
|
||||
REAKTOR_COLUMN(.w = 360.0f, .gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.w = 360.0f, .gap = reaktor_item_spacing(ctx).y) {
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = reaktor_tr("locale.formats"), .style = "h4",
|
||||
.color = "--text-bright", .box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
@@ -98,7 +98,7 @@ page_translations(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
REAKTOR_ROW(.gap = 40.0f, .flags = REAKTOR_LAY_WRAP) {
|
||||
REAKTOR_COLUMN(.w = SDL_min(reaktor_window_get_content_region_size(ctx).x, 640.0f),
|
||||
.gap = ctx->style.window.spacing.y) {
|
||||
.gap = reaktor_item_spacing(ctx).y) {
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = reaktor_tr("locale.title"), .style = "h4",
|
||||
.color = "--text-bright",
|
||||
|
||||
@@ -482,7 +482,7 @@ sample_option(App *app, struct reaktor_context *ctx, const char *label, float w,
|
||||
int hit;
|
||||
|
||||
if (w <= 0.0f) {
|
||||
const struct reaktor_user_font *f = ctx->style.font;
|
||||
const struct reaktor_user_font *f = reaktor_current_font(ctx);
|
||||
/* Nuklear takes the rounding out of a button's text room too. */
|
||||
w = f->width(f->userdata, f->height, label, (int)strlen(label))
|
||||
+ 2.0f * ((float)TAB_PAD_X + STRIP_ROUND);
|
||||
@@ -592,8 +592,7 @@ static void
|
||||
tray_show(App *app, int checked, void *user)
|
||||
{
|
||||
(void)checked; (void)user;
|
||||
SDL_RestoreWindow(reaktor_sdl_window(app));
|
||||
SDL_RaiseWindow(reaktor_sdl_window(app));
|
||||
reaktor_set_visible(app, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -10,7 +10,7 @@ head_and_note(App *app, struct reaktor_context *ctx, const char *title,
|
||||
const char *note)
|
||||
{
|
||||
(void)app;
|
||||
REAKTOR_COLUMN(.name = title, .gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_COLUMN(.name = title, .gap = reaktor_item_spacing(ctx).y) {
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = title, .style = "h4",
|
||||
.color = "--text-bright",
|
||||
|
||||
@@ -132,6 +132,25 @@ generated(const char *name)
|
||||
"u { border-top-left-radius: 4px 8px; }\n"
|
||||
"a { color: #ff0000; } a { color: var(--missing); }\n"
|
||||
"s { color: color-mix(in oklch, red, blue); }\n");
|
||||
} else if (strcmp(name, "gradients.css") == 0) {
|
||||
s = append(s, "a { background: linear-gradient(to right, #ff3d6e, #ff7a45); }\n"
|
||||
"b { background: linear-gradient(to left, #010101, #020202); }\n"
|
||||
"h1 { background: linear-gradient(to bottom, #0f0f0f, #101010); }\n"
|
||||
"h2 { background: linear-gradient(to middle, #0f0f0f, #101010); }\n"
|
||||
"i { background: linear-gradient(#030303, rgba(0, 0, 0, 0.5)); }\n"
|
||||
"q { background: linear-gradient(0deg, #040404, #050505); }\n"
|
||||
"u { background: linear-gradient(-90deg, #060606, #070707) #080808; }\n"
|
||||
"p { background: linear-gradient(45deg, #090909, #0a0a0a); }\n"
|
||||
"s { background: linear-gradient(to right, red, lime, blue); }\n"
|
||||
"em { background: linear-gradient(to right, red, blue); }\n"
|
||||
"em { background-color: #0b0b0b; }\n"
|
||||
"dl { background: linear-gradient(to right, red, blue); }\n"
|
||||
"dl { background: #0c0c0c; }\n"
|
||||
"dt { background-image: linear-gradient(to top, #0d0d0d, #0e0e0e); }\n"
|
||||
"dd { background: linear-gradient(red, blue); background-image: none; }\n"
|
||||
"ol { background: linear-gradient(to right, currentcolor, red); }\n");
|
||||
} else if (strcmp(name, "roles.css") == 0) {
|
||||
s = append(s, ":root { --c: #123123; }\n");
|
||||
} else if (strcmp(name, "star.css") == 0) {
|
||||
s = append(s, "* { line-height: 1.5; } h1 { font-size: 30px; }\n");
|
||||
} else if (strcmp(name, "self.css") == 0) {
|
||||
@@ -412,6 +431,8 @@ main(void)
|
||||
g = load1("themes.css", "light");
|
||||
check("the theme's own variables apply", fg("h1"), 0x00ff00);
|
||||
ok(" and :not() of the other theme", reaktor_sheet_color(g, "--d", c) && rgb(c) == 0x0000ff);
|
||||
ok("a sheet added later reaches a var() read before it",
|
||||
reaktor_sheet_add(g, "roles.css") && fg("h1") == 0x123123);
|
||||
reaktor_sheet_free(g);
|
||||
g = load1("themes.css", "dark");
|
||||
check(" the other theme's", fg("h1"), 0xff0000);
|
||||
@@ -435,5 +456,41 @@ main(void)
|
||||
ok("color-mix() outside srgb is dropped", !get("s").matched);
|
||||
reaktor_sheet_free(g);
|
||||
|
||||
g = load1("gradients.css", "light");
|
||||
s = get("a");
|
||||
check("to right runs across", s.gradient, REAKTOR_GRADIENT_ACROSS);
|
||||
check("its first stop", rgb(s.gradient_from), 0xff3d6e);
|
||||
check("its last stop", rgb(s.gradient_to), 0xff7a45);
|
||||
check("the first stop stands in for the color", rgb(s.bg), 0xff3d6e);
|
||||
s = get("b");
|
||||
ok("to left is across, turned round",
|
||||
s.gradient == REAKTOR_GRADIENT_ACROSS && rgb(s.gradient_from) == 0x020202 &&
|
||||
rgb(s.gradient_to) == 0x010101);
|
||||
s = get("h1");
|
||||
ok("to bottom runs down",
|
||||
s.gradient == REAKTOR_GRADIENT_DOWN && rgb(s.gradient_from) == 0x0f0f0f);
|
||||
check("an unknown side is not drawn", get("h2").gradient, REAKTOR_GRADIENT_NONE);
|
||||
s = get("i");
|
||||
ok("no direction runs down", s.gradient == REAKTOR_GRADIENT_DOWN);
|
||||
check("a stop keeps its alpha", s.gradient_to[3], 128);
|
||||
s = get("q");
|
||||
ok("0deg runs up", s.gradient == REAKTOR_GRADIENT_DOWN && rgb(s.gradient_from) == 0x050505);
|
||||
s = get("u");
|
||||
ok("-90deg runs to the left",
|
||||
s.gradient == REAKTOR_GRADIENT_ACROSS && rgb(s.gradient_from) == 0x070707);
|
||||
check("a color beside it is the color", rgb(s.bg), 0x080808);
|
||||
check("45deg is not drawn", get("p").gradient, REAKTOR_GRADIENT_NONE);
|
||||
check("three stops are not drawn", get("s").gradient, REAKTOR_GRADIENT_NONE);
|
||||
s = get("em");
|
||||
ok("background-color leaves the gradient",
|
||||
s.gradient == REAKTOR_GRADIENT_ACROSS && rgb(s.bg) == 0x0b0b0b);
|
||||
s = get("dl");
|
||||
ok("background resets it", s.gradient == REAKTOR_GRADIENT_NONE && rgb(s.bg) == 0x0c0c0c);
|
||||
ok("background-image sets one",
|
||||
get("dt").gradient == REAKTOR_GRADIENT_DOWN && rgb(get("dt").gradient_from) == 0x0e0e0e);
|
||||
check("background-image: none clears it", get("dd").gradient, REAKTOR_GRADIENT_NONE);
|
||||
check("currentcolor is not a stop", get("ol").gradient, REAKTOR_GRADIENT_NONE);
|
||||
reaktor_sheet_free(g);
|
||||
|
||||
return test_done("css");
|
||||
}
|
||||
|
||||
+2
-2
@@ -622,11 +622,11 @@ saved_file(int remove)
|
||||
char *dir = SDL_GetPrefPath(NULL, "launchtest"), *path = NULL, *text = NULL;
|
||||
int has = 0;
|
||||
|
||||
if (dir) SDL_asprintf(&path, "%ssettings.conf", dir);
|
||||
if (dir) SDL_asprintf(&path, "%ssettings.toml", dir);
|
||||
if (path && remove) SDL_RemovePath(path);
|
||||
else if (path) {
|
||||
text = (char *)SDL_LoadFile(path, NULL);
|
||||
has = text && SDL_strstr(text, "[launchtest]\nkey=on disk") != NULL;
|
||||
has = text && SDL_strstr(text, "\"launchtest.key\" = \"on disk\"") != NULL;
|
||||
}
|
||||
SDL_free(text);
|
||||
SDL_free(path);
|
||||
|
||||
+7
-5
@@ -2,6 +2,8 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "locale_internal.h"
|
||||
#include "test.h"
|
||||
|
||||
@@ -142,7 +144,7 @@ static void
|
||||
catalogs(void)
|
||||
{
|
||||
char buf[64];
|
||||
unsigned cps[64];
|
||||
unsigned *cps;
|
||||
int i, n, sorted = 1, dup = 0, has_s = 0, has_ko = 0, has_ni = 0,
|
||||
has_o = 0;
|
||||
|
||||
@@ -203,10 +205,9 @@ catalogs(void)
|
||||
reaktor_trn("files", 5, buf, sizeof buf),
|
||||
"%d \xE5\x80\x8B\xE3\x81\xAE\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB");
|
||||
|
||||
n = reaktor_locale_codepoints(NULL, 0);
|
||||
check("codepoints counted without a buffer",
|
||||
reaktor_locale_codepoints(cps, (int)(sizeof cps / sizeof cps[0])), n);
|
||||
for (i = 0; i < n && i < 64; i++) {
|
||||
cps = reaktor_locale_codepoints(&n);
|
||||
check("codepoints found", cps != NULL && n > 0, 1);
|
||||
for (i = 0; cps && i < n; i++) {
|
||||
if (i && cps[i] <= cps[i - 1]) { sorted = 0; dup += cps[i] == cps[i - 1]; }
|
||||
has_s |= cps[i] == 0x015B;
|
||||
has_ko |= cps[i] == 0x3053;
|
||||
@@ -219,6 +220,7 @@ catalogs(void)
|
||||
check("codepoints include hiragana ko", has_ko, 1);
|
||||
check("codepoints include the kanji in the language name", has_ni, 1);
|
||||
check("codepoints leave out Latin-1", has_o, 0);
|
||||
SDL_free(cps);
|
||||
|
||||
g_system_code = "pl";
|
||||
check("NULL follows the system", reaktor_locale_set(NULL), 1);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/* Compiled with debug types by tools/ci/check-abi.sh, which reads the layouts
|
||||
and constants an app compiles in from it. */
|
||||
#include "reaktor/reaktor.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
||||
#!/bin/sh
|
||||
# What libreaktor.so's ABI is beyond its symbols: the layout of every struct
|
||||
# an app sees (Reaktor's own, and Nuklear's through reaktor/nuklear.h, with
|
||||
# nk_window and nk_input, which apps reach through the context) and the
|
||||
# value of every constant reaktor/nuklear.h renames. gdb reads them from the
|
||||
# debug types of tools/abi/abi.c, so nothing is copied out of Nuklear. The
|
||||
# result must match tools/abi/libreaktor.so.SOVERSION-ARCH.abi, ARCH being the
|
||||
# compiler's target; a change means a new SOVERSION in CMakeLists.txt and a
|
||||
# new table, written with -u. Exit status 3: there is no table for this ARCH
|
||||
# yet, and the one written to smoke/abi/ can be checked in.
|
||||
# check-abi.sh [-u] [-c CC]
|
||||
set -eu
|
||||
# The types in one order whatever the machine's locale.
|
||||
LC_ALL=C
|
||||
export LC_ALL
|
||||
|
||||
update=0
|
||||
cc=cc
|
||||
while getopts uc: opt; do
|
||||
case $opt in
|
||||
u) update=1 ;;
|
||||
c) cc=$OPTARG ;;
|
||||
*) echo "usage: check-abi.sh [-u] [-c CC]" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
so=$(sed -n 's/.*SOVERSION \([0-9][0-9]*\).*/\1/p' CMakeLists.txt | head -n 1)
|
||||
[ -n "$so" ] || { echo "no SOVERSION in CMakeLists.txt"; exit 1; }
|
||||
arch=$("$cc" -dumpmachine | cut -d- -f1)
|
||||
table="tools/abi/libreaktor.so.$so-$arch.abi"
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
|
||||
"$cc" -g -O0 -fno-eliminate-unused-debug-types -Iinclude -Iexternal/nuklear \
|
||||
-Iexternal/nukanim -Iexternal/SDL/include -c tools/abi/abi.c -o "$work/abi.o"
|
||||
|
||||
{
|
||||
sed -n 's/^typedef \(struct\|union\|enum\) \(reaktor_[a-z0-9_]*\).*/\1 \2/p' include/reaktor/*.h |
|
||||
sort -u | while read -r kind name; do
|
||||
if [ "$kind" = enum ]; then echo "ptype enum $name"; else echo "ptype /o $name"; fi
|
||||
done
|
||||
for n in window input; do echo "ptype /o struct nk_$n"; done
|
||||
sed -n 's/^#define reaktor_[a-z0-9_]* *nk_\([a-z0-9_]*\)$/\1/p' include/reaktor/nuklear.h |
|
||||
while read -r n; do
|
||||
printf 'echo nk_%s:\\n\nptype /o struct nk_%s\nptype nk_%s\n' "$n" "$n" "$n"
|
||||
done
|
||||
sed -n 's/^#define \(REAKTOR_[A-Z0-9_]*\) *\(NK_[A-Z0-9_]*\)$/\1 \2/p' include/reaktor/nuklear.h |
|
||||
while read -r r n; do printf 'echo %s = \noutput/d %s\necho \\n\n' "$r" "$n"; done
|
||||
} >"$work/cmds.gdb"
|
||||
# One -ex each: a command file would stop at the first type that is not a
|
||||
# struct (nk_bool, say), and an -ex that fails does not stop the rest.
|
||||
set --
|
||||
while IFS= read -r c; do set -- "$@" -ex "$c"; done <"$work/cmds.gdb"
|
||||
gdb -batch -nx "$@" "$work/abi.o" >"$work/abi.txt" 2>&1 || :
|
||||
|
||||
# Kept where CI uploads it, so a table can be taken from a machine like CI's:
|
||||
# gdb's layout of the output differs a little between versions.
|
||||
mkdir -p smoke/abi
|
||||
cp "$work/abi.txt" "smoke/abi/$(basename "$table")"
|
||||
|
||||
if [ "$update" = 1 ]; then
|
||||
cp "$work/abi.txt" "$table"
|
||||
echo "wrote $table"
|
||||
elif [ ! -f "$table" ]; then
|
||||
echo "no $table yet: smoke/abi/ has it, or write it with -u"; exit 3
|
||||
elif ! diff -u "$table" "$work/abi.txt"; then
|
||||
echo "libreaktor's ABI changed: bump SOVERSION in CMakeLists.txt and run check-abi.sh -u"
|
||||
exit 1
|
||||
else
|
||||
echo "ABI matches $table"
|
||||
fi
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
# What libreaktor.so exports against what it should. tools/reaktor.map names
|
||||
# Reaktor's API and globs Nuklear's and nukanim's under LIBREAKTOR_0, and the
|
||||
# non-public calls the modules make under LIBREAKTOR_PRIVATE_0. A
|
||||
# REAKTOR_SHARED build must export exactly those, each under its version;
|
||||
# every public declaration in include/reaktor/ must be exported or come from
|
||||
# libreaktor-modules.a; every LIBREAKTOR_0 name must be declared there; every
|
||||
# private one must still be called by the modules, and by no app's own code.
|
||||
# check-exports.sh BUILD
|
||||
set -eu
|
||||
|
||||
build=$1
|
||||
so="$build/lib/libreaktor.so"
|
||||
mods="$build/lib/libreaktor-modules.a"
|
||||
for f in "$so" "$mods"; do
|
||||
if [ ! -f "$f" ]; then
|
||||
echo "no $f: build the libreaktor target first" >&2; exit 1
|
||||
fi
|
||||
done
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
fail=0
|
||||
|
||||
nm -D --defined-only "$so" | awk '$2 != "A" { print $3 }' | sort -u >"$work/versioned"
|
||||
sed 's/@.*//' "$work/versioned" | sort -u >"$work/exported"
|
||||
# Explicit names, and those in the private version.
|
||||
awk '/^ *#/ || /^}/ { next }
|
||||
/^LIBREAKTOR_[A-Z0-9_]* *\{/ { hidden = ($1 ~ /PRIVATE/); next }
|
||||
/;/ { n = split($0, w, /[ ;]+/)
|
||||
for (k = 1; k <= n; k++) if (w[k] != "" && w[k] !~ /[*:{}]/) print w[k] (hidden ? " hidden" : "") }' \
|
||||
tools/reaktor.map >"$work/map"
|
||||
awk '{ print $1 }' "$work/map" | sort -u >"$work/named"
|
||||
awk '$2 == "hidden" { print $1 }' "$work/map" | sort -u >"$work/hidden"
|
||||
grep -h -o -E '\breaktor_[a-z0-9_]+ *\(' include/reaktor/*.h | sed 's/ *($//' | sort -u >"$work/public"
|
||||
nm --defined-only "$mods" 2>/dev/null | awk '$2 ~ /[TDBR]/ { print $3 }' | sort -u >"$work/modules"
|
||||
nm -u "$mods" 2>/dev/null | awk '{ print $2 }' | sort -u >"$work/called"
|
||||
# The apps' own objects (not their modules') in every program linked to it.
|
||||
for f in "$build"/*; do
|
||||
[ -f "$f" ] && [ -x "$f" ] || continue
|
||||
readelf -d "$f" 2>/dev/null | grep -q 'NEEDED.*\[libreaktor\.so\.' || continue
|
||||
find "$build/CMakeFiles/$(basename "$f").dir" \( -path '*/samples/*' -o -path '*/tests/*' \) \
|
||||
-name '*.o' -exec nm -u {} + 2>/dev/null | awk '{ print $2 }'
|
||||
done | sort -u >"$work/appcalls"
|
||||
|
||||
report() {
|
||||
if [ -s "$work/$1" ]; then
|
||||
echo "$2:"; sed 's/^/ /' "$work/$1"; fail=1
|
||||
fi
|
||||
}
|
||||
comm -23 "$work/named" "$work/exported" >"$work/stale"
|
||||
report stale "named in tools/reaktor.map but not exported (gone, or a typo)"
|
||||
grep -v -E '^(nk_|nka_)' "$work/exported" | comm -23 - "$work/named" >"$work/extra"
|
||||
report extra "exported but not named in tools/reaktor.map"
|
||||
comm -23 "$work/public" "$work/exported" | comm -23 - "$work/modules" >"$work/missing"
|
||||
report missing "declared in include/reaktor/ but neither exported nor in the modules"
|
||||
grep '^reaktor_' "$work/named" | comm -23 - "$work/public" | comm -23 - "$work/hidden" >"$work/leak"
|
||||
report leak "under LIBREAKTOR_0 but not declared in include/reaktor/"
|
||||
comm -23 "$work/hidden" "$work/called" >"$work/unused"
|
||||
report unused "under LIBREAKTOR_PRIVATE_0 but no module calls them"
|
||||
comm -12 "$work/hidden" "$work/appcalls" >"$work/reached"
|
||||
report reached "private, but an app's own code calls them"
|
||||
awk -F'@@?' 'NR == FNR { if ($0 !~ /^(nk_|nka_)/) { split($0, h, " "); priv[h[1]] = (h[2] == "hidden") }; next }
|
||||
NF > 1 && ($1 in priv) && ($2 != (priv[$1] ? "LIBREAKTOR_PRIVATE_0" : "LIBREAKTOR_0")) { print $0 }' \
|
||||
"$work/map" "$work/versioned" >"$work/version"
|
||||
report version "exported under the wrong version"
|
||||
|
||||
[ "$fail" = 0 ] && echo "exports match tools/reaktor.map ($(wc -l <"$work/exported") symbols)"
|
||||
exit "$fail"
|
||||
@@ -1,7 +1,9 @@
|
||||
#!/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.
|
||||
# leaves dist/NAME.tar.gz. Where the install has libreaktor.so or
|
||||
# Reaktor.framework (a REAKTOR_SHARED build), the consumer is linked against
|
||||
# that too, and must draw the same.
|
||||
# check-libreaktor.sh [-i] [-w WRAP] BUILD NAME
|
||||
# -i: dist/NAME is installed already (a cross build ships it).
|
||||
set -eu
|
||||
@@ -21,19 +23,43 @@ name=$2
|
||||
|
||||
if [ "$installed" = 0 ]; then
|
||||
cmake --build "$build" --target libreaktor </dev/null
|
||||
cmake --install "$build" --prefix "dist/$name" --component libreaktor </dev/null
|
||||
cmake --install "$build" --prefix "dist/$name" --component libreaktor --strip </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
|
||||
runs="lib-built $build/simple
|
||||
lib-linked build-consumer/simple"
|
||||
if ls "dist/$name"/lib/libreaktor.so* >/dev/null 2>&1 || [ -d "dist/$name/Frameworks/Reaktor.framework" ]; then
|
||||
cmake -S examples/consumer -B build-consumer-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" -DCONSUMER_SHARED=ON </dev/null
|
||||
cmake --build build-consumer-shared </dev/null
|
||||
if command -v otool >/dev/null 2>&1; then
|
||||
otool -L build-consumer-shared/simple | grep -q 'Reaktor\.framework/'
|
||||
else
|
||||
readelf -d build-consumer-shared/simple | grep -q 'NEEDED.*\[libreaktor\.so\.'
|
||||
fi || { echo "the shared consumer does not link the shared libreaktor"; exit 1; }
|
||||
runs="$runs
|
||||
lib-shared build-consumer-shared/simple"
|
||||
fi
|
||||
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
|
||||
echo "$runs" | while read -r out app; do
|
||||
set -- --theme light --video dummy --shot "check/$out.bmp" --a11y-dump "check/$out.txt"
|
||||
rc=0
|
||||
$wrap "$app" "$@" </dev/null || rc=$?
|
||||
if [ "$rc" != 0 ]; then
|
||||
# Where it died, before giving up on it.
|
||||
if command -v lldb >/dev/null 2>&1; then
|
||||
$wrap lldb --batch -o run -o "bt all" -- "$app" "$@" </dev/null || :
|
||||
elif command -v gdb >/dev/null 2>&1; then
|
||||
$wrap gdb -batch -ex run -ex "thread apply all bt" --args "$app" "$@" </dev/null || :
|
||||
fi
|
||||
echo "$out: $app exited with status $rc"; exit "$rc"
|
||||
fi
|
||||
done
|
||||
for e in bmp txt; do
|
||||
cmp "check/lib-built.$e" "check/lib-linked.$e"
|
||||
if [ -f "check/lib-shared.$e" ]; then cmp "check/lib-built.$e" "check/lib-shared.$e"; fi
|
||||
done
|
||||
tar -C dist -czf "dist/$name.tar.gz" "$name"
|
||||
rm -rf "dist/$name" build-consumer
|
||||
rm -rf "dist/$name" build-consumer build-consumer-shared
|
||||
|
||||
Executable
+174
@@ -0,0 +1,174 @@
|
||||
#!/bin/sh
|
||||
# pss.sh counted all of a binary's clean pages as library. This counts only
|
||||
# the resident pages that hold libreaktor's and SDL's own code and data:
|
||||
# builds showcase, notepad and simple with linker maps into build-map, runs
|
||||
# them together, idle, and sorts each resident, file-backed page of each
|
||||
# binary by the map. A page shared with an app object, a module or the C
|
||||
# runtime is not counted. Ten launches, medians.
|
||||
# pss-pages.sh [-x XVFB] [-w WRAP] [-n RUNS]
|
||||
set -u
|
||||
|
||||
xvfb=""
|
||||
wrap=""
|
||||
runs=10
|
||||
while getopts x:w:n: opt; do
|
||||
case $opt in
|
||||
x) xvfb=$OPTARG ;;
|
||||
w) wrap=$OPTARG ;;
|
||||
n) runs=$OPTARG ;;
|
||||
*) echo "usage: pss-pages.sh [-x XVFB] [-w WRAP] [-n RUNS]" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
apps="showcase notepad simple"
|
||||
build=$PWD/build-map
|
||||
out=smoke/pss-pages
|
||||
|
||||
mkdir -p "$build/maps" "$out"
|
||||
# A directory given to -Map gets one OUTPUT.map per program (binutils 2.38).
|
||||
cmake -S . -B "$build" -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
"-DCMAKE_EXE_LINKER_FLAGS=-Wl,-Map=$build/maps/" </dev/null >"$out/configure.log" 2>&1 ||
|
||||
{ cat "$out/configure.log"; exit 1; }
|
||||
for a in $apps; do
|
||||
cmake --build "$build" --target "$a" </dev/null >"$out/build-$a.log" 2>&1 ||
|
||||
{ tail -50 "$out/build-$a.log"; exit 1; }
|
||||
[ -s "$build/maps/$a.map" ] || { echo "no map for $a"; ls "$build/maps"; exit 1; }
|
||||
done
|
||||
|
||||
# Page owners from the map: lib (an archive member outside the system), app
|
||||
# (the program's own objects and the modules compiled into it), other.
|
||||
# A page with more than one kind of owner is "mixed" and not counted.
|
||||
for a in $apps; do
|
||||
awk '
|
||||
function hex(s, v, i) {
|
||||
v = 0
|
||||
for (i = 3; i <= length(s); i++) v = v * 16 + index("0123456789abcdef", substr(s, i, 1)) - 1
|
||||
return v
|
||||
}
|
||||
/^Linker script and memory map/ { on = 1; next }
|
||||
!on { next }
|
||||
/^[ ]*\*fill\*/ { next }
|
||||
{
|
||||
n = 0
|
||||
for (i = 1; i <= NF; i++) if ($i ~ /^0x[0-9a-f]+$/) { h[++n] = $i; at = i }
|
||||
if (n < 2 || at == NF) next
|
||||
file = $(at + 1)
|
||||
if (file ~ /^\/usr\// || file ~ /^\/lib/) kind = "other"
|
||||
else if (file ~ /\.a\(/) kind = "lib"
|
||||
else if (file ~ /\.dir\//) kind = "app"
|
||||
else kind = "other"
|
||||
start = hex(h[n - 1]); size = hex(h[n])
|
||||
if (size == 0 || start == 0) next
|
||||
for (p = int(start / 4096); p <= int((start + size - 1) / 4096); p++) {
|
||||
if (!(p in own)) own[p] = kind
|
||||
else if (own[p] != kind) own[p] = "mixed"
|
||||
}
|
||||
}
|
||||
END { for (p in own) print p, own[p] }' "$build/maps/$a.map" >"$out/$a.owners"
|
||||
done
|
||||
|
||||
if [ -n "$xvfb" ]; then
|
||||
"$xvfb" :97 -screen 0 1280x1024x24 -nolisten tcp </dev/null >"$out/xvfb.log" 2>&1 &
|
||||
xvfb_pid=$!
|
||||
trap 'kill "$xvfb_pid" 2>/dev/null || :' EXIT
|
||||
n=0
|
||||
while [ ! -S /tmp/.X11-unix/X97 ]; do
|
||||
n=$((n + 1))
|
||||
if [ "$n" -gt 120 ] || ! kill -0 "$xvfb_pid" 2>/dev/null; then
|
||||
echo "Xvfb did not start"; cat "$out/xvfb.log" || :; exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
DISPLAY=:97
|
||||
export DISPLAY
|
||||
fi
|
||||
|
||||
find_app() {
|
||||
for d in /proc/[0-9]*; do
|
||||
[ "$(readlink "$d/exe" 2>/dev/null)" = "$1" ] && echo "${d#/proc/}"
|
||||
done
|
||||
}
|
||||
|
||||
# Prints the binary's resident, file-backed pages as page numbers of the
|
||||
# linked image: its mappings, less the load base, read from pagemap.
|
||||
pages() {
|
||||
pid=$1 exe=$2
|
||||
vaddr=$(readelf -lW "$exe" | awk '$1 == "LOAD" { print $3; exit }')
|
||||
awk -v exe="$exe" '$NF == exe { print $1, $3 }' "/proc/$pid/maps" |
|
||||
while read -r range off; do
|
||||
echo "$((0x${range%-*})) $((0x${range#*-}))"
|
||||
done >"$out/ranges"
|
||||
base=$(awk 'NR == 1 { print $1 }' "$out/ranges")
|
||||
base=$((base - (vaddr & ~4095)))
|
||||
while read -r lo hi; do
|
||||
# dd seeks; od would skip by reading the whole table below the binary.
|
||||
dd if="/proc/$pid/pagemap" bs=65536 iflag=skip_bytes,count_bytes skip=$((lo / 4096 * 8)) count=$(((hi - lo) / 4096 * 8)) 2>/dev/null |
|
||||
od -An -v -t x8 -w8 |
|
||||
awk -v first=$(((lo - base) / 4096)) '
|
||||
{ d = substr($1, 1, 1) }
|
||||
d == "a" || d == "b" || d == "e" || d == "f" { print first + NR - 1 }'
|
||||
done <"$out/ranges"
|
||||
}
|
||||
|
||||
rows=$out/runs.txt
|
||||
: >"$rows"
|
||||
i=0
|
||||
retries=0
|
||||
while [ "$i" -lt "$runs" ]; do
|
||||
i=$((i + 1))
|
||||
pids=""
|
||||
missing=""
|
||||
for a in $apps; do
|
||||
$wrap "$build/$a" </dev/null >"$out/$a.log" 2>&1 &
|
||||
pids="$pids $!"
|
||||
done
|
||||
sleep 10
|
||||
row=""
|
||||
found=""
|
||||
for a in $apps; do
|
||||
pid=$(find_app "$build/$a")
|
||||
if [ -z "$pid" ]; then missing=$a; break; fi
|
||||
found="$found $pid"
|
||||
pss=$(awk '/^Pss:/ { print $2 }' "/proc/$pid/smaps_rollup")
|
||||
pages "$pid" "$build/$a" >"$out/$a.present"
|
||||
counts=$(awk 'NR == FNR { own[$1] = $2; next }
|
||||
{ k = ($1 in own) ? own[$1] : "other"; c[k]++ }
|
||||
END { printf "%d %d %d %d", c["lib"] * 4, c["app"] * 4, c["mixed"] * 4, c["other"] * 4 }' \
|
||||
"$out/$a.owners" "$out/$a.present")
|
||||
row="$row $pss $counts"
|
||||
done
|
||||
# An app that quit early (a stray click or key on a live desktop does it)
|
||||
# costs that run, not the measurement: say why, and launch the run again.
|
||||
if [ -n "$missing" ]; then
|
||||
echo "run $i: $missing is not running; its log:"
|
||||
cat "$out/$missing.log" 2>/dev/null
|
||||
kill $pids 2>/dev/null || :
|
||||
for p in $pids; do wait "$p"; echo " pid $p ended with status $?"; done
|
||||
retries=$((retries + 1))
|
||||
if [ "$retries" -gt 3 ]; then echo "giving up after $retries lost runs"; exit 1; fi
|
||||
i=$((i - 1))
|
||||
continue
|
||||
fi
|
||||
echo "$row" >>"$rows"
|
||||
echo "run $i:$row"
|
||||
kill $found 2>/dev/null || :
|
||||
for p in $pids; do wait "$p" 2>/dev/null || :; done
|
||||
done
|
||||
|
||||
median() { sort -n | awk '{ v[NR] = $1 } END { print (NR % 2) ? v[(NR + 1) / 2] : (v[NR / 2] + v[NR / 2 + 1]) / 2 }'; }
|
||||
col() { awk -v c="$1" '{ print $c }' "$rows" | median; }
|
||||
|
||||
echo
|
||||
printf '%-9s %9s %9s %9s %9s %9s\n' app 'PSS kB' 'lib kB' 'app kB' 'mixed kB' 'other kB'
|
||||
c=1
|
||||
for a in $apps; do
|
||||
printf '%-9s %9s %9s %9s %9s %9s\n' "$a" "$(col $c)" "$(col $((c + 1)))" \
|
||||
"$(col $((c + 2)))" "$(col $((c + 3)))" "$(col $((c + 4)))"
|
||||
c=$((c + 5))
|
||||
done
|
||||
awk '{ p = $1 + $6 + $11; l = $2 + $7 + $12; m = $2
|
||||
if ($7 > m) m = $7; if ($12 > m) m = $12
|
||||
print p, l - m, 100 * (l - m) / p }' "$rows" >"$out/saving.txt"
|
||||
echo
|
||||
echo "summed PSS: $(awk '{ print $1 }' "$out/saving.txt" | median) kB"
|
||||
echo "shared saves: $(awk '{ print $2 }' "$out/saving.txt" | median) kB"
|
||||
echo "saving: $(awk '{ print $3 }' "$out/saving.txt" | median)% (go at 20%)"
|
||||
Executable
+116
@@ -0,0 +1,116 @@
|
||||
#!/bin/sh
|
||||
# What a shared libreaktor would save: runs showcase, notepad and simple
|
||||
# together, idle, and reads each one's PSS and the clean pages of its own
|
||||
# binary, which are roughly libreaktor's resident code. Ten launches, medians.
|
||||
# pss.sh [-x XVFB] [-w WRAP] [-n RUNS] [-a "APP..."] BUILD
|
||||
# The estimate assumes the three apps would map one copy of the largest
|
||||
# binary's code: saved = sum(binary) - max(binary). App-specific code is
|
||||
# counted as library code, so the saving is an upper bound.
|
||||
set -u
|
||||
|
||||
xvfb=""
|
||||
wrap=""
|
||||
runs=10
|
||||
apps="showcase notepad simple"
|
||||
while getopts x:w:n:a: opt; do
|
||||
case $opt in
|
||||
x) xvfb=$OPTARG ;;
|
||||
w) wrap=$OPTARG ;;
|
||||
n) runs=$OPTARG ;;
|
||||
a) apps=$OPTARG ;;
|
||||
*) echo "usage: pss.sh [-x XVFB] [-w WRAP] [-n RUNS] [-a \"APP...\"] BUILD" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
build=$(cd "$1" && pwd)
|
||||
|
||||
mkdir -p smoke/pss
|
||||
if [ -n "$xvfb" ]; then
|
||||
"$xvfb" :98 -screen 0 1280x1024x24 -nolisten tcp </dev/null >smoke/pss/xvfb.log 2>&1 &
|
||||
xvfb_pid=$!
|
||||
trap 'kill "$xvfb_pid" 2>/dev/null || :' EXIT
|
||||
n=0
|
||||
while [ ! -S /tmp/.X11-unix/X98 ]; do
|
||||
n=$((n + 1))
|
||||
if [ "$n" -gt 120 ] || ! kill -0 "$xvfb_pid" 2>/dev/null; then
|
||||
echo "Xvfb did not start"; cat smoke/pss/xvfb.log || :; exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
DISPLAY=:98
|
||||
export DISPLAY
|
||||
fi
|
||||
|
||||
# kB of PSS for the whole process, and of clean pages mapped from its binary.
|
||||
measure() {
|
||||
pss=$(awk '/^Pss:/ { print $2 }' "/proc/$1/smaps_rollup")
|
||||
bin=$(awk -v exe="$2" '
|
||||
/^[0-9a-f]+-[0-9a-f]+ / { mine = ($NF == exe) }
|
||||
mine && /^(Shared|Private)_Clean:/ { kb += $2 }
|
||||
END { print kb + 0 }' "/proc/$1/smaps")
|
||||
echo "$pss $bin"
|
||||
}
|
||||
|
||||
# Under a wrapper the app is not the child, so it is found by its binary.
|
||||
find_app() {
|
||||
for d in /proc/[0-9]*; do
|
||||
[ "$(readlink "$d/exe" 2>/dev/null)" = "$1" ] && echo "${d#/proc/}"
|
||||
done
|
||||
}
|
||||
|
||||
rows=smoke/pss/runs.txt
|
||||
: >"$rows"
|
||||
i=0
|
||||
retries=0
|
||||
while [ "$i" -lt "$runs" ]; do
|
||||
i=$((i + 1))
|
||||
pids=""
|
||||
missing=""
|
||||
for a in $apps; do
|
||||
$wrap "$build/$a" </dev/null >"smoke/pss/$a.log" 2>&1 &
|
||||
pids="$pids $!"
|
||||
done
|
||||
sleep 10
|
||||
row=""
|
||||
found=""
|
||||
for a in $apps; do
|
||||
pid=$(find_app "$build/$a")
|
||||
if [ -z "$pid" ]; then missing=$a; break; fi
|
||||
found="$found $pid"
|
||||
row="$row $(measure "$pid" "$build/$a")"
|
||||
done
|
||||
# An app that quit early (a stray click or key on a live desktop does it)
|
||||
# costs that run, not the measurement: say why, and launch the run again.
|
||||
if [ -n "$missing" ]; then
|
||||
echo "run $i: $missing is not running; its log:"
|
||||
cat "smoke/pss/$missing.log" 2>/dev/null
|
||||
kill $pids 2>/dev/null || :
|
||||
for p in $pids; do wait "$p"; echo " pid $p ended with status $?"; done
|
||||
retries=$((retries + 1))
|
||||
if [ "$retries" -gt 3 ]; then echo "giving up after $retries lost runs"; exit 1; fi
|
||||
i=$((i - 1))
|
||||
continue
|
||||
fi
|
||||
echo "$row" >>"$rows"
|
||||
echo "run $i:$row"
|
||||
kill $found 2>/dev/null || :
|
||||
for p in $pids; do wait "$p" 2>/dev/null || :; done
|
||||
done
|
||||
|
||||
median() { sort -n | awk '{ v[NR] = $1 } END { print (NR % 2) ? v[(NR + 1) / 2] : (v[NR / 2] + v[NR / 2 + 1]) / 2 }'; }
|
||||
col() { awk -v c="$1" '{ print $c }' "$rows" | median; }
|
||||
|
||||
echo
|
||||
printf '%-9s %10s %14s\n' app 'PSS kB' 'binary kB'
|
||||
c=1
|
||||
for a in $apps; do
|
||||
printf '%-9s %10s %14s\n' "$a" "$(col $c)" "$(col $((c + 1)))"
|
||||
c=$((c + 2))
|
||||
done
|
||||
awk '{ p = b = m = 0
|
||||
for (k = 1; k < NF; k += 2) { p += $k; b += $(k + 1); if ($(k + 1) > m) m = $(k + 1) }
|
||||
print p, b - m, 100 * (b - m) / p }' "$rows" >smoke/pss/saving.txt
|
||||
echo
|
||||
echo "summed PSS: $(awk '{ print $1 }' smoke/pss/saving.txt | median) kB"
|
||||
echo "shared saves: $(awk '{ print $2 }' smoke/pss/saving.txt | median) kB"
|
||||
echo "saving: $(awk '{ print $3 }' smoke/pss/saving.txt | median)% (go at 20%)"
|
||||
+14
-4
@@ -38,10 +38,20 @@ freebsd)
|
||||
[ "$(find "$tmp/pkgs" -name '*.pkg' | wc -l)" -gt 0 ] || { echo "no packages were fetched" >&2; exit 1; }
|
||||
;;
|
||||
netbsd)
|
||||
# The CDN drops a request now and then, and ftp -V says nothing when it does.
|
||||
get() {
|
||||
n=1
|
||||
until ftp -V -o "$1" "$2"; do
|
||||
[ "$n" -lt 4 ] || { echo "sysroot: could not fetch $2" >&2; return 1; }
|
||||
n=$((n + 1))
|
||||
echo "sysroot: $2 failed, try $n of 4" >&2
|
||||
sleep 10
|
||||
done
|
||||
}
|
||||
url="https://cdn.NetBSD.org/pub/NetBSD/NetBSD-$version/evbarm-aarch64/binary/sets"
|
||||
ftp -V -o "$tmp/SHA512" "$url/SHA512"
|
||||
get "$tmp/SHA512" "$url/SHA512"
|
||||
for set in base comp xbase xcomp; do
|
||||
ftp -V -o "$tmp/$set.tar.xz" "$url/$set.tar.xz"
|
||||
get "$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; }
|
||||
@@ -59,7 +69,7 @@ netbsd)
|
||||
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"
|
||||
get "$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 '
|
||||
@@ -79,7 +89,7 @@ netbsd)
|
||||
}
|
||||
}' > "$tmp/pkgs/list"
|
||||
while IFS= read -r f; do
|
||||
ftp -V -o "$tmp/pkgs/$f" "$repo/$f"
|
||||
get "$tmp/pkgs/$f" "$repo/$f"
|
||||
done < "$tmp/pkgs/list"
|
||||
mkdir -p "$dir/var/db/pkg"
|
||||
while IFS= read -r f; do
|
||||
|
||||
+188
-99
@@ -5,8 +5,9 @@ set -eu
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
usage: libreaktor-pkg.sh [-i] [-b BUILD] [-p PREFIX] [-o DIR] [-f FORMAT] [-m MAINTAINER] [-a ARCH]
|
||||
usage: libreaktor-pkg.sh [-i] [-s] [-b BUILD] [-p PREFIX] [-o DIR] [-f FORMAT] [-m MAINTAINER] [-a ARCH]
|
||||
-i install the package once it is built (through sudo or doas)
|
||||
-s build libreaktor.so too, and split the package in three (Linux and the BSDs)
|
||||
-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)
|
||||
@@ -25,10 +26,12 @@ format=""
|
||||
maintainer="Reaktor <reaktor@invalid>"
|
||||
build=""
|
||||
debarch=""
|
||||
shared=OFF
|
||||
|
||||
while getopts ib:p:o:f:m:a:h opt; do
|
||||
while getopts isb:p:o:f:m:a:h opt; do
|
||||
case $opt in
|
||||
i) install=1 ;;
|
||||
s) shared=ON ;;
|
||||
b) build=$OPTARG ;;
|
||||
p) prefix=$OPTARG ;;
|
||||
o) out=$OPTARG ;;
|
||||
@@ -76,14 +79,15 @@ if [ -z "$build" ]; then
|
||||
if command -v ninja >/dev/null 2>&1; then gen="-G Ninja"; else gen=""; fi
|
||||
# shellcheck disable=SC2086
|
||||
cmake -S "$root" -B "$build" $gen -DCMAKE_BUILD_TYPE=Release \
|
||||
-DREAKTOR_SAMPLES=OFF -DREAKTOR_TESTS=OFF
|
||||
-DREAKTOR_SAMPLES=OFF -DREAKTOR_TESTS=OFF -DREAKTOR_SHARED=$shared
|
||||
fi
|
||||
cmake --build "$build" --parallel "$ncpu" --target libreaktor
|
||||
rm -rf "$stage"
|
||||
DESTDIR="$stage" cmake --install "$build" --component libreaktor --prefix "$prefix"
|
||||
# --strip reaches the shared libraries only; the archives are installed as files.
|
||||
DESTDIR="$stage" cmake --install "$build" --component libreaktor --prefix "$prefix" --strip
|
||||
|
||||
listing() {
|
||||
(cd "$stage$prefix" &&
|
||||
(cd "$1$prefix" &&
|
||||
find . -type d ! -name . | sed 's|^\./||; s|$|/|' | sort
|
||||
find . ! -type d | sed 's|^\./||' | sort)
|
||||
}
|
||||
@@ -94,103 +98,188 @@ as_root() {
|
||||
else doas "$@"; fi
|
||||
}
|
||||
|
||||
case $format in
|
||||
deb)
|
||||
arch=${debarch:-$(dpkg --print-architecture)}
|
||||
pkg="$out/libreaktor-dev_${version}_$arch.deb"
|
||||
mkdir -p "$stage/DEBIAN"
|
||||
cat >"$stage/DEBIAN/control" <<EOF
|
||||
Package: libreaktor-dev
|
||||
Version: $version
|
||||
Architecture: $arch
|
||||
Maintainer: $maintainer
|
||||
Section: libdevel
|
||||
Priority: optional
|
||||
Homepage: $www
|
||||
Description: $summary
|
||||
EOF
|
||||
dpkg-deb --root-owner-group --build "$stage" "$pkg"
|
||||
rm -rf "$stage/DEBIAN"
|
||||
[ $install -eq 0 ] || as_root dpkg -i "$pkg"
|
||||
;;
|
||||
rpm)
|
||||
top="$work/rpm"
|
||||
rm -rf "$top"
|
||||
mkdir -p "$top/SPECS"
|
||||
cat >"$top/SPECS/libreaktor.spec" <<EOF
|
||||
Name: libreaktor-devel
|
||||
Version: $version
|
||||
Release: 1
|
||||
Summary: $summary
|
||||
License: MIT
|
||||
URL: $www
|
||||
AutoReqProv: no
|
||||
# A static build packs one package, libreaktor. A REAKTOR_SHARED build packs
|
||||
# three, the development one libreaktor-shared. Those two install the same
|
||||
# headers, so each conflicts with the other: a Conflicts line, @conflict in
|
||||
# OpenBSD's packing list, -C for NetBSD's pkg_create. FreeBSD's pkg fails on a
|
||||
# manifest conflict with a package that is not installed, and refuses a second
|
||||
# owner of a file anyway.
|
||||
static=libreaktor
|
||||
dev=libreaktor-shared
|
||||
# The runtime packages carry the SOVERSION, as Debian's do. OpenBSD reads a
|
||||
# package name's version from its first dash followed by a digit, so there
|
||||
# the SDL one has no dash before its 0.
|
||||
lib=libreaktor0
|
||||
sdl=libreaktor-sdl3-0
|
||||
[ "$format" = openbsd ] && sdl=libreaktor-sdl3
|
||||
conflicts=""
|
||||
|
||||
%description
|
||||
$summary.
|
||||
# pack NAME ROOT SUMMARY [DEPENDENCY...]: one package of the files under ROOT.
|
||||
pack() {
|
||||
name=$1 root=$2 what=$3
|
||||
shift 3
|
||||
case $format in
|
||||
deb)
|
||||
arch=${debarch:-$(dpkg --print-architecture)}
|
||||
pkg="$out/${name}_${version}_$arch.deb"
|
||||
mkdir -p "$root/DEBIAN"
|
||||
deps=""
|
||||
for d in "$@"; do deps="${deps:+$deps, }$d (= $version)"; done
|
||||
{
|
||||
echo "Package: $name"
|
||||
echo "Version: $version"
|
||||
echo "Architecture: $arch"
|
||||
echo "Maintainer: $maintainer"
|
||||
case $name in "$dev"|"$static") echo "Section: libdevel" ;; *) echo "Section: libs" ;; esac
|
||||
echo "Priority: optional"
|
||||
echo "Homepage: $www"
|
||||
[ -z "$deps" ] || echo "Depends: $deps"
|
||||
[ -z "$conflicts" ] || echo "Conflicts: $conflicts"
|
||||
echo "Description: $what"
|
||||
} >"$root/DEBIAN/control"
|
||||
dpkg-deb --root-owner-group --build "$root" "$pkg"
|
||||
rm -rf "$root/DEBIAN"
|
||||
;;
|
||||
rpm)
|
||||
top="$work/rpm-$name"
|
||||
rm -rf "$top"
|
||||
mkdir -p "$top/SPECS"
|
||||
{
|
||||
echo "Name: $name"
|
||||
echo "Version: $version"
|
||||
echo "Release: 1"
|
||||
echo "Summary: $what"
|
||||
echo "License: MIT"
|
||||
echo "URL: $www"
|
||||
echo "AutoReqProv: no"
|
||||
for d in "$@"; do echo "Requires: $d = $version-1"; done
|
||||
[ -z "$conflicts" ] || echo "Conflicts: $conflicts"
|
||||
echo
|
||||
echo "%description"
|
||||
echo "$what."
|
||||
echo
|
||||
echo "%install"
|
||||
echo "cp -a \"$root/.\" %{buildroot}/"
|
||||
echo
|
||||
echo "%files"
|
||||
# Split packages share directories, so each lists only its files.
|
||||
if [ "$split" = 0 ]; then echo "$prefix"
|
||||
else listing "$root" | grep -v '/$' | sed "s|^|$prefix/|"; fi
|
||||
} >"$top/SPECS/$name.spec"
|
||||
rpmbuild -bb --define "_topdir $top" --define "debug_package %{nil}" \
|
||||
--define "__os_install_post %{nil}" "$top/SPECS/$name.spec"
|
||||
pkg=$(find "$top/RPMS" -name '*.rpm' | head -n 1)
|
||||
cp "$pkg" "$out/"
|
||||
pkg="$out/$(basename "$pkg")"
|
||||
;;
|
||||
freebsd)
|
||||
{
|
||||
echo "name: $name"
|
||||
echo "version: \"$version\""
|
||||
echo "origin: devel/$name"
|
||||
echo "comment: \"$comment\""
|
||||
echo "desc: \"$what\""
|
||||
echo "maintainer: \"$maintainer\""
|
||||
echo "www: \"$www\""
|
||||
echo "prefix: \"$prefix\""
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "deps: {"
|
||||
for d in "$@"; do echo " $d: { origin: \"devel/$d\", version: \"$version\" }"; done
|
||||
echo "}"
|
||||
fi
|
||||
} >"$work/manifest"
|
||||
listing "$root" | grep -v '/$' >"$work/plist"
|
||||
pkg create -M "$work/manifest" -p "$work/plist" -r "$root" -o "$out"
|
||||
pkg="$out/$name-$version.pkg"
|
||||
;;
|
||||
openbsd)
|
||||
{
|
||||
[ -z "$conflicts" ] || echo "@conflict $conflicts-*"
|
||||
listing "$root"
|
||||
} >"$work/plist"
|
||||
pkg="$out/$name-$version.tgz"
|
||||
deps=""
|
||||
for d in "$@"; do deps="$deps -P devel/$d:$d-$version:$d-$version"; done
|
||||
# shellcheck disable=SC2086
|
||||
pkg_create -A "$(arch -s)" -B "$root" -p "$prefix" -f "$work/plist" \
|
||||
-D COMMENT="$comment" -D FULLPKGPATH="devel/$name" \
|
||||
-D HOMEPAGE="$www" -D MAINTAINER="$maintainer" \
|
||||
-d "-$what." $deps "$pkg"
|
||||
;;
|
||||
netbsd)
|
||||
listing "$root" | grep -v '/$' >"$work/plist"
|
||||
{
|
||||
echo "MACHINE_ARCH=$(uname -p)"
|
||||
echo "OPSYS=NetBSD"
|
||||
echo "OS_VERSION=$(uname -r)"
|
||||
echo "PKGTOOLS_VERSION=$(pkg_info -V)"
|
||||
} >"$work/build-info"
|
||||
pkg="$out/$name-$version.tgz"
|
||||
deps=""
|
||||
for d in "$@"; do deps="$deps -P $d>=$version"; done
|
||||
[ -z "$conflicts" ] || deps="$deps -C $conflicts-[0-9]*"
|
||||
# Unquoted for the splitting, with globbing off for the -C pattern.
|
||||
# shellcheck disable=SC2086
|
||||
set -f
|
||||
pkg_create -B "$work/build-info" -c "-$comment" -d "-$what." \
|
||||
-f "$work/plist" -I "$prefix" -p "$root$prefix" $deps "$pkg"
|
||||
set +f
|
||||
;;
|
||||
tar)
|
||||
pkg="$out/$name-$version-$(uname -s | tr 'A-Z' 'a-z')-$(uname -m).tar.gz"
|
||||
tar -C "$root" -czf "$pkg" .
|
||||
;;
|
||||
*)
|
||||
echo "libreaktor-pkg.sh: unknown format: $format" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
echo "packed: $pkg"
|
||||
packed="$packed $pkg"
|
||||
}
|
||||
|
||||
%install
|
||||
cp -a "$stage/." %{buildroot}/
|
||||
# A REAKTOR_SHARED build splits in three, so an app can install the libraries
|
||||
# alone: libreaktor-sdl3-0 (our SDL), libreaktor0 (libreaktor.so, which needs
|
||||
# it) and the development package with everything else, which needs both.
|
||||
split=0
|
||||
ls "$stage$prefix"/lib/libreaktor.so* >/dev/null 2>&1 && split=1
|
||||
packed=""
|
||||
if [ "$split" = 0 ]; then
|
||||
conflicts=$dev
|
||||
pack "$static" "$stage" "$summary"
|
||||
else
|
||||
sdl_root="$work/split/sdl" lib_root="$work/split/lib"
|
||||
rm -rf "$work/split"
|
||||
mkdir -p "$sdl_root$prefix/lib" "$sdl_root$prefix/share/reaktor/licenses" \
|
||||
"$lib_root$prefix/lib" "$lib_root$prefix/share/reaktor"
|
||||
mv "$stage$prefix"/lib/libreaktor-sdl3.so.* "$sdl_root$prefix/lib/"
|
||||
mv "$stage$prefix/share/reaktor/licenses/SDL.txt" "$sdl_root$prefix/share/reaktor/licenses/"
|
||||
mv "$stage$prefix"/lib/libreaktor.so.* "$lib_root$prefix/lib/"
|
||||
mv "$stage$prefix/share/reaktor/licenses" "$stage$prefix/share/reaktor/NOTICE.md" \
|
||||
"$lib_root$prefix/share/reaktor/"
|
||||
pack "$sdl" "$sdl_root" \
|
||||
"SDL 3 as Reaktor builds it, for apps linked against libreaktor.so"
|
||||
pack "$lib" "$lib_root" \
|
||||
"Reaktor, a C99 GUI library on Nuklear styled by CSS (shared library)" "$sdl"
|
||||
conflicts=$static
|
||||
pack "$dev" "$stage" \
|
||||
"Reaktor, a C99 GUI library on Nuklear styled by CSS (headers, static and shared libraries)" \
|
||||
"$lib" "$sdl"
|
||||
fi
|
||||
|
||||
%files
|
||||
$prefix
|
||||
EOF
|
||||
rpmbuild -bb --define "_topdir $top" --define "debug_package %{nil}" \
|
||||
--define "__os_install_post %{nil}" "$top/SPECS/libreaktor.spec"
|
||||
pkg=$(find "$top/RPMS" -name '*.rpm' | head -n 1)
|
||||
cp "$pkg" "$out/"
|
||||
pkg="$out/$(basename "$pkg")"
|
||||
[ $install -eq 0 ] || as_root rpm -U --replacepkgs "$pkg"
|
||||
;;
|
||||
freebsd)
|
||||
cat >"$work/manifest" <<EOF
|
||||
name: libreaktor
|
||||
version: "$version"
|
||||
origin: devel/libreaktor
|
||||
comment: "$comment"
|
||||
desc: "$summary"
|
||||
maintainer: "$maintainer"
|
||||
www: "$www"
|
||||
prefix: "$prefix"
|
||||
EOF
|
||||
listing | grep -v '/$' >"$work/plist"
|
||||
pkg create -M "$work/manifest" -p "$work/plist" -r "$stage" -o "$out"
|
||||
pkg="$out/libreaktor-$version.pkg"
|
||||
[ $install -eq 0 ] || as_root pkg add "$pkg"
|
||||
;;
|
||||
openbsd)
|
||||
listing >"$work/plist"
|
||||
pkg="$out/libreaktor-$version.tgz"
|
||||
pkg_create -A "$(arch -s)" -B "$stage" -p "$prefix" -f "$work/plist" \
|
||||
-D COMMENT="$comment" -D FULLPKGPATH=devel/libreaktor \
|
||||
-D HOMEPAGE="$www" -D MAINTAINER="$maintainer" \
|
||||
-d "-$summary." "$pkg"
|
||||
[ $install -eq 0 ] || as_root pkg_add -D unsigned "$pkg"
|
||||
;;
|
||||
netbsd)
|
||||
listing | grep -v '/$' >"$work/plist"
|
||||
cat >"$work/build-info" <<EOF
|
||||
MACHINE_ARCH=$(uname -p)
|
||||
OPSYS=NetBSD
|
||||
OS_VERSION=$(uname -r)
|
||||
PKGTOOLS_VERSION=$(pkg_info -V)
|
||||
EOF
|
||||
pkg="$out/libreaktor-$version.tgz"
|
||||
pkg_create -B "$work/build-info" -c "-$comment" -d "-$summary." \
|
||||
-f "$work/plist" -I "$prefix" -p "$stage$prefix" "$pkg"
|
||||
[ $install -eq 0 ] || as_root pkg_add -U "$pkg"
|
||||
;;
|
||||
tar)
|
||||
pkg="$out/libreaktor-$version-$(uname -s | tr 'A-Z' 'a-z')-$(uname -m).tar.gz"
|
||||
tar -C "$stage" -czf "$pkg" .
|
||||
[ $install -eq 0 ] || as_root tar -C / -xzf "$pkg"
|
||||
;;
|
||||
*)
|
||||
echo "libreaktor-pkg.sh: unknown format: $format" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
if [ $install -eq 1 ]; then
|
||||
# shellcheck disable=SC2086
|
||||
case $format in
|
||||
deb) as_root dpkg -i $packed ;;
|
||||
# Packed here and never signed, as OpenBSD's below; rpm 6 refuses
|
||||
# an unsigned package unless told.
|
||||
rpm) as_root rpm -U --replacepkgs --nosignature $packed ;;
|
||||
freebsd) for p in $packed; do as_root pkg add "$p"; done ;;
|
||||
openbsd) for p in $packed; do as_root pkg_add -D unsigned "$p"; done ;;
|
||||
netbsd) for p in $packed; do as_root pkg_add -U "$p"; done ;;
|
||||
tar) for p in $packed; do as_root tar -C / -xzf "$p"; done ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo "packed: $pkg"
|
||||
echo "use it: pkg-config --cflags --libs reaktor with PKG_CONFIG_PATH=$prefix/lib/pkgconfig,"
|
||||
echo " or find_package(reaktor) with CMAKE_PREFIX_PATH=$prefix"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
prefix=${pcfiledir}/../..
|
||||
includedir=${prefix}/include
|
||||
libdir=${prefix}/lib
|
||||
|
||||
Name: reaktor-shared
|
||||
Description: A Nuklear-powered GUI library for C, linked as libreaktor.so
|
||||
Version: @PROJECT_VERSION@
|
||||
Cflags: -I${includedir}
|
||||
Libs: -Wl,--export-dynamic -Wl,-rpath,${libdir} -L${libdir} -lreaktor -l:libreaktor-modules.a -lreaktor-sdl3 @REAKTOR_PC_LIBS@
|
||||
@@ -0,0 +1,200 @@
|
||||
LIBREAKTOR_0 {
|
||||
global:
|
||||
# Nuklear's and nukanim's APIs, which reaktor/nuklear.h hands to apps.
|
||||
nk_*; nka_*;
|
||||
# Reaktor's API: what include/reaktor/ declares and the library defines.
|
||||
reaktor_accent_color;
|
||||
reaktor_anim;
|
||||
reaktor_animate;
|
||||
reaktor_anim_progress;
|
||||
reaktor_ask;
|
||||
reaktor_borderless;
|
||||
reaktor_box_close;
|
||||
reaktor_box_id;
|
||||
reaktor_box_open;
|
||||
reaktor_box_rect;
|
||||
reaktor_button;
|
||||
reaktor_button_accent;
|
||||
reaktor_button_accent_icon;
|
||||
reaktor_button_custom;
|
||||
reaktor_button_icon;
|
||||
reaktor_button_label;
|
||||
reaktor_button_width;
|
||||
reaktor_check;
|
||||
reaktor_chevron_at;
|
||||
reaktor_chord;
|
||||
reaktor_chord_text;
|
||||
reaktor_col;
|
||||
reaktor_color_pick;
|
||||
reaktor_combo_close;
|
||||
reaktor_combo_item;
|
||||
reaktor_combo_open;
|
||||
reaktor_current_font;
|
||||
reaktor_dark;
|
||||
reaktor_date_pick;
|
||||
reaktor_diagnostics;
|
||||
reaktor_ease_at;
|
||||
reaktor_ease_name;
|
||||
reaktor_edge_round;
|
||||
reaktor_field;
|
||||
reaktor_field_select;
|
||||
reaktor_field_text;
|
||||
reaktor_file_dialog_open;
|
||||
reaktor_fill_gradient;
|
||||
reaktor_fill_round;
|
||||
reaktor_floater_close;
|
||||
reaktor_floater_is_open;
|
||||
reaktor_floater_open;
|
||||
reaktor_focus_activated;
|
||||
reaktor_focus_area;
|
||||
reaktor_focus_scroll;
|
||||
reaktor_font;
|
||||
reaktor_frame_ms;
|
||||
reaktor_gap;
|
||||
reaktor_get_theme;
|
||||
reaktor_glyph_at;
|
||||
reaktor_high_contrast;
|
||||
reaktor_hot;
|
||||
reaktor_hot_follow;
|
||||
reaktor_hot_top;
|
||||
reaktor_icon;
|
||||
reaktor_icon_surface;
|
||||
reaktor_image_centered;
|
||||
reaktor_image_file;
|
||||
reaktor_ionicon;
|
||||
reaktor_ionicon_exact;
|
||||
reaktor_item_spacing;
|
||||
reaktor_knob;
|
||||
reaktor_label;
|
||||
reaktor_lang_pref;
|
||||
reaktor_launch_app;
|
||||
reaktor_link;
|
||||
reaktor_list;
|
||||
reaktor_menubar;
|
||||
reaktor_menu_edge;
|
||||
reaktor_menu_height;
|
||||
reaktor_menu_item;
|
||||
reaktor_menu_style_pop;
|
||||
reaktor_menu_style_push;
|
||||
reaktor_note;
|
||||
reaktor_note_bounds;
|
||||
reaktor_note_here;
|
||||
reaktor_note_keys;
|
||||
reaktor_note_pop;
|
||||
reaktor_note_push;
|
||||
reaktor_note_value;
|
||||
reaktor_on;
|
||||
reaktor_page_color;
|
||||
reaktor_popup_rounding;
|
||||
reaktor_post;
|
||||
reaktor_process_cpu_ms;
|
||||
reaktor_process_memory;
|
||||
reaktor_progress;
|
||||
reaktor_progress_bar;
|
||||
reaktor_property;
|
||||
reaktor_quit;
|
||||
reaktor_radio;
|
||||
reaktor_redo;
|
||||
reaktor_redo_label;
|
||||
reaktor_reduced_motion;
|
||||
reaktor_request_quit;
|
||||
reaktor_sdl_renderer;
|
||||
reaktor_sdl_window;
|
||||
reaktor_select;
|
||||
reaktor_set_borderless;
|
||||
reaktor_set_confirm_close;
|
||||
reaktor_set_css;
|
||||
reaktor_set_theme;
|
||||
reaktor_set_title;
|
||||
reaktor_set_visible;
|
||||
reaktor_shortcut_match;
|
||||
reaktor_shortcut_text;
|
||||
reaktor_sidebar;
|
||||
reaktor_slider;
|
||||
reaktor_slider_bar;
|
||||
reaktor_soak;
|
||||
reaktor_spinner;
|
||||
reaktor_splitter;
|
||||
reaktor_style_font;
|
||||
reaktor_style_frame_pop;
|
||||
reaktor_style_get;
|
||||
reaktor_style_token;
|
||||
reaktor_swatch;
|
||||
reaktor_tabs;
|
||||
reaktor_test_app;
|
||||
reaktor_test_app_of;
|
||||
reaktor_test_check;
|
||||
reaktor_test_click;
|
||||
reaktor_test_find;
|
||||
reaktor_test_key;
|
||||
reaktor_test_settle;
|
||||
reaktor_test_state;
|
||||
reaktor_test_type;
|
||||
reaktor_test_value;
|
||||
reaktor_text_color;
|
||||
reaktor_time_pick;
|
||||
reaktor_timer;
|
||||
reaktor_timer_stop;
|
||||
reaktor_tip;
|
||||
reaktor_toast;
|
||||
reaktor_token;
|
||||
reaktor_tree;
|
||||
reaktor_undo;
|
||||
reaktor_undo_clear;
|
||||
reaktor_undo_dirty;
|
||||
reaktor_undo_group;
|
||||
reaktor_undo_label;
|
||||
reaktor_undo_push;
|
||||
reaktor_undo_saved;
|
||||
reaktor_user;
|
||||
reaktor_version;
|
||||
reaktor_visible;
|
||||
reaktor_wake;
|
||||
reaktor_window_close;
|
||||
reaktor_window_is_open;
|
||||
reaktor_window_open;
|
||||
local: *;
|
||||
};
|
||||
|
||||
# Not public: what the modules, which live in each app, call in the library.
|
||||
# A version of its own keeps them apart from the API: an app's own code must
|
||||
# not reach them, and check-exports.sh says so if it does.
|
||||
LIBREAKTOR_PRIVATE_0 {
|
||||
global:
|
||||
reaktor_a11y_changes;
|
||||
reaktor_a11y_role_name;
|
||||
reaktor_a11y_tree;
|
||||
reaktor_app_frame;
|
||||
reaktor_app_ident;
|
||||
reaktor_app_size;
|
||||
reaktor_asset_load;
|
||||
reaktor_asset_register;
|
||||
reaktor_capturing;
|
||||
reaktor_font_glyph;
|
||||
reaktor_font_valid;
|
||||
reaktor_frame_settled;
|
||||
reaktor_free;
|
||||
reaktor_ft_open;
|
||||
reaktor_ft_size;
|
||||
reaktor_grow;
|
||||
reaktor_launch_icon;
|
||||
reaktor_layout_info;
|
||||
reaktor_layout_rect;
|
||||
reaktor_main_app;
|
||||
reaktor_path;
|
||||
reaktor_path_leaf;
|
||||
reaktor_read_file;
|
||||
reaktor_restyle;
|
||||
reaktor_save_mode;
|
||||
reaktor_scale;
|
||||
reaktor_set_scale;
|
||||
reaktor_style_loads;
|
||||
reaktor_utf8_clean;
|
||||
reaktor_window_app;
|
||||
reaktor_window_points;
|
||||
reaktor_window_spawn;
|
||||
# The FreeType and plutovg calls the modules make.
|
||||
plutovg_surface_create_for_data; plutovg_surface_destroy;
|
||||
plutovg_surface_write_to_jpg_stream;
|
||||
FT_Done_Face; FT_Load_Glyph;
|
||||
} LIBREAKTOR_0;
|
||||
+1
-1
@@ -6,4 +6,4 @@ Name: reaktor
|
||||
Description: A Nuklear-powered GUI library for C
|
||||
Version: @PROJECT_VERSION@
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -lreaktor @REAKTOR_PC_LIBS@
|
||||
Libs: -L${libdir} @REAKTOR_PC_LINK@ @REAKTOR_PC_LIBS@
|
||||
|
||||
@@ -9,4 +9,35 @@ if(NOT TARGET reaktor::reaktor)
|
||||
INTERFACE_LINK_DIRECTORIES "@REAKTOR_LINK_DIRS@"
|
||||
INTERFACE_LINK_OPTIONS "@REAKTOR_LINK_OPTIONS@")
|
||||
endif()
|
||||
# The shared variant, where it is installed: the modules go into the app,
|
||||
# after libreaktor.so so they fill in what it calls, and the app
|
||||
# exports them back to it. The rpath finds the libraries wherever the
|
||||
# prefix is, /opt/reaktor included, which the loader does not search.
|
||||
# OpenBSD installs no unversioned libreaktor.so, so the first match is taken.
|
||||
file(GLOB _reaktor_so "${_reaktor_prefix}/lib/libreaktor.so*")
|
||||
file(GLOB _reaktor_sdl "${_reaktor_prefix}/lib/libreaktor-sdl3.so*")
|
||||
if(NOT TARGET reaktor::shared AND _reaktor_so AND _reaktor_sdl)
|
||||
list(GET _reaktor_so 0 _reaktor_so)
|
||||
list(GET _reaktor_sdl 0 _reaktor_sdl)
|
||||
add_library(reaktor::shared INTERFACE IMPORTED)
|
||||
set_target_properties(reaktor::shared PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_reaktor_prefix}/include"
|
||||
INTERFACE_LINK_LIBRARIES "${_reaktor_so};${_reaktor_prefix}/lib/libreaktor-modules.a;${_reaktor_sdl};@REAKTOR_LINK_LIBS@"
|
||||
INTERFACE_LINK_DIRECTORIES "@REAKTOR_LINK_DIRS@"
|
||||
INTERFACE_LINK_OPTIONS "-Wl,--export-dynamic;-Wl,-rpath,${_reaktor_prefix}/lib;@REAKTOR_LINK_OPTIONS@")
|
||||
endif()
|
||||
# On macOS, Reaktor.framework, with SDL inside. The rpath looks beside the
|
||||
# install first, then in /Library/Frameworks, where apps share one copy. The
|
||||
# modules archive is loaded whole: ld64 takes from an archive only what the
|
||||
# app calls, never what the framework calls back, as GNU ld does for a .so.
|
||||
if(NOT TARGET reaktor::shared AND EXISTS "${_reaktor_prefix}/Frameworks/Reaktor.framework")
|
||||
add_library(reaktor::shared INTERFACE IMPORTED)
|
||||
set_target_properties(reaktor::shared PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_reaktor_prefix}/include"
|
||||
INTERFACE_LINK_LIBRARIES "${_reaktor_prefix}/Frameworks/Reaktor.framework;-Wl,-force_load,${_reaktor_prefix}/lib/libreaktor-modules.a;@REAKTOR_LINK_LIBS@"
|
||||
INTERFACE_LINK_DIRECTORIES "@REAKTOR_LINK_DIRS@"
|
||||
INTERFACE_LINK_OPTIONS "-Wl,-export_dynamic;-Wl,-rpath,${_reaktor_prefix}/Frameworks;-Wl,-rpath,/Library/Frameworks;@REAKTOR_LINK_OPTIONS@")
|
||||
endif()
|
||||
unset(_reaktor_prefix)
|
||||
unset(_reaktor_so)
|
||||
unset(_reaktor_sdl)
|
||||
|
||||
Reference in New Issue
Block a user