2 * Acess2 Window Manager v3
3 * - By John Hodge (thePowersGang)
6 * - Window manager core
9 #include <wm_renderer.h>
13 #include <wm_messages.h>
16 extern void IPC_SendWMMessage(tIPC_Client *Client, uint32_t Src, uint32_t Dst, int Msg, int Len, void *Data);
19 tWMRenderer *gpWM_Renderers;
20 tWindow *gpWM_RootWindow;
23 void WM_Initialise(void)
25 WM_CreateWindow(NULL, NULL, 0, 0x0088FF, "Background");
26 gpWM_RootWindow->W = giScreenWidth;
27 gpWM_RootWindow->H = giScreenHeight;
28 gpWM_RootWindow->Flags = WINFLAG_SHOW;
31 void WM_RegisterRenderer(tWMRenderer *Renderer)
33 // TODO: Catch out duplicates
34 Renderer->Next = gpWM_Renderers;
35 gpWM_Renderers = Renderer;
39 tWindow *WM_CreateWindow(tWindow *Parent, tIPC_Client *Client, uint32_t ID, int RendererArg, const char *RendererName)
41 tWMRenderer *renderer;
45 for( renderer = gpWM_Renderers; renderer; renderer = renderer->Next )
47 if(strcmp(RendererName, renderer->Name) == 0)
54 Parent = gpWM_RootWindow;
56 // - Call create window function
57 ret = renderer->CreateWindow(RendererArg);
61 ret->Renderer = renderer;
62 ret->Flags = WINFLAG_CLEAN; // Needed to stop invaildate early exiting
68 Parent->LastChild->NextSibling = ret;
70 Parent->FirstChild = ret;
71 ret->PrevSibling = Parent->LastChild;
72 Parent->LastChild = ret;
73 ret->NextSibling = NULL;
77 gpWM_RootWindow = ret;
84 tWindow *WM_CreateWindowStruct(size_t ExtraSize)
88 ret = calloc( sizeof(tWindow) + ExtraSize, 1 );
89 ret->RendererInfo = ret + 1; // Get end of tWindow
94 void WM_RaiseWindow(tWindow *Window)
96 tWindow *parent = Window->Parent;
97 if(!Window->Parent) return ;
100 if(Window->PrevSibling)
101 Window->PrevSibling->NextSibling = Window->NextSibling;
102 if(Window->NextSibling)
103 Window->NextSibling->PrevSibling = Window->PrevSibling;
104 if(parent->FirstChild == Window)
105 parent->FirstChild = Window->NextSibling;
106 if(parent->LastChild == Window)
107 parent->LastChild = Window->PrevSibling;
110 if(parent->LastChild)
111 parent->LastChild->NextSibling = Window;
113 parent->FirstChild = Window;
114 Window->PrevSibling = parent->LastChild;
115 Window->NextSibling = NULL;
116 parent->LastChild = Window;
119 void WM_ShowWindow(tWindow *Window, int bShow)
122 struct sWndMsg_Bool _msg;
125 WM_SendMessage(NULL, Window, WNDMSG_SHOW, sizeof(_msg), &_msg);
128 Window->Flags |= WINFLAG_SHOW;
130 Window->Flags &= ~WINFLAG_SHOW;
131 WM_Invalidate(Window);
134 int WM_MoveWindow(tWindow *Window, int X, int Y)
137 if(X + Window->W < 0) X = -Window->W + 1;
138 if(Y + Window->H < 0) Y = -Window->H + 1;
139 if(X >= giScreenWidth) X = giScreenWidth - 1;
140 if(Y >= giScreenHeight) Y = giScreenHeight - 1;
142 Window->X = X; Window->Y = Y;
144 WM_Invalidate(Window);
149 int WM_ResizeWindow(tWindow *Window, int W, int H)
151 if(W <= 0 || H <= 0 ) return 1;
152 if(Window->X + W < 0) Window->X = -W + 1;
153 if(Window->Y + H < 0) Window->Y = -H + 1;
155 Window->W = W; Window->H = H;
157 WM_Invalidate(Window);
160 struct sWndMsg_Resize msg;
163 WM_SendMessage(NULL, Window, WNDMSG_RESIZE, sizeof(msg), &msg);
169 int WM_SendMessage(tWindow *Source, tWindow *Dest, int Message, int Length, void *Data)
171 if(Dest == NULL) return -2;
172 if(Length > 0 && Data == NULL) return -1;
174 // ->HandleMessage returns 1 when the message was not handled
175 if( Dest->Renderer->HandleMessage(Dest, Message, Length, Data) != 1 )
177 // TODO: Catch errors from ->HandleMessage
181 // TODO: Implement message masking
188 else if(Source->Client != Dest->Client) {
189 // TODO: Support different client source windows
190 _SysDebug("WM_SendMessage: TODO - Support inter-client messages");
197 IPC_SendWMMessage(Dest->Client, src_id, Dest->ID, Message, Length, Data);
203 void WM_Invalidate(tWindow *Window)
205 _SysDebug("Invalidating %p", Window);
206 // Don't invalidate twice (speedup)
207 // if( !(Window->Flags & WINFLAG_CLEAN) ) return;
209 // Mark for re-render
210 Window->Flags &= ~WINFLAG_CLEAN;
212 // Mark up the tree that a child window has changed
213 while( (Window = Window->Parent) )
214 Window->Flags &= ~WINFLAG_CHILDCLEAN;
217 // --- Rendering / Update
218 void WM_int_UpdateWindow(tWindow *Window)
222 // Ignore hidden windows
223 if( !(Window->Flags & WINFLAG_SHOW) )
227 if( !(Window->Flags & WINFLAG_CLEAN) )
229 Window->Renderer->Redraw(Window);
230 Window->Flags |= WINFLAG_CLEAN;
234 if( !(Window->Flags & WINFLAG_CHILDCLEAN) )
236 for( child = Window->FirstChild; child; child = child->NextSibling )
238 WM_int_UpdateWindow(child);
240 Window->Flags |= WINFLAG_CHILDCLEAN;
245 void WM_int_BlitWindow(tWindow *Window)
249 // Ignore hidden windows
250 if( !(Window->Flags & WINFLAG_SHOW) )
253 _SysDebug("Blit %p to (%i,%i) %ix%i", Window, Window->X, Window->Y, Window->W, Window->H);
254 Video_Blit(Window->RenderBuffer, Window->X, Window->Y, Window->W, Window->H);
256 for( child = Window->FirstChild; child; child = child->NextSibling )
258 WM_int_BlitWindow(child);
264 // Don't redraw if nothing has changed
265 if( (gpWM_RootWindow->Flags & WINFLAG_CHILDCLEAN) )
268 // - Iterate through visible windows, updating them as needed
269 WM_int_UpdateWindow(gpWM_RootWindow);
271 // - Draw windows from back to front to the render buffer
272 WM_int_BlitWindow(gpWM_RootWindow);