2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
8 #include <aros/config.h>
9 #include <intuition/intuition.h>
10 #include <proto/intuition.h>
11 #include <proto/graphics.h>
13 #include "intuition_intern.h"
15 static ULONG
FindMode(ULONG width
, ULONG height
, ULONG depth
, struct IntuitionBase
*IntuitionBase
)
17 struct GfxBase
*GfxBase
= GetPrivIBase(IntuitionBase
)->GfxBase
;
19 struct TagItem modetags
[] =
21 { BIDTAG_DesiredWidth
, width
}, /* 0 */
22 { BIDTAG_DesiredHeight
, height
}, /* 1 */
23 { BIDTAG_Depth
, depth
}, /* 2 */
27 /* Try to find the specified mode */
28 modeid
= BestModeIDA(modetags
);
29 D(bug("[OpenWorkbench] Size: %dx%d, depth: %d, ModeID 0x%08X\n", width
, height
, depth
, modeid
));
31 if (modeid
== INVALID_ID
)
33 /* If failed, we can have this resolution, but not this depth. Try 4 colors. */
34 modetags
[2].ti_Data
= 2;
36 modeid
= BestModeIDA(modetags
);
37 D(bug("[OpenWorkbench] Size: %dx%d, depth: 2, ModeID 0x%08X\n", width
, height
, modeid
));
43 /*****************************************************************************
46 AROS_LH0(IPTR
, OpenWorkBench
,
51 struct IntuitionBase
*, IntuitionBase
, 35, Intuition
)
54 Attempt to open the Workbench screen.
60 Tries to (re)open WorkBench screen. If successful return value
61 is a pointer to the screen structure, which shouldn't be used,
62 because other programs may close the WorkBench and make the
63 pointer invalid. If this function fails the return value is NULL.
76 *****************************************************************************/
80 struct GfxBase
*GfxBase
= GetPrivIBase(IntuitionBase
)->GfxBase
;
81 struct Screen
*wbscreen
;
83 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: <%s>\n",
84 FindTask(NULL
)->tc_Node
.ln_Name
));
86 /* Intuition not up yet? */
87 if (!GetPrivIBase(IntuitionBase
)->DefaultPointer
)
92 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
94 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: Workbench 0x%lx\n",
99 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: returning Workbench screen at 0x%lx\n",
102 UnlockPubScreenList();
104 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
106 return (IPTR
)wbscreen
;
110 /* Open the Workbench screen if we don't have one. */
111 WORD width
, height
, depth
;
115 struct TagItem screenTags
[] =
117 { SA_Width
, 0 }, /* 0 */
118 { SA_Height
, 0 }, /* 1 */
119 { SA_Depth
, 0 }, /* 2 */
120 { SA_DisplayID
, 0 }, /* 3 */
121 { SA_LikeWorkbench
, TRUE
}, /* 4 */
122 { SA_Type
, WBENCHSCREEN
}, /* 5 */
123 { SA_Title
, (IPTR
) "Workbench Screen" }, /* 6 */
124 { SA_PubName
, (IPTR
) "Workbench" }, /* 7 */
125 { SA_SharePens
, TRUE
}, /* 8 */
129 if (!GetPrivIBase(IntuitionBase
)->ScreenModePrefs
)
130 SetDisplayDefaults(IntuitionBase
);
132 width
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
->smp_Width
;
133 height
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
->smp_Height
;
134 depth
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
->smp_Depth
;
135 modeid
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
->smp_DisplayID
;
137 D(bug("[OpenWorkbench] Requested size: %dx%d, depth: %d, ModeID: 0x%08lX\n", width
, height
, depth
, modeid
));
139 /* First check if the specified ModeID exists in the system */
140 disphandle
= FindDisplayInfo(modeid
);
143 D(bug("[OpenWorkbench] Invalid ModeID given\n"));
147 if (modeid
== INVALID_ID
)
150 * We were unable to find the ModeID specified in our prefs. Need to find a replacement.
151 * First we'll try to look up a mode corresponding to user-specified width, height and depth.
154 /* Specifying -1's here causes BestModeIDA() to fail, fix up the values */
155 if (width
== STDSCREENWIDTH
)
157 D(bug("[OpenWorkbench] Using default width %d\n", GfxBase
->NormalDisplayColumns
));
158 width
= GfxBase
->NormalDisplayColumns
;
160 if (height
== STDSCREENHEIGHT
)
162 D(bug("[OpenWorkbench] Using default height %d\n", GfxBase
->NormalDisplayRows
));
163 height
= GfxBase
->NormalDisplayRows
;
166 depth
= AROS_NOMINAL_DEPTH
;
169 /* FIXME: less hacky RTG detection */
170 /* select 640x480 if we appear to have RTG hardware (instead of standard PAL/NTSC mode) */
173 modeid
= BestModeID(BIDTAG_DesiredWidth
, 800, BIDTAG_DesiredHeight
, 600,
174 BIDTAG_Depth
, 8, TAG_DONE
);
176 if (modeid
!= INVALID_ID
)
178 /* If we have 800x600 or better mode, we assume we have RTG hardware */
184 modeid
= FindMode(width
, height
, depth
, IntuitionBase
);
187 if (modeid
== INVALID_ID
)
189 /* We don't have any modes with the specified resolution. Try SVGA default (800x600) */
190 modeid
= FindMode(800, 600, depth
, IntuitionBase
);
193 if (modeid
== INVALID_ID
)
195 /* We don't have any modes with the specified resolution. Try VGA default (640x480) */
196 modeid
= FindMode(640, 480, depth
, IntuitionBase
);
199 if (modeid
== INVALID_ID
)
201 /* We don't have any modes with the specified resolution. Try Amiga default (640x200) */
202 modeid
= FindMode(640, 200, depth
, IntuitionBase
);
205 if (modeid
== INVALID_ID
)
208 * There's no even 640x200. Perhaps we are on some mobile device.
209 * Here we try the smallest known screen. This size was picked up
210 * from configure's defaults for old PalmPilot port.
212 modeid
= FindMode(160, 160, depth
, IntuitionBase
);
215 if (modeid
!= INVALID_ID
)
217 struct DimensionInfo dim
;
219 #define BOUND(min, val, max) \
220 (((val) == -1) ? -1 : ((min) > (val)) ? (min) : ((max) < (val)) ? (max) : (val))
222 /* Now fix up our specified size to fit into mode's limits. */
223 if (GetDisplayInfoData(NULL
, (UBYTE
*)&dim
, sizeof(dim
), DTAG_DIMS
, modeid
))
225 D(bug("[OpenWorkbench] Minimum size: %dx%d\n", dim
.MinRasterWidth
, dim
.MinRasterHeight
));
226 D(bug("[OpenWorkbench] Maximum size: %dx%d\n", dim
.MaxRasterWidth
, dim
.MaxRasterHeight
));
227 D(bug("[OpenWorkbench] Maximum depth: %d\n", dim
.MaxDepth
));
229 width
= BOUND(dim
.MinRasterWidth
, width
, dim
.MaxRasterWidth
);
230 height
= BOUND(dim
.MinRasterHeight
, height
, dim
.MaxRasterHeight
);
231 depth
= BOUND(0, depth
, dim
.MaxDepth
);
232 D(bug("[OpenWorkbench] Corrected size: %dx%d %dbpp\n", width
, height
, depth
));
234 GetPrivIBase(IntuitionBase
)->ScreenModePrefs
->smp_Width
= width
;
235 GetPrivIBase(IntuitionBase
)->ScreenModePrefs
->smp_Height
= height
;
236 GetPrivIBase(IntuitionBase
)->ScreenModePrefs
->smp_Depth
= depth
;
240 * Remember this ModeID because OpenScreen() with SA_LikeWorkbench set to TRUE
241 * looks at this field. We MUST have something valid here.
243 GetPrivIBase(IntuitionBase
)->ScreenModePrefs
->smp_DisplayID
= modeid
;
245 screenTags
[0].ti_Data
= width
;
246 screenTags
[1].ti_Data
= height
;
247 screenTags
[2].ti_Data
= depth
;
248 screenTags
[3].ti_Data
= modeid
;
250 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: Trying to open Workbench screen\n"));
252 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_BEFORE_OPENWB
, IntuitionBase
);
254 wbscreen
= OpenScreenTagList(NULL
, screenTags
);
259 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: failed to open Workbench screen !!!!\n"));
261 UnlockPubScreenList();
265 GetPrivIBase(IntuitionBase
)->WorkBench
= wbscreen
;
267 /* Make the screen public. */
268 PubScreenStatus( wbscreen
, 0 );
271 /* We have opened the Workbench Screen. Now tell the Workbench process
272 to open it's windows, if there is one. We still do have the pub screen
273 list locked. But while sending the Message to the Workbench task we
274 must unlock the semaphore, otherwise there can be deadlocks if the
275 Workbench task itself does something which locks the pub screen list.
277 But if we unlock the pub screen list, then some other task could try
278 to close the Workbench screen in the meantime. The trick to solve
279 this problem is to increase the psn_VisitorCount of the Workbench
280 screen here, before unlocking the pub screen list. This way the
281 Workbench screen cannot go away. */
283 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
++;
284 DEBUG_VISITOR(dprintf("OpenWorkbench: new VisitorCount %ld\n",
285 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
287 UnlockPubScreenList();
289 DEBUG_VISITOR(dprintf("OpenWorkbench: notify Workbench\n"));
291 /* Don't call this function while pub screen list is locked! */
292 TellWBTaskToOpenWindows(IntuitionBase
);
294 /* Now fix the psn_VisitorCount we have increased by one, above. It's probably
295 better to do this by hand, instead of calling UnlockPubScreen, because Un-
296 lockPubScreen can send signal to psn_SigTask. */
299 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
--;
300 DEBUG_VISITOR(dprintf("OpenWorkbench: new VisitorCount %ld\n",
301 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
302 UnlockPubScreenList();
304 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
306 return (IPTR
)wbscreen
;
310 } /* OpenWorkBench */