-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from thetarkus/next
0.2.2
- Loading branch information
Showing
6 changed files
with
377 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $@ |
Oops, something went wrong.