Add the --gallery page and release packaging

- quince --gallery shows every control in every state, light/dark/AMOLED
  and four seeds; "--gallery over" runs the real chrome on a made-up film.
- Fix: a toast's action button was drawn under the toast; the disabled
  play triangle showed a seam where its halves overlap.
- tools/package.sh (from Mulberry's): tar.gz, AppImage, Arch, .deb, Nix,
  Windows installer and portable zip; installer.sh, LICENSE, build.rs for
  the exe's icon and version, Inno Setup script, PKGBUILD.
- Release notes for 0.1.0 in docs/releases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-27 07:10:38 -06:00
commit 2949d7a0a1
19 changed files with 1079 additions and 13 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
/tests/media
/dist

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Quince contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -16,6 +16,18 @@ folders, playlists and links (through yt-dlp). The controls float over the video
- Colours from the desktop (Caelestia, KDE), your own colour or the video playing; light, dark and AMOLED; four styles,
three contrast levels and four motion levels.
## Install
Releases are on the [Releases page](https://archlinux.tail7c4f5e.ts.net/git/astar76/Quince/releases):
- Arch: `sudo pacman -U Quince-<version>-arch-x86_64.pkg.tar.zst`
- Debian 12, Ubuntu 22.04 or newer: `sudo apt install ./Quince-<version>-amd64.deb`
- Any distribution: the AppImage, or unpack the tar.gz and run its `install.sh` (`--system` for /usr/local,
`uninstall.sh` to remove it). Both need mpv's library (libmpv) from the distribution.
- Windows 10/11: `Quince-<version>-Setup.exe` (installs for your user, no admin) or the portable zip.
Linux builds need glibc 2.35 or newer.
## Build
Needs Rust, libmpv (mpv 0.38 or newer) and, for previews, ffmpeg.
@ -25,6 +37,13 @@ cargo build --release
./target/release/quince video.mkv
```
`quince --gallery` opens every control in every state instead of the player (`--gallery over` starts on the page
with the real top bar, dock, menu and toasts over a made-up film), with light, dark and AMOLED and a few seed colours.
`tools/package.sh` builds the release packages into `dist/`: tar.gz, AppImage, Arch package, .deb, the Nix file, and
the Windows installer and portable zip (cross-built with mingw, installer made with Inno Setup under wine). It needs
cargo-zigbuild, and takes appimagetool, libmpv-2.dll and the link stub for libmpv from `~/.local/opt/build-tools`.
## Tests
`cargo test` runs the unit tests. `tools/smoke.sh script.txt outdir [files]` runs the app hidden in a nested niri on Xvfb

29
build.rs Normal file
View file

@ -0,0 +1,29 @@
//! Windows: embed the icon and version resource into quince.exe (needs windres on PATH; skipped without it).
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=packaging/quince.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
return;
}
let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let ver = std::env::var("CARGO_PKG_VERSION").unwrap();
let nums: Vec<&str> = ver.split('.').collect();
let comma = format!("{},{},{},0", nums[0], nums.get(1).unwrap_or(&"0"), nums.get(2).unwrap_or(&"0"));
let ico = std::fs::canonicalize("packaging/quince.ico").unwrap().to_string_lossy().replace('\\', "/");
let rc = format!(
"1 ICON \"{ico}\"\n\
1 VERSIONINFO\nFILEVERSION {comma}\nPRODUCTVERSION {comma}\nBEGIN\n BLOCK \"StringFileInfo\"\n BEGIN\n BLOCK \"040904b0\"\n BEGIN\n\
\x20 VALUE \"ProductName\", \"Quince\"\n VALUE \"FileDescription\", \"Quince video player\"\n VALUE \"FileVersion\", \"{ver}\"\n VALUE \"ProductVersion\", \"{ver}\"\n VALUE \"OriginalFilename\", \"quince.exe\"\n\
\x20 END\n END\n BLOCK \"VarFileInfo\"\n BEGIN\n VALUE \"Translation\", 0x0409, 1200\n END\nEND\n"
);
let rc_path = out.join("quince.rc");
std::fs::write(&rc_path, rc).unwrap();
let obj = out.join("quince_res.o");
let ok = std::process::Command::new("x86_64-w64-mingw32-windres").arg(&rc_path).arg(&obj).status().map(|s| s.success()).unwrap_or(false);
if ok {
println!("cargo:rustc-link-arg-bins={}", obj.display());
} else {
println!("cargo:warning=windres not available: quince.exe has no icon/version resource");
}
}

View file

@ -29,6 +29,18 @@ Version 0.1.0, first build (2026-11-26).
small thread that does the asking.
- The dock covered mpv's console; a space typed in the console came out twice.
## Missing
- A `--gallery` page of every control in every state (the /material skill asks for one).
- Packaging (AppImage / tar.gz) and a release.
## Gallery and packages (2026-11-27)
- `quince --gallery`: every control at rest, chosen and disabled, in light, dark and AMOLED and four seeds; hover,
press and focus checked by hand in screenshots. `--gallery over` runs the real top bar, dock, menu, on-screen text
and toasts on a made-up film. It found two bugs, both fixed: the disabled play triangle showed a darker seam, and
a toast's action button (Undo) was drawn under the toast and never showed.
- `tools/package.sh` builds 0.1.0 into `dist/`: tar.gz, AppImage (bundles libmpv's closure), Arch package, .deb,
Nix file, Windows installer and portable zip. glibc floor 2.35.
- Smoke-tested: the AppImage plays the test clip with hardware decoding; the Windows build plays it under wine; the
installer installs per user to `AppData\Local\Programs\Quince` with a Start menu entry.
## Not done
- No release published yet: the packages are in `dist/`, notes in `docs/releases/0.1.0.md`.
- Windows: screensaver inhibit is D-Bus only, so it does nothing there; seek previews need ffmpeg on PATH. Not tried
on real Windows.
- Text fields clip a too-long value at the edge (egui's TextEdit) instead of fading it.

9
docs/releases/0.1.0.md Normal file
View file

@ -0,0 +1,9 @@
First release of Quince, a Material You video player built on mpv.
- Plays anything mpv plays, with hardware decoding; your mpv.conf, scripts and key bindings keep working, and mpv's console opens with `.
- Controls over the video that hide while you watch: a wavy seek bar with chapter marks and preview pictures, a play button that changes shape, volume, speed, and menus for sound, subtitles, chapters and video.
- Playlist you can reorder by dragging, and an Adjust panel for picture, sound and subtitles.
- Colours from your desktop, your own colour, or the video playing; light, dark and AMOLED; contrast and motion settings.
- Open files, folders and links, drag files in, and resume where you stopped.
Downloads: AppImage and tar.gz for any Linux with glibc 2.35 or newer (needs libmpv), an Arch package, a .deb for Debian 12 / Ubuntu 22.04 and newer, and a Windows installer (per user, no admin) or portable zip. Checksums are in SHA256SUMS-0.1.0.

10
flake.nix Normal file
View file

@ -0,0 +1,10 @@
{
description = "Material You video player built on mpv";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
packages.x86_64-linux.default = pkgs.callPackage ./packaging/nix { };
apps.x86_64-linux.default = { type = "app"; program = "${self.packages.x86_64-linux.default}/bin/quince"; };
};
}

159
installer.sh Executable file
View file

@ -0,0 +1,159 @@
#!/bin/sh
# Quince installer. Installs from a release tar.gz or AppImage, or removes an install.
# installer.sh [--user|--system] [--prefix DIR] [--url URL] [FILE]
# installer.sh --uninstall [--purge] [--user|--system] [--prefix DIR]
# --user (default): ~/.local, no root. --system: /usr/local, sudo only for the copy.
# Without FILE it uses the unpacked release folder it sits in, or Quince-*-Linux-x86_64.tar.gz or
# Quince-*-x86_64.AppImage next to it. SHA256SUMS-<version> beside the file is checked when present.
# --purge also deletes settings and data (~/.config/quince, ~/.local/state/quince, ~/.cache/quince: settings, resume positions, previews and logs). DESTDIR=dir stages under dir (no sudo).
# Needs glibc 2.35 or newer.
set -eu
app=quince main=quince need=2.35
mode=install scope=user purge=0 prefix= url= file=
while [ $# -gt 0 ]; do
case $1 in
--user) scope=user ;;
--system) scope=system ;;
--prefix) [ $# -ge 2 ] || { echo "--prefix needs a folder." >&2; exit 2; }; prefix=$2; shift ;;
--url) [ $# -ge 2 ] || { echo "--url needs an address." >&2; exit 2; }; url=$2; shift ;;
--uninstall) mode=uninstall ;;
--purge) purge=1 ;;
-h|--help) sed -n '2,9p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
-*) echo "Unknown option: $1 (see --help)." >&2; exit 2 ;;
*) file=$1 ;;
esac
shift
done
[ "$purge" = 0 ] || [ "$mode" = uninstall ] || { echo "--purge only goes with --uninstall." >&2; exit 2; }
if [ -z "$prefix" ]; then
if [ "$scope" = system ]; then prefix=/usr/local; else prefix=$HOME/.local; fi
fi
case $prefix in /*) ;; *) echo "--prefix must be an absolute path." >&2; exit 2 ;; esac
prefix=${prefix%/}
destdir=${DESTDIR:-}
root=$destdir$prefix
list=$root/lib/$app/files
sudo=
if [ -z "$destdir" ] && [ "$(id -u)" != 0 ]; then
d=$root; while [ ! -e "$d" ]; do d=$(dirname "$d"); done
[ -w "$d" ] || sudo=sudo
fi
refresh() {
[ -z "$destdir" ] || return 0
command -v update-desktop-database >/dev/null 2>&1 && $sudo update-desktop-database -q "$root/share/applications" 2>/dev/null || true
[ -f "$root/share/icons/hicolor/index.theme" ] && command -v gtk-update-icon-cache >/dev/null 2>&1 \
&& $sudo gtk-update-icon-cache -q -t -f "$root/share/icons/hicolor" 2>/dev/null || true
}
# Removes the files the last install listed, then the folders that became empty.
remove_listed() {
[ -f "$list" ] || return 0
while IFS= read -r f; do
[ -n "$f" ] || continue
$sudo rm -f "$root/$f"
d=$(dirname "$f")
while [ "$d" != . ] && $sudo rmdir "$root/$d" 2>/dev/null; do d=$(dirname "$d"); done
done < "$list"
$sudo rm -f "$list"
$sudo rmdir "$root/lib/$app" "$root/lib" 2>/dev/null || true
}
if [ "$mode" = uninstall ]; then
if [ ! -f "$list" ]; then
echo "Quince is not installed in $prefix (no $list)." >&2
[ "$purge" = 1 ] || exit 1
else
remove_listed
refresh
echo "Quince removed from $prefix."
fi
if [ "$purge" = 1 ]; then
rm -rf "${XDG_CONFIG_HOME:-$HOME/.config}/quince"
rm -rf "${XDG_STATE_HOME:-$HOME/.local/state}/quince"
rm -rf "${XDG_CACHE_HOME:-$HOME/.cache}/quince"
echo "Settings and data removed (~/.config/quince, ~/.local/state/quince, ~/.cache/quince: settings, resume positions, previews and logs)."
else
echo "Settings and data are kept (--purge deletes them)."
fi
exit 0
fi
# glibc check (MULBERRY_GLIBC overrides the detected version, for tests)
have=${MULBERRY_GLIBC:-$(getconf GNU_LIBC_VERSION 2>/dev/null | sed 's/^glibc //')}
if [ -z "$have" ]; then
echo "Quince needs glibc $need or newer, and this system does not report a glibc (musl?). Nothing was installed." >&2; exit 1
fi
if [ "$(printf '%s\n%s\n' "$need" "$have" | sort -V | head -n 1)" != "$need" ]; then
echo "Quince needs glibc $need or newer, and this system has glibc $have. Nothing was installed." >&2; exit 1
fi
here=$(cd "$(dirname "$0")" && pwd)
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT INT TERM
if [ -n "$url" ]; then
file=$tmp/$(basename "${url%%\?*}")
if command -v curl >/dev/null 2>&1; then curl -fL -o "$file" -- "$url"
elif command -v wget >/dev/null 2>&1; then wget -O "$file" -- "$url"
else echo "Neither curl nor wget is installed, so $url cannot be fetched." >&2; exit 1; fi
fi
src=
if [ -z "$file" ]; then
if [ -f "$here/bin/$main" ]; then src=$here
else
for f in "$here"/Quince-*-Linux-x86_64.tar.gz "$here"/Quince-*-x86_64.AppImage; do
[ -f "$f" ] && { file=$f; break; }
done
fi
fi
if [ -z "$src" ]; then
[ -n "$file" ] && [ -f "$file" ] || { echo "No Quince tar.gz or AppImage was given or found next to the installer." >&2; exit 1; }
dir=$(dirname "$file"); name=$(basename "$file")
for s in "$dir"/SHA256SUMS-*; do
[ -f "$s" ] || continue
line=$(grep -F " $name" "$s" | head -n 1 || true)
[ -n "$line" ] || continue
[ "${line%% *}" = "$(sha256sum "$file" | cut -d' ' -f1)" ] \
|| { echo "The checksum of $name does not match $(basename "$s"). Nothing was installed." >&2; exit 1; }
echo "Checksum ok."
done
mkdir "$tmp/x"
case $name in
*.tar.gz)
tar -xzf "$file" -C "$tmp/x"
src=$(find "$tmp/x" -maxdepth 1 -mindepth 1 -type d | head -n 1)
[ -n "$src" ] && [ -f "$src/bin/$main" ] || { echo "$name has no bin/$main, so it is not a Quince release." >&2; exit 1; } ;;
*.AppImage)
cp "$file" "$tmp/app"; chmod 755 "$tmp/app"
(cd "$tmp/x" && "$tmp/app" --appimage-extract >/dev/null 2>&1) || true
[ -d "$tmp/x/squashfs-root/usr/share" ] || { echo "Could not read the contents of $name. Nothing was installed." >&2; exit 1; }
src=$tmp/src; mkdir -p "$src/bin"
mv "$tmp/app" "$src/bin/$main"
mv "$tmp/x/squashfs-root/usr/share" "$src/share"
[ ! -d "$tmp/x/squashfs-root/usr/lib" ] || mv "$tmp/x/squashfs-root/usr/lib" "$src/lib" ;;
*) echo "Unknown file type: $name (need .tar.gz or .AppImage)." >&2; exit 1 ;;
esac
fi
# Stage with launchers pointing at this prefix, then copy and list every file for --uninstall.
st=$tmp/stage
mkdir -p "$st"
for d in bin lib share; do [ ! -d "$src/$d" ] || cp -R "$src/$d" "$st/$d"; done
for d in "$st"/share/applications/*.desktop; do
[ -f "$d" ] || continue
for b in "$st"/bin/*; do
b=$(basename "$b")
sed -i -e "s#^Exec=$b\( \|\$\)#Exec=$prefix/bin/$b\1#" -e "s#^TryExec=$b\$#TryExec=$prefix/bin/$b#" "$d"
done
done
chmod 755 "$st"/bin/*
(cd "$st" && find . \( -type f -o -type l \) | sed 's|^\./||' | sort) > "$tmp/files"
mkdir -p "$st/lib/$app"; echo "lib/$app/files" >> "$tmp/files"; cp "$tmp/files" "$st/lib/$app/files"
remove_listed
$sudo mkdir -p "$root"
$sudo cp -R "$st/." "$root/"
refresh
echo "Quince installed in $prefix/bin/$main"
case ":$PATH:" in *":$prefix/bin:"*) ;; *) echo "Note: $prefix/bin is not on your PATH." ;; esac

33
packaging/arch/.SRCINFO Normal file
View file

@ -0,0 +1,33 @@
pkgbase = quince-bin
pkgdesc = Material You video player built on mpv
pkgver = 0.1.0
pkgrel = 1
url = https://archlinux.tail7c4f5e.ts.net/git/astar76/Quince
arch = x86_64
license = MIT
depends = glibc>=2.35
depends = gcc-libs
depends = mpv
depends = dbus
depends = fontconfig
depends = libglvnd
depends = wayland
depends = libxkbcommon
depends = libxkbcommon-x11
depends = libx11
depends = libxcb
depends = libxcursor
depends = libxi
depends = libxrender
depends = hicolor-icon-theme
optdepends = xdg-desktop-portal: open file and folder dialogs
optdepends = ffmpeg: preview pictures on the seek bar
optdepends = yt-dlp: web links
provides = quince
conflicts = quince
options = !strip
options = !debug
source = Quince-0.1.0-Linux-x86_64.tar.gz::https://archlinux.tail7c4f5e.ts.net/git/astar76/Quince/releases/download/v0.1.0/Quince-0.1.0-Linux-x86_64.tar.gz
sha256sums = 0651a250de7a2dffb10721e8d03f13fe679ab1207e6da4b87b1d5203d43fa76e
pkgname = quince-bin

31
packaging/arch/PKGBUILD Normal file
View file

@ -0,0 +1,31 @@
# Maintainer: astar76
# Built by tools/package.sh from the release tar.gz (TARBALL=file://… for an offline build); it keeps pkgver,
# sha256sums and the glibc floor current.
pkgname=quince-bin
pkgver=0.1.0
pkgrel=1
pkgdesc='Material You video player built on mpv'
arch=('x86_64')
url='https://archlinux.tail7c4f5e.ts.net/git/astar76/Quince'
license=('MIT')
depends=('glibc>=2.35' 'gcc-libs' 'mpv' 'dbus' 'fontconfig' 'libglvnd' 'wayland' 'libxkbcommon' 'libxkbcommon-x11' 'libx11' 'libxcb' 'libxcursor' 'libxi' 'libxrender' 'hicolor-icon-theme')
optdepends=(
'xdg-desktop-portal: open file and folder dialogs'
'ffmpeg: preview pictures on the seek bar'
'yt-dlp: web links'
)
provides=('quince')
conflicts=('quince')
options=('!strip' '!debug')
source=("Quince-$pkgver-Linux-x86_64.tar.gz::${TARBALL:-$url/releases/download/v$pkgver/Quince-$pkgver-Linux-x86_64.tar.gz}")
sha256sums=('0651a250de7a2dffb10721e8d03f13fe679ab1207e6da4b87b1d5203d43fa76e')
package() {
cd "$srcdir/quince-$pkgver"
install -d "$pkgdir/usr"
for d in bin lib share; do [ ! -d "$d" ] || cp -R "$d" "$pkgdir/usr/"; done
if [ -d "$pkgdir/usr/share/licenses/quince" ] && [ "$pkgname" != quince ]; then
mv "$pkgdir/usr/share/licenses/quince" "$pkgdir/usr/share/licenses/$pkgname"
fi
install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
}

33
packaging/nix/default.nix Normal file
View file

@ -0,0 +1,33 @@
# Quince for Nix, from the release tar.gz. Written by tools/package.sh (version and hash); edit the header there.
# nix build .#default or nix profile install . (from the repo), or callPackage this file.
{ lib, stdenv, fetchurl, autoPatchelfHook, makeWrapper, libGL, wayland, libxkbcommon, xorg, fontconfig, dbus, mpv-unwrapped }:
stdenv.mkDerivation rec {
pname = "quince";
version = "0.1.0";
src = fetchurl {
url = "https://archlinux.tail7c4f5e.ts.net/git/astar76/Quince/releases/download/v${version}/Quince-${version}-Linux-x86_64.tar.gz";
hash = "sha256-BlGiUN56Lf+xByHo0D8T/measSB+baS4ex1SA9Q/p24=";
};
nativeBuildInputs = [ autoPatchelfHook makeWrapper ];
buildInputs = [ mpv-unwrapped stdenv.cc.cc.lib ];
# Loaded with dlopen at run time, so autoPatchelf can't see them.
runtimeDependencies = [ libGL wayland libxkbcommon xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr fontconfig dbus ];
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out
for d in bin lib share; do [ ! -d $d ] || cp -R $d $out/; done
install -Dm644 README.md $out/share/doc/quince/README.md
runHook postInstall
'';
meta = {
description = "Material You video player built on mpv";
homepage = "https://archlinux.tail7c4f5e.ts.net/git/astar76/Quince";
license = lib.licenses.mit;
platforms = [ "x86_64-linux" ];
mainProgram = "quince";
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
};
}

BIN
packaging/quince.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

51
packaging/quince.iss Normal file
View file

@ -0,0 +1,51 @@
; Inno Setup script: per-user install (no admin), Start menu entry, uninstaller.
; Built by tools/package.sh under wine: iscc /DVersion=<v> /DSrc=<folder with quince.exe> /DOut=<output folder> quince.iss
#ifndef Version
#define Version "0.0.0"
#endif
#ifndef Src
#define Src "..\dist\Quince"
#endif
#ifndef Out
#define Out "..\dist"
#endif
[Setup]
AppId={{B87F98FA-E5F3-4869-A1EB-25FA4BC2F0DF}
AppName=Quince
AppVersion={#Version}
AppVerName=Quince {#Version}
AppPublisher=astar76
AppPublisherURL=https://archlinux.tail7c4f5e.ts.net/git/astar76/Quince
VersionInfoVersion={#Version}
VersionInfoProductName=Quince
VersionInfoDescription=Quince Setup
DefaultDirName={localappdata}\Programs\Quince
DisableProgramGroupPage=yes
DisableDirPage=auto
PrivilegesRequired=lowest
ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
OutputDir={#Out}
OutputBaseFilename=Quince-{#Version}-Setup
SetupIconFile=quince.ico
UninstallDisplayIcon={app}\quince.exe
UninstallDisplayName=Quince
LicenseFile=..\LICENSE
Compression=lzma2/max
SolidCompression=yes
WizardStyle=modern
CloseApplications=yes
[Tasks]
Name: "desktopicon"; Description: "Create a desktop shortcut"; Flags: unchecked
[Files]
Source: "{#Src}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
[Icons]
Name: "{userprograms}\Quince"; Filename: "{app}\quince.exe"
Name: "{userdesktop}\Quince"; Filename: "{app}\quince.exe"; Tasks: desktopicon
[Run]
Filename: "{app}\quince.exe"; Description: "Launch Quince"; Flags: nowait postinstall skipifsilent

View file

@ -20,13 +20,14 @@ use eframe::egui;
fn main() -> eframe::Result {
let args: Vec<String> = std::env::args().skip(1).collect();
if args.iter().any(|a| a == "--help" || a == "-h") {
println!("Usage: quince [FILE or LINK]...\n\nPlays videos and sound with mpv. Settings live in ~/.config/quince.");
println!("Usage: quince [FILE or LINK]...\n quince --gallery [over] every control in every state\n\nPlays videos and sound with mpv. Settings live in ~/.config/quince.");
return Ok(());
}
if args.iter().any(|a| a == "--version") {
println!("quince {}", env!("CARGO_PKG_VERSION"));
return Ok(());
}
let gallery = args.iter().position(|a| a == "--gallery").map(|i| usize::from(args.get(i + 1).is_some_and(|p| p == "over")));
let files: Vec<String> = args
.into_iter()
.filter(|a| !a.starts_with("--"))
@ -48,6 +49,9 @@ fn main() -> eframe::Result {
renderer: eframe::Renderer::Glow,
..Default::default()
};
if let Some(page) = gallery {
return eframe::run_native("Quince", options, Box::new(move |cc| Ok(Box::new(ui::gallery::Gallery::new(cc, page)))));
}
eframe::run_native("Quince", options, Box::new(move |cc| Ok(Box::new(app::App::new(cc, files)))))
}

View file

@ -422,10 +422,14 @@ pub fn toasts(ctx: &egui::Context, v: &mut View, list: &mut Vec<Toast>) {
area(ctx, &format!("toast-btn-{key}"), br, Order::Foreground, |ui| {
let resp = ui.interact(br, Id::new(("toast-btn", key)), Sense::click());
let f = feel(&resp, true);
// painted on the toast's own layer: the area's layer may sit under it
if f.tint > 0.001 {
ui.painter().rect_filled(br, cr(radius::FULL), alpha(t.inverse_primary, f.tint));
p2.rect_filled(br, cr(radius::FULL), alpha(t.inverse_primary, f.tint));
}
ui.painter().text(br.center(), Align2::CENTER_CENTER, label, fonts::med(text::BODY), t.inverse_primary);
if f.focus {
crate::widgets::ring(&p2, t, br, cr(radius::FULL));
}
p2.text(br.center(), Align2::CENTER_CENTER, label, fonts::med(text::BODY), t.inverse_primary);
clicked = resp.clicked();
});
if clicked {

View file

@ -61,13 +61,21 @@ pub fn play_pause_glyph(p: &Painter, c: Pos2, s: f32, k: f32, color: Color32) {
[(-0.30, -0.36), (-0.08, -0.36), (-0.08, 0.36), (-0.30, 0.36)],
[(0.08, -0.36), (0.30, -0.36), (0.30, 0.36), (0.08, 0.36)],
];
for (a, b) in play.iter().zip(pause.iter()) {
let pts: Vec<Pos2> = a
.iter()
.zip(b.iter())
.map(|(x, y)| c + vec2(lerp(x.0, y.0, k), lerp(x.1, y.1, k)) * s)
.collect();
p.add(Shape::convex_polygon(pts, color, Stroke::new(s * 0.06, color)));
let halves: Vec<Vec<Pos2>> = play
.iter()
.zip(pause.iter())
.map(|(a, b)| a.iter().zip(b.iter()).map(|(x, y)| c + vec2(lerp(x.0, y.0, k), lerp(x.1, y.1, k)) * s).collect())
.collect();
let stroke = Stroke::new(s * 0.06, color);
if k.abs() < 0.05 {
// While the halves still touch they are one triangle: two would overlap at their seam, which shows when the
// colour is see-through (a disabled button).
let (l, r) = (&halves[0], &halves[1]);
p.add(Shape::convex_polygon(vec![l[0], r[1], r[2], l[3]], color, stroke));
return;
}
for pts in halves {
p.add(Shape::convex_polygon(pts, color, stroke));
}
}

415
src/ui/gallery.rs Normal file
View file

@ -0,0 +1,415 @@
//! Every control in every state (`quince --gallery`). For whoever builds Quince: nothing plays here, and the words
//! are the gallery's own. "Controls" lays out each control at rest, chosen and disabled (hover, press and focus come
//! from the hand); "Over the video" runs the real top bar, dock, menus, on-screen text and toasts on a made-up film.
use super::controls::{self, keycap, play_button, row, seek_bar, slider, tabs, text_field};
use super::glyphs as g;
use super::menu::{self, Menu};
use super::{View, chrome, menus};
use crate::app::{Act, MenuKind, Osd, Toast};
use crate::config::Settings;
use crate::fonts;
use crate::motion::{self, Motion};
use crate::mpv::{Chapter, Entry, State, Track};
use crate::script::Script;
use crate::theme::{self, Appearance, Contrast, Scheme, Theme, mix};
use crate::thumbs::Thumbs;
use crate::tokens::{size, space, text};
use crate::widgets::{Kind, button, chip, icon_button, segmented, switch};
use eframe::egui::{self, Color32, Id, Rect, ScrollArea, Sense, Ui, UiBuilder, pos2, vec2};
const PAGES: [&str; 2] = ["Controls", "Over the video"];
const LOOKS: [&str; 3] = ["Light", "Dark", "AMOLED"];
/// Seeds to try the controls under: the desktop's, Quince's own gold, and two far from it.
const SEEDS: [(&str, &str); 4] = [("Desktop", ""), ("Gold", "#c9a227"), ("Leaf", "#5f8f2f"), ("Sea", "#2f6f9f")];
/// Left column with the names of the rows.
const NAMES_W: f32 = 132.0;
pub struct Gallery {
theme: Theme,
page: usize,
look: usize,
seed: usize,
desktop: (Option<Color32>, Option<bool>),
script: Option<Script>,
last: f64,
// controls
switch_on: bool,
switch_off: bool,
chips: [bool; 3],
segment: usize,
tab: usize,
empty: String,
filled: String,
long: String,
volume: f64,
brightness: f64,
seek_paused: f64,
// over the video
state: State,
cfg: Settings,
thumbs: Thumbs,
menu: Option<(Menu, MenuKind)>,
osd: Option<Osd>,
toasts: Vec<Toast>,
}
impl Gallery {
pub fn new(cc: &eframe::CreationContext, page: usize) -> Gallery {
crate::fonts::install(&cc.egui_ctx);
let desktop = theme::desktop_seed();
let mut g = Gallery {
theme: Theme::build(Color32::GOLD, Appearance::Auto, None, Scheme::Tonal, Contrast::Standard),
page,
look: if desktop.1 == Some(false) { 0 } else { 1 },
seed: 0,
desktop,
script: Script::from_env(),
last: 0.0,
switch_on: true,
switch_off: false,
chips: [true, false, true],
segment: 1,
tab: 0,
empty: String::new(),
filled: "https://example.org/talk.webm".into(),
long: "/home/someone/Videos/A film whose name is far too long for the field it sits in (2024) 2160p.mkv".into(),
volume: 80.0,
brightness: -20.0,
seek_paused: 1830.0,
state: film(),
cfg: Settings::default(),
thumbs: Thumbs::new(),
menu: None,
osd: None,
toasts: vec![],
};
g.rebuild(&cc.egui_ctx);
g
}
fn rebuild(&mut self, ctx: &egui::Context) {
let seed = match SEEDS[self.seed].1 {
"" => self.desktop.0.unwrap_or(Color32::from_rgb(0xc9, 0xa2, 0x27)),
h => theme::hex(h).unwrap_or(Color32::GOLD),
};
let look = [Appearance::Light, Appearance::Dark, Appearance::Amoled][self.look];
self.theme = Theme::build(seed, look, self.desktop.1, Scheme::Tonal, Contrast::Standard);
self.theme.apply(ctx, Motion::Normal);
}
/// Page tabs, light/dark and the seed, in one strip.
fn header(&mut self, ui: &mut Ui, rect: Rect) {
let t = self.theme.clone();
let tabs_r = Rect::from_min_size(rect.min, vec2(300.0, size::CONTROL));
tabs(ui, &t, Id::new("g-pages"), tabs_r, &PAGES, &mut self.page);
let mut changed = false;
let seeds: Vec<&str> = SEEDS.iter().map(|s| s.0).collect();
let seed_r = Rect::from_min_size(pos2(rect.right() - 340.0, rect.top()), vec2(340.0, size::CONTROL));
changed |= segmented(ui, &t, Id::new("g-seed"), seed_r, &seeds, &mut self.seed);
let look_r = Rect::from_min_size(pos2(seed_r.left() - space::S - 250.0, rect.top()), vec2(250.0, size::CONTROL));
changed |= segmented(ui, &t, Id::new("g-look"), look_r, &LOOKS, &mut self.look);
if changed {
self.rebuild(ui.ctx());
}
}
fn controls(&mut self, ui: &mut Ui) {
let t = self.theme.clone();
let mut grid = Grid { ui, t: &t };
grid.section("Buttons");
grid.cells(40.0, &[("Filled", 148.0), ("Tonal", 148.0), ("Outlined", 148.0), ("Text", 148.0), ("Disabled", 148.0)], |ui, t, i, r| {
let kind = [Kind::Filled, Kind::Tonal, Kind::Outlined, Kind::Text, Kind::Filled][i];
button(ui, t, Id::new(("g-btn", i)), r, g::FOLDER_OPEN, "Open file", kind);
});
grid.cells(40.0, &[("Standard", 64.0), ("Standard, on", 96.0), ("Tonal", 64.0), ("Tonal, on", 80.0), ("Filled", 64.0), ("Disabled", 64.0)], |ui, t, i, r| {
let (kind, on) = [(Kind::Standard, false), (Kind::Standard, true), (Kind::Tonal, false), (Kind::Tonal, true), (Kind::Filled, false), (Kind::Standard, false)][i];
let r = Rect::from_min_size(r.min, vec2(size::CONTROL, size::CONTROL));
icon_button(ui, t, Id::new(("g-icon", i)), r, g::SUBTITLES, "Subtitles", "V", kind, on);
});
grid.cells(size::LARGE, &[("Paused", 96.0), ("Playing", 96.0), ("Disabled", 96.0)], |ui, t, i, r| {
let r = Rect::from_min_size(r.min, vec2(size::LARGE, size::LARGE));
play_button(ui, t, Id::new(("g-play", i)), r, i == 1);
});
grid.section("Seek bar");
let dur = 5400.0;
let chapters = [0.0, 900.0, 2700.0, 4000.0];
for (i, name) in ["Playing", "Paused", "Wave off", "No chapters, nothing cached", "Disabled"].into_iter().enumerate() {
let seek_paused = &mut self.seek_paused;
grid.cells(28.0, &[(name, 520.0)], |ui, t, _, r| {
let (time, cached, ch): (f64, f64, &[f64]) = match i {
3 => (600.0, 0.0, &[]),
1 => (*seek_paused, 2400.0, &chapters),
_ => (1830.0, 2400.0, &chapters),
};
let out = seek_bar(ui, t, Id::new(("g-seek", i)), r, time, dur, cached, ch, i == 0 || i == 3, i != 2);
if i == 1
&& let Some(s) = out.seek.or(out.dragging)
{
*seek_paused = s;
}
});
}
grid.section("Sliders");
let (volume, brightness) = (&mut self.volume, &mut self.brightness);
grid.cells(32.0, &[("Volume", 220.0), ("From the middle", 220.0), ("Disabled", 220.0)], |ui, t, i, r| match i {
0 => {
slider(ui, t, Id::new("g-vol"), r, volume, 0.0, 150.0, 1.0, None, &|v| format!("{v:.0} %"));
}
1 => {
slider(ui, t, Id::new("g-bright"), r, brightness, -100.0, 100.0, 1.0, Some(0.0), &|v| format!("{v:+.0}"));
}
_ => {
let mut v = 40.0;
slider(ui, t, Id::new("g-slide-off"), r, &mut v, 0.0, 100.0, 1.0, None, &|v| format!("{v:.0}"));
}
});
grid.section("Choices");
let (on, off) = (&mut self.switch_on, &mut self.switch_off);
grid.cells(size::SWITCH[1], &[("On", 80.0), ("Off", 80.0), ("Disabled", 80.0)], |ui, t, i, r| {
let r = Rect::from_min_size(r.min, vec2(size::SWITCH[0], size::SWITCH[1]));
match i {
0 => switch(ui, t, Id::new("g-sw-on"), r, on),
1 => switch(ui, t, Id::new("g-sw-off"), r, off),
_ => switch(ui, t, Id::new("g-sw-dis"), r, &mut true),
};
});
let segment = &mut self.segment;
grid.cells(size::CONTROL, &[("Segmented", 300.0), ("Disabled", 300.0)], |ui, t, i, r| {
let mut fixed = 0;
let chosen = if i == 0 { &mut *segment } else { &mut fixed };
segmented(ui, t, Id::new(("g-seg", i)), r, &["Off", "Auto", "Always"], chosen);
});
let chips = &mut self.chips;
grid.cells(32.0, &[("On", 120.0), ("Off", 120.0), ("Disabled", 120.0)], |ui, t, i, r| {
chip(ui, t, Id::new(("g-chip", i)), r.min, ["English", "Forced", "Signs"][i], &mut chips[i]);
});
let tab = &mut self.tab;
grid.cells(size::CONTROL, &[("Tabs", 360.0), ("Disabled", 360.0)], |ui, t, i, r| {
let mut fixed = 1;
let chosen = if i == 0 { &mut *tab } else { &mut fixed };
tabs(ui, t, Id::new(("g-tabs", i)), r, &["Picture", "Sound", "Subtitles"], chosen);
});
grid.section("Fields");
let (empty, filled, long) = (&mut self.empty, &mut self.filled, &mut self.long);
grid.cells(size::CONTROL, &[("Empty", 260.0), ("Filled", 260.0), ("Too long", 260.0), ("Disabled", 260.0)], |ui, t, i, r| {
let mut fixed = "~/Pictures/Screenshots".to_string();
let value = match i {
0 => &mut *empty,
1 => &mut *filled,
2 => &mut *long,
_ => &mut fixed,
};
text_field(ui, t, Id::new(("g-field", i)), r, value, "Paste a link", g::LINK);
});
grid.section("Lists");
grid.cells(56.0, &[("Playing", 380.0), ("Another", 380.0)], |ui, t, i, r| {
let (glyph, title, detail) = [(g::PAUSE, "Night walk", "1:30:00 · 1920×1080"), (g::DRAG_INDICATOR, "Harbour at dawn", "12:04")][i];
row(ui, t, Id::new(("g-row", i)), r, glyph, title, detail, i == 0);
});
grid.cells(56.0, &[("Too long", 380.0), ("Disabled", 380.0)], |ui, t, i, r| {
let title = ["A film whose name is far too long for the row it has to fit in, part two", "Unreadable file"][i];
row(ui, t, Id::new(("g-row2", i)), r, g::DRAG_INDICATOR, title, "48:10", false);
});
grid.section("Keys");
grid.cells(28.0, &[("One", 96.0), ("Two", 96.0), ("Long", 120.0)], |ui, t, i, r| {
let keys = ["Space", "Ctrl O", "Shift Right"][i];
keycap(ui.painter(), t, r.right_center(), keys);
});
}
fn over(&mut self, ctx: &egui::Context, now: f64) {
let t = self.theme.clone();
let screen = ctx.content_rect();
// a plain stand-in for the picture
let p = ctx.layer_painter(egui::LayerId::background());
p.rect_filled(screen, 0.0, mix(t.primary_container, Color32::BLACK, 0.6));
let mut acts = vec![];
{
let mut v = View { t: &t, s: &self.state, cfg: &self.cfg, acts: &mut acts, now, vis: 1.0 };
chrome::top_bar(ctx, &mut v, 0.0);
chrome::dock(ctx, &mut v, &mut self.thumbs, 0.0);
chrome::osd(ctx, &mut v, self.osd.as_ref());
chrome::toasts(ctx, &mut v, &mut self.toasts);
}
// the things that come and go
egui::Area::new(Id::new("g-over-buttons")).fixed_pos(pos2(screen.center().x - 300.0, screen.top() + 96.0)).show(ctx, |ui| {
let r = |i: f32| Rect::from_min_size(pos2(screen.center().x - 300.0 + i * 152.0, screen.top() + 96.0), vec2(144.0, size::CONTROL));
if button(ui, &t, Id::new("g-o-osd"), r(0.0), g::VOLUME_UP, "Volume", Kind::Tonal).clicked() {
self.state.volume = (self.state.volume + 10.0).min(150.0);
self.osd = Some(Osd { text: format!("Volume {:.0} %", self.state.volume), level: Some(self.state.volume as f32 / 150.0), at: now });
}
if button(ui, &t, Id::new("g-o-toast"), r(1.0), g::INFO, "Toast", Kind::Tonal).clicked() {
self.toasts.push(Toast { text: "Saved a screenshot to Pictures/Screenshots".into(), at: now, action: None });
}
if button(ui, &t, Id::new("g-o-undo"), r(2.0), g::DELETE, "With undo", Kind::Tonal).clicked() {
self.toasts.push(Toast { text: "Removed Harbour at dawn from the playlist".into(), at: now, action: Some(("Undo".into(), Act::CloseOverlays)) });
}
if button(ui, &t, Id::new("g-o-menu"), r(3.0), g::MORE_VERT, "Menu", Kind::Tonal).clicked() {
acts.push(Act::Menu(MenuKind::Context, pos2(screen.center().x - 140.0, screen.top() + 152.0), false));
}
});
if let Some((m, kind)) = &mut self.menu {
let items = menus::build(*kind, &self.state, &self.cfg);
let mut open = true;
if let Some(a) = menu::show(ctx, &t, m, &items, &mut open) {
acts.push(a);
}
if !open {
self.menu = None;
}
}
for a in acts {
match a {
Act::TogglePause => self.state.pause = !self.state.pause,
Act::Menu(kind, at, above) => {
let same = self.menu.as_ref().is_some_and(|(m, k)| *k == kind && !m.closing);
self.menu = if same { None } else { Some((Menu::new(&format!("{kind:?}"), at, above), kind)) };
}
Act::Seek(s) => self.state.time = s.clamp(0.0, self.state.duration),
Act::SeekBy(d) => self.state.time = (self.state.time + d).clamp(0.0, self.state.duration),
Act::Volume(v) => self.state.volume = v.clamp(0.0, 150.0),
Act::CloseOverlays => self.menu = None,
_ => {}
}
}
}
}
/// Lays the controls page out in rows: the row's name on the left, then cells with a caption over each.
struct Grid<'a, 'b> {
ui: &'a mut Ui,
t: &'b Theme,
}
impl Grid<'_, '_> {
fn section(&mut self, name: &str) {
self.ui.add_space(space::L);
let (r, _) = self.ui.allocate_exact_size(vec2(self.ui.available_width(), 28.0), Sense::hover());
controls::heading(self.ui.painter(), self.t, r.left_center(), name);
}
/// One row of cells `h` tall; the last cell named "Disabled" is drawn disabled.
fn cells(&mut self, h: f32, cells: &[(&str, f32)], mut draw: impl FnMut(&mut Ui, &Theme, usize, Rect)) {
let cap = 20.0;
let (r, _) = self.ui.allocate_exact_size(vec2(self.ui.available_width(), cap + h + space::M), Sense::hover());
let mut x = r.left() + NAMES_W;
for (i, (name, w)) in cells.iter().enumerate() {
let p = self.ui.painter();
p.text(pos2(x, r.top()), egui::Align2::LEFT_TOP, *name, fonts::ui(text::LABEL), self.t.on_variant);
let cell = Rect::from_min_size(pos2(x, r.top() + cap), vec2(*w, h));
let mut child = self.ui.new_child(UiBuilder::new().max_rect(cell.expand(space::S)));
if name.starts_with("Disabled") {
child.disable();
}
draw(&mut child, self.t, i, cell);
x += w + space::XL;
}
}
}
/// A made-up film for "Over the video".
fn film() -> State {
let track = |id: i64, kind: &str, title: &str, lang: &str, selected: bool| Track {
id,
kind: kind.into(),
title: Some(title.into()),
lang: Some(lang.into()),
codec: Some(if kind == "sub" { "subrip" } else { "opus" }.into()),
selected,
..Track::default()
};
State {
idle: false,
pause: false,
time: 1830.0,
duration: 5400.0,
volume: 80.0,
speed: 1.0,
title: "Night walk through the old harbour".into(),
path: "/videos/night-walk.mkv".into(),
tracks: vec![
Track { id: 1, kind: "video".into(), codec: Some("av1".into()), selected: true, ..Track::default() },
track(1, "audio", "Stereo", "eng", true),
track(2, "audio", "Commentary", "eng", false),
track(1, "sub", "English", "eng", true),
track(2, "sub", "Deutsch", "ger", false),
],
chapters: [(0.0, "Opening"), (900.0, "The quay"), (2700.0, "Fog"), (4000.0, "Morning")]
.iter()
.map(|(time, title)| Chapter { time: *time, title: Some((*title).into()) })
.collect(),
chapter: 1,
playlist: ["Night walk through the old harbour", "Harbour at dawn", "Gulls"]
.iter()
.enumerate()
.map(|(i, n)| Entry { filename: format!("/videos/{i}.mkv"), title: Some((*n).into()), current: i == 0, ..Entry::default() })
.collect(),
playlist_pos: 0,
cache_time: 2400.0,
sub_visible: true,
sub_scale: 1.0,
sub_pos: 100.0,
vid: "1".into(),
aid: "1".into(),
sid: "1".into(),
width: 1920,
height: 1080,
hwdec_current: "vaapi".into(),
hwdec: "auto-safe".into(),
aspect_override: "-1".into(),
..State::default()
}
}
impl eframe::App for Gallery {
fn raw_input_hook(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) {
if let Some(s) = &mut self.script {
s.feed(ctx, raw);
}
}
fn ui(&mut self, root: &mut Ui, _frame: &mut eframe::Frame) {
let ctx = root.ctx().clone();
let now = ctx.input(|i| i.time);
let dt = if self.last == 0.0 { 1.0 / 60.0 } else { (now - self.last) as f32 };
self.last = now;
motion::begin_frame(dt, Motion::Normal);
let screen = ctx.content_rect();
root.painter().rect_filled(screen, 0.0, self.theme.surface);
if self.page == 0 {
let head = Rect::from_min_size(screen.min + vec2(space::L, space::L), vec2(screen.width() - 2.0 * space::L, size::CONTROL));
self.header(root, head);
let body = Rect::from_min_max(pos2(screen.left() + space::L, head.bottom() + space::S), screen.max);
let mut ui = root.new_child(UiBuilder::new().max_rect(body));
ScrollArea::both().auto_shrink(false).show(&mut ui, |ui| {
ui.set_min_width(1320.0);
self.controls(ui);
ui.add_space(space::XXL);
});
} else {
self.over(&ctx, now);
// the page strip floats in the middle so the real top bar keeps its place
let w = 300.0 + space::S + 250.0 + space::S + 340.0;
let head = Rect::from_min_size(pos2(screen.center().x - w / 2.0, screen.top() + 96.0 + size::CONTROL + space::L), vec2(w, size::CONTROL));
egui::Area::new(Id::new("g-head")).fixed_pos(head.min).show(&ctx, |ui| self.header(ui, head));
}
if let Some(s) = &mut self.script {
s.after_frame(&ctx, None);
}
if motion::busy() {
ctx.request_repaint();
}
}
}

View file

@ -2,6 +2,7 @@
pub mod chrome;
pub mod controls;
pub mod gallery;
pub mod glyphs;
pub mod menu;
pub mod menus;

226
tools/package.sh Executable file
View file

@ -0,0 +1,226 @@
#!/bin/bash
# Quince release packages. Run: tools/package.sh (see the common part below for what it makes)
set -euo pipefail
root=$(cd "$(dirname "$0")/.." && pwd)
APP=quince NAME=Quince DESKTOP=quince.desktop
URL=https://archlinux.tail7c4f5e.ts.net/git/astar76/Quince
ver=$(sed -n 's/^version = "\(.*\)"/\1/p' "$root/Cargo.toml" | head -n 1)
BINS=(quince)
LICENSE=MIT NIX_LICENSE=mit SUMMARY='Material You video player built on mpv'
DEB_DEPENDS='libgl1, libegl1, libwayland-client0, libwayland-egl1, libxkbcommon0, libxkbcommon-x11-0, libx11-6, libxcursor1, libxi6, libxrandr2, libfontconfig1, libdbus-1-3, libmpv2' DEB_RECOMMENDS='xdg-desktop-portal, ffmpeg, yt-dlp' DEB_SECTION=video
NIX_ARGS='libGL, wayland, libxkbcommon, xorg, fontconfig, dbus, mpv-unwrapped' NIX_RUNTIME='libGL wayland libxkbcommon xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr fontconfig dbus' NIX_BUILD_INPUTS='mpv-unwrapped stdenv.cc.cc.lib'
WIN=1 WIN_MPV=1 WIN_DLLS=(libmpv-2.dll) BUNDLE_LIBS=1
ZIG_GLIBC=2.35
build() { RUSTFLAGS="-L $tools/linuxlib -C link-arg=-Wl,--allow-shlib-undefined" nice cargo zigbuild --release --locked -q -j 2 --target x86_64-unknown-linux-gnu.$ZIG_GLIBC; }
stage() {
install -Dm644 assets/quince.desktop "$1/applications/quince.desktop"
icon_pngs assets/quince.svg "$1" quince
install -Dm644 LICENSE "$1/licenses/quince/LICENSE"
install -Dm644 assets/Rubik-OFL.txt "$1/licenses/quince/Rubik-OFL.txt"
}
# ---------------------------------------------------------------- common part (same in every project)
# Builds into dist/ (and never writes to releases/):
# $NAME-<v>-Linux-x86_64.tar.gz bin/ share/ [lib/] laid out like a prefix, with install.sh and uninstall.sh
# $NAME-<v>-x86_64.AppImage GUI apps (DESKTOP set); BUNDLE_LIBS=1 adds the non-desktop library closure
# $NAME-<v>-arch-x86_64.pkg.tar.zst makepkg from that tar.gz, offline ($PKGDIR/PKGBUILD gets version and checksum)
# $NAME-<v>-amd64.deb the same tree under /usr, for apt
# $NAME-<v>-Setup.exe and $NAME-<v>-Windows-portable.zip when WIN=1 (mingw cross build, Inno Setup in wine)
# SHA256SUMS-<v>
# It also writes packaging/nix/default.nix (fetches the release tar.gz; version and hash filled in here) and the
# glibc floor read from the binary into installer.sh, the PKGBUILD and the .deb. Nothing is downloaded: appimagetool
# and libmpv-2.dll come from ~/.local/opt/build-tools.
# SKIP_BUILD=1 packages the existing build, NO_WIN=1 skips Windows. CARGO_TARGET_DIR is honoured.
cd "$root"; PKGDIR=${PKGDIR:-packaging/arch}
tools=${BUILD_TOOLS:-$HOME/.local/opt/build-tools}
[ "${SKIP_BUILD:-}" = 1 ] || build
tdir=${CARGO_TARGET_DIR:-$root/target}
rel=$tdir/release
# ZIG_GLIBC: built with cargo-zigbuild against that glibc, so the binary runs on older distributions too.
[ -z "${ZIG_GLIBC:-}" ] || rel=$tdir/x86_64-unknown-linux-gnu/release
out=$root/dist
mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}"; work=$(mktemp -d "${XDG_CACHE_HOME:-$HOME/.cache}/package.XXXXXX"); trap 'rm -rf "$work"' EXIT
export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(git log -1 --format=%ct 2>/dev/null || date +%s)}
# hicolor PNGs from an SVG: icon_pngs <svg> <share dir> <icon name>
icon_pngs() {
install -Dm644 "$1" "$2/icons/hicolor/scalable/apps/$3.svg"
for n in 16 24 32 48 64 128 256 512; do
mkdir -p "$2/icons/hicolor/${n}x$n/apps"; rsvg-convert -w "$n" -h "$n" "$1" -o "$2/icons/hicolor/${n}x$n/apps/$3.png"
done
}
# glibc floor: the newest GLIBC_x.y symbol version any shipped binary (or EXTRA_ELF library) needs.
glibc=$(for b in "${BINS[@]}" ${EXTRA_ELF[@]+"${EXTRA_ELF[@]}"}; do objdump -T "$rel/$b"; done | grep -o 'GLIBC_[0-9.]*' | sed 's/GLIBC_//' | sort -uV | tail -n 1)
[ -n "$glibc" ] || { echo "could not read the glibc version from the binary" >&2; exit 1; }
sed -i "s/^app=$APP main=\([^ ]*\) need=.*/app=$APP main=\1 need=$glibc/; s/glibc [0-9.]* or newer\./glibc $glibc or newer./" installer.sh
sed -i "s/'glibc>=[0-9.]*'/'glibc>=$glibc'/" $PKGDIR/PKGBUILD
# tar.gz: bin/ and share/ laid out like a prefix, so installer.sh, the PKGBUILD, the .deb and Nix just copy them.
rm -rf "$out"; mkdir -p "$out"
t=$work/$APP-$ver
mkdir -p "$t/bin" "$t/share" # stage may add $t/lib too
for b in "${BINS[@]}"; do install -m755 "$rel/$b" "$t/bin/$b"; done
stage "$t/share"
install -m755 installer.sh "$t/install.sh"
printf '#!/bin/sh\n# Removes %s installed by install.sh. --purge also deletes settings and data; --system or --prefix DIR as for install.sh.\nexec sh "$(dirname "$0")/install.sh" --uninstall "$@"\n' "$NAME" > "$t/uninstall.sh"
chmod 755 "$t/uninstall.sh"
cp README.md "$t/"
find "$t" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} +
tgz=$NAME-$ver-Linux-x86_64.tar.gz
tar -C "$work" --sort=name --owner=0 --group=0 --numeric-owner -cf - "$APP-$ver" | gzip -n -9 > "$out/$tgz"
# AppImage (GUI apps): the same tree under usr/, desktop file and icon at the top.
if [ -n "${DESKTOP:-}" ]; then
a=$work/AppDir
mkdir -p "$a/usr"
cp -R "$t/bin" "$t/share" "$a/usr/"; [ ! -d "$t/lib" ] || cp -R "$t/lib" "$a/usr/"
if [ "${BUNDLE_LIBS:-0}" = 1 ]; then
# Libraries every desktop already has (glibc, graphics, windowing, sound servers, fonts) stay with the host.
skip='^(linux-vdso|ld-linux|libc|libm|libdl|libpthread|librt|libutil|libresolv|libnsl|libgcc_s|libstdc\+\+|libGL|libGLX|libGLdispatch|libEGL|libOpenGL|libGLESv2|libgbm|libdrm|libvulkan|libX11|libX11-xcb|libxcb.*|libXau|libXdmcp|libXext|libXfixes|libXrandr|libXrender|libXi|libXcursor|libXss|libXv|libXxf86vm|libXinerama|libwayland-.*|libxkbcommon.*|libfontconfig|libfreetype|libharfbuzz|libglib-2.0|libgobject-2.0|libgio-2.0|libgmodule-2.0|libdbus-1|libsystemd|libudev|libasound|libpulse.*|libpipewire-0.3|libjack|libsndio|libcap|libselinux|libpcre2-8|libffi|libz|libexpat|libnss.*)\.so'
mkdir -p "$a/usr/lib"
ldd "$rel/${BINS[0]}" | awk '/=> \//{print $3} $1 ~ /^\// {print $1}' | while read -r lib; do
name=$(basename "$lib"); [[ $name =~ $skip ]] || cp -L "$lib" "$a/usr/lib/$name"
done
fi
cp "$a/usr/share/applications/$DESKTOP" "$a/"
icon=$(sed -n 's/^Icon=//p' "$a/$DESKTOP" | head -n 1)
for ext in svg png; do
f=$(find "$a/usr/share/icons" -name "$icon.$ext" | sort -V | tail -n 1)
[ -n "$f" ] && { cp "$f" "$a/$icon.$ext"; break; }
done
cat > "$a/AppRun" <<RUN
#!/bin/sh
here=\$(dirname "\$(readlink -f "\$0")")
[ ! -d "\$here/usr/lib" ] || [ "${BUNDLE_LIBS:-0}" != 1 ] || export LD_LIBRARY_PATH="\$here/usr/lib\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}"
exec "\$here/usr/bin/${BINS[0]}" "\$@"
RUN
chmod +x "$a/AppRun"
cp "$tools/appimagetool" "$work/appimagetool"
(cd "$work" && ./appimagetool --appimage-extract >/dev/null)
ARCH=x86_64 "$work/squashfs-root/AppRun" --no-appstream "$a" "$out/$NAME-$ver-x86_64.AppImage" >"$work/ait.log" 2>&1 \
|| { tail -20 "$work/ait.log"; exit 1; }
fi
# Arch package from the local tar.gz; the repo's PKGBUILD gets this version and checksum.
sum=$(sha256sum "$out/$tgz" | cut -d' ' -f1)
sed -i "s/^pkgver=.*/pkgver=$ver/; s/^sha256sums=.*/sha256sums=('$sum')/" $PKGDIR/PKGBUILD
mkdir "$work/arch"; cp $PKGDIR/PKGBUILD "$work/arch/"
(cd "$work/arch" && makepkg --printsrcinfo > "$root/$PKGDIR/.SRCINFO")
(cd "$work/arch" && TARBALL="file://$out/$tgz" makepkg -f -C --nodeps --noconfirm >"$work/makepkg.log" 2>&1) \
|| { tail -20 "$work/makepkg.log"; exit 1; }
cp "$work"/arch/"$APP"-bin-"$ver"-*-x86_64.pkg.tar.zst "$out/$NAME-$ver-arch-x86_64.pkg.tar.zst"
# .deb: the tar.gz tree under /usr (licenses go to /usr/share/doc/<pkg>/ as Debian expects).
d=$work/deb
mkdir -p "$d/root/usr" "$d/root/usr/share/doc/$APP" "$d/control"
for x in bin lib share; do [ ! -d "$t/$x" ] || cp -R "$t/$x" "$d/root/usr/"; done
if [ -d "$d/root/usr/share/licenses/$APP" ]; then
cp -R "$d/root/usr/share/licenses/$APP/." "$d/root/usr/share/doc/$APP/"; rm -rf "$d/root/usr/share/licenses"
fi
cp README.md "$d/root/usr/share/doc/$APP/"
{ echo "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/"; echo "Upstream-Name: $NAME"
echo "Source: $URL"; echo; echo "Files: *"; echo "License: $LICENSE"; } > "$d/root/usr/share/doc/$APP/copyright"
size=$(du -sk "$d/root" | cut -f1)
cat > "$d/control/control" <<CTL
Package: $APP
Version: $ver
Architecture: amd64
Maintainer: astar76 <[email protected]>
Installed-Size: $size
Depends: libc6 (>= $glibc)${DEB_DEPENDS:+, $DEB_DEPENDS}
${DEB_RECOMMENDS:+Recommends: $DEB_RECOMMENDS
}Section: ${DEB_SECTION:-misc}
Priority: optional
Homepage: $URL
Description: $SUMMARY
Built from $URL (version $ver). Needs glibc $glibc or newer.
CTL
(cd "$d/root" && find . -type f -printf '%P\n' | sort | xargs -d '\n' md5sum) > "$d/control/md5sums"
find "$d/root" "$d/control" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} +
echo 2.0 > "$d/debian-binary"
tar -C "$d/control" --sort=name --owner=0 --group=0 --numeric-owner -czf "$d/control.tar.gz" .
tar -C "$d/root" --sort=name --owner=0 --group=0 --numeric-owner -cJf "$d/data.tar.xz" .
deb=$out/$NAME-$ver-amd64.deb
(cd "$d" && ar rcD "$deb" debian-binary control.tar.gz data.tar.xz)
! command -v dpkg-deb >/dev/null || dpkg-deb --info "$deb" >/dev/null
# Nix: packaging/nix/default.nix fetches this release's tar.gz (flake.nix at the top calls it).
mkdir -p packaging/nix
sri=sha256-$(openssl dgst -sha256 -binary "$out/$tgz" | base64 -w0)
cat > packaging/nix/default.nix <<NIX
# $NAME for Nix, from the release tar.gz. Written by tools/package.sh (version and hash); edit the header there.
# nix build .#default or nix profile install . (from the repo), or callPackage this file.
{ lib, stdenv, fetchurl, autoPatchelfHook, makeWrapper${NIX_ARGS:+, $NIX_ARGS} }:
stdenv.mkDerivation rec {
pname = "$APP";
version = "$ver";
src = fetchurl {
url = "$URL/releases/download/v\${version}/$NAME-\${version}-Linux-x86_64.tar.gz";
hash = "$sri";
};
nativeBuildInputs = [ autoPatchelfHook makeWrapper${NIX_NATIVE:+ $NIX_NATIVE} ];
buildInputs = [ ${NIX_BUILD_INPUTS:-} ];
# Loaded with dlopen at run time, so autoPatchelf can't see them.
runtimeDependencies = [ ${NIX_RUNTIME:-} ];
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p \$out
for d in bin lib share; do [ ! -d \$d ] || cp -R \$d \$out/; done
install -Dm644 README.md \$out/share/doc/$APP/README.md
runHook postInstall
'';
${NIX_EXTRA:-}
meta = {
description = "$SUMMARY";
homepage = "$URL";
license = lib.licenses.$NIX_LICENSE;
platforms = [ "x86_64-linux" ];
mainProgram = "${BINS[0]}";
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
};
}
NIX
[ -f flake.nix ] || cat > flake.nix <<FLK
{
description = "$SUMMARY";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
packages.x86_64-linux.default = pkgs.callPackage ./packaging/nix { };
apps.x86_64-linux.default = { type = "app"; program = "\${self.packages.x86_64-linux.default}/bin/${BINS[0]}"; };
};
}
FLK
# Windows: mingw cross build, a one-folder app zipped as the portable build, and a per-user Inno Setup installer.
if [ "${WIN:-0}" = 1 ] && [ "${NO_WIN:-}" != 1 ]; then
command -v x86_64-w64-mingw32-gcc >/dev/null || { echo "Windows needs mingw-w64-gcc (sudo pacman -S mingw-w64-gcc), or NO_WIN=1." >&2; exit 1; }
if [ -n "${WIN_DLLS[*]:-}" ] && [ "${WIN_MPV:-0}" = 1 ]; then
# import library for libmpv-2.dll, so the cross linker can link "mpv"
lib=$tools/winlib; mkdir -p "$lib"
if [ ! -f "$lib/libmpv.dll.a" ]; then
{ echo "LIBRARY libmpv-2.dll"; echo EXPORTS
x86_64-w64-mingw32-objdump -p "$tools/libmpv-2.dll" | sed -n '/\[Ordinal\/Name Pointer\] Table/,/^$/p' | awk '/^\s*\[ *[0-9]+\] \+base/ {print $NF}'; } > "$lib/mpv.def"
x86_64-w64-mingw32-dlltool -d "$lib/mpv.def" -D libmpv-2.dll -l "$lib/libmpv.dll.a"
fi
export RUSTFLAGS="${RUSTFLAGS:-} -L $lib"
fi
[ "${SKIP_BUILD:-}" = 1 ] || nice cargo build --release --locked -q -j 2 --target x86_64-pc-windows-gnu
w=$work/win/$NAME; mkdir -p "$w"
for b in "${BINS[@]}"; do install -m755 "$tdir/x86_64-pc-windows-gnu/release/$b.exe" "$w/"; done
for f in ${WIN_DLLS[@]+"${WIN_DLLS[@]}"}; do install -m644 "$tools/$f" "$w/"; done
install -m644 LICENSE "$w/LICENSE.txt"
find "$work/win" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} +
(cd "$work/win" && zip -qrX9 "$out/$NAME-$ver-Windows-portable.zip" "$NAME")
iscc="$HOME/.wine/drive_c/users/$USER/AppData/Local/Programs/Inno Setup 7/ISCC.exe"
WINEDEBUG=-all wine "$iscc" /Q "/DVersion=$ver" "/DSrc=Z:$w" "/DOut=Z:$out" "Z:$root/packaging/$APP.iss" >"$work/iscc.log" 2>&1 \
|| { tail -20 "$work/iscc.log"; exit 1; }
fi
(cd "$out" && sha256sum "$NAME-$ver"-* > "SHA256SUMS-$ver")
echo "glibc floor: $glibc"
ls -l "$out"