X-Git-Url: https://git.donarmstrong.com/?p=deb_pkgs%2Fautorandr.git;a=blobdiff_plain;f=autorandr.py;h=9c272a79f05b8b199ae43580fe212bd3a569b7fd;hp=abf11980ca36be22b9ece76b64d569559120ede8;hb=refs%2Fheads%2Fwork;hpb=e853c01c118e089b3b10670bec0174834289e809 diff --git a/autorandr.py b/autorandr.py index abf1198..9c272a7 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: @@ -49,6 +54,7 @@ except NameError: virtual_profiles = [ # (name, description, callback) + ("off", "Disable all outputs", None), ("common", "Clone all connected outputs at the largest common resolution", None), ("clone-largest", "Clone all connected outputs with the largest resolution (scaled down if necessary)", None), ("horizontal", "Stack all connected outputs horizontally at their largest resolution", None), @@ -799,6 +805,11 @@ def generate_virtual_profile(configuration, modes, profile_name): configuration[output].options["transform"] = "{},0,{},0,{},{},0,0,1".format(scale, mov_x, scale, mov_y) else: configuration[output].options["off"] = None + elif profile_name == "off": + for output in configuration: + for key in list(configuration[output].options.keys()): + del configuration[output].options[key] + configuration[output].options["off"] = None return configuration @@ -865,12 +876,11 @@ def exec_scripts(profile_path, script_name, meta_information=None): candidate_directories = [user_profile_path] for config_dir in os.environ.get("XDG_CONFIG_DIRS", "/etc/xdg").split(":"): - candidate_directories += os.path.join(config_dir, "autorandr") + candidate_directories.append(os.path.join(config_dir, "autorandr")) if profile_path: - candidate_directories += profile_path + candidate_directories.append(profile_path) for folder in candidate_directories: - if script_name not in ran_scripts: script = os.path.join(folder, script_name) if os.access(script, os.X_OK | os.F_OK): @@ -1003,6 +1013,14 @@ 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")) + 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", @@ -1041,6 +1059,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") @@ -1050,6 +1069,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: