[comp.windows.x] Making a colour bitmap the root background

erc@pai.UUCP (Eric Johnson) (05/04/90)

In article <1837@beowulf.UUCP>, bownesrm@beowulf.UUCP (Waiting for the Sun) writes:
> 
> 	I have a handfull of X colour bitmaps I'd like to use as my root 
> background. Anyone know if there is a way to do this? xsetroot only
> seems to work with 1bit bitmaps.
> 
> Bob Bownes, aka iii, aka keptin comrade doktor bobwrench
> 874 Kari Dr, Eau Claire (Oh Claire!) Wisc, 54701 (715)-835-1934 voice
> bownesrm@beowulf.uucp {uunet!crdgw1,uunet!ssi}!beowulf!bownesrm


I'm not sure what format your coloured bitmaps are in, but if you
can create X pixmaps out of them, then you might want to experiment
with the following Xlib function:

	XSetWindowBackgroundPixmap( display, window, pixmap )

	Display	*display;
	Window	window;
	Pixmap	pixmap;

	This function sets the window's background to be the pixmap.  If the 
	pixmap is smaller than the window, the pixmap is replicated ("tiled")
	across the window.

You'll have better luck if you create the pixmap with the same depth as
your target window (in this case, the root window). You could try
something like:

	Display	*display;
	int	screen;
	Window	rootwindow;
	Pixmap	pixmap;


	/*
	 * You may want to support -display displayname
 	 * here, instead of NULL
	 */
	display = XOpenDisplay( NULL );

	if ( display == (Display *) NULL )
		{
		fprintf( stderr, "Cannot open connection to X server.\n" );
		exit( 1 );
		}

	screen     = DefaultScreen( display );
	rootwindow = RootWindow( display, screen );


	/*
	 * Create the pixmap at the size you want and the root`s depth.
	 * Load in your file and draw into the pixmap.
	 */

	...


	/*
	 * Tile pixmap across root window.
	 * The clear repaints the (new) background.
	 */
	XSetWindowBackgroundPixmap( display, rootwindow, pixmap );
	XClearWindow( display, rootwindow );
	XFlush( display );

	XCloseDisplay( display );
	exit( 0 );


Hope this helps,
-Eric

-- 
Eric F. Johnson, Boulware Technologies, Inc. 
415 W. Travelers Trail, Burnsville, MN 55337 USA.  Phone: +1 612-894-0313. 
erc@pai.mn.org    - or -   bungia!pai!erc
"Things are more like they are now than they've ever been," US President Ford.