2 Copyright 1995-2004, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
7 #include "intuition_intern.h"
9 #include <intuition/intuition.h>
10 #include <proto/intuition.h>
11 #include <proto/graphics.h>
13 /*****************************************************************************
17 AROS_LH0(IPTR
, OpenWorkBench
,
22 struct IntuitionBase
*, IntuitionBase
, 35, Intuition
)
25 Attempt to open the Workbench screen.
31 Tries to (re)open WorkBench screen. If successful return value
32 is a pointer to the screen structure, which shouldn't be used,
33 because other programs may close the WorkBench and make the
35 If this function fails the return value is NULL.
48 *****************************************************************************/
51 AROS_LIBBASE_EXT_DECL(struct IntuitionBase
*,IntuitionBase
)
53 struct Screen
*wbscreen
;
55 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: <%s>\n",
56 FindTask(NULL
)->tc_Node
.ln_Name
));
60 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
62 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: Workbench 0x%lx\n",
67 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: returning Workbench screen at 0x%lx\n",
70 UnlockPubScreenList();
72 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
74 return (IPTR
)wbscreen
;
78 /* Open the Workbench screen if we don't have one. */
80 WORD width
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Width
;
81 WORD height
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Height
;
82 WORD depth
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Depth
;
83 ULONG modeid
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_DisplayID
;
85 struct TagItem screenTags
[] =
87 { SA_Width
, 0 }, /* 0 */
88 { SA_Height
, 0 }, /* 1 */
89 { SA_Depth
, depth
}, /* 2 */
90 { SA_DisplayID
, 0 }, /* 3 */
91 { SA_LikeWorkbench
, TRUE
}, /* 4 */
92 { SA_Type
, WBENCHSCREEN
}, /* 5 */
93 { SA_Title
, (IPTR
) "Workbench Screen" }, /* 6 */
94 { SA_PubName
, (IPTR
) "Workbench" }, /* 7 */
95 { SA_SharePens
, TRUE
}, /* 8 */
99 APTR disphandle
= FindDisplayInfo(modeid
);
103 struct TagItem modetags
[] =
105 { BIDTAG_DesiredWidth
, width
},
106 { BIDTAG_DesiredHeight
, height
},
107 { BIDTAG_Depth
, depth
},
111 modeid
= BestModeIDA(modetags
);
112 disphandle
= FindDisplayInfo(modeid
);
117 struct DimensionInfo dim
;
119 #define BOUND(min, val, max) \
120 (((min) > (val)) ? (min) : ((max) < (val)) ? (max) : (val))
122 if (GetDisplayInfoData(disphandle
, (UBYTE
*)&dim
, sizeof(dim
), DTAG_DIMS
, 0))
124 width
= BOUND(dim
.MinRasterWidth
, width
, dim
.MaxRasterWidth
);
125 height
= BOUND(dim
.MinRasterHeight
, height
, dim
.MaxRasterHeight
);
127 screenTags
[3].ti_Data
= modeid
;
130 screenTags
[3].ti_Tag
= TAG_IGNORE
;
132 screenTags
[0].ti_Data
= width
;
133 screenTags
[1].ti_Data
= height
;
135 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: Trying to open Workbench screen\n"));
137 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_BEFORE_OPENWB
, IntuitionBase
);
139 wbscreen
= OpenScreenTagList(NULL
, screenTags
);
143 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: failed to open Workbench screen !!!!\n"));
145 UnlockPubScreenList();
149 GetPrivIBase(IntuitionBase
)->WorkBench
= wbscreen
;
151 /* Make the screen public. */
152 PubScreenStatus( wbscreen
, 0 );
156 /* We have opened the Workbench Screen. Now tell the Workbench process
157 to open it's windows, if there is one. We still do have the pub screen
158 list locked. But while sending the Message to the Workbench task we
159 must unlock the semaphore, otherwise there can be deadlocks if the
160 Workbench task itself does something which locks the pub screen list.
162 But if we unlock the pub screen list, then some other task could try
163 to close the Workbench screen in the meantime. The trick to solve
164 this problem is to increase the psn_VisitorCount of the Workbench
165 screen here, before unlocking the pub screen list. This way the
166 Workbench screen cannot go away. */
168 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
++;
169 DEBUG_VISITOR(dprintf("OpenWorkbench: new VisitorCount %ld\n",
170 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
172 UnlockPubScreenList();
174 DEBUG_VISITOR(dprintf("OpenWorkbench: notify Workbench\n"));
176 /* Don't call this function while pub screen list is locked! */
177 TellWBTaskToOpenWindows(IntuitionBase
);
179 /* Now fix the psn_VisitorCount we have increased by one, above. It's probably
180 better to do this by hand, instead of calling UnlockPubScreen, because Un-
181 lockPubScreen can send signal to psn_SigTask. */
184 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
--;
185 DEBUG_VISITOR(dprintf("OpenWorkbench: new VisitorCount %ld\n",
186 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
187 UnlockPubScreenList();
189 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
191 return (IPTR
)wbscreen
;
195 } /* OpenWorkBench */