1: #include "wm.h" 2: 3: #include "../cursors/icon.cursor" 4: #include "../cursors/xterm.cursor" 5: #include "../cursors/xterm_mask.cursor" 6: 7: #define solid_vcount (1 + 4*2) /* We're goin' around twice */ 8: #define flash_vcount (1 + 4*4) /* 4 times, if flashing! */ 9: 10: #ifndef lint 11: static char *rcsid_wmsubs_c = "$Header: wmsubs.c,v 10.3 86/02/01 16:02:10 tony Rel $"; 12: #endif 13: 14: int vcount; 15: Vertex solidBox[solid_vcount], flashBox[flash_vcount], *box; 16: 17: int iconHeight; 18: Window sizeWin; 19: int sizeWidth, sizeHeight; 20: int variableWidth; 21: int sizeX, sizeY; /* Where the size window is */ 22: Pixmap behindSize = 0; /* And what it obscures */ 23: 24: Window oldfocus; 25: 26: InitializeWm() 27: { 28: SetUpSizeWindow(); 29: SetUpBox(); 30: StoreWmCursors(); 31: 32: FocusOn(RootWindow); 33: oldfocus = 0; 34: } 35: 36: SetUpSizeWindow() 37: { 38: FontInfo finfo; 39: register int i, minwid, maxwid; 40: short cwid[10]; 41: 42: status = XQueryFont(sizefont, &finfo); 43: if (status == 0) Error("Couldn't query size font in SetUpSizeWindow"); 44: 45: status = XCharWidths("0123456789x", 11, sizefont, cwid); 46: if (status == 0) Error("Couldn't get char widths in SetUpSizeWindow"); 47: 48: minwid = 99999; 49: maxwid = 0; 50: for (i = 0; i <= 10; i++) { 51: if (cwid[i] < minwid) minwid = cwid[i]; 52: else if (cwid[i] > maxwid) maxwid = cwid[i]; 53: } 54: 55: variableWidth = (minwid != maxwid); 56: 57: sizeWidth = 7 * maxwid + 4; 58: sizeHeight = finfo.height + 4; 59: 60: sizeWin = XCreateWindow(RootWindow, 0, 0, 61: sizeWidth - 2, sizeHeight - 2, 62: 1, bgPixmap, fgPixmap); 63: if (sizeWin == 0) Error("Couldn't create sizeWin in SetUpSizeWindow"); 64: 65: status = XQueryFont(iconfont, &finfo); 66: if (status == 0) Error("Couldn't query icon font in SetUpSizeWindow"); 67: 68: iconHeight = finfo.height + 8; 69: } 70: 71: SetUpBox() 72: { 73: register int i; 74: 75: if (freeze) { 76: vcount = solid_vcount; 77: i = solid_vcount - 1; 78: box = solidBox; 79: } else { 80: vcount = flash_vcount; 81: i = flash_vcount - 1; 82: box = flashBox; 83: } 84: 85: box[i--].flags = VertexRelative | VertexDrawLastPoint; 86: while (i > 0) box[i--].flags = VertexRelative; 87: box[0].flags = 0; 88: 89: if (!freeze) box[solid_vcount-1].flags |= VertexDrawLastPoint; 90: } 91: 92: StoreWmCursors() 93: { 94: iconCursor = XCreateCursor(icon_width, icon_height, 95: (caddr_t) icon_bits, (caddr_t) NULL, 96: 8, 8, 97: WhitePixel, BlackPixel, 98: GXcopyInverted); 99: if (iconCursor == 0) { 100: Error("Couldn't store iconCursor in StoreWmCursors"); 101: } 102: textCursor = XCreateCursor(xterm_width, xterm_height, 103: (caddr_t) xterm_bits, (caddr_t) xterm_mask_bits, 104: 8, 8, 105: bgColor, fgColor, 106: GXcopyInverted); 107: if (textCursor == 0) { 108: Error("Couldn't store textCursor in StoreWmCursors"); 109: } 110: } 111: 112: /* ARGSUSED */ 113: 114: Raise(which, loc, w, winfo) 115: int which; 116: Locator loc; 117: Window w; 118: WindowInfo *winfo; 119: { 120: BEvent newbutton; 121: Window neww; 122: 123: if (w == RootWindow) return; 124: 125: GetButton(&newbutton); 126: if (!MatchUp(newbutton, which)) return; 127: 128: InterpretLocatorW(RootWindow, &neww, newbutton.location); 129: if (neww != w) return; 130: 131: if (popup) UnmapPopup(); 132: 133: XRaiseWindow(w); 134: } 135: 136: /* ARGSUSED */ 137: 138: Lower(which, loc, w, winfo) 139: int which; 140: Locator loc; 141: Window w; 142: WindowInfo *winfo; 143: { 144: BEvent newbutton; 145: Window neww; 146: 147: if (w == RootWindow) return; 148: 149: GetButton(&newbutton); 150: if (!MatchUp(newbutton, which)) return; 151: 152: InterpretLocatorW(RootWindow, &neww, newbutton.location); 153: if (neww != w) return; 154: 155: if (popup) UnmapPopup(); 156: 157: XLowerWindow(w); 158: } 159: 160: Move(which, loc, w, winfo) 161: int which; 162: Locator loc; 163: Window w; 164: WindowInfo *winfo; 165: { 166: Window subwindow; 167: BEvent newbutton; 168: int x, y, oldx, oldy, left, top; 169: int stop = FALSE; 170: 171: if (w == RootWindow) return; 172: 173: InterpretLocatorXY(RootWindow, &x, &y, loc); 174: 175: left = winfo->x; 176: top = winfo->y; 177: 178: oldx = x; 179: oldy = y; 180: 181: StoreBox(left, top, winfo->width + (winfo->bdrwidth << 1) - 1, 182: winfo->height + (winfo->bdrwidth << 1) - 1); 183: 184: /* If we're willing to freeze the server, we don't flicker the box. 185: If not, we do double inverts that draw and then erase the box, 186: so we have to do them more often */ 187: 188: if (freeze) XGrabServer(); 189: DrawBox(); 190: 191: while (!stop) { 192: /* If we've moved at all, change the box and reset old x,y */ 193: 194: if (x != oldx || y != oldy) { 195: if (freeze) DrawBox(); /* Erase */ 196: oldx = x; 197: oldy = y; 198: box[0].x = left; 199: box[0].y = top; 200: DrawBox(); /* Redraw */ 201: } else if (!freeze) DrawBox(); 202: 203: /* Find the new x,y. If there's an event, use that; otherwise 204: query the mouse */ 205: 206: if (XPending()) { 207: if (!GetEvent(&newbutton)) { 208: QueryMouse(RootWindow, &x, &y, &subwindow); 209: } 210: else if (!MatchUp(newbutton, which)) break; 211: else { 212: x = newbutton.x; 213: y = newbutton.y; 214: stop = TRUE; 215: } 216: } else QueryMouse(RootWindow, &x, &y, &subwindow); 217: 218: left += x - oldx; 219: top += y - oldy; 220: } 221: 222: if (freeze) { 223: DrawBox(); /* Erase */ 224: XUngrabServer(); 225: } 226: 227: if (!stop) return; 228: 229: if (popup) UnmapPopup(); 230: 231: XMoveWindow(w, left, top); 232: 233: FrameFocus(); /* Fix up frame */ 234: } 235: 236: Resize(which, loc, w, winfo) 237: int which; 238: Locator loc; 239: Window w; 240: WindowInfo *winfo; 241: { 242: BEvent newbutton; 243: int t; 244: int baseheight, hinc, basewidth, winc; 245: int x0, y0; /* Initial x,y of mouse */ 246: int fixedx, fixedy; /* x,y of fixed corner */ 247: int movex, movey; /* x,y of movable corner */ 248: int limitx, limity; /* limit to movement due to min window size */ 249: int oldx, oldy; /* previous location of moving corner */ 250: int newx, newy; /* new location of moving corner */ 251: int lastx, lasty; /* previous cursor location */ 252: int x, y; /* new cursor location */ 253: int dx, dy; /* flags indicating movement direction */ 254: int width, height; /* width & height of window */ 255: int usesize, stop = FALSE; 256: Window subwindow; 257: 258: if (w == RootWindow) return; 259: 260: /* Find out about window and get resizing info */ 261: 262: status = XGetResizeHint(w, &basewidth, &baseheight, &winc, &hinc); 263: if (status == 0) Error("Couldn't get resize hint in Resize"); 264: InterpretLocatorXY(RootWindow, &x0, &y0, loc); 265: 266: /* Initially fixedx is left, fixedy top, movex right, and 267: movey bottom */ 268: 269: fixedx = winfo->x; 270: fixedy = winfo->y; 271: width = winfo->width + (winfo->bdrwidth << 1) - 1; 272: height = winfo->height + (winfo->bdrwidth << 1) - 1; 273: movex = fixedx + width; 274: movey = fixedy + height; 275: 276: /* We only will use a size window if the increments are large 277: enough and the current window size corresponds to the hints */ 278: 279: usesize = (winc > 3 && hinc > 3 && 280: (winfo->width - basewidth) % winc == 0 && 281: (winfo->height - baseheight) % hinc == 0); 282: 283: if (basewidth == 0 && winc == 1 && baseheight == 0 && hinc == 1) { 284: basewidth = 1; 285: baseheight = 1; 286: } 287: 288: /* movex,y are still right and bottom */ 289: 290: limitx = movex - winfo->width + basewidth + winc; 291: limity = movey - winfo->height + baseheight + hinc; 292: 293: basewidth += (winfo->bdrwidth << 1) - 1; 294: baseheight += (winfo->bdrwidth << 1) - 1; 295: 296: /* Calculate the moving directions dx,dy */ 297: 298: CalculateMovingEdges(&dx, &dy, x0, fixedx, movex, 299: y0, fixedy, movey, winfo); 300: 301: /* Figure out which edges to move depending upon which ninth 302: the cursor is in. Adjust fixed and move edges accordingly: 303: 304: dx,y indicate which edges are fixed. Values: 305: 306: dx fixedx movex dy fixedy movey 307: 1,0 left right 1,0 top bottom 308: -1 right left -1 bottom top 309: 310: A value of 0 means that both edges are fixed in that direction */ 311: 312: /* If we're moving left edge, switch */ 313: 314: if (dx == -1) { 315: limitx = movex - (limitx - fixedx); 316: t = fixedx; fixedx = movex; movex = t; 317: width = -width; 318: } 319: 320: /* If we're moving top edge, switch */ 321: 322: if (dy == -1) { 323: limity = movey - (limity - fixedy); 324: t = fixedy; fixedy = movey; movey = t; 325: height = -height; 326: } 327: 328: oldx = newx = movex; 329: oldy = newy = movey; 330: lastx = x0; 331: lasty = y0; 332: 333: StoreBox(fixedx, fixedy, width, height); 334: 335: /* If we're willing to freeze the server, we don't flicker the box. 336: If not, we do double inverts that draw and then erase the box, 337: so we have to do them more often */ 338: 339: if (freeze) XGrabServer(); 340: DrawBox(); /* Draw box */ 341: 342: if (usesize) { 343: CreateSize (dx, dy, fixedx, fixedy, winfo); 344: FillinSize ((abs(width) - basewidth) / winc, 345: (abs(height) - baseheight) / hinc); 346: } 347: 348: /* Loop until a button event occurs */ 349: 350: while (!stop) { 351: /* If we've moved at all, change the box, fill in the 352: size window and reset old x,y */ 353: 354: if (newx != oldx || newy != oldy) { 355: if (freeze) DrawBox(); /* Erase */ 356: StoreBox(fixedx, fixedy, width, height); 357: 358: if (usesize) { 359: FillinSize ((abs(width) - basewidth) / winc, 360: (abs(height) - baseheight) / hinc); 361: } 362: oldx = newx; 363: oldy = newy; 364: DrawBox(); /* Redraw */ 365: } else if (!freeze) DrawBox(); 366: 367: /* Find the cursor x,y -- by an event if there is one, by 368: querying if not */ 369: 370: if (XPending()) { 371: if (!GetEvent(&newbutton)) { 372: QueryMouse(RootWindow, &x, &y, &subwindow); 373: } 374: else if (!MatchUp(newbutton, which)) break; 375: else { 376: x = newbutton.x; 377: y = newbutton.y; 378: stop = TRUE; 379: } 380: } else QueryMouse(RootWindow, &x, &y, &subwindow); 381: 382: /* If we haven't moved since last time, skip the rest */ 383: 384: if (x == lastx && y == lasty) continue; 385: 386: lastx = x; 387: lasty = y; 388: 389: newx = CalculateChange(dx, x, x0, winc, limitx, movex, oldx); 390: newy = CalculateChange(dy, y, y0, hinc, limity, movey, oldy); 391: width += newx - oldx; 392: height += newy - oldy; 393: } 394: 395: if (freeze) { 396: DrawBox(); /* Erase */ 397: XUngrabServer(); 398: } 399: 400: if (!stop) { 401: if (usesize) DestroySize(); 402: return; 403: } 404: 405: 406: if (newx == movex && newy == movey) { /* i.e. no change */ 407: if (usesize) DestroySize(); 408: XRaiseWindow(w); 409: } else { 410: 411: /* Re-exchange things so that fixedx,y is the left top */ 412: 413: if (newx < fixedx) { 414: t = fixedx; fixedx = newx; newx = t; 415: } 416: if (newy < fixedy) { 417: t = fixedy; fixedy = newy; newy = t; 418: } 419: 420: /* Calculate new width and height. */ 421: 422: width = newx - fixedx + 1 - (winfo->bdrwidth << 1); 423: height = newy - fixedy + 1 - (winfo->bdrwidth << 1); 424: 425: if (usesize) DestroySize(); 426: 427: if (popup) UnmapPopup(); 428: 429: XConfigureWindow(w, fixedx, fixedy, width, height); 430: FrameFocus(); 431: } 432: } 433: 434: CalculateMovingEdges(dx, dy, x0, fixedx, movex, y0, fixedy, movey, winfo) 435: int *dx, *dy, x0, fixedx, movex, y0, fixedy, movey; 436: WindowInfo *winfo; 437: { 438: int xthird, ythird; 439: 440: *dx = *dy = 1; 441: 442: /* If we're closer to the left than to the right, switch */ 443: 444: if (x0 - fixedx < movex - x0) *dx = -1; 445: 446: /* If we're closer to the top than the bottom, switch */ 447: 448: if (y0 - fixedy < movey - y0) *dy = -1; 449: 450: /* Now, watch closely! We take the offset from the point to the 451: left edge, multiply by 3 and divide by the width. This gives 452: a value of 0, 1, or 2 depending if the point is in the left, 453: middle, or right thirds. Do the same for y. Add them together. 454: If the result is odd, the point must be in one of the edge ninths, 455: rather than a corner ninth or the middle ninth. Figure out 456: which one and set dx,y accordingly. (gag) */ 457: 458: if (winfo->width > 2 && winfo->height > 2) { 459: xthird = ((x0 - winfo->x - winfo->bdrwidth) * 3) / winfo->width; 460: ythird = ((y0 - winfo->y - winfo->bdrwidth) * 3) / winfo->height; 461: 462: if ((xthird + ythird) & 1) { 463: if (xthird & 1) *dx = 0; 464: else *dy = 0; 465: } 466: } 467: } 468: 469: FillinSize(hsize, vsize) 470: register int hsize, vsize; 471: { 472: static char sizeText[7] = {'0', '0', '0', 'x', '0', '0', '0'}; 473: 474: sizeText[0] = vsize / 100 + '0'; 475: sizeText[1] = (vsize / 10) % 10 + '0'; 476: sizeText[2] = vsize % 10 + '0'; 477: sizeText[4] = hsize / 100 + '0'; 478: sizeText[5] = (hsize / 10) % 10 + '0'; 479: sizeText[6] = hsize % 10 + '0'; 480: if (variableWidth) XClear(sizeWin); 481: XText(sizeWin, 1, 1, sizeText, sizeof(sizeText), sizefont, 482: bgColor, fgColor); 483: } 484: 485: CreateSize(dx, dy, fixedx, fixedy, winfo) 486: int dx, dy, fixedx, fixedy; 487: WindowInfo *winfo; 488: { 489: int px, py; /* Size x, y */ 490: 491: /* If a corner is being moved, put the size window in the opposite 492: corner. If an edge, put in middle of opposite edge. */ 493: 494: if (dx > 0) px = fixedx + winfo->bdrwidth; 495: else if (dx < 0) px = fixedx - sizeWidth - winfo->bdrwidth + 1; 496: else px = winfo->x + winfo->bdrwidth + 497: (winfo->width - sizeWidth) / 2; 498: 499: if (dy > 0) py = fixedy + winfo->bdrwidth; 500: else if (dy < 0) py = fixedy - sizeHeight - winfo->bdrwidth + 1; 501: else py = winfo->y + winfo->bdrwidth + 502: (winfo->height - sizeHeight) / 2; 503: 504: if (freeze) { 505: sizeX = px; 506: sizeY = py; 507: behindSize = XPixmapSave(RootWindow, px, py, 508: sizeWidth, sizeHeight); 509: /* Ok to return 0; this means it wasn't on the screen */ 510: } 511: 512: XMoveWindow(sizeWin, px, py); 513: XMapWindow(sizeWin); 514: } 515: 516: DestroySize() 517: { 518: if (behindSize != 0) { 519: XUnmapTransparent(sizeWin); 520: XPixmapPut(RootWindow, 0, 0, sizeX, sizeY, sizeWidth, sizeHeight, 521: behindSize, GXcopy, AllPlanes); 522: XFreePixmap(behindSize); 523: behindSize = 0; 524: } else XUnmapWindow(sizeWin); 525: } 526: 527: int CalculateChange(direction, new, orig, inc, limit, origedge, oldedge) 528: int direction, new, orig, inc, limit, origedge, oldedge; 529: { 530: register int d, newedge; 531: 532: if (direction) { /* If we're changing this way */ 533: 534: /* Calculate the change in cursor position in inc units */ 535: 536: d = abs(new - orig) + (inc >> 1);; 537: d = (d / inc) * inc; 538: 539: /* Adjust the new position and check against the limit */ 540: 541: if (new < orig) { 542: newedge = origedge - d; 543: if (direction > 0 && newedge < limit) newedge = limit; 544: } else { 545: newedge = origedge + d; 546: if (direction < 0 && newedge > limit) newedge = limit; 547: } 548: } else newedge = oldedge; 549: 550: return(newedge); 551: } 552: 553: /* ARGSUSED */ 554: 555: Iconify(which, loc, w, winfo) 556: int which; 557: Locator loc; 558: Window w; 559: WindowInfo *winfo; 560: { 561: int x, y; 562: BEvent newbutton; 563: int width, height; 564: char *iconName; 565: WindowInfo iconInfo; 566: Window icon = 0; 567: struct _xy {short x, y} *xy; /* To turn locators into xy pairs */ 568: int downx, downy; 569: 570: if (w == RootWindow) return; 571: 572: /* First change the cursor into the icon cursor */ 573: 574: status = XGrabMouse(RootWindow, iconCursor, 575: ButtonPressed | ButtonReleased); 576: if (status == 0) Error("Couldn't grab mouse in Iconify"); 577: 578: /* Then wait for the upbutton; if it doesn't occur abort */ 579: 580: GetButton(&newbutton); 581: if (!MatchUp(newbutton, which)) return; 582: x = newbutton.x; 583: y = newbutton.y; 584: 585: /* See if it already has an associated icon window; 586: if not, figure out the size */ 587: 588: if (winfo->assoc_wind == 0) { 589: height = iconHeight; 590: 591: /* Now get the name of the window */ 592: 593: status = XFetchName(w, &iconName); 594: if (status == 0) Error("Couldn't fetch name in Iconify"); 595: 596: width = XQueryWidth(iconName, iconfont); 597: if (width == 0) width = height; 598: else width += 8; 599: 600: } else { 601: icon = winfo->assoc_wind; 602: QueryWindow(icon, &iconInfo); 603: height = iconInfo.height; 604: width = iconInfo.width; 605: 606: xy = (struct _xy *) &loc; 607: downx = xy->x; 608: downy = xy->y; 609: } 610: 611: /* Center the icon on the new cursor position */ 612: 613: x -= width >> 1 + 1; 614: if (x < 0) x = 0; 615: if (x + width + 2 > screen_width) x = screen_width - width - 2; 616: 617: y -= height >> 1 + 1; 618: if (y < 0) y = 0; 619: if (y + height + 2 > screen_height) y = screen_height - height - 2; 620: 621: /* Open the icon, give it a text cursor, choose key events, and 622: map it */ 623: 624: if (icon == 0) { 625: icon = XCreateWindow(RootWindow, x, y, width, height, 626: 1, fgPixmap, gray); 627: if (icon == 0) Error("Couldn't create icon in Iconify"); 628: XSelectInput(icon, KeyPressed|ExposeWindow|UnmapWindow); 629: XDefineCursor(icon, textCursor); 630: XSetIconWindow(w, icon); 631: } else { 632: xy = (struct _xy *) &(newbutton.location); 633: if (abs(xy->x - downx) > iconifyDelta || 634: abs(xy->y - downy) > iconifyDelta) { 635: XMoveWindow(icon, x, y); 636: } 637: } 638: 639: if (popup) UnmapPopup(); 640: 641: XMapWindow(icon); 642: XUnmapWindow(w); 643: 644: /* If the iconified window was the focus, change to the background */ 645: 646: if (focus == w) FocusOn(RootWindow); 647: FrameFocus(); 648: } 649: 650: /* ARGSUSED */ 651: 652: Deiconify(which, loc, w, winfo) 653: int which; 654: Locator loc; 655: Window w; 656: WindowInfo *winfo; 657: { 658: BEvent newbutton; 659: Window neww; 660: 661: if (w == RootWindow) return; 662: 663: GetButton(&newbutton); 664: 665: if (!MatchUp(newbutton, which)) return; 666: 667: InterpretLocatorW(RootWindow, &neww, newbutton.location); 668: if (neww != w) return; 669: 670: if (popup) UnmapPopup(); 671: 672: XUnmapWindow(w); 673: XMapWindow(winfo->assoc_wind); 674: 675: /* If icon was the focus, change to the window itself */ 676: 677: if (focus == w) FocusOn(winfo->assoc_wind); 678: FrameFocus(); 679: } 680: 681: /* ARGSUSED */ 682: 683: Select(which, loc, w, winfo) 684: int which; 685: Locator loc; 686: Window w; 687: WindowInfo *winfo; 688: { 689: BEvent newbutton; 690: Window neww; 691: 692: GetButton(&newbutton); 693: if (!MatchUp(newbutton, which)) return; 694: 695: InterpretLocatorW(RootWindow, &neww, newbutton.location); 696: if (neww == 0) neww = RootWindow; 697: if (neww != w) return; 698: 699: /* See if the current focus is an icon. If not, set oldfocus 700: so we can go back to it if we want to */ 701: 702: if (focusInfo.type != IsIcon) oldfocus = focus; 703: 704: if (popup) UnmapPopup(); 705: 706: FocusOn(w); 707: FrameFocus(); /* Now frame the focus window */ 708: XRaiseWindow(focus); 709: } 710: 711: FocusOn(w) 712: Window w; 713: { 714: focus = w; 715: QueryWindow(focus, &focusInfo); 716: XFocusKeyboard(focus); 717: } 718: 719: FrameFocus() 720: { 721: if (frameWidth == 0) return; /* Nothing to do */ 722: 723: /* Remove the frame from around any old focus window first */ 724: 725: XClear(RootWindow); 726: 727: if (focus == RootWindow) return; 728: QueryWindow(focus, &focusInfo); /* Refresh it */ 729: 730: /* Undo the default clipmode for the base window */ 731: 732: XClipClipped(RootWindow); 733: 734: XPixSet(RootWindow, 735: focusInfo.x - frameWidth, focusInfo.y - frameWidth, 736: focusInfo.width + 2 * (focusInfo.bdrwidth + frameWidth), 737: focusInfo.height + 2 * (focusInfo.bdrwidth + frameWidth), 738: fgColor); 739: 740: XClipDrawThrough(RootWindow); /* Put it back */ 741: } 742: 743: /* ARGSUSED */ 744: 745: Circulate(which, loc, w, winfo) 746: int which; 747: Locator loc; 748: Window w; 749: WindowInfo *winfo; 750: { 751: if (popup) UnmapPopup(); 752: 753: XCircWindowUp(RootWindow); 754: } 755: 756: EditIconName(be, name) 757: XKeyPressedEvent *be; 758: register char *name; 759: { 760: Window w = be->window; 761: short charcode = be->detail; 762: register int nameLen, c; 763: int x0, y0, size; 764: WindowInfo winfo; 765: register char *string; 766: int nbytes; 767: register int i; 768: 769: string = XLookupMapping (be, &nbytes); 770: nameLen = (name == NULL) ? 0 : strlen(name); 771: 772: for (i = 0; i < nbytes; i++) { 773: c = string[i]; 774: 775: 776: if (c == '\177') { /* a 'delete' */ 777: if (nameLen > 0) 778: name[--nameLen] = '\0'; 779: /* control-u if you can't read ascii */ 780: } else if (c == '\025') { 781: if (nameLen > 0) { 782: *name = '\0'; 783: nameLen = 0; 784: } 785: 786: } else if (c == '\r') { /* return means reset focus */ 787: FocusOn(oldfocus ? oldfocus : RootWindow); 788: oldfocus = 0; 789: FrameFocus(); 790: 791: } else if (c <= 0) 792: ; /* unknown character, ignore it */ 793: 794: /* Else append the letter to the name */ 795: 796: else { 797: if (name == NULL) 798: name = (char *) malloc (nameLen + 2); 799: else 800: name = (char *) realloc(name, nameLen + 2); 801: if (name == NULL) { 802: errno = ENOMEM; 803: perror("newwm:"); 804: } 805: name[nameLen] = c; 806: name[++nameLen] = '\0'; 807: } 808: } 809: 810: QueryWindow(w, &winfo); 811: x0 = winfo.x; 812: y0 = winfo.y; 813: 814: size = XQueryWidth(name, iconfont); 815: 816: /* Make sure icon is entirely on screen */ 817: 818: if (x0 < 0) x0 = 0; 819: else if (x0 + size + 10 > screen_width) { 820: x0 = screen_width - size - 10; 821: } 822: 823: if (y0 < 0) y0 = 0; 824: else if (y0 + iconHeight + 2 > screen_height) { 825: y0 = screen_height - iconHeight - 2; 826: } 827: 828: XConfigureWindow(w, x0, y0, size + 8, iconHeight); 829: XWarpMouse(w, (size+8) >> 1, iconHeight >> 1); 830: FrameFocus(); /* Redraw frame */ 831: XStoreName(winfo.assoc_wind, name); 832: 833: /* Don't redraw the text yet; the expose event will cause that */ 834: } 835: 836: StoreBox (x, y, w, h) 837: int x, y, w, h; 838: { 839: box[0].x = x; box[0].y = y; 840: box[1].x = w+2; box[1].y = 0; 841: box[2].x = 0; box[2].y = h+2; 842: box[3].x = -(w+2); box[3].y = 0; 843: box[4].x = 0; box[4].y = -(h+1); 844: box[5].x = w+1; box[5].y = 0; 845: box[6].x = 0; box[6].y = h; 846: box[7].x = -w; box[7].y = 0; 847: box[8].x = 0; box[8].y = -(h-1); 848: 849: if (!freeze) { 850: box[9].x = 0; box[9].y = h-1; 851: box[10].x = w; box[10].y = 0; 852: box[11].x = 0; box[11].y = -h; 853: box[12].x = -(w+1); box[12].y = 0; 854: box[13].x = 0; box[13].y = h+1; 855: box[14].x = w+2; box[14].y = 0; 856: box[15].x = 0; box[15].y = -(h+2); 857: box[16].x = -(w+2); box[16].y = 0; 858: } 859: } 860: 861: DrawBox() 862: { 863: XDraw(RootWindow, box, vcount, 1, 1, 0, 864: GXinvert, AllPlanes); 865: } 866: 867: InterpretLocator (w, x, y, subw, loc) 868: Window w; 869: Window *subw; 870: Locator loc; 871: int *x, *y; 872: { 873: status = XInterpretLocator(w, x, y, subw, loc); 874: if (status == 0) Error("Couldn't interpret in InterpretLocator"); 875: } 876: 877: InterpretLocatorW (w, subw, loc) 878: Window w; 879: Window *subw; 880: Locator loc; 881: { 882: int x, y; 883: 884: status = XInterpretLocator(w, &x, &y, subw, loc); 885: if (status == 0) Error("Couldn't interpret in InterpretLocator"); 886: } 887: 888: InterpretLocatorXY (w, x, y, loc) 889: Window w; 890: Locator loc; 891: int *x, *y; 892: { 893: Window subw; 894: 895: status = XInterpretLocator(w, x, y, &subw, loc); 896: if (status == 0) Error("Couldn't interpret in InterpretLocator"); 897: } 898: 899: QueryMouse (w, x, y, subw) 900: Window w; 901: Window *subw; 902: int *x, *y; 903: { 904: status = XQueryMouse(w, x, y, subw); 905: if (status == 0) Error("Couldn't query mouse in QueryMouse"); 906: } 907: 908: QueryWindow (w, info) 909: Window w; 910: WindowInfo *info; 911: { 912: status = XQueryWindow(w, info); 913: if (status == 0) Error("Couldn't query windown in QueryWindow"); 914: }