-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmxfb-separate-backgrounds
More file actions
executable file
·257 lines (184 loc) · 8.47 KB
/
mxfb-separate-backgrounds
File metadata and controls
executable file
·257 lines (184 loc) · 8.47 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
# Script to configure separate backgrounds for each Fluxbox Workspace
# Written by user PPC, modified by MX Devs Jan 2026
# Released under GPLv3
TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN="mxfb-accessories"
#EDIT STARTUP FILE FOR MXFB25
check_startup1=$(grep '#<< comment_start_setbg' $HOME/.fluxbox/startup)
check_startup2=$(grep 'COMMENTEDOUT4SETBG' $HOME/.fluxbox/startup)
if [ -z "$check_startup1" ] && [ -z "$check_startup2" ]; then
sed -i '/restore from saved background/a\
#<< comment_start_setbg' $HOME/.fluxbox/startup
find_line_nr=$(sed -n '/#<< comment_start_setbg/=' $HOME/.fluxbox/startup)
end_line_nr=$(( $find_line_nr + 8 ))
sed -i "$end_line_nr a\
#comment_end_setbg" $HOME/.fluxbox/startup
fi
#Confirmation Window
#TRANSLATORS Rotate backgrounds is a separate app which creates a wallpaper slideshow
NOTIFICATION="$(gettext 'Rotate Backgrounds has been disabled to avoid conflict."')"
#TRANSLATORS Main window text - line 1
MESSAGE1="$(gettext 'This app allows you to configure separate backgrounds for each Workspace')"
#TRANSLATORS Main window text - line 2
HINT1="$(gettext 'A selection window for each currently configured workspace will be displayed.')"
#TRANSLATORS Main window text - line 3
HINT2="$(gettext 'Select the background you want and click OK.')"
#TRANSLATORS Main window subtitle
NOTE0="$(gettext 'Notes')"
#TRANSLATORS Main window text - note 1
NOTE1="$(gettext 'Setting up separate backgrounds deactivates Nitrogen, the standard background settings app.')"
#TRANSLATORS Main window text - note 2
NOTE2="$(gettext 'Any background changes using Nitrogen will not be permanent until separate backgrounds are disabled.')"
#TRANSLATORS Main window text - note 3
NOTE3="$(gettext 'You need to rerun this app if you subsequently add new workspaces.')"
#TRANSLATORS Main window title
TITLE="$(gettext 'Separate workspace wallpapers')"
#TRANSLATORS Wallpaper selection window title
TITLE2="$(gettext 'Wallpaper selector')"
#TRANSLATORS
TITLE3="$(gettext 'Warning')"
CLASS=mxfb-sbg
#TRANSLATORS - button label
BUTTON1="$(gettext 'Cancel')"
#TRANSLATORS - button label
BUTTON2="$(gettext 'Disable')"
#TRANSLATORS - button label
BUTTON3="$(gettext 'Set up separate backgrounds')"
#TRANSLATORS - notification text
MESSAGE2="$(gettext 'Separate backgrounds have been disabled.')"
#TRANSLATORS - notification text
WARNING1="$(gettext 'There is no wallpaper image selected for Workspace')"
#TRANSLATORS - notification text
WARNING2="$(gettext 'Will substitute mx_blue.jpg to avoid any errors.')"
#TRANSLATORS Wallpaper selection window text - workspace number is added after WORKSPACE
WS_NUMBER="$(gettext 'Select background for WORKSPACE')"
ICON=/usr/share/icons/mxflux.png
yad --title="$TITLE" --window-icon=$ICON --class=$CLASS --text-align=center \
--width=500 --height=300 --center --buttons-layout=spread \
--text="\n<b>$MESSAGE1</b>\n\n$HINT1\n$HINT2\n\n$NOTE0\:\n- $NOTE1\n- $NOTE2\n- $NOTE3" \
--button="$BUTTON1":1 \
--button="$BUTTON2":2 \
--button="$BUTTON3":3 \
case $? in
1 | 252 )
exit 0
;;
2 )
#####
#DISABLE SEPARATE BACKGROUNDS
#####
awk '!/ChangeWorkspace/' ~/.fluxbox/keys > temp && mv temp ~/.fluxbox/keys
awk '!/#This executes fbsetbg/' ~/.fluxbox/keys > temp && mv temp ~/.fluxbox/keys
# block feh and enable nitrogen
HASHCHECK_NITROGEN_START=$(grep '#<< comment_start_setbg' $HOME/.fluxbox/startup)
if [ -z "$HASHCHECK_NITROGEN_START" ]; then
sed -i 's/<< COMMENTEDOUT4SETBG/#<< comment_start_setbg/' $HOME/.fluxbox/startup
fi
HASHCHECK_NITROGEN_END=$(grep '#comment_end_setbg' $HOME/.fluxbox/startup)
if [ -z "$HASHCHECK_NITROGEN_END" ]; then
sed -i 's/COMMENTEDOUT4SETBG/#comment_end_setbg/' $HOME/.fluxbox/startup
fi
HASHCHECK_NITROGEN_MX23=$(grep '#nitrogen --restore' $HOME/.fluxbox/startup)
if [ "$HASHCHECK_NITROGEN_MX23" ]; then
sed -i 's/#nitrogen/nitrogen/' $HOME/.fluxbox/startup
fi
HASHCHECK_FEH=$(grep '#~/.fehbg' $HOME/.fluxbox/startup)
if [ -z "$HASHCHECK_FEH" ]; then
sed -i 's/~\/.fehbg/#~\/.fehbg/' $HOME/.fluxbox/startup
fi
nitrogen --restore
sed -i '/$full/d' $HOME/.fluxbox/lastwallpaper
yad --title=$TITLE --class= mxfb-sbg --window-icon=$ICON \
--width=300 --height=200 --center --text-align=center \
--text="\n\n<b>$MESSAGE2</b>" --fixed --no-buttons --timeout=2
fluxbox-remote restart
exit 0
;;
3 )
#####
#SET UP SEPARATE BACKGROUNDS
#####
# block nitrogen and enable fehbg
HASHCHECK_NITROGEN_START=$(grep '#<< comment_start_setbg' $HOME/.fluxbox/startup)
if [ "$HASHCHECK_NITROGEN_START" ]; then
sed -i 's/#<< comment_start_setbg/<< COMMENTEDOUT4SETBG/' $HOME/.fluxbox/startup
fi
HASHCHECK_NITROGEN_END=$(grep '#comment_end_setbg' $HOME/.fluxbox/startup)
if [ "$HASHCHECK_NITROGEN_END" ]; then
sed -i 's/#comment_end_setbg/COMMENTEDOUT4SETBG/' $HOME/.fluxbox/startup
fi
HASHCHECK_NITROGEN_MX23=$(grep 'nitrogen --restore' $HOME/.fluxbox/startup)
if [ "$HASHCHECK_NITROGEN_MX23" ]; then
sed -i 's/nitrogen/#nitrogen/' $HOME/.fluxbox/startup
fi
HASHCHECK_FEH=$(grep '#~/.fehbg' $HOME/.fluxbox/startup)
if [ ! -z "$HASHCHECK_FEH" ]; then
sed -i 's/#~\/.fehbg/~\/.fehbg/' $HOME/.fluxbox/startup
fi
#Check if the keys file has already been edited to allow custom wallpapers for each workspace:
##check if the keys file has a ChangeWorkspace entry
expression_to_find="ChangeWorkspace"
x=$(grep $expression_to_find ~/.fluxbox/keys)
if [ -z "$x" ]; then
#Backup the keys config file:
if [ ! -d "~/.restore/fluxbox" ]; then
mkdir -p ~/.restore/fluxbox
fi
cp ~/.fluxbox/keys ~/.restore/fluxbox/keys_BAK
#Append the needed changes to the keys config file (the "\" is needed not to replace the variables:
CHECK_KEYS=$(grep 'ChangeWorkspace :Exec' $HOME/.fluxbox/keys)
if [ -z "$CHECK_KEYS" ]; then
echo "#This executes fbsetbg every time workspace is changed to load <workspace number>.jpg from ~/.fluxbox/backgrounds/numbered/
ChangeWorkspace :Exec fbsetbg ~/.fluxbox/backgrounds/numbered/\$(xprop -root _NET_CURRENT_DESKTOP |awk '{print \$3+1}').jpg" >> ~/.fluxbox/keys
fi
fi
#Create the needed folder
mkdir -p ~/.fluxbox/backgrounds/numbered/
#Check how many Workspaces Fluxbox currently has:
number_of_workspaces=$(xdotool get_num_desktops)
#Remove existing numbered wallpapers to avoid failure when wallpaper is symlinked to /usr/share/backgrounds
if [ -f "$HOME/.fluxbox/backgrounds/numbered/*.jpg" ]; then
rm -r $HOME/.fluxbox/backgrounds/numbered/*.jpg
fi
#Disable Rotate backgrounds if running
STRING="Background.Delay: 0"
if ! grep -q "$STRING" $HOME/.ideskrc;
then
sed -i 's/^\([[:blank:]]*Background\.Delay:\).*/\1 0/' "$HOME/.ideskrc"
yad --title=$TITLE --window-icon=$ICON --class=$CLASS \
--timeout=3 --no-buttons --geometry 500x100 --text-align=center \
--text="\n<b>$NOTIFICATION</b>"
fi
#Loop for as many workspaces as there are, selecting one wallpaper for each workspace
for ((n=1;n<=$number_of_workspaces;n++))
do
cd /usr/share/backgrounds/
# select wallpaper:
wallpaper=$(yad --title="$TITLE2" --window-icon=$ICON --class=$CLASS \
--width=800 --height=400 --center --text-align=center \
--file --image-filter --add-preview --large-preview \
--text="<b>\n$WS_NUMBER $n\n</b>")
# copy and rename wallpaper to match the current Workspace number:
cp $wallpaper ~/.fluxbox/backgrounds/numbered/$n.jpg
if [ ! "$?" = "0" ]; then
echo User canceled the script
exit 0
fi
#Check if wallpaper for current Workspace exists, if not, use MX25 default to avoid errors. NOTE: if the users does not select any wallpaper at this time but a wallpaper for that workspace already existed, that previous selection will be maintained
FILE=$n.jpg
cd ~/.fluxbox/backgrounds/numbered/
if [ ! -f "$FILE" ]; then
yad --title="$TITLE3" --class=$CLASS --center --window-icon=$ICON \
--text="$WARNING1 $n\n$WARNING2"
cp /usr/share/backgrounds/default25.png ~/.fluxbox/backgrounds/numbered/$n.jpg
fi
done
#Implement the changes:
sleep 2
fluxbox-remote restart
pgrep -u $(id -u) -x idesk >/dev/null && idesktoggle idesk refresh
killall -SIGUSR1 conky 2>/dev/null
~/.fehbg
;;
esac