summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-bar.c24
-rw-r--r--src/gui/curses/gui-curses-chat.c22
-rw-r--r--src/gui/gui-action.c2
-rw-r--r--src/gui/gui-bar-item.c2
-rw-r--r--src/gui/gui-bar.c157
-rw-r--r--src/gui/gui-bar.h2
-rw-r--r--src/gui/gui-buffer.c13
-rw-r--r--src/gui/gui-buffer.h1
-rw-r--r--src/gui/gui-chat.c2
-rw-r--r--src/gui/gui-window.c10
10 files changed, 189 insertions, 46 deletions
diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c
index 7feb60bd9..1ea49bc5e 100644
--- a/src/gui/curses/gui-curses-bar.c
+++ b/src/gui/curses/gui-curses-bar.c
@@ -510,9 +510,9 @@ gui_bar_window_add_missing_bars (struct t_gui_window *window)
int
gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
- char *string, int max_chars)
+ char *string, int max_chars_on_screen)
{
- int weechat_color, num_displayed, size_on_screen;
+ int weechat_color, chars_displayed, size_on_screen;
char str_color[3], utf_char[16], *next_char, *output;
if (!string || !string[0])
@@ -524,7 +524,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
else
gui_window_set_weechat_color (bar_window->win_bar, GUI_COLOR_STATUS);
- num_displayed = 0;
+ chars_displayed = 0;
while (string && string[0])
{
@@ -552,31 +552,29 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
if (gui_window_utf_char_valid (utf_char))
{
+ size_on_screen = utf8_char_size_screen (utf_char);
+ if (chars_displayed + size_on_screen > max_chars_on_screen)
+ return chars_displayed;
+ chars_displayed += size_on_screen;
output = string_iconv_from_internal (NULL, utf_char);
wprintw (bar_window->win_bar, "%s",
(output) ? output : utf_char);
- size_on_screen = utf8_char_size_screen ((output) ?
- output : utf_char);
- num_displayed += size_on_screen;
- max_chars -= size_on_screen;
if (output)
free (output);
}
else
{
+ if (chars_displayed + 1 > max_chars_on_screen)
+ return chars_displayed;
+ chars_displayed++;
wprintw (bar_window->win_bar, ".");
- num_displayed++;
- max_chars--;
}
string = next_char;
-
- if (max_chars <= 0)
- break;
}
}
- return num_displayed;
+ return chars_displayed;
}
/*
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 2b1ff6d27..b17b9bcdc 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -520,7 +520,7 @@ void
gui_chat_display_word_raw (struct t_gui_window *window, char *string,
int max_chars_on_screen, int display)
{
- char *next_char, *output, utf_char[16], chars_displayed, size_screen;
+ char *next_char, *output, utf_char[16], chars_displayed, size_on_screen;
if (display)
wmove (GUI_CURSES(window)->win_chat,
@@ -541,15 +541,15 @@ gui_chat_display_word_raw (struct t_gui_window *window, char *string,
{
memcpy (utf_char, string, next_char - string);
utf_char[next_char - string] = '\0';
- if (max_chars_on_screen > 0)
- {
- size_screen = utf8_strlen_screen (utf_char);
- if (chars_displayed + size_screen > max_chars_on_screen)
- return;
- chars_displayed += size_screen;
- }
if (gui_window_utf_char_valid (utf_char))
{
+ if (max_chars_on_screen > 0)
+ {
+ size_on_screen = utf8_strlen_screen (utf_char);
+ if (chars_displayed + size_on_screen > max_chars_on_screen)
+ return;
+ chars_displayed += size_on_screen;
+ }
output = string_iconv_from_internal (NULL, utf_char);
wprintw (GUI_CURSES(window)->win_chat,
"%s", (output) ? output : utf_char);
@@ -558,6 +558,12 @@ gui_chat_display_word_raw (struct t_gui_window *window, char *string,
}
else
{
+ if (max_chars_on_screen > 0)
+ {
+ if (chars_displayed + 1 > max_chars_on_screen)
+ return;
+ chars_displayed++;
+ }
wprintw (GUI_CURSES(window)->win_chat, ".");
}
}
diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c
index ebe07fd0b..906564c86 100644
--- a/src/gui/gui-action.c
+++ b/src/gui/gui-action.c
@@ -1370,7 +1370,7 @@ gui_action_scroll_unread (char *args)
gui_current_window->start_line_pos = 0;
gui_current_window->first_line_displayed =
(gui_current_window->start_line == gui_chat_get_first_line_displayed (gui_current_window->buffer));
- gui_current_window->buffer->chat_refresh_needed = 1;
+ gui_current_window->buffer->chat_refresh_needed = 2;
gui_status_refresh_needed = 1;
}
}
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index 5de3a1a4d..94448b2f4 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -350,7 +350,7 @@ gui_bar_item_default_buffer_filter (void *data, struct t_gui_bar_item *item,
return NULL;
snprintf (buf, sizeof (buf),
- "%s[%sF%s%s%s]",
+ "%s[%sF%s%s%s] ",
GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS),
GUI_COLOR(GUI_COLOR_STATUS),
(window->buffer->lines_hidden) ? "," : "",
diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c
index e11797556..602ef8f4d 100644
--- a/src/gui/gui-bar.c
+++ b/src/gui/gui-bar.c
@@ -132,6 +132,25 @@ gui_bar_search (char *name)
}
/*
+ * gui_bar_search_by_number: search a bar by number
+ */
+
+struct t_gui_bar *
+gui_bar_search_by_number (int number)
+{
+ struct t_gui_bar *ptr_bar;
+
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ if (ptr_bar->number == number)
+ return ptr_bar;
+ }
+
+ /* bar not found */
+ return NULL;
+}
+
+/*
* gui_bar_new: create a new bar
*/
@@ -220,6 +239,27 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
}
/*
+ * gui_bar_refresh: ask for bar refresh on screen (for all windows where bar is)
+ */
+
+void
+gui_bar_refresh (struct t_gui_bar *bar)
+{
+ struct t_gui_window *ptr_win;
+
+ if (bar->type == GUI_BAR_TYPE_ROOT)
+ gui_window_refresh_needed = 1;
+ else
+ {
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ if (gui_bar_window_search_bar (ptr_win, bar))
+ ptr_win->refresh_needed = 1;
+ }
+ }
+}
+
+/*
* gui_bar_set_name: set name for a bar
*/
@@ -235,21 +275,111 @@ gui_bar_set_name (struct t_gui_bar *bar, char *name)
}
/*
- * gui_bar_set_type: set type for a bar
+ * gui_bar_set_number: set number for a bar
*/
void
-gui_bar_set_type (struct t_gui_bar *bar, char *type)
+gui_bar_set_number (struct t_gui_bar *bar, int number)
{
- int type_value;
+ struct t_gui_bar *ptr_bar;
+ struct t_gui_window *ptr_win;
+ int i;
+
+ if (number < 1)
+ number = 1;
- (void) bar;
+ /* bar number is already ok? */
+ if (number == bar->number)
+ return;
- if (type && type[0])
+ /* remove bar from list */
+ if (bar == gui_bars)
+ {
+ gui_bars = bar->next_bar;
+ gui_bars->prev_bar = NULL;
+ }
+ if (bar == last_gui_bar)
{
- type_value = gui_bar_get_type (type);
- if (type_value >= 0)
+ last_gui_bar = bar->prev_bar;
+ last_gui_bar->next_bar = NULL;
+ }
+ if (bar->prev_bar)
+ (bar->prev_bar)->next_bar = bar->next_bar;
+ if (bar->next_bar)
+ (bar->next_bar)->prev_bar = bar->prev_bar;
+
+ if (number == 1)
+ {
+ gui_bars->prev_bar = bar;
+ bar->prev_bar = NULL;
+ bar->next_bar = gui_bars;
+ gui_bars = bar;
+ }
+ else
+ {
+ /* assign new number to all bars */
+ i = 1;
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ ptr_bar->number = i++;
+ }
+
+ ptr_bar = gui_bar_search_by_number (number);
+ if (ptr_bar)
{
+ /* add bar before ptr_bar */
+ bar->prev_bar = ptr_bar->prev_bar;
+ bar->next_bar = ptr_bar;
+ if (ptr_bar->prev_bar)
+ (ptr_bar->prev_bar)->next_bar = bar;
+ ptr_bar->prev_bar = bar;
+ }
+ else
+ {
+ /* add to end of list */
+ bar->prev_bar = last_gui_bar;
+ bar->next_bar = NULL;
+ last_gui_bar->next_bar = bar;
+ last_gui_bar = bar;
+ }
+ }
+
+ /* assign new number to all bars */
+ i = 1;
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ ptr_bar->number = i++;
+ gui_bar_free_bar_windows (ptr_bar);
+ }
+
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ if (ptr_bar->type != GUI_BAR_TYPE_ROOT)
+ gui_bar_window_new (ptr_bar, ptr_win);
+ }
+ }
+
+ gui_window_refresh_needed = 1;
+}
+
+/*
+ * gui_bar_set_position: set position for a bar
+ */
+
+void
+gui_bar_set_position (struct t_gui_bar *bar, char *position)
+{
+ int position_value;
+
+ if (position && position[0])
+ {
+ position_value = gui_bar_get_position (position);
+ if ((position_value >= 0) && ((int)bar->position != position_value))
+ {
+ bar->position = position_value;
+ gui_bar_refresh (bar);
}
}
}
@@ -270,6 +400,8 @@ gui_bar_set_size (struct t_gui_bar *bar, int size)
bar->size = size;
bar->current_size = (size == 0) ? 1 : size;
+
+ gui_bar_refresh (bar);
}
}
@@ -316,13 +448,16 @@ gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
{
gui_bar_set_name (bar, value);
}
- else if (string_strcasecmp (property, "type") == 0)
+ if (string_strcasecmp (property, "number") == 0)
{
- gui_bar_set_type (bar, value);
+ error = NULL;
+ number = strtol (value, &error, 10);
+ if (error && !error[0])
+ gui_bar_set_number (bar, number);
}
else if (string_strcasecmp (property, "position") == 0)
{
-
+ gui_bar_set_position (bar, value);
}
else if (string_strcasecmp (property, "size") == 0)
{
@@ -334,10 +469,12 @@ gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
else if (string_strcasecmp (property, "separator") == 0)
{
bar->separator = (string_strcasecmp (value, "1") == 0) ? 1 : 0;
+ gui_bar_refresh (bar);
}
else if (string_strcasecmp (property, "items") == 0)
{
gui_bar_set_items (bar, value);
+ gui_bar_draw (bar);
}
}
diff --git a/src/gui/gui-bar.h b/src/gui/gui-bar.h
index f5d487e53..100b5f23f 100644
--- a/src/gui/gui-bar.h
+++ b/src/gui/gui-bar.h
@@ -91,6 +91,8 @@ extern void gui_bar_print_log ();
/* functions (GUI dependent) */
+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_size (struct t_gui_bar *bar,
struct t_gui_window *window,
enum t_gui_bar_position position);
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 8bd38dc04..7f266db8c 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -115,7 +115,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin, char *category, char *name,
new_buffer->lines_count = 0;
new_buffer->lines_hidden = 0;
new_buffer->prefix_max_length = 0;
- new_buffer->chat_refresh_needed = 1;
+ new_buffer->chat_refresh_needed = 2;
/* nicklist */
new_buffer->nicklist = 0;
@@ -317,7 +317,7 @@ gui_buffer_set_type (struct t_gui_buffer *buffer, enum t_gui_buffer_type type)
break;
}
buffer->type = type;
- buffer->chat_refresh_needed = 1;
+ buffer->chat_refresh_needed = 2;
}
/*
@@ -662,7 +662,7 @@ gui_buffer_clear (struct t_gui_buffer *buffer)
}
}
- buffer->chat_refresh_needed = 1;
+ buffer->chat_refresh_needed = 2;
gui_status_refresh_needed = 1;
}
@@ -859,13 +859,13 @@ gui_buffer_move_to_number (struct t_gui_buffer *buffer, int number)
if (gui_buffers == last_gui_buffer)
return;
+ if (number < 1)
+ number = 1;
+
/* buffer number is already ok ? */
if (number == buffer->number)
return;
- if (number < 1)
- number = 1;
-
snprintf (buf2_str, sizeof (buf2_str) - 1, "%d", buffer->number);
/* remove buffer from list */
@@ -923,7 +923,6 @@ gui_buffer_move_to_number (struct t_gui_buffer *buffer, int number)
last_gui_buffer->next_buffer = buffer;
last_gui_buffer = buffer;
}
-
}
/* assign new number to all buffers */
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h
index 5c17cb8cd..89a63a107 100644
--- a/src/gui/gui-buffer.h
+++ b/src/gui/gui-buffer.h
@@ -86,6 +86,7 @@ struct t_gui_buffer
int lines_hidden; /* 1 if at least one line is hidden */
int prefix_max_length; /* length for prefix align */
int chat_refresh_needed; /* refresh for chat is needed ? */
+ /* (1=refresh, 2=erase+refresh) */
/* nicklist */
int nicklist; /* = 1 if nicklist is enabled */
diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c
index 18c982bfa..c3b8e0340 100644
--- a/src/gui/gui-chat.c
+++ b/src/gui/gui-chat.c
@@ -579,7 +579,7 @@ gui_chat_line_free (struct t_gui_buffer *buffer, struct t_gui_line *line)
{
ptr_win->start_line = ptr_win->start_line->next_line;
ptr_win->start_line_pos = 0;
- ptr_win->buffer->chat_refresh_needed = 1;
+ ptr_win->buffer->chat_refresh_needed = 2;
gui_status_refresh_needed = 1;
}
}
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index b7c49e946..3a9dd99a5 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -637,7 +637,7 @@ gui_window_scroll (struct t_gui_window *window, char *scroll)
window->start_line_pos = 0;
window->first_line_displayed =
(window->start_line == gui_chat_get_first_line_displayed (window->buffer));
- window->buffer->chat_refresh_needed = 1;
+ window->buffer->chat_refresh_needed = 2;
gui_status_refresh_needed = 1;
return;
}
@@ -680,7 +680,7 @@ gui_window_search_text (struct t_gui_window *window)
window->start_line_pos = 0;
window->first_line_displayed =
(window->start_line == gui_chat_get_first_line_displayed (window->buffer));
- window->buffer->chat_refresh_needed = 1;
+ window->buffer->chat_refresh_needed = 2;
gui_status_refresh_needed = 1;
return 1;
}
@@ -709,7 +709,7 @@ gui_window_search_text (struct t_gui_window *window)
window->start_line_pos = 0;
window->first_line_displayed =
(window->start_line == window->buffer->lines);
- window->buffer->chat_refresh_needed = 1;
+ window->buffer->chat_refresh_needed = 2;
gui_status_refresh_needed = 1;
return 1;
}
@@ -759,7 +759,7 @@ gui_window_search_restart (struct t_gui_window *window)
window->buffer->text_search_found = 1;
else
{
- window->buffer->chat_refresh_needed = 1;
+ window->buffer->chat_refresh_needed = 2;
gui_status_refresh_needed = 1;
}
}
@@ -784,7 +784,7 @@ gui_window_search_stop (struct t_gui_window *window)
window->start_line = NULL;
window->start_line_pos = 0;
gui_hotlist_remove_buffer (window->buffer);
- window->buffer->chat_refresh_needed = 1;
+ window->buffer->chat_refresh_needed = 2;
gui_status_refresh_needed = 1;
window->buffer->input_refresh_needed = 1;
}