cutils: Introduce bundle mechanism
Subsystems (2)
PATCH 1/4 cutils: Introduce bundle mechanism
Developers often run QEMU without installing. The bundle mechanism allows to look up files which should be present in installation even in such a situation.
--- include/qemu/cutils.h | 19 +++++++++++++++++++ util/cutils.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
include/qemu/cutils.h +19 -0
@@ -209,4 +209,23 @@ int qemu_pstrcmp0(const char **str1, const char **str2);*/ char *get_relocated_path (const char *dir); +/** +* find_bundle: +* @path: Relative path +* +* Returns a path for the specified directory or file bundled in QEMU. It uses +* the directory of the running executable as the prefix first. See +* get_relocated_path() for the details. The next candidate is "qemu-bundle" +* directory in the directory of the running executable. "qemu-bundle" +* directory is typically present in the build tree. +* +* The returned string should be freed by the caller. +* +* Returns: a path that can access the bundle, or NULL if no matching bundle +* exists. +*/ +char *find_bundle (const char *path); + +void list_bundle_candidates (const char *path); +#endif
util/cutils.c +33 -0
@@ -1057,3 +1057,36 @@ char *get_relocated_path(const char *dir) }return g_string_free (result, false); } + +static const char *const bundle_formats[] = { +"%s" G_DIR_SEPARATOR_S ".." G_DIR_SEPARATOR_S "%s" , +"%s" G_DIR_SEPARATOR_S "qemu-bundle" G_DIR_SEPARATOR_S "%s" +}; + +char *find_bundle (const char *path) +{ +const char *dir =qemu_get_exec_dir (); +char *candidate; +int i; + +for (i =0 ; i <ARRAY_SIZE (bundle_formats); i++) { + candidate =g_strdup_printf (bundle_formats[i], dir, path); +if (access (candidate,R_OK ) ==0 ) { +return candidate; + } +g_free (candidate); + } + +return NULL ; +} + +void list_bundle_candidates (const char *path) +{ +const char *dir =qemu_get_exec_dir (); +int i; + +for (i =0 ; i <ARRAY_SIZE (bundle_formats); i++) { +printf (bundle_formats[i], dir, path); +putc ('\n' , stdout); + } +}
Signature · 1 line
2.30.1 (Apple Git-130)
PATCH 2/4 datadir: Use bundle mechanism
bundle mechanism and softmmu/datadir.c provides some overlapped functionality. Use bundle mechanism in softmmu/datadir.c to remove the redundancy.
--- configure | 2 ++ meson.build | 2 +- softmmu/datadir.c | 35 ++++++++++++----------------------- 3 files changed, 15 insertions(+), 24 deletions(-)
configure +2 -0
@@ -5058,6 +5058,8 @@ for f in $UNLINK ; do fi done +symlink ../../pc-bios qemu-bundle/share/qemu + (for i in $cross_cc_vars; do export $i done
meson.build +1 -1
@@ -1197,7 +1197,7 @@ endif config_host_data.set_quoted('CONFIG_BINDIR', get_option('prefix') / get_option('bindir')) config_host_data.set_quoted('CONFIG_PREFIX', get_option('prefix')) config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / qemu_confdir) -config_host_data.set_quoted('CONFIG_QEMU_DATADIR', get_option('prefix') / qemu_datadir) +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'))
softmmu/datadir.c +12 -23
@@ -36,6 +36,7 @@ char *qemu_find_file(int type, const char *name)int i;const char *subdir;char *buf; +char *bundle;/* Try the name as a straight path first */ if (access (name,R_OK ) ==0 ) {
@@ -62,6 +63,16 @@ char *qemu_find_file(int type, const char *name) }g_free (buf); } + + bundle =g_strdup_printf ("%s/%s%s" , +CONFIG_QEMU_BUNDLE_DATADIR , subdir, name); + buf =find_bundle (bundle); +g_free (bundle); +if (buf) { +trace_load_file (name, buf); +return buf; + } +return NULL ; }
@@ -84,26 +95,6 @@ void qemu_add_data_dir(char *path) data_dir[data_dir_idx++] = path; } -/* -* Find a likely location for support files using the location of the binary. -* When running from the build tree this will be "$bindir/pc-bios". -* Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated). -* -* The caller must use g_free() to free the returned data when it is -* no longer required. -*/ -static char *find_datadir (void ) -{ - g_autofree char *dir = NULL; - - dir =g_build_filename (qemu_get_exec_dir (),"pc-bios" ,NULL ); -if (g_file_test (dir,G_FILE_TEST_IS_DIR )) { -return g_steal_pointer (&dir); - } - -return get_relocated_path (CONFIG_QEMU_DATADIR ); -} -void qemu_add_default_firmwarepath (void ) {char **dirs;
@@ -115,9 +106,6 @@ void qemu_add_default_firmwarepath(void)qemu_add_data_dir (get_relocated_path (dirs[i])); }g_strfreev (dirs); - -/* try to find datadir relative to the executable path */ -qemu_add_data_dir (find_datadir ()); }void qemu_list_data_dirs (void )
@@ -126,4 +114,5 @@ void qemu_list_data_dirs(void)for (i =0 ; i < data_dir_idx; i++) {printf ("%s\n" , data_dir[i]); } +list_bundle_candidates (CONFIG_QEMU_BUNDLE_DATADIR ); }
Signature · 1 line
2.30.1 (Apple Git-130)
PATCH 3/4 ui/icons: Use bundle mechanism
In reply to Akihiko Odaki--- configure | 10 ++++++++++ meson.build | 3 +-- ui/cocoa.m | 20 +++++++++++--------- ui/gtk.c | 8 +++++--- ui/sdl2.c | 18 +++++++++++------- 5 files changed, 38 insertions(+), 21 deletions(-)
configure +10 -0
@@ -5058,6 +5058,16 @@ for f in $UNLINK ; 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
meson.build +1 -2
@@ -1200,8 +1200,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)
ui/cocoa.m +11 -9
@@ -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];
ui/gtk.c +5 -3
@@ -2198,9 +2198,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 );
ui/sdl2.c +11 -7
@@ -877,15 +877,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);
Signature · 1 line
2.30.1 (Apple Git-130)
Re: [PATCH 3/4] ui/icons: Use bundle mechanism
Quoted 131 lines · Akihiko Odaki
Signed-off-by Akihiko Odaki <[email protected]>---
configure | 10 ++++++++++ meson.build | 3 +-- ui/cocoa.m | 20 +++++++++++--------- ui/gtk.c | 8 +++++--- ui/sdl2.c | 18 +++++++++++------- 5 files changed, 38 insertions(+), 21 deletions(-)configure +0
-0@@ -5058,6 +5058,16 @@ for f in $UNLINK ; do fidone
configure +10
-0+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.svgsymlink ../../pc-bios qemu-bundle/share/qemu
(for i in $cross_cc_vars; do
meson.build +1
-2@@ -1200,8 +1200,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)ui/cocoa.m +11
-9@@ -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];ui/gtk.c +5
-3@@ -2198,9 +2198,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 );ui/sdl2.c +11
-7@@ -877,15 +877,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);Signature · 1 line
2.30.1 (Apple Git-130)
This is a lot of code for just loading an icon. I think it would be best to simply revert commit e31746ecf8dd2f25f687c94ac14016a3ba5debfc instead.
Thank you.
Re: [PATCH 3/4] ui/icons: Use bundle mechanism
Hi,
Reverting commit e31746ecf8dd2f25f687c94ac14016a3ba5debfc solves the problem only for cocoa and introduces another problem. (For others:
see https://lore.kernel.org/qemu-devel/[email protected]/
for the context.) The fix for cocoa basically comes for free if you
fix the problem for other displays, and that's what this patch does.
Honestly I don't really like the nature of the code in the "configure" script. It is a duplicate of ui/icons/meson.build and people may overlook it when updating ui/icons/meson.build. I blindly followed what the script does for pc-bios, but I can improve it for icons and pc-bios by moving the responsibility to meson if it makes sense.
Regards,
Akihiko Odaki
Quoted 137 lines · Programmingkid
Quoted 130 lines · Akihiko Odaki
Signed-off-by Akihiko Odaki <[email protected]>---
configure | 10 ++++++++++ meson.build | 3 +-- ui/cocoa.m | 20 +++++++++++--------- ui/gtk.c | 8 +++++--- ui/sdl2.c | 18 +++++++++++------- 5 files changed, 38 insertions(+), 21 deletions(-)configure +0
-0@@ -5058,6 +5058,16 @@ for f in $UNLINK ; do fidone
configure +10
-0+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.svgsymlink ../../pc-bios qemu-bundle/share/qemu
(for i in $cross_cc_vars; do
meson.build +1
-2@@ -1200,8 +1200,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)ui/cocoa.m +11
-9@@ -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];ui/gtk.c +5
-3@@ -2198,9 +2198,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 );ui/sdl2.c +11
-8@@ -877,15 +877,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); --Quoted 2 lines
2.30.1 (Apple Git-130)
This is a lot of code for just loading an icon. I think it would be best to simply revert commit
e31746ecf8dd2f25f687c94ac14016a3ba5debfcinstead.Thank you.
Re: [PATCH 3/4] ui/icons: Use bundle mechanism
Quoted 10 lines · Akihiko Odaki
Hi,
Reverting commit
e31746ecf8dd2f25f687c94ac14016a3ba5debfcsolves the problem only for cocoa and introduces another problem. (For others:
see https://lore.kernel.org/qemu-devel/[email protected]/
for the context.)
What is the other problem that reverting the commit causes?
Quoted 2 lines
The fix for cocoa basically comes for free if you
fix the problem for other displays, and that's what this patch does.
That may be true but it also introduces the problem of having to keep track of a picture file. With the original code there is no external picture file needed.
Quoted 139 lines · Programmingkid
Quoted 137 lines
Quoted 130 lines · Akihiko Odaki
Signed-off-by Akihiko Odaki <[email protected]>---
configure | 10 ++++++++++ meson.build | 3 +-- ui/cocoa.m | 20 +++++++++++--------- ui/gtk.c | 8 +++++--- ui/sdl2.c | 18 +++++++++++------- 5 files changed, 38 insertions(+), 21 deletions(-)configure +0
-0@@ -5058,6 +5058,16 @@ for f in $UNLINK ; do fidone
configure +10
-0+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.svgsymlink ../../pc-bios qemu-bundle/share/qemu
(for i in $cross_cc_vars; do
meson.build +1
-2@@ -1200,8 +1200,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)ui/cocoa.m +11
-9@@ -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];ui/gtk.c +5
-3@@ -2198,9 +2198,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 );ui/sdl2.c +11
-8@@ -877,15 +877,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); --Quoted 2 lines
2.30.1 (Apple Git-130)
This is a lot of code for just loading an icon. I think it would be best to simply revert commit
e31746ecf8dd2f25f687c94ac14016a3ba5debfcinstead.Thank you.
PATCH 4/4 net: Use bundle mechanism
In reply to Akihiko Odaki--- configure | 1 + include/net/net.h | 2 +- meson.build | 1 + net/tap.c | 6 +++++- qemu-options.hx | 4 ++-- 5 files changed, 10 insertions(+), 4 deletions(-)
configure +1 -0
@@ -5069,6 +5069,7 @@ done symlink $source_path/ui/icons/qemu.svg qemu-bundle/share/icons/hicolor/scalable/apps/qemu.svg symlink ../../pc-bios qemu-bundle/share/qemu +symlink ../../qemu-bridge-helper qemu-bundle/libexec/qemu-bridge-helper (for i in $cross_cc_vars; do export $i
include/net/net.h +1 -1
@@ -221,7 +221,7 @@ NetClientState *net_hub_port_find(int hub_id);#define DEFAULT_NETWORK_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifup"#define DEFAULT_NETWORK_DOWN_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifdown" -#define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper" +#define DEFAULT_BUNDLE_BRIDGE_HELPER CONFIG_QEMU_BUNDLE_HELPERDIR "/qemu-bridge-helper"#define DEFAULT_BRIDGE_INTERFACE "br0"void qdev_set_nic_properties (DeviceState *dev,NICInfo *nd);
meson.build +1 -0
@@ -1200,6 +1200,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_BUNDLE_HELPERDIR', get_option('libexecdir')) 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'))
net/tap.c +5 -1
@@ -508,7 +508,11 @@ static int net_bridge_run_helper(const char *helper, const char *bridge,sigprocmask (SIG_BLOCK , &mask, &oldmask);if (!helper) { - helper = default_helper =get_relocated_path (DEFAULT_BRIDGE_HELPER ); + helper = default_helper =find_bundle (DEFAULT_BUNDLE_BRIDGE_HELPER ); +if (!helper) { +error_setg (errp,"birdge helper not found" ); +return -1 ; + } }if (socketpair (PF_UNIX ,SOCK_STREAM ,0 , sv) ==-1 ) {
qemu-options.hx +2 -2
@@ -2528,7 +2528,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, " to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n" " to deconfigure it\n" " use '[down]script=no' to disable script execution\n" - " use network helper 'helper' (default=" DEFAULT_BRIDGE_HELPER ") to\n" + " use network helper 'helper' (default=" DEFAULT_BUNDLE_BRIDGE_HELPER ") to\n" " configure it\n" " use 'fd=h' to connect to an already opened TAP interface\n" " use 'fds=x:y:...:z' to connect to already opened multiqueue capable TAP interfaces\n"
@@ -2547,7 +2547,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, "-netdev bridge,id=str[,br=bridge][,helper=helper]\n" " configure a host TAP network backend with ID 'str' that is\n" " connected to a bridge (default=" DEFAULT_BRIDGE_INTERFACE ")\n" - " using the program 'helper (default=" DEFAULT_BRIDGE_HELPER ")\n" + " using the program 'helper (default=" DEFAULT_BUNDLE_BRIDGE_HELPER ")\n" #endif #ifdef __linux__ "-netdev l2tpv3,id=str,src=srcaddr,dst=dstaddr[,srcport=srcport][,dstport=dstport]\n"
Signature · 1 line
2.30.1 (Apple Git-130)