Forgotten commit. Added automount.
[AROS.git] / arch / .unmaintained / hidd / activescreen.c
blob84b50f1437fe8350bb5f0fceb91984158ca86cab
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/intuition.h>
8 #include <proto/arossupport.h>
9 #include <proto/alib.h>
11 #include <exec/memory.h>
12 #include <exec/tasks.h>
13 #include <exec/ports.h>
15 #include <dos/dos.h>
17 #include "macros.h"
19 // #include <oop/oop.h>
21 /* Hack: prevent hidd/graphics.h from beeing included */
22 // #include "graphics_internal.h"
25 VOID activescreen_taskentry();
27 struct activescreen_msg {
28 struct Message message;
29 OOP_Object *bmobj;
33 static struct Task *activescreen_task = NULL;
34 static struct Task *parent_task = NULL;
35 static struct MsgPort *activescreen_msgport = NULL;
37 static ULONG oksig = SIGBREAKF_CTRL_E;
38 static ULONG failsig = SIGBREAKF_CTRL_D;
39 static ULONG killsig = SIGBREAKF_CTRL_C;
41 static struct ExecBase *sysbase = NULL;
44 static BOOL send_activescreen_msg( Object *bmobj, struct ExecBase *SysBase)
46 /* Allocate a new message */
47 struct activescreen_msg *msg;
49 msg = AllocMem(sizeof (*msg), MEMF_PUBLIC | MEMF_CLEAR);
50 if (NULL == msg)
51 return FALSE;
53 msg->bmobj = bmobj;
54 PutMsg(activescreen_msgport, (struct Message *)msg);
56 return TRUE;
60 VOID activatebm_callback(APTR data, OOP_Object *bmobj, BOOL activated)
63 struct GfxBase *GfxBase;
65 GfxBase = (struct GfxBase *)data;
67 if (!activated)
68 return;
70 /* We must send it to some task that can handle this.
71 We should NOT use LockIBase() inside here, since we might
72 have locked layers also. So we instead send it to some othe task
75 if (!send_activescreen_msg(bmobj, SysBase)) {
76 kprintf("!!! activatebm_callback: Could not send activatescreen message !!!!\n");
79 return;
83 BOOL init_activescreen_stuff(struct GfxBase *GfxBase)
86 BOOL ok = FALSE;
87 sysbase = SysBase;
89 kprintf("init_activescreen_stuff\n");
91 parent_task = FindTask(NULL);
93 /* Create the task */
94 activescreen_task = CreateTask("Active screen updating task"
95 , 40
96 , activescreen_taskentry
97 , 4096
100 if (NULL != activescreen_task) {
101 ULONG sigs;
103 kprintf("Task created\n");
105 sigs = Wait(oksig | failsig);
106 kprintf("Got sig: %d\n", sigs);
107 if (sigs & oksig) {
108 ok = TRUE;
112 return ok;
116 VOID cleanup_activescreen_stuff(struct GfxBase *GfxBase)
118 /* Kill the task. Note that this
119 may cause race condition problems
120 if some task continues to send messages to the task
122 Signal(activescreen_task, killsig);
126 #undef SysBase
127 #define SysBase sysbase
129 VOID activescreen_taskentry()
131 /* Create the msg port */
132 struct IntuitionBase *IntuitionBase = NULL;
133 BOOL ok = FALSE;
135 activescreen_msgport = CreateMsgPort();
136 if (NULL != activescreen_msgport) {
137 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
138 if (NULL != IntuitionBase) {
139 ok = TRUE;
140 } else {
141 kprintf("activescreen_task: Could not open intuition\n");
143 } else {
144 kprintf("activescreen_task: Could not create msgport\n");
147 if (!ok) {
148 /* Signal failure to the creating task */
149 Signal(parent_task, failsig);
151 } else {
152 ULONG portsig;
153 BOOL done = FALSE;
155 Signal(parent_task, oksig);
157 portsig = 1L << activescreen_msgport->mp_SigBit;
159 /* Go into endeless loop handling the messages */
160 while (!done) {
162 struct activescreen_msg *msg;
164 ULONG sigs;
166 if ((msg = (struct activescreen_msg *)GetMsg(activescreen_msgport))) {
167 struct Screen *scr;
169 /* Handle the message. Go through the screen list
170 and find the screen that uses the supplied HIDD bitmap
171 object
173 LockIBase(0UL);
175 for (scr = IntuitionBase->FirstScreen; NULL != scr; scr = scr->NextScreen) {
177 /* Get the hidd object */
178 if (msg->bmobj == HIDD_BM_OBJ(scr->RastPort.BitMap)) {
180 kprintf("Active screen found: %s\n", scr->Title);
182 IntuitionBase->ActiveScreen = scr;
187 UnlockIBase(0UL);
189 /* We do not reply the message, but instead free it here. */
190 FreeMem(msg, sizeof (*msg));
192 } else {
193 sigs = Wait(portsig | killsig);
195 if (sigs & killsig) {
196 /* Get outstanding messages */
197 while ((msg = (struct activescreen_msg *)GetMsg(activescreen_msgport)))
198 FreeMem(msg, sizeof (*msg));
199 done = TRUE;
202 } /* while */
204 } /* if (ok) */
206 if (NULL != IntuitionBase)
207 CloseLibrary((struct Library *)IntuitionBase);
209 if (NULL != activescreen_msgport)
210 DeleteMsgPort(activescreen_msgport);