Annotation of researchv9/X11/src/X.V11R1/clients/uwm/Move.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char *rcsid_Move_c = "$Header: Move.c,v 1.8 87/08/25 11:24:56 swick Exp $";
        !             3: #endif lint
        !             4: 
        !             5: #include <X11/copyright.h>
        !             6: 
        !             7: /*
        !             8:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
        !             9:  *
        !            10:  *                         All Rights Reserved
        !            11:  *
        !            12:  * Permission to use, copy, modify, and distribute this software and its
        !            13:  * documentation for any purpose and without fee is hereby granted,
        !            14:  * provided that the above copyright notice appear in all copies and that
        !            15:  * both that copyright notice and this permission notice appear in
        !            16:  * supporting documentation, and that the name of Digital Equipment
        !            17:  * Corporation not be used in advertising or publicity pertaining to
        !            18:  * distribution of the software without specific, written prior permission.
        !            19:  *
        !            20:  *
        !            21:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            22:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            23:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            24:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            25:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            26:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            27:  * SOFTWARE.
        !            28:  */
        !            29: 
        !            30: /*
        !            31:  * MODIFICATION HISTORY
        !            32:  *
        !            33:  * 000 -- M. Gancarz, DEC Ultrix Engineering Group
        !            34:  * 001 -- Loretta Guarino Reid, DEC Ultrix Engineering Group, 
        !            35:  *       Western Software Lab. Port to X11
        !            36:  */
        !            37: 
        !            38: #ifndef lint
        !            39: static char *sccsid = "@(#)Move.c      3.8     1/24/86";
        !            40: #endif
        !            41: 
        !            42: #include "uwm.h"
        !            43: 
        !            44: Bool Move(window, mask, button, x, y)
        !            45: Window window;                         /* Event window. */
        !            46: int mask;                              /* Button/key mask. */
        !            47: int button;                            /* Button event detail. */
        !            48: int x, y;                              /* Event mouse position. */
        !            49: {
        !            50:     register int prev_x;               /* Previous event window X location. */
        !            51:     register int prev_y;               /* Previous event window Y location. */
        !            52:     XWindowAttributes window_info;     /* Event window information. */
        !            53:     int cur_x;                         /* Current event window X location. */
        !            54:     int cur_y;                         /* Current event window Y location. */
        !            55:     int root_x;                                /* Root window X location. */
        !            56:     int root_y;                                /* Root window Y location. */
        !            57:     int ulx, uly;                      /* Event window upper left X and Y. */
        !            58:     int lrx, lry;                      /* Event window lower right X and Y. */
        !            59:     int init_ulx, init_uly;            /* Init window upper left X and Y. */
        !            60:     int init_lrx, init_lry;            /* Init window lower right X and Y. */
        !            61:     int num_vectors;                   /* Number of vectors in box. */
        !            62:     int ptrmask;                       /* state of ptr when queried */
        !            63:     Window sub_window;                 /* Query mouse event sub-window. */
        !            64:     Window root;                       /* Query mouse event root. */
        !            65:     XEvent button_event;               /* Button event packet. */
        !            66:     XSegment box[MAX_BOX_VECTORS];     /* Box vertex buffer. */
        !            67:     XSegment zap[MAX_ZAP_VECTORS];     /* Zap effect verted buffer. */
        !            68: 
        !            69:     /*
        !            70:      * Do not try to move the root window.
        !            71:      */
        !            72:     if (window == RootWindow(dpy, scr))
        !            73:         return(FALSE);
        !            74: 
        !            75:     /*
        !            76:      * Change the cursor.
        !            77:      */
        !            78:     XChangeActivePointerGrab(dpy, EVENTMASK, ArrowCrossCursor, CurrentTime);
        !            79: 
        !            80:     /*
        !            81:      * Clear the vector buffers.
        !            82:      */
        !            83:     bzero(box, sizeof(box));
        !            84:     if (Zap) bzero(zap, sizeof(zap));
        !            85:     
        !            86:     /*
        !            87:      * Gather info on the event window.
        !            88:      */
        !            89:     status = XGetWindowAttributes(dpy, window, &window_info);
        !            90:     if (status == FAILURE) return(FALSE);
        !            91: 
        !            92:     /*
        !            93:      * Initialize movement variables.
        !            94:      */
        !            95:     init_ulx = ulx = window_info.x;
        !            96:     init_uly = uly = window_info.y;
        !            97:     init_lrx = lrx = window_info.x + window_info.width +
        !            98:                      (window_info.border_width << 1) - 1;
        !            99:     init_lry = lry = window_info.y + window_info.height +
        !           100:                      (window_info.border_width << 1) - 1;
        !           101: 
        !           102:     /*
        !           103:      * Store the box.
        !           104:      */
        !           105:     if (Grid)
        !           106:         num_vectors = StoreGridBox(box, ulx, uly, lrx, lry);
        !           107:     else num_vectors = StoreBox(box, ulx, uly, lrx, lry);
        !           108: 
        !           109:     /*
        !           110:      * Initialize the previous location variables.
        !           111:      */
        !           112:     prev_x = x;
        !           113:     prev_y = y;
        !           114: 
        !           115:     /*
        !           116:      * Freeze the server, if requested by the user.
        !           117:      * This results in a solid box instead of a flickering one.
        !           118:      */
        !           119:     if (Freeze) XGrabServer(dpy);
        !           120: 
        !           121:     /*
        !           122:      * Process any pending exposure events before drawing the box.
        !           123:      */
        !           124:     while (QLength(dpy) > 0) {
        !           125:         XPeekEvent(dpy, &button_event);
        !           126:         if (((XAnyEvent *)&button_event)->window == RootWindow(dpy, scr))
        !           127:             break;
        !           128:         GetButton(&button_event);
        !           129:     }
        !           130: 
        !           131:     /*
        !           132:      * Now draw the box.
        !           133:      */
        !           134:     DrawBox();
        !           135:     Frozen = window;
        !           136: 
        !           137:     /*
        !           138:      * Main loop.
        !           139:      */
        !           140:     while (TRUE) {
        !           141: 
        !           142:        /*
        !           143:         * Check to see if we have a change in mouse button status.
        !           144:         * This is how we get out of this "while" loop.
        !           145:         */
        !           146:        if (XPending(dpy) && GetButton(&button_event)) {
        !           147:            /*
        !           148:             * Process the pending events, this sequence is the only
        !           149:             * way out of the loop and the routine.
        !           150:             */
        !           151: 
        !           152:             if ((button_event.type != ButtonPress) && 
        !           153:                (button_event.type != ButtonRelease)) {
        !           154:                 continue; /* spurious menu event... */
        !           155:             }
        !           156: 
        !           157:             /*
        !           158:              * If we froze the server, then erase the last lines drawn.
        !           159:              */
        !           160:             if (Freeze) {
        !           161:                 DrawBox();
        !           162:                 Frozen = (Window)0;
        !           163:                 XUngrabServer(dpy);
        !           164:             }
        !           165: 
        !           166:            if ((button_event.type == ButtonRelease) &&
        !           167:                (((XButtonReleasedEvent *)&button_event)->button == button)) {
        !           168: 
        !           169:                /*
        !           170:                 * The button was released, so move the window.
        !           171:                 */
        !           172: 
        !           173:                if (Zap) {
        !           174:                     num_vectors = StoreZap(zap,
        !           175:                                            init_ulx, init_uly,
        !           176:                                            init_lrx, init_lry,
        !           177:                                            ulx, uly,
        !           178:                                            lrx, lry);
        !           179:                     DrawZap();
        !           180:                     DrawZap();
        !           181:                 }
        !           182:                XMoveWindow(dpy, window, ulx, uly);
        !           183:                return(TRUE);
        !           184:            }
        !           185:            else {
        !           186: 
        !           187:                /*
        !           188:                 * Some other button event occured, this aborts the
        !           189:                 * current operation.
        !           190:                 */
        !           191: 
        !           192:                ResetCursor(button);
        !           193:                return(TRUE);
        !           194:            }
        !           195:        }
        !           196: 
        !           197:         /*
        !           198:          * Take care of all the little things that have changed.
        !           199:          */
        !           200:         XQueryPointer(dpy, 
        !           201:                      RootWindow(dpy, scr), &root,  &sub_window,
        !           202:                      &root_x, &root_y, &cur_x, &cur_y, &ptrmask);
        !           203:         if ((cur_x != prev_x) || (cur_y != prev_y)) {
        !           204: 
        !           205:             /*
        !           206:              * If we've frozen the server, then erase the old box first!
        !           207:              */
        !           208:             if (Freeze)
        !           209:                 DrawBox();
        !           210: 
        !           211:             /*
        !           212:              * Box position has changed.
        !           213:              */
        !           214:             ulx += cur_x - prev_x;
        !           215:             uly += cur_y - prev_y;
        !           216:             lrx += cur_x - prev_x;
        !           217:             lry += cur_y - prev_y;
        !           218: 
        !           219:             /*
        !           220:              * Box needs to be restored.
        !           221:              */
        !           222:             if (Grid)
        !           223:                 num_vectors = StoreGridBox(box, ulx, uly, lrx, lry);
        !           224:             else num_vectors = StoreBox(box, ulx, uly, lrx, lry);
        !           225: 
        !           226: 
        !           227:             /*
        !           228:              * Draw the new box.
        !           229:              */
        !           230:             if (Freeze)
        !           231:                 DrawBox();
        !           232:        }
        !           233: 
        !           234:        /* 
        !           235:         * Save old box position.
        !           236:         */
        !           237:        prev_x = cur_x;
        !           238:        prev_y = cur_y;
        !           239: 
        !           240:         /*
        !           241:          * If server is not frozen, then draw the "flicker" box.
        !           242:          */
        !           243:         if (!Freeze) {
        !           244:             DrawBox();
        !           245:             DrawBox();
        !           246:         }
        !           247:     }
        !           248: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.