File pm-utils-splashy.sh of Package splashy

#!/bin/bash
#
# Copyright (C) 2007 SUSE Linux Products GmbH
#
# Author: Holger Macht <hmacht@suse.de>
#
# This file is released under the GPLv2.
#

WTTYHX=/usr/lib/powersave/wttyhx
IMG=splashy_suspend_screenshot

get_x_user(){
    [ -n "$X_USER" -a -n "$DISP" ] && return 0
    local DUMMY
    read DUMMY X_USER DISP DUMMY < <($WTTYHX -v)
    return 0
}

create_snapshot() {
    get_x_user
    if [ -z "$X_USER" -o -z "$DISP" ]; then
	echo "Could not get X_USER"
	exit 1
    fi

    if [ ! -x "`which convert`" ]; then
	echo "convert from ImageMagick package not found"
	exit 1
    fi

    su - $X_USER -c "DISPLAY=$DISP xwd -root -silent > /tmp/$IMG"
    convert /tmp/$IMG -blur 20 -separate /tmp/${IMG}.png

    cp /etc/splashy/themes/default/suspend.png /etc/splashy/themes/default/suspend.png.bak
    cp /tmp/${IMG}-0.png /etc/splashy/themes/default/suspend.png
}

restore_snapshot() {
    [ -e "/etc/splashy/themes/default/suspend.png.bak" ] || exit 0
    mv /etc/splashy/themes/default/suspend.png.bak /etc/splashy/themes/default/suspend.png
    rm /etc/splashy/themes/default/suspend.png.bak
    rm /tmp/${IMG}*.png
}

case "$1" in
    hibernate)
	RES=`grep '^ *splash *= *n' /etc/suspend.conf`
	[ -z "$RES" ] && create_snapshot
	;;
    thaw)
	RES=`grep '^ *splash *= *n' /etc/suspend.conf`
	[ -z "$RES" ] && restore_snapshot
	;;

    *) ;;
esac
openSUSE Build Service is sponsored by