diff options
Diffstat (limited to 'lock')
-rwxr-xr-x | lock | 84 |
1 files changed, 69 insertions, 15 deletions
@@ -1,20 +1,74 @@ -#!/bin/sh +#!/bin/bash -# Pause music -if pgrep xmms2 &> /dev/null; then - xmms2 pause -fi +# Example locker script -- demonstrates how to use the --transfer-sleep-lock +# option with i3lock's forking mode to delay sleep until the screen is locked. -# Set pidgin away. -if pgrep pidgin &> /dev/null; then - currentStatusMessage="$(purple-remote 'getstatusmessage')" - currentStatus="$(purple-remote 'getstatus')" - purple-remote 'setstatus?status=away&message=Away' -fi +## Prepare image + +SCREEN_RESOLUTION="$(xdpyinfo | grep dimensions | cut -d' ' -f7)" +BGCOLOR="0,0,0" +convert "$HOME/photos/wallpapers/morgan-flag.png" -gravity Northwest -background $BGCOLOR -extent "$SCREEN_RESOLUTION" $HOME/photos/wallpapers/.lockscreen.png + + +## CONFIGURATION ############################################################## + +# Options to pass to i3lock +i3lock_options="-ti $HOME/photos/wallpapers/.lockscreen.png" + + +# Run before starting the locker +pre_lock() { + # Pause music + #if pgrep xmms2 &> /dev/null; then + #xmms2 pause + #fi + + # Set pidgin away. + if pgrep pidgin &> /dev/null; then + currentStatusMessage="$(purple-remote 'getstatusmessage')" + currentStatus="$(purple-remote 'getstatus')" + purple-remote 'setstatus?status=away&message=Away' + fi -#i3lock -n -i $HOME/.wallpapers/lock.png --color=0e0e0e -u -m -xscreensaver-command -lock + return +} -if pgrep pidgin &> /dev/null; then - purple-remote 'setstatus?status='"$currentStatus"'&message='"$currentStatusMessage" +# Run after the locker exits +post_lock() { + if pgrep pidgin &> /dev/null; then + purple-remote 'setstatus?status='"$currentStatus"'&message='"$currentStatusMessage" + fi + + return +} + +############################################################################### + +pre_lock + +# We set a trap to kill the locker if we get killed, then start the locker and +# wait for it to exit. The waiting is not that straightforward when the locker +# forks, so we use this polling only if we have a sleep lock to deal with. +if [[ -e /dev/fd/${XSS_SLEEP_LOCK_FD:--1} ]]; then + kill_i3lock() { + pkill -xu $EUID "$@" i3lock + } + + trap kill_i3lock TERM INT + + # we have to make sure the locker does not inherit a copy of the lock fd + i3lock $i3lock_options {XSS_SLEEP_LOCK_FD}<&- + + # now close our fd (only remaining copy) to indicate we're ready to sleep + exec {XSS_SLEEP_LOCK_FD}<&- + + while kill_i3lock -0; do + sleep 0.5 + done +else + trap 'kill %%' TERM INT + i3lock -n $i3lock_options & + wait fi + +post_lock |