I will post this script here for now as I'm not 100% confident in my code and calculations yet.
This forms the starting point for scripts that interrogate current screen brightness, backlight and gamma values as a precursor to displaying adjustment sliders.
It produces a gxmessage output to advise the user of the current parameters for their display screen. (single monitor only at present)
Not all systems display brightness or backlight values - and the xgamma and xrandr utilities seem to handle "gammas" differently so I may have more work to do. On most of my current systems it is necessary to produce a reciprocal of the reported xrandr gamma value in order to produce a valid figure which can be plugged back into xrandr for the purposes of adjustment. (Not so for xgamma).
xrandr always seems to see changes made by xgamma, but xgamma does not always seem to see changes made by xrandr. (which makes measurement and adjustment tricky).
Code: Select all
#! /bin/bash
#2021 Oct04 greengeek script to report current xgamma r,g,b gamma values & xrandr "backlight", "brightness" and r,g,b gamma values
#Note that xgamma and xrandr sometimes report gammas differently.
#Discover connected screen:
CONNECTED=$(xrandr | grep " connected " | awk '{ print$1 }')
#gxmessage "
# Here is your connected screen(s) list:
# $CONNECTED"
#(Must think about how to handle multiple connected screens)
#Sample current xgammas:
#Red xgamma:
xRgammaCurRaw=$(xgamma 2>&1 | awk '{print $3}' | tr "," " ")
xRgammaCur=$(echo $xRgammaCurRaw | grep -o '^[0-9]*\.[0-9]')
#G xgamma:
xGgammaCurRaw=$(xgamma 2>&1 | awk '{print $5}' | tr "," " ")
xGgammaCur=$(echo $xGgammaCurRaw | grep -o '^[0-9]*\.[0-9]')
#B xgamma:
xBgammaCurRaw=$(xgamma 2>&1 | awk '{print $7}' | tr "," " ")
xBgammaCur=$(echo $xBgammaCurRaw | grep -o '^[0-9]*\.[0-9]')
#Sample current "Backlight" value as reported by xrandr:
BkltCur=$(xrandr --verbose | sed -n 's/Backlight:/&\n/;s/.*\n//p')
#Samples current "Brightness" value as reported by xrandr:
BrightCur=$(xrandr --verbose | sed -n 's/Brightness:/&\n/;s/.*\n//p')
#This samples current Red gamma value as seen by xrandr:
RgammaCurRaw=$(xrandr --verbose | grep "Gamma" | awk '{print $2}' | awk -F[:] '{print $1}')
RgammaCur=$(echo "scale = 1; 1/$RgammaCurRaw" | bc -l)
#This samples current Green gamma value as seen by xrandr:
GgammaCurRaw=$(xrandr --verbose | grep "Gamma" | awk '{print $2}' | awk -F[:] '{print $2}')
GgammaCur=$(echo "scale = 1; 1/$GgammaCurRaw" | bc -l)
#This samples current Blue gamma value as seen by xrandr:
BgammaCurRaw=$(xrandr --verbose | grep "Gamma" | awk '{print $2}' | awk -F[:] '{print $3}')
BgammaCur=$(echo "scale = 1; 1/$BgammaCurRaw" | bc -l)
gxmessage " Some values may be blank if your video display/card or
software version does not report them:
Current R xgamma raw value seen by xgamma is $xRgammaCurRaw
Current R xgamma value to one decimal place is $xRgammaCur
Current G xgamma raw value seen by xgamma is $xGgammaCurRaw
Current G xgamma value to one decimal place is $xGgammaCur
Current B xgamma raw value seen by xgamma is $xBgammaCurRaw
Current B xgamma value to one decimal place is $xBgammaCur
Raw Gamma values as reported by xrandr:
Rgamma = $RgammaCurRaw
Ggamma = $GgammaCurRaw
Bgamma = $BgammaCurRaw
True (reciprocal) Gamma values ready to plug into xrandr script:
Rgamma = $RgammaCur
Ggamma = $GgammaCur
Bgamma = $BgammaCur
(Some systems may not need reciprocal calculation)
Current backlight value seen by xrandr = $BkltCur
Current brightness value seen by xrandr = $BrightCur"
Here is the script. Please delete false .gz suffix, make executable and click to run.
.