Fixed bugs with bars size and refresh

This commit is contained in:
Sebastien Helleu 2008-03-15 10:49:42 +01:00
parent 08522770e8
commit fe8d679362
4 changed files with 78 additions and 45 deletions

View File

@ -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;
}

View File

@ -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);
}
/*

View File

@ -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 ",
@ -496,6 +496,25 @@ gui_bar_item_signal_cb (void *data, char *signal,
return WEECHAT_RC_OK;
}
/*
* 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 ();

View File

@ -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;