Skip to content

Instantly share code, notes, and snippets.

@antonio
Created November 28, 2011 12:46
Show Gist options
  • Save antonio/1400271 to your computer and use it in GitHub Desktop.
Save antonio/1400271 to your computer and use it in GitHub Desktop.
Automatically configure screens
#!/usr/bin/env ruby
EXTERNAL_SCREEN = 'VGA1'
LAPTOP_SCREEN = 'LVDS1'
def use_external_screen
system "xrandr --output #{EXTERNAL_SCREEN} --auto && xrandr --output #{LAPTOP_SCREEN} --off"
end
def use_laptop_screen
system "xrandr --output #{LAPTOP_SCREEN} --auto && xrandr --output #{EXTERNAL_SCREEN} --off"
end
def is_vga_connected?
IO.popen('xrandr -q | grep " connected "').each do |l|
return true if l =~ /#{EXTERNAL_SCREEN}/
end
return false
end
loop {
if is_vga_connected?
use_external_screen
else
use_laptop_screen
end
sleep 5
}
@martinklepsch
Copy link

There is no need for the daemons gem.
You should execute this file within your .xinitrc and background it by appending &.

@antonio
Copy link
Author

antonio commented Nov 28, 2011

Yeah, you are absolutely right. I don't use .xinitrc though, but I suppose it should work as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment