[comp.unix.ultrix] DECterm/Xterm-window title customization

graham@fuel.dec.com (kris graham) (03/27/90)

In article <748@duteca.UUCP>, jeanpaul@duteca (J.P.M. van der Jagt) writes:
> From: jeanpaul@duteca (J.P.M. van der Jagt)
> Subject: sharing of /usr on 2100 server and client
> Date: 24 Mar 90 22:38:34 GMT
> 

> 
> How can I get the name of a DECterm-window in the header of that window like
> it used to work on a X11R3-xterm: echo -n "]0 (myownmachine)`dirs`
> 

Try the following X11 hack with the accompanying  .cshrc file.
Hope it works for you.

I have only experimented with it on a UWS 2.1 RISC System.

/* wtitle.c .....  X11 hack to customize dxterm title bar*/

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

static	Display *dpy;
static	int	screen;
static	Window  root;

#define	EOS	'\0';
#define	WORD	unsigned short
#define	BYTE	unsigned char
#define LONG	unsigned

typedef	struct {
    WORD size;
    WORD type;
    BYTE *buf;
    LONG *len;
} s_item;

static BYTE	term_name[7];
static int	tname_len;
static BYTE	proc_name[16];
static int	pname_len;
static LONG	proc_id;
static LONG	iosb[2];
static char	window_title[128];

Window	get_parent();

main(argc, argv)
int argc;
char **argv;
{

    int		dummy, res;
    Window	topwin;
    Window	cur_focus;

    proc_id = 0;			/* Ask for our info */
    proc_name[pname_len] = EOS;
    term_name[tname_len] = EOS;

    dpy = XOpenDisplay(NULL);
    if (dpy == NULL)
error_exit("Can not open display.",1);

    screen = DefaultScreen(dpy);
    root = RootWindow(dpy, screen);

    XGetInputFocus(dpy, &cur_focus, &dummy);
    if ((cur_focus == NULL) || (cur_focus == root))
	error_exit("The window must have input focus.",1);

    topwin = get_parent(get_parent(cur_focus));

    if ((topwin == root) || (topwin == NULL))
	error_exit("Window with input focus most likely not a terminal window.",1);

    if (argc > 1)
	strcpy(window_title, argv[1]);
    else
	strcpy(window_title, proc_name);

    XStoreName(dpy, topwin, &window_title[0]);

    if (argc > 2)
	XSetIconName(dpy, topwin, argv[2]);
    else
	XSetIconName(dpy, topwin, &term_name[0]);

    XCloseDisplay(dpy);

    return(1);
}


Window get_parent(win)
Window win;
{
    Window parent;
    Window *child;
    int    nchildren;
    Window root;

    if (XQueryTree (dpy, win, &root, &parent, &child, &nchildren))
	return(parent);
    else error_exit("XQueryTree failed.",1);
}

error_exit(str, code)
char	*str;
int	code;
{
    fprintf(stderr,str);
    exit(code);
}

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

# .cshrc  ... hack to customize titles in dxterm and xterm
#put your favorite aliases here.
#
#
  if ($?TERM) then
    if ($TERM == xterm) then
      stty dec pass8
      echo "initializing xterm"
      setenv HOSTNAME `hostname`
      echo -n "]0;"${HOSTNAME}"::"${cwd}""
      alias title 'echo -n "]0;"\!*"" '
      alias cd 'cd \!*; echo -n "]0;"${HOSTNAME}"::"${cwd}"" '
      alias pushd 'pushd \!*; echo -n "]0;"${HOSTNAME}"::"${cwd}"" '
      alias popd 'popd \!*; echo -n "]0;"${HOSTNAME}"::"${cwd}"" '
      alias rlogin 'echo -n "]0;"\!*"::";/usr/ucb/rlogin \!*; echo -n
"]0;"${HOSTNAME}"::"${cwd}"" '
      alias dlogin 'echo -n "]0;"\!*"::";/usr/bin/dlogin \!*; echo -n
"]0;"${HOSTNAME}"::"${cwd}"" '
    endif
    if ($TERM == 'vt200') then
      stty dec
      echo "initializing DECterm"
      setenv HOSTNAME `hostname`
      /usr/new/wtitle "${HOSTNAME}::${cwd}" "${USER}@${HOSTNAME}"
      alias title 'wtitle "${HOSTNAME}::$cwd" "${USER}@${HOSTNAME}"'
      alias cd 'cd \!*; wtitle "${HOSTNAME}::${cwd}"'
      alias pushd 'pushd \!*; wtitle "${HOSTNAME}::${cwd}"'
      alias popd 'popd \!*; wtitle "${HOSTNAME}::${cwd}"'
      alias rlogin 'wtitle \!*"::";/usr/ucb/rlogin \!*; wtitle
"${HOSTNAME}::${cwd}"'
      alias dlogin 'wtitle \!*"::";/usr/bin/dlogin \!*; wtitle
"${HOSTNAME}::${cwd}"'
      title
    endif
  endif
endif

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

Christopher Graham          
Digital Equipment Corp            
Ultrix Resource Center                                             
New York City

Internet: graham@fuel.enet.dec.com 
UUCP:     ...!decwrl!fuel.enet.dec.com!graham