#!/bin/bash

PLACE=$1
INTERNAL=$(xrandr | grep eDP | cut -d' ' -f1)

case $PLACE in
  single)
    for display in $(xrandr | grep -v '^ ' | grep -v '^Screen' | grep ' connected' | cut -d' ' -f1)
    do
      xrandr --output "${display}" --off
    done
    xrandr --output "${INTERNAL}" --mode 1920x1080
    systemctl --user stop polybar@hdmi.service
    systemctl --user stop polybar@external.service
    systemctl --user restart polybar@internal.service
    ;;

  home)
    xrandr --output "${INTERNAL}" --off
    xrandr --output DP1-2 --primary --auto
    xrandr --output DP2-1 --left-of DP2-2 --auto
    systemctl --user stop polybar@hdmi.service
    systemctl --user restart polybar@external.service
    systemctl --user restart polybar@internal.service
    ;;

  work)
    xrandr --output "${INTERNAL}" --off
    xrandr --output HDMI2 --auto --right-of DP1-2
    xrandr --output DP1-2 --auto --primary
    systemctl --user restart polybar@hdmi.service
    systemctl --user restart polybar@external.service
    systemctl --user stop polybar@internal.service
    ;;
esac
