Package: release.debian.org
Severity: normal
User: release.debian....@packages.debian.org
Usertags: unblock
X-Debbugs-Cc: libs...@packages.debian.org
Control: affects -1 + src:libsdl2

Please unblock package libsdl2

[ Reason ]
* New upstream stable release
* Fix axis/button mapping for game controllers with older drivers/firmware
* Fix missing input from (some?) Playstation 4 gamepads in raw HID mode

[ Impact ]
If not accepted:

Users with older kernels or game controller firmware could get the
mapping between button/axis index and user-visible purpose reported in
the order that would have been correct for a newer kernel or firmware,
causing inputs to have unexpected results. This was reported upstream
for Xbox controllers on older Linux versions, but it's a more general
bug that could affect other devices.

If the user has rw permission on game controllers' /dev/hidraw* device
nodes (for example the steam-devices package sets this up), Playstation
4 gamepads would ignore input while in "simple mode" (rumble/vibration
disabled).

[ Tests ]
Manual testing: launching some open source and proprietary SDL2 games
still works fine. (OpenArena; Steam; Battletech, deleting its bundled
SDL so the system copy will be used, including use of a PS4 controller.)

A rebuild of basically this version (disabling the more obscure audio
backends) is included in the beta branch of Valve's Steam Linux Runtime
compatibility framework, giving it wider testing. That version was
tested with various games before the beta release: according to my
notes, test targets included Aperture Desk Job, Horizon Chase Turbo,
Life is Strange, Life is Strange 2, Battle for Wesnoth, Game Dev Tycoon,
Portal 2 and Steel Rats, with PS4, PS5 and Xbox Series controllers.

There are also autopkgtests, which pass, but they're superficial: most
of SDL deals with input and output that aren't straightforward to test
automatically.

[ Risks ]
In general the changes are narrowly-targeted. The highest risk would be
that the fixes for game controller axis/button mapping could introduce
a bug of similar severity to the one they're fixing (unintended mappings
used).

test/testime.c was re-indented, resulting in a larger than expected diff.
I'm not sure why upstream did this in a stable branch, but that code is a
manual test (/usr/libexec/installed-tests/SDL2/testime in libsdl2-tests)
and is not run by games or during automated testing, so that change
is harmless.

[ Checklist ]
  [x] all changes are documented in the d/changelog
  [x] I reviewed all changes and I approve them
  [x] attach debdiff against the package in testing

unblock libsdl2/2.26.4+dfsg-1
diffstat for libsdl2-2.26.3+dfsg libsdl2-2.26.4+dfsg

 CMakeLists.txt                                              |    2 
 Makefile.os2                                                |    2 
 Makefile.w32                                                |    2 
 SDL2.spec                                                   |    2 
 VERSION.txt                                                 |    2 
 cmake/sdlchecks.cmake                                       |    6 
 configure                                                   |    2 
 configure.ac                                                |    2 
 debian/changelog                                            |   17 ++
 debian/patches/Fixed-Steam-Runtime-sandbox-detection.patch  |   26 ---
 debian/patches/Fixed-handling-simple-mode-PS4-reports.patch |   83 +++++++++++
 debian/patches/series                                       |    2 
 include/SDL_revision.h                                      |    4 
 include/SDL_version.h                                       |    2 
 src/joystick/SDL_gamecontroller.c                           |   41 +++--
 src/joystick/hidapi/SDL_hidapi_ps4.c                        |   17 +-
 src/main/windows/version.rc                                 |    8 -
 src/video/windows/SDL_windowswindow.c                       |    6 
 test/testime.c                                              |   84 +++++-------
 19 files changed, 192 insertions(+), 118 deletions(-)

diff -Nru libsdl2-2.26.3+dfsg/cmake/sdlchecks.cmake libsdl2-2.26.4+dfsg/cmake/sdlchecks.cmake
--- libsdl2-2.26.3+dfsg/cmake/sdlchecks.cmake	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/cmake/sdlchecks.cmake	2023-03-06 23:54:01.000000000 +0000
@@ -991,7 +991,11 @@
         check_c_source_compiles("
             #include <pthread.h>
             int main(int argc, char **argv) {
-              pthread_setname_np(pthread_self(), \"\");
+              #ifdef __APPLE__
+              pthread_setname_np(\"\");
+              #else
+              pthread_setname_np(pthread_self(),\"\");
+              #endif
               return 0;
             }" HAVE_PTHREAD_SETNAME_NP)
         if (HAVE_PTHREAD_NP_H)
diff -Nru libsdl2-2.26.3+dfsg/CMakeLists.txt libsdl2-2.26.4+dfsg/CMakeLists.txt
--- libsdl2-2.26.3+dfsg/CMakeLists.txt	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/CMakeLists.txt	2023-03-06 23:54:00.000000000 +0000
@@ -86,7 +86,7 @@
 # See docs/release_checklist.md
 set(SDL_MAJOR_VERSION 2)
 set(SDL_MINOR_VERSION 26)
-set(SDL_MICRO_VERSION 3)
+set(SDL_MICRO_VERSION 4)
 set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
 
 # Set defaults preventing destination file conflicts
diff -Nru libsdl2-2.26.3+dfsg/configure libsdl2-2.26.4+dfsg/configure
--- libsdl2-2.26.3+dfsg/configure	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/configure	2023-03-06 23:54:01.000000000 +0000
@@ -3454,7 +3454,7 @@
 # See docs/release_checklist.md
 SDL_MAJOR_VERSION=2
 SDL_MINOR_VERSION=26
-SDL_MICRO_VERSION=3
+SDL_MICRO_VERSION=4
 SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION
 
 SDL_BINARY_AGE=`expr $SDL_MINOR_VERSION \* 100 + $SDL_MICRO_VERSION`
diff -Nru libsdl2-2.26.3+dfsg/configure.ac libsdl2-2.26.4+dfsg/configure.ac
--- libsdl2-2.26.3+dfsg/configure.ac	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/configure.ac	2023-03-06 23:54:01.000000000 +0000
@@ -13,7 +13,7 @@
 # See docs/release_checklist.md
 SDL_MAJOR_VERSION=2
 SDL_MINOR_VERSION=26
-SDL_MICRO_VERSION=3
+SDL_MICRO_VERSION=4
 SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION
 
 SDL_BINARY_AGE=`expr $SDL_MINOR_VERSION \* 100 + $SDL_MICRO_VERSION`
diff -Nru libsdl2-2.26.3+dfsg/debian/changelog libsdl2-2.26.4+dfsg/debian/changelog
--- libsdl2-2.26.3+dfsg/debian/changelog	2023-02-16 11:16:09.000000000 +0000
+++ libsdl2-2.26.4+dfsg/debian/changelog	2023-03-09 10:49:35.000000000 +0000
@@ -1,3 +1,20 @@
+libsdl2 (2.26.4+dfsg-1) unstable; urgency=medium
+
+  * New upstream stable release 2.26.4
+    - Game controller mappings no longer overwrite existing mappings with
+      the same vendor/product but a different hardware version, fixing
+      axis/button mapping for some game controllers with older drivers
+      or firmware (SDL#7421)
+    - A Windows-specific fix not relevant to Debian
+    - Reformatting in test/testime.c is not relevant to Debian
+  * d/p/Fixed-Steam-Runtime-sandbox-detection.patch:
+    Drop patch, applied upstream
+  * d/p/Fixed-handling-simple-mode-PS4-reports.patch:
+    Fix some Playstation 4 controllers not providing input in raw HID mode
+    (regression in 2.25.1, SDL#7270)
+
+ -- Simon McVittie <s...@debian.org>  Thu, 09 Mar 2023 10:49:35 +0000
+
 libsdl2 (2.26.3+dfsg-1) unstable; urgency=medium
 
   * New upstream stable release 2.26.3
diff -Nru libsdl2-2.26.3+dfsg/debian/patches/Fixed-handling-simple-mode-PS4-reports.patch libsdl2-2.26.4+dfsg/debian/patches/Fixed-handling-simple-mode-PS4-reports.patch
--- libsdl2-2.26.3+dfsg/debian/patches/Fixed-handling-simple-mode-PS4-reports.patch	1970-01-01 01:00:00.000000000 +0100
+++ libsdl2-2.26.4+dfsg/debian/patches/Fixed-handling-simple-mode-PS4-reports.patch	2023-03-09 10:49:35.000000000 +0000
@@ -0,0 +1,83 @@
+From: Sam Lantinga <slou...@libsdl.org>
+Date: Tue, 14 Feb 2023 17:51:16 -0800
+Subject: Fixed handling simple mode PS4 reports
+
+Fixes https://github.com/libsdl-org/SDL/issues/7270
+
+(cherry picked from commit 5925cd4ef377a2211fd057ef6fa9f41141999cb7)
+(cherry picked from commit 2c6995778e941524a4857b55d4e35745313c924a)
+Origin: upstream, 2.26.5, commit:1723e93a0cce6f6248844391bff1e7cb42cf3ea0
+---
+ src/joystick/hidapi/SDL_hidapi_ps4.c | 17 +++++++++++------
+ 1 file changed, 11 insertions(+), 6 deletions(-)
+
+diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
+index 7582082..4f0a78a 100644
+--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
++++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
+@@ -830,7 +830,7 @@ HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
+ }
+ 
+ static void
+-HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
++HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet, int size)
+ {
+     static const float TOUCHPAD_SCALEX = 1.0f / 1920;
+     static const float TOUCHPAD_SCALEY = 1.0f / 920;    /* This is noted as being 944 resolution, but 920 feels better */
+@@ -933,7 +933,7 @@ HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev,
+     axis = ((int)packet->ucRightJoystickY * 257) - 32768;
+     SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
+ 
+-    if (ctx->device->is_bluetooth && ctx->official_controller) {
++    if (size > 9 && ctx->device->is_bluetooth && ctx->official_controller) {
+         if (packet->ucBatteryLevel & 0x10) {
+             SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED);
+         } else {
+@@ -951,7 +951,7 @@ HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev,
+         }
+     }
+ 
+-    if (ctx->report_touchpad) {
++    if (size > 9 && ctx->report_touchpad) {
+         touchpad_state = ((packet->ucTouchpadCounter1 & 0x80) == 0) ? SDL_PRESSED : SDL_RELEASED;
+         touchpad_x = packet->rgucTouchpadData1[0] | (((int)packet->rgucTouchpadData1[1] & 0x0F) << 8);
+         touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int)packet->rgucTouchpadData1[2] << 4);
+@@ -963,7 +963,7 @@ HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev,
+         SDL_PrivateJoystickTouchpad(joystick, 0, 1, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
+     }
+ 
+-    if (ctx->report_sensors) {
++    if (size > 9 && ctx->report_sensors) {
+         Uint16 timestamp;
+         Uint64 timestamp_us;
+         float data[3];
+@@ -1022,6 +1022,11 @@ HIDAPI_DriverPS4_IsPacketValid(SDL_DriverPS4_Context *ctx, Uint8 *data, int size
+ {
+     switch (data[0]) {
+     case k_EPS4ReportIdUsbState:
++        if (size == 10) {
++            /* This is non-enhanced mode, this packet is fine */
++            return SDL_TRUE;
++        }
++
+         /* In the case of a DS4 USB dongle, bit[2] of byte 31 indicates if a DS4 is actually connected (indicated by '0').
+          * For non-dongle, this bit is always 0 (connected).
+ 		 * This is usually the ID over USB, but the DS4v2 that started shipping with the PS4 Slim will also send this
+@@ -1082,7 +1087,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
+ 
+         switch (data[0]) {
+         case k_EPS4ReportIdUsbState:
+-            HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[1]);
++            HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[1], size - 1);
+             break;
+         case k_EPS4ReportIdBluetoothState1:
+         case k_EPS4ReportIdBluetoothState2:
+@@ -1098,7 +1103,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
+                 HIDAPI_DriverPS4_SetEnhancedMode(device, joystick);
+             }
+             /* Bluetooth state packets have two additional bytes at the beginning, the first notes if HID is present */
+-            HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t*)&data[3]);
++            HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[3], size - 3);
+             break;
+         default:
+ #ifdef DEBUG_JOYSTICK
diff -Nru libsdl2-2.26.3+dfsg/debian/patches/Fixed-Steam-Runtime-sandbox-detection.patch libsdl2-2.26.4+dfsg/debian/patches/Fixed-Steam-Runtime-sandbox-detection.patch
--- libsdl2-2.26.3+dfsg/debian/patches/Fixed-Steam-Runtime-sandbox-detection.patch	2023-02-16 11:16:09.000000000 +0000
+++ libsdl2-2.26.4+dfsg/debian/patches/Fixed-Steam-Runtime-sandbox-detection.patch	1970-01-01 01:00:00.000000000 +0100
@@ -1,26 +0,0 @@
-From: Sam Lantinga <slou...@libsdl.org>
-Date: Wed, 15 Feb 2023 13:53:57 -0800
-Subject: Fixed Steam Runtime sandbox detection
-
-Fixes hotplug issues on Steam Deck for Proton and native games
-
-(cherry picked from commit bcd97b36d23d08226e98a995eafd3d6aa35401b4)
-(cherry picked from commit e7376b7b74026d7da041d2c848e99c9f7f4d74c0)
-Origin: upstream, 2.26.4, commit:6edc0100e1a309aac924bcc1a71087903ab074f4
----
- src/core/linux/SDL_sandbox.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/core/linux/SDL_sandbox.c b/src/core/linux/SDL_sandbox.c
-index 7fb38a4..839fb1a 100644
---- a/src/core/linux/SDL_sandbox.c
-+++ b/src/core/linux/SDL_sandbox.c
-@@ -39,7 +39,7 @@ SDL_Sandbox SDL_DetectSandbox(void)
-         return SDL_SANDBOX_SNAP;
-     }
- 
--    if (access("/run/host/container-runtime", F_OK) == 0) {
-+    if (access("/run/host/container-manager", F_OK) == 0) {
-         return SDL_SANDBOX_UNKNOWN_CONTAINER;
-     }
- 
diff -Nru libsdl2-2.26.3+dfsg/debian/patches/series libsdl2-2.26.4+dfsg/debian/patches/series
--- libsdl2-2.26.3+dfsg/debian/patches/series	2023-02-16 11:16:09.000000000 +0000
+++ libsdl2-2.26.4+dfsg/debian/patches/series	2023-03-09 10:49:35.000000000 +0000
@@ -1,3 +1,3 @@
-Fixed-Steam-Runtime-sandbox-detection.patch
+Fixed-handling-simple-mode-PS4-reports.patch
 no-libdir.patch
 test-Don-t-install-bundled-copy-of-unifont.patch
diff -Nru libsdl2-2.26.3+dfsg/include/SDL_revision.h libsdl2-2.26.4+dfsg/include/SDL_revision.h
--- libsdl2-2.26.3+dfsg/include/SDL_revision.h	2023-02-06 22:49:23.000000000 +0000
+++ libsdl2-2.26.4+dfsg/include/SDL_revision.h	2023-03-06 23:54:18.000000000 +0000
@@ -1,7 +1,7 @@
 /* Generated by updaterev.sh, do not edit */
 #ifdef SDL_VENDOR_INFO
-#define SDL_REVISION "SDL-release-2.26.3-0-gadf31f6ec (" SDL_VENDOR_INFO ")"
+#define SDL_REVISION "SDL-release-2.26.4-0-g07d0f51fa (" SDL_VENDOR_INFO ")"
 #else
-#define SDL_REVISION "SDL-release-2.26.3-0-gadf31f6ec"
+#define SDL_REVISION "SDL-release-2.26.4-0-g07d0f51fa"
 #endif
 #define SDL_REVISION_NUMBER 0
diff -Nru libsdl2-2.26.3+dfsg/include/SDL_version.h libsdl2-2.26.4+dfsg/include/SDL_version.h
--- libsdl2-2.26.3+dfsg/include/SDL_version.h	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/include/SDL_version.h	2023-03-06 23:54:01.000000000 +0000
@@ -59,7 +59,7 @@
 */
 #define SDL_MAJOR_VERSION   2
 #define SDL_MINOR_VERSION   26
-#define SDL_PATCHLEVEL      3
+#define SDL_PATCHLEVEL      4
 
 /**
  * Macro to determine SDL version program was compiled against.
diff -Nru libsdl2-2.26.3+dfsg/Makefile.os2 libsdl2-2.26.4+dfsg/Makefile.os2
--- libsdl2-2.26.3+dfsg/Makefile.os2	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/Makefile.os2	2023-03-06 23:54:00.000000000 +0000
@@ -15,7 +15,7 @@
 LIBNAME = SDL2
 MAJOR_VERSION = 2
 MINOR_VERSION = 26
-MICRO_VERSION = 3
+MICRO_VERSION = 4
 VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)
 DESCRIPTION = Simple DirectMedia Layer 2
 
diff -Nru libsdl2-2.26.3+dfsg/Makefile.w32 libsdl2-2.26.4+dfsg/Makefile.w32
--- libsdl2-2.26.3+dfsg/Makefile.w32	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/Makefile.w32	2023-03-06 23:54:00.000000000 +0000
@@ -6,7 +6,7 @@
 LIBNAME = SDL2
 MAJOR_VERSION = 2
 MINOR_VERSION = 26
-MICRO_VERSION = 3
+MICRO_VERSION = 4
 VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)
 
 LIBHOME = .
diff -Nru libsdl2-2.26.3+dfsg/SDL2.spec libsdl2-2.26.4+dfsg/SDL2.spec
--- libsdl2-2.26.3+dfsg/SDL2.spec	2023-02-06 22:49:22.000000000 +0000
+++ libsdl2-2.26.4+dfsg/SDL2.spec	2023-03-06 23:54:17.000000000 +0000
@@ -1,6 +1,6 @@
 Summary: Simple DirectMedia Layer
 Name: SDL2
-Version: 2.26.3
+Version: 2.26.4
 Release: 2
 Source: http://www.libsdl.org/release/%{name}-%{version}.tar.gz
 URL: http://www.libsdl.org/
diff -Nru libsdl2-2.26.3+dfsg/src/joystick/hidapi/SDL_hidapi_ps4.c libsdl2-2.26.4+dfsg/src/joystick/hidapi/SDL_hidapi_ps4.c
--- libsdl2-2.26.3+dfsg/src/joystick/hidapi/SDL_hidapi_ps4.c	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/src/joystick/hidapi/SDL_hidapi_ps4.c	2023-03-14 09:53:46.000000000 +0000
@@ -830,7 +830,7 @@
 }
 
 static void
-HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
+HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet, int size)
 {
     static const float TOUCHPAD_SCALEX = 1.0f / 1920;
     static const float TOUCHPAD_SCALEY = 1.0f / 920;    /* This is noted as being 944 resolution, but 920 feels better */
@@ -933,7 +933,7 @@
     axis = ((int)packet->ucRightJoystickY * 257) - 32768;
     SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
 
-    if (ctx->device->is_bluetooth && ctx->official_controller) {
+    if (size > 9 && ctx->device->is_bluetooth && ctx->official_controller) {
         if (packet->ucBatteryLevel & 0x10) {
             SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED);
         } else {
@@ -951,7 +951,7 @@
         }
     }
 
-    if (ctx->report_touchpad) {
+    if (size > 9 && ctx->report_touchpad) {
         touchpad_state = ((packet->ucTouchpadCounter1 & 0x80) == 0) ? SDL_PRESSED : SDL_RELEASED;
         touchpad_x = packet->rgucTouchpadData1[0] | (((int)packet->rgucTouchpadData1[1] & 0x0F) << 8);
         touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int)packet->rgucTouchpadData1[2] << 4);
@@ -963,7 +963,7 @@
         SDL_PrivateJoystickTouchpad(joystick, 0, 1, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
     }
 
-    if (ctx->report_sensors) {
+    if (size > 9 && ctx->report_sensors) {
         Uint16 timestamp;
         Uint64 timestamp_us;
         float data[3];
@@ -1022,6 +1022,11 @@
 {
     switch (data[0]) {
     case k_EPS4ReportIdUsbState:
+        if (size == 10) {
+            /* This is non-enhanced mode, this packet is fine */
+            return SDL_TRUE;
+        }
+
         /* In the case of a DS4 USB dongle, bit[2] of byte 31 indicates if a DS4 is actually connected (indicated by '0').
          * For non-dongle, this bit is always 0 (connected).
 		 * This is usually the ID over USB, but the DS4v2 that started shipping with the PS4 Slim will also send this
@@ -1082,7 +1087,7 @@
 
         switch (data[0]) {
         case k_EPS4ReportIdUsbState:
-            HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[1]);
+            HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[1], size - 1);
             break;
         case k_EPS4ReportIdBluetoothState1:
         case k_EPS4ReportIdBluetoothState2:
@@ -1098,7 +1103,7 @@
                 HIDAPI_DriverPS4_SetEnhancedMode(device, joystick);
             }
             /* Bluetooth state packets have two additional bytes at the beginning, the first notes if HID is present */
-            HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t*)&data[3]);
+            HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[3], size - 3);
             break;
         default:
 #ifdef DEBUG_JOYSTICK
diff -Nru libsdl2-2.26.3+dfsg/src/joystick/SDL_gamecontroller.c libsdl2-2.26.4+dfsg/src/joystick/SDL_gamecontroller.c
--- libsdl2-2.26.3+dfsg/src/joystick/SDL_gamecontroller.c	2023-02-06 22:49:05.000000000 +0000
+++ libsdl2-2.26.4+dfsg/src/joystick/SDL_gamecontroller.c	2023-03-06 23:54:01.000000000 +0000
@@ -770,7 +770,7 @@
 /*
  * Helper function to scan the mappings database for a controller with the specified GUID
  */
-static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool create_mapping)
+static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool adding_mapping)
 {
     ControllerMapping_t *mapping;
     Uint16 vendor, product, crc;
@@ -790,6 +790,13 @@
         return mapping;
     }
 
+    if (adding_mapping) {
+        /* We didn't find an existing mapping */
+        return NULL;
+    }
+
+    /* Try harder to get the best match, or create a mapping */
+
     if (vendor && product) {
         /* Try again, ignoring the version */
         if (crc) {
@@ -805,30 +812,24 @@
         }
     }
 
-    if (!create_mapping) {
-        return NULL;
-    }
-
 #if SDL_JOYSTICK_XINPUT
     if (SDL_IsJoystickXInput(guid)) {
         /* This is an XInput device */
         return s_pXInputMapping;
     }
 #endif
-    if (!mapping) {
-        if (SDL_IsJoystickHIDAPI(guid)) {
-            mapping = SDL_CreateMappingForHIDAPIController(guid);
-        } else if (SDL_IsJoystickRAWINPUT(guid)) {
-            mapping = SDL_CreateMappingForRAWINPUTController(guid);
-        } else if (SDL_IsJoystickWGI(guid)) {
-            mapping = SDL_CreateMappingForWGIController(guid);
-        } else if (SDL_IsJoystickVirtual(guid)) {
-            /* We'll pick up a robust mapping in VIRTUAL_JoystickGetGamepadMapping */
+    if (SDL_IsJoystickHIDAPI(guid)) {
+        mapping = SDL_CreateMappingForHIDAPIController(guid);
+    } else if (SDL_IsJoystickRAWINPUT(guid)) {
+        mapping = SDL_CreateMappingForRAWINPUTController(guid);
+    } else if (SDL_IsJoystickWGI(guid)) {
+        mapping = SDL_CreateMappingForWGIController(guid);
+    } else if (SDL_IsJoystickVirtual(guid)) {
+        /* We'll pick up a robust mapping in VIRTUAL_JoystickGetGamepadMapping */
 #ifdef __ANDROID__
-        } else {
-            mapping = SDL_CreateMappingForAndroidController(guid);
+    } else {
+        mapping = SDL_CreateMappingForAndroidController(guid);
 #endif
-        }
     }
     return mapping;
 }
@@ -1276,7 +1277,7 @@
         }
     }
 
-    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(jGUID, SDL_FALSE);
+    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(jGUID, SDL_TRUE);
     if (pControllerMapping) {
         /* Only overwrite the mapping if the priority is the same or higher. */
         if (pControllerMapping->priority <= priority) {
@@ -1336,7 +1337,7 @@
 {
     ControllerMapping_t *mapping;
 
-    mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_TRUE);
+    mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_FALSE);
 #ifdef __LINUX__
     if (!mapping && name) {
         if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
@@ -1751,7 +1752,7 @@
 char *
 SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
 {
-    ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_TRUE);
+    ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_FALSE);
     if (mapping) {
         return CreateMappingString(mapping, guid);
     } else {
diff -Nru libsdl2-2.26.3+dfsg/src/main/windows/version.rc libsdl2-2.26.4+dfsg/src/main/windows/version.rc
--- libsdl2-2.26.3+dfsg/src/main/windows/version.rc	2023-02-06 22:49:06.000000000 +0000
+++ libsdl2-2.26.4+dfsg/src/main/windows/version.rc	2023-03-06 23:54:01.000000000 +0000
@@ -9,8 +9,8 @@
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 2,26,3,0
- PRODUCTVERSION 2,26,3,0
+ FILEVERSION 2,26,4,0
+ PRODUCTVERSION 2,26,4,0
  FILEFLAGSMASK 0x3fL
  FILEFLAGS 0x0L
  FILEOS 0x40004L
@@ -23,12 +23,12 @@
         BEGIN
             VALUE "CompanyName", "\0"
             VALUE "FileDescription", "SDL\0"
-            VALUE "FileVersion", "2, 26, 3, 0\0"
+            VALUE "FileVersion", "2, 26, 4, 0\0"
             VALUE "InternalName", "SDL\0"
             VALUE "LegalCopyright", "Copyright (C) 2023 Sam Lantinga\0"
             VALUE "OriginalFilename", "SDL2.dll\0"
             VALUE "ProductName", "Simple DirectMedia Layer\0"
-            VALUE "ProductVersion", "2, 26, 3, 0\0"
+            VALUE "ProductVersion", "2, 26, 4, 0\0"
         END
     END
     BLOCK "VarFileInfo"
diff -Nru libsdl2-2.26.3+dfsg/src/video/windows/SDL_windowswindow.c libsdl2-2.26.4+dfsg/src/video/windows/SDL_windowswindow.c
--- libsdl2-2.26.3+dfsg/src/video/windows/SDL_windowswindow.c	2023-02-06 22:49:06.000000000 +0000
+++ libsdl2-2.26.4+dfsg/src/video/windows/SDL_windowswindow.c	2023-03-06 23:54:01.000000000 +0000
@@ -1325,14 +1325,16 @@
         (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
         if (mouse->relative_mode && !mouse->relative_mode_warp && data->mouse_relative_mode_center) {
             if (GetWindowRect(data->hwnd, &rect)) {
+                /* WIN_WarpCursor() jitters by +1, and remote desktop warp wobble is +/- 1 */
+                LONG remote_desktop_adjustment = GetSystemMetrics(SM_REMOTESESSION) ? 2 : 0;
                 LONG cx, cy;
 
                 cx = (rect.left + rect.right) / 2;
                 cy = (rect.top + rect.bottom) / 2;
 
                 /* Make an absurdly small clip rect */
-                rect.left = cx;
-                rect.right = cx + 1;
+                rect.left = cx - remote_desktop_adjustment;
+                rect.right = cx + 1 + remote_desktop_adjustment;
                 rect.top = cy;
                 rect.bottom = cy + 1;
 
diff -Nru libsdl2-2.26.3+dfsg/test/testime.c libsdl2-2.26.4+dfsg/test/testime.c
--- libsdl2-2.26.3+dfsg/test/testime.c	2023-02-06 22:49:06.000000000 +0000
+++ libsdl2-2.26.4+dfsg/test/testime.c	2023-03-06 23:54:01.000000000 +0000
@@ -679,7 +679,6 @@
         return 2;
     }
 
-
 #ifdef HAVE_SDL_TTF
     /* Initialize fonts */
     TTF_Init();
@@ -714,51 +713,44 @@
         while (SDL_PollEvent(&event)) {
             SDLTest_CommonEvent(state, &event, &done);
             switch(event.type) {
-                case SDL_KEYDOWN: {
-                    switch (event.key.keysym.sym)
-                    {
-                        case SDLK_RETURN:
-                             text[0]=0x00;
-                             Redraw();
-                             break;
-                        case SDLK_BACKSPACE:
-                            /* Only delete text if not in editing mode. */
-                             if (!markedText[0])
-                             {
-                                 size_t textlen = SDL_strlen(text);
-
-                                 do {
-                                     if (textlen==0)
-                                     {
-                                         break;
-                                     }
-                                     if ((text[textlen-1] & 0x80) == 0x00)
-                                     {
-                                         /* One byte */
-                                         text[textlen-1]=0x00;
-                                         break;
-                                     }
-                                     if ((text[textlen-1] & 0xC0) == 0x80)
-                                     {
-                                         /* Byte from the multibyte sequence */
-                                         text[textlen-1]=0x00;
-                                         textlen--;
-                                     }
-                                     if ((text[textlen-1] & 0xC0) == 0xC0)
-                                     {
-                                         /* First byte of multibyte sequence */
-                                         text[textlen-1]=0x00;
-                                         break;
-                                     }
-                                 } while(1);
-
-                                 Redraw();
-                             }
-                             break;
+                case SDL_KEYDOWN:
+                    switch (event.key.keysym.sym) {
+                    case SDLK_RETURN:
+                        text[0] = 0x00;
+                        Redraw();
+                        break;
+                    case SDLK_BACKSPACE:
+                        /* Only delete text if not in editing mode. */
+                        if (!markedText[0]) {
+                            size_t textlen = SDL_strlen(text);
+
+                            do {
+                                if (textlen == 0) {
+                                    break;
+                                }
+                                if ((text[textlen - 1] & 0x80) == 0x00) {
+                                    /* One byte */
+                                    text[textlen - 1] = 0x00;
+                                    break;
+                                }
+                                if ((text[textlen - 1] & 0xC0) == 0x80) {
+                                    /* Byte from the multibyte sequence */
+                                    text[textlen - 1] = 0x00;
+                                    textlen--;
+                                }
+                                if ((text[textlen - 1] & 0xC0) == 0xC0) {
+                                    /* First byte of multibyte sequence */
+                                    text[textlen - 1] = 0x00;
+                                    break;
+                                }
+                            } while(1);
+
+                            Redraw();
+                        }
+                        break;
                     }
 
-                    if (done)
-                    {
+                    if (done) {
                         break;
                     }
 
@@ -796,9 +788,6 @@
                     Redraw();
                     break;
                 }
-                break;
-
-            }
         }
     }
     CleanupVideo();
@@ -806,5 +795,4 @@
     return 0;
 }
 
-
 /* vi: set ts=4 sw=4 expandtab: */
diff -Nru libsdl2-2.26.3+dfsg/VERSION.txt libsdl2-2.26.4+dfsg/VERSION.txt
--- libsdl2-2.26.3+dfsg/VERSION.txt	2023-02-06 22:49:23.000000000 +0000
+++ libsdl2-2.26.4+dfsg/VERSION.txt	2023-03-06 23:54:18.000000000 +0000
@@ -1 +1 @@
-release-2.26.3-0-gadf31f6ec
+release-2.26.4-0-g07d0f51fa

Reply via email to