From: Christophe-Marie Duquesne Date: Thu, 31 Oct 2019 23:46:19 +0000 (+0100) Subject: Treating a closed lid as disconnected X-Git-Tag: 1.9~3^2~7 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f5f2f52dbab6225ce31f5842711f0af515185153;p=deb_pkgs%2Fautorandr.git Treating a closed lid as disconnected --- diff --git a/autorandr.py b/autorandr.py index 44e9ad2..963303e 100755 --- a/autorandr.py +++ b/autorandr.py @@ -37,6 +37,7 @@ import subprocess import sys import shutil import time +import glob from collections import OrderedDict from distutils.version import LooseVersion as Version @@ -96,6 +97,18 @@ Usage: autorandr [options] """.strip() +def is_closed_lid(output): + if not re.match(r'(eDP(-?[0-9]\+)*|LVDS(-?[0-9]\+)*)', output): + return False + lids = glob.glob("/proc/acpi/button/lid/*/state") + if len(lids) == 1: + state_file = lids[0] + with open(state_file) as f: + content = f.read() + return "close" in content + return False + + class AutorandrException(Exception): def __init__(self, message, original_exception=None, report_bug=False): self.message = message @@ -311,7 +324,7 @@ class XrandrOutput(object): raise AutorandrException("Parsing XRandR output failed, couldn't find any display modes", report_bug=True) options = {} - if not match["connected"]: + if not match["connected"] or is_closed_lid(match["output"]): edid = None elif match["edid"]: edid = "".join(match["edid"].strip().split())