diff -Nru bamf-0.5.3~bzr0+16.10.20160516/debian/changelog bamf-0.5.3~bzr0+16.10.20160602/debian/changelog --- bamf-0.5.3~bzr0+16.10.20160516/debian/changelog 2016-06-02 17:25:30.000000000 +0000 +++ bamf-0.5.3~bzr0+16.10.20160602/debian/changelog 2016-06-02 17:25:30.000000000 +0000 @@ -1,3 +1,10 @@ +bamf (0.5.3~bzr0+16.10.20160602-0ubuntu1) yakkety; urgency=medium + + * BamfMatcher: allow overriding desktop with the environment var + BAMF_DESKTOP_FILE_HINT + + -- Marco Trevisan (TreviƱo) Thu, 02 Jun 2016 01:01:02 +0000 + bamf (0.5.3~bzr0+16.10.20160516-0ubuntu1) yakkety; urgency=medium * bamfdaemon-dbus-runner: don't try to start again if already running diff -Nru bamf-0.5.3~bzr0+16.10.20160516/src/bamf-legacy-window.c bamf-0.5.3~bzr0+16.10.20160602/src/bamf-legacy-window.c --- bamf-0.5.3~bzr0+16.10.20160516/src/bamf-legacy-window.c 2016-05-16 10:44:36.000000000 +0000 +++ bamf-0.5.3~bzr0+16.10.20160602/src/bamf-legacy-window.c 2016-06-02 01:00:35.000000000 +0000 @@ -194,7 +194,7 @@ pid = bamf_legacy_window_get_pid (self); - if (pid <= 0) + if (pid < 2) return NULL; stat_path = g_strdup_printf ("/proc/%i/status", pid); diff -Nru bamf-0.5.3~bzr0+16.10.20160516/src/bamf-matcher.c bamf-0.5.3~bzr0+16.10.20160602/src/bamf-matcher.c --- bamf-0.5.3~bzr0+16.10.20160516/src/bamf-matcher.c 2016-05-16 10:44:36.000000000 +0000 +++ bamf-0.5.3~bzr0+16.10.20160602/src/bamf-matcher.c 2016-06-02 01:00:35.000000000 +0000 @@ -30,6 +30,8 @@ #include #define BAMF_INDEX_NAME "bamf-2.index" +#define EXEC_DESKTOP_FILE_OVERRIDE "--desktop_file_hint" +#define ENV_DESKTOP_FILE_OVERRIDE "BAMF_DESKTOP_FILE_HINT" G_DEFINE_TYPE (BamfMatcher, bamf_matcher, BAMF_DBUS_TYPE_MATCHER_SKELETON); #define BAMF_MATCHER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \ @@ -79,8 +81,6 @@ "com-sun-javaws-Main", "VCLSalFrame" }; -const gchar * EXEC_DESKTOP_FILE_OVERRIDE = "--desktop_file_hint"; - static void on_view_active_changed (BamfView *view, gboolean active, BamfMatcher *matcher) { @@ -556,6 +556,49 @@ return result; } +char * +get_env_overridden_desktop_file (guint pid) +{ + gchar *environ_file; + gchar *environ; + gchar *result; + gsize file_len; + gint i; + + if (pid < 2) + return NULL; + + environ = NULL; + result = NULL; + environ_file = g_strdup_printf ("/proc/%u/environ", pid); + + if (g_file_get_contents (environ_file, &environ, &file_len, NULL)) + { + for (i = 0; i < file_len && environ && environ[i] != '\0'; i += strlen (environ + i) + 1) + { + const gchar *var = environ + i; + + if (g_str_has_prefix (var, ENV_DESKTOP_FILE_OVERRIDE"=")) + { + const gchar *file_path; + file_path = var + sizeof (ENV_DESKTOP_FILE_OVERRIDE); + + if (g_str_has_suffix (file_path, ".desktop") && + g_file_test (file_path, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR)) + { + result = g_strdup (file_path); + break; + } + } + } + } + + g_free (environ); + g_free (environ_file); + + return result; +} + static GList * pid_parent_tree (BamfMatcher *self, guint pid) { @@ -1670,8 +1713,17 @@ g_free (desktop_file); } } - else + + if (!desktop_files) { + gint pid = bamf_legacy_window_get_pid (window); + desktop_file = get_env_overridden_desktop_file (pid); + + if (desktop_file) + { + desktop_files = g_list_prepend (desktop_files, desktop_file); + } + const char *exec_string = bamf_legacy_window_get_exec_string (window); desktop_file = get_exec_overridden_desktop_file (exec_string); @@ -1679,7 +1731,8 @@ { desktop_files = g_list_prepend (desktop_files, desktop_file); } - else + + if (!desktop_files) { app_id = bamf_legacy_window_get_hint (window, _GTK_APPLICATION_ID);