home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume2 / window / part1 / USINGWM < prev    next >
Encoding:
Text File  |  1986-11-30  |  16.9 KB  |  441 lines

  1. .TL
  2. How I use WM
  3. .AU
  4. Tom Truscott
  5. .AI
  6. Research Triangle Institute
  7. P.O. Box 12194
  8. RTP, NC  27709
  9. (919) 541-7005
  10. .SH
  11. Starting up wm
  12. .PP
  13. The last line in my .profile is
  14. .DS
  15. .ft PO
  16. exec wm
  17. .ft P
  18. .DE
  19. which puts me into the window manager,
  20. so I am always in it.
  21. When I need a real terminal
  22. (e.g. to run `talk')
  23. I can type \fI<wm-esc>\fPz.
  24. Since I go right into wm
  25. it is important
  26. that TERM be set correctly.
  27. Earlier in my .profile I have
  28. .DS
  29. .ft PO
  30. export TERM
  31. case "$TERM" in
  32. sw|su)    TERM=`whatterm`;;
  33. esac
  34. .ft P
  35. .DE
  36. So that if the TERM variable is su or sw (dataSWitch)
  37. John Menges' whatterm program is invoked to figure things out.
  38. (Whatterm depends on the
  39. response characteristics of a dozen or so terminals.
  40. A more general version, using a `responsecap' database,
  41. is planned.)
  42. Whatterm is doomed to fail on an ADM terminal
  43. (unless it has the HERE-IS option)
  44. and also fails
  45. if the user is already in wm and and logging in to another computer,
  46. because `wm' itself does not respond to any escape sequences.
  47. It probably should, so whatterm will work!
  48. Actually, nested invocations of wm, while amusing,
  49. are probably unnecessarily confusing.
  50. .SH
  51. Choosing window layout
  52. .PP
  53. That is largely a matter of individual taste.
  54. My ``#1'' window is full-screen (except for the bottom line),
  55. my #2 window is the top half of the screen and my #3
  56. window is the bottom half (with an unused line between them),
  57. and my #4 window is just like #1.
  58. I am normally (99%) in the #1 window and am generally
  59. unaware of the existence of wm.
  60. But when I want
  61. to escape from the current window I can change to window #4
  62. to get a fresh screen (one wm nuisance is
  63. that it puts me back in my home directory on my home machine).
  64. Or if I want split screens, say for debugging or file comparison,
  65. I can change to window #2 and then alternate between #2 and #3.
  66. I think of having three window layers, the #1 layer,
  67. the #2/#3 layer, and the #4 layer.
  68. (In reality, wm maintains a window display order,
  69. and changing to a window puts that window on `top',
  70. so there is not really a #2/#3 layer.)
  71. On a 66 line display I bet things would be much nicer.
  72. Some people have a window which covers all but the top line,
  73. so they can put a clock or periodic `uptime' in the top line.
  74. (Note: two windows \fImust\fP have an unused line between them
  75. or else they cannot be used for simultaneous displays.)
  76. Also, some people change the wm prefix character to `^W' or `^P'
  77. so that `vi' is easier to use.
  78. .PP
  79. The undocumented experimental \fI<wm-esc>\fPf (`fit') command is also handy.
  80. For example, suppose I am in my #1 window and type ``make''.
  81. It might take a while, so I would like to switch to another window
  82. and read news.
  83. But I would also like to see the progress of the make.
  84. So I switch to a half-screen window and type `\fI<wm-esc>\fPf 1',
  85. which relocates the #1 window so that it is no longer obscured.
  86. Now I can read news and keep up with the ``make'' at the same time.
  87. This can really jumble up the windows,
  88. but in this case I can change back to #1
  89. and do a `\fI<wm-esc>\fPf 1' to make it full-screen again.
  90. .SH
  91. Window ``Performance'' Considerations
  92. .PP
  93. There are some important performance details to consider.
  94. First, your terminal needs insert-line/delete-line
  95. or scrolling region support for wm to work well
  96. on anything but full-screen windows.
  97. In particular, my #2/#3 windows are sloowww without such support.
  98. The scrolling region is best because with insert/delete-line
  99. scrolling in the #2 window causes the #3 window to jitter up and down.
  100. By the way, the scrolling region capability is often omitted in
  101. many termcap entries, so you might need to put it in.
  102. Here is the relevant vt100 stuff, which is probably the
  103. only scrolling region support you are likely to find:
  104. .DS
  105. .ft PO
  106. .\" note: the '\e' below is troff's way of saying '\'
  107. :sc=\eE7:rc=\eE8:cs=\eE[%i%d;%dr:sr=5\eEM:
  108. .ft P
  109. .DE
  110. For now, all of ``cs'', ``sc'', ``rc'', and ``sr'' must be specified
  111. or wm will not use scrolling regions.
  112. .PP
  113. By all means you should make windows be the full width of the screen.
  114. Without that wm scrolls by redrawing the whole window.
  115. The painful slowness is tolerable for smaller windows,
  116. and also for faster terminal speeds.
  117. My office terminal is at 4800 baud, and wm is okay at that speed,
  118. but even 19200 is probably too slow for a window that is full-screen
  119. except for the right-most column.
  120. .SH
  121. WM Enhancements
  122. .PP
  123. The ``Hacking WM'' document mentions several possible enhancements.
  124. Suggestions for other improvements to wm are welcome.
  125. Code for any new improvements are even more welcome!
  126. .bp
  127. .TL
  128. Hacking WM
  129. (Obscure Details for the Hard-Core User)
  130. .AU
  131. Tom Truscott
  132. .AI
  133. Research Triangle Institute
  134. P.O. Box 12194
  135. RTP, NC  27709
  136. (919) 541-7005
  137. .SH
  138. In Praise of Matt Lennon
  139. .PP
  140. Matt Lennon took an interest in Robert Jacob's Usenet wm distribution,
  141. got it running here, and talked others into trying it out.
  142. Frankly, the original version was too slow to be usable,
  143. although it was indeed interesting.
  144. (Perhaps most interesting of all was that Jacob had a version
  145. of wm running under UNIX V6!)
  146. Matt reorganized the program internally and put in the first
  147. of a series of scrolling hacks (in WMinsertln and WMdeleteln).
  148. The resulting program shares with the original wm a simplicity of design
  149. that is important in any program, but particularly in a window manager.
  150. I think of the revised wm as the ``A'' version.
  151. I am afraid a ``B'' version will be along all too soon.
  152. .SH
  153. Problems with Running Programs under WM
  154. .PP
  155. There are three common problems when running programs under wm.
  156. One problem is that some programs assume
  157. the screen is at least some minimum size, such as 24 lines and 80 columns.
  158. Typical programs betray themselves by scribbling text
  159. intended for ``line 24'' at random places on the screen,
  160. or by dumping core after the ``newwin'' curses routine refuses
  161. to create a window that encompasses that line.
  162. Fixing such programs can be a chore,
  163. but often one can just substitute `COLS' for 80, `LINES-1' for 23,
  164. and so on.
  165. Rogomatic demands 24 lines so I hacked it to overlay all lines >= LINES
  166. onto line LINES-1, which is messy but tolerable.
  167. For programs beyond hope, type \fI<wm-esc>\fPz and run the program
  168. on the real terminal.
  169. .PP
  170. A second problem is with programs that assume a specific terminal type,
  171. such as "vt100".
  172. Wm currently understands only the pseudo-terminal
  173. type "wmvirt", so such programs cannot be run under wm.
  174. It would be nice if wm could emulate an arbitrary
  175. terminal type.
  176. Then one could run wm on an ADM terminal
  177. with one window emulating a vt100 and another emulating a Tektronix 4014.
  178. Of course, wm would need to support viewports into windows.
  179. Viewports are trivial compared to emulating 4014 graphics, however.
  180. .PP
  181. A third problem is that some programs use getlogin
  182. to determine the user's login name,
  183. but under wm getlogin fails since no one is logged in
  184. on the window's control terminal (pseudo-tty).
  185. The easiest fix is to replace calls to getlogin
  186. with calls to safegetlogin:
  187. .DS
  188. .ft PO
  189. /*
  190.  * Returns a user name such that uid(user name) == getuid().
  191.  * If feasible, the session login name is used,
  192.  * but if the real uid has been changed (e.g. via 'su')
  193.  * or if certain file descriptors have been munged
  194.  * then a user name corresponding to the real uid is returned instead.
  195.  * Returns NULL if everything fails.
  196.  * Beware!  Clobbers static data from earlier calls to getpw*.
  197.  */
  198.  
  199. #include <pwd.h>
  200.  
  201. char *
  202. safegetlogin()
  203. {
  204.     register char *p;
  205.     register int uid;
  206.     register struct passwd *pwd;
  207.     static char namebuf[50];
  208.     extern char *getlogin();
  209.  
  210.     uid = getuid();
  211.     p = getlogin();
  212.     /* cannot trust getlogin, so here is a security check */
  213.     if (!p || !(pwd = getpwnam(p)) || uid != pwd->pw_uid)
  214.         p = 0;
  215.     /* if getlogin failed, try the real uid */
  216.     if (!p && (pwd = getpwuid(uid)))
  217.         p = pwd->pw_name;
  218.     if (p) {
  219.         strncpy(namebuf, p, sizeof(namebuf)-1);
  220.         p = namebuf;
  221.     }
  222.     return(p);
  223. }
  224. .ft P
  225. .DE
  226. This fixes the `galaxy' and `robots' programs, for example.
  227. We keep this routine in /usr/local/liblocal.a and link programs
  228. that call it with `-llocal'.
  229. Alas, one case that this misses is the command ``who  am  i''.
  230. The trade secret status of ``who'' precludes a clearer explanation.
  231. .SH
  232. Support for Fast Scrolling of any Rectangular Window
  233. .PP
  234. A (very) few terminals support general ``scrolling rectangles.''
  235. These are wonderful for wm because then
  236. non-full-width windows scroll quickly.
  237. Terminfo already has the ``set_window'' string capability,
  238. described in `tparm' format,
  239. to set up a scrolling rectangle.
  240. There is no such capability in termcap so a new ``sw''
  241. capability was invented, using the same format as terminfo.
  242. For example, for the HDS Concept 108 we have:
  243. .DS
  244. .ft PO
  245. .\" note: the '\e' below is troff's way of saying '\'
  246. :sw=\eEv%p1%' '%+%c%p3%' '%+%c%p2%p1%-%'!'%+%c%p4%p3%-%'!'%+%c:\e
  247. .ft P
  248. .DE
  249. For the HDS 200 we have (sorry, this is untested):
  250. .DS
  251. .ft PO
  252. .\" note: the '\e' below is troff's way of saying '\'
  253. :sw=\eE[%p1%{1}%+%d;%p2%{1}%+%d;%p3%{1}%+%d;%p4%{1}%+%dr:\e
  254. .ft P
  255. .DE
  256. You also need ``sr'' (scroll_reverse) for wm to use set_window.
  257. Wm assumes that the set_window command moves the cursor
  258. to the rectangle's home position (upper left),
  259. that cursor motion commands work in the rectangle,
  260. and that the motions are relative to the origin of the rectangle.
  261. If your terminal works differently, and it probably will,
  262. you might have to hack wm.
  263. Look for "SET_WINDOW" which, if defined, causes
  264. code to be generated to support scroll rectangles.
  265. .SH
  266. LIBCURSES
  267. .PP
  268. Wm depends heavily on the underlying screen management software (libcurses)
  269. for correctness and efficiency.
  270. A number of changes were found to be needed in libcurses
  271. to provide correctness.
  272. The major efficiency problem has been that of providing fast scrolling.
  273. Libcurses itself does not support insert/delete line or
  274. scrolling regions to provide fast scrolling.
  275. We decided not to put such support into libcurses,
  276. because that was considered too far-reaching,
  277. so insert/delete line and scrolling regions are handled
  278. within special code in wm itself,
  279. and the libcurses windows are accordingly fixed up.
  280. Wm could support scrolling regions more efficiently
  281. (by not switching back and forth between full screen
  282. and window-sized regions on every newline).
  283. It could also handle certain non-full-width windows better.
  284. For example to scroll a window that covers all but the rightmost column
  285. it could scroll all lines involved and then redraw the rightmost column.
  286. Perhaps the termlib or other packages do that sort of thing.
  287. Also, for non-full-width windows wm could perhaps scroll two
  288. or more lines at a time, or possibly even wrap around
  289. to the top line rather than scroll.
  290. .SH
  291. WM and TERMINFO
  292. .PP
  293. Wm can be compiled with
  294. Pavel Curtis' public domain ``terminfo'' library
  295. in addition to the usual one (``Curses Classic'').
  296. During compilation the TERMINFO preprocessor variable is defined
  297. if compilation with terminfo curses is detected,
  298. so that appropriate code is generated.
  299. The terminfo conventions are nicer than the classic version
  300. so wm uses the terminfo functions and variable names,
  301. and Curses Classic is supported by redefinitions and emulation routines.
  302. .PP
  303. However, wm really should only be compiled with Curses Classic.
  304. The terminfo version is slower, bigger, buggier, and does not
  305. support arrow keys.
  306. Terminfo also has more fundamental problems.
  307. It does not provide support for the TERMCAP environment variable,
  308. and there is no easy way to construct a terminfo binary file
  309. analogous to the 'wmvirt' TERMCAP string.
  310. As a result wm cannot support any terminfo-compiled applications programs.
  311. When (if) this becomes a problem there will be additional incentive
  312. for wm to be able to emulate an arbitrary terminal
  313. (also see ``problems with running programs under wm'', above).
  314. Then, in conjunction with the 4.3 kernel support for window sizes,
  315. wm can dispense with the TERMCAP variable and emulate whatever
  316. terminal is desired, thus supporting both termcap and terminfo.
  317. (\fI<wm-esc>\fPt will still be needed for tip and cu.)
  318. .SH
  319. WM response sluggishness
  320. .PP
  321. An unfortunate current side-effect of wm is that certain
  322. normally responsive terminal operations are now sluggish.
  323. For example, if you cat a file and press <Interrupt>
  324. several lines will be printed before the interrupt
  325. takes effect.
  326. Other similar special characters are also handled slowly.
  327. The reason is that wm runs in raw mode, so such characters
  328. are not ``instantly'' handled in the kernel.
  329. Instead they are passed to the currently selected
  330. pseudo-tty, which then interrupts or stops or whatever.
  331. But any characters currently queued by wm for the user's terminal
  332. are still printed!
  333. (The script program has the same behavior,
  334. but it is tolerable for the normal uses of that command.)
  335. There does not seem to be a good way around this problem.
  336. Wm's current approach is to
  337. .IP a)
  338. Only read a few (currently 64) characters from each pseudo-tty
  339. at a time, to avoid large queues from wm to the real tty.
  340. .IP b)
  341. Have wm check the size of the output queue using the undocumented
  342. TIOCOUTQ ioctl, and delay reading from the pseudo-ttys
  343. if the output queue is large.
  344. .IP c)
  345. Have wm reduce the read and queue sizes for a while after the user
  346. types Control-S.
  347. .LP
  348. The first two hacks keep the response to <Interrupt> at a tolerable level.
  349. They also keep the tty high water mark from
  350. being reached, which would put wm to sleep,
  351. which would make response very sluggish indeed.
  352. The last hack gives somewhat better response to Control-S.
  353. .PP
  354. This approach to wm sluggishness is quite new,
  355. so more tuning and better approaches to the problem are possibilities.
  356. Also, the parameters have been tuned for a Gould 9050,
  357. which is quite a fast machine, and the resulting
  358. extra cpu involved might be intolerable on a VAX.
  359. An easy `fix' is to comment out the TIOCOUTQ code in wm.c
  360. (you can probably just #undef TIOCOUTQ at the top).
  361. You might want to remove the Control-S hack as well.
  362. .SH
  363. The `.wmrc' File
  364. .PP
  365. The first line of .wmrc is the prefix character.
  366. The remaining lines describe the configured windows from bottom
  367. to top.
  368. (The last line describes the window in which the user starts.)
  369. Each line consists of the window name, the number of rows and columns,
  370. and the starting row and column (zero indexed).
  371. If the number of rows (columns) is given as zero then that dimension
  372. ``flexes'' to the height (width) of the screen,
  373. which supposedly is useful when switching among terminals
  374. of different sizes.
  375. .PP
  376. Several users have asked for the ability to specify an alternate ``shell''
  377. in a window.
  378. That could be done by extending the .wmrc lines to include
  379. a command to be executed in lieu of the shell.
  380. Other users have requested the ability to set the shell prompts
  381. in a window dependent way, among other things.
  382. I do not know how that might be done.
  383. .SH
  384. The ``SNEAKYTERMCAP'' Method
  385. .PP
  386. Ordinarily, when a window changes size, wm blasts the window
  387. with a shell command that sets TERM and TERMCAP
  388. to indicate the new window's size.
  389. (This is the same shell command generated by \fI<wm-esc>\fPt.)
  390. This not only produces clutter, it can also confuse non-shell
  391. programs running in that window.
  392. If your version of wm was compiled with SNEAKYTERMCAP defined,
  393. however, a different method is used.
  394. The TERMCAP variable is set to a filename such as /tmp/WM.33445.1
  395. and the file contains the termcap capability string.
  396. Then, when a window changes size the /tmp file is simply rewritten.
  397. But there is a security problem with this method
  398. (or with any command that uses /tmp)
  399. and /tmp gets cluttered up with lots of ``WM'' files.
  400. It would be better if the files were kept in a subdirectory
  401. of each user's home directory, and if wm itself cleaned
  402. up dead temporary files (e.g. due to a system crash).
  403. .SH
  404. Browsing About in WM Windows
  405. .PP
  406. Some terminals have extra memory so one can look back
  407. at text that scrolls off the screen.
  408. It would be nice if wm provided that too.
  409. One hundred lines of scrolled typescript should be adequate.
  410. A plausible approach would be to type \fI<wm-esc>\fPv
  411. (for `view') to put the window in browse mode.
  412. Then input to that window is interpreted as requests
  413. to move back and forth in the typescript,
  414. like the `vi' scrolling commands.
  415. Any output to the real window is held pending exit from browse mode,
  416. which might be by typing ``:q'', at which time the window
  417. is reset to its state on entry to browse mode.
  418. Of course, while a window is in browse mode one can still
  419. switch between windows, move, create, and kill windows, and so on.
  420. .PP
  421. All this can be implemented cleanly with about 100 lines of code
  422. scattered here and there (it has been written),
  423. but what about text searching and the ability to write parts
  424. of the typescript into UNIX files?
  425. What about all the other nifty `vi' commands?
  426. Why not just run `vi' (or your favorite viewing program)
  427. in the browse window!?
  428. Well, here is why not.
  429. Vi has to position itself at the end of the typescript
  430. in order to provide a ``seamless interface'' to wm.
  431. Okay, that's easy.
  432. We need an ``ignore first clear'' kludge so that when
  433. vi initially redraws the screen
  434. the window is not really redrawn.
  435. Uh, well, wm already has kludges.
  436. We need to suppress the vi status line (``seamless interface'' remember),
  437. say by displaying it instead in wm's status area.
  438. Er, uhm.  Yuck!
  439. It could be done, but it sure would be ugly.
  440. Alas, wm does not yet support browse mode.
  441.