v8 of this patch incorporates Remi's recommendations to use the hw_rawinput_t union for hardware_msg_data and send the rawinput messages to the relevant thread only.

On Fri, Jul 26, 2019 at 3:30 PM Derek Lesho <dereklesho52@gmail.com> wrote:
Signed-off-by: Derek Lesho <dereklesho52@Gmail.com>
---
 server/protocol.def | 52 ++++++++++++++++++++++++++++-----------------
 server/queue.c      | 52 +++++++++++++++++++++++++++++++++++++++++++++
 server/trace.c      | 21 ++++++++++++++++++
 tools/make_requests |  1 +
 4 files changed, 107 insertions(+), 19 deletions(-)

diff --git a/server/protocol.def b/server/protocol.def
index 8b8a8a1512..b5368c71f6 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -286,31 +286,40 @@ struct hw_msg_source
     unsigned int    origin;        /* source origin (IMO_* values) */
 };

+typedef union
+{
+    int type;
+    struct
+    {
+        int            type;    /* RIM_TYPEKEYBOARD */
+        unsigned int   message; /* message generated by this rawinput event */
+        unsigned short vkey;    /* virtual key code */
+        unsigned short scan;    /* scan code */
+    } kbd;
+    struct
+    {
+        int            type;            /* RIM_TYPEMOUSE */
+        int            x;               /* x coordinate */
+        int            y;               /* y coordinate */
+        unsigned short button_flags;    /* mouse button */
+        unsigned short button_data;     /* event details */
+    } mouse;
+    struct
+    {
+        int type; /* RIM_TYPEHID */
+        /* TODO: fill this in if/when necessary */
+    } hid;
+} hw_rawinput_t;
+#define RIM_ENABLE_NATIVE_MOUSE_MOVE   0x0800
+#define RIM_ENABLE_NATIVE_MOUSE_PRESS  0x1000
+
 struct hardware_msg_data
 {
     lparam_t             info;      /* extra info */
     unsigned int         hw_id;     /* unique id */
     unsigned int         flags;     /* hook flags */
     struct hw_msg_source source;    /* message source */
-    union
-    {
-        int type;
-        struct
-        {
-            int            type;    /* RIM_TYPEKEYBOARD */
-            unsigned int   message; /* message generated by this rawinput event */
-            unsigned short vkey;    /* virtual key code */
-            unsigned short scan;    /* scan code */
-        } kbd;
-        struct
-        {
-            int            type;            /* RIM_TYPEMOUSE */
-            int            x;               /* x coordinate */
-            int            y;               /* y coordinate */
-            unsigned short button_flags;    /* mouse button */
-            unsigned short button_data;     /* event details */
-        } mouse;
-    } rawinput;
+    hw_rawinput_t        rawinput;
 };

 struct callback_msg_data
@@ -2294,6 +2303,11 @@ enum message_type
 #define SEND_HWMSG_INJECTED    0x01


+@REQ(send_rawinput_message)
+    hw_rawinput_t input;
+@END
+
+
 /* Get a message from the current queue */
 @REQ(get_message)
     unsigned int    flags;     /* PM_* flags */
diff --git a/server/queue.c b/server/queue.c
index d12db927b9..03e64341c1 100644
--- a/server/queue.c
+++ b/server/queue.c
@@ -2421,6 +2421,58 @@ DECL_HANDLER(send_hardware_message)
     release_object( desktop );
 }

+/* send a hardware rawinput message to the queue thread */
+DECL_HANDLER(send_rawinput_message)
+{
+    const struct rawinput_device *device;
+    struct hardware_msg_data *msg_data;
+    struct message *msg;
+    struct desktop *desktop;
+    struct hw_msg_source source = { IMDT_MOUSE, IMO_HARDWARE };
+
+    desktop = get_thread_desktop( current, 0 );
+
+    switch (req->input.type)
+    {
+    case RIM_TYPEMOUSE:
+        if ((device = current->process->rawinput_mouse))
+        {
+            struct thread *thread = device->target ? get_window_thread( device->target ) : NULL;
+            if (device->target ? (thread != current) : (current->queue->input != desktop->foreground_input))
+            {
+                if ( thread )
+                    release_object( thread );
+                release_object( desktop );
+                return;
+            }
+            if (thread)
+                release_object( thread );
+
+            if (!(msg = alloc_hardware_message( 0, source, 0 ))) return;
+            msg_data = msg->data;
+
+            msg->win       = device->target;
+            msg->msg       = WM_INPUT;
+            msg->wparam    = RIM_INPUT;
+            msg->lparam    = 0;
+
+            msg_data->flags               = 0;
+            msg_data->rawinput.type       = RIM_TYPEMOUSE;
+            msg_data->rawinput.mouse.x    = req->input.mouse.x;
+            msg_data->rawinput.mouse.y    = req->input.mouse.y;
+            msg_data->rawinput.mouse.button_flags = req->input.mouse.button_flags;
+            msg_data->rawinput.mouse.button_data = req->input.mouse.button_data;
+
+            queue_hardware_message( desktop, msg, 0 );
+        }
+        break;
+    default:
+        set_error( STATUS_INVALID_PARAMETER );
+    }
+
+    release_object(desktop);
+}
+
 /* post a quit message to the current queue */
 DECL_HANDLER(post_quit_message)
 {
diff --git a/server/trace.c b/server/trace.c
index 3562823659..bccab449cf 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -390,6 +390,27 @@ static void dump_hw_input( const char *prefix, const hw_input_t *input )
     }
 }

+static void dump_hw_rawinput( const char *prefix, const hw_rawinput_t *rawinput )
+{
+    switch (rawinput->type)
+    {
+    case RIM_TYPEMOUSE:
+        fprintf( stderr, "%s{type=MOUSE,x=%d,y=%d,button_flags=%04hx,button_data=%04hx}",
+                 prefix, rawinput->mouse.x, rawinput->mouse.y, rawinput->mouse.button_flags,
+                 rawinput->mouse.button_data);
+        break;
+    case RIM_TYPEKEYBOARD:
+        fprintf( stderr, "%s{type=KEYBOARD}\n", prefix);
+        break;
+    case RIM_TYPEHID:
+        fprintf( stderr, "%s{type=HID}\n", prefix);
+        break;
+    default:
+        fprintf( stderr, "%s{type=%04x}", prefix, rawinput->type);
+        break;
+    }
+}
+
 static void dump_luid( const char *prefix, const luid_t *luid )
 {
     fprintf( stderr, "%s%d.%u", prefix, luid->high_part, luid->low_part );
diff --git a/tools/make_requests b/tools/make_requests
index 367f245653..cf631923a7 100755
--- a/tools/make_requests
+++ b/tools/make_requests
@@ -53,6 +53,7 @@ my %formats =
     "ioctl_code_t"  => [  4,   4,  "&dump_ioctl_code" ],
     "cpu_type_t"    => [  4,   4,  "&dump_cpu_type" ],
     "hw_input_t"    => [  32,  8,  "&dump_hw_input" ],
+    "hw_rawinput_t" => [  16,  8,  "&dump_hw_rawinput" ]
 );

 my @requests = ();
--
2.22.0