home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / awm2 / part10 / Restart.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-21  |  5.1 KB  |  175 lines

  1.  
  2.  
  3.  
  4. #ifndef lint
  5. static char *rcsid_Restart_c = "$Header: /usr/graph2/X11.3/contrib/windowmgrs/awm/RCS/Restart.c,v 1.3 89/02/07 22:39:52 jkh Exp $";
  6. #endif  lint
  7.  
  8. #include "X11/copyright.h"
  9. /*
  10.  *
  11.  * Copyright 1987, 1988 by Ardent Computer Corporation, Sunnyvale, Ca.
  12.  *
  13.  * Copyright 1987 by Jordan Hubbard.
  14.  *
  15.  *
  16.  *                         All Rights Reserved
  17.  *
  18.  * Permission to use, copy, modify, and distribute this software and its
  19.  * documentation for any purpose and without fee is hereby granted,
  20.  * provided that the above copyright notice appear in all copies and that
  21.  * both that copyright notice and this permission notice appear in
  22.  * supporting documentation, and that the name of Ardent Computer
  23.  * Corporation or Jordan Hubbard not be used in advertising or publicity
  24.  * pertaining to distribution of the software without specific, written
  25.  * prior permission.
  26.  *
  27.  */
  28.  
  29. /*
  30.  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  31.  *
  32.  *                         All Rights Reserved
  33.  *
  34.  * Permission to use, copy, modify, and distribute this software and its
  35.  * documentation for any purpose and without fee is hereby granted,
  36.  * provided that the above copyright notice appear in all copies and that
  37.  * both that copyright notice and this permission notice appear in
  38.  * supporting documentation, and that the name of Digital Equipment
  39.  * Corporation not be used in advertising or publicity pertaining to
  40.  * distribution of the software without specific, written prior permission.
  41.  *
  42.  *
  43.  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  44.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  45.  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  46.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  47.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  48.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  49.  * SOFTWARE.
  50.  */
  51.  
  52. /*
  53.  * MODIFICATION HISTORY
  54.  *
  55.  * 000 -- M. Gancarz, DEC Ultrix Engineering Group
  56.  * 001 -- Loretta Guarino Reid, DEC Ultrix Engineering Group,
  57.     Western Software Lab. Convert to X11.
  58.  * 002 -- Jordan Hubbard, U.C. Berkeley. Titlebar cleanup code.
  59.  */
  60.  
  61. #include "awm.h"
  62. #include "X11/Xutil.h"
  63.  
  64. extern XContext AwmContext;
  65.  
  66. /*ARGSUSED*/
  67. Boolean Restart(window, mask, button, x, y)
  68. Window window;                          /* Event window. */
  69. int mask;                               /* Button/key mask. */
  70. int button;                             /* Button event detail. */
  71. int x, y;                               /* Event mouse position. */
  72. {
  73.     Entry("Restart")
  74.  
  75.     XFreeFont(dpy, IFontInfo);
  76.     XFreeFont(dpy, PFontInfo);
  77.     XBell(dpy, VOLUME_PERCENTAGE(Volume));
  78.     XBell(dpy, VOLUME_PERCENTAGE(Volume));
  79.     XFlush(dpy);
  80.     Cleanup();
  81.     XSync(dpy, 0); /* be paranoid */
  82.     execvp(*Argv, Argv, Environ);
  83.     fprintf(stderr, "awm: Restart failed!\n");
  84.     exit(1);
  85. }
  86.  
  87. /*ARGSUSED*/
  88. Boolean Quit(window, mask, button, x, y)
  89. Window window;                          /* Event window. */
  90. int mask;                               /* Button/key mask. */
  91. int button;                             /* Button event detail. */
  92. int x, y;                               /* Event mouse position. */
  93. {
  94.      Entry("Quit")
  95.  
  96.      Cleanup();
  97.      /*
  98.       * Be a careful boy scout.
  99.       */
  100.      XSync(dpy, 0);
  101.      XCloseDisplay(dpy);
  102.      exit(0);
  103. }
  104.  
  105. /*ARGSUSED*/
  106. Boolean DestroyClient(window, mask, button, x, y)
  107. Window window;
  108. int mask;
  109. int x, y;
  110. {
  111.      AwmInfoPtr awi;
  112.  
  113.      Entry("DestroyClient")
  114.  
  115.      if (window == RootWindow(dpy, scr))
  116.         Leave(FALSE)
  117.      awi = GetAwmInfo(window);
  118.      /*
  119.       * If it's a titled window or an icon (we don't want to nuke ourselves)
  120.       * we should get the client for it. We assume the subsequent destroy
  121.       * notify will tell us to reclaim our resources.
  122.       */
  123.      window = awi->client;
  124.      XKillClient(dpy, window);
  125.      Leave(TRUE)
  126. }
  127.  
  128. /*
  129.  * Put any necessary cleanup code here, it will be invoked when awm exits
  130.  * or restarts. Currently just checks for title bar resources.
  131.  */
  132. Cleanup()
  133. {
  134.      Window junk, *windows;
  135.      unsigned int nwins;
  136.      AwmInfoPtr awi;
  137.  
  138.      Entry("Cleanup");
  139.  
  140.      if (XQueryTree(dpy, DefaultRootWindow(dpy), &junk, &junk, &windows,
  141.             &nwins)) {
  142.       int i;
  143.       
  144.       for (i = 0; i < (int)nwins; i++) {
  145.            XWindowAttributes xwa;
  146.            int bw;
  147.  
  148.            awi = GetAwmInfo(windows[i]);
  149.            if (!awi)
  150.             continue;
  151.            bw = awi->border_width;
  152.            if (awi->state & ST_ICON)
  153.             XMapWindow(dpy, awi->client);
  154.            RemoveIcon(windows[i]);
  155.            XGetWindowAttributes(dpy, awi->frame, &xwa);
  156.            if (PushDown == FALSE) {
  157.             if (awi->attrs & AT_TITLE)
  158.              xwa.y += (titleHeight + 2);
  159.             else if (awi->attrs & AT_BORDER)
  160.              xwa.y += BContext;
  161.            }
  162.            if (awi->attrs & AT_BORDER)
  163.             xwa.x -= (BContext + (bw ? bw : 1));
  164.            XReparentWindow(dpy, awi->client, RootWindow(dpy, scr),
  165.                    xwa.x, xwa.y);
  166.            XRemoveFromSaveSet(dpy, awi->client);
  167.            XSetWindowBorderWidth(dpy, awi->client, awi->border_width);
  168.            free(awi);
  169.       }
  170.       if (nwins)
  171.            XFree(windows);
  172.      }
  173.      Leave_void
  174. }
  175.