summaryrefslogtreecommitdiff
path: root/src/gui/curses
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/curses')
-rw-r--r--src/gui/curses/gui-curses-chat.c49
-rw-r--r--src/gui/curses/gui-curses-input.c4
-rw-r--r--src/gui/curses/gui-curses-window.c118
3 files changed, 101 insertions, 70 deletions
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index ec919ef47..2aafcb706 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -170,33 +170,37 @@ void
gui_chat_draw_title (struct t_gui_buffer *buffer, int erase)
{
struct t_gui_window *ptr_win;
- char format[32], *buf, *buf2, *ptr_title;
+ char format[32], *buf, *title_decoded, *ptr_title;
if (!gui_ok)
return;
+ title_decoded = (buffer->title) ?
+ (char *)gui_color_decode ((unsigned char *)buffer->title) : NULL;
+
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
- if ((ptr_win->buffer == buffer) && (buffer->num_displayed > 0))
+ if (ptr_win->buffer == buffer)
{
if (erase)
gui_window_curses_clear (GUI_CURSES(ptr_win)->win_title, GUI_COLOR_TITLE);
- snprintf (format, 32, "%%-%ds", ptr_win->win_title_width);
+ snprintf (format, sizeof (format), "%%-%ds", ptr_win->win_title_width);
wmove (GUI_CURSES(ptr_win)->win_title, 0, 0);
- if (buffer->title)
+ if (title_decoded)
{
- buf = (char *)gui_color_decode ((unsigned char *)buffer->title);
- ptr_title = utf8_add_offset ((buf) ? buf : buffer->title,
+ ptr_title = utf8_add_offset (title_decoded,
ptr_win->win_title_start);
if (!ptr_title || !ptr_title[0])
{
ptr_win->win_title_start = 0;
- ptr_title = (buf) ? buf : buffer->title;
+ ptr_title = title_decoded;
}
- buf2 = string_iconv_from_internal (NULL,
- ptr_title);
+ buf = string_iconv_from_internal (NULL,
+ ptr_title);
+ if (buf)
+ ptr_title = buf;
if (ptr_win->win_title_start > 0)
{
@@ -209,8 +213,7 @@ gui_chat_draw_title (struct t_gui_buffer *buffer, int erase)
{
gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_title,
GUI_COLOR_TITLE);
- wprintw (GUI_CURSES(ptr_win)->win_title, "%s",
- (buf2) ? buf2 : ptr_title);
+ wprintw (GUI_CURSES(ptr_win)->win_title, "%s", ptr_title);
gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_title,
GUI_COLOR_TITLE_MORE);
mvwprintw (GUI_CURSES(ptr_win)->win_title, 0,
@@ -221,24 +224,24 @@ gui_chat_draw_title (struct t_gui_buffer *buffer, int erase)
{
gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_title,
GUI_COLOR_TITLE);
- wprintw (GUI_CURSES(ptr_win)->win_title, "%s",
- (buf2) ? buf2 : ptr_title);
+ wprintw (GUI_CURSES(ptr_win)->win_title, "%s", ptr_title);
}
if (buf)
free (buf);
- if (buf2)
- free (buf2);
}
+ else
+ {
+ gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_title,
+ GUI_COLOR_TITLE);
+ wprintw (GUI_CURSES(ptr_win)->win_title, format, " ");
+ }
+ wnoutrefresh (GUI_CURSES(ptr_win)->win_title);
+ refresh ();
}
- else
- {
- gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_title,
- GUI_COLOR_TITLE);
- wprintw (GUI_CURSES(ptr_win)->win_title, format, " ");
- }
- wnoutrefresh (GUI_CURSES(ptr_win)->win_title);
- refresh ();
}
+
+ if (title_decoded)
+ free (title_decoded);
}
/*
diff --git a/src/gui/curses/gui-curses-input.c b/src/gui/curses/gui-curses-input.c
index 2a1c885f2..9787f4cb8 100644
--- a/src/gui/curses/gui-curses-input.c
+++ b/src/gui/curses/gui-curses-input.c
@@ -351,14 +351,14 @@ gui_input_draw (struct t_gui_buffer *buffer, int erase)
gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_input,
GUI_COLOR_INPUT);
- snprintf (format, 32, "%%-%ds",
+ snprintf (format, sizeof (format), "%%-%ds",
ptr_win->win_input_width - prompt_length);
offset_cursor = 0;
if (ptr_win == gui_current_window)
offset_cursor = gui_input_draw_text (ptr_win,
ptr_win->win_input_width - prompt_length);
else
- wprintw (GUI_CURSES(ptr_win)->win_input, format, "");
+ wprintw (GUI_CURSES(ptr_win)->win_input, format, " ");
wclrtoeol (GUI_CURSES(ptr_win)->win_input);
ptr_win->win_input_cursor_x = prompt_length + offset_cursor;
if (ptr_win == gui_current_window)
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 69af89496..c5d8be76d 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -425,25 +425,17 @@ gui_window_draw_separator (struct t_gui_window *window)
void
gui_window_redraw_buffer (struct t_gui_buffer *buffer)
{
- struct t_gui_window *ptr_win;
-
if (!gui_ok)
return;
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- if (ptr_win->buffer == buffer)
- {
- gui_chat_draw_title (buffer, 1);
- gui_chat_draw (buffer, 1);
- if (GUI_CURSES(ptr_win)->win_nick)
- gui_nicklist_draw (buffer, 1);
- gui_status_draw (1);
- if (CONFIG_BOOLEAN(config_look_infobar))
- gui_infobar_draw (buffer, 1);
- gui_input_draw (buffer, 1);
- }
- }
+ gui_chat_draw_title (buffer, 1);
+ gui_chat_draw (buffer, 1);
+ if (buffer->nicklist)
+ gui_nicklist_draw (buffer, 1);
+ gui_status_draw (1);
+ if (CONFIG_BOOLEAN(config_look_infobar))
+ gui_infobar_draw (buffer, 1);
+ gui_input_draw (buffer, 1);
}
/*
@@ -453,11 +445,15 @@ gui_window_redraw_buffer (struct t_gui_buffer *buffer)
void
gui_window_redraw_all_buffers ()
{
- struct t_gui_window *ptr_win;
+ struct t_gui_buffer *ptr_buffer;
+
+ if (!gui_ok)
+ return;
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
{
- gui_window_redraw_buffer (ptr_win->buffer);
+ gui_window_redraw_buffer (ptr_buffer);
}
}
@@ -877,6 +873,9 @@ gui_window_auto_resize (struct t_gui_window_tree *tree,
{
int size1, size2;
+ if (!gui_ok)
+ return 0;
+
if (tree)
{
if (tree->window)
@@ -928,29 +927,31 @@ void
gui_window_refresh_windows ()
{
struct t_gui_window *ptr_win, *old_current_window;
+ struct t_gui_buffer *ptr_buffer;
+
+ if (!gui_ok)
+ return;
+
+ old_current_window = gui_current_window;
- if (gui_ok)
+ if (gui_window_auto_resize (gui_windows_tree, 0, 0,
+ gui_window_get_width (),
+ gui_window_get_height (), 0) < 0)
+ gui_window_merge_all (gui_current_window);
+
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
- old_current_window = gui_current_window;
-
- if (gui_window_auto_resize (gui_windows_tree, 0, 0,
- gui_window_get_width (),
- gui_window_get_height (), 0) < 0)
- gui_window_merge_all (gui_current_window);
-
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- gui_window_switch_to_buffer (ptr_win, ptr_win->buffer);
- }
-
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- gui_window_redraw_buffer (ptr_win->buffer);
- gui_window_draw_separator (ptr_win);
- }
-
- gui_current_window = old_current_window;
+ gui_window_switch_to_buffer (ptr_win, ptr_win->buffer);
+ gui_window_draw_separator (ptr_win);
+ }
+
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ gui_window_redraw_buffer (ptr_buffer);
}
+
+ gui_current_window = old_current_window;
}
/*
@@ -1049,6 +1050,9 @@ gui_window_resize (struct t_gui_window *window, int pourcentage)
struct t_gui_window_tree *parent;
int old_split_pct;
+ if (!gui_ok)
+ return;
+
parent = window->ptr_tree->parent_node;
if (parent)
{
@@ -1076,6 +1080,9 @@ gui_window_merge (struct t_gui_window *window)
{
struct t_gui_window_tree *parent, *sister;
+ if (!gui_ok)
+ return 0;
+
parent = window->ptr_tree->parent_node;
if (parent)
{
@@ -1120,7 +1127,10 @@ void
gui_window_merge_all (struct t_gui_window *window)
{
int num_deleted;
-
+
+ if (!gui_ok)
+ return;
+
num_deleted = 0;
while (gui_windows->next_window)
{
@@ -1157,6 +1167,9 @@ 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)
+ return 0;
+
/* win2 over win1 ? */
if (win2->win_y + win2->win_height == win1->win_y)
{
@@ -1209,6 +1222,9 @@ gui_window_switch_up (struct t_gui_window *window)
{
struct t_gui_window *ptr_win;
+ if (!gui_ok)
+ return;
+
for (ptr_win = gui_windows; ptr_win;
ptr_win = ptr_win->next_window)
{
@@ -1232,6 +1248,9 @@ gui_window_switch_down (struct t_gui_window *window)
{
struct t_gui_window *ptr_win;
+ if (!gui_ok)
+ return;
+
for (ptr_win = gui_windows; ptr_win;
ptr_win = ptr_win->next_window)
{
@@ -1255,6 +1274,9 @@ gui_window_switch_left (struct t_gui_window *window)
{
struct t_gui_window *ptr_win;
+ if (!gui_ok)
+ return;
+
for (ptr_win = gui_windows; ptr_win;
ptr_win = ptr_win->next_window)
{
@@ -1278,6 +1300,9 @@ gui_window_switch_right (struct t_gui_window *window)
{
struct t_gui_window *ptr_win;
+ if (!gui_ok)
+ return;
+
for (ptr_win = gui_windows; ptr_win;
ptr_win = ptr_win->next_window)
{
@@ -1301,14 +1326,17 @@ void
gui_window_refresh_screen (int force)
{
int new_height, new_width;
-
+
+ if (!gui_ok)
+ return;
+
if (force || (gui_window_refresh_needed == 1))
{
endwin ();
refresh ();
getmaxyx (stdscr, new_height, new_width);
-
+
gui_ok = ((new_width > WINDOW_MIN_WIDTH) && (new_height > WINDOW_MIN_HEIGHT));
if (gui_ok)
@@ -1317,9 +1345,9 @@ gui_window_refresh_screen (int force)
gui_window_refresh_windows ();
}
}
-
- if (!force && (gui_window_refresh_needed > 0))
- gui_window_refresh_needed--;
+
+ if (gui_window_refresh_needed > 0)
+ gui_window_refresh_needed = 0;
}
/*