distribution/packages/jelos/sources/scripts/paneladj

102 lines
1.8 KiB
Bash
Executable file

#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2023-present Fewtarius
. /etc/profile
# ARGS:
#
# 1 - property to adjust (gamma (brightness)/contrast/saturation/hue)
# 2 - up/down or a defined value
PROPERTY=${1}
NEWVAL=${2}
# Command usage:
# drm_tool set /dev/dri/card0 133 saturation value
# Define the basics
MIN=1
MAX=100
STEP=1
if [ ! -e /dev/dri/card0 ]
then
echo "ERROR: No display found."
exit 1
fi
log() {
$DEBUG && echo "Info: ${*}" >>/var/log/display.log
}
getValue() {
MYVAL=$(get_setting display.${1})
if [ -n "${MYVAL}" ]
then
if [ "${MYVAL}" > "${MAX}" ]
then
MYVAL=${MAX}
elif [ "${MYVAL}" < "${MIN}" ]
then
MYVAL=${MIN}
fi
echo ${MYVAL}
else
echo $(drm_tool list 2>/dev/null | sed -n '/Connector: 133/,$p' | awk '/'${1}'/ {print $5}')
fi
}
setValue() {
log "Set (${1}: ${2})"
drm_tool set /dev/dri/card0 133 ${1} ${2} 2>/dev/null
if [ $? = 0 ]
then
set_setting display.${1} ${2}
fi
}
stepUp() {
LASTVAL=$(getValue ${PROPERTY})
NEWVAL=$(expr ${LASTVAL} + 1)
log "Step up (${PROPERTY}: ${NEWVAL})"
setValue ${PROPERTY} ${NEWVAL}
}
stepDown() {
LASTVAL=$(getValue ${PROPERTY})
NEWVAL=$(expr ${LASTVAL} - 1)
log "Step down (${PROPERTY}: ${NEWVAL})"
setValue ${PROPERTY} ${NEWVAL}
}
restoreSettings() {
for PROPERTY in brightness contrast saturation hue
do
RESTVAL=$(getValue ${PROPERTY})
setValue ${PROPERTY} ${RESTVAL}
done
}
case ${NEWVAL} in
"up")
stepUp
;;
"down")
stepDown
;;
"restore")
restoreSettings
;;
*)
if [[ "${NEWVAL}" =~ ^[0-9] ]] && \
[ "${NEWVAL}" -le "${MAX}" ] && \
[ "${NEWVAL}" -ge "${MIN}" ]
then
setValue ${PROPERTY} ${NEWVAL}
else
echo "Error: Invalid value."
exit 1
fi
;;
esac