Skip to content

Commit

Permalink
Update bindings for release SDL 2.26.0 (#253)
Browse files Browse the repository at this point in the history
* Update event structures for 2.26.0

* add new API in SDL 2.26.0

* add new hints in SDL 2.26.0

* add myself to AUTHORS.txt

* Update __all__ to be in same order as SDL_hints.h

* Rearrange hints by group/alphabetical order

* Update sensor constants and version

* Reorder bindings to match headers

* Add basic tests for new functions

* Update CI for 2.26.0

* Update news.rst

* Patch out SDL_GetJoystickGUIDInfo on older Python

* Fix xfail conditional

Co-authored-by: multiSnow <2306079+multiSnow@users.noreply.github.com>
  • Loading branch information
a-hurst and multiSnow committed Nov 22, 2022
1 parent a95e5ca commit 761d842
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 35 deletions.
7 changes: 7 additions & 0 deletions .ci/getsdl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
}

libversions = {
'2.26.0': {
'SDL2': '2.26.0',
'SDL2_mixer': '2.6.0',
'SDL2_ttf': '2.20.0',
'SDL2_image': '2.6.0',
'SDL2_gfx': '1.0.4'
},
'2.24.0': {
'SDL2': '2.24.0',
'SDL2_mixer': '2.6.0',
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
fail-fast: false
matrix:
python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']
sdl2: ['2.24.0']
sdl2: ['2.26.0']
name-prefix: ['Linux (Python ']
include:
- python-version: 'pypy-2.7'
sdl2: '2.24.0'
sdl2: '2.26.0'
name-prefix: 'Experimental / Linux ('
- python-version: 'pypy-3.7'
sdl2: '2.24.0'
sdl2: '2.26.0'
name-prefix: 'Experimental / Linux ('

env:
Expand Down Expand Up @@ -72,11 +72,11 @@ jobs:
fail-fast: false
matrix:
python-version: [3.9]
sdl2: ['2.24.0', '2.0.22', '2.0.20']
sdl2: ['2.26.0', '2.24.0', '2.0.22']
name-prefix: ['macOS (Python ']
include:
- python-version: '2.7'
sdl2: '2.24.0'
sdl2: '2.26.0'
name-prefix: 'macOS (Python '
- python-version: '3.9'
sdl2: 'from Homebrew'
Expand Down Expand Up @@ -129,22 +129,22 @@ jobs:
python-version: [3.9]
architecture: ['x64']
sdl2: [
'2.24.0', '2.0.22', '2.0.20', '2.0.18', '2.0.16', '2.0.14', '2.0.12',
'2.0.10', '2.0.9', '2.0.8', '2.0.7', '2.0.6', '2.0.5'
'2.26.0', '2.24.0', '2.0.22', '2.0.20', '2.0.18', '2.0.16', '2.0.14',
'2.0.12', '2.0.10', '2.0.9', '2.0.8', '2.0.7', '2.0.6', '2.0.5'
]
name-prefix: ['Windows (Python ']
include:
- python-version: '2.7'
architecture: 'x64'
sdl2: '2.24.0'
sdl2: '2.26.0'
name-prefix: 'Windows (Python '
- python-version: '2.7'
architecture: 'x86'
sdl2: '2.24.0'
sdl2: '2.26.0'
name-prefix: 'Windows 32-bit (Python '
- python-version: '3.9'
architecture: 'x86'
sdl2: '2.24.0'
sdl2: '2.26.0'
name-prefix: 'Windows 32-bit (Python '
- python-version: '2.7'
architecture: 'x86'
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ Thanks to everyone else for their assistance, support, fixes and improvements:
* Todd Rovito
* William Manire
* Zack Marvel
* WJ Liu
4 changes: 4 additions & 0 deletions doc/modules/sdl2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ available within :mod:`sdl2`.
* Everything from ``SDL_opengl.h`` (see PyOpenGL for a compatible OpenGL API)
* Everything from ``SDL_mutex.h``

Additionally, ``SDL_GetJoystickGUIDInfo`` only functions properly in Python 3.7
and newer due to a ctypes bug. On older versions of Python, the function can be
called but will have no effect.

Additional interfaces
---------------------
The following functions, classes, constants and macros are *not* part of
Expand Down
3 changes: 3 additions & 0 deletions doc/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ New Features:
to allow easier unpacking in Python (e.g. ``x, y, w, h = rect``).
* Cache :class:`sdl2.ext.Texture` sizes for faster retrieval, improving render
performance in some cases.
* Updated to wrap new functions and constants in SDL2 2.26.0 (PR #252 & #253).

Fixed Bugs:

* Fixed bug preventing SDL Points and Rects from being used as ``srcrect`` or
``dstrect`` for :meth:`~sdl2.ext.Renderer.copy`.
* Added a binding for ``SDL_ResetHint``, which was added in SDL 2.24.0 but
got missed in PR #246.


0.9.14
Expand Down
6 changes: 6 additions & 0 deletions sdl2/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
SDLFunc("SDL_SetClipboardText", [c_char_p], c_int),
SDLFunc("SDL_GetClipboardText", None, c_char_p),
SDLFunc("SDL_HasClipboardText", None, SDL_bool),
SDLFunc("SDL_SetPrimarySelectionText", [c_char_p], c_int, added='2.26.0'),
SDLFunc("SDL_GetPrimarySelectionText", None, c_char_p, added='2.26.0'),
SDLFunc("SDL_HasPrimarySelectionText", None, SDL_bool, added='2.26.0'),
]
_ctypes = AttributeDict()
for f in _funcdefs:
Expand All @@ -23,3 +26,6 @@
SDL_SetClipboardText = _ctypes["SDL_SetClipboardText"]
SDL_GetClipboardText = _ctypes["SDL_GetClipboardText"]
SDL_HasClipboardText = _ctypes["SDL_HasClipboardText"]
SDL_SetPrimarySelectionText = _ctypes["SDL_SetPrimarySelectionText"]
SDL_GetPrimarySelectionText = _ctypes["SDL_GetPrimarySelectionText"]
SDL_HasPrimarySelectionText = _ctypes["SDL_HasPrimarySelectionText"]
43 changes: 29 additions & 14 deletions sdl2/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ctypes import POINTER as _P
from .dll import version as sdl_version
from .dll import _bind, SDLFunc, AttributeDict
from .stdinc import Sint16, Sint32, Uint8, Uint16, Uint32, SDL_bool
from .stdinc import Sint16, Sint32, Uint8, Uint16, Uint32, Uint64, SDL_bool
from .keyboard import SDL_Keysym
from .joystick import SDL_JoystickID, SDL_JoystickPowerLevel
from .touch import SDL_FingerID, SDL_TouchID
Expand Down Expand Up @@ -264,6 +264,11 @@ class SDL_MouseButtonEvent(Structure):
("preciseX", c_float),
("preciseY", c_float)
]
if sdl_version >= 2260:
_mousewheel_fields += [
("mouseX", Sint32),
("mouseY", Sint32)
]
class SDL_MouseWheelEvent(Structure):
_fields_ = _mousewheel_fields

Expand Down Expand Up @@ -373,14 +378,19 @@ class SDL_ControllerTouchpadEvent(Structure):
("pressure", c_float),
]

class SDL_ControllerSensorEvent(Structure):
_fields_ = [
("type", Uint32),
("timestamp", Uint32),
("which", SDL_JoystickID),
("sensor", Sint32),
("data", c_float * 3),
_controller_sensor_fields = [
("type", Uint32),
("timestamp", Uint32),
("which", SDL_JoystickID),
("sensor", Sint32),
("data", c_float * 3),
]
if sdl_version >= 2260:
_controller_sensor_fields += [
("timestamp_us", Uint64)
]
class SDL_ControllerSensorEvent(Structure):
_fields_ = _controller_sensor_fields

class SDL_AudioDeviceEvent(Structure):
_fields_ = [
Expand Down Expand Up @@ -442,13 +452,18 @@ class SDL_DropEvent(Structure):
("windowID", Uint32),
]

class SDL_SensorEvent(Structure):
_fields_ = [
("type", Uint32),
("timestamp", Uint32),
("which", Sint32),
("data", (c_float * 6)),
_sensor_fields = [
("type", Uint32),
("timestamp", Uint32),
("which", Sint32),
("data", (c_float * 6)),
]
if sdl_version >= 2260:
_sensor_fields += [
("timestamp_us", Uint64)
]
class SDL_SensorEvent(Structure):
_fields_ = _sensor_fields

class SDL_QuitEvent(Structure):
_fields_ = [
Expand Down
7 changes: 6 additions & 1 deletion sdl2/gamecontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ctypes import POINTER as _P
from .dll import _bind, SDLFunc, AttributeDict
from .dll import version as sdl_version
from .stdinc import SDL_bool, Sint16, Uint32, Uint16, Uint8
from .stdinc import SDL_bool, Sint16, Uint64, Uint32, Uint16, Uint8
from .joystick import (SDL_JoystickGUID, SDL_Joystick, SDL_JoystickID,
SDL_JoystickGetGUIDString)
from .rwops import SDL_RWops, SDL_RWFromFile
Expand Down Expand Up @@ -228,6 +228,10 @@ class SDL_GameController(c_void_p):
[_P(SDL_GameController), SDL_SensorType, _P(c_float), c_int],
returns = c_int, added = '2.0.14'
),
SDLFunc("SDL_GameControllerGetSensorDataWithTimestamp",
[_P(SDL_GameController), SDL_SensorType, _P(Uint64), _P(c_float), c_int],
returns = c_int, added = '2.26.0'
),
SDLFunc("SDL_GameControllerRumble",
[_P(SDL_GameController), Uint16, Uint16, Uint32],
returns = c_int, added = '2.0.9'
Expand Down Expand Up @@ -300,6 +304,7 @@ class SDL_GameController(c_void_p):
SDL_GameControllerIsSensorEnabled = _ctypes["SDL_GameControllerIsSensorEnabled"]
SDL_GameControllerGetSensorDataRate = _ctypes["SDL_GameControllerGetSensorDataRate"]
SDL_GameControllerGetSensorData = _ctypes["SDL_GameControllerGetSensorData"]
SDL_GameControllerGetSensorDataWithTimestamp = _ctypes["SDL_GameControllerGetSensorDataWithTimestamp"]
SDL_GameControllerAddMappingsFromRW = _ctypes["SDL_GameControllerAddMappingsFromRW"]
SDL_GameControllerAddMappingsFromFile = lambda fname: SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(fname, b"rb"), 1)
SDL_GameControllerFromInstanceID = _ctypes["SDL_GameControllerFromInstanceID"]
Expand Down
34 changes: 32 additions & 2 deletions sdl2/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT",
"SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS",
"SDL_HINT_GRAB_KEYBOARD",
"SDL_HINT_HIDAPI_IGNORE_DEVICES",
"SDL_HINT_IDLE_TIMER_DISABLED",
"SDL_HINT_IME_INTERNAL_EDITING",
"SDL_HINT_IME_SHOW_UI",
Expand All @@ -49,9 +50,11 @@
"SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE",
"SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS",
"SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS",
"SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS",
"SDL_HINT_JOYSTICK_HIDAPI_LUNA",
"SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC",
"SDL_HINT_JOYSTICK_HIDAPI_SHIELD",
"SDL_HINT_JOYSTICK_HIDAPI_PS3",
"SDL_HINT_JOYSTICK_HIDAPI_PS4",
"SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE",
"SDL_HINT_JOYSTICK_HIDAPI_PS5",
Expand All @@ -63,7 +66,14 @@
"SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED",
"SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED",
"SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED",
"SDL_HINT_JOYSTICK_HIDAPI_WII",
"SDL_HINT_JOYSTICK_HIDAPI_WII_PLAYER_LED",
"SDL_HINT_JOYSTICK_HIDAPI_XBOX",
"SDL_HINT_JOYSTICK_HIDAPI_XBOX_360",
"SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED",
"SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_WIRELESS",
"SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE",
"SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED",
"SDL_HINT_JOYSTICK_RAWINPUT",
"SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT",
"SDL_HINT_JOYSTICK_HIDAPI_CORRELATE_XINPUT",
Expand All @@ -86,6 +96,7 @@
"SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
"SDL_HINT_MOUSE_RELATIVE_SCALING",
"SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE",
"SDL_HINT_MOUSE_RELATIVE_SYSTEM_SCALE",
"SDL_HINT_MOUSE_RELATIVE_WARP_MOTION",
"SDL_HINT_MOUSE_TOUCH_EVENTS",
"SDL_HINT_MOUSE_AUTO_CAPTURE",
Expand All @@ -105,6 +116,7 @@
"SDL_HINT_RENDER_OPENGL_SHADERS",
"SDL_HINT_RENDER_SCALE_QUALITY",
"SDL_HINT_RENDER_VSYNC",
"SDL_HINT_PS2_DYNAMIC_VSYNC",
"SDL_HINT_RETURN_KEY_HIDES_IME",
"SDL_HINT_RPI_VIDEO_LAYER",
"SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME",
Expand All @@ -125,6 +137,7 @@
"SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR",
"SDL_HINT_VIDEO_WAYLAND_PREFER_LIBDECOR",
"SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION",
"SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP",
"SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
"SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL",
"SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN",
Expand Down Expand Up @@ -208,6 +221,7 @@
SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN = b"SDL_VIDEO_FOREIGN_WINDOW_VULKAN"
SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR = b"SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR"
SDL_HINT_VIDEO_WAYLAND_PREFER_LIBDECOR = b"SDL_VIDEO_WAYLAND_PREFER_LIBDECOR"
SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP = b"SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP"
SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION = b"SDL_VIDEO_WAYLAND_MODE_EMULATION"
SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT = b"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"
SDL_HINT_VIDEO_X11_FORCE_EGL = b"SDL_VIDEO_X11_FORCE_EGL"
Expand Down Expand Up @@ -264,6 +278,7 @@
SDL_HINT_MOUSE_RELATIVE_MODE_WARP = b"SDL_MOUSE_RELATIVE_MODE_WARP"
SDL_HINT_MOUSE_RELATIVE_SCALING = b"SDL_MOUSE_RELATIVE_SCALING"
SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE = b"SDL_MOUSE_RELATIVE_SPEED_SCALE"
SDL_HINT_MOUSE_RELATIVE_SYSTEM_SCALE = b"SDL_MOUSE_RELATIVE_SYSTEM_SCALE"
SDL_HINT_MOUSE_RELATIVE_WARP_MOTION = b"SDL_MOUSE_RELATIVE_WARP_MOTION"
SDL_HINT_MOUSE_TOUCH_EVENTS = b"SDL_MOUSE_TOUCH_EVENTS"
SDL_HINT_TOUCH_MOUSE_EVENTS = b"SDL_TOUCH_MOUSE_EVENTS"
Expand All @@ -280,16 +295,20 @@
SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES = b"SDL_GAMECONTROLLER_IGNORE_DEVICES"
SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT = b"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT"
SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS = b"SDL_GAMECONTROLLER_USE_BUTTON_LABELS"
SDL_HINT_HIDAPI_IGNORE_DEVICES = b"SDL_HIDAPI_IGNORE_DEVICES"
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS = b"SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
SDL_HINT_JOYSTICK_HIDAPI = b"SDL_JOYSTICK_HIDAPI"
SDL_HINT_JOYSTICK_HIDAPI_CORRELATE_XINPUT = b"SDL_JOYSTICK_HIDAPI_CORRELATE_XINPUT"
SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE = b"SDL_JOYSTICK_HIDAPI_GAMECUBE"
SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE = b"SDL_JOYSTICK_GAMECUBE_RUMBLE_BRAKE"
SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS = b"SDL_JOYSTICK_HIDAPI_JOY_CONS"
SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED = b"SDL_JOYSTICK_HIDAPI_JOYCON_HOME_LED"
SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS = b"SDL_JOYSTICK_HIDAPI_COMBINE_JOY_CONS"
SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS = b"SDL_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS"
SDL_HINT_JOYSTICK_HIDAPI_LUNA = b"SDL_JOYSTICK_HIDAPI_LUNA"
SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC = b"SDL_JOYSTICK_HIDAPI_NINTENDO_CLASSIC"
SDL_HINT_JOYSTICK_HIDAPI_SHIELD = b"SDL_JOYSTICK_HIDAPI_SHIELD"
SDL_HINT_JOYSTICK_HIDAPI_PS3 = b"SDL_JOYSTICK_HIDAPI_PS3"
SDL_HINT_JOYSTICK_HIDAPI_PS4 = b"SDL_JOYSTICK_HIDAPI_PS4"
SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE = b"SDL_JOYSTICK_HIDAPI_PS4_RUMBLE"
SDL_HINT_JOYSTICK_HIDAPI_PS5 = b"SDL_JOYSTICK_HIDAPI_PS5"
Expand All @@ -299,9 +318,15 @@
SDL_HINT_JOYSTICK_HIDAPI_STEAM = b"SDL_JOYSTICK_HIDAPI_STEAM"
SDL_HINT_JOYSTICK_HIDAPI_SWITCH = b"SDL_JOYSTICK_HIDAPI_SWITCH"
SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED = b"SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED"
SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED = b"SDL_JOYSTICK_HIDAPI_JOYCON_HOME_LED"
SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED = b"SDL_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED"
SDL_HINT_JOYSTICK_HIDAPI_WII = b"SDL_JOYSTICK_HIDAPI_WII"
SDL_HINT_JOYSTICK_HIDAPI_WII_PLAYER_LED = b"SDL_JOYSTICK_HIDAPI_WII_PLAYER_LED"
SDL_HINT_JOYSTICK_HIDAPI_XBOX = b"SDL_JOYSTICK_HIDAPI_XBOX"
SDL_HINT_JOYSTICK_HIDAPI_XBOX_360 = b"SDL_JOYSTICK_HIDAPI_XBOX_360"
SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED = b"SDL_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED"
SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_WIRELESS = b"SDL_JOYSTICK_HIDAPI_XBOX_360_WIRELESS"
SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE = b"SDL_JOYSTICK_HIDAPI_XBOX_ONE"
SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED = b"SDL_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED"
SDL_HINT_JOYSTICK_RAWINPUT = b"SDL_JOYSTICK_RAWINPUT"
SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT = b"SDL_JOYSTICK_RAWINPUT_CORRELATE_XINPUT"
SDL_HINT_JOYSTICK_ROG_CHAKRAM = b"SDL_JOYSTICK_ROG_CHAKRAM"
Expand All @@ -321,6 +346,7 @@
SDL_HINT_MAC_BACKGROUND_APP = b"SDL_MAC_BACKGROUND_APP"
SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK = b"SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"
SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH = b"SDL_MAC_OPENGL_ASYNC_DISPATCH"
SDL_HINT_PS2_DYNAMIC_VSYNC = b"SDL_PS2_DYNAMIC_VSYNC"
SDL_HINT_RPI_VIDEO_LAYER = b"SDL_RPI_VIDEO_LAYER"
SDL_HINT_RENDER_DIRECT3D11_DEBUG = b"SDL_RENDER_DIRECT3D11_DEBUG"
SDL_HINT_RENDER_DIRECT3D_THREADSAFE = b"SDL_RENDER_DIRECT3D_THREADSAFE"
Expand Down Expand Up @@ -381,10 +407,12 @@
SDLFunc("SDL_SetHintWithPriority", [c_char_p, c_char_p, SDL_HintPriority], SDL_bool),
SDLFunc("SDL_SetHint", [c_char_p, c_char_p], SDL_bool),
SDLFunc("SDL_GetHint", [c_char_p], c_char_p),
SDLFunc("SDL_ResetHint", [c_char_p], SDL_bool, added='2.24.0'),
SDLFunc("SDL_ResetHints", None, None, added='2.26.0'),
SDLFunc("SDL_GetHintBoolean", [c_char_p, SDL_bool], SDL_bool, added='2.0.5'),
SDLFunc("SDL_ClearHints"),
SDLFunc("SDL_AddHintCallback", [c_char_p, SDL_HintCallback, c_void_p]),
SDLFunc("SDL_DelHintCallback",[c_char_p, SDL_HintCallback, c_void_p]),
SDLFunc("SDL_DelHintCallback", [c_char_p, SDL_HintCallback, c_void_p]),
]
_ctypes = AttributeDict()
for f in _funcdefs:
Expand All @@ -397,6 +425,8 @@
SDL_SetHintWithPriority = _ctypes["SDL_SetHintWithPriority"]
SDL_SetHint = _ctypes["SDL_SetHint"]
SDL_GetHint = _ctypes["SDL_GetHint"]
SDL_ResetHint = _ctypes["SDL_ResetHint"]
SDL_ResetHints = _ctypes["SDL_ResetHints"]
SDL_GetHintBoolean = _ctypes["SDL_GetHintBoolean"]
SDL_ClearHints = _ctypes["SDL_ClearHints"]
SDL_AddHintCallback = _ctypes["SDL_AddHintCallback"]
Expand Down
13 changes: 13 additions & 0 deletions sdl2/joystick.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class SDL_VirtualJoystickDesc(Structure):
SDLFunc("SDL_JoystickGetType", [_P(SDL_Joystick)], SDL_JoystickType, added='2.0.6'),
SDLFunc("SDL_JoystickGetGUIDString", [SDL_JoystickGUID, c_char_p, c_int]),
SDLFunc("SDL_JoystickGetGUIDFromString", [c_char_p], SDL_JoystickGUID),
SDLFunc("SDL_GetJoystickGUIDInfo",
[SDL_JoystickGUID, _P(Uint16), _P(Uint16), _P(Uint16), _P(Uint16)],
None, added = '2.26.0'
),
SDLFunc("SDL_JoystickGetAttached", [_P(SDL_Joystick)], SDL_bool),
SDLFunc("SDL_JoystickInstanceID", [_P(SDL_Joystick)], SDL_JoystickID),
SDLFunc("SDL_JoystickNumAxes", [_P(SDL_Joystick)], c_int),
Expand Down Expand Up @@ -267,3 +271,12 @@ def SDL_JoystickGetGUIDString(guid, pszGUID, cbGUID):
s += "{:x}".format(g & 0x0F)
s = s.encode('utf-8')
pszGUID.value = s[:(cbGUID * 2)]

if sys.version_info >= (3, 7, 0, 'final'):
SDL_GetJoystickGUIDInfo = _ctypes["SDL_GetJoystickGUIDInfo"]
else:
def SDL_GetJoystickGUIDInfo(guid, vendor, product, version, crc16):
# We can't modify ctypes arguments passed with byref in Python,
# so to avoid a segfault on older Python versions we just do
# nothing here since we can't replicate its functionality.
pass

0 comments on commit 761d842

Please sign in to comment.