-- v4: win32u: Only keep DPI awareness context with window objects. win32u: Fix SetThreadDpiAwarenessContext. win32u: Pass the DPI awareness context in win_proc_params. win32u: Get the thread DPI context instead of the awareness.
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/user32/sysparams.c | 10 +++++----- dlls/win32u/sysparams.c | 32 +++++++++++++------------------- dlls/win32u/win32u_private.h | 2 +- dlls/win32u/window.c | 2 +- include/ntuser.h | 2 +- 5 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 0248a4d905f..7208535186a 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -757,7 +757,7 @@ DPI_AWARENESS_CONTEXT WINAPI GetThreadDpiAwarenessContext(void) struct ntuser_thread_info *info = NtUserGetThreadInfo(); ULONG context;
- if (info->dpi_awareness) return ULongToHandle( info->dpi_awareness ); + if (info->dpi_context) return ULongToHandle( info->dpi_context );
context = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ); return UlongToHandle( NTUSER_DPI_CONTEXT_GET_AWARENESS( context ) | 0x10 ); @@ -777,15 +777,15 @@ DPI_AWARENESS_CONTEXT WINAPI SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT SetLastError( ERROR_INVALID_PARAMETER ); return 0; } - if (!(prev = info->dpi_awareness)) + if (!(prev = info->dpi_context)) { ULONG process_ctx = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ); prev = NTUSER_DPI_CONTEXT_GET_AWARENESS( process_ctx ) | 0x80000010; /* restore to process default */ } - if (((ULONG_PTR)context & ~(ULONG_PTR)0x33) == 0x80000000) info->dpi_awareness = 0; + if (((ULONG_PTR)context & ~(ULONG_PTR)0x33) == 0x80000000) info->dpi_context = 0; else if (context == DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 || context == (DPI_AWARENESS_CONTEXT)0x22) - info->dpi_awareness = 0x22; - else info->dpi_awareness = val | 0x10; + info->dpi_context = 0x22; + else info->dpi_context = val | 0x10; return ULongToHandle( prev ); }
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 54f514f557e..2f7f8e27ff3 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -39,6 +39,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(system);
+static LONG dpi_context; /* process DPI awareness context */
static HKEY video_key, enum_key, control_key, config_key, volatile_base_key;
@@ -2159,18 +2160,13 @@ static DPI_AWARENESS get_awareness_from_dpi_awareness_context( DPI_AWARENESS_CON } }
-/********************************************************************** - * get_thread_dpi_awareness - */ -DPI_AWARENESS get_thread_dpi_awareness(void) +UINT get_thread_dpi_awareness_context(void) { struct ntuser_thread_info *info = NtUserGetThreadInfo(); - ULONG_PTR context = info->dpi_awareness; - - if (context == 0) /* process default */ - return NtUserGetProcessDpiAwarenessContext( NULL ) & 3; + UINT context;
- return get_awareness_from_dpi_awareness_context((DPI_AWARENESS_CONTEXT)context); + if (!(context = info->dpi_context)) context = ReadNoFence( &dpi_context ); + return context ? context : NTUSER_DPI_UNAWARE; }
DWORD get_process_layout(void) @@ -2183,7 +2179,7 @@ DWORD get_process_layout(void) */ UINT get_thread_dpi(void) { - switch (get_thread_dpi_awareness()) + switch (NTUSER_DPI_CONTEXT_GET_AWARENESS( get_thread_dpi_awareness_context() )) { case DPI_AWARENESS_UNAWARE: return USER_DEFAULT_SCREEN_DPI; case DPI_AWARENESS_SYSTEM_AWARE: return system_dpi; @@ -2194,7 +2190,8 @@ UINT get_thread_dpi(void) /* see GetDpiForSystem */ UINT get_system_dpi(void) { - if (get_thread_dpi_awareness() == DPI_AWARENESS_UNAWARE) return USER_DEFAULT_SCREEN_DPI; + DPI_AWARENESS awareness = NTUSER_DPI_CONTEXT_GET_AWARENESS( get_thread_dpi_awareness_context() ); + if (awareness == DPI_AWARENESS_UNAWARE) return USER_DEFAULT_SCREEN_DPI; return system_dpi; }
@@ -2209,15 +2206,15 @@ UINT set_thread_dpi_awareness_context( UINT context ) RtlSetLastWin32Error( ERROR_INVALID_PARAMETER ); return 0; } - if (!(prev = info->dpi_awareness)) + if (!(prev = info->dpi_context)) { prev = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ) & 3; prev |= 0x80000010; /* restore to process default */ } - if (((ULONG_PTR)context & ~(ULONG_PTR)0x33) == 0x80000000) info->dpi_awareness = 0; + if (((ULONG_PTR)context & ~(ULONG_PTR)0x33) == 0x80000000) info->dpi_context = 0; else if (context == HandleToUlong( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ) || context == 0x22) - info->dpi_awareness = 0x22; - else info->dpi_awareness = val | 0x10; + info->dpi_context = 0x22; + else info->dpi_context = val | 0x10; return prev; }
@@ -3732,7 +3729,7 @@ BOOL WINAPI NtUserGetDpiForMonitor( HMONITOR monitor, UINT type, UINT *x, UINT * RtlSetLastWin32Error( ERROR_INVALID_ADDRESS ); return FALSE; } - switch (get_thread_dpi_awareness()) + switch (NTUSER_DPI_CONTEXT_GET_AWARENESS( get_thread_dpi_awareness_context() )) { case DPI_AWARENESS_UNAWARE: *x = *y = USER_DEFAULT_SCREEN_DPI; break; case DPI_AWARENESS_SYSTEM_AWARE: *x = *y = system_dpi; break; @@ -6225,9 +6222,6 @@ BOOL WINAPI NtUserSetSysColors( INT count, const INT *colors, const COLORREF *va return TRUE; }
- -static LONG dpi_context; - /*********************************************************************** * NtUserSetProcessDpiAwarenessContext (win32u.@) */ diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index 222db6fb5f7..aecd60bae63 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -175,7 +175,7 @@ extern UINT get_system_dpi(void); extern int get_system_metrics( int index ); extern UINT get_thread_dpi(void); extern UINT set_thread_dpi_awareness_context( UINT context ); -extern DPI_AWARENESS get_thread_dpi_awareness(void); +extern UINT get_thread_dpi_awareness_context(void); extern RECT get_virtual_screen_rect( UINT dpi ); extern BOOL is_exiting_thread( DWORD tid ); extern POINT map_dpi_point( POINT pt, UINT dpi_from, UINT dpi_to ); diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 321c81069c4..f7026654a50 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -4911,7 +4911,7 @@ static WND *create_window_handle( HWND parent, HWND owner, UNICODE_STRING *name, HINSTANCE instance, BOOL ansi, DWORD style, DWORD ex_style ) { - DPI_AWARENESS awareness = get_thread_dpi_awareness(); + DPI_AWARENESS awareness = NTUSER_DPI_CONTEXT_GET_AWARENESS( get_thread_dpi_awareness_context() ); HWND handle = 0, full_parent = 0, full_owner = 0; struct tagCLASS *class = NULL; int extra_bytes = 0; diff --git a/include/ntuser.h b/include/ntuser.h index 392ab21ec0d..b58413ac4db 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -83,7 +83,7 @@ struct ntuser_thread_info UINT receive_flags; /* currently received message flags */ UINT top_window; /* desktop window */ UINT msg_window; /* HWND_MESSAGE parent window */ - DPI_AWARENESS dpi_awareness; /* DPI awareness */ + UINT dpi_context; /* DPI awareness context */ UINT default_imc; /* default input context */ UINT64 client_imm; /* client IMM thread info */ UINT64 wmchar_data; /* client data for WM_CHAR mappings */
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/user32/winproc.c | 2 +- dlls/win32u/message.c | 4 ++-- dlls/wow64win/user.c | 4 ++-- include/ntuser.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/dlls/user32/winproc.c b/dlls/user32/winproc.c index 4525f604beb..5678e75b4e9 100644 --- a/dlls/user32/winproc.c +++ b/dlls/user32/winproc.c @@ -698,7 +698,7 @@ static LRESULT WINPROC_CallProcWtoA( winproc_callback_t callback, HWND hwnd, UIN
LRESULT dispatch_win_proc_params( struct win_proc_params *params ) { - DPI_AWARENESS_CONTEXT context = SetThreadDpiAwarenessContext( params->dpi_awareness ); + DPI_AWARENESS_CONTEXT context = SetThreadDpiAwarenessContext( ULongToHandle( params->dpi_context ) ); LRESULT result = 0;
if (!params->ansi) diff --git a/dlls/win32u/message.c b/dlls/win32u/message.c index bf393e2b7c9..877be545810 100644 --- a/dlls/win32u/message.c +++ b/dlls/win32u/message.c @@ -379,7 +379,7 @@ static BOOL init_win_proc_params( struct win_proc_params *params, HWND hwnd, UIN params->lparam = lparam; params->ansi = params->ansi_dst = ansi; params->mapping = WMCHAR_MAP_CALLWINDOWPROC; - params->dpi_awareness = ULongToHandle( get_window_dpi_awareness_context( params->hwnd ) ); + params->dpi_context = get_window_dpi_awareness_context( params->hwnd ); get_winproc_params( params, TRUE ); return TRUE; } @@ -410,7 +410,7 @@ static BOOL init_window_call_params( struct win_proc_params *params, HWND hwnd, params->lparam = lParam; params->ansi = ansi; params->mapping = mapping; - params->dpi_awareness = ULongToHandle( get_window_dpi_awareness_context( params->hwnd ) ); + params->dpi_context = get_window_dpi_awareness_context( params->hwnd ); get_winproc_params( params, !is_dialog ); return TRUE; } diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c index 9a293826ba9..33d4d786714 100644 --- a/dlls/wow64win/user.c +++ b/dlls/wow64win/user.c @@ -355,7 +355,7 @@ struct win_proc_params32 BOOL ansi; BOOL ansi_dst; enum wm_char_mapping mapping; - ULONG dpi_awareness; + ULONG dpi_context; ULONG procA; ULONG procW; }; @@ -471,7 +471,7 @@ static void win_proc_params_64to32( const struct win_proc_params *src, struct wi params.ansi = src->ansi; params.ansi_dst = src->ansi_dst; params.mapping = src->mapping; - params.dpi_awareness = HandleToUlong( src->dpi_awareness ); + params.dpi_context = src->dpi_context; params.procA = PtrToUlong( src->procA ); params.procW = PtrToUlong( src->procW ); memcpy( dst, ¶ms, sizeof(params) ); diff --git a/include/ntuser.h b/include/ntuser.h index b58413ac4db..88453c46749 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -160,7 +160,7 @@ struct win_proc_params BOOL ansi; BOOL ansi_dst; enum wm_char_mapping mapping; - DPI_AWARENESS_CONTEXT dpi_awareness; + UINT dpi_context; WNDPROC procA; WNDPROC procW; };
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/user32/sysparams.c | 67 +++++++++---------------- dlls/user32/tests/sysparams.c | 94 +++++++++++++++-------------------- dlls/win32u/sysparams.c | 49 ++++++------------ dlls/win32u/tests/win32u.c | 3 +- dlls/win32u/win32u_private.h | 1 + dlls/win32u/window.c | 4 +- dlls/wineandroid.drv/window.c | 2 +- include/ntuser.h | 4 +- 8 files changed, 87 insertions(+), 137 deletions(-)
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 7208535186a..2ec970fe1ac 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -619,6 +619,25 @@ static BOOL is_valid_dpi_awareness_context( UINT context, UINT dpi ) return FALSE; }
+/* keep in sync with win32u */ +UINT set_thread_dpi_awareness_context( UINT context ) +{ + struct ntuser_thread_info *info = NtUserGetThreadInfo(); + UINT prev; + + if (!is_valid_dpi_awareness_context( context, system_dpi )) + { + RtlSetLastWin32Error( ERROR_INVALID_PARAMETER ); + return 0; + } + + if (!(prev = info->dpi_context)) prev = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ) | NTUSER_DPI_CONTEXT_FLAG_PROCESS; + if (NTUSER_DPI_CONTEXT_GET_FLAGS( context ) & NTUSER_DPI_CONTEXT_FLAG_PROCESS) info->dpi_context = 0; + else info->dpi_context = context; + + return prev; +} + /********************************************************************** * SetProcessDpiAwarenessContext (USER32.@) */ @@ -672,26 +691,9 @@ BOOL WINAPI AreDpiAwarenessContextsEqual( DPI_AWARENESS_CONTEXT ctx1, DPI_AWAREN */ DPI_AWARENESS WINAPI GetAwarenessFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT context ) { - switch ((ULONG_PTR)context) - { - case 0x10: - case 0x11: - case 0x12: - case 0x22: - case 0x80000010: - case 0x80000011: - case 0x80000012: - case 0x80000022: - return (ULONG_PTR)context & 3; - case (ULONG_PTR)DPI_AWARENESS_CONTEXT_UNAWARE: - case (ULONG_PTR)DPI_AWARENESS_CONTEXT_SYSTEM_AWARE: - case (ULONG_PTR)DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE: - return ~(ULONG_PTR)context; - case (ULONG_PTR)DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2: - return ~(ULONG_PTR)DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE; - default: - return DPI_AWARENESS_INVALID; - } + UINT value = get_ntuser_dpi_context( context ); + if (!is_valid_dpi_awareness_context( value, 0 )) return DPI_AWARENESS_INVALID; + return NTUSER_DPI_CONTEXT_GET_AWARENESS( value ); }
/*********************************************************************** @@ -755,38 +757,17 @@ UINT WINAPI GetDpiForSystem(void) DPI_AWARENESS_CONTEXT WINAPI GetThreadDpiAwarenessContext(void) { struct ntuser_thread_info *info = NtUserGetThreadInfo(); - ULONG context;
if (info->dpi_context) return ULongToHandle( info->dpi_context ); - - context = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ); - return UlongToHandle( NTUSER_DPI_CONTEXT_GET_AWARENESS( context ) | 0x10 ); + return ULongToHandle( NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ) ); }
/********************************************************************** * SetThreadDpiAwarenessContext (USER32.@) - * copied into win32u, make sure to keep that in sync */ DPI_AWARENESS_CONTEXT WINAPI SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT context ) { - struct ntuser_thread_info *info = NtUserGetThreadInfo(); - DPI_AWARENESS prev, val = GetAwarenessFromDpiAwarenessContext( context ); - - if (val == DPI_AWARENESS_INVALID) - { - SetLastError( ERROR_INVALID_PARAMETER ); - return 0; - } - if (!(prev = info->dpi_context)) - { - ULONG process_ctx = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ); - prev = NTUSER_DPI_CONTEXT_GET_AWARENESS( process_ctx ) | 0x80000010; /* restore to process default */ - } - if (((ULONG_PTR)context & ~(ULONG_PTR)0x33) == 0x80000000) info->dpi_context = 0; - else if (context == DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 || context == (DPI_AWARENESS_CONTEXT)0x22) - info->dpi_context = 0x22; - else info->dpi_context = val | 0x10; - return ULongToHandle( prev ); + return ULongToHandle( set_thread_dpi_awareness_context( get_ntuser_dpi_context( context ) ) ); }
/********************************************************************** diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c index d895a184d13..930d6ac6c5b 100644 --- a/dlls/user32/tests/sysparams.c +++ b/dlls/user32/tests/sysparams.c @@ -224,8 +224,7 @@ static DWORD get_real_dpi(void) ok( dpi, "GetDpiForSystem failed\n" ); /* restore process-wide DPI awareness context */ ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80006010 ); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (dpi << 8)), "got %p\n", ctx ); - if (!ctx) pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80000010 ); + ok( ctx == (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (dpi << 8)), "got %p\n", ctx ); return dpi; } if (get_reg_dword(HKEY_CURRENT_USER, "Control Panel\Desktop", "LogPixels", &dpi)) @@ -3917,16 +3916,17 @@ static void test_SetProcessDpiAwarenessContext( ULONG arg ) ok( GetLastError() == ERROR_INVALID_PARAMETER, "got %#lx\n", GetLastError() ); SetLastError( 0xdeadbeef ); old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80000010 ); - todo_wine ok( !old_ctx, "SetThreadDpiAwarenessContext succeeded\n" ); - todo_wine ok( GetLastError() == ERROR_INVALID_PARAMETER, "got %#lx\n", GetLastError() ); + ok( !old_ctx, "SetThreadDpiAwarenessContext succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "got %#lx\n", GetLastError() );
old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80006010 ); - todo_wine ok( old_ctx == ctx, "got %p\n", old_ctx ); + ok( old_ctx == ctx, "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); todo_wine_if( arg != 0x12 && context != DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ) ok( ctx == expect_ctx, "got %p\n", ctx ); old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x80000011 | (real_dpi << 8)) ); - todo_wine ok( old_ctx == ULongToHandle( 0x80000000 | (UINT_PTR)expect_ctx ), "got %p\n", old_ctx ); + todo_wine_if( arg != 0x12 && arg != 0x80000012 && context != DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ) + ok( old_ctx == ULongToHandle( 0x80000000 | (UINT_PTR)expect_ctx ), "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); todo_wine_if( arg != 0x12 && context != DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ) ok( ctx == expect_ctx, "got %p\n", ctx ); @@ -3962,7 +3962,7 @@ static void test_SetThreadDpiAwarenessContext(void) old_ctx = pSetThreadDpiAwarenessContext( 0 ); ok( !old_ctx, "SetThreadDpiAwarenessContext succeeded\n" ); old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x11 ); - todo_wine ok( !old_ctx, "SetThreadDpiAwarenessContext succeeded\n" ); + ok( !old_ctx, "SetThreadDpiAwarenessContext succeeded\n" );
old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x12 ); todo_wine ok( old_ctx == (DPI_AWARENESS_CONTEXT)0x80006010, "got %p\n", old_ctx ); @@ -3976,30 +3976,30 @@ static void test_SetThreadDpiAwarenessContext(void) old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x7810 ); ok( !old_ctx, "SetThreadDpiAwarenessContext succeeded\n" ); old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x6010 ); - todo_wine ok( old_ctx == ctx, "got %p\n", old_ctx ); + ok( old_ctx == ctx, "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)0x6010, "got %p\n", ctx ); + ok( ctx == (DPI_AWARENESS_CONTEXT)0x6010, "got %p\n", ctx );
old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | ((real_dpi + 1) << 8)) ); ok( !old_ctx, "SetThreadDpiAwarenessContext succeeded\n" ); old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (real_dpi << 8)) ); - todo_wine ok( old_ctx == ctx, "got %p\n", old_ctx ); + ok( old_ctx == ctx, "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (real_dpi << 8)), "got %p\n", ctx ); + ok( ctx == (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (real_dpi << 8)), "got %p\n", ctx );
old_ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x40006010 ); - todo_wine ok( old_ctx == ctx, "got %p\n", old_ctx ); + ok( old_ctx == ctx, "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)0x40006010, "got %p\n", ctx ); + ok( ctx == (DPI_AWARENESS_CONTEXT)0x40006010, "got %p\n", ctx );
old_ctx = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); ok( old_ctx == ctx, "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)0x6010, "got %p\n", ctx ); + ok( ctx == (DPI_AWARENESS_CONTEXT)0x6010, "got %p\n", ctx ); old_ctx = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ); ok( old_ctx == ctx, "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (real_dpi << 8)), "got %p\n", ctx ); + ok( ctx == (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (real_dpi << 8)), "got %p\n", ctx ); old_ctx = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ); ok( old_ctx == ctx, "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); @@ -4009,14 +4009,13 @@ static void test_SetThreadDpiAwarenessContext(void) ctx = pGetThreadDpiAwarenessContext(); ok( ctx == (DPI_AWARENESS_CONTEXT)0x22, "got %p\n", ctx ); old_ctx = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED ); - todo_wine ok( old_ctx == ctx, "got %p\n", old_ctx ); + ok( old_ctx == ctx, "got %p\n", old_ctx ); ctx = pGetThreadDpiAwarenessContext(); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)0x40006010, "got %p\n", ctx ); + ok( ctx == (DPI_AWARENESS_CONTEXT)0x40006010, "got %p\n", ctx );
/* restore process-wide DPI awareness context */ ctx = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80006010 ); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)0x40006010, "got %p\n", ctx ); - if (!ctx) pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80000010 ); + ok( ctx == (DPI_AWARENESS_CONTEXT)0x40006010, "got %p\n", ctx ); }
static void test_IsValidDpiAwarenessContext(void) @@ -4256,21 +4255,21 @@ static void test_GetAwarenessFromDpiAwarenessContext(void) ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x22 ); ok( ret == DPI_AWARENESS_PER_MONITOR_AWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x6010 ); - todo_wine ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret ); + ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x6011 ); - todo_wine ok( ret == DPI_AWARENESS_SYSTEM_AWARE, "got %u\n", ret ); + ok( ret == DPI_AWARENESS_SYSTEM_AWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x6111 ); - todo_wine ok( ret == DPI_AWARENESS_SYSTEM_AWARE, "got %u\n", ret ); + ok( ret == DPI_AWARENESS_SYSTEM_AWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x7811 ); - todo_wine ok( ret == DPI_AWARENESS_SYSTEM_AWARE, "got %u\n", ret ); + ok( ret == DPI_AWARENESS_SYSTEM_AWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x10011 ); - todo_wine ok( ret == DPI_AWARENESS_SYSTEM_AWARE, "got %u\n", ret ); + ok( ret == DPI_AWARENESS_SYSTEM_AWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x40006010 ); - todo_wine ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret ); + ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80000012 ); ok( ret == DPI_AWARENESS_PER_MONITOR_AWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80006010 ); - todo_wine ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret ); + ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret );
ret = pGetAwarenessFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret ); @@ -4281,23 +4280,19 @@ static void test_GetAwarenessFromDpiAwarenessContext(void) ret = pGetAwarenessFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ); ok( ret == DPI_AWARENESS_PER_MONITOR_AWARE, "got %u\n", ret ); ret = pGetAwarenessFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED ); - todo_wine ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret ); + ok( ret == DPI_AWARENESS_UNAWARE, "got %u\n", ret ); }
static void test_dpi_context(void) { DPI_AWARENESS awareness; DPI_AWARENESS_CONTEXT context; - ULONG_PTR flags; BOOL ret; UINT dpi; HDC hdc = GetDC( 0 );
context = pGetThreadDpiAwarenessContext(); - /* Windows 10 >= 1709 adds extra 0x6000 flags */ - flags = (ULONG_PTR)context & 0x6000; - todo_wine - ok( context == (DPI_AWARENESS_CONTEXT)(0x10 | flags), "wrong context %p\n", context ); + todo_wine ok( context == (DPI_AWARENESS_CONTEXT)0x6010, "wrong context %p\n", context ); awareness = pGetAwarenessFromDpiAwarenessContext( context ); todo_wine ok( awareness == DPI_AWARENESS_UNAWARE, "wrong awareness %u\n", awareness ); @@ -4359,8 +4354,7 @@ static void test_dpi_context(void) ret = pIsProcessDPIAware(); ok(ret, "got %d\n", ret); context = pGetThreadDpiAwarenessContext(); - todo_wine - ok( context == (DPI_AWARENESS_CONTEXT)(0x11 | flags), "wrong context %p\n", context ); + todo_wine ok( context == (DPI_AWARENESS_CONTEXT)0x6011, "wrong context %p\n", context ); awareness = pGetAwarenessFromDpiAwarenessContext( context ); todo_wine ok( awareness == DPI_AWARENESS_SYSTEM_AWARE, "wrong awareness %u\n", awareness ); @@ -4373,8 +4367,7 @@ static void test_dpi_context(void) ok( !context, "got %p\n", context ); ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() ); context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); - todo_wine - ok( context == (DPI_AWARENESS_CONTEXT)(0x80000011 | flags), "wrong context %p\n", context ); + todo_wine ok( context == (DPI_AWARENESS_CONTEXT)0x80006011, "wrong context %p\n", context ); awareness = pGetAwarenessFromDpiAwarenessContext( context ); todo_wine ok( awareness == DPI_AWARENESS_SYSTEM_AWARE, "wrong awareness %u\n", awareness ); @@ -4384,11 +4377,11 @@ static void test_dpi_context(void) ok( dpi == USER_DEFAULT_SCREEN_DPI, "wrong dpi %u\n", dpi ); ok( !pIsProcessDPIAware(), "still aware\n" ); context = pGetThreadDpiAwarenessContext(); - ok( context == (DPI_AWARENESS_CONTEXT)(0x10 | flags), "wrong context %p\n", context ); + ok( context == (DPI_AWARENESS_CONTEXT)0x6010, "wrong context %p\n", context ); awareness = pGetAwarenessFromDpiAwarenessContext( context ); ok( awareness == DPI_AWARENESS_UNAWARE, "wrong awareness %u\n", awareness ); context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ); - ok( context == (DPI_AWARENESS_CONTEXT)(0x10 | flags), "wrong context %p\n", context ); + ok( context == (DPI_AWARENESS_CONTEXT)0x6010, "wrong context %p\n", context ); awareness = pGetAwarenessFromDpiAwarenessContext( context ); ok( awareness == DPI_AWARENESS_UNAWARE, "wrong awareness %u\n", awareness ); dpi = pGetDpiForSystem(); @@ -4409,26 +4402,21 @@ static void test_dpi_context(void) ok( dpi == real_dpi, "wrong dpi %u\n", dpi ); ok( pIsProcessDPIAware(), "not aware\n" ); context = pGetThreadDpiAwarenessContext(); - ok( context == (DPI_AWARENESS_CONTEXT)(0x11 | flags), "wrong context %p\n", context ); - context = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)(0x80000010 | flags) ); - ok( context == (DPI_AWARENESS_CONTEXT)(0x11 | flags), "wrong context %p\n", context ); + ok( context == (DPI_AWARENESS_CONTEXT)0x6011, "wrong context %p\n", context ); + context = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80006010 ); + ok( context == (DPI_AWARENESS_CONTEXT)0x6011, "wrong context %p\n", context ); context = pGetThreadDpiAwarenessContext(); - todo_wine - ok( context == (DPI_AWARENESS_CONTEXT)(0x11 | flags), "wrong context %p\n", context ); - context = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)(0x80000011 | flags) ); - todo_wine - ok( context == (DPI_AWARENESS_CONTEXT)(0x80000011 | flags), "wrong context %p\n", context ); + todo_wine ok( context == (DPI_AWARENESS_CONTEXT)0x6011, "wrong context %p\n", context ); + context = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80006011 ); + todo_wine ok( context == (DPI_AWARENESS_CONTEXT)0x80006011, "wrong context %p\n", context ); context = pGetThreadDpiAwarenessContext(); - todo_wine - ok( context == (DPI_AWARENESS_CONTEXT)(0x11 | flags), "wrong context %p\n", context ); + todo_wine ok( context == (DPI_AWARENESS_CONTEXT)0x6011, "wrong context %p\n", context ); context = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x12 ); - todo_wine - ok( context == (DPI_AWARENESS_CONTEXT)(0x80000011 | flags), "wrong context %p\n", context ); + todo_wine ok( context == (DPI_AWARENESS_CONTEXT)0x80006011, "wrong context %p\n", context ); context = pSetThreadDpiAwarenessContext( context ); - ok( context == (DPI_AWARENESS_CONTEXT)(0x12), "wrong context %p\n", context ); + ok( context == (DPI_AWARENESS_CONTEXT)0x12, "wrong context %p\n", context ); context = pGetThreadDpiAwarenessContext(); - todo_wine - ok( context == (DPI_AWARENESS_CONTEXT)(0x11 | flags), "wrong context %p\n", context ); + todo_wine ok( context == (DPI_AWARENESS_CONTEXT)0x6011, "wrong context %p\n", context );
if (real_dpi != USER_DEFAULT_SCREEN_DPI) test_dpi_stock_objects( hdc ); ReleaseDC( 0, hdc ); diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 2f7f8e27ff3..c392c1772e6 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -2135,28 +2135,13 @@ static BOOL is_valid_dpi_awareness_context( UINT context, UINT dpi ) return FALSE; }
-/* copied from user32 GetAwarenessFromDpiAwarenessContext, make sure to keep that in sync */ -static DPI_AWARENESS get_awareness_from_dpi_awareness_context( DPI_AWARENESS_CONTEXT context ) -{ - switch ((ULONG_PTR)context) - { - case 0x10: - case 0x11: - case 0x12: - case 0x22: - case 0x80000010: - case 0x80000011: - case 0x80000012: - case 0x80000022: - return (ULONG_PTR)context & 3; - case (ULONG_PTR)DPI_AWARENESS_CONTEXT_UNAWARE: - case (ULONG_PTR)DPI_AWARENESS_CONTEXT_SYSTEM_AWARE: - case (ULONG_PTR)DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE: - return ~(ULONG_PTR)context; - case (ULONG_PTR)DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2: - return ~(ULONG_PTR)DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE; - default: - return DPI_AWARENESS_INVALID; +UINT get_dpi_awareness_context_from_awareness( DPI_AWARENESS awareness ) +{ + switch (awareness) + { + default: return NTUSER_DPI_UNAWARE; + case DPI_AWARENESS_SYSTEM_AWARE: return NTUSER_DPI_SYSTEM_AWARE; + case DPI_AWARENESS_PER_MONITOR_AWARE: return NTUSER_DPI_PER_MONITOR_AWARE; } }
@@ -2195,26 +2180,22 @@ UINT get_system_dpi(void) return system_dpi; }
-/* see SetThreadDpiAwarenessContext, keep in sync with user32 */ +/* keep in sync with user32 */ UINT set_thread_dpi_awareness_context( UINT context ) { struct ntuser_thread_info *info = NtUserGetThreadInfo(); - DPI_AWARENESS prev, val = get_awareness_from_dpi_awareness_context( ULongToHandle( context ) ); + UINT prev;
- if (val == DPI_AWARENESS_INVALID) + if (!is_valid_dpi_awareness_context( context, system_dpi )) { RtlSetLastWin32Error( ERROR_INVALID_PARAMETER ); return 0; } - if (!(prev = info->dpi_context)) - { - prev = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ) & 3; - prev |= 0x80000010; /* restore to process default */ - } - if (((ULONG_PTR)context & ~(ULONG_PTR)0x33) == 0x80000000) info->dpi_context = 0; - else if (context == HandleToUlong( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ) || context == 0x22) - info->dpi_context = 0x22; - else info->dpi_context = val | 0x10; + + if (!(prev = info->dpi_context)) prev = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ) | NTUSER_DPI_CONTEXT_FLAG_PROCESS; + if (NTUSER_DPI_CONTEXT_GET_FLAGS( context ) & NTUSER_DPI_CONTEXT_FLAG_PROCESS) info->dpi_context = 0; + else info->dpi_context = context; + return prev; }
diff --git a/dlls/win32u/tests/win32u.c b/dlls/win32u/tests/win32u.c index 7606b7d23ba..3d0061fce96 100644 --- a/dlls/win32u/tests/win32u.c +++ b/dlls/win32u/tests/win32u.c @@ -2054,8 +2054,7 @@ static DWORD get_real_dpi(void) ok( dpi, "GetDpiForSystem failed\n" ); /* restore process-wide DPI awareness context */ ctx = SetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80006010 ); - todo_wine ok( ctx == (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (dpi << 8)), "got %p\n", ctx ); - if (!ctx) SetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x80000010 ); + ok( ctx == (DPI_AWARENESS_CONTEXT)((UINT_PTR)0x11 | (dpi << 8)), "got %p\n", ctx );
return dpi; } diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index aecd60bae63..e41fca01fc1 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -173,6 +173,7 @@ extern HBRUSH get_sys_color_brush( unsigned int index ); extern HPEN get_sys_color_pen( unsigned int index ); extern UINT get_system_dpi(void); extern int get_system_metrics( int index ); +extern UINT get_dpi_awareness_context_from_awareness( DPI_AWARENESS awareness ); extern UINT get_thread_dpi(void); extern UINT set_thread_dpi_awareness_context( UINT context ); extern UINT get_thread_dpi_awareness_context(void); diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index f7026654a50..582afee8883 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -869,7 +869,7 @@ UINT get_window_dpi_awareness_context( HWND hwnd ) if (win == WND_DESKTOP) return NTUSER_DPI_PER_MONITOR_AWARE; if (win != WND_OTHER_PROCESS) { - ret = MAKE_NTUSER_DPI_CONTEXT( win->dpi_awareness, 1, 0, 0 ); + ret = get_dpi_awareness_context_from_awareness( win->dpi_awareness ); release_win_ptr( win ); } else @@ -877,7 +877,7 @@ UINT get_window_dpi_awareness_context( HWND hwnd ) SERVER_START_REQ( get_window_info ) { req->handle = wine_server_user_handle( hwnd ); - if (!wine_server_call_err( req )) ret = MAKE_NTUSER_DPI_CONTEXT( reply->awareness, 1, 0, 0 ); + if (!wine_server_call_err( req )) ret = get_dpi_awareness_context_from_awareness( reply->awareness ); } SERVER_END_REQ; } diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index 3e900aa6f4d..cc9a11200ec 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -418,7 +418,7 @@ static void pull_events(void) */ static int process_events( DWORD mask ) { - DPI_AWARENESS_CONTEXT context; + UINT context; struct java_event *event, *next, *previous; unsigned int count = 0;
diff --git a/include/ntuser.h b/include/ntuser.h index 88453c46749..72cf57a5769 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -1027,9 +1027,9 @@ static inline UINT NtUserSetProcessDefaultLayout( DWORD layout ) return NtUserCallOneParam( layout, NtUserCallOneParam_SetProcessDefaultLayout ); }
-static inline DPI_AWARENESS_CONTEXT NtUserSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT context ) +static inline UINT NtUserSetThreadDpiAwarenessContext( UINT context ) { - return (DPI_AWARENESS_CONTEXT)NtUserCallOneParam( (ULONG_PTR)context, NtUserCallOneParam_SetThreadDpiAwarenessContext ); + return NtUserCallOneParam( context, NtUserCallOneParam_SetThreadDpiAwarenessContext ); }
/* NtUserCallTwoParam codes, not compatible with Windows */
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/ntuser_private.h | 3 +- dlls/win32u/sysparams.c | 10 ----- dlls/win32u/win32u_private.h | 1 - dlls/win32u/window.c | 32 +++++++-------- include/ntuser.h | 2 + server/protocol.def | 12 ++---- server/window.c | 77 +++++++++++++++++------------------- 7 files changed, 57 insertions(+), 80 deletions(-)
diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h index 11b1a3ff8a1..f0bd14179d4 100644 --- a/dlls/win32u/ntuser_private.h +++ b/dlls/win32u/ntuser_private.h @@ -74,8 +74,7 @@ typedef struct tagWND HICON hIconSmall; /* window's small icon */ HICON hIconSmall2; /* window's secondary small icon, derived from hIcon */ HIMC imc; /* window's input context */ - UINT dpi; /* window DPI */ - DPI_AWARENESS dpi_awareness; /* DPI awareness */ + UINT dpi_context; /* window DPI awareness context */ struct window_surface *surface; /* Window surface if any */ struct list vulkan_surfaces; /* list of vulkan surfaces created for this window */ struct tagDIALOGINFO *dlgInfo; /* Dialog additional info (dialogs only) */ diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index c392c1772e6..519f71ca25e 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -2135,16 +2135,6 @@ static BOOL is_valid_dpi_awareness_context( UINT context, UINT dpi ) return FALSE; }
-UINT get_dpi_awareness_context_from_awareness( DPI_AWARENESS awareness ) -{ - switch (awareness) - { - default: return NTUSER_DPI_UNAWARE; - case DPI_AWARENESS_SYSTEM_AWARE: return NTUSER_DPI_SYSTEM_AWARE; - case DPI_AWARENESS_PER_MONITOR_AWARE: return NTUSER_DPI_PER_MONITOR_AWARE; - } -} - UINT get_thread_dpi_awareness_context(void) { struct ntuser_thread_info *info = NtUserGetThreadInfo(); diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index e41fca01fc1..aecd60bae63 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -173,7 +173,6 @@ extern HBRUSH get_sys_color_brush( unsigned int index ); extern HPEN get_sys_color_pen( unsigned int index ); extern UINT get_system_dpi(void); extern int get_system_metrics( int index ); -extern UINT get_dpi_awareness_context_from_awareness( DPI_AWARENESS awareness ); extern UINT get_thread_dpi(void); extern UINT set_thread_dpi_awareness_context( UINT context ); extern UINT get_thread_dpi_awareness_context(void); diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 582afee8883..b0fe0218da5 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -450,8 +450,7 @@ HWND WINAPI NtUserSetParent( HWND hwnd, HWND parent ) { old_parent = wine_server_ptr_handle( reply->old_parent ); win->parent = parent = wine_server_ptr_handle( reply->full_parent ); - win->dpi = reply->dpi; - win->dpi_awareness = reply->awareness; + win->dpi_context = reply->dpi_context; }
} @@ -869,7 +868,7 @@ UINT get_window_dpi_awareness_context( HWND hwnd ) if (win == WND_DESKTOP) return NTUSER_DPI_PER_MONITOR_AWARE; if (win != WND_OTHER_PROCESS) { - ret = get_dpi_awareness_context_from_awareness( win->dpi_awareness ); + ret = win->dpi_context; release_win_ptr( win ); } else @@ -877,7 +876,7 @@ UINT get_window_dpi_awareness_context( HWND hwnd ) SERVER_START_REQ( get_window_info ) { req->handle = wine_server_user_handle( hwnd ); - if (!wine_server_call_err( req )) ret = get_dpi_awareness_context_from_awareness( reply->awareness ); + if (!wine_server_call_err( req )) ret = reply->dpi_context; } SERVER_END_REQ; } @@ -888,7 +887,7 @@ UINT get_window_dpi_awareness_context( HWND hwnd ) UINT get_dpi_for_window( HWND hwnd ) { WND *win; - UINT ret = 0; + UINT context = 0;
if (!(win = get_win_ptr( hwnd ))) { @@ -902,8 +901,7 @@ UINT get_dpi_for_window( HWND hwnd ) } if (win != WND_OTHER_PROCESS) { - ret = win->dpi; - if (!ret) ret = get_win_monitor_dpi( hwnd ); + context = win->dpi_context; release_win_ptr( win ); } else @@ -911,11 +909,13 @@ UINT get_dpi_for_window( HWND hwnd ) SERVER_START_REQ( get_window_info ) { req->handle = wine_server_user_handle( hwnd ); - if (!wine_server_call_err( req )) ret = reply->dpi; + if (!wine_server_call_err( req )) context = reply->dpi_context; } SERVER_END_REQ; } - return ret; + + if (NTUSER_DPI_CONTEXT_IS_MONITOR_AWARE( context )) return get_win_monitor_dpi( hwnd ); + return NTUSER_DPI_CONTEXT_GET_DPI( context ); }
static LONG_PTR get_win_data( const void *ptr, UINT size ) @@ -4911,11 +4911,10 @@ static WND *create_window_handle( HWND parent, HWND owner, UNICODE_STRING *name, HINSTANCE instance, BOOL ansi, DWORD style, DWORD ex_style ) { - DPI_AWARENESS awareness = NTUSER_DPI_CONTEXT_GET_AWARENESS( get_thread_dpi_awareness_context() ); + UINT dpi_context = get_thread_dpi_awareness_context(); HWND handle = 0, full_parent = 0, full_owner = 0; struct tagCLASS *class = NULL; int extra_bytes = 0; - UINT dpi = 0; WND *win;
SERVER_START_REQ( create_window ) @@ -4923,8 +4922,7 @@ static WND *create_window_handle( HWND parent, HWND owner, UNICODE_STRING *name, req->parent = wine_server_user_handle( parent ); req->owner = wine_server_user_handle( owner ); req->instance = wine_server_client_ptr( instance ); - req->dpi = get_system_dpi(); - req->awareness = awareness; + req->dpi_context = dpi_context; req->style = style; req->ex_style = ex_style; if (!(req->atom = get_int_atom_value( name )) && name->Length) @@ -4935,8 +4933,7 @@ static WND *create_window_handle( HWND parent, HWND owner, UNICODE_STRING *name, full_parent = wine_server_ptr_handle( reply->parent ); full_owner = wine_server_ptr_handle( reply->owner ); extra_bytes = reply->extra; - dpi = reply->dpi; - awareness = reply->awareness; + dpi_context = reply->dpi_context; class = wine_server_get_ptr( reply->class_ptr ); } } @@ -4988,8 +4985,7 @@ static WND *create_window_handle( HWND parent, HWND owner, UNICODE_STRING *name, win->class = class; win->winproc = get_class_winproc( class ); win->cbWndExtra = extra_bytes; - win->dpi = dpi; - win->dpi_awareness = awareness; + win->dpi_context = dpi_context; list_init( &win->vulkan_surfaces ); set_user_handle_ptr( handle, &win->obj ); if (is_winproc_unicode( win->winproc, !ansi )) win->flags |= WIN_ISUNICODE; @@ -5241,7 +5237,7 @@ HWND WINAPI NtUserCreateWindowEx( DWORD ex_style, UNICODE_STRING *class_name, } else NtUserSetWindowLongPtr( hwnd, GWLP_ID, (ULONG_PTR)cs.hMenu, FALSE );
- win_dpi = win->dpi; + win_dpi = NTUSER_DPI_CONTEXT_GET_DPI( win->dpi_context ); release_win_ptr( win );
if (parent) map_dpi_create_struct( &cs, thread_dpi, win_dpi ); diff --git a/include/ntuser.h b/include/ntuser.h index 72cf57a5769..ff45ffa2bc8 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -291,6 +291,8 @@ struct unpack_dde_message_result #define NTUSER_DPI_CONTEXT_FLAG_PROCESS 0x80000000 #define NTUSER_DPI_CONTEXT_FLAG_VALID_MASK (NTUSER_DPI_CONTEXT_FLAG_PROCESS | NTUSER_DPI_CONTEXT_FLAG_GDISCALED)
+#define NTUSER_DPI_CONTEXT_IS_MONITOR_AWARE( ctx ) (NTUSER_DPI_CONTEXT_GET_AWARENESS( ctx ) == DPI_AWARENESS_PER_MONITOR_AWARE) + #define NTUSER_DPI_UNAWARE MAKE_NTUSER_DPI_CONTEXT( DPI_AWARENESS_UNAWARE, 1, USER_DEFAULT_SCREEN_DPI, 0 ) #define NTUSER_DPI_SYSTEM_AWARE MAKE_NTUSER_DPI_CONTEXT( DPI_AWARENESS_SYSTEM_AWARE, 1, system_dpi, 0 ) #define NTUSER_DPI_PER_MONITOR_AWARE MAKE_NTUSER_DPI_CONTEXT( DPI_AWARENESS_PER_MONITOR_AWARE, 1, 0, 0 ) diff --git a/server/protocol.def b/server/protocol.def index 37a39206ca4..1491994197c 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -2373,8 +2373,7 @@ enum message_type user_handle_t owner; /* owner window */ atom_t atom; /* class atom */ mod_handle_t instance; /* module instance */ - int dpi; /* system DPI */ - int awareness; /* thread DPI awareness */ + unsigned int dpi_context; /* thread DPI context */ unsigned int style; /* window style */ unsigned int ex_style; /* window extended style */ VARARG(class,unicode_str); /* class name */ @@ -2384,8 +2383,7 @@ enum message_type user_handle_t owner; /* full handle of owner */ int extra; /* number of extra bytes */ client_ptr_t class_ptr; /* pointer to class in client address space */ - int dpi; /* window DPI if not per-monitor aware */ - int awareness; /* window DPI awareness */ + unsigned int dpi_context; /* window DPI context */ @END
@@ -2424,8 +2422,7 @@ enum message_type thread_id_t tid; /* thread owning the window */ atom_t atom; /* class atom */ int is_unicode; /* ANSI or unicode */ - int dpi; /* window DPI */ - int awareness; /* DPI awareness */ + unsigned int dpi_context; /* window DPI context */ @END
@@ -2465,8 +2462,7 @@ enum message_type @REPLY user_handle_t old_parent; /* old parent window */ user_handle_t full_parent; /* full handle of new parent */ - int dpi; /* new window DPI if not per-monitor aware */ - int awareness; /* new DPI awareness */ + unsigned int dpi_context; /* new DPI context */ @END
diff --git a/server/window.c b/server/window.c index 242e93f303a..c0e419a937a 100644 --- a/server/window.c +++ b/server/window.c @@ -83,8 +83,7 @@ struct window unsigned int color_key; /* color key for a layered window */ unsigned int alpha; /* alpha value for a layered window */ unsigned int layered_flags; /* flags for a layered window */ - unsigned int dpi; /* window DPI or 0 if per-monitor aware */ - DPI_AWARENESS dpi_awareness; /* DPI awareness mode */ + unsigned int dpi_context; /* DPI awareness context */ lparam_t user_data; /* user-specific data */ WCHAR *text; /* window caption text */ data_size_t text_len; /* length of window caption */ @@ -245,12 +244,20 @@ static inline void update_pixel_format_flags( struct window *win ) win->paint_flags |= PAINT_PIXEL_FORMAT_CHILD; }
+static unsigned int get_window_dpi( struct window *win ) +{ + unsigned int dpi; + if ((dpi = NTUSER_DPI_CONTEXT_GET_DPI( win->dpi_context ))) return dpi; + /* FIXME: return the window monitor DPI? */ + return USER_DEFAULT_SCREEN_DPI; +} + /* get the per-monitor DPI for a window */ static unsigned int get_monitor_dpi( struct window *win ) { /* FIXME: we return the desktop window DPI for now */ while (!is_desktop_window( win )) win = win->parent; - return win->dpi ? win->dpi : USER_DEFAULT_SCREEN_DPI; + return get_window_dpi( win ); }
/* link a window at the right place in the siblings list */ @@ -333,11 +340,7 @@ static int set_parent_window( struct window *win, struct window *parent ) win->parent = (struct window *)grab_object( parent ); link_window( win, WINPTR_TOP );
- if (!is_desktop_window( parent )) - { - win->dpi = parent->dpi; - win->dpi_awareness = parent->dpi_awareness; - } + if (!is_desktop_window( parent )) win->dpi_context = parent->dpi_context;
/* if parent belongs to a different thread and the window isn't */ /* top-level, attach the two threads */ @@ -573,8 +576,7 @@ static struct window *create_window( struct window *parent, struct window *owner win->is_linked = 0; win->is_layered = 0; win->is_orphan = 0; - win->dpi_awareness = DPI_AWARENESS_PER_MONITOR_AWARE; - win->dpi = 0; + win->dpi_context = NTUSER_DPI_PER_MONITOR_AWARE; win->user_data = 0; win->text = NULL; win->text_len = 0; @@ -760,7 +762,7 @@ static void screen_to_client( struct window *win, int *x, int *y, unsigned int d if (is_desktop_window( win )) return;
client_to_screen( win, &offset_x, &offset_y ); - map_dpi_point( win, x, y, dpi, win->dpi ); + map_dpi_point( win, x, y, dpi, get_window_dpi( win ) ); *x -= offset_x; *y -= offset_y; } @@ -816,7 +818,7 @@ static int is_point_in_window( struct window *win, int *x, int *y, unsigned int return 0; /* disabled child */ if ((win->ex_style & (WS_EX_LAYERED|WS_EX_TRANSPARENT)) == (WS_EX_LAYERED|WS_EX_TRANSPARENT)) return 0; /* transparent */ - map_dpi_point( win, x, y, dpi, win->dpi ); + map_dpi_point( win, x, y, dpi, get_window_dpi( win ) ); if (!point_in_rect( &win->visible_rect, *x, *y )) return 0; /* not in window */ if (win->win_region && @@ -857,7 +859,7 @@ static struct window *child_window_from_point( struct window *parent, int x, int { int x_child = x, y_child = y;
- if (!is_point_in_window( ptr, &x_child, &y_child, parent->dpi )) continue; /* skip it */ + if (!is_point_in_window( ptr, &x_child, &y_child, get_window_dpi( parent ) )) continue; /* skip it */
/* if window is minimized or disabled, return at once */ if (ptr->style & (WS_MINIMIZE|WS_DISABLED)) return ptr; @@ -881,7 +883,7 @@ static int get_window_children_from_point( struct window *parent, int x, int y, { int x_child = x, y_child = y;
- if (!is_point_in_window( ptr, &x_child, &y_child, parent->dpi )) continue; /* skip it */ + if (!is_point_in_window( ptr, &x_child, &y_child, get_window_dpi( parent ) )) continue; /* skip it */
/* if point is in client area, and window is not minimized or disabled, check children */ if (!(ptr->style & (WS_MINIMIZE|WS_DISABLED)) && point_in_rect( &ptr->client_rect, x_child, y_child )) @@ -934,7 +936,7 @@ static int all_windows_from_point( struct window *top, int x, int y, unsigned in if (!is_desktop_window( top ) && !is_desktop_window( top->parent )) { screen_to_client( top->parent, &x, &y, dpi ); - dpi = top->parent->dpi; + dpi = get_window_dpi( top->parent ); }
if (!is_point_in_window( top, &x, &y, dpi )) return 1; @@ -1573,7 +1575,7 @@ static void redraw_window( struct window *win, struct region *region, int frame, if (!(child_rgn = create_empty_region())) continue; if (copy_region( child_rgn, tmp )) { - map_dpi_region( child, child_rgn, win->dpi, child->dpi ); + map_dpi_region( child, child_rgn, get_window_dpi( win ), get_window_dpi( child ) ); if (rect_in_region( child_rgn, &child->window_rect )) { offset_region( child_rgn, -child->client_rect.left, -child->client_rect.top ); @@ -2086,25 +2088,19 @@ DECL_HANDLER(create_window) if (!(win = create_window( parent, owner, atom, req->instance ))) return;
if (parent && !is_desktop_window( parent )) - { - win->dpi_awareness = parent->dpi_awareness; - win->dpi = parent->dpi; - } - else if (!parent || req->awareness != DPI_AWARENESS_PER_MONITOR_AWARE) - { - win->dpi_awareness = req->awareness; - win->dpi = req->dpi; - } + win->dpi_context = parent->dpi_context; + else if (!parent || !NTUSER_DPI_CONTEXT_IS_MONITOR_AWARE( req->dpi_context )) + win->dpi_context = req->dpi_context; + win->style = req->style; win->ex_style = req->ex_style;
- reply->handle = win->handle; - reply->parent = win->parent ? win->parent->handle : 0; - reply->owner = win->owner; - reply->extra = win->nb_extra_bytes; - reply->dpi = win->dpi; - reply->awareness = win->dpi_awareness; - reply->class_ptr = get_class_client_ptr( win->class ); + reply->handle = win->handle; + reply->parent = win->parent ? win->parent->handle : 0; + reply->owner = win->owner; + reply->extra = win->nb_extra_bytes; + reply->dpi_context = win->dpi_context; + reply->class_ptr = get_class_client_ptr( win->class ); }
@@ -2124,8 +2120,7 @@ DECL_HANDLER(set_parent) reply->old_parent = win->parent->handle; reply->full_parent = parent ? parent->handle : 0; set_parent_window( win, parent ); - reply->dpi = win->dpi; - reply->awareness = win->dpi_awareness; + reply->dpi_context = win->dpi_context; }
@@ -2220,8 +2215,8 @@ DECL_HANDLER(get_window_info) reply->full_handle = win->handle; reply->last_active = win->handle; reply->is_unicode = win->is_unicode; - reply->awareness = win->dpi_awareness; - reply->dpi = win->dpi ? win->dpi : get_monitor_dpi( win ); + reply->dpi_context = win->dpi_context; + if (get_user_object( win->last_active, USER_WINDOW )) reply->last_active = win->last_active; if (win->thread) { @@ -2532,8 +2527,8 @@ DECL_HANDLER(get_window_rectangles) set_error( STATUS_INVALID_PARAMETER ); break; } - map_dpi_rect( win, &reply->window, win->dpi, req->dpi ); - map_dpi_rect( win, &reply->client, win->dpi, req->dpi ); + map_dpi_rect( win, &reply->window, get_window_dpi( win ), req->dpi ); + map_dpi_rect( win, &reply->client, get_window_dpi( win ), req->dpi ); }
@@ -2580,7 +2575,7 @@ DECL_HANDLER(get_windows_offset) x = mirror_from ? win->client_rect.right - win->client_rect.left : 0; y = 0; client_to_screen( win, &x, &y ); - map_dpi_point( win, &x, &y, win->dpi, req->dpi ); + map_dpi_point( win, &x, &y, get_window_dpi( win ), req->dpi ); reply->x += x; reply->y += y; } @@ -2591,7 +2586,7 @@ DECL_HANDLER(get_windows_offset) x = mirror_to ? win->client_rect.right - win->client_rect.left : 0; y = 0; client_to_screen( win, &x, &y ); - map_dpi_point( win, &x, &y, win->dpi, req->dpi ); + map_dpi_point( win, &x, &y, get_window_dpi( win ), req->dpi ); reply->x -= x; reply->y -= y; } @@ -2790,7 +2785,7 @@ DECL_HANDLER(update_window_zorder) if (ptr->ex_style & WS_EX_TRANSPARENT) continue; if (ptr->is_layered && (ptr->layered_flags & LWA_COLORKEY)) continue; tmp = rect; - map_dpi_rect( win, &tmp, win->parent->dpi, win->dpi ); + map_dpi_rect( win, &tmp, get_window_dpi( win->parent ), get_window_dpi( win ) ); if (!intersect_rect( &tmp, &tmp, &ptr->visible_rect )) continue; if (ptr->win_region) {
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=145869
Your paranoid android.
=== debian11b (build log) ===
error: patch failed: dlls/user32/sysparams.c:757 error: patch failed: dlls/win32u/sysparams.c:39 error: patch failed: dlls/win32u/win32u_private.h:175 error: patch failed: dlls/win32u/window.c:4911 error: patch failed: include/ntuser.h:83 error: patch failed: dlls/user32/winproc.c:698 error: patch failed: dlls/win32u/message.c:379 error: patch failed: dlls/wow64win/user.c:355 error: patch failed: include/ntuser.h:160 error: patch failed: dlls/user32/sysparams.c:619 error: patch failed: dlls/user32/tests/sysparams.c:224 error: patch failed: dlls/win32u/sysparams.c:2135 error: patch failed: dlls/win32u/tests/win32u.c:2054 error: patch failed: dlls/win32u/window.c:869 error: patch failed: dlls/wineandroid.drv/window.c:418 error: patch failed: include/ntuser.h:1027 error: patch failed: dlls/win32u/ntuser_private.h:74 error: patch failed: dlls/win32u/sysparams.c:2135 error: patch failed: dlls/win32u/window.c:450 error: patch failed: include/ntuser.h:291 error: patch failed: server/protocol.def:2373 error: patch failed: server/window.c:83 Task: Patch failed to apply
Hmm, right thanks. That was mostly meant to fix the tests, but I see now that it breaks things. Still not clear to me why or how.
It's because the win32u side does things the Windows way, and assumes that non-DPI aware windows will be scaled by the driver.
If the driver doesn't actually scale the bits, it means window coordinates between win32u and x11drv get out of sync. So we have to force per-monitor awareness to disable coordinates scaling on the win32u side.