qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v4 3/4] ui/icons: Use bundle mechanism


From: Akihiko Odaki
Subject: [PATCH v4 3/4] ui/icons: Use bundle mechanism
Date: Wed, 15 Jun 2022 06:07:45 +0900

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 meson.build          |  2 +-
 ui/cocoa.m           | 29 ++++++++++++++++-------------
 ui/gtk.c             |  6 +++++-
 ui/icons/meson.build | 36 ++++++++++++++++++++++++++++--------
 ui/sdl2.c            | 18 +++++++++++-------
 5 files changed, 61 insertions(+), 30 deletions(-)

diff --git a/meson.build b/meson.build
index c573815813f..e7b385eaf34 100644
--- a/meson.build
+++ b/meson.build
@@ -1687,7 +1687,7 @@ 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('prefix') / 
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 84c84e98fc5..bd8a3211d3b 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1562,21 +1562,24 @@ - (BOOL)verifyQuit
 - (IBAction) do_about_menu_item: (id) sender
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    char *icon_path_c = get_relocated_path(CONFIG_QEMU_ICONDIR 
"/hicolor/512x512/apps/qemu.png");
-    NSString *icon_path = [NSString stringWithUTF8String:icon_path_c];
-    g_free(icon_path_c);
-    NSImage *icon = [[NSImage alloc] initWithContentsOfFile:icon_path];
+    char *icon_path_c = find_bundle(CONFIG_QEMU_BUNDLE_ICONDIR 
"/hicolor/512x512/apps/qemu.png");
     NSString *version = @"QEMU emulator version " QEMU_FULL_VERSION;
     NSString *copyright = @QEMU_COPYRIGHT;
-    NSDictionary *options;
-    if (icon) {
-        options = @{
-            NSAboutPanelOptionApplicationIcon : icon,
-            NSAboutPanelOptionApplicationVersion : version,
-            @"Copyright" : copyright,
-        };
-        [icon release];
-    } else {
+    NSDictionary *options = nil;
+    if (icon_path_c) {
+        NSString *icon_path = [NSString stringWithUTF8String:icon_path_c];
+        g_free(icon_path_c);
+        NSImage *icon = [[NSImage alloc] initWithContentsOfFile:icon_path];
+        if (icon) {
+            options = @{
+                NSAboutPanelOptionApplicationIcon : icon,
+                NSAboutPanelOptionApplicationVersion : version,
+                @"Copyright" : copyright,
+            };
+            [icon release];
+        }
+    }
+    if (!options) {
         options = @{
             NSAboutPanelOptionApplicationVersion : version,
             @"Copyright" : copyright,
diff --git a/ui/gtk.c b/ui/gtk.c
index 2a791dd2aa0..8f7afe795f4 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2321,7 +2321,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);
+    dir = find_bundle(CONFIG_QEMU_BUNDLE_ICONDIR);
+    if (dir) {
+        gtk_icon_theme_prepend_search_path(theme, dir);
+        g_free(dir);
+    }
     gtk_icon_theme_prepend_search_path(theme, dir);
     g_free(dir);
     g_set_prgname("qemu");
diff --git a/ui/icons/meson.build b/ui/icons/meson.build
index 12c52080ebd..23292773074 100644
--- a/ui/icons/meson.build
+++ b/ui/icons/meson.build
@@ -1,13 +1,33 @@
+icons = [
+  {
+    'source': 'qemu_32x32.bmp',
+    'install': 'hicolor' / '32x32' / 'apps' / 'qemu.bmp',
+  },
+  {
+    'source': 'qemu.svg',
+    'install': 'hicolor' / 'scalable' / 'apps' / 'qemu.svg',
+  },
+]
+
 foreach s: [16, 24, 32, 48, 64, 128, 256, 512]
   s = '@0@x@0@'.format(s.to_string())
-  install_data('qemu_@0@.png'.format(s),
-               rename: 'qemu.png',
-               install_dir: qemu_icondir / 'hicolor' / s / 'apps')
+  icons += {
+    'source': 'qemu_@0@.png'.format(s),
+    'install': 'hicolor' / s / 'apps' / 'qemu.png',
+  }
 endforeach
 
-install_data('qemu_32x32.bmp',
-             rename: 'qemu.bmp',
-             install_dir: qemu_icondir / 'hicolor' / '32x32' / 'apps')
+foreach icon: icons
+  source = icon.get('source')
+  install = icon.get('install')
+
+  install_data(source,
+               rename: fs.name(install),
+               install_dir: qemu_icondir / fs.parent(install))
 
-install_data('qemu.svg',
-             install_dir: qemu_icondir / 'hicolor' / 'scalable' / 'apps')
+  run_command('mkdir', '-p', qemu_bundledir / qemu_icondir / 
fs.parent(install),
+              check: true)
+
+  run_command('ln', '-sf', meson.current_source_dir() / source, qemu_bundledir 
/ qemu_icondir / install,
+              check: true)
+endforeach
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 8cb77416af2..bbcb4762e1b 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -910,15 +910,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);
-- 
2.32.1 (Apple Git-133)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]