[Portland] xdg-screensaver.in
Bryce Harrington
bryce at osdl.org
Tue May 9 15:02:23 PDT 2006
I know Waldo asked this question before[1] a couple months ago, but it
didn't get answered before, and I'm hoping maybe someone knows better
now...
Does anyone know if there's a way to determine if the screensaver is
currently on or off? E.g., query the status of xset s on/off.
I'm working on writing a unit test for the xdg-screensaver.in script,
and need a method for determining if its functions are operating
correctly. Pretty much, this just means detecting if the screensaver is
on or off. I've googled and manned around but can't find a tool which
would provide this info. Anyone know of any other places I could check?
Looking at the xset source code[2], it looks like we need an X routine
like XActivateScreenSaver()[3] but that returns the current saver state
instead of setting it. Does XGetScreenSaver return this info in one of
its args?
Any other ideas? I'd hate to leave xdg-screensaver testless...
1: http://lists.osdl.org/pipermail/desktop_architects/2006-February/000800.html
2: http://webcvs.freedesktop.org/xorg/xc/programs/xset/xset.c?rev=1.9&view=markup
3: http://tronche.com/gui/x/xlib/window-and-session-manager/screen-saver.html
4: http://www.die.net/doc/linux/man/man3/xactivatescreensaver.3.html
Thanks,
Bryce
On Mon, May 08, 2006 at 07:47:21PM -0700, Bryce Harrington wrote:
> First cut at the screensaver script. I sorted out a simple way to do
> the screensaver suspend, but there might be a better way (open to
> suggestions.) I also implemented the other obvious functionality -
> plain disable/enable, and immediate on/off.
>
> I also wasn't sure how to do the screensaver ops for gnome - perhaps the
> xset approach is sufficient?
>
> Bryce
>
>
>
> #!/bin/sh
> #---------------------------------------------
> # xdg-screensaver
> #
> # Utility script to enable/disable screensaver.
> #
> # Refer to the usage() function below for usage.
> #
> # Copyright 2006, Bryce Harrington <bryce at osdl.org>
> #
> # LICENSE:
> #
> #---------------------------------------------
>
> # Default value for delay when suspending screensaver
> DELAY=60m
>
> examples()
> {
> cat << _EXAMPLES
> _EXAMPLES
> }
>
> usage()
> {
> cat << _USAGE
> _USAGE
> }
>
> #@xdg-utils-common@
>
> screensaver_xset()
> {
> TIMEOUT=`xset q | /bin/grep -A 2 ^Screen | /bin/grep timeout | awk '{print $2}'`
> DPMS=`xset q | /bin/grep 'DPMS is' | awk '{print $3}'`
>
> if [ "$DPMS" = "Enabled" ]; then
> DPMS="+dpms"
> else
> DPMS="-dpms"
> fi
>
> case "$1" in
> suspend)
> delay=${2:-$DELAY}
> xset s off -dpms && sleep $delay && xset s default &
> ;;
>
> restore)
> # Restores screensaver to its default settings
> xset s default "$DPMS"
> ;;
>
> enable)
> # Allows the screensaver to start automatically
> xset s on "$DPMS"
> ;;
>
> disable)
> # Prevents screensaver from starting automatically
> xset s off -dpms
> ;;
>
> activate)
> # Turns the screensaver on right now
> xset s activate
> ;;
>
> reset)
> # Turns the screensaver off right now
> xset s reset
> ;;
>
> status)
> if [ $timeout -eq 0 ]; then
> echo "disabled"
> else
> echo "enabled"
> fi
> ;;
> esac
>
> if [ $? -eq 0 ]; then
> exit_success
> else
> exit_failure_operation_failed
> fi
> }
>
> screensaver_kde()
> {
> case "$1" in
> suspend)
> delay=${2:-$DELAY}
> dcop kdesktop KScreensaverIface enable false > /dev/null && \
> sleep $delay && \
> dcop kdesktop KScreensaverIface configure > /dev/null &
> ;;
>
> restore)
> dcop kdesktop KScreensaverIface configure
> ;;
>
> enable)
> dcop kdesktop KScreensaverIface enable false > /dev/null
> ;;
>
> disable)
> dcop kdesktop KScreensaverIface enable true > /dev/null
> ;;
>
> activate)
> # Turns the screensaver on right now
> dcop kdesktop KScreensaverIface save
> ;;
>
> reset)
> # Turns the screensaver off right now
> dcop kdesktop KScreensaverIface quit
> ;;
>
> status)
> status=`dcop kdesktop KScreensaverIface isEnabled`
> if [ status = 'true' ]; then
> echo "enabled"
> elif [ status = 'false' ]; then
> echo "disabled"
> else
> echo "ERROR: kdesktop KScreensaverIface isEnabled returned '$status'"
> exit_failure_operation_failed
> fi
> ;;
>
> *)
> echo "ERROR: Unknown command '$1"
> exit_failure_operation_failed
> ;;
> esac
>
> if [ $? -eq 0 ]; then
> exit_success
> else
> exit_failure_operation_failed
> fi
> }
>
> screensaver_gnome()
> {
> # TODO
>
> if [ $? -eq 0 ]; then
> exit_success
> else
> exit_failure_operation_failed
> fi
> }
>
> [ x"$1" != x"" ] || exit_failure_arg_count
>
>
> # Always set the Xorg screensaver first
> screensaver_xset "$1" "$2"
>
> # Just in case, also do the desktop environment's screensaver
> case "$DE" in
> kde)
> screensaver_kde "$1" "$2"
> ;;
>
> gnome)
> screensaver_gnome "$1" "$2"
> ;;
>
> esac
> _______________________________________________
> Portland mailing list
> Portland at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/portland
More information about the Portland
mailing list