From 334fa18594e916097755f4584c763b1c90e291b7 Mon Sep 17 00:00:00 2001 From: Christian Schendel Date: Sun, 7 Dec 2025 16:20:34 +0000 Subject: [PATCH 1/4] [feature] check for GTK3/qt6c settings files (in progress 1) --- common/night-theme-switcher.in | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/common/night-theme-switcher.in b/common/night-theme-switcher.in index 6b73c7c..8cb20b5 100755 --- a/common/night-theme-switcher.in +++ b/common/night-theme-switcher.in @@ -128,6 +128,22 @@ check_config() { fi } +_check_for_toolkit_settings_files() { + ## GTK3 + gtk3_settings_file="$XDG_CONFIG_HOME/gtk-3.0/settings.ini" + gtk4_settings_file="$XDG_CONFIG_HOME/gtk-4.0/settings.ini" + qt6ct_settings_file="$XDG_CONFIG_HOME/qt6ct/qt6ct.conf" + + if [[ ! -w "$gtk3_settings_file" ]]; then + touch "$gtk3_settings_file" + fi + if [[ ! -w "$gtk4_settings_file" ]]; then + touch "$gtk4_settings_file" + fi + if [[ ! -w "$qt6ct_settings_file" ]]; then + touch "$qt6ct_settings_file" + fi +} _set_theme() { ## gtk-theme @@ -186,7 +202,7 @@ switch-dark-light() { if [[ ! $gtk_color_scheme == ''\''prefer-dark'\''' ]]; then gtk_color_scheme=prefer-dark - gtk_prefer_dark_theme=true + gtk_prefer_dark_theme=1 gtk_theme=$gtk_theme_dark icon_theme=$icon_theme_dark qt_custom_palette=true @@ -194,7 +210,7 @@ switch-dark-light() { _set_theme else gtk_color_scheme=default - gtk_prefer_dark_theme=false + gtk_prefer_dark_theme=0 gtk_theme=$gtk_theme_light icon_theme=$icon_theme_light qt_custom_palette=true @@ -210,7 +226,7 @@ restore-theme-on-login() { if [[ ! $gtk_color_scheme == ''\''prefer-dark'\''' ]]; then gtk_color_scheme=default - gtk_prefer_dark_theme=false + gtk_prefer_dark_theme=0 gtk_theme=$gtk_theme_light icon_theme=$icon_theme_light qt_custom_palette=true @@ -218,7 +234,7 @@ restore-theme-on-login() { _set_theme else gtk_color_scheme=prefer-dark - gtk_prefer_dark_theme=true + gtk_prefer_dark_theme=1 gtk_theme=$gtk_theme_dark icon_theme=$icon_theme_dark qt_custom_palette=true @@ -269,6 +285,9 @@ case "$1" in r) check_config && restore-theme-on-login ;; + c) + check_config && _check_for_toolkit_settings_files && preview + ;; p) check_config && preview ;; @@ -279,6 +298,7 @@ case "$1" in echo echo -e "${bold} s) swith between dark and light theme${all_off}" echo -e "${bold} r) restore theme (usefull only once after login)${all_off}" + echo -e "${bold} c) create sane default GTK/qt6ct settings files${all_off}" echo -e "${bold} p) Preview settings${all_off}" ;; esac From 7d29b4e76676cd5184b6c9ebefe946b2f97ce6b3 Mon Sep 17 00:00:00 2001 From: Christian Schendel Date: Sun, 7 Dec 2025 20:52:42 +0000 Subject: [PATCH 2/4] [feature] check for GTK3/qt6c settings files (in progress 2) --- common/night-theme-switcher.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/night-theme-switcher.in b/common/night-theme-switcher.in index 8cb20b5..51f800d 100755 --- a/common/night-theme-switcher.in +++ b/common/night-theme-switcher.in @@ -128,12 +128,16 @@ check_config() { fi } -_check_for_toolkit_settings_files() { +_reset_settings() { ## GTK3 gtk3_settings_file="$XDG_CONFIG_HOME/gtk-3.0/settings.ini" gtk4_settings_file="$XDG_CONFIG_HOME/gtk-4.0/settings.ini" qt6ct_settings_file="$XDG_CONFIG_HOME/qt6ct/qt6ct.conf" + gsettings reset org.gnome.desktop.interface color-scheme + gsettings reset org.gnome.desktop.interface gtk-theme + gsettings reset org.gnome.desktop.interface icon-theme + if [[ ! -w "$gtk3_settings_file" ]]; then touch "$gtk3_settings_file" fi @@ -286,7 +290,7 @@ case "$1" in check_config && restore-theme-on-login ;; c) - check_config && _check_for_toolkit_settings_files && preview + check_config && _reset_settings && preview ;; p) check_config && preview From c450c079134cee054cd5af10c893bbf94cdfea1e Mon Sep 17 00:00:00 2001 From: Christian Schendel Date: Mon, 8 Dec 2025 10:55:57 +0000 Subject: [PATCH 3/4] [feature] check for check for plasma-workspace (in progress 4) --- common/night-theme-switcher.in | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/night-theme-switcher.in b/common/night-theme-switcher.in index 51f800d..a7fdad2 100755 --- a/common/night-theme-switcher.in +++ b/common/night-theme-switcher.in @@ -74,6 +74,17 @@ if ! command -v gsettings >/dev/null 2>&1; then echo -e "${red}==> ERROR:${all_off}${bold} ${mesg}${all_off}" exit 1 fi +if ! command -v /usr/lib/plasma-changeicons >/dev/null 2>&1; then + notify-send \ + 'Missing dependency' \ + 'plasma-changeicons not found.\nPlease install plasma-workspace.' \ + -h string:x-canonical-private-synchronous:sys-notify \ + -u critical \ + -i dialog-error + mesg="plasma-workspace is required to use this script." + echo -e "${red}==> ERROR:${all_off}${bold} ${mesg}${all_off}" + exit 1 +fi check_config() { if [[ ! -f $default_config_file ]]; then @@ -154,6 +165,7 @@ _set_theme() { gsettings set org.gnome.desktop.interface color-scheme "$gtk_color_scheme" gsettings set org.gnome.desktop.interface gtk-theme "$gtk_theme" gsettings set org.gnome.desktop.interface icon-theme "$icon_theme" + /usr/lib/plasma-changeicons "$icon_theme" >/dev/null 2>&1 ## GTK2 if [[ -w "$HOME/.gtkrc-2.0" ]]; then @@ -195,10 +207,6 @@ _set_theme() { sed -i "s,color_scheme_path=.*,color_scheme_path=$qt_color_scheme_path,g" \ "$HOME/.config/qt6ct/qt6ct.conf" fi - ## workaround if plasma-workspace is installed - if [ -x "$(command -v /usr/lib/plasma-changeicon)" ]; then - /usr/lib/plasma-changeicons "$icon_theme" - fi } switch-dark-light() { From 77037021eedb759af5f924bd4c87a83c52361201 Mon Sep 17 00:00:00 2001 From: Christian Schendel Date: Mon, 8 Dec 2025 22:01:55 +0000 Subject: [PATCH 4/4] [feature] remove use of sed in the GTK section (in progress 5) --- common/night-theme-switcher.in | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/common/night-theme-switcher.in b/common/night-theme-switcher.in index a7fdad2..89525a8 100755 --- a/common/night-theme-switcher.in +++ b/common/night-theme-switcher.in @@ -161,38 +161,13 @@ _reset_settings() { } _set_theme() { - ## gtk-theme + ## GTK gsettings set org.gnome.desktop.interface color-scheme "$gtk_color_scheme" gsettings set org.gnome.desktop.interface gtk-theme "$gtk_theme" gsettings set org.gnome.desktop.interface icon-theme "$icon_theme" - /usr/lib/plasma-changeicons "$icon_theme" >/dev/null 2>&1 - ## GTK2 - if [[ -w "$HOME/.gtkrc-2.0" ]]; then - sed -i "s/gtk-theme-name=.*/gtk-theme-name=$gtk_theme/g" \ - "$HOME/.gtkrc-2.0" - sed -i "s/gtk-icon-theme-name=.*/gtk-icon-theme-name=$icon_theme/g" \ - "$HOME/.gtkrc-2.0" - fi - ## GTK3 - if [[ -w "$HOME/.config/gtk-3.0/settings.ini" ]]; then - sed -i "s/gtk-application-prefer-dark-theme=.*/gtk-application-prefer-dark-theme=$gtk_prefer_dark_theme/g" \ - "$HOME/.config/gtk-3.0/settings.ini" - sed -i "s/gtk-theme-name=.*/gtk-theme-name=$gtk_theme/g" \ - "$HOME/.config/gtk-3.0/settings.ini" - sed -i "s/gtk-icon-theme-name=.*/gtk-icon-theme-name=$icon_theme/g" \ - "$HOME/.config/gtk-3.0/settings.ini" - fi - ## GTK4 - if [[ -w "$HOME/.config/gtk-4.0/settings.ini" ]]; then - sed -i "s/gtk-application-prefer-dark-theme=.*/gtk-application-prefer-dark-theme=$gtk_prefer_dark_theme/g" \ - "$HOME/.config/gtk-4.0/settings.ini" - sed -i "s/gtk-icon-theme-name=.*/gtk-icon-theme-name=$icon_theme/g" \ - "$HOME/.config/gtk-4.0/settings.ini" - sed -i "s/gtk-theme-name=.*/gtk-theme-name=$gtk_theme/g" \ - "$HOME/.config/gtk-4.0/settings.ini" - fi ## QT + /usr/lib/plasma-changeicons "$icon_theme" >/dev/null 2>&1 if [[ -w "$HOME/.config/qt5ct/qt5ct.conf" ]]; then sed -i "s/icon_theme=.*/icon_theme=$icon_theme/g" \ "$HOME/.config/qt5ct/qt5ct.conf"