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;
76 gpWM_RootWindow = ret;
83 tWindow *WM_CreateWindowStruct(size_t ExtraSize)
87 ret = calloc( sizeof(tWindow) + ExtraSize, 1 );
88 ret->RendererInfo = ret + 1; // Get end of tWindow
93 void WM_ShowWindow(tWindow *Window, int bShow)
95 // TODO: Message window
97 Window->Flags |= WINFLAG_SHOW;
99 Window->Flags &= ~WINFLAG_SHOW;
100 WM_Invalidate(Window);
103 int WM_MoveWindow(tWindow *Window, int X, int Y)
106 if(X + Window->W < 0) X = -Window->W + 1;
107 if(Y + Window->H < 0) Y = -Window->H + 1;
108 if(X >= giScreenWidth) X = giScreenWidth - 1;
109 if(Y >= giScreenHeight) Y = giScreenHeight - 1;
111 Window->X = X; Window->Y = Y;
113 WM_Invalidate(Window);
118 int WM_ResizeWindow(tWindow *Window, int W, int H)
120 if(W <= 0 || H <= 0 ) return 1;
121 if(Window->X + W < 0) Window->X = -W + 1;
122 if(Window->Y + H < 0) Window->Y = -H + 1;
124 Window->W = W; Window->H = H;
126 WM_Invalidate(Window);
129 struct sWndMsg_Resize msg;
132 WM_SendMessage(NULL, Window, WNDMSG_RESIZE, sizeof(msg), &msg);
138 int WM_SendMessage(tWindow *Source, tWindow *Dest, int Message, int Length, void *Data)
140 if(Dest == NULL) return -2;
141 if(Length > 0 && Data == NULL) return -1;
143 // ->HandleMessage returns 1 when the message was not handled
144 if( Dest->Renderer->HandleMessage(Dest, Message, Length, Data) != 1 )
146 // TODO: Catch errors from ->HandleMessage
150 // TODO: Implement message masking
157 else if(Source->Client != Dest->Client) {
158 // TODO: Support different client source windows
159 _SysDebug("WM_SendMessage: TODO - Support inter-client messages");
166 IPC_SendWMMessage(Dest->Client, src_id, Dest->ID, Message, Length, Data);
172 void WM_Invalidate(tWindow *Window)
174 _SysDebug("Invalidating %p", Window);
175 // Don't invalidate twice (speedup)
176 // if( !(Window->Flags & WINFLAG_CLEAN) ) return;
178 // Mark for re-render
179 Window->Flags &= ~WINFLAG_CLEAN;
181 // Mark up the tree that a child window has changed
182 while( (Window = Window->Parent) )
183 Window->Flags &= ~WINFLAG_CHILDCLEAN;
186 // --- Rendering / Update
187 void WM_int_UpdateWindow(tWindow *Window)
191 // Ignore hidden windows
192 if( !(Window->Flags & WINFLAG_SHOW) )
196 if( !(Window->Flags & WINFLAG_CLEAN) )
198 Window->Renderer->Redraw(Window);
199 Window->Flags |= WINFLAG_CLEAN;
203 if( !(Window->Flags & WINFLAG_CHILDCLEAN) )
205 for( child = Window->FirstChild; child; child = child->NextSibling )
207 WM_int_UpdateWindow(child);
209 Window->Flags |= WINFLAG_CHILDCLEAN;
214 void WM_int_BlitWindow(tWindow *Window)
218 // Ignore hidden windows
219 if( !(Window->Flags & WINFLAG_SHOW) )
222 _SysDebug("Blit %p to (%i,%i) %ix%i", Window, Window->X, Window->Y, Window->W, Window->H);
223 Video_Blit(Window->RenderBuffer, Window->X, Window->Y, Window->W, Window->H);
225 for( child = Window->FirstChild; child; child = child->NextSibling )
227 WM_int_BlitWindow(child);
233 // Don't redraw if nothing has changed
234 if( (gpWM_RootWindow->Flags & WINFLAG_CHILDCLEAN) )
237 // - Iterate through visible windows, updating them as needed
238 WM_int_UpdateWindow(gpWM_RootWindow);
240 // - Draw windows from back to front to the render buffer
241 WM_int_BlitWindow(gpWM_RootWindow);