|
|
1.1 ! root 1: #include <X11/copyright.h> ! 2: ! 3: /* ! 4: * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. ! 5: * ! 6: * All Rights Reserved ! 7: * ! 8: * Permission to use, copy, modify, and distribute this software and its ! 9: * documentation for any purpose and without fee is hereby granted, ! 10: * provided that the above copyright notice appear in all copies and that ! 11: * both that copyright notice and this permission notice appear in ! 12: * supporting documentation, and that the name of Digital Equipment ! 13: * Corporation not be used in advertising or publicity pertaining to ! 14: * distribution of the software without specific, written prior permission. ! 15: * ! 16: * ! 17: * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ! 18: * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ! 19: * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 20: * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ! 21: * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ! 22: * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ! 23: * SOFTWARE. ! 24: */ ! 25: ! 26: /* ! 27: * MODIFICATION HISTORY ! 28: * ! 29: * 000 -- M. Gancarz, DEC Ultrix Engineering Group ! 30: * 001 -- Loretta Guarino Reid, DEC Ultrix Engineering Group, ! 31: * Western Software Lab. Port to X11. ! 32: */ ! 33: ! 34: #ifndef lint ! 35: static char *sccsid = "%W% %G%"; ! 36: #endif ! 37: ! 38: #include "uwm.h" ! 39: ! 40: Bool NewIconify(window, mask, button, x, y) ! 41: Window window; /* Event window. */ ! 42: int mask; /* Button/key mask. */ ! 43: int button; /* Button event detail. */ ! 44: int x, y; /* Event mouse position. */ ! 45: { ! 46: XWindowAttributes window_info; /* Event window info. */ ! 47: XWindowAttributes icon_info; /* Icon window info. */ ! 48: char *name; /* Event window name. */ ! 49: int mse_x, mse_y; /* Mouse X and Y coordinates. */ ! 50: int icon_x, icon_y; /* Icon U. L. X and Y coordinates. */ ! 51: int icon_w, icon_h; /* Icon width and height. */ ! 52: int icon_bdr; /* Icon border width. */ ! 53: int prev_x; /* Previous event window X location. */ ! 54: int prev_y; /* Previous event window Y location. */ ! 55: int cur_x; /* Current event window X location. */ ! 56: int cur_y; /* Current event window Y location. */ ! 57: int root_x; /* Root window X location. */ ! 58: int root_y; /* Root window Y location. */ ! 59: int ulx, uly; /* Event window upper left X and Y. */ ! 60: int lrx, lry; /* Event window lower right X and Y. */ ! 61: int init_ulx, init_uly; /* Init window upper left X and Y. */ ! 62: int init_lrx, init_lry; /* Init window lower right X and Y. */ ! 63: int num_vectors; /* Number of vectors in box. */ ! 64: int status; /* Routine call return status. */ ! 65: int ptrmask; /* pointer query state. */ ! 66: Window root; /* Mouse root window. */ ! 67: Window icon; /* Icon window. */ ! 68: Window sub_win; /* Mouse position sub-window. */ ! 69: XEvent button_event; /* Button event packet. */ ! 70: XSegment box[MAX_BOX_VECTORS]; /* Box vertex buffer. */ ! 71: XSegment 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(dpy, scr)) ! 78: return(FALSE); ! 79: ! 80: /* ! 81: * Change the cursor to the icon cursor. ! 82: */ ! 83: XChangeActivePointerGrab(dpy, EVENTMASK, ArrowCrossCursor, CurrentTime); ! 84: ! 85: /* ! 86: * Clear the vector buffers. ! 87: */ ! 88: bzero(box, sizeof(box)); ! 89: if (Zap) bzero(zap, sizeof(zap)); ! 90: ! 91: /* ! 92: * Get info on the event window. ! 93: */ ! 94: status = XGetWindowAttributes(dpy, window, &window_info); ! 95: if (status == FAILURE) return(FALSE); ! 96: ! 97: /* ! 98: * Are we iconifying or de-iconifying? ! 99: */ ! 100: if (!IsIcon(window, x, y, FALSE, &icon)) { ! 101: ! 102: /* ! 103: * Window => Icon (Iconifying). ! 104: */ ! 105: /* ! 106: * If an icon window doesn't exist for the event window, then ! 107: * make one. ! 108: */ ! 109: iconifying = TRUE; ! 110: } ! 111: else { ! 112: ! 113: /* ! 114: * Icon => Window (DeIconifying). ! 115: */ ! 116: ! 117: /* ! 118: * We call the normal window the "icon" window only to simplify ! 119: * the code later on in the function. ! 120: */ ! 121: iconifying = FALSE; ! 122: } ! 123: /* ! 124: * Get info on the icon window. ! 125: */ ! 126: status = XGetWindowAttributes(dpy, icon, &icon_info); ! 127: if (status == FAILURE) return(FALSE); ! 128: ! 129: /* ! 130: * Determine the height, width, and borderwidth of the icon. ! 131: */ ! 132: icon_h = icon_info.height; ! 133: icon_w = icon_info.width; ! 134: icon_bdr = icon_info.border_width; ! 135: ! 136: ! 137: /* ! 138: * Initialize the movement variables. ! 139: */ ! 140: init_ulx = ulx = x - (icon_w >> 1) - icon_bdr; ! 141: init_uly = uly = y - (icon_h >> 1) - icon_bdr; ! 142: init_lrx = lrx = x + (icon_w >> 1) + icon_bdr - 1; ! 143: init_lry = lry = y + (icon_h >> 1) + icon_bdr - 1; ! 144: prev_x = x; ! 145: prev_y = y; ! 146: ! 147: ! 148: /* ! 149: * Store the box. ! 150: */ ! 151: if (Grid) ! 152: num_vectors = StoreGridBox(box, ulx, uly, lrx, lry); ! 153: else num_vectors = StoreBox(box, ulx, uly, lrx, lry); ! 154: ! 155: /* ! 156: * Freeze the server, if requested by the user. ! 157: * This results in a solid box instead of a flickering one. ! 158: */ ! 159: if (Freeze) ! 160: XGrabServer(dpy); ! 161: ! 162: /* ! 163: * Process any outstanding events before drawing the box. ! 164: */ ! 165: while (QLength(dpy) > 0) { ! 166: XPeekEvent(dpy, &button_event); ! 167: if (((XAnyEvent *)&button_event)->window == RootWindow(dpy, scr)) ! 168: break; ! 169: GetButton(&button_event); ! 170: } ! 171: ! 172: /* ! 173: * Draw the box. ! 174: */ ! 175: DrawBox(); ! 176: if (Freeze) ! 177: Frozen = window; ! 178: ! 179: /* ! 180: * We spin our wheels here looking for mouse movement or a change ! 181: * in the status of the buttons. ! 182: */ ! 183: while (TRUE) { ! 184: ! 185: /* ! 186: * Check to see if we have a change in mouse button status. ! 187: * This is how we get out of this "while" loop. ! 188: */ ! 189: if (XPending(dpy) && GetButton(&button_event)) { ! 190: /* ! 191: * Process the pending events, this sequence is the only ! 192: * way out of the loop and the routine. ! 193: */ ! 194: ! 195: if ((button_event.type != ButtonPress) && ! 196: (button_event.type != ButtonRelease)) { ! 197: continue; /* spurious menu event... */ ! 198: } ! 199: ! 200: /* ! 201: * If we froze the server, then erase the last lines drawn. ! 202: */ ! 203: if (Freeze) { ! 204: DrawBox(); ! 205: Frozen = (Window)0; ! 206: XUngrabServer(dpy); ! 207: } ! 208: ! 209: /* ! 210: * Save the mouse cursor location. ! 211: */ ! 212: if (button_event.type == ButtonPress || ! 213: button_event.type == ButtonRelease) { ! 214: mse_x = ((XButtonEvent *)&button_event)->x; ! 215: mse_y = ((XButtonEvent *)&button_event)->y; ! 216: break; ! 217: } ! 218: } ! 219: else { ! 220: /* ! 221: * Continue to track the mouse until we get a change ! 222: * in button status. ! 223: */ ! 224: XQueryPointer(dpy, RootWindow(dpy, scr), ! 225: &root, &sub_win, &root_x, &root_y, &cur_x, &cur_y, ! 226: &ptrmask); ! 227: ! 228: /* ! 229: * If the mouse has moved, then make sure the box follows it. ! 230: */ ! 231: if ((cur_x != prev_x) || (cur_y != prev_y)) { ! 232: ! 233: /* ! 234: * If we've frozen the server, then erase the old box first! ! 235: */ ! 236: if (Freeze) ! 237: DrawBox(); ! 238: ! 239: /* ! 240: * Set the new box position. ! 241: */ ! 242: ulx += cur_x - prev_x; ! 243: uly += cur_y - prev_y; ! 244: lrx += cur_x - prev_x; ! 245: lry += cur_y - prev_y; ! 246: ! 247: /* ! 248: * Calculate the vectors for the new box. ! 249: */ ! 250: if (Grid) ! 251: num_vectors = StoreGridBox(box, ulx, uly, lrx, lry); ! 252: else num_vectors = StoreBox(box, ulx, uly, lrx, lry); ! 253: ! 254: /* ! 255: * Draw the new box. ! 256: */ ! 257: if (Freeze) ! 258: DrawBox(); ! 259: } ! 260: ! 261: /* ! 262: * Save the old box position. ! 263: */ ! 264: prev_x = cur_x; ! 265: prev_y = cur_y; ! 266: ! 267: /* ! 268: * If server is not frozen, then draw the "flicker" box. ! 269: */ ! 270: if (!Freeze) { ! 271: DrawBox(); ! 272: DrawBox(); ! 273: } ! 274: } ! 275: } ! 276: ! 277: /* ! 278: * If the button is not a button release of the same button pressed, ! 279: * then abort the operation. ! 280: */ ! 281: if ((button_event.type != ButtonRelease) || ! 282: (((XButtonReleasedEvent *)&button_event)->button != button)) { ! 283: ResetCursor(button); ! 284: return(TRUE); ! 285: } ! 286: ! 287: /* ! 288: * If we are here we have committed to iconifying/deiconifying. ! 289: */ ! 290: ! 291: /* ! 292: * Determine the coordinates of the icon or window; ! 293: * normalize the window or icon coordinates if the user so desires. ! 294: */ ! 295: icon_x = mse_x - (icon_w >> 1) - icon_bdr; ! 296: icon_y = mse_y - (icon_h >> 1) - icon_bdr; ! 297: if ((NIcon && iconifying) || (NWindow && !iconifying)) { ! 298: if (icon_x < 0) icon_x = 0; ! 299: if (icon_y < 0) icon_y = 0; ! 300: if ((icon_x - 1 + icon_w + (icon_bdr << 1)) > ScreenWidth) { ! 301: icon_x = ScreenWidth - icon_w - (icon_bdr << 1) + 1; ! 302: } ! 303: if ((icon_y - 1 + icon_h + (icon_bdr << 1)) > ScreenHeight) { ! 304: icon_y = ScreenHeight - icon_h - (icon_bdr << 1) + 1; ! 305: } ! 306: } ! 307: ! 308: /* ! 309: * Move the window into place. ! 310: */ ! 311: XMoveWindow(dpy, icon, icon_x, icon_y); ! 312: ! 313: /* ! 314: * Map the icon window. ! 315: */ ! 316: XMapRaised(dpy, icon); ! 317: if (!iconifying) XRemoveFromSaveSet(dpy, icon); ! 318: ! 319: if (Zap) { ! 320: num_vectors = StoreZap(zap, window_info.x, window_info.y, ! 321: window_info.x + window_info.width + ! 322: (window_info.border_width << 1), ! 323: window_info.y + window_info.height + ! 324: (window_info.border_width << 1), ! 325: ulx, uly, lrx, lry); ! 326: DrawZap(); ! 327: DrawZap(); ! 328: } ! 329: ! 330: /* ! 331: * Unmap the event window. ! 332: */ ! 333: if (iconifying) XAddToSaveSet(dpy, window); ! 334: XUnmapWindow(dpy, window); ! 335: return(TRUE); ! 336: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.