[PATCH 3/4] win32u: Move NtUserGetRawInputData from user32.

Zebediah Figura wine at gitlab.winehq.org
Mon Jun 13 02:18:57 CDT 2022


From: Zebediah Figura <zfigura at codeweavers.com>

---
 dlls/user32/rawinput.c       | 54 +--------------------
 dlls/user32/user32.spec      |  2 +-
 dlls/user32/user_main.c      |  1 +
 dlls/user32/user_private.h   |  8 +---
 dlls/win32u/Makefile.in      |  1 +
 dlls/win32u/gdiobj.c         |  1 +
 dlls/win32u/ntuser_private.h |  7 +++
 dlls/win32u/rawinput.c       | 91 ++++++++++++++++++++++++++++++++++++
 dlls/win32u/win32u.spec      |  2 +-
 dlls/win32u/win32u_private.h |  2 +
 dlls/win32u/wrappers.c       |  6 +++
 include/ntuser.h             |  1 +
 12 files changed, 114 insertions(+), 62 deletions(-)
 create mode 100644 dlls/win32u/rawinput.c

diff --git a/dlls/user32/rawinput.c b/dlls/user32/rawinput.c
index 99e2270b77c..b1c79b4e186 100644
--- a/dlls/user32/rawinput.c
+++ b/dlls/user32/rawinput.c
@@ -351,7 +351,7 @@ BOOL rawinput_device_get_usages(HANDLE handle, USAGE *usage_page, USAGE *usage)
 }
 
 
-struct rawinput_thread_data *rawinput_thread_data(void)
+struct rawinput_thread_data * WINAPI rawinput_thread_data(void)
 {
     struct user_thread_info *thread_info = get_user_thread_info();
     struct rawinput_thread_data *data = thread_info->rawinput;
@@ -593,58 +593,6 @@ BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(const RAWINPUTDEVICE *devi
     return ret;
 }
 
-/***********************************************************************
- *              GetRawInputData   (USER32.@)
- */
-UINT WINAPI GetRawInputData(HRAWINPUT rawinput, UINT command, void *data, UINT *data_size, UINT header_size)
-{
-    struct rawinput_thread_data *thread_data = rawinput_thread_data();
-    UINT size;
-
-    TRACE("rawinput %p, command %#x, data %p, data_size %p, header_size %u.\n",
-            rawinput, command, data, data_size, header_size);
-
-    if (!rawinput || thread_data->hw_id != (UINT_PTR)rawinput)
-    {
-        SetLastError(ERROR_INVALID_HANDLE);
-        return ~0U;
-    }
-
-    if (header_size != sizeof(RAWINPUTHEADER))
-    {
-        WARN("Invalid structure size %u.\n", header_size);
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return ~0U;
-    }
-
-    switch (command)
-    {
-    case RID_INPUT:
-        size = thread_data->buffer->header.dwSize;
-        break;
-    case RID_HEADER:
-        size = sizeof(RAWINPUTHEADER);
-        break;
-    default:
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return ~0U;
-    }
-
-    if (!data)
-    {
-        *data_size = size;
-        return 0;
-    }
-
-    if (*data_size < size)
-    {
-        SetLastError(ERROR_INSUFFICIENT_BUFFER);
-        return ~0U;
-    }
-    memcpy(data, thread_data->buffer, size);
-    return size;
-}
-
 #ifdef _WIN64
 typedef RAWINPUTHEADER RAWINPUTHEADER64;
 typedef RAWINPUT RAWINPUT64;
diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec
index b41d661ee2a..2379c2cced5 100644
--- a/dlls/user32/user32.spec
+++ b/dlls/user32/user32.spec
@@ -367,7 +367,7 @@
 @ stdcall GetPropW(long wstr)
 @ stdcall GetQueueStatus(long) NtUserGetQueueStatus
 @ stdcall GetRawInputBuffer(ptr ptr long)
-@ stdcall GetRawInputData(ptr long ptr ptr long)
+@ stdcall GetRawInputData(ptr long ptr ptr long) NtUserGetRawInputData
 @ stdcall GetRawInputDeviceInfoA(ptr long ptr ptr)
 @ stdcall GetRawInputDeviceInfoW(ptr long ptr ptr)
 @ stdcall GetRawInputDeviceList(ptr ptr long)
diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c
index 755fc3d578e..64b9b9f59a9 100644
--- a/dlls/user32/user_main.c
+++ b/dlls/user32/user_main.c
@@ -156,6 +156,7 @@ static const struct user_callbacks user_funcs =
     unpack_dde_message,
     register_imm,
     unregister_imm,
+    rawinput_thread_data,
 };
 
 static NTSTATUS WINAPI User32CopyImage( const struct copy_image_params *params, ULONG size )
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index aa3e1565bfa..11f8b6389ac 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -51,12 +51,6 @@ struct wm_char_mapping_data
 /* hold up to 10s of 1kHz mouse rawinput events */
 #define RAWINPUT_BUFFER_SIZE (512*1024)
 
-struct rawinput_thread_data
-{
-    UINT     hw_id;     /* current rawinput message id */
-    RAWINPUT buffer[1]; /* rawinput message data buffer */
-};
-
 extern BOOL (WINAPI *imm_register_window)(HWND) DECLSPEC_HIDDEN;
 extern void (WINAPI *imm_unregister_window)(HWND) DECLSPEC_HIDDEN;
 
@@ -73,7 +67,7 @@ struct tagWND;
 struct hardware_msg_data;
 extern BOOL rawinput_from_hardware_message(RAWINPUT *rawinput, const struct hardware_msg_data *msg_data);
 extern BOOL rawinput_device_get_usages(HANDLE handle, USAGE *usage_page, USAGE *usage);
-extern struct rawinput_thread_data *rawinput_thread_data(void);
+extern struct rawinput_thread_data * WINAPI rawinput_thread_data(void);
 extern void rawinput_update_device_list(void);
 
 extern BOOL post_dde_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD dest_tid,
diff --git a/dlls/win32u/Makefile.in b/dlls/win32u/Makefile.in
index d58ed6bb41c..cc429836de3 100644
--- a/dlls/win32u/Makefile.in
+++ b/dlls/win32u/Makefile.in
@@ -43,6 +43,7 @@ C_SRCS = \
 	path.c \
 	pen.c \
 	printdrv.c \
+	rawinput.c \
 	region.c \
 	spy.c \
 	syscall.c \
diff --git a/dlls/win32u/gdiobj.c b/dlls/win32u/gdiobj.c
index 72924bb658a..a988b1a0c4a 100644
--- a/dlls/win32u/gdiobj.c
+++ b/dlls/win32u/gdiobj.c
@@ -1181,6 +1181,7 @@ static struct unix_funcs unix_funcs =
     NtUserGetMessage,
     NtUserGetPriorityClipboardFormat,
     NtUserGetQueueStatus,
+    NtUserGetRawInputData,
     NtUserGetSystemMenu,
     NtUserGetUpdateRect,
     NtUserGetUpdateRgn,
diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h
index e39e3f54169..717538c1adc 100644
--- a/dlls/win32u/ntuser_private.h
+++ b/dlls/win32u/ntuser_private.h
@@ -49,6 +49,7 @@ struct user_callbacks
                                       void **buffer, size_t size );
     BOOL (WINAPI *register_imm)( HWND hwnd );
     void (WINAPI *unregister_imm)( HWND hwnd );
+    struct rawinput_thread_data *(WINAPI *get_rawinput_thread_data)(void);
 };
 
 #define WM_SYSTIMER         0x0118
@@ -60,6 +61,12 @@ enum system_timer_id
     SYSTEM_TIMER_CARET = 0xffff,
 };
 
+struct rawinput_thread_data
+{
+    UINT     hw_id;     /* current rawinput message id */
+    RAWINPUT buffer[1]; /* rawinput message data buffer */
+};
+
 struct user_object
 {
     HANDLE       handle;
diff --git a/dlls/win32u/rawinput.c b/dlls/win32u/rawinput.c
new file mode 100644
index 00000000000..0d2c585c36e
--- /dev/null
+++ b/dlls/win32u/rawinput.c
@@ -0,0 +1,91 @@
+/*
+ * Raw Input
+ *
+ * Copyright 2012 Henri Verbeet
+ * Copyright 2018 Zebediah Figura for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#if 0
+#pragma makedep unix
+#endif
+
+#include "win32u_private.h"
+#include "ntuser_private.h"
+#include "wine/server.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(rawinput);
+
+/**********************************************************************
+ *         NtUserGetRawInputData   (win32u.@)
+ */
+UINT WINAPI NtUserGetRawInputData( HRAWINPUT rawinput, UINT command, void *data, UINT *data_size, UINT header_size )
+{
+    struct rawinput_thread_data *thread_data;
+    UINT size;
+
+    TRACE( "rawinput %p, command %#x, data %p, data_size %p, header_size %u.\n",
+           rawinput, command, data, data_size, header_size );
+
+    if (!user_callbacks || !(thread_data = user_callbacks->get_rawinput_thread_data()))
+    {
+        SetLastError( ERROR_OUTOFMEMORY );
+        return ~0u;
+    }
+
+    if (!rawinput || thread_data->hw_id != (UINT_PTR)rawinput)
+    {
+        SetLastError( ERROR_INVALID_HANDLE );
+        return ~0u;
+    }
+
+    if (header_size != sizeof(RAWINPUTHEADER))
+    {
+        WARN( "Invalid structure size %u.\n", header_size );
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return ~0u;
+    }
+
+    switch (command)
+    {
+    case RID_INPUT:
+        size = thread_data->buffer->header.dwSize;
+        break;
+
+    case RID_HEADER:
+        size = sizeof(RAWINPUTHEADER);
+        break;
+
+    default:
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return ~0u;
+    }
+
+    if (!data)
+    {
+        *data_size = size;
+        return 0;
+    }
+
+    if (*data_size < size)
+    {
+        SetLastError( ERROR_INSUFFICIENT_BUFFER );
+        return ~0u;
+    }
+    memcpy( data, thread_data->buffer, size );
+    return size;
+}
diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec
index de500da143b..8b71504f374 100644
--- a/dlls/win32u/win32u.spec
+++ b/dlls/win32u/win32u.spec
@@ -984,7 +984,7 @@
 @ stdcall NtUserGetQueueStatus(long)
 @ stub NtUserGetQueueStatusReadonly
 @ stub NtUserGetRawInputBuffer
-@ stub NtUserGetRawInputData
+@ stdcall NtUserGetRawInputData(ptr long ptr ptr long)
 @ stub NtUserGetRawInputDeviceInfo
 @ stub NtUserGetRawInputDeviceList
 @ stub NtUserGetRawPointerDeviceData
diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h
index 957d930d9da..87901d1313e 100644
--- a/dlls/win32u/win32u_private.h
+++ b/dlls/win32u/win32u_private.h
@@ -243,6 +243,8 @@ struct unix_funcs
     BOOL     (WINAPI *pNtUserGetMessage)( MSG *msg, HWND hwnd, UINT first, UINT last );
     INT      (WINAPI *pNtUserGetPriorityClipboardFormat)( UINT *list, INT count );
     DWORD    (WINAPI *pNtUserGetQueueStatus)( UINT flags );
+    UINT     (WINAPI *pNtUserGetRawInputData)( HRAWINPUT rawinput, UINT command,
+                                               void *data, UINT *data_size, UINT header_size );
     HMENU    (WINAPI *pNtUserGetSystemMenu)( HWND hwnd, BOOL revert );
     BOOL     (WINAPI *pNtUserGetUpdateRect)( HWND hwnd, RECT *rect, BOOL erase );
     INT      (WINAPI *pNtUserGetUpdateRgn)( HWND hwnd, HRGN hrgn, BOOL erase );
diff --git a/dlls/win32u/wrappers.c b/dlls/win32u/wrappers.c
index 99e0b9f3d88..17354abc73e 100644
--- a/dlls/win32u/wrappers.c
+++ b/dlls/win32u/wrappers.c
@@ -1023,6 +1023,12 @@ DWORD WINAPI NtUserGetQueueStatus( UINT flags )
     return unix_funcs->pNtUserGetQueueStatus( flags );
 }
 
+UINT WINAPI NtUserGetRawInputData( HRAWINPUT rawinput, UINT command, void *data, UINT *data_size, UINT header_size )
+{
+    if (!unix_funcs) return ~0u;
+    return unix_funcs->pNtUserGetRawInputData( rawinput, command, data, data_size, header_size );
+}
+
 BOOL WINAPI NtUserGetUpdatedClipboardFormats( UINT *formats, UINT size, UINT *out_size )
 {
     if (!unix_funcs) return FALSE;
diff --git a/include/ntuser.h b/include/ntuser.h
index 8320a83800f..85b7a87247f 100644
--- a/include/ntuser.h
+++ b/include/ntuser.h
@@ -589,6 +589,7 @@ HWINSTA WINAPI NtUserGetProcessWindowStation(void);
 HANDLE  WINAPI NtUserGetProp( HWND hwnd, const WCHAR *str );
 ULONG   WINAPI NtUserGetProcessDpiAwarenessContext( HANDLE process );
 DWORD   WINAPI NtUserGetQueueStatus( UINT flags );
+UINT    WINAPI NtUserGetRawInputData( HRAWINPUT rawinput, UINT command, void *data, UINT *data_size, UINT header_size );
 ULONG   WINAPI NtUserGetSystemDpiForProcess( HANDLE process );
 HMENU   WINAPI NtUserGetSystemMenu( HWND hwnd, BOOL revert );
 HDESK   WINAPI NtUserGetThreadDesktop( DWORD thread );
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/233



More information about the wine-devel mailing list