home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / awm2 / part09 / Iconify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-20  |  7.4 KB  |  235 lines

  1.  
  2.  
  3.  
  4. #ifndef lint
  5. static char *rcsid_Iconify_c = "$Header: /usr/graph2/X11.3/contrib/windowmgrs/awm/RCS/Iconify.c,v 1.2 89/02/07 20:05:12 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.  
  54. /*
  55.  * MODIFICATION HISTORY
  56.  *
  57.  * 000 -- M. Gancarz, DEC Ultrix Engineering Group
  58.  * 001 -- R. Kittell, DEC Storage A/D May 20, 1986
  59.  *  Add optional warp of mouse to the upper right corner on de-iconify,
  60.  *  and to the icon center on iconify.
  61.  * 002 -- Loretta Guarino Reid, DEC Ultrix Engineering Group,
  62.  *  Western Software Lab. Port to X11.
  63.  * 003 -- Jordan Hubbard, Ardent Computer.
  64.  *  Many mods to cope with context manager, titled windows. Almost a total
  65.  *  rewrite.
  66.  * 1.2 -- Support for IconLabels.. (Isaac Salzman). A few fixes (jkh).
  67.  */
  68.  
  69. #include "awm.h"
  70.  
  71. Boolean Iconify(window, mask, button, x, y)
  72. Window window;                          /* Event window. */
  73. int mask;                               /* Button/key mask. */
  74. int button;                             /* Button event detail. */
  75. int x, y;                               /* Event mouse position. */
  76. {
  77.      XWindowAttributes fromInfo;    /* info on "from" window */
  78.      XWindowAttributes toInfo;        /* info on "to" window */
  79.      int mse_x, mse_y;            /* Mouse X and Y coordinates. */
  80.      int sub_win_x, sub_win_y;        /* relative Mouse coordinates. */
  81.      int num_vectors;            /* Number of vectors in zap buffer. */
  82.      unsigned int mmask;            /* Mouse state */
  83.      Window root;            /* Mouse root window. */
  84.      Window from, to;            /* from -> to windows */
  85.      Window sub_win;            /* Mouse position sub-window. */
  86.      XSegment zap[MAX_ZAP_VECTORS];    /* Zap effect vertex buffer. */
  87.      Boolean dozap;            /* local Zap */
  88.      AwmInfoPtr awi;
  89.      extern Window MakeIcon();
  90.  
  91.      Entry("Iconify")
  92.  
  93.      /*
  94.       * Do not try to iconify the root window.
  95.       */
  96.      if (window == RootWindow(dpy, scr))
  97.       Leave(FALSE)
  98.      /*
  99.       * The original idea of zap lines has one flaw. If a window wants
  100.       * to be created iconic, it should just appear that way without any
  101.       * fuss. CheckMap() calls us with (win, 0, 0, 0, 0) when this is the
  102.       * case, so we can special case this to turn off Zap temporarily.
  103.       * Since we don't want to mess with the global "Zap", we use
  104.       * "dozap" instead. 
  105.       */
  106.      dozap = (mask || button || x || y) ? Zap : FALSE;
  107.      /*
  108.       * Clear the vector buffer.
  109.       */
  110.      if (dozap)
  111.       bzero(zap, sizeof(zap));
  112.      
  113.      /*
  114.       * Get the mouse cursor position in case we must put a new
  115.       * icon there.
  116.       */
  117.      XQueryPointer(dpy, RootWindow(dpy, scr), &root, &sub_win, 
  118.            &mse_x, &mse_y, &sub_win_x, &sub_win_y, &mmask);
  119.      
  120.      
  121.      /*
  122.       * Figure out which direction we're going in (icon->window or vica-versa)
  123.       */
  124.      awi = GetAwmInfo(window);
  125.      if (!awi)
  126.           Leave(FALSE)
  127.      if (awi->state & ST_ICON) {
  128.           from = awi->icon;
  129.           to = (awi->frame) ? awi->frame : awi->client;
  130.       if (!(awi->state & ST_PLACED)) {
  131.            PlaceWindow(to, None);
  132.            XMapWindow(dpy, awi->client);
  133.       }
  134.      }
  135.      else if (awi->state & ST_WINDOW) {
  136.           from = (awi->frame) ? awi->frame : awi->client;
  137.           to = (awi->icon) ? awi->icon :  MakeIcon(window, mse_x, mse_y, TRUE);
  138.      }
  139.      else {
  140.           printf("Iconify: Window %x has unknown state '%x'\n",
  141.          awi->client, awi->state);
  142.       Leave(FALSE)
  143.      }
  144.      status = XGetWindowAttributes(dpy, from, &fromInfo);
  145.      if (status == FAILURE)
  146.           Leave(FALSE)
  147.      status = XGetWindowAttributes(dpy, to, &toInfo);
  148.      if (status == FAILURE)
  149.           Leave(FALSE)
  150.     
  151.      /*
  152.       * Store the zap vector buffer.
  153.       */
  154.      if (dozap) {
  155.       num_vectors =
  156.            StoreZap(zap,
  157.             fromInfo.x - 1,
  158.             fromInfo.y - 1,
  159.             fromInfo.x + fromInfo.width +
  160.             (fromInfo.border_width << 1),
  161.             fromInfo.y + fromInfo.height +
  162.             (fromInfo.border_width << 1),
  163.             toInfo.x - 1,
  164.             toInfo.y - 1,
  165.             toInfo.x + toInfo.width +
  166.             (toInfo.border_width << 1),
  167.             toInfo.y + toInfo.height +
  168.             (toInfo.border_width << 1));
  169.      }
  170.      if (awi->state & ST_ICON) {
  171.       if (!awi->frame)
  172.            XRemoveFromSaveSet(dpy, awi->client);
  173.       awi->state ^= ST_ICON;
  174.       awi->state |= ST_WINDOW;
  175. #ifdef WMSTATE
  176.       awi->wm_state.state=NormalState;
  177.       XChangeProperty(dpy,awi->client,wm_state_atom,wm_state_atom,32,
  178.               PropModeReplace,(char *) &awi->wm_state,2);
  179. #endif /* WMSTATE */
  180.      }
  181.      else if (awi->state & ST_WINDOW) {
  182.           XAddToSaveSet(dpy, awi->client);
  183.       awi->state ^= ST_WINDOW;
  184.       awi->state |= ST_ICON;
  185. #ifdef WMSTATE
  186.       awi->wm_state.state=IconicState;
  187.       XChangeProperty(dpy,awi->client,wm_state_atom,wm_state_atom,32,
  188.               PropModeReplace,(char *) &awi->wm_state,2);
  189. #endif /* WMSTATE */
  190.      }
  191.      else
  192.           fprintf(stderr, "Window state for window %x got munged!\n",
  193.              awi->client);
  194.      /*
  195.       * Map the target.
  196.       */
  197.      XMapRaised(dpy, to);
  198.      if (dozap) {
  199.       /*
  200.        * Draw the zap lines.
  201.        */
  202.       DrawZap();
  203.      }
  204.      /*
  205.       * Unmap the "from" window.
  206.       */
  207.      XUnmapWindow(dpy, from);
  208.      XFlush(dpy);
  209.      /*
  210.       * Optionally warp the mouse to the upper right corner of the
  211.       *  window.
  212.       */
  213.      if (WarpOnDeIconify && awi->state & ST_WINDOW) {
  214.       int y;
  215.  
  216.       y = (toInfo.height >= 10) ? 10 : toInfo.height / 2;
  217.       if (awi->frame) { /* compensate for title */
  218.            XWindowAttributes xwa;
  219.            XGetWindowAttributes(dpy, awi->title, &xwa);
  220.            y += xwa.height + 2;
  221.       }
  222.       status = XWarpPointer (dpy, None, to,
  223.                  0, 0, 0, 0,
  224.                  toInfo.width >= 7 ?
  225.                  toInfo.width - 7 : toInfo.width / 2,
  226.                  y);
  227.      }
  228.  
  229.      if (WarpOnIconify && awi->state & ST_ICON)
  230.       status = XWarpPointer (dpy, None, to, 
  231.                  0, 0, 0, 0,
  232.                  toInfo.width / 2, toInfo.height / 2);
  233.      Leave(FALSE)
  234. }
  235.