Public feed #890905

Stuff

public text v1 · immutable
Raw Edit
·published 2008-02-04 04:47 UTC
rendered paste body
#!/bin/sh
# Compiz wrapper
# 
# parts taken from 
#  git://anongit.opencompositing.org/users/3v1n0/compiz-wrapper
# thanks to Trevio (3v1n0) <trevi55@gmail.com>

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

GLXINFO='/usr/bin/glxinfo'

COMPIZ_OPTIONS="--ignore-desktop-hints --sm-disable"
COMPIZ_PLUGINS=""
ENV=""

FALLBACKWM="/usr/bin/metacity"
FALLBACKWM_OPTIONS="--replace"

# No indirect by default
INDIRECT=1

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

# abort script and run fallback windowmanager
abort_with_fallback_wm()
{
    verbose "aborting and using fallback: $FALLBACKWM"

    if [ -x $FALLBACKWM ]; then
	$FALLBACKWM $FALLBACKWM_OPTIONS
	exit 1
    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 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" -eq 0 ]; then
			unset LIBGL_ALWAYS_INDIRECT
			INDIRECT=1
			return 1;
		else
			verbose "Trying again with indirect rendering:\n";
			INDIRECT=0
			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 for existence if NV-GLX
check_nvidia()
{
	verbose "Checking for nVidia: "
	if xdpyinfo | grep -q NV-GLX ; then
		verbose "present. \n"
		return 0;
	else
		verbose "not present. \n"
		return 1;
	fi
}

running_under_bad_driver()
{
    LOG=$(xset q|grep "Log file"|awk '{print $3}')
    if egrep -q "/usr/lib/xorg/modules/drivers/+(nv|vga|vesa)_drv\.so" $LOG; then
	verbose "vesa or vga driver in use"
	return 0
    fi
    return 1
}

convert_gconf_plugin_list()
{
    if [ -x /usr/bin/gconftool-2 ]; then
	plugins=`gconftool-2 -g /apps/compiz/general/allscreens/options/active_plugins|sed -e 's/,/\ /g' -e 's/\[//' -e 's/\]//'`
	verbose "Converting gconf plugin list: '$plugins'"
	for i in $plugins; do
	    gconftool-2 -s /apps/compiz/plugins/$i/allscreens/options/____plugin_enabled true -t boolean;
	done
	gconftool-2 -s /apps/compiz/general/allscreens/options/active_plugins [] -t list --list-type string
    fi
}

build_env()
{
	if check_nvidia; then
		ENV="__GL_YIELD=NOTHING "
	fi
	if [ "$INDIRECT" -eq 0 ]; then
		ENV="$ENV LIBGL_ALWAYS_INDIRECT=1 "
	fi
	if check_xgl; then
		if [ -f /usr/lib/nvidia/libGL.so.1.2.xlibmesa ]; then
			ENV="$ENV LD_PRELOAD=/usr/lib/nvidia/libGL.so.1.2.xlibmesa"
			verbose "Enabling Xgl with nVidia drivers...\n"
		fi
		if [ -f /usr/lib/fglrx/libGL.so.1.2.xlibmesa ]; then
			ENV="$ENV LD_PRELOAD=/usr/lib/fglrx/libGL.so.1.2.xlibmesa"
			verbose "Enabling Xgl with fglrx ATi drivers...\n"
		fi
	fi
	if [ -n "$ENV" ]; then
		export $ENV
	fi
}

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

# if vesa or vga are in use, do not even try glxinfo (LP#119341)
if running_under_bad_driver; then
    abort_with_fallback_wm
fi

# check if we have the required bits to run compiz and if not, 
# fallback
if ! check_tfp || ! check_npot_texture || ! check_composite; then
    abort_with_fallback_wm
fi

# load the ccp plugin if present and fallback to plain gconf if not
if [ -f /usr/lib/compiz/libccp.so ]; then
	COMPIZ_PLUGINS="$COMPIZ_PLUGINS ccp"
        # convert gconf backend plugin list to ccp
	convert_gconf_plugin_list
elif [ -f /usr/lib/compiz/libgconf.so ]; then
	COMPIZ_PLUGINS="$COMPIZ_PLUGINS glib gconf"
fi

# get environment
build_env

# start the gtk-window-decorator if present
if [ -x /usr/bin/gtk-window-decorator ]; then
	/usr/bin/gtk-window-decorator --replace &
fi

/usr/bin/compiz.real $COMPIZ_OPTIONS "$@" $COMPIZ_PLUGINS || $FALLBACKWM $FALLBACKWM_OPTIONS