#!/bin/sh
#
#  xfce4
#
#  Copyright (C) 1999, 2003 Olivier Fourdan (fourdan@xfce.org)
#  Copyright (C) 2011       Guido Berhoerster (guido+xfce.org@berhoerster.name)
#  Copyright (C) 2014       Jarno Suni (8@iki.fi)
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
set -o nounset
set -o errexit
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
export PATH

# Lock by xscreensaver, gnome-screensaver, light-locker
# or xautolock if a respective daemon is running.
if pidof "`command -v xscreensaver`" >/dev/null; then
    xscreensaver-command -lock >/dev/null
elif pidof "`command -v gnome-screensaver`" >/dev/null; then
    gnome-screensaver-command --lock >/dev/null
elif pidof "`command -v light-locker`" >/dev/null; then
    light-locker-command --lock >/dev/null
elif pidof "`command -v mate-screensaver`" >/dev/null; then
    mate-screensaver-command --lock >/dev/null
elif pidof "`command -v cinnamon-screensaver`" >/dev/null; then
    cinnamon-screensaver-command --lock >/dev/null 
elif pidof "`command -v xautolock`" >/dev/null; then
    xautolock -locknow
# Note: xautolock does not tell, if it succeeded in locking,
# so be sure to start the daemon properly.
# Or use another available utility to lock.
elif command -v i3lock >/dev/null; then
	i3lock --dpms
else
 for lock_cmd in \
	"xlock -mode blank" \
	"slock" \
	"slimlock"
 do  
  if command -v $lock_cmd >/dev/null; then
	 # run the command in background
     $lock_cmd >/dev/null 2>&1 &
     # turn off display backlight:
	 xset dpms force off 
     exit
  fi
 done
 # access locking failed
 exit 1
fi

