From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 23-SEP-1990 15:53:18.92
To:	MRGATE::"ARISIA::EVERHART"
CC:	
Subj:	RE: Change the title of a Decterm ICON

Received:  by crdgw1.ge.com (5.57/GE 1.73)
	 id AA29999; Sun, 23 Sep 90 15:25:02 EDT
Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Sun, 23 SEP 90 12:18:39 PDT
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA20497; Sun, 23 Sep 90 12:11:52 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 23 Sep 90 11:19:09 GMT
From: dac.mdcbbs.com!jmi@uunet.uu.net  (JM Ivler)
Organization: MDC - Douglas Aircraft, Long Beach, CA
Subject: RE: Change the title of a Decterm ICON
Message-Id: <1990Sep23.111909.1@dac.mdcbbs.com>
References: <294@aupair.cs.athabascau.ca>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <294@aupair.cs.athabascau.ca>, terryt@cs.athabascau.ca (Terry Tanski) writes:
> 
>> Has anybody written a program that will change the title and icon
>> names of the DECterm window in which they're running? A few
>> initial thoughts on the subject have convinced me that such a
>> thing should be possible, but would probably involve writing a
>> short C (or otherwise) program to access the X libraries.
> 
> I an not sure about the icon name but I use the following DCL command
> to change the title of a DECWindow/VWS window.
> 
> $ write sys$output "<ESC>]21;{title}<ESC>\"
> 
> where {title} is the title you wish to stamp on the window. Hope this
> helps.

Here is a C program to do the ICON :-)

jmi     jmi@dac.mdcbbs.com

---------------------------- C U T   H E R E --------------------------

/*
**
**  FACILITY:
**
**      wmpropsII-- set window manager properities for the window with input
**      focus. Based on a program written at Digital.
**
**  ABSTRACT:
**
**      Given two strings, changes the window name and icon name for the window
**	with input focus. [icon only version - jmi]
**
**  AUTHORS:
**
**      M. Erik Husby
**      Access Technology, Inc.
**      Two Natick Executive Park
**      Natick, MA. 01760
**      (508)655-9191
**
**      Modified by J.M. Ivler  jmi@dac.mdcbbs.com
**            Douglas Aircraft
**            (213) 497-5147
**
**
**      No Rights reserved.  This program may be freely copied and distributed.
**
**      No promise is made that it works.
**
**
**
**  CREATION DATE:     Friday 16-JUN-1989 09:03 AM
**
**  MODIFICATION HISTORY:
**
**   21-Jul-1989    jmi     icon only (to be used with the set host)
**
**--
**/

/*
**
**  INCLUDE FILES
**
**/

#include <decw$include:xlib.h>
#include <decw$include:xutil.h>
#include <decw$include:xatom.h>
#include <stdio.h>

/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**      Given a string, changes the name of the window with input focus.
**
**  FORMAL PARAMETERS:
**
**      On the command line, the first string is the window name, the second
**      is the icon name.
**
**    ***** Changed... only supports the name of the ICON *****
**
**
**  IMPLICIT INPUTS:
**
**      none
**
**  IMPLICIT OUTPUTS:
**
**      none
**
**  FUNCTION VALUE:
**
**      none
**
**  SIDE EFFECTS:
**
**      Your palms get hairy... (just kidding :-) )
**
**--
**/
main(argc, argv)
int     argc;
char    *argv[];
{
    Display *dpy;
    Window  winCurrent;
    Window  winTop;
    Window  get_parent( Display *, Window);
    int dummy;
    void TranslateEscapes( char *, char *);
    char azIcon[512];

    if ((dpy = XOpenDisplay("")) != NULL) {

        /* Find the window with input focus. */
        XGetInputFocus(dpy, &winCurrent, &dummy);
        if ( !( (winCurrent == NULL) ||
                (winCurrent == RootWindow(dpy, DefaultScreen(dpy)) ) ) ){

            /* Now find the parent of its parent which will be the window   */
            /* created by the window manager around the window's shell. */
            winTop = get_parent(dpy, get_parent(dpy, winCurrent));
            if (!( (winTop == NULL) ||
                   (winTop == RootWindow(dpy, DefaultScreen(dpy)) ) ) ) {

                /* This changes the icon name. */
                TranslateEscapes(azIcon, argv[1]);
                XChangeProperty(
                    dpy,               /* The display containing the window. */
                    winTop,            /* The window whose property to be changed. */
                    XA_WM_ICON_NAME,   /* The property to be changed. */
                    XA_STRING,         /* The type of the property. */
                    8,                 /* Property is 8bit items. */
                    PropModeReplace,   /* The type of change being done. */
                    azIcon,            /* Address of string. */
                    strlen(azIcon)    /* Length of string. */
                    );
            }
            else {
                printf("Window with input focus most likely not a terminal window\n");
            }
        }
        else {
            printf("No window with input focus!\n");
        }

        /* Close the display. */
        XCloseDisplay(dpy);
    }
    else {
        printf("Can't open display\n");
    }
}
/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**      Gets the parent window of the specified window.  Returns NULL if no
**      parent.
**
**
**  FORMAL PARAMETERS:
**
**      The window in question.
**
**  IMPLICIT INPUTS:
**
**      none
**
**  IMPLICIT OUTPUTS:
**
**      none
**
**  FUNCTION VALUE:
**
**      The parent window if one exists.
**
**  SIDE EFFECTS:
**
**      none
**
**--
**/
static Window   get_parent( Display *dpy, Window winChild)
{
    Window winParent;
    Window *winChildren;
    int nChildren;
    Window winRoot;

    XQueryTree( dpy, winChild, &winRoot, &winParent, &winChildren, &nChildren);
    return winParent;
}
/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**
**      TranslateEscapes -- copys a string translating escape sequences.
**
**  FORMAL PARAMETERS:
**
**      The source string and the destination string.
**
**  IMPLICIT INPUTS:
**
**      none
**
**  IMPLICIT OUTPUTS:
**
**      none
**
**  FUNCTION VALUE:
**
**      none
**
**  SIDE EFFECTS:
**
**      none
**
**--
**/
void TranslateEscapes(
    char *pDst,
    char *pSrc)
{

    while (*pSrc) {
        if (*pSrc == '\\') {
            pSrc++;
            if (*pSrc == 'n') {
                *pDst = '\n';
            }
            else if (*pSrc == 't') {
                *pDst = '\t';

            }
            else if (*pSrc == 't') {
                *pDst = '\t';
            }
            else if (*pSrc == 'v') {
                *pDst = '\v';
            }
            else if (*pSrc == 'b') {
                *pDst = '\b';
            }
            else if (*pSrc == 'r') {
                *pDst = '\r';
            }
            else if (*pSrc == 'f') {
                *pDst = '\f';
            }
            else if (*pSrc == '\\') {
                *pDst = '\\';
            }
            else if (*pSrc == '\'') {
                *pDst = '\'';
            }
            else if (*pSrc == '"') {
                *pDst = '\"';
            }
            else {
                *pDst = *pSrc;
            }
        }
        else {
            *pDst = *pSrc;
        }
        pDst++;
        pSrc++;
    }
    /* And finally the null byte */
    *pDst = *pSrc;
}

