2 Copyright 1995-2007, 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:
25 - Check for open application windows. return FALSE if there are any
26 - Clean up all special buffers
27 - Close the Workbench screen
28 - Make the Workbench program mostly inactive
29 (disk activity will still be monitored)
49 *****************************************************************************/
53 struct Screen
*wbscreen
;
56 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: <%s>\n",
57 FindTask(NULL
)->tc_Node
.ln_Name
));
59 if (wbscreen
) FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_BEFORE_CLOSEWB
, IntuitionBase
);
61 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
63 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
65 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
67 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen 0x%lx\n",
72 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: no wbscreen, do nothing\n"));
73 UnlockPubScreenList();
75 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
81 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen's pubnode 0x%lx\n",
82 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
));
83 if (GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
!= 0)
85 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: visitor count %ld, do nothing\n",
86 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
91 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList\n"));
92 UnlockPubScreenList();
93 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList done\n"));
96 /* If there is a Workbench process running, tell it to close it's windows. */
98 /* Don't call this function while pub screen list is locked! */
100 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to close windows\n"));
101 TellWBTaskToCloseWindows(IntuitionBase
);
103 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
105 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
107 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
109 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: current wbscreen 0x%lx\n",
112 /* Try to close the Workbench screen, if there is any. */
113 if( wbscreen
!= NULL
)
115 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen\n"));
116 if (CloseScreen(wbscreen
))
118 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen worked\n"));
119 GetPrivIBase(IntuitionBase
)->WorkBench
= NULL
;
125 /* Grrr ... closing screen failed. I inc psn_VisitorCount by hand here,
126 * to avoid that someone else can kill it, because I must tell Workbench
127 * task that it shall open its windows again
130 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen failed\n"));
131 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
++;
140 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
141 UnlockPubScreenList();
142 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
144 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: wbscreen 0x%lx retval %ld\n",
147 if (wbscreen
&& !retval
)
149 /* Don't call this function while pub screen list is locked! */
150 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to reopen windows\n"));
151 TellWBTaskToOpenWindows(IntuitionBase
);
153 /* Fix psn_VisitorCount which was increased above */
154 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
156 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
157 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: WBScreen's pubnode 0x%lx\n",
158 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
));
159 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
--;
160 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
161 UnlockPubScreenList();
162 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
165 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Return %d\n", retval
));
169 /* Workbench screen failed to close, notify that the screen is open again */
170 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
174 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_CLOSEWB
, IntuitionBase
);
181 } /* CloseWorkBench */