about summary refs log tree commit diff
path: root/pkgs/desktops/mate/mate-control-center/mate-control-center.keybindings-dir.patch
blob: 4a3036ae16e23daab63ab165ff6808c3323fb8f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
From faeb322b01d3856f3cf163470cc38f4e88a8527c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Romildo=20Malaquias?= <malaquias@gmail.com>
Date: Sun, 28 Apr 2019 21:45:39 -0300
Subject: [PATCH] Use system data dirs to locate key bindings

---
 capplets/keybindings/Makefile.am              |  3 +-
 .../keybindings/mate-keybinding-properties.c  | 58 ++++++++++++-------
 2 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/capplets/keybindings/Makefile.am b/capplets/keybindings/Makefile.am
index e5efb109..9501dd8f 100644
--- a/capplets/keybindings/Makefile.am
+++ b/capplets/keybindings/Makefile.am
@@ -33,8 +33,7 @@ AM_CPPFLAGS = \
 	$(MATECC_CAPPLETS_CFLAGS) \
 	-DMATELOCALEDIR="\"$(datadir)/locale\"" \
 	-DMATECC_DATA_DIR="\"$(pkgdatadir)\"" \
-	-DMATECC_UI_DIR="\"$(uidir)\"" \
-	-DMATECC_KEYBINDINGS_DIR="\"$(pkgdatadir)/keybindings\""
+	-DMATECC_UI_DIR="\"$(uidir)\""
 CLEANFILES = \
 	$(MATECC_CAPPLETS_CLEANFILES) \
 	$(desktop_DATA) \
diff --git a/capplets/keybindings/mate-keybinding-properties.c b/capplets/keybindings/mate-keybinding-properties.c
index 4f257333..cf1891d2 100644
--- a/capplets/keybindings/mate-keybinding-properties.c
+++ b/capplets/keybindings/mate-keybinding-properties.c
@@ -1033,39 +1033,57 @@ static void
 reload_key_entries (GtkBuilder *builder)
 {
   gchar **wm_keybindings;
-  GDir *dir;
-  const char *name;
   GList *list, *l;
+  const gchar * const * data_dirs;
+  GHashTable *loaded_files;
+  guint i;
 
   wm_keybindings = wm_common_get_current_keybindings();
 
   clear_old_model (builder);
 
-  dir = g_dir_open (MATECC_KEYBINDINGS_DIR, 0, NULL);
-  if (!dir)
-      return;
-
-  list = NULL;
-  for (name = g_dir_read_name (dir) ; name ; name = g_dir_read_name (dir))
+  loaded_files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+  data_dirs = g_get_system_data_dirs ();
+  for (i = 0; data_dirs[i] != NULL; i++)
     {
-      if (g_str_has_suffix (name, ".xml"))
+      g_autofree gchar *dir_path = NULL;
+      GDir *dir;
+      const gchar *name;
+
+      dir_path = g_build_filename (data_dirs[i], "mate-control-center", "keybindings", NULL);
+      g_debug ("Keybinding dir: %s", dir_path);
+
+      dir = g_dir_open (dir_path, 0, NULL);
+      if (!dir)
+        continue;
+
+      for (name = g_dir_read_name (dir) ; name ; name = g_dir_read_name (dir))
         {
-      list = g_list_insert_sorted (list, g_strdup (name),
-                       (GCompareFunc) g_ascii_strcasecmp);
-    }
-    }
-  g_dir_close (dir);
+          if (g_str_has_suffix (name, ".xml") == FALSE)
+            continue;
+
+          if (g_hash_table_lookup (loaded_files, name) != NULL)
+            {
+              g_debug ("Not loading %s, it was already loaded from another directory", name);
+              continue;
+            }
 
+          g_hash_table_insert (loaded_files, g_strdup (name), g_strdup (dir_path));
+        }
+
+      g_dir_close (dir);
+    }
+  list = g_hash_table_get_keys (loaded_files);
+  list = g_list_sort(list, (GCompareFunc) g_str_equal);
   for (l = list; l != NULL; l = l->next)
     {
-        gchar *path;
-
-    path = g_build_filename (MATECC_KEYBINDINGS_DIR, l->data, NULL);
-        append_keys_to_tree_from_file (builder, path, wm_keybindings);
-    g_free (l->data);
-    g_free (path);
+      g_autofree gchar *path = NULL;
+      path = g_build_filename (g_hash_table_lookup (loaded_files, l->data), l->data, NULL);
+      g_debug ("Keybinding file: %s", path);
+      append_keys_to_tree_from_file (builder, path, wm_keybindings);
     }
   g_list_free (list);
+  g_hash_table_destroy (loaded_files);
 
   /* Load custom shortcuts _after_ system-provided ones,
    * since some of the custom shortcuts may also be listed