X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=example;h=7cf6b15111ecee755463996772bece81ca484260;hb=9ab567c4ba2e3627372f9b39733297ac3df93fb4;hp=b719c50409dae9a48ce7b4e60c42ab5da791c125;hpb=13fd7884410510c20f77bdd1204d60a419eb7ac4;p=chiark-tcl-applet.git diff --git a/example b/example index b719c50..7cf6b15 100755 --- a/example +++ b/example @@ -1,17 +1,33 @@ -#!/usr/bin/wish8.4 -f +#!/usr/bin/wish -f # -*- Tcl -*- -source applet.tcl -source subproc.tcl +# Copyright 2016,2020 Ian Jackson +# SPDX-License-Identifier: GPL-3.0-or-later +# There is NO WARRANTY. -#----- menu ----- +# usage: +# .../example program arguments... +# will run +# program arguments... WINDOWID +# and program sbould put up an X11 window as a child of WINDOWID +# +# eg, for a silly example: +# .../example xterm -id + +set lib . + +source $lib/applet.tcl +source $lib/subproc.tcl +source $lib/utils.tcl + +set debug::debug puts foreach b {1 3} { applet::setup-button-menu $b } -.m1 add command -command { msel; puts hi } -label hi -.m3 add command -command { msel; puts boo } -label boo +.m1 add command -command { applet::msel; puts hi } -label hi +.m3 add command -command { applet::msel; puts boo } -label boo #image create bitmap ims -file gs_s.xbm #image create bitmap ims -file /usr/share/ghostscript/8.71/lib/gs_s.xbm @@ -21,73 +37,9 @@ foreach b {1 3} { applet::setup-tooltip { puts VIS } { puts INVIS } applet::tooltip-set "line\nanother" -fconfigure stdout -buffering line - -set status none - -proc innerwindow-destroying {} { - global status - puts "DESTROYING $status" - switch -exact $status { - none { } - old { } - default { kill $status; set status old } - } -} - -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 "READY-done $status" -} - -set ratelimit 0 - -proc run-child {} { - global status ratelimit - - 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 - } - - set status none - set status [subproc::fork 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" - } - } +proc cmdline {id orientation} { + global argv + return [concat $argv $id] } -setupinnerwindow 40 +applet::setup-subproc cmdline