Last active
January 12, 2021 08:17
-
-
Save eaceaser/f76911eee67a3282ff55813a267a10c7 to your computer and use it in GitHub Desktop.
Simple script to detect monitor changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACTION=="change", SUBSYSTEM=="drm", RUN+="/usr/bin/machinectl --uid=<YOUR-USER-NAME> shell .host /bin/bash -c '/bin/systemctl start --no-block --user sway-monitor'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import json | |
import time | |
EXTERNAL_MONITOR_NAMES = set(['DELL U2718Q', 'DELL U3011']) | |
outputs_str = subprocess.check_output('swaymsg -s $SWAYSOCK -r -t get_outputs', shell=True) | |
outputs = json.loads(outputs_str) | |
output_names = set(x["model"] for x in outputs) | |
if len(EXTERNAL_MONITOR_NAMES.intersection(output_names)) > 0: | |
print("Dock detected") | |
subprocess.check_output('swaymsg -s $SWAYSOCK output eDP-1 disable', shell=True) | |
else : | |
print("Roaming detected") | |
subprocess.check_output('swaymsg -s $SWAYSOCK output eDP-1 enable', shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=sway-monitor execution hook | |
After=sleep.target | |
StartLimitInterval=5 | |
StartLimitBurst=1 | |
[Service] | |
ExecStart=/usr/local/bin/sway-monitor-update.py | |
Type=oneshot | |
RemainAfterExit=false | |
KillMode=process | |
[Install] | |
WantedBy=sleep.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment