@@ -747,7 +747,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
747747 if ((rawmouse -> usFlags & 0x01 ) == MOUSE_MOVE_RELATIVE ) {
748748 SDL_SendMouseMotion (data -> window , mouseID , 1 , (int )rawmouse -> lLastX , (int )rawmouse -> lLastY );
749749 } else if (rawmouse -> lLastX || rawmouse -> lLastY ) {
750- /* This is absolute motion, probably over RDP
750+ /* This is absolute motion, either using a tablet or mouse over RDP
751751
752752 Notes on how RDP appears to work, as of Windows 10 2004:
753753 - SetCursorPos() calls are cached, with multiple calls coalesced into a single call that's sent to the RDP client. If the last call to SetCursorPos() has the same value as the last one that was sent to the client, it appears to be ignored and not sent. This means that we need to jitter the SetCursorPos() position slightly in order for the recentering to work correctly.
@@ -757,17 +757,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
757757
758758 We handle this by creating a safe area within the application window, and when the mouse leaves that safe area, we warp back to the opposite side. Any single motion > 50% of the safe area is assumed to be a warp and ignored.
759759 */
760- /* synthesize relative moves from the abs position */
760+ SDL_bool remote_desktop = GetSystemMetrics ( SM_REMOTESESSION ) ? SDL_TRUE : SDL_FALSE ;
761761 SDL_bool virtual_desktop = (rawmouse -> usFlags & MOUSE_VIRTUAL_DESKTOP ) ? SDL_TRUE : SDL_FALSE ;
762+ SDL_bool normalized_coordinates = ((rawmouse -> usFlags & 0x40 ) == 0 ) ? SDL_TRUE : SDL_FALSE ;
762763 int w = GetSystemMetrics (virtual_desktop ? SM_CXVIRTUALSCREEN : SM_CXSCREEN );
763764 int h = GetSystemMetrics (virtual_desktop ? SM_CYVIRTUALSCREEN : SM_CYSCREEN );
764- int x = (int )(((float )rawmouse -> lLastX / 65535.0f ) * w );
765- int y = (int )(((float )rawmouse -> lLastY / 65535.0f ) * h );
765+ int x = normalized_coordinates ? (int )(((float )rawmouse -> lLastX / 65535.0f ) * w ) : ( int ) rawmouse -> lLastX ;
766+ int y = normalized_coordinates ? (int )(((float )rawmouse -> lLastY / 65535.0f ) * h ) : ( int ) rawmouse -> lLastY ;
766767 int relX , relY ;
767- RECT screenRect ;
768- RECT hwndRect ;
769- RECT boundsRect ;
770- int boundsWidth , boundsHeight ;
771768
772769 /* Calculate relative motion */
773770 if (data -> last_raw_mouse_position .x == 0 && data -> last_raw_mouse_position .y == 0 ) {
@@ -777,58 +774,74 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
777774 relX = (int )(x - data -> last_raw_mouse_position .x );
778775 relY = (int )(y - data -> last_raw_mouse_position .y );
779776
780- /* Calculate screen rect */
781- screenRect .left = 0 ;
782- screenRect .right = w ;
783- screenRect .top = 0 ;
784- screenRect .bottom = h ;
785-
786- /* Calculate client rect */
787- GetClientRect (hwnd , & hwndRect );
788- ClientToScreen (hwnd , (LPPOINT ) & hwndRect );
789- ClientToScreen (hwnd , (LPPOINT ) & hwndRect + 1 );
790-
791- /* Calculate bounds rect */
792- IntersectRect (& boundsRect , & screenRect , & hwndRect );
793- InflateRect (& boundsRect , -32 , -32 );
794- boundsWidth = (boundsRect .right - boundsRect .left );
795- boundsHeight = (boundsRect .bottom - boundsRect .top );
796-
797- if ((boundsWidth > 0 && SDL_abs (relX ) > (boundsWidth / 2 )) ||
798- (boundsHeight > 0 && SDL_abs (relY ) > (boundsHeight / 2 ))) {
799- /* Expected motion for warping below, ignore this */
800- } else {
801- SDL_SendMouseMotion (data -> window , mouseID , 1 , relX , relY );
802-
803- if (x < boundsRect .left || x > boundsRect .right ||
804- y < boundsRect .top || y > boundsRect .bottom ) {
805- /* Warp back to the opposite side, assuming more motion in the current direction */
806- int warpX ;
807- int warpY ;
808-
809- if (x < boundsRect .left ) {
810- warpX = boundsRect .right ;
811- } else if (x > boundsRect .right ) {
812- warpX = boundsRect .left ;
813- } else {
814- warpX = x ;
815- }
816-
817- if (y < boundsRect .top ) {
818- warpY = boundsRect .bottom ;
819- } else if (y > boundsRect .bottom ) {
820- warpY = boundsRect .top ;
821- } else {
822- warpY = y ;
777+ if (remote_desktop ) {
778+ RECT screenRect ;
779+ RECT hwndRect ;
780+ RECT boundsRect ;
781+ int boundsWidth , boundsHeight ;
782+
783+ /* Calculate screen rect */
784+ screenRect .left = 0 ;
785+ screenRect .right = w ;
786+ screenRect .top = 0 ;
787+ screenRect .bottom = h ;
788+
789+ /* Calculate client rect */
790+ GetClientRect (hwnd , & hwndRect );
791+ ClientToScreen (hwnd , (LPPOINT ) & hwndRect );
792+ ClientToScreen (hwnd , (LPPOINT ) & hwndRect + 1 );
793+
794+ /* Calculate bounds rect */
795+ IntersectRect (& boundsRect , & screenRect , & hwndRect );
796+ InflateRect (& boundsRect , -32 , -32 );
797+ boundsWidth = (boundsRect .right - boundsRect .left );
798+ boundsHeight = (boundsRect .bottom - boundsRect .top );
799+
800+ if ((boundsWidth > 0 && SDL_abs (relX ) > (boundsWidth / 2 )) ||
801+ (boundsHeight > 0 && SDL_abs (relY ) > (boundsHeight / 2 ))) {
802+ /* Expected motion for warping below, ignore this */
803+ } else {
804+ SDL_SendMouseMotion (data -> window , mouseID , 1 , relX , relY );
805+
806+ if (x < boundsRect .left || x > boundsRect .right ||
807+ y < boundsRect .top || y > boundsRect .bottom ) {
808+ /* Warp back to the opposite side, assuming more motion in the current direction */
809+ int warpX ;
810+ int warpY ;
811+
812+ if (x < boundsRect .left ) {
813+ warpX = boundsRect .right ;
814+ } else if (x > boundsRect .right ) {
815+ warpX = boundsRect .left ;
816+ } else {
817+ warpX = x ;
818+ }
819+
820+ if (y < boundsRect .top ) {
821+ warpY = boundsRect .bottom ;
822+ } else if (y > boundsRect .bottom ) {
823+ warpY = boundsRect .top ;
824+ } else {
825+ warpY = y ;
826+ }
827+ SetCursorPos (warpX , warpY );
823828 }
824- SetCursorPos (warpX , warpY );
829+ }
830+ } else {
831+ const int MAXIMUM_TABLET_RELATIVE_MOTION = 32 ;
832+ if (SDL_abs (relX ) > MAXIMUM_TABLET_RELATIVE_MOTION ||
833+ SDL_abs (relY ) > MAXIMUM_TABLET_RELATIVE_MOTION ) {
834+ /* Ignore this motion, probably a pen lift and drop */
835+ } else {
836+ SDL_SendMouseMotion (data -> window , mouseID , 1 , relX , relY );
825837 }
826838 }
827839
828840 data -> last_raw_mouse_position .x = x ;
829841 data -> last_raw_mouse_position .y = y ;
830842 }
831843 WIN_CheckRawMouseButtons (rawmouse -> usButtonFlags , data , mouseID );
844+
832845 } else if (isCapture ) {
833846 /* we check for where Windows thinks the system cursor lives in this case, so we don't really lose mouse accel, etc. */
834847 POINT pt ;
0 commit comments