Jacek Caban : win32u: Move NtUserGetDpiForMonitor implementation from user32.

Alexandre Julliard julliard at winehq.org
Mon Dec 6 16:07:59 CST 2021


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Dec  6 03:09:07 2021 +0100

win32u: Move NtUserGetDpiForMonitor implementation from user32.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/sysparams.c | 24 -------------------
 dlls/user32/user32.spec |  2 +-
 dlls/win32u/syscall.c   |  1 +
 dlls/win32u/sysparams.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
 dlls/win32u/win32u.spec |  2 +-
 dlls/wow64win/syscall.h |  1 +
 dlls/wow64win/user.c    | 10 ++++++++
 include/ntuser.h        |  1 +
 8 files changed, 76 insertions(+), 26 deletions(-)

diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 36375dabd42..11a2532411d 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -3328,30 +3328,6 @@ UINT WINAPI GetDpiForSystem(void)
     return system_dpi;
 }
 
-/***********************************************************************
- *              GetDpiForMonitorInternal   (USER32.@)
- */
-BOOL WINAPI GetDpiForMonitorInternal( HMONITOR monitor, UINT type, UINT *x, UINT *y )
-{
-    if (type > 2)
-    {
-        SetLastError( ERROR_BAD_ARGUMENTS );
-        return FALSE;
-    }
-    if (!x || !y)
-    {
-        SetLastError( ERROR_INVALID_ADDRESS );
-        return FALSE;
-    }
-    switch (GetAwarenessFromDpiAwarenessContext( GetThreadDpiAwarenessContext() ))
-    {
-    case DPI_AWARENESS_UNAWARE:      *x = *y = USER_DEFAULT_SCREEN_DPI; break;
-    case DPI_AWARENESS_SYSTEM_AWARE: *x = *y = system_dpi; break;
-    default:                         *x = *y = get_monitor_dpi( monitor ); break;
-    }
-    return TRUE;
-}
-
 /**********************************************************************
  *              GetThreadDpiAwarenessContext   (USER32.@)
  */
diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec
index 20d89c14a84..0f5e880263f 100644
--- a/dlls/user32/user32.spec
+++ b/dlls/user32/user32.spec
@@ -298,7 +298,7 @@
 @ stdcall GetDlgItemTextA(long long ptr long)
 @ stdcall GetDlgItemTextW(long long ptr long)
 @ stdcall GetDoubleClickTime()
-@ stdcall GetDpiForMonitorInternal(long long ptr ptr)
+@ stdcall GetDpiForMonitorInternal(long long ptr ptr) NtUserGetDpiForMonitor
 @ stdcall GetDpiForSystem()
 @ stdcall GetDpiForWindow(long)
 @ stdcall GetFocus()
diff --git a/dlls/win32u/syscall.c b/dlls/win32u/syscall.c
index e85633b041c..2e8b2408f31 100644
--- a/dlls/win32u/syscall.c
+++ b/dlls/win32u/syscall.c
@@ -112,6 +112,7 @@ static void * const syscalls[] =
     NtUserGetClipboardSequenceNumber,
     NtUserGetClipboardViewer,
     NtUserGetCursor,
+    NtUserGetDpiForMonitor,
     NtUserGetKeyState,
     NtUserGetKeyboardLayout,
     NtUserGetKeyboardLayoutName,
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c
index edc37e7e80f..74ab94aa818 100644
--- a/dlls/win32u/sysparams.c
+++ b/dlls/win32u/sysparams.c
@@ -1345,6 +1345,43 @@ RECT get_virtual_screen_rect(void)
     return rect;
 }
 
+/**********************************************************************
+ *           get_monitor_dpi
+ */
+static UINT get_monitor_dpi( HMONITOR monitor )
+{
+    /* FIXME: use the monitor DPI instead */
+    return system_dpi;
+}
+
+/**********************************************************************
+ *           get_thread_dpi_awareness
+ */
+static DPI_AWARENESS get_thread_dpi_awareness(void)
+{
+    struct user_thread_info *info = get_user_thread_info();
+    ULONG_PTR context = info->dpi_awareness;
+
+    if (!context) context = NtUserGetProcessDpiAwarenessContext( NULL );
+
+    switch (context)
+    {
+    case 0x10:
+    case 0x11:
+    case 0x12:
+    case 0x80000010:
+    case 0x80000011:
+    case 0x80000012:
+        return 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 ~context;
+    default:
+        return DPI_AWARENESS_INVALID;
+    }
+}
+
 /**********************************************************************
  *           NtUserGetDisplayConfigBufferSizes    (win32u.@)
  */
@@ -1764,6 +1801,30 @@ ULONG WINAPI NtUserGetSystemDpiForProcess( HANDLE process )
     return system_dpi;
 }
 
+/***********************************************************************
+ *           NtUserGetDpiForMonitor   (win32u.@)
+ */
+BOOL WINAPI NtUserGetDpiForMonitor( HMONITOR monitor, UINT type, UINT *x, UINT *y )
+{
+    if (type > 2)
+    {
+        SetLastError( ERROR_BAD_ARGUMENTS );
+        return FALSE;
+    }
+    if (!x || !y)
+    {
+        SetLastError( ERROR_INVALID_ADDRESS );
+        return FALSE;
+    }
+    switch (get_thread_dpi_awareness())
+    {
+    case DPI_AWARENESS_UNAWARE:      *x = *y = USER_DEFAULT_SCREEN_DPI; break;
+    case DPI_AWARENESS_SYSTEM_AWARE: *x = *y = system_dpi; break;
+    default:                         *x = *y = get_monitor_dpi( monitor ); break;
+    }
+    return TRUE;
+}
+
 /* retrieve the cached base keys for a given entry */
 static BOOL get_base_keys( enum parameter_key index, HKEY *base_key, HKEY *volatile_key )
 {
diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec
index a95d6eca565..c073f14896b 100644
--- a/dlls/win32u/win32u.spec
+++ b/dlls/win32u/win32u.spec
@@ -924,7 +924,7 @@
 @ stdcall NtUserGetDisplayConfigBufferSizes(long ptr ptr)
 @ stub NtUserGetDoubleClickTime
 @ stub NtUserGetDpiForCurrentProcess
-@ stub NtUserGetDpiForMonitor
+@ stdcall -syscall NtUserGetDpiForMonitor(long long ptr ptr)
 @ stub NtUserGetExtendedPointerDeviceProperty
 @ stub NtUserGetForegroundWindow
 @ stub NtUserGetGUIThreadInfo
diff --git a/dlls/wow64win/syscall.h b/dlls/wow64win/syscall.h
index 95a3df42805..bea1b00ebed 100644
--- a/dlls/wow64win/syscall.h
+++ b/dlls/wow64win/syscall.h
@@ -99,6 +99,7 @@
     SYSCALL_ENTRY( NtUserGetClipboardSequenceNumber ) \
     SYSCALL_ENTRY( NtUserGetClipboardViewer ) \
     SYSCALL_ENTRY( NtUserGetCursor ) \
+    SYSCALL_ENTRY( NtUserGetDpiForMonitor ) \
     SYSCALL_ENTRY( NtUserGetKeyState ) \
     SYSCALL_ENTRY( NtUserGetKeyboardLayout ) \
     SYSCALL_ENTRY( NtUserGetKeyboardLayoutName ) \
diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c
index 1026bc94843..eb739181812 100644
--- a/dlls/wow64win/user.c
+++ b/dlls/wow64win/user.c
@@ -315,3 +315,13 @@ NTSTATUS WINAPI wow64_NtUserGetSystemDpiForProcess( UINT *args )
 
     return NtUserGetSystemDpiForProcess( process );
 }
+
+NTSTATUS WINAPI wow64_NtUserGetDpiForMonitor( UINT *args )
+{
+    HMONITOR monitor = get_handle( &args );
+    UINT type = get_ulong( &args );
+    UINT *x = get_ptr( &args );
+    UINT *y = get_ptr( &args );
+
+    return NtUserGetDpiForMonitor( monitor, type, x, y );
+}
diff --git a/include/ntuser.h b/include/ntuser.h
index 2b747a856e8..5049926aa78 100644
--- a/include/ntuser.h
+++ b/include/ntuser.h
@@ -115,6 +115,7 @@ HWND    WINAPI NtUserGetClipboardViewer(void);
 HCURSOR WINAPI NtUserGetCursor(void);
 LONG    WINAPI NtUserGetDisplayConfigBufferSizes( UINT32 flags, UINT32 *num_path_info,
                                                   UINT32 *num_mode_info );
+BOOL    WINAPI NtUserGetDpiForMonitor( HMONITOR monitor, UINT type, UINT *x, UINT *y );
 INT     WINAPI NtUserGetKeyNameText( LONG lparam, WCHAR *buffer, INT size );
 SHORT   WINAPI NtUserGetKeyState( INT vkey );
 HKL     WINAPI NtUserGetKeyboardLayout( DWORD thread_id );




More information about the wine-cvs mailing list