1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2016-03-07 20:44:41 +00:00
commit b02945a048
6 changed files with 37 additions and 7 deletions

View File

@ -239,12 +239,16 @@ api_win_exists(const char *tag)
} }
void void
api_win_create(const char *tag, void *callback, api_win_create(
const char *tag,
void *callback,
void(*destroy)(void *callback),
void(*callback_func)(PluginWindowCallback *window_callback, const char *tag, const char * const line)) void(*callback_func)(PluginWindowCallback *window_callback, const char *tag, const char * const line))
{ {
PluginWindowCallback *window = malloc(sizeof(PluginWindowCallback)); PluginWindowCallback *window = malloc(sizeof(PluginWindowCallback));
window->callback = callback; window->callback = callback;
window->callback_func = callback_func; window->callback_func = callback_func;
window->destroy = destroy;
callbacks_add_window_handler(tag, window); callbacks_add_window_handler(tag, window);
wins_new_plugin(tag); wins_new_plugin(tag);

View File

@ -61,7 +61,10 @@ void api_log_warning(const char *message);
void api_log_error(const char *message); void api_log_error(const char *message);
int api_win_exists(const char *tag); int api_win_exists(const char *tag);
void api_win_create(const char *tag, void *callback, void api_win_create(
const char *tag,
void *callback,
void(*destroy)(void *callback),
void(*callback_func)(PluginWindowCallback *window_callback, char *tag, char *line)); void(*callback_func)(PluginWindowCallback *window_callback, char *tag, char *line));
int api_win_focus(const char *tag); int api_win_focus(const char *tag);
int api_win_show(const char *tag, const char *line); int api_win_show(const char *tag, const char *line);

View File

@ -167,7 +167,7 @@ c_api_win_create(char *tag, void(*callback)(char *tag, char *line))
{ {
WindowWrapper *wrapper = malloc(sizeof(WindowWrapper)); WindowWrapper *wrapper = malloc(sizeof(WindowWrapper));
wrapper->func = callback; wrapper->func = callback;
api_win_create(tag, wrapper, c_window_callback); api_win_create(tag, wrapper, free, c_window_callback);
} }
static int static int

View File

@ -46,6 +46,27 @@ static GSList *p_commands = NULL;
static GSList *p_timed_functions = NULL; static GSList *p_timed_functions = NULL;
static GHashTable *p_window_callbacks = NULL; static GHashTable *p_window_callbacks = NULL;
static void
_free_window_callback(PluginWindowCallback *window_callback)
{
if (window_callback->destroy) {
window_callback->destroy(window_callback->callback);
}
free(window_callback);
}
void
callbacks_init(void)
{
p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback);
}
void
callbacks_close(void)
{
g_hash_table_destroy(p_window_callbacks);
}
void void
callbacks_add_command(PluginCommand *command) callbacks_add_command(PluginCommand *command)
{ {
@ -64,10 +85,6 @@ callbacks_add_timed(PluginTimedFunction *timed_function)
void void
callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback) callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback)
{ {
if (p_window_callbacks == NULL) {
p_window_callbacks = g_hash_table_new(g_str_hash, g_str_equal);
}
g_hash_table_insert(p_window_callbacks, strdup(tag), window_callback); g_hash_table_insert(p_window_callbacks, strdup(tag), window_callback);
} }

View File

@ -57,9 +57,13 @@ typedef struct p_timed_function {
typedef struct p_window_input_callback { typedef struct p_window_input_callback {
void *callback; void *callback;
void (*destroy)(void *callback);
void (*callback_func)(struct p_window_input_callback *window_callback, const char *tag, const char * const line); void (*callback_func)(struct p_window_input_callback *window_callback, const char *tag, const char * const line);
} PluginWindowCallback; } PluginWindowCallback;
void callbacks_init(void);
void callbacks_close(void);
void callbacks_add_command(PluginCommand *command); void callbacks_add_command(PluginCommand *command);
void callbacks_add_timed(PluginTimedFunction *timed_function); void callbacks_add_timed(PluginTimedFunction *timed_function);
void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback); void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback);

View File

@ -57,6 +57,7 @@ void
plugins_init(void) plugins_init(void)
{ {
plugins = NULL; plugins = NULL;
callbacks_init();
autocompleters_init(); autocompleters_init();
plugin_themes_init(); plugin_themes_init();
@ -404,6 +405,7 @@ plugins_shutdown(void)
autocompleters_destroy(); autocompleters_destroy();
plugin_themes_close(); plugin_themes_close();
callbacks_close();
} }
gchar * gchar *