import sys
import shutil
import time
+import glob
from collections import OrderedDict
from distutils.version import LooseVersion as Version
""".strip()
+def is_closed_lid(output):
+ if not re.match(r'(eDP(-?[0-9]\+)*|LVDS(-?[0-9]\+)*)', output):
+ return False
+ lids = glob.glob("/proc/acpi/button/lid/*/state")
+ if len(lids) == 1:
+ state_file = lids[0]
+ with open(state_file) as f:
+ content = f.read()
+ return "close" in content
+ return False
+
+
class AutorandrException(Exception):
def __init__(self, message, original_exception=None, report_bug=False):
self.message = message
if output_modes:
modes[output_name] = output_modes
+ # consider a closed lid as disconnected if other outputs are connected
+ if sum(o.edid != None for o in outputs.values()) > 1:
+ for output_name in outputs.keys():
+ if is_closed_lid(output_name):
+ outputs[output_name].edid = None
+
return outputs, modes
--- /dev/null
+[Desktop Entry]
+Name=Autorandr Lid Listener
+Comment=Trigger autorandr whenever the lid state changes
+Type=Application
+Exec=bash -c "stdbuf -oL libinput debug-events | egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | while read line; do autorandr --change --default default; done"
+X-GNOME-Autostart-Phase=Initialization
--- /dev/null
+#!/bin/bash
+#
+# /!\ You must be part of the input group
+# sudo gpasswd -a $USER input
+
+stdbuf -oL libinput debug-events | \
+ egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | \
+ while read line; do
+ autorandr --change --default default
+done
--- /dev/null
+[Unit]
+Description=Runs autorandr whenever the lid state changes
+
+[Service]
+Type=simple
+ExecStart=bash -c "stdbuf -oL libinput debug-events | egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | while read line; do autorandr --batch --change --default default; done"
+Restart=always
+RestartSec=30
+SyslogIdentifier=autorandr
+
+[Install]
+WantedBy=multi-user.target