Copyright clean-up (part 1):
[AROS.git] / test / intuition / pubscreen.c
blob53c10892884fee4ccad1cbbadd2498fe8f706f35
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 // Opens a PubScreen. The name can be given as argument.
7 // Default name is "MYPUBSCREEN".
9 #include <proto/intuition.h>
10 #include <proto/dos.h>
11 #include <proto/exec.h>
13 #include <stdlib.h>
14 #include <stdio.h>
16 struct Screen *myscreen;
17 struct Window *mywindow;
18 BYTE signalnum;
20 void clean_exit(STRPTR txt)
22 if (mywindow) CloseWindow(mywindow);
23 if (myscreen) CloseScreen(myscreen);
24 FreeSignal(signalnum);
26 if (txt)
28 PutStr(txt);
29 exit(RETURN_FAIL);
31 exit(RETURN_OK);
34 int main(int argc, char **argv)
36 BOOL done = FALSE;
37 BOOL closewindow = FALSE;
38 ULONG signals, winsig, pubsig;
39 struct IntuiMessage *message;
40 char *name;
42 if (argc == 2)
44 name = argv[1];
46 else
48 name = "MYPUBSCREEN";
51 if ((signalnum = AllocSignal(-1)) == -1)
53 clean_exit("Can't allocate signal\n");
59 myscreen = OpenScreenTags
61 NULL,
62 SA_PubName, name,
63 SA_PubSig, signalnum,
64 SA_LikeWorkbench, TRUE,
65 SA_Title, name,
66 TAG_DONE
68 ) == NULL
71 clean_exit("Can't open screen\n");
77 mywindow = OpenWindowTags
79 NULL,
80 WA_Left, 30,
81 WA_Top, 30,
82 WA_Width, 250,
83 WA_Height, 100,
84 WA_DragBar, TRUE,
85 WA_DepthGadget, TRUE,
86 WA_CloseGadget, TRUE,
87 WA_Activate, TRUE,
88 WA_Title, "Close me to close the screen",
89 WA_IDCMP, IDCMP_CLOSEWINDOW,
90 WA_PubScreen, myscreen,
91 TAG_DONE
93 ) == NULL
96 clean_exit("Can't open window\n");
99 if ((PubScreenStatus(myscreen, 0) & 1) == 0)
101 clean_exit("Can't make screen public");
104 winsig = 1L << mywindow->UserPort->mp_SigBit;
105 pubsig = 1L << signalnum;
107 while (!done)
109 signals = Wait(winsig | pubsig);
111 if (mywindow && (signals & winsig))
113 while (NULL != (message = (struct IntuiMessage *)GetMsg(mywindow->UserPort)))
115 if (message->Class == IDCMP_CLOSEWINDOW)
117 closewindow = TRUE;
119 ReplyMsg((struct Message *)message);
122 if (signals & pubsig)
124 if (PubScreenStatus(myscreen, PSNF_PRIVATE) & 1)
126 done = TRUE;
128 else
130 PutStr("Failed to make screen private\n");
134 if (closewindow)
136 if (mywindow) CloseWindow(mywindow);
137 winsig = 0;
138 mywindow = NULL;
139 closewindow = FALSE;
143 clean_exit(NULL);
144 return 0;