Created
August 27, 2020 22:05
-
-
Save stefanv/91eb61cba2835c787533f5871f3ba038 to your computer and use it in GitHub Desktop.
Automated setup of side-by-side displays in i3
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
#!/bin/bash | |
# Modified from: https://faq.i3wm.org/question/2332/flexible-monitor-setup/ | |
SWITCH_WS="${HOME}/scripts/i3-switch-ws" | |
# Switch screens on, in case they were asleep | |
xset dpms force on | |
# Find laptop display (DEFAULT) | |
DEFAULT=`xrandr | grep -e eDP.*connected | cut -f 1 -d ' '` | |
echo "Laptop display: $DEFAULT" | |
# By default, set default display as primary, and move all workspaces there | |
xrandr --output $DEFAULT --primary | |
${SWITCH_WS} $DEFAULT | |
# Place other displays above of laptop display | |
# and set as primary output | |
for output in $(xrandr | grep -v $DEFAULT | grep '\Wconnected' | cut -f 1 -d ' '); do | |
if [[ ! $output =~ ^DEFAULT.*$ ]]; then | |
echo "Positioning $output to the above of $DEFAULT" | |
# This is only necessary because not all external monitors advertise | |
# their preferred mode. Otherwise xrandr argument '--auto' would suffice. | |
FIRSTMODE=$(xrandr | grep -A 1 "$output connected" | tail -n 1 | awk '{print $1}') | |
echo "Detected first mode of $output as $FIRSTMODE" | |
xrandr --output $DEFAULT --auto \ | |
--output $output --pos 0x0 --mode "$FIRSTMODE" \ | |
--right-of $DEFAULT --primary | |
${SWITCH_WS} $output | |
fi | |
done | |
# Switch off disconnected external monitors | |
for output in $(xrandr | grep -v $DEFAULT | grep '\Wdisconnected' | cut -f 1 -d ' '); do | |
xrandr --output $output --off | |
done | |
# Hack to get office keyboard fixed as well | |
if [[ -n `xinput -list | grep "Apple Keyboard"` ]]; then | |
echo | |
echo "Apple keyboard detected--setting up." | |
kbfix-apple | |
else | |
echo "Setting up keyboard for laptop" | |
kbfix | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment