Usermode/AxWin4 - Server implementation runnable
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / input.cpp
index 7519b87..c120ed4 100644 (file)
@@ -23,7 +23,8 @@ CInput::CInput(const ::AxWin::CConfigInput& config, CCompositor& compositor):
 int CInput::FillSelect(::fd_set& rfds)
 {
        FD_SET(m_keyboardFD, &rfds);
-       FD_SET(m_mouseFD, &rfds);
+       if( m_mouseFD != -1 )
+               FD_SET(m_mouseFD, &rfds);
        return ::std::max(m_keyboardFD, m_mouseFD)+1;
 }
 
@@ -31,10 +32,38 @@ void CInput::HandleSelect(::fd_set& rfds)
 {
        if( FD_ISSET(m_keyboardFD, &rfds) )
        {
-               // TODO: Read keystroke and handle
+               uint32_t        codepoint;
+               static uint32_t scancode;
+               #define KEY_CODEPOINT_MASK      0x3FFFFFFF
+               
+               size_t readlen = _SysRead(m_keyboardFD, &codepoint, sizeof(codepoint));
+               if( readlen != sizeof(codepoint) )
+               {
+                       // oops, error
+                       _SysDebug("Terminal read failed? (%i != %i)", readlen, sizeof(codepoint));
+               }
+       
+//             _SysDebug("Keypress 0x%x", codepoint);
+       
+               switch(codepoint & 0xC0000000)
+               {
+               case 0x00000000:        // Key pressed
+                       //WM_Input_KeyDown(codepoint & KEY_CODEPOINT_MASK, scancode);
+               case 0x80000000:        // Key release
+                       //WM_Input_KeyFire(codepoint & KEY_CODEPOINT_MASK, scancode);
+                       scancode = 0;
+                       break;
+               case 0x40000000:        // Key refire
+                       //WM_Input_KeyUp(codepoint & KEY_CODEPOINT_MASK, scancode);
+                       scancode = 0;
+                       break;
+               case 0xC0000000:        // Raw scancode
+                       scancode = codepoint & KEY_CODEPOINT_MASK;
+                       break;
+               }
        }
        
-       if( FD_ISSET(m_mouseFD, &rfds) )
+       if( m_mouseFD != -1 && FD_ISSET(m_mouseFD, &rfds) )
        {
                // TODO: Read mouse event and handle
        }

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