[comp.windows.x] how can I change the title in the title bar

mark@cda.mrs.umn.edu (Mark Van Overbeke) (01/08/91)

Windowers:

   I would like to be able to change the title in the title bar on an
xterm window under X11R4.  I haven't done much with X yet so am not very
familiar with capabilities.  I know I can set it with -title when the
xterm is created.  Is it possible to change that value later on to
something else?  If so, how do I do this?  Thanks.

Mark Van Overbeke                      Systems Software Programmer
Behmler Hall, Room 10C                 (612) 589-2211  ext. 6378          
E. 4th Street and College Ave.         BITNET:    Mark@UMNMOR.BITNET 
University of Minnesota, Morris        INTERNET:  Mark@caa.mrs.umn.edu 
Morris, MN   56267                                mark@cda.mrs.umn.edu

jc@bu-pub.bu.edu (James Cameron) (01/09/91)

{COMMENT: Posted to Net as this is a common question and is always nice
	  know. *8-) }	


Here is a C program that does it for you:



#include <stdio.h>

main(argc, argv)
int argc; char *argv[];
{
	char buff[512];

	argv++; argc--;
	buff[0] = '\0';
	while (argc--) {
		strcat( buff, *argv++ );
		strcat( buff, " " );
	}
	buff[strlen(buff)-1] = '\0';
	printf( "%c]2;%s%c", (char)27, buff, (char)7 ); fflush(stdout);
}



Now, you can have 3 things happen.  That first number in the printf
is what determines where the excape sequence is executed. (ie. mine is
a '2')

A 0 will change the title and the icon name.
A 1 will change the icon name.
A 2 will change the title.

Now, what is often done is to create an alias such that it shows the
current directory in the title only.  Here is how I did it:

if ($TERM == 'xterm') then
  alias cd 'cd \!*;~jc/`arch`/xtitle "  "$cwd"  "'
endif

This could be put into your .alias file.  

The reason I did it using the alias is that first I check to see
if first of all I am on a graphics computer.  As I work on two different
suns I have to directories with the compiled code in each.  The `arch`
is the architecture of the sun system.  I am on sun3 and sun4.  This allows
one alias for either system.  The $cwd is the current directory variable.

Enjoy!

jc

melby@daffy.yk.Fujitsu.CO.JP (John B. Melby) (01/10/91)

I found that little program very useful.  Of course, the output should be going
to stderr, not stdout.

-----
John B. Melby
Fujitsu Limited, Machida, Japan
melby@yk.fujitsu.co.jp

arends@Yosemite.metaphor.com (Dale M. Arends) (01/19/91)

In article <2996@ux.acs.umn.edu> mark@cda.mrs.umn.edu (Mark Van Overbeke) writes:
>
>Windowers:
>
>   I would like to be able to change the title in the title bar on an
>xterm window under X11R4.  I haven't done much with X yet so am not very
>familiar with capabilities.  I know I can set it with -title when the
>xterm is created.  Is it possible to change that value later on to
>something else?  If so, how do I do this?  Thanks.
>
>Mark Van Overbeke                      Systems Software Programmer
>Behmler Hall, Room 10C                 (612) 589-2211  ext. 6378          
>E. 4th Street and College Ave.         BITNET:    Mark@UMNMOR.BITNET 
>University of Minnesota, Morris        INTERNET:  Mark@caa.mrs.umn.edu 
>Morris, MN   56267                                mark@cda.mrs.umn.edu

Someone else uploaded a short C program to do this.  I achieve the same
results with a short shell command.

echo -n "^[]2;<string>^G"

where the ^[ is an ESC character and the ^G is a Control-G.  The <string>
can be whatever you want.  I use this script as part of my alias for the
shell's cd command so my window title always shows the current directory.

Also, if you use a 1 instead of a 2, the <string> will appear in the
window's entry in the IconManager.

Dale

-----------------------------------------------------------------------------
Dale M. Arends                    arends@Yosemite.Metaphor.com
Metaphor Computer Systems, Inc.   ...!{apple|decwrl}!metaphor!yosemite!arends

Any opinions expressed herein are my own and not those of my employer.  They
probably aren't interested and maybe don't agree and therefore ...