[gimp] Set required variables if is running from Apple application bundle
- From: Alex Samorukov <asamorukov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Set required variables if is running from Apple application bundle
- Date: Sun, 3 Nov 2019 14:07:54 +0000 (UTC)
commit 12bc46ce14efa9ea9125068edacd1bf1802f6c79
Author: Oleksii Samorukov <samm os2 kiev ua>
Date: Sun Nov 3 15:07:46 2019 +0100
Set required variables if is running from Apple application bundle
(cherry picked with small changes from commit
e13e7fd8b6a40a96a35cea8015fd90f49aa4b9b0)
app/main.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 105 insertions(+)
---
diff --git a/app/main.c b/app/main.c
index 3bc75cadf7..7fb4fdbe2e 100644
--- a/app/main.c
+++ b/app/main.c
@@ -38,6 +38,12 @@
#endif /* G_OS_WIN32 */
+#if defined(ENABLE_RELOCATABLE_RESOURCES) && defined(__APPLE__)
+#include <sys/param.h> /* PATH_MAX */
+#include <libgen.h> /* dirname */
+#include <sys/stat.h>
+#endif /* __APPLE__ */
+
#ifndef GIMP_CONSOLE_COMPILATION
#include <gdk/gdk.h>
#else
@@ -298,6 +304,86 @@ static const GOptionEntry main_entries[] =
{ NULL }
};
+#if defined(ENABLE_RELOCATABLE_RESOURCES) && defined(__APPLE__)
+static void
+gimp_macos_setenv (const char * progname)
+{
+ /* helper to set environment variables for GIMP to be relocatable.
+ * Due to the latest changes it is not recommended to set it in the shell
+ * wrapper anymore.
+ */
+ gchar resolved_path[PATH_MAX];
+ /* on some OSX installations open file limit is 256 and GIMP needs more */
+ struct rlimit limit;
+ limit.rlim_cur = 10000;
+ limit.rlim_max = 10000;
+ setrlimit (RLIMIT_NOFILE, &limit);
+ if (realpath (progname, resolved_path) && !g_getenv ("GIMP_NO_WRAPPER"))
+ {
+ /* set path to the app folder to make sure that our python is called
+ * instead of system one
+ */
+ static gboolean show_playground = TRUE;
+
+ gchar *path;
+ gchar tmp[PATH_MAX];
+ gchar *app_dir;
+ gchar res_dir[PATH_MAX];
+ size_t path_len;
+ struct stat sb;
+
+ app_dir = g_path_get_dirname (resolved_path);
+ g_snprintf (tmp, sizeof(tmp), "%s/../Resources", app_dir);
+ if (realpath (tmp, res_dir) && !stat (res_dir,&sb) && S_ISDIR (sb.st_mode))
+ g_print ("GIMP is started as MacOS application\n");
+ else
+ return;
+
+ path_len = strlen (g_getenv ("PATH") ? g_getenv ("PATH") : "") + strlen (app_dir) + 2;
+ path = g_try_malloc (path_len);
+ if (path == NULL)
+ {
+ g_warning ("Failed to allocate memory");
+ app_exit (EXIT_FAILURE);
+ }
+ if (g_getenv ("PATH"))
+ g_snprintf (path, path_len, "%s:%s", app_dir, g_getenv ("PATH"));
+ else
+ g_snprintf (path, path_len, "%s", app_dir);
+ g_free (app_dir);
+ g_setenv ("PATH", path, TRUE);
+ g_free (path);
+ g_snprintf (tmp, sizeof(tmp), "%s/lib/gtk-3.0/3.0.0", res_dir);
+ g_setenv ("GTK_PATH", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s/etc/gtk-3.0/gtk.immodules", res_dir);
+ g_setenv ("GTK_IM_MODULE_FILE", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s/lib/gegl-0.4", res_dir);
+ g_setenv ("GEGL_PATH", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s/lib/babl-0.1", res_dir);
+ g_setenv ("BABL_PATH", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache", res_dir);
+ g_setenv ("GDK_PIXBUF_MODULE_FILE", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s/etc/fonts", res_dir);
+ g_setenv ("FONTCONFIG_PATH", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s", res_dir);
+ g_setenv ("PYTHONHOME", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s/lib/python2.7:%s/lib/gimp/2.0/python", res_dir, res_dir);
+ g_setenv ("PYTHONPATH", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s/lib/gio/modules", res_dir);
+ g_setenv ("GIO_MODULE_DIR", tmp, TRUE);
+ g_snprintf (tmp, sizeof(tmp), "%s/share/libwmf/fonts", res_dir);
+ g_setenv ("WMF_FONTDIR", tmp, TRUE);
+ if (g_getenv ("HOME")!=NULL)
+ {
+ g_snprintf (tmp, sizeof(tmp),
+ "%s/Library/Application Support/GIMP/3.00/cache",
+ g_getenv("HOME"));
+ g_setenv ("XDG_CACHE_HOME", tmp, TRUE);
+ }
+ }
+}
+#endif
+
int
main (int argc,
char **argv)
@@ -314,6 +400,25 @@ main (int argc,
#ifdef ENABLE_WIN32_DEBUG_CONSOLE
gimp_open_console_window ();
#endif
+#if defined(ENABLE_RELOCATABLE_RESOURCES) && defined(__APPLE__)
+ /* remove MacOS session identifier from the command line args */
+ gint newargc = 0;
+ for (gint i = 0; i < argc; i++)
+ {
+ if (!g_str_has_prefix (argv[i], "-psn_"))
+ {
+ argv[newargc] = argv[i];
+ newargc++;
+ }
+ }
+ if (argc > newargc)
+ {
+ argv[newargc] = NULL; /* glib expects NULL terminated array */
+ argc = newargc;
+ }
+
+ gimp_macos_setenv (argv[0]);
+#endif
#if defined (__GNUC__) && defined (_WIN64)
/* mingw-w64, at least the unstable build from late July 2008,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]