From 0f8704bbb5e00c7c08cfe5548b116c8d1a25cfc0 Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Tue, 12 Sep 2023 12:45:01 +0200 Subject: [PATCH] Use screen-temperature script --- .bin/screen-temperature | 48 +++++++++++++++++++++++++++++++++++++++++ .xmonad/xmonad.hs | 6 +++--- 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100755 .bin/screen-temperature diff --git a/.bin/screen-temperature b/.bin/screen-temperature new file mode 100755 index 0000000..a613db4 --- /dev/null +++ b/.bin/screen-temperature @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import sys +import subprocess + +DEFAULT_TEMPERATURE = 3500 + +try: + with open('/tmp/temperature', 'r') as temp_file: + current_temperature = int(temp_file.read()) +except FileNotFoundError: + current_temperature = DEFAULT_TEMPERATURE + +# If no argument is given print the current temperature +if len(sys.argv) == 1: + print(current_temperature) + sys.exit(0) +elif len(sys.argv) != 2: + print(""" +Usage: + + screen-temperature + print current temperature + + screen-temperature + set screen temperature to + + screen-temperature <+|-> + increase or decrease screen temperature by +""") + sys.exit(1) + +temperature_change = sys.argv[1] + +if temperature_change.startswith("+"): + new_temperature = current_temperature + int(temperature_change[1:]) +elif temperature_change.startswith("-"): + new_temperature = current_temperature - int(temperature_change[1:]) +else: + new_temperature = int(temperature_change) + +try: + subprocess.run(["redshift", "-O", str(new_temperature), "-P"], check=True) + with open('/tmp/temperature', 'w') as temp_file: + temp_file.write(str(new_temperature) + '\n') +except subprocess.CalledProcessError: + print("Error: could not set screen temperature.") + sys.exit(1) diff --git a/.xmonad/xmonad.hs b/.xmonad/xmonad.hs index c683735..9d2e437 100644 --- a/.xmonad/xmonad.hs +++ b/.xmonad/xmonad.hs @@ -252,9 +252,9 @@ pause = spawn "playerctl pause" brighten, dim, warm, cool, resetTemp :: X () brighten = spawn "brightnessctl set 20+" dim = spawn "brightnessctl set 20-" -warm = spawn "echo $(($(cat /tmp/temperature) + 50)) > /tmp/temperature && redshift -O $(cat /tmp/temperature) -P && notify < /tmp/temperature -h string:x-canonical-private-synchronous:anything" -cool = spawn "echo $(($(cat /tmp/temperature) - 50)) > /tmp/temperature && redshift -O $(cat /tmp/temperature) -P && notify < /tmp/temperature -h string:x-canonical-private-synchronous:anything" -resetTemp = spawn "echo 3000 > /tmp/temperature && redshift -x" +warm = spawn "screen-temperature +50 && notify < /tmp/temperature -h string:x-canonical-private-synchronous:anything" +cool = spawn "screen-temperature -50 && notify < /tmp/temperature -h string:x-canonical-private-synchronous:anything" +resetTemp = spawn "screen-temperature 3000" -- }}}