[comp.sys.amiga] Shell 2.07 title bar hack

hobie@sq.uucp (Hobie Orris) (01/15/88)

	So, instead of whining and begging someone else to put the current 
directory in the Shell's title bar, I unshar'ed the source and did it myself.
It took me about an hour in all, but with these easy to follow instructions, 
anyone can have a whizzo title bar in about 10 minutes.  Instead of giving diffs
which I don't have the technology to do, I'll make you type it in.

	I couldn't find an elegant way for a task to find the address of the 
CLI window it's running in, so this is sort of ugly.  

	First of all, declare in globals.c (and as externs in shell.h):

		#include <intuition/intuition.h>
		
		struct Window *wb_window;
		long IntuitionBase;

	Next, in the routine init() in main.c, open the Intuition library and
and chase those windows until you find a likely one.  This checks for a window
title of "AmigaDOS" or "New CLI" and grabs a pointer to it. Like so:
#include <intuition/intution.h>
#include <functions.h>
init()
{
	ULONG wb_stuff[2];	/* little buffer to keep stuff in */

	[ the rest of init() goes here ]

	if (!(IntuitionBase = (long) OpenLibrary("intuition.library",0L))
	{
		puts("Gack! Cough! cough! Aggggh...\n") /* some error message */
		wb_window = NULL;
		return;	/* this results in no fun */
	}
	if (GetScreenData(wb_stuff, (long)sizeof(wb_stuff), 1L, 0L))
		wb_window = (struct Window *) wb_stuff[1]; /* get FirstWindow */
	while (wb_window != NULL)
	{
		if ((strncmp(wb_window->Title, "AmigaDOS",8) == 0) ||
		(strncmp(wb_winodw->Title, "New CLI",7) == 0))
			return;	/* HA! We got it */
		else
			wb_window = wb_window->NextWindow;
	}
	wb_window = NULL;	/* Can't find one, oh well, forget about it */
}
	
Now the window is firmly in our grasp.  All that remains is to change the title
bar every time current working directory changes.  Do this in the routine 
do_pwd() in file comm1.c:

do_pwd(str)
char *str;
{
	[ all of do_pwd() goes here except final return statement ]
	
	SetWindowTitles(wb_window, cwd, -1L);
	return(0);
}

Fanatical weenies may want to hunt down the proper places to close the intuition
library on abort and such, but I didn't bother.  That's all there is to it. My
fingers need never type `pwd' again, and I get to keep my austere `$' prompt.
I do have to roll my eyes upward to the title bar each time I need to see what
directory  I'm in, but what the hell; I need the exercise!


 Hobie Orris			| "I'm checking out of this bourgeois motel 
 guest of SoftQuad Inc. Toronto	| Push myself away from the dinner table and say
 utzoo!sq!hobie			| NO MORE JELLO FOR ME, MOM!"

cks@radio.toronto.edu (Chris Siebenmann) (01/18/88)

In article <1988Jan14.225923.6337@sq.uucp> hobie@sq.com (Hobie Orris) writes:
...
>	I couldn't find an elegant way for a task to find the address of the 
>CLI window it's running in, so this is sort of ugly.  

 First of all, thanks for actually finding out what to do and where;
having the current directory in the title bar is really nice. However,
there's a better way to find the address of the CON:/RAW: window the
shell is running in; documented very scantily in the AmigaDOS manuals
is the fact that if you send a DiskInfo packet to your console
handler, the id_VolumeNode field in the InfoData structure holds the
desired window address (this has also been mentioned on the net a
couple of times). So here's the needed code to do it in the proper
way.

[This goes in main.c, just before init()]

#include	<intuition/intuition.h>
#include	<libraries/dosextens.h>
#include	<libraries/dos.h>
extern struct Library	*OpenLibrary();
struct Library	*IntuitionBase;
struct Window	*wb_window;

[This goes where Hobie's code did, right at the end of init()]

   wb_window = NULL;
#if	RAW_CONSOLE
   if ((IntuitionBase = OpenLibrary("intuition.library", 0L)) != NULL) {
	BPTR			iLock;
	struct FileHandle	*conF;
	struct InfoData		*infTemp;
	extern long		dos_packet();

	iLock = (BPTR) Input();
	conF = (struct FileHandle *) BADDR(iLock);
	infTemp = (struct InfoData *) malloc(sizeof(struct InfoData));
	if (infTemp == 0)
		return;
	/*
	 * Send the packet.
	*/
	if (!dos_packet(conF->fh_Type, ACTION_DISK_INFO, 
			((ULONG) infTemp) >> 2)) {
		free((void *) infTemp);
		return;
	}
	wb_window = (struct Window *) infTemp->id_VolumeNode;
   }
#endif

 Hobie's other code stays the same, and works fine.

 People who wish to be thorough should probably check to make sure
that Input() is interactive; I didn't bother because I was feeling
lazy when I wrote the code.

-- 
	"Don't worry... Won't insult legendary underworld solidarity by
	 suggesting you surrender name without torture."
Chris Siebenmann		{allegra,mnetor,decvax,pyramid}!utgpu!radio!cks
cks@radio.toronto.edu	     or	...!utgpu!{chp!hak!ziebmef,ontmoh}!cks

drew@cgofs.dec.com (Steve Drew) (01/18/88)

 
>	I couldn't find an elegant way for a task to find the address of the 
> CLI window it's running in, so this is sort of ugly.  
 
>	Next, in the routine init() in main.c, open the Intuition library and
> and chase those windows until you find a likely one.  This checks for a window
> title of "AmigaDOS" or "New CLI" and grabs a pointer to it. Like so:

    Here's some of the code I'll include into shell 2.08m for directory
    string in title bar. Just to show how to get the window ptr of your
    current window. It does not rely on the window title bar string to
    contain AmigaDos ect..., but rather sends the ACTION_DISK_INFO to the
    console device which returns the window ptr in the Volume field.
    
 
#include <libraries/dosextens.h>
#include <libraries/dos.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <functions.h>

#define DOS_TRUE -1L

/* Set_My_TitleBar() Steve Drew, 1988.
 *
 * (Assumes intuition.library already open.)
 * In Shell we could do this at init();
 * like:
#include <intuition/intuition.h>

struct IntuitionBase *IntuitionBase;

init()
{
    IntuitionBase = (struct IntuitionBase *)
                OpenLibrary("intuition.library",0L);
    if (IntuitionBase == 0L)
        exit(20);
    :                       
    : ect....
 *
 * Find OUR window ptr via ACTION_DISK_INFO.
 *
 * For using to set current directory spec in title bar:
 * It would be best to set str to current directory
 * string from our cli structure, since that string
 * will still be allocated when our program exits.
 * Using the cwd string under shell, would be okay until
 * shell exits.
 * So at then end of do_pwd() in comm1.c change:
            movemem(cwd,ptr+1,(int)ptr[0]);
        to:
            strcpy(ptr+1,cwd);      /* make BSTR but still NULL terminated */ 
            Set_My_TitleBar(ptr+1);
*/

Set_My_TitleBar(str)
char *str;
{
    struct Process *mp;
    struct InfoData *id;
    long ret;
    char *wptr;

    id = (struct InfoData *)
        AllocMem((long)sizeof (struct InfoData), MEMF_CHIP | MEMF_CLEAR);
    if (id == 0) {
    	return(0);
    }
    mp = (struct Process *)FindTask(0L);     
    if (mp->pr_Task.tc_Node.ln_Type == NT_PROCESS && mp->pr_ConsoleTask)
	ret = dos_packet(mp->pr_ConsoleTask, ACTION_DISK_INFO, (ULONG)id>>2);

    if (ret == DOS_TRUE) {
	wptr = (char *)id->id_VolumeNode;
        if (wptr) {
            SetWindowTitles(wptr,str,-1L);
	}
    }
    FreeMem(id, (long) sizeof (struct InfoData));
}

==============================================================================
        
    	Steve Drew at	ENET:    CGFSV1::DREW
    			ARPA:    drew%cfgsv1.dec.com@decwrl.dec.com
    			USENET:  {decvax!decwrl}!cgfsv1.dec.com!drew    

FATQW@USU.BITNET (01/24/88)

Subject: Re: Shell 2.07 title bar hack
References: <924@radio.toronto.edu> <1988@Jan14.225923.6337@sq.uucp>
Organization: Absolutely None, Inc.

>there's a better way to find the address of the CON:/RAW: window the
>shell is running in; documented very scantily in the AmigaDOS manuals
>is the fact that if you send a DiskInfo packet to your console
>handler, the id_VolumeNode field in the InfoData structure holds the
>desired window address

One more time I'm saying this: THIS WON'T WORK WITH CONMAN!!!  That's why
my CD program I posted a while ago won't work with it.  It seems the designer
of Conman didn't see this one.  If this would work, then my CD program would
too, and everyone would be happy, right?

Please, could somebody tell Bill Howes about this?  Thanks.

                                       Bryan

       Bryan Ford                  ///// A computer does what \\\\\
Snail: 1790 East 1400 North       ///// you tell it to do, not \\\\\
       Logan, UT 84321        \\\XX///  what you want it to do. \\\XX///
Email: USU@FATQW.BITNET        \XXXX/ Murphy's Law Calender 1986 \XXXX/