window 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/rc
  2. fn checkwsys{
  3. if(~ $wsys ''){
  4. echo 'window: $wsys not defined'
  5. exit bad
  6. }
  7. }
  8. # original version used mount to do the work
  9. fn oldway{
  10. switch($#*){
  11. case 0 1
  12. echo usage: window '''minx miny maxx maxy''' cmd args ...
  13. exit usage
  14. }
  15. checkwsys
  16. dir = /mnt/wsys
  17. srv = $wsys
  18. rfork ne
  19. {
  20. if(x=`{cat /dev/ppid}; mount $srv $dir N`{{echo $x $1 }| sed 's/^ //g;s/ +/,/g'}){
  21. shift
  22. bind -b $dir /dev
  23. echo -n `{basename $1} > /dev/label >[2] /dev/null
  24. exec $* < /dev/cons > /dev/cons >[2] /dev/cons
  25. }
  26. }&
  27. }
  28. # if argument is of form '100 100 200 200' or '100,100,200,200' use old way
  29. if(~ $1 *[0-9][' ,'][0-9]*){
  30. oldway $*
  31. exit
  32. }
  33. # geometry parameters are:
  34. # -r 0 0 100 100
  35. # -dx n
  36. # -dy n
  37. # -minx n
  38. # -miny n
  39. # -maxx n
  40. # -maxy n
  41. # where n can be a number, to set the value, or +number or -number to change it
  42. # find wctl file
  43. fn getwctl{
  44. if(~ $wctl ''){
  45. if(test -f /dev/wctl) echo /dev/wctl
  46. if not if(test -f /mnt/term/dev/wctl) echo /mnt/term/dev/wctl
  47. if not if(~ $service cpu) echo /mnt/term/srv/riowctl.*.*
  48. if not {
  49. echo window: '$wctl' not defined >[1=2]
  50. exit usage
  51. }
  52. }
  53. if not echo $wctl
  54. }
  55. # use mount to make local window
  56. if(~ $1 -m){
  57. shift
  58. checkwsys
  59. dir = /mnt/wsys
  60. srv = $wsys
  61. rfork ne
  62. {
  63. unmount /mnt/acme /dev >[2]/dev/null
  64. if(mount $srv $dir 'new -pid '^`{cat /dev/ppid}^' '$"*){
  65. bind -b $dir /dev
  66. # toss geometry parameters to find command
  67. while(~ $1 -*)
  68. switch($1){
  69. case -dx -dy -minx -miny -maxx -maxy
  70. shift 2
  71. case -r
  72. shift 5
  73. case -scroll
  74. shift
  75. case -noscroll
  76. shift
  77. case -hide
  78. shift
  79. }
  80. if(~ $#* 0) cmd = rc
  81. if not cmd = $*
  82. echo -n `{basename $cmd(1)} > /dev/label >[2] /dev/null
  83. exec $cmd < /dev/cons > /dev/cons >[2] /dev/cons
  84. }
  85. }&
  86. }
  87. if not echo new -cd `{pwd} $* >> `{getwctl}