From 0d7b4cb4a7bac70bdb494dbcbeaaa18996e1a496 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 Jul 2016 22:42:15 +0100 Subject: Store plugin window callbacks by plugin name --- src/plugins/api.c | 4 +++- src/plugins/callbacks.c | 35 +++++++++++++++++++++++++++++++---- src/plugins/callbacks.h | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/plugins/api.c b/src/plugins/api.c index 955a7bde..53138a4e 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -306,7 +306,9 @@ api_win_create( window->callback = callback; window->callback_exec = callback_exec; window->callback_destroy = callback_destroy; - callbacks_add_window_handler(tag, window); + + callbacks_add_window_handler(plugin_name, tag, window); + wins_new_plugin(tag); // set status bar active diff --git a/src/plugins/callbacks.c b/src/plugins/callbacks.c index 41ba30db..a837e067 100644 --- a/src/plugins/callbacks.c +++ b/src/plugins/callbacks.c @@ -57,6 +57,12 @@ _free_window_callback(PluginWindowCallback *window_callback) free(window_callback); } +static void +_free_window_callbacks(GHashTable *window_callbacks) +{ + g_hash_table_destroy(window_callbacks); +} + static void _free_command_help(CommandHelp *help) { @@ -129,7 +135,7 @@ callbacks_init(void) { p_commands = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_command_hash); p_timed_functions = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_timed_function_list); - p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback); + p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callbacks); } // TODO move to plugin destroy functions @@ -170,16 +176,37 @@ callbacks_add_timed(const char *const plugin_name, PluginTimedFunction *timed_fu } void -callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback) +callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback) { - g_hash_table_insert(p_window_callbacks, strdup(tag), window_callback); + GHashTable *window_callbacks = g_hash_table_lookup(p_window_callbacks, plugin_name); + if (window_callbacks) { + g_hash_table_insert(window_callbacks, strdup(tag), window_callback); + } else { + window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback); + g_hash_table_insert(window_callbacks, strdup(tag), window_callback); + g_hash_table_insert(p_window_callbacks, strdup(plugin_name), window_callbacks); + } } void * callbacks_get_window_handler(const char *tag) { if (p_window_callbacks) { - return g_hash_table_lookup(p_window_callbacks, tag); + GList *window_callback_hashes = g_hash_table_get_values(p_window_callbacks); + GList *curr_hash = window_callback_hashes; + while (curr_hash) { + GHashTable *window_callback_hash = curr_hash->data; + PluginWindowCallback *callback = g_hash_table_lookup(window_callback_hash, tag); + if (callback) { + g_list_free(window_callback_hashes); + return callback; + } + + curr_hash = g_list_next(curr_hash); + } + + g_list_free(window_callback_hashes); + return NULL; } else { return NULL; } diff --git a/src/plugins/callbacks.h b/src/plugins/callbacks.h index 7284ba28..8fd577fb 100644 --- a/src/plugins/callbacks.h +++ b/src/plugins/callbacks.h @@ -68,7 +68,7 @@ void callbacks_close(void); void callbacks_add_command(const char *const plugin_name, PluginCommand *command); void callbacks_add_timed(const char *const plugin_name, PluginTimedFunction *timed_function); -void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback); +void callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback); void * callbacks_get_window_handler(const char *tag); #endif -- cgit 1.4.1-2-gfad0 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