Skip to content

Commit f1f8177

Browse files
committed
Finish adding the feature
1 parent a364e3f commit f1f8177

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

buildconfig/stubs/pygame/display.pyi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ required).
5252
"""
5353

5454
from collections.abc import Iterable
55-
from typing import Literal, Optional, Union, overload
55+
from typing import Literal, Optional, overload
5656

5757
from pygame._sdl2 import Window
5858
from pygame.constants import FULLSCREEN
59+
from pygame.rect import Rect
5960
from pygame.surface import Surface
6061
from pygame.typing import (
6162
ColorLike,
@@ -421,6 +422,24 @@ def get_desktop_sizes() -> list[tuple[int, int]]:
421422
.. versionaddedold:: 2.0.0
422423
"""
423424

425+
def get_desktop_usable_bounds() -> list[Rect]:
426+
"""Get the bounding rects of the usable area of active desktops.
427+
428+
Returns a list of :class:`pygame.Rect` representing the bounding rectangles
429+
of the usable area of the currently configured virtual desktops.
430+
431+
The usable area is the desktop area minus the areas that are used by
432+
the operating system. This includes, for example, taskbars. The location
433+
and size of the unusable areas depend on the operating system and its
434+
configuration. The usable area is usually the area that maximized windows
435+
fill.
436+
437+
The length of the list is not the same as the number of attached monitors,
438+
as a desktop can be mirrored across multiple monitors.
439+
440+
.. versionadded:: 2.5.6
441+
"""
442+
424443
def list_modes(
425444
depth: int = 0,
426445
flags: int = FULLSCREEN,

src_c/display.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,7 @@ static PyObject *
23002300
pg_get_desktop_usable_bounds(PyObject *self, PyObject *_null)
23012301
{
23022302
int display_count, i;
2303+
PyObject *result;
23032304

23042305
VIDEO_INIT_CHECK();
23052306

@@ -3175,6 +3176,8 @@ static PyMethodDef _pg_display_methods[] = {
31753176
METH_NOARGS, "provisional API, subject to change"},
31763177
{"get_desktop_sizes", (PyCFunction)pg_get_desktop_screen_sizes,
31773178
METH_NOARGS, DOC_DISPLAY_GETDESKTOPSIZES},
3179+
{"get_desktop_usable_bounds", (PyCFunction)pg_get_desktop_usable_bounds,
3180+
METH_NOARGS, DOC_DISPLAY_GETDESKTOPUSABLEBOUNDS},
31783181
{"is_fullscreen", (PyCFunction)pg_is_fullscreen, METH_NOARGS,
31793182
DOC_DISPLAY_ISFULLSCREEN},
31803183
{"is_vsync", (PyCFunction)pg_is_vsync, METH_NOARGS, DOC_DISPLAY_ISVSYNC},

src_c/doc/display_doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define DOC_DISPLAY_INFO "Info() -> _VidInfo\nCreate a video display information object."
1212
#define DOC_DISPLAY_GETWMINFO "get_wm_info() -> dict[str, int]\nGet information about the current windowing system."
1313
#define DOC_DISPLAY_GETDESKTOPSIZES "get_desktop_sizes() -> list[tuple[int, int]]\nGet sizes of active desktops."
14+
#define DOC_DISPLAY_GETDESKTOPUSABLEBOUNDS "get_desktop_usable_bounds() -> list[Rect]\nGet the bounding rects of the usable area of active desktops."
1415
#define DOC_DISPLAY_LISTMODES "list_modes(depth=0, flags=FULLSCREEN, display=0) -> list[tuple[int, int]]\nGet list of available fullscreen modes."
1516
#define DOC_DISPLAY_MODEOK "mode_ok(size, flags=0, depth=0, display=0) -> int\nPick the best color depth for a display mode."
1617
#define DOC_DISPLAY_GLGETATTRIBUTE "gl_get_attribute(flag, /) -> int\nGet the value for an OpenGL flag for the current display."

test/display_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,16 @@ def test_get_set_window_position(self):
697697
self.assertEqual(position[0], 420)
698698
self.assertEqual(position[1], 360)
699699

700+
def test_get_desktop_usable_bounds(self):
701+
bounds = pygame.display.get_desktop_usable_bounds()
702+
sizes = pygame.display.get_desktop_sizes()
703+
self.assertIsInstance(bounds, list)
704+
for i, bound in enumerate(bounds):
705+
self.assertIsInstance(bound, pygame.Rect)
706+
size = sizes[i]
707+
self.assertLessEqual(bound.w, size[0])
708+
self.assertLessEqual(bound.h, size[1])
709+
700710

701711
class DisplayUpdateTest(unittest.TestCase):
702712
def question(self, qstr):

0 commit comments

Comments
 (0)