summaryrefslogtreecommitdiff
path: root/src/firestartx
blob: 1129f9d4466af455d4e3fb395ec7dc8773134945 (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
#!/bin/bash

if [ $# = 0 ]
then
    set -- firestart
fi

get_new_display()
{
    for ((n=1; n<99; ++n))
    do
        if [ ! -e /tmp/.X$n-lock ]
        then
            NEW_DISPLAY=:$n
            return
        fi
    done
    false
}

get_new_display || exit

dpi=$(xrdb -query | sed -n -e 's/^Xft.dpi:[ \t]*//p')

launch_xserver()
{
    "$@" -- "$(which Xephyr)" "$NEW_DISPLAY" \
        -resizeable \
        -p 0 \
        -terminate \
        ${dpi:+ -dpi "$dpi"}
}

if [ "$1" != firestart ]
then
    case "$1" in
        */*)
            [ -x "$1" ] || exit
            ;;
        *)
            f1=$(command -v "$1") || exit
            shift
            set -- "$f1" "$@"
            ;;
    esac
    launch_xserver xinit "$@"
else
    XSESSION_IS_FIRESTARTX=
    if grep -qF XSESSION_IS_FIRESTARTX ~/.xsession
    then
        # Our xsession will launch firestartx along with i3, etc.
        XSESSION_IS_FIRESTARTX=y launch_xserver startx ~/.xsession &
    else
        # We need to wait for xrdb to be run, or else firefox will
        # disastrously start without the Xft.dpi setting.  But we
        # cannot poll on the setting forever since it might not exist
        # in every configuration.
        launch_xserver startx &
        enable -f /usr/lib/bash/sleep >/dev/null 2>&1 || true
        set -x
        tries=0
        while [ $tries -lt 40 ] &&
              ! xrdb -display "$NEW_DISPLAY" -query | grep -q '^Xft.dpi:'
        do
            sleep 0.05
            tries=$((tries + 1))
        done
        DISPLAY=$NEW_DISPLAY "$@" &
    fi

    wait
fi