--debug enable verbose output
--batch run autorandr for all users with active X11 sessions
- To prevent a profile from being loaded, place a script call "block" in its
+ To prevent a profile from being loaded, place a script called "block" in its
directory. The script is evaluated before the screen setup is inspected, and
in case of it returning a value of 0 the profile is skipped. This can be used
to query the status of a docking station you are about to leave.
return profiles
+def get_symlinks(profile_path):
+ "Load all symlinks from a directory"
+
+ symlinks = {}
+ for link in os.listdir(profile_path):
+ file_name = os.path.join(profile_path, link)
+ if os.path.islink(file_name):
+ symlinks[link] = os.readlink(file_name)
+
+ return symlinks
+
def find_profiles(current_config, profiles):
"Find profiles matching the currently connected outputs"
detected_profiles = []
if not os.path.isfile(environ_file):
continue
uid = os.stat(environ_file).st_uid
- if uid == 0:
+
+ # The following line assumes that user accounts start at 1000 and that
+ # no one works using the root or another system account. This is rather
+ # restrictive, but de facto default. Alternatives would be to use the
+ # UID_MIN from /etc/login.defs or FIRST_UID from /etc/adduser.conf;
+ # but effectively, both values aren't binding in any way.
+ # If this breaks your use case, please file a bug on Github.
+ if uid < 1000:
continue
process_environ = {}
return
profiles = {}
+ profile_symlinks = {}
try:
# Load profiles from each XDG config directory
# The XDG spec says that earlier entries should take precedence, so reverse the order
system_profile_path = os.path.join(directory, "autorandr")
if os.path.isdir(system_profile_path):
profiles.update(load_profiles(system_profile_path))
+ profile_symlinks.update(get_symlinks(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")
profile_path = os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "autorandr")
if os.path.isdir(profile_path):
profiles.update(load_profiles(profile_path))
+ profile_symlinks.update(get_symlinks(profile_path))
# Sort by descending mtime
profiles = OrderedDict(sorted(profiles.items(), key=lambda x: -x[1]["config-mtime"]))
except Exception as e:
raise AutorandrException("Failed to load profiles", e)
+ profile_symlinks = { k: v for k, v in profile_symlinks.items() if v in (x[0] for x in virtual_profiles) or v in profiles }
+
config, modes = parse_xrandr_output()
if "--fingerprint" in options:
load_profile = options["--default"]
if load_profile:
+ if load_profile in profile_symlinks:
+ if "--debug" in options:
+ print("'%s' symlinked to '%s'" % (load_profile, profile_symlinks[load_profile]))
+ load_profile = profile_symlinks[load_profile]
+
if load_profile in ( x[0] for x in virtual_profiles ):
load_config = generate_virtual_profile(config, modes, load_profile)
scripts_path = os.path.join(profile_path, load_profile)
sys.exit(0)
-if __name__ == '__main__':
+def exception_handled_main(argv=sys.argv):
try:
main(sys.argv)
except AutorandrException as e:
print("Unhandled exception ({0}). Please report this as a bug at https://github.com/phillipberndt/autorandr/issues.".format(e), file=sys.stderr)
raise
+
+if __name__ == '__main__':
+ exception_handled_main()