From 9cce7d263ea3f2984a619cdfcb54d264c6a4c51d Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 5 Nov 2024 01:29:53 +0300 Subject: fully support relocatable binaries, improving AppImages * You can now specify `--with-scitecodatadir` as a relative path, that will be interpreted relative to the binary's location. * Win32 binaries already were relocatable, but this was a Windows-specific hack. Win32 binaries are now built with `--with-scitecodatadir=.` since everything is in a single directory. * Ubuntu packages are now also built `--with-scitecodatadir=../share/sciteco`. This is not crucial for ordinary installations, but is meant for AppImage creation. * Since AppImages are now built from relocatable packages, we no longer need the unionfs-workaround from pkg2appimage. This should fix the strange root contents when autocompleting in AppImage builds. * This might also fix the appimage.github.io CI issues. I assume that because I could reproduce the issue on FreeBSD's Linuxulator in dependence of pkg2appimage's "union"-setting. See https://github.com/AppImage/appimage.github.io/pull/3402 * Determining the binary location actually turned out be hard and very platform-dependant. There are now implementations for Windows (which could also read argv[0]), Linux and generic UNIX (which works on FreeBSD, but I am not sure about the others). I believe this could also be useful on Mac OS to create app bundles, but this needs to be tested - currently the Mac OS binaries are installed into fixed locations and don't use relocation. --- src/interface-gtk/interface.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'src/interface-gtk/interface.c') diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c index 3121b05..829310a 100644 --- a/src/interface-gtk/interface.c +++ b/src/interface-gtk/interface.c @@ -51,6 +51,7 @@ #include "sciteco.h" #include "error.h" #include "string-utils.h" +#include "file-utils.h" #include "cmdline.h" #include "qreg.h" #include "ring.h" @@ -1124,6 +1125,8 @@ teco_interface_event_loop(GError **error) } g_assert(scitecoconfig.data != NULL); + g_autofree gchar *datadir = teco_file_get_datadir(); + /* * Initialize the CSS variable provider and the CSS provider * for the included fallback.css. @@ -1138,14 +1141,7 @@ teco_interface_event_loop(GError **error) if (!g_file_test(user_css_file, G_FILE_TEST_IS_REGULAR)) { /* use fallback CSS */ g_free(user_css_file); - /* - * FIXME: See above for icons. - */ -#ifdef G_OS_WIN32 - user_css_file = g_build_filename(scitecoconfig.data, "fallback.css", NULL); -#else - user_css_file = g_build_filename(SCITECODATADIR, "fallback.css", NULL); -#endif + user_css_file = g_build_filename(datadir, "fallback.css", NULL); } GtkCssProvider *user_css_provider = gtk_css_provider_new(); @@ -1170,15 +1166,10 @@ teco_interface_event_loop(GError **error) /* * FIXME: This is necessary so that the icon themes are found in the same * directory as sciteco.exe. - * This fails of course when $SCITECOCONFIG is changed. - * We should perhaps always use the absolute path of sciteco.exe. - * If you want to install SciTECO differently, you can still set - * $XDG_DATA_DIRS. - * - * FIXME FIXME FIXME: This is also currently broken. */ - //g_autofree char *theme_path = g_build_filename(scitecoconfig.data, "icons"); - //gtk_icon_theme_prepend_search_path(gtk_icon_theme_get_default(), theme_path); + g_autofree gchar *program_path = teco_file_get_program_path(); + g_autofree gchar *theme_path = g_build_filename(program_path, "icons", NULL); + gtk_icon_theme_prepend_search_path(gtk_icon_theme_get_default(), theme_path); #else /* * Load icons for the GTK window. @@ -1186,17 +1177,16 @@ teco_interface_event_loop(GError **error) * as a resource will be used by default. */ static const gchar *icon_files[] = { - SCITECODATADIR G_DIR_SEPARATOR_S "sciteco-48.png", - SCITECODATADIR G_DIR_SEPARATOR_S "sciteco-32.png", - SCITECODATADIR G_DIR_SEPARATOR_S "sciteco-16.png" + "sciteco-48.png", "sciteco-32.png", "sciteco-16.png" }; GList *icon_list = NULL; for (gint i = 0; i < G_N_ELEMENTS(icon_files); i++) { - GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_file(icon_files[i], NULL); + g_autofree gchar *icon_file = g_build_filename(datadir, icon_files[i], NULL); + GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_file(icon_file, NULL); /* fail silently if there's a problem with one of the icons */ - if (icon_pixbuf) + if (G_LIKELY(icon_pixbuf != NULL)) icon_list = g_list_append(icon_list, icon_pixbuf); } -- cgit v1.2.3