config: extract optimization and isa flags to separate variables
[AROS.git] / rom / intuition / closeworkbench.c
bloba0aef5bfde681b253a21bf6b13be3f564ce39e2a
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include "intuition_intern.h"
9 #include <intuition/intuition.h>
10 #include <proto/intuition.h>
12 /*****************************************************************************
14 NAME */
15 AROS_LH0(LONG, CloseWorkBench,
17 /* SYNOPSIS */
19 /* LOCATION */
20 struct IntuitionBase *, IntuitionBase, 13, Intuition)
22 /* FUNCTION
23 Attempt to close the Workbench screen. This will fail if there are any
24 non-Drawer windows open on it.
26 INPUTS
28 RESULT
29 success - TRUE if Workbench screen could be closed.
31 NOTES
32 If the Workbench screen is already closed when this function is called,
33 FALSE is returned.
35 EXAMPLE
37 BUGS
39 SEE ALSO
40 OpenWorkBench()
42 INTERNALS
44 *****************************************************************************/
46 AROS_LIBFUNC_INIT
48 struct Screen *wbscreen;
49 BOOL retval = TRUE;
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"));
60 LockPubScreenList();
61 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
63 if (!wbscreen)
65 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: no wbscreen, do nothing\n"));
66 UnlockPubScreenList();
68 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
70 return(FALSE);
72 else
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));
80 retval = FALSE;
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"));
96 LockPubScreenList();
97 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
99 wbscreen = GetPrivIBase(IntuitionBase)->WorkBench;
101 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: current wbscreen 0x%lx\n",
102 (ULONG) wbscreen));
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;
112 wbscreen = NULL;
113 retval = TRUE;
115 else
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++;
124 retval = FALSE;
127 else
129 retval = FALSE;
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",
137 (ULONG) wbscreen,
138 (ULONG) retval));
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"));
147 LockPubScreenList();
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));
159 if (!retval)
161 /* Workbench screen failed to close, notify that the screen is open again */
162 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
164 else
166 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_CLOSEWB, IntuitionBase);
169 return retval;
171 AROS_LIBFUNC_EXIT
173 } /* CloseWorkBench */