Clean up i3exit script.

This commit is contained in:
2016-02-24 21:08:13 +01:00
parent 04fa4e8181
commit 0b516a6c92

View File

@@ -2,51 +2,38 @@
### From http://www.archlinux.org/index.php/i3
LOGFILE="$LOGDIR/i3/i3exit.log"
LOGFILE_MAXSIZE=100000
_logfile="$LOGDIR/i3/i3exit.log"
FALLBACK_COLOR=000000
_fallback_color=000000
touch "$LOGFILE"
[[ $(stat -c%s "$LOGFILE") -gt $LOGFILE_MAXSIZE ]] && >$LOGFILE
touch "$_logfile"
log()
{
echo "$1"
echo "[$(date +%FT%T)] $1" >> "$LOGFILE"
echo "$*"
echo "[$(date +%FT%T)] $*" >> "$_logfile"
}
lock()
{
resolution=$(xrandr | grep '*' | awk '{ print $1 }' | head -n1)
log "[I] Resolution found: \"$resolution\""
lockscreen="$HOME/.i3/data/lockscreen/$resolution.png"
log "[I] Looking for lockscreen at \"$lockscreen\""
if [[ -f "$lockscreen" ]] ; then
log "[I] Lockscreen found, will be used as background image."
background_options="--image $lockscreen -t"
if [[ "$LOCKSCREEN" ]] ; then
i3lock --show-failed-attempts --image "$LOCKSCREEN"
else
log "[W] Lockscreen not found, using color #$FALLBACK_COLOR as background."
background_options="--color $FALLBACK_COLOR"
i3lock --show-failed-attempts --color "$_fallback_color"
fi
i3lock $background_options #-p win --image "$HOME/pictures/windows-lockscreen.jpg"
retval=$?
[[ -z "$1" ]] && sleep 3 && xset dpms force off
return $retval
}
if [[ "$1" == '-' ]]; then
read signal
else
signal="$1"
fi
screen_off() {
xset dpms force off
}
signal="$1"
log "[I] Received signal \"$signal\"."
case "$signal" in
lock)
log "[I] Locking session."
lock
lock && screen_off
;;
logout)
log "[I] Exiting i3."
@@ -54,11 +41,10 @@ case "$signal" in
;;
suspend)
log "[I] Suspending."
lock "1" && systemctl suspend
lock && systemctl suspend
;;
hibernate)
log "[I] Hibernating."
#lock &&
systemctl hibernate
;;
reboot)
@@ -71,7 +57,7 @@ case "$signal" in
;;
screen-off)
log "[I] Turning screen off."
xset dpms force off
screen_off
;;
*)
echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"