2 Copyright 1995-2008, 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 /*****************************************************************************
16 AROS_LH0(LONG
, CloseWorkBench
,
21 struct IntuitionBase
*, IntuitionBase
, 13, Intuition
)
24 Attempt to close the Workbench screen. This will fail if there are any
25 non-Drawer windows open on it.
30 success - TRUE if Workbench screen could be closed.
33 If the Workbench screen is already closed when this function is called,
47 *****************************************************************************/
51 struct Screen
*wbscreen
;
54 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: <%s>\n",
55 FindTask(NULL
)->tc_Node
.ln_Name
));
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"));
63 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
65 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen 0x%lx\n",
70 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: no wbscreen, do nothing\n"));
71 UnlockPubScreenList();
73 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
79 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen's pubnode 0x%lx\n",
80 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
));
81 if (GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
!= 0)
83 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: visitor count %ld, do nothing\n",
84 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
89 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList\n"));
90 UnlockPubScreenList();
91 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList done\n"));
93 /* If there is a Workbench process running, tell it to close its windows. */
95 /* Don't call this function while pub screen list is locked! */
97 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to close windows\n"));
98 TellWBTaskToCloseWindows(IntuitionBase
);
100 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
102 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
104 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
106 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: current wbscreen 0x%lx\n",
109 /* Try to close the Workbench screen, if there is any. */
110 if( wbscreen
!= NULL
)
112 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen\n"));
113 if (CloseScreen(wbscreen
))
115 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen worked\n"));
116 GetPrivIBase(IntuitionBase
)->WorkBench
= NULL
;
122 /* Grrr ... closing screen failed. I inc psn_VisitorCount by hand here,
123 * to avoid that someone else can kill it, because I must tell Workbench
124 * task that it shall open its windows again
127 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen failed\n"));
128 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
++;
137 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
138 UnlockPubScreenList();
139 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
141 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: wbscreen 0x%lx retval %ld\n",
144 if (wbscreen
&& !retval
)
146 /* Don't call this function while pub screen list is locked! */
147 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to reopen windows\n"));
148 TellWBTaskToOpenWindows(IntuitionBase
);
150 /* Fix psn_VisitorCount which was increased above */
151 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
153 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
154 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: WBScreen's pubnode 0x%lx\n",
155 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
));
156 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
--;
157 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
158 UnlockPubScreenList();
159 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
162 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Return %d\n", retval
));
166 /* Workbench screen failed to close, notify that the screen is open again */
167 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
171 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_CLOSEWB
, IntuitionBase
);
178 } /* CloseWorkBench */