Merge lp:~3v1n0/bamf/javaws-matching-0.2 into lp:bamf/0.2
- javaws-matching-0.2
- Merge into bamf-0.2
Proposed by
Marco Trevisan (Treviño)
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Brandon Schaefer | ||||
Approved revision: | 495 | ||||
Merged at revision: | 489 | ||||
Proposed branch: | lp:~3v1n0/bamf/javaws-matching-0.2 | ||||
Merge into: | lp:bamf/0.2 | ||||
Diff against target: |
1011 lines (+448/-211) 9 files modified
src/bamf-legacy-screen.c (+8/-27) src/bamf-legacy-window.c (+2/-2) src/bamf-matcher-private.h (+1/-0) src/bamf-matcher.c (+193/-182) tests/bamfdaemon/Makefile.am (+1/-0) tests/bamfdaemon/data/gnome-control-center.desktop (+9/-0) tests/bamfdaemon/data/gnome-display-panel.desktop (+10/-0) tests/bamfdaemon/data/gnome-mouse-panel.desktop (+10/-0) tests/bamfdaemon/test-matcher.c (+214/-0) |
||||
To merge this branch: | bzr merge lp:~3v1n0/bamf/javaws-matching-0.2 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brandon Schaefer (community) | Approve | ||
Review via email: mp+142619@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.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/bamf-legacy-screen.c' | |||
2 | --- src/bamf-legacy-screen.c 2012-07-30 03:00:43 +0000 | |||
3 | +++ src/bamf-legacy-screen.c 2013-01-10 00:14:24 +0000 | |||
4 | @@ -210,7 +210,6 @@ | |||
5 | 210 | BamfLegacyScreen *self; | 210 | BamfLegacyScreen *self; |
6 | 211 | GList *l; | 211 | GList *l; |
7 | 212 | guint xid_a, xid_b; | 212 | guint xid_a, xid_b; |
8 | 213 | guint idx_a, idx_b; | ||
9 | 214 | 213 | ||
10 | 215 | g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (data), 1); | 214 | g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (data), 1); |
11 | 216 | self = BAMF_LEGACY_SCREEN (data); | 215 | self = BAMF_LEGACY_SCREEN (data); |
12 | @@ -218,36 +217,18 @@ | |||
13 | 218 | xid_a = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (a)); | 217 | xid_a = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (a)); |
14 | 219 | xid_b = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (b)); | 218 | xid_b = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (b)); |
15 | 220 | 219 | ||
16 | 221 | gboolean idx_a_found = FALSE; | ||
17 | 222 | gboolean idx_b_found = FALSE; | ||
18 | 223 | idx_a = 0; | ||
19 | 224 | idx_b = 0; | ||
20 | 225 | |||
21 | 226 | for (l = wnck_screen_get_windows_stacked (self->priv->legacy_screen); l; l = l->next) | 220 | for (l = wnck_screen_get_windows_stacked (self->priv->legacy_screen); l; l = l->next) |
22 | 227 | { | 221 | { |
23 | 228 | gulong legacy_xid = wnck_window_get_xid (WNCK_WINDOW (l->data)); | 222 | gulong legacy_xid = wnck_window_get_xid (WNCK_WINDOW (l->data)); |
24 | 229 | 223 | ||
43 | 230 | if (!idx_a_found) | 224 | if (legacy_xid == xid_a) |
44 | 231 | { | 225 | return -1; |
45 | 232 | if (xid_a != legacy_xid) | 226 | |
46 | 233 | idx_a++; | 227 | if (legacy_xid == xid_b) |
47 | 234 | else | 228 | return 1; |
30 | 235 | idx_a_found = TRUE; | ||
31 | 236 | } | ||
32 | 237 | |||
33 | 238 | if (!idx_b_found) | ||
34 | 239 | { | ||
35 | 240 | if (xid_b != legacy_xid) | ||
36 | 241 | idx_b++; | ||
37 | 242 | else | ||
38 | 243 | idx_b_found = TRUE; | ||
39 | 244 | } | ||
40 | 245 | |||
41 | 246 | if (idx_a_found && idx_b_found) | ||
42 | 247 | break; | ||
48 | 248 | } | 229 | } |
49 | 249 | 230 | ||
51 | 250 | return (idx_a < idx_b) ? -1 : 1; | 231 | return 0; |
52 | 251 | } | 232 | } |
53 | 252 | 233 | ||
54 | 253 | static void | 234 | static void |
55 | @@ -300,11 +281,11 @@ | |||
56 | 300 | } | 281 | } |
57 | 301 | } | 282 | } |
58 | 302 | 283 | ||
60 | 303 | WnckWindow *legacy_window = wnck_window_get(xid); | 284 | WnckWindow *legacy_window = wnck_window_get (xid); |
61 | 304 | 285 | ||
62 | 305 | if (WNCK_IS_WINDOW (legacy_window)) | 286 | if (WNCK_IS_WINDOW (legacy_window)) |
63 | 306 | { | 287 | { |
65 | 307 | handle_window_opened(NULL, legacy_window, self); | 288 | handle_window_opened (NULL, legacy_window, self); |
66 | 308 | } | 289 | } |
67 | 309 | } | 290 | } |
68 | 310 | 291 | ||
69 | 311 | 292 | ||
70 | === modified file 'src/bamf-legacy-window.c' | |||
71 | --- src/bamf-legacy-window.c 2012-10-10 17:36:21 +0000 | |||
72 | +++ src/bamf-legacy-window.c 2013-01-10 00:14:24 +0000 | |||
73 | @@ -498,9 +498,9 @@ | |||
74 | 498 | guint xid = bamf_legacy_window_get_xid (self); | 498 | guint xid = bamf_legacy_window_get_xid (self); |
75 | 499 | 499 | ||
76 | 500 | /* Adding a weak ref to this object, causes to get notified after the object | 500 | /* Adding a weak ref to this object, causes to get notified after the object |
78 | 501 | * destruction, so once this BamfLegacyWindow has been closed and drestroyed | 501 | * destruction, so once this BamfLegacyWindow has been closed and destroyed |
79 | 502 | * the handle_destroy_notify() function will be called, and that will | 502 | * the handle_destroy_notify() function will be called, and that will |
81 | 503 | * provide to iniject another window like this one to the BamfLegacyScreen */ | 503 | * provide to inject another window like this one to the BamfLegacyScreen */ |
82 | 504 | g_object_weak_ref (G_OBJECT (self), (GWeakNotify) handle_destroy_notify, | 504 | g_object_weak_ref (G_OBJECT (self), (GWeakNotify) handle_destroy_notify, |
83 | 505 | GUINT_TO_POINTER (xid)); | 505 | GUINT_TO_POINTER (xid)); |
84 | 506 | 506 | ||
85 | 507 | 507 | ||
86 | === modified file 'src/bamf-matcher-private.h' | |||
87 | --- src/bamf-matcher-private.h 2012-07-27 18:38:22 +0000 | |||
88 | +++ src/bamf-matcher-private.h 2013-01-10 00:14:24 +0000 | |||
89 | @@ -46,5 +46,6 @@ | |||
90 | 46 | 46 | ||
91 | 47 | BamfApplication * bamf_matcher_get_application_by_desktop_file (BamfMatcher *self, const char *desktop_file); | 47 | BamfApplication * bamf_matcher_get_application_by_desktop_file (BamfMatcher *self, const char *desktop_file); |
92 | 48 | BamfApplication * bamf_matcher_get_application_by_xid (BamfMatcher *self, guint xid); | 48 | BamfApplication * bamf_matcher_get_application_by_xid (BamfMatcher *self, guint xid); |
93 | 49 | char * bamf_matcher_get_trimmed_exec (BamfMatcher *self, const char *exec); | ||
94 | 49 | 50 | ||
95 | 50 | #endif | 51 | #endif |
96 | 51 | 52 | ||
97 | === modified file 'src/bamf-matcher.c' | |||
98 | --- src/bamf-matcher.c 2012-10-10 17:36:21 +0000 | |||
99 | +++ src/bamf-matcher.c 2013-01-10 00:14:24 +0000 | |||
100 | @@ -48,6 +48,22 @@ | |||
101 | 48 | static BamfMatcher *static_matcher; | 48 | static BamfMatcher *static_matcher; |
102 | 49 | static guint matcher_signals[LAST_SIGNAL] = { 0 }; | 49 | static guint matcher_signals[LAST_SIGNAL] = { 0 }; |
103 | 50 | 50 | ||
104 | 51 | // Prefixes to be ignored in exec strings | ||
105 | 52 | const gchar* EXEC_BAD_PREFIXES[] = | ||
106 | 53 | { | ||
107 | 54 | "^gksu(do)?$", "^sudo$", "^su-to-root$", "^amdxdg-su$", "^java(ws)?$", | ||
108 | 55 | "^mono$", "^ruby$", "^padsp$", "^aoss$", "^python(\\d.\\d)?$", "^(ba)?sh$", | ||
109 | 56 | "^perl$", "^env$", "^xdg-open$", | ||
110 | 57 | /* javaws strings: */ "^net\\.sourceforge\\.jnlp\\.runtime\\.Boot$", "^rt.jar$" | ||
111 | 58 | }; | ||
112 | 59 | |||
113 | 60 | // Prefixes that must be considered starting point of exec strings | ||
114 | 61 | const gchar* EXEC_GOOD_PREFIXES[] = | ||
115 | 62 | { | ||
116 | 63 | "^gnome-control-center$", "^libreoffice$", "^ooffice$", "^wine$", "^steam$", | ||
117 | 64 | "^sol$" | ||
118 | 65 | }; | ||
119 | 66 | |||
120 | 51 | static void | 67 | static void |
121 | 52 | on_view_active_changed (BamfView *view, gboolean active, BamfMatcher *matcher) | 68 | on_view_active_changed (BamfView *view, gboolean active, BamfMatcher *matcher) |
122 | 53 | { | 69 | { |
123 | @@ -211,7 +227,8 @@ | |||
124 | 211 | return FALSE; | 227 | return FALSE; |
125 | 212 | } | 228 | } |
126 | 213 | 229 | ||
128 | 214 | static void bamf_matcher_prepare_path_change (BamfMatcher *self, const gchar *desktop_file, ViewChangeType change_type) | 230 | static void |
129 | 231 | bamf_matcher_prepare_path_change (BamfMatcher *self, const gchar *desktop_file, ViewChangeType change_type) | ||
130 | 215 | { | 232 | { |
131 | 216 | BamfMatcherPrivate *priv; | 233 | BamfMatcherPrivate *priv; |
132 | 217 | BamfApplication *app; | 234 | BamfApplication *app; |
133 | @@ -248,12 +265,6 @@ | |||
134 | 248 | } | 265 | } |
135 | 249 | 266 | ||
136 | 250 | static void | 267 | static void |
137 | 251 | on_view_closed (BamfView *view, BamfMatcher *self) | ||
138 | 252 | { | ||
139 | 253 | bamf_matcher_unregister_view (self, view); | ||
140 | 254 | } | ||
141 | 255 | |||
142 | 256 | static void | ||
143 | 257 | bamf_matcher_register_view_stealing_ref (BamfMatcher *self, BamfView *view) | 268 | bamf_matcher_register_view_stealing_ref (BamfMatcher *self, BamfView *view) |
144 | 258 | { | 269 | { |
145 | 259 | const char *path, *type; | 270 | const char *path, *type; |
146 | @@ -264,8 +275,8 @@ | |||
147 | 264 | path = bamf_view_export_on_bus (view, connection); | 275 | path = bamf_view_export_on_bus (view, connection); |
148 | 265 | type = bamf_view_get_view_type (view); | 276 | type = bamf_view_get_view_type (view); |
149 | 266 | 277 | ||
152 | 267 | g_signal_connect (G_OBJECT (view), "closed-internal", | 278 | g_signal_connect_swapped (G_OBJECT (view), "closed-internal", |
153 | 268 | (GCallback) on_view_closed, self); | 279 | (GCallback) bamf_matcher_unregister_view, self); |
154 | 269 | g_signal_connect (G_OBJECT (view), "active-changed", | 280 | g_signal_connect (G_OBJECT (view), "active-changed", |
155 | 270 | (GCallback) on_view_active_changed, self); | 281 | (GCallback) on_view_active_changed, self); |
156 | 271 | 282 | ||
157 | @@ -296,7 +307,7 @@ | |||
158 | 296 | 307 | ||
159 | 297 | g_signal_emit_by_name (self, "view-closed", path, type); | 308 | g_signal_emit_by_name (self, "view-closed", path, type); |
160 | 298 | 309 | ||
162 | 299 | g_signal_handlers_disconnect_by_func (G_OBJECT (view), on_view_closed, self); | 310 | g_signal_handlers_disconnect_by_func (G_OBJECT (view), bamf_matcher_unregister_view, self); |
163 | 300 | g_signal_handlers_disconnect_by_func (G_OBJECT (view), on_view_active_changed, self); | 311 | g_signal_handlers_disconnect_by_func (G_OBJECT (view), on_view_active_changed, self); |
164 | 301 | 312 | ||
165 | 302 | if (BAMF_IS_APPLICATION (view)) | 313 | if (BAMF_IS_APPLICATION (view)) |
166 | @@ -348,7 +359,7 @@ | |||
167 | 348 | else if (g_str_has_suffix (name, "LibreOffice Calc")) | 359 | else if (g_str_has_suffix (name, "LibreOffice Calc")) |
168 | 349 | { | 360 | { |
169 | 350 | binary = "libreoffice"; | 361 | binary = "libreoffice"; |
171 | 351 | parameter = "calc"; | 362 | parameter = "calc"; |
172 | 352 | } | 363 | } |
173 | 353 | else if (g_str_has_suffix (name, "LibreOffice Impress")) | 364 | else if (g_str_has_suffix (name, "LibreOffice Impress")) |
174 | 354 | { | 365 | { |
175 | @@ -466,60 +477,72 @@ | |||
176 | 466 | if (!binary) | 477 | if (!binary) |
177 | 467 | return NULL; | 478 | return NULL; |
178 | 468 | 479 | ||
196 | 469 | const char *sufix = NULL; | 480 | GList *l = NULL; |
197 | 470 | 481 | ||
198 | 471 | if (g_strcmp0 (binary, "libreoffice") == 0) | 482 | if (parameter) |
182 | 472 | sufix = " %U"; | ||
183 | 473 | else if (g_strcmp0 (binary, "ooffice") == 0) | ||
184 | 474 | sufix = " %F"; | ||
185 | 475 | |||
186 | 476 | GList *l; | ||
187 | 477 | if (!parameter) | ||
188 | 478 | exec = g_strconcat (binary, sufix, NULL); | ||
189 | 479 | else | ||
190 | 480 | exec = g_strconcat (binary, " --", parameter, sufix, NULL); | ||
191 | 481 | |||
192 | 482 | l = g_hash_table_lookup (self->priv->desktop_file_table, exec); | ||
193 | 483 | g_free (exec); | ||
194 | 484 | |||
195 | 485 | if (!l && parameter) | ||
199 | 486 | { | 483 | { |
202 | 487 | exec = g_strconcat (binary, " -", parameter, sufix, NULL); | 484 | exec = g_strconcat (binary, " --", parameter, NULL); |
201 | 488 | |||
203 | 489 | l = g_hash_table_lookup (self->priv->desktop_file_table, exec); | 485 | l = g_hash_table_lookup (self->priv->desktop_file_table, exec); |
204 | 490 | g_free (exec); | 486 | g_free (exec); |
205 | 487 | |||
206 | 488 | if (!l) | ||
207 | 489 | { | ||
208 | 490 | exec = g_strconcat (binary, " -", parameter, NULL); | ||
209 | 491 | l = g_hash_table_lookup (self->priv->desktop_file_table, exec); | ||
210 | 492 | g_free (exec); | ||
211 | 493 | |||
212 | 494 | if (!l) | ||
213 | 495 | { | ||
214 | 496 | exec = g_strconcat (binary, "-", parameter, NULL); | ||
215 | 497 | l = g_hash_table_lookup (self->priv->desktop_id_table, exec); | ||
216 | 498 | g_free (exec); | ||
217 | 499 | } | ||
218 | 500 | } | ||
219 | 501 | } | ||
220 | 502 | else | ||
221 | 503 | { | ||
222 | 504 | l = g_hash_table_lookup (self->priv->desktop_file_table, binary); | ||
223 | 491 | } | 505 | } |
224 | 492 | 506 | ||
225 | 493 | return (l ? (char *) l->data : NULL); | 507 | return (l ? (char *) l->data : NULL); |
226 | 494 | } | 508 | } |
227 | 495 | 509 | ||
228 | 496 | /* Attempts to return the binary name for a particular execution string */ | 510 | /* Attempts to return the binary name for a particular execution string */ |
231 | 497 | static char * | 511 | char * |
232 | 498 | trim_exec_string (BamfMatcher * self, char * execString) | 512 | bamf_matcher_get_trimmed_exec (BamfMatcher * self, const char * exec_string) |
233 | 499 | { | 513 | { |
235 | 500 | gchar *result = NULL, *exec = NULL, *part = NULL, *tmp = NULL; | 514 | gchar *result = NULL, *part, *tmp; |
236 | 501 | gchar **parts; | 515 | gchar **parts; |
240 | 502 | gint i, j; | 516 | gint i, j, parts_size; |
241 | 503 | gboolean regexFail; | 517 | gboolean bad_prefix; |
242 | 504 | gboolean goodPrefix = FALSE; | 518 | gboolean good_prefix = FALSE; |
243 | 519 | gboolean double_parsed = FALSE; | ||
244 | 505 | GRegex *regex; | 520 | GRegex *regex; |
245 | 506 | 521 | ||
247 | 507 | if (!execString || (execString && execString[0] == '\0')) | 522 | if (!exec_string || exec_string[0] == '\0') |
248 | 508 | return NULL; | 523 | return NULL; |
249 | 509 | 524 | ||
252 | 510 | exec = g_utf8_casefold (execString, -1); | 525 | if (!g_shell_parse_argv (exec_string, &parts_size, &parts, NULL)) |
253 | 511 | parts = g_strsplit (exec, " ", 0); | 526 | return g_strdup (exec_string); |
254 | 512 | 527 | ||
257 | 513 | i = 0; | 528 | for (i = 0; i < parts_size; ++i) |
256 | 514 | while (parts[i] != NULL) | ||
258 | 515 | { | 529 | { |
259 | 516 | part = parts[i]; | 530 | part = parts[i]; |
260 | 531 | if (*part == '%' || g_utf8_strrchr (part, -1, '=')) | ||
261 | 532 | continue; | ||
262 | 517 | 533 | ||
264 | 518 | if (part[0] != '-') | 534 | if (*part != '-' || good_prefix) |
265 | 519 | { | 535 | { |
269 | 520 | if (goodPrefix) | 536 | if (!result) |
270 | 521 | { | 537 | { |
271 | 522 | gchar *tmp = g_strconcat (result, " ", part, NULL); | 538 | tmp = g_utf8_strrchr (part, -1, G_DIR_SEPARATOR); |
272 | 539 | if (tmp) | ||
273 | 540 | part = tmp + 1; | ||
274 | 541 | } | ||
275 | 542 | |||
276 | 543 | if (good_prefix) | ||
277 | 544 | { | ||
278 | 545 | tmp = g_strconcat (result, " ", part, NULL); | ||
279 | 523 | g_free (result); | 546 | g_free (result); |
280 | 524 | result = tmp; | 547 | result = tmp; |
281 | 525 | } | 548 | } |
282 | @@ -530,113 +553,81 @@ | |||
283 | 530 | regex = g_array_index (self->priv->good_prefixes, GRegex *, j); | 553 | regex = g_array_index (self->priv->good_prefixes, GRegex *, j); |
284 | 531 | if (g_regex_match (regex, part, 0, NULL)) | 554 | if (g_regex_match (regex, part, 0, NULL)) |
285 | 532 | { | 555 | { |
288 | 533 | goodPrefix = TRUE; | 556 | good_prefix = TRUE; |
289 | 534 | result = g_strdup (part); | 557 | result = g_ascii_strdown (part, -1); |
290 | 535 | break; | 558 | break; |
291 | 536 | } | 559 | } |
292 | 537 | } | 560 | } |
302 | 538 | } | 561 | |
303 | 539 | 562 | if (good_prefix) | |
304 | 540 | if (!goodPrefix) | 563 | continue; |
305 | 541 | { | 564 | |
306 | 542 | tmp = g_utf8_strrchr (part, -1, G_DIR_SEPARATOR); | 565 | bad_prefix = FALSE; |
298 | 543 | if (tmp) | ||
299 | 544 | part = tmp + 1; | ||
300 | 545 | |||
301 | 546 | regexFail = FALSE; | ||
307 | 547 | for (j = 0; j < self->priv->bad_prefixes->len; j++) | 566 | for (j = 0; j < self->priv->bad_prefixes->len; j++) |
308 | 548 | { | 567 | { |
309 | 549 | regex = g_array_index (self->priv->bad_prefixes, GRegex *, j); | 568 | regex = g_array_index (self->priv->bad_prefixes, GRegex *, j); |
310 | 550 | if (g_regex_match (regex, part, 0, NULL)) | 569 | if (g_regex_match (regex, part, 0, NULL)) |
311 | 551 | { | 570 | { |
313 | 552 | regexFail = TRUE; | 571 | bad_prefix = TRUE; |
314 | 553 | break; | 572 | break; |
315 | 554 | } | 573 | } |
316 | 555 | } | 574 | } |
317 | 556 | 575 | ||
319 | 557 | if (!regexFail) | 576 | if (!bad_prefix) |
320 | 558 | { | 577 | { |
322 | 559 | result = g_strdup (part); | 578 | if (!double_parsed && g_utf8_strrchr (part, -1, ' ')) |
323 | 579 | { | ||
324 | 580 | /* If the current exec_string has an empty char, | ||
325 | 581 | * we double check it again to parse scripts: | ||
326 | 582 | * For example strings like 'sh -c "foo || bar"' */ | ||
327 | 583 | gchar **old_parts = parts; | ||
328 | 584 | |||
329 | 585 | if (g_shell_parse_argv (part, &parts_size, &parts, NULL)) | ||
330 | 586 | { | ||
331 | 587 | // Make the loop to restart! | ||
332 | 588 | g_strfreev (old_parts); | ||
333 | 589 | i = -1; | ||
334 | 590 | continue; | ||
335 | 591 | } | ||
336 | 592 | |||
337 | 593 | double_parsed = TRUE; | ||
338 | 594 | } | ||
339 | 595 | |||
340 | 596 | result = g_ascii_strdown (part, -1); | ||
341 | 560 | break; | 597 | break; |
342 | 561 | } | 598 | } |
343 | 562 | } | 599 | } |
344 | 563 | } | 600 | } |
345 | 564 | else if (goodPrefix) | ||
346 | 565 | { | ||
347 | 566 | break; | ||
348 | 567 | } | ||
349 | 568 | |||
350 | 569 | i++; | ||
351 | 570 | } | 601 | } |
352 | 571 | 602 | ||
353 | 572 | if (!result) | 603 | if (!result) |
354 | 573 | { | 604 | { |
356 | 574 | result = g_strdup (execString); | 605 | if (parts_size > 0) |
357 | 606 | { | ||
358 | 607 | tmp = g_utf8_strrchr (parts[0], -1, G_DIR_SEPARATOR); | ||
359 | 608 | if (tmp) | ||
360 | 609 | exec_string = tmp + 1; | ||
361 | 610 | } | ||
362 | 611 | |||
363 | 612 | result = g_strdup (exec_string); | ||
364 | 575 | } | 613 | } |
365 | 576 | else | 614 | else |
366 | 577 | { | 615 | { |
367 | 578 | tmp = result; | 616 | tmp = result; |
370 | 579 | 617 | ||
371 | 580 | regex = g_regex_new ("((\\.|-)bin|\\.py)$", 0, 0, NULL); | 618 | regex = g_regex_new ("(\\.bin|\\.py|\\.pl)$", 0, 0, NULL); |
372 | 581 | result = g_regex_replace_literal (regex, result, -1, 0, "", 0, NULL); | 619 | result = g_regex_replace_literal (regex, result, -1, 0, "", 0, NULL); |
374 | 582 | 620 | ||
375 | 583 | g_free (tmp); | 621 | g_free (tmp); |
376 | 584 | g_regex_unref (regex); | 622 | g_regex_unref (regex); |
377 | 585 | } | 623 | } |
378 | 586 | 624 | ||
379 | 587 | g_free (exec); | ||
380 | 588 | g_strfreev (parts); | 625 | g_strfreev (parts); |
381 | 589 | 626 | ||
382 | 590 | return result; | 627 | return result; |
383 | 591 | } | 628 | } |
384 | 592 | 629 | ||
385 | 593 | static GArray * | 630 | static GArray * |
386 | 594 | bad_prefix_strings (void) | ||
387 | 595 | { | ||
388 | 596 | GArray *arr = g_array_new (FALSE, TRUE, sizeof (char *)); | ||
389 | 597 | |||
390 | 598 | char *str = "^gksu(do)?$"; | ||
391 | 599 | g_array_append_val (arr, str); | ||
392 | 600 | |||
393 | 601 | str = "^sudo$"; | ||
394 | 602 | g_array_append_val (arr, str); | ||
395 | 603 | |||
396 | 604 | str = "^java$"; | ||
397 | 605 | g_array_append_val (arr, str); | ||
398 | 606 | |||
399 | 607 | str = "^mono$"; | ||
400 | 608 | g_array_append_val (arr, str); | ||
401 | 609 | |||
402 | 610 | str = "^ruby$"; | ||
403 | 611 | g_array_append_val (arr, str); | ||
404 | 612 | |||
405 | 613 | str = "^padsp$"; | ||
406 | 614 | g_array_append_val (arr, str); | ||
407 | 615 | |||
408 | 616 | str = "^aoss$"; | ||
409 | 617 | g_array_append_val (arr, str); | ||
410 | 618 | |||
411 | 619 | str = "^python(\\d.\\d)?$"; | ||
412 | 620 | g_array_append_val (arr, str); | ||
413 | 621 | |||
414 | 622 | str = "^(ba)?sh$"; | ||
415 | 623 | g_array_append_val (arr, str); | ||
416 | 624 | |||
417 | 625 | return arr; | ||
418 | 626 | } | ||
419 | 627 | |||
420 | 628 | static GArray * | ||
421 | 629 | good_prefix_strings (void) | ||
422 | 630 | { | ||
423 | 631 | GArray *arr = g_array_new (FALSE, TRUE, sizeof (char *)); | ||
424 | 632 | |||
425 | 633 | char *str = "^gnome-control-center$"; | ||
426 | 634 | g_array_append_val (arr, str); | ||
427 | 635 | |||
428 | 636 | return arr; | ||
429 | 637 | } | ||
430 | 638 | |||
431 | 639 | static GArray * | ||
432 | 640 | pid_parent_tree (BamfMatcher *self, gint pid) | 631 | pid_parent_tree (BamfMatcher *self, gint pid) |
433 | 641 | { | 632 | { |
434 | 642 | BamfMatcherPrivate *priv; | 633 | BamfMatcherPrivate *priv; |
435 | @@ -678,15 +669,6 @@ | |||
436 | 678 | } | 669 | } |
437 | 679 | 670 | ||
438 | 680 | static gboolean | 671 | static gboolean |
439 | 681 | exec_string_should_be_processed (const char *exec) | ||
440 | 682 | { | ||
441 | 683 | if (!exec) | ||
442 | 684 | return TRUE; | ||
443 | 685 | |||
444 | 686 | return !g_str_has_prefix (exec, "ooffice") && !g_str_has_prefix (exec, "libreoffice"); | ||
445 | 687 | } | ||
446 | 688 | |||
447 | 689 | static gboolean | ||
448 | 690 | is_desktop_folder_item (const char *desktop_file_path, gssize max_len) | 672 | is_desktop_folder_item (const char *desktop_file_path, gssize max_len) |
449 | 691 | { | 673 | { |
450 | 692 | gsize len; | 674 | gsize len; |
451 | @@ -850,18 +832,15 @@ | |||
452 | 850 | return; | 832 | return; |
453 | 851 | } | 833 | } |
454 | 852 | 834 | ||
467 | 853 | if (exec_string_should_be_processed (exec)) | 835 | /** |
468 | 854 | { | 836 | * Set of nasty hacks which should be removed some day. We wish to keep the full exec |
469 | 855 | /** | 837 | * strings so we can do nasty matching hacks later. A very very evil thing indeed. However this |
470 | 856 | * Set of nasty hacks which should be removed some day. We wish to keep the full exec | 838 | * helps hack around applications that run in the same process cross radically different instances. |
471 | 857 | * strings so we can do nasty matching hacks later. A very very evil thing indeed. However this | 839 | * A better solution needs to be thought up, however at this time it is not known. |
472 | 858 | * helps hack around applications that run in the same process cross radically different instances. | 840 | **/ |
473 | 859 | * A better solution needs to be thought up, however at this time it is not known. | 841 | char *tmp = bamf_matcher_get_trimmed_exec (self, exec); |
474 | 860 | **/ | 842 | g_free (exec); |
475 | 861 | char *tmp = trim_exec_string (self, exec); | 843 | exec = tmp; |
464 | 862 | g_free (exec); | ||
465 | 863 | exec = tmp; | ||
466 | 864 | } | ||
476 | 865 | 844 | ||
477 | 866 | path = g_path_get_basename (file); | 845 | path = g_path_get_basename (file); |
478 | 867 | desktop_id = g_string_new (path); | 846 | desktop_id = g_string_new (path); |
479 | @@ -958,16 +937,12 @@ | |||
480 | 958 | GString *desktop_id; | 937 | GString *desktop_id; |
481 | 959 | 938 | ||
482 | 960 | gchar **parts = g_strsplit (line, "\t", 3); | 939 | gchar **parts = g_strsplit (line, "\t", 3); |
483 | 940 | |||
484 | 941 | char *tmp = bamf_matcher_get_trimmed_exec (self, parts[1]); | ||
485 | 942 | g_free (parts[1]); | ||
486 | 943 | parts[1] = tmp; | ||
487 | 961 | exec = parts[1]; | 944 | exec = parts[1]; |
488 | 962 | 945 | ||
489 | 963 | if (exec_string_should_be_processed (exec)) | ||
490 | 964 | { | ||
491 | 965 | char *tmp = trim_exec_string (self, exec); | ||
492 | 966 | g_free (parts[1]); | ||
493 | 967 | parts[1] = tmp; | ||
494 | 968 | exec = parts[1]; | ||
495 | 969 | } | ||
496 | 970 | |||
497 | 971 | filename = g_build_filename (directory, parts[0], NULL); | 946 | filename = g_build_filename (directory, parts[0], NULL); |
498 | 972 | 947 | ||
499 | 973 | desktop_id = g_string_new (parts[0]); | 948 | desktop_id = g_string_new (parts[0]); |
500 | @@ -1172,7 +1147,7 @@ | |||
501 | 1172 | free_func (l->data); | 1147 | free_func (l->data); |
502 | 1173 | 1148 | ||
503 | 1174 | /* If the target is the first element of the list (and thanks to | 1149 | /* If the target is the first element of the list (and thanks to |
505 | 1175 | - * the previous check we're also sure that it's not the only one), | 1150 | * the previous check we're also sure that it's not the only one), |
506 | 1176 | * simply switch it with its follower, not to change the first | 1151 | * simply switch it with its follower, not to change the first |
507 | 1177 | * pointer and the hash table value for key | 1152 | * pointer and the hash table value for key |
508 | 1178 | */ | 1153 | */ |
509 | @@ -1301,15 +1276,25 @@ | |||
510 | 1301 | } | 1276 | } |
511 | 1302 | 1277 | ||
512 | 1303 | static void | 1278 | static void |
514 | 1304 | bamf_add_new_monitored_directory (BamfMatcher * self, const gchar *directory) | 1279 | bamf_matcher_add_new_monitored_directory (BamfMatcher * self, const gchar *directory) |
515 | 1305 | { | 1280 | { |
516 | 1306 | g_return_if_fail (BAMF_IS_MATCHER (self)); | 1281 | g_return_if_fail (BAMF_IS_MATCHER (self)); |
517 | 1307 | 1282 | ||
518 | 1308 | GFile *file; | 1283 | GFile *file; |
519 | 1309 | GFileMonitor *monitor; | 1284 | GFileMonitor *monitor; |
520 | 1285 | GError *error = NULL; | ||
521 | 1310 | 1286 | ||
522 | 1311 | file = g_file_new_for_path (directory); | 1287 | file = g_file_new_for_path (directory); |
524 | 1312 | monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); | 1288 | monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, &error); |
525 | 1289 | |||
526 | 1290 | if (error) | ||
527 | 1291 | { | ||
528 | 1292 | g_warning ("Error monitoring %s: %s\n", directory, error->message); | ||
529 | 1293 | g_error_free (error); | ||
530 | 1294 | g_object_unref (file); | ||
531 | 1295 | return; | ||
532 | 1296 | } | ||
533 | 1297 | |||
534 | 1313 | g_file_monitor_set_rate_limit (monitor, 1000); | 1298 | g_file_monitor_set_rate_limit (monitor, 1000); |
535 | 1314 | g_object_set_data_full (G_OBJECT (monitor), "root", g_strdup (directory), g_free); | 1299 | g_object_set_data_full (G_OBJECT (monitor), "root", g_strdup (directory), g_free); |
536 | 1315 | g_signal_connect (monitor, "changed", (GCallback) on_monitor_changed, self); | 1300 | g_signal_connect (monitor, "changed", (GCallback) on_monitor_changed, self); |
537 | @@ -1338,7 +1323,7 @@ | |||
538 | 1338 | if (!g_file_test (directory, G_FILE_TEST_IS_DIR)) | 1323 | if (!g_file_test (directory, G_FILE_TEST_IS_DIR)) |
539 | 1339 | continue; | 1324 | continue; |
540 | 1340 | 1325 | ||
542 | 1341 | bamf_add_new_monitored_directory (self, directory); | 1326 | bamf_matcher_add_new_monitored_directory (self, directory); |
543 | 1342 | 1327 | ||
544 | 1343 | bamf_file = g_build_filename (directory, "bamf.index", NULL); | 1328 | bamf_file = g_build_filename (directory, "bamf.index", NULL); |
545 | 1344 | 1329 | ||
546 | @@ -1492,8 +1477,7 @@ | |||
547 | 1492 | 1477 | ||
548 | 1493 | if (exec_string) | 1478 | if (exec_string) |
549 | 1494 | { | 1479 | { |
552 | 1495 | trimmed = trim_exec_string (self, exec_string); | 1480 | trimmed = bamf_matcher_get_trimmed_exec (self, exec_string); |
551 | 1496 | |||
553 | 1497 | if (trimmed) | 1481 | if (trimmed) |
554 | 1498 | { | 1482 | { |
555 | 1499 | if (trimmed[0] != '\0') | 1483 | if (trimmed[0] != '\0') |
556 | @@ -1882,6 +1866,7 @@ | |||
557 | 1882 | /* secondary matching */ | 1866 | /* secondary matching */ |
558 | 1883 | GList *a; | 1867 | GList *a; |
559 | 1884 | BamfView *view; | 1868 | BamfView *view; |
560 | 1869 | |||
561 | 1885 | const gchar *app_desktop_class; | 1870 | const gchar *app_desktop_class; |
562 | 1886 | 1871 | ||
563 | 1887 | for (a = self->priv->views; a; a = a->next) | 1872 | for (a = self->priv->views; a; a = a->next) |
564 | @@ -1892,10 +1877,41 @@ | |||
565 | 1892 | continue; | 1877 | continue; |
566 | 1893 | 1878 | ||
567 | 1894 | app = BAMF_APPLICATION (view); | 1879 | app = BAMF_APPLICATION (view); |
568 | 1895 | app_desktop_class = bamf_application_get_wmclass (app); | ||
569 | 1896 | 1880 | ||
570 | 1897 | if (bamf_application_contains_similar_to_window (app, bamf_window)) | 1881 | if (bamf_application_contains_similar_to_window (app, bamf_window)) |
571 | 1898 | { | 1882 | { |
572 | 1883 | char *exec_string = bamf_legacy_window_get_exec_string (window); | ||
573 | 1884 | char *trimmed_exec = bamf_matcher_get_trimmed_exec (self, exec_string); | ||
574 | 1885 | g_free (exec_string); | ||
575 | 1886 | |||
576 | 1887 | GList *ll; | ||
577 | 1888 | gboolean found_exec = FALSE; | ||
578 | 1889 | for (ll = bamf_view_get_children (BAMF_VIEW (app)); ll && !found_exec; ll = ll->next) | ||
579 | 1890 | { | ||
580 | 1891 | if (!BAMF_IS_WINDOW (ll->data)) | ||
581 | 1892 | continue; | ||
582 | 1893 | |||
583 | 1894 | BamfLegacyWindow *w = bamf_window_get_window (BAMF_WINDOW (ll->data)); | ||
584 | 1895 | char *wexec = bamf_legacy_window_get_exec_string (w); | ||
585 | 1896 | char *wtrimmed = bamf_matcher_get_trimmed_exec (self, wexec); | ||
586 | 1897 | g_free (wexec); | ||
587 | 1898 | |||
588 | 1899 | if (g_strcmp0 (trimmed_exec, wtrimmed) == 0) | ||
589 | 1900 | { | ||
590 | 1901 | best = BAMF_APPLICATION (view); | ||
591 | 1902 | found_exec = TRUE; | ||
592 | 1903 | } | ||
593 | 1904 | |||
594 | 1905 | g_free (wtrimmed); | ||
595 | 1906 | } | ||
596 | 1907 | |||
597 | 1908 | g_free (trimmed_exec); | ||
598 | 1909 | |||
599 | 1910 | if (!found_exec) | ||
600 | 1911 | continue; | ||
601 | 1912 | |||
602 | 1913 | app_desktop_class = bamf_application_get_wmclass (app); | ||
603 | 1914 | |||
604 | 1899 | if (target_class && g_strcmp0 (target_class, app_desktop_class) == 0) | 1915 | if (target_class && g_strcmp0 (target_class, app_desktop_class) == 0) |
605 | 1900 | { | 1916 | { |
606 | 1901 | best = app; | 1917 | best = app; |
607 | @@ -2068,26 +2084,26 @@ | |||
608 | 2068 | get_gnome_control_center_window_hint (BamfMatcher * self, BamfLegacyWindow * window) | 2084 | get_gnome_control_center_window_hint (BamfMatcher * self, BamfLegacyWindow * window) |
609 | 2069 | { | 2085 | { |
610 | 2070 | gchar *role; | 2086 | gchar *role; |
611 | 2071 | gchar *exec; | ||
612 | 2072 | GHashTable *desktopFileTable; | ||
613 | 2073 | GList *list; | 2087 | GList *list; |
614 | 2074 | 2088 | ||
615 | 2075 | g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL); | 2089 | g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL); |
616 | 2076 | g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL); | 2090 | g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL); |
617 | 2077 | 2091 | ||
618 | 2092 | list = NULL; | ||
619 | 2078 | role = bamf_legacy_window_get_hint (window, WM_WINDOW_ROLE); | 2093 | role = bamf_legacy_window_get_hint (window, WM_WINDOW_ROLE); |
632 | 2079 | exec = g_strconcat ("gnome-control-center", (role ? " " : NULL), role, NULL); | 2094 | |
633 | 2080 | 2095 | if (role) | |
634 | 2081 | desktopFileTable = self->priv->desktop_file_table; | 2096 | { |
635 | 2082 | list = g_hash_table_lookup (desktopFileTable, exec); | 2097 | gchar *exec = g_strconcat ("gnome-control-center ", role, NULL); |
636 | 2083 | 2098 | list = g_hash_table_lookup (self->priv->desktop_file_table, exec); | |
637 | 2084 | if (!list && g_strcmp0 ("gnome-control-center", exec) != 0) | 2099 | g_free (exec); |
638 | 2085 | { | 2100 | g_free (role); |
639 | 2086 | list = g_hash_table_lookup (desktopFileTable, "gnome-control-center"); | 2101 | } |
640 | 2087 | } | 2102 | |
641 | 2088 | 2103 | if (!role || !list) | |
642 | 2089 | g_free (exec); | 2104 | { |
643 | 2090 | g_free (role); | 2105 | list = g_hash_table_lookup (self->priv->desktop_id_table, "gnome-control-center"); |
644 | 2106 | } | ||
645 | 2091 | 2107 | ||
646 | 2092 | return (list ? (char *) list->data : NULL); | 2108 | return (list ? (char *) list->data : NULL); |
647 | 2093 | } | 2109 | } |
648 | @@ -2125,7 +2141,8 @@ | |||
649 | 2125 | g_return_if_fail (BAMF_IS_MATCHER (self)); | 2141 | g_return_if_fail (BAMF_IS_MATCHER (self)); |
650 | 2126 | g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window)); | 2142 | g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window)); |
651 | 2127 | 2143 | ||
653 | 2128 | if (bamf_legacy_window_get_window_type (window) == BAMF_WINDOW_DESKTOP) | 2144 | BamfWindowType win_type = bamf_legacy_window_get_window_type (window); |
654 | 2145 | if (win_type == BAMF_WINDOW_DESKTOP) | ||
655 | 2129 | { | 2146 | { |
656 | 2130 | BamfWindow *bamfwindow = bamf_window_new (window); | 2147 | BamfWindow *bamfwindow = bamf_window_new (window); |
657 | 2131 | bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (bamfwindow)); | 2148 | bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (bamfwindow)); |
658 | @@ -2135,8 +2152,6 @@ | |||
659 | 2135 | 2152 | ||
660 | 2136 | if (is_open_office_window (self, window)) | 2153 | if (is_open_office_window (self, window)) |
661 | 2137 | { | 2154 | { |
662 | 2138 | BamfWindowType win_type = bamf_legacy_window_get_window_type (window); | ||
663 | 2139 | |||
664 | 2140 | if (win_type == BAMF_WINDOW_SPLASHSCREEN || win_type == BAMF_WINDOW_TOOLBAR) | 2155 | if (win_type == BAMF_WINDOW_SPLASHSCREEN || win_type == BAMF_WINDOW_TOOLBAR) |
665 | 2141 | { | 2156 | { |
666 | 2142 | return; | 2157 | return; |
667 | @@ -2895,34 +2910,29 @@ | |||
668 | 2895 | BamfMatcherPrivate *priv; | 2910 | BamfMatcherPrivate *priv; |
669 | 2896 | BamfLegacyScreen *screen; | 2911 | BamfLegacyScreen *screen; |
670 | 2897 | BamfIndicatorSource *approver; | 2912 | BamfIndicatorSource *approver; |
671 | 2898 | GArray *prefixstrings; | ||
672 | 2899 | int i; | 2913 | int i; |
673 | 2900 | 2914 | ||
674 | 2901 | priv = self->priv = BAMF_MATCHER_GET_PRIVATE (self); | 2915 | priv = self->priv = BAMF_MATCHER_GET_PRIVATE (self); |
675 | 2902 | 2916 | ||
676 | 2903 | priv->known_pids = g_array_new (FALSE, TRUE, sizeof (gint)); | 2917 | priv->known_pids = g_array_new (FALSE, TRUE, sizeof (gint)); |
679 | 2904 | priv->bad_prefixes = g_array_new (FALSE, TRUE, sizeof (GRegex *)); | 2918 | priv->bad_prefixes = g_array_sized_new (FALSE, TRUE, sizeof (GRegex *), |
680 | 2905 | priv->good_prefixes = g_array_new (FALSE, TRUE, sizeof (GRegex *)); | 2919 | G_N_ELEMENTS (EXEC_BAD_PREFIXES)); |
681 | 2920 | priv->good_prefixes = g_array_sized_new (FALSE, TRUE, sizeof (GRegex *), | ||
682 | 2921 | G_N_ELEMENTS (EXEC_GOOD_PREFIXES)); | ||
683 | 2906 | priv->registered_pids = g_hash_table_new_full (g_direct_hash, g_direct_equal, | 2922 | priv->registered_pids = g_hash_table_new_full (g_direct_hash, g_direct_equal, |
684 | 2907 | NULL, g_free); | 2923 | NULL, g_free); |
685 | 2908 | 2924 | ||
688 | 2909 | prefixstrings = bad_prefix_strings (); | 2925 | for (i = 0; i < G_N_ELEMENTS (EXEC_BAD_PREFIXES); ++i) |
687 | 2910 | for (i = 0; i < prefixstrings->len; i++) | ||
689 | 2911 | { | 2926 | { |
692 | 2912 | char *str = g_array_index (prefixstrings, char *, i); | 2927 | GRegex *regex = g_regex_new (EXEC_BAD_PREFIXES[i], G_REGEX_OPTIMIZE, 0, NULL); |
691 | 2913 | GRegex *regex = g_regex_new (str, G_REGEX_OPTIMIZE, 0, NULL); | ||
693 | 2914 | g_array_append_val (priv->bad_prefixes, regex); | 2928 | g_array_append_val (priv->bad_prefixes, regex); |
694 | 2915 | } | 2929 | } |
695 | 2916 | g_array_free (prefixstrings, TRUE); | ||
696 | 2917 | 2930 | ||
699 | 2918 | prefixstrings = good_prefix_strings (); | 2931 | for (i = 0; i < G_N_ELEMENTS (EXEC_GOOD_PREFIXES); ++i) |
698 | 2919 | for (i = 0; i < prefixstrings->len; i++) | ||
700 | 2920 | { | 2932 | { |
703 | 2921 | char *str = g_array_index (prefixstrings, char *, i); | 2933 | GRegex *regex = g_regex_new (EXEC_GOOD_PREFIXES[i], G_REGEX_OPTIMIZE, 0, NULL); |
702 | 2922 | GRegex *regex = g_regex_new (str, G_REGEX_OPTIMIZE, 0, NULL); | ||
704 | 2923 | g_array_append_val (priv->good_prefixes, regex); | 2934 | g_array_append_val (priv->good_prefixes, regex); |
705 | 2924 | } | 2935 | } |
706 | 2925 | g_array_free (prefixstrings, TRUE); | ||
707 | 2926 | 2936 | ||
708 | 2927 | create_desktop_file_table (self, &(priv->desktop_file_table), | 2937 | create_desktop_file_table (self, &(priv->desktop_file_table), |
709 | 2928 | &(priv->desktop_id_table), | 2938 | &(priv->desktop_id_table), |
710 | @@ -3046,6 +3056,7 @@ | |||
711 | 3046 | g_signal_handlers_disconnect_by_func (G_OBJECT (l->data), | 3056 | g_signal_handlers_disconnect_by_func (G_OBJECT (l->data), |
712 | 3047 | (GCallback) on_monitor_changed, self); | 3057 | (GCallback) on_monitor_changed, self); |
713 | 3048 | } | 3058 | } |
714 | 3059 | |||
715 | 3049 | g_list_free_full (priv->monitors, g_object_unref); | 3060 | g_list_free_full (priv->monitors, g_object_unref); |
716 | 3050 | priv->monitors = NULL; | 3061 | priv->monitors = NULL; |
717 | 3051 | 3062 | ||
718 | 3052 | 3063 | ||
719 | === modified file 'tests/bamfdaemon/Makefile.am' | |||
720 | --- tests/bamfdaemon/Makefile.am 2012-11-28 12:16:12 +0000 | |||
721 | +++ tests/bamfdaemon/Makefile.am 2013-01-10 00:14:24 +0000 | |||
722 | @@ -119,6 +119,7 @@ | |||
723 | 119 | export LOG_PATH=$(LOG_PATH); \ | 119 | export LOG_PATH=$(LOG_PATH); \ |
724 | 120 | export XVFB_PATH=$(XVFB); \ | 120 | export XVFB_PATH=$(XVFB); \ |
725 | 121 | export DISPLAY=""; \ | 121 | export DISPLAY=""; \ |
726 | 122 | export XDG_CURRENT_DESKTOP="Unity"; \ | ||
727 | 122 | source $(XVFB_RUN); \ | 123 | source $(XVFB_RUN); \ |
728 | 123 | \ | 124 | \ |
729 | 124 | $(DBUS_LAUNCH) > $(LOG_PATH)/sessionbus.sh; \ | 125 | $(DBUS_LAUNCH) > $(LOG_PATH)/sessionbus.sh; \ |
730 | 125 | 126 | ||
731 | === added file 'tests/bamfdaemon/data/gnome-control-center.desktop' | |||
732 | --- tests/bamfdaemon/data/gnome-control-center.desktop 1970-01-01 00:00:00 +0000 | |||
733 | +++ tests/bamfdaemon/data/gnome-control-center.desktop 2013-01-10 00:14:24 +0000 | |||
734 | @@ -0,0 +1,9 @@ | |||
735 | 1 | [Desktop Entry] | ||
736 | 2 | Name=System Settings | ||
737 | 3 | Icon=preferences-system | ||
738 | 4 | Exec=gnome-control-center --overview | ||
739 | 5 | Terminal=false | ||
740 | 6 | Type=Application | ||
741 | 7 | StartupNotify=true | ||
742 | 8 | Categories=GNOME;GTK;System; | ||
743 | 9 | OnlyShowIn=GNOME;Unity; | ||
744 | 0 | 10 | ||
745 | === added file 'tests/bamfdaemon/data/gnome-display-panel.desktop' | |||
746 | --- tests/bamfdaemon/data/gnome-display-panel.desktop 1970-01-01 00:00:00 +0000 | |||
747 | +++ tests/bamfdaemon/data/gnome-display-panel.desktop 2013-01-10 00:14:24 +0000 | |||
748 | @@ -0,0 +1,10 @@ | |||
749 | 1 | [Desktop Entry] | ||
750 | 2 | Name=Displays | ||
751 | 3 | Comment=Change resolution and position of monitors and projectors | ||
752 | 4 | Exec=gnome-control-center display | ||
753 | 5 | Icon=preferences-desktop-display | ||
754 | 6 | Terminal=false | ||
755 | 7 | Type=Application | ||
756 | 8 | StartupNotify=true | ||
757 | 9 | Categories=GNOME;GTK;Settings;HardwareSettings;X-GNOME-Settings-Panel; | ||
758 | 10 | OnlyShowIn=GNOME;Unity; | ||
759 | 0 | 11 | ||
760 | === added file 'tests/bamfdaemon/data/gnome-mouse-panel.desktop' | |||
761 | --- tests/bamfdaemon/data/gnome-mouse-panel.desktop 1970-01-01 00:00:00 +0000 | |||
762 | +++ tests/bamfdaemon/data/gnome-mouse-panel.desktop 2013-01-10 00:14:24 +0000 | |||
763 | @@ -0,0 +1,10 @@ | |||
764 | 1 | [Desktop Entry] | ||
765 | 2 | Name=Mouse and Touchpad | ||
766 | 3 | Comment=Set your mouse and touchpad preferences | ||
767 | 4 | Exec=gnome-control-center mouse | ||
768 | 5 | Icon=input-mouse | ||
769 | 6 | Terminal=false | ||
770 | 7 | Type=Application | ||
771 | 8 | StartupNotify=true | ||
772 | 9 | Categories=GNOME;GTK;Settings;HardwareSettings;X-GNOME-Settings-Panel; | ||
773 | 10 | OnlyShowIn=GNOME;Unity; | ||
774 | 0 | 11 | ||
775 | === modified file 'tests/bamfdaemon/test-matcher.c' | |||
776 | --- tests/bamfdaemon/test-matcher.c 2012-10-10 17:36:21 +0000 | |||
777 | +++ tests/bamfdaemon/test-matcher.c 2013-01-10 00:14:24 +0000 | |||
778 | @@ -32,7 +32,10 @@ | |||
779 | 32 | static void test_match_desktopless_application (void); | 32 | static void test_match_desktopless_application (void); |
780 | 33 | static void test_match_desktop_application (void); | 33 | static void test_match_desktop_application (void); |
781 | 34 | static void test_match_libreoffice_windows (void); | 34 | static void test_match_libreoffice_windows (void); |
782 | 35 | static void test_match_gnome_control_center_panels (void); | ||
783 | 36 | static void test_match_javaws_windows (void); | ||
784 | 35 | static void test_new_desktop_matches_unmatched_windows (void); | 37 | static void test_new_desktop_matches_unmatched_windows (void); |
785 | 38 | static void test_trim_exec_string (void); | ||
786 | 36 | 39 | ||
787 | 37 | static GDBusConnection *gdbus_connection = NULL; | 40 | static GDBusConnection *gdbus_connection = NULL; |
788 | 38 | 41 | ||
789 | @@ -51,7 +54,10 @@ | |||
790 | 51 | g_test_add_func (DOMAIN"/Matching/Application/DesktopLess", test_match_desktopless_application); | 54 | g_test_add_func (DOMAIN"/Matching/Application/DesktopLess", test_match_desktopless_application); |
791 | 52 | g_test_add_func (DOMAIN"/Matching/Application/Desktop", test_match_desktop_application); | 55 | g_test_add_func (DOMAIN"/Matching/Application/Desktop", test_match_desktop_application); |
792 | 53 | g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows); | 56 | g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows); |
793 | 57 | g_test_add_func (DOMAIN"/Matching/Application/GnomeControlCenter", test_match_gnome_control_center_panels); | ||
794 | 58 | g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart", test_match_javaws_windows); | ||
795 | 54 | g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows); | 59 | g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows); |
796 | 60 | g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string); | ||
797 | 55 | } | 61 | } |
798 | 56 | 62 | ||
799 | 57 | static void | 63 | static void |
800 | @@ -480,3 +486,211 @@ | |||
801 | 480 | g_object_unref (screen); | 486 | g_object_unref (screen); |
802 | 481 | } | 487 | } |
803 | 482 | 488 | ||
804 | 489 | static void | ||
805 | 490 | test_match_gnome_control_center_panels (void) | ||
806 | 491 | { | ||
807 | 492 | BamfMatcher *matcher; | ||
808 | 493 | BamfWindow *window; | ||
809 | 494 | BamfLegacyScreen *screen; | ||
810 | 495 | BamfLegacyWindowTest *test_win; | ||
811 | 496 | BamfApplication *app; | ||
812 | 497 | char *hint; | ||
813 | 498 | |||
814 | 499 | screen = bamf_legacy_screen_get_default (); | ||
815 | 500 | matcher = bamf_matcher_get_default (); | ||
816 | 501 | guint xid = g_random_int (); | ||
817 | 502 | const char *exec = "gnome-control-center"; | ||
818 | 503 | const char *class_name = "Gnome-control-center"; | ||
819 | 504 | const char *class_instance = "gnome-control-center"; | ||
820 | 505 | |||
821 | 506 | cleanup_matcher_tables (matcher); | ||
822 | 507 | export_matcher_on_bus (matcher); | ||
823 | 508 | |||
824 | 509 | bamf_matcher_load_desktop_file (matcher, DATA_DIR"/gnome-control-center.desktop"); | ||
825 | 510 | bamf_matcher_load_desktop_file (matcher, DATA_DIR"/gnome-display-panel.desktop"); | ||
826 | 511 | bamf_matcher_load_desktop_file (matcher, DATA_DIR"/gnome-mouse-panel.desktop"); | ||
827 | 512 | |||
828 | 513 | test_win = bamf_legacy_window_test_new (xid, "System Settings", NULL, exec); | ||
829 | 514 | bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance); | ||
830 | 515 | bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test_win), WM_WINDOW_ROLE, NULL); | ||
831 | 516 | _bamf_legacy_screen_open_test_window (screen, test_win); | ||
832 | 517 | |||
833 | 518 | hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE); | ||
834 | 519 | g_assert_cmpstr (hint, ==, DATA_DIR"/gnome-control-center.desktop"); | ||
835 | 520 | g_free (hint); | ||
836 | 521 | app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-control-center.desktop"); | ||
837 | 522 | g_assert (find_window_in_app (app, BAMF_LEGACY_WINDOW (test_win))); | ||
838 | 523 | |||
839 | 524 | bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test_win), WM_WINDOW_ROLE, "display"); | ||
840 | 525 | bamf_legacy_window_test_set_name (test_win, "Displays"); | ||
841 | 526 | g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-control-center.desktop")); | ||
842 | 527 | app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-display-panel.desktop"); | ||
843 | 528 | g_assert (app); | ||
844 | 529 | window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data); | ||
845 | 530 | test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window)); | ||
846 | 531 | hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE); | ||
847 | 532 | g_assert_cmpstr (hint, ==, DATA_DIR"/gnome-display-panel.desktop"); | ||
848 | 533 | g_free (hint); | ||
849 | 534 | |||
850 | 535 | bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test_win), WM_WINDOW_ROLE, "mouse"); | ||
851 | 536 | bamf_legacy_window_test_set_name (test_win, "Mouse and Touchpad"); | ||
852 | 537 | g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-display-panel.desktop")); | ||
853 | 538 | app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-mouse-panel.desktop"); | ||
854 | 539 | g_assert (app); | ||
855 | 540 | window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data); | ||
856 | 541 | test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window)); | ||
857 | 542 | hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE); | ||
858 | 543 | g_assert_cmpstr (hint, ==, DATA_DIR"/gnome-mouse-panel.desktop"); | ||
859 | 544 | g_free (hint); | ||
860 | 545 | |||
861 | 546 | bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test_win), WM_WINDOW_ROLE, "invalid-role"); | ||
862 | 547 | bamf_legacy_window_test_set_name (test_win, "Invalid Panel"); | ||
863 | 548 | g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-mouse-panel.desktop")); | ||
864 | 549 | app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-control-center.desktop"); | ||
865 | 550 | g_assert (app); | ||
866 | 551 | window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data); | ||
867 | 552 | test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window)); | ||
868 | 553 | hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE); | ||
869 | 554 | g_assert_cmpstr (hint, ==, DATA_DIR"/gnome-control-center.desktop"); | ||
870 | 555 | g_free (hint); | ||
871 | 556 | |||
872 | 557 | g_object_unref (matcher); | ||
873 | 558 | g_object_unref (screen); | ||
874 | 559 | } | ||
875 | 560 | |||
876 | 561 | static void | ||
877 | 562 | test_match_javaws_windows (void) | ||
878 | 563 | { | ||
879 | 564 | BamfMatcher *matcher; | ||
880 | 565 | BamfLegacyScreen *screen; | ||
881 | 566 | BamfLegacyWindowTest *test_win; | ||
882 | 567 | BamfApplication *app1, *app2, *app3; | ||
883 | 568 | GList *app_children; | ||
884 | 569 | |||
885 | 570 | screen = bamf_legacy_screen_get_default (); | ||
886 | 571 | matcher = bamf_matcher_get_default (); | ||
887 | 572 | const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \ | ||
888 | 573 | "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \ | ||
889 | 574 | "-Xms8m -Djava.security.manager " \ | ||
890 | 575 | "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \ | ||
891 | 576 | "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \ | ||
892 | 577 | "-Dicedtea-web.bin.name=javaws " \ | ||
893 | 578 | "-Dicedtea-web.bin.location=/usr/bin/javaws "\ | ||
894 | 579 | "net.sourceforge.jnlp.runtime.Boot"; | ||
895 | 580 | const char *class_name = "sun-awt-X11-XFramePeer"; | ||
896 | 581 | const char *class_instance = "net-sourceforge-jnlp-runtime-Boot"; | ||
897 | 582 | |||
898 | 583 | cleanup_matcher_tables (matcher); | ||
899 | 584 | export_matcher_on_bus (matcher); | ||
900 | 585 | |||
901 | 586 | guint xid = g_random_int (); | ||
902 | 587 | char *exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL); | ||
903 | 588 | test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec); | ||
904 | 589 | bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance); | ||
905 | 590 | _bamf_legacy_screen_open_test_window (screen, test_win); | ||
906 | 591 | g_free (exec); | ||
907 | 592 | app1 = bamf_matcher_get_application_by_xid (matcher, xid); | ||
908 | 593 | g_assert (BAMF_IS_APPLICATION (app1)); | ||
909 | 594 | app_children = bamf_view_get_children (BAMF_VIEW (app1)); | ||
910 | 595 | g_assert_cmpuint (g_list_length (app_children), ==, 1); | ||
911 | 596 | g_assert (find_window_in_app (app1, BAMF_LEGACY_WINDOW (test_win))); | ||
912 | 597 | |||
913 | 598 | xid = g_random_int (); | ||
914 | 599 | exec = g_strconcat (exec_prefix, " Draw.jnlp", NULL); | ||
915 | 600 | test_win = bamf_legacy_window_test_new (xid, "Draw", NULL, exec); | ||
916 | 601 | bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance); | ||
917 | 602 | _bamf_legacy_screen_open_test_window (screen, test_win); | ||
918 | 603 | g_free (exec); | ||
919 | 604 | app2 = bamf_matcher_get_application_by_xid (matcher, xid); | ||
920 | 605 | g_assert (BAMF_IS_APPLICATION (app2)); | ||
921 | 606 | g_assert (app1 != app2); | ||
922 | 607 | app_children = bamf_view_get_children (BAMF_VIEW (app2)); | ||
923 | 608 | g_assert_cmpuint (g_list_length (app_children), ==, 1); | ||
924 | 609 | g_assert (find_window_in_app (app2, BAMF_LEGACY_WINDOW (test_win))); | ||
925 | 610 | |||
926 | 611 | xid = g_random_int (); | ||
927 | 612 | exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL); | ||
928 | 613 | test_win = bamf_legacy_window_test_new (xid, "Notepad Subwin", NULL, exec); | ||
929 | 614 | bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance); | ||
930 | 615 | _bamf_legacy_screen_open_test_window (screen, test_win); | ||
931 | 616 | g_free (exec); | ||
932 | 617 | app3 = bamf_matcher_get_application_by_xid (matcher, xid); | ||
933 | 618 | g_assert (app3 == app1); | ||
934 | 619 | g_assert (BAMF_IS_APPLICATION (app3)); | ||
935 | 620 | app_children = bamf_view_get_children (BAMF_VIEW (app3)); | ||
936 | 621 | g_assert_cmpuint (g_list_length (app_children), ==, 2); | ||
937 | 622 | g_assert (find_window_in_app (app3, BAMF_LEGACY_WINDOW (test_win))); | ||
938 | 623 | |||
939 | 624 | g_object_unref (matcher); | ||
940 | 625 | g_object_unref (screen); | ||
941 | 626 | } | ||
942 | 627 | |||
943 | 628 | static void | ||
944 | 629 | test_trim_exec_string (void) | ||
945 | 630 | { | ||
946 | 631 | BamfMatcher *matcher; | ||
947 | 632 | char *trimmed; | ||
948 | 633 | |||
949 | 634 | matcher = bamf_matcher_get_default (); | ||
950 | 635 | |||
951 | 636 | // Bad prefixes | ||
952 | 637 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "gksudo bad-prefix-bin"); | ||
953 | 638 | g_assert_cmpstr (trimmed, ==, "bad-prefix-bin"); | ||
954 | 639 | g_free (trimmed); | ||
955 | 640 | |||
956 | 641 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "sudo --opt val=X /usr/bin/bad-prefix-bin"); | ||
957 | 642 | g_assert_cmpstr (trimmed, ==, "bad-prefix-bin"); | ||
958 | 643 | g_free (trimmed); | ||
959 | 644 | |||
960 | 645 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "python2.7 /home/foo/bad-prefix-script.py"); | ||
961 | 646 | g_assert_cmpstr (trimmed, ==, "bad-prefix-script"); | ||
962 | 647 | g_free (trimmed); | ||
963 | 648 | |||
964 | 649 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/python3.1"); | ||
965 | 650 | g_assert_cmpstr (trimmed, ==, "python3.1"); | ||
966 | 651 | g_free (trimmed); | ||
967 | 652 | |||
968 | 653 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/python %u --option val=/path"); | ||
969 | 654 | g_assert_cmpstr (trimmed, ==, "python"); | ||
970 | 655 | g_free (trimmed); | ||
971 | 656 | |||
972 | 657 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "sh -c \"binary --option --value %U || exec binary\""); | ||
973 | 658 | g_assert_cmpstr (trimmed, ==, "binary"); | ||
974 | 659 | g_free (trimmed); | ||
975 | 660 | |||
976 | 661 | // Good prefixes | ||
977 | 662 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/libreoffice --writer %U"); | ||
978 | 663 | g_assert_cmpstr (trimmed, ==, "libreoffice --writer"); | ||
979 | 664 | g_free (trimmed); | ||
980 | 665 | |||
981 | 666 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/gnome-control-center"); | ||
982 | 667 | g_assert_cmpstr (trimmed, ==, "gnome-control-center"); | ||
983 | 668 | g_free (trimmed); | ||
984 | 669 | |||
985 | 670 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "gnome-control-center foo-panel"); | ||
986 | 671 | g_assert_cmpstr (trimmed, ==, "gnome-control-center foo-panel"); | ||
987 | 672 | g_free (trimmed); | ||
988 | 673 | |||
989 | 674 | // Other exec strings | ||
990 | 675 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "env FOOVAR=\"bar\" myprog"); | ||
991 | 676 | g_assert_cmpstr (trimmed, ==, "myprog"); | ||
992 | 677 | g_free (trimmed); | ||
993 | 678 | |||
994 | 679 | trimmed = bamf_matcher_get_trimmed_exec (matcher, "/opt/path/bin/myprog --option %U --foo=daa"); | ||
995 | 680 | g_assert_cmpstr (trimmed, ==, "myprog"); | ||
996 | 681 | g_free (trimmed); | ||
997 | 682 | |||
998 | 683 | const char *exec = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \ | ||
999 | 684 | "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \ | ||
1000 | 685 | "-Xms8m -Djava.security.manager " \ | ||
1001 | 686 | "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \ | ||
1002 | 687 | "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \ | ||
1003 | 688 | "-Dicedtea-web.bin.name=javaws " \ | ||
1004 | 689 | "-Dicedtea-web.bin.location=/usr/bin/javaws "\ | ||
1005 | 690 | "net.sourceforge.jnlp.runtime.Boot Notepad.jnlp"; | ||
1006 | 691 | trimmed = bamf_matcher_get_trimmed_exec (matcher, exec); | ||
1007 | 692 | g_assert_cmpstr (trimmed, ==, "notepad.jnlp"); | ||
1008 | 693 | g_free (trimmed); | ||
1009 | 694 | |||
1010 | 695 | g_object_unref (matcher); | ||
1011 | 696 | } |
LGTM.