#!/bin/sh
# This script imitates Exec acions of `/etc/xdg/autostart`
set -x #echo on

if [ "$1" = "start" ] ; then

    ### Debian 9 does not need these any more
    ### Comment out begin
    # Name=AT-SPI D-Bus Bus
    #/usr/lib/at-spi2-core/at-spi-bus-launcher --launch-immediately &

	# We use polkit
    #/usr/lib/polkit-gnome-authentication-agent-1 &

	# First part of gnome-keyring-daemon is started through pam.d, this is second part
	#export $(/usr/bin/gnome-keyring-daemon --start --components=pkcs11,secrets,ssh,gpg)
	#export $(/usr/bin/gnome-keyring-daemon --start --components=pkcs11,secrets,ssh)

    # Trash in Thunar
    #/usr/lib/gvfs/gvfsd-trash &
    ### Coment out end

	# configure screen resolutions and 2 screen if present
	# work, profile will not be executed and fail if 2. screen is not connected.
	xrandr --output LVDS1  --mode 1600x900  --rotate normal --output DP3 --mode 1920x1080 --rotate normal --left-of LVDS1
	 
	# home, profile will not be executed and fail if 2. screen is not connected.
	# xrandr --output HDMI3 --mode 1920x1080 --rotate normal --output LVDS1 --off
	xrandr --output LVDS1  --mode 1600x900  --rotate normal --output HDMI3 --mode 1920x1080  --rotate normal --right-of LVDS1

	# I have a special configuration of pulseaudio and have to 
	# start it here this way. 
	# Most users can comment out the next line:
	pulseaudio -D 

	# start HP lib deamon
	hp-systray -x&

	# load desktop background
	nitrogen --restore

	# don't start notification deamon dbus will do
	# dunst -lto 1 -nto 2 -cto 10 -key o&

	# start blueman applet
	blueman-applet&

	# lightweight ALSA volume icon for the systray
	volumeicon&

	# start XFCE power manager
	xfce4-power-manager

	### start network mananger
	nm-applet&

	# deja-dup deamon
	/usr/lib/deja-dup/deja-dup-monitor &

	# start xpad
	xpad --show &

	# Screen saver and locker
	#xscreensaver -no-splash
	xautolock -time 15 -locker "i3lock" 
	xset dpms 600

	# disable beebs
	xset -b 

	# use left win key as compose key
	setxkbmap -option compose:lwin
	
	### Computer hardware specific
	# change 2 keys next to cursor key
	xmodmap -e "keycode 167 = Next NoSymbol Next"
	xmodmap -e "keycode 166 = Prior NoSymbol Prior"



elif [ "$1" = "stop" ] ; then
	killall xpad
	killall /usr/lib/deja-dup/deja-dup-monitor
	killall xfce4-power-manager
	killall volumeicon
	killall nm-applet
	pkill --signal 9 'blueman-applet'
	pkill  'hp-systray'
	killall pulseaudio 
    ### The following are not needed any more with Debian 9
    #killall /usr/lib/polkit-gnome-authentication-agent-1
	#killall dunst
    #pkill  gvfsd-trash
    #killall /usr/bin/gnome-keyring-daemon
    #killall /usr/lib/gvfs/gvfsd-trash
    #killall /usr/lib/at-spi2-core/at-spi2-registryd
fi

