forked from bimlas/xfce4-night-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxfce4-night-mode.sh
executable file
·214 lines (185 loc) · 6.05 KB
/
xfce4-night-mode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
# XFCE Night Mode: Switch between light and dark variants of a theme
#
# https://gitlab.com/bimlas/xfce4-night-mode (main repository)
# https://github.com/bimlas/xfce4-night-mode (mirror, please star if you like the plugin)
function show_usage()
{
progname="$(basename $0)"
echo "$progname [night|day|toggle]"
echo "Without parameters it will set dark theme from $SUNSET to $SUNRISE"
echo 'Use `xfce4-settings-editor` -> `night-mode` to modify settings'
}
function parse_args()
{
case $# in
0)
_get_mode_by_time
;;
1)
echo "$1"
;;
*)
exit 1
esac
}
function _get_mode_by_time()
{
now="$(date '+%H%M')"
if [ $now -ge "${SUNRISE/:/}" -a $now -le "${SUNSET/:/}" ]; then
echo 'day'
else
echo 'night'
fi
}
#######################################
# Set theme to requested theme if it is not already set
# Globals:
# GTK_LIGHT
# GTK_DARK
# ICON_LIGHT
# ICON_DARK
# CURSOR_LIGHT
# CURSOR_DARK
# WM_LIGHT
# WM_DARK
# Arguments:
# Channel: xfconf channel to change
# Property: property of that xfconf channel to change
# Variable name: global that contains the name of the requested theme
# Outputs:
# None
#######################################
function set_theme()
{
current_theme="$(xfconf-query --channel $1 --property $2)"
declare -n target_theme="$3"
if [ "$current_theme" = "$target_theme" ]; then
return
fi
xfconf-query --channel "$1" --property "$2" --set "$target_theme"
if [ $? != 0 ]; then
show_usage
exit 1
fi
if [ "$2" = "/Net/ThemeName" ]
then
gsettings set org.gnome.desktop.interface gtk-theme "$target_theme"
fi
if [ "$2" = "/Net/IconThemeName" ]
then
gsettings set org.gnome.desktop.interface icon-theme "$target_theme"
fi
if [ "$2" = "/Gtk/CursorThemeName" ]
then
gsettings set org.gnome.desktop.interface cursor-theme "$target_theme"
fi
}
function get_config()
{
result="$(xfconf-query --channel 'night-mode' --property /$1 2> /dev/null)"
if ! [ "$result" ]; then
result="$3"
xfconf-query --channel 'night-mode' --property "/$1" --set "$result" --create --type "$2"
fi
echo "$result"
}
function set_config()
{
xfconf-query --channel 'night-mode' --property "/$1" --set "$3" --create --type "$2"
}
TEXT="$(get_config 'text' 'string' '<span size="xx-large">☯</span>')"
SUNRISE="$(get_config 'sunrise' 'string' '7:30')"
SUNSET="$(get_config 'sunset' 'string' '18:00')"
GTK_LIGHT="$(get_config 'Light/GtkTheme' 'string' $(xfconf-query --channel xsettings --property /Net/ThemeName))"
GTK_DARK="$(get_config 'Dark/GtkTheme' 'string' $(xfconf-query --channel xsettings --property /Net/ThemeName))"
ICON_LIGHT="$(get_config 'Light/IconTheme' 'string' $(xfconf-query --channel xsettings --property /Net/IconThemeName))"
ICON_DARK="$(get_config 'Dark/IconTheme' 'string' $(xfconf-query --channel xsettings --property /Net/IconThemeName))"
CURSOR_LIGHT="$(get_config 'Light/CursorTheme' 'string' $(xfconf-query --channel xsettings --property /Gtk/CursorThemeName))"
CURSOR_DARK="$(get_config 'Dark/CursorTheme' 'string' $(xfconf-query --channel xsettings --property /Gtk/CursorThemeName))"
WM_LIGHT="$(get_config 'Light/WindowManagerTheme' 'string' $(xfconf-query --channel xfwm4 --property /general/theme))"
WM_DARK="$(get_config 'Dark/WindowManagerTheme' 'string' $(xfconf-query --channel xfwm4 --property /general/theme))"
USERSCRIPT_LIGHT="$(get_config 'Light/UserScript' 'string')"
USERSCRIPT_DARK="$(get_config 'Dark/UserScript' 'string')"
mode="$(parse_args $@)"
if [ $? != 0 ]; then
show_usage
exit 1
fi
if [ "$mode" = "toggle" ]; then
current="$(get_config 'active' 'string' 'day')"
case "$current" in
day)
mode='night'
;;
night)
mode='day'
;;
*)
exit 1
esac
fi
case "$mode" in
day)
suffix='LIGHT'
;;
night)
suffix='DARK'
;;
*)
exit 1
esac
# GTK theme
set_theme 'xsettings' '/Net/ThemeName' "GTK_$suffix"
# Icon theme
set_theme 'xsettings' '/Net/IconThemeName' "ICON_$suffix"
# Cursor theme
set_theme 'xsettings' '/Gtk/CursorThemeName' "CURSOR_$suffix"
# Window manager theme
set_theme 'xfwm4' '/general/theme' "WM_$suffix"
# apply settings to QT theme (using Kvantum Manager and qt5ct/qt6ct configs)
if type kvantummanager > /dev/null 2>&1; then
# gtk theme applied at the moment
gtk_theme=$(gsettings get org.gnome.desktop.interface gtk-theme)
# no Arc-Lighter (only KvArc) for Kvantum Manager, so apply filter
filter="Lighter"
# remove "-"" and "'" since themes are named like KvArc, KvArcDark, KvAdapta
qt_theme=$(echo "$gtk_theme" | tr -d "-" | tr -d "'" | sed "s/$filter//g")
# apply theme
kvantummanager --set Kv"$qt_theme"
# gtk icon theme applied at the moment, also filter out single quotes
icon_theme=$(gsettings get org.gnome.desktop.interface icon-theme | tr -d "'")
# qt5ct and qt6ct config file paths
qt5ct_conf="$HOME/.config/qt5ct/qt5ct.conf"
qt6ct_conf="$HOME/.config/qt6ct/qt6ct.conf"
# parameter to look for on config files (no CLI at the moment)
param="icon_theme="
# parameter replacement
replacement="icon_theme=$icon_theme"
# change QT icon theme (if qt5ct and qt6ct config files exist)
if [ -e "$qt5ct_conf" ]; then
sed -i "/$param/c\\$replacement" "$qt5ct_conf"
fi
if [ -e "$qt6ct_conf" ]; then
sed -i "/$param/c\\$replacement" "$qt6ct_conf"
fi
fi
set_config 'active' 'string' "$mode"
# Execute user script to change wallpaper, terminal theme, etc.
userscript="USERSCRIPT_$suffix"
if [ ! -z "${!userscript}" ]; then
XFCE_NIGHT_MODE="$mode" eval "${!userscript}" 2>&1 > /dev/null
fi
echo "<txt>$TEXT</txt>"
echo "<txtclick>$0 toggle</txtclick>"
echo "<tool>
Night mode: $SUNSET - $SUNRISE
Click to toggle mode for a while
Use \`xfce4-settings-editor\` -> \`night-mode\` to modify settings
To find out what values to enter, set the color schemes you want and copy
them from the appropriate location:
* GTK theme: \`xsettings/Net/ThemeName\`
* Icon theme: \`xsettings/Net/IconThemeName\`
* Cursor theme: \`xsettings/Gtk/CursorThemeName\`
* Window manager theme: \`xfwm4/general/theme\`
</tool>"