#!/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