summaryrefslogtreecommitdiff
path: root/rc/bin/window
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 17:14:36 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 17:14:36 +0300
commit2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f (patch)
treef6343b1ce11a8c87251dd27cf3d3e26b50693fa7 /rc/bin/window
parente463eb40363ff4c68b1d903f4e0cdd0ac1c5977f (diff)
downloadplan9front-2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f.tar.xz
Import sources from 2011-03-30 iso image - rc
Diffstat (limited to 'rc/bin/window')
-rwxr-xr-xrc/bin/window100
1 files changed, 100 insertions, 0 deletions
diff --git a/rc/bin/window b/rc/bin/window
new file mode 100755
index 000000000..e6dce9262
--- /dev/null
+++ b/rc/bin/window
@@ -0,0 +1,100 @@
+#!/bin/rc
+# window [many options] cmd [arg...] - create new window and run cmd in it
+rfork e
+fn checkwsys{
+ if(~ $wsys ''){
+ echo 'window: $wsys not defined'
+ exit bad
+ }
+}
+
+# original version used mount to do the work
+fn oldway{
+ switch($#*){
+ case 0 1
+ echo usage: window '''minx miny maxx maxy''' cmd args ...
+ exit usage
+ }
+
+ checkwsys
+
+ dir = /mnt/wsys
+ srv = $wsys
+
+ rfork ne
+ {
+ if(x=`{cat /dev/ppid}; mount $srv $dir N`{{echo $x $1 }| sed 's/^ //g;s/ +/,/g'}){
+ shift
+ bind -b $dir /dev
+ echo -n `{basename $1} > /dev/label >[2] /dev/null
+ exec $* < /dev/cons > /dev/cons >[2] /dev/cons
+ }
+ }&
+}
+
+# if argument is of form '100 100 200 200' or '100,100,200,200' use old way
+if(~ $1 *[0-9][' ,'][0-9]*){
+ oldway $*
+ exit
+}
+
+# geometry parameters are:
+# -r 0 0 100 100
+# -dx n
+# -dy n
+# -minx n
+# -miny n
+# -maxx n
+# -maxy n
+# where n can be a number, to set the value, or +number or -number to change it
+
+# find wctl file
+fn getwctl{
+ if(~ $wctl ''){
+ if(test -f /dev/wctl) echo /dev/wctl
+ if not if(test -f /mnt/term/dev/wctl) echo /mnt/term/dev/wctl
+ if not if(~ $service cpu) echo /mnt/term/srv/riowctl.*.*
+ if not {
+ echo window: '$wctl' not defined >[1=2]
+ exit usage
+ }
+ }
+ if not echo $wctl
+}
+
+# use mount to make local window
+if(~ $1 -m){
+ shift
+
+ checkwsys
+
+ dir = /mnt/wsys
+ srv = $wsys
+ rfork ne
+ {
+ unmount /mnt/acme /dev >[2]/dev/null
+ if(mount $srv $dir 'new -pid '^`{cat /dev/ppid}^' '$"*){
+ bind -b $dir /dev
+ # toss geometry parameters to find command
+ while(~ $1 -*)
+ switch($1){
+ case -dx -dy -minx -miny -maxx -maxy
+ shift 2
+ case -r
+ shift 5
+ case -scroll
+ shift
+ case -noscroll
+ shift
+ case -hide
+ shift
+ }
+ if(~ $#* 0) cmd = rc
+ if not cmd = $*
+ echo -n `{basename $cmd(1)} > /dev/label >[2] /dev/null
+ exec $cmd < /dev/cons > /dev/cons >[2] /dev/cons
+ }
+ }&
+}
+
+if not echo new -cd `{pwd} $* >> `{getwctl}