### .xsession  -*- Sh -*-
## X-based session setup.

### Ivan Shmakov, 2013, 2014, 2015, 2017, 2019

## To the extent possible under law, the author(s) have dedicated
## all copyright and related and neighboring rights to this software
## to the public domain worldwide.  This software is distributed
## without any warranty.

## You should have received a copy of the CC0 Public Domain Dedication
## along with this software.  If not, see
## <http://creativecommons.org/publicdomain/zero/1.0/>.

### Code:

## Source .session_common (unless done from ~/.xsessionrc)
test "$SOURCE_SESSION_COMMON" != no \
    -a -e "$HOME"/.session_common \
    &&  . "$HOME"/.session_common

## Only allow access via XAUTHORITY (undoing 35x11-common_xhost-local)
xhost -
xhost -SI:localuser:"$(id -un)"
xhost -SI:localuser:"$USER"

## NB: SSH_AUTH_SOCK is set up in ~/.session_common now

## Set up the X environment
xsetroot \
    -def \
    -bitmap /usr/include/X11/bitmaps/root_weave
setxkbmap -compat complete \
    -layout us,ru -option terminate:ctrl_alt_backspace,\
keypad:pointerkeys,grp:toggle,compose:rwin
extra_font_dir=
for d in /srv/chroot/20??-??-??*/usr/share/fonts/X11/misc ; do
    test -d "$d" \
        || continue
    extra_font_dir=${d}
done
if [ -n "$extra_font_dir" ] ; then
    xset fp+ "$extra_font_dir"
fi
xset dpms 240 480 720
xset s 192 17

## Try either XSM, Openbox, JWM, or x-window-manager
## .
if [ -e "$HOME"/.xsmstartup ] ; then
    command -v -- xsm && exec xsm
fi
command -v -- openbox && exec openbox
command -v -- jwm && exec jwm
command -v -- x-window-manager && exec x-window-manager
printf %s\\n \
    'Neither of xsm(1), openbox(1), jwm(1) or x-window-manager(1) is available' \
    >&2

## .
exit 1

### .xsession ends here
