chiark / gitweb /
Use XAllocNamedColor instead of assuming that pixels 0 and 1 are sensible (!)
authorian <ian>
Sun, 3 Apr 2005 15:03:15 +0000 (15:03 +0000)
committerian <ian>
Sun, 3 Apr 2005 15:03:15 +0000 (15:03 +0000)
x11.cc

diff --git a/x11.cc b/x11.cc
index b88a5e9..830b407 100644 (file)
--- a/x11.cc
+++ b/x11.cc
@@ -8,16 +8,28 @@
 
 static Parameter<int> x11size("x11size", "X11 window size", 500, 100, 10, 10000);
 
+static unsigned long colour_pixel(Display *display, Colormap cmap,
+                                 const char *name) {
+  XColor colour;
+  Status st;
+  st= XAllocNamedColor(display,cmap,name,&colour,&colour);
+  if (!st) {
+    cerr << "cannot allocate colour " << name << ", quitting\n";
+    exit(1);
+  }
+  return colour.pixel;
+}
+
 X11Output::X11Output() {
   XGCValues gcvalues;
   display= XOpenDisplay(0);
   window= XCreateSimpleWindow(display,
                               DefaultRootWindow(display),
                               0,0, x11size,x11size, 0,0,0);
-  gcvalues.background= 0;
+  Colormap cmap= DefaultColormap(display,DefaultScreen(display));
+  gcvalues.background= colour_pixel(display,cmap,"black");
   fabric= XCreateGC(display,window,GCBackground,&gcvalues);
-  gcvalues.foreground= 1;
-  gcvalues.background= 1;
+  gcvalues.foreground= gcvalues.background= colour_pixel(display,cmap,"white");
   mesh= XCreateGC(display,window,GCForeground|GCBackground,&gcvalues);
   XSelectInput(display,window,0);
   XMapWindow(display,window);