From 16e11ef25ea13eeb77d5ebaf6df83a06bfc09afc Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Thu, 24 Apr 2008 15:39:34 +0200 Subject: Fixed bug with bar auto-sizing in windows --- src/core/wee-command.c | 18 ++++---- src/gui/curses/gui-curses-bar.c | 79 ++++++++++++++++++++++++-------- src/gui/curses/gui-curses-main.c | 8 ++-- src/gui/curses/gui-curses.h | 1 + src/gui/gtk/gui-gtk-bar.c | 37 +++++++++++++++ src/gui/gtk/gui-gtk.h | 1 + src/gui/gui-bar.c | 99 +++++++++++++++------------------------- src/gui/gui-bar.h | 3 +- 8 files changed, 150 insertions(+), 96 deletions(-) (limited to 'src') diff --git a/src/core/wee-command.c b/src/core/wee-command.c index b1615fdf9..f54dd57cf 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -66,7 +66,7 @@ command_bar (void *data, struct t_gui_buffer *buffer, { int type, position; long number; - char *error, *str_type, *pos_condition; + char *error, *str_type, *pos_condition, str_size[16]; struct t_gui_bar *ptr_bar; struct t_gui_bar_item *ptr_item; @@ -85,9 +85,11 @@ command_bar (void *data, struct t_gui_buffer *buffer, for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { + snprintf (str_size, sizeof (str_size), + "%d", CONFIG_INTEGER(ptr_bar->size)); gui_chat_printf (NULL, _(" %3d. %s%s%s: %s (cond: %s), %s, filling: %s, " - "%s: %s%s%d%s"), + "%s: %s"), ptr_bar->number, GUI_COLOR(GUI_COLOR_CHAT_BUFFER), ptr_bar->name, @@ -101,10 +103,7 @@ command_bar (void *data, struct t_gui_buffer *buffer, ((CONFIG_INTEGER(ptr_bar->position) == GUI_BAR_POSITION_BOTTOM) || (CONFIG_INTEGER(ptr_bar->position) == GUI_BAR_POSITION_TOP)) ? _("height") : _("width"), - (CONFIG_INTEGER(ptr_bar->size) == 0) ? _("auto") : "", - (CONFIG_INTEGER(ptr_bar->size) == 0) ? " (" : "", - ptr_bar->current_size, - (CONFIG_INTEGER(ptr_bar->size) == 0) ? ")" : ""); + (CONFIG_INTEGER(ptr_bar->size) == 0) ? _("auto") : str_size); gui_chat_printf (NULL, _(" fg: %s, bg: %s, items: %s%s (plugin: " "%s)"), @@ -2510,8 +2509,8 @@ command_init () N_("manage bars"), N_("[add barname type[,cond1,cond2,...] position size " "separator item1,item2,...] | [del barname] | " - "[set barname name|number|condition|position|size|" - "separator|items value] | [list] | [listitems]"), + "[set barname name|number|condition|position|filling|" + "size|separator|items value] | [list] | [listitems]"), N_(" add: add a new bar\n" " barname: name of bar (must be unique)\n" " type: root: outside windows),\n" @@ -2524,6 +2523,7 @@ command_init () " nicklist: on windows with nicklist\n" " without condition, bar is always displayed\n" " position: bottom, top, left or right\n" + " filling: horizontal or vertical\n" " size: size of bar (in chars)\n" "separator: 1 for using separator (line), 0 or nothing " "means no separator\n" @@ -2533,7 +2533,7 @@ command_init () " list: list all bars\n" "listitems: list all bar items"), "add|del|set|list|listitems %r name|number|conditions|" - "position|size|separator|items", + "position|filling|size|separator|items", &command_bar, NULL); hook_command (NULL, "buffer", N_("manage buffers"), diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c index 5da3963cb..21207f7de 100644 --- a/src/gui/curses/gui-curses-bar.c +++ b/src/gui/curses/gui-curses-bar.c @@ -60,6 +60,43 @@ gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar) return NULL; } +/* + * gui_bar_window_get_current_size: get current size of bar window + * return width or height, depending on bar + * position + */ + +int +gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window) +{ + return bar_window->current_size; +} + +/* + * gui_bar_window_set_current_size: set current size of all bar windows for a bar + */ + +void +gui_bar_window_set_current_size (struct t_gui_bar *bar, int size) +{ + struct t_gui_window *ptr_win; + struct t_gui_bar_window *ptr_bar_win; + + if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT) + bar->bar_window->current_size = (size == 0) ? 1 : size; + else + { + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows; + ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window) + { + ptr_bar_win->current_size = (size == 0) ? 1 : size; + } + } + } +} + /* * gui_bar_window_get_size: get total bar size (window bars) for a position * bar is optional, if not NULL, size is computed @@ -186,26 +223,26 @@ 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->current_size + 1; + bar_window->y = y2 - add_bottom - bar_window->current_size + 1; bar_window->width = x2 - x1 + 1 - add_left - add_right; - bar_window->height = bar_window->bar->current_size; + bar_window->height = bar_window->current_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 - add_left - add_right; - bar_window->height = bar_window->bar->current_size; + bar_window->height = bar_window->current_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->current_size; + bar_window->width = bar_window->current_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->current_size + 1; + bar_window->x = x2 - add_right - bar_window->current_size + 1; bar_window->y = y1 + add_top; - bar_window->width = bar_window->bar->current_size; + bar_window->width = bar_window->current_size; bar_window->height = y2 - y1 + 1; break; case GUI_BAR_NUM_POSITIONS: @@ -356,6 +393,13 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window) new_bar_window->win_bar = NULL; new_bar_window->win_separator = NULL; + new_bar_window->x = 0; + new_bar_window->y = 0; + new_bar_window->width = 1; + new_bar_window->height = 1; + new_bar_window->current_size = (CONFIG_INTEGER(bar->size) == 0) ? + 1 : CONFIG_INTEGER(bar->size); + if (gui_init_ok) { gui_bar_window_calculate_pos_size (new_bar_window, window); @@ -363,13 +407,6 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window) if (window) window->refresh_needed = 1; } - else - { - new_bar_window->x = 0; - new_bar_window->y = 0; - new_bar_window->width = 1; - new_bar_window->height = 1; - } return 1; } @@ -726,7 +763,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, items = string_explode (content, "\n", 0, 0, &items_count); if (items_count == 0) { - gui_bar_set_current_size (bar_window->bar, 1); + gui_bar_window_set_current_size (bar_window->bar, 1); gui_bar_window_recreate_bar_windows (bar_window->bar); gui_window_clear (bar_window->win_bar, CONFIG_COLOR(bar_window->bar->color_bg)); @@ -761,18 +798,19 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, num_lines = optimal_number_of_lines; else num_lines = items_count; - if (bar_window->bar->current_size != num_lines) + if (bar_window->current_size != num_lines) { - gui_bar_set_current_size (bar_window->bar, num_lines); + gui_bar_window_set_current_size (bar_window->bar, + num_lines); gui_bar_window_recreate_bar_windows (bar_window->bar); } break; case GUI_BAR_POSITION_LEFT: case GUI_BAR_POSITION_RIGHT: - if (bar_window->bar->current_size != max_length) + if (bar_window->current_size != max_length) { - gui_bar_set_current_size (bar_window->bar, - max_length); + gui_bar_window_set_current_size (bar_window->bar, + max_length); gui_bar_window_recreate_bar_windows (bar_window->bar); } break; @@ -802,7 +840,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, } else { - gui_bar_set_current_size (bar_window->bar, 1); + gui_bar_window_set_current_size (bar_window->bar, 1); gui_bar_window_recreate_bar_windows (bar_window->bar); gui_window_clear (bar_window->win_bar, CONFIG_COLOR(bar_window->bar->color_bg)); @@ -954,6 +992,7 @@ gui_bar_window_print_log (struct t_gui_bar_window *bar_window) log_printf (" y . . . . . . . . : %d", bar_window->y); log_printf (" width . . . . . . : %d", bar_window->width); log_printf (" height. . . . . . : %d", bar_window->height); + log_printf (" current_size. . . : %d", bar_window->current_size); log_printf (" win_bar . . . . . : 0x%x", bar_window->win_bar); log_printf (" win_separator . . : 0x%x", bar_window->win_separator); log_printf (" prev_bar_window . : 0x%x", bar_window->prev_bar_window); diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index 915d6388f..ee60b7487 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -204,10 +204,6 @@ gui_main_loop () /* execute hook timers */ hook_timer_exec (); - /* refresh window if needed */ - if (gui_window_refresh_needed) - gui_window_refresh_screen (); - /* refresh status bar if needed */ if (gui_status_refresh_needed) gui_status_draw (1); @@ -245,6 +241,10 @@ gui_main_loop () gui_input_draw (ptr_buffer, 1); } + /* refresh window if needed */ + if (gui_window_refresh_needed) + gui_window_refresh_screen (); + /* wait for keyboard or network activity */ FD_ZERO (&read_fds); FD_ZERO (&write_fds); diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index 02c9d7987..4d8981fa2 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -44,6 +44,7 @@ struct t_gui_bar_window int x, y; /* position of window */ int width, height; /* window size */ WINDOW *win_bar; /* bar Curses window */ + int current_size; /* current size (width or height) */ WINDOW *win_separator; /* separator (optional) */ struct t_gui_bar_window *prev_bar_window; /* link to previous bar win */ /* (only for non-root bars) */ diff --git a/src/gui/gtk/gui-gtk-bar.c b/src/gui/gtk/gui-gtk-bar.c index 7425401a9..d4853d97d 100644 --- a/src/gui/gtk/gui-gtk-bar.c +++ b/src/gui/gtk/gui-gtk-bar.c @@ -55,6 +55,43 @@ gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar) return NULL; } +/* + * gui_bar_window_get_current_size: get current size of bar window + * return width or height, depending on bar + * position + */ + +int +gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window) +{ + return bar_window->current_size; +} + +/* + * gui_bar_window_set_current_size: set current size of all bar windows for a bar + */ + +void +gui_bar_window_set_current_size (struct t_gui_bar *bar, int size) +{ + struct t_gui_window *ptr_win; + struct t_gui_bar_window *ptr_bar_win; + + if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT) + bar->bar_window->current_size = (size == 0) ? 1 : size; + else + { + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + for (ptr_bar_win = GUI_GTK(ptr_win)->bar_windows; + ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window) + { + ptr_bar_win->current_size = (size == 0) ? 1 : size; + } + } + } +} + /* * gui_bar_window_get_size: get total bar size (window bars) for a position * bar is optional, if not NULL, size is computed diff --git a/src/gui/gtk/gui-gtk.h b/src/gui/gtk/gui-gtk.h index 6aaba6840..6b5a339a0 100644 --- a/src/gui/gtk/gui-gtk.h +++ b/src/gui/gtk/gui-gtk.h @@ -59,6 +59,7 @@ struct t_gui_bar_window struct t_gui_bar *bar; /* pointer to bar */ int x, y; /* position of window */ int width, height; /* window size */ + int current_size; /* current size (width or height) */ struct t_gui_bar_window *prev_bar_window; /* link to previous bar win */ /* (only for non-root bars) */ struct t_gui_bar_window *next_bar_window; /* link to next bar win */ diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index e0873bfb1..bb46535f9 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -172,7 +172,7 @@ gui_bar_root_get_size (struct t_gui_bar *bar, enum t_gui_bar_position position) if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT) && (CONFIG_INTEGER(ptr_bar->position) == (int)position)) { - total_size += ptr_bar->current_size; + total_size += gui_bar_window_get_current_size (ptr_bar->bar_window); if (CONFIG_INTEGER(ptr_bar->separator)) total_size++; } @@ -342,6 +342,8 @@ gui_bar_config_change_position (void *data, struct t_config_option *option) ptr_bar = gui_bar_search_with_option_name (option->name); if (ptr_bar) gui_bar_refresh (ptr_bar); + + gui_window_refresh_needed = 1; } /* @@ -355,10 +357,12 @@ gui_bar_config_change_filling (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; - + ptr_bar = gui_bar_search_with_option_name (option->name); if (ptr_bar) gui_bar_refresh (ptr_bar); + + gui_window_refresh_needed = 1; } /* @@ -386,10 +390,16 @@ gui_bar_config_check_size (void *data, struct t_config_option *option, if (number < 0) return 0; - if (number <= ptr_bar->current_size - || gui_bar_check_size_add (ptr_bar, - number - ptr_bar->current_size)) - return 1; + if ((number != 0) && + ((CONFIG_INTEGER(ptr_bar->size) == 0) + || (number > CONFIG_INTEGER(ptr_bar->size)))) + { + if (!gui_bar_check_size_add (ptr_bar, + number - CONFIG_INTEGER(ptr_bar->size))) + return 0; + } + + return 1; } } @@ -407,13 +417,13 @@ gui_bar_config_change_size (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; - + ptr_bar = gui_bar_search_with_option_name (option->name); if (ptr_bar) { - ptr_bar->current_size = (CONFIG_INTEGER(ptr_bar->size) == 0) ? - 1 : CONFIG_INTEGER(ptr_bar->size); - gui_bar_refresh (ptr_bar); + gui_bar_window_set_current_size (ptr_bar, + CONFIG_INTEGER(ptr_bar->size_max)); + gui_window_refresh_needed = 1; } } @@ -424,22 +434,11 @@ gui_bar_config_change_size (void *data, struct t_config_option *option) void gui_bar_config_change_size_max (void *data, struct t_config_option *option) { - struct t_gui_bar *ptr_bar; - /* make C compiler happy */ (void) data; + (void) option; - ptr_bar = gui_bar_search_with_option_name (option->name); - if (ptr_bar) - { - if ((CONFIG_INTEGER(ptr_bar->size_max) > 0) - && (ptr_bar->current_size > CONFIG_INTEGER(ptr_bar->size_max))) - { - gui_bar_set_current_size (ptr_bar, - CONFIG_INTEGER(ptr_bar->size_max)); - } - gui_window_refresh_needed = 1; - } + gui_window_refresh_needed = 1; } /* @@ -663,31 +662,6 @@ gui_bar_set_position (struct t_gui_bar *bar, char *position) } } -/* - * gui_bar_set_current_size: set current size for a bar - */ - -void -gui_bar_set_current_size (struct t_gui_bar *bar, int current_size) -{ - if (current_size < 0) - return; - - if (current_size == 0) - current_size = 1; - - if ((CONFIG_INTEGER(bar->size_max) > 0) - && (current_size > CONFIG_INTEGER(bar->size_max))) - current_size = CONFIG_INTEGER(bar->size_max); - - /* check if new size is ok if it's more than before */ - if (current_size > bar->current_size - && !gui_bar_check_size_add (bar, current_size - bar->current_size)) - return; - - bar->current_size = current_size; -} - /* * gui_bar_set_size: set size for a bar */ @@ -708,23 +682,28 @@ gui_bar_set_size (struct t_gui_bar *bar, char *size) { new_size = number; if (size[0] == '+') - new_size = bar->current_size + new_size; + new_size = CONFIG_INTEGER(bar->size) + new_size; else if (value[0] == '-') - new_size = bar->current_size - new_size; + new_size = CONFIG_INTEGER(bar->size) - new_size; if ((size[0] == '-') && (new_size < 1)) return; if (new_size < 0) return; /* check if new size is ok if it's more than before */ - if (new_size > bar->current_size - && !gui_bar_check_size_add (bar, new_size - bar->current_size)) - return; + if ((new_size != 0) && + ((CONFIG_INTEGER(bar->size) == 0) + || (new_size > CONFIG_INTEGER(bar->size)))) + { + if (!gui_bar_check_size_add (bar, + new_size - CONFIG_INTEGER(bar->size))) + return; + } snprintf (value, sizeof (value), "%d", new_size); config_file_option_set (bar->size, value, 1); - - bar->current_size = (new_size == 0) ? 1 : new_size; + + gui_bar_window_set_current_size (bar, new_size); } } @@ -748,7 +727,9 @@ gui_bar_set_size_max (struct t_gui_bar *bar, char *size) snprintf (value, sizeof (value), "%ld", number); config_file_option_set (bar->size_max, value, 1); - if ((number > 0) && (number < bar->current_size)) + if ((number > 0) && + ((CONFIG_INTEGER(bar->size) == 0) + || (number < CONFIG_INTEGER(bar->size)))) gui_bar_set_size (bar, value); } } @@ -792,13 +773,11 @@ gui_bar_set (struct t_gui_bar *bar, char *property, char *value) else if (string_strcasecmp (property, "position") == 0) { gui_bar_set_position (bar, value); - gui_bar_refresh (bar); return 1; } else if (string_strcasecmp (property, "filling") == 0) { config_file_option_set (bar->filling, value, 1); - gui_bar_refresh (bar); return 1; } else if (string_strcasecmp (property, "size") == 0) @@ -868,7 +847,6 @@ gui_bar_alloc (char *name) new_bar->color_bg = NULL; new_bar->separator = NULL; new_bar->items = NULL; - new_bar->current_size = 1; new_bar->conditions_count = 0; new_bar->conditions_array = NULL; new_bar->items_count = 0; @@ -1043,8 +1021,6 @@ gui_bar_new_with_options (struct t_weechat_plugin *plugin, char *name, new_bar->position = position; new_bar->filling = filling; new_bar->size = size; - new_bar->current_size = (CONFIG_INTEGER(size) == 0) ? - 1 : CONFIG_INTEGER(size); new_bar->size_max = size_max; new_bar->color_fg = color_fg; new_bar->color_bg = color_bg; @@ -1472,7 +1448,6 @@ gui_bar_print_log () log_printf (" color_bg . . . . . . . : %d", CONFIG_COLOR(ptr_bar->color_bg), gui_color_get_name (CONFIG_COLOR(ptr_bar->color_bg))); - log_printf (" current_size . . . . . : %d", ptr_bar->current_size); log_printf (" separator. . . . . . . : %d", CONFIG_INTEGER(ptr_bar->separator)); log_printf (" items. . . . . . . . . : '%s'", CONFIG_STRING(ptr_bar->items)); log_printf (" items_count. . . . . . : %d", ptr_bar->items_count); diff --git a/src/gui/gui-bar.h b/src/gui/gui-bar.h index c1621544e..32b91cc63 100644 --- a/src/gui/gui-bar.h +++ b/src/gui/gui-bar.h @@ -83,7 +83,6 @@ struct t_gui_bar struct t_config_option *items; /* bar items */ /* internal vars */ - int current_size; /* current bar size (strictly > 0) */ int conditions_count; /* number of conditions */ char **conditions_array; /* exploded bar conditions */ int items_count; /* number of bar items */ @@ -137,6 +136,8 @@ extern void gui_bar_print_log (); extern struct t_gui_bar_window *gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar); +extern int gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window); +extern void gui_bar_window_set_current_size (struct t_gui_bar *bar, int size); extern int gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window, enum t_gui_bar_position position); -- cgit v1.2.3