2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2013, The MorphOS Development Team. All Rights Reserved.
7 /****************************************************************************************/
10 #include <exec/lists.h>
11 #include <exec/resident.h>
12 #include <exec/memory.h>
13 #include <exec/execbase.h>
14 #include <exec/alerts.h>
17 #include <proto/graphics.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/oop.h>
21 #include <proto/alib.h>
22 #include <devices/input.h>
23 #include <intuition/classes.h>
24 #include <intuition/pointerclass.h>
25 #include <utility/hooks.h>
26 #include <utility/utility.h>
27 #include <aros/symbolsets.h>
29 #include LC_LIBDEFS_FILE
31 #include "intuition_intern.h"
32 #include "strgadgets.h" /* To get GlobalEditFunc prototype */
33 #include "inputhandler.h"
35 #include "screennotifytask.h"
38 #include "transplayers.h"
39 #include "smallmenu.h"
43 #include <aros/debug.h>
45 #ifdef INTUITION_NOTIFY_SUPPORT
46 /* screennotify/notifyintuition init routines from notify.c */
47 struct Library
*sn_Init(struct IntuitionBase
*IntuitionBase
);
48 struct Library
*ni_Init(struct IntuitionBase
*IntuitionBase
);
51 /* There has to be a better way... */
53 AROS_UFP3(ULONG
, rootDispatcher
,
54 AROS_UFPA(Class
*, cl
, A0
),
55 AROS_UFPA(Object
*, obj
, A2
),
56 AROS_UFPA(Msg
, msg
, A1
)
59 /****************************************************************************************/
61 /* Default colors for the new screen, the same as in AmigaOS 3.1 */
63 const ULONG coltab
[] =
65 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
66 0x00000000, 0x00000000, 0x00000000, /* Black */
67 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
68 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
70 0xEEEEEEEE, 0x44444444, 0x44444444, /* Red */
71 0x55555555, 0xDDDDDDDD, 0x55555555, /* Green */
72 0x00000000, 0x44444444, 0xDDDDDDDD, /* Dark Blue */
73 0xEEEEEEEE, 0x99999999, 0x00000000, /* Yellow */
75 0xbbbbbbbb, 0x00000000, 0x00000000, /* Default colors for mouse pointer */
76 0xdddddddd, 0x00000000, 0x00000000,
77 0xeeeeeeee, 0x00000000, 0x00000000
80 static int IntuitionInit(LIBBASETYPEPTR LIBBASE
)
82 struct Library
*OOPBase
;
83 struct GfxBase
*GfxBase
;
84 struct OOP_ABDescr attrbases
[] = {
85 {IID_Hidd
, &GetPrivIBase(LIBBASE
)->HiddAttrBase
},
86 {IID_Hidd_Gfx
, &GetPrivIBase(LIBBASE
)->HiddGfxAttrBase
},
87 {IID_Hidd_Sync
, &GetPrivIBase(LIBBASE
)->HiddSyncAttrBase
},
88 {IID_Hidd_BitMap
, &GetPrivIBase(LIBBASE
)->HiddBitMapAttrBase
},
89 {IID_Hidd_PixFmt
, &GetPrivIBase(LIBBASE
)->HiddPixFmtAttrBase
},
93 DEBUG_INIT(dprintf("LIB_Init: base 0x%p\n", LIBBASE
));
94 #if defined(__AROSEXEC_SMP__)
95 GetPrivIBase(LIBBASE
)->ExecLockBase
= OpenResource("execlock.resource");
97 /* Open our dependencies */
98 if (!(GetPrivIBase(LIBBASE
)->UtilityBase
= OpenLibrary("utility.library", 0))) {
100 } else if (!(GfxBase
= GetPrivIBase(LIBBASE
)->GfxBase
= (APTR
)OpenLibrary("graphics.library", 41))) {
101 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->UtilityBase
);
103 } else if (!(GetPrivIBase(LIBBASE
)->LayersBase
= (APTR
)OpenLibrary("layers.library", 41))) {
104 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->GfxBase
);
105 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->UtilityBase
);
107 } else if (!(GetPrivIBase(LIBBASE
)->KeymapBase
= (APTR
)OpenLibrary("keymap.library", 41))) {
108 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->LayersBase
);
109 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->GfxBase
);
110 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->UtilityBase
);
112 } else if (!(OOPBase
= GetPrivIBase(LIBBASE
)->OOPBase
= (APTR
)OpenLibrary("oop.library", 41))) {
113 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->KeymapBase
);
114 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->LayersBase
);
115 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->GfxBase
);
116 CloseLibrary((APTR
)GetPrivIBase(LIBBASE
)->UtilityBase
);
120 LIBBASE
->ib_HiddBitMapBase
= OOP_GetMethodID(IID_Hidd_BitMap
, 0);
121 LIBBASE
->ib_HiddGfxBase
= OOP_GetMethodID(IID_Hidd_Gfx
, 0);
123 if (!OOP_ObtainAttrBases(attrbases
))
126 /* FIXME: This libInit is all broken if something should fail, but do we care? */
127 /* FIXME: If something fails we're screwed anyway... */
129 /* We have to open this here, but it doesn't do any allocations,
130 so it shouldn't fail...
133 /* Create semaphore and initialize it */
134 GetPrivIBase(LIBBASE
)->IBaseLock
= AllocMem (sizeof(struct SignalSemaphore
), MEMF_PUBLIC
|MEMF_CLEAR
);
136 if (!GetPrivIBase(LIBBASE
)->IBaseLock
)
139 InitSemaphore(GetPrivIBase(LIBBASE
)->IBaseLock
);
141 InitSemaphore(&GetPrivIBase(LIBBASE
)->WinDecorSem
);
142 InitSemaphore(&GetPrivIBase(LIBBASE
)->ScrDecorSem
);
143 InitSemaphore(&GetPrivIBase(LIBBASE
)->MenuDecorSem
);
145 /* Initialize global stringgadget edit hook */
146 GetPrivIBase(LIBBASE
)->DefaultEditHook
.h_Entry
= (APTR
)AROS_ASMSYMNAME(GlobalEditFunc
);
147 GetPrivIBase(LIBBASE
)->DefaultEditHook
.h_SubEntry
= NULL
;
148 GetPrivIBase(LIBBASE
)->DefaultEditHook
.h_Data
= LIBBASE
;
150 GetPrivIBase(LIBBASE
)->GlobalEditHook
= &(GetPrivIBase(LIBBASE
)->DefaultEditHook
);
152 GetPrivIBase(LIBBASE
)->DefaultPubScreen
= NULL
;
153 NEWLIST(&GetPrivIBase(LIBBASE
)->PubScreenList
);
154 InitSemaphore(&GetPrivIBase(LIBBASE
)->PubScrListLock
);
156 InitSemaphore(&GetPrivIBase(LIBBASE
)->ScreenNotificationListLock
);
157 NEWLIST(&GetPrivIBase(LIBBASE
)->ScreenNotificationList
);
159 NEWLIST(&GetPrivIBase(LIBBASE
)->Decorations
);
162 InitSemaphore(&GetPrivIBase(LIBBASE
)->GadgetLock
);
163 InitSemaphore(&GetPrivIBase(LIBBASE
)->MenuLock
);
164 InitSemaphore(&GetPrivIBase(LIBBASE
)->WindowLock
);
165 InitSemaphore(&GetPrivIBase(LIBBASE
)->IntuiActionLock
);
166 InitSemaphore(&GetPrivIBase(LIBBASE
)->InputHandlerLock
);
169 InitSemaphore(&GetPrivIBase(LIBBASE
)->DataTypesSem
);
170 GetPrivIBase(LIBBASE
)->DataTypesBase
= 0;
172 GetPrivIBase(LIBBASE
)->transphook
.h_Data
= (APTR
)GetPrivIBase(LIBBASE
);
173 GetPrivIBase(LIBBASE
)->transphook
.h_Entry
= (HOOKFUNC
)HookEntry
;
174 GetPrivIBase(LIBBASE
)->transphook
.h_SubEntry
= (HOOKFUNC
)WindowTranspFunc
;
176 GetPrivIBase(LIBBASE
)->notransphook
.h_Data
= (APTR
)GetPrivIBase(LIBBASE
);
177 GetPrivIBase(LIBBASE
)->notransphook
.h_Entry
= (HOOKFUNC
)HookEntry
;
178 GetPrivIBase(LIBBASE
)->notransphook
.h_SubEntry
= (HOOKFUNC
)WindowNoTranspFunc
;
182 memset(GetPrivIBase(LIBBASE
)->Pad
, 0xee, sizeof(GetPrivIBase(LIBBASE
)->Pad
));
183 GetPrivIBase(LIBBASE
)->SystemRequestTitle
= "System Request";
184 GetPrivIBase(LIBBASE
)->WorkbenchTitle
= "Ambient Screen";
187 * Setup the default pens to the default
188 * colors so that screens have proper color
189 * even before IPrefs is loaded.
195 p
= GetPrivIBase(LIBBASE
)->Colors
;
197 for (i
= 0; i
< COLORTABLEENTRIES
; i
++)
199 p
[i
].red
= coltab
[i
*3];
200 p
[i
].green
= coltab
[i
*3+1];
201 p
[i
].blue
= coltab
[i
*3+2];
204 LIBBASE
->PointerAlpha
= 0x9F9F;
207 GetPrivIBase(LIBBASE
)->mosmenuclass
= InitMuiMenuClass(LIBBASE
);
210 DEBUG_INIT(dprintf("LIB_Init: create menu handler task\n"));
211 /* FIXME: no cleanup routines for MenuHandler task */
212 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE
)))
215 /* FIXME: no cleanup routines for ScreennotifyHandler task */
216 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE
)))
220 DEBUG_INIT(dprintf("LIB_Init: load default preferences\n"));
221 LoadDefaultPreferences(GetPubIBase(LIBBASE
));
223 GetPrivIBase(LIBBASE
)->IPrefsLoaded
= FALSE
;
227 if (!GetPrivIBase(LIBBASE
)->SmallMenuPool
)
229 if (!(GetPrivIBase(LIBBASE
)->SmallMenuPool
= CreatePool(MEMF_SEM_PROTECTED
,(sizeof (struct SmallMenuEntry
))*20,(sizeof (struct SmallMenuEntry
))*20))) return NULL
;
233 if (!(GetPrivIBase(LIBBASE
)->IDCMPPool
= CreatePool(MEMF_SEM_PROTECTED
,(sizeof (struct IntIntuiMessage
)) * 100,sizeof (struct IntIntuiMessage
)))) return FALSE
;
236 strcpy(GetPrivIBase(LIBBASE
)->IControlExtensions
.ice_ClockFormat
,"%X");
239 GetPrivIBase(LIBBASE
)->FrameSize
= FRAMESIZE_THIN
;
244 for(i
= 0; i
< RESOURCELIST_HASHSIZE
; i
++)
246 NewList((struct List
*)&GetPrivIBase(LIBBASE
)->ResourceList
[i
]);
250 GetPrivIBase(LIBBASE
)->ScrDecorClass
= FindClass(SCRDECORCLASS
);
251 GetPrivIBase(LIBBASE
)->ScrDecorTags
= NULL
;
252 GetPrivIBase(LIBBASE
)->MenuDecorClass
= FindClass(MENUDECORCLASS
);
253 GetPrivIBase(LIBBASE
)->MenuDecorTags
= NULL
;
254 GetPrivIBase(LIBBASE
)->WinDecorClass
= FindClass(WINDECORCLASS
);
255 GetPrivIBase(LIBBASE
)->WinDecorTags
= NULL
;
256 LIBBASE
->ViewLord_ok
= FALSE
;
258 DEBUG_INIT(dprintf("LIB_Init: Setting up pointers...\n"));
260 GetPrivIBase(LIBBASE
)->DefaultPointer
= MakePointerFromPrefs
262 GetPubIBase(LIBBASE
), &GetPrivIBase(LIBBASE
)->ActivePreferences
264 GetPrivIBase(LIBBASE
)->BusyPointer
= MakePointerFromPrefs
266 GetPubIBase(LIBBASE
), &GetPrivIBase(LIBBASE
)->ActivePreferences
271 !GetPrivIBase(LIBBASE
)->DefaultPointer
272 || !GetPrivIBase(LIBBASE
)->BusyPointer
278 NEWLIST(&GetPrivIBase(LIBBASE
)->MonitorList
);
279 InitSemaphore(&GetPrivIBase(LIBBASE
)->MonitorListSem
);
280 SetDisplayDriverCallback(DisplayDriverNotify
, LIBBASE
);
282 /* Install reset handler to display manual shutdown screen */
283 GetPrivIBase(LIBBASE
)->ShutdownHandler
.is_Node
.ln_Name
=
284 LIBBASE
->Base
.LibNode
.lib_Node
.ln_Name
;
285 GetPrivIBase(LIBBASE
)->ShutdownHandler
.is_Node
.ln_Pri
= -96;
286 GetPrivIBase(LIBBASE
)->ShutdownHandler
.is_Code
=
287 (VOID_FUNC
)ShutdownScreenHandler
;
288 GetPrivIBase(LIBBASE
)->ShutdownHandler
.is_Data
=
289 &GetPrivIBase(LIBBASE
)->ShutdownHandler
;
290 AddResetCallback(&GetPrivIBase(LIBBASE
)->ShutdownHandler
);
292 DEBUG_INIT(dprintf("LIB_Init: done\n"));
297 static int InitRootClass(LIBBASETYPEPTR LIBBASE
)
299 InitSemaphore(&GetPrivIBase(LIBBASE
)->ClassListLock
);
300 NEWLIST(&GetPrivIBase(LIBBASE
)->ClassList
);
302 /* Setup root class */
304 GetPrivIBase(LIBBASE
)->RootClass
.cl_Dispatcher
.h_Entry
= (APTR
)AROS_ASMSYMNAME(rootDispatcher
);
305 GetPrivIBase(LIBBASE
)->RootClass
.cl_ID
= (ClassID
)ROOTCLASS
;
306 GetPrivIBase(LIBBASE
)->RootClass
.cl_UserData
= (IPTR
)LIBBASE
;
307 DEBUG_INIT(dprintf("LIB_Init: create rootclass\n"));
308 AddClass(&(GetPrivIBase(LIBBASE
)->RootClass
));
313 /****************************************************************************************/
315 static int IntuitionOpen(LIBBASETYPEPTR LIBBASE
)
317 struct GfxBase
*GfxBase
= GetPrivIBase(LIBBASE
)->GfxBase
;
318 DEBUG_OPEN(dprintf("LIB_Open: base 0x%lx\n", LIBBASE
));
320 /* Open the input device */
322 if (!GetPrivIBase(LIBBASE
)->InputMP
)
324 if (!(GetPrivIBase(LIBBASE
)->InputMP
= CreateMsgPort()))
326 DEBUG_OPEN(dprintf("LIB_Open: can't create port\n"));
331 if (!GetPrivIBase(LIBBASE
)->InputIO
)
333 if (!(GetPrivIBase(LIBBASE
)->InputIO
= (struct IOStdReq
*)
334 CreateIORequest(GetPrivIBase(LIBBASE
)->InputMP
, sizeof (struct IOStdReq
))) )
336 DEBUG_OPEN(dprintf("LIB_Open: can't create iorequest\n"));
341 if (!GetPrivIBase(LIBBASE
)->InputDeviceOpen
)
343 if (!OpenDevice("input.device", -1, (struct IORequest
*)GetPrivIBase(LIBBASE
)->InputIO
, 0))
345 GetPrivIBase(LIBBASE
)->InputDeviceOpen
= TRUE
;
346 GetPrivIBase(LIBBASE
)->InputBase
= (struct Library
*)GetPrivIBase(LIBBASE
)->InputIO
->io_Device
;
350 DEBUG_OPEN(dprintf("LIB_Open: can't open input.device\n"));
355 if (!GetPrivIBase(LIBBASE
)->InputHandler
)
357 D(bug("Initializing inputhandler\n"));
358 if ( !(GetPrivIBase(LIBBASE
)->InputHandler
= InitIIH(GetPubIBase(LIBBASE
))) )
360 DEBUG_OPEN(dprintf("LIB_Open: can't init input handler\n"));
364 D(bug("Adding inputhandler\n"));
365 GetPrivIBase(LIBBASE
)->InputIO
->io_Data
= (APTR
)GetPrivIBase(LIBBASE
)->InputHandler
;
366 GetPrivIBase(LIBBASE
)->InputIO
->io_Command
= IND_ADDHANDLER
;
368 D(bug("Calling DoIO()\n"));
369 DoIO((struct IORequest
*)GetPrivIBase(LIBBASE
)->InputIO
);
370 D(bug("DoIO() called\n"));
373 if (!LIBBASE
->ViewLord_ok
)
376 struct ViewExtra
*ve
;
378 if (!(ve
= GfxNew(VIEW_EXTRA_TYPE
)))
380 GetPrivIBase(LIBBASE
)->GfxBase
= NULL
;
381 DEBUG_OPEN(dprintf("LIB_Open: can't create view extra\n"));
385 D(bug("[intuition] Calling InitView()\n"));
386 InitView(&LIBBASE
->Base
.ViewLord
);
387 InitSemaphore(&LIBBASE
->ViewLordLock
);
389 GfxAssociate(&LIBBASE
->Base
.ViewLord
, ve
);
391 GetPrivIBase(LIBBASE
)->ViewLordExtra
= ve
;
392 GetPrivIBase(LIBBASE
)->SpriteNum
= -1;
394 LIBBASE
->ViewLord_ok
= TRUE
;
397 if (!GetPrivIBase(LIBBASE
)->ScreenFont
)
398 GetPrivIBase(LIBBASE
)->ScreenFont
= GetPrivIBase(LIBBASE
)->GfxBase
->DefaultFont
;
400 #if 0 /* CHECKME: stegerg: backport, disabled */
401 if (!(GetPrivIBase(LIBBASE
)->TopazFont
))
403 struct TextAttr textattr
= {"topaz.font",8,0,FPF_ROMFONT
};
404 GetPrivIBase(LIBBASE
)->TopazFont
= OpenFont(&textattr
);
408 if (!GetPrivIBase(LIBBASE
)->TimerBase
)
410 if (!(GetPrivIBase(LIBBASE
)->TimerMP
= CreateMsgPort()))
412 DEBUG_OPEN(dprintf("LIB_Open: can't create timer port\n"));
413 return FALSE
; /* don't close anything */
416 if (!(GetPrivIBase(LIBBASE
)->TimerIO
= (struct timerequest
*)CreateIORequest(GetPrivIBase(LIBBASE
)->TimerMP
, sizeof(struct timerequest
))))
418 DEBUG_OPEN(dprintf("LIB_Open: can't create timer ioreq\n"));
419 return FALSE
; /* don't close anything */
422 if (OpenDevice(TIMERNAME
,UNIT_VBLANK
, (struct IORequest
*)GetPrivIBase(LIBBASE
)->TimerIO
,0))
424 DEBUG_OPEN(dprintf("LIB_Open: can't open timer.device\n"));
425 return FALSE
; /* don't close anything */
428 GetPrivIBase(LIBBASE
)->TimerBase
= (struct Library
*)GetPrivIBase(LIBBASE
)->TimerIO
->tr_node
.io_Device
;
430 SetPrefs(&GetPrivIBase(LIBBASE
)->DefaultPreferences
, sizeof(struct Preferences
), FALSE
);
434 if (((struct Library
*)LIBBASE
)->lib_OpenCnt
== 0)
436 //check if dos is opened!!!
437 ((struct DosLibrary
*)DOSBase
)->dl_IntuitionBase
=
438 (struct Library
*)LIBBASE
;
440 /* Install intuition's version of DisplayError() that puts up
441 a requester with Retry/Cancel options */
442 GetPrivIBase(LIBBASE
)->OldDisplayErrorFunc
=
443 SetFunction(DOSBase
, -81*LIB_VECTSIZE
,
444 AROS_SLIB_ENTRY(DisplayError
, Intuition
, 81));
448 if (((struct Library
*)LIBBASE
)->lib_OpenCnt
== 0)
450 InitSkinManager(GetPubIBase(LIBBASE
));
455 /* FIXME: no cleanup routines for MenuHandler task */
456 if (!GetPrivIBase(LIBBASE
)->MenuHandlerPort
)
458 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE
)))
462 /* FIXME: no cleanup routines for ScreennotifyHandler task */
463 if (!GetPrivIBase(LIBBASE
)->ScreenNotifyReplyPort
)
465 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE
)))
469 #ifdef INTUITION_NOTIFY_SUPPORT
470 /* Add screennotify.library base if not there yet - Piru
472 if (!GetPrivIBase(LIBBASE
)->ScreenNotifyBase
)
474 GetPrivIBase(LIBBASE
)->ScreenNotifyBase
= sn_Init(GetPubIBase(LIBBASE
));
477 # if 0 /* not finished yet - Piru */
478 /* Add notifyintuition.library base if not there yet - Piru
480 if (!GetPrivIBase(LIBBASE
)->NotifyIntuitionBase
)
482 GetPrivIBase(LIBBASE
)->NotifyIntuitionBase
= ni_Init(GetPubIBase(LIBBASE
));
490 DECLARESET(CLASSESINIT
)
491 ADD2SET(InitRootClass
, CLASSESINIT
, -20)
492 ADD2INITLIB(IntuitionInit
, 0)
493 ADD2OPENLIB(IntuitionOpen
, 0)