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 #ifdef INTUITION_NOTIFY_SUPPORT
73 /* Notify that the Workbench screen is open */
74 /* NOTE: Original screennotify.library notify in this case, too! */
75 sn_DoNotify(SCREENNOTIFY_TYPE_WORKBENCH
, (APTR
) TRUE
, GetPrivIBase(IntuitionBase
)->ScreenNotifyBase
);
77 return (IPTR
)wbscreen
;
81 /* Open the Workbench screen if we don't have one. */
83 WORD width
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Width
;
84 WORD height
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Height
;
85 WORD depth
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Depth
;
86 ULONG modeid
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_DisplayID
;
88 struct TagItem screenTags
[] =
90 { SA_Width
, 0 }, /* 0 */
91 { SA_Height
, 0 }, /* 1 */
92 { SA_Depth
, depth
}, /* 2 */
93 { SA_DisplayID
, 0 }, /* 3 */
94 { SA_LikeWorkbench
, TRUE
}, /* 4 */
95 { SA_Type
, WBENCHSCREEN
}, /* 5 */
96 { SA_Title
, (IPTR
) "Workbench Screen" }, /* 6 */
97 { SA_PubName
, (IPTR
) "Workbench" }, /* 7 */
98 { SA_SharePens
, TRUE
}, /* 8 */
102 APTR disphandle
= FindDisplayInfo(modeid
);
106 struct TagItem modetags
[] =
108 { BIDTAG_DesiredWidth
, width
},
109 { BIDTAG_DesiredHeight
, height
},
110 { BIDTAG_Depth
, depth
},
114 modeid
= BestModeIDA(modetags
);
115 disphandle
= FindDisplayInfo(modeid
);
120 struct DimensionInfo dim
;
122 #define BOUND(min, val, max) \
123 (((min) > (val)) ? (min) : ((max) < (val)) ? (max) : (val))
125 if (GetDisplayInfoData(disphandle
, (UBYTE
*)&dim
, sizeof(dim
), DTAG_DIMS
, 0))
127 width
= BOUND(dim
.MinRasterWidth
, width
, dim
.MaxRasterWidth
);
128 height
= BOUND(dim
.MinRasterHeight
, height
, dim
.MaxRasterHeight
);
130 screenTags
[3].ti_Data
= modeid
;
133 screenTags
[3].ti_Tag
= TAG_IGNORE
;
135 screenTags
[0].ti_Data
= width
;
136 screenTags
[1].ti_Data
= height
;
138 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: Trying to open Workbench screen\n"));
140 wbscreen
= OpenScreenTagList(NULL
, screenTags
);
144 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: failed to open Workbench screen !!!!\n"));
146 UnlockPubScreenList();
150 GetPrivIBase(IntuitionBase
)->WorkBench
= wbscreen
;
152 /* Make the screen public. */
153 PubScreenStatus( wbscreen
, 0 );
157 /* We have opened the Workbench Screen. Now tell the Workbench process
158 to open it's windows, if there is one. We still do have the pub screen
159 list locked. But while sending the Message to the Workbench task we
160 must unlock the semaphore, otherwise there can be deadlocks if the
161 Workbench task itself does something which locks the pub screen list.
163 But if we unlock the pub screen list, then some other task could try
164 to close the Workbench screen in the meantime. The trick to solve
165 this problem is to increase the psn_VisitorCount of the Workbench
166 screen here, before unlocking the pub screen list. This way the
167 Workbench screen cannot go away. */
169 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
++;
170 DEBUG_VISITOR(dprintf("OpenWorkbench: new VisitorCount %ld\n",
171 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
173 UnlockPubScreenList();
175 DEBUG_VISITOR(dprintf("OpenWorkbench: notify Workbench\n"));
177 /* Don't call this function while pub screen list is locked! */
178 TellWBTaskToOpenWindows(IntuitionBase
);
180 /* Now fix the psn_VisitorCount we have increased by one, above. It's probably
181 better to do this by hand, instead of calling UnlockPubScreen, because Un-
182 lockPubScreen can send signal to psn_SigTask. */
185 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
--;
186 DEBUG_VISITOR(dprintf("OpenWorkbench: new VisitorCount %ld\n",
187 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
188 UnlockPubScreenList();
190 #ifdef INTUITION_NOTIFY_SUPPORT
191 /* Notify that the Workbench screen is open again */
192 sn_DoNotify(SCREENNOTIFY_TYPE_WORKBENCH
, (APTR
) TRUE
, GetPrivIBase(IntuitionBase
)->ScreenNotifyBase
);
195 return (IPTR
)wbscreen
;
199 } /* OpenWorkBench */