#!/bin/bash
#***********************************************************************
# xcompmgr_start simple script to start xcompmgr
# Generate under PCLinuxOS-LXDE for LXDE-Sessions
# Author: Daniel Meiß-Wilhelm (leiche) 
# Lincence: GPL
# Web site: www.pclinuxos.com/forum
# Required: yad bash xcompmgr
#*********************************************
# Code 0 no direct rendering
# Code 1 no lxde session
#*********************************************
export TEXTDOMAIN=xcompmgr_start
export TEXTDOMAINDIR="/usr/share/locale"
#
# check if will running xcompmgr
#
GLX=`glxinfo | grep 'direct rendering' `
#
# check if xcompmgr still running
#
RUN=`ps -e | grep -w xcompmgr | cut -d ":" -f3 | cut -d " " -f2`
RUN1=`ps -e | grep -w compton | cut -d ":" -f3 | cut -d " " -f2`
#
# some variables
#
TITLE=xcompmgr-start
VERSION=0.04
ICON=/usr/share/pixmaps/xcompmgr.png
CONF_DIR=~/.xcompmgr
if [ -f ~/.xcompmgr/main ];then
MAIN=`cat $CONF_DIR/main`
else
MAIN="-CcfF -I-.015 -O-.03 -D1 -t5 -l5 -r4.2 -o.5"  #settings from LKJ
fi
#
# running checks
#
if [ "$GLX" = "direct rendering: Yes" ]; then 
	echo $"xcompmgr will successfully start!" 
	else
    echo $"No direct rendering, exit script!"
    yad --window-icon=$ICON --button="gtk-ok:0" \
		--title="$TITLE"" $VERSION" --width=250 \
		--text=$"Your video card support no direct rendering, exit script..." \
		--timeout 15
    exit 0
fi 

if [ "$RUN1" = "compton" ];then
	echo $"compton is still running...\nWill now stopped!"
	yad --window-icon=$ICON \
		--title="$TITLE"" $VERSION" --width=250 \
		--text=$"compton is still running, it is in a conflict with xcompmgr!\n
		<b>It will now stopped!</b>"
		if [ "$?" = 0 ];then 
			killall compton
		else
			exit 0
		fi
fi

if [ "$RUN" = "xcompmgr" ];then
	echo $"xcompmgr is still running...!"
	yad --window-icon=$ICON \
		--title="$TITLE"" $VERSION" --width=250 \
		--text=$"xcompmgr is still running, would you stop it?"
		if [ "$?" = 0 ];then 
			killall xcompmgr
			exit 0
		fi
	exit 0
fi

if [ -f ~/.config/openbox/rc.xml ];then
SET1=`grep -i animateIconify ~/.config/openbox/rc.xml | cut -d ">" -f2 | cut -d "<" -f1`
	if [ "$SET1" = "yes" ];then
		yad --window-icon=$ICON --button="gtk-ok:0" \
		--title="$TITLE"" $VERSION" --width=250 \
		--text=$"xcompmgr wont propper working, you have enabled 
		<b>Animate iconify and restore</b>. \nThis will now <b>tick off</b>!
		To enable it, try:
		Open (obconf) <b>OpenBox Configuration Manager</b>
		<i>Appearanc</i> -> <i>Animate iconify and restore</i> <b>tick on</b>"
#		obconf
		perl -pi -e "s|<animateIconify>yes</animateIconify>|<animateIconify>no</animateIconify>|g" $HOME/.config/openbox/rc.xml
	fi
fi	
if [ -f ~/.config/openbox/lxde-rc.xml ];then
SET1=`grep -i animateIconify ~/.config/openbox/lxde-rc.xml | cut -d ">" -f2 | cut -d "<" -f1`
	if [ "$SET1" = "yes" ];then
		perl -pi -e "s|<animateIconify>yes</animateIconify>|<animateIconify>no</animateIconify>|g" ~/.config/openbox/lxde-rc.xml
	fi
fi

xcompmgr $MAIN
exit 0

