aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2000-03-02 13:23:42 +0000
committerGerd Moellmann2000-03-02 13:23:42 +0000
commit1f847cf8e5d4fe702934e38c6f445b10d6d856a9 (patch)
tree39ce24080121a61c26a227f40e96c5c9721c5bce
parent43f3fa09a10869de7626e4793ae98c17dee37642 (diff)
downloademacs-1f847cf8e5d4fe702934e38c6f445b10d6d856a9.tar.gz
emacs-1f847cf8e5d4fe702934e38c6f445b10d6d856a9.zip
(x_free_colors): New function.
(unload_color, free_face_colors): Use it.
-rw-r--r--src/xfaces.c92
1 files changed, 47 insertions, 45 deletions
diff --git a/src/xfaces.c b/src/xfaces.c
index 55799d183d1..3004cfaea02 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -511,6 +511,40 @@ static void clear_font_table P_ ((struct frame *));
511 511
512#ifdef HAVE_X_WINDOWS 512#ifdef HAVE_X_WINDOWS
513 513
514/* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
515 color values. Interrupt input must be blocked when this function
516 is called. */
517
518void
519x_free_colors (f, pixels, npixels)
520 struct frame *f;
521 unsigned long *pixels;
522 int npixels;
523{
524 int class = FRAME_X_DISPLAY_INFO (f)->visual->class;
525
526 /* If display has an immutable color map, freeing colors is not
527 necessary and some servers don't allow it. So don't do it. */
528 if (class != StaticColor && class != StaticGray && class != TrueColor)
529 {
530 Display *dpy = FRAME_X_DISPLAY (f);
531 Colormap cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
532 int screen_no = XScreenNumberOfScreen (FRAME_X_SCREEN (f));
533 unsigned long black = BlackPixel (dpy, screen_no);
534 unsigned long white = WhitePixel (dpy, screen_no);
535 unsigned long *px;
536 int i, j;
537
538 px = (unsigned long *) alloca (npixels * sizeof *px);
539 for (i = j = 0; i < npixels; ++i)
540 if (pixels[i] != black && pixels[i] != white)
541 px[j++] = pixels[i];
542
543 if (j)
544 XFreeColors (dpy, cmap, px, j, 0);
545 }
546}
547
514/* Create and return a GC for use on frame F. GC values and mask 548/* Create and return a GC for use on frame F. GC values and mask
515 are given by XGCV and MASK. */ 549 are given by XGCV and MASK. */
516 550
@@ -1420,23 +1454,8 @@ unload_color (f, pixel)
1420 struct frame *f; 1454 struct frame *f;
1421 unsigned long pixel; 1455 unsigned long pixel;
1422{ 1456{
1423 Display *dpy = FRAME_X_DISPLAY (f);
1424 int class = FRAME_X_DISPLAY_INFO (f)->visual->class;
1425
1426 if (pixel == BLACK_PIX_DEFAULT (f)
1427 || pixel == WHITE_PIX_DEFAULT (f))
1428 return;
1429
1430 BLOCK_INPUT; 1457 BLOCK_INPUT;
1431 1458 x_free_colors (f, &pixel, 1);
1432 /* If display has an immutable color map, freeing colors is not
1433 necessary and some servers don't allow it. So don't do it. */
1434 if (! (class == StaticColor || class == StaticGray || class == TrueColor))
1435 {
1436 Colormap cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
1437 XFreeColors (dpy, cmap, &pixel, 1, 0);
1438 }
1439
1440 UNBLOCK_INPUT; 1459 UNBLOCK_INPUT;
1441} 1460}
1442 1461
@@ -1456,62 +1475,45 @@ free_face_colors (f, face)
1456 && class != StaticGray 1475 && class != StaticGray
1457 && class != TrueColor) 1476 && class != TrueColor)
1458 { 1477 {
1459 Display *dpy;
1460 Colormap cmap;
1461
1462 BLOCK_INPUT; 1478 BLOCK_INPUT;
1463 dpy = FRAME_X_DISPLAY (f);
1464 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
1465 1479
1466 if (face->foreground != BLACK_PIX_DEFAULT (f) 1480 if (!face->foreground_defaulted_p)
1467 && face->foreground != WHITE_PIX_DEFAULT (f)
1468 && !face->foreground_defaulted_p)
1469 { 1481 {
1470 XFreeColors (dpy, cmap, &face->foreground, 1, 0); 1482 x_free_colors (f, &face->foreground, 1);
1471 IF_DEBUG (--ncolors_allocated); 1483 IF_DEBUG (--ncolors_allocated);
1472 } 1484 }
1473 1485
1474 if (face->background != BLACK_PIX_DEFAULT (f) 1486 if (!face->background_defaulted_p)
1475 && face->background != WHITE_PIX_DEFAULT (f)
1476 && !face->background_defaulted_p)
1477 { 1487 {
1478 XFreeColors (dpy, cmap, &face->background, 1, 0); 1488 x_free_colors (f, &face->background, 1);
1479 IF_DEBUG (--ncolors_allocated); 1489 IF_DEBUG (--ncolors_allocated);
1480 } 1490 }
1481 1491
1482 if (face->underline_p 1492 if (face->underline_p
1483 && !face->underline_defaulted_p 1493 && !face->underline_defaulted_p)
1484 && face->underline_color != BLACK_PIX_DEFAULT (f)
1485 && face->underline_color != WHITE_PIX_DEFAULT (f))
1486 { 1494 {
1487 XFreeColors (dpy, cmap, &face->underline_color, 1, 0); 1495 x_free_colors (f, &face->underline_color, 1);
1488 IF_DEBUG (--ncolors_allocated); 1496 IF_DEBUG (--ncolors_allocated);
1489 } 1497 }
1490 1498
1491 if (face->overline_p 1499 if (face->overline_p
1492 && !face->overline_color_defaulted_p 1500 && !face->overline_color_defaulted_p)
1493 && face->overline_color != BLACK_PIX_DEFAULT (f)
1494 && face->overline_color != WHITE_PIX_DEFAULT (f))
1495 { 1501 {
1496 XFreeColors (dpy, cmap, &face->overline_color, 1, 0); 1502 x_free_colors (f, &face->overline_color, 1);
1497 IF_DEBUG (--ncolors_allocated); 1503 IF_DEBUG (--ncolors_allocated);
1498 } 1504 }
1499 1505
1500 if (face->strike_through_p 1506 if (face->strike_through_p
1501 && !face->strike_through_color_defaulted_p 1507 && !face->strike_through_color_defaulted_p)
1502 && face->strike_through_color != BLACK_PIX_DEFAULT (f)
1503 && face->strike_through_color != WHITE_PIX_DEFAULT (f))
1504 { 1508 {
1505 XFreeColors (dpy, cmap, &face->strike_through_color, 1, 0); 1509 x_free_colors (f, &face->strike_through_color, 1);
1506 IF_DEBUG (--ncolors_allocated); 1510 IF_DEBUG (--ncolors_allocated);
1507 } 1511 }
1508 1512
1509 if (face->box != FACE_NO_BOX 1513 if (face->box != FACE_NO_BOX
1510 && !face->box_color_defaulted_p 1514 && !face->box_color_defaulted_p)
1511 && face->box_color != BLACK_PIX_DEFAULT (f)
1512 && face->box_color != WHITE_PIX_DEFAULT (f))
1513 { 1515 {
1514 XFreeColors (dpy, cmap, &face->box_color, 1, 0); 1516 x_free_colors (f, &face->box_color, 1);
1515 IF_DEBUG (--ncolors_allocated); 1517 IF_DEBUG (--ncolors_allocated);
1516 } 1518 }
1517 1519