Disable screen blanking by default via xorg configuration snippet
Further changes: - add ppa:yavdr/experimental-kodi for KODI 18 - add set-kodi-display script to allow switching DISPLAY in dual screen configuration (inkompatible with KODI 17)
This commit is contained in:
@@ -35,4 +35,9 @@
|
||||
group: '{{ vdr.group }}'
|
||||
mode: "0664"
|
||||
force: no
|
||||
# TODO: Add configuration files
|
||||
|
||||
- name: expand template for set-kodi-display
|
||||
template:
|
||||
src: 'templates/set-kodi-display.j2'
|
||||
dest: '/usr/bin/set-kodi-display'
|
||||
mode: "0755"
|
||||
|
||||
@@ -9,4 +9,4 @@ ExecStart=/usr/bin/kodi -l /run/lirc/lircd
|
||||
ExecStop=/bin/bash -c "/usr/bin/kodi-send --action=QUIT; while ps -p $MAINPID -o comm=; do sleep .25; done"
|
||||
TimeoutStopSec=10
|
||||
SuccessExitStatus=0 127 SIGKILL
|
||||
Restart=on-failure
|
||||
Restart=on-failure
|
||||
96
roles/kodi/templates/set-kodi-display.j2
Normal file
96
roles/kodi/templates/set-kodi-display.j2
Normal file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
{{ ansible_managed }}
|
||||
|
||||
This Script changes the monitor in KODI's guisettings.xml to the wanted output
|
||||
according to the DISPLAY environment variable. It works with KODI 18 (not KODI 17!).
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
GUISETTINGS = '/var/lib/vdr/.kodi/userdata/guisettings.xml'
|
||||
CACHE_DIR = '/var/lib/vdr/.kodi/.display_cache'
|
||||
VIDEOSCREEN_TEMPLATE = """<settings version="2">
|
||||
<setting id="videoscreen.monitor" default="true">{}</setting>
|
||||
</settings>"""
|
||||
|
||||
|
||||
def get_output_names():
|
||||
"""
|
||||
get display name from xrandr output for given DISPLAY environment variable
|
||||
"""
|
||||
xrandr_output = [
|
||||
l for l in subprocess.check_output(
|
||||
["xrandr"],
|
||||
env={"DISPLAY": os.environ["DISPLAY"]}
|
||||
).decode("utf-8").splitlines()
|
||||
]
|
||||
return [l.split()[0] for l in xrandr_output if " connected " in l]
|
||||
|
||||
|
||||
def parse_template(template_path, template, output=""):
|
||||
"""read videoscreen settings from backup or create a stub file"""
|
||||
try:
|
||||
xml_tree = ET.parse(template_path)
|
||||
except FileNotFoundError:
|
||||
print("{} not found, creating stub file".format(template_path))
|
||||
xml_template = ET.fromstring(template.format(output))
|
||||
xml_tree = ET.ElementTree(xml_template)
|
||||
finally:
|
||||
xml_tree.write(template_path)
|
||||
return xml_tree
|
||||
|
||||
|
||||
def backup_videoscreen():
|
||||
"""parse guisettings.xml for display name an backup videoscreen data"""
|
||||
tree = parse_template(GUISETTINGS, VIDEOSCREEN_TEMPLATE, "Default")
|
||||
root = tree.getroot()
|
||||
videoscreen = root.find("./setting[@id='videoscreen.monitor']")
|
||||
output = videoscreen.text
|
||||
xml_path = os.path.join(CACHE_DIR, '{}-videodevice.xml'.format(output))
|
||||
base_tree = ET.fromstring('<settings version="2"></settings>')
|
||||
xml_tree = ET.ElementTree(base_tree)
|
||||
backup_root = xml_tree.getroot()
|
||||
backup_root.insert(0, videoscreen)
|
||||
xml_tree.write(xml_path)
|
||||
print("written backup for {} to {}".format(output, xml_path))
|
||||
|
||||
|
||||
def change_videoscreen(output, new_videoscreen):
|
||||
"""change videoscreen node to content of backup file"""
|
||||
tree = parse_template(GUISETTINGS, VIDEOSCREEN_TEMPLATE, output)
|
||||
root = tree.getroot()
|
||||
|
||||
videoscreen = root.find('./setting[@id="videoscreen.monitor"]')
|
||||
if videoscreen is not None:
|
||||
videoscreen.text = new_videoscreen.text
|
||||
else:
|
||||
videoscreen = root.find("./settings")
|
||||
root.insert(0, new_videoscreen)
|
||||
tree.write(GUISETTINGS)
|
||||
return tree
|
||||
|
||||
if __name__ == '__main__':
|
||||
output = get_output_names()[0]
|
||||
if not output:
|
||||
sys.exit("Error: no screen name found")
|
||||
try:
|
||||
os.makedirs(CACHE_DIR, exist_ok=True)
|
||||
except PermissionError:
|
||||
sys.exit("Error: insufficient permissions to create cachedir {}".format(
|
||||
CACHE_DIR))
|
||||
try:
|
||||
backup_videoscreen()
|
||||
except FileNotFoundError:
|
||||
print("{} does not exist".format(GUISETTINGS))
|
||||
except Exception as e:
|
||||
print("Could not backup videoscreen.monitor:", str(e))
|
||||
xml_path = os.path.join(CACHE_DIR, '{}-videodevice.xml'.format(output))
|
||||
videodir_xml = parse_template(xml_path, VIDEOSCREEN_TEMPLATE, output)
|
||||
videodir_root = videodir_xml.getroot()
|
||||
new_videoscreen = videodir_root.find("./setting[@id='videoscreen.monitor']")
|
||||
guisettings_xml = change_videoscreen(output, new_videoscreen)
|
||||
Reference in New Issue
Block a user