summaryrefslogtreecommitdiff
path: root/ar/.local/bin/setmonitors
blob: 76dabb8350a5eb3edab2f6c58f692146115843ba (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh

# Run screenlayout script if available
script="$HOME/.screenlayout/default.sh"
[ -f "$script" ] && sh "$script" && exit

# Per-monitor settings
edp_cfg="--mode 1920x1080 --rotate normal --scale 1.0x1.0 --dpi 82"
hdmi_cfg="--mode 1920x1080 --rotate normal --scale 1.0x1.0 --dpi 82"
dp_cfg="--mode 2560x1600 --rotate normal --scale 1.0x1.0 --dpi 192"

# EDID 미감지 시 (640x480에 갇힌 경우) 1920x1080 폴백 적용
if xrandr -q | grep " connected" | grep -q "640x480+"; then
  xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync 2>/dev/null
  for output in $(xrandr -q | grep -w "connected" | cut -d ' ' -f 1); do
    xrandr --addmode "$output" 1920x1080_60.00 2>/dev/null
  done
  dp_cfg="--mode 1920x1080_60.00 --rotate normal --scale 1.0x1.0 --dpi 96"
fi

# Parse connected displays
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
lid_state=""
for lid_path in /proc/acpi/button/lid/*/state; do
  [ -f "$lid_path" ] && lid_state=$(cat "$lid_path") && break
done
if echo "$lid_state" | grep -q "closed"; then
  if [ -n "$hdmi" ] && [ -z "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$edp" --off --output "$hdmi" --primary $hdmi_cfg
  elif [ -z "$hdmi" ] && [ -n "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$edp" --off --output "$dp" --primary $dp_cfg
  else
    xrandr --output "$edp" --off --output "$display" --auto --primary
  fi
else
  # Apply display settings when lid is open
  if [ -n "$hdmi" ] && [ -z "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$hdmi" --primary --pos 0x0 $hdmi_cfg --output "$edp" --pos 1920x0 $edp_cfg
  elif [ -z "$hdmi" ] && [ -n "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$dp" --primary --pos 0x0 $dp_cfg --output "$edp" --pos 2560x0 $edp_cfg
  elif [ -z "$hdmi" ] && [ -z "$dp" ] && [ -n "$edp" ]; then
    xrandr --output "$edp" --primary $edp_cfg
  elif [ -n "$hdmi" ] && [ -z "$dp" ] && [ -z "$edp" ]; then
    xrandr --output "$hdmi" --primary $hdmi_cfg
  elif [ -z "$hdmi" ] && [ -n "$dp" ] && [ -z "$edp" ]; then
    xrandr --output "$dp" --primary $dp_cfg
  else
    xrandr --output "$display" --primary --auto
  fi
fi