#!/bin/bash

# This file is sourced by /etc/X11/fly-dm/Xsession, not executed.
echo fly detect default session  `date '+%F %T.%3N'`

#reset dpi and cursor size because they probably was set in Xsetup or in fly-dm for itself
echo "Xft.dpi"      | /usr/bin/xrdb -remove -quiet
echo "Xcursor.size" | /usr/bin/xrdb -remove -quiet

FLY_VM_NAME=
VM=$(systemd-detect-virt -v)
if [ $? -eq "0" ]; then export FLY_VM_NAME=$VM; 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
