+ 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;
+ }
+ }