redshift icon indicating copy to clipboard operation
redshift copied to clipboard

Add a "Detect Current Screen Colour Temperature" Feature

Open the-solipsist opened this issue 11 years ago • 8 comments

Thanks for this wonderful little program. I think it would be useful to have a command by which one could detect the current screen colour temperature. For instance:

'$ redshift --detect-temp'

Would that be possible? Is there any other way of doing this?

the-solipsist avatar Sep 17 '14 14:09 the-solipsist

It is possible, simply analyse the current gamma ramps. I think these would do better in another program that is specialised at analysing the gamma ramps and could be able to do more than just give the current temperatures. redshift --detect-temp could then be implemented by spawning that program and read its output.

maandree avatar Sep 17 '14 17:09 maandree

I have made some progress on this in a separate project. The gamma correction and brightness–contrast correction (which is not supported by redshift) can be calculated, but the calculation of the temperature is a bit off (but seems to always be within ±20 K, I assume this have to do with the accuracy we can have when applying a temperature the the gamma ramps). As of yet, redshift's fake backlight, called brightness, is not calculated.

maandree avatar Sep 18 '14 13:09 maandree

If you just want the current temperature as calculated by Redshift, you can use the -p mode. If you want to know in general when some other program has changed the gamma ramp, the solution provided by @maandree is necessary.

jonls avatar May 02 '15 01:05 jonls

Thanks, @jonis. That's exactly what I'd wanted.

the-solipsist avatar May 05 '15 10:05 the-solipsist

Unfortunately "-p" does not work in the following example: redshift -O 4100 redshift -l geoclue2 -p Period: Daytime Color temperature: 5500K Brightness: 1.00

Wayne Sallee [email protected]

WayneSallee avatar Feb 17 '18 15:02 WayneSallee

sorry for asking here but there is a similar command for blueshift?

helionmelion avatar Apr 04 '18 21:04 helionmelion

I've never used blueshift, but here is what I ended up doing for redshift:

#!/bin/bash

# Uses redshift to shift the screen color from blue to read to blue.





case "${1}" in



blue)
color=$(cat /usr/share/redshifter/screencolor) # Get last used color.
echo "Last screen color temperature: "$color"K"
let "color = color +100"
if [ "$color" -ge "800" ]; then # Check for normal value.
if [ "$color" -gt "25000" ]; then # If to high, set to max color temperature.
color="25000"
fi
else
color="5500" # Something goofy, default to standard color temperature.
fi
echo "New screen color temperature: "$color"K"
echo $color > /usr/share/redshifter/screencolor # Save new color.
redshift -O $color




# Redshift: Temperature must be between 1000K and 25000K.




red)
color=$(cat /usr/share/redshifter/screencolor) # Get last used color.
echo "Last screen color temperature: "$color"K"
let "color = color - 100"
if [ "$color" -gt "0" ]; then # Check for normal value.
if [ "$color" -gt "25000" ]; then # If to high, set to max color temperature.
color="25000"
fi
if [ "$color" -lt "1000" ]; then # If to low, set to minimum color temperature.
color="1000"
fi
else
color="5500" # Something goofy, default to standard color temperature.
fi
echo "New screen color temperature: "$color"K"
echo $color > /usr/share/redshifter/screencolor # Save new color.
redshift -O $color








esac
exit

Wayne Sallee [email protected] http://www.WayneSallee.com

WayneSallee avatar Apr 04 '18 22:04 WayneSallee

Just going to put this here...this supports shifting either the backlight or the color temperature by the specified value. Displays a notification with a progress bar to indicate the current level. Tested on Manjaro Xfce with libnotify version 0.8.3

Example usage (particularly useful if bound to hotkeys):

displayshift.sh light -25 #decreases brightness by 0.25
displayshift.sh light 10 #increases brightness by 0.1
displayshift.sh temp -500 #decreases color temperature by 500
displayshift.sh temp 200 #increases color temperature by 200

displayshift.sh:

#!/bin/bash

#usage: displayshift.sh [light|temp] [0-9]+
#light range: 1-100
#color range: 1000-25000


#--settings--

#notification icons (defaults are in papirus-icon-theme)
icolight="notification-display-brightness-medium"
icotemp="colortone"
icotemp_default="emblem-default" #shown when color temperature is exactly 6500 (default)

#cache location / files
cachefol="$HOME/.cache/displayshift"
cachelight="$cachefol/backlight.dat"
cachetemp="$cachefol/colortemp.dat"
cachenotid="$cachefol/notify.dat"


#--functions--
to_int(){ [[ "$1" =~ ^[\-]?[0-9]+$ ]] && echo "$1" || echo 0; }
msg_err(){ notify-send -i dialog-error "brightness" "$@" ; }
msg_light(){ notify-send -i $icolight -h int:value:${newlight} -r ${notid} -p " " ; }

msg_temp(){
  tempico="$icotemp"; [[ "$newtemp" = "6500" ]] && tempico="$icotemp_default"
  notify-send -i $tempico -h int:value:$((${newtemp}*4/1000)) -r ${notid} -p " "
}


#--main--

[[ -d "$cachefol" ]] || mkdir "$cachefol" || (msg_err "err: failed to create cache folder"; exit)


#read params
case "$1" in
  light) chnglight="$2"; chngtemp=0 ;;
  temp) chnglight=0; chngtemp="$2" ;;
  *) msg_err "err: invalid parameter"; exit ;;
esac
chnglight="$(to_int "$chnglight")"
chngtemp="$(to_int "$chngtemp")"


#read cache data
if [[ -f "$cachenotid" ]]; then
  notid="$(cat "$cachenotid")"
else notid=0; fi
notid="$(to_int "$notid")"

if [[ -f "$cachelight" ]]; then
  curlight="$(cat "$cachelight")"
  [[ "${curlight:0:1}" = "0" ]] && curlight="${curlight:1}"
else curlight=100; fi
curlight="$(to_int "$curlight")"

if [[ -f "$cachetemp" ]]; then
  curtemp="$(cat "$cachetemp")"
else curtemp=6500; fi
curtemp="$(to_int "$curtemp")"


#calculate new, ensure within valid range
newlight="$((curlight+chnglight))"
[[ "$newlight" -lt 1 ]] && newlight=1
[[ "$newlight" -gt 100 ]] && newlight=100
[[ "$newlight" -lt 100 ]] && newlight="0$newlight"

newtemp="$((curtemp+chngtemp))"
[[ "$newtemp" -lt 1000 ]] && newtemp=1000
[[ "$newtemp" -gt 25000 ]] && newtemp=25000


#make changes (if needed)
if ( [[ "$1" = "light" ]] && [[ ! "$newlight" = "$curlight" ]] ) || \
  ( [[ "$1" = "temp" ]] && [[ ! "$newtemp" = "$curtemp" ]] ); then

  if redshift -P -O $newtemp -b ${newlight:0:1}.${newlight:1:1}:${newlight:0:1}.${newlight:1:1}; then
    case $1 in
      light) echo "$newlight">"$cachelight" ;;
      temp) echo "$newtemp">"$cachetemp" ;;
    esac
  else msg_red "err: failed to run redshift with specified value"; exit; fi

fi


#final notification
case $1 in
  light) msg_light>"$cachenotid" ;;
  temp) msg_temp>"$cachenotid" ;;
esac

lectrode avatar Apr 14 '24 20:04 lectrode