forked from MX-Linux/mxfb-goodies
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxfb-separate-backgrounds
More file actions
executable file
·125 lines (97 loc) · 4.53 KB
/
mxfb-separate-backgrounds
File metadata and controls
executable file
·125 lines (97 loc) · 4.53 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
#!/bin/bash
#Script to configure separate backgrounds for each Fluxbox Workspace
#Written by user PPC and modified by MX Devs, September 2020
#Released under GPLv3
TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN="mxfb-separate-backgrounds"
#Confirmation Window:
MESSAGE1=$" This app allows you to configure separate backgrounds for each Workspace </b>"
HINT1=$" Selection windows will pop up for each Workspace."
HINT2=$" Type \"mxfb\" to jump to the MXFB backgrounds."
HINT3=$" Select the background you want and click OK."
NOTE1=$" NOTE 1: Background changes using the menu won't be permanent."
NOTE2=$" NOTE 2: Re-run this script when you add new workspaces!"
NOTE3=$" NOTE 3: Disable nitrogen in startup file if using that app for image setting"
TITLE=$"MXFB -- separate workspace wallpapers"
BUTTON1=$"Cancel"
BUTTON2=$"Disable separate backgrounds"
BUTTON3=$"Setup separate backgrounds"
MESSAGE2=$"Separate backgrounds have been disabled."
TITLE2=$"Wallpaper selector"
TITLE3=$"Warning"
WARNING=$"There is no wallpaper image selected for Workspace $n... Will substitute 'mx_blue.jpg' to avoid any errors."
ICON=/usr/share/icons/mxflux.png
yad --center --window-icon=$ICON --fix-window --text="
<b>$MESSAGE1\n
<b>--$HINT1
--$HINT2
-- $HINT3 \n
$NOTE1
$NOTE2
$NOTE3</b>" \
--title=$"$TITLE" --window-icon=$ICON --text-align=center \
--button="<b>$BUTTON1</b>":1 \
--button="<b>$BUTTON2</b>":3 \
--button="<b>$BUTTON3</b>":2 \
foo=$?
[[ $foo -eq 1 ]] && exit 0
if [[ $foo -eq 3 ]]; then
#sed -i 's/ChangeWorkspace/#ChangeWorkspace/' ~/.fluxbox/keys
awk '!/ChangeWorkspace/' ~/.fluxbox/keys > temp && mv temp ~/.fluxbox/keys
yad --title=$"$TITLE" --window-icon=$ICON --center --message --text="$MESSAGE2" --fixed --no-buttons --timeout=5
fluxbox-remote restart
exit 0
fi
# set idesk to no rotation to avoid conflict
sed -i -r 's/Background.Delay:[[:space:]]+1/Background.Delay: 0/' ~/.ideskrc
#Check if the keys file has already been edited to allow costume 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
echo "\$x is empty- the keys file has not been edited, editing it to allow different wallpaper for each workspace"
#Backup the keys config file:
cp ~/.fluxbox/keys ~/.restore/fluxbox/keys_BAK
#Append the needed changes to the keys config file (the "\" is needed not to replace the variables:
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
else
echo "\$x is NOT empty- the keys file seems to already allow custom wallpapers for each workspace."
### echo Do you want to set up a single wallpaper for all Workspaces?
## If no, edit the keys file, removing the line that sets the ChangeWorkspace...
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
rm ~/.fluxbox/backgrounds/numbered/*.jpg
#Loop for as many workspaces as there is, 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" --center --window-icon=$ICON --file-selection --text="
WORKSPACE $n
" --text-align=center)
# 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 a default one (mx_blue.jpg), 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
echo "File $FILE does not exist, using a default one- mx_blue.jpg"
yad --center --window-icon=$ICON--title="$TITLE3" --text="$WARNING"
cp /usr/share/backgrounds/mx_blue.jpg ~/.fluxbox/backgrounds/numbered/$n.jpg
fi
done
echo Finished setting up workspace wallpapers, restarting fluxbox
#Implement the changes:
fluxbox-remote restart
echo fluxbox restarted, script finished