Skip to content

Instantly share code, notes, and snippets.

@lukestanley
Created June 25, 2020 18:03
Show Gist options
  • Save lukestanley/89f0888cc94bf38c0b14f7d50f70a540 to your computer and use it in GitHub Desktop.
Save lukestanley/89f0888cc94bf38c0b14f7d50f70a540 to your computer and use it in GitHub Desktop.
Detects external monitor by polling xrandr and sets up my custom layout saved from arandr because XFCE didn't do it for me.
from time import sleep
from subprocess import check_output
from os import system as run
def shell(command):
return check_output(command, shell=True)
def display_count():
return str(shell("xrandr -q")).count(' connected')
def setup_display():
if display_count() == 2:
print('Display changed - dual screen detected, running layout script')
run('/home/user/bin/dual_screen.sh')
else:
print('Display changed detected but no setup is needed, since the default is okay')
last_state = display_count()
while True:
if last_state != display_count():
last_state = display_count()
setup_display()
sleep(0.8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment