Merge lp:~3v1n0/bamf/wmclass-matching into lp:bamf/0.4
- wmclass-matching
- Merge into 0.4
Proposed by
Marco Trevisan (Treviño)
Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 387 | ||||||||||||
Proposed branch: | lp:~3v1n0/bamf/wmclass-matching | ||||||||||||
Merge into: | lp:bamf/0.4 | ||||||||||||
Diff against target: |
488 lines (+198/-40) 3 files modified
src/bamf-application.c (+50/-3) src/bamf-application.h (+6/-0) src/bamf-matcher.c (+142/-37) |
||||||||||||
To merge this branch: | bzr merge lp:~3v1n0/bamf/wmclass-matching | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jason Smith (community) | Approve | ||
Review via email: mp+54941@code.launchpad.net |
Commit message
Description of the change
Now bamf uses also the window WMCLASS parameter and the .desktop file StartupWMClass to associate a window to its application.
This causes that each bamf application should now have its own class; a window is considered as part of that application only if its wmclass matches the application one.
A desktop file is now associated to an application also considering the StartupWMClass key value.
To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote : | # |
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Yes, you're right about that. I'll fix it.
lp:~3v1n0/bamf/wmclass-matching
updated
- 392. By Marco Trevisan (Treviño)
-
application_class renamed as application_wmclass
To avoid gobjet get_class function overriding
- 393. By Marco Trevisan (Treviño)
-
Some code spaces cleanup.
Revision history for this message
Jason Smith (jassmith) wrote : | # |
Works for me, looks good
review:
Approve
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 2011-01-14 15:53:35 +0000 | |||
3 | +++ src/bamf-application.c 2011-03-29 11:26:03 +0000 | |||
4 | @@ -48,6 +48,7 @@ | |||
5 | 48 | GList * desktop_file_list; | 48 | GList * desktop_file_list; |
6 | 49 | char * app_type; | 49 | char * app_type; |
7 | 50 | char * icon; | 50 | char * icon; |
8 | 51 | char * wmclass; | ||
9 | 51 | gboolean is_tab_container; | 52 | gboolean is_tab_container; |
10 | 52 | gboolean show_stubs; | 53 | gboolean show_stubs; |
11 | 53 | }; | 54 | }; |
12 | @@ -83,6 +84,19 @@ | |||
13 | 83 | return result; | 84 | return result; |
14 | 84 | } | 85 | } |
15 | 85 | 86 | ||
16 | 87 | char * | ||
17 | 88 | bamf_application_get_wmclass (BamfApplication *application) | ||
18 | 89 | { | ||
19 | 90 | BamfApplicationPrivate *priv; | ||
20 | 91 | char *result = NULL; | ||
21 | 92 | |||
22 | 93 | g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL); | ||
23 | 94 | priv = application->priv; | ||
24 | 95 | |||
25 | 96 | result = g_strdup (priv->wmclass); | ||
26 | 97 | return result; | ||
27 | 98 | } | ||
28 | 99 | |||
29 | 86 | static gboolean | 100 | static gboolean |
30 | 87 | icon_name_is_valid (char *name) | 101 | icon_name_is_valid (char *name) |
31 | 88 | { | 102 | { |
32 | @@ -212,6 +226,18 @@ | |||
33 | 212 | bamf_application_setup_icon_and_name (application); | 226 | bamf_application_setup_icon_and_name (application); |
34 | 213 | } | 227 | } |
35 | 214 | 228 | ||
36 | 229 | void | ||
37 | 230 | bamf_application_set_wmclass (BamfApplication *application, | ||
38 | 231 | char *wmclass) | ||
39 | 232 | { | ||
40 | 233 | g_return_if_fail (BAMF_IS_APPLICATION (application)); | ||
41 | 234 | |||
42 | 235 | if (wmclass && wmclass[0] != '\0') | ||
43 | 236 | application->priv->wmclass = g_strdup (wmclass); | ||
44 | 237 | else | ||
45 | 238 | application->priv->wmclass = NULL; | ||
46 | 239 | } | ||
47 | 240 | |||
48 | 215 | GArray * | 241 | GArray * |
49 | 216 | bamf_application_get_xids (BamfApplication *application) | 242 | bamf_application_get_xids (BamfApplication *application) |
50 | 217 | { | 243 | { |
51 | @@ -312,12 +338,15 @@ | |||
52 | 312 | GList *children, *l; | 338 | GList *children, *l; |
53 | 313 | BamfView *child; | 339 | BamfView *child; |
54 | 314 | 340 | ||
56 | 315 | g_return_val_if_fail (BAMF_IS_APPLICATION (view), NULL); | 341 | g_return_val_if_fail (BAMF_IS_APPLICATION (view), NULL); |
57 | 316 | self = BAMF_APPLICATION (view); | 342 | self = BAMF_APPLICATION (view); |
59 | 317 | 343 | ||
60 | 344 | if (self->priv->wmclass) | ||
61 | 345 | return g_strdup_printf ("application%i", abs (g_str_hash (self->priv->wmclass))); | ||
62 | 346 | |||
63 | 318 | if (self->priv->desktop_file) | 347 | if (self->priv->desktop_file) |
64 | 319 | return g_strdup_printf ("application%i", abs (g_str_hash (self->priv->desktop_file))); | 348 | return g_strdup_printf ("application%i", abs (g_str_hash (self->priv->desktop_file))); |
66 | 320 | 349 | ||
67 | 321 | children = bamf_view_get_children (BAMF_VIEW (self)); | 350 | children = bamf_view_get_children (BAMF_VIEW (self)); |
68 | 322 | for (l = children; l; l = l->next) | 351 | for (l = children; l; l = l->next) |
69 | 323 | { | 352 | { |
70 | @@ -562,6 +591,12 @@ | |||
71 | 562 | g_free (priv->app_type); | 591 | g_free (priv->app_type); |
72 | 563 | priv->app_type = NULL; | 592 | priv->app_type = NULL; |
73 | 564 | } | 593 | } |
74 | 594 | |||
75 | 595 | if (priv->wmclass) | ||
76 | 596 | { | ||
77 | 597 | g_free (priv->wmclass); | ||
78 | 598 | priv->wmclass = NULL; | ||
79 | 599 | } | ||
80 | 565 | 600 | ||
81 | 566 | g_signal_handlers_disconnect_by_func (G_OBJECT (bamf_matcher_get_default ()), matcher_favorites_changed, object); | 601 | g_signal_handlers_disconnect_by_func (G_OBJECT (bamf_matcher_get_default ()), matcher_favorites_changed, object); |
82 | 567 | 602 | ||
83 | @@ -577,6 +612,7 @@ | |||
84 | 577 | priv->is_tab_container = FALSE; | 612 | priv->is_tab_container = FALSE; |
85 | 578 | priv->app_type = g_strdup ("system"); | 613 | priv->app_type = g_strdup ("system"); |
86 | 579 | priv->show_stubs = TRUE; | 614 | priv->show_stubs = TRUE; |
87 | 615 | priv->wmclass = NULL; | ||
88 | 580 | 616 | ||
89 | 581 | g_signal_connect (G_OBJECT (bamf_matcher_get_default ()), "favorites-changed", | 617 | g_signal_connect (G_OBJECT (bamf_matcher_get_default ()), "favorites-changed", |
90 | 582 | (GCallback) matcher_favorites_changed, self); | 618 | (GCallback) matcher_favorites_changed, self); |
91 | @@ -651,6 +687,17 @@ | |||
92 | 651 | return application; | 687 | return application; |
93 | 652 | } | 688 | } |
94 | 653 | 689 | ||
95 | 690 | BamfApplication * | ||
96 | 691 | bamf_application_new_with_wmclass (char *wmclass) | ||
97 | 692 | { | ||
98 | 693 | BamfApplication *application; | ||
99 | 694 | application = (BamfApplication *) g_object_new (BAMF_TYPE_APPLICATION, NULL); | ||
100 | 695 | |||
101 | 696 | bamf_application_set_wmclass (application, wmclass); | ||
102 | 697 | |||
103 | 698 | return application; | ||
104 | 699 | } | ||
105 | 700 | |||
106 | 654 | /** | 701 | /** |
107 | 655 | bamf_application_get_show_stubs: | 702 | bamf_application_get_show_stubs: |
108 | 656 | @application: Application to check for menu stubs | 703 | @application: Application to check for menu stubs |
109 | 657 | 704 | ||
110 | === modified file 'src/bamf-application.h' | |||
111 | --- src/bamf-application.h 2010-09-11 02:52:33 +0000 | |||
112 | +++ src/bamf-application.h 2011-03-29 11:26:03 +0000 | |||
113 | @@ -66,6 +66,10 @@ | |||
114 | 66 | gboolean bamf_application_contains_similar_to_window (BamfApplication *app, | 66 | gboolean bamf_application_contains_similar_to_window (BamfApplication *app, |
115 | 67 | BamfWindow *window); | 67 | BamfWindow *window); |
116 | 68 | 68 | ||
117 | 69 | char * bamf_application_get_wmclass (BamfApplication *application); | ||
118 | 70 | void bamf_application_set_wmclass (BamfApplication *application, | ||
119 | 71 | char *wmclass); | ||
120 | 72 | |||
121 | 69 | BamfApplication * bamf_application_new (void); | 73 | BamfApplication * bamf_application_new (void); |
122 | 70 | 74 | ||
123 | 71 | BamfApplication * bamf_application_new_from_desktop_file (char * desktop_file); | 75 | BamfApplication * bamf_application_new_from_desktop_file (char * desktop_file); |
124 | @@ -73,4 +77,6 @@ | |||
125 | 73 | 77 | ||
126 | 74 | BamfApplication * bamf_application_new_from_desktop_files (GList * desktop_files); | 78 | BamfApplication * bamf_application_new_from_desktop_files (GList * desktop_files); |
127 | 75 | 79 | ||
128 | 80 | BamfApplication * bamf_application_new_with_wmclass (char *wmclass); | ||
129 | 81 | |||
130 | 76 | #endif | 82 | #endif |
131 | 77 | 83 | ||
132 | === modified file 'src/bamf-matcher.c' | |||
133 | --- src/bamf-matcher.c 2011-03-15 12:09:16 +0000 | |||
134 | +++ src/bamf-matcher.c 2011-03-29 11:26:03 +0000 | |||
135 | @@ -61,6 +61,7 @@ | |||
136 | 61 | GArray * known_pids; | 61 | GArray * known_pids; |
137 | 62 | GHashTable * desktop_id_table; | 62 | GHashTable * desktop_id_table; |
138 | 63 | GHashTable * desktop_file_table; | 63 | GHashTable * desktop_file_table; |
139 | 64 | GHashTable * desktop_class_table; | ||
140 | 64 | GHashTable * exec_list; | 65 | GHashTable * exec_list; |
141 | 65 | GHashTable * registered_pids; | 66 | GHashTable * registered_pids; |
142 | 66 | GList * views; | 67 | GList * views; |
143 | @@ -416,17 +417,43 @@ | |||
144 | 416 | file_list = g_list_append (file_list, datadup); | 417 | file_list = g_list_append (file_list, datadup); |
145 | 417 | id_list = g_list_append (id_list, datadup); | 418 | id_list = g_list_append (id_list, datadup); |
146 | 418 | } | 419 | } |
148 | 419 | 420 | ||
149 | 420 | g_hash_table_insert (desktop_file_table, g_strdup (exec), file_list); | 421 | g_hash_table_insert (desktop_file_table, g_strdup (exec), file_list); |
150 | 421 | g_hash_table_insert (desktop_id_table, g_strdup (desktop_id), id_list); | 422 | g_hash_table_insert (desktop_id_table, g_strdup (desktop_id), id_list); |
152 | 422 | 423 | } | |
153 | 424 | |||
154 | 425 | static void | ||
155 | 426 | insert_desktop_file_class_into_table (BamfMatcher *self, | ||
156 | 427 | const char *desktop_file, | ||
157 | 428 | GHashTable *desktop_class_table) | ||
158 | 429 | { | ||
159 | 430 | GKeyFile *desktop_keyfile; | ||
160 | 431 | char *class; | ||
161 | 432 | |||
162 | 433 | g_return_if_fail (desktop_file); | ||
163 | 434 | |||
164 | 435 | desktop_keyfile = g_key_file_new (); | ||
165 | 436 | |||
166 | 437 | if (g_key_file_load_from_file (desktop_keyfile, desktop_file, G_KEY_FILE_NONE, | ||
167 | 438 | NULL)) | ||
168 | 439 | { | ||
169 | 440 | class = g_key_file_get_string (desktop_keyfile, | ||
170 | 441 | G_KEY_FILE_DESKTOP_GROUP, | ||
171 | 442 | G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS, | ||
172 | 443 | NULL); | ||
173 | 444 | if (class) | ||
174 | 445 | g_hash_table_insert (desktop_class_table, g_strdup (desktop_file), class); | ||
175 | 446 | |||
176 | 447 | g_key_file_free (desktop_keyfile); | ||
177 | 448 | } | ||
178 | 423 | } | 449 | } |
179 | 424 | 450 | ||
180 | 425 | static void | 451 | static void |
181 | 426 | load_desktop_file_to_table (BamfMatcher * self, | 452 | load_desktop_file_to_table (BamfMatcher * self, |
182 | 427 | const char *file, | 453 | const char *file, |
183 | 428 | GHashTable *desktop_file_table, | 454 | GHashTable *desktop_file_table, |
185 | 429 | GHashTable *desktop_id_table) | 455 | GHashTable *desktop_id_table, |
186 | 456 | GHashTable *desktop_class_table) | ||
187 | 430 | { | 457 | { |
188 | 431 | GAppInfo *desktop_file; | 458 | GAppInfo *desktop_file; |
189 | 432 | char *exec; | 459 | char *exec; |
190 | @@ -467,6 +494,7 @@ | |||
191 | 467 | desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */ | 494 | desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */ |
192 | 468 | 495 | ||
193 | 469 | insert_data_into_tables (self, file, exec, desktop_id->str, desktop_file_table, desktop_id_table); | 496 | insert_data_into_tables (self, file, exec, desktop_id->str, desktop_file_table, desktop_id_table); |
194 | 497 | insert_desktop_file_class_into_table (self, file, desktop_class_table); | ||
195 | 470 | 498 | ||
196 | 471 | g_free (exec); | 499 | g_free (exec); |
197 | 472 | g_string_free (desktop_id, TRUE); | 500 | g_string_free (desktop_id, TRUE); |
198 | @@ -476,7 +504,8 @@ | |||
199 | 476 | load_directory_to_table (BamfMatcher * self, | 504 | load_directory_to_table (BamfMatcher * self, |
200 | 477 | const char *directory, | 505 | const char *directory, |
201 | 478 | GHashTable *desktop_file_table, | 506 | GHashTable *desktop_file_table, |
203 | 479 | GHashTable *desktop_id_table) | 507 | GHashTable *desktop_id_table, |
204 | 508 | GHashTable *desktop_class_table) | ||
205 | 480 | { | 509 | { |
206 | 481 | GFile *dir; | 510 | GFile *dir; |
207 | 482 | GFileEnumerator *enumerator; | 511 | GFileEnumerator *enumerator; |
208 | @@ -506,7 +535,8 @@ | |||
209 | 506 | load_desktop_file_to_table (self, | 535 | load_desktop_file_to_table (self, |
210 | 507 | path, | 536 | path, |
211 | 508 | desktop_file_table, | 537 | desktop_file_table, |
213 | 509 | desktop_id_table); | 538 | desktop_id_table, |
214 | 539 | desktop_class_table); | ||
215 | 510 | 540 | ||
216 | 511 | g_free ((gpointer) path); | 541 | g_free ((gpointer) path); |
217 | 512 | g_object_unref (info); | 542 | g_object_unref (info); |
218 | @@ -520,7 +550,8 @@ | |||
219 | 520 | load_index_file_to_table (BamfMatcher * self, | 550 | load_index_file_to_table (BamfMatcher * self, |
220 | 521 | const char *index_file, | 551 | const char *index_file, |
221 | 522 | GHashTable *desktop_file_table, | 552 | GHashTable *desktop_file_table, |
223 | 523 | GHashTable *desktop_id_table) | 553 | GHashTable *desktop_id_table, |
224 | 554 | GHashTable *desktop_class_table) | ||
225 | 524 | { | 555 | { |
226 | 525 | GFile *file; | 556 | GFile *file; |
227 | 526 | GFileInputStream *stream; | 557 | GFileInputStream *stream; |
228 | @@ -569,6 +600,7 @@ | |||
229 | 569 | g_string_truncate (desktop_id, desktop_id->len - 8); | 600 | g_string_truncate (desktop_id, desktop_id->len - 8); |
230 | 570 | 601 | ||
231 | 571 | insert_data_into_tables (self, filename->str, exec, desktop_id->str, desktop_file_table, desktop_id_table); | 602 | insert_data_into_tables (self, filename->str, exec, desktop_id->str, desktop_file_table, desktop_id_table); |
232 | 603 | insert_desktop_file_class_into_table (self, filename->str, desktop_class_table); | ||
233 | 572 | 604 | ||
234 | 573 | g_string_free (desktop_id, TRUE); | 605 | g_string_free (desktop_id, TRUE); |
235 | 574 | length = 0; | 606 | length = 0; |
236 | @@ -612,7 +644,7 @@ | |||
237 | 612 | if (!g_list_find_custom (dirs, "/usr/local/share/applications", (GCompareFunc) g_strcmp0)) | 644 | if (!g_list_find_custom (dirs, "/usr/local/share/applications", (GCompareFunc) g_strcmp0)) |
238 | 613 | dirs = g_list_prepend (dirs, g_strdup ("/usr/local/share/applications")); | 645 | dirs = g_list_prepend (dirs, g_strdup ("/usr/local/share/applications")); |
239 | 614 | 646 | ||
241 | 615 | dirs = g_list_prepend (dirs, g_strdup (g_build_filename (g_get_home_dir (), ".share/applications", NULL))); | 647 | dirs = g_list_prepend (dirs, g_strdup (g_build_filename (g_get_home_dir (), ".local/share/applications", NULL))); |
242 | 616 | 648 | ||
243 | 617 | if (data_dirs) | 649 | if (data_dirs) |
244 | 618 | g_strfreev (data_dirs); | 650 | g_strfreev (data_dirs); |
245 | @@ -690,6 +722,7 @@ | |||
246 | 690 | { | 722 | { |
247 | 691 | g_hash_table_foreach_remove (self->priv->desktop_id_table, (GHRFunc) hash_table_remove_values, path); | 723 | g_hash_table_foreach_remove (self->priv->desktop_id_table, (GHRFunc) hash_table_remove_values, path); |
248 | 692 | g_hash_table_foreach_remove (self->priv->desktop_file_table, (GHRFunc) hash_table_remove_values, path); | 724 | g_hash_table_foreach_remove (self->priv->desktop_file_table, (GHRFunc) hash_table_remove_values, path); |
249 | 725 | g_hash_table_remove (self->priv->desktop_class_table, path); | ||
250 | 693 | } | 726 | } |
251 | 694 | 727 | ||
252 | 695 | out: | 728 | out: |
253 | @@ -697,7 +730,10 @@ | |||
254 | 697 | } | 730 | } |
255 | 698 | 731 | ||
256 | 699 | static void | 732 | static void |
258 | 700 | create_desktop_file_table (BamfMatcher * self, GHashTable **desktop_file_table, GHashTable **desktop_id_table) | 733 | create_desktop_file_table (BamfMatcher * self, |
259 | 734 | GHashTable **desktop_file_table, | ||
260 | 735 | GHashTable **desktop_id_table, | ||
261 | 736 | GHashTable **desktop_class_table) | ||
262 | 701 | { | 737 | { |
263 | 702 | GList *directories; | 738 | GList *directories; |
264 | 703 | GList *l; | 739 | GList *l; |
265 | @@ -718,6 +754,12 @@ | |||
266 | 718 | (GDestroyNotify) g_free, | 754 | (GDestroyNotify) g_free, |
267 | 719 | NULL); | 755 | NULL); |
268 | 720 | 756 | ||
269 | 757 | *desktop_class_table = | ||
270 | 758 | g_hash_table_new_full ((GHashFunc) g_str_hash, | ||
271 | 759 | (GEqualFunc) g_str_equal, | ||
272 | 760 | (GDestroyNotify) g_free, | ||
273 | 761 | (GDestroyNotify) g_free); | ||
274 | 762 | |||
275 | 721 | g_return_if_fail (BAMF_IS_MATCHER (self)); | 763 | g_return_if_fail (BAMF_IS_MATCHER (self)); |
276 | 722 | 764 | ||
277 | 723 | directories = get_desktop_file_directories (self); | 765 | directories = get_desktop_file_directories (self); |
278 | @@ -740,11 +782,13 @@ | |||
279 | 740 | 782 | ||
280 | 741 | if (g_file_test (bamf_file, G_FILE_TEST_EXISTS)) | 783 | if (g_file_test (bamf_file, G_FILE_TEST_EXISTS)) |
281 | 742 | { | 784 | { |
283 | 743 | load_index_file_to_table (self, bamf_file, *desktop_file_table, *desktop_id_table); | 785 | load_index_file_to_table (self, bamf_file, *desktop_file_table, |
284 | 786 | *desktop_id_table, *desktop_class_table); | ||
285 | 744 | } | 787 | } |
286 | 745 | else | 788 | else |
287 | 746 | { | 789 | { |
289 | 747 | load_directory_to_table (self, directory, *desktop_file_table, *desktop_id_table); | 790 | load_directory_to_table (self, directory, *desktop_file_table, |
290 | 791 | *desktop_id_table, *desktop_class_table); | ||
291 | 748 | } | 792 | } |
292 | 749 | 793 | ||
293 | 750 | g_free (directory); | 794 | g_free (directory); |
294 | @@ -993,38 +1037,81 @@ | |||
295 | 993 | } | 1037 | } |
296 | 994 | else | 1038 | else |
297 | 995 | { | 1039 | { |
301 | 996 | char *class_name = window_class_name (window); | 1040 | char *window_class = window_class_name (window); |
302 | 997 | 1041 | ||
303 | 998 | if (class_name) | 1042 | char *desktop_file; |
304 | 1043 | char *desktop_class; | ||
305 | 1044 | |||
306 | 1045 | if (window_class) | ||
307 | 999 | { | 1046 | { |
310 | 1000 | class_name = g_ascii_strdown (class_name, -1); | 1047 | char *window_class_down = g_ascii_strdown (g_strdup(window_class), -1); |
311 | 1001 | l = g_hash_table_lookup (priv->desktop_id_table, class_name); | 1048 | l = g_hash_table_lookup (priv->desktop_id_table, window_class_down); |
312 | 1049 | g_free (window_class_down); | ||
313 | 1002 | 1050 | ||
314 | 1003 | for (; l; l = l->next) | 1051 | for (; l; l = l->next) |
315 | 1004 | { | 1052 | { |
323 | 1005 | if (l->data && !g_list_find_custom (desktop_files, l->data, (GCompareFunc) g_strcmp0)) | 1053 | desktop_file = l->data; |
324 | 1006 | desktop_files = g_list_prepend (desktop_files, g_strdup (l->data)); | 1054 | if (desktop_file) |
325 | 1007 | } | 1055 | { |
326 | 1008 | 1056 | desktop_class = g_hash_table_lookup (priv->desktop_class_table, desktop_file); | |
327 | 1009 | desktop_files = g_list_reverse (desktop_files); | 1057 | if ((desktop_class == NULL || g_strcmp0 (desktop_class, window_class) == 0) && |
328 | 1010 | g_free (class_name); | 1058 | !g_list_find_custom (desktop_files, desktop_file, |
329 | 1011 | } | 1059 | (GCompareFunc) g_strcmp0)) |
330 | 1060 | { | ||
331 | 1061 | desktop_files = g_list_prepend (desktop_files, g_strdup (desktop_file)); | ||
332 | 1062 | } | ||
333 | 1063 | } | ||
334 | 1064 | } | ||
335 | 1065 | |||
336 | 1066 | desktop_files = g_list_reverse (desktop_files); | ||
337 | 1067 | } | ||
338 | 1068 | |||
339 | 1069 | /* Iterate over the desktop class table, and add matching desktop files */ | ||
340 | 1070 | gpointer key; | ||
341 | 1071 | gpointer value; | ||
342 | 1072 | GHashTableIter iter; | ||
343 | 1073 | g_hash_table_iter_init (&iter, priv->desktop_class_table); | ||
344 | 1074 | |||
345 | 1075 | while (g_hash_table_iter_next (&iter, &key, &value)) | ||
346 | 1076 | { | ||
347 | 1077 | desktop_file = g_strdup (key); | ||
348 | 1078 | desktop_class = value; | ||
349 | 1079 | if (g_strcmp0 (desktop_class, window_class) == 0 && | ||
350 | 1080 | !g_list_find_custom (desktop_files, desktop_file, (GCompareFunc) g_strcmp0)) | ||
351 | 1081 | { | ||
352 | 1082 | desktop_files = g_list_prepend (desktop_files, desktop_file); | ||
353 | 1083 | } | ||
354 | 1084 | } | ||
355 | 1012 | 1085 | ||
356 | 1013 | pid = bamf_legacy_window_get_pid (window); | 1086 | pid = bamf_legacy_window_get_pid (window); |
357 | 1014 | |||
358 | 1015 | pid_list = bamf_matcher_possible_applications_for_pid (self, pid); | 1087 | pid_list = bamf_matcher_possible_applications_for_pid (self, pid); |
359 | 1016 | 1088 | ||
361 | 1017 | /* Append these files to the end to give preference to class_name style picking. | 1089 | /* Append these files to the end to give preference to window_class style picking. |
362 | 1018 | This style of matching is prefered and used by GNOME Shell however does not work | 1090 | This style of matching is prefered and used by GNOME Shell however does not work |
363 | 1019 | very well in practice, thus requiring the fallback here */ | 1091 | very well in practice, thus requiring the fallback here */ |
364 | 1020 | for (l = pid_list; l; l = l->next) | 1092 | for (l = pid_list; l; l = l->next) |
365 | 1021 | { | 1093 | { |
366 | 1094 | desktop_file = l->data; | ||
367 | 1022 | if (g_list_find_custom (desktop_files, l->data, (GCompareFunc) g_strcmp0)) | 1095 | if (g_list_find_custom (desktop_files, l->data, (GCompareFunc) g_strcmp0)) |
369 | 1023 | g_free (l->data); | 1096 | g_free (desktop_file); |
370 | 1024 | else | 1097 | else |
372 | 1025 | desktop_files = g_list_append (desktop_files, l->data); | 1098 | { |
373 | 1099 | if (window_class) | ||
374 | 1100 | { | ||
375 | 1101 | desktop_class = g_hash_table_lookup (priv->desktop_class_table, desktop_file); | ||
376 | 1102 | if ((desktop_class == NULL || g_strcmp0 (desktop_class, window_class) == 0) && | ||
377 | 1103 | !g_list_find_custom (desktop_files, desktop_file, | ||
378 | 1104 | (GCompareFunc) g_strcmp0)) | ||
379 | 1105 | { | ||
380 | 1106 | desktop_files = g_list_append (desktop_files, desktop_file); | ||
381 | 1107 | } | ||
382 | 1108 | } | ||
383 | 1109 | else | ||
384 | 1110 | desktop_files = g_list_append (desktop_files, desktop_file); | ||
385 | 1111 | } | ||
386 | 1026 | } | 1112 | } |
388 | 1027 | 1113 | ||
389 | 1114 | g_free (window_class); | ||
390 | 1028 | g_list_free (pid_list); | 1115 | g_list_free (pid_list); |
391 | 1029 | } | 1116 | } |
392 | 1030 | 1117 | ||
393 | @@ -1039,6 +1126,8 @@ | |||
394 | 1039 | BamfLegacyWindow *window; | 1126 | BamfLegacyWindow *window; |
395 | 1040 | GList *views, *a; | 1127 | GList *views, *a; |
396 | 1041 | char *desktop_file; | 1128 | char *desktop_file; |
397 | 1129 | char *win_class; | ||
398 | 1130 | char *app_class; | ||
399 | 1042 | BamfApplication *app = NULL, *best = NULL; | 1131 | BamfApplication *app = NULL, *best = NULL; |
400 | 1043 | BamfView *view; | 1132 | BamfView *view; |
401 | 1044 | 1133 | ||
402 | @@ -1049,6 +1138,7 @@ | |||
403 | 1049 | views = self->priv->views; | 1138 | views = self->priv->views; |
404 | 1050 | 1139 | ||
405 | 1051 | possible_apps = bamf_matcher_possible_applications_for_window (self, bamf_window); | 1140 | possible_apps = bamf_matcher_possible_applications_for_window (self, bamf_window); |
406 | 1141 | win_class = window_class_name(window); | ||
407 | 1052 | 1142 | ||
408 | 1053 | /* Loop over every application, inside that application see if its .desktop file | 1143 | /* Loop over every application, inside that application see if its .desktop file |
409 | 1054 | * matches with any of our possible hits. If so we match it. If we have no possible hits | 1144 | * matches with any of our possible hits. If so we match it. If we have no possible hits |
410 | @@ -1062,8 +1152,16 @@ | |||
411 | 1062 | continue; | 1152 | continue; |
412 | 1063 | 1153 | ||
413 | 1064 | app = BAMF_APPLICATION (view); | 1154 | app = BAMF_APPLICATION (view); |
414 | 1155 | app_class = bamf_application_get_wmclass (app); | ||
415 | 1156 | |||
416 | 1157 | if (app_class != NULL && g_strcmp0 (win_class, app_class) != 0) | ||
417 | 1158 | { | ||
418 | 1159 | g_free (app_class); | ||
419 | 1160 | continue; | ||
420 | 1161 | } | ||
421 | 1162 | |||
422 | 1065 | desktop_file = bamf_application_get_desktop_file (app); | 1163 | desktop_file = bamf_application_get_desktop_file (app); |
424 | 1066 | 1164 | ||
425 | 1067 | if (possible_apps) | 1165 | if (possible_apps) |
426 | 1068 | { | 1166 | { |
427 | 1069 | /* primary matching */ | 1167 | /* primary matching */ |
428 | @@ -1084,7 +1182,8 @@ | |||
429 | 1084 | if (bamf_application_contains_similar_to_window (app, bamf_window)) | 1182 | if (bamf_application_contains_similar_to_window (app, bamf_window)) |
430 | 1085 | best = app; | 1183 | best = app; |
431 | 1086 | } | 1184 | } |
433 | 1087 | 1185 | ||
434 | 1186 | g_free (app_class); | ||
435 | 1088 | g_free (desktop_file); | 1187 | g_free (desktop_file); |
436 | 1089 | } | 1188 | } |
437 | 1090 | 1189 | ||
438 | @@ -1095,16 +1194,19 @@ | |||
439 | 1095 | else | 1194 | else |
440 | 1096 | best = bamf_application_new (); | 1195 | best = bamf_application_new (); |
441 | 1097 | 1196 | ||
442 | 1197 | bamf_application_set_wmclass (best, win_class); | ||
443 | 1198 | |||
444 | 1098 | bamf_matcher_register_view (self, BAMF_VIEW (best)); | 1199 | bamf_matcher_register_view (self, BAMF_VIEW (best)); |
445 | 1099 | g_object_unref (best); | 1200 | g_object_unref (best); |
446 | 1100 | } | 1201 | } |
447 | 1101 | 1202 | ||
453 | 1102 | for (l = possible_apps; l; l = l->next) | 1203 | g_free (win_class); |
449 | 1103 | { | ||
450 | 1104 | char *str = l->data; | ||
451 | 1105 | g_free (str); | ||
452 | 1106 | } | ||
454 | 1107 | 1204 | ||
455 | 1205 | for (l = possible_apps; l; l = l->next) | ||
456 | 1206 | { | ||
457 | 1207 | char *str = l->data; | ||
458 | 1208 | g_free (str); | ||
459 | 1209 | } | ||
460 | 1108 | 1210 | ||
461 | 1109 | g_list_free (possible_apps); | 1211 | g_list_free (possible_apps); |
462 | 1110 | 1212 | ||
463 | @@ -1340,7 +1442,8 @@ | |||
464 | 1340 | load_desktop_file_to_table (self, | 1442 | load_desktop_file_to_table (self, |
465 | 1341 | desktop_file, | 1443 | desktop_file, |
466 | 1342 | self->priv->desktop_file_table, | 1444 | self->priv->desktop_file_table, |
468 | 1343 | self->priv->desktop_id_table); | 1445 | self->priv->desktop_id_table, |
469 | 1446 | self->priv->desktop_class_table); | ||
470 | 1344 | } | 1447 | } |
471 | 1345 | 1448 | ||
472 | 1346 | void | 1449 | void |
473 | @@ -1731,11 +1834,13 @@ | |||
474 | 1731 | 1834 | ||
475 | 1732 | g_array_free (prefixstrings, TRUE); | 1835 | g_array_free (prefixstrings, TRUE); |
476 | 1733 | 1836 | ||
478 | 1734 | create_desktop_file_table (self, &(priv->desktop_file_table), &(priv->desktop_id_table)); | 1837 | create_desktop_file_table (self, &(priv->desktop_file_table), |
479 | 1838 | &(priv->desktop_id_table), | ||
480 | 1839 | &(priv->desktop_class_table)); | ||
481 | 1735 | 1840 | ||
482 | 1736 | screen = bamf_legacy_screen_get_default (); | 1841 | screen = bamf_legacy_screen_get_default (); |
483 | 1737 | g_signal_connect (G_OBJECT (screen), "window-opened", | 1842 | g_signal_connect (G_OBJECT (screen), "window-opened", |
485 | 1738 | (GCallback) handle_window_opened, self); | 1843 | (GCallback) handle_window_opened, self); |
486 | 1739 | 1844 | ||
487 | 1740 | approver = bamf_indicator_source_get_default (); | 1845 | approver = bamf_indicator_source_get_default (); |
488 | 1741 | g_signal_connect (G_OBJECT (approver), "indicator-opened", | 1846 | g_signal_connect (G_OBJECT (approver), "indicator-opened", |
I am not sure I'm the right person to review this branch, but I got one nitpick nontheless :-)
The get_class() and set_class() methods on BamfApplication are not very binding friendly. If I called app.get_class() from Vala or PyGI it would normally give me the GObjectClass struct for the object, but this patch would override that method.
Maybe get/set_wmclass() instead?