From 3f1ee7db7235bb2fe06c60db0c07ff79f4ed74b3 Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Fri, 15 Oct 2021 09:56:51 +0800 Subject: [PATCH 42/51] winex11.drv: Add a get_virtual_screen_rect() to get virtual screen size in per-monitor DPI aware context. To: wine-devel@winehq.org Otherwise, it may report a scaled rectangle when running in DPI unaware context. Signed-off-by: Zhiyi Zhang --- dlls/winex11.drv/desktop.c | 2 +- dlls/winex11.drv/display.c | 20 ++++++++++++++++---- dlls/winex11.drv/init.c | 2 +- dlls/winex11.drv/mouse.c | 4 ++-- dlls/winex11.drv/window.c | 6 +++--- dlls/winex11.drv/x11drv.h | 2 ++ 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/dlls/winex11.drv/desktop.c b/dlls/winex11.drv/desktop.c index a89824772d0..64e5b5ab8d9 100644 --- a/dlls/winex11.drv/desktop.c +++ b/dlls/winex11.drv/desktop.c @@ -421,7 +421,7 @@ void X11DRV_resize_desktop( BOOL send_display_change ) HWND hwnd = GetDesktopWindow(); INT width, height; - virtual_rect = NtUserGetVirtualScreenRect(); + virtual_rect = get_virtual_screen_rect(); primary_rect = NtUserGetPrimaryMonitorRect(); width = primary_rect.right; height = primary_rect.bottom; diff --git a/dlls/winex11.drv/display.c b/dlls/winex11.drv/display.c index 3c251da8f1e..be4816970b0 100644 --- a/dlls/winex11.drv/display.c +++ b/dlls/winex11.drv/display.c @@ -44,7 +44,7 @@ void release_display_device_init_mutex(HANDLE mutex) POINT virtual_screen_to_root(INT x, INT y) { - RECT virtual = NtUserGetVirtualScreenRect(); + RECT virtual = get_virtual_screen_rect(); POINT pt; pt.x = x - virtual.left; @@ -54,7 +54,7 @@ POINT virtual_screen_to_root(INT x, INT y) POINT root_to_virtual_screen(INT x, INT y) { - RECT virtual = NtUserGetVirtualScreenRect(); + RECT virtual = get_virtual_screen_rect(); POINT pt; pt.x = x + virtual.left; @@ -62,6 +62,18 @@ POINT root_to_virtual_screen(INT x, INT y) return pt; } +/* Get virtual screen rectangle in DPI per-monitor aware context */ +RECT get_virtual_screen_rect(void) +{ + DPI_AWARENESS_CONTEXT context; + RECT virtual; + + context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); + virtual = NtUserGetVirtualScreenRect(); + SetThreadDpiAwarenessContext(context); + return virtual; +} + /* Get the primary monitor rect from the host system */ RECT get_host_primary_monitor_rect(void) { @@ -204,9 +216,9 @@ void X11DRV_DisplayDevices_Update(BOOL send_display_change) HWND foreground; UINT mask = 0; - old_virtual_rect = NtUserGetVirtualScreenRect(); + old_virtual_rect = get_virtual_screen_rect(); X11DRV_DisplayDevices_Init(TRUE); - new_virtual_rect = NtUserGetVirtualScreenRect(); + new_virtual_rect = get_virtual_screen_rect(); /* Calculate XReconfigureWMWindow() mask */ if (old_virtual_rect.left != new_virtual_rect.left) diff --git a/dlls/winex11.drv/init.c b/dlls/winex11.drv/init.c index 8f4bb9fd7e9..6f24e1bf370 100644 --- a/dlls/winex11.drv/init.c +++ b/dlls/winex11.drv/init.c @@ -91,7 +91,7 @@ static BOOL CDECL X11DRV_CreateDC( PHYSDEV *pdev, LPCWSTR device, LPCWSTR output physDev->depth = default_visual.depth; physDev->color_shifts = &X11DRV_PALETTE_default_shifts; - physDev->dc_rect = NtUserGetVirtualScreenRect(); + physDev->dc_rect = get_virtual_screen_rect(); OffsetRect( &physDev->dc_rect, -physDev->dc_rect.left, -physDev->dc_rect.top ); push_dc_driver( pdev, &physDev->dev, &x11drv_funcs.dc_funcs ); if (xrender_funcs && !xrender_funcs->pCreateDC( pdev, device, output, initData )) return FALSE; diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c index 65e04d6cab5..fedc2c197da 100644 --- a/dlls/winex11.drv/mouse.c +++ b/dlls/winex11.drv/mouse.c @@ -1540,7 +1540,7 @@ BOOL X11DRV_GetCursorPos(LPPOINT pos) */ BOOL X11DRV_ClipCursor( LPCRECT clip ) { - RECT virtual_rect = NtUserGetVirtualScreenRect(); + RECT virtual_rect = get_virtual_screen_rect(); if (!clip) clip = &virtual_rect; @@ -1853,7 +1853,7 @@ static BOOL map_raw_event_coords( XIRawEvent *event, INPUT *input ) } if (event->deviceid != thread_data->xi2_current_slave) return FALSE; - virtual_rect = NtUserGetVirtualScreenRect(); + virtual_rect = get_virtual_screen_rect(); if (x->max <= x->min) x_scale = 1; else x_scale = (virtual_rect.right - virtual_rect.left) / (x->max - x->min); diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c index d81d42e4b70..c405efaa3b5 100644 --- a/dlls/winex11.drv/window.c +++ b/dlls/winex11.drv/window.c @@ -1886,7 +1886,7 @@ BOOL X11DRV_CreateDesktopWindow( HWND hwnd ) if (!width && !height) /* not initialized yet */ { - RECT rect = NtUserGetVirtualScreenRect(); + RECT rect = get_virtual_screen_rect(); SERVER_START_REQ( set_window_pos ) { @@ -2255,7 +2255,7 @@ void X11DRV_ReleaseDC( HWND hwnd, HDC hdc ) escape.code = X11DRV_SET_DRAWABLE; escape.drawable = root_window; escape.mode = IncludeInferiors; - escape.dc_rect = NtUserGetVirtualScreenRect(); + escape.dc_rect = get_virtual_screen_rect(); OffsetRect( &escape.dc_rect, -2 * escape.dc_rect.left, -2 * escape.dc_rect.top ); NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL ); } @@ -2370,7 +2370,7 @@ done: static inline BOOL get_surface_rect( const RECT *visible_rect, RECT *surface_rect ) { - *surface_rect = NtUserGetVirtualScreenRect(); + *surface_rect = get_virtual_screen_rect(); if (!IntersectRect( surface_rect, surface_rect, visible_rect )) return FALSE; OffsetRect( surface_rect, -visible_rect->left, -visible_rect->top ); diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index 7865ca2c4c0..e245b537a48 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -706,6 +706,8 @@ extern RECT get_work_area( const RECT *monitor_rect ) DECLSPEC_HIDDEN; extern void xinerama_get_fullscreen_monitors( const RECT *rect, long *indices ) DECLSPEC_HIDDEN; extern void xinerama_init( unsigned int width, unsigned int height ) DECLSPEC_HIDDEN; +extern RECT get_virtual_screen_rect(void) DECLSPEC_HIDDEN; + #define DEPTH_COUNT 3 extern const unsigned int *depths DECLSPEC_HIDDEN; -- 2.32.0