Merge lp:~asac/bamf/match-apps-by-startup-wm-class into lp:bamf/0.4

Proposed by Alexander Sack
Status: Rejected
Rejected by: Andrea Cimitan
Proposed branch: lp:~asac/bamf/match-apps-by-startup-wm-class
Merge into: lp:bamf/0.4
Diff against target: 99 lines (+42/-16)
1 file modified
src/bamf-matcher.c (+42/-16)
To merge this branch: bzr merge lp:~asac/bamf/match-apps-by-startup-wm-class
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+44410@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Alexander Sack (asac) wrote :

as you might see i extended the dumb .index format by adding an optional column for the WM class ... using a token "BAMF_WM_CLASS::${wmclass}" to make it easier to recognize it.

Also I moved to GKeyFile API for parsing the .desktop file because the GAppInfo thing doesn't export StartupWMClass= info.

Revision history for this message
Jason Smith (jassmith) wrote :

Lovely work, initial review looks good, I need to run it through internal testing.

Revision history for this message
Alexander Sack (asac) wrote :

ping ... would like to upload a new package to natty to natty during holiday season ... ;) happy new year!

Revision history for this message
Andrea Cimitan (cimi) wrote :

The bug seems to be already fixed during this year, closing the merge request

Unmerged revisions

368. By Alexander Sack

add support for StartupWMClass to match window_class for more cases
* extend .index file format to allow the final column to optionally have a BAMF_WM_CLASS::StartupWMClass field
* prefer StartupWMClass as desktop_id if available and only fall back to .desktop filename as heuristic
  -> example of affected apps are firefox dailes that have special WM_CLASS/codename aka Minefield instead of Firefox-4.0 etc.

Note: new perl magic to generate bamf.index is:
  perl -ne '/^(.*?)=(.*)/; $$d{$ARGV}{$1} = $2; END { for $f (keys %$d) { printf "%s\t%s%s\n", $f =~ m{.*/([^/]+)$}, $$d{$f}{'Exec'},$$d{$f}{'StartupWMClass'} ? "\tBAMF_WM_CLASS::$$d{$f}{'StartupWMClass'}" : "" } }' /usr/share/applications/*.desktop > /path/to/bamf.index

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bamf-matcher.c'
2--- src/bamf-matcher.c 2010-09-24 14:53:16 +0000
3+++ src/bamf-matcher.c 2010-12-22 00:24:59 +0000
4@@ -408,24 +408,35 @@
5 GHashTable *desktop_file_table,
6 GHashTable *desktop_id_table)
7 {
8- GAppInfo *desktop_file;
9+ GKeyFile *desktop_file;
10 char *exec;
11 char *path;
12 GString *desktop_id; /* is ok... really */
13+ gchar *desktop_id_char;
14
15 g_return_if_fail (BAMF_IS_MATCHER (self));
16
17- desktop_file = G_APP_INFO (g_desktop_app_info_new_from_filename (file));
18-
19- if (!G_IS_APP_INFO (desktop_file))
20- return;
21-
22- exec = g_strdup (g_app_info_get_commandline (desktop_file));
23+ desktop_file = g_key_file_new ();
24+ if (!desktop_file)
25+ return;
26+ if (!g_key_file_load_from_file (desktop_file, file, G_KEY_FILE_NONE, NULL)) {
27+ g_key_file_free (desktop_file);
28+ return;
29+ }
30+
31+ exec = g_key_file_get_value (desktop_file, "Desktop Entry", "Exec", NULL);
32
33 if (!exec)
34 return;
35
36- g_object_unref (desktop_file);
37+ desktop_id_char = g_key_file_get_value (desktop_file, "Desktop Entry", "StartupWMClass", NULL);
38+ if (desktop_id_char) {
39+ desktop_id = g_string_new (g_ascii_strdown (desktop_id_char, -1));
40+ g_free (desktop_id_char);
41+ } else {
42+ desktop_id = NULL;
43+ }
44+ g_key_file_free (desktop_file);
45
46 if (exec_string_should_be_processed (self, exec))
47 {
48@@ -440,11 +451,13 @@
49 exec = tmp;
50 }
51
52- path = g_path_get_basename (file);
53- desktop_id = g_string_new (path);
54- g_free (path);
55-
56- desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */
57+ /* if StartupWMClass didnt exist, go for .desktop path as heuristic */
58+ if (!desktop_id) {
59+ path = g_path_get_basename (file);
60+ desktop_id = g_string_new (path);
61+ desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */
62+ g_free (path);
63+ }
64
65 insert_data_into_tables (self, file, exec, desktop_id->str, desktop_file_table, desktop_id_table);
66
67@@ -530,6 +543,7 @@
68 char *exec;
69 GString *desktop_id;
70 GString *filename;
71+ char *bamf_wm_class;
72
73 gchar **parts = g_strsplit (line, "\t", 3);
74
75@@ -545,9 +559,21 @@
76 filename = g_string_new (name);
77 g_free ((gpointer) name);
78
79- desktop_id = g_string_new (parts[0]);
80- g_string_truncate (desktop_id, desktop_id->len - 8);
81-
82+ /*
83+ * if we have a third column in index file it means we have a StatupWMClass which
84+ * is a better desktop_id/window_class than the desktop filename stripped by .desktop.
85+ * e.g. firefox-4.0.desktop dailies have window class "Minefield"
86+ * since Exec can be a multi whitespace token we expect a BAMF_WM_CLASS:: to indicate
87+ * a StartupWMClass info
88+ */
89+ bamf_wm_class = parts[2] ? strstr(parts[2], "BAMF_WM_CLASS::") : NULL;
90+ if (!bamf_wm_class) {
91+ desktop_id = g_string_new (parts[0]);
92+ g_string_truncate (desktop_id, desktop_id->len - 8);
93+ } else {
94+ desktop_id = g_string_new (g_ascii_strdown(bamf_wm_class + 15 /* strlen ("BAMF_WM_CLASS::") */, -1));
95+ }
96+
97 insert_data_into_tables (self, filename->str, exec, desktop_id->str, desktop_file_table, desktop_id_table);
98
99 g_string_free (desktop_id, TRUE);

Subscribers

People subscribed via source and target branches