416
418
file_list = g_list_append (file_list, datadup);
417
419
id_list = g_list_append (id_list, datadup);
420
422
g_hash_table_insert (desktop_file_table, g_strdup (exec), file_list);
421
423
g_hash_table_insert (desktop_id_table, g_strdup (desktop_id), id_list);
427
insert_desktop_file_class_into_table (BamfMatcher *self,
428
const char *desktop_file,
429
GHashTable *desktop_class_table)
431
GKeyFile *desktop_keyfile;
434
g_return_if_fail (desktop_file);
436
desktop_keyfile = g_key_file_new ();
438
if (g_key_file_load_from_file (desktop_keyfile, desktop_file, G_KEY_FILE_NONE,
441
class = g_key_file_get_string (desktop_keyfile,
442
G_KEY_FILE_DESKTOP_GROUP,
443
G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS,
446
g_hash_table_insert (desktop_class_table, g_strdup (desktop_file), class);
448
g_key_file_free (desktop_keyfile);
426
453
load_desktop_file_to_table (BamfMatcher * self,
427
454
const char *file,
428
455
GHashTable *desktop_file_table,
429
GHashTable *desktop_id_table)
456
GHashTable *desktop_id_table,
457
GHashTable *desktop_class_table)
431
459
GAppInfo *desktop_file;
467
495
desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */
469
497
insert_data_into_tables (self, file, exec, desktop_id->str, desktop_file_table, desktop_id_table);
498
insert_desktop_file_class_into_table (self, file, desktop_class_table);
472
501
g_string_free (desktop_id, TRUE);
569
601
g_string_truncate (desktop_id, desktop_id->len - 8);
571
603
insert_data_into_tables (self, filename->str, exec, desktop_id->str, desktop_file_table, desktop_id_table);
604
insert_desktop_file_class_into_table (self, filename->str, desktop_class_table);
573
606
g_string_free (desktop_id, TRUE);
612
645
if (!g_list_find_custom (dirs, "/usr/local/share/applications", (GCompareFunc) g_strcmp0))
613
646
dirs = g_list_prepend (dirs, g_strdup ("/usr/local/share/applications"));
615
dirs = g_list_prepend (dirs, g_strdup (g_build_filename (g_get_home_dir (), ".share/applications", NULL)));
648
dirs = g_list_prepend (dirs, g_strdup (g_build_filename (g_get_home_dir (), ".local/share/applications", NULL)));
618
651
g_strfreev (data_dirs);
741
784
if (g_file_test (bamf_file, G_FILE_TEST_EXISTS))
743
load_index_file_to_table (self, bamf_file, *desktop_file_table, *desktop_id_table);
786
load_index_file_to_table (self, bamf_file, *desktop_file_table,
787
*desktop_id_table, *desktop_class_table);
747
load_directory_to_table (self, directory, *desktop_file_table, *desktop_id_table);
791
load_directory_to_table (self, directory, *desktop_file_table,
792
*desktop_id_table, *desktop_class_table);
750
795
g_free (directory);
776
821
gulong bytesAfter;
777
822
unsigned char *buffer;
823
gboolean close_display = TRUE;
779
825
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
780
826
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
781
827
g_return_val_if_fail (atom_name, NULL);
783
829
XDisplay = XOpenDisplay (NULL);
832
XDisplay = gdk_x11_get_default_xdisplay ();
835
g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
839
close_display = FALSE;
784
842
atom = XInternAtom (XDisplay, atom_name, FALSE);
786
844
int result = XGetWindowProperty (XDisplay,
996
char *class_name = window_class_name (window);
1068
char *window_class = window_class_name (window);
1071
char *desktop_class;
1000
class_name = g_ascii_strdown (class_name, -1);
1001
l = g_hash_table_lookup (priv->desktop_id_table, class_name);
1075
char *window_class_down = g_ascii_strdown (g_strdup(window_class), -1);
1076
l = g_hash_table_lookup (priv->desktop_id_table, window_class_down);
1077
g_free (window_class_down);
1003
1079
for (; l; l = l->next)
1005
if (l->data && !g_list_find_custom (desktop_files, l->data, (GCompareFunc) g_strcmp0))
1006
desktop_files = g_list_prepend (desktop_files, g_strdup (l->data));
1009
desktop_files = g_list_reverse (desktop_files);
1010
g_free (class_name);
1081
desktop_file = l->data;
1084
desktop_class = g_hash_table_lookup (priv->desktop_class_table, desktop_file);
1085
if ((desktop_class == NULL || g_strcmp0 (desktop_class, window_class) == 0) &&
1086
!g_list_find_custom (desktop_files, desktop_file,
1087
(GCompareFunc) g_strcmp0))
1089
desktop_files = g_list_prepend (desktop_files, g_strdup (desktop_file));
1094
desktop_files = g_list_reverse (desktop_files);
1097
/* Iterate over the desktop class table, and add matching desktop files */
1100
GHashTableIter iter;
1101
g_hash_table_iter_init (&iter, priv->desktop_class_table);
1103
while (g_hash_table_iter_next (&iter, &key, &value))
1105
desktop_file = g_strdup (key);
1106
desktop_class = value;
1107
if (g_strcmp0 (desktop_class, window_class) == 0 &&
1108
!g_list_find_custom (desktop_files, desktop_file, (GCompareFunc) g_strcmp0))
1110
desktop_files = g_list_prepend (desktop_files, desktop_file);
1013
1114
pid = bamf_legacy_window_get_pid (window);
1015
1115
pid_list = bamf_matcher_possible_applications_for_pid (self, pid);
1017
/* Append these files to the end to give preference to class_name style picking.
1117
/* Append these files to the end to give preference to window_class style picking.
1018
1118
This style of matching is prefered and used by GNOME Shell however does not work
1019
1119
very well in practice, thus requiring the fallback here */
1020
1120
for (l = pid_list; l; l = l->next)
1122
desktop_file = l->data;
1022
1123
if (g_list_find_custom (desktop_files, l->data, (GCompareFunc) g_strcmp0))
1124
g_free (desktop_file);
1025
desktop_files = g_list_append (desktop_files, l->data);
1129
desktop_class = g_hash_table_lookup (priv->desktop_class_table, desktop_file);
1130
if ((desktop_class == NULL || g_strcmp0 (desktop_class, window_class) == 0) &&
1131
!g_list_find_custom (desktop_files, desktop_file,
1132
(GCompareFunc) g_strcmp0))
1134
desktop_files = g_list_append (desktop_files, desktop_file);
1138
desktop_files = g_list_append (desktop_files, desktop_file);
1142
g_free (window_class);
1028
1143
g_list_free (pid_list);
1732
1863
g_array_free (prefixstrings, TRUE);
1734
create_desktop_file_table (self, &(priv->desktop_file_table), &(priv->desktop_id_table));
1865
create_desktop_file_table (self, &(priv->desktop_file_table),
1866
&(priv->desktop_id_table),
1867
&(priv->desktop_class_table));
1736
1869
screen = bamf_legacy_screen_get_default ();
1737
1870
g_signal_connect (G_OBJECT (screen), "window-opened",
1738
(GCallback) handle_window_opened, self);
1871
(GCallback) handle_window_opened, self);
1740
1873
approver = bamf_indicator_source_get_default ();
1741
1874
g_signal_connect (G_OBJECT (approver), "indicator-opened",