[comp.sources.x] v08i102: xseticonwindow, Part01/01

thoth@reef.cis.ufl.edu (Gilligan) (08/28/90)

Submitted-by: thoth@reef.cis.ufl.edu (Gilligan)
Posting-number: Volume 8, Issue 102
Archive-name: xiconw/part01



  If you REALLY don't like twm putting labels on your icons, then
rewrite it (I have).  Otherwise you can use this cheap hack I wrote to
set your icon window to anything you want.  If there's enough interest
I can enhance it to read the !!COLOR!! XPM files and/or do text.

#!/bin/sh
# This is a shell archive (shar 3.32)
# made 08/25/1990 21:45 UTC by thoth@reef
# Source directory /net/lightning/0/thoth/src/X/xseticonwindow
#
# existing files WILL be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   3015 -rw-r--r-- README
#  12488 -rw-r--r-- COPYING
#    437 -rw-r--r-- Imakefile
#    763 -rw-r--r-- MITs,not,mine__copyright.h
#  12644 -rw-r--r-- dsimple.c
#   1651 -rw-r--r-- dsimple.h
#   8078 -rw-r--r-- xseticonwindow.c
#
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= README ==============
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
X
X	README for xseticonwindow
X  Copyright (C) 1990 Robert Forsman <thoth@ufl.edu>
X
X  This program is a quick hack that allows you to set the icon window
Xfor a particular application.  It was originally written because some
Xguy wrote to comp.windows.x trying to figure out how to make twm NOT
Xdisplay the icon name at the bottom of the icon.  He got about 5
Xidentical WRONG answers and I figured someone had to do him a favor.
X
XIf you already have a window you'd like to use then invoke
Xxseticonwindow with the -iconwindow flag (also, mail me and tell me
Xwhere the hell you found this window just lying around)
X
X   xseticonwindow -iconwindow 0xb00451
X
X  Otherwise you will have to build one from a bitmap file.  You can do
Xthis with the -bitmap, -foreground, -background, -bordercolor, and
X-borderwidth arguments.
X
X   xseticonwindow -name emacs -bitmap emacs.icon -fg yellow -bg blue -bw 2
X
X  The program sticks around once the window is configured, waiting for
Xit to be destroyed.  If you wish to interrupt the program press ^C or
Xkill -TERM it.  It will not immediately exit, but all you have to do
Xis change the window's state (iconify, deiconify, unmap, Something
Xfrom StructureNotifyMask) and the program will wake up and HOPEFULLY
Xrestore the window's previous state (iconwindow/pixmap that is).  I
Xdid have difficulties with TWM that I solved, but since most other
Xwindow managers cost money I don't support them ( for "religious"
Xreasons ).
X
X  It uses the dsimple.c package from the *FREE* MIT x11r4 distribution
Xso users of xprop and xwininfo should have no problem making it do
Xtricks.
X
X  Any problems, comments, or suggestions should be directed to me,
XRobert Forsman: <thoth@ufl.edu>.
X
XWARRANTY:
X  THERE IS NONE!
X  I make no guarantees about this software.  I don't promise to fix or
Xmaintain it and I'm not responsible if you hose yourself with it.  Any
Xhelp you get from me is pure charity.  Any damage you do is your own
Xfault (and stay away from donuts, you might cut yourself).  It's free
Xsoftware, what do you expect?
X
X  You can copy and modify this software under the terms of the GNU
XGENERAL PUBLIC LICENSE.  Essentially, you can copy this all you want
Xand you cannot restrict the copying of derivative works.
X  I've inserted a copy of their license with this in the file COPYING.
XRead it and "see the light" :).
X
X  dsimple.c and dsimple.h are NOT covered by this license, they are
Xcovered by another.  I include them merely as a convenice so you don't
Xhave to dig them out of your source ( they are located in any one of
X~x11r4/mit/clients/{xlsfonts,xprop,xwd,xwininfo}/dsimple.* ).
X
XBUGS:
X  restoring the window to its former state is a dicey affair.  I
Xshould probably watch the window for reparenting or something.
X
XTODO:
X  write a man page, get a life, make it do text at the bottom in an
Xarbitrary font (trivial, but who wants it?).
X  How do I get this put in the mit source?  I've got some other handy
Xutils that are REALLY useful (xsetprop is written, xiconify could be
Xwritten in an hour)
SHAR_EOF
$TOUCH -am 0825172590 README &&
chmod 0644 README ||
echo "restore of README failed"
set `wc -c README`;Wc_c=$1
if test "$Wc_c" != "3015"; then
	echo original size 3015, current size $Wc_c
fi
# ============= COPYING ==============
echo "x - extracting COPYING (Text)"
sed 's/^X//' << 'SHAR_EOF' > COPYING &&
X
X		    GNU GENERAL PUBLIC LICENSE
X		     Version 1, February 1989
X
X Copyright (C) 1989 Free Software Foundation, Inc.
X                    675 Mass Ave, Cambridge, MA 02139, USA
X Everyone is permitted to copy and distribute verbatim copies
X of this license document, but changing it is not allowed.
X
X			    Preamble
X
X  The license agreements of most software companies try to keep users
Xat the mercy of those companies.  By contrast, our General Public
XLicense is intended to guarantee your freedom to share and change free
Xsoftware--to make sure the software is free for all its users.  The
XGeneral Public License applies to the Free Software Foundation's
Xsoftware and to any other program whose authors commit to using it.
XYou can use it for your programs, too.
X
X  When we speak of free software, we are referring to freedom, not
Xprice.  Specifically, the General Public License is designed to make
Xsure that you have the freedom to give away or sell copies of free
Xsoftware, that you receive source code or can get it if you want it,
Xthat you can change the software or use pieces of it in new free
Xprograms; and that you know you can do these things.
X
X  To protect your rights, we need to make restrictions that forbid
Xanyone to deny you these rights or to ask you to surrender the rights.
XThese restrictions translate to certain responsibilities for you if you
Xdistribute copies of the software, or if you modify it.
X
X  For example, if you distribute copies of a such a program, whether
Xgratis or for a fee, you must give the recipients all the rights that
Xyou have.  You must make sure that they, too, receive or can get the
Xsource code.  And you must tell them their rights.
X
X  We protect your rights with two steps: (1) copyright the software, and
X(2) offer you this license which gives you legal permission to copy,
Xdistribute and/or modify the software.
X
X  Also, for each author's protection and ours, we want to make certain
Xthat everyone understands that there is no warranty for this free
Xsoftware.  If the software is modified by someone else and passed on, we
Xwant its recipients to know that what they have is not the original, so
Xthat any problems introduced by others will not reflect on the original
Xauthors' reputations.
X
X  The precise terms and conditions for copying, distribution and
Xmodification follow.
X
X		    GNU GENERAL PUBLIC LICENSE
X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X  0. This License Agreement applies to any program or other work which
Xcontains a notice placed by the copyright holder saying it may be
Xdistributed under the terms of this General Public License.  The
X"Program", below, refers to any such program or work, and a "work based
Xon the Program" means either the Program or any work containing the
XProgram or a portion of it, either verbatim or with modifications.  Each
Xlicensee is addressed as "you".
X
X  1. You may copy and distribute verbatim copies of the Program's source
Xcode as you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy an appropriate copyright notice and
Xdisclaimer of warranty; keep intact all the notices that refer to this
XGeneral Public License and to the absence of any warranty; and give any
Xother recipients of the Program a copy of this General Public License
Xalong with the Program.  You may charge a fee for the physical act of
Xtransferring a copy.
X
X  2. You may modify your copy or copies of the Program or any portion of
Xit, and copy and distribute such modifications under the terms of Paragraph
X1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating that
X    you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish, that
X    in whole or in part contains the Program or any part thereof, either
X    with or without modifications, to be licensed at no charge to all
X    third parties under the terms of this General Public License (except
X    that you may choose to grant warranty protection to some or all
X    third parties, at your option).
X
X    c) If the modified program normally reads commands interactively when
X    run, you must cause it, when started running for such interactive use
X    in the simplest and most usual way, to print or display an
X    announcement including an appropriate copyright notice and a notice
X    that there is no warranty (or else, saying that you provide a
X    warranty) and that users may redistribute the program under these
X    conditions, and telling the user how to view a copy of this General
X    Public License.
X
X    d) You may charge a fee for the physical act of transferring a
X    copy, and you may at your option offer warranty protection in
X    exchange for a fee.
X
XMere aggregation of another independent work with the Program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other work under the scope of these terms.
X
X  3. You may copy and distribute the Program (or a portion or derivative of
Xit, under Paragraph 2) in object code or executable form under the terms of
XParagraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal charge
X    for the cost of distribution) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XSource code for a work means the preferred form of the work for making
Xmodifications to it.  For an executable file, complete source code means
Xall the source code for all modules it contains; but, as a special
Xexception, it need not include source code for modules which are standard
Xlibraries that accompany the operating system on which the executable
Xfile runs, or for standard header files or definitions files that
Xaccompany that operating system.
X
X  4. You may not copy, modify, sublicense, distribute or transfer the
XProgram except as expressly provided under this General Public License.
XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
Xthe Program is void, and will automatically terminate your rights to use
Xthe Program under this License.  However, parties who have received
Xcopies, or rights to use copies, from you under this General Public
XLicense will not have their licenses terminated so long as such parties
Xremain in full compliance.
X
X  5. By copying, distributing or modifying the Program (or any work based
Xon the Program) you indicate your acceptance of this license to do so,
Xand all its terms and conditions.
X
X  6. Each time you redistribute the Program (or any work based on the
XProgram), the recipient automatically receives a license from the original
Xlicensor to copy, distribute or modify the Program subject to these
Xterms and conditions.  You may not impose any further restrictions on the
Xrecipients' exercise of the rights granted herein.
X
X  7. The Free Software Foundation may publish revised and/or new versions
Xof the General Public License from time to time.  Such new versions will
Xbe similar in spirit to the present version, but may differ in detail to
Xaddress new problems or concerns.
X
XEach version is given a distinguishing version number.  If the Program
Xspecifies a version number of the license which applies to it and "any
Xlater version", you have the option of following the terms and conditions
Xeither of that version or of any later version published by the Free
XSoftware Foundation.  If the Program does not specify a version number of
Xthe license, you may choose any version ever published by the Free Software
XFoundation.
X
X  8. If you wish to incorporate parts of the Program into other free
Xprograms whose distribution conditions are different, write to the author
Xto ask for permission.  For software which is copyrighted by the Free
XSoftware Foundation, write to the Free Software Foundation; we sometimes
Xmake exceptions for this.  Our decision will be guided by the two goals
Xof preserving the free status of all derivatives of our free software and
Xof promoting the sharing and reuse of software generally.
X
X			    NO WARRANTY
X
X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
XREPAIR OR CORRECTION.
X
X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
XPOSSIBILITY OF SUCH DAMAGES.
X
X		     END OF TERMS AND CONDITIONS
X
X	Appendix: How to Apply These Terms to Your New Programs
X
X  If you develop a new program, and you want it to be of the greatest
Xpossible use to humanity, the best way to achieve this is to make it
Xfree software which everyone can redistribute and change under these
Xterms.
X
X  To do so, attach the following notices to the program.  It is safest to
Xattach them to the start of each source file to most effectively convey
Xthe exclusion of warranty; and each file should have at least the
X"copyright" line and a pointer to where the full notice is found.
X
X    <one line to give the program's name and a brief idea of what it does.>
X    Copyright (C) 19yy  <name of author>
X
X    This program is free software; you can redistribute it and/or modify
X    it under the terms of the GNU General Public License as published by
X    the Free Software Foundation; either version 1, or (at your option)
X    any later version.
X
X    This program is distributed in the hope that it will be useful,
X    but WITHOUT ANY WARRANTY; without even the implied warranty of
X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X    GNU General Public License for more details.
X
X    You should have received a copy of the GNU General Public License
X    along with this program; if not, write to the Free Software
X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XAlso add information on how to contact you by electronic and paper mail.
X
XIf the program is interactive, make it output a short notice like this
Xwhen it starts in an interactive mode:
X
X    Gnomovision version 69, Copyright (C) 19xx name of author
X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
X    This is free software, and you are welcome to redistribute it
X    under certain conditions; type `show c' for details.
X
XThe hypothetical commands `show w' and `show c' should show the
Xappropriate parts of the General Public License.  Of course, the
Xcommands you use may be called something other than `show w' and `show
Xc'; they could even be mouse-clicks or menu items--whatever suits your
Xprogram.
X
XYou should also get your employer (if you work as a programmer) or your
Xschool, if any, to sign a "copyright disclaimer" for the program, if
Xnecessary.  Here a sample; alter the names:
X
X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
X  program `Gnomovision' (a program to direct compilers to make passes
X  at assemblers) written by James Hacker.
X
X  <signature of Ty Coon>, 1 April 1989
X  Ty Coon, President of Vice
X
XThat's all there is to it!
SHAR_EOF
$TOUCH -am 0825164390 COPYING &&
chmod 0644 COPYING ||
echo "restore of COPYING failed"
set `wc -c COPYING`;Wc_c=$1
if test "$Wc_c" != "12488"; then
	echo original size 12488, current size $Wc_c
fi
# ============= Imakefile ==============
echo "x - extracting Imakefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > Imakefile &&
X        DEPLIBS = $(DEPXMULIB) $(DEPEXTENSIONLIB) $(DEPXLIB)
XLOCAL_LIBRARIES = $(XMULIB) $(EXTENSIONLIB) $(XLIB)
X           SRCS = xseticonwindow.c dsimple.c
X           OBJS = xseticonwindow.o dsimple.o
X
XComplexProgramTarget(xseticonwindow)
X
Xshar: xseticonwindow.shar
X
XDISTFILES = README COPYING\
X	Imakefile\
X	MITs,not,mine__copyright.h\
X	dsimple.c dsimple.h\
X	xseticonwindow.c
X
Xxseticonwindow.shar: ${DISTFILES}
X	shar ${DISTFILES} > $@
SHAR_EOF
$TOUCH -am 0825174590 Imakefile &&
chmod 0644 Imakefile ||
echo "restore of Imakefile failed"
set `wc -c Imakefile`;Wc_c=$1
if test "$Wc_c" != "437"; then
	echo original size 437, current size $Wc_c
fi
# ============= MITs,not,mine__copyright.h ==============
echo "x - extracting MITs,not,mine__copyright.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > MITs,not,mine__copyright.h &&
X/* $XConsortium: copyright.h,v 1.5 89/12/22 16:11:28 rws Exp $ */
X/*
X
XCopyright 1985, 1986, 1987, 1988, 1989 by the
XMassachusetts Institute of Technology
X
XPermission to use, copy, modify, distribute, and sell this software and its
Xdocumentation for any purpose is hereby granted without fee, provided that
Xthe above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation, and that the name of M.I.T. not be used in advertising or
Xpublicity pertaining to distribution of the software without specific,
Xwritten prior permission.  M.I.T. makes no representations about the
Xsuitability of this software for any purpose.  It is provided "as is"
Xwithout express or implied warranty.
X
X*/
X
SHAR_EOF
$TOUCH -am 0825165390 MITs,not,mine__copyright.h &&
chmod 0644 MITs,not,mine__copyright.h ||
echo "restore of MITs,not,mine__copyright.h failed"
set `wc -c MITs,not,mine__copyright.h`;Wc_c=$1
if test "$Wc_c" != "763"; then
	echo original size 763, current size $Wc_c
fi
# ============= dsimple.c ==============
echo "x - extracting dsimple.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > dsimple.c &&
X/* $XConsortium: dsimple.c,v 1.10 89/12/13 11:47:29 rws Exp $ */
X#include <X11/Xos.h>
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include <X11/cursorfont.h>
X#include <stdio.h>
X/*
X * Other_stuff.h: Definitions of routines in other_stuff.
X *
X * Written by Mark Lillibridge.   Last updated 7/1/87
X *
X * Send bugs, etc. to chariot@athena.mit.edu.
X */
X
Xunsigned long Resolve_Color();
XPixmap Bitmap_To_Pixmap();
XWindow Select_Window();
Xvoid out();
Xvoid blip();
XWindow Window_With_Name();
Xvoid Fatal_Error();
X
X/*
X * Just_display: A group of routines designed to make the writting of simple
X *               X11 applications which open a display but do not open
X *               any windows much faster and easier.  Unless a routine says
X *               otherwise, it may be assumed to require program_name, dpy,
X *               and screen already defined on entry.
X *
X * Written by Mark Lillibridge.   Last updated 7/1/87
X *
X * Send bugs, etc. to chariot@athena.mit.edu.
X */
X
X
X/* This stuff is defined in the calling program by just_display.h */
Xextern char *program_name;
Xextern Display *dpy;
Xextern int screen;
X
X
X/*
X * Malloc: like malloc but handles out of memory using Fatal_Error.
X */
Xchar *Malloc(size)
X     unsigned size;
X{
X	char *data, *malloc();
X
X	if (!(data = malloc(size)))
X	  Fatal_Error("Out of memory!");
X
X	return(data);
X}
X	
X
X/*
X * Realloc: like Malloc except for realloc, handles NULL using Malloc.
X */
Xchar *Realloc(ptr, size)
X        char *ptr;
X        int size;
X{
X	char *new_ptr, *realloc();
X
X	if (!ptr)
X	  return(Malloc(size));
X
X	if (!(new_ptr = realloc(ptr, size)))
X	  Fatal_Error("Out of memory!");
X
X	return(new_ptr);
X}
X
X
X/*
X * Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obselete)
X * If found, remove it from command line.  Don't go past a lone -.
X */
Xchar *Get_Display_Name(pargc, argv)
X    int *pargc;  /* MODIFIED */
X    char **argv; /* MODIFIED */
X{
X    int argc = *pargc;
X    char **pargv = argv+1;
X    char *displayname = NULL;
X    int i;
X
X    for (i = 1; i < argc; i++) {
X	char *arg = argv[i];
X
X	if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
X	    if (++i >= argc) usage ();
X
X	    displayname = argv[i];
X	    *pargc -= 2;
X	    continue;
X	}
X	if (!strcmp(arg,"-")) {
X		while (i<argc)
X			*pargv++ = argv[i++];
X		break;
X	}
X	*pargv++ = arg;
X    }
X
X    *pargv = NULL;
X    return (displayname);
X}
X
X
X/*
X * Open_Display: Routine to open a display with correct error handling.
X *               Does not require dpy or screen defined on entry.
X */
XDisplay *Open_Display(display_name)
Xchar *display_name;
X{
X	Display *d;
X
X	d = XOpenDisplay(display_name);
X	if (d == NULL) {
X	    fprintf (stderr, "%s:  unable to open display '%s'\n",
X		     program_name, XDisplayName (display_name));
X	    usage ();
X	    /* doesn't return */
X	}
X
X	return(d);
X}
X
X
X/*
X * Setup_Display_And_Screen: This routine opens up the correct display (i.e.,
X *                           it calls Get_Display_Name) and then stores a
X *                           pointer to it in dpy.  The default screen
X *                           for this display is then stored in screen.
X *                           Does not require dpy or screen defined.
X */
Xvoid Setup_Display_And_Screen(argc, argv)
Xint *argc;      /* MODIFIED */
Xchar **argv;    /* MODIFIED */
X{
X	dpy = Open_Display (Get_Display_Name(argc, argv));
X	screen = DefaultScreen(dpy);
X}
X
X
X/*
X * Open_Font: This routine opens a font with error handling.
X */
XXFontStruct *Open_Font(name)
Xchar *name;
X{
X	XFontStruct *font;
X
X	if (!(font=XLoadQueryFont(dpy, name)))
X	  Fatal_Error("Unable to open font %s!", name);
X
X	return(font);
X}
X
X
X/*
X * Beep: Routine to beep the display.
X */
Xvoid Beep()
X{
X	XBell(dpy, 50);
X}
X
X
X/*
X * ReadBitmapFile: same as XReadBitmapFile except it returns the bitmap
X *                 directly and handles errors using Fatal_Error.
X */
Xstatic void _bitmap_error(status, filename)
X     int status;
X     char *filename;
X{
X  if (status == BitmapOpenFailed)
X    Fatal_Error("Can't open file %s!", filename);
X  else if (status == BitmapFileInvalid)
X    Fatal_Error("file %s: Bad bitmap format.", filename);
X  else
X    Fatal_Error("Out of memory!");
X}
X
XPixmap ReadBitmapFile(d, filename, width, height, x_hot, y_hot)
X     Drawable d;
X     char *filename;
X     int *width, *height, *x_hot, *y_hot;
X{
X  Pixmap bitmap;
X  int status;
X
X  status = XReadBitmapFile(dpy, RootWindow(dpy, screen), filename,
X			   (unsigned int *)width, (unsigned int *)height,
X			   &bitmap, x_hot, y_hot);
X  if (status != BitmapSuccess)
X    _bitmap_error(status, filename);
X
X  return(bitmap);
X}
X
X
X/*
X * WriteBitmapFile: same as XWriteBitmapFile except it handles errors
X *                  using Fatal_Error.
X */
Xvoid WriteBitmapFile(filename, bitmap, width, height, x_hot, y_hot)
X     char *filename;
X     Pixmap bitmap;
X     int width, height, x_hot, y_hot;
X{
X  int status;
X
X  status= XWriteBitmapFile(dpy, filename, bitmap, width, height, x_hot,
X			   y_hot);
X  if (status != BitmapSuccess)
X    _bitmap_error(status, filename);
X}
X
X
X/*
X * Select_Window_Args: a rountine to provide a common interface for
X *                     applications that need to allow the user to select one
X *                     window on the screen for special consideration.
X *                     This routine implements the following command line
X *                     arguments:
X *
X *                       -root            Selects the root window.
X *                       -id <id>         Selects window with id <id>. <id> may
X *                                        be either in decimal or hex.
X *                       -name <name>     Selects the window with name <name>.
X *
X *                     Call as Select_Window_Args(&argc, argv) in main before
X *                     parsing any of your program's command line arguments.
X *                     Select_Window_Args will remove its arguments so that
X *                     your program does not have to worry about them.
X *                     The window returned is the window selected or 0 if
X *                     none of the above arguments was present.  If 0 is
X *                     returned, Select_Window should probably be called after
X *                     all command line arguments, and other setup is done.
X *                     For examples of usage, see xwininfo, xwd, or xprop.
X */
XWindow Select_Window_Args(rargc, argv)
X     int *rargc;
X     char **argv;
X#define ARGC (*rargc)
X{
X	int nargc=1;
X	int argc;
X	char **nargv;
X	Window w=0;
X
X	nargv = argv+1; argc = ARGC;
X#define OPTION argv[0]
X#define NXTOPTP ++argv, --argc>0
X#define NXTOPT if (++argv, --argc==0) usage()
X#define COPYOPT nargv++[0]=OPTION; nargc++
X
X	while (NXTOPTP) {
X		if (!strcmp(OPTION, "-")) {
X			COPYOPT;
X			while (NXTOPTP)
X			  COPYOPT;
X			break;
X		}
X		if (!strcmp(OPTION, "-root")) {
X			w=RootWindow(dpy, screen);
X			continue;
X		}
X		if (!strcmp(OPTION, "-name")) {
X			NXTOPT;
X			w = Window_With_Name(dpy, RootWindow(dpy, screen),
X					     OPTION);
X			if (!w)
X			  Fatal_Error("No window with name %s exists!",OPTION);
X			continue;
X		}
X		if (!strcmp(OPTION, "-id")) {
X			NXTOPT;
X			w=0;
X			sscanf(OPTION, "0x%lx", &w);
X			if (!w)
X			  sscanf(OPTION, "%ld", &w);
X			if (!w)
X			  Fatal_Error("Invalid window id format: %s.", OPTION);
X			continue;
X		}
X		COPYOPT;
X	}
X	ARGC = nargc;
X	
X	return(w);
X}
X
X/*
X * Other_stuff: A group of routines which do common X11 tasks.
X *
X * Written by Mark Lillibridge.   Last updated 7/1/87
X *
X * Send bugs, etc. to chariot@athena.mit.edu.
X */
X
X
X#define NULL 0
X
Xextern Display *dpy;
Xextern int screen;
X
X/*
X * Resolve_Color: This routine takes a color name and returns the pixel #
X *                that when used in the window w will be of color name.
X *                (WARNING:  The colormap of w MAY be modified! )
X *                If colors are run out of, only the first n colors will be
X *                as correct as the hardware can make them where n depends
X *                on the display.  This routine does not require wind to
X *                be defined.
X */
Xunsigned long Resolve_Color(w, name)
X     Window w;
X     char *name;
X{
X	XColor c;
X	Colormap colormap;
X	XWindowAttributes wind_info;
X
X	/*
X	 * The following is a hack to insure machines without a rgb table
X	 * handle at least white & black right.
X	 */
X	if (!strcmp(name, "white"))
X	  name="#ffffffffffff";
X	if (!strcmp(name, "black"))
X	  name="#000000000000";
X
X	XGetWindowAttributes(dpy, w, &wind_info);
X	colormap = wind_info.colormap;
X
X	if (!XParseColor(dpy, colormap, name, &c))
X	  Fatal_Error("Bad color format '%s'.", name);
X
X	if (!XAllocColor(dpy, colormap, &c))
X	  Fatal_Error("XAllocColor failed!");
X
X	return(c.pixel);
X}
X
X
X/*
X * Bitmap_To_Pixmap: Convert a bitmap to a 2 colored pixmap.  The colors come
X *                   from the foreground and background colors of the gc.
X *                   Width and height are required solely for efficiency.
X *                   If needed, they can be obtained via. XGetGeometry.
X */
XPixmap Bitmap_To_Pixmap(dpy, d, gc, bitmap, width, height)
X     Display *dpy;
X     Drawable d;
X     GC gc;
X     Pixmap bitmap;
X     int width, height;
X{
X  Pixmap pix;
X  int x;
X  unsigned int i, depth;
X  Drawable root;
X
X  if (!XGetGeometry(dpy, d, &root, &x, &x, &i, &i, &i, &depth))
X    return(0);
X
X  pix = XCreatePixmap(dpy, d, width, height, (int)depth);
X
X  XCopyPlane(dpy, bitmap, pix, gc, 0, 0, width, height, 0, 0, 1);
X
X  return(pix);
X}
X
X
X/*
X * blip: a debugging routine.  Prints Blip! on stderr with flushing. 
X */
Xvoid blip()
X{
X  outl("blip!");
X}
X
X
X/*
X * Routine to let user select a window using the mouse
X */
X
XWindow Select_Window(dpy)
X     Display *dpy;
X{
X  int status;
X  Cursor cursor;
X  XEvent event;
X  Window target_win = None, root = RootWindow(dpy,screen);
X  int buttons = 0;
X
X  /* Make the target cursor */
X  cursor = XCreateFontCursor(dpy, XC_crosshair);
X
X  /* Grab the pointer using target cursor, letting it room all over */
X  status = XGrabPointer(dpy, root, False,
X			ButtonPressMask|ButtonReleaseMask, GrabModeSync,
X			GrabModeAsync, root, cursor, CurrentTime);
X  if (status != GrabSuccess) Fatal_Error("Can't grab the mouse.");
X
X  /* Let the user select a window... */
X  while ((target_win == None) || (buttons != 0)) {
X    /* allow one more event */
X    XAllowEvents(dpy, SyncPointer, CurrentTime);
X    XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
X    switch (event.type) {
X    case ButtonPress:
X      if (target_win == None) {
X	target_win = event.xbutton.subwindow; /* window selected */
X	if (target_win == None) target_win = root;
X      }
X      buttons++;
X      break;
X    case ButtonRelease:
X      if (buttons > 0) /* there may have been some down before we started */
X	buttons--;
X       break;
X    }
X  } 
X
X  XUngrabPointer(dpy, CurrentTime);      /* Done with pointer */
X
X  return(target_win);
X}
X
X
X/*
X * Window_With_Name: routine to locate a window with a given name on a display.
X *                   If no window with the given name is found, 0 is returned.
X *                   If more than one window has the given name, the first
X *                   one found will be returned.  Only top and its subwindows
X *                   are looked at.  Normally, top should be the RootWindow.
X */
XWindow Window_With_Name(dpy, top, name)
X     Display *dpy;
X     Window top;
X     char *name;
X{
X	Window *children, dummy;
X	unsigned int nchildren;
X	int i;
X	Window w=0;
X	char *window_name;
X
X	if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
X	  return(top);
X
X	if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
X	  return(0);
X
X	for (i=0; i<nchildren; i++) {
X		w = Window_With_Name(dpy, children[i], name);
X		if (w)
X		  break;
X	}
X	if (children) XFree ((char *)children);
X	return(w);
X}
X
X/*
X * outl: a debugging routine.  Flushes stdout then prints a message on stderr
X *       and flushes stderr.  Used to print messages when past certain points
X *       in code so we can tell where we are.  Outl may be invoked like
X *       printf with up to 7 arguments.
X */
Xoutl(msg, arg0,arg1,arg2,arg3,arg4,arg5,arg6)
X     char *msg;
X     char *arg0, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6;
X{
X	fflush(stdout);
X	fprintf(stderr, msg, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
X	fprintf(stderr, "\n");
X	fflush(stderr);
X}
X
X
X/*
X * Standard fatal error routine - call like printf but maximum of 7 arguments.
X * Does not require dpy or screen defined.
X */
Xvoid Fatal_Error(msg, arg0,arg1,arg2,arg3,arg4,arg5,arg6)
Xchar *msg;
Xchar *arg0, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6;
X{
X	fflush(stdout);
X	fflush(stderr);
X	fprintf(stderr, "%s: error: ", program_name);
X	fprintf(stderr, msg, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
X	fprintf(stderr, "\n");
X	exit(1);
X}
SHAR_EOF
$TOUCH -am 0825163290 dsimple.c &&
chmod 0644 dsimple.c ||
echo "restore of dsimple.c failed"
set `wc -c dsimple.c`;Wc_c=$1
if test "$Wc_c" != "12644"; then
	echo original size 12644, current size $Wc_c
fi
# ============= dsimple.h ==============
echo "x - extracting dsimple.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > dsimple.h &&
X/* $XConsortium: dsimple.h,v 1.2 88/09/06 17:38:22 jim Exp $ */
X/*
X * Just_display.h: This file contains the definitions needed to use the
X *                 functions in just_display.c.  It also declares the global
X *                 variables dpy, screen, and program_name which are needed to
X *                 use just_display.c.
X *
X * Written by Mark Lillibridge.   Last updated 7/1/87
X *
X * Send bugs, etc. to chariot@athena.mit.edu.
X */
X
X    /* Global variables used by routines in just_display.c */
X
Xchar *program_name = "unknown_program";       /* Name of this program */
XDisplay *dpy;                                 /* The current display */
Xint screen;                                   /* The current screen */
X
X#define INIT_NAME program_name=argv[0]        /* use this in main to setup
X                                                 program_name */
X
X    /* Declaritions for functions in just_display.c */
X
Xvoid Fatal_Error();
Xchar *Malloc();
Xchar *Realloc();
Xchar *Get_Display_Name();
XDisplay *Open_Display();
Xvoid Setup_Display_And_Screen();
XXFontStruct *Open_Font();
Xvoid Beep();
XPixmap ReadBitmapFile();
Xvoid WriteBitmapFile();
XWindow Select_Window_Args();
X
X#define X_USAGE "[host:display]"              /* X arguments handled by
X						 Get_Display_Name */
X#define SELECT_USAGE "[{-root|-id <id>|-font <font>|-name <name>}]"
X
X/*
X * Other_stuff.h: Definitions of routines in other_stuff.
X *
X * Written by Mark Lillibridge.   Last updated 7/1/87
X *
X * Send bugs, etc. to chariot@athena.mit.edu.
X */
X
Xunsigned long Resolve_Color();
XPixmap Bitmap_To_Pixmap();
XWindow Select_Window();
Xvoid out();
Xvoid blip();
XWindow Window_With_Name();
SHAR_EOF
$TOUCH -am 0825163290 dsimple.h &&
chmod 0644 dsimple.h ||
echo "restore of dsimple.h failed"
set `wc -c dsimple.h`;Wc_c=$1
if test "$Wc_c" != "1651"; then
	echo original size 1651, current size $Wc_c
fi
# ============= xseticonwindow.c ==============
echo "x - extracting xseticonwindow.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > xseticonwindow.c &&
X/*
X  xseticonwindow.c - set the icon window of an application from a
X		bitmap or preexisting window.
X */
Xstatic char ego[] =  " Copyright (C) 1990 Robert Forsman <thoth@ufl.edu> \n";
X/*
X    This program is free software; you can redistribute it and/or modify
X    it under the terms of the GNU General Public License as published by
X    the Free Software Foundation; either version 1, or (at your option)
X    any later version.
X
X    This program is distributed in the hope that it will be useful,
X    but WITHOUT ANY WARRANTY; without even the implied warranty of
X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X    GNU General Public License for more details.
X
X    You should have received a copy of the GNU General Public License
X    along with this program; if not, write to the Free Software
X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
X    dsimple.c and dsimple.h are part of the *FREE* MIT sample X
X    windows server (R4) and are subject to their copyrights and license
X    agreements (similar to public domain).  The copyright from their
X    source distribution (mit/include/copyright.h) is included for your
X    reading convenience.
X
X */
X
X#include <stdio.h>
X#include <signal.h>
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X
X#include "dsimple.h"
X
Xextern int errno;
Xextern char *sys_errlist[];
XWindow window;
X
Xusage()
X{
X    fprintf (stderr,
X	"usage:  %s [-options ...]\n\n", program_name);
X    fprintf (stderr,
X	"where options include:\n");
X    fprintf (stderr,
X	"    -help                print this message\n");
X    fprintf (stderr,
X	"    -display host:dpy    X server to contact\n");
X    fprintf (stderr,
X	"    -root                use the root window\n");
X    fprintf (stderr,
X	"    -id windowid         use the window with the specified id\n");
X    fprintf (stderr,
X	"    -name windowname     use the window with the specifed name\n");
X
X    fprintf (stderr,
X	"    -frame               don't ignore window manager frames\n");
X    fprintf (stderr,
X	"    -bitmap              name of a bitmap file to use to build the icon\n");
X    fprintf (stderr,
X	"    -foreground          foreground color for bitmap icon\n");
X    fprintf (stderr,
X	"    -background          background color for bitmap icon\n");
X    fprintf (stderr,
X	"    -bordercolor         bordercolor for icon window\n");
X    fprintf (stderr,
X	"    -borderwidth         borderwidth for icon window\n");
X    fprintf (stderr,
X	"    -iconwindow          preexisting window to use as an icon\n");
X    fprintf (stderr, "\n");
X    exit (1);
X}
X
Xint done;
X
Xhandlebreak() {
X  done = 1;
X}
X
Xlong
Xparse_color_or_die(string)
X     char *string;
X{
X  Colormap	cmap;
X  XColor	xc;
X
X  cmap = DefaultColormap(dpy, screen);
X  if (!XParseColor(dpy, cmap, string, &xc))
X    {
X      fprintf(stderr, "color \"%s\" does not make sense\n", string);
X      exit(1);
X    }
X  if (!XAllocColor(dpy, cmap, &xc))
X    {
X      fprintf(stderr, "Unable to allocate color \"%s\", colormap probably full", string);
X      exit(1);
X    }
X  return xc.pixel;
X}
X
Xlong
Xparse_int_or_die(string)
X     char *string;
X{
X  long	l;
X  int	idx;
X  if (1!=sscanf(string, "%li%n", &l, &idx) || string[idx]!=0)
X    {
X      fprintf(stderr, "Unable to parse integer \"%s\"\n", string);
X      exit(1);
X    }
X  return l;
X}
X
Xmain(argc,argv)
X     int argc;
X     char **argv;
X{
X  int	i,j;
X  int	frame;
X  Window	window, iconwindow;
X  XWMHints	*backup, ours;
X  char		*bitmapname;
X  Pixmap	stipple;
X  long	foreground, background, bordercolor;
X  int	borderwidth;
X
X  INIT_NAME;
X  Setup_Display_And_Screen(&argc, argv);
X  window = Select_Window_Args(&argc, argv);
X
X  frame = 0;
X  bitmapname = NULL;
X  foreground = WhitePixel(dpy,screen);
X  background = BlackPixel(dpy,screen);
X  bordercolor = BlackPixel(dpy,screen);
X  borderwidth = 1;
X  iconwindow = None;
X  for (i=1,j=1; i<argc; i++)
X    {
X      if (0==strcmp(argv[i],"-frame")) {
X	frame = 1;
X	continue;
X      }
X      if (0==strcmp(argv[i],"-bitmap")) {
X	if (++i >= argc)
X	  usage();
X	bitmapname = argv[i];
X	continue;
X      }
X      if (0==strcmp(argv[i],"-foreground") || 0==strcmp(argv[i],"-fg")) {
X	if (++i >= argc)
X	  usage();
X	foreground = parse_color_or_die(argv[i]);
X	continue;
X      }
X      if (0==strcmp(argv[i],"-background") || 0==strcmp(argv[i],"-bg")) {
X	if (++i >= argc)
X	  usage();
X	background = parse_color_or_die(argv[i]);
X	continue;
X      }
X      if (0==strcmp(argv[i],"-bordercolor") || 0==strcmp(argv[i],"-bc")) {
X	if (++i >= argc)
X	  usage();
X	bordercolor = parse_color_or_die(argv[i]);
X	continue;
X      }
X      if (0==strcmp(argv[i],"-borderwidth") || 0==strcmp(argv[i],"-bw")) {
X	if (++i >= argc)
X	  usage();
X	borderwidth = parse_int_or_die(argv[i]);
X	continue;
X      }
X      if (0==strcmp(argv[i],"-iconwindow")) {
X	if (++i >= argc)
X	  usage();
X	iconwindow = parse_int_or_die(argv[i]);
X	continue;
X      }
X      argv[j++] = argv[i];
X    }
X  if (j>1)
X    usage();
X  if (bitmapname==NULL && iconwindow==None)
X    {
X      fprintf(stderr,"I can not construct an icon window without a bitmap file name\n and you have not given me an icon window of your own.\n");
X      usage();
X    }
X
X  if (!window) {
X    printf("\nxseticonwindow ==> Please select the window you would like\n");
X    printf("               ==> to set the iconwindow of by clicking the\n");
X    printf("               ==> mouse in that window.\n");
X    window = Select_Window(dpy);
X    if (window && !frame) {
X      Window root;
X      int dummyi;
X      unsigned int dummy;
X      
X      if (XGetGeometry (dpy, window, &root, &dummyi, &dummyi,
X			&dummy, &dummy, &dummy, &dummy) &&
X	  window != root)
X	window = XmuClientWindow (dpy, window);
X    }
X  }
X
X  if (iconwindow==None)
X    {
X      XGCValues xgcv;
X      GC	gc;
X      Pixmap	pmap;
X      unsigned int	width,height;
X      int	xhot,yhot;
X      int	rval;
X
X      rval = XReadBitmapFile(dpy, DefaultRootWindow(dpy), bitmapname,
X			     &width, &height, &stipple, &xhot, &yhot);
X      switch (rval)
X	{
X	case BitmapOpenFailed:
X	  fprintf(stderr,"Unable to open bitmap file %s (%s)\n", bitmapname,
X		  sys_errlist[errno]);
X	  exit(1); break;
X	case BitmapFileInvalid:
X	  fprintf(stderr,"Bitmap file %s has bogus format\n", bitmapname);
X	  exit(1); break;
X	case BitmapNoMemory:
X	  fprintf(stderr,"Bitmap file %s ran out of memory\n", bitmapname);
X	  exit(1); break;
X	case BitmapSuccess:
X	  break;
X	default:
X	  fprintf(stderr,"XReadBitmapFile returned strange code %d\n",rval);
X	  break;
X	}
X      iconwindow = XCreateSimpleWindow
X	(dpy, DefaultRootWindow(dpy), 0, 0, width, height, borderwidth,
X	 bordercolor, background);
X
X      xgcv.stipple = stipple;
X      xgcv.foreground = foreground;
X      xgcv.background = background;
X      xgcv.fill_style = FillOpaqueStippled;
X      gc = XCreateGC(dpy, iconwindow,
X		     GCStipple|GCForeground|GCBackground|GCFillStyle,
X		     &xgcv);
X      pmap = XCreatePixmap(dpy, iconwindow, width, height,
X			   DefaultDepth(dpy,screen));
X      XFillRectangle(dpy, pmap, gc, 0, 0, width, height);
X      XSetWindowBackgroundPixmap(dpy, iconwindow, pmap);
X      XFreePixmap(dpy, stipple);
X    }
X  XWithdrawWindow(dpy, window, screen);
X  backup = XGetWMHints(dpy,window);
X  if (backup==NULL)
X    {
X      fprintf(stderr, "Error getting window hints from window 0x%x\n",window);
X      exit(1);
X    }
X  bcopy(backup, &ours, sizeof(ours));
X  ours.flags |= IconWindowHint;
X  ours.flags &= ~(long)IconPixmapHint;
X  ours.icon_window = iconwindow;
X  XSetWMHints(dpy, window, &ours);
X  XMapWindow(dpy, window);
X  XSelectInput(dpy, window, StructureNotifyMask);
X
X  signal(SIGHUP,handlebreak);
X  signal(SIGINT,handlebreak);
X  signal(SIGQUIT,handlebreak);
X  signal(SIGTERM,handlebreak);
X
X  done = 0;
X  while (!done)
X    {
X      static XEvent	xev;
X      XNextEvent(dpy,&xev);
X      if (xev.type==DestroyNotify)
X	exit(0);
X    }
X  XWithdrawWindow(dpy, window, screen);
X  XSetWMHints(dpy, window, backup);
X  XMapWindow(dpy, window);
X  XFlush(dpy);
X  sleep (3);
X  /* I don't know why I need this other pair, but TWM freaks and unmanages
X     the window if I don't */
X  XWithdrawWindow(dpy, window, screen);
X  XMapWindow(dpy, window);
X
X  XCloseDisplay(dpy);
X}
SHAR_EOF
$TOUCH -am 0825174090 xseticonwindow.c &&
chmod 0644 xseticonwindow.c ||
echo "restore of xseticonwindow.c failed"
set `wc -c xseticonwindow.c`;Wc_c=$1
if test "$Wc_c" != "8078"; then
	echo original size 8078, current size $Wc_c
fi
exit 0
--
/--------------------
"a window is a terrible thing to paste" -me
( My name's not really Gilligan, It's Robert Forsman, without an `e' )
--------------------/

dan
----------------------------------------------------
O'Reilly && Associates   argv@sun.com / argv@ora.com
Opinions expressed reflect those of the author only.