Skip to content

Display and control your Android device

Add filename parameter to icon loading

Romain Vimont6ca1b79228e7
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 <SDL3/SDL_surface.h>
+#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 d50b670f..6a6d8eb5 100644
--- a/app/src/screen.c
+++ b/app/src/screen.c
@@ -477,7 +477,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());
@@ -492,7 +492,7 @@ sc_screen_init(struct sc_screen *screen,
}
}
- scrcpy_icon_destroy(icon);
+ sc_icon_destroy(icon);
} else {
// not fatal
LOGE("Could not load icon");