diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index f022ec5..dc16c05 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -18,7 +18,8 @@ Geminux combines a custom-patched Linux `7.3.5` kernel, pure-Linux MTK flasher, - `dwm` with Pango/HarfBuzz multi-font bar (`drw.c`), EWMH/XEmbed system tray, touch-friendly `>= 68px` status bar, `Mod4 = Fn+Alt` + one-shot `Super_L` tap-latch, `Fn+F` (`XF86XK_UWB`/`XF86XK_RFKill`) hardware Airplane Mode binding, `SIGHUP` self-reexec, and `SIGUSR1` `.Xresources` reload. - `dmenu` with Pango/HarfBuzz, dynamic full-screen-height item rows (`68px` touch rows), and mouse/touch click selection, paired with `geminux-launcher` pinning the 11 GUI apps alongside `Webarchy Browser`, `Bantam AI agent`, and `Lynx Web Browser` in `st` (and wrapping `Terminal=true` `.desktop` entries in `st -e`). - **Zero-Rust notifications**: `dunst v1.12.2` compiled with `WAYLAND=0 DUNSTIFY=0` and custom pure-C PNG (`libpng` + Cairo) / JPEG (`libjpeg-turbo`) icon loader replacing `gdk-pixbuf` ([src/dunst-notify/](file:///home/lux/proj/geminux/src/dunst-notify/)), paired with a lightweight GDBus `notify-send` / `dunstify`. -- **Webarchy & pure-C `gdk-pixbuf`**: [src/webarchy/webarchy.cpp](file:///home/lux/proj/geminux/src/webarchy/webarchy.cpp) provides a standalone C++20 `GTK3` + `WebKit2GTK-4.1` multi-tab browser adapted for the `2160x1080` ultrawide display (`1080x506` logical @ `GDK_SCALE=2`) with a collapsible flush-right vertical tab bar, DPI-scaled `pt` CSS reloaded live from `~/.Xresources` via `SIGUSR1`, persistent SQLite cookies/bookmarks under `~/.local/share/geminux/webarchy` and `~/.config/geminux/webarchy`, single-instance FIFO URL forwarding, and automatic CPU renderer fallback on WebProcess crash. [scripts/build-webarchy.sh](file:///home/lux/proj/geminux/scripts/build-webarchy.sh) also cross-compiles pure-C GNOME `gdk-pixbuf 2.42.12` (`-Dbuiltin_loaders=all`, zero `libglycin`/`librsvg`) so `gtk+3.0` and `gst-plugins-good` install cleanly without Rust, and [scripts/compile-gsettings-schemas.sh](file:///home/lux/proj/geminux/scripts/compile-gsettings-schemas.sh) compiles `/usr/share/glib-2.0/schemas/gschemas.compiled` for `WebKitNetworkProcess`. +- **Unified desktop & GTK2/GTK3 theming**: Switching `.xth` palettes via `geminux-themes` or `geminux-apply-theme` updates `~/.Xresources`, `xrdb`, `dunstrc` (`geminux-sync-dunst-theme`), and generates a light- or dark-based `Geminux-` GTK2 (`gtk-2.0/gtkrc`, `~/.gtkrc-2.0`) and GTK3 (`gtk-3.0/gtk.css`, `~/.config/gtk-3.0/settings.ini`, `~/.config/xsettingsd/xsettingsd.conf`) theme via `geminux-sync-gtk-theme`, sending `SIGHUP` to `xsettingsd` and `SIGUSR1` to live `dwm`, `st`, `webarchy`, and `libgemui` clients for instant in-place reload. +- **Webarchy & pure-C `gdk-pixbuf`**: [src/webarchy/webarchy.cpp](file:///home/lux/proj/geminux/src/webarchy/webarchy.cpp) provides a standalone C++20 `GTK3` + `WebKit2GTK-4.1` multi-tab browser adapted for the `2160x1080` ultrawide display (`1080x506` logical @ `GDK_SCALE=2`) with a collapsible flush-right vertical tab bar, DPI-scaled `pt` CSS reloaded live from `~/.Xresources` via `SIGUSR1` (selecting the generated `Geminux-` GTK3 theme and dark/light preference dynamically), persistent SQLite cookies/bookmarks under `~/.local/share/geminux/webarchy` and `~/.config/geminux/webarchy`, single-instance FIFO URL forwarding, and automatic CPU renderer fallback on WebProcess crash. [scripts/build-webarchy.sh](file:///home/lux/proj/geminux/scripts/build-webarchy.sh) also cross-compiles pure-C GNOME `gdk-pixbuf 2.42.12` (`-Dbuiltin_loaders=all`, zero `libglycin`/`librsvg`) so `gtk+3.0` and `gst-plugins-good` install cleanly without Rust, and [scripts/compile-gsettings-schemas.sh](file:///home/lux/proj/geminux/scripts/compile-gsettings-schemas.sh) compiles `/usr/share/glib-2.0/schemas/gschemas.compiled` for `WebKitNetworkProcess`. - **Native media & `yt-dlp` stack**: Native Alpine Edge `mpv` (configured via [overlay/rootfs/etc/mpv/mpv.conf](file:///home/lux/proj/geminux/overlay/rootfs/etc/mpv/mpv.conf) for Panfrost X11 EGL, PipeWire/Pulse/ALSA, and `/tmp/geminux-mpv.sock` media-key IPC), `ffmpeg`/`ffprobe`, and `gst-libav` (for WebKit HTML5 media), paired with `mpg123`, `openmpt123`, `python3`/`py3-pip`, and `yt-dlp-core` + `yt-dlp-ejs-rt-quickjs` (`quickjs`, avoiding `deno`/`py3-cryptography`). ## Custom UI toolkit and zero-poll C11 daemons diff --git a/MANUAL.md b/MANUAL.md index bbb70b1..8e8631b 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -54,7 +54,7 @@ geminux-apply-theme # list available themes geminux-apply-theme TokyoNight ``` -`geminux-apply-theme` updates `~/.Xresources`, merges into the X11 resource database via `xrdb`, translates the unified `theme.*` keys into `~/.config/dunst/dunstrc` via `geminux-sync-dunst-theme`, restarts `dunst`, and sends `SIGUSR1` to live `dwm`, `st`, `webarchy`, and `libgemui` applications for instant in-place redraw. +`geminux-apply-theme` updates `~/.Xresources`, merges into the X11 resource database via `xrdb`, translates the unified `theme.*` keys into `~/.config/dunst/dunstrc` via `geminux-sync-dunst-theme`, generates a matching `Geminux-` GTK2/GTK3 theme (selecting an Adwaita dark or light base from `theme.bgMain` luminance) under `~/.themes/` / `~/.local/share/themes/` and updates `~/.gtkrc-2.0`, `~/.config/gtk-3.0/settings.ini`, and `~/.config/xsettingsd/xsettingsd.conf` via `geminux-sync-gtk-theme`, restarts `dunst`, `SIGHUP`s `xsettingsd` for live GTK2/GTK3 reloading, and sends `SIGUSR1` to live `dwm`, `st`, `webarchy`, and `libgemui` applications for instant in-place redraw. ## Applications and daemons diff --git a/POWER-OPTIMIZATION.md b/POWER-OPTIMIZATION.md index 665dd87..8677893 100644 --- a/POWER-OPTIMIZATION.md +++ b/POWER-OPTIMIZATION.md @@ -45,7 +45,7 @@ Closing the Gemini PDA clamshell (`SW_LID = 1`) suspends immediately to RAM (`me - **Audio**: PipeWire uses `default.clock.min-quantum = 1024` and `quantum = 2048` (`10-geminux-power.conf`); WirePlumber suspends idle ALSA and BlueZ nodes after `3` seconds (`50-geminux-suspend.conf`) so audio DSP clocks gate quickly. - **Bluetooth**: BlueZ disables automatic adapter enable and fast page scan (`AutoEnable = false`, `FastConnectable = false` in [etc/bluetooth/main.conf](file:///home/lux/proj/geminux/overlay/rootfs/etc/bluetooth/main.conf)), and `geminux-hwinit` runs `rfkill block bluetooth` after loading `btmt6797`; users toggle Bluetooth on demand via `geminux-net`. - **Wi-Fi & NTP**: NetworkManager configures `wifi.powersave = 2` (`10-geminux-power.conf`) to keep CONSYS Wi-Fi awake while associated so GTK rekeys, ARP, and DNS never stall; `geminux-powerd` powers down CONSYS cleanly across system suspend. [etc/chrony/sources.d/10-geminux.sources](file:///home/lux/proj/geminux/overlay/rootfs/etc/chrony/sources.d/10-geminux.sources) caps NTP pool peers (`maxsources 2`) and lengthens polling (`minpoll 10 maxpoll 14`), paired with an offline hook on `down|vpn-down` in [30-geminux-chrony](file:///home/lux/proj/geminux/overlay/rootfs/etc/NetworkManager/dispatcher.d/30-geminux-chrony). -- **GTK / D-Bus**: [etc/profile.d/10-geminux-env.sh](file:///home/lux/proj/geminux/overlay/rootfs/etc/profile.d/10-geminux-env.sh) exports `NO_AT_BRIDGE=1` so GTK3/`webarchy` never auto-activate AT-SPI accessibility bridge daemons. +- **GTK / XSETTINGS / D-Bus**: [etc/profile.d/10-geminux-env.sh](file:///home/lux/proj/geminux/overlay/rootfs/etc/profile.d/10-geminux-env.sh) exports `NO_AT_BRIDGE=1` so GTK3/`webarchy` never auto-activate AT-SPI accessibility bridge daemons, and `geminux-session` runs `xsettingsd` as an event-driven X11 `XSETTINGS` selection daemon (`SIGHUP` on theme switch) with zero polling timers. - **Storage**: `noatime,commit=60` in `etc/fstab` alongside `vm.dirty_writeback_centisecs=1500` reduces eMMC write amplification and wakes; microSD mounts at `/media/sdcard` likewise mount with `noatime` and rely purely on `eudev` hotplug events (`95-geminux-sdcard.rules`) with zero background polling when idle or empty. ## Auditing on device diff --git a/README.md b/README.md index c8d31ae..02ca9f6 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ Geminux is an Alpine Linux (`aarch64`, musl, OpenRC) distribution built specific | Flasher & GPT | Vendored GPLv3 `mtkclient` + MT6797 DA + GPT builder + offline credential & LUKS2 provisioning | [flash-mtk.sh](file:///home/lux/proj/geminux/flash-mtk.sh), [flash-mtk.py](file:///home/lux/proj/geminux/flash-mtk.py), [scripts/geminux_accounts.py](file:///home/lux/proj/geminux/scripts/geminux_accounts.py), [scripts/geminux_luks.py](file:///home/lux/proj/geminux/scripts/geminux_luks.py) | | Display server | XLibre Xorg 25.x (`modesetting` `ShadowFB` + `TearFree` rotated 2D scanout alongside Panfrost Glamor/EGL 3D, `fbdev`, `libinput`) | [scripts/build-xlibre.sh](file:///home/lux/proj/geminux/scripts/build-xlibre.sh) | | Window manager & terminal | Patched `dwm` (Pango, systray, `.Xresources`, `Mod4`, `Fn+F` Airplane Mode keybind, `SIGHUP` self-reexec), `st` (HarfBuzz ligatures, focus cursor sync & unfocused cursor-blink gating, wheel scrollback), full-height `dmenu` | [scripts/build-suckless.sh](file:///home/lux/proj/geminux/scripts/build-suckless.sh) | -| Notifications | Pure-X11 zero-`gdk-pixbuf` `dunst v1.12.2` + custom GDBus `notify-send` / `dunstify` | [scripts/build-dunst.sh](file:///home/lux/proj/geminux/scripts/build-dunst.sh) | -| Web browser | Webarchy C++20 `GTK3` + `WebKit2GTK-4.1` ultrawide browser (right-side vertical tab bar, DPI-scaled `.Xresources` `SIGUSR1` theming) + pure-C `gdk-pixbuf 2.42.12` | [scripts/build-webarchy.sh](file:///home/lux/proj/geminux/scripts/build-webarchy.sh), [scripts/compile-gsettings-schemas.sh](file:///home/lux/proj/geminux/scripts/compile-gsettings-schemas.sh) | +| Notifications | Pure-X11 zero-`gdk-pixbuf` `dunst v1.12.2` + custom GDBus `notify-send` / `dunstify` (`geminux-sync-dunst-theme`) | [scripts/build-dunst.sh](file:///home/lux/proj/geminux/scripts/build-dunst.sh) | +| Web browser | Webarchy C++20 `GTK3` + `WebKit2GTK-4.1` ultrawide browser (right-side vertical tab bar, DPI-scaled `.Xresources` `SIGUSR1` theming, live `xsettingsd` / `Geminux-*` GTK2/GTK3 sync) + pure-C `gdk-pixbuf 2.42.12` | [scripts/build-webarchy.sh](file:///home/lux/proj/geminux/scripts/build-webarchy.sh), [scripts/compile-gsettings-schemas.sh](file:///home/lux/proj/geminux/scripts/compile-gsettings-schemas.sh) | | UI & system daemons | `libgemui.so`, 11 landscape HiDPI apps (`geminux-net` Cellular/eSIM/DNS + Airplane Mode banner), zero-poll C11 daemons (`geminux-cellctl` dual-SIM / ST33 `lpac` eSIM + `ccmni*` PDN, `geminux-imsd` VoLTE/VoWiFi `SWu`/SMS-over-IMS/RTP, `geminux-powerd` hardware Airplane Mode, `geminux-dnsctl`, etc.) | [scripts/build-geminux-ui.sh](file:///home/lux/proj/geminux/scripts/build-geminux-ui.sh) | | Media & CLI tools | Native Alpine Edge `mpv` (`/etc/mpv/mpv.conf` with Panfrost X11 EGL + PipeWire + IPC), `ffmpeg`/`ffprobe`, `gst-libav`, `mpg123`, `openmpt123`, `yt-dlp` (`quickjs`), `python3`/`pip3`, `gpg` (`gnupg`), `pass`, `dosfstools` (`mkfs.vfat`/`fsck.vfat`/`fatlabel`), `bantam`, `lynx`, `gsocket`, `.apexrc`, default `htoprc` | [scripts/build-bantam.sh](file:///home/lux/proj/geminux/scripts/build-bantam.sh), [scripts/build-gsocket.sh](file:///home/lux/proj/geminux/scripts/build-gsocket.sh), [overlay/rootfs/etc/mpv/mpv.conf](file:///home/lux/proj/geminux/overlay/rootfs/etc/mpv/mpv.conf) | | Local APK repository | 10 signed `@geminux` `.apk` packages + `APKINDEX.tar.gz` | [scripts/package-local-apks.sh](file:///home/lux/proj/geminux/scripts/package-local-apks.sh) | @@ -36,7 +36,7 @@ Geminux is an Alpine Linux (`aarch64`, musl, OpenRC) distribution built specific ## Verification status vs. on-device testing -All cross-compiled binaries, kernel/DTB artifacts, GPT repartitioning logic, offline credential/LUKS2 builders, XKB keymap compilation, `.Xresources`-to-`dunstrc` theme syncing, MT6797 CCCI framing/handshake unit tests, 3GPP IMS/AKA/ESP/SIP/RTP protocol tests ([scripts/test-ims-protocol.py](file:///home/lux/proj/geminux/scripts/test-ims-protocol.py)), zero-poll power policy tests, Webarchy renderer profile & WebKit GSettings schema tests, `dosfstools` & `/media/sdcard` automount tests, ELF binary Rust scan, and `apk upgrade --simulate` checks are verified automatically via [scripts/check-rebuild.sh](file:///home/lux/proj/geminux/scripts/check-rebuild.sh). +All cross-compiled binaries, kernel/DTB artifacts, GPT repartitioning logic, offline credential/LUKS2 builders, XKB keymap compilation, `.Xresources`-to-`dunstrc`/GTK2/GTK3 theme syncing, MT6797 CCCI framing/handshake unit tests, 3GPP IMS/AKA/ESP/SIP/RTP protocol tests ([scripts/test-ims-protocol.py](file:///home/lux/proj/geminux/scripts/test-ims-protocol.py)), zero-poll power policy tests, Webarchy renderer profile & WebKit GSettings schema tests, `dosfstools` & `/media/sdcard` automount tests, ELF binary Rust scan, and `apk upgrade --simulate` checks are verified automatically via [scripts/check-rebuild.sh](file:///home/lux/proj/geminux/scripts/check-rebuild.sh). Live hardware bring-up on a physical Planet Computers Gemini PDA (x27 Wi-Fi + 4G) has been verified for USB BROM/DA flashing, offline account provisioning, LUKS2 full-disk encryption unlock & first-boot ext4 resize, `SSD2092` FHD+ display & multi-touch gestures (`geminux-touchd`), tear-free rotated `ShadowFB` scanout, lid-close S3 deep sleep & resume, CONSYS Wi-Fi/BT (`geminux-net` DNS tab & associated WLAN persistence), MT6797 MD1 baseband boot (`MD_STATE=READY`), ST33 eUICC / physical SIM slot switching & `geminux-imsd` standby, `Fn+F` hardware Airplane Mode radio teardown/restore, Webarchy ultrawide Panfrost GPU rendering, PipeWire audio, Media Controller + 10-bit Bayer camera ISP, AW9120 RGB back LEDs, Chrony online time sync, and USB NCM networking. Accessory/carrier-dependent checks (such as live VoLTE/VoWiFi calls/SMS with an active carrier SIM/eUICC profile and external Slimport/HDMI monitors) are documented in the hardware checklist in [INSTALL.md](file:///home/lux/proj/geminux/INSTALL.md). diff --git a/overlay/rootfs/usr/bin/geminux-apply-theme b/overlay/rootfs/usr/bin/geminux-apply-theme index 6538749..dc0fb9a 100755 --- a/overlay/rootfs/usr/bin/geminux-apply-theme +++ b/overlay/rootfs/usr/bin/geminux-apply-theme @@ -1,5 +1,5 @@ #!/bin/sh -# Apply a Geminux .xth theme across .Xresources, xrdb, dunst, dwm, st, and libgemui apps. +# Apply a Geminux .xth theme across .Xresources, xrdb, dunst, GTK2/GTK3, dwm, st, and libgemui apps. set -eu HOME_DIR="${HOME:-/home/user}" @@ -30,6 +30,7 @@ if [ -n "${DISPLAY:-}" ] && command -v xrdb >/dev/null 2>&1; then fi /usr/bin/geminux-sync-dunst-theme +/usr/bin/geminux-sync-gtk-theme # Signal live applications (dwm, st, webarchy, libgemui apps) to reload .Xresources via SIGUSR1 for proc in dwm st webarchy geminux-dialer geminux-callscreen geminux-sms geminux-contacts \ diff --git a/overlay/rootfs/usr/bin/geminux-session b/overlay/rootfs/usr/bin/geminux-session index afd9e90..6ba1f8d 100755 --- a/overlay/rootfs/usr/bin/geminux-session +++ b/overlay/rootfs/usr/bin/geminux-session @@ -50,6 +50,10 @@ if command -v geminux-sync-dunst-theme >/dev/null 2>&1; then geminux-sync-dunst-theme 2>/dev/null || true fi +if command -v geminux-sync-gtk-theme >/dev/null 2>&1; then + geminux-sync-gtk-theme --no-reload 2>/dev/null || true +fi + if command -v xset >/dev/null 2>&1; then # Suspend and backlight blanking are managed event-driven by geminux-powerd. xset s off -dpms 2>/dev/null || true @@ -74,6 +78,7 @@ start_bg() { start_bg pipewire start_bg pipewire-pulse start_bg wireplumber +start_bg xsettingsd -c "$HOME_DIR/.config/xsettingsd/xsettingsd.conf" start_bg dunst start_bg geminux-statusd start_bg geminux-touchd diff --git a/overlay/rootfs/usr/bin/geminux-sync-gtk-theme b/overlay/rootfs/usr/bin/geminux-sync-gtk-theme new file mode 100755 index 0000000..beca79b --- /dev/null +++ b/overlay/rootfs/usr/bin/geminux-sync-gtk-theme @@ -0,0 +1,796 @@ +#!/bin/sh +# Synchronize active GTK2, GTK3, and xsettingsd themes/fonts with .Xresources/.xth theme. +set -eu + +HOME_DIR="${HOME:-/home/user}" +XRES_FILE="${GEMINUX_XRESOURCES:-$HOME_DIR/.Xresources}" +if [ ! -r "$XRES_FILE" ] && [ -r /etc/skel/.Xresources ]; then + XRES_FILE="/etc/skel/.Xresources" +fi + +THEMES_OUT_DIR="${GEMINUX_GTK_THEMES_DIR:-$HOME_DIR/.themes}" +XDG_THEMES_OUT_DIR="${GEMINUX_XDG_THEMES_DIR:-$HOME_DIR/.local/share/themes}" +GTK2_RC_OUT="${GEMINUX_GTK2_RC:-$HOME_DIR/.gtkrc-2.0}" +GTK3_CONF_DIR="${GEMINUX_GTK3_DIR:-$HOME_DIR/.config/gtk-3.0}" +XSETTINGSD_CONF="${GEMINUX_XSETTINGSD_CONF:-$HOME_DIR/.config/xsettingsd/xsettingsd.conf}" + +get_xres() { + key="$1" + def="$2" + if [ -r "$XRES_FILE" ]; then + val="$(awk -F: -v k="$key" ' + $0 !~ /^[[:space:]]*[!#]/ { + kpart = $1 + gsub(/^[[:space:]]+|[[:space:]]+$/, "", kpart) + if (kpart == k) { + sub(/^[^:]*:[[:space:]]*/, "", $0) + gsub(/^[[:space:]"'\'']+|[[:space:]"'\'']+$/, "", $0) + print $0 + } + } + ' "$XRES_FILE" | tail -n 1)" + if [ -n "$val" ]; then + printf '%s' "$val" + return + fi + fi + printf '%s' "$def" +} + +RAW_NAME="$(get_xres "theme.name" "GeminuxHelio")" +SAFE_NAME="$(printf '%s' "$RAW_NAME" | tr -cd 'A-Za-z0-9._-')" +[ -n "$SAFE_NAME" ] || SAFE_NAME="GeminuxHelio" +GTK_THEME_NAME="Geminux-$SAFE_NAME" + +BG_MAIN="$(get_xres "theme.bgMain" "#0f1419")" +BG_BAR="$(get_xres "theme.bgBar" "$BG_MAIN")" +BG_HEADER="$(get_xres "theme.bgHeader" "$BG_MAIN")" +BG_FOOTER="$(get_xres "theme.bgFooter" "$BG_HEADER")" +BG_OVERLAY="$(get_xres "theme.bgOverlay" "$BG_HEADER")" +BG_ALT_EVEN="$(get_xres "theme.bgAltEven" "$BG_MAIN")" +BG_ALT_ODD="$(get_xres "theme.bgAltOdd" "$BG_ALT_EVEN")" +BG_INPUT="$(get_xres "theme.bgInput" "$BG_MAIN")" +BG_BUTTON="$(get_xres "theme.bgButton" "$BG_ALT_EVEN")" +BG_INPUT_FOCUS="$(get_xres "theme.bgInputFocus" "$BG_BUTTON")" +BG_SEARCH="$(get_xres "theme.bgSearch" "$BG_BUTTON")" +FG_MAIN="$(get_xres "theme.fgMain" "#e6e1cf")" +FG_BRIGHT="$(get_xres "theme.fgBright" "$FG_MAIN")" +FG_MUTED="$(get_xres "theme.fgMuted" "#7b8898")" +SEL_BG="$(get_xres "theme.selBg" "#2b5278")" +SEL_FG="$(get_xres "theme.selFg" "#ffffff")" +ACCENT="$(get_xres "theme.accent" "$SEL_BG")" +ACCENT_ALT="$(get_xres "theme.accentAlt" "$ACCENT")" +HIGHLIGHT="$(get_xres "theme.highlight" "$ACCENT")" +BORDER="$(get_xres "theme.border" "#283444")" +DIVIDER="$(get_xres "theme.divider" "$BORDER")" +SUCCESS="$(get_xres "theme.success" "#2ecc71")" +INFO="$(get_xres "theme.info" "#5dade2")" +WARNING="$(get_xres "theme.warning" "#e67e22")" +DANGER="$(get_xres "theme.danger" "#f07178")" +DANGER_BG="$(get_xres "theme.dangerBg" "#4c1d24")" + +FONT_FACE="$(get_xres "theme.fontFace" "Fira Code" | tr -d '"')" +[ -n "$FONT_FACE" ] || FONT_FACE="Fira Code" + +BASE_SIZE="$(get_xres "theme.baseFontSize" "32")" +case "$BASE_SIZE" in + ''|*[!0-9]*) BASE_SIZE=32 ;; +esac +PT_SIZE="$(awk -v b="$BASE_SIZE" 'BEGIN { + pt = int(b * 10 / 32 + 0.5) + if (pt < 8) pt = 8 + if (pt > 16) pt = 16 + printf "%d", pt +}')" +GTK_FONT="$FONT_FACE $PT_SIZE" + +CURSOR_THEME="$(get_xres "Xcursor.theme" "default" | tr -d '"')" +[ -n "$CURSOR_THEME" ] || CURSOR_THEME="default" +CURSOR_SIZE="$(get_xres "Xcursor.size" "64")" +case "$CURSOR_SIZE" in + ''|*[!0-9]*) CURSOR_SIZE=64 ;; +esac + +IS_DARK="$(awk -v h="$BG_MAIN" ' + function hex2(s, i, a, b) { + s = tolower(s) + a = index("0123456789abcdef", substr(s, i, 1)) - 1 + b = index("0123456789abcdef", substr(s, i + 1, 1)) - 1 + if (a < 0 || b < 0) return -1 + return a * 16 + b + } + BEGIN { + if (length(h) == 7 && substr(h, 1, 1) == "#") { + r = hex2(h, 2) + g = hex2(h, 4) + b = hex2(h, 6) + if (r >= 0 && g >= 0 && b >= 0) { + lum = 0.2126 * r + 0.7152 * g + 0.0722 * b + print (lum < 128.0) ? "1" : "0" + exit + } + } + print "1" + } +')" + +if [ "$IS_DARK" = "1" ]; then + ADWAITA_IMPORT="resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained-dark.css" + PREFER_DARK_BOOL="true" + COLOR_SCHEME="prefer-dark" +else + ADWAITA_IMPORT="resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained.css" + PREFER_DARK_BOOL="false" + COLOR_SCHEME="prefer-light" +fi + +PREV_THEME="" +if [ -r "$XSETTINGSD_CONF" ]; then + PREV_THEME="$(awk '$1 == "Net/ThemeName" { + sub(/^Net\/ThemeName[[:space:]]+/, "", $0) + gsub(/^"|"$/, "", $0) + print $0 + exit + }' "$XSETTINGSD_CONF")" +fi + +THEME_ROOT="$THEMES_OUT_DIR/$GTK_THEME_NAME" +mkdir -p "$THEME_ROOT/gtk-2.0" "$THEME_ROOT/gtk-3.0" \ + "$XDG_THEMES_OUT_DIR" "$(dirname "$GTK2_RC_OUT")" \ + "$GTK3_CONF_DIR" "$(dirname "$XSETTINGSD_CONF")" + +cat > "$THEME_ROOT/index.theme.tmp.$$" < "$THEME_ROOT/gtk-2.0/gtkrc.tmp.$$" <*" style "geminux-button" +class "GtkEntry" style "geminux-entry" +class "GtkTextView" style "geminux-entry" +class "GtkSpinButton" style "geminux-entry" +class "GtkMenuBar" style "geminux-menubar" +class "GtkToolbar" style "geminux-menubar" +class "GtkMenu" style "geminux-menu" +widget_class "**" style "geminux-menu" +class "GtkMenuItem" style "geminux-menu-item" +widget_class "**" style "geminux-menu-item" +class "GtkNotebook" style "geminux-notebook" +class "GtkTreeView" style "geminux-treeview" +widget_class "*.*" style "geminux-treeview" +class "GtkScrollbar" style "geminux-scrollbar" +class "GtkProgressBar" style "geminux-progressbar" +widget "gtk-tooltip*" style "geminux-tooltip" +EOF +mv -f "$THEME_ROOT/gtk-2.0/gtkrc.tmp.$$" "$THEME_ROOT/gtk-2.0/gtkrc" + +cat > "$THEME_ROOT/gtk-3.0/gtk.css.tmp.$$" < header { + background-image: none; + background-color: $BG_BAR; + border-color: $BORDER; +} + +notebook > header tab { + background-image: none; + background-color: $BG_HEADER; + color: $FG_MUTED; + border-color: $BORDER; +} + +notebook > header tab:hover { + color: $FG_MAIN; + background-color: $BG_ALT_EVEN; +} + +notebook > header tab:checked { + background-color: $BG_MAIN; + color: $FG_BRIGHT; + border-color: $ACCENT; +} + +checkbutton check, +radiobutton radio { + background-color: $BG_INPUT; + border-color: $BORDER; + color: $SEL_FG; +} + +checkbutton check:checked, +radiobutton radio:checked, +modelbutton check:checked, +modelbutton radio:checked { + background-image: none; + background-color: $SEL_BG; + border-color: $ACCENT; + color: $SEL_FG; +} + +switch { + background-image: none; + background-color: $BG_BUTTON; + border: 1px solid $BORDER; + color: $FG_MAIN; +} + +switch:checked { + background-image: none; + background-color: $SEL_BG; + border-color: $ACCENT; + color: $SEL_FG; +} + +switch slider { + background-image: none; + background-color: $FG_BRIGHT; + border: 1px solid $BORDER; +} + +progressbar trough, +scale trough { + background-image: none; + background-color: $BG_SEARCH; + border: 1px solid $BORDER; +} + +progressbar progress, +scale highlight { + background-image: none; + background-color: $ACCENT; + border-color: $ACCENT; +} + +scale slider { + background-image: none; + background-color: $FG_BRIGHT; + border: 1px solid $ACCENT; +} + +scrollbar { + background-color: $BG_BAR; + border-color: $BORDER; +} + +scrollbar trough { + background-color: $BG_BAR; +} + +scrollbar slider { + background-image: none; + background-color: $DIVIDER; +} + +scrollbar slider:hover { + background-color: $ACCENT; +} + +scrollbar slider:active { + background-color: $SEL_BG; +} + +tooltip, +tooltip.background, +.tooltip { + background-image: none; + background-color: $BG_OVERLAY; + color: $FG_BRIGHT; + border: 1px solid $ACCENT; +} + +separator, +.separator { + background-color: $DIVIDER; + color: $DIVIDER; +} + +frame > border, +scrolledwindow > border, +.frame { + border-color: $BORDER; +} + +*:link { + color: $ACCENT; +} + +*:visited { + color: $ACCENT_ALT; +} + +infobar.info { + background-color: $SEL_BG; + color: $SEL_FG; +} + +infobar.warning { + background-color: $BG_OVERLAY; + color: $WARNING; + border-color: $WARNING; +} + +infobar.error { + background-color: $DANGER_BG; + color: $FG_BRIGHT; + border-color: $DANGER; +} +EOF +mv -f "$THEME_ROOT/gtk-3.0/gtk.css.tmp.$$" "$THEME_ROOT/gtk-3.0/gtk.css" + +cat > "$THEME_ROOT/gtk-3.0/gtk-dark.css.tmp.$$" < "$GTK2_RC_OUT.tmp.$$" < "$GTK3_CONF_DIR/settings.ini.tmp.$$" < "$XSETTINGSD_CONF.tmp.$$" </dev/null || true + done + sleep 0.05 2>/dev/null || sleep 1 + write_xsettingsd "$GTK_THEME_NAME" + fi + for pid in $XSD_PIDS; do + kill -HUP "$pid" 2>/dev/null || true + done + elif [ -n "${DISPLAY:-}" ] && command -v xsettingsd >/dev/null 2>&1; then + xsettingsd -c "$XSETTINGSD_CONF" >/dev/null 2>&1 /dev/null 2>&1; then + gsettings set org.gnome.desktop.interface gtk-theme "$GTK_THEME_NAME" 2>/dev/null || true + gsettings set org.gnome.desktop.interface color-scheme "$COLOR_SCHEME" 2>/dev/null || true + gsettings set org.gnome.desktop.interface font-name "$GTK_FONT" 2>/dev/null || true + fi +fi diff --git a/prebuilt/geminux/usr/bin/geminux-themes b/prebuilt/geminux/usr/bin/geminux-themes index 7e8fb39..644da1a 100755 Binary files a/prebuilt/geminux/usr/bin/geminux-themes and b/prebuilt/geminux/usr/bin/geminux-themes differ diff --git a/prebuilt/webarchy/usr/bin/webarchy b/prebuilt/webarchy/usr/bin/webarchy index ba00ba6..e47f933 100755 Binary files a/prebuilt/webarchy/usr/bin/webarchy and b/prebuilt/webarchy/usr/bin/webarchy differ diff --git a/scripts/apply-geminux-overlay.sh b/scripts/apply-geminux-overlay.sh index 11c2154..414fb20 100755 --- a/scripts/apply-geminux-overlay.sh +++ b/scripts/apply-geminux-overlay.sh @@ -217,6 +217,11 @@ mkdir -p "$TARGET_ROOTFS/home/user/.cache" "$TARGET_ROOTFS/home/user/.config" \ "$TARGET_ROOTFS/home/user/.local/share/geminux" \ "$TARGET_ROOTFS/home/user/Pictures" "$TARGET_ROOTFS/home/user/Videos" \ "$TARGET_ROOTFS/home/user/Downloads" +if [ -x "$TARGET_ROOTFS/usr/bin/geminux-sync-gtk-theme" ]; then + HOME="$TARGET_ROOTFS/etc/skel" \ + GEMINUX_XRESOURCES="$TARGET_ROOTFS/etc/skel/.Xresources" \ + "$TARGET_ROOTFS/usr/bin/geminux-sync-gtk-theme" --no-reload +fi if [ -d "$TARGET_ROOTFS/etc/skel" ]; then cp -af "$TARGET_ROOTFS/etc/skel/." "$TARGET_ROOTFS/home/user/" fi diff --git a/scripts/check-rebuild.sh b/scripts/check-rebuild.sh index a94f1ca..9a01181 100755 --- a/scripts/check-rebuild.sh +++ b/scripts/check-rebuild.sh @@ -34,7 +34,7 @@ for bad_pkg in sway wayfire weston phosh cage xwayland grim slurp wofi \ exit 1 fi done -for req_pkg in ffmpeg mpv gst-libav; do +for req_pkg in ffmpeg mpv gst-libav xsettingsd; do if ! grep -Fxq "P:$req_pkg" "$ROOTFS_DIR/lib/apk/db/installed"; then echo "FAIL: expected native package '$req_pkg' is not installed in rootfs" >&2 exit 1 @@ -364,6 +364,15 @@ for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit", "root/.config/htop/htoprc", "root/.lynx.cfg", "root/.apexrc", + "usr/bin/xsetroot", + "usr/bin/xsettingsd", + "usr/bin/geminux-sync-gtk-theme", + "etc/skel/.gtkrc-2.0", + "etc/skel/.config/gtk-3.0/settings.ini", + "etc/skel/.config/xsettingsd/xsettingsd.conf", + "home/user/.gtkrc-2.0", + "home/user/.config/gtk-3.0/settings.ini", + "home/user/.config/xsettingsd/xsettingsd.conf", "etc/NetworkManager/dispatcher.d/30-geminux-chrony", "etc/polkit-1/rules.d/10-geminux.rules"): if not os.path.lexists(os.path.join(rootfs, req_rel)): diff --git a/scripts/rootfs-packages.txt b/scripts/rootfs-packages.txt index f9f0275..3a4a336 100644 --- a/scripts/rootfs-packages.txt +++ b/scripts/rootfs-packages.txt @@ -183,6 +183,7 @@ xkeyboard-config xrandr xrdb xset +xsettingsd xsetroot yabasic yt-dlp-core diff --git a/scripts/test-theme-dunst-sync.py b/scripts/test-theme-dunst-sync.py index c0d3a63..3923bad 100755 --- a/scripts/test-theme-dunst-sync.py +++ b/scripts/test-theme-dunst-sync.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Verify all Geminux .xth themes and dunst theme synchronization.""" +"""Verify all Geminux .xth themes, dunst synchronization, and GTK2/GTK3 synchronization.""" import glob import os @@ -11,6 +11,9 @@ import tempfile BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) THEMES_DIR = os.path.join(BASE_DIR, "overlay", "rootfs", "etc", "skel", ".xthemes") SYNC_SCRIPT = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "bin", "geminux-sync-dunst-theme") +GTK_SYNC_SCRIPT = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "bin", "geminux-sync-gtk-theme") + +LIGHT_THEMES = frozenset({"CatppuccinLatte", "GruvboxLight", "SolarizedLight"}) REQUIRED_KEYS = ( "theme.name", "theme.fontFace", "theme.iconFontFace", "theme.baseFontSize", @@ -42,7 +45,7 @@ def main(): assert len(themes) >= 20, f"Expected >= 20 themes, found {len(themes)}" with tempfile.TemporaryDirectory(prefix="geminux-dunst-test-") as tmp: - for th in themes: + for idx, th in enumerate(themes): vals = parse_xres(th) for req in REQUIRED_KEYS: assert req in vals and vals[req], f"Missing {req} in {os.path.basename(th)}" @@ -66,7 +69,76 @@ def main(): assert "font = Fira Code " in txt assert "width = 720" in txt - print(f"[PASS] Verified {len(themes)} .xth themes and dunst synchronization") + th_home = os.path.join(tmp, f"home-{idx}") + os.makedirs(th_home, exist_ok=True) + gtk_env = { + k: v for k, v in os.environ.items() + if k not in ( + "GEMINUX_GTK_THEMES_DIR", "GEMINUX_XDG_THEMES_DIR", + "GEMINUX_GTK2_RC", "GEMINUX_GTK3_DIR", "GEMINUX_XSETTINGSD_CONF", + ) + } + gtk_env["HOME"] = th_home + gtk_env["GEMINUX_XRESOURCES"] = th + subprocess.run([GTK_SYNC_SCRIPT, "--no-reload"], env=gtk_env, check=True) + + tname = vals["theme.name"] + gtk_name = f"Geminux-{tname}" + theme_root = os.path.join(th_home, ".themes", gtk_name) + is_light = tname in LIGHT_THEMES + + for cfg_rel in (".gtkrc-2.0", ".config/gtk-3.0/settings.ini", ".config/xsettingsd/xsettingsd.conf"): + cfg_path = os.path.join(th_home, cfg_rel) + with open(cfg_path, encoding="utf-8") as cf: + cfg_txt = cf.read() + assert gtk_name in cfg_txt, f"Missing {gtk_name} in {cfg_rel} for {tname}" + assert "/tmp" not in cfg_txt and "/home" not in cfg_txt, ( + f"Hardcoded path leaked into {cfg_rel} for {tname}: {cfg_txt}" + ) + + with open(os.path.join(th_home, ".config/gtk-3.0/settings.ini"), encoding="utf-8") as sf: + ini_txt = sf.read() + exp_dark_bool = "false" if is_light else "true" + assert f"gtk-application-prefer-dark-theme={exp_dark_bool}" in ini_txt, ( + f"Expected gtk-application-prefer-dark-theme={exp_dark_bool} for {tname}" + ) + + with open(os.path.join(th_home, ".config/xsettingsd/xsettingsd.conf"), encoding="utf-8") as xf: + xsd_txt = xf.read() + assert f'Net/ThemeName "{gtk_name}"' in xsd_txt + assert "Xft/DPI" not in xsd_txt, f"Unexpected Xft/DPI in xsettingsd.conf for {tname}" + + with open(os.path.join(theme_root, "index.theme"), encoding="utf-8") as itf: + idx_txt = itf.read() + assert f"GtkTheme={gtk_name}" in idx_txt + + with open(os.path.join(theme_root, "gtk-2.0/gtkrc"), encoding="utf-8") as rc2f: + rc2_txt = rc2f.read() + assert 'engine "' not in rc2_txt, f"External GTK2 engine referenced in {tname}" + for ck in ("theme.bgMain", "theme.fgMain", "theme.selBg", "theme.accent"): + assert vals[ck] in rc2_txt, f"Missing {ck} in gtkrc for {tname}" + + with open(os.path.join(theme_root, "gtk-3.0/gtk.css"), encoding="utf-8") as css3f: + css3_txt = css3f.read() + exp_base = "gtk-contained.css" if is_light else "gtk-contained-dark.css" + assert f'@import url("resource:///org/gtk/libgtk/theme/Adwaita/{exp_base}");' in css3_txt, ( + f"Wrong Adwaita base CSS in {tname}: expected {exp_base}" + ) + assert css3_txt.count("{") == css3_txt.count("}"), f"Unbalanced braces in gtk.css for {tname}" + for ck in ("theme.bgMain", "theme.fgMain", "theme.selBg", "theme.accent", "theme.dangerBg"): + assert vals[ck] in css3_txt, f"Missing {ck} in gtk.css for {tname}" + + with open(os.path.join(theme_root, "gtk-3.0/gtk-dark.css"), encoding="utf-8") as css3df: + assert '@import url("gtk.css");' in css3df.read() + + xdg_link = os.path.join(th_home, ".local/share/themes", gtk_name) + assert os.path.islink(xdg_link), f"Missing XDG symlink {xdg_link}" + assert os.readlink(xdg_link) == f"../../../.themes/{gtk_name}", ( + f"Unexpected XDG symlink target for {tname}: {os.readlink(xdg_link)}" + ) + assert os.path.isfile(os.path.join(xdg_link, "gtk-3.0/gtk.css")) + + print(f"[PASS] Verified {len(themes)} .xth themes, dunst synchronization, and GTK2/GTK3 theme generation") return 0 diff --git a/scripts/test-webarchy-renderer.py b/scripts/test-webarchy-renderer.py index 6a05ed1..de46efc 100755 --- a/scripts/test-webarchy-renderer.py +++ b/scripts/test-webarchy-renderer.py @@ -67,9 +67,11 @@ int main(int argc, char** argv) { ::setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "0", 1); ::setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "0", 1); ::setenv("JSC_useJIT", "0", 1); + ::unsetenv("GTK_THEME"); configureWebkitRenderer(false); CHECK(::getenv("WEBKIT_DISABLE_DMABUF_RENDERER") == nullptr); CHECK(::getenv("WEBKIT_DISABLE_COMPOSITING_MODE") == nullptr); + CHECK(::getenv("GTK_THEME") == nullptr); CHECK(std::string(::getenv("JSC_useJIT")) == "0"); FILE* f = std::fopen(flag.c_str(), "wb"); diff --git a/src/geminux-apps/geminux-themes.c b/src/geminux-apps/geminux-themes.c index e46fafc..668fdbf 100644 --- a/src/geminux-apps/geminux-themes.c +++ b/src/geminux-apps/geminux-themes.c @@ -79,7 +79,7 @@ static void apply_selected(themes_state_t *st) { const char *argv[] = {"/usr/bin/geminux-apply-theme", st->items[st->sel].name, NULL}; int rc = gemui_run_cmd_capture(argv, NULL, 0); gemui_theme_reload(st->app); - gemui_show_toast(st->app, rc == 0 ? "Applied .Xresources + dunst theme" : "Theme apply failed", 2000); + gemui_show_toast(st->app, rc == 0 ? "Applied .Xresources, GTK2/GTK3 & dunst theme" : "Theme apply failed", 2000); gemui_request_redraw(st->app); } @@ -146,7 +146,7 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) { } gemui_draw_button(app, cr, (gemui_rect_t){right_x, h - 94, right_w, 74}, - "Apply Across DWM, st, dmenu, dunst & Apps", HIT_APPLY, 0, true, false, false); + "Apply Across DWM, st, dmenu, dunst, GTK2/3 & Apps", HIT_APPLY, 0, true, false, false); } static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) { diff --git a/src/webarchy/webarchy.cpp b/src/webarchy/webarchy.cpp index 46c7e3d..579150c 100644 --- a/src/webarchy/webarchy.cpp +++ b/src/webarchy/webarchy.cpp @@ -75,7 +75,6 @@ void configureWebkitRenderer(bool software) { ::unsetenv("WEBKIT_DISABLE_COMPOSITING_MODE"); ::unsetenv("WEBKIT_SKIA_ENABLE_CPU_RENDERING"); ::setenv("GDK_BACKEND", "x11", 1); - ::setenv("GTK_THEME", "Adwaita:dark", 1); ::setenv("NO_AT_BRIDGE", "1", 1); ::setenv("GTK_A11Y", "none", 1); ::setenv("WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS", "1", 1); @@ -322,6 +321,7 @@ static const UaPreset kUaPresets[] = { }; struct XresTheme { + std::string name = "GeminuxHelio"; std::string fontFace = "Fira Code, Noto Sans"; std::string bgMain = "#0f1419"; std::string bgBar = "#0b0e14"; @@ -370,6 +370,7 @@ XresTheme loadXresourcesTheme() { auto it = kv.find(k); if (it != kv.end() && !it->second.empty()) dst = it->second; }; + pick("theme.name", t.name); pick("theme.fontFace", t.fontFace); pick("theme.bgMain", t.bgMain); pick("theme.bgBar", t.bgBar); @@ -478,14 +479,54 @@ struct BrowserApp { bool syncingUiFlags = false; }; +bool isDarkHexColor(const std::string& hex) { + if (hex.size() != 7 || hex[0] != '#') return true; + auto hexByte = [&](size_t pos, int& out) -> bool { + auto nib = [](char c) -> int { + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return 10 + (c - 'a'); + if (c >= 'A' && c <= 'F') return 10 + (c - 'A'); + return -1; + }; + int hi = nib(hex[pos]); + int lo = nib(hex[pos + 1]); + if (hi < 0 || lo < 0) return false; + out = (hi << 4) | lo; + return true; + }; + int r = 0, g = 0, b = 0; + if (!hexByte(1, r) || !hexByte(3, g) || !hexByte(5, b)) return true; + double lum = 0.2126 * r + 0.7152 * g + 0.0722 * b; + return lum < 128.0; +} + +std::string sanitizeGtkThemeSuffix(const std::string& raw) { + std::string out; + for (unsigned char ch : raw) { + if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || + (ch >= '0' && ch <= '9') || ch == '.' || ch == '_' || ch == '-') { + out.push_back(static_cast(ch)); + } + } + return out.empty() ? "GeminuxHelio" : out; +} + void applyGtkThemeCss(BrowserApp* app) { if (!app || !app->cssProvider) return; XresTheme t = loadXresourcesTheme(); std::string gtkFont = t.fontFace + ", Noto Sans 9"; + bool preferDark = isDarkHexColor(t.bgMain); + std::string candidateTheme = "Geminux-" + sanitizeGtkThemeSuffix(t.name); + std::string homeThemeCss = getHomeDirPath() + "/.themes/" + candidateTheme + "/gtk-3.0/gtk.css"; + std::string sysThemeCss = "/usr/share/themes/" + candidateTheme + "/gtk-3.0/gtk.css"; + std::string gtkThemeName = + (::access(homeThemeCss.c_str(), R_OK) == 0 || ::access(sysThemeCss.c_str(), R_OK) == 0) + ? candidateTheme + : "Adwaita"; if (GtkSettings* gs = gtk_settings_get_default()) { g_object_set(gs, - "gtk-application-prefer-dark-theme", TRUE, - "gtk-theme-name", "Adwaita:dark", + "gtk-application-prefer-dark-theme", preferDark ? TRUE : FALSE, + "gtk-theme-name", gtkThemeName.c_str(), "gtk-font-name", gtkFont.c_str(), nullptr); }