Alexandre Julliard : user32: Scale coordinates in Get/SetCursorPos() based on DPI awareness.

Alexandre Julliard julliard at winehq.org
Mon Aug 27 16:18:15 CDT 2018


Module: wine
Branch: master
Commit: 910f3ed4daaac96842159cfeef0b64ed2e533ace
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=910f3ed4daaac96842159cfeef0b64ed2e533ace

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Aug 27 14:19:13 2018 +0200

user32: Scale coordinates in Get/SetCursorPos() based on DPI awareness.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/input.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/input.c b/dlls/user32/input.c
index ab9b70f..9d87393 100644
--- a/dlls/user32/input.c
+++ b/dlls/user32/input.c
@@ -240,6 +240,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetCursorPos( POINT *pt )
 {
     BOOL ret;
     DWORD last_change;
+    UINT dpi;
 
     if (!pt) return FALSE;
 
@@ -256,6 +257,13 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetCursorPos( POINT *pt )
 
     /* query new position from graphics driver if we haven't updated recently */
     if (ret && GetTickCount() - last_change > 100) ret = USER_Driver->pGetCursorPos( pt );
+    if (ret && (dpi = get_thread_dpi()))
+    {
+        DPI_AWARENESS_CONTEXT context;
+        context = SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
+        *pt = map_dpi_point( *pt, get_monitor_dpi( MonitorFromPoint( *pt, MONITOR_DEFAULTTOPRIMARY )), dpi );
+        SetThreadDpiAwarenessContext( context );
+    }
     return ret;
 }
 
@@ -289,14 +297,19 @@ BOOL WINAPI GetCursorInfo( PCURSORINFO pci )
  */
 BOOL WINAPI DECLSPEC_HOTPATCH SetCursorPos( INT x, INT y )
 {
+    POINT pt = { x, y };
     BOOL ret;
     INT prev_x, prev_y, new_x, new_y;
+    UINT dpi;
+
+    if ((dpi = get_thread_dpi()))
+        pt = map_dpi_point( pt, dpi, get_monitor_dpi( MonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY )));
 
     SERVER_START_REQ( set_cursor )
     {
         req->flags = SET_CURSOR_POS;
-        req->x     = x;
-        req->y     = y;
+        req->x     = pt.x;
+        req->y     = pt.y;
         if ((ret = !wine_server_call( req )))
         {
             prev_x = reply->prev_x;




More information about the wine-cvs mailing list