- Added automatic monitor.conf setup to hdr-helper script

- Setup script now copies config file and backups up old one
This commit is contained in:
2025-10-08 23:19:04 +01:00
parent 6e5d3906aa
commit 4e16d193f7
2 changed files with 29 additions and 9 deletions
+8
View File
@@ -84,6 +84,10 @@ else
fi
}
setup_conf_file() {
python monitor-setup.py
}
auto_hdr() {
if [[ $(kscreen-doctor -o | grep -A 15 $MONITOR | grep HDR) == *"enabled"* ]]; then
disable_hdr
@@ -112,6 +116,8 @@ show_help () {
echo " hdr-helper -h (--help)"
echo "Tests whether the connected display is HDR capable"
echo " hdr-helper -t (--test)"
echo "Automate monitor.conf file setup"
echo " hdr-helper -a (--auto-setup-conf-file)"
echo ""
echo "=== Info ==="
echo "Currently only KDE Plasma is supported running Wayland. Ensure that kscreen-doctor"
@@ -158,6 +164,8 @@ elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
show_help
elif [[ $1 == "-t" ]] || [[ $1 == "--test" ]]; then
test_hdr_support
elif [[ $1 == "-a" ]] || [[ $1 == "--auto-setup-conf-file" ]]; then
setup_conf_file
elif [[ $# -eq 0 ]]; then # Automatically Toggle HDR | Default Behaviour
auto_hdr
else
+21 -9
View File
@@ -1,9 +1,14 @@
import re
import subprocess
import os
import shutil
class Setup():
class MonitorSetup():
def __init__(self):
self._stg_conf_file = "monitor.conf"
self._conf_file_path = os.path.join(os.path.expanduser('~'),
".config/hdr-helper",self._stg_conf_file)
################################
self.default_mode = None
self.alt_rate = None
self.alt_res_and_rate = None
@@ -54,12 +59,11 @@ class Setup():
print(f"Alternative Resolution and Rate: {self.alt_res_and_rate}")
def edit_config_file(self):
conf_file = "monitor.conf"
if os.path.isfile(conf_file):
with open(conf_file, "r") as file:
if os.path.isfile(self._stg_conf_file):
with open(self._stg_conf_file, "r") as file:
lines = file.readlines()
with open(conf_file, "w") as file:
with open(self._stg_conf_file, "w") as file:
for line in lines:
if "MONITOR=" in line:
line = line.replace("MONITOR=\n", f"MONITOR={self.output_name}\n")
@@ -75,9 +79,17 @@ class Setup():
file.write(line)
def copy_config_file(self):
# Backup existing config file if it exists
if os.path.isfile(self._conf_file_path):
shutil.move(self._conf_file_path, self._conf_file_path + ".backup" )
# Copy staging config file to target location
if os.path.isfile(self._stg_conf_file):
shutil.copy(self._stg_conf_file, self._conf_file_path)
setup = Setup()
setup = MonitorSetup()
setup.extract_display_info()
#setup.print_display_info()
setup.edit_config_file()
setup.edit_config_file()
setup.copy_config_file()