Skip to content

Commit 586dce7

Browse files
committed
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 f4cce4d
1 parent ad5ac61 commit 586dce7

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

autorandr.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,29 @@ def apply_configuration(configuration, dry_run=False):
422422

423423
# Disable all unused outputs
424424
argv = base_argv[:]
425+
disable_argv = []
425426
for output in outputs:
426427
if not configuration[output].edid or "off" in configuration[output].options:
427-
argv += configuration[output].option_vector
428-
if argv != base_argv:
429-
if subprocess.call(argv) != 0:
430-
return False
428+
disable_argv += configuration[output].option_vector
429+
if disable_argv:
430+
if subprocess.call(base_argv + disable_argv) != 0:
431+
# Disabling the outputs failed. Retry with the next command:
432+
# Sometimes disabling of outputs fails due to an invalid RRSetScreenSize.
433+
# This does not occur if simultaneously the primary screen is reset.
434+
pass
435+
else:
436+
disable_argv = []
431437

432438
# Enable remaining outputs in pairs of two
433439
remaining_outputs = [ x for x in outputs if configuration[x].edid ]
434440
for index in range(0, len(remaining_outputs), 2):
435-
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:
436-
return False
441+
argv = base_argv[:]
442+
if disable_argv:
443+
argv += disable_argv
444+
disable_argv = []
445+
argv += configuration[remaining_outputs[index]].option_vector + (configuration[remaining_outputs[index + 1]].option_vector if index < len(remaining_outputs) - 1 else [])
446+
if subprocess.call(argv) != 0:
447+
raise RuntimeError("Command failed: %s" % " ".join(argv))
437448

438449
def add_unused_outputs(source_configuration, target_configuration):
439450
"Add outputs that are missing in target to target, in 'off' state"

0 commit comments

Comments
 (0)