[Tkabber-dev] r96 - trunk/plugins/green

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Feb 12 04:59:16 MSK 2008

Author: kostix
Date: 2008-02-12 04:59:16 +0300 (Tue, 12 Feb 2008)
New Revision: 96

green/green.tcl: Reworked to that winpm-related stuff is only touched
 when running on Windows. This allows the plugin to work on any system.

green/tkabber-swsusp.tcl: Implemented the "actuator script" to be used
 on non-Windows systems to deliver power managements to the running
 instances of Tkabber on X Window-based systems.

green/README: Added extensive documentation.

Added: trunk/plugins/green/README
--- trunk/plugins/green/README	                        (rev 0)
+++ trunk/plugins/green/README	2008-02-12 01:59:16 UTC (rev 96)
@@ -0,0 +1,159 @@
+"Green" -- plugin for Tkabber.
+I. The Idea
+This plugin introduces special processing of the system's "power
+management events" in Tkabber: disconnecting all active
+connections to the server when the system is suspending and
+(optional) restoring of these connections after the system
+resumes its normal operation.
+This plugin is primarily targeted to the users of laptops who
+want to gracefully handle periods of hibernation.
+II. Usage
+The usage of this plugin heavily depends on the power management
+facilities the underlying OS provides. Currently this plugin
+supports Windows 2000 and above through the usage of external
+Tcl/Tk extension and X Window-based systems (namely, Linux)
+through the usage of special "actuator script".
+In any case, this plugin should be installed as any other
+Tkabber plugin first.
+When the system reports it's about to suspend, Tkabber remembers
+the current connections then tears them down.
+When the system reports it resumed its normal operation, Tkabber
+consults the options(resume_sessions) flag (see below) -- if
+it's on, Tkabber waits for options(resume_delay) seconds to
+allow the network to come up, then attempts to restore the
+remembered connections.
+Tkabber waits this timeout in a non-blocking manner, so you can
+manually re-establish the connections you need -- Tkabber won't
+try to re-establish them again. On the other hand, there's
+currently no way to abort scheduled reconnection attempt.
+See the "Configuration" section below for additional details.
+II.1. Usage in Windows
+You have to install the "winpm" Tcl/Tk extension [1] for this
+plugin to be able to track Windows power management broadcasts.
+Winpm should be installed in one of the standard places Tcl
+searches for packages. With a standard installation of
+ActiveTcl [2] this is usually the "C:\Tcl\lib" directory.
+You can get the idea of where Tcl looks for its packages by
+issuing the
+set auto_path
+command in the Tkabber's console (main menu, "Help" -> "Show
+II.2. Usage in X Window System
+Since X Window doesn have any notion of power broadcasts, each
+X-based system uses its own way of delivering the information
+about power state changes to the running applications. Usually
+this is done via some specific shell scripts.
+To handle this kind of setup this plugin provides one special
+"actuator script" which uses the ability of Tcl/Tk programs
+running on the same X display to communicate by sending Tcl
+scripts to each other.
+This script is called "tkabber-swsusp.tcl" and is placed in
+the plugin directory. It's not required by the plugin itself and
+can be freely relocated, if needed.
+The actuator script accepts one mandatory command-line parameter
+which specifies the power management event to report; its
+acceptable values are "suspend" or "resume", which are
+self-explanatory.  It is up to the user to arrange for this
+script to be run in the right time with a suitable command-line
+You have to observe several factors when setting this up:
+* This script is written in Tcl and requires presence of
+  both Tcl and Tk in the system (Tk-based tclkit will also
+  work, just run it directly with this script, like
+  "tclkit /path/to/tkabber-swsusp.tcl").
+* For Tk to initialize and be able to find Tcl interpreters
+  controlling the running instances of Tkabber, this script has
+  to be run on the same X display to which Tkabber instances
+  of interest are connected. This means that if the script
+  is started by some kind of a daemon (which will probably be
+  the case) you have to let the script know which display to
+  connect to by exporting the properly set DISPLAY environment
+  variable. For example, provided you have just one display on
+  the localhost (the usual case), you can run:
+  export DISPLAY
+  /path/to/tkabber-swsusp.tcl
+  or even (in bash):
+  DISPLAY=:0 /path/to/tkabber-swsusp.tcl
+* Since a Tk application can connect to just one display at a
+  time, if you have several displays with running instances of
+  Tkabber you will need to arrange for the actuator script to
+  run several times -- one per display -- each time with
+  appropriate environment settings (see above).
+III. Configuration
+This plugin can be configured via the Customize interface of
+Tkabber -- open its window via the "Tkabber" -> "Customize"
+main menu entry, then navigate to the "Plugins" -> "Green"
+group of settings.
+Currently there are two options to tweak:
+* options(resume_sessions) -- when set, on system resume Tkabber
+  will attempt to restore the connections it teared down when
+  the system was suspending.  It is on by default.
+* options(resume_delay) -- specifies the number of seconds to
+  wait before attempting to re-establish the connectons when
+  resuming. This is intended to allow the network to come up.
+NOTE that due to currently present limitations of Tkabber, if
+you're using multi-login, you must provide "loginconf" array for
+each connection you're using, complete enough so that this
+plugin is able to connect without user intervention. This means
+providing at least the user, server and password fields.
+See [3] and [4] for details on specifying those loginconf
+arrays.  Their numbering doesn't matter for this plugin -- it
+picks the correct one based on the user/server couple.
+IV. Limitations
+* Support for restoring multiple connections is clunky.
+* There's no way to cancel the scheduled reconnection attempt.
+* Reconnection attempt isn't cancelled when processing suspend
+  event. This may provoke strange behaviour.
+V. Links
+1. http://tkwinpm.googlecode.com
+2. http://www.activestate.com
+3. http://tkabber.jabber.ru/files/doc/tkabber.html#s.postload-login
+4. http://tkabber.jabber.ru/node/192
+# vim:tw=64:noet

Property changes on: trunk/plugins/green/README
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/plugins/green/green.tcl
--- trunk/plugins/green/green.tcl	2008-02-11 18:10:24 UTC (rev 95)
+++ trunk/plugins/green/green.tcl	2008-02-12 01:59:16 UTC (rev 96)
@@ -1,27 +1,32 @@
 # $Id$
 # "Green" -- Tkabber plugin which allows Tkabber to properly
-# handle changes in the Windows power state (disconnection on
+# handle changes in the system power state (disconnection on
 # suspend and (possibly) re-connection on resume).
-# REQUIRES tkwinpm Tcl extension: http://tkwinpm.googlecode.com
+# On Windows it requires winpm Tcl extension: http://tkwinpm.googlecode.com
 # Written by Konstantin Khomoutov <flatworm at users.sourceforge.net>
 # See README for usage guidelines.
 # See license.terms for details about distribution.
 namespace eval green {
-	if {[catch { package require winpm }]} {
-		global errorInfo
-		puts stderr "Power management support is unavailable:\
-			failed to load \"winpm\" package.\
-			The error was:\n\
-			$errorInfo"
-		return
+	if {[string equal $::tcl_platform(platform) windows]} {
+		if {[catch { package require winpm }]} {
+			global errorInfo
+			puts stderr "Power management support is unavailable:\
+				failed to load \"winpm\" package.\
+				The error was:\n\
+				$errorInfo"
+			return
+		}
+		winpm bind PBT_APMSUSPEND [namespace current]::on_suspend
+		winpm bind PBT_APMRESUMESUSPEND [namespace current]::on_resume
 	variable active [list]
 	variable options
 	custom::defgroup Green \
-		[::msgcat::mc "Power management support (for Windows)."] \
+		[::msgcat::mc "Power management support."] \
 		-group Plugins
 	custom::defvar options(resume_sessions) 1 \
@@ -37,9 +42,6 @@
 			to come up."] \
 		-type integer \
 		-group Green
-	winpm bind PBT_APMSUSPEND [namespace current]::on_suspend
-	winpm bind PBT_APMRESUMESUSPEND [namespace current]::on_resume
 proc green::on_suspend {} {

Added: trunk/plugins/green/tkabber-swsusp.tcl
--- trunk/plugins/green/tkabber-swsusp.tcl	                        (rev 0)
+++ trunk/plugins/green/tkabber-swsusp.tcl	2008-02-12 01:59:16 UTC (rev 96)
@@ -0,0 +1,41 @@
+#! /usr/bin/env wish
+# $Id$
+# This is an "actuator" 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 at 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]

Property changes on: trunk/plugins/green/tkabber-swsusp.tcl
Name: svn:executable
   + *
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

More information about the Tkabber-dev mailing list