Merge lp:~3v1n0/bamf/more-java-friendly-desktops into lp:bamf

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: no longer in the source branch.
Merged at revision: 575
Proposed branch: lp:~3v1n0/bamf/more-java-friendly-desktops
Merge into: lp:bamf
Prerequisite: lp:~3v1n0/bamf/create-local-desktop
Diff against target: 215 lines (+68/-10)
6 files modified
src/bamf-application.c (+12/-4)
src/bamf-matcher-private.h (+0/-1)
src/bamf-matcher.c (+32/-0)
src/bamf-matcher.h (+3/-0)
tests/bamfdaemon/test-application.c (+5/-5)
tests/bamfdaemon/test-matcher.c (+16/-0)
To merge this branch: bzr merge lp:~3v1n0/bamf/more-java-friendly-desktops
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Christopher Townsend Approve
Review via email: mp+179009@code.launchpad.net

Commit message

BamfMatcher: ignore known invalid window class values when matching windows

And generate better .desktop files for local apps.
This will make us life easier with Java.

Description of the change

Make .desktop generation more robust, avoiding matching errors on some
applications that shares the same WM_CLASS (such as JavaWS)
Disable StartupNotification by default on these .desktop files.

Tests updated

To post a comment you must log in.
Revision history for this message
Christopher Townsend (townsend) wrote :

Merges and compiles cleanly and all tests pass. Code looks good. +1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
575. By Marco Trevisan (Treviño)

BamfMatcher: ignore known invalid window class values when matching windows

And generate better .desktop files for local apps.
This will make us life easier with Java.

Approved by PS Jenkins bot, Christopher Townsend.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bamf-application.c'
2--- src/bamf-application.c 2013-08-06 15:49:30 +0000
3+++ src/bamf-application.c 2013-08-07 16:08:26 +0000
4@@ -496,6 +496,7 @@
5 {
6 BamfApplicationPrivate *priv;
7 BamfLegacyWindow *window;
8+ BamfMatcher *matcher;
9 GKeyFile *key_file;
10 const gchar *name, *icon, *iclass, *nclass, *class, *exec;
11 GFile *data_dir, *apps_dir, *icons_dir, *desktop_file, *icon_file, *mini_icon;
12@@ -517,13 +518,20 @@
13 return FALSE;
14 }
15
16+ matcher = bamf_matcher_get_default ();
17 data_dir = g_file_new_for_path (g_get_user_data_dir ());
18 name = bamf_view_get_name (BAMF_VIEW (self));
19 icon = bamf_view_get_icon (BAMF_VIEW (self));
20+ nclass = bamf_legacy_window_get_class_name (window);
21 iclass = bamf_legacy_window_get_class_instance_name (window);
22- nclass = bamf_legacy_window_get_class_name (window);
23 mini_icon = bamf_legacy_window_get_saved_mini_icon (window);
24
25+ if (!bamf_matcher_is_valid_class_name (matcher, iclass))
26+ iclass = NULL;
27+
28+ if (!bamf_matcher_is_valid_class_name (matcher, nclass))
29+ nclass = NULL;
30+
31 apps_dir = try_create_subdir (data_dir, "applications", priv->cancellable);
32 icons_dir = NULL;
33
34@@ -540,7 +548,7 @@
35
36 desktop_file = NULL;
37 icon_file = NULL;
38- class = (iclass) ? iclass : nclass;
39+ class = (nclass) ? nclass : iclass;
40
41 if (class)
42 {
43@@ -550,7 +558,6 @@
44
45 if (!G_IS_FILE (desktop_file))
46 {
47- BamfMatcher *matcher = bamf_matcher_get_default ();
48 gchar *trimmed_exec = bamf_matcher_get_trimmed_exec (matcher, exec);
49 try_create_local_desktop_data (apps_dir, icons_dir, trimmed_exec,
50 &desktop_file, &icon_file, priv->cancellable);
51@@ -622,8 +629,9 @@
52 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
53 G_KEY_FILE_DESKTOP_KEY_EXEC, exec);
54
55+ // It would be nice to be able to find if enabling this from some win property
56 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
57- G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, TRUE);
58+ G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, FALSE);
59
60 if (class)
61 {
62
63=== modified file 'src/bamf-matcher-private.h'
64--- src/bamf-matcher-private.h 2013-07-24 00:11:46 +0000
65+++ src/bamf-matcher-private.h 2013-08-07 16:08:26 +0000
66@@ -51,7 +51,6 @@
67
68 BamfApplication * bamf_matcher_get_application_by_desktop_file (BamfMatcher *self, const char *desktop_file);
69 BamfApplication * bamf_matcher_get_application_by_xid (BamfMatcher *self, guint xid);
70-gboolean bamf_matcher_is_valid_process_prefix (BamfMatcher *self, const char *exec);
71 char * get_exec_overridden_desktop_file (const char *exec);
72
73 gboolean is_autostart_desktop_file (const gchar *desktop_file);
74
75=== modified file 'src/bamf-matcher.c'
76--- src/bamf-matcher.c 2013-08-05 16:18:46 +0000
77+++ src/bamf-matcher.c 2013-08-07 16:08:26 +0000
78@@ -75,6 +75,13 @@
79 "^sol$"
80 };
81
82+// These class names are ignored as matching values
83+const gchar * CLASS_BAD_VALUES[] =
84+{
85+ "sun-awt-X11-XFramePeer", "net-sourceforge-jnlp-runtime-Boot",
86+ "com-sun-javaws-Main", "VCLSalFrame"
87+};
88+
89 const gchar * EXEC_DESKTOP_FILE_OVERRIDE = "--desktop_file_hint";
90
91 static void
92@@ -1586,6 +1593,25 @@
93 return FALSE;
94 }
95
96+gboolean
97+bamf_matcher_is_valid_class_name (BamfMatcher *self, const char *class_name)
98+{
99+ int i;
100+
101+ g_return_val_if_fail (BAMF_IS_MATCHER (self), FALSE);
102+
103+ if (!class_name)
104+ return TRUE;
105+
106+ for (i = 0; i < G_N_ELEMENTS (CLASS_BAD_VALUES); ++i)
107+ {
108+ if (g_strcmp0 (class_name, CLASS_BAD_VALUES[i]) == 0)
109+ return FALSE;
110+ }
111+
112+ return TRUE;
113+}
114+
115 static GList *
116 bamf_matcher_possible_applications_for_window (BamfMatcher *self,
117 BamfWindow *bamf_window,
118@@ -1610,6 +1636,12 @@
119 class_name = bamf_legacy_window_get_class_name (window);
120 instance_name = bamf_legacy_window_get_class_instance_name (window);
121
122+ if (!bamf_matcher_is_valid_class_name (self, class_name))
123+ class_name = NULL;
124+
125+ if (!bamf_matcher_is_valid_class_name (self, instance_name))
126+ instance_name = NULL;
127+
128 target_class = instance_name;
129 filter_by_wmclass = bamf_matcher_has_instance_class_desktop_file (self, target_class);
130
131
132=== modified file 'src/bamf-matcher.h'
133--- src/bamf-matcher.h 2013-07-25 16:54:16 +0000
134+++ src/bamf-matcher.h 2013-08-07 16:08:26 +0000
135@@ -111,6 +111,9 @@
136 gboolean bamf_matcher_is_valid_process_prefix (BamfMatcher *matcher,
137 const char *process_name);
138
139+gboolean bamf_matcher_is_valid_class_name (BamfMatcher *matcher,
140+ const char *class_name);
141+
142 char * bamf_matcher_get_trimmed_exec (BamfMatcher *matcher,
143 const char *exec_string);
144
145
146=== modified file 'tests/bamfdaemon/test-application.c'
147--- tests/bamfdaemon/test-application.c 2013-08-06 15:49:21 +0000
148+++ tests/bamfdaemon/test-application.c 2013-08-07 16:08:26 +0000
149@@ -1141,7 +1141,7 @@
150 verify_application_desktop_file_content (BamfApplication *application)
151 {
152 GKeyFile *key_file;
153- const gchar *desktop_file, *exec, *class;
154+ const gchar *desktop_file, *exec;
155 gchar *str_value;
156 GError *error = NULL;
157 BamfView *main_child;
158@@ -1186,11 +1186,11 @@
159 g_assert_cmpstr (str_value, ==, exec);
160 g_clear_pointer (&str_value, g_free);
161
162- g_assert (g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
163- G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, &error));
164+ g_assert (!g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
165+ G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, &error));
166 g_assert (!error);
167
168- class = bamf_legacy_window_get_class_instance_name (main_window);
169+ const gchar *class = bamf_legacy_window_get_class_instance_name (main_window);
170 class = class ? class : bamf_legacy_window_get_class_name (main_window);
171
172 if (class)
173@@ -1215,7 +1215,7 @@
174
175 application = bamf_application_new ();
176 lwin = bamf_legacy_window_test_new (20, "window", NULL, "awesome --exec");
177- bamf_legacy_window_test_set_wmclass (lwin, "application-class", "instance-class");
178+ bamf_legacy_window_test_set_wmclass (lwin, NULL, "instance-class");
179 win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
180 bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
181
182
183=== modified file 'tests/bamfdaemon/test-matcher.c'
184--- tests/bamfdaemon/test-matcher.c 2013-07-25 16:55:10 +0000
185+++ tests/bamfdaemon/test-matcher.c 2013-08-07 16:08:26 +0000
186@@ -1212,6 +1212,21 @@
187 g_object_unref (screen);
188 }
189
190+static void
191+test_class_valid_name (void)
192+{
193+ BamfMatcher *matcher;
194+
195+ matcher = bamf_matcher_get_default ();
196+ g_assert (bamf_matcher_is_valid_class_name (matcher, "any-good-class"));
197+ g_assert (!bamf_matcher_is_valid_class_name (matcher, "sun-awt-X11-XFramePeer"));
198+ g_assert (!bamf_matcher_is_valid_class_name (matcher, "net-sourceforge-jnlp-runtime-Boot"));
199+ g_assert (!bamf_matcher_is_valid_class_name (matcher, "com-sun-javaws-Main"));
200+ g_assert (!bamf_matcher_is_valid_class_name (matcher, "VCLSalFrame"));
201+
202+ g_object_unref (matcher);
203+}
204+
205 /* Initialize test suite */
206
207 void
208@@ -1222,6 +1237,7 @@
209 g_test_add_func (DOMAIN"/Allocation", test_allocation);
210 g_test_add_func (DOMAIN"/AutostartDesktopFile/User", test_autostart_desktop_file_user);
211 g_test_add_func (DOMAIN"/AutostartDesktopFile/System", test_autostart_desktop_file_system);
212+ g_test_add_func (DOMAIN"/ClassValidName", test_class_valid_name);
213 g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string);
214 g_test_add_func (DOMAIN"/GetViewByPath", test_get_view_by_path);
215 g_test_add_func (DOMAIN"/LoadDesktopFile", test_load_desktop_file);

Subscribers

People subscribed via source and target branches