Merge lp:~3v1n0/bamf/match-envionment-var into lp:bamf

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 638
Merged at revision: 637
Proposed branch: lp:~3v1n0/bamf/match-envionment-var
Merge into: lp:bamf
Diff against target: 112 lines (+58/-5)
2 files modified
src/bamf-legacy-window.c (+1/-1)
src/bamf-matcher.c (+57/-4)
To merge this branch: bzr merge lp:~3v1n0/bamf/match-envionment-var
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+296157@code.launchpad.net

Commit message

BamfMatcher: allow overriding desktop with the environment var BAMF_DESKTOP_FILE_HINT

When such environment variable is exported on the parent process of a window, we use it
to override the matching system.

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

+1

review: Approve
lp:~3v1n0/bamf/match-envionment-var updated
639. By Marco Trevisan (Treviño)

BamfMatcher, BamfLegacyWindow: ignore PIDs 0 and 1.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bamf-legacy-window.c'
2--- src/bamf-legacy-window.c 2016-04-09 02:06:08 +0000
3+++ src/bamf-legacy-window.c 2016-06-01 11:59:11 +0000
4@@ -194,7 +194,7 @@
5
6 pid = bamf_legacy_window_get_pid (self);
7
8- if (pid <= 0)
9+ if (pid < 2)
10 return NULL;
11
12 stat_path = g_strdup_printf ("/proc/%i/status", pid);
13
14=== modified file 'src/bamf-matcher.c'
15--- src/bamf-matcher.c 2016-03-22 13:36:15 +0000
16+++ src/bamf-matcher.c 2016-06-01 11:59:11 +0000
17@@ -30,6 +30,8 @@
18 #include <strings.h>
19
20 #define BAMF_INDEX_NAME "bamf-2.index"
21+#define EXEC_DESKTOP_FILE_OVERRIDE "--desktop_file_hint"
22+#define ENV_DESKTOP_FILE_OVERRIDE "BAMF_DESKTOP_FILE_HINT"
23
24 G_DEFINE_TYPE (BamfMatcher, bamf_matcher, BAMF_DBUS_TYPE_MATCHER_SKELETON);
25 #define BAMF_MATCHER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
26@@ -79,8 +81,6 @@
27 "com-sun-javaws-Main", "VCLSalFrame"
28 };
29
30-const gchar * EXEC_DESKTOP_FILE_OVERRIDE = "--desktop_file_hint";
31-
32 static void
33 on_view_active_changed (BamfView *view, gboolean active, BamfMatcher *matcher)
34 {
35@@ -556,6 +556,49 @@
36 return result;
37 }
38
39+char *
40+get_env_overridden_desktop_file (guint pid)
41+{
42+ gchar *environ_file;
43+ gchar *environ;
44+ gchar *result;
45+ gsize file_len;
46+ gint i;
47+
48+ if (pid < 2)
49+ return NULL;
50+
51+ environ = NULL;
52+ result = NULL;
53+ environ_file = g_strdup_printf ("/proc/%u/environ", pid);
54+
55+ if (g_file_get_contents (environ_file, &environ, &file_len, NULL))
56+ {
57+ for (i = 0; i < file_len && environ && environ[i] != '\0'; i += strlen (environ + i) + 1)
58+ {
59+ const gchar *var = environ + i;
60+
61+ if (g_str_has_prefix (var, ENV_DESKTOP_FILE_OVERRIDE"="))
62+ {
63+ const gchar *file_path;
64+ file_path = var + sizeof (ENV_DESKTOP_FILE_OVERRIDE);
65+
66+ if (g_str_has_suffix (file_path, ".desktop") &&
67+ g_file_test (file_path, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR))
68+ {
69+ result = g_strdup (file_path);
70+ break;
71+ }
72+ }
73+ }
74+ }
75+
76+ g_free (environ);
77+ g_free (environ_file);
78+
79+ return result;
80+}
81+
82 static GList *
83 pid_parent_tree (BamfMatcher *self, guint pid)
84 {
85@@ -1670,8 +1713,17 @@
86 g_free (desktop_file);
87 }
88 }
89- else
90+
91+ if (!desktop_files)
92 {
93+ gint pid = bamf_legacy_window_get_pid (window);
94+ desktop_file = get_env_overridden_desktop_file (pid);
95+
96+ if (desktop_file)
97+ {
98+ desktop_files = g_list_prepend (desktop_files, desktop_file);
99+ }
100+
101 const char *exec_string = bamf_legacy_window_get_exec_string (window);
102 desktop_file = get_exec_overridden_desktop_file (exec_string);
103
104@@ -1679,7 +1731,8 @@
105 {
106 desktop_files = g_list_prepend (desktop_files, desktop_file);
107 }
108- else
109+
110+ if (!desktop_files)
111 {
112 app_id = bamf_legacy_window_get_hint (window, _GTK_APPLICATION_ID);
113

Subscribers

People subscribed via source and target branches