Usermode/AxWin4 - Mouse input in progress
authorJohn Hodge <[email protected]>
Sun, 8 Jun 2014 15:12:55 +0000 (23:12 +0800)
committerJohn Hodge <[email protected]>
Sun, 8 Jun 2014 15:12:55 +0000 (23:12 +0800)
Usermode/Applications/axwin4_src/Server/CConfig.cpp
Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp
Usermode/Applications/axwin4_src/Server/compositor.cpp
Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp
Usermode/Applications/axwin4_src/Server/include/CConfigInput.hpp
Usermode/Applications/axwin4_src/Server/include/input.hpp
Usermode/Applications/axwin4_src/Server/include/video.hpp
Usermode/Applications/axwin4_src/Server/input.cpp
Usermode/Libraries/ld-acess.so_src/include_exp/acess/devices/joystick.h [new file with mode: 0644]

index 567f1a3..eec783b 100644 (file)
@@ -22,7 +22,8 @@ CConfigVideo::CConfigVideo()
 {
 }
 
-CConfigInput::CConfigInput()
+CConfigInput::CConfigInput():
+       mouse_device("/Devices/Mouse/system")
 {
 }
 
index b222cea..a9818cd 100644 (file)
@@ -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 );
index dbabc9f..6f512c8 100644 (file)
@@ -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
 
index 51f04c9..0b773ce 100644 (file)
@@ -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);
 };
index 1aeb9a7..28553ca 100644 (file)
@@ -8,12 +8,16 @@
 #ifndef _CCONFIGINPUT_H_
 #define _CCONFIGINPUT_H_
 
+#include <string>
+
 namespace AxWin {
 
 class CConfigInput
 {
 public:
        CConfigInput();
+       
+       ::std::string   mouse_device;
 };
 
 };     // namespace AxWin
index 952e2e9..f8b27ce 100644 (file)
@@ -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);
index 539410b..9ca7b42 100644 (file)
@@ -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);
 };
 
 };
index c120ed4..409658c 100644 (file)
@@ -9,6 +9,9 @@
 #include <input.hpp>
 #include <CCompositor.hpp>
 #include <algorithm>
+#include <acess/devices/joystick.h>
+#include <cerrno>
+#include <system_error>
 
 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 (file)
index 0000000..e5d670f
--- /dev/null
@@ -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 <stdint.h>
+
+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
+

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