[gnome-settings-daemon/gnome-3-24] media-keys: Use hash table keys that uniquely identify a key
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/gnome-3-24] media-keys: Use hash table keys that uniquely identify a key
- Date: Sat, 22 Jul 2017 16:55:50 +0000 (UTC)
commit 5922234ac2b29b3e394d72d2b4a17947b9221632
Author: Florian Müllner <fmuellner gnome org>
Date: Mon Jul 10 23:35:20 2017 +0200
media-keys: Use hash table keys that uniquely identify a key
We keep track of ongoing and requested grab operations by registering
a key in a corresponding hash table. However currently we use the
key's current binding as hash table key, which is subject to changes.
To not mess up the tracking when a setting changes at the wrong time,
base the hash table keys on immutable properties that uniquely identify
the key.
https://bugzilla.gnome.org/show_bug.cgi?id=784702
plugins/media-keys/gsd-media-keys-manager.c | 43 ++++++++++++++++++---------
1 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index ccfa57e..b5a1818 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -319,8 +319,21 @@ set_launch_context_env (GsdMediaKeysManager *manager,
}
static char *
-get_key_string (GsdMediaKeysManager *manager,
- MediaKey *key)
+get_key_string (MediaKey *key)
+{
+ if (key->settings_key != NULL)
+ return g_strdup_printf ("settings:%s", key->settings_key);
+ else if (key->hard_coded != NULL)
+ return g_strdup_printf ("fixed:%s", key->hard_coded);
+ else if (key->custom_path != NULL)
+ return g_strdup_printf ("custom:%s", key->custom_path);
+ else
+ g_assert_not_reached ();
+}
+
+static char *
+get_binding (GsdMediaKeysManager *manager,
+ MediaKey *key)
{
if (key->settings_key != NULL)
return g_settings_get_string (manager->priv->settings, key->settings_key);
@@ -462,7 +475,7 @@ grab_media_keys (GsdMediaKeysManager *manager)
char *tmp;
key = g_ptr_array_index (manager->priv->keys, i);
- tmp = get_key_string (manager, key);
+ tmp = get_binding (manager, key);
g_variant_builder_add (&builder, "(su)", tmp, key->modes);
g_free (tmp);
}
@@ -479,7 +492,7 @@ grab_accelerator_complete (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- char *binding;
+ char *keyname;
GrabData *data = user_data;
MediaKey *key = data->key;
GsdMediaKeysManager *manager = data->manager;
@@ -495,16 +508,16 @@ grab_accelerator_complete (GObject *object,
if (key->ungrab_requested)
ungrab_media_key (key, manager);
- binding = get_key_string (manager, key);
- g_hash_table_remove (manager->priv->keys_pending_grab, binding);
+ keyname = get_key_string (key);
+ g_hash_table_remove (manager->priv->keys_pending_grab, keyname);
media_key_unref (key);
g_slice_free (GrabData, data);
- if ((key = g_hash_table_lookup (manager->priv->keys_to_grab, binding)) != NULL) {
+ if ((key = g_hash_table_lookup (manager->priv->keys_to_grab, keyname)) != NULL) {
grab_media_key (key, manager);
- g_hash_table_remove (manager->priv->keys_to_grab, binding);
+ g_hash_table_remove (manager->priv->keys_to_grab, keyname);
}
- g_free (binding);
+ g_free (keyname);
}
@@ -513,12 +526,13 @@ grab_media_key (MediaKey *key,
GsdMediaKeysManager *manager)
{
GrabData *data;
- char *binding;
+ char *binding, *keyname;
- binding = get_key_string (manager, key);
- if (g_hash_table_lookup (manager->priv->keys_pending_grab, binding)) {
+ keyname = get_key_string (key);
+ binding = get_binding (manager, key);
+ if (g_hash_table_lookup (manager->priv->keys_pending_grab, keyname)) {
g_hash_table_insert (manager->priv->keys_to_grab,
- g_strdup (binding), media_key_ref (key));
+ g_strdup (keyname), media_key_ref (key));
goto out;
}
@@ -531,8 +545,9 @@ grab_media_key (MediaKey *key,
manager->priv->grab_cancellable,
grab_accelerator_complete,
data);
- g_hash_table_add (manager->priv->keys_pending_grab, g_strdup (binding));
+ g_hash_table_add (manager->priv->keys_pending_grab, g_strdup (keyname));
out:
+ g_free (keyname);
g_free (binding);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]