Screen notify: how to hook?

This forum is for general developer support questions.

Screen notify: how to hook?

Postby capehill » Mon Jan 29, 2018 8:26 pm

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...
capehill
 
Posts: 24
Joined: Sun Jun 18, 2017 2:07 pm

Re: Screen notify: how to hook?

Postby mritter0 » Tue Jan 30, 2018 1:31 am

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);
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 212
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Screen notify: how to hook?

Postby broadblues » Wed Feb 07, 2018 4:06 pm

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).
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 540
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Screen notify: how to hook?

Postby capehill » Thu Feb 08, 2018 9:54 pm

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.
capehill
 
Posts: 24
Joined: Sun Jun 18, 2017 2:07 pm

Re: Screen notify: how to hook?

Postby capehill » Thu Feb 08, 2018 9:57 pm

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
capehill
 
Posts: 24
Joined: Sun Jun 18, 2017 2:07 pm


Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 8 guests