diff --git a/ChangeLog b/ChangeLog index 85fe15e13..c2b69f69a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,13 @@ WeeChat ChangeLog ================= Sébastien Helleu -v0.3.8-dev, 2012-04-08 +v0.3.8-dev, 2012-04-11 Version 0.3.8 (under dev!) -------------------------- +* core: fix display bugs and crashs with small windows (bug #36107) * core: convert options weechat.look.prefix_align_more and weechat.look.prefix_buffer_align_more from boolean to string (task #11197) * core: fix display bug with prefix when length is greater than max and prefix diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 3a1ed8641..340da2a86 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -264,7 +264,7 @@ config_change_save_config_on_exit (void *data, struct t_config_option *option) (void) data; (void) option; - if (gui_ok && !CONFIG_BOOLEAN(config_look_save_config_on_exit)) + if (gui_init_ok && !CONFIG_BOOLEAN(config_look_save_config_on_exit)) { gui_chat_printf (NULL, _("Warning: you should now issue /save to write " @@ -313,7 +313,7 @@ config_change_buffer_content (void *data, struct t_config_option *option) (void) data; (void) option; - if (gui_ok) + if (gui_init_ok) gui_current_window->refresh_needed = 1; } @@ -328,7 +328,7 @@ config_change_mouse (void *data, struct t_config_option *option) (void) data; (void) option; - if (gui_ok) + if (gui_init_ok) { if (CONFIG_BOOLEAN(config_look_mouse)) gui_mouse_enable (); @@ -364,7 +364,7 @@ config_change_buffer_time_format (void *data, struct t_config_option *option) gui_chat_time_length = gui_chat_get_time_length (); gui_chat_change_time_format (); - if (gui_ok) + if (gui_init_ok) gui_window_ask_refresh (1); } @@ -417,7 +417,7 @@ config_change_eat_newline_glitch (void *data, struct t_config_option *option) (void) data; (void) option; - if (gui_ok) + if (gui_init_ok) { if (CONFIG_BOOLEAN(config_look_eat_newline_glitch)) { @@ -518,7 +518,7 @@ config_change_paste_bracketed (void *data, struct t_config_option *option) (void) data; (void) option; - if (gui_ok) + if (gui_init_ok) gui_window_set_bracketed_paste_mode (CONFIG_BOOLEAN(config_look_paste_bracketed)); } @@ -609,7 +609,7 @@ config_change_color (void *data, struct t_config_option *option) (void) data; (void) option; - if (gui_ok) + if (gui_init_ok) { gui_color_init_weechat (); gui_window_ask_refresh (1); diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c index 5234fbd69..f974a66bc 100644 --- a/src/gui/curses/gui-curses-bar-window.c +++ b/src/gui/curses/gui-curses-bar-window.c @@ -104,41 +104,40 @@ gui_bar_window_create_win (struct t_gui_bar_window *bar_window) GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = NULL; } - GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar = newwin (bar_window->height, - bar_window->width, - bar_window->y, - bar_window->x); - - if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SEPARATOR])) + if ((bar_window->x >= 0) && (bar_window->y >= 0)) { - switch (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_POSITION])) + GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar = newwin (bar_window->height, + bar_window->width, + bar_window->y, + bar_window->x); + + if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SEPARATOR])) { - case GUI_BAR_POSITION_BOTTOM: - GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = newwin (1, - bar_window->width, - bar_window->y - 1, - bar_window->x); - break; - case GUI_BAR_POSITION_TOP: - GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = newwin (1, - bar_window->width, - bar_window->y + bar_window->height, - bar_window->x); - break; - case GUI_BAR_POSITION_LEFT: - GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = newwin (bar_window->height, - 1, - bar_window->y, - bar_window->x + bar_window->width); - break; - case GUI_BAR_POSITION_RIGHT: - GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = newwin (bar_window->height, - 1, - bar_window->y, - bar_window->x - 1); - break; - case GUI_BAR_NUM_POSITIONS: - break; + switch (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_POSITION])) + { + case GUI_BAR_POSITION_BOTTOM: + GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = + newwin (1, bar_window->width, + bar_window->y - 1, bar_window->x); + break; + case GUI_BAR_POSITION_TOP: + GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = + newwin (1, bar_window->width, + bar_window->y + bar_window->height, bar_window->x); + break; + case GUI_BAR_POSITION_LEFT: + GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = + newwin (bar_window->height, 1, + bar_window->y, bar_window->x + bar_window->width); + break; + case GUI_BAR_POSITION_RIGHT: + GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = + newwin (bar_window->height, 1, + bar_window->y, bar_window->x - 1); + break; + case GUI_BAR_NUM_POSITIONS: + break; + } } } } @@ -403,6 +402,9 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, if (!gui_init_ok) return; + if ((bar_window->x < 0) || (bar_window->y < 0)) + return; + if (!str_start_input[0]) { snprintf (str_start_input, sizeof (str_start_input), "%c%c%c", diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 2e6f88d7d..09f426830 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -1300,25 +1300,171 @@ gui_chat_calculate_line_diff (struct t_gui_window *window, } } +/* + * gui_chat_draw_formatted_buffer: draw chat window for a formatted buffer + */ + +void +gui_chat_draw_formatted_buffer (struct t_gui_window *window) +{ + struct t_gui_line *ptr_line; + int line_pos, count, old_scrolling, old_lines_after; + + /* display at position of scrolling */ + if (window->scroll->start_line) + { + ptr_line = window->scroll->start_line; + line_pos = window->scroll->start_line_pos; + } + else + { + /* look for first line to display, starting from last line */ + ptr_line = NULL; + line_pos = 0; + gui_chat_calculate_line_diff (window, &ptr_line, &line_pos, + (-1) * (window->win_chat_height - 1)); + } + + count = 0; + + if (line_pos > 0) + { + /* display end of first line at top of screen */ + count = gui_chat_display_line (window, ptr_line, + gui_chat_display_line (window, + ptr_line, + 0, 1) - + line_pos, 0); + ptr_line = gui_line_get_next_displayed (ptr_line); + window->scroll->first_line_displayed = 0; + } + else + window->scroll->first_line_displayed = + (ptr_line == gui_line_get_first_displayed (window->buffer)); + + /* display lines */ + while (ptr_line && (window->win_chat_cursor_y <= window->win_chat_height - 1)) + { + count = gui_chat_display_line (window, ptr_line, 0, 0); + ptr_line = gui_line_get_next_displayed (ptr_line); + } + + old_scrolling = window->scroll->scrolling; + old_lines_after = window->scroll->lines_after; + + window->scroll->scrolling = (window->win_chat_cursor_y > window->win_chat_height - 1); + + /* check if last line of buffer is entirely displayed and scrolling */ + /* if so, disable scroll indicator */ + if (!ptr_line && window->scroll->scrolling) + { + if ((count == gui_chat_display_line (window, gui_line_get_last_displayed (window->buffer), 0, 1)) + || (count == window->win_chat_height)) + window->scroll->scrolling = 0; + } + + if (!window->scroll->scrolling + && (window->scroll->start_line == gui_line_get_first_displayed (window->buffer))) + { + window->scroll->start_line = NULL; + window->scroll->start_line_pos = 0; + } + + window->scroll->lines_after = 0; + if (window->scroll->scrolling && ptr_line) + { + /* count number of lines after last line displayed */ + while (ptr_line) + { + ptr_line = gui_line_get_next_displayed (ptr_line); + if (ptr_line) + window->scroll->lines_after++; + } + window->scroll->lines_after++; + } + + if ((window->scroll->scrolling != old_scrolling) + || (window->scroll->lines_after != old_lines_after)) + { + hook_signal_send ("window_scrolled", + WEECHAT_HOOK_SIGNAL_POINTER, window); + } + + if (!window->scroll->scrolling + && window->scroll->reset_allowed) + { + window->scroll->start_line = NULL; + window->scroll->start_line_pos = 0; + } + + /* cursor is below end line of chat window? */ + if (window->win_chat_cursor_y > window->win_chat_height - 1) + { + window->win_chat_cursor_x = 0; + window->win_chat_cursor_y = window->win_chat_height - 1; + } + + window->scroll->reset_allowed = 0; +} + +/* + *gui_chat_draw_free_buffer: draw chat window for a free buffer + */ + +void +gui_chat_draw_free_buffer (struct t_gui_window *window, int clear_chat) +{ + struct t_gui_line *ptr_line; + int y_start, y_end, y; + + ptr_line = (window->scroll->start_line) ? + window->scroll->start_line : window->buffer->lines->first_line; + if (ptr_line) + { + if (!ptr_line->data->displayed) + ptr_line = gui_line_get_next_displayed (ptr_line); + if (ptr_line) + { + y_start = (window->scroll->start_line) ? ptr_line->data->y : 0; + y_end = y_start + window->win_chat_height - 1; + while (ptr_line && (ptr_line->data->y <= y_end)) + { + y = ptr_line->data->y - y_start; + if (y < window->coords_size) + { + window->coords[y].line = ptr_line; + window->coords[y].data = ptr_line->data->message; + } + if (ptr_line->data->refresh_needed || clear_chat) + { + gui_chat_display_line_y (window, ptr_line, + y); + } + ptr_line = gui_line_get_next_displayed (ptr_line); + } + } + } +} + /* * gui_chat_draw: draw chat window for a buffer */ void -gui_chat_draw (struct t_gui_buffer *buffer, int erase) +gui_chat_draw (struct t_gui_buffer *buffer, int clear_chat) { struct t_gui_window *ptr_win; struct t_gui_line *ptr_line; char format_empty[32]; - int i, line_pos, count, old_scrolling, old_lines_after; - int y_start, y_end, y; + int i; - if (!gui_ok) + if (!gui_init_ok) return; for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { - if (ptr_win->buffer->number == buffer->number) + if ((ptr_win->buffer->number == buffer->number) + && (ptr_win->win_chat_x >= 0) && (ptr_win->win_chat_y >= 0)) { gui_window_coords_alloc (ptr_win); @@ -1327,7 +1473,7 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase) GUI_COLOR_CHAT_INACTIVE_BUFFER, GUI_COLOR_CHAT); - if (erase) + if (clear_chat) { snprintf (format_empty, 32, "%%-%ds", ptr_win->win_chat_width); for (i = 0; i < ptr_win->win_chat_height; i++) @@ -1343,132 +1489,14 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase) switch (ptr_win->buffer->type) { case GUI_BUFFER_TYPE_FORMATTED: - /* display at position of scrolling */ - if (ptr_win->scroll->start_line) - { - ptr_line = ptr_win->scroll->start_line; - line_pos = ptr_win->scroll->start_line_pos; - } + /* min 2 lines for chat area */ + if (ptr_win->win_chat_height < 2) + mvwprintw (GUI_WINDOW_OBJECTS(ptr_win)->win_chat, 0, 0, "..."); else - { - /* look for first line to display, starting from last line */ - ptr_line = NULL; - line_pos = 0; - gui_chat_calculate_line_diff (ptr_win, &ptr_line, &line_pos, - (-1) * (ptr_win->win_chat_height - 1)); - } - - count = 0; - - if (line_pos > 0) - { - /* display end of first line at top of screen */ - count = gui_chat_display_line (ptr_win, ptr_line, - gui_chat_display_line (ptr_win, - ptr_line, - 0, 1) - - line_pos, 0); - ptr_line = gui_line_get_next_displayed (ptr_line); - ptr_win->scroll->first_line_displayed = 0; - } - else - ptr_win->scroll->first_line_displayed = - (ptr_line == gui_line_get_first_displayed (ptr_win->buffer)); - - /* display lines */ - while (ptr_line && (ptr_win->win_chat_cursor_y <= ptr_win->win_chat_height - 1)) - { - count = gui_chat_display_line (ptr_win, ptr_line, 0, 0); - ptr_line = gui_line_get_next_displayed (ptr_line); - } - - old_scrolling = ptr_win->scroll->scrolling; - old_lines_after = ptr_win->scroll->lines_after; - - ptr_win->scroll->scrolling = (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1); - - /* check if last line of buffer is entirely displayed and scrolling */ - /* if so, disable scroll indicator */ - if (!ptr_line && ptr_win->scroll->scrolling) - { - if ((count == gui_chat_display_line (ptr_win, gui_line_get_last_displayed (ptr_win->buffer), 0, 1)) - || (count == ptr_win->win_chat_height)) - ptr_win->scroll->scrolling = 0; - } - - if (!ptr_win->scroll->scrolling - && (ptr_win->scroll->start_line == gui_line_get_first_displayed (ptr_win->buffer))) - { - ptr_win->scroll->start_line = NULL; - ptr_win->scroll->start_line_pos = 0; - } - - ptr_win->scroll->lines_after = 0; - if (ptr_win->scroll->scrolling && ptr_line) - { - /* count number of lines after last line displayed */ - while (ptr_line) - { - ptr_line = gui_line_get_next_displayed (ptr_line); - if (ptr_line) - ptr_win->scroll->lines_after++; - } - ptr_win->scroll->lines_after++; - } - - if ((ptr_win->scroll->scrolling != old_scrolling) - || (ptr_win->scroll->lines_after != old_lines_after)) - { - hook_signal_send ("window_scrolled", - WEECHAT_HOOK_SIGNAL_POINTER, ptr_win); - } - - if (!ptr_win->scroll->scrolling - && ptr_win->scroll->reset_allowed) - { - ptr_win->scroll->start_line = NULL; - ptr_win->scroll->start_line_pos = 0; - } - - /* cursor is below end line of chat window? */ - if (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1) - { - ptr_win->win_chat_cursor_x = 0; - ptr_win->win_chat_cursor_y = ptr_win->win_chat_height - 1; - } - - ptr_win->scroll->reset_allowed = 0; - + gui_chat_draw_formatted_buffer (ptr_win); break; case GUI_BUFFER_TYPE_FREE: - /* display at position of scrolling */ - ptr_line = (ptr_win->scroll->start_line) ? - ptr_win->scroll->start_line : buffer->lines->first_line; - if (ptr_line) - { - if (!ptr_line->data->displayed) - ptr_line = gui_line_get_next_displayed (ptr_line); - if (ptr_line) - { - y_start = (ptr_win->scroll->start_line) ? ptr_line->data->y : 0; - y_end = y_start + ptr_win->win_chat_height - 1; - while (ptr_line && (ptr_line->data->y <= y_end)) - { - y = ptr_line->data->y - y_start; - if (y < ptr_win->coords_size) - { - ptr_win->coords[y].line = ptr_line; - ptr_win->coords[y].data = ptr_line->data->message; - } - if (ptr_line->data->refresh_needed || erase) - { - gui_chat_display_line_y (ptr_win, ptr_line, - y); - } - ptr_line = gui_line_get_next_displayed (ptr_line); - } - } - } + gui_chat_draw_free_buffer (ptr_win, clear_chat); break; case GUI_BUFFER_NUM_TYPES: break; @@ -1490,18 +1518,3 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase) buffer->chat_refresh_needed = 0; } - -/* - * gui_chat_draw_line: add a line to chat window for a buffer - */ - -void -gui_chat_draw_line (struct t_gui_buffer *buffer, struct t_gui_line *line) -{ - /* - * This function does nothing in Curses GUI, - * line will be displayed by gui_buffer_draw_chat() - */ - (void) buffer; - (void) line; -} diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index c45026d2a..d86335bc6 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -437,7 +437,6 @@ gui_main_end (int clean_exit) gui_buffer_close (gui_buffers); } - gui_ok = 0; gui_init_ok = 0; /* delete global history */ diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 6266261f6..5569e058e 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -106,9 +106,6 @@ gui_window_read_terminal_size () gui_term_cols = new_width; gui_term_lines = new_height; } - - gui_ok = ((gui_term_cols >= GUI_WINDOW_MIN_WIDTH) - && (gui_term_lines >= GUI_WINDOW_MIN_HEIGHT)); } /* @@ -157,7 +154,7 @@ gui_window_objects_free (struct t_gui_window *window, int free_separator) void gui_window_clear_weechat (WINDOW *window, int weechat_color) { - if (!gui_ok) + if (!gui_init_ok) return; wbkgdset (window, ' ' | COLOR_PAIR (gui_color_weechat_get_pair (weechat_color))); @@ -172,7 +169,7 @@ gui_window_clear_weechat (WINDOW *window, int weechat_color) void gui_window_clear (WINDOW *window, int fg, int bg) { - if (!gui_ok) + if (!gui_init_ok) return; if ((fg > 0) && (fg & GUI_COLOR_EXTENDED_FLAG)) @@ -932,13 +929,6 @@ gui_window_calculate_pos_size (struct t_gui_window *window) struct t_gui_bar_window *ptr_bar_win; int add_top, add_bottom, add_left, add_right; - if ((window->win_width < GUI_WINDOW_MIN_WIDTH) - || (window->win_height < GUI_WINDOW_MIN_HEIGHT)) - { - gui_ok = 0; - return; - } - for (ptr_bar_win = window->bar_windows; ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window) { @@ -957,8 +947,17 @@ gui_window_calculate_pos_size (struct t_gui_window *window) window->win_chat_cursor_x = window->win_x + add_left; window->win_chat_cursor_y = window->win_y + add_top; - if ((window->win_chat_width <= 1) || (window->win_chat_height <= 0)) - gui_ok = 0; + /* chat area too small? (not enough space left) */ + if ((window->win_chat_width < 1) || (window->win_chat_height < 1)) + { + /* invalidate the chat area, it will not be displayed */ + window->win_chat_x = -1; + window->win_chat_y = -1; + window->win_chat_width = 0; + window->win_chat_height = 0; + window->win_chat_cursor_x = 0; + window->win_chat_cursor_y = 0; + } } /* @@ -1005,7 +1004,7 @@ gui_window_draw_separator (struct t_gui_window *window) void gui_window_redraw_buffer (struct t_gui_buffer *buffer) { - if (!gui_ok) + if (!gui_init_ok) return; gui_chat_draw (buffer, 1); @@ -1020,7 +1019,7 @@ gui_window_redraw_all_buffers () { struct t_gui_buffer *ptr_buffer; - if (!gui_ok) + if (!gui_init_ok) return; for (ptr_buffer = gui_buffers; ptr_buffer; @@ -1042,7 +1041,7 @@ gui_window_switch_to_buffer (struct t_gui_window *window, struct t_gui_bar_window *ptr_bar_window; struct t_gui_buffer *old_buffer; - if (!gui_ok) + if (!gui_init_ok) return; gui_buffer_add_value_num_displayed (window->buffer, -1); @@ -1087,35 +1086,38 @@ gui_window_switch_to_buffer (struct t_gui_window *window, if (!weechat_upgrading && (old_buffer != buffer)) gui_hotlist_remove_buffer (buffer); - if (gui_ok) + gui_bar_window_remove_unused_bars (window); + gui_bar_window_add_missing_bars (window); + + /* create bar windows */ + for (ptr_bar_window = window->bar_windows; ptr_bar_window; + ptr_bar_window = ptr_bar_window->next_bar_window) { - gui_bar_window_remove_unused_bars (window); - gui_bar_window_add_missing_bars (window); + gui_bar_window_content_build (ptr_bar_window, window); + gui_bar_window_calculate_pos_size (ptr_bar_window, window); + gui_bar_window_create_win (ptr_bar_window); + } - /* create bar windows */ - for (ptr_bar_window = window->bar_windows; ptr_bar_window; - ptr_bar_window = ptr_bar_window->next_bar_window) - { - gui_bar_window_content_build (ptr_bar_window, window); - gui_bar_window_calculate_pos_size (ptr_bar_window, window); - gui_bar_window_create_win (ptr_bar_window); - } + gui_window_calculate_pos_size (window); - gui_window_calculate_pos_size (window); + /* destroy Curses windows */ + gui_window_objects_free (window, 0); - /* destroy Curses windows */ - gui_window_objects_free (window, 0); - - /* create Curses windows */ - if (GUI_WINDOW_OBJECTS(window)->win_chat) - delwin (GUI_WINDOW_OBJECTS(window)->win_chat); + /* create Curses windows */ + if (GUI_WINDOW_OBJECTS(window)->win_chat) + { + delwin (GUI_WINDOW_OBJECTS(window)->win_chat); + GUI_WINDOW_OBJECTS(window)->win_chat = NULL; + } + if ((window->win_chat_x >= 0) && (window->win_chat_y >= 0)) + { GUI_WINDOW_OBJECTS(window)->win_chat = newwin (window->win_chat_height, window->win_chat_width, window->win_chat_y, window->win_chat_x); - gui_window_draw_separator (window); - gui_buffer_ask_chat_refresh (window->buffer, 2); } + gui_window_draw_separator (window); + gui_buffer_ask_chat_refresh (window->buffer, 2); if (window->buffer->type == GUI_BUFFER_TYPE_FREE) { @@ -1193,7 +1195,7 @@ gui_window_page_up (struct t_gui_window *window) char scroll[32]; int num_lines; - if (!gui_ok) + if (!gui_init_ok) return; num_lines = ((window->win_chat_height - 1) * @@ -1243,7 +1245,7 @@ gui_window_page_down (struct t_gui_window *window) int line_pos, num_lines; char scroll[32]; - if (!gui_ok) + if (!gui_init_ok) return; num_lines = ((window->win_chat_height - 1) * @@ -1298,7 +1300,7 @@ gui_window_scroll_up (struct t_gui_window *window) { char scroll[32]; - if (!gui_ok) + if (!gui_init_ok) return; switch (window->buffer->type) @@ -1342,7 +1344,7 @@ gui_window_scroll_down (struct t_gui_window *window) int line_pos; char scroll[32]; - if (!gui_ok) + if (!gui_init_ok) return; switch (window->buffer->type) @@ -1389,7 +1391,7 @@ gui_window_scroll_down (struct t_gui_window *window) void gui_window_scroll_top (struct t_gui_window *window) { - if (!gui_ok) + if (!gui_init_ok) return; switch (window->buffer->type) @@ -1426,7 +1428,7 @@ gui_window_scroll_bottom (struct t_gui_window *window) { char scroll[32]; - if (!gui_ok) + if (!gui_init_ok) return; switch (window->buffer->type) @@ -1475,14 +1477,14 @@ gui_window_auto_resize (struct t_gui_window_tree *tree, int size1, size2; struct t_gui_window_tree *parent; - if (!gui_ok) + if (!gui_init_ok) return 0; if (tree) { if (tree->window) { - if ((width < GUI_WINDOW_MIN_WIDTH) || (height < GUI_WINDOW_MIN_HEIGHT)) + if ((width < 1) || (height < 2)) return -1; if (!simulate) { @@ -1549,7 +1551,7 @@ gui_window_refresh_windows () struct t_gui_bar *ptr_bar; int add_bottom, add_top, add_left, add_right; - if (!gui_ok) + if (!gui_init_ok) return; old_current_window = gui_current_window; @@ -1608,7 +1610,7 @@ gui_window_split_horizontal (struct t_gui_window *window, int percentage) struct t_gui_window *new_window; int height1, height2; - if (!gui_ok) + if (!gui_init_ok) return NULL; new_window = NULL; @@ -1616,7 +1618,7 @@ gui_window_split_horizontal (struct t_gui_window *window, int percentage) height1 = (window->win_height * percentage) / 100; height2 = window->win_height - height1; - if ((height1 >= GUI_WINDOW_MIN_HEIGHT) && (height2 >= GUI_WINDOW_MIN_HEIGHT) + if ((height1 >= 2) && (height2 >= 2) && (percentage > 0) && (percentage < 100)) { new_window = gui_window_new (window, window->buffer, @@ -1653,7 +1655,7 @@ gui_window_split_vertical (struct t_gui_window *window, int percentage) struct t_gui_window *new_window; int width1, width2; - if (!gui_ok) + if (!gui_init_ok) return NULL; new_window = NULL; @@ -1661,7 +1663,7 @@ gui_window_split_vertical (struct t_gui_window *window, int percentage) width1 = (window->win_width * percentage) / 100; width2 = window->win_width - width1 - 1; - if ((width1 >= GUI_WINDOW_MIN_WIDTH) && (width2 >= GUI_WINDOW_MIN_WIDTH) + if ((width1 >= 1) && (width2 >= 1) && (percentage > 0) && (percentage < 100)) { new_window = gui_window_new (window, window->buffer, @@ -1700,7 +1702,7 @@ gui_window_resize (struct t_gui_window *window, int percentage) struct t_gui_window_tree *parent; int old_split_pct, add_bottom, add_top, add_left, add_right; - if (!gui_ok) + if (!gui_init_ok) return; parent = window->ptr_tree->parent_node; @@ -1742,7 +1744,7 @@ gui_window_resize_delta (struct t_gui_window *window, int delta_percentage) struct t_gui_window_tree *parent; int old_split_pct, add_bottom, add_top, add_left, add_right; - if (!gui_ok) + if (!gui_init_ok) return; parent = window->ptr_tree->parent_node; @@ -1787,7 +1789,7 @@ gui_window_merge (struct t_gui_window *window) { struct t_gui_window_tree *parent, *sister; - if (!gui_ok) + if (!gui_init_ok) return 0; parent = window->ptr_tree->parent_node; @@ -1834,7 +1836,7 @@ gui_window_merge_all (struct t_gui_window *window) { int num_deleted, add_bottom, add_top, add_left, add_right; - if (!gui_ok) + if (!gui_init_ok) return; num_deleted = 0; @@ -1879,7 +1881,7 @@ gui_window_merge_all (struct t_gui_window *window) int gui_window_side_by_side (struct t_gui_window *win1, struct t_gui_window *win2) { - if (!gui_ok) + if (!gui_init_ok) return 0; /* win2 over win1 ? */ @@ -1934,7 +1936,7 @@ gui_window_switch_up (struct t_gui_window *window) { struct t_gui_window *ptr_win; - if (!gui_ok) + if (!gui_init_ok) return; for (ptr_win = gui_windows; ptr_win; @@ -1958,7 +1960,7 @@ gui_window_switch_down (struct t_gui_window *window) { struct t_gui_window *ptr_win; - if (!gui_ok) + if (!gui_init_ok) return; for (ptr_win = gui_windows; ptr_win; @@ -1982,7 +1984,7 @@ gui_window_switch_left (struct t_gui_window *window) { struct t_gui_window *ptr_win; - if (!gui_ok) + if (!gui_init_ok) return; for (ptr_win = gui_windows; ptr_win; @@ -2006,7 +2008,7 @@ gui_window_switch_right (struct t_gui_window *window) { struct t_gui_window *ptr_win; - if (!gui_ok) + if (!gui_init_ok) return; for (ptr_win = gui_windows; ptr_win; @@ -2102,7 +2104,7 @@ gui_window_swap (struct t_gui_window *window, int direction) struct t_gui_window *window2, *ptr_win; struct t_gui_buffer *buffer1; - if (!window || !gui_ok) + if (!window || !gui_init_ok) return; window2 = NULL; diff --git a/src/gui/gtk/gui-gtk-chat.c b/src/gui/gtk/gui-gtk-chat.c index 539534f0f..e368b69cf 100644 --- a/src/gui/gtk/gui-gtk-chat.c +++ b/src/gui/gtk/gui-gtk-chat.c @@ -352,7 +352,7 @@ gui_chat_calculate_line_diff (struct t_gui_window *window, struct t_gui_line **l */ void -gui_chat_draw (struct t_gui_buffer *buffer, int erase) +gui_chat_draw (struct t_gui_buffer *buffer, int clear_chat) { /*struct t_gui_window *ptr_win; struct t_gui_line *ptr_line; @@ -366,46 +366,10 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase) char format[32], date[128], *buf; struct tm *date_tmp;*/ - if (!gui_ok) + if (!gui_init_ok) return; /* TODO: write this function for Gtk */ (void) buffer; - (void) erase; -} - -/* - * gui_chat_draw_line: add a line to chat window for a buffer - */ - -void -gui_chat_draw_line (struct t_gui_buffer *buffer, struct t_gui_line *line) -{ - /* - struct t_gui_window *ptr_win; - unsigned char *message_without_color; - GtkTextIter start, end; - */ - - (void) buffer; - (void) line; - - /* - ptr_win = gui_buffer_find_window (buffer); - if (ptr_win) - { - message_without_color = gui_color_decode ((unsigned char *)(line->message)); - if (message_without_color) - { - gtk_text_buffer_insert_at_cursor (GUI_WINDOW_OBJECTS(ptr_win)->textbuffer_chat, - (char *)message_without_color, -1); - gtk_text_buffer_insert_at_cursor (GUI_WINDOW_OBJECTS(ptr_win)->textbuffer_chat, - "\n", -1); - gtk_text_buffer_get_bounds (GUI_WINDOW_OBJECTS(ptr_win)->textbuffer_chat, - &start, &end); - gtk_text_buffer_apply_tag (ptr_win->textbuffer_chat, ptr_win->texttag_chat, &start, &end); - free (message_without_color); - } - } - */ + (void) clear_chat; } diff --git a/src/gui/gtk/gui-gtk-main.c b/src/gui/gtk/gui-gtk-main.c index 568cc3632..57ee22efb 100644 --- a/src/gui/gtk/gui-gtk-main.c +++ b/src/gui/gtk/gui-gtk-main.c @@ -93,8 +93,6 @@ gui_main_init () gui_color_init (); - gui_ok = 1; - /* build prefixes according to config */ gui_chat_prefix_build (); diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c index 5aea4a65a..24ce6c22a 100644 --- a/src/gui/gtk/gui-gtk-window.c +++ b/src/gui/gtk/gui-gtk-window.c @@ -264,7 +264,7 @@ gui_window_switch_to_buffer (struct t_gui_window *window, void gui_window_page_up (struct t_gui_window *window) { - if (!gui_ok) + if (!gui_init_ok) return; if (!window->scroll->first_line_displayed) @@ -288,7 +288,7 @@ gui_window_page_down (struct t_gui_window *window) struct t_gui_line *ptr_line; int line_pos; - if (!gui_ok) + if (!gui_init_ok) return; if (window->scroll->start_line) @@ -320,7 +320,7 @@ gui_window_page_down (struct t_gui_window *window) void gui_window_scroll_up (struct t_gui_window *window) { - if (!gui_ok) + if (!gui_init_ok) return; if (!window->scroll->first_line_displayed) @@ -345,7 +345,7 @@ gui_window_scroll_down (struct t_gui_window *window) struct t_gui_line *ptr_line; int line_pos; - if (!gui_ok) + if (!gui_init_ok) return; if (window->scroll->start_line) @@ -378,7 +378,7 @@ gui_window_scroll_down (struct t_gui_window *window) void gui_window_scroll_top (struct t_gui_window *window) { - if (!gui_ok) + if (!gui_init_ok) return; if (!window->scroll->first_line_displayed) @@ -396,7 +396,7 @@ gui_window_scroll_top (struct t_gui_window *window) void gui_window_scroll_bottom (struct t_gui_window *window) { - if (!gui_ok) + if (!gui_init_ok) return; if (window->scroll->start_line) @@ -471,7 +471,7 @@ gui_window_refresh_windows () { /*struct t_gui_window *ptr_win, *old_current_window;*/ - if (gui_ok) + if (gui_init_ok) { /* TODO: write this function for Gtk */ } @@ -487,7 +487,7 @@ gui_window_split_horizontal (struct t_gui_window *window, int percentage) struct t_gui_window *new_window; int height1, height2; - if (!gui_ok) + if (!gui_init_ok) return NULL; new_window = NULL; @@ -532,7 +532,7 @@ gui_window_split_vertical (struct t_gui_window *window, int percentage) struct t_gui_window *new_window; int width1, width2; - if (!gui_ok) + if (!gui_init_ok) return NULL; new_window = NULL; diff --git a/src/gui/gui-bar-window.c b/src/gui/gui-bar-window.c index 1c0778d91..51e0f4b2b 100644 --- a/src/gui/gui-bar-window.c +++ b/src/gui/gui-bar-window.c @@ -361,6 +361,18 @@ gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window, case GUI_BAR_NUM_POSITIONS: break; } + + /* bar window can not be displayed? (not enough space left) */ + if ((bar_window->x < x1) || (bar_window->x > x2) + || (bar_window->y < y1) || (bar_window->y > y2) + || (bar_window->width < 1) || (bar_window->height < 1)) + { + /* invalidate the bar window, it will not be displayed */ + bar_window->x = -1; + bar_window->y = -1; + bar_window->width = 0; + bar_window->height = 0; + } } /* @@ -1121,13 +1133,11 @@ gui_bar_window_get_max_size_in_window (struct t_gui_bar_window *bar_window, { case GUI_BAR_POSITION_BOTTOM: case GUI_BAR_POSITION_TOP: - max_size = (window->win_chat_height + bar_window->height) - - GUI_WINDOW_CHAT_MIN_HEIGHT; + max_size = (window->win_chat_height + bar_window->height) - 1; break; case GUI_BAR_POSITION_LEFT: case GUI_BAR_POSITION_RIGHT: - max_size = (window->win_chat_width + bar_window->width) - - GUI_WINDOW_CHAT_MIN_HEIGHT; + max_size = (window->win_chat_width + bar_window->width) - 1; break; case GUI_BAR_NUM_POSITIONS: break; diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index f9f814b0c..5946fe37f 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -275,8 +275,8 @@ gui_bar_check_size_add (struct t_gui_bar *bar, int add_size) if ((CONFIG_INTEGER(bar->options[GUI_BAR_OPTION_TYPE]) == GUI_BAR_TYPE_ROOT) || (gui_bar_window_search_bar (ptr_window, bar))) { - if ((ptr_window->win_chat_width - sub_width < GUI_WINDOW_CHAT_MIN_WIDTH) - || (ptr_window->win_chat_height - sub_height < GUI_WINDOW_CHAT_MIN_HEIGHT)) + if ((ptr_window->win_chat_width - sub_width < 1) + || (ptr_window->win_chat_height - sub_height < 1)) return 0; } } diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index e5a2e37a4..5e4a264c0 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -92,7 +92,7 @@ extern char *gui_chat_string_next_char (struct t_gui_window *window, const unsigned char *string, int apply_style, int apply_style_inactive); -extern void gui_chat_draw (struct t_gui_buffer *buffer, int erase); +extern void gui_chat_draw (struct t_gui_buffer *buffer, int clear_chat); extern void gui_chat_draw_line (struct t_gui_buffer *buffer, struct t_gui_line *line); diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 921d4708e..4132cf5fd 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -58,8 +58,6 @@ int gui_init_ok = 0; /* = 1 if GUI is initialized*/ -int gui_ok = 0; /* = 1 if GUI is ok */ - /* (0 when size too small) */ int gui_window_refresh_needed = 0; /* = 1 if refresh needed */ /* = 2 for full refresh */ struct t_gui_window *gui_windows = NULL; /* first window */ @@ -963,7 +961,7 @@ gui_window_free (struct t_gui_window *window) void gui_window_switch_previous (struct t_gui_window *window) { - if (!gui_ok) + if (!gui_init_ok) return; gui_window_switch ((window->prev_window) ? @@ -977,7 +975,7 @@ gui_window_switch_previous (struct t_gui_window *window) void gui_window_switch_next (struct t_gui_window *window) { - if (!gui_ok) + if (!gui_init_ok) return; gui_window_switch ((window->next_window) ? @@ -993,7 +991,7 @@ gui_window_switch_by_number (int number) { struct t_gui_window *ptr_win; - if (!gui_ok) + if (!gui_init_ok) return; ptr_win = gui_window_search_by_number (number); @@ -1010,7 +1008,7 @@ gui_window_switch_by_buffer (struct t_gui_window *window, int buffer_number) { struct t_gui_window *ptr_win; - if (!gui_ok) + if (!gui_init_ok) return; ptr_win = (window->next_window) ? window->next_window : gui_windows; @@ -1567,7 +1565,7 @@ gui_window_search_stop (struct t_gui_window *window) void gui_window_zoom (struct t_gui_window *window) { - if (!gui_ok) + if (!gui_init_ok) return; if (gui_window_layout_before_zoom) diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h index 67df5cbef..f0eabb1ca 100644 --- a/src/gui/gui-window.h +++ b/src/gui/gui-window.h @@ -20,17 +20,10 @@ #ifndef __WEECHAT_GUI_WINDOW_H #define __WEECHAT_GUI_WINDOW_H 1 -#define GUI_WINDOW_MIN_WIDTH 10 -#define GUI_WINDOW_MIN_HEIGHT 5 - -#define GUI_WINDOW_CHAT_MIN_WIDTH 5 -#define GUI_WINDOW_CHAT_MIN_HEIGHT 2 - struct t_infolist; struct t_gui_bar_window; extern int gui_init_ok; -extern int gui_ok; extern int gui_window_refresh_needed; extern int gui_window_cursor_x, gui_window_cursor_y;