🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #2093

Re: Help with some windowing code

#2093
From: owl
Date: Sun, 12 Nov 1989 19:40
127 lines
4141 bytes
In article <YZKoMW600WB5Eu5EkJ@andrew.cmu.edu>, rg20+@andrew.cmu.edu 
  (Rick Francis Golembiewski) writes:

>I was looking for code to do the following in C (Lattice)
>
>1> Get the window pointer of the selected window

struct IntuitionBase *IntuitionBase;

..
    long lock;
    struct Window *activeWindow;

    lock = LockIBase(0);

    activeWindow = IntuitionBase->ActiveWindow;
    /* Do whatever you want with activeWindow */

    UnlockIBase(lock); /* Check usage, my Amiga & RKM are 6000 miles east */
    /* Note: activeWindow is now unsafe to use ... */
    
>2> Force a refresh of the screen.

You could always open & immediately close a full screen window (preferably a
window with no borders, drag bar, title eetc). With luck, the user won't 
notice it's appearance & disappearance.

>3> How to trap keyboard input? (ie I'de like to have hot keys activate
>my program).

The following is extracted (and slightly modified) from a program that I've
written (you might want to handle the installation & cleanup differently).

To set up your input handler:

/* Some global vars:
static struct Task *me;
static struct MsgPort *inputDevPort; 
static struct IOStdReq *inputRequestBlock;
static struct Interrupt handlerStuff;
static int inputOpen;

int install_handler(void)
{
    /* Install input handler */
    me = FindTask(0);
    inputDevPort = CreatePort(0,0);
    if (inputDevPort)
    {
        if (inputRequestBlock = CreateStdIO(inputDevPort))
        {

            handlerStuff.is_Data = NULL;
            handlerStuff.is_Code = (void *)handle_input;
            handlerStuff.is_Node.ln_Pri = 51;

            if (OpenDevice("input.device", 0, inputRequestBlock, 0) == 0)
            {
                inputOpen = TRUE;
                inputRequestBlock->io_Command = IND_ADDHANDLER;
                inputRequestBlock->io_Data    = (APTR)&handlerStuff;

                DoIO(inputRequestBlock);
                return TRUE;
            }
        }
    }
    return FALSE;
}

To clean up:

void cleanup_handler(void)
{
    if (inputOpen)
    {
        inputRequestBlock->io_Command = IND_REMHANDLER;
        inputRequestBlock->io_Data    = (APTR)&handlerStuff;
        DoIO(inputRequestBlock);
        CloseDevice(inputRequestBlock);
    }
    if (inputRequestBlock) DeleteStdIO(inputRequestBlock);
    if (inputDevPort) DeletePort(inputDevPort);
}

And your input handler must be something like this:

static long __saveds __asm handle_input(register __a0 struct InputEvent *ev
, register __a1 void *dummy)
{
    struct InputEvent *ep, *laste;
    static struct InputEvent retkey;

    if (req)
        /* run down the list of events to see if they pressed the magic key */
        for (ep = ev, laste = NULL; ep != NULL; ep = ep->ie_NextEvent)
        {
	    if (ep->ie_Class == IECLASS_RAWKEY  &&
	        (ep->ie_Qualifier & AMIGALEFT) &&
		(ep->ie_Code == KEYCODE_V)) /* Checks for Left Amiga-V */
            {
	        /* Wake up your task, eg with Signal(me, somesignal) */
                /* we can handle this event so take it off the chain */
                if (laste == NULL)
                    ev = &retkey;
                else
                    laste->ie_NextEvent = &retkey;
                break;
            }
            else
                laste = ep;
        }

   /* pass on the pointer to the event */
   return (long)ev;
}


>I also had the following questions: What happens when a window is
>removed from the display list?  (ie by just reassigning the pointers).

No idea ...

>Any Help would be appriciated. 

David Gay
dg3i+@andrew.cmu.edu
Technical Details
Message-ID: <86.255d80c1@drycas.club.cc.cmu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!drycas!owl
References: <YZKoMW600WB5Eu5EkJ@andrew.cmu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!drycas!owl
From: owl@drycas.club.cc.cmu.edu
Newsgroups: comp.sys.amiga.tech
Subject: Re: Help with some windowing code
Message-ID: <86.255d80c1@drycas.club.cc.cmu.edu>
Date: 12 Nov 89 19:40:01 GMT
References: <YZKoMW600WB5Eu5EkJ@andrew.cmu.edu>
Organization: Computer Club, Carnegie-Mellon University
Lines: 127