Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!purdue!decwrl!ucbvax!webster.UUCP!jef
From: jef@webster.UUCP (Jef Poskanzer)
Newsgroups: comp.windows.x
Subject: Re: Icons & Xterm (X11)
Message-ID: <8805061948.AA22369@webster.sybase.uucp>
Date: 6 May 88 19:48:21 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The Internet
Lines: 141

The following message, sent to xpert two months ago, explains one way of
setting icon bitmaps in X11.

- - - - - - - - - -

Date: Tue, 15 Mar 88 13:44:49 PST
From: jef (Jef Poskanzer)
Subject: Re: How do I set an icon's pixmap?
To: pacbell!sun!athena.mit.edu!xpert

>If the Shell widget has an iconPixmap resource, it will be stored into the
>WM_HINTS property.  Both uwm and wm will acknowledge and use this (I've
>verified empirically); I can't vouch for any others.

Excellent.  I went ahead and added a string-to-pixmap type converter,
and now I can set icon pixmaps in my .Xdefaults file for *most* clients.
In particular, I can set them for xterm.  The issues remaining are:

1) If a client specifies its own icon pixmap, for example xload, xclock,
xlogo, then any user-specified iconPixmap resource is apparently ignored.
I've tried the obvious "xclock*iconPixmap: bitmapfilename", and a bunch of
variations, and I can't get it to listen to me.  This is probably just
a matter of me not understanding the defaulting precedences for resources.

2) Just setting a pixmap is useful, but what would be really nice is for
window managers to use the specified pixmap as a background and then add
the tool's name.  They do this if you let them supply their own icon
pixmap, so it shouldn't be hard to get this to happen for user-supplied
ones.

Anyway, I've appended the diffs to lib/Xt/Converters.c to add the type
converter.  They also fix a minor bug in the string-to-cursor converter
that prevented a user from specifying a cursor file using a full pathname.
---
Jef

        Jef Poskanzer   pacbell!sybase!jef@Sun.Com   jef@lbl-rtsg.ARPA

- - - - - - - - - -

*** ,Converters.c	Fri Feb 26 09:31:50 1988
--- Converters.c	Tue Mar 15 12:42:15 1988
***************
*** 101,106 ****
--- 105,111 ----
  static void CvtStringToFont();
  static void CvtStringToFontStruct();
  static void CvtStringToInt();
+ static void CvtStringToPixmap();
  static void CvtStringToPixel();
  
  
***************
*** 406,411 ****
--- 411,419 ----
  	    bitmap_file_path = BITMAPDIR;
      }
  
+     if ( name[0] == '/' || name[0] == '.' )
+ 	strcpy( filename, name );
+     else
          sprintf( filename, "%s/%s", bitmap_file_path, name );
      if (XReadBitmapFile( DisplayOfScreen(screen), RootWindowOfScreen(screen),
  			 filename, &width, &height, &source, &xhot, &yhot )
***************
*** 550,555 ****
--- 558,620 ----
  
  
  /*ARGSUSED*/
+ static void CvtStringToPixmap(args, num_args, fromVal, toVal)
+     XrmValuePtr args;
+     Cardinal    *num_args;
+     XrmValuePtr	fromVal;
+     XrmValuePtr	toVal;
+ {
+     char *name = (char *)fromVal->addr;
+     Screen *screen;
+     XrmName app_name;
+     XrmClass app_class;
+     static char* bitmap_file_path = NULL;
+     char filename[MAXPATHLEN];
+     Pixmap pixmap;
+     int width, height, xhot, yhot;
+ 
+     if (*num_args != 1)
+      XtError("String to Pixmap conversion needs screen argument");
+ 
+     screen = *((Screen **) args[0].addr);
+ 
+     if (bitmap_file_path == NULL) {
+ 	XrmName xrm_name[3];
+ 	XrmClass xrm_class[3];
+ 	XrmRepresentation rep_type;
+ 	XrmValue value;
+ 	xrm_name[0] = XtApplicationName;
+ 	xrm_name[1] = StringToQuark( "bitmapFilePath" );
+ 	xrm_name[2] = NULL;
+ 	xrm_class[0] = XtApplicationClass;
+ 	xrm_class[1] = StringToQuark( "BitmapFilePath" );
+ 	xrm_class[2] = NULL;
+ 	if (XrmQGetResource( XtDefaultDB, xrm_name, xrm_class,
+ 			     &rep_type, &value )
+ 	    && rep_type == StringToQuark(XtRString))
+ 	    bitmap_file_path = value.addr;
+ 	else
+ 	    bitmap_file_path = BITMAPDIR;
+     }
+ 
+     if ( name[0] == '/' || name[0] == '.' )
+ 	strcpy( filename, name );
+     else
+ 	sprintf( filename, "%s/%s", bitmap_file_path, name );
+     if (XReadBitmapFile( DisplayOfScreen(screen), RootWindowOfScreen(screen),
+ 			 filename, &width, &height, &pixmap, &xhot, &yhot )
+ 	!= BitmapSuccess) {
+ 	XtStringConversionWarning( name, "Pixmap" );
+ 	pixmap = None;		/* absolute fall-back for failed conversion */
+ 	done(&pixmap, Pixmap);
+ 	return;
+     }
+ 
+     done(&pixmap, Pixmap);
+ };
+ 
+ 
+ /*ARGSUSED*/
  static void CvtStringToPixel(args, num_args, fromVal, toVal)
      XrmValuePtr args;
      Cardinal    *num_args;
***************
*** 723,728 ****
--- 788,795 ----
      Add(XtQString,  XtQFontStruct,  CvtStringToFontStruct,  
  	screenConvertArg, XtNumber(screenConvertArg));
      Add(XtQString,  XtQInt,	    CvtStringToInt,	    NULL, 0);
+     Add(XtQString,  XtQPixmap,      CvtStringToPixmap,      
+ 	screenConvertArg, XtNumber(screenConvertArg));
      Add(XtQString,  XtQPixel,       CvtStringToPixel,       
  	colorConvertArgs, XtNumber(colorConvertArgs));