[comp.windows.x] Tom's posting of mytitle.c

jkh@pcsbst.UUCP (jkh) (04/02/89)

...
..
    if (i == len)
	printf("\033]2;%s: ~%s\007", host,&wd[i]);
    else
	printf("\033]2;%s: %s\007", host,wd);
...

Oh urg! This seems to be going about it the wrong way, if you're going
to write a program to do this.. Also, you're probably a lot better off
just writing aliases to echo the appropriate escape sequences than you
are hacking up a program and having to suffer the startup time.
I believe that several people have already posted examples of this..
However, if you MUST have an exec for some reason or another,
I would suggest something like:

----

#ifndef lint
static char *rcsid_setname_c = "$Header: /usr/NSA/projects/X11.3/secret/xxxxxx/<deleted>/<encoded>/<deleted>/setname.c,v 1.0 89/04/2 14:39:57:11 #6 Exp $";
#endif  lint

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

/*
 * setname.c
 *
 * Version: 1.0.
 * Revision level: 0.
 * Security classification: Low.
 * Funded-By: NSA Contract #100243SSNA-06
 * Project-Number: 30023-10A4
 * Programmer: #6
 * Inspected-By: #32
 */

main(argc, argv)
int argc;
char *argv[];
{
	Display *dpy;
	Window victim;
	char *id;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <new-title>\n", argv[0]);
		exit(1);
	}
	dpy = XOpenDisplay(0);
	if (!dpy) {
		fprintf(stderr, "%s: Can't open display.\n", argv[0]);
		exit(2);
	}
	if (!(id = getenv("WINDOWID"))) {
		fprintf(stderr, "%s: Can't get WINDOWID from environment.\n",
		  argv[0]);
		exit(3);
	}
	victim = atol(id);
	if (victim) {
		XStoreName(dpy, victim, argv[1]);
		XSync(dpy, 0);
	}
	else
		fprintf(stderr, "%s: Bad window ID '%s'.\n", argv[0], id);
}

Of course, you could get fancier and accumulate multiple arguments, if
specified (instead of having to surround a title containing spaces
with quotes), or add a -i flag to do a XSetIconName() rather than
a XStoreName() (allowing one to name the icon). These are left as an
exercise to the bored reader with nothing better to do.

Actually, it just occurred to me that such a program does have
a use, though in a much less verbose form (do all the checks done above,
but just exit if you find an error, don't print anything). I.E:

#include <X11/Xlib.h>

main(argc, argv)
int argc;
char *argv[];
{
	Display *dpy;
	Window victim;
	char *id;

	if (argc == 2 && (dpy = XOpenDisplay(0)) && (id = getenv("WINDOWID"))
	  && (victim = atol(id))) {
		XStoreName(dpy, victim, argv[1]);
		XSync(dpy, 0);
	}
}

You could alias various commands like "cd", "pushd", "popd" and whatever
to print the CWD by invoking this program, but not suffer from extraneous
garbage being printed when you log in via an ordinary ascii terminal
(do people still use those?) or use a shell under EMACS.

					Jordan


P.S. Just tested the above. A *lot* faster than sending esc's and a whole
lot less obnoxious in terms of potential side-effects.-- 
--------
				Jordan Hubbard
				PCS Computer Systeme GmbH
				West Germany
	UUCP:			{uunet,decwrl}!pyramid!pcsbst!jkh
	ARPA:			jkh@violet.berkeley.edu

	"I'd like a burrito please."
	"Was?"
	"Uh. Ich moechte ein Mexicanische 'Burrito', bitte."
	"Hahahahahahaha.. Das ist ein guter Witz. Du bist toll.."
	"Hey! It's real easy, just take some cheese, some meat and
	some beans and roll it up like this.."
	"Raus!"

news@bnr-fos.UUCP (news) (04/13/89)

I tried writing out the same binary characters (and the same ASCII ones)
from a mainframe program running via tn3270.  It didn't change the icon 
label (I'm suffering from only uwm on this machine.) Any ideas? It does
work perfectly for xterms.  
 
P.S. is tn3270 a standard tool or something we dredged up?  I have no
man page for it. Sigh.
 
utgpu!bnr-vpa!bnr-fos!hwt%bnr-public | BNR is not 	| All that evil requires
hwt@bnr (BITNET/NETNORTH) 	     | responsible for 	| is that good men do
(613) 765-2337 (Voice)		     | my opinions	| nothing.