6262--fingerprint fingerprint your current hardware setup
6363--config dump your current xrandr setup
6464--dry-run don't change anything, only print the xrandr commands
65+ --debug enable verbose output
6566
6667 To prevent a profile from being loaded, place a script call "block" in its
6768 directory. The script is evaluated before the screen setup is inspected, and
@@ -171,7 +172,11 @@ class XrandrOutput(object):
171172 EDID_UNAVAILABLE = "--CONNECTED-BUT-EDID-UNAVAILABLE-"
172173
173174 def __repr__ (self ):
174- return "<%s%s %s>" % (self .output , (" %s..%s" % (self .edid [:5 ], self .edid [- 5 :])) if self .edid else "" , " " .join (self .option_vector ))
175+ return "<%s%s %s>" % (self .output , self .short_edid , " " .join (self .option_vector ))
176+
177+ @property
178+ def short_edid (self ):
179+ return ("%s..%s" % (self .edid [:5 ], self .edid [- 5 :])) if self .edid else ""
175180
176181 @property
177182 def options_with_defaults (self ):
@@ -358,6 +363,27 @@ def __ne__(self, other):
358363 def __eq__ (self , other ):
359364 return self .edid_equals (other ) and self .output == other .output and self .filtered_options == other .filtered_options
360365
366+ def verbose_diff (self , other ):
367+ "Compare to another XrandrOutput and return a list of human readable differences"
368+ diffs = []
369+ if not self .edid_equals (other ):
370+ diffs .append ("EDID `%s' differs from `%s'" % (self .short_edid , other .short_edid ))
371+ if self .output != other .output :
372+ diffs .append ("Output name `%s' differs from `%s'" % (self .output , other .output ))
373+ if "off" in self .options and "off" not in other .options :
374+ diffs .append ("The output is disabled currently, but active in the new configuration" )
375+ elif "off" in other .options and "off" not in self .options :
376+ diffs .append ("The output is currently enabled, but inactive in the new configuration" )
377+ else :
378+ for name in set (chain .from_iterable ((self .options .keys (), other .options .keys ()))):
379+ if name not in other .options :
380+ diffs .append ("Option --%s %sis not present in the new configuration" % (name , "(= `%s') " % self .options [name ] if self .options [name ] else "" ))
381+ elif name not in self .options :
382+ diffs .append ("Option --%s (`%s' in the new configuration) is not present currently" % (name , other .options [name ]))
383+ elif self .options [name ] != other .options [name ]:
384+ diffs .append ("Option --%s %sis `%s' in the new configuration" % (name , "(= `%s') " % self .options [name ] if self .options [name ] else "" , other .options [name ]))
385+ return diffs
386+
361387def xrandr_version ():
362388 "Return the version of XRandR that this system uses"
363389 if getattr (xrandr_version , "version" , False ) is False :
@@ -619,6 +645,23 @@ def generate_virtual_profile(configuration, modes, profile_name):
619645 configuration [output ].options ["off" ] = None
620646 return configuration
621647
648+ def print_profile_differences (one , another ):
649+ "Print the differences between two profiles for debugging"
650+ if one == another :
651+ return
652+ print ("| Differences between the two profiles:" , file = sys .stderr )
653+ for output in set (chain .from_iterable ((one .keys (), another .keys ()))):
654+ if output not in one :
655+ if "off" not in another [output ].options :
656+ print ("| Output `%s' is missing from the active configuration" % output , file = sys .stderr )
657+ elif output not in another :
658+ if "off" not in one [output ].options :
659+ print ("| Output `%s' is missing from the new configuration" % output , file = sys .stderr )
660+ else :
661+ for line in one [output ].verbose_diff (another [output ]):
662+ print ("| [Output %s] %s" % (output , line ), file = sys .stderr )
663+ print ("\\ -" , file = sys .stderr )
664+
622665def exit_help ():
623666 "Print help and exit"
624667 print (help_text )
@@ -634,7 +677,7 @@ def exec_scripts(profile_path, script_name):
634677
635678def main (argv ):
636679 try :
637- options = dict (getopt .getopt (argv [1 :], "s:l:d:cfh" , [ "dry-run" , "change" , "default=" , "save=" , "load=" , "force" , "fingerprint" , "config" , "skip-options=" , "help" ])[0 ])
680+ options = dict (getopt .getopt (argv [1 :], "s:l:d:cfh" , [ "dry-run" , "change" , "default=" , "save=" , "load=" , "force" , "fingerprint" , "config" , "debug" , " skip-options=" , "help" ])[0 ])
638681 except getopt .GetoptError as e :
639682 print ("Failed to parse options: {0}.\n "
640683 "Use --help to get usage information." .format (str (e )),
@@ -711,9 +754,12 @@ def main(argv):
711754 props .append ("(detected)" )
712755 if ("-c" in options or "--change" in options ) and not load_profile :
713756 load_profile = profile_name
714- if is_equal_configuration (config , profiles [profile_name ]["config" ]):
757+ configs_are_equal = is_equal_configuration (config , profiles [profile_name ]["config" ])
758+ if configs_are_equal :
715759 props .append ("(current)" )
716760 print ("%s%s%s" % (profile_name , " " if props else "" , " " .join (props )), file = sys .stderr )
761+ if not configs_are_equal and "--debug" in options and profile_name in detected_profiles :
762+ print_profile_differences (config , profiles [profile_name ]["config" ])
717763
718764 if "-d" in options :
719765 options ["--default" ] = options ["-d" ]
@@ -737,6 +783,10 @@ def main(argv):
737783 if load_config == dict (config ) and not "-f" in options and not "--force" in options :
738784 print ("Config already loaded" , file = sys .stderr )
739785 sys .exit (0 )
786+ if "--debug" in options and load_config != dict (config ):
787+ print ("Loading profile '%s'" % load_profile )
788+ print_profile_differences (config , load_config )
789+
740790 remove_irrelevant_outputs (config , load_config )
741791
742792 try :
0 commit comments