From e20b7220513e6010d883ae76ca1cf2c8f0ec26af Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 13 Nov 2011 10:02:27 +0800 Subject: [PATCH] Usermode/AxWin3 - Cleaned up focus code a little, added IPC focus call --- .../Applications/axwin3_src/WM/include/wm.h | 4 +-- Usermode/Applications/axwin3_src/WM/ipc.c | 24 ++++++++++++++++ .../axwin3_src/WM/renderer_menu.c | 17 ++++++----- Usermode/Applications/axwin3_src/WM/wm.c | 28 ++++++++++++++++++- .../Applications/axwin3_src/WM/wm_input.c | 20 +------------ .../axwin3_src/include/ipcmessages.h | 1 + .../axwin3_src/libaxwin3.so_src/r_menu.c | 1 + .../axwin3_src/libaxwin3.so_src/wm.c | 12 +++++++- Usermode/include/axwin3/axwin.h | 1 + 9 files changed, 78 insertions(+), 30 deletions(-) diff --git a/Usermode/Applications/axwin3_src/WM/include/wm.h b/Usermode/Applications/axwin3_src/WM/include/wm.h index 35e7e212..d6fd3ad2 100644 --- a/Usermode/Applications/axwin3_src/WM/include/wm.h +++ b/Usermode/Applications/axwin3_src/WM/include/wm.h @@ -41,12 +41,12 @@ typedef struct sIPC_Client tIPC_Client; // --- Management 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_FocusWindow(tWindow *Destination); +extern void WM_RaiseWindow(tWindow *Window); extern void WM_ShowWindow(tWindow *Window, int bShow); extern int WM_ResizeWindow(tWindow *Window, int W, int H); extern int WM_MoveWindow(tWindow *Window, int X, int Y); extern int WM_SendMessage(tWindow *Source, tWindow *Dest, int MessageID, int Length, void *Data); -extern void WM_GiveFocus(tWindow *Destination); -extern void WM_RaiseWindow(tWindow *Window); // --- Rendering extern void WM_Render_FillRect(tWindow *Window, int X, int Y, int W, int H, tColour Colour); extern void WM_Render_DrawRect(tWindow *Window, int X, int Y, int W, int H, tColour Colour); diff --git a/Usermode/Applications/axwin3_src/WM/ipc.c b/Usermode/Applications/axwin3_src/WM/ipc.c index da56149b..ffad8e5d 100644 --- a/Usermode/Applications/axwin3_src/WM/ipc.c +++ b/Usermode/Applications/axwin3_src/WM/ipc.c @@ -12,6 +12,7 @@ #include #include #include +#include #define AXWIN_PORT 4101 @@ -37,6 +38,8 @@ struct sIPC_Client tWindow **Windows; }; +// === IMPORTS === +extern tWindow *gpWM_FocusedWindow; // Needed for _FocusWindow // === PROTOTYPES === void IPC_Init(void); @@ -277,6 +280,22 @@ int IPC_Msg_SendMsg(tIPC_Client *Client, tAxWin_IPCMessage *Msg) return 0; } +int IPC_Msg_FocusWindow(tIPC_Client *Client, tAxWin_IPCMessage *Msg) +{ + tWindow *win; + + // Don't allow the focus to be changed unless the client has the focus + if(!gpWM_FocusedWindow) return 1; + if(gpWM_FocusedWindow->Client != Client) return 1; + + win = IPC_int_GetWindow(Client, Msg->Window); + if(!win) return 1; + + WM_FocusWindow(win); + + return 0; +} + int IPC_Msg_CreateWin(tIPC_Client *Client, tAxWin_IPCMessage *Msg) { tIPCMsg_CreateWin *info = (void*)Msg->Data; @@ -455,6 +474,11 @@ void IPC_Handle(const tIPC_Type *IPCType, const void *Ident, size_t MsgLen, tAxW _SysDebug(" IPC_Handle: IPCMSG_CREATEWIN"); rv = IPC_Msg_CreateWin(client, Msg); break; + // --- Give a window focus + case IPCMSG_FOCUSWINDOW: + _SysDebug(" IPC_Handle: IPCMSG_FOCUSWINDOW"); + rv = IPC_Msg_FocusWindow(client, Msg); + break; // --- Show/Hide a window case IPCMSG_SHOWWINDOW: _SysDebug(" IPC_Handle: IPCMSG_SHOWWINDOW"); diff --git a/Usermode/Applications/axwin3_src/WM/renderer_menu.c b/Usermode/Applications/axwin3_src/WM/renderer_menu.c index b70016da..7d07c93a 100644 --- a/Usermode/Applications/axwin3_src/WM/renderer_menu.c +++ b/Usermode/Applications/axwin3_src/WM/renderer_menu.c @@ -170,7 +170,7 @@ void Renderer_Menu_Redraw(tWindow *Window) if(item->UnderlineW) { WM_Render_FillRect(Window, - ciMenu_LeftPadding + item->UnderlineX, y + ciMenu_FontHeight + 1, + ciMenu_LeftPadding + item->UnderlineX, y + ciMenu_FontHeight, item->UnderlineW, 1, cMenu_LabelColour ); @@ -301,6 +301,7 @@ int Renderer_Menu_int_AddItem(tWindow *Window, int Length, void *Data) + ciMenu_Gap + info->MaxShortcutWidth + ciMenu_RightPadding; // TODO: Smarter height? + // Doesn't matter a lot here really WM_ResizeWindow(Window, info->CachedW, info->nItems*ciMenu_ItemHeight); } @@ -320,7 +321,7 @@ int Renderer_Menu_int_GetItemByPos(tWindow *Window, tMenuWindowInfo *Info, int X if( !Info->Items[i]->Label ) { - // Spacer - doesn't hilight + // Spacer - not selectable if(Y < ciMenu_SpacerHeight) { return -1; } @@ -328,7 +329,7 @@ int Renderer_Menu_int_GetItemByPos(tWindow *Window, tMenuWindowInfo *Info, int X } else { - // Normal item, set the hilight + // Normal item, can be selected/hilighted if(Y < ciMenu_ItemHeight) { return i; } @@ -346,10 +347,12 @@ int Renderer_Menu_HandleMessage(tWindow *Window, int Msg, int Length, void *Data case WNDMSG_SHOW: { struct sWndMsg_Bool *msg = Data; if(Length < sizeof(*msg)) return -1; - if(msg->Val) { - // Take focus? - _SysDebug(" - Shown, take focus"); - WM_GiveFocus(Window); + if(msg->Val) + { +// _SysDebug(" - Shown, take focus"); + // TODO: This shouldn't really be done, instead focus should be given + // when the menu is shown. +// WM_FocusWindow(Window); } else { diff --git a/Usermode/Applications/axwin3_src/WM/wm.c b/Usermode/Applications/axwin3_src/WM/wm.c index 38bbbf34..17540a8a 100644 --- a/Usermode/Applications/axwin3_src/WM/wm.c +++ b/Usermode/Applications/axwin3_src/WM/wm.c @@ -18,6 +18,8 @@ extern void IPC_SendWMMessage(tIPC_Client *Client, uint32_t Src, uint32_t Dst, i // === GLOBALS === tWMRenderer *gpWM_Renderers; tWindow *gpWM_RootWindow; +//! Window which will recieve the next keyboard event +tWindow *gpWM_FocusedWindow; // === CODE === void WM_Initialise(void) @@ -116,18 +118,42 @@ void WM_RaiseWindow(tWindow *Window) parent->LastChild = Window; } +void WM_FocusWindow(tWindow *Destination) +{ + struct sWndMsg_Bool _msg; + + if( gpWM_FocusedWindow == Destination ) + return ; + if( Destination && !(Destination->Flags & WINFLAG_SHOW) ) + return ; + + _msg.Val = 0; + WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_FOCUS, sizeof(_msg), &_msg); + _msg.Val = 1; + WM_SendMessage(NULL, Destination, WNDMSG_FOCUS, sizeof(_msg), &_msg); + + gpWM_FocusedWindow = Destination; +} + + void WM_ShowWindow(tWindow *Window, int bShow) { // Message window struct sWndMsg_Bool _msg; + if( !!(Window->Flags & WINFLAG_SHOW) == bShow ) + return ; + _msg.Val = !!bShow; WM_SendMessage(NULL, Window, WNDMSG_SHOW, sizeof(_msg), &_msg); if(bShow) Window->Flags |= WINFLAG_SHOW; - else + else { Window->Flags &= ~WINFLAG_SHOW; + if( Window == gpWM_FocusedWindow ) + WM_FocusWindow(Window->Parent); + } WM_Invalidate(Window); } diff --git a/Usermode/Applications/axwin3_src/WM/wm_input.c b/Usermode/Applications/axwin3_src/WM/wm_input.c index af258ff1..66088f92 100644 --- a/Usermode/Applications/axwin3_src/WM/wm_input.c +++ b/Usermode/Applications/axwin3_src/WM/wm_input.c @@ -15,8 +15,6 @@ extern tWindow *gpWM_RootWindow; // === GLOBALS === -//! Window which will recieve the next keyboard event -tWindow *gpWM_FocusedWindow; //! Window in which the mouse button was originally pressed tWindow *gpWM_DownStartWindow[MAX_BUTTONS]; @@ -93,7 +91,7 @@ void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed) if( ButtonIndex == 0 && Pressed == 1 ) { _SysDebug("Gave focus to %p", win); - WM_GiveFocus(win); + WM_FocusWindow(win); WM_RaiseWindow(win); } @@ -112,19 +110,3 @@ void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed) WM_Input_int_SendBtnMsg(win, X, Y, ButtonIndex, Pressed); } -// --- Manipulation Functions --- -void WM_GiveFocus(tWindow *Destination) -{ - struct sWndMsg_Bool _msg; - - if( gpWM_FocusedWindow == Destination ) - return ; - - _msg.Val = 0; - WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_FOCUS, sizeof(_msg), &_msg); - _msg.Val = 1; - WM_SendMessage(NULL, Destination, WNDMSG_FOCUS, sizeof(_msg), &_msg); - - gpWM_FocusedWindow = Destination; -} - diff --git a/Usermode/Applications/axwin3_src/include/ipcmessages.h b/Usermode/Applications/axwin3_src/include/ipcmessages.h index 3f695ce9..a3fda63b 100644 --- a/Usermode/Applications/axwin3_src/include/ipcmessages.h +++ b/Usermode/Applications/axwin3_src/include/ipcmessages.h @@ -96,6 +96,7 @@ enum eAxWin_IPCMessageTypes IPCMSG_CREATEWIN, //!< Create a window IPCMSG_DESTROYWIN, //!< Destroy a window IPCMSG_SHOWWINDOW, //!< Show/Hide a window + IPCMSG_FOCUSWINDOW, //!< Give a window focus (no data) IPCMSG_SETWINPOS, //!< Set a window position }; diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_menu.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_menu.c index 78fa169a..1a6bfdf0 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_menu.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_menu.c @@ -67,6 +67,7 @@ void AxWin3_Menu_ShowAt(tHWND Menu, int X, int Y) { AxWin3_MoveWindow(Menu, X, Y); AxWin3_ShowWindow(Menu, 1); + AxWin3_FocusWindow(Menu); } tAxWin3_MenuItem *AxWin3_Menu_AddItem( diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c index a03aa9a8..d64bcbc8 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c @@ -54,7 +54,7 @@ tWindow *AxWin3_int_GetWindowFromID(uint32_t ServerID) tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID) { int idx, newWinID; - tWindowBlock *block, *prev; + tWindowBlock *block, *prev = NULL; tWindow *ret; block = &gAxWin3_WindowList; @@ -212,6 +212,16 @@ void AxWin3_SendMessage(tHWND Window, tHWND Destination, int Message, int Length free(msg); } +void AxWin3_FocusWindow(tHWND Window) +{ + tAxWin_IPCMessage *msg; + + msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_FOCUSWINDOW, 0, 0); + + AxWin3_int_SendIPCMessage(msg); + free(msg); +} + void AxWin3_ShowWindow(tHWND Window, int bShow) { tAxWin_IPCMessage *msg; diff --git a/Usermode/include/axwin3/axwin.h b/Usermode/include/axwin3/axwin.h index 4ad955d6..07bfe045 100644 --- a/Usermode/include/axwin3/axwin.h +++ b/Usermode/include/axwin3/axwin.h @@ -49,6 +49,7 @@ extern void AxWin3_DestroyWindow(tHWND Window); // --- Core window management functions extern void AxWin3_SendMessage(tHWND Window, tHWND Dest, int Message, int Length, void *Data); +extern void AxWin3_FocusWindow(tHWND Window); extern void AxWin3_ShowWindow(tHWND Window, int bShow); extern void AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H); extern void AxWin3_MoveWindow(tHWND Window, short X, short Y); -- 2.20.1