3131
3232#include "doc/display_doc.h"
3333
34+ #ifndef PG_SDL3
3435#include <SDL_syswm.h>
36+ #endif
3537
3638static PyTypeObject pgVidInfo_Type ;
3739
@@ -499,12 +501,14 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
499501{
500502 PyObject * dict ;
501503 PyObject * tmp ;
502- SDL_SysWMinfo info ;
503504 SDL_Window * win ;
504505
505506 VIDEO_INIT_CHECK ();
506507
508+ #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
509+ SDL_SysWMinfo info ;
507510 SDL_VERSION (& (info .version ))
511+ #endif
508512 dict = PyDict_New ();
509513 if (!dict ) {
510514 return NULL ;
@@ -514,12 +518,32 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
514518 if (!win ) {
515519 return dict ;
516520 }
521+ #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
517522 if (!SDL_GetWindowWMInfo (win , & info )) {
518523 return dict ;
519524 }
525+ #endif
520526
521527 (void )tmp ;
522528#if defined(SDL_VIDEO_DRIVER_WINDOWS )
529+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
530+ tmp = PyLong_FromLongLong ((long long )SDL_GetPointerProperty (
531+ SDL_GetWindowProperties (win ), SDL_PROP_WINDOW_WIN32_HWND_POINTER ,
532+ NULL ));
533+ PyDict_SetItemString (dict , "window" , tmp );
534+ Py_DECREF (tmp );
535+
536+ tmp = PyLong_FromLongLong ((long long )SDL_GetPointerProperty (
537+ SDL_GetWindowProperties (win ), SDL_PROP_WINDOW_WIN32_HDC_POINTER ,
538+ NULL ));
539+ PyDict_SetItemString (dict , "hdc" , tmp );
540+ Py_DECREF (tmp );
541+ tmp = PyLong_FromLongLong ((long long )SDL_GetPointerProperty (
542+ SDL_GetWindowProperties (win ), SDL_PROP_WINDOW_WIN32_INSTANCE_POINTER ,
543+ NULL ));
544+ PyDict_SetItemString (dict , "hinstance" , tmp );
545+ Py_DECREF (tmp );
546+ #else
523547 tmp = PyLong_FromLongLong ((long long )info .info .win .window );
524548 PyDict_SetItemString (dict , "window" , tmp );
525549 Py_DECREF (tmp );
@@ -531,12 +555,26 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
531555 PyDict_SetItemString (dict , "hinstance" , tmp );
532556 Py_DECREF (tmp );
533557#endif
534- #if defined(SDL_VIDEO_DRIVER_WINRT )
558+ #endif
559+ #if defined(SDL_VIDEO_DRIVER_WINRT ) && !SDL_VERSION_ATLEAST (3 , 0 , 0 )
535560 tmp = PyCapsule_New (info .info .winrt .window , "window" , NULL );
536561 PyDict_SetItemString (dict , "window" , tmp );
537562 Py_DECREF (tmp );
538563#endif
539564#if defined(SDL_VIDEO_DRIVER_X11 )
565+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
566+ tmp = PyLong_FromLong (SDL_GetNumberProperty (
567+ SDL_GetWindowProperties (win ), SDL_PROP_WINDOW_X11_WINDOW_NUMBER , 0 ));
568+ PyDict_SetItemString (dict , "window" , tmp );
569+ Py_DECREF (tmp );
570+
571+ tmp = PyCapsule_New (
572+ SDL_GetPointerProperty (SDL_GetWindowProperties (win ),
573+ SDL_PROP_WINDOW_X11_DISPLAY_POINTER , NULL ),
574+ "display" , NULL );
575+ PyDict_SetItemString (dict , "display" , tmp );
576+ Py_DECREF (tmp );
577+ #else
540578 tmp = PyLong_FromLong (info .info .x11 .window );
541579 PyDict_SetItemString (dict , "window" , tmp );
542580 Py_DECREF (tmp );
@@ -545,7 +583,8 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
545583 PyDict_SetItemString (dict , "display" , tmp );
546584 Py_DECREF (tmp );
547585#endif
548- #if defined(SDL_VIDEO_DRIVER_DIRECTFB )
586+ #endif
587+ #if defined(SDL_VIDEO_DRIVER_DIRECTFB ) && !SDL_VERSION_ATLEAST (3 , 0 , 0 )
549588 tmp = PyCapsule_New (info .info .dfb .dfb , "dfb" , NULL );
550589 PyDict_SetItemString (dict , "dfb" , tmp );
551590 Py_DECREF (tmp );
@@ -559,11 +598,46 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
559598 Py_DECREF (tmp );
560599#endif
561600#if defined(SDL_VIDEO_DRIVER_COCOA )
601+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
602+ tmp = PyCapsule_New (
603+ SDL_GetPointerProperty (SDL_GetWindowProperties (win ),
604+ SDL_PROP_WINDOW_COCOA_WINDOW_POINTER , NULL ),
605+ "window" , NULL );
606+ PyDict_SetItemString (dict , "window" , tmp );
607+ Py_DECREF (tmp );
608+ #else
562609 tmp = PyCapsule_New (info .info .cocoa .window , "window" , NULL );
563610 PyDict_SetItemString (dict , "window" , tmp );
564611 Py_DECREF (tmp );
565612#endif
613+ #endif
566614#if defined(SDL_VIDEO_DRIVER_UIKIT )
615+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
616+ tmp = PyCapsule_New (
617+ SDL_GetPointerProperty (SDL_GetWindowProperties (win ),
618+ SDL_PROP_WINDOW_UIKIT_WINDOW_POINTER , NULL ),
619+ "window" , NULL );
620+ PyDict_SetItemString (dict , "window" , tmp );
621+ Py_DECREF (tmp );
622+
623+ tmp = PyLong_FromLong (SDL_GetPointerNumber (
624+ SDL_GetWindowProperties (win ),
625+ SDL_PROP_WINDOW_UIKIT_OPENGL_FRAMEBUFFER_NUMBER , 0 ));
626+ PyDict_SetItemString (dict , "framebuffer" , tmp );
627+ Py_DECREF (tmp );
628+
629+ tmp = PyLong_FromLong (SDL_GetPointerNumber (
630+ SDL_GetWindowProperties (win ),
631+ SDL_PROP_WINDOW_UIKIT_OPENGL_RENDERBUFFER_NUMBER , 0 ));
632+ PyDict_SetItemString (dict , "colorbuffer" , tmp );
633+ Py_DECREF (tmp );
634+
635+ tmp = PyLong_FromLong (SDL_GetPointerNumber (
636+ SDL_GetWindowProperties (win ),
637+ SDL_PROP_WINDOW_UIKIT_OPENGL_RESOLVE_FRAMEBUFFER_NUMBER , 0 ));
638+ PyDict_SetItemString (dict , "resolveFramebuffer" , tmp );
639+ Py_DECREF (tmp );
640+ #else
567641 tmp = PyCapsule_New (info .info .uikit .window , "window" , NULL );
568642 PyDict_SetItemString (dict , "window" , tmp );
569643 Py_DECREF (tmp );
@@ -580,7 +654,23 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
580654 PyDict_SetItemString (dict , "resolveFramebuffer" , tmp );
581655 Py_DECREF (tmp );
582656#endif
657+ #endif
583658#if defined(SDL_VIDEO_DRIVER_WAYLAND )
659+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
660+ tmp = PyCapsule_New (
661+ SDL_GetPointerProperty (SDL_GetWindowProperties (win ),
662+ SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER , NULL ),
663+ "display" , NULL );
664+ PyDict_SetItemString (dict , "display" , tmp );
665+ Py_DECREF (tmp );
666+
667+ tmp = PyCapsule_New (
668+ SDL_GetPointerProperty (SDL_GetWindowProperties (win ),
669+ SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER , NULL ),
670+ "surface" , NULL );
671+ PyDict_SetItemString (dict , "surface" , tmp );
672+ Py_DECREF (tmp );
673+ #else
584674 tmp = PyCapsule_New (info .info .wl .display , "display" , NULL );
585675 PyDict_SetItemString (dict , "display" , tmp );
586676 Py_DECREF (tmp );
@@ -593,7 +683,22 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
593683 PyDict_SetItemString (dict , "shell_surface" , tmp );
594684 Py_DECREF (tmp );
595685#endif
686+ #endif
596687#if defined(SDL_VIDEO_DRIVER_ANDROID )
688+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
689+ tmp = PyCapsule_New (
690+ SDL_GetPointerProperty (SDL_GetWindowProperties (win ),
691+ SDL_PROP_WINDOW_ANDROID_WINDOW_POINTER , NULL ),
692+ "window" , NULL );
693+ PyDict_SetItemString (dict , "window" , tmp );
694+ Py_DECREF (tmp );
695+
696+ tmp = PyLong_FromLong ((long )SDL_GetPointerProperty (
697+ SDL_GetWindowProperties (win ), SDL_PROP_WINDOW_ANDROID_SURFACE_POINTER ,
698+ NULL ));
699+ PyDict_SetItemString (dict , "surface" , tmp );
700+ Py_DECREF (tmp );
701+ #else
597702 tmp = PyCapsule_New (info .info .android .window , "window" , NULL );
598703 PyDict_SetItemString (dict , "window" , tmp );
599704 Py_DECREF (tmp );
@@ -602,14 +707,29 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
602707 PyDict_SetItemString (dict , "surface" , tmp );
603708 Py_DECREF (tmp );
604709#endif
710+ #endif
605711#if defined(SDL_VIDEO_DRIVER_VIVANTE )
712+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
713+ tmp = PyLong_FromLong ((long )SDL_GetPointerProperty (
714+ SDL_GetWindowProperties (win ), SDL_PROP_WINDOW_VIVANTE_DISPLAY_POINTER ,
715+ NULL ));
716+ PyDict_SetItemString (dict , "display" , tmp );
717+ Py_DECREF (tmp );
718+
719+ tmp = PyLong_FromLong ((long )SDL_GetPointerProperty (
720+ SDL_GetWindowProperties (win ), SDL_PROP_WINDOW_VIVANTE_WINDOW_POINTER ,
721+ NULL ));
722+ PyDict_SetItemString (dict , "window" , tmp );
723+ Py_DECREF (tmp );
724+ #else
606725 tmp = PyLong_FromLong ((long )info .info .vivante .display );
607726 PyDict_SetItemString (dict , "display" , tmp );
608727 Py_DECREF (tmp );
609728
610729 tmp = PyLong_FromLong ((long )info .info .vivante .window );
611730 PyDict_SetItemString (dict , "window" , tmp );
612731 Py_DECREF (tmp );
732+ #endif
613733#endif
614734
615735 return dict ;
@@ -980,9 +1100,6 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
9801100 int display = _get_display (win );
9811101 char * title = state -> title ;
9821102 const char * scale_env , * winid_env ;
983- SDL_SysWMinfo wm_info ;
984-
985- SDL_VERSION (& wm_info .version );
9861103
9871104 char * keywords [] = {"size" , "flags" , "depth" , "display" , "vsync" , NULL };
9881105
@@ -2729,6 +2846,63 @@ pg_desktop_refresh_rates(PyObject *self, PyObject *_null)
27292846 return result ;
27302847}
27312848
2849+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2850+ typedef enum {
2851+ SDL_SYSWM_UNKNOWN ,
2852+ SDL_SYSWM_WINDOWS ,
2853+ SDL_SYSWM_X11 ,
2854+ SDL_SYSWM_DIRECTFB ,
2855+ SDL_SYSWM_COCOA ,
2856+ SDL_SYSWM_UIKIT ,
2857+ SDL_SYSWM_WAYLAND ,
2858+ SDL_SYSWM_MIR , /* no longer available, left for API/ABI compatibility. */
2859+ SDL_SYSWM_WINRT ,
2860+ SDL_SYSWM_ANDROID ,
2861+ SDL_SYSWM_VIVANTE ,
2862+ SDL_SYSWM_OS2 ,
2863+ SDL_SYSWM_HAIKU ,
2864+ SDL_SYSWM_KMSDRM ,
2865+ SDL_SYSWM_RISCOS
2866+ } SDL_SYSWM_TYPE ;
2867+
2868+ static SDL_SYSWM_TYPE
2869+ get_syswm_type ()
2870+ {
2871+ const char * driver = SDL_GetCurrentVideoDriver ();
2872+ if (!driver ) {
2873+ return SDL_SYSWM_UNKNOWN ;
2874+ }
2875+
2876+ if (strcmp (driver , "android" ) == 0 ) {
2877+ return SDL_SYSWM_ANDROID ;
2878+ }
2879+ else if (strcmp (driver , "cocoa" ) == 0 ) {
2880+ return SDL_SYSWM_COCOA ;
2881+ }
2882+ else if (strcmp (driver , "kmsdrm" ) == 0 ) {
2883+ return SDL_SYSWM_KMSDRM ;
2884+ }
2885+ else if (strcmp (driver , "uikit" ) == 0 ) {
2886+ return SDL_SYSWM_UIKIT ;
2887+ }
2888+ else if (strcmp (driver , "vivante" ) == 0 ) {
2889+ return SDL_SYSWM_VIVANTE ;
2890+ }
2891+ else if (strcmp (driver , "wayland" ) == 0 ) {
2892+ return SDL_SYSWM_WAYLAND ;
2893+ }
2894+ else if (strcmp (driver , "windows" ) == 0 ) {
2895+ return SDL_SYSWM_WINDOWS ;
2896+ }
2897+ else if (strcmp (driver , "x11" ) == 0 ) {
2898+ return SDL_SYSWM_X11 ;
2899+ }
2900+ else {
2901+ return SDL_SYSWM_UNKNOWN ;
2902+ }
2903+ }
2904+ #endif
2905+
27322906static PyObject *
27332907pg_toggle_fullscreen (PyObject * self , PyObject * _null )
27342908{
@@ -2738,7 +2912,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
27382912 pgSurfaceObject * display_surface ;
27392913 _DisplayState * state = DISPLAY_MOD_STATE (self );
27402914 GL_glViewport_Func p_glViewport = NULL ;
2741- SDL_SysWMinfo wm_info ;
2915+ SDL_SYSWM_TYPE subsystem ;
27422916 int is_renderer_software = 0 ;
27432917
27442918 VIDEO_INIT_CHECK ();
@@ -2748,10 +2922,16 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
27482922
27492923 flags = SDL_GetWindowFlags (win );
27502924
2925+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2926+ subsystem = get_syswm_type ();
2927+ #else
2928+ SDL_SysWMinfo wm_info ;
27512929 SDL_VERSION (& wm_info .version );
27522930 if (!SDL_GetWindowWMInfo (win , & wm_info )) {
27532931 return RAISE (pgExc_SDLError , SDL_GetError ());
27542932 }
2933+ subsystem = wm_info .subsystem ;
2934+ #endif
27552935
27562936 if (state -> using_gl && pg_renderer != NULL ) {
27572937 return RAISE (pgExc_SDLError ,
@@ -2774,7 +2954,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
27742954#endif
27752955 }
27762956
2777- switch (wm_info . subsystem ) {
2957+ switch (subsystem ) {
27782958 // if we get this to work correctly with more systems, move them here
27792959 case SDL_SYSWM_WINDOWS :
27802960 case SDL_SYSWM_X11 :
@@ -2876,7 +3056,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
28763056 }
28773057 SDL_SetWindowSize (win , w * scale , h * scale );
28783058
2879- if (is_renderer_software && wm_info . subsystem == SDL_SYSWM_X11 ) {
3059+ if (is_renderer_software && subsystem == SDL_SYSWM_X11 ) {
28803060 /* display surface lost? */
28813061 SDL_DestroyTexture (pg_texture );
28823062 SDL_DestroyRenderer (pg_renderer );
@@ -2950,7 +3130,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
29503130 }
29513131 display_surface -> surf = SDL_GetWindowSurface (win );
29523132 }
2953- else if (wm_info . subsystem == SDL_SYSWM_X11 ) {
3133+ else if (subsystem == SDL_SYSWM_X11 ) {
29543134 /* This is a HACK, specifically to work around faulty behaviour of
29553135 * SDL_SetWindowFullscreen on X11 when switching out of fullscreen
29563136 * would change the physical resolution of the display back to the
@@ -3025,7 +3205,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
30253205 if (result != 0 ) {
30263206 return RAISE (pgExc_SDLError , SDL_GetError ());
30273207 }
3028- if (is_renderer_software && wm_info . subsystem == SDL_SYSWM_X11 ) {
3208+ if (is_renderer_software && subsystem == SDL_SYSWM_X11 ) {
30293209 if (PyErr_WarnEx (
30303210 PyExc_Warning ,
30313211 "recreating software renderer in toggle_fullscreen" ,
@@ -3089,7 +3269,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
30893269 }
30903270 display_surface -> surf = SDL_GetWindowSurface (win );
30913271 }
3092- else if (wm_info . subsystem == SDL_SYSWM_WAYLAND ) {
3272+ else if (subsystem == SDL_SYSWM_WAYLAND ) {
30933273 /* This only happens AFTER other options have been exhausted.
30943274 * with GL, Renderer, or the correct window size, toggling works.
30953275 * Only entering a hard fullscreen state is unsupported. */
0 commit comments