Skip to content

Commit a364e3f

Browse files
committed
Add c code
1 parent a6db5c7 commit a364e3f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src_c/display.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,51 @@ pg_get_desktop_screen_sizes(PyObject *self, PyObject *_null)
22962296
return result;
22972297
}
22982298

2299+
static PyObject *
2300+
pg_get_desktop_usable_bounds(PyObject *self, PyObject *_null)
2301+
{
2302+
int display_count, i;
2303+
2304+
VIDEO_INIT_CHECK();
2305+
2306+
#if PG_SDL3
2307+
SDL_DisplayID *displays = SDL_GetDisplays(&display_count);
2308+
if (displays == NULL) {
2309+
return RAISE(pgExc_SDLError, SDL_GetError());
2310+
}
2311+
#else
2312+
display_count = SDL_GetNumVideoDisplays();
2313+
if (display_count < 0) {
2314+
return RAISE(pgExc_SDLError, SDL_GetError());
2315+
}
2316+
#endif
2317+
2318+
result = PyList_New(display_count);
2319+
if (!result) {
2320+
return NULL;
2321+
}
2322+
2323+
for (i = 0; i < display_count; i++) {
2324+
SDL_Rect bounds;
2325+
#if PG_SDL3
2326+
SDL_DisplayID display_id = displays[i];
2327+
if (SDL_GetDisplayUsableBounds(display_id, &bounds) == SDL_FALSE) {
2328+
return RAISE(pgExc_SDLError, SDL_GetError());
2329+
}
2330+
#else
2331+
if (SDL_GetDisplayUsableBounds(i, &bounds) < 0) {
2332+
return RAISE(pgExc_SDLError, SDL_GetError());
2333+
}
2334+
#endif
2335+
PyObject *pg_rect = pgRect_New(&bounds);
2336+
if (pg_rect == NULL) {
2337+
return NULL; /* exception already set */
2338+
}
2339+
PyList_SET_ITEM(result, i, pg_rect);
2340+
}
2341+
return result;
2342+
}
2343+
22992344
static PyObject *
23002345
pg_is_fullscreen(PyObject *self, PyObject *_null)
23012346
{

0 commit comments

Comments
 (0)