From 6fbf6b93bec9b8b5bd6d7c683eefb0ebed8dff77 Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Sun, 9 Nov 2014 08:07:04 +0800 Subject: [PATCH] Usermode/AxWin4 - Send mouse/keyboard events to client --- AcessNative/RunNative | 1 + Externals/libspiderscript/source | 2 +- .../axwin4_src/Common/include/ipc_proto.hpp | 10 ++++++ .../axwin4_src/Server/CWindow.cpp | 6 +++- .../axwin4_src/Server/compositor.cpp | 12 +++++-- .../axwin4_src/Server/include/CCompositor.hpp | 1 + .../axwin4_src/Server/include/ipc.hpp | 5 ++- .../Applications/axwin4_src/Server/ipc.cpp | 31 +++++++++++++++++-- Usermode/Libraries/libaxwin4.so_src/ipc.cpp | 12 +++++++ 9 files changed, 72 insertions(+), 8 deletions(-) diff --git a/AcessNative/RunNative b/AcessNative/RunNative index f22ed7fe..03ec6b00 100755 --- a/AcessNative/RunNative +++ b/AcessNative/RunNative @@ -25,5 +25,6 @@ echo Kernel is $KERNEL_PID sleep 1 LD_LIBRARY_PATH=${DIR}:${DISTROOT}Libs AN_PREOPEN=$VTERM:$VTERM:$VTERM ${DBG} ${DISTROOT}Apps/AxWin/4.0/AxWinServer +trap '' SIGINT cleanup diff --git a/Externals/libspiderscript/source b/Externals/libspiderscript/source index a5d190a8..9f2d7faf 160000 --- a/Externals/libspiderscript/source +++ b/Externals/libspiderscript/source @@ -1 +1 @@ -Subproject commit a5d190a89ca3f3a78c8b44a855b044ff4e713bb3 +Subproject commit 9f2d7faf34c16ceaee2f1bffe3d5558c41382523 diff --git a/Usermode/Applications/axwin4_src/Common/include/ipc_proto.hpp b/Usermode/Applications/axwin4_src/Common/include/ipc_proto.hpp index e47ed14d..d9c71bd3 100644 --- a/Usermode/Applications/axwin4_src/Common/include/ipc_proto.hpp +++ b/Usermode/Applications/axwin4_src/Common/include/ipc_proto.hpp @@ -33,6 +33,9 @@ enum IPCMSG_BLIT, // (win, sx, sy, dx, dy, w, h) - Blit locally IPCMSG_DRAWCTL, // (win, x, y, w, h, ctlid) - Draw IPCMSG_DRAWTEXT, // (win, x, y, fontid, text) - Draw text using an internal font + + // - Client-bound commands + IPCMSG_INPUTEVENT, // (u8 event, u16 win, ...) }; enum eIPC_GlobalAttrs @@ -50,6 +53,13 @@ enum eIPC_WinAttrs IPC_WINATTR_TITLE, // string }; +enum eIPC_InputEvents +{ + IPC_INEV_KEYBOARD, // (u16 keysym, u8 keydown, string text) + IPC_INEV_MOUSEBTN, // (u16 x, u16 y) + IPC_INEV_MOUSEMOVE, // (u16 x, u16 y, u8 btn, u8 btndown) +}; + }; #endif diff --git a/Usermode/Applications/axwin4_src/Server/CWindow.cpp b/Usermode/Applications/axwin4_src/Server/CWindow.cpp index 55c24823..7d50b7b4 100644 --- a/Usermode/Applications/axwin4_src/Server/CWindow.cpp +++ b/Usermode/Applications/axwin4_src/Server/CWindow.cpp @@ -59,7 +59,7 @@ void CWindow::Move(int X, int Y) void CWindow::Resize(unsigned int W, unsigned int H) { m_surface.Resize(W, H); - IPC::SendMessage_NotifyDims(m_client, W, H); + IPC::SendMessage_NotifyDims(m_client, m_id, W, H); } void CWindow::SetFlags(uint32_t Flags) { @@ -74,14 +74,18 @@ uint64_t CWindow::ShareSurface() void CWindow::MouseButton(int ButtonID, int X, int Y, bool Down) { + IPC::SendMessage_MouseButton(m_client, m_id, X, Y, ButtonID, Down); } void CWindow::MouseMove(int NewX, int NewY) { + // TODO: Only enable move events if client requests them + //IPC::SendMessage_MouseMove(m_client, m_id, NewX, NewY); } void CWindow::KeyEvent(::uint32_t Scancode, const ::std::string &Translated, bool Down) { + IPC::SendMessage_KeyEvent(m_client, m_id, Scancode, Down, Translated.c_str()); } diff --git a/Usermode/Applications/axwin4_src/Server/compositor.cpp b/Usermode/Applications/axwin4_src/Server/compositor.cpp index da924e8d..cf8192ec 100644 --- a/Usermode/Applications/axwin4_src/Server/compositor.cpp +++ b/Usermode/Applications/axwin4_src/Server/compositor.cpp @@ -16,6 +16,7 @@ namespace AxWin { CCompositor::CCompositor(CVideo& video): // TODO: Support multiple screens m_video(video), + m_focussed_window(nullptr), m_windowIDBuffer(video.width(), video.height()) { // @@ -54,7 +55,7 @@ void CCompositor::Redraw() { // Redraw the screen and clear damage rects if( m_damageRects.empty() ) { - _SysDebug("- No damaged regions"); + //_SysDebug("- No damaged regions"); return ; } @@ -112,7 +113,8 @@ void CCompositor::MouseMove(unsigned int Cursor, unsigned int X, unsigned int Y, CWindow *dstwin = getWindowForCoord(X, Y); if( dstwin ) { - // TODO: Pass event on to window + // Pass event on to window + dstwin->MouseMove(X, Y); } } @@ -125,13 +127,17 @@ void CCompositor::MouseButton(unsigned int Cursor, unsigned int X, unsigned int { // 1. Give focus and bring to front // 2. Send event - // TODO: Pass event on to window + dstwin->MouseButton(Button, X, Y, Press); } } void CCompositor::KeyState(unsigned int KeyboardID, uint32_t KeySym, bool Press, uint32_t Codepoint) { _SysDebug("KeyState(%i, 0x%x, %b, 0x%x)", KeyboardID, KeySym, Press, Codepoint); + if( m_focussed_window ) + { + m_focussed_window->KeyEvent(KeySym, "", Press); + } } CWindow* CCompositor::getWindowForCoord(unsigned int X, unsigned int Y) diff --git a/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp b/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp index ec40d369..fe243039 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp @@ -50,6 +50,7 @@ class CCompositor CVideo& m_video; ::std::list m_damageRects; ::std::list m_windows; + CWindow* m_focussed_window; CWindowIDBuffer m_windowIDBuffer; // One 32-bit value per pixel diff --git a/Usermode/Applications/axwin4_src/Server/include/ipc.hpp b/Usermode/Applications/axwin4_src/Server/include/ipc.hpp index 5706a85b..50b0dbe2 100644 --- a/Usermode/Applications/axwin4_src/Server/include/ipc.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/ipc.hpp @@ -31,7 +31,10 @@ extern void RegisterClient(CClient& client); extern CClient* GetClientByID(uint16_t id); extern void DeregisterClient(CClient& client); -extern void SendMessage_NotifyDims(CClient& client, unsigned int NewW, unsigned int NewH); +extern void SendMessage_NotifyDims(CClient& client, unsigned int WinID, unsigned int NewW, unsigned int NewH); +extern void SendMessage_MouseButton(CClient& client, unsigned int WinID, unsigned int X, unsigned int Y, uint8_t Button, bool Pressed); +extern void SendMessage_MouseMove(CClient& client, unsigned int WinID, unsigned int X, unsigned int Y); +extern void SendMessage_KeyEvent(CClient& client, unsigned int WinID, uint32_t KeySym, bool Pressed, const char *Translated); extern void HandleMessage(CClient& client, CDeserialiser& message); diff --git a/Usermode/Applications/axwin4_src/Server/ipc.cpp b/Usermode/Applications/axwin4_src/Server/ipc.cpp index 1c5ba994..5f59ae19 100644 --- a/Usermode/Applications/axwin4_src/Server/ipc.cpp +++ b/Usermode/Applications/axwin4_src/Server/ipc.cpp @@ -101,9 +101,36 @@ void DeregisterClient(CClient& client) } -void SendMessage_NotifyDims(CClient& client, unsigned int NewW, unsigned int NewH) +void SendMessage_NotifyDims(CClient& client, unsigned int WinID, unsigned int NewW, unsigned int NewH) { - _SysDebug("TODO: CClient::SendNotify_Dims"); + _SysDebug("TODO: IPC::SendMessage_NotifyDims"); +} +void SendMessage_MouseButton(CClient& client, unsigned int WinID, unsigned int X, unsigned int Y, uint8_t Button, bool Pressed) +{ + CSerialiser msg; + msg.WriteU8(IPCMSG_INPUTEVENT); + msg.WriteU8(IPC_INEV_MOUSEBTN); + msg.WriteU16(WinID); + msg.WriteU16(X); + msg.WriteU16(Y); + msg.WriteU8(Button); + msg.WriteU8(Pressed ? 0 : 1); + client.SendMessage(msg); +} +void SendMessage_MouseMove(CClient& client, unsigned int WinID, unsigned int X, unsigned int Y) +{ + _SysDebug("TODO: IPC::SendMessage_MouseButton"); +} +void SendMessage_KeyEvent(CClient& client, unsigned int WinID, uint32_t KeySym, bool Pressed, const char *Translated) +{ + CSerialiser msg; + msg.WriteU8(IPCMSG_INPUTEVENT); + msg.WriteU8(IPC_INEV_KEYBOARD); + msg.WriteU16(WinID); + msg.WriteU16(KeySym); + msg.WriteU8(Pressed ? 0 : 1); + msg.WriteString(Translated); + client.SendMessage(msg); } diff --git a/Usermode/Libraries/libaxwin4.so_src/ipc.cpp b/Usermode/Libraries/libaxwin4.so_src/ipc.cpp index a262a9ee..e42d4060 100644 --- a/Usermode/Libraries/libaxwin4.so_src/ipc.cpp +++ b/Usermode/Libraries/libaxwin4.so_src/ipc.cpp @@ -86,6 +86,15 @@ void RecvMessage(CDeserialiser& message) _SysDebug("RecvMessage: id=%i", id); switch(id) { + case IPCMSG_PING: + // If we hear ping, we must pong + { + CSerialiser pong; + pong.WriteU8(IPCMSG_REPLY); + pong.WriteU8(IPCMSG_PING); + SendMessage(pong); + } + break; case IPCMSG_REPLY: // Flag reply and take a copy of this message if( !gSyncReplyActive ) @@ -103,6 +112,9 @@ void RecvMessage(CDeserialiser& message) gSyncReplyBuf = message; } break; + // TODO: Handle messages from server (input events, IPC) + // TODO: If an event is currently being processed, save the message in a queue to be handled when processing is complete + // - This will prevent deep recursion (and make server errors aparent) default: _SysDebug("TODO: RecvMessage(%i)", id); break; -- 2.20.1