diff mbox series

[v2,3/4] ui/icons: Use bundle mechanism

Message ID 20220226124535.76885-4-akihiko.odaki@gmail.com (mailing list archive)
State New, archived
Headers show
Series cutils: Introduce bundle mechanism | expand

Commit Message

Akihiko Odaki Feb. 26, 2022, 12:45 p.m. UTC
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 configure   | 10 ++++++++++
 meson.build |  3 +--
 ui/cocoa.m  | 20 +++++++++++---------
 ui/gtk.c    |  8 +++++---
 ui/sdl2.c   | 18 +++++++++++-------
 5 files changed, 38 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/configure b/configure
index fda1a35cbc0..80d36a85bc5 100755
--- a/configure
+++ b/configure
@@ -3089,6 +3089,16 @@  for f in $LINKS ; do
     fi
 done
 
+for icon_extension in bmp png ; do
+  for icon_file in $source_path/ui/icons/qemu_*.$icon_extension ; do
+    icon_basename=${icon_file%.$icon_extension}
+    icon_name=${icon_basename#$source_path/ui/icons/qemu_}
+    icon_dir=qemu-bundle/share/icons/hicolor/$icon_name/apps
+    symlink $icon_file $icon_dir/qemu.$icon_extension
+  done
+done
+
+symlink $source_path/ui/icons/qemu.svg qemu-bundle/share/icons/hicolor/scalable/apps/qemu.svg
 symlink ../../pc-bios qemu-bundle/share/qemu
 
 (for i in $cross_cc_vars; do
diff --git a/meson.build b/meson.build
index a2c987b41d6..f7e64a74545 100644
--- a/meson.build
+++ b/meson.build
@@ -1472,8 +1472,7 @@  config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / qemu_c
 config_host_data.set_quoted('CONFIG_QEMU_BUNDLE_DATADIR', qemu_datadir)
 config_host_data.set_quoted('CONFIG_QEMU_DESKTOPDIR', get_option('prefix') / qemu_desktopdir)
 config_host_data.set_quoted('CONFIG_QEMU_FIRMWAREPATH', get_option('qemu_firmwarepath'))
-config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('prefix') / get_option('libexecdir'))
-config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', get_option('prefix') / qemu_icondir)
+config_host_data.set_quoted('CONFIG_QEMU_BUNDLE_ICONDIR', qemu_icondir)
 config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('prefix') / get_option('localedir'))
 config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', get_option('prefix') / get_option('localstatedir'))
 config_host_data.set_quoted('CONFIG_QEMU_MODDIR', get_option('prefix') / qemu_moddir)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index a8f1cdaf926..e5e49c50fbb 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1477,15 +1477,17 @@  - (void)make_about_window
     NSRect picture_rect = NSMakeRect(x, y, picture_width, picture_height);
 
     /* Make the picture of QEMU */
-    NSImageView *picture_view = [[NSImageView alloc] initWithFrame:
-                                                     picture_rect];
-    char *qemu_image_path_c = get_relocated_path(CONFIG_QEMU_ICONDIR "/hicolor/512x512/apps/qemu.png");
-    NSString *qemu_image_path = [NSString stringWithUTF8String:qemu_image_path_c];
-    g_free(qemu_image_path_c);
-    NSImage *qemu_image = [[NSImage alloc] initWithContentsOfFile:qemu_image_path];
-    [picture_view setImage: qemu_image];
-    [picture_view setImageScaling: NSImageScaleProportionallyUpOrDown];
-    [superView addSubview: picture_view];
+    char *qemu_image_path_c = find_bundle(CONFIG_QEMU_BUNDLE_ICONDIR "/hicolor/512x512/apps/qemu.png");
+    if (qemu_image_path_c) {
+        NSString *qemu_image_path = [NSString stringWithUTF8String:qemu_image_path_c];
+        g_free(qemu_image_path_c);
+        NSImageView *picture_view = [[NSImageView alloc] initWithFrame:
+                                                         picture_rect];
+        NSImage *qemu_image = [[NSImage alloc] initWithContentsOfFile:qemu_image_path];
+        [picture_view setImage: qemu_image];
+        [picture_view setImageScaling: NSImageScaleProportionallyUpOrDown];
+        [superView addSubview: picture_view];
+    }
 
     /* Make the name label */
     NSBundle *bundle = [NSBundle mainBundle];
diff --git a/ui/gtk.c b/ui/gtk.c
index a8567b9ddc8..a86d1c126f0 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2296,9 +2296,11 @@  static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     s->opts = opts;
 
     theme = gtk_icon_theme_get_default();
-    dir = get_relocated_path(CONFIG_QEMU_ICONDIR);
-    gtk_icon_theme_prepend_search_path(theme, dir);
-    g_free(dir);
+    dir = find_bundle(CONFIG_QEMU_BUNDLE_ICONDIR);
+    if (dir) {
+        gtk_icon_theme_prepend_search_path(theme, dir);
+        g_free(dir);
+    }
     g_set_prgname("qemu");
 
     s->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 46a252d7d9d..9d1f6e74cb5 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -893,15 +893,19 @@  static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
     }
 
 #ifdef CONFIG_SDL_IMAGE
-    dir = get_relocated_path(CONFIG_QEMU_ICONDIR "/hicolor/128x128/apps/qemu.png");
-    icon = IMG_Load(dir);
+    dir = find_bundle(CONFIG_QEMU_BUNDLE_ICONDIR "/hicolor/128x128/apps/qemu.png");
+    if (dir) {
+        icon = IMG_Load(dir);
+    }
 #else
     /* Load a 32x32x4 image. White pixels are transparent. */
-    dir = get_relocated_path(CONFIG_QEMU_ICONDIR "/hicolor/32x32/apps/qemu.bmp");
-    icon = SDL_LoadBMP(dir);
-    if (icon) {
-        uint32_t colorkey = SDL_MapRGB(icon->format, 255, 255, 255);
-        SDL_SetColorKey(icon, SDL_TRUE, colorkey);
+    dir = find_bundle(CONFIG_QEMU_BUNDLE_ICONDIR "/hicolor/32x32/apps/qemu.bmp");
+    if (dir) {
+        icon = SDL_LoadBMP(dir);
+        if (icon) {
+            uint32_t colorkey = SDL_MapRGB(icon->format, 255, 255, 255);
+            SDL_SetColorKey(icon, SDL_TRUE, colorkey);
+        }
     }
 #endif
     g_free(dir);