@@ -847,24 +847,30 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
847847 int w , h ;
848848 PyObject * size = NULL ;
849849 int vsync = SDL_FALSE ;
850+ uint64_t hwnd = 0 ;
850851 /* display will get overwritten by ParseTupleAndKeywords only if display
851852 parameter is given. By default, put the new window on the same
852853 screen as the old one */
853854 int display = _get_display (win );
854855 char * title = state -> title ;
855- char * scale_env ;
856+ char * scale_env , * winid_env ;
856857 SDL_SysWMinfo wm_info ;
857858
858859 SDL_VERSION (& wm_info .version );
859860
860861 char * keywords [] = {"size" , "flags" , "depth" , "display" , "vsync" , NULL };
861862
862863 scale_env = SDL_getenv ("PYGAME_FORCE_SCALE" );
864+ winid_env = SDL_getenv ("SDL_WINDOWID" );
863865
864866 if (!PyArg_ParseTupleAndKeywords (arg , kwds , "|Oiiii" , keywords , & size ,
865867 & flags , & depth , & display , & vsync ))
866868 return NULL ;
867869
870+ if (hwnd == 0 && winid_env != NULL ) {
871+ hwnd = SDL_strtoull (winid_env , NULL , 0 );
872+ }
873+
868874 if (scale_env != NULL ) {
869875 flags |= PGS_SCALED ;
870876 if (strcmp (scale_env , "photo" ) == 0 ) {
@@ -1104,7 +1110,12 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
11041110
11051111 if (!win ) {
11061112 /*open window*/
1107- win = SDL_CreateWindow (title , x , y , w_1 , h_1 , sdl_flags );
1113+ if (hwnd != 0 ) {
1114+ win = SDL_CreateWindowFrom ((void * )hwnd );
1115+ }
1116+ else {
1117+ win = SDL_CreateWindow (title , x , y , w_1 , h_1 , sdl_flags );
1118+ }
11081119 if (!win )
11091120 return RAISE (pgExc_SDLError , SDL_GetError ());
11101121 }
0 commit comments