2 Copyright 1995-2010, 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 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
58 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen 0x%p\n", wbscreen
));
60 if (wbscreen
) FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_BEFORE_CLOSEWB
, IntuitionBase
);
62 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
64 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
68 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: no wbscreen, do nothing\n"));
69 UnlockPubScreenList();
71 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
77 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen's pubnode 0x%lx\n",
78 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
));
79 if (GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
!= 0)
81 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: visitor count %ld, do nothing\n",
82 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
));
87 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList\n"));
88 UnlockPubScreenList();
89 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList done\n"));
91 /* If there is a Workbench process running, tell it to close its windows. */
93 /* Don't call this function while pub screen list is locked! */
95 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to close windows\n"));
96 TellWBTaskToCloseWindows(IntuitionBase
);
98 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
100 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
102 wbscreen
= GetPrivIBase(IntuitionBase
)->WorkBench
;
104 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: current wbscreen 0x%lx\n",
107 /* Try to close the Workbench screen, if there is any. */
108 if( wbscreen
!= NULL
)
110 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen\n"));
111 if (CloseScreen(wbscreen
))
113 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen worked\n"));
114 GetPrivIBase(IntuitionBase
)->WorkBench
= NULL
;
120 /* Grrr ... closing screen failed. I inc psn_VisitorCount by hand here,
121 * to avoid that someone else can kill it, because I must tell Workbench
122 * task that it shall open its windows again
125 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen failed\n"));
126 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
++;
135 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
136 UnlockPubScreenList();
137 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
139 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: wbscreen 0x%lx retval %ld\n",
142 if (wbscreen
&& !retval
)
144 /* Don't call this function while pub screen list is locked! */
145 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to reopen windows\n"));
146 TellWBTaskToOpenWindows(IntuitionBase
);
148 /* Fix psn_VisitorCount which was increased above */
149 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
151 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
152 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: WBScreen's pubnode 0x%lx\n",
153 (ULONG
) GetPrivScreen(wbscreen
)->pubScrNode
));
154 GetPrivScreen(wbscreen
)->pubScrNode
->psn_VisitorCount
--;
155 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
156 UnlockPubScreenList();
157 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
160 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Return %d\n", retval
));
164 /* Workbench screen failed to close, notify that the screen is open again */
165 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_OPENWB
, IntuitionBase
);
169 FireScreenNotifyMessage((IPTR
) wbscreen
, SNOTIFY_AFTER_CLOSEWB
, IntuitionBase
);
176 } /* CloseWorkBench */