#!/bin/sh
# Xgl Setting Script
# written by Momonga Project

export LANG="ja_JP.EUC-JP"

if [ -z "$DISPLAY" ]; then
        echo 'this command need X'
        echo 'run X or use "gnome-xgl-switch"'
        exit 1
fi

case `id -u` in
0)
        ;;
*)
        zenity  --title="momonga-xgl-setting" --info --text="root桼Ǽ¹ԤƤ"
        exit 1
        ;;
esac

if [ ! -f /etc/sysconfig/compiz/aiglx ]; then
	mkdir -p /etc/sysconfig/compiz/
	echo "disable" > /etc/sysconfig/compiz/aiglx
fi

if [ "`cat /etc/sysconfig/xgl/status`" = "enable"  ]; then
	XGL_STATUS="ͭ"
else
	XGL_STATUS="̵"
fi

if [ "`cat /etc/sysconfig/compiz/aiglx`" = "enable"  ]; then
	AIGLX_STATUS="ͭ"
else
	AIGLX_STATUS="̵"
fi

CMD=`zenity  --title="momonga-xgl-setting"  --text="򤷤Ƥ\nߤΥơ : Xgl $XGL_STATUS : AIGLX $AIGLX_STATUS \n\n ưκݤ gset-compiz ץ饰ͭˤƤ" --width=320 --height=320 --column="Check" --column="option" --column="Mode" --list --radiolist --hide-column=2 << EOF
""
--enable-xgl --auto
Enable Xgl-Compiz  (auto)
""
--enable-xgl --set
Enable Xgl-Compiz  (add option)
""
--enable-aiglx
Enable AIGLX-Compiz
""
--disable-aiglx
Disable Xgl-Compiz / AIGLX-Compiz
EOF`

if [ "$?" = "1" ]; then
        exit 0
fi

if [ "X_$CMD" = "X_" ]; then
        zenity  --title="momonga-xgl-setting" --error --text="ץ󤬻ꤵƤޤ"
        exit 1
fi

if [ "X_$CMD" = "X_--enable-xgl --set" ]; then
        OPT=`zenity  --title="momonga-xgl-setting" --entry --text="XglΥץϤƤ"`
        if [ "X_$OPT" = "X_" ]; then
                zenity  --title="momonga-xgl-setting" --error --text="ץ󤬻ꤵƤޤ"
                exit 1
        fi
fi

zenity  --title="momonga-xgl-setting" --question --text="XФƵưޤǤ"

if [ "$?" = "1" ]; then
        exit 0
fi

case $CMD in

--enable-aiglx)
        CMD="--disable-xgl"
        echo "enable" > /etc/sysconfig/compiz/aiglx
        ;;

--disable-aiglx)
        CMD="--disable-xgl"
        echo "disable" > /etc/sysconfig/compiz/aiglx
        ;;

*)
        if [ "X_`cat /etc/sysconfig/compiz/aiglx`" == "X_enable" ] ; then
                echo "disable" > /etc/sysconfig/compiz/aiglx
        fi

        ;;
esac

echo yes | gnome-xgl-switch $CMD "$OPT"

