home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 083.lha / twm / TWM.article < prev    next >
Text File  |  1986-11-20  |  9KB  |  157 lines

  1. TWM - A Paneless Approach to Tiny Window Management
  2.  
  3. by Nick Sullivan
  4.  
  5. (   This text is a slightly adapted version of an article from Volume 8,
  6.  Issue 4 of Transactor Magazine.
  7.     Freely distributable, but copyright (c)1987, Transactor Publishing Inc.)
  8.  
  9.  
  10. Most programs on the Amiga can be divided into three fairly tidy classes.
  11. The commonest class consists of programs like DIR and LIST, that you invoke
  12. as commands, that do their work then exit. Another class consists of
  13. handlers, like the console handler ConMan, or PopToFront, from a few
  14. Transactors ago. These programs, or their offspring, live in the system
  15. usually until next reboot, but because they require no user interaction, they
  16. are invisible.
  17.  
  18. Programs in the third class are the ones you interact with for an extended
  19. period of time, such as text editors, terminal emulators and paint programs,
  20. or that you might keep around for sporadic interaction, such as PopColours
  21. and Structure Browser. One benefit of the Amiga's multitasking environment is
  22. that you don't have to take such programs down in order to do something else.
  23. You can switch readily from your editor to your terminal, for instance, and
  24. keep your text in memory; you can switch from the terminal back to the editor
  25. and stay on-line.
  26.  
  27. The extent to which you can take advantage of this capability depends, of
  28. course, on how much RAM you have in your system in relation to the size of
  29. the programs you're running. Even with a lot of expansion RAM, though, you
  30. are still limited by the amount of available "chip RAM" - the special area
  31. of memory that the Amiga's custom chips can use. On current Amigas, chip
  32. RAM is limited to 512K and, while that sounds like a lot, it can quickly
  33. get eaten up by programs that use lots of windows, colourful screens,
  34. gadgets, and other display elements that need chip RAM to survive.
  35.  
  36. The other problem with running a lot of interactive programs simultaneously
  37. is that they tend to crowd your monitor screen. That makes for a lot of
  38. depth-arranging and resizing as you flit from one task to another - the
  39. infamous "electronic shell-game" - and can get pretty tiresome if you have
  40. to do a lot of it. A few programs even put up a full-size window and won't
  41. allow you to get at the Workbench screen behind.
  42.  
  43. One approach that some programs have taken to relieve the on-screen
  44. congestion has been to supply a "tiny window mode", which can be invoked when
  45. the program is not in active use. This idea was arrived at independently
  46. quite a while ago in at least two programs I know of - Rick Stiles' shareware
  47. text editor Uedit, and Chris Zamara's PopColours. In Uedit particularly, use
  48. of the tiny window (invoked by clicking on the editor's title bar) achieves a
  49. significant savings in chip RAM. Using a normal 640 by 200 window on the
  50. Workbench screen, which has two bit-planes, Uedit needs 32K for its bit-map,
  51. plus a bit more for gadgets. Its tiny window, however, is a mere 100 by 20
  52. pixels in size, and so consumes less than 600 bytes. Clearly, the chip RAM
  53. penalty for running concurrent applications would be considerably eased if
  54. the use of a tiny window mode was more widespread.
  55.  
  56. A tiny window consists of no more than an inch or two of title bar with an
  57. equivalent thickness of empty window beneath. It is draggable, and may be
  58. depth arranged (since part of its purpose is to keep the application that
  59. owns it out of your hair), but not resizable. Clicking in the empty part
  60. reactivates the parent program, prompting it to take the tiny window down,
  61. put its working window (or screen) back up, and carry on with business as
  62. usual.
  63.  
  64. One reason for this article is to advocate the use of tiny windows in
  65. programs - including commercial programs - in which their use is appropriate
  66. (for one approach to implementing a tiny window mode see the listings for
  67. "TWM" and "Test1"). Suppose this idea *were* generally adopted,
  68. though, making it easier to run several such programs concurrently. Now the
  69. user has another problem: the new disorder of TWL (Tiny Window Litter), in
  70. which one's visible workspace is obscured by annoying swarms of tiny windows
  71. that continually seem to be getting in your way as you work, no matter how
  72. much you try to shuffle things around.
  73.  
  74. So the other reason for this article is to present TWM, for 'Tiny Window
  75. Manager', a small and easily implemented piece of code that enables programs
  76. to support a tiny window mode while giving users a method of avoiding the
  77. anguish of TWL, and the consequent disruption of their lives.
  78.  
  79. From the user's point of view, TWM is a kind of central storage compartment
  80. in which sleeping programs are housed, and from which they can be activated.
  81. The programs do not have to maintain any display of their own - not even a
  82. tiny window - so the user's screen is free from clutter. TWM's own working
  83. window contains gadgets bearing the names of its "client programs". When the
  84. user clicks on one of these gadgets, the corresponding client program is
  85. awoken and resumes operation. TWM also has its own tiny window mode; when
  86. that is in use, the amount of chip RAM jointly consumed for graphics by the
  87. client programs and TWM itself is very small. When the system is hosting two
  88. or more applications that support TWM, there is a significant savings in both
  89. resources and convenience. Of course, even if TWM is not running,
  90. applications that support it will run normally - but instead of disappearing
  91. entirely when they go to sleep, they will put up a tiny window in the usual
  92. way.
  93.  
  94. From the programmer's point of view, TWM comes in two parts - the program TWM
  95. itself, and a short C-language module called twmClient.c. The twmClient code
  96. can be compiled and linked with any application that supports a tiny window
  97. mode. Let us suppose that this client application has been running in its
  98. active mode but now, as a result of some action of the user's (perhaps a menu
  99. selection, perhaps clicking on a gadget) it has taken down its working
  100. display and is about to put up its tiny window and go to sleep.
  101.  
  102. Before taking that step, the application now calls the function PostMe() in
  103. the twmClient module, passing as an argument the name by which it would like
  104. to be known, as in:
  105.  
  106.    PostMe("PopColours");
  107.  
  108. PostMe(), in its turn, searches the system for a public message port with
  109. the name "TinyWindowManager". If the search succeeds, PostMe() sends a
  110. message to that port with the name of the client, and waits at its own
  111. message port for a reply. Effectively, the client application has now let
  112. itself go to sleep and, because it has closed its working window, there are
  113. no visible signs of its existence.
  114.  
  115. The message sent by the client is now picked up by the TWM program, which the
  116. user has earlier run, and which is now displaying one of its own windows
  117. (either the tiny window or the larger working window) on the user's
  118. screen. On receipt of the message TWM creates a gadget bearing the client
  119. application's name. The gadget will be displayed in TWM's working window
  120. (immediately, if that window is up). There may be other gadgets in the window
  121. also - one for each client application. This is the only indication that the
  122. clients still exist and, when TWM is in its tiny window mode, there is no
  123. sign of them at all. Chip RAM is conserved, and the user's window is
  124. uncluttered. When the user later clicks on the gadget, TWM replies to the
  125. message the client sent, deletes the gadget, then forgets about the client
  126. altogether.
  127.  
  128. Back now to PostMe(), waiting asleep at its message port for a reply to its
  129. message. The reply has finally come, signifying that the user has selected
  130. the client's gadget in the TWM working window, and wants the client to put
  131. up its own working window again. PostMe() now returns to the client, with
  132. the value TRUE, and the client goes back to work.
  133.  
  134. Several things might have gone wrong along the way. The most probable of
  135. these is that the user may not currently have TWM running. A remoter
  136. possibility is that TWM might have failed to allocate memory for the client's
  137. gadget, or could not open a window. In all these cases, PostMe() returns
  138. FALSE to the client, who then knows that it is necessary to put up a tiny
  139. window of its own after all.
  140.  
  141. As you will see in the code, there are other details. In case the client
  142. application wishes to wake itself up (in response to time-out or some other
  143. kind of message) while it is in TWM's care, an UnPostMe() function is also
  144. provided. Most clients won't need UnPostMe(); in that case, the programmer
  145. can remove UnPostMe() from twmClient.c to shrink the code even further.
  146. Another detail is that TWM remembers where the user last placed its windows,
  147. and restores them to the chosen position each time they are re-opened. Uedit
  148. and PopColours also have this feature, and it is recommended that other tiny
  149. window programs include it.
  150.  
  151. The intent of TWM is to institute a standard of which all tiny window
  152. programs can take advantage. Therefore all the code is freely
  153. redistributable, and may be used in any program - PD, shareware, or
  154. commercial.
  155.  
  156.  
  157.