123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #!/bin/bash
- # This is a simple program that toggles/untoggles the screensaver
- # and power management, useful to watch videos fullscreen.
- # This script relies on the script notify-send-improved.
-
- # i3-screensaver-toggle - A simple program to toggle screensaver
- # Copyright (C) 2017 Fabrizio Romano Genovese <egonigredo@gmail.com>
- # This copyrighted material is made available to anyone wishing to use,
- # modify, copy, or redistribute it subject to the terms and conditions of
- # the GNU General Public License v.2, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful, but WITHOUT
- # ANY WARRANTY expressed or implied, including the implied warranties of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- # Public License for more details.
- # You should have received a copy of the
- # GNU General Public License along with this program; if not,
- # see <http://www.gnu.org/licenses/>
- # Put this file in /bin/ or in /usr/bin. Do not forget to give
- # sudo chmod +x i3-toggle-screensaver
- # to make it executable.
- version=1.0
- if [[ "$#" -ge 2 ]]; then
- echo "Usage: $0 {-v, --version | -h --help}"
- exit 2
- elif [[ "$#" -eq 1 ]]; then
- case $1 in
- -v | --version)
- echo "$0 - Version $version"
- exit 0;;
- -h | --help)
- echo "This is a simple program that toggles/untoggles the screensaver and power management, useful to watch videos fullscreen."
- echo "- v, --version Display current version"
- echo "-h, --help Display this message"
- exit 0;;
- *)
- echo "Usage: $0 {-v, --version | -h, --help}"
- exit 2;;
- esac
- fi
- # Check if notify-send-improved is installed
- if [ ! -f /bin/notify-send-improved ]; then
- echo "Notify-send-improved not present."
- echo "Please install it."
- exit 2
- fi
- # Here we read the status and notification id from a temporary file.
- # If the file doesn't exist, we initialize variables parsing xset.
- # If the file exists, we just parse it.
- if [ ! -f "/tmp/i3-screensaver-toggle.dat" ]; then
- notification_id="0"
- if xset q | grep "DPMS is Disabled" > /dev/null; then
- screensaver_mode="OFF"
- else
- screensaver_mode="ON"
- fi
- else
- screensaver_mode=`cat /tmp/i3-screensaver-toggle.dat | cut -d'.' -f 1`
- notification_id=`cat /tmp/i3-screensaver-toggle.dat | cut -d'.' -f 2`
- fi
- # Here we check the previous status and notification, then proceed to change.
- if [ $screensaver_mode = "ON" ]; then
- screensaver_mode="OFF"
- xset s off
- xset -dpms
- # Here we check if the notification was already used before or not, if it was, we replace it with the new one.
- if [ $notification_id = "0" ]; then
- notification_id=$(notify-send-improved "Screensaver Toggle" --print-id -t 1000 "Screensaver/PowerManagement off" | tee /dev/tty)
- else
- notify-send-improved "Screensaver Toggle" --print-id --replace=$notification_id -t 1000 "Screensaver/PowerManagement off"
- fi
- else
- screensaver_mode="ON"
- xset s on
- xset +dpms
- # Here we check if the notification was already used before or not, if it was, we replace it with the new one.
- if [ $notification_id = "0" ]; then
- notification_id=$(notify-send-improved "Screensaver Toggle" --print-id -t 1000 "Screensaver/PowerManagement on" | tee /dev/tty)
- else
- notify-send-improved "Screensaver Toggle" --print-id --replace=$notification_id -t 1000 "Screensaver/PowerManagement on"
- fi
- fi
- echo "$screensaver_mode.$notification_id" > /tmp/i3-screensaver-toggle.dat
|