@@ -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,28 @@ PG_SetWindowFullscreen(SDL_Window *window, bool fullscreen,
1152
1161
}
1153
1162
}
1154
1163
1155
- ret = 0 ;
1164
+ /* Try to sync window here.
1165
+ * TODO: this call seems to error a lot, so for now skip error handling.
1166
+ * Possibly related issue: https://github.com/libsdl-org/SDL/issues/11239
1167
+ */
1168
+ SDL_SyncWindow (window );
1169
+ ret = true;
1156
1170
end :
1157
1171
SDL_free (modes );
1158
1172
return ret ;
1159
1173
}
1174
+ #else
1175
+ static bool
1176
+ PG_SetWindowFullscreen (SDL_Window * window , bool fullscreen ,
1177
+ bool non_desktop_fullscreen )
1178
+ {
1179
+ int flags = 0 ;
1180
+ if (fullscreen ) {
1181
+ flags = non_desktop_fullscreen ? SDL_WINDOW_FULLSCREEN
1182
+ : SDL_WINDOW_FULLSCREEN_DESKTOP ;
1183
+ }
1184
+ return (SDL_SetWindowFullscreen (window , flags ) == 0 ) ? true : false;
1185
+ }
1160
1186
#endif
1161
1187
1162
1188
static PyObject *
@@ -1235,6 +1261,16 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1235
1261
}
1236
1262
}
1237
1263
1264
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1265
+ /* In SDL2, display == 0 meant primary display, so compat code for it */
1266
+ if (display == 0 ) {
1267
+ display = SDL_GetPrimaryDisplay ();
1268
+ if (display == 0 ) {
1269
+ return RAISE (pgExc_SDLError , SDL_GetError ());
1270
+ }
1271
+ }
1272
+ #endif
1273
+
1238
1274
if ((vsync == -1 ) && ((flags & PGS_OPENGL ) == 0 )) {
1239
1275
return RAISE (PyExc_ValueError ,
1240
1276
"requested adaptive vsync without OpenGL" );
@@ -1437,11 +1473,16 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1437
1473
if (flags & PGS_SCALED && !(flags & PGS_FULLSCREEN )) {
1438
1474
SDL_Rect display_bounds ;
1439
1475
int fractional_scaling = SDL_FALSE ;
1440
-
1476
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1477
+ if (!SDL_GetDisplayUsableBounds (display , & display_bounds )) {
1478
+ return RAISE (pgExc_SDLError , SDL_GetError ());
1479
+ }
1480
+ #else
1441
1481
if (0 !=
1442
1482
SDL_GetDisplayUsableBounds (display , & display_bounds )) {
1443
1483
return RAISE (pgExc_SDLError , SDL_GetError ());
1444
1484
}
1485
+ #endif
1445
1486
1446
1487
if (SDL_GetHintBoolean ("SDL_HINT_RENDER_SCALE_QUALITY" ,
1447
1488
SDL_FALSE )) {
@@ -1849,6 +1890,11 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1849
1890
}
1850
1891
}
1851
1892
}
1893
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1894
+ if (!SDL_SyncWindow (win )) {
1895
+ return RAISE (pgExc_SDLError , SDL_GetError ());
1896
+ }
1897
+ #endif
1852
1898
1853
1899
/*return the window's surface (screen)*/
1854
1900
Py_INCREF (surface );
@@ -1947,6 +1993,11 @@ pg_set_window_position(PyObject *self, PyObject *arg)
1947
1993
if (win ) {
1948
1994
/* Will raise errors with SDL 3, deal with it during the porting */
1949
1995
SDL_SetWindowPosition (win , x , y );
1996
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1997
+ if (!SDL_SyncWindow (win )) {
1998
+ return RAISE (pgExc_SDLError , SDL_GetError ());
1999
+ }
2000
+ #endif
1950
2001
}
1951
2002
1952
2003
Py_RETURN_NONE ;
@@ -1973,7 +2024,16 @@ pg_mode_ok(PyObject *self, PyObject *args, PyObject *kwds)
1973
2024
& display_index )) {
1974
2025
return NULL ;
1975
2026
}
1976
- #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
2027
+
2028
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2029
+ /* In SDL2, display == 0 meant primary display, so compat code for it */
2030
+ if (display_index == 0 ) {
2031
+ display_index = SDL_GetPrimaryDisplay ();
2032
+ if (display_index == 0 ) {
2033
+ return RAISE (pgExc_SDLError , SDL_GetError ());
2034
+ }
2035
+ }
2036
+ #else
1977
2037
/* Display ID is not bounded by number of displays in SDL3 */
1978
2038
if (display_index < 0 || display_index >= SDL_GetNumVideoDisplays ()) {
1979
2039
return RAISE (PyExc_ValueError ,
@@ -2039,7 +2099,15 @@ pg_list_modes(PyObject *self, PyObject *args, PyObject *kwds)
2039
2099
return NULL ;
2040
2100
}
2041
2101
2042
- #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
2102
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2103
+ /* In SDL2, display == 0 meant primary display, so compat code for it */
2104
+ if (display_index == 0 ) {
2105
+ display_index = SDL_GetPrimaryDisplay ();
2106
+ if (display_index == 0 ) {
2107
+ return RAISE (pgExc_SDLError , SDL_GetError ());
2108
+ }
2109
+ }
2110
+ #else
2043
2111
/* Display ID is not bounded by number of displays in SDL3 */
2044
2112
if (display_index < 0 || display_index >= SDL_GetNumVideoDisplays ()) {
2045
2113
return RAISE (PyExc_ValueError ,
@@ -2700,6 +2768,11 @@ pg_iconify(PyObject *self, PyObject *_null)
2700
2768
return RAISE (pgExc_SDLError , "No open window" );
2701
2769
}
2702
2770
SDL_MinimizeWindow (win );
2771
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2772
+ if (!SDL_SyncWindow (win )) {
2773
+ return RAISE (pgExc_SDLError , SDL_GetError ());
2774
+ }
2775
+ #endif
2703
2776
return PyBool_FromLong (1 );
2704
2777
}
2705
2778
@@ -3035,7 +3108,6 @@ static PyObject *
3035
3108
pg_toggle_fullscreen (PyObject * self , PyObject * _null )
3036
3109
{
3037
3110
SDL_Window * win = pg_GetDefaultWindow ();
3038
- int result ;
3039
3111
SDL_WindowFlags flags ;
3040
3112
int window_w , window_h , w , h , window_display , x , y ;
3041
3113
pgSurfaceObject * display_surface ;
@@ -3164,8 +3236,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3164
3236
/* TOGGLE FULLSCREEN OFF */
3165
3237
3166
3238
if (state -> unscaled_render ) {
3167
- result = SDL_SetWindowFullscreen (win , 0 );
3168
- if (result != 0 ) {
3239
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3169
3240
return RAISE (pgExc_SDLError , SDL_GetError ());
3170
3241
}
3171
3242
}
@@ -3179,8 +3250,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3179
3250
if (scale < 1 ) {
3180
3251
scale = 1 ;
3181
3252
}
3182
- result = SDL_SetWindowFullscreen (win , 0 );
3183
- if (result != 0 ) {
3253
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3184
3254
return RAISE (pgExc_SDLError , SDL_GetError ());
3185
3255
}
3186
3256
SDL_SetWindowSize (win , w * scale , h * scale );
@@ -3220,8 +3290,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3220
3290
/* this is literally the only place where state->toggle_windowed_w
3221
3291
* should ever be read. We only use it because with GL, there is no
3222
3292
* display surface we can query for dimensions. */
3223
- result = SDL_SetWindowFullscreen (win , 0 );
3224
- if (result != 0 ) {
3293
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3225
3294
return RAISE (pgExc_SDLError , SDL_GetError ());
3226
3295
}
3227
3296
SDL_GL_MakeCurrent (win , state -> gl_context );
@@ -3257,8 +3326,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3257
3326
else if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) ==
3258
3327
SDL_WINDOW_FULLSCREEN_DESKTOP ) {
3259
3328
#endif
3260
- result = SDL_SetWindowFullscreen (win , 0 );
3261
- if (result != 0 ) {
3329
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3262
3330
return RAISE (pgExc_SDLError , SDL_GetError ());
3263
3331
}
3264
3332
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3287,15 +3355,11 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3287
3355
if (win == NULL ) {
3288
3356
return RAISE (pgExc_SDLError , SDL_GetError ());
3289
3357
}
3290
- else {
3291
- result = 0 ;
3292
- }
3293
3358
display_surface -> surf = SDL_GetWindowSurface (win );
3294
3359
pg_SetDefaultWindow (win );
3295
3360
}
3296
3361
else {
3297
- result = SDL_SetWindowFullscreen (win , 0 );
3298
- if (result != 0 ) {
3362
+ if (!PG_SetWindowFullscreen (win , 0 , 0 )) {
3299
3363
return RAISE (pgExc_SDLError , SDL_GetError ());
3300
3364
}
3301
3365
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3330,24 +3394,12 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3330
3394
state -> fullscreen_backup_y = y ;
3331
3395
3332
3396
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 ) {
3397
+ if (!PG_SetWindowFullscreen (win , 1 , 0 )) {
3340
3398
return RAISE (pgExc_SDLError , SDL_GetError ());
3341
3399
}
3342
3400
}
3343
3401
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 ) {
3402
+ if (!PG_SetWindowFullscreen (win , 1 , 0 )) {
3351
3403
return RAISE (pgExc_SDLError , SDL_GetError ());
3352
3404
}
3353
3405
if (is_renderer_software && subsystem == SDL_SYSWM_X11 ) {
@@ -3380,13 +3432,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3380
3432
#endif
3381
3433
}
3382
3434
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 ) {
3435
+ if (!PG_SetWindowFullscreen (win , 1 , 0 )) {
3390
3436
return RAISE (pgExc_SDLError , SDL_GetError ());
3391
3437
}
3392
3438
SDL_GL_MakeCurrent (win , state -> gl_context );
@@ -3411,13 +3457,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3411
3457
}
3412
3458
}
3413
3459
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 ) {
3460
+ if (!PG_SetWindowFullscreen (win , 1 , 0 )) {
3421
3461
return RAISE (pgExc_SDLError , SDL_GetError ());
3422
3462
}
3423
3463
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3434,8 +3474,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3434
3474
return PyLong_FromLong (-1 );
3435
3475
}
3436
3476
else {
3437
- result = SDL_SetWindowFullscreen (win , SDL_WINDOW_FULLSCREEN );
3438
- if (result != 0 ) {
3477
+ if (!PG_SetWindowFullscreen (win , 1 , 1 )) {
3439
3478
return RAISE (pgExc_SDLError , SDL_GetError ());
3440
3479
}
3441
3480
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3447,7 +3486,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3447
3486
if (win == NULL ) {
3448
3487
return RAISE (pgExc_SDLError , SDL_GetError ());
3449
3488
}
3450
- if (0 != SDL_SetWindowFullscreen (win , SDL_WINDOW_FULLSCREEN )) {
3489
+ if (! PG_SetWindowFullscreen (win , 1 , 1 )) {
3451
3490
return RAISE (pgExc_SDLError , SDL_GetError ());
3452
3491
}
3453
3492
display_surface -> surf = SDL_GetWindowSurface (win );
@@ -3461,7 +3500,12 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3461
3500
}
3462
3501
}
3463
3502
}
3464
- return PyLong_FromLong (result != 0 );
3503
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3504
+ if (!SDL_SyncWindow (win )) {
3505
+ return RAISE (pgExc_SDLError , SDL_GetError ());
3506
+ }
3507
+ #endif
3508
+ return PyLong_FromLong (1 );
3465
3509
}
3466
3510
3467
3511
/* This API is provisional, and, not finalised, and should not be documented
@@ -3539,6 +3583,11 @@ pg_display_resize_event(PyObject *self, PyObject *event)
3539
3583
/* do not do anything that would invalidate a display surface! */
3540
3584
return PyLong_FromLong (-1 );
3541
3585
}
3586
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3587
+ if (!SDL_SyncWindow (win )) {
3588
+ return RAISE (pgExc_SDLError , SDL_GetError ());
3589
+ }
3590
+ #endif
3542
3591
Py_RETURN_FALSE ;
3543
3592
}
3544
3593
@@ -3771,7 +3820,11 @@ pg_message_box(PyObject *self, PyObject *arg, PyObject *kwargs)
3771
3820
3772
3821
int clicked_button_id ;
3773
3822
3823
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
3824
+ if (!SDL_ShowMessageBox (& msgbox_data , & clicked_button_id )) {
3825
+ #else
3774
3826
if (SDL_ShowMessageBox (& msgbox_data , & clicked_button_id )) {
3827
+ #endif
3775
3828
PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3776
3829
goto error ;
3777
3830
}
0 commit comments