From: John Hodge Date: Sun, 8 Jun 2014 15:12:55 +0000 (+0800) Subject: Usermode/AxWin4 - Mouse input in progress X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=aa5e13445f3d9ab6e0c0049780f38daed443104f;p=tpg%2Facess2.git Usermode/AxWin4 - Mouse input in progress --- diff --git a/Usermode/Applications/axwin4_src/Server/CConfig.cpp b/Usermode/Applications/axwin4_src/Server/CConfig.cpp index 567f1a3a..eec783b4 100644 --- a/Usermode/Applications/axwin4_src/Server/CConfig.cpp +++ b/Usermode/Applications/axwin4_src/Server/CConfig.cpp @@ -22,7 +22,8 @@ CConfigVideo::CConfigVideo() { } -CConfigInput::CConfigInput() +CConfigInput::CConfigInput(): + mouse_device("/Devices/Mouse/system") { } diff --git a/Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp b/Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp index b222cea8..a9818cdb 100644 --- a/Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp +++ b/Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp @@ -51,7 +51,8 @@ void CIPCChannel_AcessIPCPipe::HandleSelect(const fd_set& rfds) _SysDebug("ERROR - Failure to open new client on FD%i", m_fd); } else { - _SysDebug("CIPCChannel_AcessIPCPipe::HandleSelect - New client on FD %i with FD%i", m_fd, newfd); + _SysDebug("CIPCChannel_AcessIPCPipe::HandleSelect - New client on FD %i with FD%i", + m_fd, newfd); // emplace creates a new object within the list m_clients.emplace( m_clients.end(), *this, newfd ); diff --git a/Usermode/Applications/axwin4_src/Server/compositor.cpp b/Usermode/Applications/axwin4_src/Server/compositor.cpp index dbabc9f6..6f512c8d 100644 --- a/Usermode/Applications/axwin4_src/Server/compositor.cpp +++ b/Usermode/Applications/axwin4_src/Server/compositor.cpp @@ -91,5 +91,16 @@ void CCompositor::BlitFromSurface(const CSurface& dest, const CRect& src_rect) } } +void CCompositor::MouseMove(unsigned int Cursor, unsigned int X, unsigned int Y, int dX, int dY) +{ + _SysDebug("MouseButton(%i, %i,%i, %+i,%+i)", Cursor, X, Y, dX, dY); + m_video.SetCursorPos(X+dX, Y+dY); +} + +void CCompositor::MouseButton(unsigned int Cursor, unsigned int X, unsigned int Y, eMouseButton Button, bool Press) +{ + _SysDebug("MouseButton(%i, %i,%i, %i=%i)", Cursor, X, Y, Button, Press); +} + } // namespace AxWin diff --git a/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp b/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp index 51f04c91..0b773cef 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp @@ -54,8 +54,8 @@ public: void DamageArea(const CRect& rect); void BlitFromSurface(const CSurface& dest, const CRect& src_rect); - void MouseMove(unsigned int CursorID, unsigned int X, unsigned int Y, int dX, int dY); - void MouseButton(unsigned int CursorID, unsigned int X, unsigned int Y, eMouseButton Button, bool Press); + void MouseMove(unsigned int Cursor, unsigned int X, unsigned int Y, int dX, int dY); + void MouseButton(unsigned int Cursor, unsigned int X, unsigned int Y, eMouseButton Button, bool Press); void KeyState(unsigned int KeyboardID, uint32_t KeySym, bool Press, uint32_t Codepoint); }; diff --git a/Usermode/Applications/axwin4_src/Server/include/CConfigInput.hpp b/Usermode/Applications/axwin4_src/Server/include/CConfigInput.hpp index 1aeb9a7d..28553ca0 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CConfigInput.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CConfigInput.hpp @@ -8,12 +8,16 @@ #ifndef _CCONFIGINPUT_H_ #define _CCONFIGINPUT_H_ +#include + namespace AxWin { class CConfigInput { public: CConfigInput(); + + ::std::string mouse_device; }; }; // namespace AxWin diff --git a/Usermode/Applications/axwin4_src/Server/include/input.hpp b/Usermode/Applications/axwin4_src/Server/include/input.hpp index 952e2e92..f8b27cea 100644 --- a/Usermode/Applications/axwin4_src/Server/include/input.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/input.hpp @@ -19,6 +19,10 @@ class CInput CCompositor& m_compositor; int m_keyboardFD; int m_mouseFD; + + unsigned int m_mouseX; + unsigned int m_mouseY; + unsigned int m_mouseBtns; public: CInput(const CConfigInput& config, CCompositor& compositor); int FillSelect(::fd_set& rfds); diff --git a/Usermode/Applications/axwin4_src/Server/include/video.hpp b/Usermode/Applications/axwin4_src/Server/include/video.hpp index 539410b4..9ca7b42f 100644 --- a/Usermode/Applications/axwin4_src/Server/include/video.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/video.hpp @@ -26,11 +26,11 @@ public: void BlitLine(const uint32_t* src, unsigned int dst_y, unsigned int dst_x, unsigned int width); void Flush(); + void SetCursorPos(int X, int Y); private: void SetBufFormat(unsigned int FormatID); void SetCursorBitmap(); - void SetCursorPos(int X, int Y); }; }; diff --git a/Usermode/Applications/axwin4_src/Server/input.cpp b/Usermode/Applications/axwin4_src/Server/input.cpp index c120ed45..409658cf 100644 --- a/Usermode/Applications/axwin4_src/Server/input.cpp +++ b/Usermode/Applications/axwin4_src/Server/input.cpp @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include namespace AxWin { @@ -17,7 +20,9 @@ CInput::CInput(const ::AxWin::CConfigInput& config, CCompositor& compositor): m_keyboardFD(0), m_mouseFD(-1) { - + m_mouseFD = _SysOpen(config.mouse_device.c_str(), OPENFLAG_READ|OPENFLAG_WRITE); + if( m_mouseFD == -1 ) + throw ::std::system_error(errno, ::std::system_category()); } int CInput::FillSelect(::fd_set& rfds) @@ -66,6 +71,64 @@ void CInput::HandleSelect(::fd_set& rfds) if( m_mouseFD != -1 && FD_ISSET(m_mouseFD, &rfds) ) { // TODO: Read mouse event and handle + const int c_n_axies = 4; + const int c_n_buttons = 5; + struct mouse_axis *axies; + uint8_t *buttons; + + char data[sizeof(struct mouse_header) + sizeof(*axies)*c_n_axies + c_n_buttons]; + struct mouse_header *mouseinfo = (struct mouse_header*)data; + + _SysSeek(m_mouseFD, 0, SEEK_SET); + int len = _SysRead(m_mouseFD, data, sizeof(data)); + if( len < 0 ) + throw ::std::system_error(errno, ::std::system_category()); + + len -= sizeof(*mouseinfo); + if( len < 0 ) { + _SysDebug("Mouse data undersized (%i bytes short on header)", len); + return ; + } + if( mouseinfo->NAxies > c_n_axies || mouseinfo->NButtons > c_n_buttons ) { + _SysDebug("%i axies, %i buttons above prealloc counts (%i, %i)", + mouseinfo->NAxies, mouseinfo->NButtons, c_n_axies, c_n_buttons + ); + return ; + } + if( len < sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons ) { + _SysDebug("Mouse data undersized (body doesn't fit %i < %i)", + len, sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons + ); + return ; + } + + // What? No X/Y? + if( mouseinfo->NAxies < 2 ) { + _SysDebug("Mouse data lacks X/Y"); + return ; + } + + axies = (struct mouse_axis*)( mouseinfo + 1 ); + buttons = (uint8_t*)( axies + mouseinfo->NAxies ); + + m_compositor.MouseMove(0, + m_mouseX, m_mouseY, + axies[0].CursorPos - m_mouseX, axies[1].CursorPos - m_mouseY + ); + m_mouseX = axies[0].CursorPos; + m_mouseY = axies[1].CursorPos; + + for( int i = 0; i < mouseinfo->NButtons; i ++ ) + { + int bit = 1 << i; + int cur = buttons[i] > 128; + if( !!(m_mouseBtns & bit) != cur ) + { + m_compositor.MouseButton(0, m_mouseX, m_mouseY, (eMouseButton)i, cur); + // Flip button state + m_mouseBtns ^= bit; + } + } } } diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/devices/joystick.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/devices/joystick.h new file mode 100644 index 00000000..e5d670f2 --- /dev/null +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/devices/joystick.h @@ -0,0 +1,47 @@ +/* + * Acess2 System Calls + * - By John Hodge (thePowersGang) + * + * acess/devices/joystick.h + * - Joystick IOCtls and structures + */ +#ifndef _SYS_DEVICES_JOYSTICK_H +#define _SYS_DEVICES_JOYSTICK_H + +#if __cplusplus +extern "C" { +#endif + +#include + +struct mouse_attribute +{ + uint32_t Num; + uint32_t Value; +}; + +struct mouse_header +{ + uint16_t NAxies; + uint16_t NButtons; +}; + +struct mouse_axis +{ + int16_t MinValue; + int16_t MaxValue; + int16_t CurValue; + uint16_t CursorPos; +}; + +enum { + JOY_IOCTL_GETSETAXISLIMIT = 6, + JOY_IOCTL_GETSETAXISPOSITION, +}; + +#if __cplusplus +} +#endif + +#endif +