Skip to content

Instantly share code, notes, and snippets.

@brospars
Created March 21, 2018 08:09
Show Gist options
  • Save brospars/fb31015b6f9e60e6d28ccb8f1597b5d9 to your computer and use it in GitHub Desktop.
Save brospars/fb31015b6f9e60e6d28ccb8f1597b5d9 to your computer and use it in GitHub Desktop.
Switch between monitor configurations

Make an alias in $HOME/.bash_aliases

# switch monitor mode
alias sm='function _switch_monitor(){ $HOME/switch_monitor.sh $1;};_switch_monitor'

Here is an example of xrandr settings for switching between the built-in screen and the dual screen config (built-in uses a new mode no present by default)

#!/bin/bash

case $1 in
	dock)
		# ----- desktop dock with dual screen (main on display port, second on vga, builtin off)
		xrandr  --output "DP-2" --pos 0x0 --mode 1920x1080 --refresh 60.00 --primary --output "VGA-1" --pos 1920x0 --mode 1920x1200 --refresh 59.95 --output "LVDS-1" --off
		
		;;
	nomad)
		# ----- nomad with builtin screen
		# new mode bigger resolution
		if xrandr -q | grep -q "1600x900_60.00" ; then
			# found
			echo -n ""
		else
			# not found
			xrandr --newmode "1600x900_60.00"  118.25  1600 1696 1856 2112  900 903 908 934 -hsync +vsync
		fi
		xrandr --addmode LVDS-1 "1600x900_60.00"
		xrandr --output "VGA-1" --off --output "DP-2" --off --output "LVDS-1" --pos 0x0 --mode 1600x900_60.00 --primary
		;;
	*)
		echo "Unknown monitor config"
	;;
esac


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