[GRASS-SVN] r34961 - grass/trunk/general/g.cairocomp

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Dec 20 21:13:20 EST 2008


Author: glynn
Date: 2008-12-20 21:13:19 -0500 (Sat, 20 Dec 2008)
New Revision: 34961

Modified:
   grass/trunk/general/g.cairocomp/main.c
Log:
Make visual= parameter optional


Modified: grass/trunk/general/g.cairocomp/main.c
===================================================================
--- grass/trunk/general/g.cairocomp/main.c	2008-12-20 21:06:35 UTC (rev 34960)
+++ grass/trunk/general/g.cairocomp/main.c	2008-12-21 02:13:19 UTC (rev 34961)
@@ -27,7 +27,6 @@
 
 static int width, height;
 static XID output;
-static XID visid;
 static Display *dpy;
 static cairo_surface_t *surface;
 static cairo_t *cairo;
@@ -73,7 +72,7 @@
     fclose(fp);
 }
 
-static void init_xlib(const char *scr)
+static void init_xlib(const char *scr, const char *vis)
 {
     XVisualInfo templ;
     XVisualInfo *vinfo;
@@ -81,17 +80,31 @@
     Visual *visual;
     Pixmap pix;
     int scrn;
+    long visid;
     cairo_surface_t *s1, *s2;
 
     dpy = XOpenDisplay(NULL);
     if (!dpy)
 	G_fatal_error(_("Unable to open display"));
 
-    scrn = scr
-	? atoi(scr)
-	: DefaultScreen(dpy);
+    if (scr)
+	scrn = atoi(scr);
+    else {
+	const char *p = getenv("GRASS_CAIRO_SCREEN");
+	if (!p || sscanf(p, "%i", &scrn) != 1)
+	    scrn = DefaultScreen(dpy);
+    }
+
     screen = ScreenOfDisplay(dpy, scrn);
 
+    if (vis)
+	visid = strtoul(vis, NULL, 0);
+    else {
+	const char *p = getenv("GRASS_CAIRO_VISUAL");
+	if (!p || sscanf(p, "%li", &visid) != 1)
+	    visid = DefaultVisual(dpy, scrn)->visualid;
+    }
+
     templ.visualid = visid;
     templ.screen = scrn;
     vinfo = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &templ, &count);
@@ -198,7 +211,7 @@
     opt.visual = G_define_option();
     opt.visual->key = "visual";
     opt.visual->type = TYPE_INTEGER;
-    opt.visual->required = YES;
+    opt.visual->required = NO;
     opt.visual->description = _("Output Visual XID");
 
     opt.screen = G_define_option();
@@ -237,7 +250,6 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
-    visid = strtoul(opt.visual->answer, NULL, 0);
     width = atoi(opt.width->answer);
     height = atoi(opt.height->answer);
 
@@ -254,7 +266,7 @@
 	return 0;
     }
 
-    init_xlib(opt.screen->answer);
+    init_xlib(opt.screen->answer, opt.visual->answer);
 
     if (opt.bg->answer)
 	erase(opt.bg->answer);



More information about the grass-commit mailing list