Skip to content

Conversation

damusss
Copy link
Member

@damusss damusss commented Jul 13, 2025

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

    • Added get_desktop_usable_bounds() to retrieve usable desktop areas (excluding taskbars/docks) as a list of Rects.
    • Returns usable bounds per configured virtual desktop; count may differ from attached monitors and supports multi-monitor mirroring.
  • Documentation

    • Added API docs describing signature and behavior of get_desktop_usable_bounds().
  • Tests

    • Added tests validating returned Rects and that each bound does not exceed corresponding desktop sizes.

@damusss damusss requested a review from a team as a code owner July 13, 2025 07:49
@damusss damusss added New API This pull request may need extra debate as it adds a new class or function to pygame display pygame.display labels Jul 13, 2025
@ankith26
Copy link
Member

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

Walkthrough

Added 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

Cohort / File(s) Summary
Stub typings
buildconfig/stubs/pygame/display.pyi
Declares get_desktop_usable_bounds() -> list[Rect]; adds from pygame.rect import Rect; removes Union from typing imports; places declaration after get_desktop_sizes.
C display module
src_c/display.c
Adds pg_get_desktop_usable_bounds (SDL3 and pre-SDL3 paths) that gathers usable display bounds, converts them to Rect objects, returns a Python list; registers method in _pg_display_methods with DOC_DISPLAY_GETDESKTOPUSABLEBOUNDS.
Docs macro
src_c/doc/display_doc.h
Adds DOC_DISPLAY_GETDESKTOPUSABLEBOUNDS documenting the new function signature and purpose.
Tests
test/display_test.py
Adds test_get_desktop_usable_bounds asserting the result is a list of pygame.Rect and each rect's width/height do not exceed corresponding get_desktop_sizes() values.

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]
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

I mapped the screens where windows hop,
Found cozy bounds where menus stop.
Rects lined up in tidy rows,
Where taskbars end and free space grows.
I thump my paw — new API glows. 🐇✨

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 details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f1f8177 and 0cc2c49.

📒 Files selected for processing (1)
  • src_c/display.c (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src_c/display.c
⏰ 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)
  • GitHub Check: arm64
  • GitHub Check: debug_coverage (ubuntu-24.04, 3.13.5)
  • GitHub Check: dev-check
  • GitHub Check: build (ubuntu-22.04)
  • GitHub Check: msys2 (clang64, clang-x86_64)
  • GitHub Check: msys2 (mingw64, x86_64)
  • GitHub Check: msys2 (ucrt64, ucrt-x86_64)
  • GitHub Check: debug_coverage (ubuntu-24.04, 3.9.23)
  • GitHub Check: Debian (Bookworm - 12) [armv7]
  • GitHub Check: debug_coverage (ubuntu-24.04, 3.14.0rc1)
  • GitHub Check: Debian (Bookworm - 12) [s390x]
  • GitHub Check: AMD64
  • GitHub Check: Debian (Bookworm - 12) [ppc64le]
  • GitHub Check: Debian (Bookworm - 12) [armv6]
  • GitHub Check: aarch64
  • GitHub Check: i686
  • GitHub Check: build (ubuntu-24.04)
  • GitHub Check: build (macos-14)
  • GitHub Check: x86_64
  • GitHub Check: x86
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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

🧹 Nitpick comments (1)
test/display_test.py (1)

700-709: Avoid potential IndexError and assert list alignment

If, 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

📥 Commits

Reviewing files that changed from the base of the PR and between a6db5c7 and f1f8177.

📒 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 LGTM

The 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 LGTM

Return 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 LGTM

Correctly registered with METH_NOARGS and linked to the doc macro.

@robertpfeiffer
Copy link
Contributor

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>
Copy link
Member

@MyreMylar MyreMylar left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display pygame.display 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.

Add pygame.display.get_desktop_workarea() to retrieve usable display bounds (excluding taskbar / Dock)
4 participants