- SDR to HDR brightness control has been implemented. - Sample monitor.conf file is now provided. - VS Code debug launch file has been added. - Updated Readme.
121 lines
3.2 KiB
Bash
Executable File
121 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
_VERSION=1.1.0.0
|
|
CONFIG_PATH="$HOME/.config/hdr-helper/"
|
|
CONFIG_FILE="$CONFIG_PATH/monitor.conf"
|
|
CONFIG_CURR_BRIGHTNESS="$CONFIG_PATH/current-brightness-level"
|
|
|
|
show_hdr_status() {
|
|
ICON="/usr/share/icons/breeze-dark/devices/64/monitor.svg"
|
|
|
|
if [[ $(kscreen-doctor -o | grep HDR) == *"enabled"* ]]; then
|
|
notify-send -a "HDR Helper" -i $ICON "HDR Enabled"
|
|
else
|
|
notify-send -a "HDR Helper" -i $ICON "HDR Disabled"
|
|
fi
|
|
}
|
|
|
|
set_brightness() {
|
|
if [[ "$SDR_TARGET_BRIGHTNESS" -gt 0 ]]; then
|
|
# Store the current brightness level before attempting to update it.
|
|
kscreen-doctor -o | \
|
|
grep Brightness | \
|
|
head -n 1 | \
|
|
grep -oP "(?<=set to )[0-9]+" \
|
|
> $CONFIG_CURR_BRIGHTNESS
|
|
kscreen-doctor output.$MONITOR.brightness.$SDR_TARGET_BRIGHTNESS
|
|
fi
|
|
}
|
|
|
|
restore_brightness() {
|
|
if [ -f $CONFIG_CURR_BRIGHTNESS ]; then
|
|
kscreen-doctor output.$MONITOR.brightness.$(cat $CONFIG_CURR_BRIGHTNESS)
|
|
rm $CONFIG_CURR_BRIGHTNESS
|
|
fi
|
|
}
|
|
|
|
refresh_display() {
|
|
kscreen-doctor output.$MONITOR.mode.$TEMP_RES
|
|
kscreen-doctor output.$MONITOR.mode.$NATIVE_RES
|
|
show_hdr_status
|
|
}
|
|
|
|
enable_hdr () {
|
|
kscreen-doctor output.$MONITOR.hdr.enable
|
|
refresh_display
|
|
set_brightness
|
|
}
|
|
|
|
disable_hdr() {
|
|
kscreen-doctor output.$MONITOR.hdr.disable
|
|
refresh_display
|
|
restore_brightness
|
|
}
|
|
|
|
auto_hdr() {
|
|
if [[ $(kscreen-doctor -o | grep HDR) == *"enabled"* ]]; then
|
|
disable_hdr
|
|
else
|
|
enable_hdr
|
|
fi
|
|
}
|
|
|
|
show_version() {
|
|
echo "HDR Helper v"$_VERSION
|
|
}
|
|
|
|
show_help () {
|
|
echo "--- Usage ---"
|
|
echo "hdr-helper | The default behaviour will automatically enable or disable HDR"
|
|
echo "hdr-helper -e | Force enables HDR"
|
|
echo "hdr-helper -d | Force disables HDR"
|
|
echo "hdr-helper -s | Shows detected HDR status as a system notification"
|
|
echo "hdr-helper -v | Displays version information"
|
|
echo "hdr-helper -h | Displays this help screen"
|
|
echo ""
|
|
echo "--- Info ---"
|
|
echo "Currently only KDE Plasma is supported running Wayland. Ensure that kscreen-doctor"
|
|
echo "is present on your system for HDR Helper to function."
|
|
echo ""
|
|
echo "--- Config ---"
|
|
echo "Please modify the MONITOR, NATIVE_RES and TEMP_RES values in monitor.conf."
|
|
}
|
|
|
|
# Check Dependencies
|
|
if [[ $(whereis kscreen-doctor) != *"kscreen-doctor" ]]; then
|
|
echo "Error: kscreen-doctor cannot be detected, aborting."
|
|
echo "Please note that only KDE Plasma is currently supported on Wayland."
|
|
echo ""
|
|
show_version
|
|
|
|
exit -1
|
|
fi
|
|
|
|
# Import monitor.conf values
|
|
if source "$CONFIG_FILE"; then
|
|
if [[ $MONITOR == "" ]] || [[ $NATIVE_RES == "" ]] || [[ $TEMP_RES == "" ]]; then
|
|
echo "Error: monitor.conf has not been configured."
|
|
exit -2
|
|
fi
|
|
else
|
|
echo "Error: monitor.conf file not found. Please ensure it's been properly setup."
|
|
exit -3
|
|
fi
|
|
|
|
# Handle Args
|
|
if [[ $1 == "-e" ]] || [[ $1 == "--enable" ]]; then
|
|
enable_hdr
|
|
elif [[ $1 == "-d" ]] || [[ $1 == "--disable" ]]; then
|
|
disable_hdr
|
|
elif [[ $1 == "-s" ]] || [[ $1 == "--status" ]]; then
|
|
show_hdr_status
|
|
elif [[ $1 == "-v" ]] || [[ $1 == "--version" ]]; then
|
|
show_version
|
|
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
|
show_help
|
|
elif [[ $# -eq 0 ]]; then # Automatically Toggle HDR | Default Behaviour
|
|
auto_hdr
|
|
else
|
|
show_help
|
|
fi
|