home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / awm2 / part08 / Move.c < prev   
Encoding:
C/C++ Source or Header  |  1989-02-20  |  8.5 KB  |  309 lines

  1.  
  2.  
  3.  
  4. #ifndef lint
  5. static char *rcsid_Move_c = "$Header: /usr/graph2/X11.3/contrib/windowmgrs/awm/RCS/Move.c,v 1.2 89/02/07 21:22:55 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. Port to X11
  58.  */
  59.  
  60. #include "awm.h"
  61.  
  62. /*ARGSUSED*/
  63. Boolean Move(window, mask, button, x, y)
  64. Window window;                /* Event window. */
  65. int mask;                /* Button/key mask. */
  66. int button;                /* Button event detail. */
  67. int x, y;                /* Event mouse position. */
  68. {
  69.      register int prev_x;        /* Previous event window X location. */
  70.      register int prev_y;        /* Previous event window Y location. */
  71.      XWindowAttributes window_info;    /* Event window information. */
  72.      int cur_x;                /* Current event window X location. */
  73.      int cur_y;                /* Current event window Y location. */
  74.      int root_x;                /* Root window X location. */
  75.      int root_y;                /* Root window Y location. */
  76.      int ulx, uly;            /* Event window upper left X and Y. */
  77.      int lrx, lry;            /* Event window lower right X and Y. */
  78.      int init_ulx, init_uly;        /* Init window upper left X and Y. */
  79.      int init_lrx, init_lry;        /* Init window lower right X and Y. */
  80.      int num_vectors;            /* Number of vectors in box. */
  81.      unsigned int ptrmask;        /* state of ptr when queried */
  82.      Window sub_window;            /* Query mouse event sub-window. */
  83.      Window root;            /* Query mouse event root. */
  84.      AwmInfoPtr awi;
  85.      XEvent button_event;        /* Button event packet. */
  86.      XSegment box[MAX_BOX_VECTORS];    /* Box vertex buffer. */
  87.      XSegment zap[MAX_ZAP_VECTORS];    /* Zap effect verted buffer. */
  88.      int (*storegrid_func)();        /* Function to use for grid */
  89.      int (*storebox_func)();        /* Function to use for box */
  90.      extern void ungrab_pointer();
  91.      extern void grab_pointer();
  92.      
  93.      Entry("Move")
  94.       
  95.      /*
  96.       * Do not try to move the root window.
  97.       */
  98.      if (window == RootWindow(dpy, scr))
  99.       Leave(FALSE)
  100.             
  101.      /*
  102.       * Change the cursor.
  103.       */
  104.      grab_pointer();
  105.      /*
  106.       * Clear the vector buffers.
  107.       */
  108.      bzero(box, sizeof(box));
  109.      if (Zap)
  110.       bzero(zap, sizeof(zap));
  111.      
  112.      /*
  113.       * Gather info on the event window.
  114.       */
  115.      awi = GetAwmInfo(window);
  116.      if (!awi)
  117.       Leave(FALSE)
  118.      status = XGetWindowAttributes(dpy, window, &window_info);
  119.      if (status == FAILURE)
  120.       Leave(FALSE)
  121.  
  122.      if (awi->title && !IsIcon(window, None)) {
  123.       storegrid_func = StoreTitleGridBox;
  124.       storebox_func = StoreTitleBox;
  125.      }
  126.      else {
  127.       storegrid_func = StoreGridBox;
  128.       storebox_func = StoreBox;
  129.      }
  130.      /*
  131.       * Initialize movement variables.
  132.       */
  133.      init_ulx = ulx = window_info.x;
  134.      init_uly = uly = window_info.y;
  135.      init_lrx = lrx = window_info.x + window_info.width +
  136.       (window_info.border_width << 1) - 1;
  137.      init_lry = lry = window_info.y + window_info.height +
  138.       (window_info.border_width << 1) - 1;
  139.      
  140.      /*
  141.       * Store the box.
  142.       */
  143.      if (Grid)
  144.       num_vectors = (*storegrid_func)(box, ulx, uly, lrx, lry);
  145.      else
  146.       num_vectors = (*storebox_func)(box, ulx, uly, lrx, lry);
  147.      
  148.      /*
  149.       * Initialize the previous location variables.
  150.       */
  151.      prev_x = x;
  152.      prev_y = y;
  153.      
  154.      /*
  155.       * Freeze the server, if requested by the user.
  156.       * This results in a solid box instead of a flickering one.
  157.       */
  158.      if (Freeze)
  159.       XGrabServer(dpy);
  160.      Snatched = True;
  161.      /*
  162.       * Process any pending exposure events before drawing the box.
  163.       */
  164.      while (QLength(dpy) > 0) {
  165.       XPeekEvent(dpy, &button_event);
  166.       if (((XAnyEvent *)&button_event)->window == RootWindow(dpy, scr))
  167.            break;
  168.       GetButton(&button_event);
  169.      }
  170.      
  171.      /*
  172.       * Now draw the box.
  173.       */
  174.      
  175.      DrawBox();
  176.      Frozen = window;
  177.      
  178.      /*
  179.       * Main loop.
  180.       */
  181.      while (TRUE) {
  182.       
  183.       /*
  184.        * Check to see if we have a change in mouse button status.
  185.        * This is how we get out of this "while" loop.
  186.        */
  187.       if (XPending(dpy) && !ProcessRequests(box, num_vectors) &&
  188.           GetButton(&button_event)) {
  189.            /*
  190.         * Process the pending events, this sequence is the only
  191.         * way out of the loop and the routine.
  192.         */
  193.            
  194.            if ((button_event.type != ButtonPress) && 
  195.            (button_event.type != ButtonRelease)) {
  196.             continue; /* spurious menu event... */
  197.            }
  198.            
  199.            /*
  200.         * If we froze the server, then erase the last lines drawn.
  201.         */
  202.            if (Freeze) {
  203.             DrawBox();
  204.             Frozen = (Window)0;
  205.             XUngrabServer(dpy);
  206.            }
  207.            
  208.            if ((button_event.type == ButtonRelease) &&
  209.            (((XButtonReleasedEvent *)&button_event)->button == button)) {
  210.             
  211.             /*
  212.              * The button was released, so move the window.
  213.              */
  214.             
  215.             if (Zap) {
  216.              num_vectors = StoreZap(zap,
  217.                         init_ulx, init_uly,
  218.                         init_lrx, init_lry,
  219.                         ulx, uly,
  220.                         lrx, lry);
  221.              DrawZap();
  222.              DrawZap();
  223.             }
  224. #ifdef titan /* 5x4 alignment */
  225.             ulx = ((ulx + 3) / 5) * 5;
  226.             uly = ((uly + 2) / 4) * 4;
  227. #endif /* titan */
  228.             if (Wall) {
  229.              if (ulx < 0)
  230.                   ulx = 0;
  231.              if (ulx > (ScreenWidth - window_info.width))
  232.                   ulx = (ScreenWidth - window_info.width);
  233.              if (uly < 0)
  234.                   uly = 0;
  235.              if (uly > (ScreenHeight - window_info.height))
  236.                   uly = (ScreenHeight - window_info.height);
  237.             }
  238.             XMoveWindow(dpy, window, ulx, uly);
  239.             Snatched = False;
  240.             ungrab_pointer();
  241.             Leave(TRUE)
  242.            }
  243.            else {
  244.             /*
  245.              * Some other button event occured, this aborts the
  246.              * current operation.
  247.              */
  248.             
  249.             ResetCursor(button);
  250.             Snatched = False;
  251.             ungrab_pointer();
  252.             Leave(TRUE)
  253.            }
  254.       }
  255.       
  256.       /*
  257.        * Take care of all the little things that have changed.
  258.        */
  259.       XQueryPointer(dpy, 
  260.             RootWindow(dpy, scr), &root,  &sub_window,
  261.             &root_x, &root_y, &cur_x, &cur_y, &ptrmask);
  262.       if ((cur_x != prev_x) || (cur_y != prev_y)) {
  263.            
  264.            /*
  265.         * If we've frozen the server, then erase the old box first!
  266.         */
  267.            if (Freeze)
  268.             DrawBox();
  269.            
  270.            /*
  271.         * Box position has changed.
  272.         */
  273.            ulx += cur_x - prev_x;
  274.            uly += cur_y - prev_y;
  275.            lrx += cur_x - prev_x;
  276.            lry += cur_y - prev_y;
  277.            
  278.            /*
  279.         * Box needs to be restored.
  280.         */
  281.            if (Grid)
  282.             num_vectors = (*storegrid_func)(box, ulx, uly, lrx, lry);
  283.            else
  284.             num_vectors = (*storebox_func)(box, ulx, uly, lrx, lry);
  285.            
  286.            
  287.            /*
  288.         * Draw the new box.
  289.         */
  290.            if (Freeze)
  291.             DrawBox();
  292.       }
  293.       
  294.       /* 
  295.        * Save old box position.
  296.        */
  297.       prev_x = cur_x;
  298.       prev_y = cur_y;
  299.       
  300.       /*
  301.        * If server is not frozen, then draw the "flicker" box.
  302.        */
  303.       if (!Freeze) {
  304.            DrawBox();
  305.            DrawBox();
  306.       }
  307.      }
  308. }
  309.