Rémi Bernon : winebus.sys: Use a physical collection for the HID input report.

Alexandre Julliard julliard at winehq.org
Thu Mar 3 16:06:42 CST 2022


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

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Thu Mar  3 12:02:01 2022 +0100

winebus.sys: Use a physical collection for the HID input report.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winebus.sys/bus_sdl.c      |  4 ++--
 dlls/winebus.sys/bus_udev.c     |  2 +-
 dlls/winebus.sys/hid.c          | 40 +++++++++++++++++++++++++---------------
 dlls/winebus.sys/unix_private.h |  2 +-
 4 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c
index 9efd8e2d00e..3d9935f0714 100644
--- a/dlls/winebus.sys/bus_sdl.c
+++ b/dlls/winebus.sys/bus_sdl.c
@@ -279,7 +279,7 @@ static NTSTATUS build_joystick_report_descriptor(struct unix_device *iface)
     if (!hid_device_begin_report_descriptor(iface, &device_usage))
         return STATUS_NO_MEMORY;
 
-    if (!hid_device_begin_input_report(iface))
+    if (!hid_device_begin_input_report(iface, &device_usage))
         return STATUS_NO_MEMORY;
 
     for (i = 0; i < axis_count; i++)
@@ -333,7 +333,7 @@ static NTSTATUS build_controller_report_descriptor(struct unix_device *iface)
     if (!hid_device_begin_report_descriptor(iface, &device_usage))
         return STATUS_NO_MEMORY;
 
-    if (!hid_device_begin_input_report(iface))
+    if (!hid_device_begin_input_report(iface, &device_usage))
         return STATUS_NO_MEMORY;
 
     if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages,
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c
index 7a0a9587af0..db173b63fb5 100644
--- a/dlls/winebus.sys/bus_udev.c
+++ b/dlls/winebus.sys/bus_udev.c
@@ -665,7 +665,7 @@ static NTSTATUS build_report_descriptor(struct unix_device *iface, struct udev_d
     if (!hid_device_begin_report_descriptor(iface, &device_usage))
         return STATUS_NO_MEMORY;
 
-    if (!hid_device_begin_input_report(iface))
+    if (!hid_device_begin_input_report(iface, &device_usage))
         return STATUS_NO_MEMORY;
 
     abs_count = 0;
diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c
index ba0fa77ee11..d5637c0353b 100644
--- a/dlls/winebus.sys/hid.c
+++ b/dlls/winebus.sys/hid.c
@@ -74,23 +74,21 @@ static BOOL hid_report_descriptor_append_usage(struct hid_report_descriptor *des
     return hid_report_descriptor_append(desc, template, sizeof(template));
 }
 
-BOOL hid_device_begin_report_descriptor(struct unix_device *iface, const USAGE_AND_PAGE *device_usage)
+static BOOL hid_device_begin_collection(struct hid_report_descriptor *desc, const USAGE_AND_PAGE *usage, BYTE type)
 {
-    struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
     const BYTE template[] =
     {
-        USAGE_PAGE(2, device_usage->UsagePage),
-        USAGE(2, device_usage->Usage),
-        COLLECTION(1, Application),
+        USAGE_PAGE(2, usage->UsagePage),
+        USAGE(2, usage->Usage),
+        COLLECTION(1, type),
     };
 
     memset(desc, 0, sizeof(*desc));
     return hid_report_descriptor_append(desc, template, sizeof(template));
 }
 
-BOOL hid_device_end_report_descriptor(struct unix_device *iface)
+static BOOL hid_device_end_collection(struct hid_report_descriptor *desc)
 {
-    struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
     static const BYTE template[] =
     {
         END_COLLECTION,
@@ -99,15 +97,27 @@ BOOL hid_device_end_report_descriptor(struct unix_device *iface)
     return hid_report_descriptor_append(desc, template, sizeof(template));
 }
 
-BOOL hid_device_begin_input_report(struct unix_device *iface)
+BOOL hid_device_begin_report_descriptor(struct unix_device *iface, const USAGE_AND_PAGE *device_usage)
+{
+    struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
+    memset(desc, 0, sizeof(*desc));
+    return hid_device_begin_collection(desc, device_usage, Application);
+}
+
+BOOL hid_device_end_report_descriptor(struct unix_device *iface)
+{
+    struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
+    return hid_device_end_collection(desc);
+}
+
+BOOL hid_device_begin_input_report(struct unix_device *iface, const USAGE_AND_PAGE *physical_usage)
 {
     struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
     struct hid_device_state *state = &iface->hid_device_state;
     const BYTE report_id = ++desc->next_report_id[HidP_Input];
     const BYTE template[] =
     {
-        COLLECTION(1, Report),
-            REPORT_ID(1, report_id),
+        REPORT_ID(1, report_id),
     };
 
     if (state->report_len)
@@ -118,6 +128,10 @@ BOOL hid_device_begin_input_report(struct unix_device *iface)
 
     state->id = report_id;
     state->bit_size += 8;
+
+    if (!hid_device_begin_collection(desc, physical_usage, Physical))
+        return FALSE;
+
     return hid_report_descriptor_append(desc, template, sizeof(template));
 }
 
@@ -125,10 +139,6 @@ BOOL hid_device_end_input_report(struct unix_device *iface)
 {
     struct hid_report_descriptor *desc = &iface->hid_report_descriptor;
     struct hid_device_state *state = &iface->hid_device_state;
-    static const BYTE template[] =
-    {
-        END_COLLECTION,
-    };
 
     state->report_len = (state->bit_size + 7) / 8;
     if (!(state->report_buf = calloc(1, state->report_len))) return FALSE;
@@ -136,7 +146,7 @@ BOOL hid_device_end_input_report(struct unix_device *iface)
 
     state->report_buf[0] = state->id;
     state->last_report_buf[0] = state->id;
-    return hid_report_descriptor_append(desc, template, sizeof(template));
+    return hid_device_end_collection(desc);
 }
 
 static BOOL hid_device_add_button_count(struct unix_device *iface, BYTE count)
diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h
index 2cf6d382759..553631e40fb 100644
--- a/dlls/winebus.sys/unix_private.h
+++ b/dlls/winebus.sys/unix_private.h
@@ -245,7 +245,7 @@ extern BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event) DEC
 extern BOOL hid_device_begin_report_descriptor(struct unix_device *iface, const USAGE_AND_PAGE *device_usage) DECLSPEC_HIDDEN;
 extern BOOL hid_device_end_report_descriptor(struct unix_device *iface) DECLSPEC_HIDDEN;
 
-extern BOOL hid_device_begin_input_report(struct unix_device *iface) DECLSPEC_HIDDEN;
+extern BOOL hid_device_begin_input_report(struct unix_device *iface, const USAGE_AND_PAGE *physical_usage) DECLSPEC_HIDDEN;
 extern BOOL hid_device_end_input_report(struct unix_device *iface) DECLSPEC_HIDDEN;
 extern BOOL hid_device_add_buttons(struct unix_device *iface, USAGE usage_page,
                                    USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list