|
|
1.1 ! root 1: #include <X/mit-copyright.h> ! 2: ! 3: /* Copyright Massachusetts Institute of Technology 1986 */ ! 4: ! 5: #include <sys/types.h> ! 6: #include "../Xlib/Xlib.h" ! 7: #undef CURSOR ! 8: #include "../Xlib/Xkeyboard.h" ! 9: #include <stdio.h> ! 10: #include <errno.h> ! 11: #include "../X/vsinput.h" ! 12: #include "../X/Xdev.h" ! 13: ! 14: extern int errno, XFlush(); ! 15: char *Xalloc(), *Xrealloc(), *strcpy(); ! 16: ! 17: #define Xpixmap(p) ((Pixmap) p->data) ! 18: #define Xbitmap(b) ((Bitmap) b->data) ! 19: #define Xfinf(f) ((FontInfo *) f->data) ! 20: #define Xfont(f) (Xfinf(f)->id) ! 21: #define Xcursor(c) ((Cursor) c->data) ! 22: #define npix(p) (((p) << pixshift) | basepix) ! 23: #define opix(p) (((p) &~ basepix) >> pixshift) ! 24: #define nmask(m) ((m) << pixshift) ! 25: ! 26: static Window w, t, ot, tt; ! 27: static int extrapix; ! 28: static int pixplanes = 0; ! 29: static int pixshift = 0; ! 30: static int basepix = 0; ! 31: static int screen_height, screen_width; ! 32: static int tilex = 0; ! 33: static int tiley = 0; ! 34: static CLIP tileclip = {0, 0, 0, 0}; ! 35: static vsCursor mouse = {0, 0}; ! 36: static vsBox mbox = {0, 0, 0, 0}; ! 37: static int cursor_x, cursor_y; ! 38: static DEVICE *dev; ! 39: ! 40: /*ARGSUSED*/ ! 41: ProcessInput (ev) ! 42: vsEvent ev; ! 43: { ! 44: } ! 45: ! 46: /*ARGSUSED*/ ! 47: OpenDisplay (display) ! 48: char *display; /* display number */ ! 49: { ! 50: OpaqueFrame frame; ! 51: char def[32]; ! 52: char *option; ! 53: Color cdef; ! 54: ! 55: if (XOpenDisplay((char *) NULL) == NULL) { ! 56: errno = EINVAL; ! 57: return(-1); ! 58: } ! 59: if (option = XGetDefault("X", "BorderWidth")) ! 60: frame.bdrwidth = atoi(option); ! 61: else ! 62: frame.bdrwidth = 0; ! 63: if (frame.bdrwidth && DisplayCells() > 2 && ! 64: (option = XGetDefault("X", "Border")) && ! 65: XParseColor(option, &cdef) && ! 66: XGetHardwareColor(&cdef)) ! 67: frame.border = XMakeTile(cdef.pixel); ! 68: else ! 69: frame.border = BlackPixmap; ! 70: frame.background = NULL; ! 71: frame.x = 0; ! 72: frame.y = 0; ! 73: sprintf(def, "=%dx%d+0+0", ! 74: DisplayWidth() - (frame.bdrwidth << 1), ! 75: DisplayHeight() - (frame.bdrwidth << 1)); ! 76: w = XCreate("X", "X", "", def, &frame, 50, 50); ! 77: screen_height = frame.height; ! 78: screen_width = frame.width; ! 79: XMapWindow(w); ! 80: XSelectInput(w, KeyPressed|KeyReleased|ButtonPressed|ButtonReleased| ! 81: MouseMoved|EnterWindow|LeaveWindow); ! 82: t = XCreateTransparency(w, 0, 0, screen_width, screen_height); ! 83: ot = XCreateTransparency(w, 0, 0, screen_width, screen_height); ! 84: XTileAbsolute(ot); ! 85: tt = XCreateTransparency(ot, 0, 0, screen_width, screen_height); ! 86: XMapWindow(t); ! 87: XMapWindow(tt); ! 88: XMapWindow(ot); ! 89: return(dpyno()); ! 90: } ! 91: ! 92: InputReader () ! 93: { ! 94: XEvent xev; ! 95: vsEvent ev; ! 96: int nstate; ! 97: static int state = 0; ! 98: vsCursor ms; ! 99: ! 100: XPending(); ! 101: while (QLength()) { ! 102: XNextEvent(&xev); ! 103: switch (xev.type) { ! 104: case EnterWindow: ! 105: if (xev.subwindow) ! 106: continue; ! 107: case MouseMoved: ! 108: ms.x = ((XMouseMovedEvent *) (&xev))->x - cursor_x; ! 109: ms.y = ((XMouseMovedEvent *) (&xev))->y - cursor_y; ! 110: if ((ms.x != mouse.x || ms.y != mouse.y) && ! 111: ms.x >= 0 && ms.x < screen_width && ! 112: ms.y >= 0 && ms.y < screen_height) { ! 113: mouse = ms; ! 114: if (ms.y >= mbox.bottom || ms.y < mbox.top || ! 115: ms.x >= mbox.right || ms.x < mbox.left) { ! 116: mbox.bottom = 0; ! 117: Deal_with_movement(); ! 118: } ! 119: } ! 120: if (xev.type != EnterWindow) ! 121: continue; ! 122: ev.vse_time = ((XKeyOrButtonEvent *) (&xev))->time; ! 123: nstate = ((XEnterWindowEvent *) (&xev))->detail & ~ValueMask; ! 124: nstate ^= state; ! 125: ev.vse_direction = VSE_KBTUP; ! 126: ButtonTransition(&ev, nstate & state); ! 127: KeyTransition(&ev, nstate & state); ! 128: ev.vse_direction = VSE_KBTDOWN; ! 129: KeyTransition(&ev, nstate & ~state); ! 130: ButtonTransition(&ev, nstate & ~state); ! 131: continue; ! 132: case LeaveWindow: ! 133: state = ((XLeaveWindowEvent *) (&xev))->detail & ~ValueMask; ! 134: continue; ! 135: } ! 136: ev.vse_x = mouse.x; ! 137: ev.vse_y = mouse.y; ! 138: ev.vse_time = ((XKeyOrButtonEvent *) (&xev))->time; ! 139: ev.vse_key = ((XKeyOrButtonEvent *) (&xev))->detail & ValueMask; ! 140: switch (xev.type) { ! 141: case KeyPressed: ! 142: ev.vse_device = VSE_DKB; ! 143: ev.vse_direction = VSE_KBTDOWN; ! 144: break; ! 145: case KeyReleased: ! 146: ev.vse_device = VSE_DKB; ! 147: ev.vse_direction = VSE_KBTUP; ! 148: break; ! 149: case ButtonPressed: ! 150: ev.vse_device = VSE_MOUSE; ! 151: ev.vse_direction = VSE_KBTDOWN; ! 152: ev.vse_key = 2 - ev.vse_key; ! 153: break; ! 154: case ButtonReleased: ! 155: ev.vse_device = VSE_MOUSE; ! 156: ev.vse_direction = VSE_KBTUP; ! 157: ev.vse_key = 2 - ev.vse_key; ! 158: break; ! 159: } ! 160: Deal_with_input(&ev); ! 161: } ! 162: } ! 163: ! 164: KeyTransition (ev, bits) ! 165: register vsEvent *ev; ! 166: register int bits; ! 167: { ! 168: ev->vse_device = VSE_DKB; ! 169: if (bits & ControlMask) { ! 170: ev->vse_x = mouse.x; ! 171: ev->vse_y = mouse.y; ! 172: ev->vse_key = KC_CTRL; ! 173: Deal_with_input(ev); ! 174: } ! 175: if (bits & MetaMask) { ! 176: ev->vse_x = mouse.x; ! 177: ev->vse_y = mouse.y; ! 178: ev->vse_key = KC_META; ! 179: Deal_with_input(ev); ! 180: } ! 181: if (bits & ShiftMask) { ! 182: ev->vse_x = mouse.x; ! 183: ev->vse_y = mouse.y; ! 184: ev->vse_key = KC_SHIFT; ! 185: Deal_with_input(ev); ! 186: } ! 187: if (bits & ShiftLockMask) { ! 188: ev->vse_x = mouse.x; ! 189: ev->vse_y = mouse.y; ! 190: ev->vse_key = KC_LOCK; ! 191: Deal_with_input(ev); ! 192: } ! 193: } ! 194: ! 195: ButtonTransition (ev, bits) ! 196: register vsEvent *ev; ! 197: register int bits; ! 198: { ! 199: ev->vse_device = VSE_MOUSE; ! 200: if (bits & LeftMask) { ! 201: ev->vse_x = mouse.x; ! 202: ev->vse_y = mouse.y; ! 203: ev->vse_key = 2 - LeftButton; ! 204: Deal_with_input(ev); ! 205: } ! 206: if (bits & MiddleMask) { ! 207: ev->vse_x = mouse.x; ! 208: ev->vse_y = mouse.y; ! 209: ev->vse_key = 2 - MiddleButton; ! 210: Deal_with_input(ev); ! 211: } ! 212: if (bits & RightMask) { ! 213: ev->vse_x = mouse.x; ! 214: ev->vse_y = mouse.y; ! 215: ev->vse_key = 2 - RightButton; ! 216: Deal_with_input(ev); ! 217: } ! 218: } ! 219: ! 220: InitDisplay (info) ! 221: DEVICE *info; /* device data */ ! 222: { ! 223: char *option; ! 224: int planes; ! 225: static vsEventQueue queue = {NULL, 0, 0, 0}; ! 226: ! 227: dev = info; ! 228: info->id = XDEV_XNEST; ! 229: info->width = screen_width; ! 230: info->height = screen_height; ! 231: info->planes = DisplayPlanes(); ! 232: info->entries = 0; ! 233: pixplanes = 0; ! 234: if (DisplayCells() > 2 && ! 235: (option = XGetDefault("X", "CellExponent")) && ! 236: (pixplanes = atoi(option)) && ! 237: XGetColorCells(0, 1, 0, &planes, &extrapix)) { ! 238: while (pixplanes && ! 239: !XGetColorCells(1, 1, pixplanes, &planes, &basepix)) ! 240: pixplanes--; ! 241: if (pixplanes) { ! 242: info->entries = 1 << pixplanes; ! 243: while (!(planes & 1)) { ! 244: pixshift++; ! 245: planes >>= 1; ! 246: } ! 247: } else ! 248: XFreeColors(&extrapix, 1, 0); ! 249: } ! 250: info->mouse = &mouse; ! 251: info->mbox = &mbox; ! 252: info->queue = &queue; ! 253: Define_input_handler(InputReader); ! 254: Define_block_handler(XFlush); ! 255: return(0); ! 256: } ! 257: ! 258: DisplayDead () ! 259: { ! 260: return(0); ! 261: } ! 262: ! 263: InitMouse () ! 264: { ! 265: } ! 266: ! 267: caddr_t AllocateSpace (bytes) ! 268: int bytes; /* number of bytes to allocate */ ! 269: { ! 270: static char *buf = NULL; ! 271: static int buflen = 0; ! 272: ! 273: if (bytes > buflen) { ! 274: free(buf); ! 275: buf = Xalloc((bytes + 0xff) &~ 0xff); ! 276: } ! 277: return(buf); ! 278: } ! 279: ! 280: PixFill (srcpix, xymask, dstx, dsty, width, height, clips, clipcount, ! 281: func, zmask) ! 282: int srcpix; /* source pixel */ ! 283: BITMAP *xymask; /* source mask or NULL */ ! 284: int dstx, dsty; /* destination */ ! 285: int width, height; ! 286: register CLIP *clips; /* clipping rectangles */ ! 287: int clipcount; /* count of rectangles */ ! 288: int func; /* GX display function */ ! 289: int zmask; /* plane mask */ ! 290: { ! 291: srcpix = npix(srcpix); ! 292: zmask = nmask(zmask); ! 293: for (; --clipcount >= 0; clips++) { ! 294: SetClip(clips); ! 295: XPixFill(t, dstx - clips->left, dsty - clips->top, width, height, ! 296: srcpix, xymask ? Xbitmap(xymask) : NULL, func, zmask); ! 297: } ! 298: } ! 299: ! 300: TileFill (tile, xoff, yoff, xymask, dstx, dsty, width, height, ! 301: clips, clipcount, func, zmask) ! 302: PIXMAP *tile; /* source tile */ ! 303: int xoff, yoff; /* tile origin */ ! 304: BITMAP *xymask; /* source mask or NULL */ ! 305: int dstx, dsty; /* destination */ ! 306: int width, height; ! 307: register CLIP *clips; /* clipping rectangles */ ! 308: int clipcount; /* count of rectangles */ ! 309: int func; /* GX display function */ ! 310: int zmask; /* plane mask */ ! 311: { ! 312: zmask = nmask(zmask); ! 313: SetTileOrigin(tile, xoff, yoff); ! 314: for (; --clipcount >= 0; clips++) { ! 315: SetTileClip(clips); ! 316: XTileFill(tt, dstx - clips->left, dsty - clips->top, width, height, ! 317: Xpixmap(tile), xymask ? Xbitmap(xymask) : NULL, ! 318: func, zmask); ! 319: } ! 320: } ! 321: ! 322: PixmapPut (src, srcx, srcy, width, height, dstx, dsty, clips, clipcount, ! 323: func, zmask) ! 324: PIXMAP *src; /* source */ ! 325: int srcx, srcy; /* region of source */ ! 326: int width, height; ! 327: int dstx, dsty; /* destination */ ! 328: register CLIP *clips; /* clipping rectangles */ ! 329: int clipcount; /* count of rectangles */ ! 330: int func; /* GX display function */ ! 331: int zmask; /* plane mask */ ! 332: { ! 333: zmask = nmask(zmask); ! 334: for (; --clipcount >= 0; clips++) { ! 335: SetClip(clips); ! 336: XPixmapPut(t, srcx, srcy, dstx - clips->left, dsty - clips->top, ! 337: width, height, Xpixmap(src), func, zmask); ! 338: } ! 339: } ! 340: ! 341: PixmapBitsPut (width, height, format, data, xymask, dstx, dsty, ! 342: clips, clipcount, func, zmask) ! 343: int width; /* source width */ ! 344: int height; /* source height */ ! 345: int format; /* 0: XY-format, 1: Z-format */ ! 346: char *data; /* source data */ ! 347: BITMAP *xymask; /* source mask or NULL */ ! 348: int dstx, dsty; /* destination */ ! 349: register CLIP *clips; /* clipping rectangles */ ! 350: int clipcount; /* count of rectangles */ ! 351: int func; /* GX display function */ ! 352: int zmask; /* plane mask */ ! 353: { ! 354: ToPixmap(width, height, format, data); ! 355: zmask = nmask(zmask); ! 356: for (; --clipcount >= 0; clips++) { ! 357: SetClip(clips); ! 358: if (format == XYFormat) ! 359: XPixmapBitsPutXY(t, dstx - clips->left, dsty - clips->top, ! 360: width, height, data, ! 361: xymask ? Xbitmap(xymask) : NULL, func, zmask); ! 362: else { ! 363: XPixmapBitsPutZ(t, dstx - clips->left, dsty - clips->top, ! 364: width, height, data, ! 365: xymask ? Xbitmap(xymask) : NULL, func, zmask); ! 366: } ! 367: } ! 368: } ! 369: ! 370: BitmapBitsPut (width, height, data, fore, back, xymask, dstx, dsty, ! 371: clips, clipcount, func, zmask) ! 372: int width; /* source width */ ! 373: int height; /* source height */ ! 374: char *data; /* source data */ ! 375: int fore; /* foreground source pixel */ ! 376: int back; /* background source pixel */ ! 377: BITMAP *xymask; /* source mask or NULL */ ! 378: int dstx, dsty; /* destination */ ! 379: register CLIP *clips; /* clipping rectangles */ ! 380: int clipcount; /* count of rectangles */ ! 381: int func; /* GX display function */ ! 382: int zmask; /* plane mask */ ! 383: { ! 384: fore = npix(fore); ! 385: back = npix(back); ! 386: zmask = nmask(zmask); ! 387: for (; --clipcount >= 0; clips++) { ! 388: SetClip(clips); ! 389: XBitmapBitsPut(t, dstx - clips->left, dsty - clips->top, ! 390: width, height, data, fore, back, ! 391: xymask ? Xbitmap(xymask) : NULL, func, zmask); ! 392: } ! 393: } ! 394: ! 395: CopyArea (srcx, srcy, width, height, dstx, dsty, clips, clipcount, func, zmask) ! 396: int srcx, srcy; /* source */ ! 397: int width, height; ! 398: int dstx, dsty; /* destination */ ! 399: register CLIP *clips; /* clipping rectangles */ ! 400: int clipcount; /* count of rectangles */ ! 401: int func; /* GX display function */ ! 402: int zmask; /* plane mask */ ! 403: { ! 404: int dstr, dstb, left, top; ! 405: ! 406: dstr = dstx + width; ! 407: dstb = dsty + height; ! 408: srcx -= dstx; ! 409: srcy -= dsty; ! 410: for (; --clipcount >= 0; clips++) { ! 411: left = clips->left; ! 412: if (left < dstx) ! 413: left = dstx; ! 414: width = clips->left + clips->width; ! 415: if (width > dstr) ! 416: width = dstr; ! 417: width -= left; ! 418: top = clips->top; ! 419: if (top < dsty) ! 420: top = dsty; ! 421: height = clips->top + clips->height; ! 422: if (height > dstb) ! 423: height = dstb; ! 424: height -= top; ! 425: if (width > 0 && height > 0) ! 426: XCopyArea(w, srcx + left, srcy + top, left, top, ! 427: width, height, func, zmask); ! 428: } ! 429: } ! 430: ! 431: PrintText (string, strlen, font, fore, back, charpad, spacepad, dstx, dsty, ! 432: clips, clipcount, func, zmask) ! 433: char *string; /* character string */ ! 434: int strlen; /* string length */ ! 435: FONT *font; /* source font */ ! 436: int fore; /* foreground source pixel */ ! 437: int back; /* background source pixel */ ! 438: int charpad; /* inter-character pad */ ! 439: int spacepad; /* space-character pad */ ! 440: int dstx, dsty; /* destination */ ! 441: register CLIP *clips; /* clipping rectangles */ ! 442: int clipcount; /* count of rectangles */ ! 443: int func; /* GX display function */ ! 444: int zmask; /* plane mask */ ! 445: { ! 446: fore = npix(fore); ! 447: back = npix(back); ! 448: zmask = nmask(zmask); ! 449: for (; --clipcount >= 0; clips++) { ! 450: SetClip(clips); ! 451: XTextPad(t, dstx - clips->left, dsty - clips->top, string, strlen, ! 452: Xfont(font), charpad, spacepad, fore, back, func, zmask); ! 453: } ! 454: } ! 455: ! 456: PrintTextMask (string, strlen, font, srcpix, charpad, spacepad, dstx, dsty, ! 457: clips, clipcount, func, zmask) ! 458: char *string; /* character string */ ! 459: int strlen; /* string length */ ! 460: FONT *font; /* font mask */ ! 461: int srcpix; /* source pixel */ ! 462: int charpad; /* inter-character pad */ ! 463: int spacepad; /* space-character pad */ ! 464: int dstx, dsty; /* destination */ ! 465: register CLIP *clips; /* clipping rectangles */ ! 466: int clipcount; /* count of rectangles */ ! 467: int func; /* GX display function */ ! 468: int zmask; /* plane mask */ ! 469: { ! 470: srcpix = npix(srcpix); ! 471: zmask = nmask(zmask); ! 472: for (; --clipcount >= 0; clips++) { ! 473: SetClip(clips); ! 474: XTextMaskPad(t, dstx - clips->left, dsty - clips->top, string, ! 475: strlen, Xfont(font), charpad, spacepad, srcpix, ! 476: func, zmask); ! 477: } ! 478: } ! 479: ! 480: DrawCurve (verts, vertcount, xbase, ybase, srcpix, altpix, mode, ! 481: bwidth, bheight, pat, patlen, patmul, clips, clipcount, func, zmask) ! 482: Vertex *verts; /* vertexes */ ! 483: int vertcount; /* vertex count */ ! 484: int xbase, ybase; /* draw origin */ ! 485: int srcpix; /* source pixel * ! 486: int altpix; /* alternate source pixel */ ! 487: int mode; /* 0: solid, 1: dashed, 2: patterned */ ! 488: int bwidth; /* brush width */ ! 489: int bheight; /* brush height */ ! 490: int pat; /* pattern */ ! 491: int patlen; /* pattern length */ ! 492: int patmul; /* pattern repeat count */ ! 493: register CLIP *clips; /* clipping rectangles */ ! 494: int clipcount; /* count of rectangles */ ! 495: int func; /* GX display function */ ! 496: int zmask; /* plane mask */ ! 497: { ! 498: srcpix = npix(srcpix); ! 499: altpix = npix(altpix); ! 500: zmask = nmask(zmask); ! 501: for (; --clipcount >= 0; clips++) { ! 502: SetClip(clips); ! 503: PathOffsets(verts, vertcount, ! 504: xbase - clips->left, ybase - clips->top); ! 505: xbase = clips->left; ! 506: ybase = clips->top; ! 507: switch (mode) { ! 508: case DrawSolidLine: ! 509: XDraw(t, verts, vertcount, bwidth, bheight, srcpix, ! 510: func, zmask); ! 511: break; ! 512: case DrawDashedLine: ! 513: XDrawDashed(t, verts, vertcount, bwidth, bheight, srcpix, ! 514: XMakePattern(pat, patlen, patmul), func, zmask); ! 515: break; ! 516: case DrawPatternedLine: ! 517: XDrawPatterned(t, verts, vertcount, bwidth, bheight, srcpix, ! 518: altpix, XMakePattern(pat, patlen, patmul), ! 519: func, zmask); ! 520: break; ! 521: } ! 522: } ! 523: } ! 524: ! 525: DrawFilled (verts, vertcount, xbase, ybase, srcpix, tile, xoff, yoff, ! 526: clips, clipcount, func, zmask) ! 527: Vertex *verts; /* vertexes */ ! 528: int vertcount; /* vertex count */ ! 529: int xbase, ybase; /* draw origin */ ! 530: int srcpix; /* source pixel */ ! 531: PIXMAP *tile; /* optional tile or NULL */ ! 532: int xoff, yoff; /* tile origin */ ! 533: register CLIP *clips; /* clipping rectangles */ ! 534: int clipcount; /* count of rectangles */ ! 535: int func; /* GX display function */ ! 536: int zmask; /* plane mask */ ! 537: { ! 538: if (tile) ! 539: SetTileOrigin(tile, xoff, yoff); ! 540: else ! 541: srcpix = npix(srcpix); ! 542: zmask = nmask(zmask); ! 543: for (; --clipcount >= 0; clips++) { ! 544: PathOffsets(verts, vertcount, ! 545: xbase - clips->left, ybase - clips->top); ! 546: xbase = clips->left; ! 547: ybase = clips->top; ! 548: if (tile) { ! 549: SetTileClip(clips); ! 550: XDrawTiled(tt, verts, vertcount, Xpixmap(tile), func, zmask); ! 551: } else { ! 552: SetClip(clips); ! 553: XDrawFilled(t, verts, vertcount, srcpix, func, zmask); ! 554: } ! 555: } ! 556: } ! 557: ! 558: PathOffsets (verts, vertcount, xoff, yoff) ! 559: register Vertex *verts; ! 560: register int vertcount, xoff, yoff; ! 561: { ! 562: for (; --vertcount >= 0; verts++) { ! 563: if (!(verts->flags & VertexRelative)) { ! 564: verts->x += xoff; ! 565: verts->y += yoff; ! 566: } ! 567: } ! 568: } ! 569: ! 570: SetClip (clip) ! 571: register CLIP *clip; ! 572: { ! 573: static CLIP normclip = {0, 0, 0, 0}; ! 574: ! 575: if (clip->left != normclip.left || clip->top != normclip.top || ! 576: clip->width != normclip.width || clip->height != normclip.height) { ! 577: XConfigureWindow(t, clip->left, clip->top, ! 578: clip->width, clip->height); ! 579: normclip = *clip; ! 580: } ! 581: } ! 582: ! 583: SetTileClip (clip) ! 584: register CLIP *clip; ! 585: { ! 586: if (clip->left != tileclip.left || clip->top != tileclip.top || ! 587: clip->width != tileclip.width || clip->height != tileclip.height) { ! 588: XConfigureWindow(tt, clip->left - tilex, clip->top - tiley, ! 589: clip->width, clip->height); ! 590: tileclip = *clip; ! 591: } ! 592: } ! 593: ! 594: SetTileOrigin (tile, xoff, yoff) ! 595: register PIXMAP *tile; ! 596: register int xoff, yoff; ! 597: { ! 598: if (tile->width) { ! 599: xoff %= tile->width; ! 600: if (xoff) ! 601: xoff -= tile->width; ! 602: yoff %= tile->height; ! 603: if (yoff) ! 604: yoff -= tile->height; ! 605: if (xoff != tilex || yoff != tiley) { ! 606: XConfigureWindow(ot, xoff, yoff, ! 607: screen_width - xoff, screen_height - yoff); ! 608: tileclip.left += (xoff - tilex); ! 609: tileclip.top += (yoff - tiley); ! 610: tilex = xoff; ! 611: tiley = yoff; ! 612: } ! 613: } ! 614: } ! 615: ! 616: PIXMAP *PixmapSave (srcx, srcy, width, height) ! 617: int srcx, srcy; /* source */ ! 618: int width, height; ! 619: { ! 620: Pixmap pix; ! 621: PIXMAP *pm; ! 622: ! 623: pix = XPixmapSave(w, srcx, srcy, width, height); ! 624: if (pix == NULL) ! 625: return(NULL); ! 626: pm = (PIXMAP *) Xalloc (sizeof (PIXMAP)); ! 627: pm->width = width; ! 628: pm->height = height; ! 629: pm->refcnt = 1; ! 630: pm->data = (caddr_t) pix; ! 631: IsTile(pm); ! 632: return(pm); ! 633: } ! 634: ! 635: PixmapGet (srcx, srcy, width, height, client, format, swapit) ! 636: int srcx, srcy; /* source */ ! 637: int width, height; ! 638: int client; /* file desc to write to */ ! 639: int format; /* 0: XY-format, 1: Z-format */ ! 640: int swapit; /* 1: swap shorts */ ! 641: { ! 642: int count; ! 643: caddr_t data; ! 644: ! 645: if (format == XYFormat) { ! 646: count = (XYPixmapSize(width, height, dev->planes) + 3) & ~3; ! 647: data = Xalloc(count); ! 648: if (XPixmapGetXY(w, srcx, srcy, width, height, data) == NULL) ! 649: return; ! 650: } else { ! 651: if (dev->planes > 8) ! 652: count = WZPixmapSize(width, height); ! 653: else { ! 654: count = BZPixmapSize(width, height); ! 655: swapit = 0; ! 656: } ! 657: count = (count + 3) & ~3; ! 658: data = Xalloc(count); ! 659: if (XPixmapGetZ(w, srcx, srcy, width, height, data) == NULL) ! 660: return; ! 661: } ! 662: FromPixmap(width, height, format, data); ! 663: if (swapit) ! 664: Swap_shorts(data, count >> 1); ! 665: Write(client, data, count); ! 666: free(data); ! 667: } ! 668: ! 669: ResolveColor (red, green, blue) ! 670: unsigned short *red, *green, *blue; /* update in place */ ! 671: { ! 672: Color def; ! 673: ! 674: if (dev->entries) { ! 675: def.pixel = extrapix; ! 676: def.red = *red; ! 677: def.green = *green; ! 678: def.blue = *blue; ! 679: XStoreColor(&def); ! 680: XQueryColor(&def); ! 681: *red = def.red; ! 682: *green = def.green; ! 683: *blue = def.blue; ! 684: } ! 685: } ! 686: ! 687: StoreColors (count, entries) ! 688: int count; /* number of entries */ ! 689: register ColorDef *entries; ! 690: { ! 691: register Color *ptr; ! 692: register int n; ! 693: static Color *ents = NULL; ! 694: static entcnt = 0; ! 695: ! 696: if (count > entcnt) { ! 697: free ((caddr_t) ents); ! 698: ents = (Color *) Xalloc(count * sizeof(Color)); ! 699: entcnt = count; ! 700: } ! 701: for (ptr = ents, n = count; --n >= 0; entries++, ptr++) { ! 702: ptr->pixel = npix(entries->pixel); ! 703: ptr->red = entries->red; ! 704: ptr->green = entries->green; ! 705: ptr->blue = entries->blue; ! 706: } ! 707: XStoreColors(count, ents); ! 708: } ! 709: ! 710: FONT *GetFont (name) ! 711: char *name; /* font or file name */ ! 712: { ! 713: register FontInfo *info; ! 714: register FONT *fd; ! 715: char *fname; ! 716: ! 717: info = XOpenFont(name); ! 718: if (info == NULL) { ! 719: errno = EINVAL; ! 720: return(NULL); ! 721: } ! 722: fd = (FONT *) Xalloc(sizeof(FONT)); ! 723: fname = Xalloc(strlen(name) + 1); ! 724: strcpy(fname, name); ! 725: fd->name = fname; ! 726: fd->first = info->firstchar; ! 727: fd->last = info->lastchar; ! 728: fd->space = ' '; ! 729: fd->height = info->height; ! 730: fd->avg_width = info->width; ! 731: fd->fixed = info->fixedwidth; ! 732: fd->base = info->baseline; ! 733: fd->refcnt = 1; ! 734: fd->data = (caddr_t) info; ! 735: return(fd); ! 736: } ! 737: ! 738: FreeFont (font) ! 739: FONT *font; ! 740: { ! 741: XCloseFont(Xfinf(font)); ! 742: free(font->name); ! 743: free((caddr_t) font); ! 744: } ! 745: ! 746: CharWidth (c, font) ! 747: unsigned c; /* character */ ! 748: register FONT *font; /* font */ ! 749: { ! 750: if (c < font->first || c > font->last) ! 751: return(0); ! 752: else if (font->fixed) ! 753: return(font->avg_width); ! 754: else ! 755: return(Xfinf(font)->widths[c - font->first]); ! 756: } ! 757: ! 758: TextWidth (string, strlen, spacepad, font) ! 759: char *string; /* character string */ ! 760: int strlen; /* string length */ ! 761: int spacepad; /* space-character pad */ ! 762: register FONT *font; /* font */ ! 763: { ! 764: register u_char *strptr = (u_char *) string; ! 765: short c; ! 766: register short *widths; ! 767: int width = 0; ! 768: ! 769: if (font->fixed) { ! 770: width = strlen * font->avg_width; ! 771: if (spacepad) { ! 772: while (--strlen >= 0) ! 773: if (*strptr++ == font->space) ! 774: width += spacepad; ! 775: } ! 776: } else { ! 777: widths = Xfinf(font)->widths; ! 778: while (--strlen >= 0) { ! 779: c = *strptr++; ! 780: if (c >= font->first && c <= font->last) { ! 781: if (c == font->space) ! 782: width += spacepad; ! 783: width += widths[c - font->first]; ! 784: } ! 785: } ! 786: } ! 787: return (width); ! 788: } ! 789: ! 790: BITMAP *StoreBitmap (width, height, data) ! 791: int width; /* bitmap width */ ! 792: int height; /* bitmap height */ ! 793: char *data; /* bitmap data */ ! 794: { ! 795: Bitmap bitmap; ! 796: register BITMAP *bm; ! 797: ! 798: bitmap = XStoreBitmap(width, height, data); ! 799: if (bitmap == NULL) ! 800: return(NULL); ! 801: bm = (BITMAP *) Xalloc(sizeof(BITMAP)); ! 802: bm->width = width; ! 803: bm->height = height; ! 804: bm->refcnt = 1; ! 805: bm->data = (caddr_t) bitmap; ! 806: return(bm); ! 807: } ! 808: ! 809: FreeBitmap (bitmap) ! 810: BITMAP *bitmap; ! 811: { ! 812: XFreeBitmap(Xbitmap(bitmap)); ! 813: free((caddr_t) bitmap); ! 814: } ! 815: ! 816: BITMAP *CharBitmap (c, font) ! 817: unsigned c; /* character */ ! 818: register FONT *font; /* font */ ! 819: { ! 820: Bitmap bitmap; ! 821: register BITMAP *bm; ! 822: ! 823: bitmap = XCharBitmap(Xfont(font), (int) c); ! 824: if (bitmap == NULL) ! 825: return(NULL); ! 826: bm = (BITMAP *) Xalloc(sizeof(BITMAP)); ! 827: bm->width = CharWidth(c, font); ! 828: bm->height = Xfinf(font)->height; ! 829: bm->refcnt = 1; ! 830: bm->data = (caddr_t) bitmap; ! 831: return(bm); ! 832: } ! 833: ! 834: PIXMAP *StorePixmap (width, height, format, data) ! 835: int width; /* pixmap width */ ! 836: int height; /* pixmap height */ ! 837: int format; /* 0: XY-format, 1: Z-format */ ! 838: char *data; /* pixmap data */ ! 839: { ! 840: Pixmap pix; ! 841: register PIXMAP *pm; ! 842: ! 843: ToPixmap(width, height, format, data); ! 844: if (format == XYFormat) ! 845: pix = XStorePixmapXY(width, height, data); ! 846: else ! 847: pix = XStorePixmapZ(width, height, data); ! 848: if (pix == NULL) ! 849: return(NULL); ! 850: pm = (PIXMAP *) Xalloc (sizeof (PIXMAP)); ! 851: pm->width = width; ! 852: pm->height = height; ! 853: pm->refcnt = 1; ! 854: pm->data = (caddr_t) pix; ! 855: IsTile(pm); ! 856: return(pm); ! 857: } ! 858: ! 859: FreePixmap (pixmap) ! 860: PIXMAP *pixmap; ! 861: { ! 862: XFreePixmap(Xpixmap(pixmap)); ! 863: free((caddr_t) pixmap); ! 864: } ! 865: ! 866: ToPixmap (width, height, format, data) ! 867: int width, height, format; ! 868: char *data; ! 869: { ! 870: register int n; ! 871: int shift; ! 872: register u_short *sptr; ! 873: register u_char *cptr; ! 874: register char *ptr; ! 875: ! 876: if (dev->entries == 0) ! 877: return; ! 878: if (format == XYFormat) { ! 879: n = BitmapSize(width, height); ! 880: if (pixshift) { ! 881: ptr = data + XYPixmapSize(width, height, dev->planes); ! 882: shift = XYPixmapSize(width, height, pixplanes); ! 883: bcopy(ptr - shift, ! 884: ptr - (shift + XYPixmapSize(width, height, pixshift)), ! 885: shift); ! 886: for (shift = 0, ptr -= n; ! 887: shift < pixshift; ! 888: shift++, ptr -= n) { ! 889: if (basepix & (1 << shift)) ! 890: AllOnes(ptr, width, height); ! 891: else ! 892: bzero(ptr, n); ! 893: } ! 894: } ! 895: for (shift = dev->planes, ptr = data; ! 896: --shift >= pixshift + pixplanes; ! 897: ptr += n) { ! 898: if (basepix & (1 << shift)) ! 899: AllOnes(ptr, width, height); ! 900: } ! 901: } else if (dev->planes > 8) { ! 902: for (n = WZPixmapSize(width, height) >> 1, sptr = (u_short *) data; ! 903: --n >= 0; ! 904: sptr++) ! 905: *sptr = npix(*sptr); ! 906: } else { ! 907: for (n = BZPixmapSize(width, height), cptr = (u_char *) data; ! 908: --n >= 0; ! 909: cptr++) ! 910: *cptr = npix(*cptr); ! 911: } ! 912: } ! 913: ! 914: AllOnes (data, width, height) ! 915: register char *data; ! 916: int width, height; ! 917: { ! 918: register int n, cnt; ! 919: register char *ptr; ! 920: ! 921: n = BitmapSize(width, 1); ! 922: for (ptr = data, cnt = n; --cnt >= 0; ) ! 923: *ptr++ = ~0; ! 924: for (ptr = data + n, cnt = height; --cnt > 0; ptr += n) ! 925: bcopy(data, ptr, n); ! 926: } ! 927: ! 928: FromPixmap (width, height, format, data) ! 929: int width, height, format; ! 930: register char *data; ! 931: { ! 932: register int n; ! 933: register u_short *sptr; ! 934: register u_char *cptr; ! 935: register char *ptr; ! 936: int cnt, shift; ! 937: ! 938: if (dev->entries == 0) ! 939: return; ! 940: if (format == XYFormat) { ! 941: if (pixshift) { ! 942: cnt = BitmapSize(width, height); ! 943: shift = XYPixmapSize(width, height, pixshift); ! 944: for (ptr = data + XYPixmapSize(width, height, dev->planes) - cnt, ! 945: n = pixshift; ! 946: --n >= 0; ! 947: ptr -= cnt) ! 948: bcopy(ptr - shift, ptr, cnt); ! 949: } ! 950: bzero(data, XYPixmapSize(width, height, dev->planes - pixplanes)); ! 951: } else if (dev->planes > 8) { ! 952: for (n = WZPixmapSize(width, height) >> 1, sptr = (u_short *) data; ! 953: --n >= 0; ! 954: sptr++) ! 955: *sptr = opix(*sptr); ! 956: } else { ! 957: for (n = BZPixmapSize(width, height), cptr = (u_char *) data; ! 958: --n >= 0; ! 959: cptr++) ! 960: *cptr = opix(*cptr); ! 961: } ! 962: } ! 963: ! 964: PIXMAP *MakePixmap (xymask, fore, back) ! 965: BITMAP *xymask; /* mask or NULL */ ! 966: int fore; /* foreground pixel */ ! 967: int back; /* background pixel */ ! 968: { ! 969: Pixmap pix; ! 970: register PIXMAP *pm; ! 971: ! 972: pix = XMakePixmap(xymask ? Xbitmap(xymask) : NULL, ! 973: npix(fore), npix(back)); ! 974: if (pix == NULL) ! 975: return(NULL); ! 976: pm = (PIXMAP *) Xalloc (sizeof (PIXMAP)); ! 977: pm->refcnt = 1; ! 978: pm->data = (caddr_t) pix; ! 979: if (xymask) { ! 980: pm->width = xymask->width; ! 981: pm->height = xymask->height; ! 982: IsTile(pm); ! 983: } else { ! 984: pm->width = 0; ! 985: pm->height = 0; ! 986: pm->tile = 1; ! 987: } ! 988: return(pm); ! 989: } ! 990: ! 991: IsTile (pm) ! 992: PIXMAP *pm; ! 993: { ! 994: int width, height; ! 995: ! 996: XQueryTileShape(pm->width, pm->height, &width, &height); ! 997: if (pm->width == width && pm->height == height) ! 998: pm->tile = 1; ! 999: else ! 1000: pm->tile = 0; ! 1001: } ! 1002: ! 1003: QueryShape (shape, width, height) ! 1004: int shape; /* 0: cursor, 1: tile, 2: brush */ ! 1005: short *width, *height; /* update in place */ ! 1006: { ! 1007: int rwidth, rheight; ! 1008: ! 1009: switch (shape) { ! 1010: case CursorShape: ! 1011: XQueryCursorShape(*width, *height, &rwidth, &rheight); ! 1012: break; ! 1013: case TileShape: ! 1014: XQueryTileShape(*width, *height, &rwidth, &rheight); ! 1015: break; ! 1016: case BrushShape: ! 1017: XQueryBrushShape(*width, *height, &rwidth, &rheight); ! 1018: break; ! 1019: } ! 1020: *width = rwidth; ! 1021: *height = rheight; ! 1022: } ! 1023: ! 1024: CURSOR *StoreCursor (func, image, fore, back, mask, xoff, yoff) ! 1025: int func; /* GX display function */ ! 1026: BITMAP *image; /* cursor image */ ! 1027: int fore; /* foreground pixel */ ! 1028: int back; /* background pixel */ ! 1029: BITMAP *mask; /* cursor mask or NULL */ ! 1030: int xoff, yoff; /* tip */ ! 1031: { ! 1032: Cursor cursor; ! 1033: register CURSOR *cr; ! 1034: int width, height; ! 1035: ! 1036: cursor = XStoreCursor(Xbitmap(image), mask ? Xbitmap(mask) : NULL, ! 1037: xoff, yoff, npix(fore), npix(back), func); ! 1038: if (cursor == NULL) ! 1039: return(NULL); ! 1040: XQueryCursorShape(image->width, image->height, &width, &height); ! 1041: cr = (CURSOR *) Xalloc(sizeof(CURSOR)); ! 1042: cr->width = width; ! 1043: cr->height = height; ! 1044: cr->xoff = xoff; ! 1045: cr->yoff = yoff; ! 1046: cr->xmin = xoff; ! 1047: cr->ymin = yoff; ! 1048: cr->xmax = screen_width - (width - xoff); ! 1049: cr->ymax = screen_height - (height - yoff); ! 1050: cr->refcnt = 1; ! 1051: cr->data = (caddr_t) cursor; ! 1052: return(cr); ! 1053: } ! 1054: ! 1055: FreeCursor (cursor) ! 1056: CURSOR *cursor; ! 1057: { ! 1058: XFreeCursor(Xcursor(cursor)); ! 1059: free((caddr_t) cursor); ! 1060: } ! 1061: ! 1062: LoadCursor (cursor) ! 1063: CURSOR *cursor; ! 1064: { ! 1065: if (cursor->xoff != cursor_x || cursor->yoff != cursor_y) { ! 1066: XCondWarpMouse(w, mouse.x + cursor->xoff, mouse.y + cursor->yoff, ! 1067: w, mouse.x + cursor_x, mouse.y + cursor_y, 1, 1); ! 1068: cursor_x = cursor->xoff; ! 1069: cursor_y = cursor->yoff; ! 1070: } ! 1071: XDefineCursor(w, Xcursor(cursor)); ! 1072: } ! 1073: ! 1074: /*ARGSUSED*/ ! 1075: SetMouseCharacteristics (threshold, acceleration) ! 1076: int threshold, acceleration; ! 1077: { ! 1078: } ! 1079: ! 1080: SetCursorPosition (pos) ! 1081: vsCursor *pos; ! 1082: { ! 1083: XCondWarpMouse(w, pos->x + cursor_x, pos->y + cursor_y, w, 0, 0, 0, 0); ! 1084: mouse = *pos; ! 1085: } ! 1086: ! 1087: /*ARGSUSED*/ ! 1088: SetAutoRepeat (onoff) ! 1089: int onoff; /* 0: off, 1: on */ ! 1090: { ! 1091: } ! 1092: ! 1093: /*ARGSUSED*/ ! 1094: SetKeyClick (volume) ! 1095: int volume; /* 0: off, 1-8: on */ ! 1096: { ! 1097: } ! 1098: ! 1099: SoundBell (volume) ! 1100: int volume; /* 0-7 */ ! 1101: { ! 1102: XFeep(volume); ! 1103: } ! 1104: ! 1105: /*ARGSUSED*/ ! 1106: SetLockLED (onoff) ! 1107: int onoff; /* 0: off, 1: on */ ! 1108: { ! 1109: } ! 1110: ! 1111: SetVideo (onoff) ! 1112: int onoff; /* 0: off, 1: on */ ! 1113: { ! 1114: return(onoff - 1); ! 1115: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.