Skip to content

Commit 6f1dc93

Browse files
committed
Add ClipboardUpdate event
Still missing other related functions to handle the clipboard
1 parent 4bce984 commit 6f1dc93

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
99
### Added
1010

1111
- `tcod.sdl.video.Window` now accepts an SDL WindowID.
12-
- `MouseState.integer_position` and `MouseMotion.integer_motion` to handle cases where integer values are preferred.
13-
- `KeyboardEvent.pressed`, `KeyboardEvent.which`, `KeyboardEvent.window_id`
12+
- `tcod.event`:
13+
- `MouseState.integer_position` and `MouseMotion.integer_motion` to handle cases where integer values are preferred.
14+
- `ClipboardUpdate` event.
15+
- `KeyboardEvent.pressed`, `KeyboardEvent.which`, `KeyboardEvent.window_id` attributes.
1416

1517
### Changed
1618

tcod/event.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,27 @@ def _from_sdl_event(cls, sdl_event: _C_SDL_Event) -> Self:
10411041
return cls(type=types[sdl_event.type], which=int(sdl_event.gdevice.which), **_unpack_sdl_event(sdl_event))
10421042

10431043

1044+
@attrs.define(slots=True, kw_only=True)
1045+
class ClipboardUpdate(Event):
1046+
"""Announces changed contents of the clipboard.
1047+
1048+
.. versionadded:: Unreleased
1049+
"""
1050+
1051+
mime_types: tuple[str, ...]
1052+
"""The MIME types of the clipboard."""
1053+
1054+
@classmethod
1055+
def _from_sdl_event(cls, sdl_event: _C_SDL_Event) -> Self:
1056+
return cls(
1057+
mime_types=tuple(
1058+
str(ffi.string(sdl_event.clipboard.mime_types[i]), encoding="utf8")
1059+
for i in range(sdl_event.clipboard.num_mime_types)
1060+
),
1061+
**_unpack_sdl_event(sdl_event),
1062+
)
1063+
1064+
10441065
@functools.cache
10451066
def _find_event_name(index: int, /) -> str:
10461067
"""Return the SDL event name for this index."""
@@ -1085,6 +1106,7 @@ def __repr__(self) -> str:
10851106
lib.SDL_EVENT_GAMEPAD_ADDED: ControllerDevice,
10861107
lib.SDL_EVENT_GAMEPAD_REMOVED: ControllerDevice,
10871108
lib.SDL_EVENT_GAMEPAD_REMAPPED: ControllerDevice,
1109+
lib.SDL_EVENT_CLIPBOARD_UPDATE: ClipboardUpdate,
10881110
}
10891111

10901112

0 commit comments

Comments
 (0)