Solving some bugs and enhancing the behavior of the script

This commit is contained in:
Frank 2015-06-23 20:07:22 +02:00
parent 2de037c84c
commit 558784cc49

View file

@ -1,5 +1,18 @@
#!/bin/bash #!/bin/bash
DONT_SUPPORT_3D="Your machine does not support 3D acceleration"
if [ $LANG = es_ES.UTF-8 ]; then
DONT_SUPPORT_3D="Su equipo no soporta aceleración 3D"
fi
# First, check if the computer
# supports 3D acceleration. If not, it
# it informs the user and then exits.
[ 0 = $(glxinfo |grep "renderer string:" |grep -v llvmpipe | wc -c) ] && zenity \
--info --text="$DONT_SUPPORT_3D" && exit 0
# Check if compton is currently running. # Check if compton is currently running.
case "$(pgrep -u $USER compton | wc -w)" in case "$(pgrep -u $USER compton | wc -w)" in
@ -17,7 +30,6 @@ if $COMPTON_RUNNING; then
elif ! $COMPTON_RUNNING; then elif ! $COMPTON_RUNNING; then
COMPTON=false COMPTON=false
DISCOMPTON=true DISCOMPTON=true
fi fi
# The text that will be showed to the user. # The text that will be showed to the user.
@ -38,26 +50,64 @@ if [ $LANG = es_ES.UTF-8 ]; then
fi fi
# Zenity is summoned to interact with the user. # Zenity is summoned to interact with the user.
# The XOR with the "exit 0" means that the script
# will exit with no error if zenity is "canceled"
# (user clicking on the "cancel" button, for
# instance).
ans=$(zenity --list --hide-header\ ans=$(zenity --list --hide-header\
--title "$TITLE"\ --title "$TITLE"\
--text "$TEXT"\ --text "$TEXT"\
--radiolist\ --radiolist\
--column "" --column ""\ --column "" --column ""\
$COMPTON "$COMPTON_ENABLED"\ $COMPTON "$COMPTON_ENABLED"\
$DISCOMPTON "$COMPTON_DISABLED") $DISCOMPTON "$COMPTON_DISABLED" || exit 0)
#The program reacts to the user's decision. # Evaluate if compton is runnning or not, if it does,
if [[ $ans = "$COMPTON_ENABLED" ]] && ! $COMPTON_RUNNING; then # warn the user if he/she tries to run compton again
rm $HOME/.config/disable-compton # or disable the compositor if he/she select to disable
compton-launcher # it. If compton is not running, run and enable it if
# the user selects to do so:
#A message is displayed if the user decides to run a program that is already running # .-----------------.
elif [[ $ans = "$COMPTON_ENABLED" ]] && $COMPTON_RUNNING; then # | |
zenity --info \ # | |
--text="$INFO" # | Compton running |
# | |
else # | |
killall compton # '-----------------'
# |
# | .-----------------. .-----------------.
# |-->| User selects no |-->| Disable compton |
# | '-----------------' '-----------------'
# | .------------------. .-----------------.
# '-->| User selects yes |->| Inform the user |
# '------------------' '-----------------'
# .---------------------.
# | |
# | |
# | Compton not running |
# | |
# | |
# '---------------------'
# |
# | .-----------------. .------------.
# |-->| User selects no |-->| Do nothing |
# | '-----------------' '------------'
# | .------------------. .-----------------.
# '-->| User selects yes |-->| Enable compton |
# '------------------' '-----------------'
if $COMPTON_RUNNING # Compton running
then
if [[ $ans == $COMPTON_DISABLED ]]; then
touch $HOME/.config/disable-compton touch $HOME/.config/disable-compton
killall compton
elif [[ $ans == $COMPTON_ENABLED ]]; then
zenity --info --text="Compton is already running"
fi
else # Compton not running
if [[ $ans == $COMPTON_ENABLED ]]; then
rm -f $HOME/.config/disable-compton
compton-launcher
else
exit 0
fi
fi fi