summaryrefslogtreecommitdiff
path: root/bin/setup-desktop.sh
blob: 4ad1e48bb583223da6fffc85c8b21975f9fc8e75 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash

# Refresh /sys devices
xrandr -q &>/dev/null

have_dells=0
have_widescreen=""
have_projector=""
have_tv=""
display_count=0

# TODO: List screens if none are known

# These modes are all supported by the eDP-1 panel
zoom_modes=( 640x360 720x405 864x486 960x540
             1024x576 1280x720 1360x768 1368x768
             1600x900 1920x1080 2048x1152 2560x1440 )

# These all look decently sharp
edp_display_modes=( 1600x900 1920x1080 2048x1152 2880x1620 )
chosen_mode=2
all_screens=( )
default_mode=${edp_display_modes[$chosen_mode]}

## The zoomer will source us, don't do anything if that's the case
#if [[ "$(basename $BASH_SOURCE)" != "$(basename $0)" ]]; then
#    return
#fi

# There is no parse-edid available for Fedora
PARSE_EDID=parse-edid
if ! which parse-edid &>/dev/null; then
    PARSE_EDID=read_edid.py
fi

function setup_display()
{
    for output in /sys/class/drm/card*-*; do
        if [ "$(cat $output/status)" == "connected" ]; then
            card=$(basename $output)
            card=${card##card?-}
            edid=$(cat $output/edid | $PARSE_EDID 2>&1 | grep Identifier | cut -d '"' -f2)

            # 27" Dell monitors
            if [ "$edid" == "DELL U2715H" ]; then
                have_dells=1
            fi

            # Coral 2.401 projector
            if [ "$edid" == "AMX_HDMI1_A2" ]; then
                have_tv=$card
            fi

            # 34" widescreen Dell monitors
            if [ "$edid" == "DELL U3415W" ]; then
                have_widescreen=$card
            fi

            # Cisco + TV
            if [ "$edid" == "CS-CODECPLUS" ]; then
                have_tv="$card"
            fi

            # Crestron
            if [ "$edid" == "Crestron" ]; then
                have_tv="$card"
            fi

            all_screens+=( "$card:$edid" )
            (( display_count++ ))
        fi
    done

    if [ "$have_dells" == "1" ]; then
        xrandr --output DP-1 --auto --output DP-2 --auto --right-of DP-1 --output eDP-1 --off
    elif [ ! -z "$have_widescreen" ]; then
        xrandr --output $have_widescreen --mode 3440x1440 --output eDP-1 --off
    elif [ ! -z "$have_tv" ]; then
        xrandr --output eDP-1 --mode "$default_mode" --output $have_tv --auto --right-of eDP-1
    else
        xrandr --output eDP-1 --mode "$default_mode" --output DP-1 --off --output DP-2 --off --panning 0x0
    fi
}

function zoom_display()
{
    if [ -z "$1" ]; then
        xrandr --output eDP-1 --mode $default_mode --panning 0x0
    else
        if [ $1 -gt ${#zoom_modes} ]; then
            echo "There are only ${#zoom_modes} zoom stops"
            exit 1
        fi

        mode=${zoom_modes[$1]}
    fi

    xrandr --output eDP-1 --mode $mode --panning $default_mode
}

if [[ "$1" == "zoom" ]]; then
    zoom_display $2
else
    setup_display
fi