diff --git a/overlay/rootfs/etc/skel/.Xresources b/overlay/rootfs/etc/skel/.Xresources index b6df279..d59a60d 100644 --- a/overlay/rootfs/etc/skel/.Xresources +++ b/overlay/rootfs/etc/skel/.Xresources @@ -1,73 +1,96 @@ -! Geminux Unified Theme: GeminuxHelio -theme.name: GeminuxHelio +! Geminux Unified Theme: Anodized (Obsidian & brushed silver, brass-amber highlight, Fira Code + Nerd Fonts) +theme.name: Anodized +theme.isDark: 1 theme.fontFace: Fira Code +theme.uiFontFace: Roboto theme.iconFontFace: DejaVuSansM Nerd Font theme.baseFontSize: 32 +theme.gtkTheme: Geminux-Anodized +theme.qtTheme: Fusion +theme.iconTheme: Adwaita +*TkTheme: gtkTtk -theme.bgMain: #0f1419 -theme.bgBar: #0b0e14 -theme.bgHeader: #131922 -theme.bgFooter: #0b0e14 -theme.bgOverlay: #161d26 -theme.bgAltEven: #121820 -theme.bgAltOdd: #18202a -theme.bgInput: #0b0e14 -theme.bgInputFocus: #1b2838 -theme.bgButton: #1d2633 -theme.bgSearch: #243040 -theme.bgBubbleIn: #1b2632 -theme.bgBubbleOut: #1c3244 -theme.bgToast: #132230 +Xft.dpi: 192 +Xft.antialias: 1 +Xft.hinting: 1 +Xft.hintstyle: hintslight +Xft.rgba: rgb +Xcursor.theme: default +Xcursor.size: 64 -theme.fgMain: #e6e1cf -theme.fgBright: #ffffff -theme.fgMuted: #7b8898 +theme.bgMain: #08090b +theme.bgBar: #0e1014 +theme.bgHeader: #12151a +theme.bgFooter: #0b0d11 +theme.bgOverlay: #171b22 +theme.bgAltEven: #101318 +theme.bgAltOdd: #14181f +theme.bgInput: #161a21 +theme.bgInputFocus: #1e232c +theme.bgButton: #1c212a +theme.bgSearch: #191e27 +theme.bgBubbleIn: #181d25 +theme.bgBubbleOut: #252c38 +theme.bgToast: #1c222b +theme.fgMain: #e4e8ee +theme.fgBright: #f5f7fa +theme.fgMuted: #89929f +theme.selBg: #38414f +theme.selFg: #f5f7fa +theme.accent: #cfd6e0 +theme.accentAlt: #e5eaf0 +theme.highlight: #e2bc72 +theme.border: #2d3440 +theme.divider: #20252f +theme.success: #79cf9c +theme.info: #9eb3c8 +theme.warning: #e2bc72 +theme.danger: #e07a7a +theme.dangerBg: #3f1d20 -theme.selBg: #2b5278 -theme.selFg: #ffffff -theme.accent: #59c2ff -theme.accentAlt: #ffb454 -theme.highlight: #ff8f40 -theme.border: #283444 -theme.divider: #364559 - -theme.success: #7fd962 -theme.info: #59c2ff -theme.warning: #ffb454 -theme.danger: #f07178 -theme.dangerBg: #4c1d24 +dwm.borderpx: 4 +dwm.font: Fira Code, DejaVuSansM Nerd Font 38px +dwm.background: #0e1014 +dwm.foreground: #e4e8ee +dwm.border: #2d3440 +dwm.selbackground: #38414f +dwm.selforeground: #f5f7fa +dwm.selborder: #cfd6e0 +dwm.normbgcolor: #0e1014 +dwm.normfgcolor: #e4e8ee +dwm.normbordercolor: #2d3440 +dwm.selbgcolor: #38414f +dwm.selfgcolor: #f5f7fa +dwm.selbordercolor: #cfd6e0 dmenu.font: Fira Code, DejaVuSansM Nerd Font 40px -dmenu.background: #0b0e14 -dmenu.foreground: #e6e1cf -dmenu.selbackground: #2b5278 -dmenu.selforeground: #ffffff -dmenu.outbackground: #243040 -dmenu.outforeground: #ffffff -dmenu.highlight: #ffb454 - -dwm.font: Fira Code, DejaVuSansM Nerd Font 38px -dwm.background: #0b0e14 -dwm.foreground: #e6e1cf -dwm.border: #283444 -dwm.selbackground: #2b5278 -dwm.selforeground: #ffffff -dwm.selborder: #59c2ff -dwm.normbgcolor: #0b0e14 -dwm.normbordercolor: #283444 -dwm.normfgcolor: #e6e1cf -dwm.selbgcolor: #2b5278 -dwm.selbordercolor: #59c2ff -dwm.selfgcolor: #ffffff -dwm.borderpx: 4 +dmenu.background: #12151a +dmenu.foreground: #e4e8ee +dmenu.selbackground: #38414f +dmenu.selforeground: #f5f7fa +dmenu.outbackground: #191e27 +dmenu.outforeground: #cfd6e0 +dmenu.highlight: #e2bc72 st.font: Fira Code:pixelsize=44:style=Regular:antialias=true:autohint=true st.termname: xterm-256color -st.background: #0f1419 -st.foreground: #e6e1cf -st.cursorColor: #59c2ff - -Xft.dpi: 192 -Xcursor.theme: default -Xcursor.size: 64 -*TkTheme: gtkTtk +st.background: #08090b +st.foreground: #e4e8ee +st.cursorColor: #cfd6e0 +st.revCursorColor: #08090b +st.color0: #08090b +st.color1: #d97878 +st.color2: #79cf9c +st.color3: #e2bc72 +st.color4: #8ba6c4 +st.color5: #b39bc8 +st.color6: #84b8be +st.color7: #d5dce4 +st.color8: #5b6370 +st.color9: #eb9494 +st.color10: #96deb3 +st.color11: #edd092 +st.color12: #a6bdd6 +st.color13: #cab5dc +st.color14: #a2cdd2 +st.color15: #f5f7fa diff --git a/overlay/rootfs/usr/bin/geminux-apply-theme b/overlay/rootfs/usr/bin/geminux-apply-theme index 6f86903..37760f8 100755 --- a/overlay/rootfs/usr/bin/geminux-apply-theme +++ b/overlay/rootfs/usr/bin/geminux-apply-theme @@ -108,6 +108,13 @@ if [ -n "${DISPLAY:-}" ] && command -v xrdb >/dev/null 2>&1; then xrdb -nocpp -load "$HOME_DIR/.Xresources" >/dev/null 2>&1 || true fi +WP_CONF="${XDG_CONFIG_HOME:-$HOME_DIR/.config}/geminux/wallpaper.conf" +if [ -n "${DISPLAY:-}" ] && [ -r "$WP_CONF" ] && grep -q '^USE_THEME_BG=1$' "$WP_CONF" 2>/dev/null; then + if command -v geminux-apply-wallpaper >/dev/null 2>&1; then + geminux-apply-wallpaper --restore >/dev/null 2>&1 || true + fi +fi + if [ -n "${DISPLAY:-}" ] && [ "${GEMINUX_NO_SIGNAL:-0}" != "1" ]; then _pids="$( (ps -eo pid=,comm= 2>/dev/null || ps -ax -o pid=,comm= 2>/dev/null || true) | awk ' { diff --git a/overlay/rootfs/usr/bin/geminux-apply-wallpaper b/overlay/rootfs/usr/bin/geminux-apply-wallpaper new file mode 100755 index 0000000..059f065 --- /dev/null +++ b/overlay/rootfs/usr/bin/geminux-apply-wallpaper @@ -0,0 +1,34 @@ +#!/bin/sh +# Apply or restore the Geminux desktop wallpaper via geminux-themes CLI engine (POSIX sh) +set -eu + +case "${1:-}" in + -h|--help) + printf 'Usage:\n' + printf ' geminux-apply-wallpaper [--restore]\n' + printf ' geminux-apply-wallpaper IMAGE_PATH [--mode fill|fit|center|tile|stretch|span] [--bg #RRGGBB|theme] [--no-save]\n' + printf ' geminux-apply-wallpaper --solid #RRGGBB [--no-save]\n' + printf ' geminux-apply-wallpaper --theme-bg [--no-save]\n' + exit 0 + ;; +esac + +SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" + +if [ -x "$SCRIPT_DIR/geminux-themes" ]; then + BIN="$SCRIPT_DIR/geminux-themes" +elif command -v geminux-themes >/dev/null 2>&1; then + BIN="$(command -v geminux-themes)" +else + printf 'geminux-apply-wallpaper: geminux-themes executable not found\n' >&2 + exit 1 +fi + +case "${1:-}" in + ""|--restore) + exec "$BIN" --restore-wallpaper + ;; + *) + exec "$BIN" --apply-wallpaper "$@" + ;; +esac diff --git a/overlay/rootfs/usr/bin/geminux-launcher b/overlay/rootfs/usr/bin/geminux-launcher index 1017d5a..394f854 100755 --- a/overlay/rootfs/usr/bin/geminux-launcher +++ b/overlay/rootfs/usr/bin/geminux-launcher @@ -32,6 +32,7 @@ LAUNCHER_LIST="  Control Center|geminux-control 󰥔 Date & Timezone|geminux-datetime  Themes|geminux-themes +󰸉 Wallpaper|geminux-themes --wallpaper  Lock Screen|geminux-lock 󰤄 Suspend Now|doas /usr/bin/geminux-power-ctl suspend " diff --git a/overlay/rootfs/usr/bin/geminux-session b/overlay/rootfs/usr/bin/geminux-session index 1d8c136..73e3ddf 100755 --- a/overlay/rootfs/usr/bin/geminux-session +++ b/overlay/rootfs/usr/bin/geminux-session @@ -60,6 +60,11 @@ if command -v geminux-sync-gtk-theme >/dev/null 2>&1; then geminux-sync-gtk-theme --no-reload 2>/dev/null || true fi +WP_CONF="${XDG_CONFIG_HOME:-$HOME_DIR/.config}/geminux/wallpaper.conf" +if [ -n "${DISPLAY:-}" ] && [ -r "$WP_CONF" ] && command -v geminux-apply-wallpaper >/dev/null 2>&1; then + geminux-apply-wallpaper --restore >/dev/null 2>&1 || 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 diff --git a/overlay/rootfs/usr/bin/geminux-sync-dunst-theme b/overlay/rootfs/usr/bin/geminux-sync-dunst-theme index abd3171..795ec72 100755 --- a/overlay/rootfs/usr/bin/geminux-sync-dunst-theme +++ b/overlay/rootfs/usr/bin/geminux-sync-dunst-theme @@ -37,15 +37,15 @@ if [ -r "$XRES_FILE" ]; then ' "$XRES_FILE")" fi -BG_MAIN="${X_bgMain:-#0f1419}" +BG_MAIN="${X_bgMain:-#08090b}" BG_OVERLAY="${X_bgOverlay:-${X_bgHeader:-$BG_MAIN}}" -FG_MAIN="${X_fgMain:-#e6e1cf}" +FG_MAIN="${X_fgMain:-#e4e8ee}" FG_BRIGHT="${X_fgBright:-$FG_MAIN}" -FG_MUTED="${X_fgMuted:-#7b8898}" -ACCENT="${X_accent:-${X_selBg:-#59c2ff}}" -BORDER="${X_border:-#283444}" -DANGER="${X_danger:-#f07178}" -DANGER_BG="${X_dangerBg:-#4c1d24}" +FG_MUTED="${X_fgMuted:-#89929f}" +ACCENT="${X_accent:-${X_selBg:-#cfd6e0}}" +BORDER="${X_border:-#2d3440}" +DANGER="${X_danger:-#e07a7a}" +DANGER_BG="${X_dangerBg:-#3f1d20}" FONT_FACE="${X_fontFace:-Fira Code}" BASE_SIZE="${X_baseFontSize:-32}" diff --git a/overlay/rootfs/usr/bin/geminux-sync-gtk-theme b/overlay/rootfs/usr/bin/geminux-sync-gtk-theme index 52fe148..ebdddfe 100755 --- a/overlay/rootfs/usr/bin/geminux-sync-gtk-theme +++ b/overlay/rootfs/usr/bin/geminux-sync-gtk-theme @@ -52,12 +52,12 @@ if [ -r "$XRES_FILE" ]; then ' "$XRES_FILE")" fi -RAW_NAME="${X_theme_name:-GeminuxHelio}" +RAW_NAME="${X_theme_name:-Anodized}" SAFE_NAME="$(printf '%s' "$RAW_NAME" | tr -cd 'A-Za-z0-9._-')" -[ -n "$SAFE_NAME" ] || SAFE_NAME="GeminuxHelio" +[ -n "$SAFE_NAME" ] || SAFE_NAME="Anodized" GTK_THEME_NAME="Geminux-$SAFE_NAME" -BG_MAIN="${X_theme_bgMain:-#0f1419}" +BG_MAIN="${X_theme_bgMain:-#08090b}" BG_BAR="${X_theme_bgBar:-$BG_MAIN}" BG_HEADER="${X_theme_bgHeader:-$BG_MAIN}" BG_FOOTER="${X_theme_bgFooter:-$BG_HEADER}" @@ -68,21 +68,21 @@ BG_INPUT="${X_theme_bgInput:-$BG_MAIN}" BG_BUTTON="${X_theme_bgButton:-$BG_ALT_EVEN}" BG_INPUT_FOCUS="${X_theme_bgInputFocus:-$BG_BUTTON}" BG_SEARCH="${X_theme_bgSearch:-$BG_BUTTON}" -FG_MAIN="${X_theme_fgMain:-#e6e1cf}" +FG_MAIN="${X_theme_fgMain:-#e4e8ee}" FG_BRIGHT="${X_theme_fgBright:-$FG_MAIN}" -FG_MUTED="${X_theme_fgMuted:-#7b8898}" -SEL_BG="${X_theme_selBg:-#2b5278}" -SEL_FG="${X_theme_selFg:-#ffffff}" +FG_MUTED="${X_theme_fgMuted:-#89929f}" +SEL_BG="${X_theme_selBg:-#38414f}" +SEL_FG="${X_theme_selFg:-#f5f7fa}" ACCENT="${X_theme_accent:-$SEL_BG}" ACCENT_ALT="${X_theme_accentAlt:-$ACCENT}" HIGHLIGHT="${X_theme_highlight:-$ACCENT}" -BORDER="${X_theme_border:-#283444}" +BORDER="${X_theme_border:-#2d3440}" DIVIDER="${X_theme_divider:-$BORDER}" -SUCCESS="${X_theme_success:-#2ecc71}" -INFO="${X_theme_info:-#5dade2}" -WARNING="${X_theme_warning:-#e67e22}" -DANGER="${X_theme_danger:-#f07178}" -DANGER_BG="${X_theme_dangerBg:-#4c1d24}" +SUCCESS="${X_theme_success:-#79cf9c}" +INFO="${X_theme_info:-#9eb3c8}" +WARNING="${X_theme_warning:-#e2bc72}" +DANGER="${X_theme_danger:-#e07a7a}" +DANGER_BG="${X_theme_dangerBg:-#3f1d20}" FONT_FACE="${X_theme_fontFace:-Fira Code}" [ -n "$FONT_FACE" ] || FONT_FACE="Fira Code" diff --git a/prebuilt/geminux/usr/bin/geminux-net b/prebuilt/geminux/usr/bin/geminux-net index e52c68e..acebd8f 100755 Binary files a/prebuilt/geminux/usr/bin/geminux-net and b/prebuilt/geminux/usr/bin/geminux-net differ diff --git a/prebuilt/geminux/usr/bin/geminux-themes b/prebuilt/geminux/usr/bin/geminux-themes index 5958bb4..72d90b2 100755 Binary files a/prebuilt/geminux/usr/bin/geminux-themes and b/prebuilt/geminux/usr/bin/geminux-themes differ diff --git a/prebuilt/geminux/usr/lib/libgemui.so b/prebuilt/geminux/usr/lib/libgemui.so index 41ce05d..e70af65 100755 Binary files a/prebuilt/geminux/usr/lib/libgemui.so and b/prebuilt/geminux/usr/lib/libgemui.so differ diff --git a/prebuilt/suckless/usr/bin/dmenu b/prebuilt/suckless/usr/bin/dmenu index acf916d..32388cb 100755 Binary files a/prebuilt/suckless/usr/bin/dmenu and b/prebuilt/suckless/usr/bin/dmenu differ diff --git a/prebuilt/suckless/usr/bin/dwm b/prebuilt/suckless/usr/bin/dwm index cf01f15..25c47f4 100755 Binary files a/prebuilt/suckless/usr/bin/dwm and b/prebuilt/suckless/usr/bin/dwm differ diff --git a/prebuilt/suckless/usr/bin/st b/prebuilt/suckless/usr/bin/st index bfdfe53..bf4193b 100755 Binary files a/prebuilt/suckless/usr/bin/st and b/prebuilt/suckless/usr/bin/st differ diff --git a/prebuilt/webarchy/usr/bin/webarchy b/prebuilt/webarchy/usr/bin/webarchy index e47f933..ca6d001 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 a24a6ca..ee43bb5 100755 --- a/scripts/apply-geminux-overlay.sh +++ b/scripts/apply-geminux-overlay.sh @@ -219,6 +219,12 @@ mkdir -p "$TARGET_ROOTFS/home/user/.cache" "$TARGET_ROOTFS/home/user/.config" \ "$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 + rm -rf "$TARGET_ROOTFS/etc/skel/.themes"/Geminux-* \ + "$TARGET_ROOTFS/etc/skel/.local/share/themes"/Geminux-* \ + "$TARGET_ROOTFS/etc/skel/.config/qt6ct/colors"/Geminux-*.conf \ + "$TARGET_ROOTFS/home/user/.themes"/Geminux-* \ + "$TARGET_ROOTFS/home/user/.local/share/themes"/Geminux-* \ + "$TARGET_ROOTFS/home/user/.config/qt6ct/colors"/Geminux-*.conf HOME="$TARGET_ROOTFS/etc/skel" \ GEMINUX_RUNTIME_HOME="/home/user" \ GEMINUX_XRESOURCES="$TARGET_ROOTFS/etc/skel/.Xresources" \ diff --git a/scripts/build-geminux-ui.sh b/scripts/build-geminux-ui.sh index 22a763c..60dd24f 100755 --- a/scripts/build-geminux-ui.sh +++ b/scripts/build-geminux-ui.sh @@ -54,6 +54,7 @@ EOF libx11-dev \ libxft-dev \ libxext-dev \ + libxinerama-dev \ libxrandr-dev \ libxi-dev \ libxtst-dev \ @@ -63,6 +64,7 @@ EOF glib-dev \ libjpeg-turbo-dev \ libpng-dev \ + libwebp-dev \ fontconfig-dev \ freetype-dev \ expat-dev \ diff --git a/scripts/check-rebuild.sh b/scripts/check-rebuild.sh index 6fd4365..ba97b76 100755 --- a/scripts/check-rebuild.sh +++ b/scripts/check-rebuild.sh @@ -382,7 +382,7 @@ for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit", "etc/skel/.config/gtk-4.0/gtk.css", "etc/skel/.config/qt6ct/qt6ct.conf", "etc/skel/.config/qt6ct/colors/Geminux.conf", - "etc/skel/.config/qt6ct/colors/Geminux-GeminuxHelio.conf", + "etc/skel/.config/qt6ct/colors/Geminux-Anodized.conf", "etc/skel/.config/Kvantum/kvantum.kvconfig", "etc/skel/.config/Kvantum/Geminux/Geminux.kvconfig", "etc/skel/.config/xsettingsd/xsettingsd.conf", @@ -393,12 +393,13 @@ for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit", "home/user/.config/gtk-4.0/gtk.css", "home/user/.config/qt6ct/qt6ct.conf", "home/user/.config/qt6ct/colors/Geminux.conf", - "home/user/.config/qt6ct/colors/Geminux-GeminuxHelio.conf", + "home/user/.config/qt6ct/colors/Geminux-Anodized.conf", "home/user/.config/Kvantum/kvantum.kvconfig", "home/user/.config/Kvantum/Geminux/Geminux.kvconfig", "home/user/.config/xsettingsd/xsettingsd.conf", "etc/NetworkManager/dispatcher.d/30-geminux-chrony", - "etc/polkit-1/rules.d/10-geminux.rules"): + "etc/polkit-1/rules.d/10-geminux.rules", + "usr/bin/geminux-apply-wallpaper"): if not os.path.lexists(os.path.join(rootfs, req_rel)): raise SystemExit(f"FAIL: missing required path {os.path.join(rootfs, req_rel)}") if os.path.lexists(os.path.join(rootfs, "usr/lib/geminux-mpv")): @@ -424,10 +425,12 @@ for rel, needle in ( ("etc/shells", "/bin/bash"), ("etc/profile.d/10-geminux-env.sh", "QT_QPA_PLATFORMTHEME=qt6ct:gtk3"), ("etc/profile.d/10-geminux-env.sh", "ADW_DISABLE_PORTAL=1"), + ("etc/skel/.Xresources", "theme.name: Anodized"), ("etc/skel/.Xresources", "*TkTheme: gtkTtk"), - ("etc/skel/.config/qt6ct/qt6ct.conf", "color_scheme_path=/home/user/.config/qt6ct/colors/Geminux-GeminuxHelio.conf"), + ("etc/skel/.config/qt6ct/qt6ct.conf", "color_scheme_path=/home/user/.config/qt6ct/colors/Geminux-Anodized.conf"), ("usr/bin/geminux-launcher", "Webarchy Browser"), ("usr/bin/geminux-launcher", "Bantam AI agent"), + ("usr/bin/geminux-launcher", "Wallpaper"), ): p = os.path.join(rootfs, rel) with open(p, "r", encoding="utf-8") as f: @@ -445,6 +448,20 @@ with open(os.path.join(repo_dir, "src/dwm/dwm.c"), "r", encoding="utf-8") as f: dwm_src = f.read() if "PropertyChangeMask |\n FocusChangeMask;" not in dwm_src or "NotifyWhileGrabbed" not in dwm_src: raise SystemExit("FAIL: src/dwm/dwm.c missing root FocusChangeMask or NotifyWhileGrabbed guard") +for sym in ("render_opcode", "in_xerror", "XAllowEvents(dpy, AsyncBoth, CurrentTime)", "XUngrabPointer(dpy, CurrentTime)"): + if sym not in dwm_src: + raise SystemExit(f"FAIL: src/dwm/dwm.c missing {sym}") +with open(os.path.join(repo_dir, "src/dmenu/dmenu.c"), "r", encoding="utf-8") as f: + dmenu_src = f.read() +for sym in ("dmenu_xerror", "dmenu_render_opcode"): + if sym not in dmenu_src: + raise SystemExit(f"FAIL: src/dmenu/dmenu.c missing {sym}") +for drw_rel in ("src/dwm/drw.c", "src/dmenu/drw.c"): + with open(os.path.join(repo_dir, drw_rel), "r", encoding="utf-8") as f: + drw_src = f.read() + for sym in ("drw_fc_substitute", "drw_sanitize_utf8", "PANGO_ELLIPSIZE_END"): + if sym not in drw_src: + raise SystemExit(f"FAIL: {drw_rel} missing {sym}") with open(os.path.join(repo_dir, "src/st/x.c"), "r", encoding="utf-8") as f: stx_src = f.read() if 'ttywrite("\\033[I", 3, 0);\n\t\tredraw();' not in stx_src or 'ttywrite("\\033[O", 3, 0);\n\t\tredraw();' not in stx_src: diff --git a/scripts/test-theme-dunst-sync.py b/scripts/test-theme-dunst-sync.py index 32dd532..0585b7c 100755 --- a/scripts/test-theme-dunst-sync.py +++ b/scripts/test-theme-dunst-sync.py @@ -44,6 +44,8 @@ def main(): themes = sorted(glob.glob(os.path.join(THEMES_DIR, "*.xth"))) assert len(themes) >= 22, f"Expected >= 22 themes, found {len(themes)}" assert any(os.path.basename(th) == "Anodized.xth" for th in themes), "Missing Anodized.xth" + def_xres = parse_xres(os.path.join(BASE_DIR, "overlay", "rootfs", "etc", "skel", ".Xresources")) + assert def_xres.get("theme.name") == "Anodized", f"Expected default theme Anodized, got {def_xres.get('theme.name')}" with tempfile.TemporaryDirectory(prefix="geminux-dunst-test-") as tmp: for idx, th in enumerate(themes): @@ -280,7 +282,87 @@ def main(): assert os.path.isfile(xth_dunstrc) assert os.path.isfile(os.path.join(xth_home, ".themes/Geminux-Custom_Test/gtk-3.0/gtk.css")) - print(f"[PASS] Verified {len(themes)} .xth themes, geminux-xth.h, dunst synchronization, and GTK2/3/4/Qt/Tk theme generation") + wp_hdr = os.path.join(BASE_DIR, "src", "geminux-apps", "geminux-wallpaper.h") + wp_c = os.path.join(tmp, "test_wp.c") + wp_bin = os.path.join(tmp, "test_wp") + wp_dir = os.path.join(tmp, "wp_cfg_dir") + wp_conf = os.path.join(wp_dir, "wallpaper.conf") + with open(wp_c, "w", encoding="utf-8") as cf: + cf.write( + '#include \n' + '#include \n' + '#include \n' + '#include \n' + f'#include "{wp_hdr}"\n' + 'int main(void) {\n' + ' geminux_wp_mode_t m = GEMINUX_WP_FILL;\n' + ' assert(strcmp(geminux_wp_mode_name(GEMINUX_WP_FILL), "fill") == 0);\n' + ' assert(strcmp(geminux_wp_mode_label(GEMINUX_WP_SPAN), "Span") == 0);\n' + ' assert(geminux_wp_mode_parse("FILL", &m) && m == GEMINUX_WP_FILL);\n' + ' assert(geminux_wp_mode_parse("Fit", &m) && m == GEMINUX_WP_FIT);\n' + ' assert(geminux_wp_mode_parse("center", &m) && m == GEMINUX_WP_CENTER);\n' + ' assert(geminux_wp_mode_parse("tile", &m) && m == GEMINUX_WP_TILE);\n' + ' assert(geminux_wp_mode_parse("stretch", &m) && m == GEMINUX_WP_STRETCH);\n' + ' assert(geminux_wp_mode_parse("span", &m) && m == GEMINUX_WP_SPAN);\n' + ' assert(geminux_wp_mode_parse("zoom", &m) && m == GEMINUX_WP_FILL);\n' + ' assert(!geminux_wp_mode_parse("bogus", &m));\n' + ' assert(geminux_wp_is_image_name("photo.JPG"));\n' + ' assert(geminux_wp_is_image_name("/home/user/Pictures/desk.webp"));\n' + ' assert(geminux_wp_is_image_name("vector.svg"));\n' + ' assert(!geminux_wp_is_image_name("notes.txt"));\n' + ' assert(!geminux_wp_is_image_name(".png"));\n' + ' assert(!geminux_wp_is_image_name("no_extension"));\n' + ' int r = -1, g = -1, b = -1;\n' + ' assert(geminux_wp_parse_hex("#1a2b3c", &r, &g, &b) && r == 0x1a && g == 0x2b && b == 0x3c);\n' + ' assert(geminux_wp_parse_hex("AABBCC", &r, &g, &b) && r == 0xaa && g == 0xbb && b == 0xcc);\n' + ' assert(!geminux_wp_parse_hex("#123", &r, &g, &b));\n' + ' assert(!geminux_wp_parse_hex("#gggggg", &r, &g, &b));\n' + ' double px = 0, py = 0, pw = 0, ph = 0;\n' + ' geminux_wp_calc_placement(1920, 1080, 1600, 1200, GEMINUX_WP_FILL, &px, &py, &pw, &ph);\n' + ' assert(fabs(ph - 1200.0) < 0.01 && pw > 1600.0 && px < 0.0 && fabs(py) < 0.01);\n' + ' geminux_wp_calc_placement(1920, 1080, 1600, 1200, GEMINUX_WP_FIT, &px, &py, &pw, &ph);\n' + ' assert(fabs(pw - 1600.0) < 0.01 && fabs(ph - 900.0) < 0.01 && fabs(px) < 0.01 && fabs(py - 150.0) < 0.01);\n' + ' geminux_wp_calc_placement(800, 600, 1600, 1200, GEMINUX_WP_CENTER, &px, &py, &pw, &ph);\n' + ' assert(fabs(pw - 800.0) < 0.01 && fabs(ph - 600.0) < 0.01 && fabs(px - 400.0) < 0.01 && fabs(py - 300.0) < 0.01);\n' + ' geminux_wp_calc_placement(800, 600, 1600, 1200, GEMINUX_WP_STRETCH, &px, &py, &pw, &ph);\n' + ' assert(fabs(px) < 0.01 && fabs(py) < 0.01 && fabs(pw - 1600.0) < 0.01 && fabs(ph - 1200.0) < 0.01);\n' + ' geminux_wp_cfg_t cfg, loaded;\n' + f' assert(!geminux_wp_cfg_load("{wp_conf}", &loaded));\n' + ' geminux_wp_cfg_init(&cfg);\n' + ' cfg.type = GEMINUX_WP_IMAGE;\n' + ' cfg.mode = GEMINUX_WP_FIT;\n' + ' snprintf(cfg.path, sizeof(cfg.path), "/home/user/Pictures/desk.png");\n' + ' snprintf(cfg.color, sizeof(cfg.color), "#112233");\n' + ' cfg.use_theme_bg = false;\n' + f' assert(geminux_wp_cfg_save("{wp_conf}", &cfg));\n' + f' assert(geminux_wp_cfg_load("{wp_conf}", &loaded));\n' + ' assert(loaded.type == GEMINUX_WP_IMAGE && loaded.mode == GEMINUX_WP_FIT);\n' + ' assert(strcmp(loaded.path, "/home/user/Pictures/desk.png") == 0);\n' + ' assert(strcmp(loaded.color, "#112233") == 0 && !loaded.use_theme_bg);\n' + ' cfg.type = GEMINUX_WP_SOLID;\n' + ' cfg.use_theme_bg = true;\n' + f' assert(geminux_wp_cfg_save("{wp_conf}", &cfg));\n' + f' assert(geminux_wp_cfg_load("{wp_conf}", &loaded));\n' + ' assert(loaded.type == GEMINUX_WP_SOLID && loaded.use_theme_bg);\n' + ' return 0;\n' + '}\n' + ) + subprocess.run(["cc", "-std=c11", "-Wall", "-Wextra", "-Werror", wp_c, "-o", wp_bin, "-lm"], check=True) + subprocess.run([wp_bin], check=True) + + wp_script = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "bin", "geminux-apply-wallpaper") + subprocess.run(["sh", "-n", wp_script], check=True) + wp_help = subprocess.run([wp_script, "--help"], capture_output=True, text=True, check=True) + assert "--restore" in wp_help.stdout and "--apply-wallpaper" not in wp_help.stdout + for srel, needle in ( + ("overlay/rootfs/usr/bin/geminux-session", "geminux-apply-wallpaper --restore"), + ("overlay/rootfs/usr/bin/geminux-apply-theme", "geminux-apply-wallpaper --restore"), + ("overlay/rootfs/usr/bin/geminux-launcher", "geminux-themes --wallpaper"), + ): + with open(os.path.join(BASE_DIR, srel), encoding="utf-8") as sf: + assert needle in sf.read(), f"Missing '{needle}' in {srel}" + + print(f"[PASS] Verified {len(themes)} .xth themes, geminux-xth.h, wallpaper helpers, dunst synchronization, and GTK2/3/4/Qt/Tk theme generation") return 0 diff --git a/src/dmenu/config.def.h b/src/dmenu/config.def.h index 3fdd53c..52dbb38 100644 --- a/src/dmenu/config.def.h +++ b/src/dmenu/config.def.h @@ -9,9 +9,9 @@ static const char *fonts[] = { static const char *prompt = NULL; static const char *colors[SchemeLast][2] = { /* fg bg */ - [SchemeNorm] = { "#e6e1cf", "#0b0e14" }, - [SchemeSel] = { "#ffffff", "#2b5278" }, - [SchemeOut] = { "#ffffff", "#243040" }, + [SchemeNorm] = { "#e4e8ee", "#12151a" }, + [SchemeSel] = { "#f5f7fa", "#38414f" }, + [SchemeOut] = { "#cfd6e0", "#191e27" }, }; static unsigned int lines = 12; static unsigned int lineheight = 82; diff --git a/src/dmenu/dmenu.c b/src/dmenu/dmenu.c index 8427b4e..790759f 100644 --- a/src/dmenu/dmenu.c +++ b/src/dmenu/dmenu.c @@ -64,6 +64,34 @@ static char xres_font[256] = ""; static char *dyn_colors[SchemeLast][2] = { {NULL, NULL}, {NULL, NULL}, {NULL, NULL} }; static Cursor vpointer = None, bpointer = None; static int pointer_hidden = 0, xi_opcode = -1, xfixes_ok = 0; +static int dmenu_render_opcode = -1; +static int (*dmenu_xerror_prev)(Display *, XErrorEvent *) = NULL; + +static int dmenu_xerror(Display *disp, XErrorEvent *ee) { + if (ee->error_code == BadWindow || ee->error_code == BadDrawable) + return 0; + if (dmenu_render_opcode > 0 && ee->request_code == dmenu_render_opcode) { + static unsigned int render_err_logged = 0; + if (render_err_logged < 8) { + render_err_logged++; + fprintf(stderr, "dmenu: ignoring non-fatal RENDER error: minor=%d, error=%d\n", + ee->minor_code, ee->error_code); + } + return 0; + } + { + static int in_xerror = 0; + if (in_xerror) return 0; + in_xerror = 1; + if (dmenu_xerror_prev && dmenu_xerror_prev != dmenu_xerror) { + int rc = dmenu_xerror_prev(disp, ee); + in_xerror = 0; + return rc; + } + in_xerror = 0; + return 0; + } +} #include "config.h" @@ -964,6 +992,14 @@ int main(int argc, char *argv[]) { fputs("warning: no locale support\n", stderr); if (!(dpy = XOpenDisplay(NULL))) die("cannot open display"); + { + int (*prev_err)(Display *, XErrorEvent *) = XSetErrorHandler(dmenu_xerror); + if (prev_err && prev_err != dmenu_xerror) + dmenu_xerror_prev = prev_err; + int rev = 0, rerr = 0; + if (!XQueryExtension(dpy, "RENDER", &dmenu_render_opcode, &rev, &rerr)) + dmenu_render_opcode = -1; + } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); diff --git a/src/dmenu/drw.c b/src/dmenu/drw.c index e91910c..ce35e05 100644 --- a/src/dmenu/drw.c +++ b/src/dmenu/drw.c @@ -1,9 +1,11 @@ /* See LICENSE file for copyright and license details. */ /* Pango + HarfBuzz + Xft drawing backend for Geminux dmenu */ #include +#include #include #include #include +#include #include #include #include @@ -12,6 +14,84 @@ #include "drw.h" #include "util.h" +#ifdef FC_COLOR +static void drw_fc_substitute(FcPattern *pattern, gpointer data) { + (void)data; + FcPatternDel(pattern, FC_COLOR); + FcPatternAddBool(pattern, FC_COLOR, FcFalse); +} +#endif + +static size_t drw_sanitize_utf8(char *dst, size_t dst_sz, const char *src, size_t src_len) { + if (!dst || dst_sz == 0) return 0; + if (!src) { + dst[0] = '\0'; + return 0; + } + size_t i = 0, o = 0; + while (i < src_len && o + 1 < dst_sz) { + unsigned char c = (unsigned char)src[i]; + if (c == '\0') break; + if (c < 0x80) { + dst[o++] = (char)c; + i++; + } else if (c >= 0xC2 && c <= 0xDF) { + if (i + 1 < src_len && ((unsigned char)src[i + 1] & 0xC0) == 0x80) { + if (o + 2 >= dst_sz) break; + dst[o++] = (char)c; + dst[o++] = src[i + 1]; + i += 2; + } else { + dst[o++] = '?'; + i++; + } + } else if (c >= 0xE0 && c <= 0xEF) { + if (i + 2 < src_len) { + unsigned char c1 = (unsigned char)src[i + 1]; + unsigned char c2 = (unsigned char)src[i + 2]; + int ok = ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80); + if (ok && c == 0xE0 && c1 < 0xA0) ok = 0; + if (ok && c == 0xED && c1 > 0x9F) ok = 0; + if (ok) { + if (o + 3 >= dst_sz) break; + dst[o++] = (char)c; + dst[o++] = (char)c1; + dst[o++] = (char)c2; + i += 3; + continue; + } + } + dst[o++] = '?'; + i++; + } else if (c >= 0xF0 && c <= 0xF4) { + if (i + 3 < src_len) { + unsigned char c1 = (unsigned char)src[i + 1]; + unsigned char c2 = (unsigned char)src[i + 2]; + unsigned char c3 = (unsigned char)src[i + 3]; + int ok = ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80 && (c3 & 0xC0) == 0x80); + if (ok && c == 0xF0 && c1 < 0x90) ok = 0; + if (ok && c == 0xF4 && c1 > 0x8F) ok = 0; + if (ok) { + if (o + 4 >= dst_sz) break; + dst[o++] = (char)c; + dst[o++] = (char)c1; + dst[o++] = (char)c2; + dst[o++] = (char)c3; + i += 4; + continue; + } + } + dst[o++] = '?'; + i++; + } else { + dst[o++] = '?'; + i++; + } + } + dst[o] = '\0'; + return o; +} + Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) { Drw *drw = ecalloc(1, sizeof(Drw)); drw->dpy = dpy; @@ -54,6 +134,14 @@ Fnt *drw_fontset_create(Drw *drw, const char *fonts[], size_t fontcount) { fnt->dpy = drw->dpy; fnt->fontmap = pango_xft_get_font_map(drw->dpy, drw->screen); +#ifdef FC_COLOR +#if PANGO_VERSION_CHECK(1, 48, 0) + pango_fc_font_map_set_default_substitute(PANGO_FC_FONT_MAP(fnt->fontmap), + drw_fc_substitute, NULL, NULL); +#else + pango_xft_set_default_substitute(drw->dpy, drw->screen, drw_fc_substitute, NULL, NULL); +#endif +#endif fnt->context = pango_font_map_create_context(fnt->fontmap); fnt->desc = pango_font_description_from_string(spec); pango_context_set_font_description(fnt->context, fnt->desc); @@ -119,14 +207,14 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, int orig_x = x; unsigned int orig_w = w; int ty, render = x || y || w || h; - unsigned int ew, eh; + unsigned int ew = 0, eh = 0; XftDraw *d = NULL; if (!drw || (render && !drw->scheme) || !text || !drw->fonts) return 0; if (!render) { - w = ~0; + w = ~0U; } else { XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); @@ -137,32 +225,36 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, w = (w > lpad) ? (w - lpad) : 0; } - size_t len = strlen(text); - if (len >= sizeof(buf)) len = sizeof(buf) - 1; - memcpy(buf, text, len); - buf[len] = '\0'; + size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, strlen(text)); - if (len > 0 && w > 0) { - drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh); - while (len > 3 && ew > w) { - len--; - while (len > 0 && (buf[len] & 0xc0) == 0x80) len--; - if (len >= 3) memcpy(buf + len - 3, "...", 3); - buf[len] = '\0'; - drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh); + if (slen > 0 && w > 0) { + if (!render) { + drw_font_getexts(drw->fonts, buf, (unsigned int)slen, &ew, &eh); + x += (int)ew; + } else if (d) { + PangoLayout *layout = drw->fonts->layout; + PangoRectangle r; + int max_w = (w > (unsigned int)(INT_MAX / PANGO_SCALE)) + ? (INT_MAX / PANGO_SCALE) : (int)w; + pango_layout_set_single_paragraph_mode(layout, TRUE); + pango_layout_set_width(layout, max_w * PANGO_SCALE); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); + pango_layout_set_text(layout, buf, (int)slen); + pango_layout_get_extents(layout, NULL, &r); + ew = (unsigned int)((r.width + PANGO_SCALE - 1) / PANGO_SCALE); + eh = (unsigned int)((r.height + PANGO_SCALE - 1) / PANGO_SCALE); + if (eh == 0) eh = drw->fonts->h; + if (ew <= w || w >= 12) { + ty = y + (int)(h - eh) / 2; + if (ty < y) ty = y; + pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg], + layout, x * PANGO_SCALE, ty * PANGO_SCALE); + } + pango_layout_set_width(layout, -1); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); + pango_layout_set_single_paragraph_mode(layout, FALSE); + x += (int)ew; } - if (ew > w) { - len = 0; - buf[0] = '\0'; - } - if (render && d) { - pango_layout_set_text(drw->fonts->layout, buf, -1); - ty = y + (int)(h - eh) / 2; - if (ty < y) ty = y; - pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg], - drw->fonts->layout, x * PANGO_SCALE, ty * PANGO_SCALE); - } - x += (int)ew; } if (d) XftDrawDestroy(d); @@ -173,13 +265,11 @@ int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align) { char buf[1024]; if (!drw || !drw->scheme || !drw->fonts || !text) return x; - int len = textlen < (int)sizeof(buf) - 1 ? textlen : (int)sizeof(buf) - 1; - if (len < 0) len = 0; - memcpy(buf, text, (size_t)len); - buf[len] = '\0'; + if (textlen < 0) textlen = 0; + size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, (size_t)textlen); unsigned int ew = 0, eh = 0; - drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh); + drw_font_getexts(drw->fonts, buf, (unsigned int)slen, &ew, &eh); int dx = (align == AlignR && ew < w) ? x + (int)(w - ew) : x; int ty = y + (int)(h - eh) / 2; if (ty < y) ty = y; @@ -187,11 +277,22 @@ int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, XftDraw *d = XftDrawCreate(drw->dpy, drw->drawable, DefaultVisual(drw->dpy, drw->screen), DefaultColormap(drw->dpy, drw->screen)); - pango_layout_set_text(drw->fonts->layout, buf, len); + PangoLayout *layout = drw->fonts->layout; + pango_layout_set_single_paragraph_mode(layout, TRUE); + if (w > 0) { + int max_w = (w > (unsigned int)(INT_MAX / PANGO_SCALE)) + ? (INT_MAX / PANGO_SCALE) : (int)w; + pango_layout_set_width(layout, max_w * PANGO_SCALE); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); + } + pango_layout_set_text(layout, buf, (int)slen); pango_xft_render_layout(d, &drw->scheme[ColFg], - drw->fonts->layout, dx * PANGO_SCALE, ty * PANGO_SCALE); + layout, dx * PANGO_SCALE, ty * PANGO_SCALE); + pango_layout_set_width(layout, -1); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); + pango_layout_set_single_paragraph_mode(layout, FALSE); XftDrawDestroy(d); - return dx + (int)ew; + return dx + (int)(ew < w ? ew : w); } void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) { @@ -209,13 +310,18 @@ unsigned int drw_fontset_getwidth(Drw *drw, const char *text) { void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) { + char buf[1024]; PangoRectangle r; if (!font || !text) { if (w) *w = 0; if (h) *h = 0; return; } - pango_layout_set_text(font->layout, text, (int)len); + size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, (size_t)len); + pango_layout_set_single_paragraph_mode(font->layout, FALSE); + pango_layout_set_width(font->layout, -1); + pango_layout_set_ellipsize(font->layout, PANGO_ELLIPSIZE_NONE); + pango_layout_set_text(font->layout, buf, (int)slen); pango_layout_get_extents(font->layout, NULL, &r); if (w) *w = (unsigned int)((r.width + PANGO_SCALE - 1) / PANGO_SCALE); if (h) *h = (unsigned int)((r.height + PANGO_SCALE - 1) / PANGO_SCALE); diff --git a/src/dwm/config.def.h b/src/dwm/config.def.h index df84404..213e1cf 100644 --- a/src/dwm/config.def.h +++ b/src/dwm/config.def.h @@ -13,12 +13,12 @@ static const unsigned int systrayspacing = 8; static const int systraypinningfailfirst = 1; static const int showsystray = 1; static const char *font = "Fira Code, DejaVuSansM Nerd Font 38px"; -static char normbgcolor[64] = "#0b0e14"; -static char normbordercolor[64] = "#283444"; -static char normfgcolor[64] = "#e6e1cf"; -static char selbgcolor[64] = "#2b5278"; -static char selbordercolor[64] = "#59c2ff"; -static char selfgcolor[64] = "#ffffff"; +static char normbgcolor[64] = "#0e1014"; +static char normbordercolor[64] = "#2d3440"; +static char normfgcolor[64] = "#e4e8ee"; +static char selbgcolor[64] = "#38414f"; +static char selbordercolor[64] = "#cfd6e0"; +static char selfgcolor[64] = "#f5f7fa"; static char *colors[][3] = { /* fg bg border */ [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor }, diff --git a/src/dwm/drw.c b/src/dwm/drw.c index 862610e..302bcee 100644 --- a/src/dwm/drw.c +++ b/src/dwm/drw.c @@ -1,8 +1,10 @@ /* See LICENSE file for copyright and license details. */ /* Pango + HarfBuzz + Xft drawing backend for Geminux DWM */ +#include #include #include #include +#include #include #include #include @@ -11,6 +13,84 @@ #include "drw.h" #include "util.h" +#ifdef FC_COLOR +static void drw_fc_substitute(FcPattern *pattern, gpointer data) { + (void)data; + FcPatternDel(pattern, FC_COLOR); + FcPatternAddBool(pattern, FC_COLOR, FcFalse); +} +#endif + +static size_t drw_sanitize_utf8(char *dst, size_t dst_sz, const char *src, size_t src_len) { + if (!dst || dst_sz == 0) return 0; + if (!src) { + dst[0] = '\0'; + return 0; + } + size_t i = 0, o = 0; + while (i < src_len && o + 1 < dst_sz) { + unsigned char c = (unsigned char)src[i]; + if (c == '\0') break; + if (c < 0x80) { + dst[o++] = (char)c; + i++; + } else if (c >= 0xC2 && c <= 0xDF) { + if (i + 1 < src_len && ((unsigned char)src[i + 1] & 0xC0) == 0x80) { + if (o + 2 >= dst_sz) break; + dst[o++] = (char)c; + dst[o++] = src[i + 1]; + i += 2; + } else { + dst[o++] = '?'; + i++; + } + } else if (c >= 0xE0 && c <= 0xEF) { + if (i + 2 < src_len) { + unsigned char c1 = (unsigned char)src[i + 1]; + unsigned char c2 = (unsigned char)src[i + 2]; + int ok = ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80); + if (ok && c == 0xE0 && c1 < 0xA0) ok = 0; + if (ok && c == 0xED && c1 > 0x9F) ok = 0; + if (ok) { + if (o + 3 >= dst_sz) break; + dst[o++] = (char)c; + dst[o++] = (char)c1; + dst[o++] = (char)c2; + i += 3; + continue; + } + } + dst[o++] = '?'; + i++; + } else if (c >= 0xF0 && c <= 0xF4) { + if (i + 3 < src_len) { + unsigned char c1 = (unsigned char)src[i + 1]; + unsigned char c2 = (unsigned char)src[i + 2]; + unsigned char c3 = (unsigned char)src[i + 3]; + int ok = ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80 && (c3 & 0xC0) == 0x80); + if (ok && c == 0xF0 && c1 < 0x90) ok = 0; + if (ok && c == 0xF4 && c1 > 0x8F) ok = 0; + if (ok) { + if (o + 4 >= dst_sz) break; + dst[o++] = (char)c; + dst[o++] = (char)c1; + dst[o++] = (char)c2; + dst[o++] = (char)c3; + i += 4; + continue; + } + } + dst[o++] = '?'; + i++; + } else { + dst[o++] = '?'; + i++; + } + } + dst[o] = '\0'; + return o; +} + Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) { Drw *drw = ecalloc(1, sizeof(Drw)); drw->dpy = dpy; @@ -49,6 +129,14 @@ Fnt *drw_font_create(Drw *drw, const char font[]) { fnt->dpy = drw->dpy; fnt->fontmap = pango_xft_get_font_map(drw->dpy, drw->screen); +#ifdef FC_COLOR +#if PANGO_VERSION_CHECK(1, 48, 0) + pango_fc_font_map_set_default_substitute(PANGO_FC_FONT_MAP(fnt->fontmap), + drw_fc_substitute, NULL, NULL); +#else + pango_xft_set_default_substitute(drw->dpy, drw->screen, drw_fc_substitute, NULL, NULL); +#endif +#endif fnt->context = pango_font_map_create_context(fnt->fontmap); fnt->desc = pango_font_description_from_string(font && font[0] ? font : "Fira Code 18px"); pango_context_set_font_description(fnt->context, fnt->desc); @@ -114,14 +202,14 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, int orig_x = x; unsigned int orig_w = w; int ty, render = x || y || w || h; - unsigned int ew, eh; + unsigned int ew = 0, eh = 0; XftDraw *d = NULL; if (!drw || (render && !drw->scheme) || !text || !drw->font) return 0; if (!render) { - w = ~0; + w = ~0U; } else { XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); @@ -132,38 +220,41 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, w = (w > lpad) ? (w - lpad) : 0; } - size_t len = strlen(text); - if (len >= sizeof(buf)) len = sizeof(buf) - 1; - memcpy(buf, text, len); - buf[len] = '\0'; + size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, strlen(text)); - if (len > 0 && w > 0) { - drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup); - while (len > 3 && ew > w) { - len--; - while (len > 0 && (buf[len] & 0xc0) == 0x80) len--; - if (len >= 3) memcpy(buf + len - 3, "...", 3); - buf[len] = '\0'; - drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup); - } - if (ew > w) { - len = 0; - buf[0] = '\0'; - } - - if (render && d) { + if (slen > 0 && w > 0) { + if (!render) { + drw_font_getexts(drw->font, buf, (unsigned int)slen, &ew, &eh, markup); + x += (int)ew; + } else if (d) { + PangoLayout *layout = drw->font->layout; + PangoRectangle r; + int max_w = (w > (unsigned int)(INT_MAX / PANGO_SCALE)) + ? (INT_MAX / PANGO_SCALE) : (int)w; + pango_layout_set_single_paragraph_mode(layout, TRUE); + pango_layout_set_width(layout, max_w * PANGO_SCALE); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); if (markup) - pango_layout_set_markup(drw->font->layout, buf, -1); + pango_layout_set_markup(layout, buf, (int)slen); else - pango_layout_set_text(drw->font->layout, buf, -1); - ty = y + (int)(h - eh) / 2; - if (ty < y) ty = y; - pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg], - drw->font->layout, x * PANGO_SCALE, ty * PANGO_SCALE); + pango_layout_set_text(layout, buf, (int)slen); + pango_layout_get_extents(layout, NULL, &r); + ew = (unsigned int)((r.width + PANGO_SCALE - 1) / PANGO_SCALE); + eh = (unsigned int)((r.height + PANGO_SCALE - 1) / PANGO_SCALE); + if (eh == 0) eh = drw->font->h; + if (ew <= w || w >= 12) { + ty = y + (int)(h - eh) / 2; + if (ty < y) ty = y; + pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg], + layout, x * PANGO_SCALE, ty * PANGO_SCALE); + } + pango_layout_set_width(layout, -1); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); + pango_layout_set_single_paragraph_mode(layout, FALSE); if (markup) - pango_layout_set_attributes(drw->font->layout, NULL); + pango_layout_set_attributes(layout, NULL); + x += (int)ew; } - x += (int)ew; } if (d) XftDrawDestroy(d); @@ -185,16 +276,21 @@ unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup) { void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup) { + char buf[1024]; PangoRectangle r; if (!font || !text) { if (w) *w = 0; if (h) *h = 0; return; } + size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, (size_t)len); + pango_layout_set_single_paragraph_mode(font->layout, FALSE); + pango_layout_set_width(font->layout, -1); + pango_layout_set_ellipsize(font->layout, PANGO_ELLIPSIZE_NONE); if (markup) - pango_layout_set_markup(font->layout, text, (int)len); + pango_layout_set_markup(font->layout, buf, (int)slen); else - pango_layout_set_text(font->layout, text, (int)len); + pango_layout_set_text(font->layout, buf, (int)slen); pango_layout_get_extents(font->layout, NULL, &r); if (markup) pango_layout_set_attributes(font->layout, NULL); diff --git a/src/dwm/dwm.c b/src/dwm/dwm.c index b949cea..23cb376 100644 --- a/src/dwm/dwm.c +++ b/src/dwm/dwm.c @@ -308,6 +308,7 @@ static char stext[512]; static char xres_font[256] = ""; static int screen; static int sw, sh; +static int render_opcode = -1; static int bh; static int lrpad; static int (*xerrorxlib)(Display *, XErrorEvent *); @@ -505,6 +506,8 @@ static void buttonpress(XEvent *e) { restack(selmon); XAllowEvents(dpy, ReplayPointer, CurrentTime); click = ClkClientWin; + } else { + XAllowEvents(dpy, AsyncBoth, CurrentTime); } for (i = 0; i < LENGTH(buttons); i++) { if (click == buttons[i].click && buttons[i].func && @@ -516,7 +519,9 @@ static void buttonpress(XEvent *e) { } static void checkotherwm(void) { - xerrorxlib = XSetErrorHandler(xerrorstart); + int (*prev_err)(Display *, XErrorEvent *) = XSetErrorHandler(xerrorstart); + if (prev_err && prev_err != xerror) + xerrorxlib = prev_err; XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); XSync(dpy, False); XSetErrorHandler(xerror); @@ -1075,12 +1080,30 @@ static int extracteventtime(const XEvent *e, Time *out) { static Time getservertime(Window w) { XEvent ev; + Time ts = CurrentTime; + struct pollfd pfd = { .fd = ConnectionNumber(dpy), .events = POLLIN }; + unsigned long long deadline = now_ms() + 200ULL; + + while (XCheckTypedWindowEvent(dpy, w, PropertyNotify, &ev)) ; XSelectInput(dpy, w, PropertyChangeMask); XChangeProperty(dpy, w, netatom[NetWMName], utf8string, 8, PropModeAppend, (unsigned char *)"", 0); - XWindowEvent(dpy, w, PropertyChangeMask, &ev); + XFlush(dpy); + + for (;;) { + XEventsQueued(dpy, QueuedAfterReading); + if (XCheckTypedWindowEvent(dpy, w, PropertyNotify, &ev)) { + ts = ev.xproperty.time; + break; + } + unsigned long long now = now_ms(); + if (now >= deadline) break; + int rem = (int)(deadline - now); + if (poll(&pfd, 1, rem) < 0 && errno != EINTR) break; + } + XSelectInput(dpy, w, 0); - return ev.xproperty.time; + return ts; } static Time getfocustime(void) { @@ -1291,10 +1314,10 @@ static void grabbuttons(Client *c, int focused) { if (buttons[i].click == ClkClientWin) { for (j = 0; j < LENGTH(modifiers); j++) { XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], - c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + c->win, False, BUTTONMASK, GrabModeAsync, GrabModeAsync, None, None); if (buttons[i].mask & Mod4Mask) { XGrabButton(dpy, buttons[i].button, buttons[i].mask | Mod5Mask | modifiers[j], - c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + c->win, False, BUTTONMASK, GrabModeAsync, GrabModeAsync, None, None); } } } @@ -1868,7 +1891,10 @@ static void movemouse(const Arg *arg) { if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess) return; - if (!getrootptr(&x, &y)) return; + if (!getrootptr(&x, &y)) { + XUngrabPointer(dpy, CurrentTime); + return; + } do { XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev); switch (ev.type) { @@ -2343,6 +2369,11 @@ static void setup(void) { sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); root = RootWindow(dpy, screen); + { + int rev = 0, rerr = 0; + if (!XQueryExtension(dpy, "RENDER", &render_opcode, &rev, &rerr)) + render_opcode = -1; + } drw = drw_create(dpy, screen, root, (unsigned int)sw, (unsigned int)sh); dwmfont = drw_font_create(drw, font); drw_setfont(drw, dwmfont); @@ -3230,9 +3261,29 @@ static int xerror(Display *dpy, XErrorEvent *ee) { (ee->request_code == X_GrabKey && ee->error_code == BadAccess) || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable)) return 0; - fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", - ee->request_code, ee->error_code); - return xerrorxlib(dpy, ee); + if (render_opcode > 0 && ee->request_code == render_opcode) { + static unsigned int render_err_logged = 0; + if (render_err_logged < 8) { + render_err_logged++; + fprintf(stderr, "dwm: ignoring non-fatal RENDER error: minor=%d, error=%d\n", + ee->minor_code, ee->error_code); + } + return 0; + } + { + static int in_xerror = 0; + if (in_xerror) return 0; + in_xerror = 1; + fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", + ee->request_code, ee->error_code); + if (xerrorxlib && xerrorxlib != xerror) { + int rc = xerrorxlib(dpy, ee); + in_xerror = 0; + return rc; + } + in_xerror = 0; + return 0; + } } static int xerrordummy(Display *dpy, XErrorEvent *ee) { diff --git a/src/geminux-apps/Makefile b/src/geminux-apps/Makefile index 26cd3ad..67a3de0 100644 --- a/src/geminux-apps/Makefile +++ b/src/geminux-apps/Makefile @@ -38,8 +38,8 @@ geminux-net: geminux-net.c geminux-wifi-list.h geminux-bt-list.h ../geminux-daem geminux-audio: geminux-audio.c geminux-audio-parse.h ../libgemui/gemui.h $(CC) $(CFLAGS) -o $@ $< $(LIBS) -geminux-themes: geminux-themes.c geminux-xth.h ../libgemui/gemui.h - $(CC) $(CFLAGS) -o $@ $< $(LIBS) -lm +geminux-themes: geminux-themes.c geminux-xth.h geminux-wallpaper.h geminux-wallpaper-x11.h ../libgemui/gemui.h + $(CC) $(CFLAGS) -DHAVE_LIBJPEG=1 -DHAVE_LIBWEBP=1 -o $@ $< $(LIBS) -lXrandr -lXinerama -ljpeg -lwebp -lm geminux-%: geminux-%.c ../libgemui/gemui.h $(CC) $(CFLAGS) -o $@ $< $(LIBS) diff --git a/src/geminux-apps/geminux-net.c b/src/geminux-apps/geminux-net.c index ba9e1b5..c3cb137 100644 --- a/src/geminux-apps/geminux-net.c +++ b/src/geminux-apps/geminux-net.c @@ -58,6 +58,22 @@ enum { WORK_BT_REM, }; +static void reapply_saved_wallpaper(void) { + const char *xdg = getenv("XDG_CONFIG_HOME"); + const char *home = getenv("HOME"); + char conf[560]; + if (xdg && xdg[0]) { + snprintf(conf, sizeof(conf), "%s/geminux/wallpaper.conf", xdg); + } else { + snprintf(conf, sizeof(conf), "%s/.config/geminux/wallpaper.conf", + (home && home[0]) ? home : "/home/user"); + } + if (access(conf, R_OK) == 0) { + const char *wpv[] = {"geminux-apply-wallpaper", "--restore", NULL}; + gemui_spawn_detached(wpv); + } +} + typedef struct { char col1[128]; char col2[96]; @@ -1662,6 +1678,7 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v const char *argv[] = {"xrandr", "--output", "HDMI-1", st->hdmi_on ? "--off" : "--auto", NULL}; gemui_run_cmd_timeout(argv, NULL, 0, 2000); st->hdmi_on = !st->hdmi_on; + reapply_saved_wallpaper(); refresh_tab(st); } } else if (hit->id == HIT_ACTION) { @@ -1700,6 +1717,7 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v } else if (hit->val == 4) { const char *argv[] = {"xrandr", "--output", "HDMI-1", "--same-as", "DSI-1", NULL}; gemui_run_cmd_timeout(argv, NULL, 0, 2000); + reapply_saved_wallpaper(); refresh_tab(st); } } diff --git a/src/geminux-apps/geminux-themes.c b/src/geminux-apps/geminux-themes.c index 05a6b5f..8163035 100644 --- a/src/geminux-apps/geminux-themes.c +++ b/src/geminux-apps/geminux-themes.c @@ -1,7 +1,10 @@ -/* Geminux Unified Theme Browser, Live Preview, Importer & .xth Editor */ +/* Geminux Unified Theme Browser, Live Preview, Importer, .xth Editor & Wallpaper Manager */ +#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200809L #include "../libgemui/gemui.h" #include "geminux-xth.h" +#include "geminux-wallpaper.h" +#include "geminux-wallpaper-x11.h" #include #include @@ -12,9 +15,9 @@ #include #define MAX_THEMES 128 -#define MAX_DIR_ITEMS 256 +#define MAX_DIR_ITEMS 512 -enum { VIEW_BROWSE = 0, VIEW_EDITOR = 1, VIEW_IMPORT = 2 }; +enum { VIEW_BROWSE = 0, VIEW_EDITOR = 1, VIEW_IMPORT = 2, VIEW_WALLPAPER = 3 }; enum { ED_TAB_GEN = 0, ED_TAB_UI = 1, ED_TAB_WM = 2, ED_TAB_TERM = 3 }; typedef struct { @@ -71,10 +74,31 @@ typedef struct { int imp_scroll; geminux_xth_t imp_preview; bool imp_valid; + + /* Wallpaper view */ + geminux_wp_cfg_t wp_cfg; + char wp_dir[512]; + char wp_path_input[768]; + bool wp_show_all; + dir_item_t wp_items[MAX_DIR_ITEMS]; + int wp_count; + int wp_sel; + int wp_scroll; + char wp_hex[16]; + int wp_r, wp_g, wp_b; + int wp_drag_chan; /* 0=none, 1=R, 2=G, 3=B */ + gemui_rect_t wp_slider_rect[3]; + char wp_prev_path[768]; + cairo_surface_t *wp_prev_surf; + int wp_prev_orig_w; + int wp_prev_orig_h; + bool wp_prev_failed; + bool wp_initialized; } themes_state_t; enum { HIT_FILTER = 1, + HIT_MAIN_TAB, HIT_ROW, HIT_APPLY, HIT_EDIT, @@ -109,7 +133,24 @@ enum { HIT_IMP_NAME, HIT_IMP_DO, HIT_IMP_DO_APPLY, - HIT_IMP_BACK + HIT_IMP_BACK, + + HIT_WP_TYPE, + HIT_WP_MODE, + HIT_WP_QUICK_DIR, + HIT_WP_TOGGLE_ALL, + HIT_WP_PATH, + HIT_WP_PASTE_PATH, + HIT_WP_ITEM, + HIT_WP_THEME_BG, + HIT_WP_HEX, + HIT_WP_PASTE_HEX, + HIT_WP_SLIDER_R, + HIT_WP_SLIDER_G, + HIT_WP_SLIDER_B, + HIT_WP_SWATCH, + HIT_WP_CLEAR, + HIT_WP_APPLY }; static int cmp_theme_entry(const void *a, const void *b) { @@ -164,6 +205,16 @@ static void user_themes_dir(char *out, size_t sz) { } } +static void wp_conf_path(char *out, size_t sz) { + const char *xdg = getenv("XDG_CONFIG_HOME"); + const char *home = getenv("HOME"); + if (xdg && xdg[0]) { + snprintf(out, sz, "%s/geminux/wallpaper.conf", xdg); + } else { + snprintf(out, sz, "%s/.config/geminux/wallpaper.conf", (home && home[0]) ? home : "/tmp"); + } +} + static void set_focus_input(themes_state_t *st, int hit_id, char *buf, size_t cap) { st->focus_id = hit_id; st->focus_buf = buf; @@ -597,18 +648,333 @@ static void draw_mini_preview(themes_state_t *st, cairo_t *cr, gemui_rect_t r, } } +static void draw_main_tabs(themes_state_t *st, cairo_t *cr, int w, int y, int *next_y) { + int pad = 20; + int cw = w - pad * 2; + int tab_h = 54; + int tab_w = (cw - 14) / 2; + + gemui_draw_button(st->app, cr, (gemui_rect_t){pad, y, tab_w, tab_h}, + "Themes & Editor", HIT_MAIN_TAB, 0, false, st->view == VIEW_BROWSE, false); + gemui_draw_button(st->app, cr, (gemui_rect_t){pad + tab_w + 14, y, tab_w, tab_h}, + "Wallpaper", HIT_MAIN_TAB, 1, false, st->view == VIEW_WALLPAPER, false); + if (next_y) *next_y = y + tab_h + 14; +} + +static void theme_bg_hex_from_app(gemui_app_t *app, char *out_hex, size_t sz) { + const gemui_theme_t *t = app ? gemui_theme(app) : NULL; + if (t) { + int r = (int)(t->bg_main.r * 255.0 + 0.5); + int g = (int)(t->bg_main.g * 255.0 + 0.5); + int b = (int)(t->bg_main.b * 255.0 + 0.5); + geminux_wp_format_hex(r, g, b, out_hex, sz); + } else { + geminux_wp_read_theme_bg(NULL, out_hex, sz); + } +} + +static void wp_resolved_bg_hex(themes_state_t *st, char *out_hex, size_t sz) { + if (st->wp_cfg.use_theme_bg) { + theme_bg_hex_from_app(st->app, out_hex, sz); + } else { + snprintf(out_hex, sz, "%s", st->wp_cfg.color[0] ? st->wp_cfg.color : "#08090b"); + } +} + +static void wp_sync_rgb_from_cfg(themes_state_t *st) { + int r = 8, g = 9, b = 11; + if (geminux_wp_parse_hex(st->wp_cfg.color, &r, &g, &b)) { + st->wp_r = r; st->wp_g = g; st->wp_b = b; + geminux_wp_format_hex(r, g, b, st->wp_hex, sizeof(st->wp_hex)); + snprintf(st->wp_cfg.color, sizeof(st->wp_cfg.color), "%s", st->wp_hex); + } else { + st->wp_r = 8; st->wp_g = 9; st->wp_b = 11; + snprintf(st->wp_hex, sizeof(st->wp_hex), "#08090b"); + snprintf(st->wp_cfg.color, sizeof(st->wp_cfg.color), "#08090b"); + } +} + +static void wp_commit_rgb(themes_state_t *st, int r, int g, int b) { + st->wp_r = r < 0 ? 0 : (r > 255 ? 255 : r); + st->wp_g = g < 0 ? 0 : (g > 255 ? 255 : g); + st->wp_b = b < 0 ? 0 : (b > 255 ? 255 : b); + geminux_wp_format_hex(st->wp_r, st->wp_g, st->wp_b, st->wp_hex, sizeof(st->wp_hex)); + snprintf(st->wp_cfg.color, sizeof(st->wp_cfg.color), "%s", st->wp_hex); + st->wp_cfg.use_theme_bg = false; +} + +static void wp_destroy_preview(themes_state_t *st) { + if (st->wp_prev_surf) { + cairo_surface_destroy(st->wp_prev_surf); + st->wp_prev_surf = NULL; + } + st->wp_prev_path[0] = '\0'; + st->wp_prev_orig_w = 0; + st->wp_prev_orig_h = 0; + st->wp_prev_failed = false; +} + +static void wp_refresh_preview(themes_state_t *st) { + char exp[800]; + expand_tilde(st->wp_path_input, exp, sizeof(exp)); + struct stat sb; + if (!exp[0] || stat(exp, &sb) != 0 || !S_ISREG(sb.st_mode)) { + wp_destroy_preview(st); + return; + } + if (strcmp(exp, st->wp_prev_path) == 0 && (st->wp_prev_surf != NULL || st->wp_prev_failed)) { + return; + } + wp_destroy_preview(st); + snprintf(st->wp_prev_path, sizeof(st->wp_prev_path), "%.*s", + (int)(sizeof(st->wp_prev_path) - 1), exp); + st->wp_prev_surf = geminux_wp_make_preview_surface(exp, 960, 480, + &st->wp_prev_orig_w, + &st->wp_prev_orig_h); + st->wp_prev_failed = (st->wp_prev_surf == NULL); +} + +static void wp_scan_dir(themes_state_t *st, const char *dir, const char *prefer_base) { + char exp[800]; + expand_tilde(dir, exp, sizeof(exp)); + DIR *d = opendir(exp); + if (!d) return; + + snprintf(st->wp_dir, sizeof(st->wp_dir), "%.*s", (int)(sizeof(st->wp_dir) - 1), exp); + st->wp_count = 0; + if (strcmp(st->wp_dir, "/") != 0) { + snprintf(st->wp_items[st->wp_count].name, sizeof(st->wp_items[0].name), ".."); + st->wp_items[st->wp_count].is_dir = true; + st->wp_count++; + } + + struct dirent *de; + dir_item_t rest[MAX_DIR_ITEMS]; + int rc = 0; + while ((de = readdir(d)) != NULL && rc < MAX_DIR_ITEMS - 1) { + if (de->d_name[0] == '.') continue; + char full[1024]; + if (snprintf(full, sizeof(full), "%s/%s", strcmp(st->wp_dir, "/") == 0 ? "" : st->wp_dir, + de->d_name) >= (int)sizeof(full)) { + continue; + } + struct stat sb; + if (stat(full, &sb) != 0) continue; + bool is_d = S_ISDIR(sb.st_mode); + if (!is_d && !st->wp_show_all && !geminux_wp_is_image_name(de->d_name)) continue; + snprintf(rest[rc].name, sizeof(rest[0].name), "%s", de->d_name); + rest[rc].is_dir = is_d; + rc++; + } + closedir(d); + + if (rc > 1) qsort(rest, (size_t)rc, sizeof(rest[0]), cmp_dir_item); + st->wp_sel = 0; + st->wp_scroll = 0; + for (int i = 0; i < rc && st->wp_count < MAX_DIR_ITEMS; i++) { + int idx = st->wp_count++; + st->wp_items[idx] = rest[i]; + if (prefer_base && prefer_base[0] && !rest[i].is_dir && strcmp(rest[i].name, prefer_base) == 0) { + st->wp_sel = idx; + } + } +} + +static bool wp_is_existing_dir(const char *dir) { + struct stat sb; + return dir && dir[0] && stat(dir, &sb) == 0 && S_ISDIR(sb.st_mode); +} + +static bool wp_find_system_dir(char *out, size_t sz) { + if (!out || sz == 0) return false; + const char *cand = "/usr/share/geminux/wallpapers"; + if (wp_is_existing_dir(cand)) { + snprintf(out, sz, "%s", cand); + return true; + } + out[0] = '\0'; + return false; +} + +static bool wp_resolve_bundled_image(const char *arg, char *out, size_t sz) { + if (!arg || !arg[0] || strchr(arg, '/')) return false; + const char *home = getenv("HOME"); + const char *h = (home && home[0]) ? home : "/"; + char dirs[4][560]; + int nd = 0; + if (wp_find_system_dir(dirs[nd], sizeof(dirs[0]))) nd++; + snprintf(dirs[nd++], sizeof(dirs[0]), "%s/Pictures/Wallpapers", strcmp(h, "/") == 0 ? "" : h); + snprintf(dirs[nd++], sizeof(dirs[0]), "%s/Wallpapers", strcmp(h, "/") == 0 ? "" : h); + snprintf(dirs[nd++], sizeof(dirs[0]), "%s/Pictures", strcmp(h, "/") == 0 ? "" : h); + + static const char *const EXTS[5] = {"", ".png", ".jpg", ".jpeg", ".webp"}; + for (int di = 0; di < nd; di++) { + if (!wp_is_existing_dir(dirs[di])) continue; + for (int ei = 0; ei < 5; ei++) { + char cand[800]; + snprintf(cand, sizeof(cand), "%s/%s%s", strcmp(dirs[di], "/") == 0 ? "" : dirs[di], arg, EXTS[ei]); + struct stat sb; + if (stat(cand, &sb) == 0 && S_ISREG(sb.st_mode)) { + char *rp = realpath(cand, NULL); + const char *src = rp ? rp : cand; + snprintf(out, sz, "%.*s", (int)(sz - 1), src); + free(rp); + return true; + } + } + } + return false; +} + +static void wp_sync_sel_to_input(themes_state_t *st) { + if (st->wp_sel < 0 || st->wp_sel >= st->wp_count) return; + const dir_item_t *it = &st->wp_items[st->wp_sel]; + if (!it->is_dir) { + char tmp[1024]; + snprintf(tmp, sizeof(tmp), "%s/%s", strcmp(st->wp_dir, "/") == 0 ? "" : st->wp_dir, it->name); + snprintf(st->wp_path_input, sizeof(st->wp_path_input), "%.*s", + (int)(sizeof(st->wp_path_input) - 1), tmp); + wp_refresh_preview(st); + } +} + +static void wp_select_first_image_if_dir(themes_state_t *st) { + if (st->wp_count <= 0) return; + if (st->wp_sel >= 0 && st->wp_sel < st->wp_count && !st->wp_items[st->wp_sel].is_dir) return; + for (int i = 0; i < st->wp_count; i++) { + if (!st->wp_items[i].is_dir) { + st->wp_sel = i; + break; + } + } +} + +static void wp_init_state(themes_state_t *st) { + st->wp_initialized = true; + char cpath[560]; + wp_conf_path(cpath, sizeof(cpath)); + geminux_wp_cfg_load(cpath, &st->wp_cfg); + wp_sync_rgb_from_cfg(st); + snprintf(st->wp_path_input, sizeof(st->wp_path_input), "%.*s", + (int)(sizeof(st->wp_path_input) - 1), st->wp_cfg.path); + + char start_dir[512] = ""; + char pref_base[260] = ""; + if (st->wp_cfg.path[0]) { + const char *slash = strrchr(st->wp_cfg.path, '/'); + if (slash && slash > st->wp_cfg.path) { + size_t dlen = (size_t)(slash - st->wp_cfg.path); + if (dlen >= sizeof(start_dir)) dlen = sizeof(start_dir) - 1; + memcpy(start_dir, st->wp_cfg.path, dlen); + start_dir[dlen] = '\0'; + snprintf(pref_base, sizeof(pref_base), "%.*s", (int)(sizeof(pref_base) - 1), slash + 1); + } else if (slash == st->wp_cfg.path) { + snprintf(start_dir, sizeof(start_dir), "/"); + snprintf(pref_base, sizeof(pref_base), "%.*s", (int)(sizeof(pref_base) - 1), slash + 1); + } + } + + if (!wp_is_existing_dir(start_dir)) { + pref_base[0] = '\0'; + if (!wp_find_system_dir(start_dir, sizeof(start_dir))) { + const char *home = getenv("HOME"); + const char *h = (home && home[0]) ? home : "/"; + const char *cands[4] = {"Pictures/Wallpapers", "Pictures", "Wallpapers", NULL}; + start_dir[0] = '\0'; + for (int i = 0; cands[i]; i++) { + char cand[600]; + snprintf(cand, sizeof(cand), "%s/%s", strcmp(h, "/") == 0 ? "" : h, cands[i]); + if (wp_is_existing_dir(cand)) { + snprintf(start_dir, sizeof(start_dir), "%.*s", (int)(sizeof(start_dir) - 1), cand); + break; + } + } + if (!start_dir[0]) snprintf(start_dir, sizeof(start_dir), "%.*s", (int)(sizeof(start_dir) - 1), h); + } + } + + wp_scan_dir(st, start_dir, pref_base); + if (!st->wp_path_input[0] && st->wp_cfg.type == GEMINUX_WP_IMAGE) { + wp_select_first_image_if_dir(st); + wp_sync_sel_to_input(st); + } else { + wp_refresh_preview(st); + } +} + +static void wp_apply_now(themes_state_t *st) { + char theme_bg[16]; + theme_bg_hex_from_app(st->app, theme_bg, sizeof(theme_bg)); + + if (st->wp_cfg.type == GEMINUX_WP_IMAGE) { + char exp[800]; + expand_tilde(st->wp_path_input, exp, sizeof(exp)); + char *rp = realpath(exp, NULL); + const char *src = rp ? rp : exp; + struct stat sb; + if (!src[0] || stat(src, &sb) != 0 || !S_ISREG(sb.st_mode)) { + free(rp); + gemui_show_toast(st->app, "Select a valid image file first", 2200); + gemui_request_redraw(st->app); + return; + } + snprintf(st->wp_cfg.path, sizeof(st->wp_cfg.path), "%.*s", + (int)(sizeof(st->wp_cfg.path) - 1), src); + snprintf(st->wp_path_input, sizeof(st->wp_path_input), "%.*s", + (int)(sizeof(st->wp_path_input) - 1), src); + free(rp); + wp_refresh_preview(st); + } + + char err[256]; + if (!geminux_wp_apply_x11(&st->wp_cfg, theme_bg, err, sizeof(err))) { + gemui_show_toast(st->app, err[0] ? err : "Failed to apply wallpaper", 2400); + gemui_request_redraw(st->app); + return; + } + + char cpath[560]; + wp_conf_path(cpath, sizeof(cpath)); + if (geminux_wp_cfg_save(cpath, &st->wp_cfg)) { + gemui_show_toast(st->app, + st->wp_cfg.type == GEMINUX_WP_SOLID + ? "Solid background applied & saved" + : "Wallpaper applied & saved", + 2000); + } else { + gemui_show_toast(st->app, "Wallpaper applied (failed to save config)", 2200); + } + gemui_request_redraw(st->app); +} + +static void wp_swatch_palette(const gemui_theme_t *t, char out[8][16]) { + gemui_color_t c[5] = {t->bg_main, t->bg_bar, t->bg_header, t->accent, t->sel_bg}; + for (int i = 0; i < 5; i++) { + geminux_wp_format_hex((int)(c[i].r * 255.0 + 0.5), + (int)(c[i].g * 255.0 + 0.5), + (int)(c[i].b * 255.0 + 0.5), + out[i], 16); + } + snprintf(out[5], 16, "#11161f"); + snprintf(out[6], 16, "#1f2430"); + snprintf(out[7], 16, "#000000"); +} + static void draw_browse_view(themes_state_t *st, cairo_t *cr, int w, int h) { const gemui_theme_t *t = gemui_theme(st->app); char badge[96]; snprintf(badge, sizeof(badge), "Active: %s", st->active_name[0] ? st->active_name : t->name); - gemui_draw_header(st->app, cr, "\xef\x94\xbf", "Geminux Themes & Editor", badge); + gemui_draw_header(st->app, cr, "\xef\x94\xbf", "Geminux Themes & Wallpaper", badge); int hdr_h = 76; int pad = 20; int btn_h = 56; - int ftr_h = btn_h * 2 + 16; - int body_y = hdr_h + 16; - int body_h = h - body_y - ftr_h - pad - 14; + int ftr_h = btn_h * 2 + 14; + int body_y = hdr_h + 14; + draw_main_tabs(st, cr, w, body_y, &body_y); + + int fy1 = h - pad - ftr_h; + int body_h = fy1 - body_y - 14; int list_w = (w * 43) / 100; if (list_w < 540) list_w = 540; @@ -671,7 +1037,6 @@ static void draw_browse_view(themes_state_t *st, cairo_t *cr, int w, int h) { /* Footer actions (2 tidy rows) */ int cw = w - pad * 2; - int fy1 = h - pad - ftr_h; int fy2 = fy1 + btn_h + 14; int gap = 12; int bw5 = (cw - gap * 4) / 5; @@ -998,11 +1363,289 @@ static void draw_import_view(themes_state_t *st, cairo_t *cr, int w, int h) { "Install & Apply", HIT_IMP_DO_APPLY, 0, true, false, false); } +static void draw_wallpaper_view(themes_state_t *st, cairo_t *cr, int w, int h) { + const gemui_theme_t *t = gemui_theme(st->app); + char bg_hex[16]; + wp_resolved_bg_hex(st, bg_hex, sizeof(bg_hex)); + + char badge[96]; + if (st->wp_cfg.type == GEMINUX_WP_SOLID) { + snprintf(badge, sizeof(badge), "Solid %s%s", bg_hex, st->wp_cfg.use_theme_bg ? " (Theme)" : ""); + } else if (st->wp_prev_orig_w > 0 && st->wp_prev_orig_h > 0) { + snprintf(badge, sizeof(badge), "%s (%dx%d)", + geminux_wp_mode_label(st->wp_cfg.mode), st->wp_prev_orig_w, st->wp_prev_orig_h); + } else { + snprintf(badge, sizeof(badge), "Mode: %s", geminux_wp_mode_label(st->wp_cfg.mode)); + } + gemui_draw_header(st->app, cr, "\xef\x80\xbe", "Geminux Themes & Wallpaper", badge); + + int hdr_h = 76; + int pad = 20; + int y = hdr_h + 14; + draw_main_tabs(st, cr, w, y, &y); + + int cw = w - pad * 2; + int btn_h = 56; + int fy = h - btn_h - pad; + int body_h = fy - y - 14; + int left_w = (cw * 45) / 100; + int right_x = pad + left_w + pad; + int right_w = cw - left_w - pad; + + /* Left column */ + int ly = y; + int type_gap = 12; + int type_w = (left_w - type_gap) / 2; + gemui_draw_button(st->app, cr, (gemui_rect_t){pad, ly, type_w, 54}, + "Image Wallpaper", HIT_WP_TYPE, GEMINUX_WP_IMAGE, + false, st->wp_cfg.type == GEMINUX_WP_IMAGE, false); + gemui_draw_button(st->app, cr, (gemui_rect_t){pad + type_w + type_gap, ly, type_w, 54}, + "Solid Color", HIT_WP_TYPE, GEMINUX_WP_SOLID, + false, st->wp_cfg.type == GEMINUX_WP_SOLID, false); + ly += 54 + 12; + + int left_rem_h = (y + body_h) - ly; + if (st->wp_cfg.type == GEMINUX_WP_IMAGE) { + int in_h = 52; + int gap = 10; + int all_w = 110; + int qbw = (left_w - all_w - gap * 4) / 4; + const char *home = getenv("HOME"); + const char *hdir = (home && home[0]) ? home : "/"; + char pics_dir[560]; + snprintf(pics_dir, sizeof(pics_dir), "%s/Pictures", strcmp(hdir, "/") == 0 ? "" : hdir); + bool q_active[4] = { + strcmp(st->wp_dir, hdir) == 0, + strcmp(st->wp_dir, pics_dir) == 0, + strcmp(st->wp_dir, "/media/sdcard") == 0, + strcmp(st->wp_dir, "/") == 0, + }; + const char *qnames[4] = {"Home", "Pictures", "SD Card", "Root /"}; + for (int i = 0; i < 4; i++) { + gemui_draw_button(st->app, cr, (gemui_rect_t){pad + i * (qbw + gap), ly, qbw, in_h}, + qnames[i], HIT_WP_QUICK_DIR, i, false, q_active[i], false); + } + gemui_draw_button(st->app, cr, (gemui_rect_t){pad + 4 * (qbw + gap), ly, left_w - 4 * (qbw + gap), in_h}, + "All", HIT_WP_TOGGLE_ALL, 0, false, st->wp_show_all, false); + ly += in_h + 12; + + int paste_w = 136; + gemui_draw_input(st->app, cr, (gemui_rect_t){pad, ly, left_w - paste_w - gap, in_h}, + "/path/to/wallpaper.png", st->wp_path_input, false, + st->focus_id == HIT_WP_PATH, HIT_WP_PATH, 0); + gemui_draw_button(st->app, cr, (gemui_rect_t){pad + left_w - paste_w, ly, paste_w, in_h}, + "Paste", HIT_WP_PASTE_PATH, 0, false, false, false); + ly += in_h + 12; + + int list_h = (y + body_h) - ly; + if (list_h < 120) list_h = 120; + gemui_rect_t list_r = {pad, ly, left_w, list_h}; + gemui_fill_round(cr, list_r, 12.0, t->bg_alt_even); + gemui_stroke_round(cr, list_r, 12.0, 1.0, t->border); + + int row_h = 50; + int vis_rows = (list_h - 16) / row_h; + if (vis_rows < 1) vis_rows = 1; + if (st->wp_sel < st->wp_scroll) st->wp_scroll = st->wp_sel; + if (st->wp_sel >= st->wp_scroll + vis_rows) st->wp_scroll = st->wp_sel - vis_rows + 1; + if (st->wp_scroll > st->wp_count - vis_rows) st->wp_scroll = st->wp_count - vis_rows; + if (st->wp_scroll < 0) st->wp_scroll = 0; + + for (int i = 0; i < vis_rows && st->wp_scroll + i < st->wp_count; i++) { + int idx = st->wp_scroll + i; + gemui_rect_t rr = {pad + 10, ly + 8 + i * row_h, left_w - 20, row_h - 4}; + bool is_sel = (idx == st->wp_sel); + if (is_sel) gemui_fill_round(cr, rr, 8.0, t->sel_bg); + char lbl[280]; + snprintf(lbl, sizeof(lbl), "%s%s", st->wp_items[idx].is_dir ? "[DIR] " : "", st->wp_items[idx].name); + gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 12, rr.y, rr.w - 24, rr.h}, + lbl, -2, is_sel || st->wp_items[idx].is_dir, GEMUI_ALIGN_LEFT, + is_sel ? t->sel_fg : (st->wp_items[idx].is_dir ? t->accent : t->fg_main)); + gemui_hit_add(st->app, rr, HIT_WP_ITEM, idx); + } + } else { + gemui_rect_t pnl_r = {pad, ly, left_w, left_rem_h}; + gemui_fill_round(cr, pnl_r, 12.0, t->bg_alt_even); + gemui_stroke_round(cr, pnl_r, 12.0, 1.0, t->border); + + int ip = 16; + int px = pad + ip; + int pw = left_w - ip * 2; + int py = ly + ip; + int in_h = 52; + + gemui_draw_toggle(st->app, cr, (gemui_rect_t){px, py, pw, in_h}, + "Match Active Theme Background", st->wp_cfg.use_theme_bg, + HIT_WP_THEME_BG, 0, false); + py += in_h + 12; + + gemui_color_t sc; + gemui_color_parse(bg_hex, &sc); + int sw_w = 72; + int paste_w = 136; + gemui_fill_round(cr, (gemui_rect_t){px, py, sw_w, in_h}, 8.0, sc); + gemui_stroke_round(cr, (gemui_rect_t){px, py, sw_w, in_h}, 8.0, 1.5, t->border); + gemui_draw_input(st->app, cr, (gemui_rect_t){px + sw_w + 12, py, pw - sw_w - paste_w - 24, in_h}, + "#RRGGBB", st->wp_hex, false, st->focus_id == HIT_WP_HEX, HIT_WP_HEX, 0); + gemui_draw_button(st->app, cr, (gemui_rect_t){px + pw - paste_w, py, paste_w, in_h}, + "Paste", HIT_WP_PASTE_HEX, 0, false, false, false); + py += in_h + 12; + + int sli_h = 84; + const int rgb_vals[3] = {st->wp_r, st->wp_g, st->wp_b}; + const char *rgb_names[3] = {"Red (R)", "Green (G)", "Blue (B)"}; + const int rgb_hits[3] = {HIT_WP_SLIDER_R, HIT_WP_SLIDER_G, HIT_WP_SLIDER_B}; + for (int ci = 0; ci < 3; ci++) { + char vtxt[16]; + snprintf(vtxt, sizeof(vtxt), "%d", rgb_vals[ci]); + gemui_rect_t sr = {px, py, pw, sli_h}; + st->wp_slider_rect[ci] = sr; + gemui_draw_slider(st->app, cr, sr, rgb_names[ci], (double)rgb_vals[ci] / 255.0, vtxt, + rgb_hits[ci], ci + 1, st->wp_drag_chan == ci + 1); + py += sli_h + 12; + } + + int lbl_h = 34; + gemui_draw_text(cr, t, (gemui_rect_t){px, py, pw, lbl_h}, + "Theme & Dark Swatches", -2, false, GEMUI_ALIGN_LEFT, t->fg_muted); + py += lbl_h + 8; + + char sw_hexes[8][16]; + wp_swatch_palette(t, sw_hexes); + int gap = 12; + int ssz = (pw - gap * 7) / 8; + int sh = 54; + for (int i = 0; i < 8; i++) { + gemui_color_t c; + gemui_color_parse(sw_hexes[i], &c); + gemui_rect_t sr = {px + i * (ssz + gap), py, ssz, sh}; + gemui_fill_round(cr, sr, 8.0, c); + bool act = (!st->wp_cfg.use_theme_bg && strcmp(st->wp_hex, sw_hexes[i]) == 0); + gemui_stroke_round(cr, sr, 8.0, act ? 3.0 : 1.0, act ? t->highlight : t->border); + gemui_hit_add(st->app, sr, HIT_WP_SWATCH, i); + } + } + + /* Right column: Live desktop preview + mode/color controls */ + int prev_h = (body_h * 54) / 100; + gemui_rect_t prev_card = {right_x, y, right_w, prev_h}; + gemui_fill_round(cr, prev_card, 14.0, t->bg_alt_even); + gemui_stroke_round(cr, prev_card, 14.0, 1.0, t->border); + + int p_pad = 16; + int cap_h = 38; + int screen_x = right_x + p_pad; + int screen_y = y + p_pad; + int screen_w = right_w - p_pad * 2; + int screen_h = prev_h - p_pad * 2 - cap_h - 6; + if (screen_w > 40 && screen_h > 40) { + geminux_wp_cfg_t render_cfg = st->wp_cfg; + geminux_wp_render_onto_cairo(cr, (double)screen_x, (double)screen_y, + (double)screen_w, (double)screen_h, + &render_cfg, st->wp_prev_surf, bg_hex); + /* Simulated mini DWM top bar so bar/wallpaper contrast is visible */ + int mbar_h = 24; + gemui_fill_rect(cr, (gemui_rect_t){screen_x, screen_y, screen_w, mbar_h}, t->bg_bar); + gemui_fill_rect(cr, (gemui_rect_t){screen_x, screen_y, 44, mbar_h}, t->sel_bg); + gemui_stroke_round(cr, (gemui_rect_t){screen_x, screen_y, screen_w, screen_h}, 4.0, 1.0, t->border); + } + + char cap[512]; + if (st->wp_cfg.type == GEMINUX_WP_SOLID) { + snprintf(cap, sizeof(cap), "Solid Color: %s%s", bg_hex, + st->wp_cfg.use_theme_bg ? " (matches active theme)" : ""); + } else if (st->wp_prev_surf) { + const char *sl = strrchr(st->wp_path_input, '/'); + const char *bname = (sl && sl[1]) ? (sl + 1) : st->wp_path_input; + snprintf(cap, sizeof(cap), "%.*s (%dx%d)", 120, bname, st->wp_prev_orig_w, st->wp_prev_orig_h); + } else if (st->wp_prev_failed) { + snprintf(cap, sizeof(cap), "Cannot decode selected file (try PNG/JPEG/WebP)"); + } else { + snprintf(cap, sizeof(cap), "Select an image file on the left to preview"); + } + gemui_draw_text(cr, t, (gemui_rect_t){right_x + p_pad, y + prev_h - cap_h - p_pad / 2, right_w - p_pad * 2, cap_h}, + cap, -2, false, GEMUI_ALIGN_LEFT, st->wp_prev_failed ? t->warning : t->fg_muted); + + int cy = y + prev_h + 12; + int ctrl_h = (y + body_h) - cy; + gemui_rect_t ctrl_card = {right_x, cy, right_w, ctrl_h}; + gemui_fill_round(cr, ctrl_card, 12.0, t->bg_alt_even); + gemui_stroke_round(cr, ctrl_card, 12.0, 1.0, t->border); + + int cpad = 16; + int cx = right_x + cpad; + int c_in_w = right_w - cpad * 2; + int iy = cy + cpad; + int lbl_h = 34; + + if (st->wp_cfg.type == GEMINUX_WP_IMAGE) { + gemui_draw_text(cr, t, (gemui_rect_t){cx, iy, c_in_w, lbl_h}, + "Scaling Mode", -2, true, GEMUI_ALIGN_LEFT, t->fg_muted); + iy += lbl_h + 6; + + int gap = 10; + int mw = (c_in_w - gap * 2) / 3; + int m_h = 56; + for (int i = 0; i < GEMINUX_WP_MODE_COUNT; i++) { + int r = i / 3, c = i % 3; + gemui_draw_button(st->app, cr, (gemui_rect_t){cx + c * (mw + gap), iy + r * (m_h + gap), mw, m_h}, + geminux_wp_mode_label((geminux_wp_mode_t)i), HIT_WP_MODE, i, + false, (int)st->wp_cfg.mode == i, false); + } + iy += m_h * 2 + gap + 12; + + gemui_draw_text(cr, t, (gemui_rect_t){cx, iy, c_in_w, lbl_h}, + "Background Matte (for Fit / Center)", -2, true, GEMUI_ALIGN_LEFT, t->fg_muted); + iy += lbl_h + 6; + + int tog_w = (c_in_w * 36) / 100; + int sw_w = 64; + int paste_w = 136; + int hex_w = c_in_w - tog_w - sw_w - paste_w - gap * 3; + gemui_draw_toggle(st->app, cr, (gemui_rect_t){cx, iy, tog_w, m_h}, + "Match Theme", st->wp_cfg.use_theme_bg, HIT_WP_THEME_BG, 0, false); + gemui_color_t mc; + gemui_color_parse(bg_hex, &mc); + int hx = cx + tog_w + gap; + gemui_fill_round(cr, (gemui_rect_t){hx, iy, sw_w, m_h}, 8.0, mc); + gemui_stroke_round(cr, (gemui_rect_t){hx, iy, sw_w, m_h}, 8.0, 1.5, t->border); + gemui_draw_input(st->app, cr, (gemui_rect_t){hx + sw_w + gap, iy, hex_w, m_h}, + "#RRGGBB", st->wp_hex, false, st->focus_id == HIT_WP_HEX, HIT_WP_HEX, 0); + gemui_draw_button(st->app, cr, (gemui_rect_t){cx + c_in_w - paste_w, iy, paste_w, m_h}, + "Paste", HIT_WP_PASTE_HEX, 0, false, false, false); + } else { + int line_h = 44; + char info1[96]; + snprintf(info1, sizeof(info1), "Selected Color: %s", bg_hex); + gemui_draw_text(cr, t, (gemui_rect_t){cx, iy, c_in_w, line_h}, + info1, 0, true, GEMUI_ALIGN_LEFT, t->fg_bright); + iy += line_h + 8; + gemui_draw_text(cr, t, (gemui_rect_t){cx, iy, c_in_w, line_h}, + "Saved to ~/.config/geminux/wallpaper.conf", -2, false, GEMUI_ALIGN_LEFT, t->fg_main); + iy += line_h + 4; + gemui_draw_text(cr, t, (gemui_rect_t){cx, iy, c_in_w, line_h}, + "Restored on session start, HDMI layout & theme switches", + -4, false, GEMUI_ALIGN_LEFT, t->fg_muted); + } + + /* Footer */ + int clear_w = 340; + int abw = 290; + int cbw = 220; + gemui_draw_button(st->app, cr, (gemui_rect_t){pad, fy, clear_w, btn_h}, + "Reset to Theme Bg", HIT_WP_CLEAR, 0, false, false, false); + gemui_draw_button(st->app, cr, (gemui_rect_t){w - pad - 14 - cbw - abw, fy, abw, btn_h}, + "Apply Wallpaper", HIT_WP_APPLY, 0, true, false, false); + gemui_draw_button(st->app, cr, (gemui_rect_t){w - pad - cbw, fy, cbw, btn_h}, + "Close", HIT_QUIT, 0, false, false, false); +} + static void on_theme(gemui_app_t *app, void *ud) { themes_state_t *st = (themes_state_t *)ud; const gemui_theme_t *cur = gemui_theme(app); if (cur && cur->name[0]) snprintf(st->active_name, sizeof(st->active_name), "%s", cur->name); + gemui_request_redraw(app); } static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) { @@ -1010,9 +1653,38 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) { themes_state_t *st = (themes_state_t *)ud; if (st->view == VIEW_EDITOR) draw_editor_view(st, cr, w, h); else if (st->view == VIEW_IMPORT) draw_import_view(st, cr, w, h); + else if (st->view == VIEW_WALLPAPER) draw_wallpaper_view(st, cr, w, h); else draw_browse_view(st, cr, w, h); } +static void wp_on_hex_edited(themes_state_t *st) { + int r = 0, g = 0, b = 0; + if (geminux_wp_parse_hex(st->wp_hex, &r, &g, &b)) { + st->wp_r = r; + st->wp_g = g; + st->wp_b = b; + geminux_wp_format_hex(r, g, b, st->wp_cfg.color, sizeof(st->wp_cfg.color)); + st->wp_cfg.use_theme_bg = false; + } +} + +static void on_focus_text_edited(themes_state_t *st) { + if (st->focus_id == HIT_ED_HEX) { + int r = 0, g = 0, b = 0; + if (geminux_xth_parse_hex(st->ed_hex, &r, &g, &b)) { + st->ed_r = r; st->ed_g = g; st->ed_b = b; + snprintf(st->ed_xth.colors[st->ed_color_idx], 16, "#%02x%02x%02x", r, g, b); + if (st->ed_auto_sync && st->ed_tab == ED_TAB_UI) geminux_xth_sync_derived(&st->ed_xth); + } + } else if (st->focus_id == HIT_IMP_PATH) { + imp_refresh_preview(st, true); + } else if (st->focus_id == HIT_WP_HEX) { + wp_on_hex_edited(st); + } else if (st->focus_id == HIT_WP_PATH) { + wp_refresh_preview(st); + } +} + static void apply_text_paste(themes_state_t *st) { if (!st->focus_buf || st->focus_cap < 2) return; char clip[512]; @@ -1023,14 +1695,30 @@ static void apply_text_paste(themes_state_t *st) { if (ch >= 0x20 && ch != 0x7f) st->focus_buf[len++] = (char)ch; } st->focus_buf[len] = '\0'; - if (st->focus_id == HIT_ED_HEX) { - int r = 0, g = 0, b = 0; - if (geminux_xth_parse_hex(st->ed_hex, &r, &g, &b)) { - st->ed_r = r; st->ed_g = g; st->ed_b = b; - ed_commit_rgb_to_slot(st); - } - } else if (st->focus_id == HIT_IMP_PATH) { - imp_refresh_preview(st, true); + on_focus_text_edited(st); + gemui_request_redraw(st->app); +} + +static void step_into_dir(const char *cur_dir, const char *entry, char *out, size_t sz) { + if (strcmp(entry, "..") == 0) { + snprintf(out, sz, "%.*s", (int)(sz - 1), cur_dir); + char *slash = strrchr(out, '/'); + if (slash && slash != out) *slash = '\0'; + else snprintf(out, sz, "/"); + } else { + char tmp[1024]; + snprintf(tmp, sizeof(tmp), "%s/%s", strcmp(cur_dir, "/") == 0 ? "" : cur_dir, entry); + snprintf(out, sz, "%.*s", (int)(sz - 1), tmp); + } +} + +static void switch_main_tab(themes_state_t *st, int target_view) { + set_focus_input(st, 0, NULL, 0); + if (target_view == VIEW_WALLPAPER) { + if (!st->wp_initialized) wp_init_state(st); + st->view = VIEW_WALLPAPER; + } else { + st->view = VIEW_BROWSE; } gemui_request_redraw(st->app); } @@ -1045,12 +1733,13 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char * if ((state & ControlMask) && (ks == XK_u || ks == XK_U)) { if (st->focus_buf) { st->focus_buf[0] = '\0'; + on_focus_text_edited(st); gemui_request_redraw(app); } return; } if (ks == XK_Escape) { - if (st->view != VIEW_BROWSE) { + if (st->view == VIEW_EDITOR || st->view == VIEW_IMPORT) { st->view = VIEW_BROWSE; set_focus_input(st, 0, NULL, 0); gemui_request_redraw(app); @@ -1067,16 +1756,7 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char * if (st->focus_buf) { if (ks == XK_BackSpace) { gemui_utf8_pop_char(st->focus_buf); - if (st->focus_id == HIT_ED_HEX) { - int r = 0, g = 0, b = 0; - if (geminux_xth_parse_hex(st->ed_hex, &r, &g, &b)) { - st->ed_r = r; st->ed_g = g; st->ed_b = b; - snprintf(st->ed_xth.colors[st->ed_color_idx], 16, "#%02x%02x%02x", r, g, b); - if (st->ed_auto_sync && st->ed_tab == ED_TAB_UI) geminux_xth_sync_derived(&st->ed_xth); - } - } else if (st->focus_id == HIT_IMP_PATH) { - imp_refresh_preview(st, true); - } + on_focus_text_edited(st); gemui_request_redraw(app); return; } @@ -1094,6 +1774,20 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char * gemui_request_redraw(app); return; } + if (st->focus_id == HIT_WP_PATH) { + char exp[800]; + expand_tilde(st->wp_path_input, exp, sizeof(exp)); + struct stat sb; + if (stat(exp, &sb) == 0 && S_ISDIR(sb.st_mode)) { + wp_scan_dir(st, exp, NULL); + gemui_request_redraw(app); + } else { + wp_refresh_preview(st); + set_focus_input(st, 0, NULL, 0); + wp_apply_now(st); + } + return; + } if (st->focus_id == HIT_FILTER && st->view == VIEW_BROWSE) { apply_selected(st); return; @@ -1108,16 +1802,7 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char * if (cur + add + 1 < st->focus_cap) { memcpy(st->focus_buf + cur, utf8, add); st->focus_buf[cur + add] = '\0'; - if (st->focus_id == HIT_ED_HEX) { - int r = 0, g = 0, b = 0; - if (geminux_xth_parse_hex(st->ed_hex, &r, &g, &b)) { - st->ed_r = r; st->ed_g = g; st->ed_b = b; - snprintf(st->ed_xth.colors[st->ed_color_idx], 16, "#%02x%02x%02x", r, g, b); - if (st->ed_auto_sync && st->ed_tab == ED_TAB_UI) geminux_xth_sync_derived(&st->ed_xth); - } - } else if (st->focus_id == HIT_IMP_PATH) { - imp_refresh_preview(st, true); - } + on_focus_text_edited(st); gemui_request_redraw(app); } return; @@ -1125,6 +1810,11 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char * } /* Unfocused navigation shortcuts */ + if (ks == XK_Tab && (st->view == VIEW_BROWSE || st->view == VIEW_WALLPAPER)) { + switch_main_tab(st, st->view == VIEW_BROWSE ? VIEW_WALLPAPER : VIEW_BROWSE); + return; + } + if (st->view == VIEW_BROWSE) { if (ks == XK_q) gemui_quit(app, 0); else if (ks == XK_Down || ks == XK_j) { @@ -1139,6 +1829,31 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char * reload_themes(st, NULL); gemui_request_redraw(app); } + } else if (st->view == VIEW_WALLPAPER) { + if (ks == XK_q) gemui_quit(app, 0); + else if (st->wp_cfg.type == GEMINUX_WP_IMAGE && (ks == XK_Down || ks == XK_j)) { + if (st->wp_sel + 1 < st->wp_count) { + st->wp_sel++; + wp_sync_sel_to_input(st); + gemui_request_redraw(app); + } + } else if (st->wp_cfg.type == GEMINUX_WP_IMAGE && (ks == XK_Up || ks == XK_k)) { + if (st->wp_sel > 0) { + st->wp_sel--; + wp_sync_sel_to_input(st); + gemui_request_redraw(app); + } + } else if (ks == XK_Return || ks == XK_space) { + if (st->wp_cfg.type == GEMINUX_WP_IMAGE && st->wp_sel >= 0 && st->wp_sel < st->wp_count && + st->wp_items[st->wp_sel].is_dir) { + char next[1024]; + step_into_dir(st->wp_dir, st->wp_items[st->wp_sel].name, next, sizeof(next)); + wp_scan_dir(st, next, NULL); + gemui_request_redraw(app); + } else { + wp_apply_now(st); + } + } } else if (st->view == VIEW_EDITOR && st->ed_tab != ED_TAB_GEN) { int first = 0, last = -1; ed_tab_slot_range(st->ed_tab, &first, &last); @@ -1154,14 +1869,19 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char * } } +static int slider_byte_from_x(gemui_rect_t sr, int x) { + if (sr.w <= 0) return 0; + int v = ((x - sr.x) * 255 + sr.w / 2) / sr.w; + if (v < 0) v = 0; + if (v > 255) v = 255; + return v; +} + static void update_rgb_slider_from_x(themes_state_t *st, int chan, int mx) { if (chan < 1 || chan > 3) return; gemui_rect_t sr = st->ed_slider_rect[chan - 1]; if (sr.w <= 0) return; - double f = (double)(mx - sr.x) / (double)sr.w; - if (f < 0.0) f = 0.0; - if (f > 1.0) f = 1.0; - int val = (int)(f * 255.0 + 0.5); + int val = slider_byte_from_x(sr, mx); if (chan == 1) st->ed_r = val; else if (chan == 2) st->ed_g = val; else st->ed_b = val; @@ -1169,6 +1889,18 @@ static void update_rgb_slider_from_x(themes_state_t *st, int chan, int mx) { gemui_request_redraw(st->app); } +static void update_wp_rgb_slider_from_x(themes_state_t *st, int chan, int mx) { + if (chan < 1 || chan > 3) return; + gemui_rect_t sr = st->wp_slider_rect[chan - 1]; + if (sr.w <= 0) return; + int v = slider_byte_from_x(sr, mx); + int r = (chan == 1) ? v : st->wp_r; + int g = (chan == 2) ? v : st->wp_g; + int b = (chan == 3) ? v : st->wp_b; + wp_commit_rgb(st, r, g, b); + gemui_request_redraw(st->app); +} + static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) { themes_state_t *st = (themes_state_t *)ud; @@ -1189,17 +1921,27 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v } else if (st->view == VIEW_IMPORT) { int next = st->imp_sel + delta; if (next >= 0 && next < st->imp_count) { st->imp_sel = next; gemui_request_redraw(app); } + } else if (st->view == VIEW_WALLPAPER && st->wp_cfg.type == GEMINUX_WP_IMAGE) { + int next = st->wp_sel + delta; + if (next >= 0 && next < st->wp_count) { + st->wp_sel = next; + wp_sync_sel_to_input(st); + gemui_request_redraw(app); + } } return; } if (type == GEMUI_PTR_UP) { st->ed_drag_chan = 0; + st->wp_drag_chan = 0; return; } if (type == GEMUI_PTR_MOVE) { if (st->view == VIEW_EDITOR && st->ed_drag_chan >= 1 && st->ed_drag_chan <= 3) { update_rgb_slider_from_x(st, st->ed_drag_chan, x); + } else if (st->view == VIEW_WALLPAPER && st->wp_drag_chan >= 1 && st->wp_drag_chan <= 3) { + update_wp_rgb_slider_from_x(st, st->wp_drag_chan, x); } return; } @@ -1213,13 +1955,16 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v } if (hit->id != HIT_FILTER && hit->id != HIT_ED_FIELD && - hit->id != HIT_ED_HEX && hit->id != HIT_IMP_PATH && hit->id != HIT_IMP_NAME) { + hit->id != HIT_ED_HEX && hit->id != HIT_IMP_PATH && hit->id != HIT_IMP_NAME && + hit->id != HIT_WP_PATH && hit->id != HIT_WP_HEX) { set_focus_input(st, 0, NULL, 0); } if (hit->id == HIT_FILTER) { set_focus_input(st, HIT_FILTER, st->filter, sizeof(st->filter)); gemui_request_redraw(app); + } else if (hit->id == HIT_MAIN_TAB) { + switch_main_tab(st, hit->val == 1 ? VIEW_WALLPAPER : VIEW_BROWSE); } else if (hit->id == HIT_ROW) { if (st->sel == hit->val) apply_selected(st); else { st->sel = hit->val; gemui_request_redraw(app); } @@ -1359,14 +2104,7 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v const dir_item_t *it = &st->imp_items[hit->val]; if (it->is_dir) { char next[1024]; - if (strcmp(it->name, "..") == 0) { - snprintf(next, sizeof(next), "%s", st->imp_dir); - char *slash = strrchr(next, '/'); - if (slash && slash != next) *slash = '\0'; - else snprintf(next, sizeof(next), "/"); - } else { - snprintf(next, sizeof(next), "%s/%s", strcmp(st->imp_dir, "/") == 0 ? "" : st->imp_dir, it->name); - } + step_into_dir(st->imp_dir, it->name, next, sizeof(next)); imp_scan_dir(st, next); snprintf(st->imp_path, sizeof(st->imp_path), "%s", st->imp_dir); st->imp_valid = false; @@ -1386,9 +2124,250 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v } else if (hit->id == HIT_IMP_BACK) { st->view = VIEW_BROWSE; gemui_request_redraw(app); + } else if (hit->id == HIT_WP_TYPE) { + st->wp_cfg.type = (hit->val == GEMINUX_WP_SOLID) ? GEMINUX_WP_SOLID : GEMINUX_WP_IMAGE; + st->wp_drag_chan = 0; + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_MODE && hit->val >= 0 && hit->val < GEMINUX_WP_MODE_COUNT) { + st->wp_cfg.mode = (geminux_wp_mode_t)hit->val; + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_QUICK_DIR) { + const char *home = getenv("HOME"); + const char *h = (home && home[0]) ? home : "/"; + char target[640] = ""; + if (hit->val == 1) { + snprintf(target, sizeof(target), "%s/Pictures", strcmp(h, "/") == 0 ? "" : h); + } else if (hit->val == 2) { + snprintf(target, sizeof(target), "/media/sdcard"); + } else if (hit->val == 3) { + snprintf(target, sizeof(target), "/"); + } else { + snprintf(target, sizeof(target), "%s", h); + } + if (!wp_is_existing_dir(target)) { + snprintf(target, sizeof(target), "%s", h); + } + wp_scan_dir(st, target, NULL); + if (!st->wp_path_input[0]) { + wp_select_first_image_if_dir(st); + wp_sync_sel_to_input(st); + } + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_TOGGLE_ALL) { + st->wp_show_all = !st->wp_show_all; + wp_scan_dir(st, st->wp_dir, NULL); + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_PATH) { + set_focus_input(st, HIT_WP_PATH, st->wp_path_input, sizeof(st->wp_path_input)); + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_PASTE_PATH) { + set_focus_input(st, HIT_WP_PATH, st->wp_path_input, sizeof(st->wp_path_input)); + apply_text_paste(st); + } else if (hit->id == HIT_WP_ITEM && hit->val >= 0 && hit->val < st->wp_count) { + const dir_item_t *it = &st->wp_items[hit->val]; + if (it->is_dir) { + char next[1024]; + step_into_dir(st->wp_dir, it->name, next, sizeof(next)); + wp_scan_dir(st, next, NULL); + } else { + bool was_same = (st->wp_sel == hit->val); + st->wp_sel = hit->val; + char full[1024]; + snprintf(full, sizeof(full), "%s/%s", strcmp(st->wp_dir, "/") == 0 ? "" : st->wp_dir, it->name); + bool same_input = (strcmp(st->wp_path_input, full) == 0); + snprintf(st->wp_path_input, sizeof(st->wp_path_input), "%.*s", + (int)(sizeof(st->wp_path_input) - 1), full); + wp_refresh_preview(st); + if (was_same && same_input) { + wp_apply_now(st); + return; + } + } + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_THEME_BG) { + st->wp_cfg.use_theme_bg = !st->wp_cfg.use_theme_bg; + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_HEX) { + set_focus_input(st, HIT_WP_HEX, st->wp_hex, sizeof(st->wp_hex)); + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_PASTE_HEX) { + set_focus_input(st, HIT_WP_HEX, st->wp_hex, sizeof(st->wp_hex)); + apply_text_paste(st); + } else if (hit->id == HIT_WP_SLIDER_R || hit->id == HIT_WP_SLIDER_G || hit->id == HIT_WP_SLIDER_B) { + st->wp_drag_chan = hit->val; + update_wp_rgb_slider_from_x(st, hit->val, x); + } else if (hit->id == HIT_WP_SWATCH && hit->val >= 0 && hit->val < 8) { + char sw_hexes[8][16]; + wp_swatch_palette(gemui_theme(app), sw_hexes); + int r = 0, g = 0, b = 0; + if (geminux_wp_parse_hex(sw_hexes[hit->val], &r, &g, &b)) { + wp_commit_rgb(st, r, g, b); + } + gemui_request_redraw(app); + } else if (hit->id == HIT_WP_CLEAR) { + st->wp_cfg.type = GEMINUX_WP_SOLID; + st->wp_cfg.use_theme_bg = true; + wp_apply_now(st); + } else if (hit->id == HIT_WP_APPLY) { + wp_apply_now(st); } } +static void print_wallpaper_usage(FILE *out) { + fprintf(out, + "Usage:\n" + " geminux-themes [--wallpaper]\n" + " geminux-themes --install /path/to/Theme.xth [Name]\n" + " geminux-themes --restore-wallpaper\n" + " geminux-themes --apply-wallpaper [IMAGE_PATH | --solid #RRGGBB | --theme-bg]" + " [--mode fill|fit|center|tile|stretch|span] [--bg #RRGGBB|theme] [--no-save]\n"); +} + +static int cli_restore_wallpaper(void) { + char cpath[560]; + wp_conf_path(cpath, sizeof(cpath)); + geminux_wp_cfg_t cfg; + if (!geminux_wp_cfg_load(cpath, &cfg)) { + return 0; + } + if (cfg.type == GEMINUX_WP_IMAGE && !cfg.path[0]) { + return 0; + } + char theme_bg[16]; + geminux_wp_read_theme_bg(NULL, theme_bg, sizeof(theme_bg)); + char err[256]; + if (!geminux_wp_apply_x11(&cfg, theme_bg, err, sizeof(err))) { + fprintf(stderr, "geminux-themes: %s\n", err[0] ? err : "failed to restore wallpaper"); + return 1; + } + return 0; +} + +static int cli_apply_wallpaper(int argc, char **argv) { + char cpath[560]; + wp_conf_path(cpath, sizeof(cpath)); + geminux_wp_cfg_t cfg; + bool had_cfg = geminux_wp_cfg_load(cpath, &cfg); + bool save = true; + bool got_target = false; + bool explicit_bg = false; + + for (int i = 2; i < argc; i++) { + const char *a = argv[i]; + if (strcmp(a, "-h") == 0 || strcmp(a, "--help") == 0) { + print_wallpaper_usage(stdout); + return 0; + } else if (strcmp(a, "--no-save") == 0) { + save = false; + } else if (strcmp(a, "--theme-bg") == 0) { + cfg.type = GEMINUX_WP_SOLID; + cfg.use_theme_bg = true; + got_target = true; + explicit_bg = true; + } else if (strcmp(a, "--solid") == 0) { + if (i + 1 >= argc) { + fprintf(stderr, "geminux-themes: --solid requires a #RRGGBB color\n"); + return 1; + } + int r = 0, g = 0, b = 0; + if (!geminux_wp_parse_hex(argv[++i], &r, &g, &b)) { + fprintf(stderr, "geminux-themes: invalid hex color '%s'\n", argv[i]); + return 1; + } + cfg.type = GEMINUX_WP_SOLID; + cfg.use_theme_bg = false; + geminux_wp_format_hex(r, g, b, cfg.color, sizeof(cfg.color)); + got_target = true; + explicit_bg = true; + } else if (strcmp(a, "--mode") == 0) { + if (i + 1 >= argc) { + fprintf(stderr, "geminux-themes: --mode requires fill|fit|center|tile|stretch|span\n"); + return 1; + } + geminux_wp_mode_t m = GEMINUX_WP_FILL; + if (!geminux_wp_mode_parse(argv[++i], &m)) { + fprintf(stderr, "geminux-themes: invalid wallpaper mode '%s'\n", argv[i]); + return 1; + } + cfg.mode = m; + } else if (strcmp(a, "--bg") == 0) { + if (i + 1 >= argc) { + fprintf(stderr, "geminux-themes: --bg requires #RRGGBB or theme\n"); + return 1; + } + const char *bv = argv[++i]; + if (geminux_wp_ci_eq(bv, "theme")) { + cfg.use_theme_bg = true; + } else { + int r = 0, g = 0, b = 0; + if (!geminux_wp_parse_hex(bv, &r, &g, &b)) { + fprintf(stderr, "geminux-themes: invalid background hex color '%s'\n", bv); + return 1; + } + cfg.use_theme_bg = false; + geminux_wp_format_hex(r, g, b, cfg.color, sizeof(cfg.color)); + } + explicit_bg = true; + } else if (a[0] == '-' && strcmp(a, "--") != 0) { + fprintf(stderr, "geminux-themes: unknown option '%s'\n", a); + print_wallpaper_usage(stderr); + return 1; + } else { + const char *raw = (strcmp(a, "--") == 0 && i + 1 < argc) ? argv[++i] : a; + char exp[800], bpath[800]; + expand_tilde(raw, exp, sizeof(exp)); + char *rp = realpath(exp, NULL); + const char *resolved = rp ? rp : exp; + struct stat sb; + if (stat(resolved, &sb) != 0 || !S_ISREG(sb.st_mode)) { + if (wp_resolve_bundled_image(raw, bpath, sizeof(bpath))) { + resolved = bpath; + } else { + fprintf(stderr, "geminux-themes: image file not found: %s\n", raw); + free(rp); + return 1; + } + } + cfg.type = GEMINUX_WP_IMAGE; + snprintf(cfg.path, sizeof(cfg.path), "%.*s", (int)(sizeof(cfg.path) - 1), resolved); + free(rp); + got_target = true; + } + } + + if (!got_target && !had_cfg && !explicit_bg) { + print_wallpaper_usage(stderr); + return 1; + } + if (cfg.type == GEMINUX_WP_IMAGE && !cfg.path[0]) { + fprintf(stderr, "geminux-themes: no image path specified\n"); + return 1; + } + + char theme_bg[16]; + geminux_wp_read_theme_bg(NULL, theme_bg, sizeof(theme_bg)); + char err[256]; + if (!geminux_wp_apply_x11(&cfg, theme_bg, err, sizeof(err))) { + fprintf(stderr, "geminux-themes: %s\n", err[0] ? err : "failed to apply wallpaper"); + return 1; + } + + if (save && !geminux_wp_cfg_save(cpath, &cfg)) { + fprintf(stderr, "geminux-themes: applied wallpaper, but failed to write %s\n", cpath); + return 1; + } + + const char *resolved_bg = cfg.use_theme_bg ? theme_bg : cfg.color; + if (cfg.type == GEMINUX_WP_SOLID) { + printf("Geminux applied solid background: %s%s\n", + resolved_bg, cfg.use_theme_bg ? " (theme)" : ""); + } else { + printf("Geminux applied wallpaper: %s (mode=%s, bg=%s)\n", + cfg.path, geminux_wp_mode_name(cfg.mode), resolved_bg); + } + return 0; +} + int main(int argc, char **argv) { if (argc >= 2 && strcmp(argv[1], "--install") == 0) { if (argc < 3 || !argv[2][0]) { @@ -1406,15 +2385,39 @@ int main(int argc, char **argv) { printf("Installed theme to %s\n", dest); return 0; } + if (argc >= 2 && strcmp(argv[1], "--restore-wallpaper") == 0) { + return cli_restore_wallpaper(); + } + if (argc >= 2 && strcmp(argv[1], "--apply-wallpaper") == 0) { + return cli_apply_wallpaper(argc, argv); + } - themes_state_t st; - memset(&st, 0, sizeof(st)); - st.app = gemui_create("geminux-themes", "Geminux Themes & Editor", 1900, 920, false); - if (!st.app) return 1; - reload_themes(&st, NULL); + bool start_wallpaper = false; + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--wallpaper") == 0) start_wallpaper = true; + else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { + print_wallpaper_usage(stdout); + return 0; + } + } + + themes_state_t *st = calloc(1, sizeof(*st)); + if (!st) return 1; + st->app = gemui_create("geminux-themes", "Geminux Themes & Wallpaper", 1900, 920, false); + if (!st->app) { + free(st); + return 1; + } + reload_themes(st, NULL); + if (start_wallpaper) { + wp_init_state(st); + st->view = VIEW_WALLPAPER; + } gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr, .on_theme = on_theme }; - gemui_set_handlers(st.app, &h, &st); - int rc = gemui_run(st.app); - gemui_destroy(st.app); + gemui_set_handlers(st->app, &h, st); + int rc = gemui_run(st->app); + wp_destroy_preview(st); + gemui_destroy(st->app); + free(st); return rc; } diff --git a/src/geminux-apps/geminux-wallpaper-x11.h b/src/geminux-apps/geminux-wallpaper-x11.h new file mode 100644 index 0000000..994ae51 --- /dev/null +++ b/src/geminux-apps/geminux-wallpaper-x11.h @@ -0,0 +1,758 @@ +/* + * Geminux X11 + Cairo image loader & native root Pixmap wallpaper engine. + * Included by src/geminux-apps/geminux-themes.c (uses pure-C gdk-pixbuf dlopen, + * Cairo PNG, libjpeg, libwebp, or ImageMagick fallback). + */ +#ifndef GEMINUX_WALLPAPER_X11_H +#define GEMINUX_WALLPAPER_X11_H + +#include "geminux-wallpaper.h" +#include "../libgemui/gemui.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_LIBJPEG +#include +#include +#endif + +#ifdef HAVE_LIBWEBP +#include +#endif + +typedef struct { + int x; + int y; + int w; + int h; +} geminux_wp_mon_t; + +static inline bool geminux_wp_have_cmd(const char *cmd) { + if (!cmd || !cmd[0]) return false; + if (strchr(cmd, '/')) return access(cmd, X_OK) == 0; + const char *path_env = getenv("PATH"); + if (!path_env || !path_env[0]) return false; + + const char *p = path_env; + while (*p) { + const char *colon = strchr(p, ':'); + size_t dlen = colon ? (size_t)(colon - p) : strlen(p); + char cand[768]; + if (dlen == 0) { + snprintf(cand, sizeof(cand), "./%s", cmd); + } else if (dlen < sizeof(cand) - 2) { + memcpy(cand, p, dlen); + if (cand[dlen - 1] == '/') cand[dlen] = '\0'; + else { + cand[dlen] = '/'; + cand[dlen + 1] = '\0'; + } + size_t cur = strlen(cand); + snprintf(cand + cur, sizeof(cand) - cur, "%s", cmd); + } else { + cand[0] = '\0'; + } + if (cand[0] && access(cand, X_OK) == 0) return true; + if (!colon) break; + p = colon + 1; + } + return false; +} + +static inline cairo_surface_t *geminux_wp_rgba_to_cairo(const unsigned char *px, + int w, int h, + int nc, int stride) { + if (!px || w <= 0 || h <= 0 || (nc != 3 && nc != 4) || stride < w * nc) return NULL; + cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + if (!surf || cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) { + if (surf) cairo_surface_destroy(surf); + return NULL; + } + + cairo_surface_flush(surf); + unsigned char *dst_data = cairo_image_surface_get_data(surf); + int dst_stride = cairo_image_surface_get_stride(surf); + + for (int y = 0; y < h; y++) { + const unsigned char *sp = px + (size_t)y * (size_t)stride; + uint32_t *dp = (uint32_t *)(dst_data + (size_t)y * (size_t)dst_stride); + for (int x = 0; x < w; x++) { + uint32_t r = sp[0]; + uint32_t g = sp[1]; + uint32_t b = sp[2]; + uint32_t a = (nc == 4) ? sp[3] : 255U; + if (a == 0U) { + dp[x] = 0U; + } else if (a == 255U) { + dp[x] = (255U << 24) | (r << 16) | (g << 8) | b; + } else { + uint32_t pr = (r * a + 127U) / 255U; + uint32_t pg = (g * a + 127U) / 255U; + uint32_t pb_c = (b * a + 127U) / 255U; + dp[x] = (a << 24) | (pr << 16) | (pg << 8) | pb_c; + } + sp += nc; + } + } + + cairo_surface_mark_dirty(surf); + return surf; +} + +static inline cairo_surface_t *geminux_wp_try_cairo_png(const char *path) { + FILE *f = fopen(path, "rb"); + if (!f) return NULL; + unsigned char sig[8]; + size_t nr = fread(sig, 1, sizeof(sig), f); + fclose(f); + if (nr != 8) return NULL; + static const unsigned char PNG_SIG[8] = {0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n'}; + if (memcmp(sig, PNG_SIG, 8) != 0) return NULL; + + cairo_surface_t *s = cairo_image_surface_create_from_png(path); + if (!s || cairo_surface_status(s) != CAIRO_STATUS_SUCCESS || + cairo_image_surface_get_width(s) <= 0 || cairo_image_surface_get_height(s) <= 0) { + if (s) cairo_surface_destroy(s); + return NULL; + } + return s; +} + +typedef void *(*geminux_gp_new_fn)(const char *, void **); +typedef void *(*geminux_gp_orient_fn)(void *); +typedef int (*geminux_gp_int_fn)(const void *); +typedef const unsigned char *(*geminux_gp_pixels_fn)(const void *); +typedef void (*geminux_gp_unref_fn)(void *); + +static inline void geminux_wp_dlsym_copy(void *dst_fn_ptr, void *handle, const char *sym) { + void *p = handle ? dlsym(handle, sym) : NULL; + memcpy(dst_fn_ptr, &p, sizeof(p)); +} + +static inline cairo_surface_t *geminux_wp_try_gdk_pixbuf(const char *path) { + static int init_state = 0; /* 0=uninit, 1=ready, -1=unavailable */ + static geminux_gp_new_fn fn_new = NULL; + static geminux_gp_orient_fn fn_orient = NULL; + static geminux_gp_int_fn fn_w = NULL; + static geminux_gp_int_fn fn_h = NULL; + static geminux_gp_int_fn fn_nc = NULL; + static geminux_gp_int_fn fn_bps = NULL; + static geminux_gp_int_fn fn_stride = NULL; + static geminux_gp_pixels_fn fn_pixels = NULL; + static geminux_gp_unref_fn fn_unref = NULL; + + if (init_state == 0) { + void *pb_dl = dlopen("libgdk_pixbuf-2.0.so.0", RTLD_LAZY); + if (!pb_dl) { + init_state = -1; + return NULL; + } + void *gobj_dl = dlopen("libgobject-2.0.so.0", RTLD_LAZY); + geminux_wp_dlsym_copy(&fn_new, pb_dl, "gdk_pixbuf_new_from_file"); + geminux_wp_dlsym_copy(&fn_orient, pb_dl, "gdk_pixbuf_apply_embedded_orientation"); + geminux_wp_dlsym_copy(&fn_w, pb_dl, "gdk_pixbuf_get_width"); + geminux_wp_dlsym_copy(&fn_h, pb_dl, "gdk_pixbuf_get_height"); + geminux_wp_dlsym_copy(&fn_nc, pb_dl, "gdk_pixbuf_get_n_channels"); + geminux_wp_dlsym_copy(&fn_bps, pb_dl, "gdk_pixbuf_get_bits_per_sample"); + geminux_wp_dlsym_copy(&fn_stride, pb_dl, "gdk_pixbuf_get_rowstride"); + geminux_wp_dlsym_copy(&fn_pixels, pb_dl, "gdk_pixbuf_read_pixels"); + geminux_wp_dlsym_copy(&fn_unref, pb_dl, "g_object_unref"); + if (!fn_unref && gobj_dl) { + geminux_wp_dlsym_copy(&fn_unref, gobj_dl, "g_object_unref"); + } + if (!fn_new || !fn_w || !fn_h || !fn_nc || !fn_bps || !fn_stride || !fn_pixels || !fn_unref) { + if (gobj_dl) dlclose(gobj_dl); + dlclose(pb_dl); + init_state = -1; + return NULL; + } + init_state = 1; + } + if (init_state < 0) return NULL; + + void *pb = fn_new(path, NULL); + if (!pb) return NULL; + if (fn_orient) { + void *ori = fn_orient(pb); + if (ori) { + fn_unref(pb); + pb = ori; + } + } + + int w = fn_w(pb); + int h = fn_h(pb); + int nc = fn_nc(pb); + int bps = fn_bps(pb); + int stride = fn_stride(pb); + const unsigned char *px = fn_pixels(pb); + + cairo_surface_t *surf = (bps == 8) ? geminux_wp_rgba_to_cairo(px, w, h, nc, stride) : NULL; + fn_unref(pb); + return surf; +} + +#ifdef HAVE_LIBJPEG +typedef struct { + struct jpeg_error_mgr pub; + jmp_buf setjmp_buf; +} geminux_wp_jpeg_err_t; + +static void geminux_wp_jpeg_error_exit(j_common_ptr cinfo) { + geminux_wp_jpeg_err_t *jerr = (geminux_wp_jpeg_err_t *)cinfo->err; + longjmp(jerr->setjmp_buf, 1); +} + +static inline cairo_surface_t *geminux_wp_try_libjpeg(const char *path) { + FILE *f = fopen(path, "rb"); + if (!f) return NULL; + unsigned char magic[2]; + size_t nr = fread(magic, 1, sizeof(magic), f); + rewind(f); + if (nr != 2 || magic[0] != 0xff || magic[1] != 0xd8) { + fclose(f); + return NULL; + } + + struct jpeg_decompress_struct cinfo; + geminux_wp_jpeg_err_t jerr; + cairo_surface_t *volatile surf = NULL; + unsigned char *volatile row_buf = NULL; + + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = geminux_wp_jpeg_error_exit; + if (setjmp(jerr.setjmp_buf)) { + free(row_buf); + if (surf) cairo_surface_destroy(surf); + jpeg_destroy_decompress(&cinfo); + fclose(f); + return NULL; + } + + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, f); + jpeg_read_header(&cinfo, TRUE); + cinfo.out_color_space = JCS_RGB; + jpeg_start_decompress(&cinfo); + + int w = (int)cinfo.output_width; + int h = (int)cinfo.output_height; + int nc = (int)cinfo.output_components; + if (w <= 0 || h <= 0 || nc != 3) { + jpeg_destroy_decompress(&cinfo); + fclose(f); + return NULL; + } + + surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) { + cairo_surface_destroy(surf); + jpeg_destroy_decompress(&cinfo); + fclose(f); + return NULL; + } + + row_buf = malloc((size_t)w * 3U); + if (!row_buf) { + cairo_surface_destroy(surf); + jpeg_destroy_decompress(&cinfo); + fclose(f); + return NULL; + } + + cairo_surface_flush(surf); + unsigned char *dst_data = cairo_image_surface_get_data(surf); + int dst_stride = cairo_image_surface_get_stride(surf); + + while (cinfo.output_scanline < cinfo.output_height) { + int y = (int)cinfo.output_scanline; + JSAMPROW ptr = row_buf; + jpeg_read_scanlines(&cinfo, &ptr, 1); + uint32_t *dp = (uint32_t *)(dst_data + (size_t)y * (size_t)dst_stride); + for (int x = 0; x < w; x++) { + uint32_t r = row_buf[x * 3]; + uint32_t g = row_buf[x * 3 + 1]; + uint32_t b = row_buf[x * 3 + 2]; + dp[x] = (255U << 24) | (r << 16) | (g << 8) | b; + } + } + + cairo_surface_mark_dirty(surf); + free(row_buf); + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + fclose(f); + return surf; +} +#endif + +#ifdef HAVE_LIBWEBP +static inline cairo_surface_t *geminux_wp_try_libwebp(const char *path) { + FILE *f = fopen(path, "rb"); + if (!f) return NULL; + unsigned char hdr[12]; + size_t nr = fread(hdr, 1, sizeof(hdr), f); + if (nr != sizeof(hdr) || memcmp(hdr, "RIFF", 4) != 0 || memcmp(hdr + 8, "WEBP", 4) != 0) { + fclose(f); + return NULL; + } + + struct stat sb; + if (fstat(fileno(f), &sb) != 0 || !S_ISREG(sb.st_mode) || + sb.st_size <= 12 || (uint64_t)sb.st_size > 64ULL * 1024ULL * 1024ULL) { + fclose(f); + return NULL; + } + + size_t fsz = (size_t)sb.st_size; + uint8_t *raw = malloc(fsz); + if (!raw) { + fclose(f); + return NULL; + } + rewind(f); + size_t got = fread(raw, 1, fsz, f); + fclose(f); + if (got != fsz) { + free(raw); + return NULL; + } + + int w = 0, h = 0; + uint8_t *rgba = WebPDecodeRGBA(raw, fsz, &w, &h); + free(raw); + if (!rgba) return NULL; + + cairo_surface_t *surf = geminux_wp_rgba_to_cairo(rgba, w, h, 4, w * 4); + WebPFree(rgba); + return surf; +} +#endif + +static inline cairo_surface_t *geminux_wp_try_magick_fallback(const char *path) { + const char *cmd = geminux_wp_have_cmd("magick") ? "magick" + : (geminux_wp_have_cmd("convert") ? "convert" : NULL); + if (!cmd) return NULL; + + const char *tmpdir = getenv("TMPDIR"); + if (!tmpdir || !tmpdir[0]) tmpdir = "/tmp"; + char tmpl[320]; + snprintf(tmpl, sizeof(tmpl), "%.*s/geminux-wp-XXXXXX", (int)(sizeof(tmpl) - 24), tmpdir); + int fd = mkstemp(tmpl); + if (fd < 0) return NULL; + close(fd); + + char out_spec[336]; + snprintf(out_spec, sizeof(out_spec), "png:%s", tmpl); + const char *av[] = {cmd, path, out_spec, NULL}; + cairo_surface_t *s = NULL; + if (gemui_run_cmd_timeout(av, NULL, 0, 8000) == 0) { + s = geminux_wp_try_cairo_png(tmpl); + } + unlink(tmpl); + return s; +} + +static inline cairo_surface_t *geminux_wp_load_surface(const char *path, + int *out_orig_w, + int *out_orig_h) { + if (out_orig_w) *out_orig_w = 0; + if (out_orig_h) *out_orig_h = 0; + if (!path || !path[0]) return NULL; + + struct stat sb; + if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) return NULL; + + cairo_surface_t *s = geminux_wp_try_gdk_pixbuf(path); + if (!s) s = geminux_wp_try_cairo_png(path); +#ifdef HAVE_LIBJPEG + if (!s) s = geminux_wp_try_libjpeg(path); +#endif +#ifdef HAVE_LIBWEBP + if (!s) s = geminux_wp_try_libwebp(path); +#endif + if (!s) s = geminux_wp_try_magick_fallback(path); + + if (s) { + if (out_orig_w) *out_orig_w = cairo_image_surface_get_width(s); + if (out_orig_h) *out_orig_h = cairo_image_surface_get_height(s); + } + return s; +} + +static inline cairo_surface_t *geminux_wp_make_preview_surface(const char *path, + int max_w, int max_h, + int *out_orig_w, + int *out_orig_h) { + int ow = 0, oh = 0; + cairo_surface_t *full = geminux_wp_load_surface(path, &ow, &oh); + if (out_orig_w) *out_orig_w = ow; + if (out_orig_h) *out_orig_h = oh; + if (!full || ow <= 0 || oh <= 0) return full; + + if (max_w <= 0 || max_h <= 0 || (ow <= max_w && oh <= max_h)) { + return full; + } + + double sx = (double)max_w / (double)ow; + double sy = (double)max_h / (double)oh; + double sc = (sx < sy) ? sx : sy; + int tw = (int)((double)ow * sc + 0.5); + int th = (int)((double)oh * sc + 0.5); + if (tw < 1) tw = 1; + if (th < 1) th = 1; + + cairo_surface_t *thumb = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, tw, th); + if (cairo_surface_status(thumb) != CAIRO_STATUS_SUCCESS) { + cairo_surface_destroy(thumb); + return full; + } + cairo_t *cr = cairo_create(thumb); + cairo_scale(cr, (double)tw / (double)ow, (double)th / (double)oh); + cairo_set_source_surface(cr, full, 0.0, 0.0); + cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BEST); + cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_PAD); + cairo_paint(cr); + cairo_destroy(cr); + cairo_surface_destroy(full); + return thumb; +} + +static inline void geminux_wp_render_onto_cairo(cairo_t *cr, + double rx, double ry, + double rw, double rh, + const geminux_wp_cfg_t *cfg, + cairo_surface_t *img, + const char *resolved_bg_hex) { + if (!cr || rw <= 0.0 || rh <= 0.0) return; + + int r = 8, g = 9, b = 11; + if (!geminux_wp_parse_hex(resolved_bg_hex, &r, &g, &b)) { + r = 8; g = 9; b = 11; + } + + cairo_save(cr); + cairo_rectangle(cr, rx, ry, rw, rh); + cairo_clip(cr); + + cairo_set_source_rgb(cr, (double)r / 255.0, (double)g / 255.0, (double)b / 255.0); + cairo_paint(cr); + + if (cfg && cfg->type == GEMINUX_WP_IMAGE && img && + cairo_surface_status(img) == CAIRO_STATUS_SUCCESS) { + int iw = cairo_image_surface_get_width(img); + int ih = cairo_image_surface_get_height(img); + if (iw > 0 && ih > 0) { + if (cfg->mode == GEMINUX_WP_TILE) { + cairo_translate(cr, rx, ry); + cairo_set_source_surface(cr, img, 0.0, 0.0); + cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); + cairo_paint(cr); + } else { + double dx = 0.0, dy = 0.0, dw = 0.0, dh = 0.0; + geminux_wp_calc_placement(iw, ih, (int)(rw + 0.5), (int)(rh + 0.5), + cfg->mode, &dx, &dy, &dw, &dh); + if (dw > 0.0 && dh > 0.0) { + cairo_rectangle(cr, rx + dx, ry + dy, dw, dh); + cairo_clip(cr); + cairo_translate(cr, rx + dx, ry + dy); + cairo_scale(cr, dw / (double)iw, dh / (double)ih); + cairo_set_source_surface(cr, img, 0.0, 0.0); + cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BEST); + cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_PAD); + cairo_paint(cr); + } + } + } + } + + cairo_restore(cr); +} + +static inline void geminux_wp_read_theme_bg(Display *dpy_opt, char *out_hex, size_t sz) { + if (!out_hex || sz == 0) return; + snprintf(out_hex, sz, "#08090b"); + + Display *dpy = dpy_opt ? dpy_opt : XOpenDisplay(NULL); + bool found = false; + if (dpy) { + XrmInitialize(); + char *prop_rms = NULL; + const char *rms = NULL; + Atom actual_type = None; + int actual_fmt = 0; + unsigned long nitems = 0, bytes_after = 0; + unsigned char *prop_data = NULL; + Window root = DefaultRootWindow(dpy); + if (XGetWindowProperty(dpy, root, XA_RESOURCE_MANAGER, 0, 1024L * 1024L, False, XA_STRING, + &actual_type, &actual_fmt, &nitems, &bytes_after, &prop_data) == Success) { + if (prop_data && actual_fmt == 8 && nitems > 0) { + prop_rms = (char *)prop_data; + rms = prop_rms; + } else if (prop_data) { + XFree(prop_data); + } + } + if (!rms || !rms[0]) { + rms = XResourceManagerString(dpy); + } + if (rms && rms[0]) { + XrmDatabase db = XrmGetStringDatabase(rms); + if (db) { + char *rtype = NULL; + XrmValue rval; + if (XrmGetResource(db, "theme.bgMain", "Theme.BgMain", &rtype, &rval) && rval.addr) { + int r = 0, g = 0, b = 0; + if (geminux_wp_parse_hex(rval.addr, &r, &g, &b)) { + geminux_wp_format_hex(r, g, b, out_hex, sz); + found = true; + } + } + XrmDestroyDatabase(db); + } + } + if (prop_rms) XFree(prop_rms); + if (!dpy_opt) XCloseDisplay(dpy); + } + + if (found) return; + + const char *home = getenv("HOME"); + if (!home || !home[0]) return; + char xpath[640]; + snprintf(xpath, sizeof(xpath), "%s/.Xresources", home); + FILE *f = fopen(xpath, "r"); + if (!f) return; + + char line[512]; + while (fgets(line, sizeof(line), f)) { + const char *p = line; + while (*p == ' ' || *p == '\t') p++; + if (strncmp(p, "theme.bgMain:", 13) == 0) { + p += 13; + while (*p == ' ' || *p == '\t') p++; + char tok[32]; + size_t ti = 0; + while (p[ti] && !isspace((unsigned char)p[ti]) && ti + 1 < sizeof(tok)) { + tok[ti] = p[ti]; + ti++; + } + tok[ti] = '\0'; + int r = 0, g = 0, b = 0; + if (geminux_wp_parse_hex(tok, &r, &g, &b)) { + geminux_wp_format_hex(r, g, b, out_hex, sz); + break; + } + } + } + fclose(f); +} + +static inline int geminux_wp_noop_xerr(Display *d, XErrorEvent *e) { + (void)d; + (void)e; + return 0; +} + +static inline int geminux_wp_query_monitors(Display *dpy, Window root, int sw, int sh, + geminux_wp_mon_t *out, int max_out) { + int n = 0; + XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root); + if (!res) res = XRRGetScreenResources(dpy, root); + if (res) { + RRCrtc seen_crtcs[16]; + int n_seen = 0; + for (int i = 0; i < res->noutput && n < max_out; i++) { + XRROutputInfo *oi = XRRGetOutputInfo(dpy, res, res->outputs[i]); + if (!oi) continue; + if (oi->connection == RR_Connected && oi->crtc != None) { + bool dup = false; + for (int s = 0; s < n_seen; s++) { + if (seen_crtcs[s] == oi->crtc) { dup = true; break; } + } + if (!dup && n_seen < 16) { + seen_crtcs[n_seen++] = oi->crtc; + XRRCrtcInfo *ci = XRRGetCrtcInfo(dpy, res, oi->crtc); + if (ci) { + if (ci->width > 0 && ci->height > 0) { + out[n].x = ci->x; + out[n].y = ci->y; + out[n].w = (int)ci->width; + out[n].h = (int)ci->height; + n++; + } + XRRFreeCrtcInfo(ci); + } + } + } + XRRFreeOutputInfo(oi); + } + XRRFreeScreenResources(res); + } + + if (n <= 0 && XineramaIsActive(dpy)) { + int nx = 0; + XineramaScreenInfo *xs = XineramaQueryScreens(dpy, &nx); + if (xs) { + for (int i = 0; i < nx && n < max_out; i++) { + if (xs[i].width > 0 && xs[i].height > 0) { + out[n].x = xs[i].x_org; + out[n].y = xs[i].y_org; + out[n].w = xs[i].width; + out[n].h = xs[i].height; + n++; + } + } + XFree(xs); + } + } + + if (n <= 0 && max_out > 0) { + out[0].x = 0; + out[0].y = 0; + out[0].w = sw; + out[0].h = sh; + n = 1; + } + return n; +} + +static inline bool geminux_wp_read_root_pmap(Display *dpy, Window root, Atom prop, unsigned long *out_id) { + Atom actual_type = None; + int actual_fmt = 0; + unsigned long nitems = 0, bytes_after = 0; + unsigned char *data = NULL; + bool ok = false; + + if (XGetWindowProperty(dpy, root, prop, 0, 1, False, XA_PIXMAP, + &actual_type, &actual_fmt, &nitems, &bytes_after, &data) == Success) { + if (actual_type == XA_PIXMAP && actual_fmt == 32 && nitems == 1 && data) { + unsigned long val = 0; + memcpy(&val, data, sizeof(unsigned long)); + if (val != 0UL) { + *out_id = val; + ok = true; + } + } + if (data) XFree(data); + } + return ok; +} + +static inline bool geminux_wp_apply_x11(const geminux_wp_cfg_t *cfg, + const char *theme_bg_hex, + char *err_buf, size_t err_sz) { + if (err_buf && err_sz > 0) err_buf[0] = '\0'; + if (!cfg) { + if (err_buf && err_sz > 0) snprintf(err_buf, err_sz, "Invalid wallpaper config"); + return false; + } + + char bg_hex[16]; + int r = 0, g = 0, b = 0; + if (cfg->use_theme_bg && theme_bg_hex && geminux_wp_parse_hex(theme_bg_hex, &r, &g, &b)) { + geminux_wp_format_hex(r, g, b, bg_hex, sizeof(bg_hex)); + } else if (geminux_wp_parse_hex(cfg->color, &r, &g, &b)) { + geminux_wp_format_hex(r, g, b, bg_hex, sizeof(bg_hex)); + } else { + snprintf(bg_hex, sizeof(bg_hex), "#08090b"); + } + + cairo_surface_t *img = NULL; + if (cfg->type == GEMINUX_WP_IMAGE) { + img = geminux_wp_load_surface(cfg->path, NULL, NULL); + if (!img) { + if (err_buf && err_sz > 0) { + snprintf(err_buf, err_sz, "Unable to load image: %.180s", + cfg->path[0] ? cfg->path : "(no file selected)"); + } + return false; + } + } + + /* Dedicated Display connection so RetainPermanent never affects libgemui's main Display */ + Display *wdpy = XOpenDisplay(NULL); + if (!wdpy) { + if (img) cairo_surface_destroy(img); + if (err_buf && err_sz > 0) snprintf(err_buf, err_sz, "Failed to open X11 display"); + return false; + } + + int scr = DefaultScreen(wdpy); + Window root = RootWindow(wdpy, scr); + int sw = DisplayWidth(wdpy, scr); + int sh = DisplayHeight(wdpy, scr); + if (sw <= 0 || sh <= 0) { + if (img) cairo_surface_destroy(img); + XCloseDisplay(wdpy); + if (err_buf && err_sz > 0) snprintf(err_buf, err_sz, "Invalid X11 screen dimensions"); + return false; + } + + geminux_wp_mon_t mons[16]; + int n_mons = geminux_wp_query_monitors(wdpy, root, sw, sh, mons, 16); + + Pixmap pmap = XCreatePixmap(wdpy, root, (unsigned int)sw, (unsigned int)sh, + (unsigned int)DefaultDepth(wdpy, scr)); + cairo_surface_t *xsurf = cairo_xlib_surface_create(wdpy, pmap, DefaultVisual(wdpy, scr), sw, sh); + cairo_t *cr = cairo_create(xsurf); + + geminux_wp_cfg_t fill_only; + geminux_wp_cfg_init(&fill_only); + fill_only.type = GEMINUX_WP_SOLID; + fill_only.use_theme_bg = false; + geminux_wp_render_onto_cairo(cr, 0.0, 0.0, (double)sw, (double)sh, &fill_only, NULL, bg_hex); + + if (cfg->type == GEMINUX_WP_IMAGE) { + if (cfg->mode == GEMINUX_WP_SPAN || cfg->mode == GEMINUX_WP_TILE) { + geminux_wp_render_onto_cairo(cr, 0.0, 0.0, (double)sw, (double)sh, cfg, img, bg_hex); + } else { + for (int i = 0; i < n_mons; i++) { + geminux_wp_render_onto_cairo(cr, (double)mons[i].x, (double)mons[i].y, + (double)mons[i].w, (double)mons[i].h, + cfg, img, bg_hex); + } + } + } + + cairo_destroy(cr); + cairo_surface_flush(xsurf); + cairo_surface_destroy(xsurf); + if (img) cairo_surface_destroy(img); + + Atom a_xroot = XInternAtom(wdpy, "_XROOTPMAP_ID", False); + Atom a_eset = XInternAtom(wdpy, "ESETROOT_PMAP_ID", False); + + XGrabServer(wdpy); + unsigned long old_xroot = 0, old_eset = 0; + if (geminux_wp_read_root_pmap(wdpy, root, a_xroot, &old_xroot) && + geminux_wp_read_root_pmap(wdpy, root, a_eset, &old_eset) && + old_xroot == old_eset && old_xroot != (unsigned long)pmap) { + XErrorHandler prev = XSetErrorHandler(geminux_wp_noop_xerr); + XKillClient(wdpy, (XID)old_xroot); + XSync(wdpy, False); + XSetErrorHandler(prev); + } + + unsigned long pval = (unsigned long)pmap; + XSetWindowBackgroundPixmap(wdpy, root, pmap); + XChangeProperty(wdpy, root, a_xroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *)&pval, 1); + XChangeProperty(wdpy, root, a_eset, XA_PIXMAP, 32, PropModeReplace, (unsigned char *)&pval, 1); + XClearWindow(wdpy, root); + XUngrabServer(wdpy); + XSync(wdpy, False); + + XSetCloseDownMode(wdpy, RetainPermanent); + XCloseDisplay(wdpy); + return true; +} + +#endif /* GEMINUX_WALLPAPER_X11_H */ diff --git a/src/geminux-apps/geminux-wallpaper.h b/src/geminux-apps/geminux-wallpaper.h new file mode 100644 index 0000000..19ef1c6 --- /dev/null +++ b/src/geminux-apps/geminux-wallpaper.h @@ -0,0 +1,303 @@ +/* + * Geminux Wallpaper configuration, image filtering, and placement geometry helpers. + * Pure C11/POSIX with zero X11 or Cairo dependencies for unit-testability. + */ +#ifndef GEMINUX_WALLPAPER_H +#define GEMINUX_WALLPAPER_H + +#include +#include +#include +#include +#include +#include +#include +#include + +typedef enum { + GEMINUX_WP_IMAGE = 0, + GEMINUX_WP_SOLID = 1 +} geminux_wp_type_t; + +typedef enum { + GEMINUX_WP_FILL = 0, + GEMINUX_WP_FIT = 1, + GEMINUX_WP_CENTER = 2, + GEMINUX_WP_TILE = 3, + GEMINUX_WP_STRETCH = 4, + GEMINUX_WP_SPAN = 5, + GEMINUX_WP_MODE_COUNT = 6 +} geminux_wp_mode_t; + +typedef struct { + geminux_wp_type_t type; + geminux_wp_mode_t mode; + char path[768]; + char color[16]; + bool use_theme_bg; +} geminux_wp_cfg_t; + +static inline bool geminux_wp_ci_eq(const char *a, const char *b) { + if (!a || !b) return false; + while (*a && *b) { + if (tolower((unsigned char)*a) != tolower((unsigned char)*b)) return false; + a++; + b++; + } + return *a == '\0' && *b == '\0'; +} + +static inline void geminux_wp_cfg_init(geminux_wp_cfg_t *cfg) { + if (!cfg) return; + memset(cfg, 0, sizeof(*cfg)); + cfg->type = GEMINUX_WP_IMAGE; + cfg->mode = GEMINUX_WP_FILL; + snprintf(cfg->color, sizeof(cfg->color), "#08090b"); + cfg->use_theme_bg = true; +} + +static inline const char *geminux_wp_mode_name(geminux_wp_mode_t m) { + switch (m) { + case GEMINUX_WP_FILL: return "fill"; + case GEMINUX_WP_FIT: return "fit"; + case GEMINUX_WP_CENTER: return "center"; + case GEMINUX_WP_TILE: return "tile"; + case GEMINUX_WP_STRETCH: return "stretch"; + case GEMINUX_WP_SPAN: return "span"; + default: return "fill"; + } +} + +static inline const char *geminux_wp_mode_label(geminux_wp_mode_t m) { + switch (m) { + case GEMINUX_WP_FILL: return "Fill"; + case GEMINUX_WP_FIT: return "Fit"; + case GEMINUX_WP_CENTER: return "Center"; + case GEMINUX_WP_TILE: return "Tile"; + case GEMINUX_WP_STRETCH: return "Stretch"; + case GEMINUX_WP_SPAN: return "Span"; + default: return "Fill"; + } +} + +static inline bool geminux_wp_mode_parse(const char *s, geminux_wp_mode_t *out) { + if (!s || !s[0]) return false; + geminux_wp_mode_t m; + if (geminux_wp_ci_eq(s, "fill") || geminux_wp_ci_eq(s, "zoom")) m = GEMINUX_WP_FILL; + else if (geminux_wp_ci_eq(s, "fit") || geminux_wp_ci_eq(s, "max")) m = GEMINUX_WP_FIT; + else if (geminux_wp_ci_eq(s, "center") || geminux_wp_ci_eq(s, "centered")) m = GEMINUX_WP_CENTER; + else if (geminux_wp_ci_eq(s, "tile") || geminux_wp_ci_eq(s, "tiled")) m = GEMINUX_WP_TILE; + else if (geminux_wp_ci_eq(s, "stretch") || geminux_wp_ci_eq(s, "scale")) m = GEMINUX_WP_STRETCH; + else if (geminux_wp_ci_eq(s, "span")) m = GEMINUX_WP_SPAN; + else return false; + if (out) *out = m; + return true; +} + +static inline int geminux_wp_hex_digit(char c) { + 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; +} + +static inline bool geminux_wp_parse_hex(const char *s, int *r, int *g, int *b) { + if (!s) return false; + if (s[0] == '#') s++; + for (int i = 0; i < 6; i++) { + if (geminux_wp_hex_digit(s[i]) < 0) return false; + } + if (s[6] != '\0') return false; + int rv = (geminux_wp_hex_digit(s[0]) << 4) | geminux_wp_hex_digit(s[1]); + int gv = (geminux_wp_hex_digit(s[2]) << 4) | geminux_wp_hex_digit(s[3]); + int bv = (geminux_wp_hex_digit(s[4]) << 4) | geminux_wp_hex_digit(s[5]); + if (r) *r = rv; + if (g) *g = gv; + if (b) *b = bv; + return true; +} + +static inline void geminux_wp_format_hex(int r, int g, int b, char *out, size_t sz) { + if (!out || sz == 0) return; + if (r < 0) r = 0; else if (r > 255) r = 255; + if (g < 0) g = 0; else if (g > 255) g = 255; + if (b < 0) b = 0; else if (b > 255) b = 255; + snprintf(out, sz, "#%02x%02x%02x", r, g, b); +} + +static inline bool geminux_wp_is_image_name(const char *name) { + if (!name || !name[0]) return false; + const char *slash = strrchr(name, '/'); + const char *base = slash ? (slash + 1) : name; + const char *dot = strrchr(base, '.'); + if (!dot || dot == base || dot[1] == '\0') return false; + const char *ext = dot + 1; + static const char *const EXTS[] = { + "png", "jpg", "jpeg", "webp", "bmp", "gif", + "tif", "tiff", "svg", "pnm", "ppm", "pgm", "xbm", "xpm" + }; + for (size_t i = 0; i < sizeof(EXTS) / sizeof(EXTS[0]); i++) { + if (geminux_wp_ci_eq(ext, EXTS[i])) return true; + } + return false; +} + +static inline void geminux_wp_calc_placement(int img_w, int img_h, int dst_w, int dst_h, + geminux_wp_mode_t mode, + double *out_x, double *out_y, + double *out_w, double *out_h) { + double x = 0.0, y = 0.0, w = 0.0, h = 0.0; + if (img_w > 0 && img_h > 0 && dst_w > 0 && dst_h > 0) { + double sx = (double)dst_w / (double)img_w; + double sy = (double)dst_h / (double)img_h; + switch (mode) { + case GEMINUX_WP_FILL: + case GEMINUX_WP_SPAN: { + double s = (sx > sy) ? sx : sy; + w = (double)img_w * s; + h = (double)img_h * s; + x = ((double)dst_w - w) * 0.5; + y = ((double)dst_h - h) * 0.5; + break; + } + case GEMINUX_WP_FIT: { + double s = (sx < sy) ? sx : sy; + w = (double)img_w * s; + h = (double)img_h * s; + x = ((double)dst_w - w) * 0.5; + y = ((double)dst_h - h) * 0.5; + break; + } + case GEMINUX_WP_CENTER: + w = (double)img_w; + h = (double)img_h; + x = ((double)dst_w - w) * 0.5; + y = ((double)dst_h - h) * 0.5; + break; + case GEMINUX_WP_STRETCH: + x = 0.0; + y = 0.0; + w = (double)dst_w; + h = (double)dst_h; + break; + case GEMINUX_WP_TILE: + default: + x = 0.0; + y = 0.0; + w = (double)img_w; + h = (double)img_h; + break; + } + } + if (out_x) *out_x = x; + if (out_y) *out_y = y; + if (out_w) *out_w = w; + if (out_h) *out_h = h; +} + +static inline void geminux_wp_mkdir_p(const char *dir) { + if (!dir || !dir[0]) return; + char tmp[1024]; + snprintf(tmp, sizeof(tmp), "%.*s", (int)(sizeof(tmp) - 1), dir); + size_t len = strlen(tmp); + if (len > 1 && tmp[len - 1] == '/') tmp[len - 1] = '\0'; + for (char *p = tmp + 1; *p; p++) { + if (*p == '/') { + *p = '\0'; + mkdir(tmp, 0755); + *p = '/'; + } + } + mkdir(tmp, 0755); +} + +static inline bool geminux_wp_cfg_load(const char *conf_path, geminux_wp_cfg_t *cfg) { + if (!cfg) return false; + geminux_wp_cfg_init(cfg); + if (!conf_path || !conf_path[0]) return false; + + FILE *f = fopen(conf_path, "r"); + if (!f) return false; + + char line[1024]; + while (fgets(line, sizeof(line), f)) { + size_t n = strlen(line); + while (n > 0 && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = '\0'; + if (line[0] == '\0' || line[0] == '#') continue; + + if (strncmp(line, "TYPE=", 5) == 0) { + const char *v = line + 5; + if (geminux_wp_ci_eq(v, "solid")) cfg->type = GEMINUX_WP_SOLID; + else if (geminux_wp_ci_eq(v, "image")) cfg->type = GEMINUX_WP_IMAGE; + } else if (strncmp(line, "PATH=", 5) == 0) { + snprintf(cfg->path, sizeof(cfg->path), "%.*s", (int)(sizeof(cfg->path) - 1), line + 5); + } else if (strncmp(line, "MODE=", 5) == 0) { + geminux_wp_mode_t pm = GEMINUX_WP_FILL; + if (geminux_wp_mode_parse(line + 5, &pm)) cfg->mode = pm; + } else if (strncmp(line, "COLOR=", 6) == 0) { + int r = 0, g = 0, b = 0; + if (geminux_wp_parse_hex(line + 6, &r, &g, &b)) { + geminux_wp_format_hex(r, g, b, cfg->color, sizeof(cfg->color)); + } + } else if (strncmp(line, "USE_THEME_BG=", 13) == 0) { + cfg->use_theme_bg = (line[13] == '1'); + } + } + fclose(f); + return true; +} + +static inline bool geminux_wp_cfg_save(const char *conf_path, const geminux_wp_cfg_t *cfg) { + if (!conf_path || !conf_path[0] || !cfg) return false; + + const char *slash = strrchr(conf_path, '/'); + if (slash && slash > conf_path) { + char pdir[1024]; + size_t dlen = (size_t)(slash - conf_path); + if (dlen >= sizeof(pdir)) dlen = sizeof(pdir) - 1; + memcpy(pdir, conf_path, dlen); + pdir[dlen] = '\0'; + geminux_wp_mkdir_p(pdir); + } + + char clean_path[768]; + size_t pi = 0; + for (size_t i = 0; cfg->path[i] && pi + 1 < sizeof(clean_path); i++) { + if (cfg->path[i] != '\n' && cfg->path[i] != '\r') clean_path[pi++] = cfg->path[i]; + } + clean_path[pi] = '\0'; + + char hex[16]; + int r = 8, g = 9, b = 11; + if (geminux_wp_parse_hex(cfg->color, &r, &g, &b)) { + geminux_wp_format_hex(r, g, b, hex, sizeof(hex)); + } else { + snprintf(hex, sizeof(hex), "#08090b"); + } + + char tmp[1024]; + snprintf(tmp, sizeof(tmp), "%.*s.tmp.%ld", (int)(sizeof(tmp) - 32), conf_path, (long)getpid()); + FILE *f = fopen(tmp, "w"); + if (!f) return false; + + fprintf(f, "# Geminux wallpaper configuration\n"); + fprintf(f, "TYPE=%s\n", cfg->type == GEMINUX_WP_SOLID ? "solid" : "image"); + fprintf(f, "PATH=%s\n", clean_path); + fprintf(f, "MODE=%s\n", geminux_wp_mode_name(cfg->mode)); + fprintf(f, "COLOR=%s\n", hex); + fprintf(f, "USE_THEME_BG=%d\n", cfg->use_theme_bg ? 1 : 0); + + if (fflush(f) != 0) { + fclose(f); + remove(tmp); + return false; + } + fclose(f); + if (rename(tmp, conf_path) != 0) { + remove(tmp); + return false; + } + return true; +} + +#endif /* GEMINUX_WALLPAPER_H */ diff --git a/src/libgemui/gemui.c b/src/libgemui/gemui.c index f664b90..5c50bb8 100644 --- a/src/libgemui/gemui.c +++ b/src/libgemui/gemui.c @@ -150,40 +150,40 @@ bool gemui_color_parse(const char *hex, gemui_color_t *out) { void gemui_theme_defaults(gemui_theme_t *t) { memset(t, 0, sizeof(*t)); - snprintf(t->name, sizeof(t->name), "GeminuxHelio"); + snprintf(t->name, sizeof(t->name), "Anodized"); snprintf(t->font_face, sizeof(t->font_face), "Fira Code"); snprintf(t->icon_font_face, sizeof(t->icon_font_face), "DejaVuSansM Nerd Font"); t->base_font_size = 32; t->dpi = 192; - gemui_color_parse("#11141a", &t->bg_main); - gemui_color_parse("#161b23", &t->bg_bar); - gemui_color_parse("#1b212b", &t->bg_header); - gemui_color_parse("#141922", &t->bg_footer); - gemui_color_parse("#18202c", &t->bg_overlay); - gemui_color_parse("#1a202a", &t->bg_alt_even); - gemui_color_parse("#1e2531", &t->bg_alt_odd); - gemui_color_parse("#212936", &t->bg_input); - gemui_color_parse("#273244", &t->bg_input_focus); - gemui_color_parse("#232b38", &t->bg_button); - gemui_color_parse("#202835", &t->bg_search); - gemui_color_parse("#222b3a", &t->bg_bubble_in); - gemui_color_parse("#1f3a52", &t->bg_bubble_out); - gemui_color_parse("#233044", &t->bg_toast); - gemui_color_parse("#d8dee9", &t->fg_main); - gemui_color_parse("#eceff4", &t->fg_bright); - gemui_color_parse("#8a95a8", &t->fg_muted); - gemui_color_parse("#2f6feb", &t->sel_bg); - gemui_color_parse("#ffffff", &t->sel_fg); - gemui_color_parse("#58a6ff", &t->accent); - gemui_color_parse("#79c0ff", &t->accent_alt); - gemui_color_parse("#d2a8ff", &t->highlight); - gemui_color_parse("#30394a", &t->border); - gemui_color_parse("#262f3e", &t->divider); - gemui_color_parse("#3fb950", &t->success); - gemui_color_parse("#58a6ff", &t->info); - gemui_color_parse("#d29922", &t->warning); - gemui_color_parse("#f85149", &t->danger); - gemui_color_parse("#4d1c20", &t->danger_bg); + gemui_color_parse("#08090b", &t->bg_main); + gemui_color_parse("#0e1014", &t->bg_bar); + gemui_color_parse("#12151a", &t->bg_header); + gemui_color_parse("#0b0d11", &t->bg_footer); + gemui_color_parse("#171b22", &t->bg_overlay); + gemui_color_parse("#101318", &t->bg_alt_even); + gemui_color_parse("#14181f", &t->bg_alt_odd); + gemui_color_parse("#161a21", &t->bg_input); + gemui_color_parse("#1e232c", &t->bg_input_focus); + gemui_color_parse("#1c212a", &t->bg_button); + gemui_color_parse("#191e27", &t->bg_search); + gemui_color_parse("#181d25", &t->bg_bubble_in); + gemui_color_parse("#252c38", &t->bg_bubble_out); + gemui_color_parse("#1c222b", &t->bg_toast); + gemui_color_parse("#e4e8ee", &t->fg_main); + gemui_color_parse("#f5f7fa", &t->fg_bright); + gemui_color_parse("#89929f", &t->fg_muted); + gemui_color_parse("#38414f", &t->sel_bg); + gemui_color_parse("#f5f7fa", &t->sel_fg); + gemui_color_parse("#cfd6e0", &t->accent); + gemui_color_parse("#e5eaf0", &t->accent_alt); + gemui_color_parse("#e2bc72", &t->highlight); + gemui_color_parse("#2d3440", &t->border); + gemui_color_parse("#20252f", &t->divider); + gemui_color_parse("#79cf9c", &t->success); + gemui_color_parse("#9eb3c8", &t->info); + gemui_color_parse("#e2bc72", &t->warning); + gemui_color_parse("#e07a7a", &t->danger); + gemui_color_parse("#3f1d20", &t->danger_bg); } static void gemui_apply_xrm_db(XrmDatabase db, gemui_theme_t *t) { diff --git a/src/st/config.def.h b/src/st/config.def.h index b432707..4ca6581 100644 --- a/src/st/config.def.h +++ b/src/st/config.def.h @@ -96,32 +96,32 @@ unsigned int tabspaces = 8; /* Terminal colors (16 first used in escape sequence) */ static const char *colorname[] = { /* 8 normal colors */ - "black", - "red3", - "green3", - "yellow3", - "blue2", - "magenta3", - "cyan3", - "gray90", + "#08090b", + "#d97878", + "#79cf9c", + "#e2bc72", + "#8ba6c4", + "#b39bc8", + "#84b8be", + "#d5dce4", /* 8 bright colors */ - "gray50", - "red", - "green", - "yellow", - "#5c5cff", - "magenta", - "cyan", - "white", + "#5b6370", + "#eb9494", + "#96deb3", + "#edd092", + "#a6bdd6", + "#cab5dc", + "#a2cdd2", + "#f5f7fa", [255] = 0, /* more colors can be added after 255 to use with DefaultXX */ - "#161616", - "#dddddd", - "#f4d03f", - "#555555", + "#08090b", + "#e4e8ee", + "#cfd6e0", + "#08090b", }; diff --git a/src/webarchy/webarchy.cpp b/src/webarchy/webarchy.cpp index 579150c..67e696d 100644 --- a/src/webarchy/webarchy.cpp +++ b/src/webarchy/webarchy.cpp @@ -321,28 +321,28 @@ static const UaPreset kUaPresets[] = { }; struct XresTheme { - std::string name = "GeminuxHelio"; + std::string name = "Anodized"; std::string fontFace = "Fira Code, Noto Sans"; - std::string bgMain = "#0f1419"; - std::string bgBar = "#0b0e14"; - std::string bgHeader = "#131922"; - std::string bgOverlay = "#161d26"; - std::string bgAltEven = "#121820"; - std::string bgAltOdd = "#18202a"; - std::string bgInput = "#0b0e14"; - std::string bgInputFocus = "#1b2838"; - std::string bgButton = "#1d2633"; - std::string fgMain = "#e6e1cf"; - std::string fgBright = "#ffffff"; - std::string fgMuted = "#7b8898"; - std::string selBg = "#2b5278"; - std::string selFg = "#ffffff"; - std::string accent = "#59c2ff"; - std::string accentAlt = "#ffb454"; - std::string border = "#283444"; - std::string divider = "#364559"; - std::string danger = "#f07178"; - std::string dangerBg = "#4c1d24"; + std::string bgMain = "#08090b"; + std::string bgBar = "#0e1014"; + std::string bgHeader = "#12151a"; + std::string bgOverlay = "#171b22"; + std::string bgAltEven = "#101318"; + std::string bgAltOdd = "#14181f"; + std::string bgInput = "#161a21"; + std::string bgInputFocus = "#1e232c"; + std::string bgButton = "#1c212a"; + std::string fgMain = "#e4e8ee"; + std::string fgBright = "#f5f7fa"; + std::string fgMuted = "#89929f"; + std::string selBg = "#38414f"; + std::string selFg = "#f5f7fa"; + std::string accent = "#cfd6e0"; + std::string accentAlt = "#e5eaf0"; + std::string border = "#2d3440"; + std::string divider = "#20252f"; + std::string danger = "#e07a7a"; + std::string dangerBg = "#3f1d20"; }; XresTheme loadXresourcesTheme() { @@ -508,7 +508,7 @@ std::string sanitizeGtkThemeSuffix(const std::string& raw) { out.push_back(static_cast(ch)); } } - return out.empty() ? "GeminuxHelio" : out; + return out.empty() ? "Anodized" : out; } void applyGtkThemeCss(BrowserApp* app) {