@@ -114,32 +114,45 @@ SDL_Surface *load_surface_from_xdg(const char *path){
114114 // Spec for this is here: https://specifications.freedesktop.org/icon-theme/latest/#icon_lookup
115115 SDL_Surface * surface = NULL ;
116116 const char * xdg_dirs = getenv ("XDG_DATA_DIRS" );
117- const char * icon_path = "/icons/hicolor/scalable/apps/" ;
118- if (xdg_dirs != NULL ){
119- ssize_t last_delim = -1 ;
120- ssize_t dirs_len = strlen (xdg_dirs );
121- while (surface == NULL && last_delim < dirs_len ){
122- char xdg_path [4096 ] = {0 };
123- ssize_t start_ind = last_delim ;
124- if (start_ind < 0 )
125- start_ind = 0 ;
126-
127- ssize_t end = strcspn (& xdg_dirs [start_ind ], ":" );
128- memcpy (& xdg_path , & xdg_dirs [start_ind ], end );
129- memcpy (& xdg_path [end ], icon_path , strlen (icon_path ));
130- memcpy (& xdg_path [end + strlen (icon_path )], path , strlen (path ));
131- surface = IMG_Load (xdg_path );
132- if (surface == NULL ) {
133- log_error (
134- "Could not load image from xdg %s\n%s" ,
135- xdg_path ,
136- IMG_GetError ()
137- );
117+ const char * sizes [] = {
118+ "scalable" ,
119+ "512x512" ,
120+ "256x256" ,
121+ "128x128" ,
122+ "64x64" ,
123+ "32x32"
124+ };
125+
126+ for (int i = 0 ; i < sizeof (sizes ) / sizeof (void * ); i ++ ){
127+ char icon_path [128 ] = {};
128+ snprintf (icon_path , 127 , "/icons/hicolor/%s/apps/" , sizes [i ]);
129+
130+ if (xdg_dirs != NULL ){
131+ ssize_t last_delim = -1 ;
132+ ssize_t dirs_len = strlen (xdg_dirs );
133+ while (surface == NULL && last_delim < dirs_len ){
134+ char xdg_path [4096 ] = {0 };
135+ ssize_t start_ind = last_delim ;
136+ if (start_ind < 0 )
137+ start_ind = 0 ;
138+
139+ ssize_t end = strcspn (& xdg_dirs [start_ind ], ":" );
140+ memcpy (& xdg_path , & xdg_dirs [start_ind ], end );
141+ memcpy (& xdg_path [end ], icon_path , strlen (icon_path ));
142+ memcpy (& xdg_path [end + strlen (icon_path )], path , strlen (path ));
143+ surface = IMG_Load (xdg_path );
144+ if (surface != NULL )
145+ return surface ;
146+
147+ last_delim += end + 1 ;
138148 }
139- last_delim += end + 1 ;
140149 }
141150 }
142- return surface ;
151+
152+ log_error (
153+ "Could not load %s from XDG_DATA_DIRS" ,
154+ path
155+ );
143156}
144157#endif
145158
0 commit comments