From c2fc6dd83b7ee47adb13a600f98a8b15607e1453 Mon Sep 17 00:00:00 2001
From: eSh <mr.eshua@gmail.com>
Date: Sun, 6 Aug 2023 02:14:02 +0200
Subject: [PATCH 1/2] add themes and icons folder sync

---
 bin/periodic/fix-theming | 79 ++++++++++++++++++++++++++++++++--------
 1 file changed, 63 insertions(+), 16 deletions(-)

diff --git a/bin/periodic/fix-theming b/bin/periodic/fix-theming
index 7164577..151b036 100755
--- a/bin/periodic/fix-theming
+++ b/bin/periodic/fix-theming
@@ -1,30 +1,77 @@
 #!/bin/bash
 
+# Exit out if the same script is already running in the background
+pidof -sq -o %PPID -x "$(basename "$0")" && exit
+
+# Set the directory paths
+target_themes_dir="$HOME/.themes"
+target_icons_dir="$HOME/.icons"
+
+# Create target directories if they don't exist
+mkdir -p "$target_themes_dir" "$target_icons_dir" ||
+    { echo "failed to make directories $target_themes_dir & $target_icons_dir"; exit 1; }
+
 sync_theme() {
-	# Get the current system theme
-	theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
-	# Enable syncing the current theme with xfwm4 if not already enabled
-	[ "$(xfconf-query -c xsettings -p /Xfce/SyncThemes)" != 'true' ] && xfconf-query -c xsettings -p /Xfce/SyncThemes -n -t bool -s true
-	# Apply the current theme with gsettings
-	gsettings set org.gnome.desktop.interface gtk-theme "$theme"
-	# Apply the current theme for the all the GTK flatpaks
-    flatpak override --user --env=GTK_THEME="$theme"
+    # Get the current system theme
+    theme_name=$(xfconf-query -c xsettings -p /Net/ThemeName)
+
+    # Cleanup source & target themes directories
+    source_themes_dirs=()
+    rm -rf "$target_themes_dir"/*
+
+    # Go through each item in $XDG_DATA_DIRS to find all other directories where
+    # themes are stored, and save only the current one to source_themes_dirs
+    while read -r dir; do
+        themes_subdir=${dir%/}/themes/${theme_name}
+        [ -d "$themes_subdir" ] && source_themes_dirs+=("$themes_subdir")
+    done < <(printf '%s:%s\n' "$XDG_DATA_DIRS" "$HOME/.local/share" | tr ':' '\n' | sort -u)
+
+    rsync -av --delete --progress "${source_themes_dirs[@]}" "$target_themes_dir"
+    echo "Directory $target_themes_dir is synchronized with source directories"
+
+    # Enable syncing the current theme with xfwm4 if not already enabled
+    [ "$(xfconf-query -c xsettings -p /Xfce/SyncThemes)" != 'true' ] && xfconf-query -c xsettings -p /Xfce/SyncThemes -n -t bool -s true
+    # Apply the current theme with gsettings
+    gsettings set org.gnome.desktop.interface gtk-theme "$theme_name"
+    # Apply the current theme for the all the GTK flatpaks
+    flatpak override --user --env=GTK_THEME="$theme_name"
+}
+
+sync_icons() {
+    # Get the current icons theme
+    icons_theme_name=$(xfconf-query -c xsettings -p /Net/IconThemeName)
+
+    # Cleanup source & target themes directories
+    source_icons_dirs=()
+    rm -rf "$target_icons_dir"/*
+
+    # Go through each item in $XDG_DATA_DIRS to find all other directories where
+    # icons are stored, and save only the current one to source_icons_dirs
+    while read -r dir; do
+        icons_subdir=${dir%/}/icons/${icons_theme_name}
+        [ -d "$icons_subdir" ] && source_icons_dirs+=("$icons_subdir")
+    done < <(printf '%s:%s\n' "$XDG_DATA_DIRS" "$HOME/.local/share" | tr ':' '\n' | sort -u)
+
+    rsync -av --delete --progress "${source_icons_dirs[@]}" "$target_icons_dir"
+    echo "Directory $target_icons_dir is synchronized with source directories"
 }
 
 sync_font() {
-	# Get the current system font
-	font=$(xfconf-query -c xsettings -p /Gtk/FontName)
-	# Apply the same font for the title of xfce windows
-	xfconf-query -c xfwm4 -p /general/title_font -n -t string -s "$font"
+    # Get the current system font
+    font=$(xfconf-query -c xsettings -p /Gtk/FontName)
+    # Apply the same font for the title of xfce windows
+    xfconf-query -c xfwm4 -p /general/title_font -n -t string -s "$font"
 }
 
 sync_theme
+sync_icons
 sync_font
 
 # Monitor when the user changes their system theme or font in XFCE and sync them as needed
 while read -r line; do
-	case "$line" in
-		'set: /Net/ThemeName') sync_theme ;;
-		'set: /Gtk/FontName') sync_font ;;
-	esac
+    case "$line" in
+        'set: /Net/ThemeName') sync_theme ;;
+        'set: /Net/IconThemeName') sync_icons ;;
+        'set: /Gtk/FontName') sync_font ;;
+    esac
 done < <(xfconf-query -c xsettings -m)
-- 
2.39.5


From 72dc4f5c0de995d86e462f6b2b20cfc851e8fe10 Mon Sep 17 00:00:00 2001
From: eSh <mr.eshua@gmail.com>
Date: Sun, 6 Aug 2023 02:15:26 +0200
Subject: [PATCH 2/2] Delete bin/periodic/fix-flatpaks-theming

---
 bin/periodic/fix-flatpaks-theming | 44 -------------------------------
 1 file changed, 44 deletions(-)
 delete mode 100755 bin/periodic/fix-flatpaks-theming

diff --git a/bin/periodic/fix-flatpaks-theming b/bin/periodic/fix-flatpaks-theming
deleted file mode 100755
index dd3f8f0..0000000
--- a/bin/periodic/fix-flatpaks-theming
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/bash
-
-# Exit out if the same script is already running in the background
-pidof -sq -o %PPID -x "$(basename "$0")" && exit
-
-# Set the directory paths
-
-target_themes_dir="$HOME/.themes"
-target_icons_dir="$HOME/.icons"
-
-# Create target directories if they don't exist
-mkdir -p "$target_themes_dir" "$target_icons_dir" ||
-	{ echo "failed to make directories $target_themes_dir & $target_icons_dir"; exit 1; }
-
-# Go through each item in $XDG_DATA_DIRS to find all other directories where
-# themes & icons are stored, and save these to source_themes_dirs & source_icons_dirs respectively
-while read -r dir; do
-	themes_subdir=${dir%/}/themes
-	icons_subdir=${dir%/}/icons
-	# Directories inside user's home directory will be created if nonexistant
-	for subdir in $themes_subdir $icons_subdir; do
-		[[ "$subdir" = "$HOME"/* ]] && mkdir -p "$subdir"
-	done
-	[ -d "$themes_subdir" ] && source_themes_dirs+=("$themes_subdir/")
-	[ -d "$icons_subdir" ] && source_icons_dirs+=("$icons_subdir/")
-done < <(printf '%s:%s\n' "$XDG_DATA_DIRS" "$HOME/.local/share" | tr ':' '\n' | sort -u)
-
-# Function to synchronize themes and icons from source to target directory
-sync_themes_and_icons() {
-    rsync -av --delete --progress "${source_themes_dirs[@]}" "$target_themes_dir"
-    rsync -av --delete --progress "${source_icons_dirs[@]}" "$target_icons_dir"
-    echo "Directories $target_themes_dir and $target_icons_dir are synchronized with source directories"
-}
-
-# Initial synchronization
-sync_themes_and_icons
-
-echo "Set watch for theme directories:" "${source_themes_dirs[@]}" ", and icon directories:" "${source_icons_dirs[@]}"
-
-# Start watching for file changes in the source theme and icon directories
-inotifywait -qmr -e 'modify,attrib,move,move_self,create,delete,delete_self,unmount' "${source_themes_dirs[@]}" "${source_icons_dirs[@]}" |
-while read -r _; do
-    sync_themes_and_icons
-done
-- 
2.39.5