about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/api.c4
-rw-r--r--src/plugins/callbacks.c35
-rw-r--r--src/plugins/callbacks.h2
3 files changed, 35 insertions, 6 deletions
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
@@ -58,6 +58,12 @@ _free_window_callback(PluginWindowCallback *window_callback)
 }
 
 static void
+_free_window_callbacks(GHashTable *window_callbacks)
+{
+    g_hash_table_destroy(window_callbacks);
+}
+
+static void
 _free_command_help(CommandHelp *help)
 {
     int i = 0;
@@ -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