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 f107f114af6..05db64d1721 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -2136,28 +2136,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; } }
@@ -2196,26 +2181,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 027c8880edd..0ba9123c1ba 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 */