From 0e2fa128a686142c313e758eccd4c1dac96bfa03 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 28 Jun 2008 12:59:58 +0200 Subject: [PATCH] Add "buffer_title" bar item, and create title bar when using /bar default --- src/gui/gui-bar-item.c | 31 ++++++++++++++++++++++++++++++- src/gui/gui-bar-item.h | 1 + src/gui/gui-bar.c | 19 ++++++++++++++++++- src/gui/gui-buffer.c | 1 + 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 3533c7faa..35498dce3 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -50,7 +50,7 @@ struct t_gui_bar_item *last_gui_bar_item = NULL; /* last bar item */ char *gui_bar_item_names[GUI_BAR_NUM_ITEMS] = { "input_prompt", "input_text", "time", "buffer_count", "buffer_plugin", "buffer_name", "buffer_filter", "nicklist_count", "scroll", "hotlist", - "completion" + "completion", "buffer_title" }; struct t_gui_bar_item_hook *gui_bar_item_hooks = NULL; struct t_hook *gui_bar_item_timer = NULL; @@ -993,6 +993,28 @@ gui_bar_item_default_completion (void *data, struct t_gui_bar_item *item, return buf; } +/* + * gui_bar_item_default_buffer_title: default item for buffer title + */ + +char * +gui_bar_item_default_buffer_title (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width, int max_height) +{ + /* make C compiler happy */ + (void) data; + (void) item; + (void) max_width; + (void) max_height; + + if (!window) + window = gui_current_window; + + return (window->buffer->title) ? + strdup (window->buffer->title) : NULL; +} + /* * gui_bar_item_timer_cb: timer callback */ @@ -1159,6 +1181,13 @@ gui_bar_item_init () &gui_bar_item_default_completion, NULL); gui_bar_item_hook ("partial_completion", gui_bar_item_names[GUI_BAR_ITEM_COMPLETION]); + + /* buffer title */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_BUFFER_TITLE], + &gui_bar_item_default_buffer_title, NULL); + gui_bar_item_hook ("buffer_title_changed", + gui_bar_item_names[GUI_BAR_ITEM_BUFFER_TITLE]); } /* diff --git a/src/gui/gui-bar-item.h b/src/gui/gui-bar-item.h index 1fbb07ae7..7d225c217 100644 --- a/src/gui/gui-bar-item.h +++ b/src/gui/gui-bar-item.h @@ -33,6 +33,7 @@ enum t_gui_bar_item_weechat GUI_BAR_ITEM_SCROLL, GUI_BAR_ITEM_HOTLIST, GUI_BAR_ITEM_COMPLETION, + GUI_BAR_ITEM_BUFFER_TITLE, /* number of bar items */ GUI_BAR_NUM_ITEMS, }; diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index bc40ec145..09358c5d4 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -1656,11 +1656,28 @@ gui_bar_create_default () "0", buf)) { gui_chat_printf (NULL, _("Bar \"%s\" created"), - "input"); + "status"); } free (buf); } } + + /* search title bar */ + ptr_bar = gui_bar_search ("title"); + if (!ptr_bar) + { + /* create title bar */ + if (gui_bar_new (NULL, "title", "0", "0", "window", "", + "top", "horizontal", "1", "0", + gui_color_get_name (CONFIG_COLOR(config_color_title)), + gui_color_get_name (CONFIG_COLOR(config_color_title)), + gui_color_get_name (CONFIG_COLOR(config_color_title_bg)), + "0", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_TITLE])) + { + gui_chat_printf (NULL, _("Bar \"%s\" created"), + "title"); + } + } } /* diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 34778fb00..6b013147a 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -392,6 +392,7 @@ gui_buffer_set_title (struct t_gui_buffer *buffer, const char *new_title) free (buffer->title); buffer->title = (new_title && new_title[0]) ? strdup (new_title) : NULL; gui_buffer_ask_title_refresh (buffer, 1); + hook_signal_send ("buffer_title_changed", WEECHAT_HOOK_SIGNAL_STRING, NULL); } /*