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
=== modified file 'src/bamf-legacy-window.c'
--- src/bamf-legacy-window.c 2013-01-08 13:29:11 +0000
+++ src/bamf-legacy-window.c 2013-01-10 00:24:22 +0000
@@ -48,10 +48,6 @@
48{48{
49 WnckWindow * legacy_window;49 WnckWindow * legacy_window;
50 char * mini_icon_path;50 char * mini_icon_path;
51 gulong closed_id;
52 gulong name_changed_id;
53 gulong state_changed_id;
54 gulong geometry_changed_id;
55 gboolean is_closed;51 gboolean is_closed;
56};52};
5753
@@ -203,9 +199,9 @@
203 WnckWindow *window;199 WnckWindow *window;
204 GdkPixbuf *pbuf;200 GdkPixbuf *pbuf;
205 char *tmp;201 char *tmp;
206 202
207 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);203 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
208 204
209 if (self->priv->mini_icon_path)205 if (self->priv->mini_icon_path)
210 {206 {
211 if (g_file_test (self->priv->mini_icon_path, G_FILE_TEST_EXISTS))207 if (g_file_test (self->priv->mini_icon_path, G_FILE_TEST_EXISTS))
@@ -213,23 +209,23 @@
213 else209 else
214 g_free (self->priv->mini_icon_path);210 g_free (self->priv->mini_icon_path);
215 }211 }
216 212
217 window = self->priv->legacy_window;213 window = self->priv->legacy_window;
218 214
219 if (!window)215 if (!window)
220 return NULL;216 return NULL;
221 217
222 if (wnck_window_get_icon_is_fallback (window))218 if (wnck_window_get_icon_is_fallback (window))
223 return NULL;219 return NULL;
224 220
225 tmp = tmpnam (NULL);221 tmp = tmpnam (NULL);
226 if (!tmp)222 if (!tmp)
227 return NULL;223 return NULL;
228 224
229 pbuf = wnck_window_get_icon (window);225 pbuf = wnck_window_get_icon (window);
230 if (!gdk_pixbuf_save (pbuf, tmp, "png", NULL, NULL))226 if (!gdk_pixbuf_save (pbuf, tmp, "png", NULL, NULL))
231 return NULL;227 return NULL;
232 228
233 self->priv->mini_icon_path = g_strdup (tmp);229 self->priv->mini_icon_path = g_strdup (tmp);
234 return self->priv->mini_icon_path;230 return self->priv->mini_icon_path;
235}231}
@@ -301,12 +297,12 @@
301bamf_legacy_window_get_stacking_position (BamfLegacyWindow *self)297bamf_legacy_window_get_stacking_position (BamfLegacyWindow *self)
302{298{
303 BamfLegacyScreen *screen;299 BamfLegacyScreen *screen;
304 300
305 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), -1);301 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), -1);
306302
307 screen = bamf_legacy_screen_get_default ();303 screen = bamf_legacy_screen_get_default ();
308 g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), -1);304 g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), -1);
309 305
310 return g_list_index (bamf_legacy_screen_get_windows (screen), self);306 return g_list_index (bamf_legacy_screen_get_windows (screen), self);
311}307}
312308
@@ -494,8 +490,6 @@
494490
495 self = BAMF_LEGACY_WINDOW (object);491 self = BAMF_LEGACY_WINDOW (object);
496492
497 g_signal_handler_disconnect (wnck_screen_get_default (),
498 self->priv->closed_id);
499493
500 if (self->priv->mini_icon_path)494 if (self->priv->mini_icon_path)
501 {495 {
@@ -507,16 +501,11 @@
507 self->priv->mini_icon_path = NULL;501 self->priv->mini_icon_path = NULL;
508 }502 }
509503
504 g_signal_handlers_disconnect_by_data (wnck_screen_get_default (), self);
505
510 if (self->priv->legacy_window)506 if (self->priv->legacy_window)
511 {507 {
512 g_signal_handler_disconnect (self->priv->legacy_window,508 g_signal_handlers_disconnect_by_data (self->priv->legacy_window, self);
513 self->priv->name_changed_id);
514
515 g_signal_handler_disconnect (self->priv->legacy_window,
516 self->priv->state_changed_id);
517
518 g_signal_handler_disconnect (self->priv->legacy_window,
519 self->priv->geometry_changed_id);
520 }509 }
521510
522 G_OBJECT_CLASS (bamf_legacy_window_parent_class)->dispose (object);511 G_OBJECT_CLASS (bamf_legacy_window_parent_class)->dispose (object);
@@ -525,15 +514,10 @@
525static void514static void
526bamf_legacy_window_init (BamfLegacyWindow * self)515bamf_legacy_window_init (BamfLegacyWindow * self)
527{516{
528 WnckScreen *screen;517 self->priv = BAMF_LEGACY_WINDOW_GET_PRIVATE (self);
529518
530 BamfLegacyWindowPrivate *priv;519 g_signal_connect (wnck_screen_get_default (), "window-closed",
531 priv = self->priv = BAMF_LEGACY_WINDOW_GET_PRIVATE (self);520 (GCallback) handle_window_closed, self);
532
533 screen = wnck_screen_get_default ();
534
535 priv->closed_id = g_signal_connect (G_OBJECT (screen), "window-closed",
536 (GCallback) handle_window_closed, self);
537}521}
538522
539static void523static void
@@ -590,14 +574,14 @@
590574
591 self->priv->legacy_window = legacy_window;575 self->priv->legacy_window = legacy_window;
592576
593 self->priv->name_changed_id = g_signal_connect (G_OBJECT (legacy_window), "name-changed",577 g_signal_connect (G_OBJECT (legacy_window), "name-changed",
594 (GCallback) handle_name_changed, self);578 (GCallback) handle_name_changed, self);
595579
596 self->priv->state_changed_id = g_signal_connect (G_OBJECT (legacy_window), "state-changed",580 g_signal_connect (G_OBJECT (legacy_window), "state-changed",
597 (GCallback) handle_state_changed, self);581 (GCallback) handle_state_changed, self);
598582
599 self->priv->geometry_changed_id = g_signal_connect (G_OBJECT (legacy_window), "geometry-changed",583 g_signal_connect (G_OBJECT (legacy_window), "geometry-changed",
600 (GCallback) handle_geometry_changed, self);584 (GCallback) handle_geometry_changed, self);
601585
602 return self;586 return self;
603}587}
604588
=== modified file 'src/bamf-matcher.c'
--- src/bamf-matcher.c 2013-01-08 22:42:09 +0000
+++ src/bamf-matcher.c 2013-01-10 00:24:22 +0000
@@ -56,7 +56,8 @@
56{56{
57 "^gksu(do)?$", "^sudo$", "^su-to-root$", "^amdxdg-su$", "^java(ws)?$",57 "^gksu(do)?$", "^sudo$", "^su-to-root$", "^amdxdg-su$", "^java(ws)?$",
58 "^mono$", "^ruby$", "^padsp$", "^aoss$", "^python(\\d.\\d)?$", "^(ba)?sh$",58 "^mono$", "^ruby$", "^padsp$", "^aoss$", "^python(\\d.\\d)?$", "^(ba)?sh$",
59 "^perl$", "^env$", "^xdg-open$"59 "^perl$", "^env$", "^xdg-open$",
60 /* javaws strings: */ "^net\\.sourceforge\\.jnlp\\.runtime\\.Boot$", "^rt.jar$"
60};61};
6162
62// Prefixes that must be considered starting point of exec strings63// Prefixes that must be considered starting point of exec strings
@@ -995,7 +996,6 @@
995 if (!enumerator)996 if (!enumerator)
996 continue;997 continue;
997998
998
999 info = g_file_enumerator_next_file (enumerator, NULL, NULL);999 info = g_file_enumerator_next_file (enumerator, NULL, NULL);
10001000
1001 while (info)1001 while (info)
@@ -1075,7 +1075,7 @@
10751075
1076 dirs = list_prepend_desktop_file_env_directories (dirs, "XDG_DATA_HOME");1076 dirs = list_prepend_desktop_file_env_directories (dirs, "XDG_DATA_HOME");
10771077
1078 //If this doesn't exist, we need to track .local or the home itself!1078 /* If XDG_DATA_HOME doesn't exist, we need to track .local or the home itself! */
1079 path = g_build_filename (g_get_home_dir (), ".local/share/applications", NULL);1079 path = g_build_filename (g_get_home_dir (), ".local/share/applications", NULL);
10801080
1081 if (!g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0))1081 if (!g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0))
@@ -1860,6 +1860,36 @@
18601860
1861 if (bamf_application_contains_similar_to_window (app, bamf_window))1861 if (bamf_application_contains_similar_to_window (app, bamf_window))
1862 {1862 {
1863 char *exec_string = bamf_legacy_window_get_exec_string (window);
1864 char *trimmed_exec = bamf_matcher_get_trimmed_exec (self, exec_string);
1865 g_free (exec_string);
1866
1867 GList *ll;
1868 gboolean found_exec = FALSE;
1869 for (ll = bamf_view_get_children (BAMF_VIEW (app)); ll && !found_exec; ll = ll->next)
1870 {
1871 if (!BAMF_IS_WINDOW (ll->data))
1872 continue;
1873
1874 BamfLegacyWindow *w = bamf_window_get_window (BAMF_WINDOW (ll->data));
1875 char *wexec = bamf_legacy_window_get_exec_string (w);
1876 char *wtrimmed = bamf_matcher_get_trimmed_exec (self, wexec);
1877 g_free (wexec);
1878
1879 if (g_strcmp0 (trimmed_exec, wtrimmed) == 0)
1880 {
1881 best = BAMF_APPLICATION (view);
1882 found_exec = TRUE;
1883 }
1884
1885 g_free (wtrimmed);
1886 }
1887
1888 g_free (trimmed_exec);
1889
1890 if (!found_exec)
1891 continue;
1892
1863 app_desktop_class = bamf_application_get_wmclass (app);1893 app_desktop_class = bamf_application_get_wmclass (app);
18641894
1865 if (target_class && g_strcmp0 (target_class, app_desktop_class) == 0)1895 if (target_class && g_strcmp0 (target_class, app_desktop_class) == 0)
@@ -2033,7 +2063,7 @@
20332063
2034 if (role)2064 if (role)
2035 {2065 {
2036 gchar *exec = g_strdup_printf ("gnome-control-center %s", role);2066 gchar *exec = g_strconcat ("gnome-control-center ", role, NULL);
2037 list = g_hash_table_lookup (self->priv->desktop_file_table, exec);2067 list = g_hash_table_lookup (self->priv->desktop_file_table, exec);
2038 g_free (exec);2068 g_free (exec);
2039 g_free (role);2069 g_free (role);
20402070
=== modified file 'tests/bamfdaemon/test-matcher.c'
--- tests/bamfdaemon/test-matcher.c 2013-01-08 18:55:38 +0000
+++ tests/bamfdaemon/test-matcher.c 2013-01-10 00:24:22 +0000
@@ -33,6 +33,7 @@
33static void test_match_desktop_application (void);33static void test_match_desktop_application (void);
34static void test_match_libreoffice_windows (void);34static void test_match_libreoffice_windows (void);
35static void test_match_gnome_control_center_panels (void);35static void test_match_gnome_control_center_panels (void);
36static void test_match_javaws_windows (void);
36static void test_new_desktop_matches_unmatched_windows (void);37static void test_new_desktop_matches_unmatched_windows (void);
37static void test_match_transient_windows (void);38static void test_match_transient_windows (void);
38static void test_trim_exec_string (void);39static void test_trim_exec_string (void);
@@ -55,6 +56,7 @@
55 g_test_add_func (DOMAIN"/Matching/Application/Desktop", test_match_desktop_application);56 g_test_add_func (DOMAIN"/Matching/Application/Desktop", test_match_desktop_application);
56 g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows);57 g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows);
57 g_test_add_func (DOMAIN"/Matching/Application/GnomeControlCenter", test_match_gnome_control_center_panels);58 g_test_add_func (DOMAIN"/Matching/Application/GnomeControlCenter", test_match_gnome_control_center_panels);
59 g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart", test_match_javaws_windows);
58 g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows);60 g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows);
59 g_test_add_func (DOMAIN"/Matching/Windows/Transient", test_match_transient_windows);61 g_test_add_func (DOMAIN"/Matching/Windows/Transient", test_match_transient_windows);
60 g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string);62 g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string);
@@ -559,6 +561,73 @@
559}561}
560562
561static void563static void
564test_match_javaws_windows (void)
565{
566 BamfMatcher *matcher;
567 BamfLegacyScreen *screen;
568 BamfLegacyWindowTest *test_win;
569 BamfApplication *app1, *app2, *app3;
570 GList *app_children;
571
572 screen = bamf_legacy_screen_get_default ();
573 matcher = bamf_matcher_get_default ();
574 const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
575 "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
576 "-Xms8m -Djava.security.manager " \
577 "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
578 "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
579 "-Dicedtea-web.bin.name=javaws " \
580 "-Dicedtea-web.bin.location=/usr/bin/javaws "\
581 "net.sourceforge.jnlp.runtime.Boot";
582 const char *class_name = "sun-awt-X11-XFramePeer";
583 const char *class_instance = "net-sourceforge-jnlp-runtime-Boot";
584
585 cleanup_matcher_tables (matcher);
586 export_matcher_on_bus (matcher);
587
588 guint xid = g_random_int ();
589 char *exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL);
590 test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
591 bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
592 _bamf_legacy_screen_open_test_window (screen, test_win);
593 g_free (exec);
594 app1 = bamf_matcher_get_application_by_xid (matcher, xid);
595 g_assert (BAMF_IS_APPLICATION (app1));
596 app_children = bamf_view_get_children (BAMF_VIEW (app1));
597 g_assert_cmpuint (g_list_length (app_children), ==, 1);
598 g_assert (find_window_in_app (app1, BAMF_LEGACY_WINDOW (test_win)));
599
600 xid = g_random_int ();
601 exec = g_strconcat (exec_prefix, " Draw.jnlp", NULL);
602 test_win = bamf_legacy_window_test_new (xid, "Draw", NULL, exec);
603 bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
604 _bamf_legacy_screen_open_test_window (screen, test_win);
605 g_free (exec);
606 app2 = bamf_matcher_get_application_by_xid (matcher, xid);
607 g_assert (BAMF_IS_APPLICATION (app2));
608 g_assert (app1 != app2);
609 app_children = bamf_view_get_children (BAMF_VIEW (app2));
610 g_assert_cmpuint (g_list_length (app_children), ==, 1);
611 g_assert (find_window_in_app (app2, BAMF_LEGACY_WINDOW (test_win)));
612
613 xid = g_random_int ();
614 exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL);
615 test_win = bamf_legacy_window_test_new (xid, "Notepad Subwin", NULL, exec);
616 bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
617 _bamf_legacy_screen_open_test_window (screen, test_win);
618 g_free (exec);
619 app3 = bamf_matcher_get_application_by_xid (matcher, xid);
620 g_assert (app3 == app1);
621 g_assert (BAMF_IS_APPLICATION (app3));
622 app_children = bamf_view_get_children (BAMF_VIEW (app3));
623 g_assert_cmpuint (g_list_length (app_children), ==, 2);
624 g_assert (find_window_in_app (app3, BAMF_LEGACY_WINDOW (test_win)));
625
626 g_object_unref (matcher);
627 g_object_unref (screen);
628}
629
630static void
562test_match_transient_windows (void)631test_match_transient_windows (void)
563{632{
564 BamfMatcher *matcher;633 BamfMatcher *matcher;
@@ -660,5 +729,17 @@
660 g_assert_cmpstr (trimmed, ==, "myprog");729 g_assert_cmpstr (trimmed, ==, "myprog");
661 g_free (trimmed);730 g_free (trimmed);
662731
732 const char *exec = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
733 "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
734 "-Xms8m -Djava.security.manager " \
735 "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
736 "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
737 "-Dicedtea-web.bin.name=javaws " \
738 "-Dicedtea-web.bin.location=/usr/bin/javaws "\
739 "net.sourceforge.jnlp.runtime.Boot Notepad.jnlp";
740 trimmed = bamf_matcher_get_trimmed_exec (matcher, exec);
741 g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
742 g_free (trimmed);
743
663 g_object_unref (matcher);744 g_object_unref (matcher);
664}745}

Subscribers

People subscribed via source and target branches