From 3117b20bcbfbed588ede9b29a7f90eafc762b138 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 4 Jun 2011 22:10:31 +0800 Subject: [PATCH] AxWin2 - Fiddling, almost ready for testing :) --- Usermode/Applications/axwin2_src/WM/common.h | 3 + .../Applications/axwin2_src/WM/messages.c | 17 +++--- Usermode/Applications/axwin2_src/WM/wm.c | 61 ++++++++++++++++++- Usermode/Applications/axwin2_src/WM/wm.h | 31 +++------- Usermode/include/axwin2/axwin.h | 2 + Usermode/include/axwin2/messages.h | 11 +++- 6 files changed, 89 insertions(+), 36 deletions(-) diff --git a/Usermode/Applications/axwin2_src/WM/common.h b/Usermode/Applications/axwin2_src/WM/common.h index bc140bb7..00c84538 100644 --- a/Usermode/Applications/axwin2_src/WM/common.h +++ b/Usermode/Applications/axwin2_src/WM/common.h @@ -75,6 +75,9 @@ extern void IPC_FillSelect(int *nfds, fd_set *set); extern void IPC_HandleSelect(fd_set *set); extern void Input_FillSelect(int *nfds, fd_set *set); extern void Input_HandleSelect(fd_set *set); +// --- Local WM --- +extern tApplication *AxWin_RegisterClient(int IdentLen, void *Ident, tMessages_Handle_Callback *Cb, const char *Name); +extern void AxWin_DeregisterClient(tApplication *App); // --- Video --- extern void Video_Setup(void); extern void Video_Update(void); diff --git a/Usermode/Applications/axwin2_src/WM/messages.c b/Usermode/Applications/axwin2_src/WM/messages.c index f4aa3142..61ffc530 100644 --- a/Usermode/Applications/axwin2_src/WM/messages.c +++ b/Usermode/Applications/axwin2_src/WM/messages.c @@ -20,7 +20,7 @@ void IPC_FillSelect(int *nfds, fd_set *set); void IPC_HandleSelect(fd_set *set); void Messages_RespondDatagram(void *Ident, size_t Length, void *Data); void Messages_RespondIPC(void *Ident, size_t Length, void *Data); -void Messages_Handle(void *Ident, size_t MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond); +void Messages_Handle(size_t IdentLen, void *Ident, size_t MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond); // === GLOBALS === int giNetworkFileHandle = -1; @@ -33,9 +33,6 @@ void IPC_Init(void) // TODO: Check this giNetworkFileHandle = open("/Devices/ip/loop/udp", OPENFLAG_READ); tmp = AXWIN_PORT; ioctl(giNetworkFileHandle, 4, &tmp); // TODO: Don't hard-code IOCtl number - - // TODO: Open a handle to something like /Devices/proc/cur/messages to watch for messages -// giMessagesFileHandle = open("/Devices/" } void IPC_FillSelect(int *nfds, fd_set *set) @@ -58,7 +55,7 @@ void IPC_HandleSelect(fd_set *set) identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] ); msg = staticBuf + identlen; - Messages_Handle(staticBuf, readlen - identlen, (void*)msg, Messages_RespondDatagram); + Messages_Handle(identlen, staticBuf, readlen - identlen, (void*)msg, Messages_RespondDatagram); } while(SysGetMessage(NULL, NULL)) @@ -68,7 +65,7 @@ void IPC_HandleSelect(fd_set *set) char data[len]; SysGetMessage(NULL, data); - Messages_Handle(&tid, len, (void*)data, Messages_RespondIPC); + Messages_Handle(sizeof(tid), &tid, len, (void*)data, Messages_RespondIPC); } } @@ -87,7 +84,7 @@ void Messages_RespondIPC(void *Ident, size_t Length, void *Data) SysSendMessage( *(tid_t*)Ident, Length, Data ); } -void Messages_Handle(void *Ident, size_t MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond) +void Messages_Handle(size_t IdentLen, void *Ident, size_t MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond) { if( MsgLen < sizeof(tAxWin_Message) ) return ; @@ -107,11 +104,13 @@ void Messages_Handle(void *Ident, size_t MsgLen, tAxWin_Message *Msg, tMessages_ break; case MSG_SREQ_REGISTER: - if( Msg->Len == strnlen(Msg->Len, Msg->Data) ) { - // Special handling? + if( Msg->Data[Msg->Size-1] != '\0' ) { + // Invalid message return ; } + AxWin_RegisterClient(IdentLen, Ident, Respond, Msg->Data); + break; default: diff --git a/Usermode/Applications/axwin2_src/WM/wm.c b/Usermode/Applications/axwin2_src/WM/wm.c index ea803051..fd0f0562 100644 --- a/Usermode/Applications/axwin2_src/WM/wm.c +++ b/Usermode/Applications/axwin2_src/WM/wm.c @@ -37,6 +37,7 @@ tApplication *gWM_Applications; // --- Element type flags struct { void (*Init)(tElement *This); + void (*Delete)(tElement *This); void (*UpdateFlags)(tElement *This); void (*UpdateSize)(tElement *This); void (*UpdateText)(tElement *This); @@ -44,8 +45,54 @@ struct { {NULL, NULL, NULL, NULL}, // NULL {NULL, NULL, NULL, NULL} // Box }; +const int ciWM_NumWidgetTypes = sizeof(gaWM_WidgetTypes)/sizeof(gaWM_WidgetTypes[0]); // === CODE === +tApplication *AxWin_RegisterClient(int IdentLen, void *Ident, tMessages_Handle_Callback *Cb, const char *Name) +{ + tApplication *ret = calloc( 1, sizeof(tApplication) + 1 + strlen(Name) + 1 + IdentLen ); + + ret->Name = &ret->MetaElement.DebugName[1]; + strcpy(ret->Name, Name); + ret->Ident = ret->Name + strlen(Name) + 1; + memcpy(ret->Ident, Ident, IdentLen); + ret->SendMessage = Cb; + + ret->Next = gWM_Applications; + gWM_Applications = ret; + + // TODO: Inform listeners of the new application + + return ret; +} + +void AxWin_DeregisterClient(tApplication *App) +{ + tElement *win, *next; + // TODO: Implement DeregisterClient + + for( win = App->MetaElement.FirstChild; win; win = next ) + { + next = win->NextSibling; + AxWin_DeleteElement(win); + } + + // TODO: Inform listeners of deleted application + // TODO: Remove from list + free(App); +} + +tElement *AxWin_CreateWindow(tApplication *App, const char *Name) +{ + tElement *ret; + + // TODO: Implement _CreateTab + + ret = AxWin_CreateElement(&App->MetaElement, ELETYPE_WINDOW, 0, NULL); + ret->Text = strdup(Name); + return ret; +} + // --- Widget Creation and Control --- tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName) { @@ -73,7 +120,7 @@ tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const ret->PaddingT = 2; ret->PaddingB = 2; - if( gaWM_WidgetTypes[Type].Init ) + if( Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Type].Init ) gaWM_WidgetTypes[Type].Init(ret); WM_UpdateMinDims(ret->Parent); @@ -86,7 +133,19 @@ tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const */ void AxWin_DeleteElement(tElement *Element) { + tElement *child, *next; + + for(child = Element->FirstChild; child; child = next) + { + next = child->NextSibling; + AxWin_DeleteElement(child); + } + // TODO: Implement AxWin_DeleteElement + // TODO: Clean up related data. + if( Element->Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Element->Type].Delete ) + gaWM_WidgetTypes[Element->Type].Delete(Element); + free(Element); } diff --git a/Usermode/Applications/axwin2_src/WM/wm.h b/Usermode/Applications/axwin2_src/WM/wm.h index 8de9e206..28372513 100644 --- a/Usermode/Applications/axwin2_src/WM/wm.h +++ b/Usermode/Applications/axwin2_src/WM/wm.h @@ -19,11 +19,14 @@ struct sAxWin_Element tElement *FirstChild; tElement *LastChild; tElement *NextSibling; - + + // User modifiable attributes short PaddingL, PaddingR; short PaddingT, PaddingB; short GapSize; + uint32_t Flags; + short FixedWith; // Fixed Long Size attribute (height) short FixedCross; // Fixed Cross Size attribute (width) @@ -35,8 +38,6 @@ struct sAxWin_Element short MinCross; // Minimum cross size void *Data; - uint32_t Flags; - // -- Render Cache short CachedX, CachedY; short CachedW, CachedH; @@ -44,32 +45,16 @@ struct sAxWin_Element char DebugName[]; }; -struct sTab -{ - int Type; // Should be zero, allows a tab to be the parent of an element - - tElement *Parent; - tElement *FirstChild; - tElement *LastChild; - tTab *NextTab; - - char *Name; - - tElement *RootElement; -}; - struct sApplication { - tApplication *Next; + tApplication *Next; void *Ident; tMessages_Handle_Callback *SendMessage; - int nTabs; - tTab *Tabs; - tTab *CurrentTab; - - char Name[]; + char *Name; + tElement MetaElement; + }; #endif diff --git a/Usermode/include/axwin2/axwin.h b/Usermode/include/axwin2/axwin.h index 1455c83e..5ef6ed82 100644 --- a/Usermode/include/axwin2/axwin.h +++ b/Usermode/include/axwin2/axwin.h @@ -107,6 +107,8 @@ enum eElementFlags enum eElementTypes { ELETYPE_NONE, + + ELETYPE_WINDOW, ELETYPE_BOX, //!< Content box (invisible in itself) ELETYPE_TABBAR, //!< Tab Bar diff --git a/Usermode/include/axwin2/messages.h b/Usermode/include/axwin2/messages.h index 713f0114..d944f515 100644 --- a/Usermode/include/axwin2/messages.h +++ b/Usermode/include/axwin2/messages.h @@ -27,10 +27,10 @@ enum eAxWin_Messages // - Windows MSG_SREQ_REGISTER, // bool (char[] Name) - Registers this PID with the Window Manager - MSG_SREQ_ADDTAB, // TAB (char[] Name) - Adds a tab to the window - MSG_SREQ_DELTAB, // void (TAB Tab) - Closes a tab + MSG_SREQ_ADDWIN, // ELEMENT (char[] Name) - Adds a tab to the window + MSG_SREQ_DELWIN, // void (ELEMENT Tab) - Closes a tab - MSG_SREQ_SETICON // void (TAB Tab, char[] IconURI) - Set the icon of a tab (or application) + MSG_SREQ_SETICON, // void (TAB Tab, char[] IconURI) - Set the icon of a tab (or application) MSG_SREQ_NEWDIALOG, // DIALOG (TAB Parent, char[] Name) - Creates a dialog MSG_SREQ_DELDIALOG, // void (DIALOG Dialog) - Closes a dialog @@ -50,6 +50,11 @@ enum eAxWin_Messages MSG_SREQ_RECT, MSG_SREQ_FILLRECT, MSG_SREQ_RIMG, MSG_SREQ_SIMG, // Register/Set Image MSG_SREQ_SETFONT, MSG_SREQ_PUTTEXT, + + // - Callback Registration + + // - WM Control + MSG_SREQ_SET_MAXIMIZE_AREA, // void (uint16_t X, Y, W, H) // Server->Client Responses MSG_SRSP_VERSION, -- 2.20.1