chiark / gitweb /
applet: Introduce applet::become
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Mar 2020 15:10:17 +0000 (15:10 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Mar 2020 15:10:17 +0000 (15:10 +0000)
Rather than doing this when applet.tcl is source, which was weird and
troublesome.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
applet.tcl
example
xbatmon-simple-tray

index 871cf97f380764a13088b7495d3f4cc2bbcc98d0..5e300aba53bd032a5f16e402b2441ac9a6d83917 100644 (file)
@@ -68,16 +68,17 @@ package require tktray
 #
 #  This also uses the same variables as setup-subwindow.
 
-wm withdraw .
-
-tktray::icon .i -class example
-.i configure -docked 1
+namespace eval applet {
 
-fconfigure stdout -buffering none
-fconfigure stderr -buffering none
+proc become {} {
+    wm withdraw .
 
+    tktray::icon .i -class example
+    .i configure -docked 1
 
-namespace eval applet {
+    fconfigure stdout -buffering none
+    fconfigure stderr -buffering none
+}
 
 # used by both menus and tooltips
 variable posted 0
diff --git a/example b/example
index 7cf6b15111ecee755463996772bece81ca484260..70e74cb209be02e77d4d871684a47781df29947f 100755 (executable)
--- a/example
+++ b/example
@@ -20,6 +20,8 @@ source $lib/applet.tcl
 source $lib/subproc.tcl
 source $lib/utils.tcl
 
+applet::become
+
 set debug::debug puts
 
 foreach b {1 3} {
index 72ed960b0b4db277231791d1c83e9e1789890d5e..292f415f533e015ce29d561d7c8358a4a10cf35b 100755 (executable)
@@ -14,6 +14,7 @@ set lib .
 source $lib/subproc.tcl
 source $lib/utils.tcl
 source $lib/args.tcl
+source $lib/applet.tcl
 
 proc cmdline {id orientation} {
     global argv
@@ -201,7 +202,7 @@ proc tt-info {chan} {
 #----- modes -----
 
 proc mode/normal {} {
-    uplevel #0 { source $lib/applet.tcl }
+    uplevel #0 { applet::become }
     applet::setup-subproc cmdline
     applet::setup-tooltip tt-show tt-invisible
 }