Skip to content

Commit 90e8f44

Browse files
committed
sdl3(display): handle event/env api changes
1 parent fb13d26 commit 90e8f44

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src_c/display.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@ pg_display_init(PyObject *self, PyObject *_null)
239239
drivername = SDL_getenv("SDL_VIDEODRIVER");
240240
if (drivername &&
241241
!SDL_strncasecmp("windib", drivername, SDL_strlen(drivername))) {
242+
#if SDL_VERSION_ATLEAST(3, 0, 0)
243+
SDL_setenv_unsafe("SDL_VIDEODRIVER", "windows", 1);
244+
#else
242245
SDL_setenv("SDL_VIDEODRIVER", "windows", 1);
246+
#endif
243247
}
244248
if (!SDL_WasInit(SDL_INIT_VIDEO)) {
245249
if (!_pg_mac_display_init()) {
@@ -733,7 +737,11 @@ _get_video_window_pos(int *x, int *y, int *center_window)
733737
return 0;
734738
}
735739

740+
#if SDL_VERSION_ATLEAST(3, 0, 0)
741+
static bool
742+
#else
736743
static int SDLCALL
744+
#endif
737745
pg_ResizeEventWatch(void *userdata, SDL_Event *event)
738746
{
739747
SDL_Window *pygame_window;
@@ -759,7 +767,11 @@ pg_ResizeEventWatch(void *userdata, SDL_Event *event)
759767
}
760768

761769
if (state->unscaled_render && pg_renderer != NULL) {
770+
#if SDL_VERSION_ATLEAST(3, 0, 0)
771+
if (event->type == SDL_WINDOWEVENT_SIZE_CHANGED) {
772+
#else
762773
if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
774+
#endif
763775
int w = event->window.data1;
764776
int h = event->window.data2;
765777
pgSurfaceObject *display_surface = pg_GetDefaultWindowSurface();
@@ -779,10 +791,18 @@ pg_ResizeEventWatch(void *userdata, SDL_Event *event)
779791
}
780792

781793
if (pg_renderer != NULL) {
794+
#if SDL_VERSION_ATLEAST(3, 0, 0)
795+
if (event->type == SDL_WINDOWEVENT_MAXIMIZED) {
796+
#else
782797
if (event->window.event == SDL_WINDOWEVENT_MAXIMIZED) {
798+
#endif
783799
SDL_RenderSetIntegerScale(pg_renderer, SDL_FALSE);
784800
}
801+
#if SDL_VERSION_ATLEAST(3, 0, 0)
802+
if (event->type == SDL_WINDOWEVENT_RESTORED) {
803+
#else
785804
if (event->window.event == SDL_WINDOWEVENT_RESTORED) {
805+
#endif
786806
SDL_RenderSetIntegerScale(
787807
pg_renderer, !(SDL_GetHintBoolean(
788808
"SDL_HINT_RENDER_SCALE_QUALITY", SDL_FALSE)));
@@ -791,7 +811,11 @@ pg_ResizeEventWatch(void *userdata, SDL_Event *event)
791811
}
792812

793813
if (state->using_gl) {
814+
#if SDL_VERSION_ATLEAST(3, 0, 0)
815+
if (event->type == SDL_WINDOWEVENT_SIZE_CHANGED) {
816+
#else
794817
if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
818+
#endif
795819
GL_glViewport_Func p_glViewport =
796820
(GL_glViewport_Func)SDL_GL_GetProcAddress("glViewport");
797821
int wnew = event->window.data1;
@@ -817,7 +841,11 @@ pg_ResizeEventWatch(void *userdata, SDL_Event *event)
817841
return 0;
818842
}
819843

844+
#if SDL_VERSION_ATLEAST(3, 0, 0)
845+
if (event->type == SDL_WINDOWEVENT_SIZE_CHANGED) {
846+
#else
820847
if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
848+
#endif
821849
SDL_Surface *sdl_surface = SDL_GetWindowSurface(window);
822850
pgSurfaceObject *old_surface = pg_GetDefaultWindowSurface();
823851
if (sdl_surface != old_surface->surf) {
@@ -853,7 +881,7 @@ pg_display_set_autoresize(PyObject *self, PyObject *arg)
853881
int
854882
_get_display(SDL_Window *win)
855883
{
856-
char *display_env = SDL_getenv("PYGAME_DISPLAY");
884+
const char *display_env = SDL_getenv("PYGAME_DISPLAY");
857885
int display = 0; /* default display 0 */
858886

859887
if (win != NULL) {
@@ -932,7 +960,7 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
932960
screen as the old one */
933961
int display = _get_display(win);
934962
char *title = state->title;
935-
char *scale_env, *winid_env;
963+
const char *scale_env, *winid_env;
936964
SDL_SysWMinfo wm_info;
937965

938966
SDL_VERSION(&wm_info.version);

0 commit comments

Comments
 (0)