Amiga-Development

Please login or register.

Login with username, password and session length
Advanced search  

News:

Created for developers of all Amiga camps

Author Topic: IDCMP_Hook issues  (Read 2481 times)

0 Members and 1 Guest are viewing this topic.

adminZRt75

  • Administrator
  • Hero Member
  • *****
  • Posts: 590
    • View Profile
IDCMP_Hook issues
« on: December 26, 2012, 02:22:29 PM »

Started by broadblues on utilitybase

broadblues
Member

   Posted: 2006-Oct-15 23:22:03 ยท Edited by: broadblues

On 0s4 update 4 :

I am attempting to use an IDCMP hook to determine the qualifier pressed when a button is clicked on.

I've got the following hook

VARARGS68K void idcmphookfunc( struct Hook *hook, Object *window, struct IntuiMessage *msg )
{
 qualifier = msg->Qualifier;
}

struct Hook idcmphook =
{
 {0},
 (HOOKFUNC)idcmphookfunc,
 (HOOKFUNC)idcmphookfunc,
 NULL
};

added to the window with

WINDOW_IDCMPHook,&idcmphook,
WINDOW_IDCMPHookBits,IDCMP_GADGETUP,

then in the switch statement after a RA_HandleINput

i have

 printf("qualifier %d\n",qualifier);
 if(qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
 {
   Alterdate(-28,&displayed);

 }
 else
 {
   Alterdate(-7,&displayed);
 }


the printf in the above being for debug purposes.

The problem is this seem to work except that the qualifier seems to be delayed by one click.

It seems that the IDCMP_Hook is executed after the handleinput?

How do I get this in sync, so that the qualifier extracted corresponds to the gadgetup being processed?



broadblues
Member

   Posted: 2006-Oct-16 14:32:40

Well I solved it. :-)

I was thrown of the scent by a few forum posts that suggested that the IDCMPhook was executed on a different task to the programs main task.
This appears not to be the case. Checking with IExec->FindTask(0) revealed that the hook is called on the *same task* as RA_HandleInput().

But is it definetely called after the msg has been processed with RA_HandleInput(), whichmust mean it's called by RA_handleinput the next time RA_HandleInput is called.

The process for handleinput must be:

call hook on previous message
reply previous message
get next message
process message and return result or WHMI_LASTMSG if no next message.

So given that my hook is called after I get notfied of the gadgetup the hook must handle the gadget if I want to test for the qualifier.

The easiest way was to set a global flag.

eg

BOOL leftclick = FALSE;

/* Hook function is called on next invocation of RA_Handleinput ie after i got the gadgetup for my gadget */
/* so I set leftclick within Ra_Handleinput loop and test for it here */

VARARGS68K void idcmphookfunc( struct Hook *hook, Object *window, struct IntuiMessage *msg )
{
 if(msg->Class == IDCMP_GADGETUP)
 {
   if(leftclick)
   {
     if(msg->Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
     {
        Alterdate(-28,&displayed);

     }
     else
     {
        Alterdate(-7,&displayed);
     }
    }
 .....
 .....
 }
}
BOOL Handlewindow()
{
 leftclick = FALSE;

 while((result = RA_HandleInput(windowMain,&click)) != WMHI_LASTMSG)
 {
   switch(result & WMHI_CLASSMASK)
   {
    case WMHI_GADGETUP:
       switch(result & WMHI_GADGETMASK)
       {
         case GAD_PLEFT:
           leftclick = TRUE;
           break;
         .....
         othergads
         .......
       }
   }
 }
 if(leftclick)
 {
   /* Updates the window gadgets */
   /* Ra_handle input loop has now quit so hook will have been called. */
   Setdaygads();
 }
}

Hope this helps anyone else who's confused by the IDCMPHook. Ideally the documentaion could be
more specific about when this hook is called.

I wander if this varies other types of event such as IDCMP_IDCMPUPDATE etc.



Hypex
Member

   Posted: 2006-Oct-16 16:25:06

I haven't used these hooks yet, but if I do I will know a little better about them. Thanks for the detailed response when you had solved the problem. Reaction could be my next endeavour once I get a few OS4 programs working.



ssolie
OS4 Fan

   Posted: 2006-Oct-16 23:32:00

@broadblues
Check the gadgets/layout.h header file. Could have sworn a LAYOUT_InputQualifier (or similar) tag had been added just for grabbing such information without using an IDCMP hook.

Sorry, not near my SDK right now.



broadblues
Member

   Posted: 2006-Oct-16 23:50:15

@solie

If it has, it's since the update 4 SDK. At least I cant find anything the autodocs or headers.

Would be a welcome addtion.



joerg
Member

   Posted: 2006-Oct-17 03:51:18

window.class, not layout.gadget. #define WINDOW_Qualifier (WINDOW_Dummy + 53)
It's not in the autodoc, no idea if it was in the update4 SDK includes already, but it was implemented in 2003 already.



broadblues
Member

   Posted: 2006-Oct-17 11:01:40

Just looked, and it is in the update4 SDK but not in the autodoc as you say.

Wish I'd spotted that earlier, would have saved quite a bit of time.

On the flip side, I've leant a bit about IDCMP Hook subtles.

Logged