summaryrefslogtreecommitdiff
path: root/graphics/xplot/patches/patch-ae
blob: 683c3498bb0eaafd800fbbaaf7bd12fd190f6823 (plain)
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
$NetBSD: patch-ae,v 1.1 2001/08/01 20:56:30 he Exp $

--- xplot.c.orig	Wed Jul  2 22:26:09 1997
+++ xplot.c
@@ -842,38 +842,39 @@
     /* Allocate some color cells */
       
     if (d_i[d].virgin ) {
+      int default_depth;
+      int default_screen;
+      int default_cmap;
+      XVisualInfo visual_info;
+
       d_i[d].virgin = 0;
       
       d_i[d].xplot_nagle_atom = XInternAtom(pl->dpy, "XPLOT_NAGLE", False);
 
-      d_i[d].clr_map = DefaultColormap(pl->dpy, DefaultScreen(pl->dpy));
+      default_screen = ScreenNumberOfScreen(pl->screen);
+      default_depth = DefaultDepth(pl->dpy, default_screen);
+      default_cmap = DefaultColormap(pl->dpy, default_screen);
       
-      if ( option_mono ||
+      i = DirectColor;
+      while (!XMatchVisualInfo(pl->dpy, default_screen, default_depth,
+			       i--, &visual_info))
+	;
 
-	   ! XAllocColorCells(pl->dpy, 
-			      d_i[d].clr_map, 0,
-			      &d_i[d].line_plane_mask, 1,
-			      d_i[d].pixel, NColors) )
-	{
-	  /* probably only one bit plane, or all the color cells are taken */
-#if 1
-	  if (! option_mono)
-	    fputs("XAllocColorCells failed, will only have one plot color\n",
-		  stderr);
-#endif
-	  for ( i = 0; i < NColors; i++) {
-	    d_i[d].Colors[i] = WhitePixelOfScreen(pl->screen);
-	  }
-	} else {
-	  for (i = 0; i < NColors; i++)  {
-	    XParseColor(pl->dpy, d_i[d].clr_map, ColorNames[i], &d_i[d].clr);
-	    d_i[d].clr.pixel = d_i[d].pixel[i];
-	    XStoreColor (pl->dpy, d_i[d].clr_map, &d_i[d].clr);
-	    d_i[d].clr.pixel |= d_i[d].line_plane_mask;
-	    XStoreColor (pl->dpy, d_i[d].clr_map, &d_i[d].clr);
-	    d_i[d].Colors[i] = d_i[d].clr.pixel;
+      if (i < StaticColor || option_mono) {
+      mono:
+	for ( i = 0; i < NColors; i++) {
+	  d_i[d].Colors[i] = WhitePixelOfScreen(pl->screen);
+	}
+      } else {
+	for (i = 0; i < NColors; i++)  {
+	  XParseColor(pl->dpy, default_cmap, ColorNames[i], &d_i[d].clr);
+	  if (!XAllocColor(pl->dpy, default_cmap, &d_i[d].clr)) {
+	    fprintf(stderr, "XAllocColor failed, reverting to monochrome\n");
+	    goto mono;
 	  }
+	  d_i[d].Colors[i] = d_i[d].clr.pixel;
 	}
+      }
     }
     
     for (i = 0; i < NColors; i++) {