Skip to content

pos attribute added to MOUSEWHEEL event#3783

Merged
damusss merged 8 commits into
pygame-community:mainfrom
DickerDackel:mousewheelpos
May 17, 2026
Merged

pos attribute added to MOUSEWHEEL event#3783
damusss merged 8 commits into
pygame-community:mainfrom
DickerDackel:mousewheelpos

Conversation

@DickerDackel
Copy link
Copy Markdown
Contributor

@DickerDackel DickerDackel commented Apr 29, 2026

Up to now, if the position where a MOUSEWHEEL event happends is required, a user has to either fall back on the additionally created MOUSEBUTTON events, or poll the mouse position manually.

Position information in the MOUSEWHEEL event was added with SDL 2.0.26. In case pygame was built with an SDL version older than 2.0.26, the pos value will be None.

Position information in the MOUSEWHEEL event was added with SDL 2.0.26.
In case pygame was built with an SDL version older than 2.0.26, the
`pos` value will be `(0, 0)`.
@DickerDackel DickerDackel requested a review from a team as a code owner April 29, 2026 12:10
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough
📝 Walkthrough
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a pos attribute to MOUSEWHEEL events, which is the primary focus of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the change: adding a pos attribute to MOUSEWHEEL events, the rationale (users previously needed workarounds), and the SDL version dependency with fallback behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/reST/ref/event.rst`:
- Around line 163-164: Replace the awkward phrase in the MOUSEWHEEL note so it
clearly ties the fallback to the SDL build: update the sentence referencing the
``MOUSEWHEEL`` event and its ``pos`` attribute to say that if pygame was built
against an older SDL version (pre-2.0.26) the ``pos`` attribute will be ``(0,
0)``; ensure the words “built against an older SDL version (pre-2.0.26)” replace
“was build on a version lower than that” to remove ambiguity.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3079e045-217a-48af-978a-6671418afc99

📥 Commits

Reviewing files that changed from the base of the PR and between bf1bf82 and a6a4f3e.

📒 Files selected for processing (2)
  • docs/reST/ref/event.rst
  • src_c/event.c

Comment thread docs/reST/ref/event.rst Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
docs/reST/ref/event.rst (1)

163-165: ⚠️ Potential issue | 🟡 Minor

Polish footnote wording for clarity and grammar.

Please change “was build on a version lower than that” to “was built against an older SDL version” and fix punctuation/spacing after “SDL 2.26.0”.

Suggested diff
-(``5``): Position information was added to ``MOUSEWHEEL`` events in SDL 2.26.0  If
-pygame was build on a version lower than that, the ``pos`` attribute is ``(0, 0)``.
+(``5``): Position information was added to ``MOUSEWHEEL`` events in SDL 2.26.0. If
+pygame was built against an older SDL version, the ``pos`` attribute is ``(0, 0)``.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/reST/ref/event.rst` around lines 163 - 165, Update the footnote text
labeled "(``5``): Position information was added to ``MOUSEWHEEL`` events in SDL
2.26.0  If pygame was build on a version lower than that, the ``pos`` attribute
is ``(0, 0)``." — change “was build on a version lower than that” to “was built
against an older SDL version” and fix the punctuation/spacing after “SDL 2.26.0”
so it reads “…SDL 2.26.0. If pygame was built against an older SDL version, the
``pos`` attribute is ``(0, 0)``.” Ensure the footnote text with marker (``5``)
is updated exactly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@docs/reST/ref/event.rst`:
- Around line 163-165: Update the footnote text labeled "(``5``): Position
information was added to ``MOUSEWHEEL`` events in SDL 2.26.0  If pygame was
build on a version lower than that, the ``pos`` attribute is ``(0, 0)``." —
change “was build on a version lower than that” to “was built against an older
SDL version” and fix the punctuation/spacing after “SDL 2.26.0” so it reads
“…SDL 2.26.0. If pygame was built against an older SDL version, the ``pos``
attribute is ``(0, 0)``.” Ensure the footnote text with marker (``5``) is
updated exactly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8c5c06be-b377-413d-84ae-be0e29ea4a19

📥 Commits

Reviewing files that changed from the base of the PR and between a6a4f3e and 1fc7868.

📒 Files selected for processing (2)
  • docs/reST/ref/event.rst
  • src_c/event.c
✅ Files skipped from review due to trivial changes (1)
  • src_c/event.c

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src_c/event.c (1)

1383-1393: Add regression tests for MOUSEWHEEL.pos to lock API behavior.

This introduces a new public attribute, but current test context shows no dedicated attribute-level MOUSEWHEEL test. Please add coverage for both populated pos and the (0, 0) fallback path.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src_c/event.c` around lines 1383 - 1393, Add unit tests that verify the new
public attribute MOUSEWHEEL.pos returns the expected tuple when the SDL wheel
fields are present and also returns (0, 0) when those fields are absent;
specifically, create tests that simulate an event with event->wheel.mouse_x /
event->wheel.mouseX values and assert MOUSEWHEEL.pos equals that pair (to
exercise the pg_tuple_couple_from_values_int branch), and a separate test that
simulates the older SDL path where the code hits the fallback branch and assert
MOUSEWHEEL.pos == (0, 0). Ensure tests exercise both SDL_VERSION_ATLEAST(3,0,0)
and the else fallback behavior (or mock the event fields directly) so the API
behavior is locked.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src_c/event.c`:
- Around line 1383-1393: Add unit tests that verify the new public attribute
MOUSEWHEEL.pos returns the expected tuple when the SDL wheel fields are present
and also returns (0, 0) when those fields are absent; specifically, create tests
that simulate an event with event->wheel.mouse_x / event->wheel.mouseX values
and assert MOUSEWHEEL.pos equals that pair (to exercise the
pg_tuple_couple_from_values_int branch), and a separate test that simulates the
older SDL path where the code hits the fallback branch and assert MOUSEWHEEL.pos
== (0, 0). Ensure tests exercise both SDL_VERSION_ATLEAST(3,0,0) and the else
fallback behavior (or mock the event fields directly) so the API behavior is
locked.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 21975845-ff3d-47bf-a3b5-b63b8c0526d9

📥 Commits

Reviewing files that changed from the base of the PR and between fe848a5 and 3180e5e.

📒 Files selected for processing (1)
  • src_c/event.c

Comment thread src_c/event.c Outdated
Copy link
Copy Markdown
Member

@oddbookworm oddbookworm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one definitely actionable comment, and one I would like to see justified if behavior is correct, or adjusted if incorrect

Comment thread src_c/event.c
Comment thread docs/reST/ref/event.rst Outdated
@Starbuck5 Starbuck5 added New API This pull request may need extra debate as it adds a new class or function to pygame event pygame.event labels May 3, 2026
Copy link
Copy Markdown
Member

@oddbookworm oddbookworm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks Dackel! 🎉

Copy link
Copy Markdown
Member

@Starbuck5 Starbuck5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Copy Markdown
Member

@damusss damusss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pointed out a few typos, but other than that, it looks good to me, thank you!

Comment thread docs/reST/ref/event.rst Outdated
@damusss damusss added this to the 2.5.8 milestone May 17, 2026
@damusss damusss merged commit d999e34 into pygame-community:main May 17, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event pygame.event New API This pull request may need extra debate as it adds a new class or function to pygame

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants