[comp.windows.x] Title bar flicker fix for XTerm

sinclair@cs.glasgow.ac.uk (Duncan Sinclair) (10/02/90)

Here's a small patch for xterm.

Using tcsh, I set re-set the title of xterm before each shell prompt,
so that it states my current working directory.  This ensures that my
title is up to date, no matter where I am, or what I'm doing.

But what would really bug me is that the most of the time, the
update would not be necessary, and would cause an unsightly flicker
of the title bar.

I hacked xterm where it set the title, so that it would only
set the new title if it had actually changed.

It should also work for the icon name, but I never change that,
so I don't know if it does.

There may be a more correct way of doing this, but it works for me.

Standard disclaimers apply.


           Duncan Sinclair.

----------------
To apply, cd into the xterm source directory (<mumble>/mit/clients/xterm),
and run `patch <this-file'.
You can build xterm seperate from the rest of the X source using xmkmf.

Patch begins...

*** misc.c.keep	Tue Mar 20 10:19:19 1990
--- misc.c	Mon Jul 30 11:11:07 1990
***************
*** 601,607 ****
--- 601,615 ----
  {
  	extern Widget toplevel;
  	Arg args[1];
+ /* Start changes added 30/7/90 by D. Sinclair (sinclair@cs.glasgow.ac.uk)
+ 	char *buf;
  
+ /* If the attribute isn't going to change, then don't bother... */
+ /* This stops my title bar flickering every time I hit return.  */
+ 	XtSetArg( args[0], attribute, &buf );
+ 	XtGetValues( toplevel, args, 1 );
+ 	if (strncmp((char *)value,buf,511) == 0) return;
+ /* Changes end.  */
  	XtSetArg( args[0], attribute, value );
  	XtSetValues( toplevel, args, 1 );
  }

Patch ends...

-- 
Duncan Sinclair                     |  Try one    sinclair@cs.glasgow.ac.uk
Computing Science Research Student  |  of these:  sinclair@uk.ac.glasgow.cs
University of Glasgow               |..!mcsun!ukc!uk.ac.glasgow.cs!sinclair
Quote: "It takes a smart man to know when he's stupid." -- Barney Rubble

stolcke@ICSI.Berkeley.EDU (Andreas Stolcke) (10/03/90)

In article <6459@vanuata.cs.glasgow.ac.uk>, sinclair@cs.glasgow.ac.uk (Duncan Sinclair) writes:
|> Using tcsh, I set re-set the title of xterm before each shell prompt,
|> so that it states my current working directory.  This ensures that my
|> title is up to date, no matter where I am, or what I'm doing.
|> 
|> But what would really bug me is that the most of the time, the
|> update would not be necessary, and would cause an unsightly flicker
|> of the title bar.

May I suggest a different approach to the same end.  Instead of 
having the tcsh prompt string set the title bar on every command,
alias the `cd ' command so as to set it only when actually changing the
current directory.  (This should work for any shell with something equivalent
to an aliasing mechanism).

-- 
Andreas Stolcke
International Computer Science Institute	stolcke@icsi.Berkeley.EDU
1957 Center St., Suite 600, Berkeley, CA 94704	(415) 642-4274 ext. 126

geg@beep.mlb.semi.harris.com (Greg Garland) (10/03/90)

In article <28434@pasteur.Berkeley.EDU>, stolcke@ICSI.Berkeley.EDU (Andreas Stolcke) writes:
|> In article <6459@vanuata.cs.glasgow.ac.uk>, sinclair@cs.glasgow.ac.uk (Duncan Sinclair) writes:
|> |> Using tcsh, I set re-set the title of xterm before each shell prompt,
|> May I suggest a different approach to the same end.  Instead of 
|> having the tcsh prompt string set the title bar on every command,
|> alias the `cd ' command so as to set it only when actually changing the
|> current directory.  (This should work for any shell with something equivalent
|> to an aliasing mechanism).
|> 

Better call it something besides 'cd', though, like 'xcd'.  I called it 'cd'
originally, but I noticed that when I ran sunview (to use some non-X stuff) 
the escape sequences seem to cause the SunView 'shelltool's to hang.

Greg G.

casey@gauss.llnl.gov (Casey Leedom) (10/03/90)

/ From: sinclair@cs.glasgow.ac.uk (Duncan Sinclair)
| 
| Using tcsh, I set re-set the title of xterm before each shell prompt,
| so that it states my current working directory.  This ensures that my
\ title is up to date, no matter where I am, or what I'm doing.

/ From: stolcke@ICSI.Berkeley.EDU (Andreas Stolcke)
| 
| May I suggest a different approach to the same end.  Instead of 
| having the tcsh prompt string set the title bar on every command,
| alias the `cd ' command so as to set it only when actually changing the
| current directory.  (This should work for any shell with something equivalent
\ to an aliasing mechanism).

  Which doesn't work if you have, say, a super user shell that you keep
suspended in the background for easy access to super user powers.  If you only
update the title with the current working directory when you do a ``cd'' then
a suspend of the super user shell or a foregrounding of it won't set the
prompt.

  I also used to include an update of the current working directory in my
prompt string and was annoyed by the flicker.  Nice patch if it works.  I'll
have to give it a shot.  You should submit it to the regular xbugs address for
inclusion in R5.

Casey

brossard@sasun1.epfl.ch (Alain Brossard EPFL-SIC/SII) (10/03/90)

In article <28434@pasteur.Berkeley.EDU>, stolcke@ICSI.Berkeley.EDU (Andreas Stolcke) writes:
> May I suggest a different approach to the same end.  Instead of 
> having the tcsh prompt string set the title bar on every command,
> alias the `cd ' command so as to set it only when actually changing the
> current directory.
> Andreas Stolcke

	But that doesn't work all the time, for example when I rlogin
somewhere and then come back, the title is wrong or when I do something
like | ( cd newdir ; tar xf - ) then the title is wrong at the end of
the command.  So it is better to do the change in the prompt.

-- 

Alain Brossard, Ecole Polytechnique Federale de Lausanne,
	SIC/SII, EL-Ecublens, CH-1015 Lausanne, Suisse
brossard@sasun1.epfl.ch

sinclair@cs.glasgow.ac.uk (Duncan Sinclair) (10/03/90)

stolcke@ICSI.Berkeley.EDU (Andreas Stolcke) writes:

>In article <6459@vanuata.cs.glasgow.ac.uk>, sinclair@cs.glasgow.ac.uk (Duncan Sinclair) writes:
>|> Using tcsh, I set re-set the title of xterm before each shell prompt,
>|> so that it states my current working directory.  This ensures that my
>|> title is up to date, no matter where I am, or what I'm doing.

>May I suggest a different approach to the same end.  Instead of 
>having the tcsh prompt string set the title bar on every command,
>alias the `cd ' command so as to set it only when actually changing the
>current directory.  (This should work for any shell with something equivalent
>to an aliasing mechanism).

Show me a way to make it work in this scenario:

Say I have two suns called `midway' and `vanuata'.

I am running an xterm on midway, and so have, say, the title bar:
"midway:/usr/X11/src/local/tvtwm"

In /usr/hosts there are links from midway & vanuata to /usr/ucb/rsh.
This allows me to type `vanuata' to rlogin onto it.

Once I reach vanuata, the title bar becomes:
"vanuata:/users/grad/sinclair"

I run a few commands, then logoff, returning to midway.

In my system I now have the correct title bar, in other systems I don't.

I did use the alias method before, but I'm too much of a perfectionist,
and I just wasn't happy with it.

I could create my own equivalent `/usr/hosts', with a ton of shell
scripts so that the title would be reset automatically, but that would
be too much hassle for such a little thing.

Instead I use tcsh's "precmd" alias, and put a small hack into xterm
which can be useful either way.


            Duncan S.


-- 
Duncan Sinclair                     |  Try one    sinclair@cs.glasgow.ac.uk
Computing Science Research Student  |  of these:  sinclair@uk.ac.glasgow.cs
University of Glasgow               |..!mcsun!ukc!uk.ac.glasgow.cs!sinclair
Quote: "It takes a smart man to know when he's stupid." -- Barney Rubble

moss@brl.mil (Gary S. Moss (VLD/VMB) <moss>) (10/03/90)

In article <1990Oct3.011511.2263@mlb.semi.harris.com>, geg@beep.mlb.semi.harris.com (Greg Garland) writes:
|> Better call it something besides 'cd', though, like 'xcd'.  I called it 'cd'
|> originally, but I noticed that when I ran sunview (to use some non-X stuff) 
|> the escape sequences seem to cause the SunView 'shelltool's to hang.
Well, I have an answer for this one if you use a modern Bourne shell (one with
shell functions):

# Define functions for labeling window title and icon, where available.
case "$TERM" in
xterm)	case "$BANNER" in
	console) # BANNER=console xterm -T console -C -ls	
		title_bar() { echo "\033]0;console:$TCWD\007\c"; }
		icon_name() { echo "\033]1;console\007\c"; }
		PS1="console$ ";;
	*)		# X window
		title_bar() { echo "\033]0;$HOST:$TCWD\007\c"; }
		icon_name() { echo "\033]1;$HOST\007\c"; };;
	esac;;
sun*)	case "BANNER" in
	console) # BANNER=console cmdtool -C
		title_bar() { echo "\033]lconsole:$TCWD\033\\\\\c"; }
		icon_name() { echo "\033]Lconsole\033\\\\\c"; }
		PS1="console$ ";;
	*)		#Suntools window
		title_bar() { echo "\033]l$HOST:$TCWD\033\\\\\c"; }
		icon_name() { echo "\033]L$HOST\033\\\\\c"; };;
	esac;;
iris*)	case "`tty`" in
	/dev/console)	#Iris console window
		title_bar() { echo -n "\033P1.yconsole:$TCWD\033\\"; }
		PS1="console$ ";;
	*)		#Iris window
		title_bar() { echo -n "\033P1.y$HOST:$TCWD\033\\"; };;
	esac;;
tty5620*)	# 5620 myx software
	title_bar() { myxban -l "$HOST:$TCWD"; myxban -r "$SHELL"; };;
tty630*)	# 630 layers software
	title_bar() { echo '\033[?'`expr "$PS1" : '.*'`";2v$PS1\c"; };;
*)		# other terminals
	title_bar() { PS1="$HOST:$TCWD$ "; };;
esac

cd()	{
	PREVDIR="$CWD"	# used by backd()
	case $# in
	0)	builtin cd;;
	*)	builtin cd "$1";;
	esac
	CWD=`pwd`
	case $CWD in
	$HOME*)	TCWD=`echo $CWD | sed -e "s!^$HOME!~!" `;;
	*)	TCWD=$CWD;;
	esac
	title_bar
	icon_name
	}

kaul@icarus.eng.ohio-state.edu (Rich Kaul) (10/03/90)

In article <6459@vanuata.cs.glasgow.ac.uk> sinclair@cs.glasgow.ac.uk (Duncan Sinclair) writes:
   Here's a small patch for xterm.

   Using tcsh, I set re-set the title of xterm before each shell prompt,
   so that it states my current working directory.  This ensures that my
   title is up to date, no matter where I am, or what I'm doing.

This may be a nit, but what is wrong with cwdcmd in tcsh?  It does
what you want with a minimum of fuss and without messing with the
xterm source.  When I ran tcsh I used the following for my xterms and
never got that annoying flicker.  (Note that the ^[ are real escapes,
and the ^G and ^A are real control characters.)

#
# Prompting information for tcsh.
#
if ($?DISPLAY) then             # X Windows Prompt
        alias cwdcmd 'echo -n "^[]0;"{$HOST}":$cwd^G"'
        echo -n "^[]0;"{$HOST}":$cwd^G"
        set prompt="%h> "
# Suntools Prompting
else if ($?WINDOW_PARENT || ($TERM == "sun" && `tty` != "/dev/console")) then
        alias cwdcmd 'echo -n "^[]l"{$HOST}": $cwd^[\^A"'
        echo -n ^[\]l"$HOST": $cwd^[\\
        set prompt="%h> "
else                            # Everything else
        set prompt={$HOST}":%~> "
endif
-- 
Rich Kaul                         | It wouldn't be research if we
kaul@icarus.eng.ohio-state.edu    | knew what we were doing.

stolcke@ICSI.Berkeley.EDU (Andreas Stolcke) (10/04/90)

In article <1990Oct3.011511.2263@mlb.semi.harris.com>, geg@beep.mlb.semi.harris.com (Greg Garland) writes:
|> Better call it something besides 'cd', though, like 'xcd'.  I called it 'cd'
|> originally, but I noticed that when I ran sunview (to use some non-X stuff) 
|> the escape sequences seem to cause the SunView 'shelltool's to hang.
 

The alias command can easily be made conditional on the terminal type,
e.g.

	if ($term == xterm) alias cd ....

A suntool window has $term == sun, so it won't be affected.

-- 
Andreas Stolcke
International Computer Science Institute	stolcke@icsi.Berkeley.EDU
1957 Center St., Suite 600, Berkeley, CA 94704	(415) 642-4274 ext. 126

me@dude.pcs.com (Michael Elbel) (10/04/90)

geg@beep.mlb.semi.harris.com (Greg Garland) writes:

> Better call it something besides 'cd', though, like 'xcd'.  I called it 'cd'
> originally, but I noticed that when I ran sunview (to use some non-X stuff) 
> the escape sequences seem to cause the SunView 'shelltool's to hang.

No need to do that, just make the aliasing conditional. Here's what I have
in my .bashrc.

	if [ "(" "$TERM" = "xterm" ")" -o "(" "$TERM" = "xterm+" ")" ] ; then
  		set_headline() {	
    		case "$PWD" in
      		${HOME}*) echo -n "\033]0;`expr $PWD : $HOME'\(.*\)'`\007" ;;
      		*) echo -n "\033]0;${PWD}\007" ;;
    		esac
  		}

  		cd()	{ builtin cd $*; set_headline; }
  		pushd()	{ builtin pushd $*; set_headline; }
  		popd()	{ builtin popd $*; set_headline; }
		pwd() { builtin pwd ; set_headline ; }

		set_headline
	fi

Michael
--
Michael Elbel 		|  Wollen haetten wir schon moegen
 me@dude.PCS.COM 	|  aber duerfen haben wir uns nicht getraut.
			|  - Karl Valentin

smarks@eng.sun.COM (Stuart Marks, There go I but for the grace of Root) (10/05/90)

In reference to some comments about shell aliases to change the title
string, soleil!mlb.semi.harris.com!beep!geg@rutgers.edu (Greg Garland) wrote:

| Better call it something besides 'cd', though, like 'xcd'.  I called it 'cd'
| originally, but I noticed that when I ran sunview (to use some non-X stuff) 
| the escape sequences seem to cause the SunView 'shelltool's to hang.

This occurs because xterm and shelltool use different escape sequences to
set the title string.  Xterm uses

	^[]2;yourtexthere^G

whereas SunView shelltool uses

	^[]lyourtexthere^[\

By coincidence, X11R3 and earlier versions of xterm would accept a string
similar to SunView's.  You could set an xterm with the same sequence,
except that the string would be terminated by ESC instead of ESC-backslash.
So, if you programmed your shell to emit

	^[]lyourtexthere^[

to set the title string for xterm, and then moved over a SunView shelltool,
the shelltool would "hang" building up the title string.  It would stay
"hung" until it got ESC-backslash.

This happened to me once.  The resulting title string was quite amusing
once I got the shelltool out of that mode.  Now my shells base their
title-setting sequences on the terminal type.

s'marks

Stuart W. Marks			ARPA: smarks@eng.sun.com
Windows & Graphics Software	UUCP: sun!smarks
Sun Microsystems, Inc.

earle@POSEUR.JPL.NASA.GOV (Greg Earle - Sun JPL on-site Software Support) (10/05/90)

>>> Using tcsh, I set re-set the title of xterm before each shell prompt,
>>
>>May I suggest a different approach to the same end.  Instead of 
>>having the tcsh prompt string set the title bar on every command,
>>alias the `cd ' command so as to set it only when actually changing the
>>current directory.
>
>Better call it something besides 'cd', though, like 'xcd'.

Naaaahhhh ... you guys are all wet.  Use tcsh's `cwdcmd' alias:

if ($?HOSTTYPE) then
# set tcsh prompt & other stuff
    if ($?WINDOWID) then
	set prompt="`hostname`:"$shelldepth":%h % "
	set WM_NAME=`xprop -id $WINDOWID WM_CLASS | sed 's/^.*"\(.*\)",.*/\1/g'`
	alias cwdcmd 'echo -n "^[]2;"{$WM_NAME}":$cwd^G"'
# make sure accidental ^D doesn't kill my console xterm!
	xprop -id $WINDOWID WM_COMMAND | egrep '"-C' > /dev/null
	if ($status == 0) then
	    set ignoreeof
	    set watch=(1 any any)
	endif
    else
# put the current directory in prompt if not running in X11 or OpenWindows
	set prompt="`hostname`:"$shelldepth":%h [%/] % "
    endif
...
else
# set csh prompt & other stuff
...
endif

--
	- Greg Earle			| "This is Kraft.  It uses a blue box.
	  Sun Los Angeles		|  This is Stouffer's.  It uses red.
	  JPL on-site Software Support	|  The choice is yours."
	  earle@poseur.JPL.NASA.GOV	| Pretty damn convincing argument, eh?

zjmw36@gpss36.trc.amoco.com (Joe M. Wade) (10/08/90)

In article <28459@pasteur.Berkeley.EDU>, stolcke@ICSI.Berkeley.EDU
(Andreas Stolcke) writes:
|> In article <1990Oct3.011511.2263@mlb.semi.harris.com>,
geg@beep.mlb.semi.harris.com (Greg Garland) writes:
|> |> Better call it something besides 'cd', though, like 'xcd'.  I
called it 'cd'
|> |> originally, but I noticed that when I ran sunview (to use some
non-X stuff) 
|> |> the escape sequences seem to cause the SunView 'shelltool's to hang.
|>  
|> 
|> The alias command can easily be made conditional on the terminal type,
|> e.g.
|> 
|> 	if ($term == xterm) alias cd ....
|> 
|> A suntool window has $term == sun, so it won't be affected.
|> 
|> -- 
There's an easier way. I alias cd to do the directory change and call a 
shell script which performs the appropriate actions for both shelltools and
xterms based on whether the WINDOWID variable is set (there are other
things you could check). This way it works for both environments.

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
*  Joe M. Wade (jwade@trc.amoco.com)         (918) 660-4387    *
*  Amoco Research Center * 4502 E. 41st St. * Tulsa, OK  74102 *
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

klute@heike.informatik.uni-dortmund.de (Rainer Klute) (10/09/90)

In article <2127@apctrc.UUCP>, zjmw36@gpss36.trc.amoco.com (Joe M. Wade)
writes:
|> There's an easier way. I alias cd to do the directory change and call a
|> shell script which performs the appropriate actions for both shelltools
and
|> xterms based on whether the WINDOWID variable is set (there are other
|> things you could check). This way it works for both environments.

That's too slow. You should do all this stuff with shell-only constructs.
Calling shell scripts or programs wastes too much time.

--
  Dipl.-Inform. Rainer Klute      klute@irb.informatik.uni-dortmund.de
  Univ. Dortmund, IRB             klute@unido.uucp, klute@unido.bitnet
  Postfach 500500         |)|/    Tel.: +49 231 755-4663
D-4600 Dortmund 50        |\|\    Fax : +49 231 755-2386