Usermode/AxWin3 - Added support for getting display dimensions
authorJohn Hodge <[email protected]>
Wed, 9 Nov 2011 00:50:49 +0000 (08:50 +0800)
committerJohn Hodge <[email protected]>
Wed, 9 Nov 2011 00:50:49 +0000 (08:50 +0800)
Usermode/Applications/axwin3_src/Interface/main.c
Usermode/Applications/axwin3_src/WM/ipc.c
Usermode/Applications/axwin3_src/WM/video.c
Usermode/Applications/axwin3_src/include/ipcmessages.h
Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h
Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c
Usermode/include/axwin3/axwin.h

index 19cd90e..990489e 100644 (file)
@@ -18,6 +18,8 @@ void  create_sidebar(void);
 // === GLOBALS ===
 tHWND  gSidebar;
 tAxWin3_Widget *gSidebarRoot;
+ int   giScreenWidth;
+ int   giScreenHeight;
 
 // === CODE ===
 int systembutton_fire(tAxWin3_Widget *Widget)
@@ -43,9 +45,11 @@ void create_sidebar(void)
 {
        tAxWin3_Widget  *btn, *txt, *ele;
 
+       // TODO: Register to be told when the display layout changes
+       AxWin3_GetDisplayDims(0, NULL, NULL, &giScreenWidth, &giScreenHeight);
+
        // Create sidebar
-       // TODO: Get screen dimensions somehow
-       gSidebar = AxWin3_Widget_CreateWindow(NULL, SIDEBAR_WIDTH, 480, ELEFLAG_VERTICAL);
+       gSidebar = AxWin3_Widget_CreateWindow(NULL, SIDEBAR_WIDTH, giScreenHeight, ELEFLAG_VERTICAL);
        AxWin3_MoveWindow(gSidebar, 0, 0);
        gSidebarRoot = AxWin3_Widget_GetRoot(gSidebar); 
 
@@ -71,10 +75,14 @@ void create_sidebar(void)
        ele = AxWin3_Widget_AddWidget(gSidebarRoot, ELETYPE_BOX, ELEFLAG_VERTICAL|ELEFLAG_NOSTRETCH, "Version/Time");
        txt = AxWin3_Widget_AddWidget(ele, ELETYPE_TEXT, ELEFLAG_NOSTRETCH, "Version String");
        AxWin3_Widget_SetSize(txt, 20);
-       AxWin3_Widget_SetText(txt, "2.0");
+       AxWin3_Widget_SetText(txt, "3.0");
 
        // Show!
        AxWin3_ShowWindow(gSidebar, 1); 
        
 }
 
+void create_mainmenu(void)
+{
+}
+
index a21c783..aa02016 100644 (file)
@@ -338,6 +338,62 @@ int IPC_Msg_SetWinPos(tIPC_Client *Client, tAxWin_IPCMessage *Msg)
        return 0;
 }
 
+int IPC_Msg_GetDisplayCount(tIPC_Client *Client, tAxWin_IPCMessage *Msg)
+{
+       tAxWin_IPCMessage       *ret_hdr;
+       tIPCMsg_ReturnInt       *ret;
+       char    buf[sizeof(*ret_hdr)+sizeof(*ret)];
+       
+       if( !(Msg->Flags & IPCMSG_FLAG_RETURN) )        return 0;
+       
+       ret_hdr = (void*)buf;
+       ret_hdr->ID = IPCMSG_GETDISPLAYCOUNT;
+       ret_hdr->Flags = 0;
+       ret_hdr->Window = -1;
+       ret_hdr->Size = sizeof(*ret);
+       ret = (void*)ret_hdr->Data;
+       ret->Value = 1; // HARD CODE - Current version only supports one display
+       
+       Client->IPCType->SendMessage(Client->Ident, sizeof(buf), buf);
+       return 0;
+}
+
+int IPC_Msg_GetDisplayDims(tIPC_Client *Client, tAxWin_IPCMessage *Msg)
+{
+       tIPCMsg_GetDisplayDims  *info;
+       tAxWin_IPCMessage       *ret_hdr;
+       tIPCMsg_RetDisplayDims  *ret;
+       char    buf[sizeof(*ret_hdr)+sizeof(*ret)];
+       
+       if( !(Msg->Flags & IPCMSG_FLAG_RETURN) )        return 0;
+
+       info = (void*)Msg->Data;        
+
+       ret_hdr = (void*)buf;
+       ret_hdr->ID = IPCMSG_GETDISPLAYDIMS;
+       ret_hdr->Flags = 0;
+       ret_hdr->Window = -1;
+       ret_hdr->Size = sizeof(*ret);
+       ret = (void*)ret_hdr->Data;
+       
+       // HARD CODE! Only one display supported
+       if( info->DisplayID == 0 )
+       {
+               ret->X = 0;
+               ret->Y = 0;
+               ret->W = giScreenWidth;
+               ret->H = giScreenHeight;
+       }
+       else
+       {
+               ret->X = 0;     ret->Y = 0;
+               ret->W = 0;     ret->H = 0;
+       }
+       
+       Client->IPCType->SendMessage(Client->Ident, sizeof(buf), buf);
+       return 0;
+}
+
 void IPC_Handle(const tIPC_Type *IPCType, const void *Ident, size_t MsgLen, tAxWin_IPCMessage *Msg)
 {
        tIPC_Client     *client;
@@ -361,13 +417,24 @@ void IPC_Handle(const tIPC_Type *IPCType, const void *Ident, size_t MsgLen, tAxW
                if( Msg->Size < 4 )     return;
                if( Msg->Flags & IPCMSG_FLAG_RETURN )
                {
+                       tIPCMsg_ReturnInt       *ret = (void*)Msg->Data;
                        Msg->ID = IPCMSG_PING;
-                       Msg->Size = sizeof(tIPCMsg_Return);
-                       ((tIPCMsg_Return*)Msg->Data)->Value = AXWIN_VERSION;
-                       IPCType->SendMessage(Ident, sizeof(tIPCMsg_Return), Msg);
+                       Msg->Size = sizeof(*ret);
+                       ret->Value = AXWIN_VERSION;
+                       IPCType->SendMessage(Ident, sizeof(*Msg)+sizeof(*ret), Msg);
                }
                break;
 
+       // -- Get display count
+       case IPCMSG_GETDISPLAYCOUNT:
+               rv = IPC_Msg_GetDisplayCount(client, Msg);
+               break;
+       
+       // --- Get display dimensions
+       case IPCMSG_GETDISPLAYDIMS:
+               rv = IPC_Msg_GetDisplayDims(client, Msg);
+               break;
+
        // --- Send a message
        case IPCMSG_SENDMSG:
                _SysDebug(" IPC_Handle: IPCMSG_SENDMSG %i", ((tIPCMsg_SendMsg*)Msg->Data)->ID);
index f04e95e..393d5bf 100644 (file)
@@ -39,30 +39,15 @@ void Video_Setup(void)
                exit(-1);
        }
        
-       // Set width
-       tmpInt = giScreenWidth;
-       tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
-       if(tmpInt != giScreenWidth)
-       {
-               fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
-                       giScreenWidth, tmpInt);
-               giScreenWidth = tmpInt;
-       }
-       
-       // Set height
-       tmpInt = giScreenHeight;
-       tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
-       if(tmpInt != giScreenHeight)
-       {
-               fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
-                       giScreenHeight, tmpInt);
-               giScreenHeight = tmpInt;
-       }
        
        // Set mode to video
        tmpInt = TERM_MODE_FB;
        ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
        
+       // Get dimensions
+       giScreenWidth = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, NULL );
+       giScreenHeight = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, NULL );
+       
        // Force VT to be shown
        ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
        
index bd2072a..3f695ce 100644 (file)
 #include <stdint.h>
 
 typedef struct sAxWin_IPCMessage       tAxWin_IPCMessage;
-typedef struct sIPCMsg_Return  tIPCMsg_Return;
+typedef struct sIPCMsg_ReturnInt       tIPCMsg_ReturnInt;
 typedef struct sIPCMsg_CreateWin       tIPCMsg_CreateWin;
 typedef struct sIPCMsg_ShowWindow      tIPCMsg_ShowWindow;
 typedef struct sIPCMsg_SetWindowPos    tIPCMsg_SetWindowPos;
 typedef struct sIPCMsg_SendMsg tIPCMsg_SendMsg;
 
+typedef struct sIPCMsg_GetDisplayDims  tIPCMsg_GetDisplayDims;
+typedef struct sIPCMsg_RetDisplayDims  tIPCMsg_RetDisplayDims;
+
 /**
  * \name Flags for IPC Messages
  * \{
@@ -37,7 +40,7 @@ struct sAxWin_IPCMessage
        char    Data[];
 };
 
-struct sIPCMsg_Return
+struct sIPCMsg_ReturnInt
 {
        uint32_t        Value;
 };
@@ -70,9 +73,25 @@ struct sIPCMsg_SetWindowPos
        uint8_t         bSetDims;
 };
 
+struct sIPCMsg_GetDisplayDims
+{
+       uint16_t        DisplayID;
+};
+
+struct sIPCMsg_RetDisplayDims
+{
+       uint16_t        X;
+       uint16_t        Y;
+       uint16_t        W;
+       uint16_t        H;
+};
+
 enum eAxWin_IPCMessageTypes
 {
        IPCMSG_PING,    //!< Get the server version
+       IPCMSG_GETDISPLAYCOUNT, 
+       IPCMSG_GETDISPLAYDIMS,
+
        IPCMSG_SENDMSG,         //!< Send a message to another window (or to self)
        IPCMSG_CREATEWIN,       //!< Create a window
        IPCMSG_DESTROYWIN,      //!< Destroy a window
index 6f5fcd5..82f76c6 100644 (file)
@@ -15,6 +15,7 @@ extern const char     *gsAxWin3_int_ServerDesc;
 extern tAxWin_IPCMessage       *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes);
 extern void    AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg);
 extern tAxWin_IPCMessage       *AxWin3_int_GetIPCMessage(void);
+extern tAxWin_IPCMessage       *AxWin3_int_WaitIPCMessage(int WantedID);
 extern void    AxWin3_int_HandleMessage(tAxWin_IPCMessage *Msg);
 
 
index 3b6a3ba..c1d562f 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <ipcmessages.h>       // AxWin3 common
 #include "include/internal.h"
+#include "include/ipc.h"
 
 // === CONSTANTS ===
 enum eConnectionType
@@ -164,3 +165,15 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(void)
        return ret;
 }
 
+tAxWin_IPCMessage *AxWin3_int_WaitIPCMessage(int WantedID)
+{
+       tAxWin_IPCMessage       *msg;
+       for(;;)
+       {
+               msg = AxWin3_int_GetIPCMessage();
+               if(msg->ID == WantedID) return msg;
+               AxWin3_int_HandleMessage( msg );
+               free(msg);
+       }
+}
+
index f63e0f7..43eef70 100644 (file)
@@ -118,10 +118,12 @@ tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Fl
        }
        if( newID == info->nElements )
        {
-               info->nElements ++;
+               const int size_step = 4;
+               info->nElements += 4;
                info->Elements = realloc(info->Elements, sizeof(*info->Elements)*info->nElements);
-               newID = info->nElements - 1;
-               _SysDebug("Expanded and allocated %i", newID);
+               newID = info->nElements - 4;
+               memset( &info->Elements[newID+1], 0, (size_step-1)*sizeof(info->Elements));
+               _SysDebug("Expanded to %i and allocated %i", info->nElements, newID);
        }
        else
                _SysDebug("Allocated %i", newID);
index fd91e88..a03aa9a 100644 (file)
@@ -89,6 +89,48 @@ tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID)
        return ret;
 }
 
+int AxWin3_GetDisplayCount(void)
+{
+       tAxWin_IPCMessage       *msg;
+       tIPCMsg_ReturnInt       *ret;
+        int    rv;
+       
+       msg = AxWin3_int_AllocateIPCMessage(NULL, IPCMSG_GETDISPLAYCOUNT, IPCMSG_FLAG_RETURN, 0);
+       AxWin3_int_SendIPCMessage(msg);
+       free(msg);      
+
+       msg = AxWin3_int_WaitIPCMessage(IPCMSG_GETDISPLAYCOUNT);
+       if(msg->Size < sizeof(*ret))    return -1;
+       ret = (void*)msg->Data;
+       rv = ret->Value;
+       free(msg);
+       return rv;
+}
+
+int AxWin3_GetDisplayDims(int Display, int *X, int *Y, int *Width, int *Height)
+{
+       tAxWin_IPCMessage       *msg;
+       tIPCMsg_GetDisplayDims  *req;
+       tIPCMsg_RetDisplayDims  *ret;
+       
+       msg = AxWin3_int_AllocateIPCMessage(NULL, IPCMSG_GETDISPLAYDIMS, IPCMSG_FLAG_RETURN, sizeof(*req));
+       req = (void*)msg->Data;
+       req->DisplayID = Display;
+       AxWin3_int_SendIPCMessage(msg);
+       free(msg);
+
+       msg = AxWin3_int_WaitIPCMessage(IPCMSG_GETDISPLAYDIMS);
+       if(msg->Size < sizeof(*ret))    return -1;
+       ret = (void*)msg->Data;
+       
+       if(X)   *X = ret->X;
+       if(X)   *X = ret->Y;
+       if(Width)       *Width = ret->W;
+       if(Height)      *Height = ret->H;
+       
+       return 0;
+}
+
 tHWND AxWin3_CreateWindow(
        tHWND Parent, const char *Renderer, int RendererArg,
        int DataBytes, tAxWin3_WindowMessageHandler MessageHandler
index 7d1d3f4..4ad955d 100644 (file)
@@ -20,6 +20,10 @@ extern void  AxWin3_Connect(const char *ServerDesc);
 extern tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callback);
 extern void    AxWin3_MainLoop(void);
 
+// --- Non-Window based functions
+extern int     AxWin3_GetDisplayCount(void);
+extern int     AxWin3_GetDisplayDims(int Display, int *X, int *Y, int *Width, int *Height);
+
 // --- Window creation/deletion
 /**
  * \brief Create a new window (with the required client structures)

UCC git Repository :: git.ucc.asn.au