Annotation of 43BSDTahoe/new/X/uwm/NewIconify.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char *rcsid_NewIconify_c = "$Header: NewIconify.c,v 10.5 86/11/19 16:24:13 jg Rel $";
        !             3: #endif lint
        !             4: 
        !             5: /*
        !             6:  *                     COPYRIGHT 1985, 1986
        !             7:  *                DIGITAL EQUIPMENT CORPORATION
        !             8:  *                    MAYNARD, MASSACHUSETTS
        !             9:  *                     ALL RIGHTS RESERVED.
        !            10:  *
        !            11:  * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
        !            12:  * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
        !            13:  * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITIBILITY OF THIS SOFTWARE FOR
        !            14:  * ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
        !            15:  *
        !            16:  * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT RIGHTS,
        !            17:  * APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN ADDITION TO THAT
        !            18:  * SET FORTH ABOVE.
        !            19:  *
        !            20:  *
        !            21:  * Permission to use, copy, modify, and distribute this software and its
        !            22:  * documentation for any purpose and without fee is hereby granted, provided
        !            23:  * that the above copyright notice appear in all copies and that both that
        !            24:  * copyright notice and this permission notice appear in supporting documentation,
        !            25:  * and that the name of Digital Equipment Corporation not be used in advertising
        !            26:  * or publicity pertaining to distribution of the software without specific, 
        !            27:  * written prior permission.
        !            28:  *
        !            29:  */
        !            30: 
        !            31: 
        !            32: /*
        !            33:  * MODIFICATION HISTORY
        !            34:  *
        !            35:  * 000 -- M. Gancarz, DEC Ultrix Engineering Group
        !            36:  */
        !            37: 
        !            38: #ifndef lint
        !            39: static char *sccsid = "@(#)NewIconify.c        3.8     1/24/86";
        !            40: #endif
        !            41: 
        !            42: #include "uwm.h"
        !            43: 
        !            44: Bool NewIconify(window, mask, button, x, y)
        !            45: Window window;                          /* Event window. */
        !            46: int mask;                               /* Button/key mask. */
        !            47: short button;                           /* Button event detail. */
        !            48: int x, y;                               /* Event mouse position. */
        !            49: {
        !            50:     register WindowInfo window_info;   /* Event window info. */
        !            51:     register WindowInfo icon_info;     /* Icon window info. */
        !            52:     char *name;                                /* Event window name. */
        !            53:     int mse_x, mse_y;                  /* Mouse X and Y coordinates. */
        !            54:     int icon_x, icon_y;                        /* Icon U. L. X and Y coordinates. */
        !            55:     int icon_w, icon_h;                        /* Icon width and height. */
        !            56:     int icon_bdr;                      /* Icon border width. */
        !            57:     int prev_x;                                /* Previous event window X location. */
        !            58:     int prev_y;                                /* Previous event window Y location. */
        !            59:     int cur_x;                         /* Current event window X location. */
        !            60:     int cur_y;                         /* Current event window Y location. */
        !            61:     int ulx, uly;                      /* Event window upper left X and Y. */
        !            62:     int lrx, lry;                      /* Event window lower right X and Y. */
        !            63:     int init_ulx, init_uly;            /* Init window upper left X and Y. */
        !            64:     int init_lrx, init_lry;            /* Init window lower right X and Y. */
        !            65:     int num_vectors;                   /* Number of vectors in box. */
        !            66:     int status;                                /* Routine call return status. */
        !            67:     Window icon;                       /* Icon window. */
        !            68:     Window sub_win;                    /* Mouse position sub-window. */
        !            69:     XButtonEvent button_event;         /* Button event packet. */
        !            70:     Vertex box[MAX_BOX_VECTORS];       /* Box vertex buffer. */
        !            71:     Vertex zap[MAX_ZAP_VECTORS];       /* Zap effect vertex buffer. */
        !            72:     Bool iconifying;                   /* Are we iconifying? */
        !            73: 
        !            74:     /*
        !            75:      * Do not lower or iconify the root window.
        !            76:      */
        !            77:     if (window == RootWindow)
        !            78:         return(FALSE);
        !            79: 
        !            80:     /*
        !            81:      * Change the cursor to the icon cursor.
        !            82:      */
        !            83:     status = XGrabButton(RootWindow, ArrowCrossCursor, mask, EVENTMASK);
        !            84:     if (status == FAILURE)
        !            85:         Error("NewIconify -> Unable to grab button and change cursor.");
        !            86: 
        !            87:     /*
        !            88:      * Clear the vector buffers.
        !            89:      */
        !            90:     bzero(box, sizeof(box));
        !            91:     if (Zap) bzero(zap, sizeof(zap));
        !            92:     
        !            93:     /*
        !            94:      * Get info on the event window.
        !            95:      */
        !            96:     status = XQueryWindow(window, &window_info);
        !            97:     if (status == FAILURE) return(FALSE);
        !            98: 
        !            99:     /*
        !           100:      * Are we iconifying or de-iconifying?
        !           101:      */
        !           102:     if (window_info.type != IsIcon) {
        !           103: 
        !           104:         /*
        !           105:          * Window => Icon (Iconifying).
        !           106:          */
        !           107:         /*
        !           108:          * If an icon window doesn't exist for the event window, then
        !           109:          * make one.
        !           110:          */
        !           111:         if (window_info.assoc_wind == 0) {
        !           112: 
        !           113:            /*
        !           114:              * Set the icon border width.
        !           115:              */ 
        !           116:             icon_bdr = IBorderWidth;
        !           117: 
        !           118:             /*
        !           119:              * Determine the size of the icon window.
        !           120:              */
        !           121:             status = XFetchName(window, &name);
        !           122:             if (status == FAILURE) return(FALSE);
        !           123:             icon_h = IFontInfo.height + (VIconPad << 1);
        !           124:             icon_w = XQueryWidth(name, IFont);
        !           125:             if (icon_w == 0) icon_w = icon_h;
        !           126:             else icon_w += (HIconPad << 1);
        !           127: 
        !           128: 
        !           129:             /*
        !           130:              * Create the icon window.
        !           131:              */
        !           132:             icon = XCreateWindow(RootWindow, x + (icon_w >> 1),
        !           133:                                  y + (icon_h >> 1), icon_w, icon_h,
        !           134:                                  icon_bdr, IBorder, IBackground);
        !           135:             if (icon == FAILURE) return(FALSE);
        !           136: 
        !           137:             /*
        !           138:              * Use the text cursor whenever the mouse is in the icon window.
        !           139:              */
        !           140:             XDefineCursor(icon, TextCursor);
        !           141: 
        !           142:             /*
        !           143:              * Select "key pressed", "window exposure" and "unmap window"
        !           144:              * events for the icon window.
        !           145:              */
        !           146:             XSelectInput(icon, (KeyPressed | ExposeWindow | UnmapWindow));
        !           147: 
        !           148:             /*
        !           149:              * Set the event window's icon window to be the new icon window.
        !           150:              */
        !           151:             XSetIconWindow(window, icon);
        !           152:         }
        !           153:         else {
        !           154:             /*
        !           155:              * If we already have an icon window all we have to do is
        !           156:              * retrieve the info on it and move it into place.
        !           157:              */
        !           158:             icon = window_info.assoc_wind;
        !           159: 
        !           160:             /*
        !           161:              * Get info on the icon window.
        !           162:              */
        !           163:             status = XQueryWindow(icon, &icon_info);
        !           164:             if (status == FAILURE) return(FALSE);
        !           165: 
        !           166:             /*
        !           167:              * Determine the height, width, and borderwidth of the icon.
        !           168:              */
        !           169:             icon_h = icon_info.height;
        !           170:             icon_w = icon_info.width;
        !           171:             icon_bdr = icon_info.bdrwidth;
        !           172:         }
        !           173: 
        !           174:         iconifying = TRUE;
        !           175:     }
        !           176:     else {
        !           177: 
        !           178:         /*
        !           179:          * Icon => Window (DeIconifying).
        !           180:          */
        !           181:         /*
        !           182:          * If the window is gone, destroy the icon and return.
        !           183:          */
        !           184:         if (window_info.assoc_wind == 0) {
        !           185:             XDestroyWindow(window);
        !           186:             Grab(mask);
        !           187:             return(FALSE);
        !           188:         }
        !           189: 
        !           190:         /*
        !           191:          * We call the normal window the "icon" window only to simplify
        !           192:          * the code later on in the function.
        !           193:          */
        !           194:         icon = window_info.assoc_wind;
        !           195: 
        !           196:         /*
        !           197:          * Get info on the icon window.
        !           198:          */
        !           199:         status = XQueryWindow(icon, &icon_info);
        !           200:         if (status == FAILURE) return(FALSE);
        !           201: 
        !           202:         /*
        !           203:          * Determine the height, width, and borderwidth of the icon.
        !           204:          */
        !           205:         icon_h = icon_info.height;
        !           206:         icon_w = icon_info.width;
        !           207:         icon_bdr = icon_info.bdrwidth;
        !           208: 
        !           209:         iconifying = FALSE;
        !           210:     }
        !           211: 
        !           212:     /*
        !           213:      * Initialize the movement variables.
        !           214:      */
        !           215:     init_ulx = ulx = x - (icon_w >> 1) - icon_bdr;
        !           216:     init_uly = uly = y - (icon_h >> 1) - icon_bdr;
        !           217:     init_lrx = lrx = x + (icon_w >> 1) + icon_bdr - 1;
        !           218:     init_lry = lry = y + (icon_h >> 1) + icon_bdr - 1;
        !           219:     prev_x = x;
        !           220:     prev_y = y;
        !           221: 
        !           222: 
        !           223:     /*
        !           224:      * Store the box.
        !           225:      */
        !           226:     if (Grid)
        !           227:         num_vectors = StoreGridBox(box, ulx, uly, lrx, lry);
        !           228:     else num_vectors = StoreBox(box, ulx, uly, lrx, lry);
        !           229: 
        !           230:     /*
        !           231:      * Freeze the server, if requested by the user.
        !           232:      * This results in a solid box instead of a flickering one.
        !           233:      */
        !           234:     if (Freeze)
        !           235:         XGrabServer();
        !           236: 
        !           237:     /*
        !           238:      * Process any outstanding events before drawing the box.
        !           239:      */
        !           240:     while (QLength() > 0) {
        !           241:         XPeekEvent(&button_event);
        !           242:         if (button_event.window == RootWindow)
        !           243:             break;
        !           244:         GetButton(&button_event);
        !           245:     }
        !           246: 
        !           247:     /*
        !           248:      * Draw the box.
        !           249:      */
        !           250:     DrawBox();
        !           251:     if (Freeze)
        !           252:         Frozen = window;
        !           253: 
        !           254:     /*
        !           255:      * We spin our wheels here looking for mouse movement or a change
        !           256:      * in the status of the buttons.
        !           257:      */
        !           258:     while (TRUE) {
        !           259: 
        !           260:        /*
        !           261:         * Check to see if we have a change in mouse button status.
        !           262:         * This is how we get out of this "while" loop.
        !           263:         */
        !           264:        if (XPending() && GetButton(&button_event)) {
        !           265:             /*
        !           266:              * Process the pending events, this sequence is the only
        !           267:              * way out of the loop and the routine.
        !           268:              */
        !           269: 
        !           270:             /*
        !           271:              * If we froze the server, then erase the last lines drawn.
        !           272:              */
        !           273:             if (Freeze) {
        !           274:                 DrawBox();
        !           275:                 Frozen = (Window)0;
        !           276:                 XUngrabServer();
        !           277:             }
        !           278: 
        !           279:             /*
        !           280:              * Save the mouse cursor location.
        !           281:              */
        !           282:            mse_x = button_event.x;
        !           283:            mse_y = button_event.y;
        !           284:            break;
        !           285:        }
        !           286:        else {
        !           287:            /*
        !           288:             * Continue to track the mouse until we get a change
        !           289:              * in button status.
        !           290:             */
        !           291:             XUpdateMouse(RootWindow, &cur_x, &cur_y, &sub_win);
        !           292: 
        !           293:             /*
        !           294:              * If the mouse has moved, then make sure the box follows it.
        !           295:              */
        !           296:             if ((cur_x != prev_x) || (cur_y != prev_y)) {
        !           297: 
        !           298:                 /*
        !           299:                  * If we've frozen the server, then erase the old box first!
        !           300:                  */
        !           301:                 if (Freeze)
        !           302:                     DrawBox();
        !           303:     
        !           304:                 /*
        !           305:                  * Set the new box position.
        !           306:                  */
        !           307:                 ulx += cur_x - prev_x;
        !           308:                 uly += cur_y - prev_y;
        !           309:                 lrx += cur_x - prev_x;
        !           310:                 lry += cur_y - prev_y;
        !           311:     
        !           312:                 /*
        !           313:                  * Calculate the vectors for the new box.
        !           314:                  */
        !           315:                 if (Grid)
        !           316:                     num_vectors = StoreGridBox(box, ulx, uly, lrx, lry);
        !           317:                 else num_vectors = StoreBox(box, ulx, uly, lrx, lry);
        !           318:     
        !           319:                 /*
        !           320:                  * Draw the new box.
        !           321:                  */
        !           322:                 if (Freeze)
        !           323:                     DrawBox();
        !           324:             }
        !           325: 
        !           326:             /*
        !           327:              * Save the old box position.
        !           328:              */
        !           329:             prev_x = cur_x;
        !           330:             prev_y = cur_y;
        !           331: 
        !           332:             /*
        !           333:              * If server is not frozen, then draw the "flicker" box.
        !           334:              */
        !           335:             if (!Freeze) {
        !           336:                 DrawBox();
        !           337:                 DrawBox();
        !           338:             }
        !           339:        }
        !           340:     }
        !           341: 
        !           342:     /*
        !           343:      * Restore the main cursor.
        !           344:      */
        !           345:     Grab(mask);
        !           346: 
        !           347:     /*
        !           348:      * If the button is not a button release of the same button pressed,
        !           349:      * then abort the operation.
        !           350:      */
        !           351:     if ((button_event.type != ButtonReleased) ||
        !           352:         ((button_event.detail & ValueMask) != button)) {
        !           353:            return(TRUE);
        !           354:     }
        !           355: 
        !           356:     /*
        !           357:      * If we are here we have committed to iconifying/deiconifying.
        !           358:      */
        !           359: 
        !           360:     /*
        !           361:      * Determine the coordinates of the icon or window;
        !           362:      * normalize the window or icon coordinates if the user so desires.
        !           363:      */
        !           364:     icon_x = mse_x - (icon_w >> 1) - icon_bdr;
        !           365:     icon_y = mse_y - (icon_h >> 1) - icon_bdr;
        !           366:     if ((NIcon && iconifying) || (NWindow && !iconifying)) {
        !           367:         if (icon_x < 0) icon_x = 0;
        !           368:         if (icon_y < 0) icon_y = 0;
        !           369:         if ((icon_x - 1 + icon_w + (icon_bdr << 1)) > ScreenWidth) {
        !           370:             icon_x = ScreenWidth - icon_w - (icon_bdr << 1) + 1;
        !           371:         }
        !           372:         if ((icon_y - 1 + icon_h + (icon_bdr << 1)) > ScreenHeight) {
        !           373:             icon_y = ScreenHeight - icon_h - (icon_bdr << 1) + 1;
        !           374:         }
        !           375:     }
        !           376: 
        !           377:     /*
        !           378:      * Move the window into place.
        !           379:      */
        !           380:     XMoveWindow(icon, icon_x, icon_y);
        !           381: 
        !           382:     /*
        !           383:      * Map the icon window.
        !           384:      */
        !           385:     XMapWindow(icon);
        !           386: 
        !           387:     if (Zap) {
        !           388:         num_vectors = StoreZap(zap, window_info.x, window_info.y,
        !           389:                                window_info.x + window_info.width +
        !           390:                                (window_info.bdrwidth << 1),
        !           391:                                window_info.y + window_info.height +
        !           392:                                (window_info.bdrwidth << 1),
        !           393:                                ulx, uly, lrx, lry);
        !           394:         DrawZap();
        !           395:         DrawZap();
        !           396:     }
        !           397: 
        !           398:     /*
        !           399:      * Unmap the event window.
        !           400:      */
        !           401:     XUnmapWindow(window);
        !           402:     return(TRUE);
        !           403: }

unix.superglobalmegacorp.com

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