From: Phillip Berndt Date: Wed, 18 Feb 2015 07:02:18 +0000 (+0100) Subject: If disabling outputs failed, try to disable them together with the second xrandr... X-Git-Tag: 1.0~78 X-Git-Url: https://git.donarmstrong.com/?p=deb_pkgs%2Fautorandr.git;a=commitdiff_plain;h=586dce7ec54977b8a7cd1c38df7734fbd9a659c9 If disabling outputs failed, try to disable them together with the second xrandr call My notbook complains when I remove it from its docking station that RRSetScreenSize failed if I disable a screen. Issuing the whole xrandr command in one single call works fine. This is related to f4cce4dc3928ba3f917208c31693abc807b1ff3c --- diff --git a/autorandr.py b/autorandr.py index d7095f2..ee55935 100755 --- a/autorandr.py +++ b/autorandr.py @@ -422,18 +422,29 @@ def apply_configuration(configuration, dry_run=False): # Disable all unused outputs argv = base_argv[:] + disable_argv = [] for output in outputs: if not configuration[output].edid or "off" in configuration[output].options: - argv += configuration[output].option_vector - if argv != base_argv: - if subprocess.call(argv) != 0: - return False + disable_argv += configuration[output].option_vector + if disable_argv: + if subprocess.call(base_argv + disable_argv) != 0: + # Disabling the outputs failed. Retry with the next command: + # Sometimes disabling of outputs fails due to an invalid RRSetScreenSize. + # This does not occur if simultaneously the primary screen is reset. + pass + else: + disable_argv = [] # Enable remaining outputs in pairs of two remaining_outputs = [ x for x in outputs if configuration[x].edid ] for index in range(0, len(remaining_outputs), 2): - if subprocess.call((base_argv[:] + configuration[remaining_outputs[index]].option_vector + (configuration[remaining_outputs[index + 1]].option_vector if index < len(remaining_outputs) - 1 else []))) != 0: - return False + argv = base_argv[:] + if disable_argv: + argv += disable_argv + disable_argv = [] + argv += configuration[remaining_outputs[index]].option_vector + (configuration[remaining_outputs[index + 1]].option_vector if index < len(remaining_outputs) - 1 else []) + if subprocess.call(argv) != 0: + raise RuntimeError("Command failed: %s" % " ".join(argv)) def add_unused_outputs(source_configuration, target_configuration): "Add outputs that are missing in target to target, in 'off' state"