Page 1 of 1

Screen notify: how to hook?

PostPosted: Mon Jan 29, 2018 8:26 pm
by capehill
I am trying to implement "before WB close" and "after WB open" notification support for SDL2. I have various success when using the message method. Depending how I configure the notification, test application gets only the "before close" event, or both during WB screen mode switch - but any further notifications are not received (imagine another WB mode switch like 32->16->32).

Therefore I am wondering how to use the hook method alternatively, but couldn't find any examples.

I suppose I will try to create a separate task for notification listener if this is a matter of not actually checking the messages. Now notification message port is checked in the common event handler which is "pumped" by the SDL application, but it's able to receive normal Intuition messages after mode switch, so I have no idea why not new screen notifications...

Re: Screen notify: how to hook?

PostPosted: Tue Jan 30, 2018 1:31 am
by mritter0
Here is what I use:

Code: Select all
struct MsgPort                  *ScrNotPort;
APTR                        ScrNot;
struct ScreenNotifyMessage         *ScrNotMsg;


         /* Set up Screen Notify system */
   if (!(ScrNotPort=(struct MsgPort *)IExec->AllocSysObject(ASOT_PORT,NULL)))
   {
      SAK_EasyRequest(Objects[OID_WINDOW],MainWindow,RequesterTitle,REQIMAGE_ERROR,0,SAK_LocaleString(MSG_COULD_NOT_CREATE_USER_PORT),SAK_LocaleString(MSG_TERMINATE));

      return(FALSE);
   }

      if (!(ScrNot=IIntuition->StartScreenNotifyTags(
         SNA_Notify,                     SNOTIFY_BEFORE_CLOSEWB|SNOTIFY_AFTER_OPENWB,
         SNA_MsgPort,                  ScrNotPort,
         SNA_Priority,                  0,
      TAG_DONE)))
      {
         SAK_EasyRequest(Objects[OID_WINDOW],MainWindow,RequesterTitle,REQIMAGE_ERROR,0,SAK_LocaleString(MSG_COULD_NOT_SET_UP_SCREEN_NOTIFY),SAK_LocaleString(MSG_TERMINATE));
         goto QuitProgram;
      }


Signals=IExec->Wait(SignalsMask | PORTMASK(ScrNotPort) | .......


      if (Signals & PORTMASK(ScrNotPort))
      {
         while((ScrNotMsg=(struct ScreenNotifyMessage *)IExec->GetMsg(ScrNotPort)))
         {
            Result=ScrNotMsg->snm_Class;
            IExec->ReplyMsg((struct Message *)ScrNotMsg);

            switch(Result)
            {
               case SNOTIFY_BEFORE_CLOSEWB:
                  if (WindowClosed || Iconified)
                     break;
// do what you need
                  break;

               case SNOTIFY_AFTER_OPENWB:
                  if (WindowClosed || Iconified)
                     break;
// do what you need
                  break;

               case SNOTIFY_BEFORE_CLOSESCREEN:
                  if (WindowClosed || Iconified)
                     break;
                  if (ScrNotMsg->snm_Object != DefaultPubScreen)
                     break;
// do what you need
                  break;
            }
         }
      }


// at quit program
   while(!IIntuition->EndScreenNotify(ScrNot))
      IDOS->Delay(5);
   if (ScrNotPort)
      IExec->FreeSysObject(ASOT_PORT,ScrNotPort);

Re: Screen notify: how to hook?

PostPosted: Wed Feb 07, 2018 4:06 pm
by broadblues
capehill wrote:I am trying to implement "before WB close" and "after WB open" notification support for SDL2. I have various success when using the message method. Depending how I configure the notification, test application gets only the "before close" event, or both during WB screen mode switch - but any further notifications are not received (imagine another WB mode switch like 32->16->32).

Therefore I am wondering how to use the hook method alternatively, but couldn't find any examples.

I suppose I will try to create a separate task for notification listener if this is a matter of not actually checking the messages. Now notification message port is checked in the common event handler which is "pumped" by the SDL application, but it's able to receive normal Intuition messages after mode switch, so I have no idea why not new screen notifications...



Have you considered doing this via the WorkbenchControl() WBCTRLA_AddSetupCleanupHook / WBCTRLA_RemSetupCleanupHook pair? This is what they are for and probably more reliable than screen notifiation. You should keep the work done in the hook to minimum, possibly just sending a message to signal to the app (the hook runs on he WB process).

Re: Screen notify: how to hook?

PostPosted: Thu Feb 08, 2018 9:54 pm
by capehill
mritter0 wrote:Here is what I use:


Hey thanks. Now that I have added a separate task I seem to be able to receive both events frequently. Sometimes events trigger multiple times, not sure why.

Re: Screen notify: how to hook?

PostPosted: Thu Feb 08, 2018 9:57 pm
by capehill
broadblues wrote:Have you considered doing this via the WorkbenchControl() WBCTRLA_AddSetupCleanupHook / WBCTRLA_RemSetupCleanupHook pair? This is what they are for and probably more reliable than screen notifiation. You should keep the work done in the hook to minimum, possibly just sending a message to signal to the app (the hook runs on he WB process).


I didn't know about such a function earlier, will study it soon. Thanks.

Still I wonder, should there be some example in the SDK regarding Intuition's screen notify hook if it's meant for public consumption?

EDIT: code is here, by the way. It's not yet functional though: https://github.com/AmigaPorts/sdl2-amig ... nification