chiark / gitweb /
fix respawn error handling
[chiark-tcl-applet.git] / applet.tcl
index 5d9a65dc1c4fe487b8191837889d063414456028..133eb13d4ab3d0731f4dd0a155f2085068d21968 100644 (file)
@@ -56,25 +56,28 @@ package require tktray
 #
 # Alternatively of icon, it may provide other arrangements for
 # using the provided subwindow.  Such a caller should call
 #
 # Alternatively of icon, it may provide other arrangements for
 # using the provided subwindow.  Such a caller should call
-#      applet::setup-subwindow \
-#                WIDTH HEIGHT DEFAULT-ORIENTATION BORDER-COLOUR BORDER-WIDTH \
-#                ON-DESTROYING ON-READY
+#      applet::setup-subwindow ON-DESTROYING ON-READY
 #  Then the main code will call ON-DESTROYING just before
 #  destroying the inner window and recreating it, and
 #  [concat ON-READY [list ORIENTATION]]
 #  just after.  The inner window to use is called .i.i.b.
 #
 #  Then the main code will call ON-DESTROYING just before
 #  destroying the inner window and recreating it, and
 #  [concat ON-READY [list ORIENTATION]]
 #  just after.  The inner window to use is called .i.i.b.
 #
+#  This uses variables, in the applet namespace,
+#      w h border_colour border_width deforient
+#  These should be set before setup-subwindow is called and not
+#  modified thereafter.
+#
 #  The user of the subwindow machinery may call
 #      applet::subwindow-need-recreate
 #  if for any reason the inner window should be destroyed and recreated.
 #
 # Alternatively, it may request that a subprocess be spawned
 # repeatedly with the xid of a suitable window.
 #  The user of the subwindow machinery may call
 #      applet::subwindow-need-recreate
 #  if for any reason the inner window should be destroyed and recreated.
 #
 # Alternatively, it may request that a subprocess be spawned
 # repeatedly with the xid of a suitable window.
-#      applet::setup-subproc \
-#                WIDTH HEIGHT DEFAULT-ORIENTATION BORDER-COLOUR BORDER-WIDTH \
-#                GET-CMDLINE
+#      applet::setup-subproc GET-CMDLINE
 #  Then the main code will call [concat GET_CMDLINE [list XID ORIENTATION]]
 #  to get the command line to run.
 #  Then the main code will call [concat GET_CMDLINE [list XID ORIENTATION]]
 #  to get the command line to run.
+#
+#  This also uses the same variables as setup-subwindow.
 
 wm withdraw .
 
 
 wm withdraw .
 
@@ -212,6 +215,12 @@ proc setimage {image} {
 variable subwindow_on_destroying
 variable subwindow_on_ready
 
 variable subwindow_on_destroying
 variable subwindow_on_ready
 
+variable w 50
+variable h 50
+variable deforient horizontal
+variable border_colour darkblue
+variable border_width 1
+
 proc subwindow-need-recreate {} {
     variable innerwindow_after
     debug "IW-EVENT"
 proc subwindow-need-recreate {} {
     variable innerwindow_after
     debug "IW-EVENT"
@@ -223,9 +232,9 @@ proc innerwindow-resetup {} {
     variable innerwindow_after
     variable subwindow_on_destroying
     variable subwindow_on_ready
     variable innerwindow_after
     variable subwindow_on_destroying
     variable subwindow_on_ready
-    variable subwindow_border_colour
-    variable subwindow_border_width
-    variable subwindow_default_orientation
+    variable border_colour
+    variable border_width
+    variable deforient
     unset innerwindow_after
 
     debug RESETUP
     unset innerwindow_after
 
     debug RESETUP
@@ -239,22 +248,21 @@ proc innerwindow-resetup {} {
     set orientation [.i orientation]
     debug "orientation $orientation"
     if {![string compare $orientation unknown]} {
     set orientation [.i orientation]
     debug "orientation $orientation"
     if {![string compare $orientation unknown]} {
-       set orientation $subwindow_default_orientation
+       set orientation $deforient
     }
     .i configure -image applet::innerwindow-ph-$orientation
 
     }
     .i configure -image applet::innerwindow-ph-$orientation
 
-    frame .i.i.b -background darkblue -bd 1
+    frame .i.i.b -background $border_colour -bd $border_width
     pack .i.i.b -fill both -side left -expand 1
 
     uplevel #0 $subwindow_on_ready [list $orientation]
 }
 
     pack .i.i.b -fill both -side left -expand 1
 
     uplevel #0 $subwindow_on_ready [list $orientation]
 }
 
-proc setup-subwindow {
-    w h default_orientation border_colour border_width on_destroying on_ready
-} {
-    foreach v {
-       default_orientation border_width border_colour on_destroying on_ready
-    } {
+proc setup-subwindow {on_destroying on_ready} {
+    variable w
+    variable h
+
+    foreach v {on_destroying on_ready} {
        variable subwindow_$v [set $v]
     }
 
        variable subwindow_$v [set $v]
     }
 
@@ -274,10 +282,9 @@ proc setup-subwindow {
 variable subproc none
 variable ratelimit {}
 
 variable subproc none
 variable ratelimit {}
 
-proc setup-subproc {w h deforient border_colour border_width get_cmdline} {
+proc setup-subproc {get_cmdline} {
     variable subproc_get_cmdline $get_cmdline
     variable subproc_get_cmdline $get_cmdline
-    setup-subwindow $w $h $deforient $border_colour $border_width \
-       applet::subproc-destroying applet::subproc-ready
+    setup-subwindow applet::subproc-destroying applet::subproc-ready
 }
 
 proc subproc-destroying {} {
 }
 
 proc subproc-destroying {} {
@@ -331,7 +338,7 @@ proc run-child {} {
        set ratelimit [lrange $ratelimit 1 end]
     }
     if {[llength $ratelimit] > 10} {
        set ratelimit [lrange $ratelimit 1 end]
     }
     if {[llength $ratelimit] > 10} {
-       debug stderr "crashing repeatedly, quitting $ratelimit"
+       puts stderr "crashing repeatedly, quitting $ratelimit"
        exit 127
     }
 
        exit 127
     }