[comp.windows.x] how can I put a digital clock in the title bar?

wws@rruxc.uucp (Still Searching) (04/25/91)

While reading the Frequently Asked Questions, I discovered the item below.
It works super-duper.  I've extended it by creating an aliased function in
ksh(ell) which puts my current directory name and the current date-time in
my title bar every time I execute "mycd."  A co-worker wrote a little shell
program that sleeps 1 and then updates the title bar so that it looks like
he has a digital clock running in the title bar.  Pretty neat.
We really do need a feature like that, but we need it in an X client instead
of an xterm.  Does anyone have a suggestion how to do this?

Thank you,
Wayne Scott

----------------------------------------------------------------------
Subject: 62)  How can I change the titlebar of my xterm window?

	The solution involves sending an escape sequence to xterm which will
cause it to update the property which the window manager relies upon for the
string which appears in the window titlebar.
	A solution is as easy as typing this in an xterm running a shell:
		echo "ESC]2;TEXT^G"
where ESC is the escape key, TEXT is the string you wish to have displayed,
and ^G is a Control-G (the BEL character).

	Here is a more complicated csh alias which changes the titlebar to
the current working directory when you change directories:
		alias newcd 'cd \!* ; echo ESC]2\;$cwd^G'

	The digit '2' in these strings indicates to xterm that it should 
change only the title of the window; to change both the title and the name 
used in the icon, use the digit '0' instead, and use '1' to change only the 
icon name.

	These sequences work for both R3 and R4 xterm windows; the R4 xterm,
however, does not accept the looser sequences which worked under R3 and
demands a semicolon, above, for example, where the R3 xterm allowed any
character.

----------------------------------------------
	wws@bcr.cc.bellcore.com
I'm just a soul whose intentions are good,
Oh Lord, please don't let me be misunderstood.

jordan@tcs.COM (Jordan Hayes) (04/27/91)

If you are using Xt, somewhere you will have made an applicationShell,
and you could add the code below to your program.  It "ticks" every
second; if you didn't like that, change the 1000 to 10000 for every
10 seconds, or 60000 for once per minute and change the sprintf()
call to use %16.16s instead ...

...

extern XtAppContext	app;

static void
_Tick(closure, id)
	XtPointer	closure;
	XtIntervalId	*id;
{
	char		*str, buf[40];
	Widget		shell;
	struct timeval	tp;
	struct timezone	tzp;

	shell = (Widget)closure;
	if (gettimeofday(&tp, &tzp) < 0)
		(void)strcpy(buf, "time = ?");
	else {
		str = ctime(&tp.tv_sec);
		(void)sprintf(buf, "%19.19s", str);
	}
	XStoreName(XtDisplay(shell), XtWindow(shell), buf);
	XtAppAddTimeOut(app, 1000, _Tick, (XtPointer)shell);
}

	...

	Widget	shell;

	shell = XtAppCreateShell(NULL, "Bart", applicationShellWidgetClass,
	    display, NULL, 0);

	XtAppAddTimeOut(app, 1000, _Tick, (XtPointer)shell);

	...

/jordan

chuck@Morgan.COM (Chuck Ocheret) (05/06/91)

-- 
+--------------------+             Chuck Ocheret             +---------------+
|chuck@fid.Morgan.COM|       Morgan Stanley & Co., Inc.      |(212) 703-4474 |
|    Duty now ...    |19th Floor, 1251 Avenue of the Americas|for the future.|
+--------------------+      New York, N.Y.  10020 USA        +---------------+

chuck@Morgan.COM (Chuck Ocheret) (05/06/91)

> If you are using Xt, somewhere you will have made an applicationShell,
> and you could add the code below to your program.  It "ticks" every
> second...
> 
> ...
> 
>	 XStoreName(XtDisplay(shell), XtWindow(shell), buf);
> ...

Also note that if you are using Xt, your shell is probably a subclass
of WMShell so you would be better off using the XtNtitle resource
instead of calling XStoreName().  XtSetValues() incurs more client CPU
overhead but keeps the shell up to date locally.  WMShell provides many
of the window manager goodies like XtN(min|max)(Width|Height),
XtN(width|height)Inc, XtNbase(Width|Height), etc....

~chuck
-- 
+--------------------+             Chuck Ocheret             +---------------+
|chuck@fid.Morgan.COM|       Morgan Stanley & Co., Inc.      |(212) 703-4474 |
|    Duty now ...    |19th Floor, 1251 Avenue of the Americas|for the future.|
+--------------------+      New York, N.Y.  10020 USA        +---------------+

jordan@tcs.COM (Jordan Hayes) (05/08/91)

Chuck Ocheret <chuck@fid.Morgan.COM> writes:

	>	 XStoreName(XtDisplay(shell), XtWindow(shell), buf);

	Also note that if you are using Xt, your shell is probably a
	subclass of WMShell so you would be better off using the
	XtNtitle resource instead of calling XStoreName().
	XtSetValues() incurs more client CPU overhead but keeps the
	shell up to date locally.

Presumably you would want to keep the client up-to-date for the purpose
of being able to read it back with a XtGetValues, but since it ticks
once per second, how long would your answer be valid?

:~>

/jordan