From 8ba51a6f711c5466e060a5958cc15c31b2b2ac7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Mon, 10 Jun 2024 10:46:44 +0200 Subject: [PATCH] win32u: Call NtUserMapWindowPoints with per-monitor DPI from the drivers. --- dlls/user32/win.c | 3 ++- dlls/win32u/window.c | 3 +-- dlls/winemac.drv/event.c | 5 ++++- dlls/winemac.drv/window.c | 4 ++-- dlls/winex11.drv/event.c | 8 ++++---- dlls/winex11.drv/mouse.c | 2 +- dlls/winex11.drv/window.c | 2 +- dlls/wow64win/user.c | 2 ++ include/ntuser.h | 4 +++- 9 files changed, 20 insertions(+), 13 deletions(-) diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 2aa06b1dccb..7a552b48db4 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -760,7 +760,8 @@ HWND WINAPI ChildWindowFromPointEx( HWND parent, POINT pt, UINT flags ) */ INT WINAPI MapWindowPoints( HWND hwnd_from, HWND hwnd_to, POINT *points, UINT count ) { - return NtUserMapWindowPoints( hwnd_from, hwnd_to, points, count ); + UINT dpi = NTUSER_DPI_CONTEXT_GET_DPI( (UINT_PTR)GetThreadDpiAwarenessContext() ); + return NtUserMapWindowPoints( hwnd_from, hwnd_to, points, count, dpi ); } diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 162b9e370dc..c0ebeb6e8a9 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -5585,8 +5585,7 @@ ULONG_PTR WINAPI NtUserCallHwndParam( HWND hwnd, DWORD_PTR param, DWORD code ) case NtUserCallHwndParam_MapWindowPoints: { struct map_window_points_params *params = (void *)param; - return map_window_points( hwnd, params->hwnd_to, params->points, params->count, - get_thread_dpi() ); + return map_window_points( hwnd, params->hwnd_to, params->points, params->count, params->dpi ); } case NtUserCallHwndParam_MirrorRgn: diff --git a/dlls/winemac.drv/event.c b/dlls/winemac.drv/event.c index ab31c9d22c7..1628745f2b7 100644 --- a/dlls/winemac.drv/event.c +++ b/dlls/winemac.drv/event.c @@ -315,7 +315,10 @@ BOOL query_ime_char_rect(macdrv_query* query) if (NtUserGetGUIThreadInfo(0, &info)) { - NtUserMapWindowPoints(info.hwndCaret, 0, (POINT*)&info.rcCaret, 2); + /* NtUserGetGUIThreadInfo always return client-relative rcCaret in window DPI */ + NtUserMapWindowPoints(info.hwndCaret, 0, (POINT *)&info.rcCaret, 2, NtUserGetDpiForWindow(info.hwndCaret)); + NtUserLogicalToPerMonitorDPIPhysicalPoint(info.hwndCaret, (POINT *)&info.rcCaret.left); + NtUserLogicalToPerMonitorDPIPhysicalPoint(info.hwndCaret, (POINT *)&info.rcCaret.right); if (range->length && info.rcCaret.left == info.rcCaret.right) info.rcCaret.right++; query->ime_char_rect.rect = cgrect_from_rect(info.rcCaret); ret = TRUE; diff --git a/dlls/winemac.drv/window.c b/dlls/winemac.drv/window.c index 79f1e493eb7..32e544d733b 100644 --- a/dlls/winemac.drv/window.c +++ b/dlls/winemac.drv/window.c @@ -2230,7 +2230,7 @@ void macdrv_window_frame_changed(HWND hwnd, const macdrv_event *event) rect = rect_from_cgrect(event->window_frame_changed.frame); macdrv_mac_to_window_rect(data, &rect); - NtUserMapWindowPoints(0, parent, (POINT *)&rect, 2); + NtUserMapWindowPoints(0, parent, (POINT *)&rect, 2, 0 /* per-monitor DPI */); width = rect.right - rect.left; height = rect.bottom - rect.top; @@ -2465,7 +2465,7 @@ void macdrv_window_restore_requested(HWND hwnd, const macdrv_event *event) rect = rect_from_cgrect(event->window_restore_requested.frame); macdrv_mac_to_window_rect(data, &rect); - NtUserMapWindowPoints(0, parent, (POINT *)&rect, 2); + NtUserMapWindowPoints(0, parent, (POINT *)&rect, 2, 0 /* per-monitor DPI */); release_win_data(data); diff --git a/dlls/winex11.drv/event.c b/dlls/winex11.drv/event.c index 9cfbfc813de..3c4a5254b33 100644 --- a/dlls/winex11.drv/event.c +++ b/dlls/winex11.drv/event.c @@ -917,7 +917,7 @@ static BOOL X11DRV_Expose( HWND hwnd, XEvent *xev ) if (NtUserGetWindowLongW( data->hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) mirror_rect( &data->client_rect, &rect ); abs_rect = rect; - NtUserMapWindowPoints( hwnd, 0, (POINT *)&abs_rect, 2 ); + NtUserMapWindowPoints( hwnd, 0, (POINT *)&abs_rect, 2, 0 /* per-monitor DPI */ ); SERVER_START_REQ( update_window_zorder ) { @@ -1088,7 +1088,7 @@ static BOOL X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev ) else pos = root_to_virtual_screen( x, y ); X11DRV_X_to_window_rect( data, &rect, pos.x, pos.y, event->width, event->height ); - if (root_coords) NtUserMapWindowPoints( 0, parent, (POINT *)&rect, 2 ); + if (root_coords) NtUserMapWindowPoints( 0, parent, (POINT *)&rect, 2, 0 /* per-monitor DPI */ ); TRACE( "win %p/%lx new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n", hwnd, data->whole_window, (int)rect.left, (int)rect.top, @@ -1418,7 +1418,7 @@ static HWND find_drop_window( HWND hQueryWnd, LPPOINT lpPt ) if (!(NtUserGetWindowLongW( hQueryWnd, GWL_STYLE ) & WS_MINIMIZE)) { POINT pt = *lpPt; - NtUserMapWindowPoints( 0, hQueryWnd, &pt, 1 ); + NtUserMapWindowPoints( 0, hQueryWnd, &pt, 1, 0 /* per-monitor DPI */ ); NtUserGetClientRect( hQueryWnd, &tempRect, dpi ); if (PtInRect( &tempRect, pt)) @@ -1435,7 +1435,7 @@ static HWND find_drop_window( HWND hQueryWnd, LPPOINT lpPt ) if(!(NtUserGetWindowLongW( hQueryWnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES)) return 0; - NtUserMapWindowPoints( 0, hQueryWnd, lpPt, 1 ); + NtUserMapWindowPoints( 0, hQueryWnd, lpPt, 1, 0 /* per-monitor DPI */ ); return hQueryWnd; } diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c index dce3c888170..30444de0cdf 100644 --- a/dlls/winex11.drv/mouse.c +++ b/dlls/winex11.drv/mouse.c @@ -519,7 +519,7 @@ static void map_event_coords( HWND hwnd, Window window, Window event_root, int x if (NtUserGetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) pt.x = data->client_rect.right - data->client_rect.left - 1 - pt.x; - NtUserMapWindowPoints( hwnd, 0, &pt, 1 ); + NtUserMapWindowPoints( hwnd, 0, &pt, 1, 0 /* per-monitor DPI */ ); } release_win_data( data ); } diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c index ef2f80ba02f..d24b1c08184 100644 --- a/dlls/winex11.drv/window.c +++ b/dlls/winex11.drv/window.c @@ -2442,7 +2442,7 @@ void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect, if (escape.drawable) { POINT pt = { 0, 0 }; - NtUserMapWindowPoints( 0, parent, &pt, 1 ); + NtUserMapWindowPoints( 0, parent, &pt, 1, 0 /* per-monitor DPI */ ); escape.dc_rect = *win_rect; OffsetRect( &escape.dc_rect, pt.x, pt.y ); if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren; diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c index 35bcbdf6c3e..2f41820abbd 100644 --- a/dlls/wow64win/user.c +++ b/dlls/wow64win/user.c @@ -1717,12 +1717,14 @@ NTSTATUS WINAPI wow64_NtUserCallHwndParam( UINT *args ) ULONG hwnd_to; ULONG points; UINT count; + UINT dpi; } *params32 = UlongToPtr( param ); struct map_window_points_params params; params.hwnd_to = LongToHandle( params32->hwnd_to ); params.points = UlongToPtr( params32->points ); params.count = params32->count; + params.dpi = params32->dpi; return NtUserCallHwndParam( hwnd, (UINT_PTR)¶ms, code ); } diff --git a/include/ntuser.h b/include/ntuser.h index 507ed2e47ec..10afabfdc60 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -1414,14 +1414,16 @@ struct map_window_points_params HWND hwnd_to; POINT *points; UINT count; + UINT dpi; }; -static inline int NtUserMapWindowPoints( HWND hwnd_from, HWND hwnd_to, POINT *points, UINT count ) +static inline int NtUserMapWindowPoints( HWND hwnd_from, HWND hwnd_to, POINT *points, UINT count, UINT dpi ) { struct map_window_points_params params; params.hwnd_to = hwnd_to; params.points = points; params.count = count; + params.dpi = dpi; return NtUserCallHwndParam( hwnd_from, (UINT_PTR)¶ms, NtUserCallHwndParam_MapWindowPoints ); }