[comp.windows.x] Hobbes cursor for root

erc@pai.UUCP (Eric Johnson) (07/13/90)

A few days ago, I saw a Hobbes bitmap (the face of the tiger
Hobbes from the comic strip Calvin and Hobbes), apparently from:
"David McFadzean <david@hpcpdcc>".  Since I liked the bitmap,
I threw together a program to make the root window cursor be
the Hobbes bitmap, mainly because I had never had reason to use
XCreatePixmapCursor() before.  The program is a throw-away,
so don't waste much (if any) time on it.  Here it is--note that
the artwork is all McFadzean's, not mine (I claim no artistic
abilities).

hobbes.c just uses the X library, so you can compile (on UNIX)
with something akin to:
cc -o hobbes hobbes.c -lX11

For Interactive's 386/ix, add in a -linet after the -lX11. For
SCO Open Desktop, add in -ltlisock -lsocket -lnsl_s after
the -lX11 (SCO didn't like the large bitmap size for this
cursor, though).

You can pass a -display DisplayName to the program.

Have fun,
-Eric

------------------------cut here------------------------------------------
/*
 *	hobbes.c
 *	Program to make the root window's cursor be
 *	the Hobbes (a la Calvin and Hobbes) cursor from:
 *	"David McFadzean <david@hpcpdcc>"
 *
 *	Link this program with the X library, e.g.
 *
 *	cc -o hobbes hobbes.c -lX11
 *
 *	13 July 90
 *
 *	E F Johnson
 *	erc@pai.mn.org
 *		Have fun.
 *
 *	Note: since it is a "weird" bitmap size (25x25),
 *	I'd seen occasions on a Sun SPARC where the
 *	whole picture isn't drawn. I don't really think
 *	its worth it to track down, though.
 *
 *	Tested on:
 *	Sun SPARCStation-1, X11R4, colour
 *	HP 375, X11R3, colour
 *	386 PC, X11R3 (SCO Open DeskTop), colour--cursor is too big, sorry.
 */

#include  <stdio.h>
#include  <X11/Xlib.h>
#include  <X11/Xutil.h>


/*
 *	Hobbes cursor from
 *	"David McFadzean <david@hpcpdcc>"
 */
#define hobbes_width 25
#define hobbes_height 25
#define hobbes_x_hot 16
#define hobbes_y_hot 15
static char hobbes_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00,
   0x78, 0xe0, 0x07, 0x00, 0xfc, 0xf8, 0x07, 0x00, 0xcc, 0x07, 0x04, 0x00,
   0x0c, 0xf0, 0x0b, 0x00, 0x7c, 0x1c, 0x06, 0x00, 0x38, 0x00, 0x00, 0x00,
   0xe0, 0x03, 0x10, 0x00, 0xe0, 0x41, 0x11, 0x00, 0x20, 0x40, 0x11, 0x00,
   0xe0, 0x07, 0x10, 0x00, 0xe0, 0xc1, 0x17, 0x00, 0x10, 0xe0, 0x2f, 0x00,
   0x20, 0xe0, 0x6f, 0x00, 0x18, 0xe0, 0x2f, 0x00, 0x20, 0xc6, 0x67, 0x00,
   0x18, 0x84, 0x2b, 0x00, 0x20, 0x08, 0x64, 0x00, 0x70, 0xf0, 0x13, 0x00,
   0x80, 0x01, 0x08, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00};

/*
 *	Hobbes cursor mask from
 *	"David McFadzean <david@hpcpdcc>"
 */
#define hobbesmask_width 25
#define hobbesmask_height 25
static char hobbesmask_bits[] = {
    0x00, 0x00, 0x00, 0xfe, 0x00, 0xe0, 0x07, 0xfe, 
    0xfc, 0xf0, 0x0f, 0xfe, 0xfe, 0xfd, 0x0f, 0xfe, 
    0xfe, 0xff, 0x0f, 0xfe, 0xfe, 0xff, 0x1f, 0xfe, 
    0xfe, 0xff, 0x1f, 0xfe, 0xfe, 0xff, 0x1f, 0xfe, 
    0xfe, 0xff, 0x3f, 0xfe, 0xfc, 0xff, 0x3f, 0xfe, 
    0xf0, 0xff, 0x3f, 0xfe, 0xf0, 0xff, 0x3f, 0xfe, 
    0xf0, 0xff, 0x3f, 0xfe, 0xf8, 0xff, 0x7f, 0xfe, 
    0xf8, 0xff, 0xff, 0xfe, 0xfc, 0xff, 0xff, 0xfe, 
    0xfc, 0xff, 0xff, 0xfe, 0xfc, 0xff, 0xff, 0xfe, 
    0xfc, 0xff, 0xff, 0xfe, 0xfc, 0xff, 0xff, 0xfe, 
    0xf8, 0xff, 0xff, 0xfe, 0xf8, 0xff, 0x3f, 0xfe, 
    0xc0, 0xff, 0x1f, 0xfe, 0x00, 0xff, 0x0f, 0xfe, 
    0x00, 0x00, 0x00, 0xfe, 
};


main( argc, argv )

int	argc;
char	*argv[];

{	/* main */
	char		display_name[ 256 ];
	int		i;
	Display		*display;
	int		screen;
	Window		rootwindow;
	Pixmap		hobbes_pix, mask_pix;
	Colormap	cmap;
	XColor		black, white, tmp;
	Cursor		cursor;


	/*
	 * Determine display name
	 */
	display_name[0] = '\0';
	i = 1;
	while( i < argc )
		{
		if ( strncmp( argv[i], "-disp", 5 ) == 0 )
			{
			i++;
			if ( i < argc )
				{
				strcpy( display_name, argv[i] );
				}
			}
		i++;
		}


	/*
	 * Open display connection
	 */
	display = XOpenDisplay( display_name );

	if ( display == (Display *) NULL )
		{
		fprintf( stderr, "Error in opening display connection\n" );
		exit( 1 );
		}


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


	/*
	 * Create pixmaps for the cursor and the cursor mask
	 */
	hobbes_pix = XCreateBitmapFromData( display,
				rootwindow,
				hobbes_bits,
				hobbes_width,
				hobbes_height );
			

	mask_pix = XCreateBitmapFromData( display,
				rootwindow,
				hobbesmask_bits,
				hobbesmask_width,
				hobbesmask_height );
			

	/*
	 * Get XColor structs
	 * for black and white.
	 * We assume the default
	 * colormap has entries
	 * for black and white.
	 */
	cmap = DefaultColormap( display, screen );

	XLookupColor( display, cmap, "black", &tmp, &black );
	XLookupColor( display, cmap, "white", &tmp, &white ); 


	/*
	 * Now, create cursor from the pixmaps
	 */
	cursor = XCreatePixmapCursor( display,
			hobbes_pix,
			mask_pix,
			&black,
			&white,
			hobbes_x_hot,	
			hobbes_y_hot );


	/*
	 * Set root window to use hobbes cursor
	 */
	XDefineCursor( display, rootwindow, cursor );
	XFlush( display );


	/*
	 * Clean up and exit
	 */
	XFreePixmap( display, hobbes_pix );
	XFreePixmap( display, mask_pix );

	XCloseDisplay( display );
	exit( 0 );

}	/* main */


/*
 *	end of file
 */

------------------------cut here------------------------------------------

-- 
Eric F. Johnson               phone: +1 612 894 0313    BTI: Industrial
Boulware Technologies, Inc.   fax:   +1 612 894 0316    automation systems
415 W. Travelers Trail        email: erc@pai.mn.org     and services
Burnsville, MN 55337 USA