From 14e18e531fd3eae5cd482d1eb8c79247a27cd1f4 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 22 Nov 2026 22:29:33 +0000 Subject: [PATCH] guest: dark GTK, libadwaita and Chromium in the Wayland session, SDL windows that map on wland (libdecor preferred from the start), and a pointer on Xwayland's root window --- guest/base/build.sh | 4 ++- guest/base/rootfs/etc/chromium.d/kw-wayland | 6 ++-- guest/base/rootfs/etc/gtk-3.0/settings.ini | 8 +++++ guest/base/rootfs/etc/gtk-4.0/settings.ini | 8 +++++ guest/base/rootfs/etc/profile.d/kw-wayland.sh | 13 +++++++- guest/base/rootfs/usr/lib/kw/bin/wland | 2 +- guest/base/rootfs/usr/local/bin/Xwayland | 32 +++++++++++++++++++ 7 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 guest/base/rootfs/etc/gtk-3.0/settings.ini create mode 100644 guest/base/rootfs/etc/gtk-4.0/settings.ini create mode 100755 guest/base/rootfs/usr/local/bin/Xwayland diff --git a/guest/base/build.sh b/guest/base/build.sh index e14f6cd..c159e33 100755 --- a/guest/base/build.sh +++ b/guest/base/build.sh @@ -31,7 +31,9 @@ # bin/wland: Wayland apps in the page, through # the relay the Debian image carries), # etc/profile.d/{kw-path.sh,kw-term.sh,kw-gl.sh,kw-wayland.sh}, -# etc/chromium.d/kw-wayland, the X.Org +# etc/chromium.d/kw-wayland, +# usr/local/bin/Xwayland (the distro's, with a +# pointer on its root window), the X.Org # fbdev/evdev config, usr/share/licenses/unkernel, # usr/lib/kw-base (the base's id), and an empty # /data mount point. Its scripts run the base's diff --git a/guest/base/rootfs/etc/chromium.d/kw-wayland b/guest/base/rootfs/etc/chromium.d/kw-wayland index 34d08c5..1c9e836 100644 --- a/guest/base/rootfs/etc/chromium.d/kw-wayland +++ b/guest/base/rootfs/etc/chromium.d/kw-wayland @@ -2,7 +2,9 @@ # Copyright (C) 2026 Pooya Parsa # /etc/chromium.d/kw-wayland (the kw layer): Debian's chromium wrapper # sources this. In a Wayland session (in the page every shell has one: -# kw-wayland.sh) Chromium uses Wayland rather than look for an X display; +# kw-wayland.sh) Chromium uses Wayland rather than look for an X display, +# and is dark like the page's desktop (its own UI, and prefers-color-scheme +# for the pages it shows); # and started with neither a Wayland nor an X display (not from a shell, # or a machine booted without kw.wayland=1) where the machine can show # Wayland windows (/dev/kwshm), it gets wland's session: wland starts the @@ -14,7 +16,7 @@ if [ -z "${WAYLAND_DISPLAY:-}" ] && [ -z "${DISPLAY:-}" ] && [ -c /dev/kwshm ] & _kw_env=$(/usr/lib/kw/bin/wland 2>/dev/null) && eval "$_kw_env" unset _kw_env fi -[ -z "${WAYLAND_DISPLAY:-}" ] || CHROMIUM_FLAGS="$CHROMIUM_FLAGS --ozone-platform=wayland" +[ -z "${WAYLAND_DISPLAY:-}" ] || CHROMIUM_FLAGS="$CHROMIUM_FLAGS --ozone-platform=wayland --force-dark-mode" # Guest GL's render node is there but not Mesa's EGL, which Debian's chromium # does not pull in: its GPU process cannot start and it renders in software. if [ -c /dev/dri/renderD128 ] && ! ls /usr/lib/*-linux-gnu/libEGL.so.1 >/dev/null 2>&1; then diff --git a/guest/base/rootfs/etc/gtk-3.0/settings.ini b/guest/base/rootfs/etc/gtk-3.0/settings.ini new file mode 100644 index 0000000..e8e0526 --- /dev/null +++ b/guest/base/rootfs/etc/gtk-3.0/settings.ini @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2026 Pooya Parsa +# /etc/gtk-3.0/settings.ini (the kw layer): GTK 3 apps use their dark +# variant, as the page's desktop is dark. A user's own +# ~/.config/gtk-3.0/settings.ini comes after this and wins. + +[Settings] +gtk-application-prefer-dark-theme=1 diff --git a/guest/base/rootfs/etc/gtk-4.0/settings.ini b/guest/base/rootfs/etc/gtk-4.0/settings.ini new file mode 100644 index 0000000..30e5eda --- /dev/null +++ b/guest/base/rootfs/etc/gtk-4.0/settings.ini @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2026 Pooya Parsa +# /etc/gtk-4.0/settings.ini (the kw layer): GTK 4 apps use their dark +# variant, as the page's desktop is dark. A user's own +# ~/.config/gtk-4.0/settings.ini comes after this and wins. + +[Settings] +gtk-application-prefer-dark-theme=1 diff --git a/guest/base/rootfs/etc/profile.d/kw-wayland.sh b/guest/base/rootfs/etc/profile.d/kw-wayland.sh index 9d343b9..b860e8f 100644 --- a/guest/base/rootfs/etc/profile.d/kw-wayland.sh +++ b/guest/base/rootfs/etc/profile.d/kw-wayland.sh @@ -13,7 +13,10 @@ # X or ask are told to use Wayland: XDG_SESSION_TYPE (Chromium's and # Electron's automatic choice, Qt, session-aware apps), GTK, Qt, SDL, # Firefox, Electron. Each only where unset; the X fallbacks stay for apps -# without a Wayland backend. Debian's chromium wrapper takes its flag from +# without a Wayland backend. The page's desktop is dark, so apps are asked +# for their dark variant: GTK by /etc/gtk-3.0 and gtk-4.0/settings.ini, +# libadwaita (which ignores that setting and would ask a settings portal, +# and none runs) by ADW_DEBUG_COLOR_SCHEME, Chromium by its flag. Debian's chromium wrapper takes its flag from # /etc/chromium.d/kw-wayland instead (it clears CHROMIUM_FLAGS). # Shell builtins only: every shell start reads this. [ -O / ] is root # ($UID is bash's only). @@ -42,6 +45,14 @@ if [ -n "${WAYLAND_DISPLAY:-}" ]; then export GDK_BACKEND="${GDK_BACKEND:-wayland,x11}" export QT_QPA_PLATFORM="${QT_QPA_PLATFORM:-wayland;xcb}" export SDL_VIDEODRIVER="${SDL_VIDEODRIVER:-wayland,x11}" + # SDL 2.32 hangs before its window's first buffer when the compositor answers + # the decoration protocol with "client-side" (wland draws no title bars): it + # moves the window to libdecor in the middle of its wait for the first + # configure. Preferring libdecor from the start avoids that move; with the + # plugin (libdecor-0-plugin-1-cairo) the window gets a title bar, without it + # none, and it maps either way. + export SDL_VIDEO_WAYLAND_PREFER_LIBDECOR="${SDL_VIDEO_WAYLAND_PREFER_LIBDECOR:-1}" export MOZ_ENABLE_WAYLAND="${MOZ_ENABLE_WAYLAND:-1}" export ELECTRON_OZONE_PLATFORM_HINT="${ELECTRON_OZONE_PLATFORM_HINT:-auto}" + export ADW_DEBUG_COLOR_SCHEME="${ADW_DEBUG_COLOR_SCHEME:-prefer-dark}" fi diff --git a/guest/base/rootfs/usr/lib/kw/bin/wland b/guest/base/rootfs/usr/lib/kw/bin/wland index f7e2324..3e766d7 100755 --- a/guest/base/rootfs/usr/lib/kw/bin/wland +++ b/guest/base/rootfs/usr/lib/kw/bin/wland @@ -191,7 +191,7 @@ export XDG_RUNTIME_DIR="$dir" WAYLAND_DISPLAY="$disp" # The toolkit hints (XDG_SESSION_TYPE=wayland, GTK, Qt, SDL, Firefox, Electron). [ -r /etc/profile.d/kw-wayland.sh ] && . /etc/profile.d/kw-wayland.sh if [ $# -eq 0 ]; then - echo "export XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR' WAYLAND_DISPLAY='$WAYLAND_DISPLAY' XDG_SESSION_TYPE='$XDG_SESSION_TYPE' GDK_BACKEND='$GDK_BACKEND' QT_QPA_PLATFORM='$QT_QPA_PLATFORM' SDL_VIDEODRIVER='$SDL_VIDEODRIVER' MOZ_ENABLE_WAYLAND='$MOZ_ENABLE_WAYLAND' ELECTRON_OZONE_PLATFORM_HINT='$ELECTRON_OZONE_PLATFORM_HINT'" + echo "export XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR' WAYLAND_DISPLAY='$WAYLAND_DISPLAY' XDG_SESSION_TYPE='$XDG_SESSION_TYPE' GDK_BACKEND='$GDK_BACKEND' QT_QPA_PLATFORM='$QT_QPA_PLATFORM' SDL_VIDEODRIVER='$SDL_VIDEODRIVER' SDL_VIDEO_WAYLAND_PREFER_LIBDECOR='$SDL_VIDEO_WAYLAND_PREFER_LIBDECOR' MOZ_ENABLE_WAYLAND='$MOZ_ENABLE_WAYLAND' ELECTRON_OZONE_PLATFORM_HINT='$ELECTRON_OZONE_PLATFORM_HINT' ADW_DEBUG_COLOR_SCHEME='$ADW_DEBUG_COLOR_SCHEME'" exit 0 fi export LANG="${LANG:-C.UTF-8}" diff --git a/guest/base/rootfs/usr/local/bin/Xwayland b/guest/base/rootfs/usr/local/bin/Xwayland new file mode 100755 index 0000000..58d201b --- /dev/null +++ b/guest/base/rootfs/usr/local/bin/Xwayland @@ -0,0 +1,32 @@ +#!/run/kw-lower/bin/busybox sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2026 Pooya Parsa + +# /usr/local/bin/Xwayland (the kw layer): runs the distro's Xwayland +# (/usr/bin/Xwayland) and gives its root window a pointer. Xwayland's root +# window has no cursor, which every X window that sets none of its own +# inherits (the Athena widgets' apps: xeyes, XPaint, twm's desktop), so the +# compositor hides the pointer over them (in the page: no pointer at all). +# When Xwayland is given a display (:N), this sets the root window's cursor +# to left_ptr (xsetroot, from x11-xserver-utils; nothing without it) once +# the display's socket is there. A server that resets when its last client +# leaves (no -noreset) forgets it if xsetroot was that client. Found first +# on PATH (before /usr/bin; sudo's secure_path too), so whatever starts +# Xwayland by name gets it: a shell, a launcher app, xwayland-satellite. + +real=/usr/bin/Xwayland +[ -x $real ] || { echo "Xwayland: not installed (Debian: sudo apt-get install xwayland)" >&2; exit 127; } +d= +for a; do case $a in :[0-9]*) d=${a#:}; break ;; esac; done +if [ -n "$d" ] && [ -x /usr/bin/xsetroot ] && [ ! -e "/tmp/.X11-unix/X$d" ]; then + ( + i=0 + while [ ! -S "/tmp/.X11-unix/X$d" ]; do + i=$((i + 1)) + [ $i -gt 300 ] && exit 0 + sleep 0.1 + done + DISPLAY=:$d /usr/bin/xsetroot -cursor_name left_ptr 2>/dev/null + ) /dev/null 2>&1 & +fi +exec $real "$@"