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
=== modified file 'src/bamf-matcher.c'
--- src/bamf-matcher.c 2010-09-24 14:53:16 +0000
+++ src/bamf-matcher.c 2010-12-22 00:24:59 +0000
@@ -408,24 +408,35 @@
408 GHashTable *desktop_file_table,408 GHashTable *desktop_file_table,
409 GHashTable *desktop_id_table)409 GHashTable *desktop_id_table)
410{410{
411 GAppInfo *desktop_file;411 GKeyFile *desktop_file;
412 char *exec;412 char *exec;
413 char *path;413 char *path;
414 GString *desktop_id; /* is ok... really */414 GString *desktop_id; /* is ok... really */
415 gchar *desktop_id_char;
415416
416 g_return_if_fail (BAMF_IS_MATCHER (self));417 g_return_if_fail (BAMF_IS_MATCHER (self));
417418
418 desktop_file = G_APP_INFO (g_desktop_app_info_new_from_filename (file));419 desktop_file = g_key_file_new ();
419420 if (!desktop_file)
420 if (!G_IS_APP_INFO (desktop_file))421 return;
421 return;422 if (!g_key_file_load_from_file (desktop_file, file, G_KEY_FILE_NONE, NULL)) {
422423 g_key_file_free (desktop_file);
423 exec = g_strdup (g_app_info_get_commandline (desktop_file));424 return;
425 }
426
427 exec = g_key_file_get_value (desktop_file, "Desktop Entry", "Exec", NULL);
424 428
425 if (!exec)429 if (!exec)
426 return;430 return;
427431
428 g_object_unref (desktop_file);432 desktop_id_char = g_key_file_get_value (desktop_file, "Desktop Entry", "StartupWMClass", NULL);
433 if (desktop_id_char) {
434 desktop_id = g_string_new (g_ascii_strdown (desktop_id_char, -1));
435 g_free (desktop_id_char);
436 } else {
437 desktop_id = NULL;
438 }
439 g_key_file_free (desktop_file);
429440
430 if (exec_string_should_be_processed (self, exec))441 if (exec_string_should_be_processed (self, exec))
431 {442 {
@@ -440,11 +451,13 @@
440 exec = tmp;451 exec = tmp;
441 }452 }
442453
443 path = g_path_get_basename (file);454 /* if StartupWMClass didnt exist, go for .desktop path as heuristic */
444 desktop_id = g_string_new (path);455 if (!desktop_id) {
445 g_free (path);456 path = g_path_get_basename (file);
446457 desktop_id = g_string_new (path);
447 desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */458 desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */
459 g_free (path);
460 }
448 461
449 insert_data_into_tables (self, file, exec, desktop_id->str, desktop_file_table, desktop_id_table);462 insert_data_into_tables (self, file, exec, desktop_id->str, desktop_file_table, desktop_id_table);
450463
@@ -530,6 +543,7 @@
530 char *exec;543 char *exec;
531 GString *desktop_id;544 GString *desktop_id;
532 GString *filename;545 GString *filename;
546 char *bamf_wm_class;
533547
534 gchar **parts = g_strsplit (line, "\t", 3);548 gchar **parts = g_strsplit (line, "\t", 3);
535549
@@ -545,9 +559,21 @@
545 filename = g_string_new (name);559 filename = g_string_new (name);
546 g_free ((gpointer) name);560 g_free ((gpointer) name);
547561
548 desktop_id = g_string_new (parts[0]);562 /*
549 g_string_truncate (desktop_id, desktop_id->len - 8);563 * if we have a third column in index file it means we have a StatupWMClass which
550 564 * is a better desktop_id/window_class than the desktop filename stripped by .desktop.
565 * e.g. firefox-4.0.desktop dailies have window class "Minefield"
566 * since Exec can be a multi whitespace token we expect a BAMF_WM_CLASS:: to indicate
567 * a StartupWMClass info
568 */
569 bamf_wm_class = parts[2] ? strstr(parts[2], "BAMF_WM_CLASS::") : NULL;
570 if (!bamf_wm_class) {
571 desktop_id = g_string_new (parts[0]);
572 g_string_truncate (desktop_id, desktop_id->len - 8);
573 } else {
574 desktop_id = g_string_new (g_ascii_strdown(bamf_wm_class + 15 /* strlen ("BAMF_WM_CLASS::") */, -1));
575 }
576
551 insert_data_into_tables (self, filename->str, exec, desktop_id->str, desktop_file_table, desktop_id_table);577 insert_data_into_tables (self, filename->str, exec, desktop_id->str, desktop_file_table, desktop_id_table);
552578
553 g_string_free (desktop_id, TRUE);579 g_string_free (desktop_id, TRUE);

Subscribers

People subscribed via source and target branches