1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
|
/* $XTermId: cachedGCs.c,v 1.75 2018/07/15 18:21:17 tom Exp $ */
/*
* Copyright 2007-2017,2018 by Thomas E. Dickey
*
* All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name(s) of the above copyright
* holders shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization.
*/
#include <data.h>
#include <xstrings.h>
#include <fontutils.h>
#include <X11/Xmu/Drawing.h>
/*
* hide (or eliminate) calls to
* XCreateGC()
* XFreeGC()
* XGetGCValues()
* XSetBackground()
* XSetFont()
* XSetForeground()
* XtGetGC()
* XtReleaseGC()
* by associating an integer with each GC, maintaining a cache which
* reflects frequency of use rather than most recent usage.
*
* FIXME: XTermFonts should hold gc, font, fs.
*/
typedef struct {
GC gc;
unsigned used;
unsigned cset;
XTermFonts *font;
Pixel tile;
Pixel fg;
Pixel bg;
} CgsCacheData;
#define DEPTH 8
#define ITEM() (int) (me->data - me->list)
#define LIST(item) me->list[item]
#define LINK(item) me->data = (me->list + (item))
#define THIS(field) me->data->field
#define NEXT(field) me->next.field
#define HaveFont(font) (Boolean) ((font) != 0 && (font)->fs != 0)
#define GC_CSet GCFunction
typedef struct {
CgsCacheData list[DEPTH];
CgsCacheData *data; /* points to current list[] entry */
XtGCMask mask; /* changes since the last getCgsGC() */
CgsCacheData next; /* updated values, apply in getCgsGC() */
} CgsCache;
#if OPT_TRACE
#define CASE(name) case gc##name: result = #name; break
static const char *
traceCgsEnum(CgsEnum value)
{
const char *result = "?";
switch (value) {
CASE(Norm);
CASE(Bold);
CASE(NormReverse);
CASE(BoldReverse);
CASE(Border);
CASE(Filler);
#if OPT_BOX_CHARS
CASE(Line);
CASE(Dots);
#endif
#if OPT_DEC_CHRSET
CASE(CNorm);
CASE(CBold);
#endif
#if OPT_WIDE_CHARS
CASE(Wide);
CASE(WBold);
CASE(WideReverse);
CASE(WBoldReverse);
#endif
CASE(VTcursNormal);
CASE(VTcursFilled);
CASE(VTcursReverse);
CASE(VTcursOutline);
#if OPT_TEK4014
CASE(TKcurs);
#endif
CASE(MAX);
}
return result;
}
#undef CASE
static const char *
traceVTwin(XtermWidget xw, VTwin *value)
{
const char *result = "?";
if (value == 0)
result = "null";
else if (value == &(TScreenOf(xw)->fullVwin))
result = "fullVwin";
#ifndef NO_ACTIVE_ICON
else if (value == &(TScreenOf(xw)->iconVwin))
result = "iconVwin";
#endif
return result;
}
#if OPT_TRACE > 1
static String
traceCSet(unsigned cset)
{
static char result[80];
switch (cset) {
case CSET_SWL:
strcpy(result, "SWL");
break;
case CSET_DHL_TOP:
strcpy(result, "DHL_TOP");
break;
case CSET_DHL_BOT:
strcpy(result, "DHL_BOT");
break;
case CSET_DWL:
strcpy(result, "DWL");
break;
default:
sprintf(result, "%#x", cset);
break;
}
return result;
}
static String
traceFont(XTermFonts * font)
{
static char result[80];
if (HaveFont(font)) {
XFontStruct *fs = font->fs;
sprintf(result, "%p(%dx%d %d %#lx)",
fs,
fs->max_bounds.width,
fs->max_bounds.ascent + fs->max_bounds.descent,
fs->max_bounds.descent,
(unsigned long) (fs->fid));
} else {
strcpy(result, "null");
}
return result;
}
static String
tracePixel(XtermWidget xw, Pixel value)
{
#define CASE(name) { name, #name }
static struct {
TermColors code;
String name;
} t_colors[] = {
CASE(TEXT_FG),
CASE(TEXT_BG),
CASE(TEXT_CURSOR),
CASE(MOUSE_FG),
CASE(MOUSE_BG),
#if OPT_TEK4014
CASE(TEK_FG),
CASE(TEK_BG),
#endif
#if OPT_HIGHLIGHT_COLOR
CASE(HIGHLIGHT_BG),
CASE(HIGHLIGHT_FG),
#endif
#if OPT_TEK4014
CASE(TEK_CURSOR),
#endif
};
TScreen *screen = TScreenOf(xw);
String result = 0;
int n;
for (n = 0; n < NCOLORS; ++n) {
if (value == T_COLOR(screen, t_colors[n].code)) {
result = t_colors[n].name;
break;
}
}
if (result == 0) {
for (n = 0; n < MAXCOLORS; ++n) {
#if OPT_COLOR_RES
if (screen->Acolors[n].mode > 0
&& value == screen->Acolors[n].value) {
result = screen->Acolors[n].resource;
break;
}
#else
if (value == screen->Acolors[n]) {
char temp[80];
sprintf(temp, "Acolors[%d]", n);
result = x_strdup(temp);
break;
}
#endif
}
}
if (result == 0) {
char temp[80];
sprintf(temp, "%#lx", value);
result = x_strdup(temp);
}
return result;
}
#undef CASE
#endif /* OPT_TRACE > 1 */
#endif /* OPT_TRACE */
static CgsCache *
allocCache(void **cache_pointer)
{
if (*cache_pointer == 0) {
*cache_pointer = TypeCallocN(CgsCache, gcMAX);
TRACE(("allocCache %p\n", *cache_pointer));
}
return *((CgsCache **) cache_pointer);
}
#define ALLOC_CACHE(p) ((*(p) == 0) ? allocCache(p) : *(p))
static int
dataIndex(CgsCache * me)
{
return ITEM();
}
static void
relinkData(CgsCache * me, int item)
{
LINK(item);
}
/*
* Returns the appropriate cache pointer.
*/
static CgsCache *
myCache(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId)
{
CgsCache *result = 0;
if ((int) cgsId >= 0 && cgsId < gcMAX) {
#ifdef NO_ACTIVE_ICON
(void) xw;
(void) cgsWin;
#else
if (cgsWin == &(TScreenOf(xw)->iconVwin))
result = ALLOC_CACHE(&(TScreenOf(xw)->icon_cgs_cache));
else
#endif
result = ALLOC_CACHE(&(TScreenOf(xw)->main_cgs_cache));
result += cgsId;
if (result->data == 0) {
result->data = result->list;
}
}
return result;
}
static Display *
myDisplay(XtermWidget xw)
{
return TScreenOf(xw)->display;
}
static Drawable
myDrawable(XtermWidget xw, VTwin *cgsWin)
{
Drawable drawable = 0;
if (cgsWin != 0 && cgsWin->window != 0)
drawable = cgsWin->window;
if (drawable == 0)
drawable = RootWindowOfScreen(XtScreen(xw));
return drawable;
}
static GC
newCache(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId, CgsCache * me)
{
XGCValues xgcv;
XtGCMask mask;
THIS(font) = NEXT(font);
THIS(cset) = NEXT(cset);
THIS(fg) = NEXT(fg);
THIS(bg) = NEXT(bg);
memset(&xgcv, 0, sizeof(xgcv));
xgcv.font = NEXT(font)->fs->fid;
mask = (GCForeground | GCBackground | GCFont);
switch (cgsId) {
case gcFiller:
case gcBorder:
mask &= (XtGCMask) ~ GCFont;
/* FALLTHRU */
case gcNorm:
case gcBold:
case gcNormReverse:
case gcBoldReverse:
#if OPT_WIDE_CHARS
case gcWide:
case gcWBold:
case gcWideReverse:
case gcWBoldReverse:
#endif
mask |= (GCGraphicsExposures | GCFunction);
xgcv.graphics_exposures = True; /* default */
xgcv.function = GXcopy;
break;
#if OPT_BOX_CHARS
case gcLine:
mask |= (GCGraphicsExposures | GCFunction);
xgcv.graphics_exposures = True; /* default */
xgcv.function = GXcopy;
break;
case gcDots:
xgcv.fill_style = FillTiled;
xgcv.tile =
XmuCreateStippledPixmap(XtScreen((Widget) xw),
THIS(fg),
THIS(bg),
xw->core.depth);
THIS(tile) = xgcv.tile;
mask = (GCForeground | GCBackground);
mask |= (GCGraphicsExposures | GCFunction | GCTile | GCFillStyle);
xgcv.graphics_exposures = True; /* default */
xgcv.function = GXcopy;
break;
#endif
#if OPT_DEC_CHRSET
case gcCNorm:
case gcCBold:
break;
#endif
case gcVTcursNormal: /* FALLTHRU */
case gcVTcursFilled: /* FALLTHRU */
case gcVTcursReverse: /* FALLTHRU */
case gcVTcursOutline: /* FALLTHRU */
break;
#if OPT_TEK4014
case gcTKcurs: /* FALLTHRU */
/* FIXME */
#endif
case gcMAX: /* should not happen */
return 0;
}
xgcv.foreground = NEXT(fg);
xgcv.background = NEXT(bg);
THIS(gc) = XCreateGC(myDisplay(xw), myDrawable(xw, cgsWin), mask, &xgcv);
TRACE(("getCgsGC(%s) created gc %p(%d)\n",
traceCgsEnum(cgsId), (void *) THIS(gc), ITEM()));
THIS(used) = 0;
return THIS(gc);
}
#define SameFont(a, b) \
(Boolean) (HaveFont(a) \
&& HaveFont(b) \
&& (((a)->fs == (b)->fs) \
|| !memcmp((a)->fs, (b)->fs, sizeof(*((a)->fs)))))
#define SameColor(a,b) ((a) == (b))
#define SameCSet(a,b) ((a) == (b))
static GC
chgCache(XtermWidget xw, CgsEnum cgsId GCC_UNUSED, CgsCache * me, Bool both)
{
XGCValues xgcv;
XtGCMask mask = (GCForeground | GCBackground | GCFont);
memset(&xgcv, 0, sizeof(xgcv));
TRACE2(("chgCache(%s) old data fg=%s, bg=%s, font=%s cset %s\n",
traceCgsEnum(cgsId),
tracePixel(xw, THIS(fg)),
tracePixel(xw, THIS(bg)),
traceFont(THIS(font)),
traceCSet(THIS(cset))));
#if OPT_TRACE > 1
if (!SameFont(THIS(font), NEXT(font)))
TRACE2(("...chgCache new font=%s\n", traceFont(NEXT(font))));
if (!SameCSet(THIS(cset), NEXT(cset)))
TRACE2(("...chgCache new cset=%s\n", traceCSet(NEXT(cset))));
if (!SameColor(THIS(fg), NEXT(fg)))
TRACE2(("...chgCache new fg=%s\n", tracePixel(xw, NEXT(fg))));
if (!SameColor(THIS(bg), NEXT(bg)))
TRACE2(("...chgCache new bg=%s\n", tracePixel(xw, NEXT(bg))));
#endif
if (both) {
THIS(font) = NEXT(font);
THIS(cset) = NEXT(cset);
}
THIS(fg) = NEXT(fg);
THIS(bg) = NEXT(bg);
xgcv.font = THIS(font)->fs->fid;
xgcv.foreground = THIS(fg);
xgcv.background = THIS(bg);
XChangeGC(myDisplay(xw), THIS(gc), mask, &xgcv);
TRACE2(("...chgCache(%s) updated gc %p(%d)\n",
traceCgsEnum(cgsId), THIS(gc), ITEM()));
THIS(used) = 0;
return THIS(gc);
}
/*
* Use the "setCgsXXXX()" calls to initialize parameters for a new GC.
*/
void
setCgsFore(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId, Pixel fg)
{
CgsCache *me;
if ((me = myCache(xw, cgsWin, cgsId)) != 0) {
NEXT(fg) = fg;
me->mask |= GCForeground;
}
}
void
setCgsBack(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId, Pixel bg)
{
CgsCache *me;
if ((me = myCache(xw, cgsWin, cgsId)) != 0) {
NEXT(bg) = bg;
me->mask |= GCBackground;
}
}
#if OPT_DEC_CHRSET
void
setCgsCSet(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId, unsigned cset)
{
CgsCache *me;
if ((me = myCache(xw, cgsWin, cgsId)) != 0) {
NEXT(cset) = cset;
me->mask |= GC_CSet;
}
}
#else
#define setCgsCSet(xw, cgsWin, dstCgsId, cset) /* nothing */
#endif
void
setCgsFont(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId, XTermFonts * font)
{
CgsCache *me;
if ((me = myCache(xw, cgsWin, cgsId)) != 0) {
TScreen *screen = TScreenOf(xw);
if (!HaveFont(font)) {
if (cgsId != gcNorm)
(void) getCgsGC(xw, cgsWin, gcNorm);
#ifndef NO_ACTIVE_ICON
if (cgsWin == &(TScreenOf(xw)->iconVwin))
font = getIconicFont(screen);
else
#endif
font = GetNormalFont(screen, fNorm);
}
if (HaveFont(font) && okFont(font->fs)) {
TRACE2(("setCgsFont next: %s for %s slot %p, gc %p\n",
traceFont(font), traceCgsEnum(cgsId),
me, THIS(gc)));
TRACE2(("...next font was %s\n", traceFont(NEXT(font))));
NEXT(font) = font;
me->mask |= GCFont;
} else {
/* EMPTY */
TRACE2(("...NOT updated font for %s\n",
traceCgsEnum(cgsId)));
}
}
}
/*
* Discard all of the font information, e.g., we are resizing the font.
* Keep the GC's so we can simply change them rather than creating new ones.
*/
void
clrCgsFonts(XtermWidget xw, VTwin *cgsWin, XTermFonts * font)
{
if (HaveFont(font)) {
int j;
for_each_gc(j) {
CgsCache *me;
if ((me = myCache(xw, cgsWin, (CgsEnum) j)) != 0) {
int k;
for (k = 0; k < DEPTH; ++k) {
if (SameFont(LIST(k).font, font)) {
TRACE2(("clrCgsFonts %s gc %p(%d) %s\n",
traceCgsEnum((CgsEnum) j),
LIST(k).gc,
k,
traceFont(font)));
LIST(k).font = 0;
LIST(k).cset = 0;
}
}
if (SameFont(NEXT(font), font)) {
TRACE2(("clrCgsFonts %s next %s\n",
traceCgsEnum((CgsEnum) j),
traceFont(font)));
NEXT(font) = 0;
NEXT(cset) = 0;
me->mask &= (unsigned) ~(GCFont | GC_CSet);
}
}
}
}
}
/*
* Return a GC associated with the given id, allocating if needed.
*/
GC
getCgsGC(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId)
{
CgsCache *me;
GC result = 0;
if ((me = myCache(xw, cgsWin, cgsId)) != 0) {
TRACE2(("getCgsGC(%s, %s)\n",
traceVTwin(xw, cgsWin), traceCgsEnum(cgsId)));
if (me->mask != 0) {
int j;
unsigned used = 0;
/* fill in the unchanged fields */
if (!(me->mask & GC_CSet))
NEXT(cset) = 0; /* OPT_DEC_CHRSET */
if (!(me->mask & GCFont))
NEXT(font) = THIS(font);
if (!(me->mask & GCForeground))
NEXT(fg) = THIS(fg);
if (!(me->mask & GCBackground))
NEXT(bg) = THIS(bg);
if (NEXT(font) == 0) {
setCgsFont(xw, cgsWin, cgsId, 0);
}
TRACE2(("...Cgs new data fg=%s, bg=%s, font=%s cset %s\n",
tracePixel(xw, NEXT(fg)),
tracePixel(xw, NEXT(bg)),
traceFont(NEXT(font)),
traceCSet(NEXT(cset))));
/* try to find the given data in an already-created GC */
for (j = 0; j < DEPTH; ++j) {
if (LIST(j).gc != 0
&& SameFont(LIST(j).font, NEXT(font))
&& SameCSet(LIST(j).cset, NEXT(cset))
&& SameColor(LIST(j).fg, NEXT(fg))
&& SameColor(LIST(j).bg, NEXT(bg))) {
LINK(j);
result = THIS(gc);
TRACE2(("getCgsGC existing %p(%d)\n", result, ITEM()));
break;
}
}
if (result == 0) {
/* try to find an empty slot, to create a new GC */
used = 0;
for (j = 0; j < DEPTH; ++j) {
if (LIST(j).gc == 0) {
LINK(j);
result = newCache(xw, cgsWin, cgsId, me);
break;
}
if (used < LIST(j).used)
used = LIST(j).used;
}
}
if (result == 0) {
int k;
/* if none were empty, pick the least-used slot, to modify */
for (j = 0, k = -1; j < DEPTH; ++j) {
if (used >= LIST(j).used) {
used = LIST(j).used;
k = j;
}
}
LINK(k);
TRACE2(("...getCgsGC least-used(%d) was %d\n", k, THIS(used)));
result = chgCache(xw, cgsId, me, True);
}
me->next = *(me->data);
} else {
result = THIS(gc);
}
me->mask = 0;
THIS(used) += 1;
TRACE2(("...getCgsGC(%s, %s) gc %p(%d), used %d\n",
traceVTwin(xw, cgsWin),
traceCgsEnum(cgsId), result, ITEM(), THIS(used)));
}
return result;
}
/*
* Return the font for the given GC.
*/
CgsEnum
getCgsId(XtermWidget xw, VTwin *cgsWin, GC gc)
{
int n;
CgsEnum result = gcNorm;
for_each_gc(n) {
CgsCache *me;
if ((me = myCache(xw, cgsWin, (CgsEnum) n)) != 0) {
if (THIS(gc) == gc) {
result = (CgsEnum) n;
break;
}
}
}
return result;
}
/*
* Return the font for the given GC.
*/
XTermFonts *
getCgsFont(XtermWidget xw, VTwin *cgsWin, GC gc)
{
int n;
XTermFonts *result = 0;
for_each_gc(n) {
CgsCache *me;
if ((me = myCache(xw, cgsWin, (CgsEnum) n)) != 0) {
if (THIS(gc) == gc) {
result = THIS(font);
break;
}
}
}
return result;
}
/*
* Return the foreground color for the given GC.
*/
Pixel
getCgsFore(XtermWidget xw, VTwin *cgsWin, GC gc)
{
int n;
Pixel result = 0;
for_each_gc(n) {
CgsCache *me;
if ((me = myCache(xw, cgsWin, (CgsEnum) n)) != 0) {
if (THIS(gc) == gc) {
result = THIS(fg);
break;
}
}
}
return result;
}
/*
* Return the background color for the given GC.
*/
Pixel
getCgsBack(XtermWidget xw, VTwin *cgsWin, GC gc)
{
int n;
Pixel result = 0;
for_each_gc(n) {
CgsCache *me;
if ((me = myCache(xw, cgsWin, (CgsEnum) n)) != 0) {
if (THIS(gc) == gc) {
result = THIS(bg);
break;
}
}
}
return result;
}
/*
* Copy the parameters (except GC of course) from one cache record to another.
*/
void
copyCgs(XtermWidget xw, VTwin *cgsWin, CgsEnum dstCgsId, CgsEnum srcCgsId)
{
if (dstCgsId != srcCgsId) {
CgsCache *me;
if ((me = myCache(xw, cgsWin, srcCgsId)) != 0) {
TRACE(("copyCgs from %s to %s\n",
traceCgsEnum(srcCgsId),
traceCgsEnum(dstCgsId)));
TRACE2(("copyCgs from %s (me %p, fg %s, bg %s, cset %s) to %s {{\n",
traceCgsEnum(srcCgsId),
me,
tracePixel(xw, THIS(fg)),
tracePixel(xw, THIS(bg)),
traceCSet(THIS(cset)),
traceCgsEnum(dstCgsId)));
setCgsCSet(xw, cgsWin, dstCgsId, THIS(cset));
setCgsFore(xw, cgsWin, dstCgsId, THIS(fg));
setCgsBack(xw, cgsWin, dstCgsId, THIS(bg));
setCgsFont(xw, cgsWin, dstCgsId, THIS(font));
TRACE2(("...copyCgs }}\n"));
}
}
}
/*
* Interchange colors in the cache, e.g., for reverse-video.
*/
void
redoCgs(XtermWidget xw, Pixel fg, Pixel bg, CgsEnum cgsId)
{
VTwin *cgsWin = WhichVWin(TScreenOf(xw));
CgsCache *me = myCache(xw, cgsWin, cgsId);
if (me != 0) {
CgsCacheData *save_data = me->data;
int n;
for (n = 0; n < DEPTH; ++n) {
if (LIST(n).gc != 0 && HaveFont(LIST(n).font)) {
LINK(n);
if (LIST(n).fg == fg
&& LIST(n).bg == bg) {
setCgsFore(xw, cgsWin, cgsId, bg);
setCgsBack(xw, cgsWin, cgsId, fg);
} else if (LIST(n).fg == bg
&& LIST(n).bg == fg) {
setCgsFore(xw, cgsWin, cgsId, fg);
setCgsBack(xw, cgsWin, cgsId, bg);
} else {
continue;
}
(void) chgCache(xw, cgsId, me, False);
}
}
me->data = save_data;
}
}
/*
* Swap the cache records, e.g., when doing reverse-video.
*/
void
swapCgs(XtermWidget xw, VTwin *cgsWin, CgsEnum dstCgsId, CgsEnum srcCgsId)
{
if (dstCgsId != srcCgsId) {
CgsCache *src;
if ((src = myCache(xw, cgsWin, srcCgsId)) != 0) {
CgsCache *dst;
if ((dst = myCache(xw, cgsWin, dstCgsId)) != 0) {
CgsCache tmp;
int srcIndex = dataIndex(src);
int dstIndex = dataIndex(dst);
EXCHANGE(*src, *dst, tmp);
relinkData(src, dstIndex);
relinkData(dst, srcIndex);
}
}
}
}
/*
* Free any GC associated with the given id.
*/
GC
freeCgs(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId)
{
CgsCache *me;
if ((me = myCache(xw, cgsWin, cgsId)) != 0) {
int j;
for (j = 0; j < DEPTH; ++j) {
if (LIST(j).gc != 0) {
TRACE(("freeCgs(%s, %s) gc %p(%d)\n",
traceVTwin(xw, cgsWin),
traceCgsEnum(cgsId), (void *) LIST(j).gc, j));
clrCgsFonts(xw, cgsWin, LIST(j).font);
#if OPT_BOX_CHARS
if (cgsId == gcDots) {
XmuReleaseStippledPixmap(XtScreen((Widget) xw), LIST(j).tile);
}
#endif
XFreeGC(TScreenOf(xw)->display, LIST(j).gc);
memset(&LIST(j), 0, sizeof(LIST(j)));
}
LINK(0);
}
}
return 0;
}
#ifdef NO_LEAKS
void
noleaks_cachedCgs(XtermWidget xw)
{
#ifndef NO_ACTIVE_ICON
free(TScreenOf(xw)->icon_cgs_cache);
#endif
free(TScreenOf(xw)->main_cgs_cache);
}
#endif
|