diff --git a/app/src/icon.c b/app/src/icon.c index f95301fc..0a84f5ba 100644 --- a/app/src/icon.c +++ b/app/src/icon.c @@ -17,17 +17,16 @@ #include "util/file.h" #include "util/log.h" -#define SCRCPY_ICON_FILENAME "scrcpy.png" #define SCRCPY_DEFAULT_ICON_DIR PREFIX "/share/icons/hicolor/256x256/apps" static char * -get_icon_path(void) { +get_icon_path(const char *filename) { char *icon_path; char *icon_dir = sc_get_env("SCRCPY_ICON_DIR"); if (icon_dir) { // if the envvar is set, use it - icon_path = sc_file_build_path(icon_dir, SCRCPY_ICON_FILENAME); + icon_path = sc_file_build_path(icon_dir, filename); free(icon_dir); if (!icon_path) { LOG_OOM(); @@ -38,15 +37,14 @@ get_icon_path(void) { } #ifndef PORTABLE - icon_path = - sc_file_build_path(SCRCPY_DEFAULT_ICON_DIR, SCRCPY_ICON_FILENAME); + icon_path = sc_file_build_path(SCRCPY_DEFAULT_ICON_DIR, filename); if (!icon_path) { LOG_OOM(); return NULL; } LOGD("Using icon: %s", icon_path); #else - icon_path = sc_file_get_local_path(SCRCPY_ICON_FILENAME); + icon_path = sc_file_get_local_path(filename); if (!icon_path) { LOGE("Could not get icon path"); return NULL; @@ -183,7 +181,7 @@ to_sdl_pixel_format(enum AVPixelFormat fmt) { } static SDL_Surface * -load_from_path(const char *path) { +sc_icon_load_from_full_path(const char *path) { AVFrame *frame = decode_image(path); if (!frame) { return NULL; @@ -280,19 +278,19 @@ error: } SDL_Surface * -scrcpy_icon_load(void) { - char *icon_path = get_icon_path(); +sc_icon_load(const char *filename) { + char *icon_path = get_icon_path(filename); if (!icon_path) { return NULL; } - SDL_Surface *icon = load_from_path(icon_path); + SDL_Surface *icon = sc_icon_load_from_full_path(icon_path); free(icon_path); return icon; } void -scrcpy_icon_destroy(SDL_Surface *icon) { +sc_icon_destroy(SDL_Surface *icon) { SDL_PropertiesID props = SDL_GetSurfaceProperties(icon); assert(props); AVFrame *frame = SDL_GetPointerProperty(props, "sc_frame", NULL); diff --git a/app/src/icon.h b/app/src/icon.h index 21fbc548..48817f37 100644 --- a/app/src/icon.h +++ b/app/src/icon.h @@ -5,10 +5,12 @@ #include +#define SC_ICON_FILENAME_SCRCPY "scrcpy.png" + SDL_Surface * -scrcpy_icon_load(void); +sc_icon_load(const char *filename); void -scrcpy_icon_destroy(SDL_Surface *icon); +sc_icon_destroy(SDL_Surface *icon); #endif diff --git a/app/src/screen.c b/app/src/screen.c index c42f0b05..f45f250a 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -410,7 +410,7 @@ sc_screen_init(struct sc_screen *screen, goto error_destroy_texture; } - SDL_Surface *icon = scrcpy_icon_load(); + SDL_Surface *icon = sc_icon_load(SC_ICON_FILENAME_SCRCPY); if (icon) { if (!SDL_SetWindowIcon(screen->window, icon)) { LOGW("Could not set window icon: %s", SDL_GetError()); @@ -425,7 +425,7 @@ sc_screen_init(struct sc_screen *screen, } } - scrcpy_icon_destroy(icon); + sc_icon_destroy(icon); } else { // not fatal LOGE("Could not load icon"); diff --git a/app/src/usb/screen_otg.c b/app/src/usb/screen_otg.c index 7ebe4e9f..02c04b4d 100644 --- a/app/src/usb/screen_otg.c +++ b/app/src/usb/screen_otg.c @@ -74,7 +74,7 @@ sc_screen_otg_init(struct sc_screen_otg *screen, goto error_destroy_renderer; } - SDL_Surface *icon = scrcpy_icon_load(); + SDL_Surface *icon = sc_icon_load(SC_ICON_FILENAME_SCRCPY); if (icon) { bool ok = SDL_SetWindowIcon(screen->window, icon); if (!ok) { @@ -82,7 +82,7 @@ sc_screen_otg_init(struct sc_screen_otg *screen, } ok = sc_texture_set_from_surface(&screen->tex, icon); - scrcpy_icon_destroy(icon); + sc_icon_destroy(icon); if (!ok) { LOGE("Could not set icon: %s", SDL_GetError()); }