xgamma-gui 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. #Written by PANZERKOPF
  3. #100215 hacked by BK
  4. #101207 hacked by EW
  5. #121019 BK: fixed. internationalized.
  6. #121022 L18L: complete the internationalization.
  7. #101207 EW:
  8. # this is a Xdialog frontend for the xgamma program - setting colour calibration for the screen
  9. # It is using the 3 RGB channels
  10. # xgamma uses a logharithmic scale for the gamma values (0.1 - darkest, 1.0 - default, 10.0 - brightest) -> Y Values
  11. # The GUI uses a linear scale (going from -100 - darkest, 0.0 - default, +100 - brightest) -> X Values
  12. # The transformation is given by Y=10^(X/100)
  13. # the calculation has to be performed with bc,
  14. # to use decimal values in the exponent the equation must be rewritten Y = exp ( X/100 * log (10))
  15. # or, setting the precision to 3 decimal points using bc command: Y=$(echo "e( "$X"/100 * l(10))" | bc -l)
  16. # The reverse transformation is XRED=$(echo "scale:0; 100 * l($YRED) / l(10)" | bc -l)
  17. export TEXTDOMAIN=xgamma-gui
  18. export OUTPUT_CHARSET=UTF-8
  19. TITLE="$(gettext 'Monitor Gamma calibration')"
  20. BACKTITLE="$(gettext 'Set value for each colour, or adjust equally if only want to adjust brightness of screen.')
  21. $(gettext 'The spinboxes are adjustable in the range -100 to +100, where -100 is darkest, 0 is default, and +100 is brightest.')"
  22. if [ "`which xgamma`" = "" ]; then
  23. Xdialog --title "${TITLE}" --msgbox "$(gettext 'xgamma not found.')" 0 0
  24. exit
  25. fi
  26. #get current settings (for startup)
  27. YGAMMA="$(xgamma 2>&1 | tr -s ' ' | sed -e 's%[^0-9. ]%%g' | tr -s ' ')" #ex: 10.000 1.000 1.000
  28. YRED="$(echo "$YGAMMA" | cut -f 2 -d ' ')"
  29. YGREEN="$(echo "$YGAMMA" | cut -f 3 -d ' ')"
  30. YBLUE="$(echo "$YGAMMA" | cut -f 4 -d ' ')"
  31. inYRED="$YRED"
  32. inYGREEN="$YGREEN"
  33. inYBLUE="$YBLUE"
  34. echo $YGAMMA
  35. echo $YRED $YGREEN $YBLUE
  36. #transform y-->x values, 3 decimals precision, to get the current values;
  37. XRED=$(echo "scale=3; 100 * l("$YRED") / l(10)" | bc -l)
  38. XRED=$(echo "scale=0; "$XRED"/1" | bc -l) # cut decimals
  39. XGREEN=$(echo "scale=3; 100 * l("$YGREEN") / l(10)" | bc -l)
  40. XGREEN=$(echo "scale=0; "$XGREEN"/1" | bc -l) # cut decimals
  41. XBLUE=$(echo "scale=3; 100 * l("$YBLUE") / l(10)" | bc -l)
  42. XBLUE=$(echo "scale=0; "$XBLUE"/1" | bc -l) # cut decimals
  43. EXCODE="0"
  44. REDLABEL="$(gettext 'Red')"
  45. GREENLABEL="$(gettext 'Green')"
  46. BLUELABEL="$(gettext 'Blue')"
  47. APPLIEDFLAG='no'
  48. while [ "${EXCODE}" = "0" ]; do
  49. XDGOUT=`Xdialog --wrap --left --backtitle "${BACKTITLE}" --title "${TITLE}" --stdout --buttons-style "text" --icon "/usr/share/images/xgamma-gui.xpm" --ok-label "$(gettext 'Apply')" --cancel-label "$(gettext 'Exit')" \
  50. --3spinsbox "" 356x0 "-100" "100" "$XRED" "${REDLABEL}" "-100" "100" "$XGREEN" "${GREENLABEL}" "-100" "100" "$XBLUE" "${BLUELABEL}"`
  51. # get exit code
  52. EXCODE=${?}
  53. XGAMMA=$XDGOUT
  54. # substitute >space< for >/<, otherways there are problems to parse the string properly
  55. XGAMMA=$(echo $XGAMMA| sed 's:/: :g')
  56. [ "${EXCODE}" != "0" ] && break
  57. APPLIEDFLAG='yes'
  58. # cut in pieces (parse) and assign
  59. set -- ${XGAMMA// / }
  60. XRED=$1
  61. XGREEN=$2
  62. XBLUE=$3
  63. # make transformation x-->y
  64. YRED=$(echo "scale=3; e( "$XRED"/100 * l(10))" | bc -l)
  65. YGREEN=$(echo "scale=3; e( "$XGREEN"/100 * l(10))" | bc -l)
  66. YBLUE=$(echo "scale=3; e( "$XBLUE"/100 * l(10))" | bc -l)
  67. #apply gamma values
  68. xgamma -rgamma ${YRED} -ggamma ${YGREEN} -bgamma ${YBLUE}
  69. done
  70. # if default values we dont need xgamma at startup, so remove the file. This saves time in .xinitrc
  71. if [ "$XGAMMA" = "0 0 0" ]; then
  72. rm -f $HOME/.xgamma-gamma
  73. exit
  74. fi
  75. if [ "$inYRED" = "$YRED" ];then
  76. if [ "$inYGREEN" = "$YGREEN" ];then
  77. if [ "$inYBLUE" = "$YBLUE" ];then
  78. exit
  79. fi
  80. fi
  81. fi
  82. [ "$APPLIEDFLAG" = "no" ] && exit
  83. # else ask if we want to save the current values and create a startup calibration file
  84. Xdialog --yesno "$(gettext 'Save current configuration?')" 0 0
  85. if [ ${?} -eq 0 ]; then
  86. echo -n "xgamma -rgamma $YRED -ggamma $YGREEN -bgamma $YBLUE"' &' > $HOME/.xgamma-gamma
  87. #...xgamma is executed in /root/.xinitrc
  88. echo "Saved"
  89. fi
  90. ###END###