66
77#include "build.h"
88
9- #if defined __APPLE__
9+ #if defined( __APPLE__ ) && defined( HAVE_OSX_FRAMEWORKS )
1010# include <SDL2/SDL.h>
1111#else
1212# include "SDL.h"
2929
3030#if defined(__APPLE__ )
3131# include "osxbits.h"
32- #elif defined(HAVE_GTK )
32+ #endif
33+ #if defined(HAVE_GTK )
3334# include "gtkbits.h"
34- #else
35- int startwin_open (void ) { return 0 ; }
36- int startwin_close (void ) { return 0 ; }
37- int startwin_puts (const char * s ) { (void )s ; return 0 ; }
38- int startwin_idle (void * s ) { (void )s ; return 0 ; }
39- int startwin_settitle (const char * s ) { (void )s ; return 0 ; }
4035#endif
4136
4237static int backgroundidle = 0 ;
@@ -48,6 +43,7 @@ static SDL_Window *sdl_window;
4843static SDL_Renderer * sdl_renderer ; // For non-GL 8-bit mode output.
4944static SDL_Texture * sdl_texture ; // For non-GL 8-bit mode output.
5045static SDL_Surface * sdl_surface ; // For non-GL 8-bit mode output.
46+ static SDL_Surface * sdl_appicon ;
5147static int usesdlrenderer = 0 ;
5248static unsigned char * frame ;
5349static float curshadergamma = 1.f , cursysgamma = -1.f ;
@@ -84,9 +80,7 @@ static int buildkeytranslationtable(void);
8480static void enumdisplays (void );
8581static void shutdownvideo (void );
8682
87- #ifndef __APPLE__
88- static SDL_Surface * loadappicon (void );
89- #endif
83+ static void loadappicon (void );
9084
9185int wm_msgbox (const char * name , const char * fmt , ...)
9286{
@@ -107,7 +101,7 @@ int wm_msgbox(const char *name, const char *fmt, ...)
107101 do {
108102 rv = 0 ;
109103
110- #if defined HAVE_GTK
104+ #if defined( HAVE_GTK )
111105 if (wmgtk_msgbox (name , buf ) >= 0 ) {
112106 rv = 1 ;
113107 break ;
@@ -159,7 +153,7 @@ int wm_ynbox(const char *name, const char *fmt, ...)
159153 do {
160154 rv = 0 ;
161155
162- #if defined HAVE_GTK
156+ #if defined( HAVE_GTK )
163157 if ((rv = wmgtk_ynbox (name , buf )) >= 0 ) {
164158 break ;
165159 }
@@ -181,14 +175,14 @@ int wm_ynbox(const char *name, const char *fmt, ...)
181175
182176int wm_filechooser (const char * initialdir , const char * initialfile , const char * type , int foropen , char * * choice )
183177{
184- #if defined __APPLE__ || defined HAVE_GTK
178+ #if ( defined( __APPLE__ ) && defined( HAVE_OSX_FRAMEWORKS )) || defined( HAVE_GTK )
185179 int rv ;
186180 if (mouseacquired && moustat ) {
187181 SDL_SetRelativeMouseMode (SDL_FALSE );
188182 }
189- #if defined __APPLE__
183+ #if defined( __APPLE__ ) && defined( HAVE_OSX_FRAMEWORKS )
190184 rv = wmosx_filechooser (initialdir , initialfile , type , foropen , choice );
191- #elif defined HAVE_GTK
185+ #elif defined( HAVE_GTK )
192186 rv = wmgtk_filechooser (initialdir , initialfile , type , foropen , choice );
193187#endif
194188 SDL_RaiseWindow (sdl_window );
@@ -204,7 +198,7 @@ int wm_filechooser(const char *initialdir, const char *initialfile, const char *
204198
205199int wm_idle (void * ptr )
206200{
207- #if defined HAVE_GTK
201+ #if defined( HAVE_GTK )
208202 return wmgtk_idle (ptr );
209203#else
210204 (void )ptr ;
@@ -295,8 +289,12 @@ int main(int argc, char *argv[])
295289 // This avoids doubled character input in the (OSX) startup window's edit fields.
296290 SDL_EventState (SDL_TEXTINPUT , SDL_IGNORE );
297291
292+ loadappicon ();
293+
298294 r = app_main (_buildargc , (char const * const * )_buildargv );
299295
296+ if (sdl_appicon ) SDL_FreeSurface (sdl_appicon );
297+
300298#ifdef __APPLE__
301299 free (_buildargv );
302300#endif
@@ -903,13 +901,7 @@ int setvideomode(int xdim, int ydim, int bitspp, int fullsc)
903901 break ;
904902 } while (1 );
905903
906- #ifndef __APPLE__
907- {
908- SDL_Surface * icon = loadappicon ();
909- SDL_SetWindowIcon (sdl_window , icon );
910- SDL_FreeSurface (icon );
911- }
912- #endif
904+ if (sdl_appicon ) SDL_SetWindowIcon (sdl_window , sdl_appicon );
913905
914906 if (bitspp == 8 ) {
915907 int i , j , pitch ;
@@ -1229,19 +1221,19 @@ void *getglprocaddress(const char *name, int ext)
12291221#endif
12301222
12311223
1232- #ifndef __APPLE__
1233- extern struct sdlappicon sdlappicon ;
1234- static SDL_Surface * loadappicon (void )
1224+ static void loadappicon (void )
12351225{
1236- SDL_Surface * surf ;
1226+ #if !defined(__APPLE__ ) || (defined(__APPLE__ ) && !defined(HAVE_OSX_FRAMEWORKS ))
1227+ extern struct sdlappicon sdlappicon ;
12371228
1238- surf = SDL_CreateRGBSurfaceFrom ((void * )sdlappicon .pixels ,
1229+ sdl_appicon = SDL_CreateRGBSurfaceFrom ((void * )sdlappicon .pixels ,
12391230 sdlappicon .width , sdlappicon .height , 32 , sdlappicon .width * 4 ,
12401231 0xffl ,0xff00l ,0xff0000l ,0xff000000l );
1241-
1242- return surf ;
1243- }
1232+ if (! sdl_appicon ) {
1233+ debugprintf ( "loadappicon: error creating appicon surface: %s\n" , SDL_GetError ()) ;
1234+ }
12441235#endif
1236+ }
12451237
12461238//
12471239//
0 commit comments