File ecomp.sh of Package ecomorph

#!/bin/sh
# Ecomp Manager wrapper script
# 
# Copyright (c) 2007 Kristian Lyngstøl <kristian@bohemians.org>
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#
# Contributions by: Treviño (3v1n0) <trevi55@gmail.com>, Ubuntu Packages
#
# Much of this code is based on Beryl code, also licensed under the GPL.
# This script will detect what options we need to pass to ecomp to get it
# started, and start a default plugin and possibly window decorator.
# 
# modifyed by sda00 <sda00@himki.net>
#

#ECOMP_BIN_PATH="/usr/local/bin/" # For window decorators and ecomp
ECOMP_BIN_PATH="/usr/bin/"
PLUGIN_PATH="/usr/lib/ecomp/" 
GLXINFO="/usr/bin/glxinfo"
#KWIN="/usr/bin/kwin"
#METACITY="/usr/bin/metacity"
ECOMP_NAME="ecomorph" # Final name for ecomp (ecomp.real) 

# For Xgl LD_PRELOAD
#if [ "`lsmod | grep -w nvidia\  | grep -v grep`" != "" ] ; then
if [ "`/sbin/lspci | grep -i vga | grep -i nvidia\  | grep -v grep`" != "" ] ; then
#nv_driver_version="`nvidia-settings -V -q NvidiaDriverVersion  | grep  \  | awk -F: '{ print $3 }' | awk -F. '{ print $1"."$2 }'  | sed 's/^\ //g' `"
	if [ -e /usr/X11R6/lib/libGL.so ] ; then
		LIBGL_NVIDIA="/usr/X11R6/lib/libGL.so"
	else
		LIBGL_NVIDIA="/usr/lib/libGL.so"
	fi

# Minimum amount of memory (in kilo bytes) that nVidia cards need
# to be allowed to start
# Set to 262144 to require 256MB
#NVIDIA_MEMORY="65536" # 64MB
NVIDIA_MEMORY="`nvidia-settings -V -q VideoRam | grep Attribute | awk -F: '{ print $3 }' | awk -F. '{ print $1 }'  | sed 's/^\ //g' `"
NVIDIA_SETTINGS="nvidia-settings" # Assume it's in the path by default
fi

#For ATI cards:
if [ "`/sbin/lspci | grep -i vga | grep ATI `" != "" ] ; then
	if [ -e /usr/X11R6/lib/libGL.so ] ; then 
		LIBGL_FGLRX="/usr/X11R6/lib/libGL.so"
	else
		LIBGL_FGLRX="/usr/lib/libGL.so"
	fi
fi

#For Intel cards:
if [ "`/sbin/lspci | grep -i vga | grep Intel `" != "" ] ; then
export LIBGL_ALWAYS_INDIRECT=1
export INTEL_BATCH=1
LIBGL_INTEL="/usr/lib/libGL.so"
fi

# For detecting what driver is in use, the + is for one or more /'s
XORG_DRIVER_PATH="/usr/lib/xorg/modules/drivers/+"
#XORG_DRIVER_PATH="/usr/local/lib/xorg/modules/drivers/+"

#FALLBACKWM="${METACITY}"
#FALLBACKWM_OPTIONS="--replace $@"

# Driver whitelist
WHITELIST="nvidia intel ati radeon i810"

# blacklist based on the pci ids 
# See http://wiki.ecomp-fusion.org/Hardware/Blacklist for details
T="   1002:5954 1002:5854 1002:5955" # ati rs480
T="$T 1002:4153" # ATI Rv350
T="$T 8086:2982 8086:2992 8086:29a2 8086:2a02 8086:2a12"  # intel 965
T="$T 8086:2972" # i965 (x3000)
T="$T 1002:3152 1002:3150 1002:5462 1002:5653 " # ati X300 X600,X600 X700 
BLACKLIST_PCIIDS="$T"
unset T

#ECOMP_OPTIONS="--ignore-desktop-hints --replace"
ECOMP_OPTIONS=""
#ECOMP_PLUGINS="dbus"
ECOMP_PLUGINS=""
ENV=""

# Use emerald by default if it exist
USE_EMERALD="yes"

# No indirect by default
INDIRECT="no"

# Set to yes to enable verbose
VERBOSE="yes"

# Echos the arguments if verbose
verbose()
{
	if [ "x$VERBOSE" = "xyes" ]; then
		printf "$*"
	fi
}


# Check for non power of two texture support
check_npot_texture()
{
	verbose "Checking for non power of two support: "
	if glxinfo 2> /dev/null | egrep -q '(GL_ARB_texture_non_power_of_two|GL_NV_texture_rectangle|GL_EXT_texture_rectangle|GL_ARB_texture_rectangle)' ; then
		verbose "present. \n";
		return 0;
	else
		verbose "Not present. \n"
		return 1;
	fi

}

# Check for presence of FBConfig
check_fbconfig()
{
	verbose "Checking for FBConfig: "
	if [ "$INDIRECT" = "yes" ]; then
		$GLXINFO -i | grep -q GLX.*fbconfig 
		FB=$?
	else
		$GLXINFO | grep -q GLX.*fbconfig 
		FB=$?
	fi

	if [ $FB = "0" ]; then
		unset FB
		verbose "present. \n"
		return 0;
	else
		unset FB
		verbose "not present. \n"
		return 1;
	fi
}


# Check for TFP
check_tfp()
{
	verbose "Checking for texture_from_pixmap: "
	if [ $($GLXINFO 2>/dev/null | grep GLX_EXT_texture_from_pixmap -c) -gt 2 ] ; then
		verbose "present. \n"
		return 0;
	else
		verbose "not present. \n"
		if [ "$INDIRECT" = "yes" ]; then
			unset LIBGL_ALWAYS_INDIRECT
			INDIRECT="no"
			return 1;
		else
			verbose "Trying again with indirect rendering:\n";
			INDIRECT="yes"
			export LIBGL_ALWAYS_INDIRECT=1
			check_tfp;
			return $?
		fi
	fi
}

# Check wether the composite extension is present
check_composite()
{
	verbose "Checking for Composite extension: "
	if xdpyinfo -queryExtensions | grep -q Composite ; then
		verbose "present. \n";
		return 0;
	else
		verbose "not present. \n";
		return 1;
	fi
}

# Detects if Xgl is running
check_xgl()
{
	verbose "Checking for Xgl: "
	if xvinfo | grep -q Xgl ; then
		verbose "present. \n"
		return 0;
	else
		verbose "not present. \n"
		return 1;
	fi
}

# Check if the nVidia card has enough video ram to make sense
check_nvidia_memory()
{
	MEM=$(${NVIDIA_SETTINGS} -q VideoRam | egrep Attribute\ \'VideoRam\'\ .*: | cut -d: -f3 | sed 's/[^0-9]//g')
	if [ $MEM -lt $NVIDIA_MEMORY ]; then
		verbose "Less than ${NVIDIA_MEMORY}kb of memory and nVidia";
		return 1;
	fi
	return 0;
}

# Check for existence if NV-GLX
check_nvidia()
{
	if [ ! -z $NVIDIA_INTERNAL_TEST ]; then
		return $NVIDIA_INTERNAL_TEST;
	fi
	verbose "Checking for nVidia: "
	if xdpyinfo | grep -q NV-GLX ; then
		verbose "present. \n"
		NVIDIA_INTERNAL_TEST=0
		return 0;
	else
		verbose "not present. \n"
		NVIDIA_INTERNAL_TEST=1
		return 1;
	fi
}

# Check if the max texture size is large enough compared to the resolution
check_texture_size()
{
	TEXTURE_LIMIT=$(glxinfo -l | grep GL_MAX_TEXTURE_SIZE | sed 's/.*=[^0-9]//g')
	RESOLUTION=$(xdpyinfo  | grep -i dimensions: | sed 's/[^0-9]*pixels.*(.*).*//' | sed 's/[^0-9x]*//')
	VRES=$(echo $RESOLUTION | sed 's/.*x//')
	HRES=$(echo $RESOLUTION | sed 's/x.*//')
	verbose "Comparing resolution ($RESOLUTION) to maximum 3D texture size ($TEXTURE_LIMIT): ";
	if [ $VRES -gt $TEXTURE_LIMIT ] || [ $HRES -gt $TEXTURE_LIMIT ]; then
		verbose "Failed.\n"
		return 1;
	fi
	verbose "Passed.\n"
	return 0
}

# check driver whitelist
running_under_whitelisted_driver()
{
	LOG=$(xset q|grep "Log file"|awk '{print $3}')
	if [ -z "$LOG" ];then
		verbose "AIEEEEH, no Log file found \n"
		verbose "$(xset q) \n"
	return 0
	fi
	for DRV in ${WHITELIST}; do
		if egrep -q "Loading ${XORG_DRIVER_PATH}${DRV}_drv\.so" $LOG &&
		   ! egrep -q "Unloading ${XORG_DRIVER_PATH}${DRV}_drv\.so" $LOG; 
		then
			return 0
		fi
	done
	verbose "No whitelisted driver found\n"
	return 1
}

# check pciid blacklist
have_blacklisted_pciid()
{
	OUTPUT=$(/sbin/lspci -n)
	for ID in ${BLACKLIST_PCIIDS}; do
		if echo "$OUTPUT" | egrep -q "$ID"; then
			verbose "Blacklisted PCIID '$ID' found \n"
			return 0
		fi
	done
	OUTPUT=$(/sbin/lspci -vn | grep -i VGA)
	verbose "Detected PCI ID for VGA: $OUTPUT\n"
	return 1
}

build_env()
{
	if check_nvidia; then
		ENV="__GL_YIELD=NOTHING "
	fi
	if [ "$INDIRECT" = "yes" ]; then
		ENV="$ENV LIBGL_ALWAYS_INDIRECT=1 "
	fi
	if check_xgl; then
		if [ -f ${LIBGL_NVIDIA} ]; then
			ENV="$ENV LD_PRELOAD=${LIBGL_NVIDIA}"
			verbose "Enabling Xgl with nVidia drivers...\n"
		fi
		if [ -f ${LIBGL_FGLRX} ]; then
			ENV="$ENV LD_PRELOAD=${LIBGL_FGLRX}"
			verbose "Enabling Xgl with fglrx ATi drivers...\n"
		fi
        if [ -f ${LIBGL_INTEL} ]; then
            ENV="$ENV LD_PRELOAD=${LIBGL_INTEL}"
            verbose "Enabling Xgl for Intel cards...\n"
        fi
	fi

	ENV="$ENV FROM_WRAPPER=yes"

	if [ -n "$ENV" ]; then
		export $ENV
	fi
}

build_args()
{
	if [ $INDIRECT = "yes" ]; then
		ECOMP_OPTIONS="$ECOMP_OPTIONS --indirect-rendering "
	fi
	if check_nvidia; then
		ECOMP_OPTIONS="$ECOMP_OPTIONS --loose-binding"
	fi
}

####################
# Execution begins here.

# Read configuration from XDG paths
if [ -z "$XDG_CONFIG_DIRS" ]; then
	test -f /etc/xdg/ecomp/ecomp-manager && . /etc/xdg/ecomp/ecomp-manager
else
	test -f $XDG_CONFIG_DIRS/ecomp/ecomp-manager && . $XDG_CONFIG_DIRS/ecomp/ecomp-manager
fi

if [ -z "$XDG_CONFIG_HOME" ]; then
	test -f $HOME/.config/ecomp/ecomp-manager && . $HOME/.config/ecomp/ecomp-manager
else
	test -f $XDG_CONFIG_HOME/ecomp/ecomp-manager && .  $XDG_CONFIG_HOME/ecomp/ecomp-manager
fi


if [ "x$LIBGL_ALWAYS_INDIRECT" = "x1" ]; then
	INDIRECT="yes";
fi

# if we run under Xgl, we can skip some tests here
if ! check_xgl; then
	# if vesa or vga are in use, do not even try glxinfo (LP#119341)
	if ! running_under_whitelisted_driver || have_blacklisted_pciid; then
		abort_with_fallback_wm
	fi
	# check if we have the required bits to run ecomp and if not, 
	# fallback
	if ! check_tfp || ! check_npot_texture || ! check_composite || ! check_texture_size; then
		abort_with_fallback_wm
	fi

	if check_nvidia && ! check_nvidia_memory; then
		abort_with_fallback_wm
	fi

	if ! check_fbconfig; then
		abort_with_fallback_wm
	fi
fi

#ECOMP_PLUGINS="mblur decoration png text thumbnail svg shift zoom minimize regex video imgjpeg ring move fade cube rotate scale switcher scaleaddon staticswitcher cubereflex expo wobbly water animation"
##ECOMP_PLUGINS="mblur decoration png text thumbnail svg shift zoom minimize regex video imgjpeg ring move fade scale switcher scaleaddon staticswitcher expo wobbly water animation wall"
#ECOMP_PLUGINS="ini"
#ECOMP_PLUGINS="cube cubereflex"
ECOMP_PLUGINS="wall expo wobbly water decoration png text thumbnail svg shift zoom minimize regex video imgjpeg ring move fade scale switcher scaleaddon staticswitcher animation"
# get environment
build_env
build_args

#ecomorph --replace $ECOMP_OPTIONS "$@" $ECOMP_PLUGINS 
ecomorph $ECOMP_OPTIONS "$@" $ECOMP_PLUGINS
#> /dev/null

openSUSE Build Service is sponsored by