Skip to content

Commit 936b458

Browse files
committed
Allow wrapping SDL windows via WindowID
1 parent 67c1bf7 commit 936b458

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- `tcod.sdl.video.Window` now accepts an SDL WindowID.
12+
913
## [20.1.0] - 2026-02-25
1014

1115
### Added

tcod/sdl/video.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,14 @@ class Window:
174174
When using the libtcod :any:`Context` you can access its `Window` via :any:`Context.sdl_window`.
175175
"""
176176

177-
def __init__(self, sdl_window_p: Any) -> None: # noqa: ANN401
177+
def __init__(self, sdl_window_p: Any | int) -> None: # noqa: ANN401
178+
"""Wrap a SDL_Window pointer or SDL WindowID.
179+
180+
.. versionchanged:: Unreleased
181+
Now accepts `int` types as an SDL WindowID.
182+
"""
183+
if isinstance(sdl_window_p, int):
184+
sdl_window_p = _check_p(lib.SDL_GetWindowFromID(sdl_window_p))
178185
if ffi.typeof(sdl_window_p) is not ffi.typeof("struct SDL_Window*"):
179186
msg = "sdl_window_p must be {!r} type (was {!r}).".format(
180187
ffi.typeof("struct SDL_Window*"), ffi.typeof(sdl_window_p)
@@ -186,11 +193,13 @@ def __init__(self, sdl_window_p: Any) -> None: # noqa: ANN401
186193
self.p = sdl_window_p
187194

188195
def __eq__(self, other: object) -> bool:
196+
"""Return True if `self` and `other` wrap the same window."""
189197
if not isinstance(other, Window):
190198
return NotImplemented
191199
return bool(self.p == other.p)
192200

193201
def __hash__(self) -> int:
202+
"""Return the hash of this instances SDL window pointer."""
194203
return hash(self.p)
195204

196205
def _as_property_pointer(self) -> Any: # noqa: ANN401

0 commit comments

Comments
 (0)