Merge lp:~3v1n0/bamf/javaws-matching into lp:bamf/0.4

Proposed by Marco Trevisan (Treviño) on 2013-01-10
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2013-01-10
Approved revision: 529
Merged at revision: 516
Proposed branch: lp:~3v1n0/bamf/javaws-matching
Merge into: lp:bamf/0.4
Diff against target: 332 lines (+140/-45)
3 files modified
src/bamf-legacy-window.c (+25/-41)
src/bamf-matcher.c (+34/-4)
tests/bamfdaemon/test-matcher.c (+81/-0)
To merge this branch: bzr merge lp:~3v1n0/bamf/javaws-matching
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing on 2013-01-10
Brandon Schaefer (community) 2013-01-10 Approve on 2013-01-10
Review via email: mp+142617@code.launchpad.net

Commit message

BamfMatcher: Don't associate .desktopless applications with different exec string, fix JavaWS apps

Description of the change

Don't associate to the similar application, windows that have different execution path. Also add some rules to fix Java Web Start applications matching.

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 2013-01-08 13:29:11 +0000
3+++ src/bamf-legacy-window.c 2013-01-10 00:24:22 +0000
4@@ -48,10 +48,6 @@
5 {
6 WnckWindow * legacy_window;
7 char * mini_icon_path;
8- gulong closed_id;
9- gulong name_changed_id;
10- gulong state_changed_id;
11- gulong geometry_changed_id;
12 gboolean is_closed;
13 };
14
15@@ -203,9 +199,9 @@
16 WnckWindow *window;
17 GdkPixbuf *pbuf;
18 char *tmp;
19-
20+
21 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
22-
23+
24 if (self->priv->mini_icon_path)
25 {
26 if (g_file_test (self->priv->mini_icon_path, G_FILE_TEST_EXISTS))
27@@ -213,23 +209,23 @@
28 else
29 g_free (self->priv->mini_icon_path);
30 }
31-
32+
33 window = self->priv->legacy_window;
34-
35+
36 if (!window)
37 return NULL;
38-
39+
40 if (wnck_window_get_icon_is_fallback (window))
41 return NULL;
42-
43+
44 tmp = tmpnam (NULL);
45 if (!tmp)
46 return NULL;
47-
48+
49 pbuf = wnck_window_get_icon (window);
50 if (!gdk_pixbuf_save (pbuf, tmp, "png", NULL, NULL))
51 return NULL;
52-
53+
54 self->priv->mini_icon_path = g_strdup (tmp);
55 return self->priv->mini_icon_path;
56 }
57@@ -301,12 +297,12 @@
58 bamf_legacy_window_get_stacking_position (BamfLegacyWindow *self)
59 {
60 BamfLegacyScreen *screen;
61-
62+
63 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), -1);
64
65 screen = bamf_legacy_screen_get_default ();
66 g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), -1);
67-
68+
69 return g_list_index (bamf_legacy_screen_get_windows (screen), self);
70 }
71
72@@ -494,8 +490,6 @@
73
74 self = BAMF_LEGACY_WINDOW (object);
75
76- g_signal_handler_disconnect (wnck_screen_get_default (),
77- self->priv->closed_id);
78
79 if (self->priv->mini_icon_path)
80 {
81@@ -507,16 +501,11 @@
82 self->priv->mini_icon_path = NULL;
83 }
84
85+ g_signal_handlers_disconnect_by_data (wnck_screen_get_default (), self);
86+
87 if (self->priv->legacy_window)
88 {
89- g_signal_handler_disconnect (self->priv->legacy_window,
90- self->priv->name_changed_id);
91-
92- g_signal_handler_disconnect (self->priv->legacy_window,
93- self->priv->state_changed_id);
94-
95- g_signal_handler_disconnect (self->priv->legacy_window,
96- self->priv->geometry_changed_id);
97+ g_signal_handlers_disconnect_by_data (self->priv->legacy_window, self);
98 }
99
100 G_OBJECT_CLASS (bamf_legacy_window_parent_class)->dispose (object);
101@@ -525,15 +514,10 @@
102 static void
103 bamf_legacy_window_init (BamfLegacyWindow * self)
104 {
105- WnckScreen *screen;
106-
107- BamfLegacyWindowPrivate *priv;
108- priv = self->priv = BAMF_LEGACY_WINDOW_GET_PRIVATE (self);
109-
110- screen = wnck_screen_get_default ();
111-
112- priv->closed_id = g_signal_connect (G_OBJECT (screen), "window-closed",
113- (GCallback) handle_window_closed, self);
114+ self->priv = BAMF_LEGACY_WINDOW_GET_PRIVATE (self);
115+
116+ g_signal_connect (wnck_screen_get_default (), "window-closed",
117+ (GCallback) handle_window_closed, self);
118 }
119
120 static void
121@@ -590,14 +574,14 @@
122
123 self->priv->legacy_window = legacy_window;
124
125- self->priv->name_changed_id = g_signal_connect (G_OBJECT (legacy_window), "name-changed",
126- (GCallback) handle_name_changed, self);
127-
128- self->priv->state_changed_id = g_signal_connect (G_OBJECT (legacy_window), "state-changed",
129- (GCallback) handle_state_changed, self);
130-
131- self->priv->geometry_changed_id = g_signal_connect (G_OBJECT (legacy_window), "geometry-changed",
132- (GCallback) handle_geometry_changed, self);
133+ g_signal_connect (G_OBJECT (legacy_window), "name-changed",
134+ (GCallback) handle_name_changed, self);
135+
136+ g_signal_connect (G_OBJECT (legacy_window), "state-changed",
137+ (GCallback) handle_state_changed, self);
138+
139+ g_signal_connect (G_OBJECT (legacy_window), "geometry-changed",
140+ (GCallback) handle_geometry_changed, self);
141
142 return self;
143 }
144
145=== modified file 'src/bamf-matcher.c'
146--- src/bamf-matcher.c 2013-01-08 22:42:09 +0000
147+++ src/bamf-matcher.c 2013-01-10 00:24:22 +0000
148@@ -56,7 +56,8 @@
149 {
150 "^gksu(do)?$", "^sudo$", "^su-to-root$", "^amdxdg-su$", "^java(ws)?$",
151 "^mono$", "^ruby$", "^padsp$", "^aoss$", "^python(\\d.\\d)?$", "^(ba)?sh$",
152- "^perl$", "^env$", "^xdg-open$"
153+ "^perl$", "^env$", "^xdg-open$",
154+ /* javaws strings: */ "^net\\.sourceforge\\.jnlp\\.runtime\\.Boot$", "^rt.jar$"
155 };
156
157 // Prefixes that must be considered starting point of exec strings
158@@ -995,7 +996,6 @@
159 if (!enumerator)
160 continue;
161
162-
163 info = g_file_enumerator_next_file (enumerator, NULL, NULL);
164
165 while (info)
166@@ -1075,7 +1075,7 @@
167
168 dirs = list_prepend_desktop_file_env_directories (dirs, "XDG_DATA_HOME");
169
170- //If this doesn't exist, we need to track .local or the home itself!
171+ /* If XDG_DATA_HOME doesn't exist, we need to track .local or the home itself! */
172 path = g_build_filename (g_get_home_dir (), ".local/share/applications", NULL);
173
174 if (!g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0))
175@@ -1860,6 +1860,36 @@
176
177 if (bamf_application_contains_similar_to_window (app, bamf_window))
178 {
179+ char *exec_string = bamf_legacy_window_get_exec_string (window);
180+ char *trimmed_exec = bamf_matcher_get_trimmed_exec (self, exec_string);
181+ g_free (exec_string);
182+
183+ GList *ll;
184+ gboolean found_exec = FALSE;
185+ for (ll = bamf_view_get_children (BAMF_VIEW (app)); ll && !found_exec; ll = ll->next)
186+ {
187+ if (!BAMF_IS_WINDOW (ll->data))
188+ continue;
189+
190+ BamfLegacyWindow *w = bamf_window_get_window (BAMF_WINDOW (ll->data));
191+ char *wexec = bamf_legacy_window_get_exec_string (w);
192+ char *wtrimmed = bamf_matcher_get_trimmed_exec (self, wexec);
193+ g_free (wexec);
194+
195+ if (g_strcmp0 (trimmed_exec, wtrimmed) == 0)
196+ {
197+ best = BAMF_APPLICATION (view);
198+ found_exec = TRUE;
199+ }
200+
201+ g_free (wtrimmed);
202+ }
203+
204+ g_free (trimmed_exec);
205+
206+ if (!found_exec)
207+ continue;
208+
209 app_desktop_class = bamf_application_get_wmclass (app);
210
211 if (target_class && g_strcmp0 (target_class, app_desktop_class) == 0)
212@@ -2033,7 +2063,7 @@
213
214 if (role)
215 {
216- gchar *exec = g_strdup_printf ("gnome-control-center %s", role);
217+ gchar *exec = g_strconcat ("gnome-control-center ", role, NULL);
218 list = g_hash_table_lookup (self->priv->desktop_file_table, exec);
219 g_free (exec);
220 g_free (role);
221
222=== modified file 'tests/bamfdaemon/test-matcher.c'
223--- tests/bamfdaemon/test-matcher.c 2013-01-08 18:55:38 +0000
224+++ tests/bamfdaemon/test-matcher.c 2013-01-10 00:24:22 +0000
225@@ -33,6 +33,7 @@
226 static void test_match_desktop_application (void);
227 static void test_match_libreoffice_windows (void);
228 static void test_match_gnome_control_center_panels (void);
229+static void test_match_javaws_windows (void);
230 static void test_new_desktop_matches_unmatched_windows (void);
231 static void test_match_transient_windows (void);
232 static void test_trim_exec_string (void);
233@@ -55,6 +56,7 @@
234 g_test_add_func (DOMAIN"/Matching/Application/Desktop", test_match_desktop_application);
235 g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows);
236 g_test_add_func (DOMAIN"/Matching/Application/GnomeControlCenter", test_match_gnome_control_center_panels);
237+ g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart", test_match_javaws_windows);
238 g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows);
239 g_test_add_func (DOMAIN"/Matching/Windows/Transient", test_match_transient_windows);
240 g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string);
241@@ -559,6 +561,73 @@
242 }
243
244 static void
245+test_match_javaws_windows (void)
246+{
247+ BamfMatcher *matcher;
248+ BamfLegacyScreen *screen;
249+ BamfLegacyWindowTest *test_win;
250+ BamfApplication *app1, *app2, *app3;
251+ GList *app_children;
252+
253+ screen = bamf_legacy_screen_get_default ();
254+ matcher = bamf_matcher_get_default ();
255+ const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
256+ "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
257+ "-Xms8m -Djava.security.manager " \
258+ "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
259+ "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
260+ "-Dicedtea-web.bin.name=javaws " \
261+ "-Dicedtea-web.bin.location=/usr/bin/javaws "\
262+ "net.sourceforge.jnlp.runtime.Boot";
263+ const char *class_name = "sun-awt-X11-XFramePeer";
264+ const char *class_instance = "net-sourceforge-jnlp-runtime-Boot";
265+
266+ cleanup_matcher_tables (matcher);
267+ export_matcher_on_bus (matcher);
268+
269+ guint xid = g_random_int ();
270+ char *exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL);
271+ test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
272+ bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
273+ _bamf_legacy_screen_open_test_window (screen, test_win);
274+ g_free (exec);
275+ app1 = bamf_matcher_get_application_by_xid (matcher, xid);
276+ g_assert (BAMF_IS_APPLICATION (app1));
277+ app_children = bamf_view_get_children (BAMF_VIEW (app1));
278+ g_assert_cmpuint (g_list_length (app_children), ==, 1);
279+ g_assert (find_window_in_app (app1, BAMF_LEGACY_WINDOW (test_win)));
280+
281+ xid = g_random_int ();
282+ exec = g_strconcat (exec_prefix, " Draw.jnlp", NULL);
283+ test_win = bamf_legacy_window_test_new (xid, "Draw", NULL, exec);
284+ bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
285+ _bamf_legacy_screen_open_test_window (screen, test_win);
286+ g_free (exec);
287+ app2 = bamf_matcher_get_application_by_xid (matcher, xid);
288+ g_assert (BAMF_IS_APPLICATION (app2));
289+ g_assert (app1 != app2);
290+ app_children = bamf_view_get_children (BAMF_VIEW (app2));
291+ g_assert_cmpuint (g_list_length (app_children), ==, 1);
292+ g_assert (find_window_in_app (app2, BAMF_LEGACY_WINDOW (test_win)));
293+
294+ xid = g_random_int ();
295+ exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL);
296+ test_win = bamf_legacy_window_test_new (xid, "Notepad Subwin", NULL, exec);
297+ bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
298+ _bamf_legacy_screen_open_test_window (screen, test_win);
299+ g_free (exec);
300+ app3 = bamf_matcher_get_application_by_xid (matcher, xid);
301+ g_assert (app3 == app1);
302+ g_assert (BAMF_IS_APPLICATION (app3));
303+ app_children = bamf_view_get_children (BAMF_VIEW (app3));
304+ g_assert_cmpuint (g_list_length (app_children), ==, 2);
305+ g_assert (find_window_in_app (app3, BAMF_LEGACY_WINDOW (test_win)));
306+
307+ g_object_unref (matcher);
308+ g_object_unref (screen);
309+}
310+
311+static void
312 test_match_transient_windows (void)
313 {
314 BamfMatcher *matcher;
315@@ -660,5 +729,17 @@
316 g_assert_cmpstr (trimmed, ==, "myprog");
317 g_free (trimmed);
318
319+ const char *exec = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
320+ "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
321+ "-Xms8m -Djava.security.manager " \
322+ "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
323+ "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
324+ "-Dicedtea-web.bin.name=javaws " \
325+ "-Dicedtea-web.bin.location=/usr/bin/javaws "\
326+ "net.sourceforge.jnlp.runtime.Boot Notepad.jnlp";
327+ trimmed = bamf_matcher_get_trimmed_exec (matcher, exec);
328+ g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
329+ g_free (trimmed);
330+
331 g_object_unref (matcher);
332 }

Subscribers

People subscribed via source and target branches