diff --git a/src/tox-weechat-gui.c b/src/tox-weechat-gui.c index 8b1291d..8158d1a 100644 --- a/src/tox-weechat-gui.c +++ b/src/tox-weechat-gui.c @@ -19,38 +19,27 @@ bar_item_input_prompt(void *data, } char * -irc_bar_item_buffer_plugin(void *data, struct t_gui_bar_item *item, +bar_item_buffer_plugin(void *data, struct t_gui_bar_item *item, struct t_gui_window *window, struct t_gui_buffer *buffer, struct t_hashtable *extra_info) { - char string[512]; + char string[256]; const char *name = weechat_plugin_get_name(weechat_plugin); - char *status = "online" + const char *status = tox_weechat_online_status ? "online" : "offline"; + const char *color = weechat_color(tox_weechat_online_status ? "green" : "red"); + snprintf(string, sizeof(string), + "%s %s%s", name, color, status); - - snprintf(string, sizeof(string), "%s %s%s", - name, - weechat_color(" - ); - } - else - { - snprintf (buf, sizeof (buf), "%s", name); - } - } - else - { - snprintf (buf, sizeof (buf), "%s", name); - } - return strdup (buf); + return strdup(string); } void tox_weechat_gui_init() { weechat_bar_item_new("input_prompt", bar_item_input_prompt, NULL); + weechat_bar_item_new("buffer_plugin", bar_item_buffer_plugin, NULL); } diff --git a/src/tox-weechat-tox.c b/src/tox-weechat-tox.c index 7f7f8ba..04bf6f3 100644 --- a/src/tox-weechat-tox.c +++ b/src/tox-weechat-tox.c @@ -79,6 +79,13 @@ tox_weechat_do_timer_cb(void *data, tox_do(tox); weechat_hook_timer(tox_do_interval(tox), 0, 1, tox_weechat_do_timer_cb, data); + int connected = tox_isconnected(tox); + if (connected ^ tox_weechat_online_status) + { + tox_weechat_online_status = connected; + weechat_bar_item_update("buffer_plugin"); + } + return WEECHAT_RC_OK; } diff --git a/src/tox-weechat.c b/src/tox-weechat.c index 6bcab8c..5a9f216 100644 --- a/src/tox-weechat.c +++ b/src/tox-weechat.c @@ -17,7 +17,7 @@ WEECHAT_PLUGIN_LICENSE("MIT"); struct t_weechat_plugin *weechat_plugin = NULL; struct t_gui_buffer *tox_main_buffer = NULL; -int online_status = 0; +int tox_weechat_online_status = 0; int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[]) diff --git a/src/tox-weechat.h b/src/tox-weechat.h index ebe3891..8b871b8 100644 --- a/src/tox-weechat.h +++ b/src/tox-weechat.h @@ -5,7 +5,7 @@ extern struct t_weechat_plugin *weechat_plugin; extern Tox *tox; -extern int online_status; +extern int tox_weechat_online_status; extern struct t_gui_buffer *tox_main_buffer;