2 Copyright 1995-2007, The AROS Development Team. All rights reserved.
6 #include <proto/exec.h>
7 #include <proto/intuition.h>
8 #include <proto/alib.h>
9 #include <proto/layers.h>
10 #include <exec/memory.h>
11 #include <exec/alerts.h>
12 #include <exec/interrupts.h>
13 #include <exec/ports.h>
14 #include <intuition/intuition.h>
15 #include <intuition/intuitionbase.h>
16 #include "intuition_intern.h"
18 #include "screennotifytask.h"
22 #include <aros/debug.h>
24 void DefaultScreennotifyHandler(struct ScreennotifyTaskParams
*taskparams
);
26 /**************************************************************************************************/
27 /******************************
28 ** CreateScreennotifyHandlerTask() **
29 ******************************/
30 struct Task
*CreateScreennotifyHandlerTask(APTR taskparams
, struct IntuitionBase
*IntuitionBase
)
35 task
= AllocMem(sizeof (struct Task
), MEMF_PUBLIC
|MEMF_CLEAR
);
38 NEWLIST(&task
->tc_MemEntry
);
39 task
->tc_Node
.ln_Type
= NT_TASK
;
40 task
->tc_Node
.ln_Name
= SCREENNOTIFYTASK_NAME
;
41 task
->tc_Node
.ln_Pri
= SCREENNOTIFYTASK_PRIORITY
;
43 stack
= AllocMem(SCREENNOTIFYTASK_STACKSIZE
, MEMF_PUBLIC
);
46 task
->tc_SPLower
=stack
;
47 task
->tc_SPUpper
=(UBYTE
*)stack
+ SCREENNOTIFYTASK_STACKSIZE
;
50 struct TagItem tags
[] =
52 {TASKTAG_ARG1
, (IPTR
)taskparams
},
56 #if AROS_STACK_GROWS_DOWNWARDS
57 task
->tc_SPReg
= (UBYTE
*)task
->tc_SPUpper
-SP_OFFSET
;
59 task
->tc_SPReg
=(UBYTE
*)task
->tc_SPLower
+SP_OFFSET
;
62 if(NewAddTask(task
, DefaultScreennotifyHandler
, NULL
, tags
) != NULL
)
64 /* Everything went OK */
69 FreeMem(stack
, SCREENNOTIFYTASK_STACKSIZE
);
71 } /* if(stack != NULL) */
72 FreeMem(task
,sizeof(struct Task
));
81 /**************************************************************************************************/
83 /***************************
84 ** DefaultScreennotifyHandler() **
85 ***************************/
86 void DefaultScreennotifyHandler(struct ScreennotifyTaskParams
*taskparams
)
88 struct IntuitionBase
*IntuitionBase
= taskparams
->intuitionBase
;
89 struct MsgPort
*port
= NULL
;
92 if ((port
= AllocMem(sizeof(struct MsgPort
), MEMF_PUBLIC
| MEMF_CLEAR
)))
94 port
->mp_Node
.ln_Type
= NT_MSGPORT
;
95 port
->mp_Flags
= PA_SIGNAL
;
96 port
->mp_SigBit
= AllocSignal(-1);
97 port
->mp_SigTask
= FindTask(0);
98 NEWLIST(&port
->mp_MsgList
);
102 } /* if ((mem = AllocMem(sizeof(struct MsgPort), MEMF_PUBLIC | MEMF_CLEAR))) */
106 taskparams
->ScreennotifyHandlerPort
= port
;
107 taskparams
->success
= TRUE
;
110 Signal(taskparams
->Caller
, SIGF_INTUITION
);
114 D(bug("DefaultScreennotifyHandler: initialization failed. waiting for parent task to kill me.\n"));
118 D(bug("DefaultScreennotifyHandler: initialization ok. Now waiting for messages from Intuition.\n"));
122 struct ScreenNotifyMessage
*msg
;
125 while((msg
= (struct ScreenNotifyMessage
*) GetMsg(port
)))
127 FreeMem((APTR
) msg
, sizeof(struct ScreenNotifyMessage
));
128 } /* while((msg = (struct ScreenNotifyMessage *)GetMsg(port))) */
133 /**************************************************************************************************/
135 /*******************************
136 ** InitDefaultScreennotifyHandler() **
137 *******************************/
138 BOOL
InitDefaultScreennotifyHandler(struct IntuitionBase
*IntuitionBase
)
140 struct ScreennotifyTaskParams params
;
144 params
.intuitionBase
= IntuitionBase
;
145 params
.Caller
= FindTask(NULL
);
146 params
.success
= FALSE
;
148 SetSignal(0, SIGF_INTUITION
);
150 if ((task
= CreateScreennotifyHandlerTask(¶ms
, IntuitionBase
)))
152 Wait(SIGF_INTUITION
);
157 GetPrivIBase(IntuitionBase
)->ScreenNotifyReplyPort
= params
.ScreennotifyHandlerPort
;
164 } /* if ((task = CreateScreennotifyHandlerTask(¶ms, IntuitionBase))) */