From: John Hodge Date: Tue, 21 Feb 2012 10:41:23 +0000 (+0800) Subject: Usermode/AxWin3 - Fixing mouse code to handle non 3 button mice :) X-Git-Tag: rel0.15~759 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=63b1cebc8d28cf2c3a104c49e0c63fec52fafd56;p=tpg%2Facess2.git Usermode/AxWin3 - Fixing mouse code to handle non 3 button mice :) --- diff --git a/Usermode/Applications/axwin3_src/WM/input.c b/Usermode/Applications/axwin3_src/WM/input.c index da5b0d33..c3443a9e 100644 --- a/Usermode/Applications/axwin3_src/WM/input.c +++ b/Usermode/Applications/axwin3_src/WM/input.c @@ -100,39 +100,50 @@ void Input_HandleSelect(fd_set *set) if(FD_ISSET(giMouseFD, set)) { int i; - struct sMouseInfo { + struct sMouseAxis { + int16_t MinValue; + int16_t MaxValue; + int16_t CurValue; + uint16_t CursorPos; + } *axies; + uint8_t *buttons; + struct sMouseHdr { uint16_t NAxies; uint16_t NButtons; - struct sMouseAxis { - int16_t MinValue; - int16_t MaxValue; - int16_t CurValue; - uint16_t CursorPos; - } Axies[2]; - uint8_t Buttons[3]; - } mouseinfo; - + } *mouseinfo; + char data[sizeof(*mouseinfo) + sizeof(*axies)*3 + 5]; + + mouseinfo = (void*)data; + seek(giMouseFD, 0, SEEK_SET); - if( read(giMouseFD, &mouseinfo, sizeof(mouseinfo)) != sizeof(mouseinfo) ) - { - // Not a 3 button mouse, oops + i = read(giMouseFD, data, sizeof(data)); + i -= sizeof(*mouseinfo); + if( i < 0 ) return ; - } + if( i < sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons ) + return ; + + // What? No X/Y? + if( mouseinfo->NAxies < 2 ) + return ; + + axies = (void*)( mouseinfo + 1 ); + buttons = (void*)( axies + mouseinfo->NAxies ); // Handle movement - Video_SetCursorPos( mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos ); + Video_SetCursorPos( axies[0].CursorPos, axies[1].CursorPos ); WM_Input_MouseMoved( giInput_MouseX, giInput_MouseY, - mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos + axies[0].CursorPos, axies[1].CursorPos ); - giInput_MouseX = mouseinfo.Axies[0].CursorPos; - giInput_MouseY = mouseinfo.Axies[1].CursorPos; + giInput_MouseX = axies[0].CursorPos; + giInput_MouseY = axies[1].CursorPos; - for( i = 0; i < mouseinfo.NButtons; i ++ ) + for( i = 0; i < mouseinfo->NButtons; i ++ ) { - int bit = 1 << i; - int cur = mouseinfo.Buttons[i] > 128; + int bit = 1 << i; + int cur = buttons[i] > 128; if( !!(giInput_MouseButtonState & bit) != cur ) {