#!/bin/bash

# This file is sourced by /etc/X11/fly-dm/Xsession, not executed.

FLY_VM_NAME=
VM=$(systemd-detect-virt -v)
if [ $? -eq "0" ]; then
  export FLY_VM_NAME=$VM
else
  #it is really required if autologin only
  if [ ! -z ${FLY_AUTOLOGIN} ]; then
    /usr/bin/fly-dm-set-dpi.sh
  fi
fi

# replace default session name if autologin
if [ "$session" = "default" ]; then
  session="fly-wm"
  export DESKTOP_SESSION="fly"
  if [ -z "$FLY_VM_NAME" ]; then
    # try to detect real keyboard and touchscreen
    ls -d /sys/class/input/*/*::capslock > /dev/null 2>&1
    if [ $? -ne "0" ]; then
      if [ ! -z "$IS_TOUCH" ]; then
        export DESKTOP_SESSION="fly-tablet"
      fi
    fi
  fi

  echo "[Desktop]" > $HOME/.dmrc
  echo "Session=$DESKTOP_SESSION" >> $HOME/.dmrc
fi
