-#!/usr/bin/wish8.4
+#!/usr/bin/wish8.4 -f
+# -*- Tcl -*-
-#----- general machinery -----
+source applet.tcl
-package require tktray
+#----- specifics -----
-wm withdraw .
+.m1 add command -command { msel; puts hi } -label hi
+.m3 add command -command { msel; puts boo } -label boo
-image create bitmap ims -file /usr/share/ghostscript/8.71/lib/gs_s.xbm
+image create bitmap ims -file gs_s.xbm
+#image create bitmap ims -file /usr/share/ghostscript/8.71/lib/gs_s.xbm
+#setimage ims
+#setimage ims
-tktray::icon .i -class example
-.i configure -docked 1
+setuptooltip
+settooltip "line\nanother"
-set posted 0
+fconfigure stdout -buffering line
-foreach b {1 3} {
- menu .m$b -tearoff 0
+set status none
+
+proc innerwindow-destroying {} {
+ global status
+ puts "DESTROYING $status"
+ switch -exact $status {
+ none { }
+ old { }
+ default { kill $status; set status old }
+ }
}
-proc pressed {b x y} {
- global posted
- if {$posted == $b} {
- puts "unpost $posted toggle"
- .m$posted unpost
- set posted 0
- } elseif {[winfo exists .m$b]} {
- if {$posted} {
- .m$posted unpost
- puts "unpost $posted other"
+proc innerwindow-ready {} {
+ global status
+ puts "READY $status"
+ switch -exact $status {
+ none {
+ run-child
+ }
+ old {
+ # wait for it to die
+ }
+ default {
+ error "unexpected state $status"
}
- puts "post $b"
- set posted $b
- .m$b post $x $y
}
+ puts "READY-done $status"
}
-proc msel {} {
- global posted
- set posted 0
-}
+set ratelimit 0
-bind .i <ButtonPress> { pressed %b %X %Y }
+proc run-child {} {
+ global status ratelimit
-#----- specifics -----
+ puts "RUN-CHILD $status"
+ set now [clock seconds]
+ lappend ratelimit $now
+ while {[lindex $ratelimit 0] < {$now - 10}} {
+ set ratelimit [lrange $ratelimit 1 end]
+ }
+ if {[llength $ratelimit] > 10} {
+ puts stderr "crashing repeatedly, quitting $ratelimit"
+ exit 127
+ }
-.i configure -image ims
-.m1 add command -command { msel; puts hi } -label hi
-.m3 add command -command { msel; puts boo } -label boo
+ set status none
+ set status [fork-then child-died {
+ execl xacpi-simple [list -into [winfo id .i.i.b.c]]
+ }]
+ puts "FORKED $status"
+}
+
+proc child-died {how how2} {
+ puts "DIED $how $how2"
+ global status
+ switch -exact $status {
+ old {
+ set status none
+ run-child
+ }
+ default {
+ set status none
+ innerwindow-resetup-required "child died"
+ }
+ }
+}
+setupinnerwindow 40