From: John Hodge Date: Fri, 3 Jun 2011 07:36:51 +0000 (+0800) Subject: AxWin2 - Huge changes, getting to the working point X-Git-Tag: rel0.10~88 X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=commitdiff_plain;h=ad2ec62655e1d6eb8f2b4a4684eb5d7952aea0fb AxWin2 - Huge changes, getting to the working point - Improved messaging, cleaner non-polling API --- diff --git a/Usermode/Applications/axwin2_src/Shell_src/Makefile b/Usermode/Applications/axwin2_src/Shell_src/Makefile index 761fb7d1..55744b97 100644 --- a/Usermode/Applications/axwin2_src/Shell_src/Makefile +++ b/Usermode/Applications/axwin2_src/Shell_src/Makefile @@ -2,7 +2,7 @@ -include ../../Makefile.cfg -CPPFLAGS += -I../include +CPPFLAGS += LDFLAGS += -laxwin2 DIR = Apps/AxWin/1.0 diff --git a/Usermode/Applications/axwin2_src/Shell_src/main.c b/Usermode/Applications/axwin2_src/Shell_src/main.c index 43b37fd3..2bc0becb 100644 --- a/Usermode/Applications/axwin2_src/Shell_src/main.c +++ b/Usermode/Applications/axwin2_src/Shell_src/main.c @@ -3,6 +3,8 @@ * - By John Hodge (thePowersGang) */ #include +#include +#include // === CONSTANTS === enum eTerminal_Events @@ -25,6 +27,14 @@ tAxWin_Element *geConsole; int main(int argc, char *argv[]) { tAxWin_Element *menu, *tab; + + if(argc != 1) + { + fprintf(stderr, "Usage: %s\n", argv[0]); + fprintf(stderr, "\tThis application takes no arguments\n"); + return 0; + } + AxWin_Register("Terminal", Global_HandleMessage); menu = AxWin_AddMenuItem(NULL, "File", 0); @@ -45,10 +55,18 @@ int main(int argc, char *argv[]) */ int Global_HandleMessage(tAxWin_Message *Message) { - return 0; + switch(Message->ID) + { + default: + return 0; + } } int Shell_HandleMessage(tAxWin_Message *Message) { - return 0; + switch(Message->ID) + { + default: + return 0; + } } diff --git a/Usermode/Applications/axwin2_src/WM/Makefile b/Usermode/Applications/axwin2_src/WM/Makefile index 032eb8f9..79bbe1ca 100644 --- a/Usermode/Applications/axwin2_src/WM/Makefile +++ b/Usermode/Applications/axwin2_src/WM/Makefile @@ -2,7 +2,7 @@ -include ../../Makefile.cfg -CPPFLAGS += -I../include +CPPFLAGS += DIR := Apps/AxWin/1.0 BIN := AxWinWM diff --git a/Usermode/Applications/axwin2_src/WM/commandline.c b/Usermode/Applications/axwin2_src/WM/commandline.c index df6328f0..67db5744 100644 --- a/Usermode/Applications/axwin2_src/WM/commandline.c +++ b/Usermode/Applications/axwin2_src/WM/commandline.c @@ -42,6 +42,8 @@ void ParseCommandline(int argc, char *argv[]) ShowHelp(argv[0]); exit(EXIT_SUCCESS); break; + default: + break; } } } diff --git a/Usermode/Applications/axwin2_src/WM/common.h b/Usermode/Applications/axwin2_src/WM/common.h index ff60f8c6..bc140bb7 100644 --- a/Usermode/Applications/axwin2_src/WM/common.h +++ b/Usermode/Applications/axwin2_src/WM/common.h @@ -8,18 +8,20 @@ #include #include #include +#include // _SysDebug + +typedef void tMessages_Handle_Callback(void*, size_t, void*); +typedef struct sFont tFont; #include "wm.h" #include "image.h" //#include "font.h" -typedef struct sFont tFont; - // === MACROS === static inline uint32_t Video_AlphaBlend(uint32_t _orig, uint32_t _new, uint8_t _alpha) { - int ao,ro,go,bo; - int an,rn,gn,bn; + uint16_t ao,ro,go,bo; + uint16_t an,rn,gn,bn; if( _alpha == 0 ) return _orig; if( _alpha == 255 ) return _new; @@ -54,8 +56,8 @@ static inline uint32_t Video_AlphaBlend(uint32_t _orig, uint32_t _new, uint8_t _ } // === GLOBALS === -extern char *gsTerminalDevice; -extern char *gsMouseDevice; +extern const char *gsTerminalDevice; +extern const char *gsMouseDevice; extern int giScreenWidth; extern int giScreenHeight; @@ -66,12 +68,25 @@ extern int giMouseFD; // === Functions === extern void memset32(void *ptr, uint32_t val, size_t count); +// --- Initialisation --- +extern void ParseCommandline(int argc, char *argv[]); +extern void IPC_Init(void); +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); // --- Video --- +extern void Video_Setup(void); extern void Video_Update(void); extern void Video_FillRect(short X, short Y, short W, short H, uint32_t Color); extern void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color); extern int Video_DrawText(short X, short Y, short W, short H, tFont *Font, uint32_t Color, char *Text); -extern void Video_DrawImage(short X, short Y, short W, short H, tImage *Image); -// --- Debug Hack --- -extern void _SysDebug(const char *Format, ...); +extern void Video_DrawImage(short X, short Y, short W, short H, tImage *Image); +// --- Interface --- +extern void Interface_Init(void); +extern void Interface_Update(void); +extern void Interface_Render(void); +// --- Decorator --- +extern void Decorator_RenderWidget(tElement *Element); + #endif diff --git a/Usermode/Applications/axwin2_src/WM/decorator.c b/Usermode/Applications/axwin2_src/WM/decorator.c index cc74e1a1..171b5261 100644 --- a/Usermode/Applications/axwin2_src/WM/decorator.c +++ b/Usermode/Applications/axwin2_src/WM/decorator.c @@ -37,6 +37,18 @@ void Decorator_RenderWidget(tElement *Element) case ELETYPE_BOX: break; // Box is a meta-element case ELETYPE_TABBAR: // Tab Bar + Video_DrawRect( + Element->CachedX, Element->CachedY, + Element->CachedW, Element->CachedH, + BOX_BORDER + ); + Video_FillRect( + Element->CachedX+1, Element->CachedY+1, + Element->CachedW-2, Element->CachedH-2, + BOX_BGCOLOUR + ); + // Enumerate Items. + break; case ELETYPE_TOOLBAR: // Tool Bar Video_DrawRect( Element->CachedX, Element->CachedY, diff --git a/Usermode/Applications/axwin2_src/WM/interface.c b/Usermode/Applications/axwin2_src/WM/interface.c index 65632bb1..91396ee6 100644 --- a/Usermode/Applications/axwin2_src/WM/interface.c +++ b/Usermode/Applications/axwin2_src/WM/interface.c @@ -19,6 +19,15 @@ tElement *gpInterface_HeaderBar; tElement *gpInterface_TabBar; tElement *gpInterface_TabContent; const char csLogoSmall[] = "base64:///"RESOURCE_LogoSmall_sif; +tApplication *gpInterface_CurrentApp; + +typedef struct sApplicationLink tApplicationLink; + +struct sApplicationLink { + tApplication *App; + tElement *Button; + char Name[]; +}; // === CODE === /** @@ -82,13 +91,23 @@ void Interface_Init(void) void Interface_Update(void) { +// tApplication *app; +// tApplicationLink *lnk; giInterface_Width = giScreenWidth/16; AxWin_SetSize( gpInterface_Sidebar, giInterface_Width ); + + // Scan application list for changes + // - HACK for now, just directly access it +// for( app = gWM_Applications; app; app = app->Next ) +// { +// AxWin_CreateElement(); +// } + + // Update current tab list } void Interface_Render(void) { - Video_FillRect( 0, 0, giInterface_Width, giScreenHeight, diff --git a/Usermode/Applications/axwin2_src/WM/main.c b/Usermode/Applications/axwin2_src/WM/main.c index dd802963..781194a8 100644 --- a/Usermode/Applications/axwin2_src/WM/main.c +++ b/Usermode/Applications/axwin2_src/WM/main.c @@ -6,19 +6,11 @@ #include // === IMPORTS === -extern void ParseCommandline(int argc, char *argv[]); -extern void Video_Setup(void); extern void WM_Update(void); -extern void Interface_Init(void); -extern void IPC_Init(void); -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); // === GLOBALS === -char *gsTerminalDevice = NULL; -char *gsMouseDevice = NULL; +const char *gsTerminalDevice = NULL; +const char *gsMouseDevice = NULL; int giScreenWidth = 640; int giScreenHeight = 480; diff --git a/Usermode/Applications/axwin2_src/WM/messages.c b/Usermode/Applications/axwin2_src/WM/messages.c index 14718abe..f4aa3142 100644 --- a/Usermode/Applications/axwin2_src/WM/messages.c +++ b/Usermode/Applications/axwin2_src/WM/messages.c @@ -13,7 +13,6 @@ #define STATICBUF_SIZE 64 // === TYPES === -typedef void tMessages_Handle_Callback(void*, size_t, void*); // === PROTOTYPES === void IPC_Init(void); @@ -21,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, int MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond); +void Messages_Handle(void *Ident, size_t MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond); // === GLOBALS === int giNetworkFileHandle = -1; @@ -88,20 +87,33 @@ void Messages_RespondIPC(void *Ident, size_t Length, void *Data) SysSendMessage( *(tid_t*)Ident, Length, Data ); } -void Messages_Handle(void *Ident, int MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond) +void Messages_Handle(void *Ident, size_t MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond) { + if( MsgLen < sizeof(tAxWin_Message) ) + return ; + if( MsgLen < sizeof(tAxWin_Message) + Msg->Size ) + return ; + switch(Msg->ID) { - #if 0 case MSG_SREQ_PING: + if( MsgLen < sizeof(tAxWin_Message) + 4 ) return; Msg->ID = MSG_SRSP_VERSION; - Msg->Size = 2; + Msg->Size = 4; Msg->Data[0] = 0; Msg->Data[1] = 1; *(uint16_t*)&Msg->Data[2] = -1; Respond(Ident, sizeof(Msg->ID), Msg); break; - #endif + + case MSG_SREQ_REGISTER: + if( Msg->Len == strnlen(Msg->Len, Msg->Data) ) { + // Special handling? + return ; + } + + break; + default: fprintf(stderr, "WARNING: Unknown message %i (%p)\n", Msg->ID, Respond); _SysDebug("WARNING: Unknown message %i (%p)\n", Msg->ID, Respond); diff --git a/Usermode/Applications/axwin2_src/WM/video.c b/Usermode/Applications/axwin2_src/WM/video.c index 5c604256..39ba1e51 100644 --- a/Usermode/Applications/axwin2_src/WM/video.c +++ b/Usermode/Applications/axwin2_src/WM/video.c @@ -131,7 +131,8 @@ void Video_DrawImage(short X, short Y, short W, short H, tImage *Image) { int r, g, b, a; // New int or, og, ob; // Original - for( x = 0; x < W; x ++ ) { + for( x = 0; x < W; x ++ ) + { b = data[x*4+0]; g = data[x*4+1]; r = data[x*4+2]; a = data[x*4+3]; if( a == 0 ) continue; // 100% transparent ob = buf[x*4+0]; og = buf[x*4+1]; or = buf[x*4+2]; @@ -165,7 +166,8 @@ void Video_DrawImage(short X, short Y, short W, short H, tImage *Image) case IMGFMT_RGB: for( y = 0; y < H; y ++ ) { - for( x = 0; x < W; x ++ ) { + for( x = 0; x < W; x ++ ) + { buf[x*4+0] = data[x*3+2]; // Blue buf[x*4+1] = data[x*3+1]; // Green buf[x*4+2] = data[x*3+0]; // Red @@ -174,5 +176,8 @@ void Video_DrawImage(short X, short Y, short W, short H, tImage *Image) buf += giScreenWidth * 4; } break; + default: + _SysDebug("ERROR: Unknown image format %i\n", Image->Format); + break; } } diff --git a/Usermode/Applications/axwin2_src/WM/video_text.c b/Usermode/Applications/axwin2_src/WM/video_text.c index b7764248..3d680d5d 100644 --- a/Usermode/Applications/axwin2_src/WM/video_text.c +++ b/Usermode/Applications/axwin2_src/WM/video_text.c @@ -2,6 +2,7 @@ * Acess GUI (AxWin) Version 2 * By John Hodge (thePowersGang) */ +#include #include "common.h" typedef struct sGlyph { @@ -43,6 +44,7 @@ struct sFont { // === PROTOTYPES === int Video_DrawText(short X, short Y, short W, short H, tFont *Font, uint32_t Color, char *Text); +void Video_GetTextDims(tFont *Font, const char *Text, int *W, int *H); tGlyph *_GetGlyph(tFont *Font, uint32_t Codepoint); void _RenderGlyph(short X, short Y, tGlyph *Glyph, uint32_t Color); tGlyph *_SystemFont_CacheGlyph(tFont *Font, uint32_t Codepoint); diff --git a/Usermode/Applications/axwin2_src/WM/wm.c b/Usermode/Applications/axwin2_src/WM/wm.c index e4d45b5c..ea803051 100644 --- a/Usermode/Applications/axwin2_src/WM/wm.c +++ b/Usermode/Applications/axwin2_src/WM/wm.c @@ -8,6 +8,7 @@ #include #include #include "wm.h" +#include // _SysDebug // === IMPORTS === extern void Decorator_RenderWidget(tElement *Element); @@ -26,9 +27,14 @@ void WM_RenderWidget(tElement *Element); void WM_Update(void); // === GLOBALS === +// - TODO: Handle windows by having multiple root elements tElement gWM_RootElement = { .DebugName = "ROOT" }; + +tApplication *gWM_Applications; + +// --- Element type flags struct { void (*Init)(tElement *This); void (*UpdateFlags)(tElement *This); @@ -81,6 +87,7 @@ tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const void AxWin_DeleteElement(tElement *Element) { // TODO: Implement AxWin_DeleteElement + free(Element); } /** @@ -153,6 +160,8 @@ void AxWin_SetText(tElement *Element, const char *Text) } } break; + default: // Any other, no special case + break ; } return ; @@ -166,6 +175,7 @@ void AxWin_SetText(tElement *Element, const char *Text) */ /** * \brief Updates the dimensions of an element + * \todo What is the \a Pass parameter for * * The dimensions of an element are calculated from the parent's * cross dimension (the side at right angles to the alignment) sans some @@ -266,7 +276,7 @@ void WM_UpdateDimensions(tElement *Element, int Pass) else child->CachedW = with; - WM_UpdateDimensions(child, 0); + WM_UpdateDimensions(child, Pass); } _SysDebug("%p'%s' Done", Element, Element->DebugName); diff --git a/Usermode/Applications/axwin2_src/WM/wm.h b/Usermode/Applications/axwin2_src/WM/wm.h index 552fd4d9..8de9e206 100644 --- a/Usermode/Applications/axwin2_src/WM/wm.h +++ b/Usermode/Applications/axwin2_src/WM/wm.h @@ -5,8 +5,11 @@ #define _WM_H_ #include +#include "common.h" typedef struct sAxWin_Element tElement; +typedef struct sTab tTab; +typedef struct sApplication tApplication; struct sAxWin_Element { @@ -41,28 +44,32 @@ struct sAxWin_Element char DebugName[]; }; -typedef struct sTab +struct sTab { int Type; // Should be zero, allows a tab to be the parent of an element tElement *Parent; tElement *FirstChild; tElement *LastChild; - struct sTab *NextTab; + tTab *NextTab; char *Name; tElement *RootElement; -} tTab; +}; -typedef struct sApplication +struct sApplication { - pid_t PID; + tApplication *Next; + + void *Ident; + tMessages_Handle_Callback *SendMessage; int nTabs; tTab *Tabs; + tTab *CurrentTab; char Name[]; -} tApplication; +}; #endif diff --git a/Usermode/include/axwin2/axwin.h b/Usermode/include/axwin2/axwin.h index ad5b76d9..1455c83e 100644 --- a/Usermode/include/axwin2/axwin.h +++ b/Usermode/include/axwin2/axwin.h @@ -15,6 +15,7 @@ typedef struct sAxWin_Element tAxWin_Element; //typedef struct sAxWin_Message tAxWin_Message; typedef int tAxWin_MessageCallback(tAxWin_Message *); +//typedef int tAxWin_MessageCallback(void *Source, int Message, int Length, void *Data); // === Functions === extern int AxWin_Register(const char *ApplicationName, tAxWin_MessageCallback *DefaultHandler); diff --git a/Usermode/include/axwin2/messages.h b/Usermode/include/axwin2/messages.h index 4d53ab5d..713f0114 100644 --- a/Usermode/include/axwin2/messages.h +++ b/Usermode/include/axwin2/messages.h @@ -22,7 +22,7 @@ typedef struct sAxWin_RetMsg tAxWin_RetMsg; */ enum eAxWin_Messages { - // Server Requests + // Client->Server Requests MSG_SREQ_PING, // - Windows MSG_SREQ_REGISTER, // bool (char[] Name) - Registers this PID with the Window Manager @@ -30,6 +30,8 @@ enum eAxWin_Messages MSG_SREQ_ADDTAB, // TAB (char[] Name) - Adds a tab to the window MSG_SREQ_DELTAB, // void (TAB Tab) - Closes a tab + 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 @@ -49,7 +51,7 @@ enum eAxWin_Messages MSG_SREQ_RIMG, MSG_SREQ_SIMG, // Register/Set Image MSG_SREQ_SETFONT, MSG_SREQ_PUTTEXT, - // Server Responses + // Server->Client Responses MSG_SRSP_VERSION, MSG_SRSP_RETURN, // {int RequestID, void[] Return Value} - Returns a value from a server request @@ -104,8 +106,9 @@ struct sAxWin_SRsp_NewWindow */ struct sAxWin_Message { + uint32_t Source; uint16_t ID; - uint16_t Size; //!< Size in DWORDS + uint16_t Size; // Size of data char Data[]; };