Skip to content

Commit 64bcb02

Browse files
committed
Add which and window_id attribute for mouse events
1 parent 3b33302 commit 64bcb02

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
1515
- `Drop` event.
1616
- `KeyboardEvent.pressed`, `KeyboardEvent.which`, `KeyboardEvent.window_id` attributes.
1717
- `WindowEvent.data` and `WindowEvent.window_id` attributes and added missing SDL3 window events.
18+
- `which` and `window_id` attributes for mouse events.
1819

1920
### Changed
2021

tcod/event.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,18 @@ class MouseState(Event):
446446
state: MouseButtonMask = attrs.field(default=MouseButtonMask(0))
447447
"""A bitmask of which mouse buttons are currently held."""
448448

449+
which: int = 0
450+
"""The mouse device ID for this event.
451+
452+
..versionadded:: Unreleased
453+
"""
454+
455+
window_id: int = 0
456+
"""The window ID with mouse focus.
457+
458+
..versionadded:: Unreleased
459+
"""
460+
449461
@property
450462
def integer_position(self) -> Point[int]:
451463
"""Integer coordinates of this event.
@@ -547,6 +559,7 @@ def tile_motion(self, xy: tuple[int, int]) -> None:
547559
@classmethod
548560
def _from_sdl_event(cls, sdl_event: _C_SDL_Event) -> Self:
549561
motion = sdl_event.motion
562+
common = {"which": int(motion.which), "window_id": int(motion.windowID)}
550563
state = MouseButtonMask(motion.state)
551564

552565
pixel = Point(float(motion.x), float(motion.y))
@@ -559,6 +572,7 @@ def _from_sdl_event(cls, sdl_event: _C_SDL_Event) -> Self:
559572
tile=None,
560573
tile_motion=None,
561574
state=state,
575+
**common,
562576
**_unpack_sdl_event(sdl_event),
563577
)
564578
else:
@@ -573,6 +587,7 @@ def _from_sdl_event(cls, sdl_event: _C_SDL_Event) -> Self:
573587
tile=tile,
574588
tile_motion=tile_motion,
575589
state=state,
590+
**common,
576591
**_unpack_sdl_event(sdl_event),
577592
)
578593
self.sdl_event = sdl_event
@@ -601,6 +616,18 @@ class MouseButtonEvent(Event):
601616
Is now strictly a :any:`MouseButton` type.
602617
"""
603618

619+
which: int = 0
620+
"""The mouse device ID for this event.
621+
622+
..versionadded:: Unreleased
623+
"""
624+
625+
window_id: int = 0
626+
"""The window ID with mouse focus.
627+
628+
..versionadded:: Unreleased
629+
"""
630+
604631
@classmethod
605632
def _from_sdl_event(cls, sdl_event: _C_SDL_Event) -> Self:
606633
button = sdl_event.button
@@ -610,7 +637,14 @@ def _from_sdl_event(cls, sdl_event: _C_SDL_Event) -> Self:
610637
tile: Point[int] | None = None
611638
else:
612639
tile = Point(floor(subtile[0]), floor(subtile[1]))
613-
self = cls(position=pixel, tile=tile, button=MouseButton(button.button), **_unpack_sdl_event(sdl_event))
640+
self = cls(
641+
position=pixel,
642+
tile=tile,
643+
button=MouseButton(button.button),
644+
which=int(button.which),
645+
window_id=int(button.windowID),
646+
**_unpack_sdl_event(sdl_event),
647+
)
614648
self.sdl_event = sdl_event
615649
return self
616650

0 commit comments

Comments
 (0)