31
31
32
32
#include "doc/display_doc.h"
33
33
34
+ #ifndef PG_SDL3
34
35
#include <SDL_syswm.h>
36
+ #endif
35
37
36
38
static PyTypeObject pgVidInfo_Type ;
37
39
@@ -499,12 +501,14 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
499
501
{
500
502
PyObject * dict ;
501
503
PyObject * tmp ;
502
- SDL_SysWMinfo info ;
503
504
SDL_Window * win ;
504
505
505
506
VIDEO_INIT_CHECK ();
506
507
508
+ #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
509
+ SDL_SysWMinfo info ;
507
510
SDL_VERSION (& (info .version ))
511
+ #endif
508
512
dict = PyDict_New ();
509
513
if (!dict ) {
510
514
return NULL ;
@@ -514,12 +518,32 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
514
518
if (!win ) {
515
519
return dict ;
516
520
}
521
+ #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
517
522
if (!SDL_GetWindowWMInfo (win , & info )) {
518
523
return dict ;
519
524
}
525
+ #endif
520
526
521
527
(void )tmp ;
522
528
#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
523
547
tmp = PyLong_FromLongLong ((long long )info .info .win .window );
524
548
PyDict_SetItemString (dict , "window" , tmp );
525
549
Py_DECREF (tmp );
@@ -531,12 +555,26 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
531
555
PyDict_SetItemString (dict , "hinstance" , tmp );
532
556
Py_DECREF (tmp );
533
557
#endif
534
- #if defined(SDL_VIDEO_DRIVER_WINRT )
558
+ #endif
559
+ #if defined(SDL_VIDEO_DRIVER_WINRT ) && !SDL_VERSION_ATLEAST (3 , 0 , 0 )
535
560
tmp = PyCapsule_New (info .info .winrt .window , "window" , NULL );
536
561
PyDict_SetItemString (dict , "window" , tmp );
537
562
Py_DECREF (tmp );
538
563
#endif
539
564
#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
540
578
tmp = PyLong_FromLong (info .info .x11 .window );
541
579
PyDict_SetItemString (dict , "window" , tmp );
542
580
Py_DECREF (tmp );
@@ -545,7 +583,8 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
545
583
PyDict_SetItemString (dict , "display" , tmp );
546
584
Py_DECREF (tmp );
547
585
#endif
548
- #if defined(SDL_VIDEO_DRIVER_DIRECTFB )
586
+ #endif
587
+ #if defined(SDL_VIDEO_DRIVER_DIRECTFB ) && !SDL_VERSION_ATLEAST (3 , 0 , 0 )
549
588
tmp = PyCapsule_New (info .info .dfb .dfb , "dfb" , NULL );
550
589
PyDict_SetItemString (dict , "dfb" , tmp );
551
590
Py_DECREF (tmp );
@@ -559,11 +598,46 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
559
598
Py_DECREF (tmp );
560
599
#endif
561
600
#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
562
609
tmp = PyCapsule_New (info .info .cocoa .window , "window" , NULL );
563
610
PyDict_SetItemString (dict , "window" , tmp );
564
611
Py_DECREF (tmp );
565
612
#endif
613
+ #endif
566
614
#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
567
641
tmp = PyCapsule_New (info .info .uikit .window , "window" , NULL );
568
642
PyDict_SetItemString (dict , "window" , tmp );
569
643
Py_DECREF (tmp );
@@ -580,7 +654,23 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
580
654
PyDict_SetItemString (dict , "resolveFramebuffer" , tmp );
581
655
Py_DECREF (tmp );
582
656
#endif
657
+ #endif
583
658
#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
584
674
tmp = PyCapsule_New (info .info .wl .display , "display" , NULL );
585
675
PyDict_SetItemString (dict , "display" , tmp );
586
676
Py_DECREF (tmp );
@@ -593,7 +683,22 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
593
683
PyDict_SetItemString (dict , "shell_surface" , tmp );
594
684
Py_DECREF (tmp );
595
685
#endif
686
+ #endif
596
687
#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
597
702
tmp = PyCapsule_New (info .info .android .window , "window" , NULL );
598
703
PyDict_SetItemString (dict , "window" , tmp );
599
704
Py_DECREF (tmp );
@@ -602,14 +707,29 @@ pg_get_wm_info(PyObject *self, PyObject *_null)
602
707
PyDict_SetItemString (dict , "surface" , tmp );
603
708
Py_DECREF (tmp );
604
709
#endif
710
+ #endif
605
711
#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
606
725
tmp = PyLong_FromLong ((long )info .info .vivante .display );
607
726
PyDict_SetItemString (dict , "display" , tmp );
608
727
Py_DECREF (tmp );
609
728
610
729
tmp = PyLong_FromLong ((long )info .info .vivante .window );
611
730
PyDict_SetItemString (dict , "window" , tmp );
612
731
Py_DECREF (tmp );
732
+ #endif
613
733
#endif
614
734
615
735
return dict ;
@@ -980,9 +1100,6 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
980
1100
int display = _get_display (win );
981
1101
char * title = state -> title ;
982
1102
const char * scale_env , * winid_env ;
983
- SDL_SysWMinfo wm_info ;
984
-
985
- SDL_VERSION (& wm_info .version );
986
1103
987
1104
char * keywords [] = {"size" , "flags" , "depth" , "display" , "vsync" , NULL };
988
1105
@@ -2729,6 +2846,63 @@ pg_desktop_refresh_rates(PyObject *self, PyObject *_null)
2729
2846
return result ;
2730
2847
}
2731
2848
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
+
2732
2906
static PyObject *
2733
2907
pg_toggle_fullscreen (PyObject * self , PyObject * _null )
2734
2908
{
@@ -2738,7 +2912,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
2738
2912
pgSurfaceObject * display_surface ;
2739
2913
_DisplayState * state = DISPLAY_MOD_STATE (self );
2740
2914
GL_glViewport_Func p_glViewport = NULL ;
2741
- SDL_SysWMinfo wm_info ;
2915
+ SDL_SYSWM_TYPE subsystem ;
2742
2916
int is_renderer_software = 0 ;
2743
2917
2744
2918
VIDEO_INIT_CHECK ();
@@ -2748,10 +2922,16 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
2748
2922
2749
2923
flags = SDL_GetWindowFlags (win );
2750
2924
2925
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2926
+ subsystem = get_syswm_type ();
2927
+ #else
2928
+ SDL_SysWMinfo wm_info ;
2751
2929
SDL_VERSION (& wm_info .version );
2752
2930
if (!SDL_GetWindowWMInfo (win , & wm_info )) {
2753
2931
return RAISE (pgExc_SDLError , SDL_GetError ());
2754
2932
}
2933
+ subsystem = wm_info .subsystem ;
2934
+ #endif
2755
2935
2756
2936
if (state -> using_gl && pg_renderer != NULL ) {
2757
2937
return RAISE (pgExc_SDLError ,
@@ -2774,7 +2954,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
2774
2954
#endif
2775
2955
}
2776
2956
2777
- switch (wm_info . subsystem ) {
2957
+ switch (subsystem ) {
2778
2958
// if we get this to work correctly with more systems, move them here
2779
2959
case SDL_SYSWM_WINDOWS :
2780
2960
case SDL_SYSWM_X11 :
@@ -2876,7 +3056,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
2876
3056
}
2877
3057
SDL_SetWindowSize (win , w * scale , h * scale );
2878
3058
2879
- if (is_renderer_software && wm_info . subsystem == SDL_SYSWM_X11 ) {
3059
+ if (is_renderer_software && subsystem == SDL_SYSWM_X11 ) {
2880
3060
/* display surface lost? */
2881
3061
SDL_DestroyTexture (pg_texture );
2882
3062
SDL_DestroyRenderer (pg_renderer );
@@ -2950,7 +3130,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
2950
3130
}
2951
3131
display_surface -> surf = SDL_GetWindowSurface (win );
2952
3132
}
2953
- else if (wm_info . subsystem == SDL_SYSWM_X11 ) {
3133
+ else if (subsystem == SDL_SYSWM_X11 ) {
2954
3134
/* This is a HACK, specifically to work around faulty behaviour of
2955
3135
* SDL_SetWindowFullscreen on X11 when switching out of fullscreen
2956
3136
* would change the physical resolution of the display back to the
@@ -3025,7 +3205,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3025
3205
if (result != 0 ) {
3026
3206
return RAISE (pgExc_SDLError , SDL_GetError ());
3027
3207
}
3028
- if (is_renderer_software && wm_info . subsystem == SDL_SYSWM_X11 ) {
3208
+ if (is_renderer_software && subsystem == SDL_SYSWM_X11 ) {
3029
3209
if (PyErr_WarnEx (
3030
3210
PyExc_Warning ,
3031
3211
"recreating software renderer in toggle_fullscreen" ,
@@ -3089,7 +3269,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
3089
3269
}
3090
3270
display_surface -> surf = SDL_GetWindowSurface (win );
3091
3271
}
3092
- else if (wm_info . subsystem == SDL_SYSWM_WAYLAND ) {
3272
+ else if (subsystem == SDL_SYSWM_WAYLAND ) {
3093
3273
/* This only happens AFTER other options have been exhausted.
3094
3274
* with GL, Renderer, or the correct window size, toggling works.
3095
3275
* Only entering a hard fullscreen state is unsupported. */
0 commit comments