X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=autorandr.py;h=237aa83edc9035423b760bfa7382590f82bc64df;hb=07288eb0d7ac83dd7d0a0d59322660a0d309445a;hp=eae65a801b0254ad01687927aa09125b8727a21a;hpb=134d0edc7e70690d7d4308cc1013ed4354bc8df8;p=deb_pkgs%2Fautorandr.git diff --git a/autorandr.py b/autorandr.py index eae65a8..237aa83 100755 --- a/autorandr.py +++ b/autorandr.py @@ -42,6 +42,11 @@ from distutils.version import LooseVersion as Version from functools import reduce from itertools import chain +if sys.version_info.major == 2: + import ConfigParser as configparser +else: + import configparser + try: input = raw_input except NameError: @@ -763,13 +768,13 @@ def generate_virtual_profile(configuration, modes, profile_name): for output in configuration: configuration[output].options = {} if output in modes and configuration[output].edid: - def key(a, b): + def key(a): score = int(a["width"]) * int(a["height"]) if a["preferred"]: score += 10**6 return score - modes = sorted(modes[output], key=key) - mode = modes[-1] + output_modes = sorted(modes[output], key=key) + mode = output_modes[-1] configuration[output].options["mode"] = mode["name"] configuration[output].options["rate"] = mode["rate"] configuration[output].options["pos"] = pos_specifier % shift @@ -783,13 +788,13 @@ def generate_virtual_profile(configuration, modes, profile_name): for output in configuration: configuration[output].options = {} if output in modes and configuration[output].edid: - def key(a, b): + def key(a): score = int(a["width"]) * int(a["height"]) if a["preferred"]: score += 10**6 return score - modes = sorted(modes[output], key=key) - mode = modes[-1] + output_modes = sorted(modes[output], key=key) + mode = output_modes[-1] configuration[output].options["mode"] = mode["name"] configuration[output].options["rate"] = mode["rate"] configuration[output].options["pos"] = "0x0" @@ -1008,6 +1013,15 @@ def dispatch_call_to_sessions(argv): X11_displays_done.add(display) +def read_config(options, directory): + """Parse a configuration config.ini from directory and merge it into + the options dictionary""" + config = configparser.ConfigParser() + config.read(os.path.join(directory, "settings.ini")) + if config.has_section("config"): + for key, value in config.items("config"): + options.setdefault("--%s" % key, value) + def main(argv): try: opts, args = getopt.getopt(argv[1:], "s:r:l:d:cfh", @@ -1046,6 +1060,7 @@ def main(argv): if os.path.isdir(system_profile_path): profiles.update(load_profiles(system_profile_path)) profile_symlinks.update(get_symlinks(system_profile_path)) + read_config(options, system_profile_path) # For the user's profiles, prefer the legacy ~/.autorandr if it already exists # profile_path is also used later on to store configurations profile_path = os.path.expanduser("~/.autorandr") @@ -1055,6 +1070,7 @@ def main(argv): if os.path.isdir(profile_path): profiles.update(load_profiles(profile_path)) profile_symlinks.update(get_symlinks(profile_path)) + read_config(options, profile_path) # Sort by descending mtime profiles = OrderedDict(sorted(profiles.items(), key=lambda x: -x[1]["config-mtime"])) except Exception as e: