diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 39956183a5..37d5ae2d12 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -41,6 +41,7 @@ object SessionFiles { "libblfastpath.so" to "usr/local/lib/libblfastpath.so", "libssbs.so" to "usr/local/lib/libssbs.so", "usr/local/bin/droiddeck-session" to "usr/local/bin/droiddeck-session", + "usr/local/bin/droiddeck-fonts" to "usr/local/bin/droiddeck-fonts", "usr/local/bin/droiddeck-agent" to "usr/local/bin/droiddeck-agent", "usr/local/bin/steam-compatibility" to "usr/local/bin/steam-compatibility", "usr/local/bin/droiddeck-clipboard" to "usr/local/bin/droiddeck-clipboard", diff --git a/docs/development/evidence/cjk-fonts-steam-bigpicture-zh-2026-10-05.png b/docs/development/evidence/cjk-fonts-steam-bigpicture-zh-2026-10-05.png new file mode 100644 index 0000000000..b998787048 Binary files /dev/null and b/docs/development/evidence/cjk-fonts-steam-bigpicture-zh-2026-10-05.png differ diff --git a/tools/linuxfs/desktop/droiddeck-desktop b/tools/linuxfs/desktop/droiddeck-desktop index 395799784c..d0a2d7a834 100644 --- a/tools/linuxfs/desktop/droiddeck-desktop +++ b/tools/linuxfs/desktop/droiddeck-desktop @@ -16,11 +16,6 @@ export QT_QPA_PLATFORMTHEME=lxqt # The prefs for this are only advisory and a profile can override them; the environment is not. export MOZ_DISABLE_CONTENT_SANDBOX=1 MOZ_DISABLE_GMP_SANDBOX=1 MOZ_DISABLE_RDD_SANDBOX=1 export MOZ_DISABLE_SOCKET_PROCESS_SANDBOX=1 MOZ_DISABLE_UTILITY_SANDBOX=1 -# Firefox seals the size of the shared memory it hands a tab; on Android 16 (Galaxy S25/S26, -# RedMagic) adding the seal fails, Firefox only warns, and the tab refuses the unsealed memory -# ("Shared memory PlatformHandle is not safe to map") and dies on signal 11 - every page. Firefox's -# own switch skips the seals. -export MOZ_SHM_NO_SEALS=1 # pixman composites in software and gives programs shm buffers only, so a Vulkan program on it # fails at its swapchain. vulkan (or gles2) composite on the GPU and give programs DMA-BUFs, but # stock wlroots allocates through gbm on a real DRM node and the KGSL stand-in is not one ("unable @@ -89,35 +84,9 @@ fi # already running and exit without a word - a desktop with a wallpaper and nothing on it. # Only the app's own compositor socket (wayland-0) is kept. find "$XDG_RUNTIME_DIR" -mindepth 1 -maxdepth 1 ! -name 'wayland-0*' ! -name 'keymap.xkb' -exec rm -rf {} + 2>/dev/null -# fontconfig's rules (sans-serif -> DejaVu Sans and the rest) live as links in /etc/fonts/conf.d, -# and the rootfs has none: applications then find fonts but no default font. Firefox logs -# "no fonts" and draws pages without text. -if [ -d /usr/share/fontconfig/conf.default ] && ! ls /etc/fonts/conf.d/*.conf 2>/dev/null | grep -qv droiddeck; then - for f in /usr/share/fontconfig/conf.default/*.conf; do ln -sf "$f" /etc/fonts/conf.d/; done - echo "== fontconfig: linked $(ls /etc/fonts/conf.d/*.conf | wc -l) default rules" -fi -# Those rules map sans-serif and friends onto whatever a full distribution installs, and this -# rootfs has one family. Naming it outright is what gives every toolkit a default font: without -# one Gecko reports "no fonts" with families found, and draws pages with no text at all. -if [ ! -f /etc/fonts/local.conf ]; then - { echo '' - for generic in sans-serif sans serif monospace mono cursive fantasy system-ui ui-sans-serif; do - case $generic in - serif) face="DejaVu Serif" ;; - mono*|ui-mono) face="DejaVu Sans Mono" ;; - *) face="DejaVu Sans" ;; - esac - printf '%s%s\n' "$generic" "$face" - done - echo '' - } > /etc/fonts/local.conf - echo "== fontconfig: wrote local.conf (DejaVu as the default family)" -fi -# The cache in the image was built before those rules existed; rebuild it once, and only once. -if [ ! -f /var/cache/fontconfig/.droiddeck-built ] && command -v fc-cache >/dev/null 2>&1; then - fc-cache -f >/dev/null 2>&1 && touch /var/cache/fontconfig/.droiddeck-built - echo "== fontconfig: cache rebuilt, default sans is $(fc-match sans-serif 2>/dev/null)" -fi +# Fontconfig defaults and Android language fallbacks are set up by droiddeck-session before this +# script or any desktop program starts. The generated defaults live in conf.d, leaving local.conf +# available for the user's own final overrides. # The menu's "Steam" / "Steam Big Picture" entries and one entry per installed game: all of them # hand off to the app (droiddeck-steam-launch), since the client cannot draw on this desktop. export BL_DESKTOP=1 diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fonts b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fonts new file mode 100755 index 0000000000..cddcc15bc8 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fonts @@ -0,0 +1,46 @@ +#!/bin/bash +# DroidDeck's fontconfig setup for the Linux runtime. The rootfs ships DejaVu alone and no rules +# for a default family: applications then find fonts but no default, and Firefox logs "no fonts" +# and draws pages without text. DejaVu also has no CJK, Thai or Arabic glyphs, so those draw as +# tofu boxes. The app binds Android's fonts for the session, which adds language-specific fallbacks +# separately. This script links fontconfig's default rules and writes generic DejaVu aliases to an +# owned conf.d file. Fontconfig reads local.conf afterward, so user overrides keep precedence and +# are never replaced. +# The first argument is the root to set up, "/" in a session; the tests point it at a temp tree. +set -u +root=${1:-/} +root=${root%/} +# "/" strips to empty above; put it back so the paths below read as absolute and the test for a +# real session ("/") still holds. +[ -n "$root" ] || root=/ +conf_dir=$root/etc/fonts +defaults_dir=$root/usr/share/fontconfig/conf.default +mkdir -p "$conf_dir/conf.d" 2>/dev/null + +# The default rules (sans-serif -> DejaVu Sans and the rest) live as links in /etc/fonts/conf.d, +# and the rootfs has none. Linked by name, so a file we ship is never overwritten. +if [ -d "$defaults_dir" ]; then + for f in "$defaults_dir"/*.conf; do + [ -e "$f" ] || continue + [ -e "$conf_dir/conf.d/${f##*/}" ] || ln -sf "$f" "$conf_dir/conf.d/${f##*/}" + done +fi + +owned_conf=$conf_dir/conf.d/65-droiddeck-default-fonts.conf +{ + echo '' + for generic in sans-serif sans serif monospace mono cursive fantasy system-ui ui-sans-serif; do + case $generic in + serif) face="DejaVu Serif" ;; + mono*|ui-mono) face="DejaVu Sans Mono" ;; + *) face="DejaVu Sans" ;; + esac + printf '%s%s\n' "$generic" "$face" + done + echo '' +} > "$owned_conf.new" +if ! cmp -s "$owned_conf.new" "$owned_conf" 2>/dev/null; then + mv -f "$owned_conf.new" "$owned_conf" + echo "== fontconfig: wrote DejaVu defaults" +fi +rm -f "$owned_conf.new" diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 77205c03ce..3dbeaef1ab 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -144,6 +144,9 @@ program_cores() { } if [ -z "${BL_INSIDE:-}" ]; then + # Install the shared default-family aliases before Steam, gamescope or the desktop queries fonts. + /usr/local/bin/droiddeck-fonts 2>&1 | sed 's/^/[fonts] /' + # Android's directory binding and language-specific family matches handle CJK and Thai fonts. device_fonts=/usr/local/share/fonts/android if [ -d "$device_fonts" ] && [ -d /etc/fonts/conf.d ] && command -v fc-cache >/dev/null 2>&1; then fonts_rules=$( diff --git a/tools/tests/test_droiddeck_fonts.py b/tools/tests/test_droiddeck_fonts.py new file mode 100644 index 0000000000..4c75cb7b95 --- /dev/null +++ b/tools/tests/test_droiddeck_fonts.py @@ -0,0 +1,76 @@ +import subprocess +import tempfile +import unittest +from pathlib import Path + + +FONTS = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-fonts" +SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session" + + +class DroidDeckFontsTest(unittest.TestCase): + def setUp(self): + temporary = tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + self.root = Path(temporary.name) + defaults = self.root / "usr/share/fontconfig/conf.default" + defaults.mkdir(parents=True) + (defaults / "60-latin.conf").write_text("") + dejavu = self.root / "usr/share/fonts/truetype/dejavu" + dejavu.mkdir(parents=True) + (dejavu / "DejaVuSans.ttf").write_text("dejavu") + + def run_fonts(self): + subprocess.run(["bash", str(FONTS), str(self.root)], check=True, capture_output=True) + + def local_conf(self): + return (self.root / "etc/fonts/local.conf").read_text() + + def owned_conf(self): + return (self.root / "etc/fonts/conf.d/65-droiddeck-default-fonts.conf").read_text() + + def test_default_rules_linked_and_dejavu_is_the_default(self): + self.run_fonts() + self.assertTrue((self.root / "etc/fonts/conf.d/60-latin.conf").is_symlink()) + text = self.owned_conf() + self.assertIn("sans-serifDejaVu Sans", text) + self.assertIn("monospaceDejaVu Sans Mono", text) + self.assertNotIn("Noto Sans CJK", text) + self.assertFalse((self.root / "etc/fonts/local.conf").exists()) + + def test_an_existing_conf_d_rule_is_not_replaced(self): + conf_d = self.root / "etc/fonts/conf.d" + conf_d.mkdir(parents=True) + (conf_d / "60-latin.conf").write_text("mine") + self.run_fonts() + self.assertFalse((conf_d / "60-latin.conf").is_symlink()) + self.assertEqual("mine", (conf_d / "60-latin.conf").read_text()) + + def test_custom_local_conf_survives_and_device_language_fallback_remains_configured(self): + custom = self.root / "etc/fonts/local.conf" + custom.parent.mkdir(parents=True, exist_ok=True) + custom.write_text("45") + self.run_fonts() + self.assertEqual("45", self.local_conf()) + session = SESSION.read_text() + self.assertIn('device_fonts=/usr/local/share/fonts/android', session) + self.assertIn('zh-cn=Noto Sans CJK SC', session) + self.assertIn('ja=Noto Sans CJK JP', session) + self.assertIn('ko=Noto Sans CJK KR', session) + self.assertIn('th=Noto Sans Thai', session) + + def test_unchanged_fonts_do_not_rewrite_owned_conf(self): + self.run_fonts() + owned = self.root / "etc/fonts/conf.d/65-droiddeck-default-fonts.conf" + before = owned.stat().st_mtime_ns + self.run_fonts() + self.assertEqual(before, owned.stat().st_mtime_ns) + + def test_the_session_runs_the_bootstrap_before_it_starts_a_program(self): + text = SESSION.read_text() + self.assertIn("/usr/local/bin/droiddeck-fonts", text) + self.assertLess(text.index("droiddeck-fonts"), text.index("droiddeck-steam-install")) + + +if __name__ == "__main__": + unittest.main()