#!/bin/bash

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

if [ -z "${XAUTHORITY}" ]; then
   export XAUTHORITY="$HOME/.Xauthority"
fi
#to inform X server about ... dont need anymore due to API call to label session used in fly-dm
#/usr/bin/xlsclients > /dev/null 2>&1

session="$1"

if ! test -d "$HOME"; then
      if [ "$LANG" = "ru_RU.UTF-8" ]; then
        HOME_CAPTION="Внимание"
        HOME_MESSAGE="Нет домашнего каталога ${HOME}."
      else
        HOME_CAPTION="Attention"
        HOME_MESSAGE="No home directory ${HOME}."
      fi
      fly-dialog --caption "$HOME_CAPTION" --error "$HOME_MESSAGE"
fi

#if dbus-user-session package is here then only one session allowed (DEVOS-1682)
if [ -f /usr/lib/systemd/user/dbus.service ]; then
  NUM_SESS=`loginctl show-user $USER |grep Sessions= | cut -f2 -d'=' | wc -w`
  if [ "$NUM_SESS" -gt "1" ]; then
    if [ "$LANG" = "ru_RU.UTF-8" ]; then
      SESS_CAPTION="Внимание"
      SESS_MESSAGE="У вас уже есть открытая графическая сессия. Повторный вход запрещен."
    else
      SESS_CAPTION="Attention"
      SESS_MESSAGE="You has other open GUI session. This one is not allowed."
    fi
    fly-dialog --caption "$SESS_CAPTION" --error "$SESS_MESSAGE"
    exit
  fi
fi

#DEVOS-1793 - done in X server
#fly-wmfunc FLYWM_IS_NESTED_SESSION
#if [ "$?" = 0 ]; then
#xrandr --output default --preferred
#fi
