From 4e16d193f7ce7e474a4d5c1d2f37f66051492dad Mon Sep 17 00:00:00 2001 From: Fil Sapia Date: Wed, 8 Oct 2025 23:19:04 +0100 Subject: [PATCH] - Added automatic monitor.conf setup to hdr-helper script - Setup script now copies config file and backups up old one --- hdr-helper | 8 ++++++++ setup.py => monitor-setup.py | 30 +++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) rename setup.py => monitor-setup.py (74%) diff --git a/hdr-helper b/hdr-helper index 51145f1..86a773f 100755 --- a/hdr-helper +++ b/hdr-helper @@ -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 diff --git a/setup.py b/monitor-setup.py similarity index 74% rename from setup.py rename to monitor-setup.py index 97e933a..25cb46e 100644 --- a/setup.py +++ b/monitor-setup.py @@ -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() \ No newline at end of file +setup.edit_config_file() +setup.copy_config_file() \ No newline at end of file