-
-
Notifications
You must be signed in to change notification settings - Fork 201
Add pygame.display.get_desktop_usable_bounds
#3530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@coderabbitai full review |
✅ Actions performedFull review triggered. |
WalkthroughAdded pygame.display.get_desktop_usable_bounds() returning a list of Rects for usable desktop areas. Implemented in C with SDL2/SDL3 paths, exposed in the display module and documented via a new doc macro. Stubs updated and a unit test verifies types and size constraints. Changes
Sequence Diagram(s)sequenceDiagram
participant Py as Python user
participant Mod as pygame.display
participant C as pg_get_desktop_usable_bounds (C)
participant SDL as SDL Video API
Py->>Mod: get_desktop_usable_bounds()
Mod->>C: call (no args)
alt SDL3
C->>SDL: SDL_GetDisplays() / SDL_GetDisplayUsableBounds()
else pre-SDL3
C->>SDL: SDL_GetNumVideoDisplays() / SDL_GetDisplayUsableBounds()
end
SDL-->>C: usable bounds per display
C-->>Mod: list[Rect]
Mod-->>Py: list[Rect]
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Nitpick comments (1)
test/display_test.py (1)
700-709
: Avoid potential IndexError and assert list alignmentIf, for any reason, the two lists differ in length, this loop will raise IndexError. Assert the lengths match and iterate with zip to keep the test robust.
Apply this diff:
def test_get_desktop_usable_bounds(self): bounds = pygame.display.get_desktop_usable_bounds() sizes = pygame.display.get_desktop_sizes() self.assertIsInstance(bounds, list) - for i, bound in enumerate(bounds): - self.assertIsInstance(bound, pygame.Rect) - size = sizes[i] - self.assertLessEqual(bound.w, size[0]) - self.assertLessEqual(bound.h, size[1]) + self.assertEqual(len(bounds), len(sizes)) + for bound, size in zip(bounds, sizes): + self.assertIsInstance(bound, pygame.Rect) + self.assertLessEqual(bound.w, size[0]) + self.assertLessEqual(bound.h, size[1])
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
buildconfig/stubs/pygame/display.pyi
(2 hunks)src_c/display.c
(2 hunks)src_c/doc/display_doc.h
(1 hunks)test/display_test.py
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
test/display_test.py (2)
buildconfig/stubs/pygame/display.pyi (2)
get_desktop_usable_bounds
(425-441)get_desktop_sizes
(406-423)buildconfig/stubs/pygame/rect.pyi (1)
Rect
(303-303)
buildconfig/stubs/pygame/display.pyi (4)
buildconfig/stubs/pygame/typing.pyi (1)
rect
(57-57)src_py/typing.py (1)
rect
(57-57)buildconfig/stubs/typing_sample_app.py (1)
rect
(100-101)buildconfig/stubs/pygame/rect.pyi (1)
Rect
(303-303)
🔇 Additional comments (4)
src_c/doc/display_doc.h (1)
14-14
: Doc macro addition LGTMThe new macro name and summary align with existing patterns and the API behavior.
buildconfig/stubs/pygame/display.pyi (2)
425-442
: Stub signature and docstring LGTMReturn type list[Rect] matches runtime objects. The docstring mirrors the new API semantics and version tag is present.
55-55
: No Union usage detected – import removal is safe
- buildconfig/stubs/pygame/display.pyi: scanned for “Union” with ripgrep; no occurrences found.
src_c/display.c (1)
3179-3181
: Method registration LGTMCorrectly registered with METH_NOARGS and linked to the doc macro.
This could be used to implement "Do what I mean" window sizing when passing in (0,0) for windowed mode. I always hated how windowed mode overlaps with the task bar in that case! |
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, LGTM 👍 Seems like it could be useful for application positioning especially with things like no frame windows.
As I said on discord,
pygame.display.get_desktop_sizes
exist but doesn't take in consideration the taskbar or any other OS reserved space. The SDL function for it exists, so it makes sense to me to add it to display. It would be very tedious to do this in python cross platform without it. It's a differnt function from the sizes because it returns rects, but the return list uses the same logic so with the same index you get the full size and usable area for the same desktop. Also, it's alredy SDL3 compatible, so there will be no problems when display is ported. There is no conflict with window because this is one of the features that make sense for display, and doesn't concert any windows (display should only hold this functions)Summary by CodeRabbit
New Features
Documentation
Tests