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

  1.  
  2.  
  3.  
  4. #ifndef lint
  5. static char *rcsid_MoveOpaque_c = "$Header: /usr/graph2/X11.3/contrib/windowmgrs/awm/RCS/MoveOpaque.c,v 1.2 89/02/07 21:23:00 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 -- Loretta Guarino Reid, DEC Ultrix Engineering Group,
  59.  * Western Software Lab. Convert to X11.
  60.  * 002 -- Jordan Hubbard, Ardent Computer
  61.  *  Changed to work with awm.
  62.  */
  63.  
  64. #include "awm.h"
  65.  
  66. /*ARGSUSED*/
  67. Boolean MoveOpaque(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.      int prev_x, prev_y;        /* Previous mouse location. */
  74.      int rbound, dbound;        /* potential right/down boundries */
  75.      int cur_x, cur_y;            /* Current mouse location. */
  76.      int win_x, win_y;            /* Current window location. */
  77.      int root_x;            /* Root window X location. */
  78.      int root_y;            /* Root window Y location. */
  79.      int ptrmask;            /* state of ptr when queried */
  80.      XWindowAttributes window_info;    /* Event window information. */
  81.      Window sub_window;            /* Query mouse event sub-window. */
  82.      Window root;            /* Query mouse event root. */
  83.      XEvent button_event;        /* Button event packet. */
  84.      extern void grab_pointer();
  85.      extern void ungrab_pointer();
  86.      
  87.      Entry("MoveOpaque")
  88.  
  89.      /*
  90.       * Do not try to move the root window.
  91.       */
  92.      if (window == RootWindow(dpy, scr))
  93.       Leave(FALSE)
  94.         
  95.      /*
  96.       * Change the cursor.
  97.       */
  98.      grab_pointer();
  99.      
  100.      /*
  101.       * Gather info on the event window.
  102.       */
  103.      status = XGetWindowAttributes(dpy, window, &window_info);
  104.      if (status == FAILURE)
  105.       Leave(FALSE)
  106.  
  107.      /*
  108.       * Initialize movement variables.
  109.       */
  110.      prev_x = cur_x = x;
  111.      prev_y = cur_y = y;
  112.      win_x = window_info.x;
  113.      win_y = window_info.y;
  114.      rbound = ScreenWidth - (window_info.width + window_info.border_width);
  115.      dbound = ScreenHeight - (window_info.height + window_info.border_width);
  116.  
  117.      /*
  118.       * Main loop.
  119.       */
  120.      while (TRUE) {
  121.       
  122.       /*
  123.        * Check to see if we have a change in mouse button status.
  124.        * This is how we get out of this "while" loop.
  125.        */
  126.       if (XCheckMaskEvent(dpy,
  127.                   ButtonPressMask | ButtonReleaseMask,
  128.                   &button_event)) {
  129.            
  130.            /*
  131.         * If the button event was something other than the
  132.         * release of the original button pressed, then move the
  133.         * window back to where it was originally.
  134.         */
  135.            if ((button_event.type != ButtonRelease) ||
  136.            (((XButtonReleasedEvent *)&button_event)->button
  137.             != button)) {
  138.             ResetCursor(button);
  139.             XMoveWindow(dpy, window, window_info.x, window_info.y);
  140.            }
  141.            ungrab_pointer();
  142.            Leave(TRUE);
  143.       }
  144.       
  145.       /*
  146.        * Take care of all the little things that have changed; 
  147.        * i.e., move the window, if necessary.
  148.        */
  149.       XQueryPointer(dpy, RootWindow(dpy, scr), 
  150.             &root, &sub_window, &root_x, &root_y, &cur_x, &cur_y, 
  151.             &ptrmask);
  152.       if ((cur_x != prev_x) || (cur_y != prev_y)) {
  153.            win_x += (cur_x - prev_x);
  154.            win_y += (cur_y - prev_y);
  155. #ifdef titan /* align to 5x4 */
  156.            win_x = ((win_x + 3) / 5) * 5;
  157.            win_y = ((win_y + 2) / 4) * 4;
  158. #endif /* titan */
  159.            if (Wall) {
  160.             if (win_x < 0)
  161.              win_x = 0;
  162.             else if (win_x > rbound)
  163.              win_x = rbound;
  164.             if (win_y < 0)
  165.              win_y = 0;
  166.             else if (win_y > dbound)
  167.              win_y = dbound;
  168.             }
  169.            XMoveWindow(dpy, window, win_x, win_y);
  170.            prev_x = cur_x;
  171.            prev_y = cur_y;
  172.       }
  173.      }
  174. }
  175.