Skip to content

Commit

Permalink
Merge pull request #5 from thetarkus/next
Browse files Browse the repository at this point in the history
0.2.2
  • Loading branch information
thetarkus authored Feb 26, 2019
2 parents 5bb4363 + 8164998 commit 944ff78
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 94 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ifndef PREFIX
PREFIX=$(HOME)/.local/bin
EXTRAS_PREFIX=$(HOME)/.local/share/idlelock.sh
ifeq ($(USER),root)
PREFIX=/usr/local/bin
EXTRAS_PREFIX=/usr/share/idlelock.sh
endif
endif

Expand All @@ -13,13 +15,15 @@ build:
gcc ./xidleseconds.c -o xidleseconds -lX11 -lXss

install: all
mkdir -p $(PREFIX)
mkdir -p $(PREFIX) $(EXTRAS_PREFIX)
cp idlelock.sh $(PREFIX)/idlelock.sh
mv xidleseconds $(PREFIX)/xidleseconds
cp extras/* $(EXTRAS_PREFIX)

uninstall:
rm $(PREFIX)/idlelock.sh
rm $(PREFIX)/xidleseconds
rm -rf $(EXTRAS_PREFIX)

clean:
rm xidleseconds
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# idlelock.sh 0.2.1
# idlelock.sh 0.2.2


## Installation
Expand All @@ -12,7 +12,8 @@ sudo apt install libx11 libxss
sudo pacman -S libx11 libxss

# Clone and install
git clone https://github.com/thetarkus/idlelock.sh && cd idlelock.sh && make && sudo make install
git clone https://github.com/thetarkus/idlelock.sh && cd idlelock.sh
make && sudo make install
```
After installation, minimal configuration is required.

Expand All @@ -31,29 +32,30 @@ Run `idlelock.sh -h` for more information
#!/usr/bin/env bash
idlelock.sh \
--lock-on-sleep \
--inhibit 'fullscreen' \
--unlock 'pkill i3lock' \
--inhibit 'fullscreen' `# Never activate any timer when fullscreen.` \
--unlock-cmd 'pkill i3lock' \
\
`# Restore screen to full brightness on user activity.` \
--restore 'xrandr --output $OUTPUT --brightness 1' \
--restore-cmd 'xrandr --output $OUTPUT --brightness 1' \
\
`# Notify user of inactivity by dimming the screen.` \
-120 'notify' \
--timer 120 \
+command 'xrandr --output $OUTPUT --brightness .5' \
\
`# Turn the screen off 20 seconds later.` \
-140 'screen off' \
--timer 140 \
+command 'xset dpms force off' \
\
`# Run the screen locker 40 seconds after turning the screen off.` \
-180 'lock' \
--timer 180 \
+command 'pgrep -x i3lock || i3lock -n' \
+inhibit 'audio' `# Do not lock when audio is playing.` \
+primary `# Primary timer that can be ran with 'loginctl lock-session'` \
\
`# Suspend the system after 5 total minutes of inactivity.` \
-300 'sleep' \
--timer 300 \
+command 'systemctl suspend' \
+restore 'xset dpms force on' `# Turn screen on after resuming from sleep.` \
+restore 'xset dpms force on' `# Turn screen on after system resume.` \
+inhibit 'network $DEVICE 2000' `# Inhibit when downloading at 2Mbps.` \
+repeat `# Retry command every 300 seconds of inactivity.`
```
30 changes: 30 additions & 0 deletions extras/pause-idlelock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
pause_file=${PAUSE_FILE:-$HOME/.cache/idlelock.sh/pause}
value=(${1//:/ })
count=${1//[^:]}

# Parse seconds from first argument
case "${#count}" in
0) seconds=$(( value[0] * 60 )) ;; # m
1) seconds=$(( value[0] * 3600 + value[1] * 60 )) ;; # h:m
*) seconds=$(( value[0] * 3600 + value[1] * 60 + value[2] )) ;; # h:m:s
esac

# Pause
if (( seconds > 0 )); then
h=$(($seconds/3600)); m=$(($seconds%3600/60)); s=$(($seconds%60))
pause_until=$(( $(printf '%(%s)T') + seconds ))
mkdir -p $(dirname $pause_file)
echo $pause_until > $pause_file
printf 'paused for: %d hours, %d minutes, %d seconds\n' $h $m $s
echo 'paused until:' $(date -d @$pause_until)
notify-send -t 3000 "Screensaver is paused for ${h}h ${m}m ${s}s."

# Unpause
else
rm -f $pause_file > /dev/null 2>&1
notify-send -t 3000 "Screensaver is no longer paused."
echo unpaused
fi

exit 0
49 changes: 49 additions & 0 deletions extras/set-brightness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set_brightness_xbacklight() {
#
# Change the screen brightness using xbacklight (hardware)
#
pkill xbacklight
brightness_file=${BRIGHTNESS_FILE:-$HOME/.cache/idlelock.sh/brightness}
mkdir -p $(dirname $brightness_file)

# restore brightness
if [[ $1 = 'restore' ]]; then
[[ -f $brightness_file ]] && \
xbacklight -set $(<$brightness_file) && \
rm -f $brightness_file

# set brightness
else
echo $(backlight -get) > $brightness_file
(( $1 > 0 )) && xbacklight -set $1 || xbacklight -dec $1
fi
}


set_brightness_xrandr() {
#
# Change the screen brightness using xrandr (software fallback)
#
[[ $1 = 'restore' ]] \
&& percent=${XRANDR_PERCENT:-1} \
|| percent=$(echo "$1/100" | bc -l)

# ignore negative brightness
[[ ${percent:0:1} = '-' ]] && percent=${percent:1}

# re-try until successful, sometimes display doesnt show as connected
for i in {1..5}; do
while IFS=$'\n' read -r display; do
[[ -z $display ]] && continue
xrandr --output $display --brightness $percent && success=0
done <<< "$(xrandr | grep -oP '.*(?= connected)')"
sleep 1
[[ $success = 0 ]] && return
done
}


xbacklight 2> /dev/null \
&& set_brightness_xbacklight $@ \
|| set_brightness_xrandr $@
Loading

0 comments on commit 944ff78

Please sign in to comment.