wip prep commit in lieu of gfx subsystem update changes.
[AROS.git] / rom / intuition / intuition_init.c
blobd9ece952d46cd25c545db967134318503d6057a3
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2013, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 /****************************************************************************************/
9 #include <string.h>
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>
15 #include <hidd/gfx.h>
16 #include <oop/oop.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"
34 #include "menutask.h"
35 #include "screennotifytask.h"
37 #ifdef SKINS
38 #include "transplayers.h"
39 #include "smallmenu.h"
40 #endif
42 #define DEBUG 0
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);
49 #endif
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},
90 {NULL , NULL }
93 DEBUG_INIT(dprintf("LIB_Init: base 0x%p\n", LIBBASE));
95 /* Open our dependencies */
96 if (!(GetPrivIBase(LIBBASE)->UtilityBase = OpenLibrary("utility.library", 0))) {
97 return FALSE;
98 } else if (!(GfxBase = GetPrivIBase(LIBBASE)->GfxBase = (APTR)OpenLibrary("graphics.library", 41))) {
99 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
100 return FALSE;
101 } else if (!(GetPrivIBase(LIBBASE)->LayersBase = (APTR)OpenLibrary("layers.library", 41))) {
102 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
103 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
104 return FALSE;
105 } else if (!(GetPrivIBase(LIBBASE)->KeymapBase = (APTR)OpenLibrary("keymap.library", 41))) {
106 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->LayersBase);
107 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
108 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
109 return FALSE;
110 } else if (!(OOPBase = GetPrivIBase(LIBBASE)->OOPBase = (APTR)OpenLibrary("oop.library", 41))) {
111 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->KeymapBase);
112 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->LayersBase);
113 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
114 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
115 return FALSE;
118 LIBBASE->ib_HiddBitMapBase = OOP_GetMethodID(IID_Hidd_BitMap, 0);
119 LIBBASE->ib_HiddGfxBase = OOP_GetMethodID(IID_Hidd_Gfx, 0);
121 if (!OOP_ObtainAttrBases(attrbases))
122 return FALSE;
124 /* FIXME: This libInit is all broken if something should fail, but do we care? */
125 /* FIXME: If something fails we're screwed anyway... */
127 /* We have to open this here, but it doesn't do any allocations,
128 so it shouldn't fail...
131 /* Create semaphore and initialize it */
132 GetPrivIBase(LIBBASE)->IBaseLock = AllocMem (sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR);
134 if (!GetPrivIBase(LIBBASE)->IBaseLock)
135 return FALSE;
137 InitSemaphore(GetPrivIBase(LIBBASE)->IBaseLock);
139 InitSemaphore(&GetPrivIBase(LIBBASE)->WinDecorSem);
140 InitSemaphore(&GetPrivIBase(LIBBASE)->ScrDecorSem);
141 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuDecorSem);
143 /* Initialize global stringgadget edit hook */
144 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Entry = (APTR)AROS_ASMSYMNAME(GlobalEditFunc);
145 GetPrivIBase(LIBBASE)->DefaultEditHook.h_SubEntry = NULL;
146 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Data = LIBBASE;
148 GetPrivIBase(LIBBASE)->GlobalEditHook = &(GetPrivIBase(LIBBASE)->DefaultEditHook);
150 GetPrivIBase(LIBBASE)->DefaultPubScreen = NULL;
151 NEWLIST(&GetPrivIBase(LIBBASE)->PubScreenList);
152 InitSemaphore(&GetPrivIBase(LIBBASE)->PubScrListLock);
154 InitSemaphore(&GetPrivIBase(LIBBASE)->ScreenNotificationListLock);
155 NEWLIST(&GetPrivIBase(LIBBASE)->ScreenNotificationList);
157 NEWLIST(&GetPrivIBase(LIBBASE)->Decorations);
160 InitSemaphore(&GetPrivIBase(LIBBASE)->GadgetLock);
161 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuLock);
162 InitSemaphore(&GetPrivIBase(LIBBASE)->WindowLock);
163 InitSemaphore(&GetPrivIBase(LIBBASE)->IntuiActionLock);
164 InitSemaphore(&GetPrivIBase(LIBBASE)->InputHandlerLock);
166 #ifdef SKINS
167 InitSemaphore(&GetPrivIBase(LIBBASE)->DataTypesSem);
168 GetPrivIBase(LIBBASE)->DataTypesBase = 0;
170 GetPrivIBase(LIBBASE)->transphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
171 GetPrivIBase(LIBBASE)->transphook.h_Entry = (HOOKFUNC)HookEntry;
172 GetPrivIBase(LIBBASE)->transphook.h_SubEntry = (HOOKFUNC)WindowTranspFunc;
174 GetPrivIBase(LIBBASE)->notransphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
175 GetPrivIBase(LIBBASE)->notransphook.h_Entry = (HOOKFUNC)HookEntry;
176 GetPrivIBase(LIBBASE)->notransphook.h_SubEntry = (HOOKFUNC)WindowNoTranspFunc;
177 #endif
179 #ifdef __MORPHOS__
180 memset(GetPrivIBase(LIBBASE)->Pad, 0xee, sizeof(GetPrivIBase(LIBBASE)->Pad));
181 GetPrivIBase(LIBBASE)->SystemRequestTitle = "System Request";
182 GetPrivIBase(LIBBASE)->WorkbenchTitle = "Ambient Screen";
183 #endif
185 * Setup the default pens to the default
186 * colors so that screens have proper color
187 * even before IPrefs is loaded.
190 struct Color32 *p;
191 ULONG i;
193 p = GetPrivIBase(LIBBASE)->Colors;
195 for (i = 0; i < COLORTABLEENTRIES; i++)
197 p[i].red = coltab[i*3];
198 p[i].green = coltab[i*3+1];
199 p[i].blue = coltab[i*3+2];
202 LIBBASE->PointerAlpha = 0x9F9F;
204 #ifdef __MORPHOS__
205 GetPrivIBase(LIBBASE)->mosmenuclass = InitMuiMenuClass(LIBBASE);
206 #endif
208 DEBUG_INIT(dprintf("LIB_Init: create menu handler task\n"));
209 /* FIXME: no cleanup routines for MenuHandler task */
210 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
211 return FALSE;
213 /* FIXME: no cleanup routines for ScreennotifyHandler task */
214 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
215 return FALSE;
218 DEBUG_INIT(dprintf("LIB_Init: load default preferences\n"));
219 LoadDefaultPreferences(GetPubIBase(LIBBASE));
220 #ifdef USEGETIPREFS
221 GetPrivIBase(LIBBASE)->IPrefsLoaded = FALSE;
222 #endif
224 #ifdef SKINS
225 if (!GetPrivIBase(LIBBASE)->SmallMenuPool)
227 if (!(GetPrivIBase(LIBBASE)->SmallMenuPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct SmallMenuEntry))*20,(sizeof (struct SmallMenuEntry))*20))) return NULL;
229 #endif
231 if (!(GetPrivIBase(LIBBASE)->IDCMPPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct IntIntuiMessage)) * 100,sizeof (struct IntIntuiMessage)))) return FALSE;
233 #ifdef SKINS
234 strcpy(GetPrivIBase(LIBBASE)->IControlExtensions.ice_ClockFormat,"%X");
235 #endif
237 GetPrivIBase(LIBBASE)->FrameSize = FRAMESIZE_THIN;
240 WORD i;
242 for(i = 0; i < RESOURCELIST_HASHSIZE; i++)
244 NewList((struct List *)&GetPrivIBase(LIBBASE)->ResourceList[i]);
248 GetPrivIBase(LIBBASE)->ScrDecorClass = FindClass(SCRDECORCLASS);
249 GetPrivIBase(LIBBASE)->ScrDecorTags = NULL;
250 GetPrivIBase(LIBBASE)->MenuDecorClass = FindClass(MENUDECORCLASS);
251 GetPrivIBase(LIBBASE)->MenuDecorTags = NULL;
252 GetPrivIBase(LIBBASE)->WinDecorClass = FindClass(WINDECORCLASS);
253 GetPrivIBase(LIBBASE)->WinDecorTags = NULL;
254 LIBBASE->ViewLord_ok = FALSE;
256 DEBUG_INIT(dprintf("LIB_Init: Setting up pointers...\n"));
258 GetPrivIBase(LIBBASE)->DefaultPointer = MakePointerFromPrefs
260 GetPubIBase(LIBBASE), &GetPrivIBase(LIBBASE)->ActivePreferences
262 GetPrivIBase(LIBBASE)->BusyPointer = MakePointerFromPrefs
264 GetPubIBase(LIBBASE), &GetPrivIBase(LIBBASE)->ActivePreferences
269 !GetPrivIBase(LIBBASE)->DefaultPointer
270 || !GetPrivIBase(LIBBASE)->BusyPointer
273 return FALSE;
276 NEWLIST(&GetPrivIBase(LIBBASE)->MonitorList);
277 InitSemaphore(&GetPrivIBase(LIBBASE)->MonitorListSem);
278 SetDisplayDriverCallback(DisplayDriverNotify, LIBBASE);
280 #if defined(__AROS_ARCH_pc__) /* for now */
281 /* Install reset handler to display manual shutdown screen */
282 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Node.ln_Pri = -96;
283 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Code =
284 (VOID_FUNC)ShutdownScreenHandler;
285 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Data =
286 &GetPrivIBase(LIBBASE)->ShutdownHandler;
287 AddResetCallback(&GetPrivIBase(LIBBASE)->ShutdownHandler);
288 #endif
290 DEBUG_INIT(dprintf("LIB_Init: done\n"));
292 return TRUE;
295 static int InitRootClass(LIBBASETYPEPTR LIBBASE)
297 InitSemaphore(&GetPrivIBase(LIBBASE)->ClassListLock);
298 NEWLIST(&GetPrivIBase(LIBBASE)->ClassList);
300 /* Setup root class */
302 GetPrivIBase(LIBBASE)->RootClass.cl_Dispatcher.h_Entry = (APTR)AROS_ASMSYMNAME(rootDispatcher);
303 GetPrivIBase(LIBBASE)->RootClass.cl_ID = (ClassID)ROOTCLASS;
304 GetPrivIBase(LIBBASE)->RootClass.cl_UserData = (IPTR)LIBBASE;
305 DEBUG_INIT(dprintf("LIB_Init: create rootclass\n"));
306 AddClass(&(GetPrivIBase(LIBBASE)->RootClass));
308 return TRUE;
311 /****************************************************************************************/
313 static int IntuitionOpen(LIBBASETYPEPTR LIBBASE)
315 struct GfxBase *GfxBase = GetPrivIBase(LIBBASE)->GfxBase;
316 DEBUG_OPEN(dprintf("LIB_Open: base 0x%lx\n", LIBBASE));
318 /* Open the input device */
320 if (!GetPrivIBase(LIBBASE)->InputMP)
322 if (!(GetPrivIBase(LIBBASE)->InputMP = CreateMsgPort()))
324 DEBUG_OPEN(dprintf("LIB_Open: can't create port\n"));
325 return FALSE;
329 if (!GetPrivIBase(LIBBASE)->InputIO)
331 if (!(GetPrivIBase(LIBBASE)->InputIO = (struct IOStdReq *)
332 CreateIORequest(GetPrivIBase(LIBBASE)->InputMP, sizeof (struct IOStdReq))) )
334 DEBUG_OPEN(dprintf("LIB_Open: can't create iorequest\n"));
335 return FALSE;
339 if (!GetPrivIBase(LIBBASE)->InputDeviceOpen)
341 if (!OpenDevice("input.device", -1, (struct IORequest *)GetPrivIBase(LIBBASE)->InputIO, 0))
343 GetPrivIBase(LIBBASE)->InputDeviceOpen = TRUE;
344 GetPrivIBase(LIBBASE)->InputBase = (struct Library *)GetPrivIBase(LIBBASE)->InputIO->io_Device;
346 else
348 DEBUG_OPEN(dprintf("LIB_Open: can't open input.device\n"));
349 return FALSE;
353 if (!GetPrivIBase(LIBBASE)->InputHandler)
355 D(bug("Initializing inputhandler\n"));
356 if ( !(GetPrivIBase(LIBBASE)->InputHandler = InitIIH(GetPubIBase(LIBBASE))) )
358 DEBUG_OPEN(dprintf("LIB_Open: can't init input handler\n"));
359 return FALSE;
362 D(bug("Adding inputhandler\n"));
363 GetPrivIBase(LIBBASE)->InputIO->io_Data = (APTR)GetPrivIBase(LIBBASE)->InputHandler;
364 GetPrivIBase(LIBBASE)->InputIO->io_Command = IND_ADDHANDLER;
366 D(bug("Calling DoIO()\n"));
367 DoIO((struct IORequest *)GetPrivIBase(LIBBASE)->InputIO);
368 D(bug("DoIO() called\n"));
371 if (!LIBBASE->ViewLord_ok)
373 #ifdef __MORPHOS__
374 struct ViewExtra *ve;
376 if (!(ve = GfxNew(VIEW_EXTRA_TYPE)))
378 GetPrivIBase(LIBBASE)->GfxBase = NULL;
379 DEBUG_OPEN(dprintf("LIB_Open: can't create view extra\n"));
380 return FALSE;
382 #endif
383 D(bug("[intuition] Calling InitView()\n"));
384 InitView(&LIBBASE->Base.ViewLord);
385 InitSemaphore(&LIBBASE->ViewLordLock);
386 #ifdef __MORPHOS__
387 GfxAssociate(&LIBBASE->Base.ViewLord, ve);
389 GetPrivIBase(LIBBASE)->ViewLordExtra = ve;
390 GetPrivIBase(LIBBASE)->SpriteNum = -1;
391 #endif
392 LIBBASE->ViewLord_ok = TRUE;
395 if (!GetPrivIBase(LIBBASE)->ScreenFont)
396 GetPrivIBase(LIBBASE)->ScreenFont = GetPrivIBase(LIBBASE)->GfxBase->DefaultFont;
398 #if 0 /* CHECKME: stegerg: backport, disabled */
399 if (!(GetPrivIBase(LIBBASE)->TopazFont))
401 struct TextAttr textattr = {"topaz.font",8,0,FPF_ROMFONT};
402 GetPrivIBase(LIBBASE)->TopazFont = OpenFont(&textattr);
404 #endif
406 if (!GetPrivIBase(LIBBASE)->TimerBase)
408 if (!(GetPrivIBase(LIBBASE)->TimerMP = CreateMsgPort()))
410 DEBUG_OPEN(dprintf("LIB_Open: can't create timer port\n"));
411 return FALSE; /* don't close anything */
414 if (!(GetPrivIBase(LIBBASE)->TimerIO = (struct timerequest *)CreateIORequest(GetPrivIBase(LIBBASE)->TimerMP, sizeof(struct timerequest))))
416 DEBUG_OPEN(dprintf("LIB_Open: can't create timer ioreq\n"));
417 return FALSE; /* don't close anything */
420 if (OpenDevice(TIMERNAME,UNIT_VBLANK, (struct IORequest *)GetPrivIBase(LIBBASE)->TimerIO,0))
422 DEBUG_OPEN(dprintf("LIB_Open: can't open timer.device\n"));
423 return FALSE; /* don't close anything */
426 GetPrivIBase(LIBBASE)->TimerBase = (struct Library *)GetPrivIBase(LIBBASE)->TimerIO->tr_node.io_Device;
428 SetPrefs(&GetPrivIBase(LIBBASE)->DefaultPreferences, sizeof(struct Preferences), FALSE);
431 #if 0
432 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
434 //check if dos is opened!!!
435 ((struct DosLibrary *)DOSBase)->dl_IntuitionBase =
436 (struct Library *)LIBBASE;
438 /* Install intuition's version of DisplayError() that puts up
439 a requester with Retry/Cancel options */
440 GetPrivIBase(LIBBASE)->OldDisplayErrorFunc =
441 SetFunction(DOSBase, -81*LIB_VECTSIZE,
442 AROS_SLIB_ENTRY(DisplayError, Intuition, 81));
444 #else
445 # ifdef SKINS
446 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
448 InitSkinManager(GetPubIBase(LIBBASE));
450 # endif
451 #endif
453 /* FIXME: no cleanup routines for MenuHandler task */
454 if (!GetPrivIBase(LIBBASE)->MenuHandlerPort)
456 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
457 return FALSE;
460 /* FIXME: no cleanup routines for ScreennotifyHandler task */
461 if (!GetPrivIBase(LIBBASE)->ScreenNotifyReplyPort)
463 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
464 return FALSE;
467 #ifdef INTUITION_NOTIFY_SUPPORT
468 /* Add screennotify.library base if not there yet - Piru
470 if (!GetPrivIBase(LIBBASE)->ScreenNotifyBase)
472 GetPrivIBase(LIBBASE)->ScreenNotifyBase = sn_Init(GetPubIBase(LIBBASE));
475 # if 0 /* not finished yet - Piru */
476 /* Add notifyintuition.library base if not there yet - Piru
478 if (!GetPrivIBase(LIBBASE)->NotifyIntuitionBase)
480 GetPrivIBase(LIBBASE)->NotifyIntuitionBase = ni_Init(GetPubIBase(LIBBASE));
482 # endif
483 #endif
485 return TRUE;
488 DECLARESET(CLASSESINIT)
489 ADD2SET(InitRootClass, CLASSESINIT, -20)
490 ADD2INITLIB(IntuitionInit, 0)
491 ADD2OPENLIB(IntuitionOpen, 0)