summaryrefslogtreecommitdiff
path: root/ar/.local/bin/setmonitor
blob: 8ed45897e96cbcd5d62784bb61c66a7f6c266f1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh

# Parse connected displays
default="--mode 1920x1080 --rotate normal --scale 1.0x1.0 --dpi 96"

for connected in $(xrandr -q | grep -w "connected" | cut -d ' ' -f 1); do
  case $connected in
  eDP*) edp="$connected" ;;
  HDMI*) hdmi="$connected" ;;
  DP*) dp="$connected" ;;
  *) display="$connected" ;;
  esac
done

# If the lid is closed, turn off the laptop's screen
if grep -q "closed" /proc/acpi/button/lid/LID/state; then
  if [ -n "$hdmi" ] && [ -z "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$edp" --off --output "$hdmi" --primary $default
  elif [ -z "$hdmi" ] && [ -n "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$edp" --off --output "$dp" --primary $default
  else
    xrandr --output "$edp" --off --output "$display" --auto --primary $default
  fi
else
  # Apply display settings when lid is open
  if [ -n "$hdmi" ] && [ -z "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$edp" --pos 1920x0 $default --output "$hdmi" --primary --pos 0x0 $default
  elif [ -z "$hdmi" ] && [ -n "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$edp" --pos 1920x0 $default --output "$dp" --primary --pos 0x0 $default
  elif [ -z "$hdmi" ] && [ -z "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$edp" --primary $default
  else
    xrandr --output "$display" --primary --auto
  fi
fi