summaryrefslogtreecommitdiff
path: root/src/plugins/buflist
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-03-25 21:39:59 +0100
committerSébastien Helleu <flashcode@flashtux.org>2017-03-25 21:39:59 +0100
commit9816c8cbce202c97c5d6fd14260ff7e18a6a97c4 (patch)
tree4513c30ef3704f1ae128dbb6d711f4a7114aac95 /src/plugins/buflist
parent370fbeb5a39b0b168551c1dd6d23c02f60c32721 (diff)
downloadweechat-9816c8cbce202c97c5d6fd14260ff7e18a6a97c4.zip
buflist: add option buflist.look.signals_refresh
Diffstat (limited to 'src/plugins/buflist')
-rw-r--r--src/plugins/buflist/buflist-config.c105
-rw-r--r--src/plugins/buflist/buflist-config.h3
-rw-r--r--src/plugins/buflist/buflist.c36
3 files changed, 108 insertions, 36 deletions
diff --git a/src/plugins/buflist/buflist-config.c b/src/plugins/buflist/buflist-config.c
index 48f5a4766..d61ac9a6a 100644
--- a/src/plugins/buflist/buflist-config.c
+++ b/src/plugins/buflist/buflist-config.c
@@ -31,6 +31,7 @@ struct t_config_file *buflist_config_file = NULL;
/* buflist config, look section */
+struct t_config_option *buflist_config_look_signals_refresh;
struct t_config_option *buflist_config_look_sort;
/* buflist config, format section */
@@ -43,6 +44,8 @@ struct t_config_option *buflist_config_format_hotlist_level_none;
struct t_config_option *buflist_config_format_hotlist_separator;
struct t_config_option *buflist_config_format_lag;
+struct t_hook **buflist_config_signals_refresh = NULL;
+int buflist_config_num_signals_refresh = 0;
char **buflist_config_sort_fields = NULL;
int buflist_config_sort_fields_count = 0;
@@ -71,6 +74,90 @@ buflist_config_change_sort (const void *pointer, void *data,
}
/*
+ * Frees the signals hooked for refresh.
+ */
+
+void
+buflist_config_free_signals_refresh ()
+{
+ int i;
+
+ if (!buflist_config_signals_refresh)
+ return;
+
+ for (i = 0; i < buflist_config_num_signals_refresh; i++)
+ {
+ weechat_unhook (buflist_config_signals_refresh[i]);
+ }
+
+ free (buflist_config_signals_refresh);
+ buflist_config_signals_refresh = NULL;
+
+ buflist_config_num_signals_refresh = 0;
+}
+
+/*
+ * Callback for a signal on a buffer.
+ */
+
+int
+buflist_config_signal_buffer_cb (const void *pointer, void *data,
+ const char *signal, const char *type_data,
+ void *signal_data)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) signal;
+ (void) type_data;
+ (void) signal_data;
+
+ weechat_bar_item_update (BUFLIST_BAR_ITEM_NAME);
+
+ return WEECHAT_RC_OK;
+}
+
+/*
+ * Callback for changes on option "buflist.look.signals_refresh".
+ */
+
+void
+buflist_config_change_signals_refresh (const void *pointer, void *data,
+ struct t_config_option *option)
+{
+ char **signals;
+ int count, i;
+
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) option;
+
+ if (buflist_config_signals_refresh)
+ buflist_config_free_signals_refresh ();
+
+ signals = weechat_string_split (
+ weechat_config_string (buflist_config_look_signals_refresh),
+ ",", 0, 0, &count);
+ if (signals && (count > 0))
+ {
+ buflist_config_signals_refresh = malloc (
+ count * sizeof (*buflist_config_signals_refresh));
+ if (buflist_config_signals_refresh)
+ {
+ buflist_config_num_signals_refresh = count;
+ for (i = 0; i < count; i++)
+ {
+ buflist_config_signals_refresh[i] = weechat_hook_signal (
+ signals[i], &buflist_config_signal_buffer_cb, NULL, NULL);
+ }
+ }
+ }
+ if (signals)
+ weechat_string_free_split (signals);
+}
+
+/*
* Callback for changes on format options.
*/
@@ -130,6 +217,20 @@ buflist_config_init ()
NULL, NULL, NULL,
&buflist_config_change_sort, NULL, NULL,
NULL, NULL, NULL);
+ buflist_config_look_signals_refresh = weechat_config_new_option (
+ buflist_config_file, ptr_section,
+ "signals_refresh", "string",
+ N_("comma-separated list of signals that are hooked and trigger the "
+ "refresh of buffers list"),
+ NULL, 0, 0,
+ "buffer_opened,buffer_closed,buffer_merged,buffer_unmerged,"
+ "buffer_moved,buffer_renamed,buffer_switch,buffer_hidden,"
+ "buffer_unhidden,buffer_localvar_added,buffer_localvar_changed,"
+ "window_switch,hotlist_changed",
+ NULL, 0,
+ NULL, NULL, NULL,
+ &buflist_config_change_signals_refresh, NULL, NULL,
+ NULL, NULL, NULL);
/* format */
ptr_section = weechat_config_new_section (buflist_config_file, "format",
@@ -273,6 +374,7 @@ buflist_config_read ()
if (rc == WEECHAT_CONFIG_READ_OK)
{
buflist_config_change_sort (NULL, NULL, NULL);
+ buflist_config_change_signals_refresh (NULL, NULL, NULL);
}
return rc;
@@ -297,6 +399,9 @@ buflist_config_free ()
{
weechat_config_free (buflist_config_file);
+ if (buflist_config_signals_refresh)
+ buflist_config_free_signals_refresh ();
+
if (buflist_config_sort_fields)
{
weechat_string_free_split (buflist_config_sort_fields);
diff --git a/src/plugins/buflist/buflist-config.h b/src/plugins/buflist/buflist-config.h
index e7991a034..87c7fbf8b 100644
--- a/src/plugins/buflist/buflist-config.h
+++ b/src/plugins/buflist/buflist-config.h
@@ -24,6 +24,9 @@
extern struct t_config_file *buflist_config_file;
+extern struct t_config_option *buflist_config_look_signals_refresh;
+extern struct t_config_option *buflist_config_look_sort;
+
extern struct t_config_option *buflist_config_format_buffer;
extern struct t_config_option *buflist_config_format_buffer_current;
extern struct t_config_option *buflist_config_format_hotlist;
diff --git a/src/plugins/buflist/buflist.c b/src/plugins/buflist/buflist.c
index 1a6d772df..4918d2917 100644
--- a/src/plugins/buflist/buflist.c
+++ b/src/plugins/buflist/buflist.c
@@ -221,41 +221,12 @@ buflist_sort_buffers ()
}
/*
- * Callback for a signal on a buffer.
- */
-
-int
-buflist_signal_buffer_cb (const void *pointer, void *data,
- const char *signal, const char *type_data,
- void *signal_data)
-{
- /* make C compiler happy */
- (void) pointer;
- (void) data;
- (void) signal;
- (void) type_data;
- (void) signal_data;
-
- weechat_bar_item_update (BUFLIST_BAR_ITEM_NAME);
-
- return WEECHAT_RC_OK;
-}
-
-/*
* Initializes buflist plugin.
*/
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
- char *signals_buffers[] =
- { "buffer_opened", "buffer_closed", "buffer_merged", "buffer_unmerged",
- "buffer_moved", "buffer_renamed", "buffer_switch", "buffer_hidden",
- "buffer_unhidden", "buffer_localvar_added", "buffer_localvar_changed",
- "window_switch", "hotlist_changed", NULL
- };
- int i;
-
/* make C compiler happy */
(void) argc;
(void) argv;
@@ -275,13 +246,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
buflist_command_init ();
- /* hook some signals */
- for (i = 0; signals_buffers[i]; i++)
- {
- weechat_hook_signal (signals_buffers[i],
- &buflist_signal_buffer_cb, NULL, NULL);
- }
-
weechat_bar_new (BUFLIST_BAR_NAME, "off", "0", "root", "", "left",
"columns_vertical", "vertical", "0", "0",
"default", "default", "default", "on",