home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / windows / x / 20182 < prev    next >
Encoding:
Text File  |  1992-12-14  |  6.0 KB  |  184 lines

  1. Newsgroups: comp.windows.x
  2. Path: sparky!uunet!mcsun!sun4nl!fwi.uva.nl!wijkstra
  3. From: wijkstra@fwi.uva.nl (Marcel Wijkstra (AIO))
  4. Subject: X client that sits & waits SUMMARY (switching mwm<->twm)
  5. Message-ID: <1992Dec14.131654.21870@fwi.uva.nl>
  6. Sender: news@fwi.uva.nl
  7. Nntp-Posting-Host: ic.fwi.uva.nl
  8. Organization: FWI, University of Amsterdam
  9. References: <1992Dec9.104532.24382@fwi.uva.nl>
  10. Date: Mon, 14 Dec 1992 13:16:54 GMT
  11. Lines: 171
  12.  
  13.  
  14. SUMMARY
  15. -------
  16. Recently, I posted a request for an X client that just sits and waits
  17. (until it gets killed). The reason for this, was that I wanted this client
  18. to be the last one executed in my .xinitrc, so that I would be able to
  19. kill my window manager (which normally is the last line in .xinitrc) without
  20. terminating X.  This would allow me to start a different window manager.
  21. Finally, killing the small X client would end my X session.
  22.  
  23. I got several replies, most of them pointing to small programs that pop up
  24. a little one-button menu, which exits when it is pushed. Those are:
  25.  
  26. NAME    FTP-SITE        DIR        POINTED BY
  27. killme    larry.mcrcim.mcgill.edu    /X/        mouse@larry.mcrcim.mcgill.edu
  28. xlogo                        janzen@mprgate.mpr.ca
  29. xlogout                        shmdgljd@rchland.vnet.ibm.com
  30. source for some unnamed program            cwikla@wri.com
  31. xquitbutton ftp.dcs.ed.ac.uk    /pub/X11R5/local/xquitbutton/ gdmr@dcs.ed.ac.uk
  32. xsleep                        aad@lovecraft.siemens.com
  33.  
  34. klai@jman.dco.dec.com Suggested I'd use xtools as the 1st X client, and put
  35. all subsequent client in .xtoolsrc
  36.  
  37. eillihca@drizzle.StanFord.EDU Handed me a small shell script - JAXU - to
  38. replace the 'mwm' (or 'twm' or whatever) call in .xinitrc. This JAXU
  39. would exit the window manager exits normally, but would start a different
  40. window manager if it receives a signal USR1.
  41.  
  42. casper@fwi.uva.nl Provided a solution that uses the 'f.function' property
  43. from twm and therefore is not generally applicable.
  44.  
  45. tl@etek.chalmers.se Uses xconsole. 
  46.  
  47.  
  48. COMMENTS
  49. --------
  50. I don't want a seperate "Exit-X-button" on my desktop, I just want to exit
  51. X  as I uses to (i.e. from within the twm root menu); therefore, these
  52. little pop-up X clients are no good for me (perhaps YOU like them).
  53. The JAXU script seems to me as the best solution, but unfortunately I know
  54. to little about handling signals in sh to use it while knowing what I'm doing.
  55. Furthermore, I want to go through as little trouble as possible, i.e. I don't
  56. want ANYTHING to change in the looks and feels of my X session (except for
  57. the additional possibility of switching between two window managers).
  58. Therefore, I created
  59.  
  60.  
  61. MY OWN SOLUTION
  62. ---------------
  63. With the help of all above mentioned advises, and vdlinden@fwi.uva.nl, I
  64. created some solution myself:
  65.  
  66. I use a script 'wm' to start and switch the different window managers:
  67.  
  68.     #!/bin/csh -f
  69.     
  70.      switch ($1)
  71.       case mwm:
  72.         goto MWM
  73.       case twm:
  74.         goto TWM
  75.       default:
  76.         exit
  77.      endsw
  78.     
  79.     MWM:
  80.      mwm
  81.     TWM:
  82.      twm
  83.      goto MWM
  84.  
  85. This script simple calls it first argument - which must be the desired
  86. initial window manager (e.g. 'wm mwm'). When this one exits, the next
  87. one is started.
  88. If you need more than 2 window managers, you may need some other mechanism
  89. than this simple loop. But I'm sure you Xperts can write a fancy menu-driven
  90. window manager selector if you need one...
  91.  
  92.  
  93. The discussed 'X client that just sits and waits' is called 'xwait':
  94.  
  95.     #include <stdio.h>
  96.     #include <X11/Xlib.h>
  97.     
  98.     void main(argc,argv)
  99.       int  argc;
  100.       char *argv[];
  101.     {
  102.       char    *displayname;
  103.       int     arg,pid;
  104.       Display *dpy;
  105.       XEvent  *evt;
  106.                         /* GET DISPLAYNAME */
  107.       displayname=NULL;
  108.       for (arg=1;arg<argc;arg++)
  109.         if (! strncmp(argv[arg],"-display",strlen(argv[arg])))
  110.           displayname=argv[++arg];
  111.                         /* OPEN DISPLAY */
  112.       dpy = XOpenDisplay(displayname);
  113.       if (!dpy) {
  114.         fprintf(stderr, "%s: can't open display %s\n", *argv,displayname);
  115.         return; }
  116.                         /* PASS PID TO STDOUT */
  117.       pid=getpid();
  118.       fprintf(stdout,"%d\n",pid);
  119.                         /* FLUSH */
  120.       fclose(stdout);
  121.     
  122.                         /* WAIT FOREVER */
  123.       XNextEvent(dpy,evt);
  124.     }
  125.  
  126. xwait Can be called without any arguments, or with '-display <displayname>'.
  127. It simply connects to the X server, and waits for any events. I know little
  128. about X, but it works, i.e. xwait does not receive any events and thus
  129. waits "forever".
  130.  
  131.  
  132. In my .mwmrc, the following lines occur:
  133.  
  134. Menu RootMenu
  135. {
  136. ...
  137.     "TWM"        f.quit_mwm
  138.     "Exit X"    !"kill `cat ${XWAIT}`"
  139. }
  140.  
  141. In my .twmrc, similar lines occur.
  142. As soon as 'f.quit_mwm' is executed, control is gained by 'wm' (see above)
  143. again, which then calls 'twm'.
  144. ${XWAIT} Is the filename of a temporary file that holds the PID of 'xwait'.
  145. I know of no other simple way of passing the PID of a program that runs
  146. on the foreground to its parent. The danger of this mechanism - apart from
  147. its uglyness - is that this file may be deleted, in which case you don't
  148. know xwait's PID... A different solution would be to use 'ps' (e.g.
  149. ps eauxww | grep xwait | grep $DISPLAY | grep -v grep) to query the
  150. PID of xwait, but I don't like that approach either.
  151.  
  152.  
  153. Finally, in .xinitrc, I do:
  154.  
  155.     XWAIT=/tmp/xwait.${DISPLAY}
  156.     wm mwm &
  157.     xwait > ${XWAIT}
  158.     rm -f ${XWAIT}
  159.  
  160. ${XWAIT} Is a unique filename, so no other window manager started in a similar
  161. way should be able to access it (unless it *wants* to do evil).
  162. 'xwait' Writes to ${XWAIT} and closes this file before it terminates (see
  163. source of 'xwait').
  164.  
  165.  
  166. DISCLAIMER
  167. ----------
  168. If you have any comments, or know a better way for some things I suggested
  169. (e.g. how to pass the PIX of xwait to mwm), please let me know.
  170. Also, if you think what I do is absolutely wrong, drop me a note too.
  171.  
  172. Remember however, that the above contruction takes into account, that it has
  173. to run on a Sun4 (on which an X session is usually terminated with some
  174. root menu option (like 'Exit TWM')) as well as on an RS/6000 (which uses
  175. the Ctrl-Alt-BackSpace key-combination to exit the X session). Especially
  176. the latter is a bit hard to handle.
  177.  
  178. Marcel.
  179. -- 
  180.  X       Marcel Wijkstra   AIO   (wijkstra@fwi.uva.nl)
  181. |X|         Faculty of Mathematics and Computer Science    
  182.  X           University of Amsterdam   The Netherlands
  183. ======Life stinks. Fortunately, I've got a cold.========
  184.