summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/curses/gui-curses-bar.c12
-rw-r--r--src/gui/curses/gui-curses-window.c5
-rw-r--r--src/gui/gui-bar-item.c100
-rw-r--r--src/gui/gui-bar-item.h6
4 files changed, 78 insertions, 45 deletions
diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c
index 1e27fb81c..2166542ad 100644
--- a/src/gui/curses/gui-curses-bar.c
+++ b/src/gui/curses/gui-curses-bar.c
@@ -120,25 +120,25 @@ gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
case GUI_BAR_POSITION_BOTTOM:
bar_window->x = x1 + add_left;
bar_window->y = y2 - add_bottom - bar_window->bar->size + 1;
- bar_window->width = x2 - add_right - x1 + 1;
- bar_window->height = bar_window->bar->size - add_top - add_bottom;
+ bar_window->width = x2 - x1 + 1 - add_left - add_right;
+ bar_window->height = bar_window->bar->size;
break;
case GUI_BAR_POSITION_TOP:
bar_window->x = x1 + add_left;
bar_window->y = y1 + add_top;
- bar_window->width = x2 - x1 + 1;
- bar_window->height = bar_window->bar->size - add_left - add_right;
+ bar_window->width = x2 - x1 + 1 - add_left - add_right;
+ bar_window->height = bar_window->bar->size;
break;
case GUI_BAR_POSITION_LEFT:
bar_window->x = x1 + add_left;
bar_window->y = y1 + add_top;
- bar_window->width = bar_window->bar->size - add_left - add_right;
+ bar_window->width = bar_window->bar->size;
bar_window->height = y2 - add_top - add_bottom - y1 + 1;
break;
case GUI_BAR_POSITION_RIGHT:
bar_window->x = x2 - add_right - bar_window->bar->size + 1;
bar_window->y = y1 + add_top;
- bar_window->width = bar_window->bar->size - add_left - add_right;
+ bar_window->width = bar_window->bar->size;
bar_window->height = y2 - y1 + 1;
break;
}
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index d2ab8720e..a23128f10 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -28,8 +28,10 @@
#include "../../core/weechat.h"
#include "../../core/wee-config.h"
+#include "../../core/wee-hook.h"
#include "../../core/wee-log.h"
#include "../../core/wee-string.h"
+#include "../../plugins/plugin.h"
#include "../gui-window.h"
#include "../gui-bar.h"
#include "../gui-buffer.h"
@@ -567,6 +569,9 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
buffer->num_displayed++;
gui_hotlist_remove_buffer (buffer);
+
+ hook_signal_send ("buffer_switch",
+ WEECHAT_HOOK_SIGNAL_POINTER, buffer);
}
/*
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index b70286cb5..f99191864 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -46,13 +46,7 @@ char *gui_bar_item_names[GUI_BAR_NUM_ITEMS] =
{ "buffer_count", "buffer_plugin", "buffer_name", "nicklist_count", "scroll",
"hotlist"
};
-struct t_hook *gui_bar_item_hook1 = NULL;
-struct t_hook *gui_bar_item_hook2 = NULL;
-struct t_hook *gui_bar_item_hook3 = NULL;
-struct t_hook *gui_bar_item_hook4 = NULL;
-struct t_hook *gui_bar_item_hook5 = NULL;
-struct t_hook *gui_bar_item_hook6 = NULL;
-struct t_hook *gui_bar_item_hook7 = NULL;
+struct t_gui_bar_item_hook *gui_bar_item_hooks = NULL;
/*
@@ -287,7 +281,7 @@ gui_bar_item_default_buffer_plugin (void *data, struct t_gui_bar_item *item,
(void) max_height;
if (!window)
- return NULL;
+ window = gui_current_window;
snprintf (buf, sizeof (buf), "%s[%s%s%s] ",
GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS),
@@ -316,7 +310,7 @@ gui_bar_item_default_buffer_name (void *data, struct t_gui_bar_item *item,
(void) max_height;
if (!window)
- return NULL;
+ window = gui_current_window;
snprintf (buf, sizeof (buf), "%s%d%s:%s%s%s/%s%s ",
GUI_COLOR(GUI_COLOR_STATUS_NUMBER),
@@ -349,7 +343,10 @@ gui_bar_item_default_nicklist_count (void *data, struct t_gui_bar_item *item,
(void) max_width;
(void) max_height;
- if (!window || !window->buffer->nicklist)
+ if (!window)
+ window = gui_current_window;
+
+ if (!window->buffer->nicklist)
return NULL;
snprintf (buf, sizeof (buf), "%s[%s%d%s] ",
@@ -378,7 +375,10 @@ gui_bar_item_default_scroll (void *data, struct t_gui_bar_item *item,
(void) max_width;
(void) max_height;
- if (!window || !window->scroll)
+ if (!window)
+ window = gui_current_window;
+
+ if (!window->scroll)
return NULL;
snprintf (buf, sizeof (buf), "%s%s ",
@@ -497,6 +497,25 @@ gui_bar_item_signal_cb (void *data, char *signal,
}
/*
+ * gui_bar_item_hook: hook a signal to update bar items
+ */
+
+void
+gui_bar_item_hook (char *signal, char *item)
+{
+ struct t_gui_bar_item_hook *bar_item_hook;
+
+ bar_item_hook = (struct t_gui_bar_item_hook *)malloc (sizeof (struct t_gui_bar_item_hook));
+ if (bar_item_hook)
+ {
+ bar_item_hook->hook = hook_signal (NULL, signal,
+ &gui_bar_item_signal_cb, item);
+ bar_item_hook->next_hook = gui_bar_item_hooks;
+ gui_bar_item_hooks = bar_item_hook;
+ }
+}
+
+/*
* gui_bar_item_init: init default items in WeeChat
*/
@@ -507,52 +526,51 @@ gui_bar_item_init ()
gui_bar_item_new (NULL,
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT],
&gui_bar_item_default_buffer_count, NULL);
- gui_bar_item_hook1 = hook_signal (NULL, "buffer_open",
- &gui_bar_item_signal_cb,
- gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT]);
- gui_bar_item_hook2 = hook_signal (NULL, "buffer_closed",
- &gui_bar_item_signal_cb,
- gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT]);
+ gui_bar_item_hook ("buffer_open",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT]);
+ gui_bar_item_hook ("buffer_closed",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT]);
/* buffer plugin */
gui_bar_item_new (NULL,
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_PLUGIN],
&gui_bar_item_default_buffer_plugin, NULL);
+ gui_bar_item_hook ("buffer_switch",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_PLUGIN]);
/* buffer name */
gui_bar_item_new (NULL,
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME],
&gui_bar_item_default_buffer_name, NULL);
- gui_bar_item_hook3 = hook_signal (NULL, "buffer_renamed",
- &gui_bar_item_signal_cb,
- gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]);
- gui_bar_item_hook4 = hook_signal (NULL, "buffer_moved",
- &gui_bar_item_signal_cb,
- gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]);
+ gui_bar_item_hook ("buffer_switch",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]);
+ gui_bar_item_hook ("buffer_renamed",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]);
+ gui_bar_item_hook ("buffer_moved",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]);
/* nicklist count */
gui_bar_item_new (NULL,
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT],
&gui_bar_item_default_nicklist_count, NULL);
- gui_bar_item_hook5 = hook_signal (NULL, "nicklist_changed",
- &gui_bar_item_signal_cb,
- gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT]);
+ gui_bar_item_hook ("buffer_switch",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT]);
+ gui_bar_item_hook ("nicklist_changed",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT]);
/* scroll indicator */
gui_bar_item_new (NULL,
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_SCROLL],
&gui_bar_item_default_scroll, NULL);
- gui_bar_item_hook6 = hook_signal (NULL, "window_scrolled",
- &gui_bar_item_signal_cb,
- gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_SCROLL]);
+ gui_bar_item_hook ("window_scrolled",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_SCROLL]);
/* hotlist */
gui_bar_item_new (NULL,
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_HOTLIST],
&gui_bar_item_default_hotlist, NULL);
- gui_bar_item_hook7 = hook_signal (NULL, "hotlist_changed",
- &gui_bar_item_signal_cb,
- gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_HOTLIST]);
+ gui_bar_item_hook ("hotlist_changed",
+ gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_HOTLIST]);
}
/*
@@ -562,14 +580,18 @@ gui_bar_item_init ()
void
gui_bar_item_end ()
{
+ struct t_gui_bar_item_hook *next_bar_item_hook;
+
/* remove hooks */
- unhook (gui_bar_item_hook1);
- unhook (gui_bar_item_hook2);
- unhook (gui_bar_item_hook3);
- unhook (gui_bar_item_hook4);
- unhook (gui_bar_item_hook5);
- unhook (gui_bar_item_hook6);
- unhook (gui_bar_item_hook7);
+ while (gui_bar_item_hooks)
+ {
+ next_bar_item_hook = gui_bar_item_hooks->next_hook;
+
+ unhook (gui_bar_item_hooks->hook);
+ free (gui_bar_item_hooks);
+
+ gui_bar_item_hooks = next_bar_item_hook;
+ }
/* remove bar items */
gui_bar_item_free_all ();
diff --git a/src/gui/gui-bar-item.h b/src/gui/gui-bar-item.h
index 78cc93681..d0f878557 100644
--- a/src/gui/gui-bar-item.h
+++ b/src/gui/gui-bar-item.h
@@ -48,6 +48,12 @@ struct t_gui_bar_item
struct t_gui_bar_item *next_item; /* link to next bar item */
};
+struct t_gui_bar_item_hook
+{
+ struct t_hook *hook; /* pointer to hook */
+ struct t_gui_bar_item_hook *next_hook; /* next hook */
+};
+
/* variables */
extern struct t_gui_bar_item *gui_bar_items;