2 Copyright © 1995-2013, 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>
12 /*****************************************************************************
15 AROS_LH0(LONG
, CloseWorkBench
,
20 struct IntuitionBase
*, IntuitionBase
, 13, Intuition
)
23 Attempt to close the Workbench screen. This will fail if there are any
24 non-Drawer windows open on it.
29 success - TRUE if Workbench screen could be closed.
32 If the Workbench screen is already closed when this function is called,
44 *****************************************************************************/
48 struct Screen
*wbscreen
;
51 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: <%s>\n",
52 FindTask(NULL
)->tc_Node
.ln_Name
));
54 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
55 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen 0x%p\n", wbscreen
));
57 if (wbscreen
) FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_BEFORE_CLOSEWB
, IntuitionBase
);
59 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
61 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
65 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: no wbscreen, do nothing\n"));
66 UnlockPubScreenList();
68 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
74 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen's pubnode 0x%lx\n",
75 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
));
76 if (GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
!= 0)
78 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: visitor count %ld, do nothing\n",
79 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
84 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList\n"));
85 UnlockPubScreenList();
86 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList done\n"));
88 /* If there is a Workbench process running, tell it to close its windows. */
90 /* Don't call this function while pub screen list is locked! */
92 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to close windows\n"));
93 TellWBTaskToCloseWindows(IntuitionBase
);
95 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
97 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
99 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
101 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: current wbscreen 0x%lx\n",
104 /* Try to close the Workbench screen, if there is any. */
105 if( wbscreen
!= NULL
)
107 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen\n"));
108 if (CloseScreen(wbscreen
))
110 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen worked\n"));
111 GetPrivIBase(IntuitionBase
)->WorkBench
= NULL
;
117 /* Grrr ... closing screen failed. I inc psn_VisitorCount by hand here,
118 * to avoid that someone else can kill it, because I must tell Workbench
119 * task that it shall open its windows again
122 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen failed\n"));
123 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
++;
132 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
133 UnlockPubScreenList();
134 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
136 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: wbscreen 0x%lx retval %ld\n",
139 if (wbscreen
&& !retval
)
141 /* Don't call this function while pub screen list is locked! */
142 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to reopen windows\n"));
143 TellWBTaskToOpenWindows(IntuitionBase
);
145 /* Fix psn_VisitorCount which was increased above */
146 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
148 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
149 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: WBScreen's pubnode 0x%lx\n",
150 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
));
151 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
--;
152 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
153 UnlockPubScreenList();
154 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
157 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Return %d\n", retval
));
161 /* Workbench screen failed to close, notify that the screen is open again */
162 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
166 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_CLOSEWB
, IntuitionBase
);
173 } /* CloseWorkBench */