Screen notify: how to hook?

This forum is for general developer support questions.
Post Reply
capehill
Posts: 24
Joined: Sun Jun 18, 2017 1:07 pm

Screen notify: how to hook?

Post 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...
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

Re: Screen notify: how to hook?

Post 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);
Workbench Explorer - A better way to browse drawers
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 594
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Screen notify: how to hook?

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

Re: Screen notify: how to hook?

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

Re: Screen notify: how to hook?

Post 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
Post Reply