mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Merge branch 'master' into plugins
This commit is contained in:
commit
1a7d664b85
@ -239,12 +239,16 @@ api_win_exists(const char *tag)
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
PluginWindowCallback *window = malloc(sizeof(PluginWindowCallback));
|
||||
window->callback = callback;
|
||||
window->callback_func = callback_func;
|
||||
window->destroy = destroy;
|
||||
callbacks_add_window_handler(tag, window);
|
||||
wins_new_plugin(tag);
|
||||
|
||||
|
@ -61,7 +61,10 @@ void api_log_warning(const char *message);
|
||||
void api_log_error(const char *message);
|
||||
|
||||
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));
|
||||
int api_win_focus(const char *tag);
|
||||
int api_win_show(const char *tag, const char *line);
|
||||
|
@ -167,7 +167,7 @@ c_api_win_create(char *tag, void(*callback)(char *tag, char *line))
|
||||
{
|
||||
WindowWrapper *wrapper = malloc(sizeof(WindowWrapper));
|
||||
wrapper->func = callback;
|
||||
api_win_create(tag, wrapper, c_window_callback);
|
||||
api_win_create(tag, wrapper, free, c_window_callback);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -46,6 +46,27 @@ static GSList *p_commands = NULL;
|
||||
static GSList *p_timed_functions = 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
|
||||
callbacks_add_command(PluginCommand *command)
|
||||
{
|
||||
@ -63,10 +84,6 @@ callbacks_add_timed(PluginTimedFunction *timed_function)
|
||||
void
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,13 @@ typedef struct p_timed_function {
|
||||
|
||||
typedef struct p_window_input_callback {
|
||||
void *callback;
|
||||
void (*destroy)(void *callback);
|
||||
void (*callback_func)(struct p_window_input_callback *window_callback, const char *tag, const char * const line);
|
||||
} PluginWindowCallback;
|
||||
|
||||
void callbacks_init(void);
|
||||
void callbacks_close(void);
|
||||
|
||||
void callbacks_add_command(PluginCommand *command);
|
||||
void callbacks_add_timed(PluginTimedFunction *timed_function);
|
||||
void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback);
|
||||
|
@ -228,7 +228,7 @@ lua_api_win_create(lua_State *L)
|
||||
int *p_callback_ref = malloc(sizeof(int));
|
||||
*p_callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
||||
api_win_create(tag, p_callback_ref, lua_window_callback);
|
||||
api_win_create(tag, p_callback_ref, NULL, lua_window_callback);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ void
|
||||
plugins_init(void)
|
||||
{
|
||||
plugins = NULL;
|
||||
callbacks_init();
|
||||
autocompleters_init();
|
||||
|
||||
#ifdef PROF_HAVE_PYTHON
|
||||
@ -488,6 +489,7 @@ plugins_shutdown(void)
|
||||
|
||||
autocompleters_destroy();
|
||||
plugin_themes_close();
|
||||
callbacks_close();
|
||||
}
|
||||
|
||||
gchar *
|
||||
|
@ -303,7 +303,7 @@ python_api_win_create(PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
if (p_callback && PyCallable_Check(p_callback)) {
|
||||
api_win_create(tag, p_callback, python_window_callback);
|
||||
api_win_create(tag, p_callback, NULL, python_window_callback);
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
|
@ -213,7 +213,7 @@ ruby_api_win_create(VALUE self, VALUE v_tag, VALUE v_callback)
|
||||
{
|
||||
char *tag = STR2CSTR(v_tag);
|
||||
|
||||
api_win_create(tag, (void*)v_callback, ruby_window_callback);
|
||||
api_win_create(tag, (void*)v_callback, NULL, ruby_window_callback);
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user