#! /usr/bin/env wish
# $Id: swsusp-tkabber.tcl 114 2008-07-29 13:49:39Z kostix $
# This is the "activator" script for the Tkabber "green" plugin
# intended to work on X Window-based systems (namely, Linux).
# It finds all the running instance of Tkabber on the current
# display and directs the "green" plugin loaded in each of them
# (if any) to perform the actions corresponding to a power
# management event which is passed as the sole command-line
# argument to this script ("suspend" or "resume").
# Written by Konstantin Khomoutov <flatworm@users.sourceforge.net>
# See README for usage guidelines.
# See license.terms for details on distribution.

wm withdraw .

if {$argc != 1} {
	puts stderr [::msgcat::mc "Usage: %s {suspend|resume}" [file tail $argv0]]
	exit 1
}

set event [lindex $argv 0]
switch -- $event {
	suspend - resume {}
	default {
		puts stderr [::msgcat::mc "Wrong parameter value \"%s\":\
			must be suspend or resume" $event]
		exit 2
	}
}

proc bgerror message {
	puts stderr $message
	exit 3
}

foreach app [lsearch -all -inline [winfo interps] tkabber*] {
	eval [list send -async $app ::plugins::green::on_$event]
}

exit

