@@ -279,7 +279,11 @@ pg_get_init(PyObject *self, PyObject *_null)
279
279
static PyObject *
280
280
pg_get_active (PyObject * self , PyObject * _null )
281
281
{
282
- SDL_WindowFlags flags = SDL_GetWindowFlags (pg_GetDefaultWindow ());
282
+ SDL_Window * win = pg_GetDefaultWindow ();
283
+ if (!win ) {
284
+ Py_RETURN_FALSE ;
285
+ }
286
+ SDL_WindowFlags flags = SDL_GetWindowFlags (win );
283
287
284
288
#if SDL_VERSION_ATLEAST (3 , 0 , 0 )
285
289
return PyBool_FromLong (!(flags & SDL_WINDOW_HIDDEN ) &&
@@ -460,7 +464,12 @@ pg_GetVideoInfo(pg_VideoInfo *info)
460
464
}
461
465
else {
462
466
#if SDL_VERSION_ATLEAST (3 , 0 , 0 )
463
- if ((mode_ptr = SDL_GetCurrentDisplayMode (0 ))) {
467
+ SDL_DisplayID primary_display = SDL_GetPrimaryDisplay ();
468
+ if (primary_display == 0 ) {
469
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
470
+ return (pg_VideoInfo * )NULL ;
471
+ }
472
+ if ((mode_ptr = SDL_GetCurrentDisplayMode (primary_display ))) {
464
473
info -> current_w = mode_ptr -> w ;
465
474
info -> current_h = mode_ptr -> h ;
466
475
formatenum = mode_ptr -> format ;
@@ -1118,12 +1127,12 @@ PG_CreateWindowCompat(const char *title, int x, int y, int w, int h,
1118
1127
}
1119
1128
1120
1129
#if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1121
- /* Returns 0 on success, negative on failure. */
1122
- static int
1130
+ /* Returns true on success, false on failure. */
1131
+ static bool
1123
1132
PG_SetWindowFullscreen (SDL_Window * window , bool fullscreen ,
1124
1133
bool non_desktop_fullscreen )
1125
1134
{
1126
- int ret = -1 ;
1135
+ bool ret = false ;
1127
1136
SDL_DisplayMode * * modes = NULL ;
1128
1137
SDL_DisplayMode * chosen_mode = NULL ;
1129
1138
if (!SDL_SetWindowFullscreen (window , fullscreen )) {
@@ -1152,11 +1161,24 @@ PG_SetWindowFullscreen(SDL_Window *window, bool fullscreen,
1152
1161
}
1153
1162
}
1154
1163
1155
- ret = 0 ;
1164
+ SDL_SyncWindow (window );
1165
+ ret = true;
1156
1166
end :
1157
1167
SDL_free (modes );
1158
1168
return ret ;
1159
1169
}
1170
+ #else
1171
+ static bool
1172
+ PG_SetWindowFullscreen (SDL_Window * window , bool fullscreen ,
1173
+ bool non_desktop_fullscreen )
1174
+ {
1175
+ int flags = 0 ;
1176
+ if (fullscreen ) {
1177
+ flags = non_desktop_fullscreen ? SDL_WINDOW_FULLSCREEN
1178
+ : SDL_WINDOW_FULLSCREEN_DESKTOP ;
1179
+ }
1180
+ return (SDL_SetWindowFullscreen (window , flags ) == 0 ) ? true : false;
1181
+ }
1160
1182
#endif
1161
1183
1162
1184
static PyObject *
@@ -1235,6 +1257,16 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1235
1257
}
1236
1258
}
1237
1259
1260
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1261
+ /* In SDL2, display == 0 meant primary display, so compat code for it */
1262
+ if (display == 0 ) {
1263
+ display = SDL_GetPrimaryDisplay ();
1264
+ if (display == 0 ) {
1265
+ return RAISE (pgExc_SDLError , SDL_GetError ());
1266
+ }
1267
+ }
1268
+ #endif
1269
+
1238
1270
if ((vsync == -1 ) && ((flags & PGS_OPENGL ) == 0 )) {
1239
1271
return RAISE (PyExc_ValueError ,
1240
1272
"requested adaptive vsync without OpenGL" );
@@ -1437,11 +1469,16 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1437
1469
if (flags & PGS_SCALED && !(flags & PGS_FULLSCREEN )) {
1438
1470
SDL_Rect display_bounds ;
1439
1471
int fractional_scaling = SDL_FALSE ;
1440
-
1472
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1473
+ if (!SDL_GetDisplayUsableBounds (display , & display_bounds )) {
1474
+ return RAISE (pgExc_SDLError , SDL_GetError ());
1475
+ }
1476
+ #else
1441
1477
if (0 !=
1442
1478
SDL_GetDisplayUsableBounds (display , & display_bounds )) {
1443
1479
return RAISE (pgExc_SDLError , SDL_GetError ());
1444
1480
}
1481
+ #endif
1445
1482
1446
1483
if (SDL_GetHintBoolean ("SDL_HINT_RENDER_SCALE_QUALITY" ,
1447
1484
SDL_FALSE )) {
@@ -1592,7 +1629,7 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1592
1629
vsync to be always on or always off, or vsync is on by default
1593
1630
for the whole desktop because of wayland GL compositing. */
1594
1631
if (vsync == -1 ) {
1595
- if (SDL_GL_SetSwapInterval (-1 ) != 0 ) {
1632
+ if (! PG_GL_SetSwapInterval (-1 )) {
1596
1633
PyErr_SetString (pgExc_SDLError ,
1597
1634
"adaptive vsync for OpenGL not "
1598
1635
"available" );
@@ -1602,7 +1639,7 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1602
1639
}
1603
1640
}
1604
1641
else if (vsync == 1 ) {
1605
- if (SDL_GL_SetSwapInterval (1 ) != 0 ) {
1642
+ if (! PG_GL_SetSwapInterval (1 )) {
1606
1643
PyErr_SetString (pgExc_SDLError ,
1607
1644
"regular vsync for OpenGL not "
1608
1645
"available" );
@@ -1611,7 +1648,7 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1611
1648
}
1612
1649
}
1613
1650
else {
1614
- SDL_GL_SetSwapInterval (0 );
1651
+ PG_GL_SetSwapInterval (0 );
1615
1652
}
1616
1653
}
1617
1654
else {
@@ -1849,6 +1886,9 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1849
1886
}
1850
1887
}
1851
1888
}
1889
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1890
+ SDL_SyncWindow (win );
1891
+ #endif
1852
1892
1853
1893
/*return the window's surface (screen)*/
1854
1894
Py_INCREF (surface );
@@ -1947,6 +1987,9 @@ pg_set_window_position(PyObject *self, PyObject *arg)
1947
1987
if (win ) {
1948
1988
/* Will raise errors with SDL 3, deal with it during the porting */
1949
1989
SDL_SetWindowPosition (win , x , y );
1990
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1991
+ SDL_SyncWindow (win );
1992
+ #endif
1950
1993
}
1951
1994
1952
1995
Py_RETURN_NONE ;
@@ -1973,7 +2016,16 @@ pg_mode_ok(PyObject *self, PyObject *args, PyObject *kwds)
1973
2016
& display_index )) {
1974
2017
return NULL ;
1975
2018
}
1976
- #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
2019
+
2020
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2021
+ /* In SDL2, display == 0 meant primary display, so compat code for it */
2022
+ if (display_index == 0 ) {
2023
+ display_index = SDL_GetPrimaryDisplay ();
2024
+ if (display_index == 0 ) {
2025
+ return RAISE (pgExc_SDLError , SDL_GetError ());
2026
+ }
2027
+ }
2028
+ #else
1977
2029
/* Display ID is not bounded by number of displays in SDL3 */
1978
2030
if (display_index < 0 || display_index >= SDL_GetNumVideoDisplays ()) {
1979
2031
return RAISE (PyExc_ValueError ,
@@ -2039,7 +2091,15 @@ pg_list_modes(PyObject *self, PyObject *args, PyObject *kwds)
2039
2091
return NULL ;
2040
2092
}
2041
2093
2042
- #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
2094
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2095
+ /* In SDL2, display == 0 meant primary display, so compat code for it */
2096
+ if (display_index == 0 ) {
2097
+ display_index = SDL_GetPrimaryDisplay ();
2098
+ if (display_index == 0 ) {
2099
+ return RAISE (pgExc_SDLError , SDL_GetError ());
2100
+ }
2101
+ }
2102
+ #else
2043
2103
/* Display ID is not bounded by number of displays in SDL3 */
2044
2104
if (display_index < 0 || display_index >= SDL_GetNumVideoDisplays ()) {
2045
2105
return RAISE (PyExc_ValueError ,
@@ -2700,6 +2760,9 @@ pg_iconify(PyObject *self, PyObject *_null)
2700
2760
return RAISE (pgExc_SDLError , "No open window" );
2701
2761
}
2702
2762
SDL_MinimizeWindow (win );
2763
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2764
+ SDL_SyncWindow (win );
2765
+ #endif
2703
2766
return PyBool_FromLong (1 );
2704
2767
}
2705
2768
@@ -3035,7 +3098,6 @@ static PyObject *
3035
3098
pg_toggle_fullscreen (PyObject * self , PyObject * _null )
3036
3099
{
3037
3100
SDL_Window * win = pg_GetDefaultWindow ();
3038
- int result ;
3039
3101
SDL_WindowFlags flags ;
3040
3102
int window_w , window_h , w , h , window_display , x , y ;
3041
3103
pgSurfaceObject * display_surface ;
@@ -3164,8 +3226,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3164
3226
/* TOGGLE FULLSCREEN OFF */
3165
3227
3166
3228
if (state -> unscaled_render ) {
3167
- result = SDL_SetWindowFullscreen (win , 0 );
3168
- if (result != 0 ) {
3229
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3169
3230
return RAISE (pgExc_SDLError , SDL_GetError ());
3170
3231
}
3171
3232
}
@@ -3179,8 +3240,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3179
3240
if (scale < 1 ) {
3180
3241
scale = 1 ;
3181
3242
}
3182
- result = SDL_SetWindowFullscreen (win , 0 );
3183
- if (result != 0 ) {
3243
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3184
3244
return RAISE (pgExc_SDLError , SDL_GetError ());
3185
3245
}
3186
3246
SDL_SetWindowSize (win , w * scale , h * scale );
@@ -3220,8 +3280,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3220
3280
/* this is literally the only place where state->toggle_windowed_w
3221
3281
* should ever be read. We only use it because with GL, there is no
3222
3282
* display surface we can query for dimensions. */
3223
- result = SDL_SetWindowFullscreen (win , 0 );
3224
- if (result != 0 ) {
3283
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3225
3284
return RAISE (pgExc_SDLError , SDL_GetError ());
3226
3285
}
3227
3286
SDL_GL_MakeCurrent (win , state -> gl_context );
@@ -3257,8 +3316,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3257
3316
else if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) ==
3258
3317
SDL_WINDOW_FULLSCREEN_DESKTOP ) {
3259
3318
#endif
3260
- result = SDL_SetWindowFullscreen (win , 0 );
3261
- if (result != 0 ) {
3319
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3262
3320
return RAISE (pgExc_SDLError , SDL_GetError ());
3263
3321
}
3264
3322
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3287,15 +3345,11 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3287
3345
if (win == NULL ) {
3288
3346
return RAISE (pgExc_SDLError , SDL_GetError ());
3289
3347
}
3290
- else {
3291
- result = 0 ;
3292
- }
3293
3348
display_surface -> surf = SDL_GetWindowSurface (win );
3294
3349
pg_SetDefaultWindow (win );
3295
3350
}
3296
3351
else {
3297
- result = SDL_SetWindowFullscreen (win , 0 );
3298
- if (result != 0 ) {
3352
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3299
3353
return RAISE (pgExc_SDLError , SDL_GetError ());
3300
3354
}
3301
3355
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3330,24 +3384,12 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3330
3384
state -> fullscreen_backup_y = y ;
3331
3385
3332
3386
if (state -> unscaled_render ) {
3333
- #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3334
- result = PG_SetWindowFullscreen (win , 1 , 0 );
3335
- #else
3336
- result =
3337
- SDL_SetWindowFullscreen (win , SDL_WINDOW_FULLSCREEN_DESKTOP );
3338
- #endif
3339
- if (result != 0 ) {
3387
+ if (!PG_SetWindowFullscreen (win , 1 , 0 )) {
3340
3388
return RAISE (pgExc_SDLError , SDL_GetError ());
3341
3389
}
3342
3390
}
3343
3391
else if (pg_renderer != NULL ) {
3344
- #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3345
- result = PG_SetWindowFullscreen (win , 1 , 0 );
3346
- #else
3347
- result =
3348
- SDL_SetWindowFullscreen (win , SDL_WINDOW_FULLSCREEN_DESKTOP );
3349
- #endif
3350
- if (result != 0 ) {
3392
+ if (!PG_SetWindowFullscreen (win , 1 , 0 )) {
3351
3393
return RAISE (pgExc_SDLError , SDL_GetError ());
3352
3394
}
3353
3395
if (is_renderer_software && subsystem == SDL_SYSWM_X11 ) {
@@ -3380,13 +3422,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3380
3422
#endif
3381
3423
}
3382
3424
else if (state -> using_gl ) {
3383
- #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3384
- result = PG_SetWindowFullscreen (win , 1 , 0 );
3385
- #else
3386
- result =
3387
- SDL_SetWindowFullscreen (win , SDL_WINDOW_FULLSCREEN_DESKTOP );
3388
- #endif
3389
- if (result != 0 ) {
3425
+ if (!PG_SetWindowFullscreen (win , 1 , 0 )) {
3390
3426
return RAISE (pgExc_SDLError , SDL_GetError ());
3391
3427
}
3392
3428
SDL_GL_MakeCurrent (win , state -> gl_context );
@@ -3411,13 +3447,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3411
3447
}
3412
3448
}
3413
3449
else if (w == display_mode -> w && h == display_mode -> h ) {
3414
- #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3415
- result = PG_SetWindowFullscreen (win , 1 , 0 );
3416
- #else
3417
- result =
3418
- SDL_SetWindowFullscreen (win , SDL_WINDOW_FULLSCREEN_DESKTOP );
3419
- #endif
3420
- if (result != 0 ) {
3450
+ if (!PG_SetWindowFullscreen (win , 1 , 0 )) {
3421
3451
return RAISE (pgExc_SDLError , SDL_GetError ());
3422
3452
}
3423
3453
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3434,8 +3464,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3434
3464
return PyLong_FromLong (-1 );
3435
3465
}
3436
3466
else {
3437
- result = SDL_SetWindowFullscreen (win , SDL_WINDOW_FULLSCREEN );
3438
- if (result != 0 ) {
3467
+ if (!PG_SetWindowFullscreen (win , 1 , 1 )) {
3439
3468
return RAISE (pgExc_SDLError , SDL_GetError ());
3440
3469
}
3441
3470
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3447,7 +3476,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3447
3476
if (win == NULL ) {
3448
3477
return RAISE (pgExc_SDLError , SDL_GetError ());
3449
3478
}
3450
- if (0 != SDL_SetWindowFullscreen (win , SDL_WINDOW_FULLSCREEN )) {
3479
+ if (! PG_SetWindowFullscreen (win , 1 , 1 )) {
3451
3480
return RAISE (pgExc_SDLError , SDL_GetError ());
3452
3481
}
3453
3482
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3461,7 +3490,10 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3461
3490
}
3462
3491
}
3463
3492
}
3464
- return PyLong_FromLong (result != 0 );
3493
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3494
+ SDL_SyncWindow (win );
3495
+ #endif
3496
+ return PyLong_FromLong (1 );
3465
3497
}
3466
3498
3467
3499
/* This API is provisional, and, not finalised, and should not be documented
@@ -3539,6 +3571,9 @@ pg_display_resize_event(PyObject *self, PyObject *event)
3539
3571
/* do not do anything that would invalidate a display surface! */
3540
3572
return PyLong_FromLong (-1 );
3541
3573
}
3574
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3575
+ SDL_SyncWindow (win );
3576
+ #endif
3542
3577
Py_RETURN_FALSE ;
3543
3578
}
3544
3579
@@ -3771,7 +3806,11 @@ pg_message_box(PyObject *self, PyObject *arg, PyObject *kwargs)
3771
3806
3772
3807
int clicked_button_id ;
3773
3808
3809
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3810
+ if (!SDL_ShowMessageBox (& msgbox_data , & clicked_button_id )) {
3811
+ #else
3774
3812
if (SDL_ShowMessageBox (& msgbox_data , & clicked_button_id )) {
3813
+ #endif
3775
3814
PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3776
3815
goto error ;
3777
3816
}
0 commit comments