From 92adef39bf56e641077e0af452d53d33614326f5 Mon Sep 17 00:00:00 2001 From: duma97 Date: Mon, 24 Nov 2025 22:24:25 +0400 Subject: [PATCH] Pywal major update, system-wide light/dark theme support. --- README.md | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ pywal.sh | 93 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 215 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 29a43e4..b922215 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,133 @@ wal -i ~/.config/hypr/wallpapers/sakura.jpg && ~/pywal.sh - This sync happens automatically on startup and when you open waypaper (Super+W) - For pywal integration, use `wal -i` as shown above, then run the apply script (which also syncs Caelestia) +### System-Wide Theme Syncing (Dark/Light Mode) + +The enhanced `pywal.sh` script now supports system-wide theme synchronization, making browsers, GTK apps, and other applications respect PyWal color scheme and dark/light mode preference. + +#### Basic Usage + +```bash +# Apply dark theme with wallpaper (default) +~/.config/hypr/pywal.sh ~/Pictures/wallpaper.jpg + +# Apply light theme with wallpaper +~/.config/hypr/pywal.sh ~/Pictures/wallpaper.jpg light + +# Switch to light mode (keep current wallpaper) +~/.config/hypr/pywal.sh "" light + +# Switch to dark mode (keep current wallpaper) +~/.config/hypr/pywal.sh "" dark + +# Refresh themes (reapply current colors) +~/.config/hypr/pywal.sh +``` + +#### Enhanced System-Wide Support (Optional) + +For full system-wide theming across all applications, install these optional packages: + +**1. GTK Theme Support** + +```bash +# Install GTK theme generator +yay -S wal-gtk-theme-git + +# The script will automatically generate GTK themes +# GTK apps (Nautilus, GNOME apps, etc.) will use PyWal colors +``` + +**2. Firefox Theme Support** + +```bash +# Install pywalfox backend +yay -S python-pywalfox +pywalfox install + +# Then install the Pywalfox extension from Firefox Add-ons: +# https://addons.mozilla.org/en-US/firefox/addon/pywalfox/ +``` + +**3. Qt Application Support (Optional)** + +```bash +# Install Qt theming tools +yay -S qt5ct qt6ct kvantum + +# Set environment variables +echo "QT_QPA_PLATFORMTHEME=qt5ct" >> ~/.config/environment.d/qt.conf +echo "QT_STYLE_OVERRIDE=kvantum" >> ~/.config/environment.d/qt.conf +``` + +**4. Create GTK Configuration Files** + +```bash +# Create GTK 3 settings +mkdir -p ~/.config/gtk-3.0 +cat > ~/.config/gtk-3.0/settings.ini << 'EOF' +[Settings] +gtk-theme-name=FlatColor +gtk-icon-theme-name=Papirus-Dark +gtk-font-name=Sans 10 +gtk-cursor-theme-name=Adwaita +gtk-cursor-theme-size=24 +gtk-application-prefer-dark-theme=1 +EOF + +# Create GTK 4 settings (same content) +mkdir -p ~/.config/gtk-4.0 +cp ~/.config/gtk-3.0/settings.ini ~/.config/gtk-4.0/ +``` + +#### What Gets Themed + +Once configured, the following applications will sync with your PyWal colors: + +- **Hyprland**: Window borders and decorations +- **Caelestia Shell**: Status bar and UI elements +- **Kitty Terminal**: Background, foreground, and color palette +- **GTK Applications**: File managers (Nautilus), settings, GNOME apps +- **Firefox**: Browser UI via Pywalfox (if installed) +- **Chrome/Chromium**: Via system dark mode preference +- **Qt Applications**: Via qt5ct/qt6ct (if configured) +- **Bash Shell**: Terminal color sequences + +#### Automatic Dark/Light Mode by Time (Optional) + +Create a script to automatically switch themes based on time of day: + +```bash +# Create auto-theme script +cat > ~/.local/bin/auto-theme.sh << 'EOF' +#!/bin/bash +HOUR=$(date +%H) + +if [ $HOUR -ge 18 ] || [ $HOUR -lt 6 ]; then + # Dark mode (6 PM to 6 AM) + ~/.config/hypr/pywal.sh "" dark +else + # Light mode (6 AM to 6 PM) + ~/.config/hypr/pywal.sh "" light +fi +EOF + +chmod +x ~/.local/bin/auto-theme.sh + +# Add to Hyprland config to run on startup +echo "exec-once = ~/.local/bin/auto-theme.sh" >> ~/.config/hypr/hyprland.conf +``` + +#### How It Works + +The enhanced `pywal.sh` script: +1. Generates PyWal colors from wallpaper (or switches theme mode) +2. Creates GTK themes via `wal-gtk` (if installed) +3. Sets system-wide dark/light preference via `gsettings` +4. Updates Firefox theme via `pywalfox` (if installed) +5. Reloads Hyprland, Caelestia, and Kitty with new colors +6. Automatically detects if theme is light or dark based on background brightness + ### Monitor Configuration If you have different monitors, adjust lines 4-18 in `~/.config/hypr/hyprland.conf`: diff --git a/pywal.sh b/pywal.sh index b7ebd2e..4474859 100755 --- a/pywal.sh +++ b/pywal.sh @@ -1,10 +1,68 @@ #!/bin/bash -# Script to apply pywal colors to Hyprland, Caelestia shell, and Kitty terminal +# Extended pywal script with system-wide theme support +# Usage: ./pywal.sh [wallpaper_path] [light|dark] +# Examples: +# ./pywal.sh ~/Pictures/wallpaper.jpg # Apply dark theme +# ./pywal.sh ~/Pictures/wallpaper.jpg light # Apply light theme +# ./pywal.sh # Just refresh themes (use existing wallpaper) -# Generate pywal colors (this assumes you've already run 'wal -i /path/to/wallpaper') -# The templates will be automatically processed +WALLPAPER="$1" +LIGHT_MODE="$2" -echo "Applying pywal colors to Hyprland, Caelestia, and Kitty..." +echo "Applying pywal colors system-wide..." + +# Generate pywal colors +if [ -n "$WALLPAPER" ]; then + # New wallpaper provided + if [ "$LIGHT_MODE" = "-l" ] || [ "$LIGHT_MODE" = "light" ]; then + wal -i "$WALLPAPER" -l + DARK_MODE=0 + GTK_THEME="prefer-light" + echo "✓ Generated light theme from wallpaper" + else + wal -i "$WALLPAPER" + DARK_MODE=1 + GTK_THEME="prefer-dark" + echo "✓ Generated dark theme from wallpaper" + fi +elif [ "$LIGHT_MODE" = "light" ] || [ "$LIGHT_MODE" = "-l" ]; then + # No wallpaper, just switch to light mode + wal -l + DARK_MODE=0 + GTK_THEME="prefer-light" + echo "✓ Switched to light theme" +elif [ "$LIGHT_MODE" = "dark" ]; then + # No wallpaper, just switch to dark mode + wal + DARK_MODE=1 + GTK_THEME="prefer-dark" + echo "✓ Switched to dark theme" +else + # No arguments, just refresh with existing colors + if [ -f ~/.cache/wal/wal ]; then + wal -R + # Detect if current theme is light or dark + BG_COLOR=$(grep -oP 'background.*#\K[0-9A-Fa-f]{6}' ~/.cache/wal/colors.json | head -1) + if [ -n "$BG_COLOR" ]; then + # Convert hex to decimal and check brightness + R=$((16#${BG_COLOR:0:2})) + G=$((16#${BG_COLOR:2:2})) + B=$((16#${BG_COLOR:4:2})) + BRIGHTNESS=$(( (R + G + B) / 3 )) + if [ $BRIGHTNESS -gt 128 ]; then + DARK_MODE=0 + GTK_THEME="prefer-light" + else + DARK_MODE=1 + GTK_THEME="prefer-dark" + fi + fi + echo "✓ Refreshed existing theme" + else + echo "✗ No wallpaper specified and no existing theme found" + exit 1 + fi +fi # Update Caelestia's wallpaper reference to match the one pywal used if [ -f ~/.cache/wal/wal ]; then @@ -22,6 +80,29 @@ if [ -f ~/.cache/wal/caelestia-scheme.json ]; then echo "✓ Caelestia colors updated" fi +# Generate GTK themes from PyWal colors +if command -v wal-gtk &> /dev/null; then + wal-gtk + echo "✓ GTK themes generated" +else + echo "ℹ wal-gtk not found - install 'wal-gtk-theme-git' for GTK theme support" +fi + +# Set GNOME/GTK dark mode preference (affects browsers and GTK apps) +if command -v gsettings &> /dev/null; then + gsettings set org.gnome.desktop.interface color-scheme "$GTK_THEME" 2>/dev/null && \ + echo "✓ System dark mode preference set to: $GTK_THEME" || \ + echo "ℹ Could not set GTK color scheme preference" +fi + +# Update Firefox theme via pywalfox +if command -v pywalfox &> /dev/null; then + pywalfox update &>/dev/null & + echo "✓ Firefox theme update triggered" +else + echo "ℹ pywalfox not found - install 'python-pywalfox' for Firefox support" +fi + # Reload Hyprland configuration if command -v hyprctl &> /dev/null; then hyprctl reload @@ -44,4 +125,6 @@ if command -v kitty &> /dev/null; then fi fi -echo "Done! Colors applied successfully." +echo "" +echo "Done! Theme applied system-wide." +echo "Current mode: $([ "$DARK_MODE" = "1" ] && echo "Dark" || echo "Light")"