@@ -0,0 +1,106 @@
1+From faeb322b01d3856f3cf163470cc38f4e88a8527c Mon Sep 17 00:00:00 2001
2+From: =?UTF-8?q?Jos=C3=A9=20Romildo=20Malaquias?= <malaquias@gmail.com>
3+Date: Sun, 28 Apr 2019 21:45:39 -0300
4+Subject: [PATCH] Use system data dirs to locate key bindings
5+
6+---
7+ capplets/keybindings/Makefile.am | 3 +-
8+ .../keybindings/mate-keybinding-properties.c | 58 ++++++++++++-------
9+ 2 files changed, 39 insertions(+), 22 deletions(-)
10+
11+diff --git a/capplets/keybindings/Makefile.am b/capplets/keybindings/Makefile.am
12+index e5efb109..9501dd8f 100644
13+--- a/capplets/keybindings/Makefile.am
14++++ b/capplets/keybindings/Makefile.am
15+@@ -33,8 +33,7 @@ AM_CPPFLAGS = \
16+ $(MATECC_CAPPLETS_CFLAGS) \
17+ -DMATELOCALEDIR="\"$(datadir)/locale\"" \
18+ -DMATECC_DATA_DIR="\"$(pkgdatadir)\"" \
19+- -DMATECC_UI_DIR="\"$(uidir)\"" \
20+- -DMATECC_KEYBINDINGS_DIR="\"$(pkgdatadir)/keybindings\""
21++ -DMATECC_UI_DIR="\"$(uidir)\""
22+ CLEANFILES = \
23+ $(MATECC_CAPPLETS_CLEANFILES) \
24+ $(desktop_DATA) \
25+diff --git a/capplets/keybindings/mate-keybinding-properties.c b/capplets/keybindings/mate-keybinding-properties.c
26+index 4f257333..cf1891d2 100644
27+--- a/capplets/keybindings/mate-keybinding-properties.c
28++++ b/capplets/keybindings/mate-keybinding-properties.c
29+@@ -1033,39 +1033,57 @@ static void
30+ reload_key_entries (GtkBuilder *builder)
31+ {
32+ gchar **wm_keybindings;
33+- GDir *dir;
34+- const char *name;
35+ GList *list, *l;
36++ const gchar * const * data_dirs;
37++ GHashTable *loaded_files;
38++ guint i;
39+
40+ wm_keybindings = wm_common_get_current_keybindings();
41+
42+ clear_old_model (builder);
43+
44+- dir = g_dir_open (MATECC_KEYBINDINGS_DIR, 0, NULL);
45+- if (!dir)
46+- return;
47+-
48+- list = NULL;
49+- for (name = g_dir_read_name (dir) ; name ; name = g_dir_read_name (dir))
50++ loaded_files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
51++ data_dirs = g_get_system_data_dirs ();
52++ for (i = 0; data_dirs[i] != NULL; i++)
53+ {
54+- if (g_str_has_suffix (name, ".xml"))
55++ g_autofree gchar *dir_path = NULL;
56++ GDir *dir;
57++ const gchar *name;
58++
59++ dir_path = g_build_filename (data_dirs[i], "mate-control-center", "keybindings", NULL);
60++ g_debug ("Keybinding dir: %s", dir_path);
61++
62++ dir = g_dir_open (dir_path, 0, NULL);
63++ if (!dir)
64++ continue;
65++
66++ for (name = g_dir_read_name (dir) ; name ; name = g_dir_read_name (dir))
67+ {
68+- list = g_list_insert_sorted (list, g_strdup (name),
69+- (GCompareFunc) g_ascii_strcasecmp);
70+- }
71+- }
72+- g_dir_close (dir);
73++ if (g_str_has_suffix (name, ".xml") == FALSE)
74++ continue;
75++
76++ if (g_hash_table_lookup (loaded_files, name) != NULL)
77++ {
78++ g_debug ("Not loading %s, it was already loaded from another directory", name);
79++ continue;
80++ }
81+
82++ g_hash_table_insert (loaded_files, g_strdup (name), g_strdup (dir_path));
83++ }
84++
85++ g_dir_close (dir);
86++ }
87++ list = g_hash_table_get_keys (loaded_files);
88++ list = g_list_sort(list, (GCompareFunc) g_str_equal);
89+ for (l = list; l != NULL; l = l->next)
90+ {
91+- gchar *path;
92+-
93+- path = g_build_filename (MATECC_KEYBINDINGS_DIR, l->data, NULL);
94+- append_keys_to_tree_from_file (builder, path, wm_keybindings);
95+- g_free (l->data);
96+- g_free (path);
97++ g_autofree gchar *path = NULL;
98++ path = g_build_filename (g_hash_table_lookup (loaded_files, l->data), l->data, NULL);
99++ g_debug ("Keybinding file: %s", path);
100++ append_keys_to_tree_from_file (builder, path, wm_keybindings);
101+ }
102+ g_list_free (list);
103++ g_hash_table_destroy (loaded_files);
104+
105+ /* Load custom shortcuts _after_ system-provided ones,
106+ * since some of the custom shortcuts may also be listed