- 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:
@@ -84,6 +84,10 @@ else
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup_conf_file() {
|
||||||
|
python monitor-setup.py
|
||||||
|
}
|
||||||
|
|
||||||
auto_hdr() {
|
auto_hdr() {
|
||||||
if [[ $(kscreen-doctor -o | grep -A 15 $MONITOR | grep HDR) == *"enabled"* ]]; then
|
if [[ $(kscreen-doctor -o | grep -A 15 $MONITOR | grep HDR) == *"enabled"* ]]; then
|
||||||
disable_hdr
|
disable_hdr
|
||||||
@@ -112,6 +116,8 @@ show_help () {
|
|||||||
echo " hdr-helper -h (--help)"
|
echo " hdr-helper -h (--help)"
|
||||||
echo "Tests whether the connected display is HDR capable"
|
echo "Tests whether the connected display is HDR capable"
|
||||||
echo " hdr-helper -t (--test)"
|
echo " hdr-helper -t (--test)"
|
||||||
|
echo "Automate monitor.conf file setup"
|
||||||
|
echo " hdr-helper -a (--auto-setup-conf-file)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Info ==="
|
echo "=== Info ==="
|
||||||
echo "Currently only KDE Plasma is supported running Wayland. Ensure that kscreen-doctor"
|
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
|
show_help
|
||||||
elif [[ $1 == "-t" ]] || [[ $1 == "--test" ]]; then
|
elif [[ $1 == "-t" ]] || [[ $1 == "--test" ]]; then
|
||||||
test_hdr_support
|
test_hdr_support
|
||||||
|
elif [[ $1 == "-a" ]] || [[ $1 == "--auto-setup-conf-file" ]]; then
|
||||||
|
setup_conf_file
|
||||||
elif [[ $# -eq 0 ]]; then # Automatically Toggle HDR | Default Behaviour
|
elif [[ $# -eq 0 ]]; then # Automatically Toggle HDR | Default Behaviour
|
||||||
auto_hdr
|
auto_hdr
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
class Setup():
|
class MonitorSetup():
|
||||||
def __init__(self):
|
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.default_mode = None
|
||||||
self.alt_rate = None
|
self.alt_rate = None
|
||||||
self.alt_res_and_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}")
|
print(f"Alternative Resolution and Rate: {self.alt_res_and_rate}")
|
||||||
|
|
||||||
def edit_config_file(self):
|
def edit_config_file(self):
|
||||||
conf_file = "monitor.conf"
|
if os.path.isfile(self._stg_conf_file):
|
||||||
if os.path.isfile(conf_file):
|
with open(self._stg_conf_file, "r") as file:
|
||||||
with open(conf_file, "r") as file:
|
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
|
|
||||||
with open(conf_file, "w") as file:
|
with open(self._stg_conf_file, "w") as file:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if "MONITOR=" in line:
|
if "MONITOR=" in line:
|
||||||
line = line.replace("MONITOR=\n", f"MONITOR={self.output_name}\n")
|
line = line.replace("MONITOR=\n", f"MONITOR={self.output_name}\n")
|
||||||
@@ -75,9 +79,17 @@ class Setup():
|
|||||||
|
|
||||||
file.write(line)
|
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 = MonitorSetup()
|
||||||
setup = Setup()
|
|
||||||
setup.extract_display_info()
|
setup.extract_display_info()
|
||||||
#setup.print_display_info()
|
setup.edit_config_file()
|
||||||
setup.edit_config_file()
|
setup.copy_config_file()
|
||||||
Reference in New Issue
Block a user