graphics.library: In INVERSVID mode, don't clobber the GC's pens
[AROS.git] / workbench / c / AROSMonDrvs.c
blob0e74baefe26cad55b0e8516a02b25f7185f737f0
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Code that loads and initializes necessary HIDDs.
6 Lang: english
7 */
9 #define DEBUG 0
11 #include <aros/debug.h>
12 #include <dos/dosextens.h>
13 #include <workbench/icon.h>
14 #include <proto/alib.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
17 #include <proto/icon.h>
19 #include <aros/shcommands.h>
21 #include <stdlib.h>
22 #include <string.h>
24 #define MONITORS_DIR "DEVS:Monitors"
25 #define COMPOSITING_NAME "Compositor"
27 /************************************************************************/
29 /* This code does almost the same thing as C:LoadMonDrvs does on other systems.
30 However, additionally we support priority-based sorting for display drivers.
31 This is needed in order to make monitor ID assignment more predictable */
33 struct MonitorNode
35 struct Node n;
36 char Name[1];
39 static BYTE checkIcon(STRPTR name, struct Library *IconBase)
41 LONG pri = 0;
42 struct DiskObject *dobj = GetDiskObject(name);
44 if (dobj == NULL)
45 return 0;
47 if ((dobj->do_Type == WBTOOL) || (dobj->do_Type == WBPROJECT))
49 const STRPTR *toolarray = (const STRPTR *)dobj->do_ToolTypes;
50 STRPTR s;
52 if ((s = FindToolType(toolarray, "STARTPRI")))
54 pri = atol(s);
55 if (pri < -128)
56 pri = -128;
57 else if (pri > 127)
58 pri = 127;
60 FreeDiskObject(dobj);
62 return pri;
65 static BOOL findMonitors(struct List *monitorsList, struct DosLibrary *DOSBase, struct Library *IconBase, struct ExecBase *SysBase, APTR poolmem)
67 BOOL retvalue = TRUE;
68 LONG error;
69 struct AnchorPath *ap = AllocPooled(poolmem, sizeof(struct AnchorPath));
71 DB2(bug("[LoadMonDrvs] AnchorPath 0x%p\n", ap));
72 if (ap)
74 /* Initialize important fields in AnchorPath, especially
75 ap_Strlen (prevents memory trashing) */
76 ap->ap_Flags = 0;
77 ap->ap_Strlen = 0;
78 ap->ap_BreakBits = 0;
80 error = MatchFirst("~(#?.info)", ap);
81 while (!error)
83 struct MonitorNode *newnode;
85 DB2(bug("[LoadMonDrvs] Found monitor name %s\n", ap->ap_Info.fib_FileName));
87 /* Software composition driver was loaded before */
88 if (strcmp(ap->ap_Info.fib_FileName, COMPOSITING_NAME))
90 newnode = AllocPooled(poolmem, sizeof(struct MonitorNode) + strlen(ap->ap_Info.fib_FileName));
91 DB2(bug("[LoadMonDrvs] Monitor node 0x%p\n", newnode));
92 if (newnode == NULL)
94 retvalue = FALSE;
95 break;
98 strcpy(newnode->Name, ap->ap_Info.fib_FileName);
99 if (IconBase)
100 newnode->n.ln_Pri = checkIcon(ap->ap_Info.fib_FileName, IconBase);
101 else
102 newnode->n.ln_Pri = 0;
103 Enqueue(monitorsList, &newnode->n);
106 error = MatchNext(ap);
109 if (error != ERROR_NO_MORE_ENTRIES)
111 retvalue = FALSE;
112 /* FIXME: Why no MatchEnd() in this case?
113 goto exit; */
115 MatchEnd(ap);
117 else
118 retvalue = FALSE;
120 return retvalue;
123 static void loadMonitors(struct List *monitorsList, struct DosLibrary *DOSBase)
125 struct MonitorNode *node;
127 D(bug("[LoadMonDrvs] Loading monitor drivers...\n"));
128 D(bug(" Pri Name\n"));
130 ForeachNode(monitorsList, node)
132 D(bug("%4d %s\n", node->n.ln_Pri, node->Name));
133 Execute(node->Name, BNULL, BNULL);
136 D(bug("--------------------------\n"));
139 AROS_SH2H(AROSMonDrvs, 1.0, "Load AROS Monitor and Compositor drivers",
140 AROS_SHAH(BOOL, , NOCOMPOSITION,/S,FALSE, "Only load Monitors"),
141 AROS_SHAH(BOOL, , ONLYCOMPOSITION,/S,FALSE, "Only load Compositor"))
143 AROS_SHCOMMAND_INIT
145 APTR pool;
146 struct Library *IconBase;
147 BPTR dir, olddir;
148 BOOL res = TRUE;
149 IPTR args[2] = {FALSE, FALSE};
151 dir = Lock(MONITORS_DIR, SHARED_LOCK);
152 D(bug("[LoadMonDrvs] Monitors directory 0x%p\n", dir));
153 if (dir)
155 olddir = CurrentDir(dir);
157 if (!args[0])
159 /* Software composition driver is ran first */
160 D(bug("[LoadMonDrvs] Loading composition driver...\n"));
161 Execute(COMPOSITING_NAME, BNULL, BNULL);
164 if (!args[1])
166 pool = CreatePool(MEMF_ANY, sizeof(struct MonitorNode) * 10, sizeof(struct MonitorNode) * 5);
167 DB2(bug("[LoadMonDrvs] Created pool 0x%p\n", pool));
168 if (pool)
170 struct List MonitorsList;
172 NewList(&MonitorsList);
173 IconBase = OpenLibrary("icon.library", 0);
174 if (IconBase)
176 findMonitors(&MonitorsList, DOSBase, IconBase, SysBase, pool);
177 loadMonitors(&MonitorsList, DOSBase);
178 CloseLibrary(IconBase);
180 DeletePool(pool);
182 else
183 res = FALSE;
186 CurrentDir(olddir);
187 UnLock(dir);
190 return res;
192 AROS_SHCOMMAND_EXIT