From 2f786d7164faa96acf47281debc2b458318701d0 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 8 Nov 2011 13:52:26 +0800 Subject: [PATCH] Usermode/AxWin3 - Implemented passing messages to the client --- .../Applications/axwin3_src/WM/include/wm.h | 3 +- .../axwin3_src/WM/include/wm_internals.h | 4 +- Usermode/Applications/axwin3_src/WM/ipc.c | 28 ++++++++++++-- Usermode/Applications/axwin3_src/WM/wm.c | 38 +++++++++++++------ .../axwin3_src/include/ipcmessages.h | 2 +- .../axwin3_src/libaxwin3.so_src/wm.c | 2 +- 6 files changed, 59 insertions(+), 18 deletions(-) diff --git a/Usermode/Applications/axwin3_src/WM/include/wm.h b/Usermode/Applications/axwin3_src/WM/include/wm.h index 19994ae5..86008be6 100644 --- a/Usermode/Applications/axwin3_src/WM/include/wm.h +++ b/Usermode/Applications/axwin3_src/WM/include/wm.h @@ -33,10 +33,11 @@ typedef struct sWindow tWindow; typedef struct sWMRenderer tWMRenderer; typedef uint32_t tColour; typedef struct sFont tFont; +typedef struct sIPC_Client tIPC_Client; // === FUNCTIONS === // --- Management -extern tWindow *WM_CreateWindow(tWindow *Parent, int Flags, const char *Renderer); +extern tWindow *WM_CreateWindow(tWindow *Parent, tIPC_Client *Client, uint32_t ID, int Flags, const char *Renderer); extern void WM_Invalidate(tWindow *Window); extern void WM_ShowWindow(tWindow *Window, int bShow); extern int WM_ResizeWindow(tWindow *Window, int W, int H); diff --git a/Usermode/Applications/axwin3_src/WM/include/wm_internals.h b/Usermode/Applications/axwin3_src/WM/include/wm_internals.h index aada7203..ea0826c2 100644 --- a/Usermode/Applications/axwin3_src/WM/include/wm_internals.h +++ b/Usermode/Applications/axwin3_src/WM/include/wm_internals.h @@ -19,7 +19,9 @@ struct sWindow tWindow *FirstChild; tWindow *LastChild; - + + tIPC_Client *Client; + uint32_t ID; //!< Client assigned ID tWMRenderer *Renderer; int Flags; diff --git a/Usermode/Applications/axwin3_src/WM/ipc.c b/Usermode/Applications/axwin3_src/WM/ipc.c index 22482af4..a21c7835 100644 --- a/Usermode/Applications/axwin3_src/WM/ipc.c +++ b/Usermode/Applications/axwin3_src/WM/ipc.c @@ -20,7 +20,6 @@ // === TYPES === typedef struct sIPC_Type tIPC_Type; -typedef struct sIPC_Client tIPC_Client; struct sIPC_Type { @@ -270,7 +269,7 @@ int IPC_Msg_SendMsg(tIPC_Client *Client, tAxWin_IPCMessage *Msg) src = IPC_int_GetWindow(Client, Msg->Window); if(!src) return 1; - dest = IPC_int_GetWindow(Client, info->Dest); + dest = IPC_int_GetWindow(Client, info->Remote); if(!dest) return 1; WM_SendMessage(src, dest, info->ID, info->Length, info->Data); @@ -298,7 +297,7 @@ int IPC_Msg_CreateWin(tIPC_Client *Client, tAxWin_IPCMessage *Msg) return 1; // - Create the new window, and save its pointer - newwin = WM_CreateWindow(parent, info->RendererArg, info->Renderer); + newwin = WM_CreateWindow(parent, Client, info->NewWinID, info->RendererArg, info->Renderer); IPC_int_SetWindow(Client, info->NewWinID, newwin); return 0; @@ -401,3 +400,26 @@ void IPC_Handle(const tIPC_Type *IPCType, const void *Ident, size_t MsgLen, tAxW _SysDebug("IPC_Handle: rv = %i", rv); } +// --- Server->Client replies +void IPC_SendWMMessage(tIPC_Client *Client, uint32_t Src, uint32_t Dst, int MsgID, int Len, void *Data) +{ + tAxWin_IPCMessage *hdr; + tIPCMsg_SendMsg *msg; + char buf[sizeof(*hdr)+sizeof(*msg)+Len]; + + hdr = (void*)buf; + msg = (void*)hdr->Data; + + hdr->ID = IPCMSG_SENDMSG; + hdr->Flags = 0; + hdr->Size = sizeof(*msg) + Len; + hdr->Window = Dst; + + msg->Remote = Src; + msg->ID = MsgID; + msg->Length = Len; + memcpy(msg->Data, Data, Len); + + Client->IPCType->SendMessage(Client->Ident, sizeof(buf), buf); +} + diff --git a/Usermode/Applications/axwin3_src/WM/wm.c b/Usermode/Applications/axwin3_src/WM/wm.c index e1602296..bfa86b10 100644 --- a/Usermode/Applications/axwin3_src/WM/wm.c +++ b/Usermode/Applications/axwin3_src/WM/wm.c @@ -12,6 +12,9 @@ #include #include +// === IMPORTS === +extern void IPC_SendWMMessage(tIPC_Client *Client, uint32_t Src, uint32_t Dst, int Msg, int Len, void *Data); + // === GLOBALS === tWMRenderer *gpWM_Renderers; tWindow *gpWM_RootWindow; @@ -19,7 +22,7 @@ tWindow *gpWM_RootWindow; // === CODE === void WM_Initialise(void) { - WM_CreateWindow(NULL, 0x0088FF, "Background"); + WM_CreateWindow(NULL, NULL, 0, 0x0088FF, "Background"); gpWM_RootWindow->W = giScreenWidth; gpWM_RootWindow->H = giScreenHeight; gpWM_RootWindow->Flags = WINFLAG_SHOW; @@ -33,7 +36,7 @@ void WM_RegisterRenderer(tWMRenderer *Renderer) } // --- Manipulation -tWindow *WM_CreateWindow(tWindow *Parent, int RendererArg, const char *RendererName) +tWindow *WM_CreateWindow(tWindow *Parent, tIPC_Client *Client, uint32_t ID, int RendererArg, const char *RendererName) { tWMRenderer *renderer; tWindow *ret; @@ -52,6 +55,8 @@ tWindow *WM_CreateWindow(tWindow *Parent, int RendererArg, const char *RendererN // - Call create window function ret = renderer->CreateWindow(RendererArg); + ret->Client = Client; + ret->ID = ID; ret->Parent = Parent; ret->Renderer = renderer; ret->Flags = WINFLAG_CLEAN; // Needed to stop invaildate early exiting @@ -141,10 +146,26 @@ int WM_SendMessage(tWindow *Source, tWindow *Dest, int Message, int Length, void // TODO: Catch errors from ->HandleMessage return 0; } - - // TODO: Pass on to user - _SysDebug("WM_SendMessage: TODO - Implement sending to client application"); - + + // TODO: Implement message masking + + if(Dest->Client) + { + uint32_t src_id; + if(!Source) + src_id = -1; + else if(Source->Client != Dest->Client) { + // TODO: Support different client source windows + _SysDebug("WM_SendMessage: TODO - Support inter-client messages"); + return -1; + } + else { + src_id = Source->ID; + } + + IPC_SendWMMessage(Dest->Client, src_id, Dest->ID, Message, Length, Data); + } + return 1; } @@ -153,17 +174,12 @@ void WM_Invalidate(tWindow *Window) // Don't invalidate twice (speedup) if( !(Window->Flags & WINFLAG_CLEAN) ) return; -// _SysDebug("Invalidating %p"); - // Mark for re-render Window->Flags &= ~WINFLAG_CLEAN; // Mark up the tree that a child window has changed while( (Window = Window->Parent) ) - { -// _SysDebug("Childclean removed from %p", Window); Window->Flags &= ~WINFLAG_CHILDCLEAN; - } } // --- Rendering / Update diff --git a/Usermode/Applications/axwin3_src/include/ipcmessages.h b/Usermode/Applications/axwin3_src/include/ipcmessages.h index aa69d34c..bd2072a5 100644 --- a/Usermode/Applications/axwin3_src/include/ipcmessages.h +++ b/Usermode/Applications/axwin3_src/include/ipcmessages.h @@ -51,7 +51,7 @@ struct sIPCMsg_CreateWin struct sIPCMsg_SendMsg { - uint32_t Dest; + uint32_t Remote; // Dest/Source for Server/Client bound uint16_t ID; uint16_t Length; char Data[]; diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c index 55eec69a..8b279668 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c @@ -132,7 +132,7 @@ void AxWin3_SendMessage(tHWND Window, tHWND Destination, int Message, int Length msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SENDMSG, 0, sizeof(*info)+Length); info = (void*)msg->Data; - info->Dest = AxWin3_int_GetWindowID(Destination); + info->Remote = AxWin3_int_GetWindowID(Destination); info->ID = Message; info->Length = Length; memcpy(info->Data, Data, Length); -- 2.20.1