pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/devel



Module Name:    pkgsrc
Committed By:   nia
Date:           Sun Nov 12 21:28:04 UTC 2023

Modified Files:
        pkgsrc/devel/SDL2: Makefile buildlink3.mk
Added Files:
        pkgsrc/devel/SDL2-legacy-darwin: DESCR Makefile PLIST buildlink3.mk
            distinfo options.mk
        pkgsrc/devel/SDL2-legacy-darwin/patches: patch-include_SDL__platform.h
            patch-include_SDL__syswm.h
            patch-src_audio_coreaudio_SDL__coreaudio.h
            patch-src_cpuinfo_SDL__cpuinfo.c
            patch-src_file_cocoa_SDL__rwopsbundlesupport.m
            patch-src_filesystem_cocoa_SDL__sysfilesystem.m
            patch-src_joystick_darwin_SDL__sysjoystick.c
            patch-src_joystick_darwin_SDL__sysjoystick__c.h
            patch-src_power_macosx_SDL__syspower.c
            patch-src_thread_pthread_SDL__systhread.c
            patch-src_video_cocoa_SDL__cocoaclipboard.m
            patch-src_video_cocoa_SDL__cocoakeyboard.m
            patch-src_video_cocoa_SDL__cocoamessagebox.m
            patch-src_video_cocoa_SDL__cocoamodes.m
            patch-src_video_cocoa_SDL__cocoamouse.h
            patch-src_video_cocoa_SDL__cocoaopengl.m
            patch-src_video_cocoa_SDL__cocoavideo.h
            patch-src_video_cocoa_SDL__cocoavideo.m
            patch-src_video_cocoa_SDL__cocoawindow.h
            patch-src_video_cocoa_SDL__cocoawindow.m
            patch-src_video_x11_SDL__x11opengl.c

Log Message:
import SDL2-2.0.3 as devel/SDL2-legacy-darwin

This is the version of SDL2 from TigerPorts and TigerBrew.

Simple DirectMedia Layer is a cross-platform development library designed to
provide low level access to audio, keyboard, mouse, joystick, and graphics
hardware via OpenGL and Direct3D. It is used by video playback software,
emulators, and popular games including Valve's award winning catalog and many
Humble Bundle games.

SDL officially supports Windows, Mac OS X, Linux, iOS, and Android. Support for
other platforms may be found in the source code.

SDL is written in C, works natively with C++, and there are bindings available
for several other languages, including C# and Python.

SDL 2.0 is distributed under the zlib license. This license allows you to use
SDL freely in any software.

This package is based on an older version of SDL2 suitable for use with
legacy platforms such as PowerPC versions of Mac OS X. Features such as
synchronous audio are unavailable. It may also be useful for developers
seeking to target a wide range of SDL2 versions.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 pkgsrc/devel/SDL2/Makefile
cvs rdiff -u -r1.18 -r1.19 pkgsrc/devel/SDL2/buildlink3.mk
cvs rdiff -u -r0 -r1.1 pkgsrc/devel/SDL2-legacy-darwin/DESCR \
    pkgsrc/devel/SDL2-legacy-darwin/Makefile \
    pkgsrc/devel/SDL2-legacy-darwin/PLIST \
    pkgsrc/devel/SDL2-legacy-darwin/buildlink3.mk \
    pkgsrc/devel/SDL2-legacy-darwin/distinfo \
    pkgsrc/devel/SDL2-legacy-darwin/options.mk
cvs rdiff -u -r0 -r1.1 \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-include_SDL__platform.h \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-include_SDL__syswm.h \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_audio_coreaudio_SDL__coreaudio.h \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_cpuinfo_SDL__cpuinfo.c \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_file_cocoa_SDL__rwopsbundlesupport.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_filesystem_cocoa_SDL__sysfilesystem.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_joystick_darwin_SDL__sysjoystick.c \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_joystick_darwin_SDL__sysjoystick__c.h \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_power_macosx_SDL__syspower.c \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_thread_pthread_SDL__systhread.c \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoaclipboard.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoakeyboard.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamessagebox.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamodes.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamouse.h \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoaopengl.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoavideo.h \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoavideo.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoawindow.h \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoawindow.m \
    pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_x11_SDL__x11opengl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/devel/SDL2/Makefile
diff -u pkgsrc/devel/SDL2/Makefile:1.84 pkgsrc/devel/SDL2/Makefile:1.85
--- pkgsrc/devel/SDL2/Makefile:1.84     Thu Nov  2 19:34:12 2023
+++ pkgsrc/devel/SDL2/Makefile  Sun Nov 12 21:28:04 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.84 2023/11/02 19:34:12 adam Exp $
+# $NetBSD: Makefile,v 1.85 2023/11/12 21:28:04 nia Exp $
 
 DISTNAME=      SDL2-2.28.5
 CATEGORIES=    devel
@@ -16,6 +16,9 @@ USE_LIBTOOL=  yes
 USE_TOOLS+=    gmake pkg-config
 GNU_CONFIGURE= yes
 
+# See devel/SDL2-legacy-darwin
+NOT_FOR_PLATFORM+=     Darwin-*-powerpc*
+
 # Let pkgsrc handle the rpath.
 CONFIGURE_ARGS+=       --disable-rpath
 

Index: pkgsrc/devel/SDL2/buildlink3.mk
diff -u pkgsrc/devel/SDL2/buildlink3.mk:1.18 pkgsrc/devel/SDL2/buildlink3.mk:1.19
--- pkgsrc/devel/SDL2/buildlink3.mk:1.18        Sat May  6 19:08:48 2023
+++ pkgsrc/devel/SDL2/buildlink3.mk     Sun Nov 12 21:28:04 2023
@@ -1,7 +1,13 @@
-# $NetBSD: buildlink3.mk,v 1.18 2023/05/06 19:08:48 ryoon Exp $
+# $NetBSD: buildlink3.mk,v 1.19 2023/11/12 21:28:04 nia Exp $
 
 BUILDLINK_TREE+=       SDL2
 
+.include "../../mk/bsd.fast.prefs.mk"
+.if ${MACHINE_PLATFORM:MDarwin-*-powerpc*}
+# This defines SDL2_BUILDLINK3_MK.
+.  include "../../devel/SDL2-legacy-darwin/buildlink3.mk"
+.endif
+
 .if !defined(SDL2_BUILDLINK3_MK)
 SDL2_BUILDLINK3_MK:=
 

Added files:

Index: pkgsrc/devel/SDL2-legacy-darwin/DESCR
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/DESCR:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/DESCR       Sun Nov 12 21:28:04 2023
@@ -0,0 +1,19 @@
+Simple DirectMedia Layer is a cross-platform development library designed to
+provide low level access to audio, keyboard, mouse, joystick, and graphics
+hardware via OpenGL and Direct3D. It is used by video playback software,
+emulators, and popular games including Valve's award winning catalog and many
+Humble Bundle games.
+
+SDL officially supports Windows, Mac OS X, Linux, iOS, and Android. Support for
+other platforms may be found in the source code.
+
+SDL is written in C, works natively with C++, and there are bindings available
+for several other languages, including C# and Python.
+
+SDL 2.0 is distributed under the zlib license. This license allows you to use
+SDL freely in any software.
+
+This package is based on an older version of SDL2 suitable for use with
+legacy platforms such as PowerPC versions of Mac OS X. Features such as
+synchronous audio are unavailable. It may also be useful for developers
+seeking to target a wide range of SDL2 versions.
Index: pkgsrc/devel/SDL2-legacy-darwin/Makefile
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/Makefile:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/Makefile    Sun Nov 12 21:28:04 2023
@@ -0,0 +1,49 @@
+# $NetBSD: Makefile,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+DISTNAME=      SDL2-2.0.3
+CATEGORIES=    devel
+MASTER_SITES=  https://libsdl.org/release/
+
+MAINTAINER=    nia%NetBSD.org@localhost
+HOMEPAGE=      https://www.libsdl.org/
+COMMENT=       Legacy SDL2 suitable for old Mac OS X versions
+LICENSE=       zlib
+
+USE_LIBTOOL=   yes
+USE_TOOLS+=    gmake pkg-config
+GNU_CONFIGURE= yes
+
+# Let pkgsrc handle the rpath.
+CONFIGURE_ARGS+=       --disable-rpath
+
+# Explicitly link against libraries.
+CONFIGURE_ARGS+=       --disable-alsa-shared
+CONFIGURE_ARGS+=       --disable-pulseaudio-shared
+CONFIGURE_ARGS+=       --disable-x11-shared
+
+# Deprecated, removed from pkgsrc.
+CONFIGURE_ARGS+=       --disable-esd
+
+CONFIGURE_ARGS+=       --disable-video-wayland
+CONFIGURE_ARGS.Darwin+=        --disable-haptic
+
+# Needed to support the older joystick controller.
+LDFLAGS.Darwin+=       -framework ForceFeedback
+
+.include "../../mk/bsd.prefs.mk"
+
+# Runtime detection is lacking and illegal instruction faults happen
+# on e.g. QEMU with -cpu pentium.
+.if ${MACHINE_ARCH} == "i386"
+CONFIGURE_ARGS+=       --disable-sse
+CONFIGURE_ARGS+=       --disable-ssemath
+CONFIGURE_ARGS+=       --disable-sse2
+.endif
+
+PKGCONFIG_OVERRIDE+=   sdl2.pc.in
+
+.include "options.mk"
+.include "../../converters/libiconv/buildlink3.mk"
+.include "../../mk/dlopen.buildlink3.mk"
+.include "../../mk/pthread.buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
Index: pkgsrc/devel/SDL2-legacy-darwin/PLIST
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/PLIST:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/PLIST       Sun Nov 12 21:28:04 2023
@@ -0,0 +1,71 @@
+@comment $NetBSD: PLIST,v 1.1 2023/11/12 21:28:04 nia Exp $
+bin/sdl2-config
+include/SDL2/SDL.h
+include/SDL2/SDL_assert.h
+include/SDL2/SDL_atomic.h
+include/SDL2/SDL_audio.h
+include/SDL2/SDL_bits.h
+include/SDL2/SDL_blendmode.h
+include/SDL2/SDL_clipboard.h
+include/SDL2/SDL_config.h
+include/SDL2/SDL_cpuinfo.h
+include/SDL2/SDL_endian.h
+include/SDL2/SDL_error.h
+include/SDL2/SDL_events.h
+include/SDL2/SDL_filesystem.h
+include/SDL2/SDL_gamecontroller.h
+include/SDL2/SDL_gesture.h
+include/SDL2/SDL_haptic.h
+include/SDL2/SDL_hints.h
+include/SDL2/SDL_joystick.h
+include/SDL2/SDL_keyboard.h
+include/SDL2/SDL_keycode.h
+include/SDL2/SDL_loadso.h
+include/SDL2/SDL_log.h
+include/SDL2/SDL_main.h
+include/SDL2/SDL_messagebox.h
+include/SDL2/SDL_mouse.h
+include/SDL2/SDL_mutex.h
+include/SDL2/SDL_name.h
+include/SDL2/SDL_opengl.h
+include/SDL2/SDL_opengles.h
+include/SDL2/SDL_opengles2.h
+include/SDL2/SDL_pixels.h
+include/SDL2/SDL_platform.h
+include/SDL2/SDL_power.h
+include/SDL2/SDL_quit.h
+include/SDL2/SDL_rect.h
+include/SDL2/SDL_render.h
+include/SDL2/SDL_revision.h
+include/SDL2/SDL_rwops.h
+include/SDL2/SDL_scancode.h
+include/SDL2/SDL_shape.h
+include/SDL2/SDL_stdinc.h
+include/SDL2/SDL_surface.h
+include/SDL2/SDL_system.h
+include/SDL2/SDL_syswm.h
+include/SDL2/SDL_test.h
+include/SDL2/SDL_test_assert.h
+include/SDL2/SDL_test_common.h
+include/SDL2/SDL_test_compare.h
+include/SDL2/SDL_test_crc32.h
+include/SDL2/SDL_test_font.h
+include/SDL2/SDL_test_fuzzer.h
+include/SDL2/SDL_test_harness.h
+include/SDL2/SDL_test_images.h
+include/SDL2/SDL_test_log.h
+include/SDL2/SDL_test_md5.h
+include/SDL2/SDL_test_random.h
+include/SDL2/SDL_thread.h
+include/SDL2/SDL_timer.h
+include/SDL2/SDL_touch.h
+include/SDL2/SDL_types.h
+include/SDL2/SDL_version.h
+include/SDL2/SDL_video.h
+include/SDL2/begin_code.h
+include/SDL2/close_code.h
+lib/libSDL2.la
+lib/libSDL2_test.a
+lib/libSDL2main.a
+lib/pkgconfig/sdl2.pc
+share/aclocal/sdl2.m4
Index: pkgsrc/devel/SDL2-legacy-darwin/buildlink3.mk
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/buildlink3.mk:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/buildlink3.mk       Sun Nov 12 21:28:04 2023
@@ -0,0 +1,50 @@
+# $NetBSD: buildlink3.mk,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+BUILDLINK_TREE+=       SDL2
+
+.if !defined(SDL2_BUILDLINK3_MK)
+SDL2_BUILDLINK3_MK:=
+
+BUILDLINK_ABI_DEPENDS.SDL2+=   SDL2>=2.0.3
+BUILDLINK_API_DEPENDS.SDL2+=   SDL2>=2.0.3<2.1.0
+BUILDLINK_PKGSRCDIR.SDL2?=     ../../devel/SDL2-legacy-darwin
+BUILDLINK_INCDIRS.SDL2+=       include/SDL2
+
+pkgbase := SDL2
+.include "../../mk/pkg-build-options.mk"
+
+.if ${PKG_BUILD_OPTIONS.SDL2:Malsa}
+.include "../../audio/alsa-lib/buildlink3.mk"
+.endif
+
+.if ${PKG_BUILD_OPTIONS.SDL2:Mpulseaudio}
+.include "../../audio/pulseaudio/buildlink3.mk"
+.endif
+
+.if ${PKG_BUILD_OPTIONS.SDL2:Mnas}
+.include "../../audio/nas/buildlink3.mk"
+.endif
+
+.if ${PKG_BUILD_OPTIONS.SDL2:Mopengl} && ${OPSYS} != "Darwin"
+.include "../../graphics/MesaLib/buildlink3.mk"
+.endif
+
+.if ${PKG_BUILD_OPTIONS.SDL2:Mrpi}
+.include "../../misc/raspberrypi-userland/buildlink3.mk"
+.endif
+
+.if ${PKG_BUILD_OPTIONS.SDL2:Mx11}
+.include "../../x11/libXcursor/buildlink3.mk"
+.include "../../x11/libXi/buildlink3.mk"
+.include "../../x11/libXinerama/buildlink3.mk"
+.include "../../x11/libXrandr/buildlink3.mk"
+.include "../../x11/libXScrnSaver/buildlink3.mk"
+.endif
+
+.include "../../converters/libiconv/buildlink3.mk"
+.include "../../mk/dlopen.buildlink3.mk"
+.include "../../mk/pthread.buildlink3.mk"
+
+.endif # SDL2_BUILDLINK3_MK
+
+BUILDLINK_TREE+=       -SDL2
Index: pkgsrc/devel/SDL2-legacy-darwin/distinfo
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/distinfo:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/distinfo    Sun Nov 12 21:28:04 2023
@@ -0,0 +1,26 @@
+$NetBSD: distinfo,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+BLAKE2s (SDL2-2.0.3.tar.gz) = 8b452c9d005e8b6da7b1cb8ab3e019522894714aa75c3c5ff100b49b1e75d1f6
+SHA512 (SDL2-2.0.3.tar.gz) = b6d2485154fbc07ab86a4305485e116d35fac25a97033b9e1c65ee0eb8251a18209cb1de3a914d9c0ddc53aa1ffac66c865b111d218e79eb5a10ed00dfec7540
+Size (SDL2-2.0.3.tar.gz) = 3871267 bytes
+SHA1 (patch-include_SDL__platform.h) = 6342e9528e5f5ecaae76a9cc9b196e0a7c0994ab
+SHA1 (patch-include_SDL__syswm.h) = f0a20f2536a7c0079053ff3a5069a580b036e9ec
+SHA1 (patch-src_audio_coreaudio_SDL__coreaudio.h) = 74d1a7782a177407b5ed571a8b86ea0ce7638048
+SHA1 (patch-src_cpuinfo_SDL__cpuinfo.c) = aa77236a2f9e6a662bb7671eb3a5a481a1a9478f
+SHA1 (patch-src_file_cocoa_SDL__rwopsbundlesupport.m) = 0fbd9d7f0f07ae3d00eaee7228305859d1109fb4
+SHA1 (patch-src_filesystem_cocoa_SDL__sysfilesystem.m) = f19fffa10898ac8bc772089af5b020c5246d3c41
+SHA1 (patch-src_joystick_darwin_SDL__sysjoystick.c) = c3c0490b51413003bb09a68489cb8fd67dab6ee3
+SHA1 (patch-src_joystick_darwin_SDL__sysjoystick__c.h) = a6b1e701949b7ea7173e01c586138c5938c0e6d0
+SHA1 (patch-src_power_macosx_SDL__syspower.c) = fbca2984f8738ed3b74417a209c2bdef69f06dd0
+SHA1 (patch-src_thread_pthread_SDL__systhread.c) = 13772719c7a2d2a408d3b5838636d51f25575965
+SHA1 (patch-src_video_cocoa_SDL__cocoaclipboard.m) = a9af5f93b3c96cebd7495159f0cb6257ae0bbfd1
+SHA1 (patch-src_video_cocoa_SDL__cocoakeyboard.m) = 1795e77319d759b4c372fe72adf3c4a1ae02ede0
+SHA1 (patch-src_video_cocoa_SDL__cocoamessagebox.m) = d3195f9c560205531957d0380608ce60fc42abec
+SHA1 (patch-src_video_cocoa_SDL__cocoamodes.m) = ac7e6996da2323d9f8b0bbc0520839d98181b949
+SHA1 (patch-src_video_cocoa_SDL__cocoamouse.h) = 12128f15544e898c02f700f48a644e836848ca55
+SHA1 (patch-src_video_cocoa_SDL__cocoaopengl.m) = 6d1099e16c491577bd033a77d87f5b35e9a96829
+SHA1 (patch-src_video_cocoa_SDL__cocoavideo.h) = eb74c336f935c3308cd31ef2b7c344cae98372b6
+SHA1 (patch-src_video_cocoa_SDL__cocoavideo.m) = 0f508c257ed89b6c0680d277e5bfb5aa5391f97c
+SHA1 (patch-src_video_cocoa_SDL__cocoawindow.h) = 4a0fe88e8f6d22afeb3587e23309b548abd60568
+SHA1 (patch-src_video_cocoa_SDL__cocoawindow.m) = 93903df0d968994b4c1c88f588ac5c11324ba318
+SHA1 (patch-src_video_x11_SDL__x11opengl.c) = 6df31f56c49a2173ee4ac78286c93a54ae8a9156
Index: pkgsrc/devel/SDL2-legacy-darwin/options.mk
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/options.mk:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/options.mk  Sun Nov 12 21:28:04 2023
@@ -0,0 +1,72 @@
+# $NetBSD: options.mk,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+PKG_OPTIONS_VAR=               PKG_OPTIONS.SDL2
+PKG_OPTIONS_OPTIONAL_GROUPS=   gl
+PKG_SUPPORTED_OPTIONS=         alsa dbus nas pulseaudio x11
+PKG_SUGGESTED_OPTIONS.Linux=   alsa
+PKG_OPTIONS_GROUP.gl=          opengl
+PKG_SUGGESTED_OPTIONS+=                opengl
+
+.include "../../mk/bsd.fast.prefs.mk"
+
+.if ${OPSYS} == "NetBSD" && ${MACHINE_ARCH:Mearm*}
+PKG_OPTIONS_GROUP.gl+= rpi
+.endif
+
+.if ${OPSYS} != "Darwin"
+PKG_SUGGESTED_OPTIONS+=        x11
+.endif
+
+.include "../../mk/bsd.options.mk"
+
+.if !empty(PKG_OPTIONS:Malsa)
+.include "../../audio/alsa-lib/buildlink3.mk"
+.else
+CONFIGURE_ARGS+=       --disable-alsa
+.endif
+
+.if !empty(PKG_OPTIONS:Mdbus)
+.include "../../sysutils/dbus/buildlink3.mk"
+.else
+CONFIGURE_ARGS+=       --disable-dbus
+.endif
+
+.if !empty(PKG_OPTIONS:Mnas)
+.include "../../audio/nas/buildlink3.mk"
+.else
+CONFIGURE_ARGS+=       --disable-nas
+.endif
+
+.if !empty(PKG_OPTIONS:Mopengl)
+.  if ${OPSYS} != "Darwin"
+.include "../../graphics/MesaLib/buildlink3.mk"
+.  endif
+.else
+CONFIGURE_ARGS+=       --disable-video-opengl
+.endif
+
+.if !empty(PKG_OPTIONS:Mpulseaudio)
+.include "../../audio/pulseaudio/buildlink3.mk"
+.else
+CONFIGURE_ARGS+=       --disable-pulseaudio
+.endif
+
+.if !empty(PKG_OPTIONS:Mx11)
+.include "../../x11/libXScrnSaver/buildlink3.mk"
+.include "../../x11/libXcursor/buildlink3.mk"
+.include "../../x11/libXi/buildlink3.mk"
+.include "../../x11/libXinerama/buildlink3.mk"
+.include "../../x11/libXrandr/buildlink3.mk"
+.else
+CONFIGURE_ARGS+=       --disable-video-x11
+.endif
+
+.if !empty(PKG_OPTIONS:Mrpi)
+LOWER_VENDOR=          raspberry
+SUBST_CLASSES+=                vc
+SUBST_STAGE.vc=                pre-configure
+SUBST_MESSAGE.vc=      Fixing path to VideoCore libraries.
+SUBST_FILES.vc=                configure
+SUBST_SED.vc+=         -e "s;/opt/vc;${PREFIX};g"
+.include "../../misc/raspberrypi-userland/buildlink3.mk"
+.endif

Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-include_SDL__platform.h
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-include_SDL__platform.h:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-include_SDL__platform.h       Sun Nov 12 21:28:04 2023
@@ -0,0 +1,26 @@
+$NetBSD: patch-include_SDL__platform.h,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- include/SDL_platform.h.orig        2014-03-16 02:31:42.000000000 +0000
++++ include/SDL_platform.h
+@@ -70,7 +70,7 @@
+ /* lets us know what version of Mac OS X we're compiling on */
+ #include "AvailabilityMacros.h"
+ #include "TargetConditionals.h"
+-#if TARGET_OS_IPHONE
++#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+ /* if compiling for iPhone */
+ #undef __IPHONEOS__
+ #define __IPHONEOS__ 1
+@@ -80,7 +80,9 @@
+ #undef __MACOSX__
+ #define __MACOSX__  1
+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
++#if 0
+ # error SDL for Mac OS X only supports deploying on 10.5 and above.
++#endif
+ #endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */
+ #endif /* TARGET_OS_IPHONE */
+ #endif /* defined(__APPLE__) */
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-include_SDL__syswm.h
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-include_SDL__syswm.h:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-include_SDL__syswm.h  Sun Nov 12 21:28:04 2023
@@ -0,0 +1,20 @@
+$NetBSD: patch-include_SDL__syswm.h,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- include/SDL_syswm.h.orig   2014-03-16 02:31:42.000000000 +0000
++++ include/SDL_syswm.h
+@@ -83,6 +83,12 @@ struct SDL_SysWMinfo;
+ 
+ #if defined(SDL_VIDEO_DRIVER_COCOA)
+ #ifdef __OBJC__
++#if defined(__ALTIVEC__) && !defined(MAC_OS_X_VERSION_10_5)
++/* to cricumvent a bug in Mac OS X 10.4 SDK */
++#define vector __vector
++#include <CoreServices/CoreServices.h>
++#undef vector
++#endif
+ #include <Cocoa/Cocoa.h>
+ #else
+ typedef struct _NSWindow NSWindow;
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_audio_coreaudio_SDL__coreaudio.h
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_audio_coreaudio_SDL__coreaudio.h:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_audio_coreaudio_SDL__coreaudio.h  Sun Nov 12 21:28:04 2023
@@ -0,0 +1,22 @@
+$NetBSD: patch-src_audio_coreaudio_SDL__coreaudio.h,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/audio/coreaudio/SDL_coreaudio.h.orig   2014-03-16 02:31:44.000000000 +0000
++++ src/audio/coreaudio/SDL_coreaudio.h
+@@ -31,7 +31,14 @@
+ 
+ #if MACOSX_COREAUDIO
+ #include <CoreAudio/CoreAudio.h>
++#if defined(__ALTIVEC__) && !defined(MAC_OS_X_VERSION_10_5)
++/* to cricumvent a bug in Mac OS X 10.4 SDK */
++#define vector __vector
+ #include <CoreServices/CoreServices.h>
++#undef vector
++#else
++#include <CoreServices/CoreServices.h>
++#endif
+ #else
+ #include <AudioToolbox/AudioToolbox.h>
+ #endif
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_cpuinfo_SDL__cpuinfo.c
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_cpuinfo_SDL__cpuinfo.c:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_cpuinfo_SDL__cpuinfo.c    Sun Nov 12 21:28:04 2023
@@ -0,0 +1,17 @@
+$NetBSD: patch-src_cpuinfo_SDL__cpuinfo.c,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+NetBSD support.
+
+--- src/cpuinfo/SDL_cpuinfo.c.orig     2014-03-16 02:31:44.000000000 +0000
++++ src/cpuinfo/SDL_cpuinfo.c
+@@ -665,7 +665,9 @@ SDL_GetSystemRAM(void)
+ #endif
+ #ifdef HAVE_SYSCTLBYNAME
+         if (SDL_SystemRAM <= 0) {
+-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
++#ifdef HW_PHYSMEM64
++            int mib[2] = {CTL_HW, HW_PHYSMEM64};
++#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ #ifdef HW_REALMEM
+             int mib[2] = {CTL_HW, HW_REALMEM};
+ #else
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_file_cocoa_SDL__rwopsbundlesupport.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_file_cocoa_SDL__rwopsbundlesupport.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_file_cocoa_SDL__rwopsbundlesupport.m      Sun Nov 12 21:28:04 2023
@@ -0,0 +1,20 @@
+$NetBSD: patch-src_file_cocoa_SDL__rwopsbundlesupport.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/file/cocoa/SDL_rwopsbundlesupport.m.orig       2014-03-16 02:31:41.000000000 +0000
++++ src/file/cocoa/SDL_rwopsbundlesupport.m
+@@ -21,6 +21,12 @@
+ #include "../../SDL_internal.h"
+ 
+ #ifdef __APPLE__
++#if defined(__ALTIVEC__) && !defined(MAC_OS_X_VERSION_10_5)
++/* to cricumvent a bug in Mac OS X 10.4 SDK */
++#define vector __vector
++#include <CoreServices/CoreServices.h>
++#undef vector
++#endif
+ #import <Foundation/Foundation.h>
+ 
+ #include "SDL_rwopsbundlesupport.h"
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_filesystem_cocoa_SDL__sysfilesystem.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_filesystem_cocoa_SDL__sysfilesystem.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_filesystem_cocoa_SDL__sysfilesystem.m     Sun Nov 12 21:28:04 2023
@@ -0,0 +1,20 @@
+$NetBSD: patch-src_filesystem_cocoa_SDL__sysfilesystem.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/filesystem/cocoa/SDL_sysfilesystem.m.orig      2014-03-16 02:31:41.000000000 +0000
++++ src/filesystem/cocoa/SDL_sysfilesystem.m
+@@ -25,6 +25,12 @@
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ /* System dependent filesystem routines                                */
+ 
++#if defined(__ALTIVEC__) && !defined(MAC_OS_X_VERSION_10_5)
++/* to cricumvent a bug in Mac OS X 10.4 SDK */
++#define vector __vector
++#include <CoreServices/CoreServices.h>
++#undef vector
++#endif
+ #include <Foundation/Foundation.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_joystick_darwin_SDL__sysjoystick.c
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_joystick_darwin_SDL__sysjoystick.c:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_joystick_darwin_SDL__sysjoystick.c        Sun Nov 12 21:28:04 2023
@@ -0,0 +1,1421 @@
+$NetBSD: patch-src_joystick_darwin_SDL__sysjoystick.c,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/joystick/darwin/SDL_sysjoystick.c.orig 2014-03-16 02:31:41.000000000 +0000
++++ src/joystick/darwin/SDL_sysjoystick.c
+@@ -1,6 +1,6 @@
+ /*
+   Simple DirectMedia Layer
+-  Copyright (C) 1997-2014 Sam Lantinga <slouken%libsdl.org@localhost>
++  Copyright (C) 1997-2013 Sam Lantinga <slouken%libsdl.org@localhost>
+ 
+   This software is provided 'as-is', without any express or implied
+   warranty.  In no event will the authors be held liable for any damages
+@@ -18,11 +18,31 @@
+      misrepresented as being the original software.
+   3. This notice may not be removed or altered from any source distribution.
+ */
+-#include "../../SDL_internal.h"
++#include "SDL_config.h"
+ 
+ #ifdef SDL_JOYSTICK_IOKIT
+ 
++/* SDL joystick driver for Darwin / Mac OS X, based on the IOKit HID API */
++/* Written 2001 by Max Horn */
++
++#include <unistd.h>
++#include <ctype.h>
++#include <sysexits.h>
++#include <mach/mach.h>
++#include <mach/mach_error.h>
++#include <IOKit/IOKitLib.h>
++#include <IOKit/IOCFPlugIn.h>
++#ifdef MACOS_10_0_4
++#include <IOKit/hidsystem/IOHIDUsageTables.h>
++#else
++/* The header was moved here in Mac OS X 10.1 */
++#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
++#endif
+ #include <IOKit/hid/IOHIDLib.h>
++#include <IOKit/hid/IOHIDKeys.h>
++#include <CoreFoundation/CoreFoundation.h>
++#include <Carbon/Carbon.h>      /* for NewPtrClear, DisposePtr */
++#include <IOKit/IOMessage.h>
+ 
+ /* For force feedback testing. */
+ #include <ForceFeedback/ForceFeedback.h>
+@@ -33,365 +53,639 @@
+ #include "../SDL_joystick_c.h"
+ #include "SDL_sysjoystick_c.h"
+ #include "SDL_events.h"
+-#include "../../haptic/darwin/SDL_syshaptic_c.h"    /* For haptic hot plugging */
+ #if !SDL_EVENTS_DISABLED
+ #include "../../events/SDL_events_c.h"
+ #endif
+ 
+-/* The base object of the HID Manager API */
+-static IOHIDManagerRef hidman = NULL;
+ 
+ /* Linked list of all available devices */
+ static recDevice *gpDeviceList = NULL;
+-
+-/* if SDL_TRUE then a device was added since the last update call */
++/* OSX reference to the notification object that tells us about device insertion/removal */
++IONotificationPortRef notificationPort = 0;
++/* if 1 then a device was added since the last update call */
+ static SDL_bool s_bDeviceAdded = SDL_FALSE;
+ static SDL_bool s_bDeviceRemoved = SDL_FALSE;
+ 
+ /* static incrementing counter for new joystick devices seen on the system. Devices should start with index 0 */
+ static int s_joystick_instance_id = -1;
+ 
+-
+ static void
+-FreeElementList(recElement *pElement)
++HIDReportErrorNum(char *strError, long numError)
+ {
+-    while (pElement) {
+-        recElement *pElementNext = pElement->pNext;
+-        SDL_free(pElement);
+-        pElement = pElementNext;
+-    }
++    SDL_SetError(strError);
+ }
+ 
+-static recDevice *
+-FreeDevice(recDevice *removeDevice)
+-{
+-    recDevice *pDeviceNext = NULL;
+-    if (removeDevice) {
+-        /* save next device prior to disposing of this device */
+-        pDeviceNext = removeDevice->pNext;
++static void HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
++                                     recDevice * pDevice);
+ 
+-        if ( gpDeviceList == removeDevice ) {
+-            gpDeviceList = pDeviceNext;
+-        } else {
+-            recDevice *device = gpDeviceList;
+-            while (device->pNext != removeDevice) {
+-                device = device->pNext;
+-            }
+-            device->pNext = pDeviceNext;
+-        }
+-        removeDevice->pNext = NULL;
+-
+-        /* free element lists */
+-        FreeElementList(removeDevice->firstAxis);
+-        FreeElementList(removeDevice->firstButton);
+-        FreeElementList(removeDevice->firstHat);
+-
+-        SDL_free(removeDevice);
+-    }
+-    return pDeviceNext;
+-}
++/* returns current value for element, polling element
++ * will return 0 on error conditions which should be accounted for by application
++ */
+ 
+ static SInt32
+-GetHIDElementState(recDevice *pDevice, recElement *pElement)
++HIDGetElementValue(recDevice * pDevice, recElement * pElement)
+ {
+-    SInt32 value = 0;
+-
+-    if (pDevice && pElement) {
+-        IOHIDValueRef valueRef;
+-        if (IOHIDDeviceGetValue(pDevice->deviceRef, pElement->elementRef, &valueRef) == kIOReturnSuccess) {
+-            value = (SInt32) IOHIDValueGetIntegerValue(valueRef);
+-
++    IOReturn result = kIOReturnSuccess;
++    IOHIDEventStruct hidEvent;
++    hidEvent.value = 0;
++
++    if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) {
++        result =
++            (*(pDevice->interface))->getElementValue(pDevice->interface,
++                                                     pElement->cookie,
++                                                     &hidEvent);
++        if (kIOReturnSuccess == result) {
+             /* record min and max for auto calibration */
+-            if (value < pElement->minReport) {
+-                pElement->minReport = value;
+-            }
+-            if (value > pElement->maxReport) {
+-                pElement->maxReport = value;
+-            }
++            if (hidEvent.value < pElement->minReport)
++                pElement->minReport = hidEvent.value;
++            if (hidEvent.value > pElement->maxReport)
++                pElement->maxReport = hidEvent.value;
+         }
+     }
+ 
+-    return value;
++    /* auto user scale */
++    return hidEvent.value;
+ }
+ 
+ static SInt32
+-GetHIDScaledCalibratedState(recDevice * pDevice, recElement * pElement, SInt32 min, SInt32 max)
++HIDScaledCalibratedValue(recDevice * pDevice, recElement * pElement,
++                         long min, long max)
+ {
+-    const float deviceScale = max - min;
+-    const float readScale = pElement->maxReport - pElement->minReport;
+-    const SInt32 value = GetHIDElementState(pDevice, pElement);
+-    if (readScale == 0) {
++    float deviceScale = max - min;
++    float readScale = pElement->maxReport - pElement->minReport;
++    SInt32 value = HIDGetElementValue(pDevice, pElement);
++    if (readScale == 0)
+         return value;           /* no scaling at all */
+-    }
+-    return ((value - pElement->minReport) * deviceScale / readScale) + min;
++    else
++        return ((value - pElement->minReport) * deviceScale / readScale) +
++            min;
+ }
+ 
+ 
+ static void
+-JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender)
++HIDRemovalCallback(void *target, IOReturn result, void *refcon, void *sender)
+ {
+-    recDevice *device = (recDevice *) ctx;
++    recDevice *device = (recDevice *) refcon;
+     device->removed = 1;
+-#if SDL_HAPTIC_IOKIT
+-    MacHaptic_MaybeRemoveDevice(device->ffservice);
+-#endif
+     s_bDeviceRemoved = SDL_TRUE;
+ }
+ 
+ 
+-static void AddHIDElement(const void *value, void *parameter);
++/* Called by the io port notifier on removal of this device
++ */
++void JoystickDeviceWasRemovedCallback( void * refcon, io_service_t service, natural_t messageType, void * messageArgument )
++{
++    if( messageType == kIOMessageServiceIsTerminated && refcon )
++    {
++        recDevice *device = (recDevice *) refcon;
++        device->removed = 1;
++        s_bDeviceRemoved = SDL_TRUE;
++    }
++}
++
++
++/* Create and open an interface to device, required prior to extracting values or building queues.
++ * Note: application now owns the device and must close and release it prior to exiting
++ */
+ 
+-/* Call AddHIDElement() on all elements in an array of IOHIDElementRefs */
+-static void
+-AddHIDElements(CFArrayRef array, recDevice *pDevice)
++static IOReturn
++HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice)
+ {
+-    const CFRange range = { 0, CFArrayGetCount(array) };
+-    CFArrayApplyFunction(array, range, AddHIDElement, pDevice);
++    IOReturn result = kIOReturnSuccess;
++    HRESULT plugInResult = S_OK;
++    SInt32 score = 0;
++    IOCFPlugInInterface **ppPlugInInterface = NULL;
++
++    if (NULL == pDevice->interface) {
++        result =
++            IOCreatePlugInInterfaceForService(hidDevice,
++                                              kIOHIDDeviceUserClientTypeID,
++                                              kIOCFPlugInInterfaceID,
++                                              &ppPlugInInterface, &score);
++        if (kIOReturnSuccess == result) {
++            /* Call a method of the intermediate plug-in to create the device interface */
++            plugInResult =
++                (*ppPlugInInterface)->QueryInterface(ppPlugInInterface,
++                                                     CFUUIDGetUUIDBytes
++                                                     (kIOHIDDeviceInterfaceID),
++                                                     (void *)
++                                                     &(pDevice->interface));
++            if (S_OK != plugInResult)
++                HIDReportErrorNum
++                    ("Couldn't query HID class device interface from plugInInterface",
++                     plugInResult);
++            (*ppPlugInInterface)->Release(ppPlugInInterface);
++        } else
++            HIDReportErrorNum
++                ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.",
++                 result);
++    }
++    if (NULL != pDevice->interface) {
++        result = (*(pDevice->interface))->open(pDevice->interface, 0);
++        if (kIOReturnSuccess != result)
++            HIDReportErrorNum
++                ("Failed to open pDevice->interface via open.", result);
++        else
++        {
++            pDevice->portIterator = 0;
++
++            /* It's okay if this fails, we have another detection method below */
++            (*(pDevice->interface))->setRemovalCallback(pDevice->interface,
++                                                        HIDRemovalCallback,
++                                                        pDevice, pDevice);
++
++            /* now connect notification for new devices */
++            pDevice->notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
++
++            CFRunLoopAddSource(CFRunLoopGetCurrent(),
++                               IONotificationPortGetRunLoopSource(pDevice->notificationPort),
++                               kCFRunLoopDefaultMode);
++
++            /* Register for notifications when a serial port is added to the system */
++            result = IOServiceAddInterestNotification(pDevice->notificationPort,
++                                                      hidDevice,
++                                                      kIOGeneralInterest,
++                                                      JoystickDeviceWasRemovedCallback,
++                                                      pDevice,
++                                                      &pDevice->portIterator);
++            if (kIOReturnSuccess != result) {
++                HIDReportErrorNum
++                    ("Failed to register for removal callback.", result);
++            }
++        }
++
++    }
++    return result;
+ }
+ 
+-static SDL_bool
+-ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) {
+-    while (listitem) {
+-        if (listitem->cookie == cookie) {
+-            return SDL_TRUE;
++/* Closes and releases interface to device, should be done prior to exiting application
++ * Note: will have no affect if device or interface do not exist
++ * application will "own" the device if interface is not closed
++ * (device may have to be plug and re-plugged in different location to get it working again without a restart)
++ */
++
++static IOReturn
++HIDCloseReleaseInterface(recDevice * pDevice)
++{
++    IOReturn result = kIOReturnSuccess;
++
++    if ((NULL != pDevice) && (NULL != pDevice->interface)) {
++        /* close the interface */
++        result = (*(pDevice->interface))->close(pDevice->interface);
++        if (kIOReturnNotOpen == result) {
++            /* do nothing as device was not opened, thus can't be closed */
++        } else if (kIOReturnSuccess != result)
++            HIDReportErrorNum("Failed to close IOHIDDeviceInterface.",
++                              result);
++        /* release the interface */
++        result = (*(pDevice->interface))->Release(pDevice->interface);
++        if (kIOReturnSuccess != result)
++            HIDReportErrorNum("Failed to release IOHIDDeviceInterface.",
++                              result);
++        pDevice->interface = NULL;
++
++        if ( pDevice->portIterator )
++        {
++            IOObjectRelease( pDevice->portIterator );
++            pDevice->portIterator = 0;
+         }
+-        listitem = listitem->pNext;
+     }
+-    return SDL_FALSE;
++    return result;
+ }
+ 
+-/* See if we care about this HID element, and if so, note it in our recDevice. */
++/* extracts actual specific element information from each element CF dictionary entry */
++
+ static void
+-AddHIDElement(const void *value, void *parameter)
++HIDGetElementInfo(CFTypeRef refElement, recElement * pElement)
+ {
+-    recDevice *pDevice = (recDevice *) parameter;
+-    IOHIDElementRef refElement = (IOHIDElementRef) value;
+-    const CFTypeID elementTypeID = refElement ? CFGetTypeID(refElement) : 0;
+-
+-    if (refElement && (elementTypeID == IOHIDElementGetTypeID())) {
+-        const IOHIDElementCookie cookie = IOHIDElementGetCookie(refElement);
+-        const uint32_t usagePage = IOHIDElementGetUsagePage(refElement);
+-        const uint32_t usage = IOHIDElementGetUsage(refElement);
+-        recElement *element = NULL;
+-        recElement **headElement = NULL;
++    long number;
++    CFTypeRef refType;
+ 
+-        /* look at types of interest */
+-        switch (IOHIDElementGetType(refElement)) {
+-            case kIOHIDElementTypeInput_Misc:
+-            case kIOHIDElementTypeInput_Button:
+-            case kIOHIDElementTypeInput_Axis: {
+-                switch (usagePage) {    /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
+-                    case kHIDPage_GenericDesktop:
+-                        switch (usage) {
+-                            case kHIDUsage_GD_X:
+-                            case kHIDUsage_GD_Y:
+-                            case kHIDUsage_GD_Z:
+-                            case kHIDUsage_GD_Rx:
+-                            case kHIDUsage_GD_Ry:
+-                            case kHIDUsage_GD_Rz:
+-                            case kHIDUsage_GD_Slider:
+-                            case kHIDUsage_GD_Dial:
+-                            case kHIDUsage_GD_Wheel:
+-                                if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
+-                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
+-                                    if (element) {
+-                                        pDevice->axes++;
+-                                        headElement = &(pDevice->firstAxis);
+-                                    }
+-                                }
+-                                break;
+-
+-                            case kHIDUsage_GD_Hatswitch:
+-                                if (!ElementAlreadyAdded(cookie, pDevice->firstHat)) {
+-                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
+-                                    if (element) {
+-                                        pDevice->hats++;
+-                                        headElement = &(pDevice->firstHat);
+-                                    }
+-                                }
+-                                break;
+-                        }
+-                        break;
++    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementCookieKey));
++    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
++        pElement->cookie = (IOHIDElementCookie) number;
++    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMinKey));
++    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
++        pElement->minReport = pElement->min = number;
++    pElement->maxReport = pElement->min;
++    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMaxKey));
++    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
++        pElement->maxReport = pElement->max = number;
++/*
++    TODO: maybe should handle the following stuff somehow?
+ 
+-                    case kHIDPage_Simulation:
+-                        switch (usage) {
+-                            case kHIDUsage_Sim_Rudder:
+-                            case kHIDUsage_Sim_Throttle:
+-                                if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
+-                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
+-                                    if (element) {
+-                                        pDevice->axes++;
+-                                        headElement = &(pDevice->firstAxis);
+-                                    }
+-                                }
+-                                break;
++    refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey));
++    if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
++        pElement->scaledMin = number;
++    refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey));
++    if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
++        pElement->scaledMax = number;
++    refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey));
++    if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
++        pElement->size = number;
++    refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey));
++    if (refType)
++        pElement->relative = CFBooleanGetValue (refType);
++    refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey));
++    if (refType)
++        pElement->wrapping = CFBooleanGetValue (refType);
++    refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey));
++    if (refType)
++        pElement->nonLinear = CFBooleanGetValue (refType);
++    refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey));
++    if (refType)
++        pElement->preferredState = CFBooleanGetValue (refType);
++    refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey));
++    if (refType)
++        pElement->nullState = CFBooleanGetValue (refType);
++*/
++}
+ 
+-                            default:
+-                                break;
+-                        }
+-                        break;
++/* examines CF dictionary value in device element hierarchy to determine if it is element of interest or a collection of more elements
++ * if element of interest allocate storage, add to list and retrieve element specific info
++ * if collection then pass on to deconstruction collection into additional individual elements
++ */
+ 
+-                    case kHIDPage_Button:
+-                        if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
+-                            element = (recElement *) SDL_calloc(1, sizeof (recElement));
++static void
++HIDAddElement(CFTypeRef refElement, recDevice * pDevice)
++{
++    recElement *element = NULL;
++    recElement **headElement = NULL;
++    long elementType, usagePage, usage;
++    CFTypeRef refElementType =
++        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementTypeKey));
++    CFTypeRef refUsagePage =
++        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsagePageKey));
++    CFTypeRef refUsage =
++        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsageKey));
++
++
++    if ((refElementType)
++        &&
++        (CFNumberGetValue(refElementType, kCFNumberLongType, &elementType))) {
++        /* look at types of interest */
++        if ((elementType == kIOHIDElementTypeInput_Misc)
++            || (elementType == kIOHIDElementTypeInput_Button)
++            || (elementType == kIOHIDElementTypeInput_Axis)) {
++            if (refUsagePage
++                && CFNumberGetValue(refUsagePage, kCFNumberLongType,
++                                    &usagePage) && refUsage
++                && CFNumberGetValue(refUsage, kCFNumberLongType, &usage)) {
++                switch (usagePage) {    /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
++                case kHIDPage_GenericDesktop:
++                    {
++                        switch (usage) {        /* look at usage to determine function */
++                        case kHIDUsage_GD_X:
++                        case kHIDUsage_GD_Y:
++                        case kHIDUsage_GD_Z:
++                        case kHIDUsage_GD_Rx:
++                        case kHIDUsage_GD_Ry:
++                        case kHIDUsage_GD_Rz:
++                        case kHIDUsage_GD_Slider:
++                        case kHIDUsage_GD_Dial:
++                        case kHIDUsage_GD_Wheel:
++                            element = (recElement *)
++                                NewPtrClear(sizeof(recElement));
+                             if (element) {
+-                                pDevice->buttons++;
+-                                headElement = &(pDevice->firstButton);
++                                pDevice->axes++;
++                                headElement = &(pDevice->firstAxis);
+                             }
++                            break;
++                        case kHIDUsage_GD_Hatswitch:
++                            element = (recElement *)
++                                NewPtrClear(sizeof(recElement));
++                            if (element) {
++                                pDevice->hats++;
++                                headElement = &(pDevice->firstHat);
++                            }
++                            break;
+                         }
+-                        break;
+-
+-                    default:
+-                        break;
+-                }
+-            }
+-            break;
++                    }
++                    break;
++                case kHIDPage_Simulation:
++                    switch (usage) {
++                        case kHIDUsage_Sim_Rudder:
++                        case kHIDUsage_Sim_Throttle:
++                            element = (recElement *)
++                                NewPtrClear(sizeof(recElement));
++                            if (element) {
++                                pDevice->axes++;
++                                headElement = &(pDevice->firstAxis);
++                            }
++                            break;
+ 
+-            case kIOHIDElementTypeCollection: {
+-                CFArrayRef array = IOHIDElementGetChildren(refElement);
+-                if (array) {
+-                    AddHIDElements(array, pDevice);
++                        default:
++                            break;
++                    }
++                    break;
++                case kHIDPage_Button:
++                    element = (recElement *)
++                        NewPtrClear(sizeof(recElement));
++                    if (element) {
++                        pDevice->buttons++;
++                        headElement = &(pDevice->firstButton);
++                    }
++                    break;
++                default:
++                    break;
+                 }
+             }
+-            break;
++        } else if (kIOHIDElementTypeCollection == elementType)
++            HIDGetCollectionElements((CFMutableDictionaryRef) refElement,
++                                     pDevice);
++    }
+ 
+-            default:
+-                break;
++    if (element && headElement) {       /* add to list */
++        recElement *elementPrevious = NULL;
++        recElement *elementCurrent = *headElement;
++        while (elementCurrent && usage >= elementCurrent->usage) {
++            elementPrevious = elementCurrent;
++            elementCurrent = elementCurrent->pNext;
++        }
++        if (elementPrevious) {
++            elementPrevious->pNext = element;
++        } else {
++            *headElement = element;
+         }
++        element->usagePage = usagePage;
++        element->usage = usage;
++        element->pNext = elementCurrent;
++        HIDGetElementInfo(refElement, element);
++        pDevice->elements++;
++    }
++}
+ 
+-        if (element && headElement) {       /* add to list */
+-            recElement *elementPrevious = NULL;
+-            recElement *elementCurrent = *headElement;
+-            while (elementCurrent && usage >= elementCurrent->usage) {
+-                elementPrevious = elementCurrent;
+-                elementCurrent = elementCurrent->pNext;
+-            }
+-            if (elementPrevious) {
+-                elementPrevious->pNext = element;
+-            } else {
+-                *headElement = element;
+-            }
++/* collects information from each array member in device element list (each array member = element) */
+ 
+-            element->elementRef = refElement;
+-            element->usagePage = usagePage;
+-            element->usage = usage;
+-            element->pNext = elementCurrent;
++static void
++HIDGetElementsCFArrayHandler(const void *value, void *parameter)
++{
++    if (CFGetTypeID(value) == CFDictionaryGetTypeID())
++        HIDAddElement((CFTypeRef) value, (recDevice *) parameter);
++}
+ 
+-            element->minReport = element->min = (SInt32) IOHIDElementGetLogicalMin(refElement);
+-            element->maxReport = element->max = (SInt32) IOHIDElementGetLogicalMax(refElement);
+-            element->cookie = IOHIDElementGetCookie(refElement);
++/* handles retrieval of element information from arrays of elements in device IO registry information */
+ 
+-            pDevice->elements++;
+-        }
++static void
++HIDGetElements(CFTypeRef refElementCurrent, recDevice * pDevice)
++{
++    CFTypeID type = CFGetTypeID(refElementCurrent);
++    if (type == CFArrayGetTypeID()) {   /* if element is an array */
++        CFRange range = { 0, CFArrayGetCount(refElementCurrent) };
++        /* CountElementsCFArrayHandler called for each array member */
++        CFArrayApplyFunction(refElementCurrent, range,
++                             HIDGetElementsCFArrayHandler, pDevice);
+     }
+ }
+ 
+-static SDL_bool
+-GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
++/* handles extracting element information from element collection CF types
++ * used from top level element decoding and hierarchy deconstruction to flatten device element list
++ */
++
++static void
++HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
++                         recDevice * pDevice)
+ {
+-    Uint32 *guid32 = NULL;
+-    CFTypeRef refCF = NULL;
+-    CFArrayRef array = NULL;
++    CFTypeRef refElementTop =
++        CFDictionaryGetValue(deviceProperties, CFSTR(kIOHIDElementKey));
++    if (refElementTop)
++        HIDGetElements(refElementTop, pDevice);
++}
+ 
+-    /* get usage page and usage */
+-    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsagePageKey));
+-    if (refCF) {
+-        CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usagePage);
+-    }
+-    if (pDevice->usagePage != kHIDPage_GenericDesktop) {
+-        return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
+-    }
++/* use top level element usage page and usage to discern device usage page and usage setting appropriate vlaues in device record */
+ 
+-    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsageKey));
+-    if (refCF) {
+-        CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usage);
+-    }
++static void
++HIDTopLevelElementHandler(const void *value, void *parameter)
++{
++    CFTypeRef refCF = 0;
++    if (CFGetTypeID(value) != CFDictionaryGetTypeID())
++        return;
++    refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsagePageKey));
++    if (!CFNumberGetValue
++        (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage))
++        SDL_SetError("CFNumberGetValue error retrieving pDevice->usagePage.");
++    refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsageKey));
++    if (!CFNumberGetValue
++        (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage))
++        SDL_SetError("CFNumberGetValue error retrieving pDevice->usage.");
++}
+ 
+-    if ((pDevice->usage != kHIDUsage_GD_Joystick &&
+-         pDevice->usage != kHIDUsage_GD_GamePad &&
+-         pDevice->usage != kHIDUsage_GD_MultiAxisController)) {
+-        return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
+-    }
++/* extracts device info from CF dictionary records in IO registry */
+ 
+-    pDevice->deviceRef = hidDevice;
++static void
++HIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties,
++                 recDevice * pDevice)
++{
++    CFMutableDictionaryRef usbProperties = 0;
++    io_registry_entry_t parent1, parent2;
+ 
+-    /* get device name */
+-    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey));
+-    if (!refCF) {
+-        /* Maybe we can't get "AwesomeJoystick2000", but we can get "Logitech"? */
+-        refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
+-    }
+-    if ((!refCF) || (!CFStringGetCString(refCF, pDevice->product, sizeof (pDevice->product), kCFStringEncodingUTF8))) {
+-        SDL_strlcpy(pDevice->product, "Unidentified joystick", sizeof (pDevice->product));
+-    }
++    /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
++     * get dictionary for USB properties: step up two levels and get CF dictionary for USB properties
++     */
++    if ((KERN_SUCCESS == IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1))
++        && (KERN_SUCCESS == IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
++        && (KERN_SUCCESS == IORegistryEntryCreateCFProperties(parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) {
++        if (usbProperties) {
++            CFTypeRef refCF = 0;
++            /* get device info
++             * try hid dictionary first, if fail then go to usb dictionary
++             */
+ 
+-    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey));
+-    if (refCF) {
+-        CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->guid.data[0]);
+-    }
++            /* get product name */
++            refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
++            if (!refCF) {
++                refCF = CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name"));
++            }
++            if (refCF) {
++                if (!CFStringGetCString(refCF, pDevice->product, 256, CFStringGetSystemEncoding())) {
++                    SDL_SetError("CFStringGetCString error retrieving pDevice->product.");
++                }
++            }
+ 
+-    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductIDKey));
+-    if (refCF) {
+-        CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->guid.data[8]);
+-    }
++            /* get usage page and usage */
++            refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey));
++            if (refCF) {
++                if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage)) {
++                    SDL_SetError("CFNumberGetValue error retrieving pDevice->usagePage.");
++                }
+ 
+-    /* Check to make sure we have a vendor and product ID
+-       If we don't, use the same algorithm as the Linux code for Bluetooth devices */
+-    guid32 = (Uint32*)pDevice->guid.data;
+-    if (!guid32[0] && !guid32[1]) {
+-        /* If we don't have a vendor and product ID this is probably a Bluetooth device */
+-        const Uint16 BUS_BLUETOOTH = 0x05;
+-        Uint16 *guid16 = (Uint16 *)guid32;
+-        *guid16++ = BUS_BLUETOOTH;
+-        *guid16++ = 0;
+-        SDL_strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4);
+-    }
++                refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey));
++                if (refCF) {
++                    if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage)) {
++                        SDL_SetError("CFNumberGetValue error retrieving pDevice->usage.");
++                    }
++                }
++            }
+ 
+-    array = IOHIDDeviceCopyMatchingElements(hidDevice, NULL, kIOHIDOptionsTypeNone);
+-    if (array) {
+-        AddHIDElements(array, pDevice);
+-        CFRelease(array);
++            refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDVendorIDKey));
++            if (refCF) {
++                if (!CFNumberGetValue(refCF, kCFNumberLongType, &pDevice->guid.data[0])) {
++                    SDL_SetError("CFNumberGetValue error retrieving pDevice->guid[0]");
++                }
++            }
++
++            refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductIDKey));
++            if (refCF) {
++                if (!CFNumberGetValue(refCF, kCFNumberLongType, &pDevice->guid.data[8])) {
++                    SDL_SetError("CFNumberGetValue error retrieving pDevice->guid[8]");
++                }
++            }
++
++            /* Check to make sure we have a vendor and product ID
++               If we don't, use the same algorithm as the Linux code for Bluetooth devices */
++            {
++                Uint32 *guid32 = (Uint32*)pDevice->guid.data;
++                if (!guid32[0] && !guid32[1]) {
++                    const Uint16 BUS_BLUETOOTH = 0x05;
++                    Uint16 *guid16 = (Uint16 *)guid32;
++                    *guid16++ = BUS_BLUETOOTH;
++                    *guid16++ = 0;
++                    SDL_strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4);
++                }
++            }
++
++            /* If we don't have a vendor and product ID this is probably a Bluetooth device */
++
++            if (NULL == refCF) {    /* get top level element HID usage page or usage */
++                /* use top level element instead */
++                CFTypeRef refCFTopElement = 0;
++                refCFTopElement = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDElementKey));
++                {
++                    /* refCFTopElement points to an array of element dictionaries */
++                    CFRange range = { 0, CFArrayGetCount(refCFTopElement) };
++                    CFArrayApplyFunction(refCFTopElement, range, HIDTopLevelElementHandler, pDevice);
++                }
++            }
++
++            CFRelease(usbProperties);
++        } else {
++            SDL_SetError("IORegistryEntryCreateCFProperties failed to create usbProperties.");
++        }
++
++        if (kIOReturnSuccess != IOObjectRelease(parent2)) {
++            SDL_SetError("IOObjectRelease error with parent2");
++        }
++        if (kIOReturnSuccess != IOObjectRelease(parent1)) {
++            SDL_SetError("IOObjectRelease error with parent1");
++        }
+     }
++}
+ 
+-    return SDL_TRUE;
++
++static recDevice *
++HIDBuildDevice(io_object_t hidDevice)
++{
++    recDevice *pDevice = (recDevice *) NewPtrClear(sizeof(recDevice));
++    if (pDevice) {
++        /* get dictionary for HID properties */
++        CFMutableDictionaryRef hidProperties = 0;
++        kern_return_t result =
++            IORegistryEntryCreateCFProperties(hidDevice, &hidProperties,
++                                              kCFAllocatorDefault,
++                                              kNilOptions);
++        if ((result == KERN_SUCCESS) && hidProperties) {
++            /* create device interface */
++            result = HIDCreateOpenDeviceInterface(hidDevice, pDevice);
++            if (kIOReturnSuccess == result) {
++                HIDGetDeviceInfo(hidDevice, hidProperties, pDevice);    /* hidDevice used to find parents in registry tree */
++                HIDGetCollectionElements(hidProperties, pDevice);
++            } else {
++                DisposePtr((Ptr) pDevice);
++                pDevice = NULL;
++            }
++            CFRelease(hidProperties);
++        } else {
++            DisposePtr((Ptr) pDevice);
++            pDevice = NULL;
++        }
++    }
++    return pDevice;
+ }
+ 
++/* disposes of the element list associated with a device and the memory associated with the list
++ */
+ 
+ static void
+-JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
++HIDDisposeElementList(recElement ** elementList)
+ {
+-    if (res != kIOReturnSuccess) {
+-        return;
++    recElement *pElement = *elementList;
++    while (pElement) {
++        recElement *pElementNext = pElement->pNext;
++        DisposePtr((Ptr) pElement);
++        pElement = pElementNext;
+     }
++    *elementList = NULL;
++}
+ 
+-    recDevice *device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
++/* disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL
++ * all your device no longer belong to us... (i.e., you do not 'own' the device anymore)
++ */
+ 
+-    if (!device) {
+-        SDL_OutOfMemory();
+-        return;
+-    }
++static recDevice *
++HIDDisposeDevice(recDevice ** ppDevice)
++{
++    kern_return_t result = KERN_SUCCESS;
++    recDevice *pDeviceNext = NULL;
++    if (*ppDevice) {
++        /* save next device prior to disposing of this device */
++        pDeviceNext = (*ppDevice)->pNext;
+ 
+-    if (!GetDeviceInfo(ioHIDDeviceObject, device)) {
+-        SDL_free(device);
+-        return;   /* not a device we care about, probably. */
++        /* free posible io_service_t */
++        if ((*ppDevice)->ffservice) {
++            IOObjectRelease((*ppDevice)->ffservice);
++            (*ppDevice)->ffservice = 0;
++        }
++
++        /* free element lists */
++        HIDDisposeElementList(&(*ppDevice)->firstAxis);
++        HIDDisposeElementList(&(*ppDevice)->firstButton);
++        HIDDisposeElementList(&(*ppDevice)->firstHat);
++
++        result = HIDCloseReleaseInterface(*ppDevice);   /* function sanity checks interface value (now application does not own device) */
++        if (kIOReturnSuccess != result)
++            HIDReportErrorNum
++                ("HIDCloseReleaseInterface failed when trying to dipose device.",
++                 result);
++        DisposePtr((Ptr) * ppDevice);
++        *ppDevice = NULL;
+     }
++    return pDeviceNext;
++}
++
++
++/* Given an io_object_t from OSX adds a joystick device to our list if appropriate
++ */
++int
++AddDeviceHelper( io_object_t ioHIDDeviceObject )
++{
++    recDevice *device;
+ 
+-    /* Get notified when this device is disconnected. */
+-    IOHIDDeviceRegisterRemovalCallback(ioHIDDeviceObject, JoystickDeviceWasRemovedCallback, device);
+-    IOHIDDeviceScheduleWithRunLoop(ioHIDDeviceObject, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
++    /* build a device record */
++    device = HIDBuildDevice(ioHIDDeviceObject);
++    if (!device)
++        return 0;
++
++    /* Filter device list to non-keyboard/mouse stuff */
++    if ((device->usagePage != kHIDPage_GenericDesktop) ||
++        ((device->usage != kHIDUsage_GD_Joystick &&
++          device->usage != kHIDUsage_GD_GamePad &&
++          device->usage != kHIDUsage_GD_MultiAxisController))) {
++
++        /* release memory for the device */
++        HIDDisposeDevice(&device);
++        DisposePtr((Ptr) device);
++        return 0;
++    }
+ 
+     /* Allocate an instance ID for this device */
+     device->instance_id = ++s_joystick_instance_id;
+ 
+-    /* We have to do some storage of the io_service_t for SDL_HapticOpenFromJoystick */
+-    if (IOHIDDeviceGetService != NULL) {  /* weak reference: available in 10.6 and later. */
+-        const io_service_t ioservice = IOHIDDeviceGetService(ioHIDDeviceObject);
+-        if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK)) {
+-            device->ffservice = ioservice;
+-#if SDL_HAPTIC_IOKIT
+-            MacHaptic_MaybeAddDevice(ioservice);
+-#endif
+-        }
++    /* We have to do some storage of the io_service_t for
++     * SDL_HapticOpenFromJoystick */
++    if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
++        device->ffservice = ioHIDDeviceObject;
++    } else {
++        device->ffservice = 0;
+     }
+ 
+     device->send_open_event = 1;
+@@ -413,93 +707,25 @@ JoystickDeviceWasAddedCallback(void *ctx
+         }
+         curdevice->pNext = device;
+     }
+-}
+-
+-static SDL_bool
+-ConfigHIDManager(CFArrayRef matchingArray)
+-{
+-    CFRunLoopRef runloop = CFRunLoopGetCurrent();
+-
+-    /* Run in a custom RunLoop mode just while initializing,
+-       so we can detect sticks without messing with everything else. */
+-    CFStringRef tempRunLoopMode = CFSTR("SDLJoystickInit");
+-
+-    if (IOHIDManagerOpen(hidman, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
+-        return SDL_FALSE;
+-    }
+-
+-    IOHIDManagerRegisterDeviceMatchingCallback(hidman, JoystickDeviceWasAddedCallback, NULL);
+-    IOHIDManagerScheduleWithRunLoop(hidman, runloop, tempRunLoopMode);
+-    IOHIDManagerSetDeviceMatchingMultiple(hidman, matchingArray);
+ 
+-    while (CFRunLoopRunInMode(tempRunLoopMode,0,TRUE)==kCFRunLoopRunHandledSource) {
+-        /* no-op. Callback fires once per existing device. */
+-    }
+-
+-    /* Put this in the normal RunLoop mode now, for future hotplug events. */
+-    IOHIDManagerUnscheduleFromRunLoop(hidman, runloop, tempRunLoopMode);
+-    IOHIDManagerScheduleWithRunLoop(hidman, runloop, kCFRunLoopDefaultMode);
+-
+-    return SDL_TRUE;  /* good to go. */
++    return 1;
+ }
+ 
+ 
+-static CFDictionaryRef
+-CreateHIDDeviceMatchDictionary(const UInt32 page, const UInt32 usage, int *okay)
+-{
+-    CFDictionaryRef retval = NULL;
+-    CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
+-    CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
+-    const void *keys[2] = { (void *) CFSTR(kIOHIDDeviceUsagePageKey), (void *) CFSTR(kIOHIDDeviceUsageKey) };
+-    const void *vals[2] = { (void *) pageNumRef, (void *) usageNumRef };
+-
+-    if (pageNumRef && usageNumRef) {
+-        retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+-    }
+-
+-    if (pageNumRef) {
+-        CFRelease(pageNumRef);
+-    }
+-    if (usageNumRef) {
+-        CFRelease(usageNumRef);
+-    }
+-
+-    if (!retval) {
+-        *okay = 0;
+-    }
+-
+-    return retval;
+-}
+-
+-static SDL_bool
+-CreateHIDManager(void)
++/* Called by our IO port notifier on the master port when a HID device is inserted, we iterate
++ *  and check for new joysticks
++ */
++void JoystickDeviceWasAddedCallback( void *refcon, io_iterator_t iterator )
+ {
+-    SDL_bool retval = SDL_FALSE;
+-    int okay = 1;
+-    const void *vals[] = {
+-        (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay),
+-        (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad, &okay),
+-        (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController, &okay),
+-    };
+-    const size_t numElements = SDL_arraysize(vals);
+-    CFArrayRef array = okay ? CFArrayCreate(kCFAllocatorDefault, vals, numElements, &kCFTypeArrayCallBacks) : NULL;
+-    size_t i;
++    io_object_t ioHIDDeviceObject = 0;
+ 
+-    for (i = 0; i < numElements; i++) {
+-        if (vals[i]) {
+-            CFRelease((CFTypeRef) vals[i]);
+-        }
+-    }
+-
+-    if (array) {
+-        hidman = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
+-        if (hidman != NULL) {
+-            retval = ConfigHIDManager(array);
++    while ( ( ioHIDDeviceObject = IOIteratorNext(iterator) ) )
++    {
++        if ( ioHIDDeviceObject )
++        {
++            AddDeviceHelper( ioHIDDeviceObject );
+         }
+-        CFRelease(array);
+     }
+-
+-    return retval;
+ }
+ 
+ 
+@@ -511,13 +737,81 @@ CreateHIDManager(void)
+ int
+ SDL_SYS_JoystickInit(void)
+ {
++    IOReturn result = kIOReturnSuccess;
++    mach_port_t masterPort = 0;
++    io_iterator_t hidObjectIterator = 0;
++    CFMutableDictionaryRef hidMatchDictionary = NULL;
++    io_object_t ioHIDDeviceObject = 0;
++    io_iterator_t portIterator = 0;
++
+     if (gpDeviceList) {
+         return SDL_SetError("Joystick: Device list already inited.");
+     }
+ 
+-    if (!CreateHIDManager()) {
+-        return SDL_SetError("Joystick: Couldn't initialize HID Manager");
+-    }
++    result = IOMasterPort(bootstrap_port, &masterPort);
++    if (kIOReturnSuccess != result) {
++        return SDL_SetError("Joystick: IOMasterPort error with bootstrap_port.");
++    }
++
++    /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
++    hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
++    if (hidMatchDictionary) {
++        /* Add key for device type (joystick, in this case) to refine the matching dictionary. */
++
++        /* NOTE: we now perform this filtering later
++           UInt32 usagePage = kHIDPage_GenericDesktop;
++           UInt32 usage = kHIDUsage_GD_Joystick;
++           CFNumberRef refUsage = NULL, refUsagePage = NULL;
++
++           refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage);
++           CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage);
++           refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage);
++           CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage);
++         */
++    } else {
++        return SDL_SetError
++            ("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching.");
++    }
++
++    /* Now search I/O Registry for matching devices. */
++    result =
++        IOServiceGetMatchingServices(masterPort, hidMatchDictionary,
++                                     &hidObjectIterator);
++    /* Check for errors */
++    if (kIOReturnSuccess != result) {
++        return SDL_SetError("Joystick: Couldn't create a HID object iterator.");
++    }
++    if (!hidObjectIterator) {   /* there are no joysticks */
++        gpDeviceList = NULL;
++        return 0;
++    }
++    /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */
++
++    /* build flat linked list of devices from device iterator */
++
++    gpDeviceList = NULL;
++
++    while ((ioHIDDeviceObject = IOIteratorNext(hidObjectIterator))) {
++        AddDeviceHelper( ioHIDDeviceObject );
++    }
++    result = IOObjectRelease(hidObjectIterator);        /* release the iterator */
++
++    /* now connect notification for new devices */
++    notificationPort = IONotificationPortCreate(masterPort);
++    hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
++
++    CFRunLoopAddSource(CFRunLoopGetCurrent(),
++                       IONotificationPortGetRunLoopSource(notificationPort),
++                       kCFRunLoopDefaultMode);
++
++    /* Register for notifications when a serial port is added to the system */
++    result = IOServiceAddMatchingNotification(notificationPort,
++                                                            kIOFirstMatchNotification,
++                                                            hidMatchDictionary,
++                                                            JoystickDeviceWasAddedCallback,
++                                                            NULL,
++                                                            &portIterator);
++    while (IOIteratorNext(portIterator)) {}; /* Run out the iterator or notifications won't start (you can also use it to iterate the available devices). */
+ 
+     return SDL_SYS_NumJoysticks();
+ }
+@@ -529,10 +823,10 @@ SDL_SYS_NumJoysticks()
+     recDevice *device = gpDeviceList;
+     int nJoySticks = 0;
+ 
+-    while (device) {
+-        if (!device->removed) {
++    while ( device )
++    {
++        if ( !device->removed )
+             nJoySticks++;
+-        }
+         device = device->pNext;
+     }
+ 
+@@ -544,16 +838,18 @@ SDL_SYS_NumJoysticks()
+ void
+ SDL_SYS_JoystickDetect()
+ {
+-    if (s_bDeviceAdded || s_bDeviceRemoved) {
++    if ( s_bDeviceAdded || s_bDeviceRemoved )
++    {
+         recDevice *device = gpDeviceList;
+         s_bDeviceAdded = SDL_FALSE;
+         s_bDeviceRemoved = SDL_FALSE;
+         int device_index = 0;
+         /* send notifications */
+-        while (device) {
+-            if (device->send_open_event) {
++        while ( device )
++        {
++            if ( device->send_open_event )
++            {
+                 device->send_open_event = 0;
+-/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceAdded()? */
+ #if !SDL_EVENTS_DISABLED
+                 SDL_Event event;
+                 event.type = SDL_JOYDEVICEADDED;
+@@ -569,25 +865,43 @@ SDL_SYS_JoystickDetect()
+ 
+             }
+ 
+-            if (device->removed) {
+-                const int instance_id = device->instance_id;
+-                device = FreeDevice(device);
++            if ( device->removed )
++            {
++                recDevice *removeDevice = device;
++                if ( gpDeviceList == removeDevice )
++                {
++                    device = device->pNext;
++                    gpDeviceList = device;
++                }
++                else
++                {
++                    device = gpDeviceList;
++                    while ( device->pNext != removeDevice )
++                    {
++                        device = device->pNext;
++                    }
++
++                    device->pNext = removeDevice->pNext;
++                }
+ 
+-/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceRemoved()? */
+ #if !SDL_EVENTS_DISABLED
+                 SDL_Event event;
+                 event.type = SDL_JOYDEVICEREMOVED;
+ 
+                 if (SDL_GetEventState(event.type) == SDL_ENABLE) {
+-                    event.jdevice.which = instance_id;
++                    event.jdevice.which = removeDevice->instance_id;
+                     if ((SDL_EventOK == NULL)
+                         || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
+                         SDL_PushEvent(&event);
+                     }
+                 }
++
++                DisposePtr((Ptr) removeDevice);
+ #endif /* !SDL_EVENTS_DISABLED */
+ 
+-            } else {
++            }
++            else
++            {
+                 device = device->pNext;
+                 device_index++;
+             }
+@@ -607,9 +921,8 @@ SDL_SYS_JoystickNameForDeviceIndex(int d
+ {
+     recDevice *device = gpDeviceList;
+ 
+-    while (device_index-- > 0) {
++    for (; device_index > 0; device_index--)
+         device = device->pNext;
+-    }
+ 
+     return device->product;
+ }
+@@ -622,9 +935,8 @@ SDL_SYS_GetInstanceIdOfDeviceIndex(int d
+     recDevice *device = gpDeviceList;
+     int index;
+ 
+-    for (index = device_index; index > 0; index--) {
++    for (index = device_index; index > 0; index--)
+         device = device->pNext;
+-    }
+ 
+     return device->instance_id;
+ }
+@@ -640,9 +952,8 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joys
+     recDevice *device = gpDeviceList;
+     int index;
+ 
+-    for (index = device_index; index > 0; index--) {
++    for (index = device_index; index > 0; index--)
+         device = device->pNext;
+-    }
+ 
+     joystick->instance_id = device->instance_id;
+     joystick->hwdata = device;
+@@ -663,10 +974,11 @@ SDL_SYS_JoystickAttached(SDL_Joystick * 
+ {
+     recDevice *device = gpDeviceList;
+ 
+-    while (device) {
+-        if (joystick->instance_id == device->instance_id) {
++    while ( device )
++    {
++        if ( joystick->instance_id == device->instance_id )
+             return SDL_TRUE;
+-        }
++
+         device = device->pNext;
+     }
+ 
+@@ -686,24 +998,53 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * jo
+     SInt32 value, range;
+     int i;
+ 
+-    if (!device) {
++    if ( !device )
+         return;
+-    }
+ 
+     if (device->removed) {      /* device was unplugged; ignore it. */
++        recDevice *devicelist = gpDeviceList;
+         joystick->closed = 1;
+         joystick->uncentered = 1;
++
++        if ( devicelist == device )
++        {
++            gpDeviceList = device->pNext;
++        }
++        else
++        {
++            while ( devicelist->pNext != device )
++            {
++                devicelist = devicelist->pNext;
++            }
++
++            devicelist->pNext = device->pNext;
++        }
++
++        DisposePtr((Ptr) device);
+         joystick->hwdata = NULL;
++
++#if !SDL_EVENTS_DISABLED
++        SDL_Event event;
++        event.type = SDL_JOYDEVICEREMOVED;
++
++        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
++            event.jdevice.which = joystick->instance_id;
++            if ((SDL_EventOK == NULL)
++                || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
++                SDL_PushEvent(&event);
++            }
++        }
++#endif /* !SDL_EVENTS_DISABLED */
++
+         return;
+     }
+ 
+     element = device->firstAxis;
+     i = 0;
+     while (element) {
+-        value = GetHIDScaledCalibratedState(device, element, -32768, 32767);
+-        if (value != joystick->axes[i]) {
++        value = HIDScaledCalibratedValue(device, element, -32768, 32767);
++        if (value != joystick->axes[i])
+             SDL_PrivateJoystickAxis(joystick, i, value);
+-        }
+         element = element->pNext;
+         ++i;
+     }
+@@ -711,13 +1052,11 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * jo
+     element = device->firstButton;
+     i = 0;
+     while (element) {
+-        value = GetHIDElementState(device, element);
+-        if (value > 1) {          /* handle pressure-sensitive buttons */
++        value = HIDGetElementValue(device, element);
++        if (value > 1)          /* handle pressure-sensitive buttons */
+             value = 1;
+-        }
+-        if (value != joystick->buttons[i]) {
++        if (value != joystick->buttons[i])
+             SDL_PrivateJoystickButton(joystick, i, value);
+-        }
+         element = element->pNext;
+         ++i;
+     }
+@@ -728,12 +1067,11 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * jo
+         Uint8 pos = 0;
+ 
+         range = (element->max - element->min + 1);
+-        value = GetHIDElementState(device, element) - element->min;
+-        if (range == 4) {         /* 4 position hatswitch - scale up value */
++        value = HIDGetElementValue(device, element) - element->min;
++        if (range == 4)         /* 4 position hatswitch - scale up value */
+             value *= 2;
+-        } else if (range != 8) {    /* Neither a 4 nor 8 positions - fall back to default position (centered) */
++        else if (range != 8)    /* Neither a 4 nor 8 positions - fall back to default position (centered) */
+             value = -1;
+-        }
+         switch (value) {
+         case 0:
+             pos = SDL_HAT_UP;
+@@ -767,14 +1105,13 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * jo
+             pos = SDL_HAT_CENTERED;
+             break;
+         }
+-
+-        if (pos != joystick->hats[i]) {
++        if (pos != joystick->hats[i])
+             SDL_PrivateJoystickHat(joystick, i, pos);
+-        }
+-
+         element = element->pNext;
+         ++i;
+     }
++
++    return;
+ }
+ 
+ /* Function to close a joystick after use */
+@@ -788,17 +1125,14 @@ SDL_SYS_JoystickClose(SDL_Joystick * joy
+ void
+ SDL_SYS_JoystickQuit(void)
+ {
+-    while (FreeDevice(gpDeviceList)) {
+-        /* spin */
+-    }
++    while (NULL != gpDeviceList)
++        gpDeviceList = HIDDisposeDevice(&gpDeviceList);
+ 
+-    if (hidman) {
+-        IOHIDManagerClose(hidman, kIOHIDOptionsTypeNone);
+-        CFRelease(hidman);
+-        hidman = NULL;
++    if ( notificationPort )
++    {
++        IONotificationPortDestroy( notificationPort );
++        notificationPort = 0;
+     }
+-
+-    s_bDeviceAdded = s_bDeviceRemoved = SDL_FALSE;
+ }
+ 
+ 
+@@ -807,9 +1141,8 @@ SDL_JoystickGUID SDL_SYS_JoystickGetDevi
+     recDevice *device = gpDeviceList;
+     int index;
+ 
+-    for (index = device_index; index > 0; index--) {
++    for (index = device_index; index > 0; index--)
+         device = device->pNext;
+-    }
+ 
+     return device->guid;
+ }
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_joystick_darwin_SDL__sysjoystick__c.h
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_joystick_darwin_SDL__sysjoystick__c.h:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_joystick_darwin_SDL__sysjoystick__c.h     Sun Nov 12 21:28:04 2023
@@ -0,0 +1,88 @@
+$NetBSD: patch-src_joystick_darwin_SDL__sysjoystick__c.h,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts".
+
+--- src/joystick/darwin/SDL_sysjoystick_c.h.orig       2014-03-16 02:31:41.000000000 +0000
++++ src/joystick/darwin/SDL_sysjoystick_c.h
+@@ -1,6 +1,6 @@
+ /*
+   Simple DirectMedia Layer
+-  Copyright (C) 1997-2014 Sam Lantinga <slouken%libsdl.org@localhost>
++  Copyright (C) 1997-2013 Sam Lantinga <slouken%libsdl.org@localhost>
+ 
+   This software is provided 'as-is', without any express or implied
+   warranty.  In no event will the authors be held liable for any damages
+@@ -18,23 +18,38 @@
+      misrepresented as being the original software.
+   3. This notice may not be removed or altered from any source distribution.
+ */
+-#include "../../SDL_internal.h"
++#include "SDL_config.h"
+ 
+ #ifndef SDL_JOYSTICK_IOKIT_H
+ 
++
+ #include <IOKit/hid/IOHIDLib.h>
++#include <IOKit/hid/IOHIDKeys.h>
++#include <IOKit/IOKitLib.h>
++
+ 
+ struct recElement
+ {
+-    IOHIDElementRef elementRef;
+-    IOHIDElementCookie cookie;
+-    uint32_t usagePage, usage;      /* HID usage */
+-    SInt32 min;                   /* reported min value possible */
+-    SInt32 max;                   /* reported max value possible */
++    IOHIDElementCookie cookie;  /* unique value which identifies element, will NOT change */
++    long usagePage, usage;      /* HID usage */
++    long min;                   /* reported min value possible */
++    long max;                   /* reported max value possible */
++#if 0
++    /* TODO: maybe should handle the following stuff somehow? */
++
++    long scaledMin;             /* reported scaled min value possible */
++    long scaledMax;             /* reported scaled max value possible */
++    long size;                  /* size in bits of data return from element */
++    Boolean relative;           /* are reports relative to last report (deltas) */
++    Boolean wrapping;           /* does element wrap around (one value higher than max is min) */
++    Boolean nonLinear;          /* are the values reported non-linear relative to element movement */
++    Boolean preferredState;     /* does element have a preferred state (such as a button) */
++    Boolean nullState;          /* does element have null state */
++#endif                          /* 0 */
+ 
+     /* runtime variables used for auto-calibration */
+-    SInt32 minReport;             /* min returned value */
+-    SInt32 maxReport;             /* max returned value */
++    long minReport;             /* min returned value */
++    long maxReport;             /* max returned value */
+ 
+     struct recElement *pNext;   /* next element in list */
+ };
+@@ -42,17 +57,19 @@ typedef struct recElement recElement;
+ 
+ struct joystick_hwdata
+ {
+-    IOHIDDeviceRef deviceRef;   /* HIDManager device handle */
+     io_service_t ffservice;     /* Interface for force feedback, 0 = no ff */
++    IOHIDDeviceInterface **interface;   /* interface to device, NULL = no interface */
++    IONotificationPortRef notificationPort; /* port to be notified on joystick removal */
++    io_iterator_t portIterator; /* iterator for removal callback */
+ 
+     char product[256];          /* name of product */
+-    uint32_t usage;                 /* usage page from IOUSBHID Parser.h which defines general usage */
+-    uint32_t usagePage;             /* usage within above page from IOUSBHID Parser.h which defines specific usage */
++    long usage;                 /* usage page from IOUSBHID Parser.h which defines general usage */
++    long usagePage;             /* usage within above page from IOUSBHID Parser.h which defines specific usage */
+ 
+-    int axes;                  /* number of axis (calculated, not reported by device) */
+-    int buttons;               /* number of buttons (calculated, not reported by device) */
+-    int hats;                  /* number of hat switches (calculated, not reported by device) */
+-    int elements;              /* number of total elements (should be total of above) (calculated, not reported by device) */
++    long axes;                  /* number of axis (calculated, not reported by device) */
++    long buttons;               /* number of buttons (calculated, not reported by device) */
++    long hats;                  /* number of hat switches (calculated, not reported by device) */
++    long elements;              /* number of total elements (should be total of above) (calculated, not reported by device) */
+ 
+     recElement *firstAxis;
+     recElement *firstButton;
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_power_macosx_SDL__syspower.c
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_power_macosx_SDL__syspower.c:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_power_macosx_SDL__syspower.c      Sun Nov 12 21:28:04 2023
@@ -0,0 +1,20 @@
+$NetBSD: patch-src_power_macosx_SDL__syspower.c,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/power/macosx/SDL_syspower.c.orig       2014-03-16 02:31:42.000000000 +0000
++++ src/power/macosx/SDL_syspower.c
+@@ -23,6 +23,12 @@
+ #ifndef SDL_POWER_DISABLED
+ #if SDL_POWER_MACOSX
+ 
++#if defined(__ALTIVEC__) && !defined(MAC_OS_X_VERSION_10_5)
++/* to cricumvent a bug in Mac OS X 10.4 SDK */
++#define vector __vector
++#include <CoreServices/CoreServices.h>
++#undef vector
++#endif
+ #include <Carbon/Carbon.h>
+ #include <IOKit/ps/IOPowerSources.h>
+ #include <IOKit/ps/IOPSKeys.h>
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_thread_pthread_SDL__systhread.c
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_thread_pthread_SDL__systhread.c:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_thread_pthread_SDL__systhread.c   Sun Nov 12 21:28:04 2023
@@ -0,0 +1,15 @@
+$NetBSD: patch-src_thread_pthread_SDL__systhread.c,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+NetBSD support. This was upstreamed ages ago.
+
+--- src/thread/pthread/SDL_systhread.c.orig    2014-03-16 02:31:44.000000000 +0000
++++ src/thread/pthread/SDL_systhread.c
+@@ -128,6 +128,8 @@ SDL_SYS_SetupThread(const char *name)
+             ppthread_setname_np(pthread_self(), name);
+             #endif
+         }
++        #elif defined(__NetBSD__)
++            pthread_setname_np(pthread_self(), "%s", name);
+         #elif HAVE_PTHREAD_SETNAME_NP
+             pthread_setname_np(pthread_self(), name);
+         #elif HAVE_PTHREAD_SET_NAME_NP
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoaclipboard.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoaclipboard.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoaclipboard.m Sun Nov 12 21:28:04 2023
@@ -0,0 +1,23 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoaclipboard.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/video/cocoa/SDL_cocoaclipboard.m.orig  2014-03-16 02:31:45.000000000 +0000
++++ src/video/cocoa/SDL_cocoaclipboard.m
+@@ -30,11 +30,15 @@ GetTextFormat(_THIS)
+ {
+     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ 
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+     if (data->osversion >= 0x1060) {
+         return NSPasteboardTypeString;
+     } else {
++#endif
+         return NSStringPboardType;
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+     }
++#endif
+ }
+ 
+ int
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoakeyboard.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoakeyboard.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoakeyboard.m  Sun Nov 12 21:28:04 2023
@@ -0,0 +1,23 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoakeyboard.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/video/cocoa/SDL_cocoakeyboard.m.orig   2014-03-16 02:31:45.000000000 +0000
++++ src/video/cocoa/SDL_cocoakeyboard.m
+@@ -426,6 +426,7 @@ HandleModifiers(_THIS, unsigned short sc
+ static void
+ UpdateKeymap(SDL_VideoData *data)
+ {
++#if defined(MAC_OS_X_VERSION_10_5)
+     TISInputSourceRef key_layout;
+     const void *chr_data;
+     int i;
+@@ -483,6 +484,7 @@ UpdateKeymap(SDL_VideoData *data)
+ 
+ cleanup:
+     CFRelease(key_layout);
++#endif
+ }
+ 
+ void
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamessagebox.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamessagebox.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamessagebox.m        Sun Nov 12 21:28:04 2023
@@ -0,0 +1,21 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoamessagebox.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+The altivec header inclusion does not appear to be used in these files, and
+breaks non-Altivec builds.
+
+--- src/video/cocoa/SDL_cocoamessagebox.m.orig 2014-03-16 02:31:45.000000000 +0000
++++ src/video/cocoa/SDL_cocoamessagebox.m
+@@ -22,13 +22,6 @@
+ 
+ #if SDL_VIDEO_DRIVER_COCOA
+ 
+-#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
+-#include <altivec.h>
+-#undef bool
+-#undef vector
+-#undef pixel
+-#endif
+-
+ #include "SDL_events.h"
+ #include "SDL_timer.h"
+ #include "SDL_messagebox.h"
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamodes.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamodes.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamodes.m     Sun Nov 12 21:28:04 2023
@@ -0,0 +1,93 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoamodes.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/video/cocoa/SDL_cocoamodes.m.orig      2014-03-16 02:31:41.000000000 +0000
++++ src/video/cocoa/SDL_cocoamodes.m
+@@ -127,6 +127,7 @@ GetDisplayMode(_THIS, const void *modere
+     }
+     data->moderef = moderef;
+ 
++    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+     if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+         CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef;
+         CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
+@@ -146,6 +147,7 @@ GetDisplayMode(_THIS, const void *modere
+ 
+         CFRelease(fmt);
+     }
++    #endif
+ 
+     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+     if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
+@@ -184,17 +186,21 @@ GetDisplayMode(_THIS, const void *modere
+ static void
+ Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
+ {
++    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+     if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+         CGDisplayModeRelease((CGDisplayModeRef) moderef);  /* NULL is ok */
+     }
++    #endif
+ }
+ 
+ static void
+ Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
+ {
++    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+     if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+         CFRelease(modelist);  /* NULL is ok */
+     }
++    #endif
+ }
+ 
+ static const char *
+@@ -257,9 +263,11 @@ Cocoa_InitModes(_THIS)
+                 continue;
+             }
+ 
++            #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+             if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+                 moderef = CGDisplayCopyDisplayMode(displays[i]);
+             }
++            #endif
+ 
+             #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+             if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
+@@ -319,9 +327,11 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDi
+     SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+     CFArrayRef modes = NULL;
+ 
++    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+     if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+         modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
+     }
++    #endif
+ 
+     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+     if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
+@@ -337,9 +347,11 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDi
+             const void *moderef = CFArrayGetValueAtIndex(modes, i);
+             SDL_DisplayMode mode;
+             if (GetDisplayMode(_this, moderef, &mode)) {
++    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+                 if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+                     CGDisplayModeRetain((CGDisplayModeRef) moderef);
+                 }
++    #endif
+                 SDL_AddDisplayMode(display, &mode);
+             }
+         }
+@@ -351,9 +363,11 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDi
+ static CGError
+ Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode)
+ {
++    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+     if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+         return CGDisplaySetDisplayMode(display, (CGDisplayModeRef) mode, NULL);
+     }
++    #endif
+  
+     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+     if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamouse.h
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamouse.h:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoamouse.h     Sun Nov 12 21:28:04 2023
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoamouse.h,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/video/cocoa/SDL_cocoamouse.h.orig      2014-03-16 02:31:41.000000000 +0000
++++ src/video/cocoa/SDL_cocoamouse.h
+@@ -25,6 +25,10 @@
+ 
+ #include "SDL_cocoavideo.h"
+ 
++#if !defined(MAC_OS_X_VERSION_10_5)
++typedef float CGFloat;
++#endif
++
+ extern void Cocoa_InitMouse(_THIS);
+ extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
+ extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoaopengl.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoaopengl.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoaopengl.m    Sun Nov 12 21:28:04 2023
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoaopengl.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/video/cocoa/SDL_cocoaopengl.m.orig     2014-03-16 02:31:41.000000000 +0000
++++ src/video/cocoa/SDL_cocoaopengl.m
+@@ -347,9 +347,11 @@ Cocoa_GL_GetDrawableSize(_THIS, SDL_Wind
+ 
+     /* This gives us the correct viewport for a Retina-enabled view, only
+      * supported on 10.7+. */
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+     if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
+         viewport = [contentView convertRectToBacking:viewport];
+     }
++#endif
+ 
+     if (w) {
+         *w = viewport.size.width;
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoavideo.h
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoavideo.h:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoavideo.h     Sun Nov 12 21:28:04 2023
@@ -0,0 +1,32 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoavideo.h,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/video/cocoa/SDL_cocoavideo.h.orig      2014-03-16 02:31:41.000000000 +0000
++++ src/video/cocoa/SDL_cocoavideo.h
+@@ -25,6 +25,12 @@
+ 
+ #include "SDL_opengl.h"
+ 
++#if defined(__ALTIVEC__) && !defined(MAC_OS_X_VERSION_10_5)
++/* to cricumvent a bug in Mac OS X 10.4 SDK */
++#define vector __vector
++#include <CoreServices/CoreServices.h>
++#undef vector
++#endif
+ #include <ApplicationServices/ApplicationServices.h>
+ #include <Cocoa/Cocoa.h>
+ 
+@@ -39,6 +45,11 @@
+ #include "SDL_cocoaopengl.h"
+ #include "SDL_cocoawindow.h"
+ 
++#if !defined(MAC_OS_X_VERSION_10_5)
++typedef long int NSInteger;
++typedef unsigned int NSUInteger;
++#endif
++
+ /* Private display data */
+ 
+ @class SDLTranslatorResponder;
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoavideo.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoavideo.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoavideo.m     Sun Nov 12 21:28:04 2023
@@ -0,0 +1,21 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoavideo.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+The altivec header inclusion does not appear to be used in these files, and
+breaks non-Altivec builds.
+
+--- src/video/cocoa/SDL_cocoavideo.m.orig      2014-03-16 02:31:41.000000000 +0000
++++ src/video/cocoa/SDL_cocoavideo.m
+@@ -22,13 +22,6 @@
+ 
+ #if SDL_VIDEO_DRIVER_COCOA
+ 
+-#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
+-#include <altivec.h>
+-#undef bool
+-#undef vector
+-#undef pixel
+-#endif
+-
+ #include "SDL.h"
+ #include "SDL_endian.h"
+ #include "SDL_cocoavideo.h"
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoawindow.h
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoawindow.h:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoawindow.h    Sun Nov 12 21:28:04 2023
@@ -0,0 +1,29 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoawindow.h,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/video/cocoa/SDL_cocoawindow.h.orig     2014-03-16 02:31:41.000000000 +0000
++++ src/video/cocoa/SDL_cocoawindow.h
+@@ -35,7 +35,11 @@ typedef enum
+     PENDING_OPERATION_MINIMIZE
+ } PendingWindowOperation;
+ 
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+ @interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
++#else
++@interface Cocoa_WindowListener : NSResponder {
++#endif
+     SDL_WindowData *_data;
+     BOOL observingVisible;
+     BOOL wasCtrlLeft;
+@@ -73,7 +77,9 @@ typedef enum
+ -(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
+ -(void) windowWillExitFullScreen:(NSNotification *) aNotification;
+ -(void) windowDidExitFullScreen:(NSNotification *) aNotification;
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
++#endif
+ 
+ /* Window event handling */
+ -(void) mouseDown:(NSEvent *) theEvent;
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoawindow.m
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoawindow.m:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_cocoa_SDL__cocoawindow.m    Sun Nov 12 21:28:04 2023
@@ -0,0 +1,175 @@
+$NetBSD: patch-src_video_cocoa_SDL__cocoawindow.m,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+Restore support for Mac OS X 10.4, from "TigerPorts":
+https://raw.githubusercontent.com/evanmiller/TigerPorts/master/devel/libsdl2/files/patch-SDL2-2.0.3_OSX_104.diff
+
+--- src/video/cocoa/SDL_cocoawindow.m.orig     2014-03-16 02:31:41.000000000 +0000
++++ src/video/cocoa/SDL_cocoawindow.m
+@@ -23,7 +23,9 @@
+ #if SDL_VIDEO_DRIVER_COCOA
+ 
+ #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
++#if 0
+ # error SDL for Mac OS X must be built with a 10.7 SDK or above.
++#endif
+ #endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
+ 
+ #include "SDL_syswm.h"
+@@ -100,7 +102,14 @@ ScheduleContextUpdates(SDL_WindowData *d
+     NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
+     NSMutableArray *contexts = data->nscontexts;
+     @synchronized (contexts) {
++#if defined(MAC_OS_X_VERSION_10_5)
+         for (SDLOpenGLContext *context in contexts) {
++#else
++        /* old way to iterate */
++        int i;
++        for (i = 0; i < [contexts count]; i++) {
++            SDLOpenGLContext *context = [contexts objectAtIndex:i];
++#endif
+             if (context == currentContext) {
+                 [context update];
+             } else {
+@@ -190,10 +199,12 @@ SetWindowStyle(SDL_Window * window, unsi
+         [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
+         [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
+         [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+         [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
+         [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
+         [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
+         [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
++#endif
+     } else {
+         [window setDelegate:self];
+     }
+@@ -212,9 +223,11 @@ SetWindowStyle(SDL_Window * window, unsi
+ 
+     [view setNextResponder:self];
+ 
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+     if ([view respondsToSelector:@selector(setAcceptsTouchEvents:)]) {
+         [view setAcceptsTouchEvents:YES];
+     }
++#endif
+ }
+ 
+ - (void)observeValueForKeyPath:(NSString *)keyPath
+@@ -282,7 +295,9 @@ SetWindowStyle(SDL_Window * window, unsi
+     inFullscreenTransition = YES;
+ 
+     /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+     [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
++#endif
+     [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
+     return YES;
+ }
+@@ -319,10 +334,12 @@ SetWindowStyle(SDL_Window * window, unsi
+         [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
+         [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
+         [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+         [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
+         [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
+         [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
+         [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
++#endif
+     } else {
+         [window setDelegate:nil];
+     }
+@@ -346,8 +363,14 @@ SetWindowStyle(SDL_Window * window, unsi
+        !!! FIXME:   http://bugzilla.libsdl.org/show_bug.cgi?id=1825
+     */
+     windows = [NSApp orderedWindows];
+-    for (NSWindow *win in windows)
+-    {
++#if defined(MAC_OS_X_VERSION_10_5)
++    for (NSWindow *win in windows) {
++#else
++    /* old way to iterate */
++    int i;
++    for (i = 0; i < [windows count]; i++) {
++        NSWindow *win = [windows objectAtIndex:i];
++#endif
+         if (win == window) {
+             continue;
+         }
+@@ -597,12 +620,14 @@ SetWindowStyle(SDL_Window * window, unsi
+         [nswindow miniaturize:nil];
+     } else {
+         /* Adjust the fullscreen toggle button and readd menu now that we're here. */
++#if MAC_OS_X_VERSION_MIN_REQUIRED > 1070
+         if (window->flags & SDL_WINDOW_RESIZABLE) {
+             /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
+             [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
+         } else {
+             [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
+         }
++#endif
+         [NSMenu setMenuBarVisible:YES];
+ 
+         pendingWindowOperation = PENDING_OPERATION_NONE;
+@@ -620,6 +645,7 @@ SetWindowStyle(SDL_Window * window, unsi
+     }
+ }
+ 
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
+ {
+     if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+@@ -628,6 +654,7 @@ SetWindowStyle(SDL_Window * window, unsi
+         return proposedOptions;
+     }
+ }
++#endif
+ 
+ 
+ /* We'll respond to key events by doing nothing so we don't beep.
+@@ -822,6 +849,7 @@ SetWindowStyle(SDL_Window * window, unsi
+     [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
+ }
+ 
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+ - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
+ {
+     NSSet *touches = 0;
+@@ -875,6 +903,7 @@ SetWindowStyle(SDL_Window * window, unsi
+         touch = (NSTouch*)[enumerator nextObject];
+     }
+ }
++#endif
+ 
+ @end
+ 
+@@ -1040,6 +1069,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * w
+     [nswindow setBackgroundColor:[NSColor blackColor]];
+ 
+     if (videodata->allow_spaces) {
++#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+         SDL_assert(videodata->osversion >= 0x1070);
+         SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
+         /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
+@@ -1047,6 +1077,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * w
+             /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
+             [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
+         }
++#endif
+     }
+ 
+     /* Create a default view for this window */
+@@ -1490,7 +1521,14 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * 
+         }
+ 
+         NSArray *contexts = [[data->nscontexts copy] autorelease];
++#if defined(MAC_OS_X_VERSION_10_5)
+         for (SDLOpenGLContext *context in contexts) {
++#else
++        /* old way to iterate */
++        int i;
++        for (i = 0; i < [contexts count]; i++) {
++            SDLOpenGLContext *context = [contexts objectAtIndex:i];
++#endif
+             /* Calling setWindow:NULL causes the context to remove itself from the context list. */            
+             [context setWindow:NULL];
+         }
Index: pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_x11_SDL__x11opengl.c
diff -u /dev/null pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_x11_SDL__x11opengl.c:1.1
--- /dev/null   Sun Nov 12 21:28:04 2023
+++ pkgsrc/devel/SDL2-legacy-darwin/patches/patch-src_video_x11_SDL__x11opengl.c        Sun Nov 12 21:28:04 2023
@@ -0,0 +1,16 @@
+$NetBSD: patch-src_video_x11_SDL__x11opengl.c,v 1.1 2023/11/12 21:28:04 nia Exp $
+
+NetBSD support. This was upstreamed a long time ago.
+We can have different versioning systems depending on modular xorg vs. xsrc.
+
+--- src/video/x11/SDL_x11opengl.c.orig 2014-03-16 02:31:44.000000000 +0000
++++ src/video/x11/SDL_x11opengl.c
+@@ -31,7 +31,7 @@
+ #include "SDL_loadso.h"
+ #include "SDL_x11opengles.h"
+ 
+-#if defined(__IRIX__)
++#if defined(__IRIX__) || defined(__NetBSD__)
+ /* IRIX doesn't have a GL library versioning system */
+ #define DEFAULT_OPENGL  "libGL.so"
+ #elif defined(__MACOSX__)



Home | Main Index | Thread Index | Old Index