summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-bar.c391
-rw-r--r--src/gui/curses/gui-curses-chat.c4
-rw-r--r--src/gui/curses/gui-curses-color.c26
-rw-r--r--src/gui/curses/gui-curses-main.c32
-rw-r--r--src/gui/curses/gui-curses-window.c131
-rw-r--r--src/gui/curses/gui-curses.h20
-rw-r--r--src/gui/gtk/gui-gtk-bar.c232
-rw-r--r--src/gui/gtk/gui-gtk-color.c23
-rw-r--r--src/gui/gtk/gui-gtk-main.c3
-rw-r--r--src/gui/gtk/gui-gtk-window.c37
-rw-r--r--src/gui/gtk/gui-gtk.h11
-rw-r--r--src/gui/gui-bar-item.c4
-rw-r--r--src/gui/gui-bar.c231
-rw-r--r--src/gui/gui-bar.h42
-rw-r--r--src/gui/gui-buffer.c9
-rw-r--r--src/gui/gui-color.c3
-rw-r--r--src/gui/gui-color.h5
-rw-r--r--src/gui/gui-completion.c20
-rw-r--r--src/gui/gui-window.c36
-rw-r--r--src/gui/gui-window.h7
20 files changed, 1038 insertions, 229 deletions
diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c
index 567413651..7feb60bd9 100644
--- a/src/gui/curses/gui-curses-bar.c
+++ b/src/gui/curses/gui-curses-bar.c
@@ -40,6 +40,26 @@
/*
+ * gui_bar_window_search_bar: search a reference to a bar in a window
+ */
+
+struct t_gui_bar_window *
+gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar)
+{
+ struct t_gui_bar_window *ptr_bar_win;
+
+ for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if (ptr_bar_win->bar == bar)
+ return ptr_bar_win;
+ }
+
+ /* bar window not found for window */
+ return NULL;
+}
+
+/*
* gui_bar_window_get_size: get total bar size (window bars) for a position
* bar is optional, if not NULL, size is computed
* from bar 1 to bar # - 1
@@ -47,7 +67,7 @@
int
gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
- int position)
+ enum t_gui_bar_position position)
{
struct t_gui_bar_window *ptr_bar_window;
int total_size;
@@ -73,6 +93,9 @@ gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
case GUI_BAR_POSITION_RIGHT:
total_size += ptr_bar_window->width;
break;
+ case GUI_BAR_NUM_POSITIONS:
+ /* make C compiler happy */
+ break;
}
if (ptr_bar_window->bar->separator)
total_size++;
@@ -82,6 +105,50 @@ gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
}
/*
+ * gui_bar_check_size_add: check if "add_size" is ok for bar
+ * return 1 if new size is ok
+ * 0 if new size is too big
+ */
+
+int
+gui_bar_check_size_add (struct t_gui_bar *bar, int add_size)
+{
+ struct t_gui_window *ptr_win;
+ int sub_width, sub_height;
+
+ sub_width = 0;
+ sub_height = 0;
+
+ switch (bar->position)
+ {
+ case GUI_BAR_POSITION_BOTTOM:
+ case GUI_BAR_POSITION_TOP:
+ sub_height = add_size;
+ break;
+ case GUI_BAR_POSITION_LEFT:
+ case GUI_BAR_POSITION_RIGHT:
+ sub_width = add_size;
+ break;
+ case GUI_BAR_NUM_POSITIONS:
+ break;
+ }
+
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ if ((bar->type == GUI_BAR_TYPE_ROOT)
+ || (gui_bar_window_search_bar (ptr_win, bar)))
+ {
+ if ((ptr_win->win_chat_width - sub_width < GUI_WINDOW_CHAT_MIN_WIDTH)
+ || (ptr_win->win_chat_height - sub_height < GUI_WINDOW_CHAT_MIN_HEIGHT))
+ return 0;
+ }
+ }
+
+ /* new size ok */
+ return 1;
+}
+
+/*
* gui_bar_window_calculate_pos_size: calculate position and size of a bar
*/
@@ -95,7 +162,7 @@ gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
if (window)
{
x1 = window->win_x;
- y1 = window->win_y + 1;
+ y1 = window->win_y;
x2 = x1 + window->win_width - 1;
y2 = y1 + window->win_height - 1;
add_left = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_LEFT);
@@ -119,28 +186,31 @@ 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->y = y2 - add_bottom - bar_window->bar->current_size + 1;
bar_window->width = x2 - x1 + 1 - add_left - add_right;
- bar_window->height = bar_window->bar->size;
+ bar_window->height = bar_window->bar->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->size;
+ bar_window->height = bar_window->bar->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->size;
+ bar_window->width = bar_window->bar->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->size + 1;
+ bar_window->x = x2 - add_right - bar_window->bar->current_size + 1;
bar_window->y = y1 + add_top;
- bar_window->width = bar_window->bar->size;
+ bar_window->width = bar_window->bar->current_size;
bar_window->height = y2 - y1 + 1;
break;
+ case GUI_BAR_NUM_POSITIONS:
+ /* make C compiler happy */
+ break;
}
}
@@ -195,11 +265,35 @@ gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
bar_window->y,
bar_window->x - 1);
break;
+ case GUI_BAR_NUM_POSITIONS:
+ /* make C compiler happy */
+ break;
}
}
}
/*
+ * gui_bar_window_find_pos: find position for bar window (keeping list sorted
+ * by bar number)
+ */
+
+struct t_gui_bar_window *
+gui_bar_window_find_pos (struct t_gui_bar *bar, struct t_gui_window *window)
+{
+ struct t_gui_bar_window *ptr_bar_window;
+
+ for (ptr_bar_window = GUI_CURSES(window)->bar_windows; ptr_bar_window;
+ ptr_bar_window = ptr_bar_window->next_bar_window)
+ {
+ if (ptr_bar_window->bar->number > bar->number)
+ return ptr_bar_window;
+ }
+
+ /* position not found, best position is at the end */
+ return NULL;
+}
+
+/*
* gui_bar_window_new: create a new "window bar" for a bar, in screen or a window
* if window is not NULL, bar window will be in this window
* return 1 if ok, 0 if error
@@ -208,10 +302,21 @@ gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
int
gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
{
- struct t_gui_bar_window *new_bar_window;
+ struct t_gui_bar_window *new_bar_window, *pos_bar_window;
- if (!gui_init_ok)
- return 0;
+ if (window)
+ {
+ /* bar is type "window_active" and window is not active */
+ if ((bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ && gui_current_window
+ && (gui_current_window != window))
+ return 1;
+
+ /* bar is type "window_inactive" and window is active */
+ if ((bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ && (!gui_current_window || (gui_current_window == window)))
+ return 1;
+ }
new_bar_window = malloc (sizeof (*new_bar_window));
if (new_bar_window)
@@ -220,19 +325,53 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
if (window)
{
bar->bar_window = NULL;
- new_bar_window->next_bar_window = GUI_CURSES(window)->bar_windows;
- GUI_CURSES(window)->bar_windows = new_bar_window;
+ if (GUI_CURSES(window)->bar_windows)
+ {
+ pos_bar_window = gui_bar_window_find_pos (bar, window);
+ if (pos_bar_window)
+ {
+ /* insert before bar window found */
+ new_bar_window->prev_bar_window = pos_bar_window->prev_bar_window;
+ new_bar_window->next_bar_window = pos_bar_window;
+ if (pos_bar_window->prev_bar_window)
+ (pos_bar_window->prev_bar_window)->next_bar_window = new_bar_window;
+ else
+ GUI_CURSES(window)->bar_windows = new_bar_window;
+ pos_bar_window->prev_bar_window = new_bar_window;
+ }
+ else
+ {
+ /* add to end of list for window */
+ new_bar_window->prev_bar_window = GUI_CURSES(window)->last_bar_window;
+ new_bar_window->next_bar_window = NULL;
+ (GUI_CURSES(window)->last_bar_window)->next_bar_window = new_bar_window;
+ GUI_CURSES(window)->last_bar_window = new_bar_window;
+ }
+ }
+ else
+ {
+ new_bar_window->prev_bar_window = NULL;
+ new_bar_window->next_bar_window = NULL;
+ GUI_CURSES(window)->bar_windows = new_bar_window;
+ GUI_CURSES(window)->last_bar_window = new_bar_window;
+ }
}
else
{
bar->bar_window = new_bar_window;
+ new_bar_window->prev_bar_window = NULL;
new_bar_window->next_bar_window = NULL;
}
new_bar_window->win_bar = NULL;
new_bar_window->win_separator = NULL;
- gui_bar_window_calculate_pos_size (new_bar_window, window);
- gui_bar_window_create_win (new_bar_window);
+ if (gui_init_ok)
+ {
+ gui_bar_window_calculate_pos_size (new_bar_window, window);
+ gui_bar_window_create_win (new_bar_window);
+ if (window)
+ window->refresh_needed = 1;
+ }
return 1;
}
@@ -242,12 +381,135 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
}
/*
+ * gui_bar_window_free: free a bar window
+ */
+
+void
+gui_bar_window_free (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
+{
+ /* remove window bar from list */
+ if (window)
+ {
+ if (bar_window->prev_bar_window)
+ (bar_window->prev_bar_window)->next_bar_window = bar_window->next_bar_window;
+ if (bar_window->next_bar_window)
+ (bar_window->next_bar_window)->prev_bar_window = bar_window->prev_bar_window;
+ if (GUI_CURSES(window)->bar_windows == bar_window)
+ GUI_CURSES(window)->bar_windows = bar_window->next_bar_window;
+ if (GUI_CURSES(window)->last_bar_window == bar_window)
+ GUI_CURSES(window)->last_bar_window = bar_window->prev_bar_window;
+
+ window->refresh_needed = 1;
+ }
+
+ /* free data */
+ if (bar_window->win_bar)
+ delwin (bar_window->win_bar);
+ if (bar_window->win_separator)
+ delwin (bar_window->win_separator);
+
+ free (bar_window);
+}
+
+/*
+ * gui_bar_free_bar_windows: free bar windows for a bar
+ */
+
+void
+gui_bar_free_bar_windows (struct t_gui_bar *bar)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
+
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows;
+ while (ptr_bar_win)
+ {
+ next_bar_win = ptr_bar_win->next_bar_window;
+
+ if (ptr_bar_win->bar == bar)
+ gui_bar_window_free (ptr_bar_win, ptr_win);
+
+ ptr_bar_win = next_bar_win;
+ }
+ }
+}
+
+/*
+ * gui_bar_window_remove_unused_bars: remove unused bars for a window
+ * return 1 if at least one bar was removed
+ * 0 if no bar was removed
+ */
+
+int
+gui_bar_window_remove_unused_bars (struct t_gui_window *window)
+{
+ int rc;
+ struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
+
+ rc = 0;
+
+ ptr_bar_win = GUI_CURSES(window)->bar_windows;
+ while (ptr_bar_win)
+ {
+ next_bar_win = ptr_bar_win->next_bar_window;
+
+ if (((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ && (window != gui_current_window))
+ || ((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ && (window == gui_current_window)))
+ {
+ gui_bar_window_free (ptr_bar_win, window);
+ rc = 1;
+ }
+
+ ptr_bar_win = next_bar_win;
+ }
+
+ return rc;
+}
+
+/*
+ * gui_bar_window_add_missing_bars: add missing bars for a window
+ * return 1 if at least one bar was created
+ * 0 if no bar was created
+ */
+
+int
+gui_bar_window_add_missing_bars (struct t_gui_window *window)
+{
+ int rc;
+ struct t_gui_bar *ptr_bar;
+
+ rc = 0;
+
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ if (((ptr_bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ && (window == gui_current_window))
+ || ((ptr_bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ && (window != gui_current_window)))
+ {
+ if (!gui_bar_window_search_bar (window, ptr_bar))
+ {
+ gui_bar_window_new (ptr_bar, window);
+ rc = 1;
+ }
+ }
+ }
+
+ return rc;
+}
+
+/*
* gui_bar_window_print_string: print a string text on a bar window
* return number of chars displayed on screen
*/
int
-gui_bar_window_print_string (struct t_gui_bar_window *bar_win,
+gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
char *string, int max_chars)
{
int weechat_color, num_displayed, size_on_screen;
@@ -256,11 +518,11 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_win,
if (!string || !string[0])
return 0;
- if ((bar_win->bar->position == GUI_BAR_POSITION_LEFT)
- || (bar_win->bar->position == GUI_BAR_POSITION_RIGHT))
- gui_window_set_weechat_color (bar_win->win_bar, GUI_COLOR_CHAT);
+ if ((bar_window->bar->position == GUI_BAR_POSITION_LEFT)
+ || (bar_window->bar->position == GUI_BAR_POSITION_RIGHT))
+ gui_window_set_weechat_color (bar_window->win_bar, GUI_COLOR_CHAT);
else
- gui_window_set_weechat_color (bar_win->win_bar, GUI_COLOR_STATUS);
+ gui_window_set_weechat_color (bar_window->win_bar, GUI_COLOR_STATUS);
num_displayed = 0;
@@ -276,7 +538,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_win,
str_color[2] = '\0';
string += 2;
sscanf (str_color, "%d", &weechat_color);
- gui_window_set_weechat_color (bar_win->win_bar, weechat_color);
+ gui_window_set_weechat_color (bar_window->win_bar, weechat_color);
}
}
else
@@ -291,7 +553,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_win,
if (gui_window_utf_char_valid (utf_char))
{
output = string_iconv_from_internal (NULL, utf_char);
- wprintw (bar_win->win_bar, "%s",
+ wprintw (bar_window->win_bar, "%s",
(output) ? output : utf_char);
size_on_screen = utf8_char_size_screen ((output) ?
output : utf_char);
@@ -302,7 +564,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_win,
}
else
{
- wprintw (bar_win->win_bar, ".");
+ wprintw (bar_window->win_bar, ".");
num_displayed++;
max_chars--;
}
@@ -322,29 +584,29 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_win,
*/
void
-gui_bar_window_draw (struct t_gui_window *window,
- struct t_gui_bar_window *bar_win)
+gui_bar_window_draw (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
{
int x, y, i, max_width, max_height, items_count, num_lines, line;
char *item_value, *item_value2, **items;
struct t_gui_bar_item *ptr_item;
- if ((bar_win->bar->position == GUI_BAR_POSITION_LEFT)
- || (bar_win->bar->position == GUI_BAR_POSITION_RIGHT))
- gui_window_curses_clear (bar_win->win_bar, GUI_COLOR_CHAT);
+ if ((bar_window->bar->position == GUI_BAR_POSITION_LEFT)
+ || (bar_window->bar->position == GUI_BAR_POSITION_RIGHT))
+ gui_window_curses_clear (bar_window->win_bar, GUI_COLOR_CHAT);
else
- gui_window_curses_clear (bar_win->win_bar, GUI_COLOR_STATUS);
+ gui_window_curses_clear (bar_window->win_bar, GUI_COLOR_STATUS);
- max_width = bar_win->width;
- max_height = bar_win->height;
+ max_width = bar_window->width;
+ max_height = bar_window->height;
x = 0;
y = 0;
/* for each item of bar */
- for (i = 0; i < bar_win->bar->items_count; i++)
+ for (i = 0; i < bar_window->bar->items_count; i++)
{
- ptr_item = gui_bar_item_search (bar_win->bar->items_array[i]);
+ ptr_item = gui_bar_item_search (bar_window->bar->items_array[i]);
if (ptr_item && ptr_item->build_callback)
{
item_value = (ptr_item->build_callback) (ptr_item->build_callback_data,
@@ -364,8 +626,9 @@ gui_bar_window_draw (struct t_gui_window *window,
items_count : max_height;
for (line = 0; line < num_lines; line++)
{
- wmove (bar_win->win_bar, y, x);
- x += gui_bar_window_print_string (bar_win, items[line],
+ wmove (bar_window->win_bar, y, x);
+ x += gui_bar_window_print_string (bar_window,
+ items[line],
max_width);
if (num_lines > 1)
{
@@ -383,38 +646,41 @@ gui_bar_window_draw (struct t_gui_window *window,
}
}
- wnoutrefresh (bar_win->win_bar);
+ wnoutrefresh (bar_window->win_bar);
- if (bar_win->bar->separator)
+ if (bar_window->bar->separator)
{
- switch (bar_win->bar->position)
+ switch (bar_window->bar->position)
{
case GUI_BAR_POSITION_BOTTOM:
- gui_window_set_weechat_color (bar_win->win_separator,
+ gui_window_set_weechat_color (bar_window->win_separator,
GUI_COLOR_SEPARATOR);
- mvwhline (bar_win->win_separator, 0, 0, ACS_HLINE,
- bar_win->width);
+ mvwhline (bar_window->win_separator, 0, 0, ACS_HLINE,
+ bar_window->width);
break;
case GUI_BAR_POSITION_TOP:
- gui_window_set_weechat_color (bar_win->win_separator,
+ gui_window_set_weechat_color (bar_window->win_separator,
GUI_COLOR_SEPARATOR);
- mvwhline (bar_win->win_separator, 0, 0, ACS_HLINE,
- bar_win->width);
+ mvwhline (bar_window->win_separator, 0, 0, ACS_HLINE,
+ bar_window->width);
break;
case GUI_BAR_POSITION_LEFT:
- gui_window_set_weechat_color (bar_win->win_separator,
+ gui_window_set_weechat_color (bar_window->win_separator,
GUI_COLOR_SEPARATOR);
- mvwvline (bar_win->win_separator, 0, 0, ACS_VLINE,
- bar_win->height);
+ mvwvline (bar_window->win_separator, 0, 0, ACS_VLINE,
+ bar_window->height);
break;
case GUI_BAR_POSITION_RIGHT:
- gui_window_set_weechat_color (bar_win->win_separator,
+ gui_window_set_weechat_color (bar_window->win_separator,
GUI_COLOR_SEPARATOR);
- mvwvline (bar_win->win_separator, 0, 0, ACS_VLINE,
- bar_win->height);
+ mvwvline (bar_window->win_separator, 0, 0, ACS_VLINE,
+ bar_window->height);
+ break;
+ case GUI_BAR_NUM_POSITIONS:
+ /* make C compiler happy */
break;
}
- wnoutrefresh (bar_win->win_separator);
+ wnoutrefresh (bar_window->win_separator);
}
refresh ();
@@ -433,7 +699,7 @@ gui_bar_draw (struct t_gui_bar *bar)
if (bar->bar_window)
{
/* root bar */
- gui_bar_window_draw (NULL, bar->bar_window);
+ gui_bar_window_draw (bar->bar_window, NULL);
}
else
{
@@ -445,7 +711,7 @@ gui_bar_draw (struct t_gui_bar *bar)
{
if (ptr_bar_win->bar == bar)
{
- gui_bar_window_draw (ptr_win, ptr_bar_win);
+ gui_bar_window_draw (ptr_bar_win, ptr_win);
}
}
}
@@ -453,23 +719,6 @@ gui_bar_draw (struct t_gui_bar *bar)
}
/*
- * gui_bar_window_free: delete a bar window
- */
-
-void
-gui_bar_window_free (struct t_gui_bar_window *bar_window)
-{
- /* delete Curses windows */
- if (bar_window->win_bar)
- delwin (bar_window->win_bar);
- if (bar_window->win_separator)
- delwin (bar_window->win_separator);
-
- /* free bar window */
- free (bar_window);
-}
-
-/*
* gui_bar_window_print_log: print bar window infos in log (usually for crash dump)
*/
@@ -485,4 +734,6 @@ gui_bar_window_print_log (struct t_gui_bar_window *bar_window)
log_printf (" height. . . . . . : %d", bar_window->height);
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);
+ log_printf (" next_bar_window . : 0x%x", bar_window->next_bar_window);
}
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 83dc6d005..2b1ff6d27 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -160,7 +160,7 @@ gui_chat_set_color (struct t_gui_window *window, int fg, int bg)
void
gui_chat_set_weechat_color (struct t_gui_window *window, int weechat_color)
{
- if ((weechat_color >= 0) && (weechat_color < GUI_NUM_COLORS))
+ if ((weechat_color >= 0) && (weechat_color < GUI_COLOR_NUM_COLORS))
{
gui_chat_reset_style (window);
gui_chat_set_style (window,
@@ -1394,7 +1394,7 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
}
wnoutrefresh (GUI_CURSES(ptr_win)->win_chat);
refresh ();
-
+
if (buffer->type == GUI_BUFFER_TYPE_FREE)
{
for (ptr_line = buffer->lines; ptr_line;
diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c
index 8c7476b9e..e18c04732 100644
--- a/src/gui/curses/gui-curses-color.c
+++ b/src/gui/curses/gui-curses-color.c
@@ -55,8 +55,6 @@ struct t_gui_color gui_weechat_colors[GUI_CURSES_NUM_WEECHAT_COLORS + 1] =
{ 0, 0, 0, NULL }
};
-struct t_gui_color *gui_color[GUI_NUM_COLORS];
-
/*
* gui_color_search: search a color by name
@@ -296,7 +294,7 @@ gui_color_get_pair (int num_color)
{
int fg, bg;
- if ((num_color < 0) || (num_color > GUI_NUM_COLORS - 1))
+ if ((num_color < 0) || (num_color > GUI_COLOR_NUM_COLORS - 1))
return COLOR_WHITE;
fg = gui_color[num_color]->foreground;
@@ -430,7 +428,7 @@ gui_color_rebuild_weechat ()
if (has_colors ())
{
- for (i = 0; i < GUI_NUM_COLORS; i++)
+ for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
if (gui_color[i])
{
@@ -445,6 +443,22 @@ gui_color_rebuild_weechat ()
}
/*
+ * gui_color_pre_init: pre-init colors
+ */
+
+void
+gui_color_pre_init ()
+{
+ int i;
+
+ for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
+ {
+ gui_color[i] = NULL;
+ }
+}
+
+
+/*
* gui_color_init: init GUI colors
*/
@@ -468,8 +482,8 @@ void
gui_color_end ()
{
int i;
-
- for (i = 0; i < GUI_NUM_COLORS; i++)
+
+ for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
gui_color_free (gui_color[i]);
}
diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c
index 2d7815fcf..eac8336e1 100644
--- a/src/gui/curses/gui-curses-main.c
+++ b/src/gui/curses/gui-curses-main.c
@@ -62,7 +62,10 @@ gui_main_pre_init (int *argc, char **argv[])
/* make C compiler happy */
(void) argc;
(void) argv;
-
+
+ /* pre-init colors */
+ gui_color_pre_init ();
+
/* build empty prefixes (before reading config) */
gui_chat_prefix_build_empty ();
}
@@ -76,6 +79,7 @@ gui_main_init ()
{
struct t_gui_buffer *ptr_buffer;
struct t_gui_bar *ptr_bar;
+ struct t_gui_bar_window *ptr_bar_win;
initscr ();
@@ -91,7 +95,7 @@ gui_main_init ()
gui_infobar = NULL;
- gui_ok = ((COLS > WINDOW_MIN_WIDTH) && (LINES > WINDOW_MIN_HEIGHT));
+ gui_ok = ((COLS > GUI_WINDOW_MIN_WIDTH) && (LINES > GUI_WINDOW_MIN_HEIGHT));
refresh ();
@@ -132,11 +136,14 @@ gui_main_init ()
but no window was created (GUI was not initialized) */
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- if ((ptr_bar->type == GUI_BAR_TYPE_ROOT)
- && (!ptr_bar->bar_window))
- {
+ if ((ptr_bar->type == GUI_BAR_TYPE_ROOT) && (!ptr_bar->bar_window))
gui_bar_window_new (ptr_bar, NULL);
- }
+ }
+ for (ptr_bar_win = GUI_CURSES(gui_windows)->bar_windows;
+ ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ gui_bar_window_calculate_pos_size (ptr_bar_win, gui_windows);
+ gui_bar_window_create_win (ptr_bar_win);
}
}
}
@@ -169,6 +176,7 @@ void
gui_main_loop ()
{
struct t_hook *hook_fd_keyboard;
+ struct t_gui_window *ptr_win;
struct t_gui_buffer *ptr_buffer;
struct timeval tv_timeout;
fd_set read_fds, write_fds, except_fds;
@@ -198,7 +206,7 @@ gui_main_loop ()
/* refresh window if needed */
if (gui_window_refresh_needed)
gui_window_refresh_screen (0);
-
+
/* refresh status bar if needed */
if (gui_status_refresh_needed)
{
@@ -206,6 +214,16 @@ gui_main_loop ()
gui_status_refresh_needed = 0;
}
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ if (ptr_win->refresh_needed)
+ {
+ gui_window_switch_to_buffer (ptr_win, ptr_win->buffer);
+ gui_window_redraw_buffer (ptr_win->buffer);
+ ptr_win->refresh_needed = 0;
+ }
+ }
+
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
{
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 9a356150e..be00e721f 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -74,8 +74,9 @@ int
gui_window_objects_init (struct t_gui_window *window)
{
struct t_gui_curses_objects *new_objects;
-
- if ((new_objects = malloc (sizeof (*new_objects))))
+
+ new_objects = malloc (sizeof (*new_objects));
+ if (new_objects)
{
window->gui_objects = new_objects;
GUI_CURSES(window)->win_title = NULL;
@@ -86,10 +87,10 @@ gui_window_objects_init (struct t_gui_window *window)
GUI_CURSES(window)->win_input = NULL;
GUI_CURSES(window)->win_separator = NULL;
GUI_CURSES(window)->bar_windows = NULL;
+ GUI_CURSES(window)->last_bar_window = NULL;
return 1;
}
- else
- return 0;
+ return 0;
}
/*
@@ -97,7 +98,8 @@ gui_window_objects_init (struct t_gui_window *window)
*/
void
-gui_window_objects_free (struct t_gui_window *window, int free_separator)
+gui_window_objects_free (struct t_gui_window *window, int free_separator,
+ int free_bar_windows)
{
if (GUI_CURSES(window)->win_title)
{
@@ -134,6 +136,13 @@ gui_window_objects_free (struct t_gui_window *window, int free_separator)
delwin (GUI_CURSES(window)->win_separator);
GUI_CURSES(window)->win_separator = NULL;
}
+ if (free_bar_windows)
+ {
+ while (GUI_CURSES(window)->bar_windows)
+ {
+ gui_bar_window_free (GUI_CURSES(window)->bar_windows, window);
+ }
+ }
}
/*
@@ -197,7 +206,7 @@ gui_window_curses_clear (WINDOW *window, int num_color)
void
gui_window_set_weechat_color (WINDOW *window, int num_color)
{
- if ((num_color >= 0) && (num_color < GUI_NUM_COLORS))
+ if ((num_color >= 0) && (num_color < GUI_COLOR_NUM_COLORS))
{
wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE);
wattron (window, COLOR_PAIR(gui_color_get_pair (num_color)) |
@@ -213,12 +222,19 @@ gui_window_set_weechat_color (WINDOW *window, int num_color)
int
gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate)
{
+ struct t_gui_bar_window *ptr_bar_win;
int max_length, max_height, lines, width_used;
int add_top, add_bottom, add_left, add_right;
if (!gui_ok)
return 0;
+ for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ gui_bar_window_calculate_pos_size (ptr_bar_win, window);
+ }
+
add_bottom = gui_bar_window_get_size (NULL, window, GUI_BAR_POSITION_BOTTOM);
add_top = gui_bar_window_get_size (NULL, window, GUI_BAR_POSITION_TOP);
add_left = gui_bar_window_get_size (NULL, window, GUI_BAR_POSITION_LEFT);
@@ -486,16 +502,52 @@ gui_window_redraw_all_buffers ()
}
/*
- * gui_window_switch_to_buffer: switch to another buffer
+ * gui_window_switch: switch to another window
+ */
+
+void
+gui_window_switch (struct t_gui_window *window)
+{
+ struct t_gui_window *old_window;
+ int changes;
+
+ if (gui_current_window == window)
+ return;
+
+ old_window = gui_current_window;
+
+ gui_current_window = window;
+ changes = gui_bar_window_remove_unused_bars (old_window)
+ || gui_bar_window_add_missing_bars (old_window);
+ if (changes)
+ {
+ gui_current_window = old_window;
+ gui_window_switch_to_buffer (gui_current_window,
+ gui_current_window->buffer);
+ gui_current_window = window;
+ }
+
+ gui_bar_window_remove_unused_bars (gui_current_window);
+ gui_bar_window_add_missing_bars (gui_current_window);
+ gui_window_switch_to_buffer (gui_current_window,
+ gui_current_window->buffer);
+
+ gui_window_redraw_buffer (gui_current_window->buffer);
+}
+
+/*
+ * gui_window_switch_to_buffer: switch to another buffer in a window
*/
void
gui_window_switch_to_buffer (struct t_gui_window *window,
struct t_gui_buffer *buffer)
{
+ struct t_gui_bar_window *ptr_bar_win;
+
if (!gui_ok)
return;
-
+
if (window->buffer->num_displayed > 0)
window->buffer->num_displayed--;
@@ -512,9 +564,16 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
window->win_nick_start = 0;
gui_window_calculate_pos_size (window, 1);
+
+ /* create bar windows */
+ for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ gui_bar_window_create_win (ptr_bar_win);
+ }
/* destroy Curses windows */
- gui_window_objects_free (window, 0);
+ gui_window_objects_free (window, 0, 0);
/* create Curses windows */
GUI_CURSES(window)->win_title = newwin (window->win_title_height,
@@ -570,6 +629,13 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
gui_hotlist_remove_buffer (buffer);
+ /* redraw bars in window */
+ for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ gui_bar_draw (ptr_bar_win->bar);
+ }
+
hook_signal_send ("buffer_switch",
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
}
@@ -911,7 +977,7 @@ gui_window_auto_resize (struct t_gui_window_tree *tree,
{
if (tree->window)
{
- if ((width < WINDOW_MIN_WIDTH) || (height < WINDOW_MIN_HEIGHT))
+ if ((width < GUI_WINDOW_MIN_WIDTH) || (height < GUI_WINDOW_MIN_HEIGHT))
return -1;
if (!simulate)
{
@@ -986,12 +1052,15 @@ gui_window_refresh_windows ()
gui_window_get_width () - add_left - add_right,
gui_window_get_height () - add_top - add_bottom,
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);
gui_window_draw_separator (ptr_win);
+ ptr_win->refresh_needed = 0;
}
for (ptr_buffer = gui_buffers; ptr_buffer;
@@ -1019,7 +1088,7 @@ gui_window_split_horiz (struct t_gui_window *window, int pourcentage)
height1 = (window->win_height * pourcentage) / 100;
height2 = window->win_height - height1;
- if ((height1 >= WINDOW_MIN_HEIGHT) && (height2 >= WINDOW_MIN_HEIGHT)
+ if ((height1 >= GUI_WINDOW_MIN_HEIGHT) && (height2 >= GUI_WINDOW_MIN_HEIGHT)
&& (pourcentage > 0) && (pourcentage <= 100))
{
if ((new_window = gui_window_new (window,
@@ -1037,10 +1106,8 @@ gui_window_split_horiz (struct t_gui_window *window, int pourcentage)
new_window->buffer->num_displayed++;
gui_window_switch_to_buffer (window, window->buffer);
-
- gui_current_window = new_window;
- gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer);
- gui_window_redraw_buffer (gui_current_window->buffer);
+
+ gui_window_switch (new_window);
}
}
}
@@ -1061,7 +1128,7 @@ gui_window_split_vertic (struct t_gui_window *window, int pourcentage)
width1 = (window->win_width * pourcentage) / 100;
width2 = window->win_width - width1 - 1;
- if ((width1 >= WINDOW_MIN_WIDTH) && (width2 >= WINDOW_MIN_WIDTH)
+ if ((width1 >= GUI_WINDOW_MIN_WIDTH) && (width2 >= GUI_WINDOW_MIN_WIDTH)
&& (pourcentage > 0) && (pourcentage <= 100))
{
if ((new_window = gui_window_new (window,
@@ -1079,9 +1146,7 @@ gui_window_split_vertic (struct t_gui_window *window, int pourcentage)
gui_window_switch_to_buffer (window, window->buffer);
- gui_current_window = new_window;
- gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer);
- gui_window_redraw_buffer (gui_current_window->buffer);
+ gui_window_switch (new_window);
/* create & draw separator */
gui_window_draw_separator (gui_current_window);
@@ -1294,9 +1359,7 @@ gui_window_switch_up (struct t_gui_window *window)
if ((ptr_win != window) &&
(gui_window_side_by_side (window, ptr_win) == 1))
{
- gui_current_window = ptr_win;
- gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer);
- gui_window_redraw_buffer (gui_current_window->buffer);
+ gui_window_switch (ptr_win);
return;
}
}
@@ -1320,9 +1383,7 @@ gui_window_switch_down (struct t_gui_window *window)
if ((ptr_win != window) &&
(gui_window_side_by_side (window, ptr_win) == 3))
{
- gui_current_window = ptr_win;
- gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer);
- gui_window_redraw_buffer (gui_current_window->buffer);
+ gui_window_switch (ptr_win);
return;
}
}
@@ -1346,9 +1407,7 @@ gui_window_switch_left (struct t_gui_window *window)
if ((ptr_win != window) &&
(gui_window_side_by_side (window, ptr_win) == 4))
{
- gui_current_window = ptr_win;
- gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer);
- gui_window_redraw_buffer (gui_current_window->buffer);
+ gui_window_switch (ptr_win);
return;
}
}
@@ -1372,9 +1431,7 @@ gui_window_switch_right (struct t_gui_window *window)
if ((ptr_win != window) &&
(gui_window_side_by_side (window, ptr_win) == 2))
{
- gui_current_window = ptr_win;
- gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer);
- gui_window_redraw_buffer (gui_current_window->buffer);
+ gui_window_switch (ptr_win);
return;
}
}
@@ -1400,7 +1457,8 @@ gui_window_refresh_screen (int force)
getmaxyx (stdscr, new_height, new_width);
- gui_ok = ((new_width > WINDOW_MIN_WIDTH) && (new_height > WINDOW_MIN_HEIGHT));
+ gui_ok = ((new_width > GUI_WINDOW_MIN_WIDTH)
+ && (new_height > GUI_WINDOW_MIN_HEIGHT));
if (gui_ok)
{
@@ -1514,8 +1572,9 @@ void
gui_window_objects_print_log (struct t_gui_window *window)
{
struct t_gui_bar_window *ptr_bar_win;
-
+
log_printf ("");
+ log_printf (" window specific objects:");
log_printf (" win_title . . . . . : 0x%x", GUI_CURSES(window)->win_title);
log_printf (" win_chat. . . . . . : 0x%x", GUI_CURSES(window)->win_chat);
log_printf (" win_nick. . . . . . : 0x%x", GUI_CURSES(window)->win_nick);
@@ -1523,6 +1582,12 @@ gui_window_objects_print_log (struct t_gui_window *window)
log_printf (" win_infobar . . . . : 0x%x", GUI_CURSES(window)->win_infobar);
log_printf (" win_input . . . . . : 0x%x", GUI_CURSES(window)->win_input);
log_printf (" win_separator . . . : 0x%x", GUI_CURSES(window)->win_separator);
+ log_printf (" bar_windows . . . . : 0x%x", GUI_CURSES(window)->bar_windows);
+ log_printf (" last_bar_windows. . : 0x%x", GUI_CURSES(window)->last_bar_window);
+ log_printf (" current_style_fg. . : %d", GUI_CURSES(window)->current_style_fg);
+ log_printf (" current_style_bg. . : %d", GUI_CURSES(window)->current_style_bg);
+ log_printf (" current_style_attr. : %d", GUI_CURSES(window)->current_style_attr);
+ log_printf (" current_color_attr. : %d", GUI_CURSES(window)->current_color_attr);
for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
ptr_bar_win = ptr_bar_win->next_bar_window)
diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h
index d42cbe9da..3a2d9d3e4 100644
--- a/src/gui/curses/gui-curses.h
+++ b/src/gui/curses/gui-curses.h
@@ -28,8 +28,11 @@
#include <curses.h>
#endif
-#define WINDOW_MIN_WIDTH 10
-#define WINDOW_MIN_HEIGHT 5
+#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
#define GUI_CURSES_NUM_WEECHAT_COLORS 15
@@ -42,9 +45,10 @@ struct t_gui_bar_window
int width, height; /* window size */
WINDOW *win_bar; /* bar Curses window */
WINDOW *win_separator; /* separator (optional) */
- struct t_gui_bar_window *next_bar_window;
- /* link to next bar window */
- /* (only used if bar is in windows) */
+ 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 */
+ /* (only for non-root bars) */
};
struct t_gui_curses_objects
@@ -56,7 +60,8 @@ struct t_gui_curses_objects
WINDOW *win_infobar; /* info bar window */
WINDOW *win_input; /* input window */
WINDOW *win_separator; /* separation between 2 splited (V) win */
- struct t_gui_bar_window *bar_windows; /* bar windows */
+ struct t_gui_bar_window *bar_windows; /* bar windows */
+ struct t_gui_bar_window *last_bar_window; /* last bar window */
int current_style_fg; /* current foreground color */
int current_style_bg; /* current background color */
int current_style_attr; /* current attributes (bold, ..) */
@@ -67,6 +72,7 @@ extern struct t_gui_color gui_weechat_colors[];
/* color functions */
extern int gui_color_get_pair (int num_color);
+extern void gui_color_pre_init ();
extern void gui_color_init ();
extern void gui_color_end ();
@@ -74,6 +80,8 @@ extern void gui_color_end ();
extern void gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
struct t_gui_window *window);
extern void gui_bar_window_create_win (struct t_gui_bar_window *bar_window);
+extern int gui_bar_window_remove_unused_bars (struct t_gui_window *window);
+extern int gui_bar_window_add_missing_bars (struct t_gui_window *window);
/* chat functions */
extern void gui_chat_calculate_line_diff (struct t_gui_window *window,
diff --git a/src/gui/gtk/gui-gtk-bar.c b/src/gui/gtk/gui-gtk-bar.c
index 6c726bc8a..570cbed10 100644
--- a/src/gui/gtk/gui-gtk-bar.c
+++ b/src/gui/gtk/gui-gtk-bar.c
@@ -35,14 +35,34 @@
/*
- * gui_bar_windows_get_size: get total bar size (window bars) for a position
- * bar is optional, if not NULL, size is computed
- * from bar 1 to bar # - 1
+ * gui_bar_window_search_bar: search a reference to a bar in a window
+ */
+
+struct t_gui_bar_window *
+gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar)
+{
+ struct t_gui_bar_window *ptr_bar_win;
+
+ for (ptr_bar_win = GUI_GTK(window)->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if (ptr_bar_win->bar == bar)
+ return ptr_bar_win;
+ }
+
+ /* bar window not found for window */
+ return NULL;
+}
+
+/*
+ * gui_bar_window_get_size: get total bar size (window bars) for a position
+ * bar is optional, if not NULL, size is computed
+ * from bar 1 to bar # - 1
*/
int
gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
- int position)
+ enum t_gui_bar_position position)
{
(void) bar;
(void) window;
@@ -53,6 +73,69 @@ gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
}
/*
+ * gui_bar_check_size_add: check if "add_size" is ok for bar
+ * return 1 if new size is ok
+ * 0 if new size is too big
+ */
+
+int
+gui_bar_check_size_add (struct t_gui_bar *bar, int add_size)
+{
+ (void) bar;
+ (void) add_size;
+
+ /* TODO: write this function for Gtk */
+ return 1;
+}
+
+/*
+ * gui_bar_window_calculate_pos_size: calculate position and size of a bar
+ */
+
+void
+gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
+{
+ (void) bar_window;
+ (void) window;
+
+ /* TODO: write this function for Gtk */
+}
+
+/*
+ * gui_bar_window_create_win: create curses window for bar
+ */
+
+void
+gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
+{
+ (void) bar_window;
+
+ /* TODO: write this function for Gtk */
+}
+
+/*
+ * gui_bar_window_find_pos: find position for bar window (keeping list sorted
+ * by bar number)
+ */
+
+struct t_gui_bar_window *
+gui_bar_window_find_pos (struct t_gui_bar *bar, struct t_gui_window *window)
+{
+ struct t_gui_bar_window *ptr_bar_window;
+
+ for (ptr_bar_window = GUI_GTK(window)->bar_windows; ptr_bar_window;
+ ptr_bar_window = ptr_bar_window->next_bar_window)
+ {
+ if (ptr_bar_window->bar->number > bar->number)
+ return ptr_bar_window;
+ }
+
+ /* position not found, best position is at the end */
+ return NULL;
+}
+
+/*
* gui_bar_window_new: create a new "window bar" for a bar, in screen or a window
* if window is not NULL, bar window will be in this window
*/
@@ -68,28 +151,151 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
}
/*
- * gui_bar_draw: draw a bar
+ * gui_bar_window_free: free a bar window
*/
void
-gui_bar_draw (struct t_gui_bar *bar)
+gui_bar_window_free (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
{
- (void) bar;
+ (void) bar_window;
+ (void) window;
+
+ /* TODO: write this function for Gtk */
+}
+
+/*
+ * gui_bar_free_bar_windows: free bar windows for a bar
+ */
+
+void
+gui_bar_free_bar_windows (struct t_gui_bar *bar)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
+
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ ptr_bar_win = GUI_GTK(gui_windows)->bar_windows;
+ while (ptr_bar_win)
+ {
+ next_bar_win = ptr_bar_win->next_bar_window;
+
+ if (ptr_bar_win->bar == bar)
+ gui_bar_window_free (ptr_bar_win, ptr_win);
+
+ ptr_bar_win = next_bar_win;
+ }
+ }
+}
+
+/*
+ * gui_bar_window_remove_unused_bars: remove unused bars for a window
+ * return 1 if at least one bar was removed
+ * 0 if no bar was removed
+ */
+
+int
+gui_bar_window_remove_unused_bars (struct t_gui_window *window)
+{
+ int rc;
+ struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
+
+ rc = 0;
+
+ ptr_bar_win = GUI_GTK(window)->bar_windows;
+ while (ptr_bar_win)
+ {
+ next_bar_win = ptr_bar_win->next_bar_window;
+
+ if (((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ && (window != gui_current_window))
+ || ((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ && (window == gui_current_window)))
+ {
+ gui_bar_window_free (ptr_bar_win, window);
+ rc = 1;
+ }
+
+ ptr_bar_win = next_bar_win;
+ }
+
+ return rc;
+}
+
+/*
+ * gui_bar_window_add_missing_bars: add missing bars for a window
+ * return 1 if at least one bar was created
+ * 0 if no bar was created
+ */
+
+int
+gui_bar_window_add_missing_bars (struct t_gui_window *window)
+{
+ int rc;
+ struct t_gui_bar *ptr_bar;
+
+ rc = 0;
+
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ if (((ptr_bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ && (window == gui_current_window))
+ || ((ptr_bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ && (window != gui_current_window)))
+ {
+ if (!gui_bar_window_search_bar (window, ptr_bar))
+ {
+ gui_bar_window_new (ptr_bar, window);
+ rc = 1;
+ }
+ }
+ }
+
+ return rc;
+}
+
+/*
+ * gui_bar_window_print_string: print a string text on a bar window
+ * return number of chars displayed on screen
+ */
+int
+gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
+ char *string, int max_chars)
+{
+ (void) bar_window;
+ (void) string;
+ (void) max_chars;
+
/* TODO: write this function for Gtk */
+ return 0;
}
/*
- * gui_bar_window_free: delete an bar window
+ * gui_bar_window_draw: draw a bar for a window
*/
void
-gui_bar_window_free (struct t_gui_bar_window *bar_window)
+gui_bar_window_draw (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
{
- /* TODO: complete this function for Gtk */
+ (void) bar_window;
+ (void) window;
- /* free bar window */
- free (bar_window);
+ /* TODO: write this function for Gtk */
+}
+
+/*
+ * gui_bar_draw: draw a bar
+ */
+
+void
+gui_bar_draw (struct t_gui_bar *bar)
+{
+ (void) bar;
+
+ /* TODO: write this function for Gtk */
}
/*
@@ -106,4 +312,6 @@ 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 (" prev_bar_window . : 0x%x", bar_window->prev_bar_window);
+ log_printf (" next_bar_window . : 0x%x", bar_window->next_bar_window);
}
diff --git a/src/gui/gtk/gui-gtk-color.c b/src/gui/gtk/gui-gtk-color.c
index 77d3dcbf8..cb04d3d1a 100644
--- a/src/gui/gtk/gui-gtk-color.c
+++ b/src/gui/gtk/gui-gtk-color.c
@@ -54,8 +54,6 @@ struct t_gui_color gui_weechat_colors[] =
{ 0, 0, 0, NULL }
};
-struct t_gui_color *gui_color[GUI_NUM_COLORS];
-
/*
* gui_color_search: search a color by name
@@ -121,7 +119,7 @@ gui_color_get_pair (int num_color)
{
int fg, bg;
- if ((num_color < 0) || (num_color > GUI_NUM_COLORS - 1))
+ if ((num_color < 0) || (num_color > GUI_COLOR_NUM_COLORS - 1))
return WEECHAT_COLOR_WHITE;
fg = gui_color[num_color]->foreground;
@@ -167,7 +165,7 @@ gui_color_rebuild_weechat ()
{
int i;
- for (i = 0; i < GUI_NUM_COLORS; i++)
+ for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
if (gui_color[i])
{
@@ -181,6 +179,21 @@ gui_color_rebuild_weechat ()
}
/*
+ * gui_color_pre_init: pre-init colors
+ */
+
+void
+gui_color_pre_init ()
+{
+ int i;
+
+ for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
+ {
+ gui_color[i] = NULL;
+ }
+}
+
+/*
* gui_color_init: init GUI colors
*/
@@ -200,7 +213,7 @@ gui_color_end ()
{
int i;
- for (i = 0; i < GUI_NUM_COLORS; i++)
+ for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
gui_color_free (gui_color[i]);
}
diff --git a/src/gui/gtk/gui-gtk-main.c b/src/gui/gtk/gui-gtk-main.c
index b00ce369f..d2f216e02 100644
--- a/src/gui/gtk/gui-gtk-main.c
+++ b/src/gui/gtk/gui-gtk-main.c
@@ -63,6 +63,9 @@ GtkWidget *gui_gtk_label1;
void
gui_main_pre_init (int *argc, char **argv[])
{
+ /* pre-init colors */
+ gui_color_pre_init ();
+
/* build empty prefixes (before reading config) */
gui_chat_prefix_build_empty ();
diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c
index 0c34d1815..5db023317 100644
--- a/src/gui/gtk/gui-gtk-window.c
+++ b/src/gui/gtk/gui-gtk-window.c
@@ -30,6 +30,7 @@
#include "../../core/wee-config.h"
#include "../../core/wee-log.h"
#include "../gui-window.h"
+#include "../gui-bar.h"
#include "../gui-buffer.h"
#include "../gui-chat.h"
#include "../gui-hotlist.h"
@@ -67,7 +68,7 @@ int
gui_window_objects_init (struct t_gui_window *window)
{
struct t_gui_gtk_objects *new_objects;
-
+
if ((new_objects = malloc (sizeof (*new_objects))))
{
window->gui_objects = new_objects;
@@ -77,10 +78,10 @@ gui_window_objects_init (struct t_gui_window *window)
GUI_GTK(window)->textview_nicklist = NULL;
GUI_GTK(window)->textbuffer_nicklist = NULL;
GUI_GTK(window)->bar_windows = NULL;
+ GUI_GTK(window)->last_bar_window = NULL;
return 1;
}
- else
- return 0;
+ return 0;
}
/*
@@ -88,11 +89,13 @@ gui_window_objects_init (struct t_gui_window *window)
*/
void
-gui_window_objects_free (struct t_gui_window *window, int free_separator)
+gui_window_objects_free (struct t_gui_window *window, int free_separator,
+ int free_bar_windows)
{
/* TODO: write this function for Gtk */
(void) window;
(void) free_separator;
+ (void) free_bar_windows;
}
/*
@@ -172,6 +175,26 @@ gui_window_redraw_all_buffers ()
}
/*
+ * gui_window_switch: switch to another window
+ */
+
+void
+gui_window_switch (struct t_gui_window *window)
+{
+ if (gui_current_window == window)
+ return;
+
+ /* remove unused bars from current window */
+ /* ... */
+
+ gui_current_window = window;
+
+ gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer);
+
+ gui_window_redraw_buffer (gui_current_window->buffer);
+}
+
+/*
* gui_window_switch_to_buffer: switch to another buffer
*/
@@ -927,6 +950,12 @@ gui_window_objects_print_log (struct t_gui_window *window)
log_printf (" texttag_chat. . . . : 0x%x", GUI_GTK(window)->texttag_chat);
log_printf (" textview_nicklist . : 0x%x", GUI_GTK(window)->textview_nicklist);
log_printf (" textbuffer_nicklist : 0x%x", GUI_GTK(window)->textbuffer_nicklist);
+ log_printf (" bar_windows . . . . : 0x%x", GUI_GTK(window)->bar_windows);
+ log_printf (" last_bar_windows. . : 0x%x", GUI_GTK(window)->last_bar_window);
+ log_printf (" current_style_fg. . : %d", GUI_GTK(window)->current_style_fg);
+ log_printf (" current_style_bg. . : %d", GUI_GTK(window)->current_style_bg);
+ log_printf (" current_style_attr. : %d", GUI_GTK(window)->current_style_attr);
+ log_printf (" current_color_attr. : %d", GUI_GTK(window)->current_color_attr);
for (ptr_bar_win = GUI_GTK(window)->bar_windows; ptr_bar_win;
ptr_bar_win = ptr_bar_win->next_bar_window)
diff --git a/src/gui/gtk/gui-gtk.h b/src/gui/gtk/gui-gtk.h
index ffe8ef707..6aaba6840 100644
--- a/src/gui/gtk/gui-gtk.h
+++ b/src/gui/gtk/gui-gtk.h
@@ -59,9 +59,10 @@ struct t_gui_bar_window
struct t_gui_bar *bar; /* pointer to bar */
int x, y; /* position of window */
int width, height; /* window size */
- struct t_gui_bar_window *next_bar_window;
- /* link to next bar window */
- /* (only used if bar is in windows) */
+ 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 */
+ /* (only for non-root bars) */
};
struct t_gui_gtk_objects
@@ -71,7 +72,8 @@ struct t_gui_gtk_objects
GtkTextTag *texttag_chat; /* texttag widget for chat */
GtkWidget *textview_nicklist; /* textview widget for nicklist */
GtkTextBuffer *textbuffer_nicklist; /* textbuffer widget for nicklist */
- struct t_gui_bar_window *bar_windows; /* bar windows */
+ struct t_gui_bar_window *bar_windows; /* bar windows */
+ struct t_gui_bar_window *last_bar_window; /* last bar window */
int current_style_fg; /* current foreground color */
int current_style_bg; /* current background color */
int current_style_attr; /* current attributes (bold, ..) */
@@ -95,6 +97,7 @@ extern GtkWidget *gui_gtk_label1;
/* color functions */
extern int gui_color_get_pair (int num_color);
+extern void gui_color_pre_init ();
extern void gui_color_init ();
extern void gui_color_end ();
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index c5cce18b8..5de3a1a4d 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -350,9 +350,9 @@ 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_NAME),
+ GUI_COLOR(GUI_COLOR_STATUS),
(window->buffer->lines_hidden) ? "," : "",
(window->buffer->lines_hidden) ? _("filtered") : "",
GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS));
diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c
index d5cec0517..e11797556 100644
--- a/src/gui/gui-bar.c
+++ b/src/gui/gui-bar.c
@@ -34,7 +34,7 @@
char *gui_bar_type_str[GUI_BAR_NUM_TYPES] =
-{ "root", "window_active", "window_inactive" };
+{ "root", "window", "window_active", "window_inactive" };
char *gui_bar_position_str[GUI_BAR_NUM_POSITIONS] =
{ "bottom", "top", "left", "right" };
@@ -43,11 +43,51 @@ struct t_gui_bar *last_gui_bar = NULL; /* last bar */
/*
+ * gui_bar_get_type: get type number with string
+ * return -1 if type is not found
+ */
+
+int
+gui_bar_get_type (char *type)
+{
+ int i;
+
+ for (i = 0; i < GUI_BAR_NUM_TYPES; i++)
+ {
+ if (string_strcasecmp (type, gui_bar_type_str[i]) == 0)
+ return i;
+ }
+
+ /* type not found */
+ return -1;
+}
+
+/*
+ * gui_bar_get_position: get position number with string
+ * return -1 if type is not found
+ */
+
+int
+gui_bar_get_position (char *position)
+{
+ int i;
+
+ for (i = 0; i < GUI_BAR_NUM_POSITIONS; i++)
+ {
+ if (string_strcasecmp (position, gui_bar_position_str[i]) == 0)
+ return i;
+ }
+
+ /* position not found */
+ return -1;
+}
+
+/*
* gui_bar_root_get_size: get total bar size ("root" type) for a position
*/
int
-gui_bar_root_get_size (struct t_gui_bar *bar, int position)
+gui_bar_root_get_size (struct t_gui_bar *bar, enum t_gui_bar_position position)
{
struct t_gui_bar *ptr_bar;
int total_size;
@@ -61,7 +101,7 @@ gui_bar_root_get_size (struct t_gui_bar *bar, int position)
if ((ptr_bar->type == GUI_BAR_TYPE_ROOT)
&& (ptr_bar->position == position))
{
- total_size += ptr_bar->size;
+ total_size += ptr_bar->current_size;
if (ptr_bar->separator)
total_size++;
}
@@ -101,7 +141,7 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
{
struct t_gui_bar *new_bar;
struct t_gui_window *ptr_win;
- int i, type_value, position_value;
+ int type_value, position_value;
if (!name || !name[0])
return NULL;
@@ -111,28 +151,12 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
return NULL;
/* look for type */
- type_value = -1;
- for (i = 0; i < GUI_BAR_NUM_TYPES; i++)
- {
- if (string_strcasecmp (type, gui_bar_type_str[i]) == 0)
- {
- type_value = i;
- break;
- }
- }
+ type_value = gui_bar_get_type (type);
if (type_value < 0)
return NULL;
/* look for position */
- position_value = -1;
- for (i = 0; i < GUI_BAR_NUM_POSITIONS; i++)
- {
- if (string_strcasecmp (position, gui_bar_position_str[i]) == 0)
- {
- position_value = i;
- break;
- }
- }
+ position_value = gui_bar_get_position (position);
if (position_value < 0)
return NULL;
@@ -146,6 +170,7 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
new_bar->type = type_value;
new_bar->position = position_value;
new_bar->size = size;
+ new_bar->current_size = (size == 0) ? 1 : size;
new_bar->separator = separator;
if (items && items[0])
{
@@ -161,10 +186,21 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
}
new_bar->bar_window = NULL;
+ /* add bar to bars queue */
+ new_bar->prev_bar = last_gui_bar;
+ if (gui_bars)
+ last_gui_bar->next_bar = new_bar;
+ else
+ gui_bars = new_bar;
+ last_gui_bar = new_bar;
+ new_bar->next_bar = NULL;
+
+ /* add window bar */
if (type_value == GUI_BAR_TYPE_ROOT)
{
/* create only one window for bar */
gui_bar_window_new (new_bar, NULL);
+ gui_window_refresh_needed = 1;
}
else
{
@@ -176,17 +212,6 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
}
}
- /* add bar to bars queue */
- new_bar->prev_bar = last_gui_bar;
- if (gui_bars)
- last_gui_bar->next_bar = new_bar;
- else
- gui_bars = new_bar;
- last_gui_bar = new_bar;
- new_bar->next_bar = NULL;
-
- gui_window_refresh_needed = 1;
-
return new_bar;
}
@@ -195,6 +220,128 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
}
/*
+ * gui_bar_set_name: set name for a bar
+ */
+
+void
+gui_bar_set_name (struct t_gui_bar *bar, char *name)
+{
+ if (name && name[0])
+ {
+ if (bar->name)
+ free (bar->name);
+ bar->name = strdup (name);
+ }
+}
+
+/*
+ * gui_bar_set_type: set type for a bar
+ */
+
+void
+gui_bar_set_type (struct t_gui_bar *bar, char *type)
+{
+ int type_value;
+
+ (void) bar;
+
+ if (type && type[0])
+ {
+ type_value = gui_bar_get_type (type);
+ if (type_value >= 0)
+ {
+ }
+ }
+}
+
+/*
+ * gui_bar_set_size: set size for a bar
+ */
+
+void
+gui_bar_set_size (struct t_gui_bar *bar, int size)
+{
+ if (size >= 0)
+ {
+ /* check if new size is ok */
+ if (size > bar->current_size
+ && !gui_bar_check_size_add (bar, size - bar->current_size))
+ return;
+
+ bar->size = size;
+ bar->current_size = (size == 0) ? 1 : size;
+ }
+}
+
+/*
+ * gui_bar_set_items: set items for a bar
+ */
+
+void
+gui_bar_set_items (struct t_gui_bar *bar, char *items)
+{
+ if (bar->items)
+ free (bar->items);
+ if (bar->items_array)
+ string_free_exploded (bar->items_array);
+
+ if (items && items[0])
+ {
+ bar->items = strdup (items);
+ bar->items_array = string_explode (items, ",", 0, 0,
+ &bar->items_count);
+ }
+ else
+ {
+ bar->items = NULL;
+ bar->items_count = 0;
+ bar->items_array = NULL;
+ }
+}
+
+/*
+ * gui_bar_set: set a property for bar
+ */
+
+void
+gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
+{
+ long number;
+ char *error;
+
+ if (!bar || !property || !value)
+ return;
+
+ if (string_strcasecmp (property, "name") == 0)
+ {
+ gui_bar_set_name (bar, value);
+ }
+ else if (string_strcasecmp (property, "type") == 0)
+ {
+ gui_bar_set_type (bar, value);
+ }
+ else if (string_strcasecmp (property, "position") == 0)
+ {
+
+ }
+ else if (string_strcasecmp (property, "size") == 0)
+ {
+ error = NULL;
+ number = strtol (value, &error, 10);
+ if (error && !error[0])
+ gui_bar_set_size (bar, number);
+ }
+ else if (string_strcasecmp (property, "separator") == 0)
+ {
+ bar->separator = (string_strcasecmp (value, "1") == 0) ? 1 : 0;
+ }
+ else if (string_strcasecmp (property, "items") == 0)
+ {
+ gui_bar_set_items (bar, value);
+ }
+}
+
+/*
* gui_bar_update: update a bar on screen
*/
@@ -217,11 +364,20 @@ gui_bar_update (char *name)
void
gui_bar_free (struct t_gui_bar *bar)
{
+ /* remove bar window(s) */
+ if (bar->bar_window)
+ {
+ gui_bar_window_free (bar->bar_window, NULL);
+ gui_window_refresh_needed = 1;
+ }
+ else
+ gui_bar_free_bar_windows (bar);
+
/* remove bar from bars list */
if (bar->prev_bar)
- bar->prev_bar->next_bar = bar->next_bar;
+ (bar->prev_bar)->next_bar = bar->next_bar;
if (bar->next_bar)
- bar->next_bar->prev_bar = bar->prev_bar;
+ (bar->next_bar)->prev_bar = bar->prev_bar;
if (gui_bars == bar)
gui_bars = bar->next_bar;
if (last_gui_bar == bar)
@@ -230,16 +386,12 @@ gui_bar_free (struct t_gui_bar *bar)
/* free data */
if (bar->name)
free (bar->name);
- if (bar->bar_window)
- gui_bar_window_free (bar->bar_window);
if (bar->items)
free (bar->items);
if (bar->items_array)
string_free_exploded (bar->items_array);
free (bar);
-
- gui_window_refresh_needed = 1;
}
/*
@@ -299,6 +451,7 @@ gui_bar_print_log ()
ptr_bar->position,
gui_bar_position_str[ptr_bar->position]);
log_printf (" size . . . . . . . . . : %d", ptr_bar->size);
+ log_printf (" current_size . . . . . : %d", ptr_bar->current_size);
log_printf (" separator. . . . . . . : %d", ptr_bar->separator);
log_printf (" items. . . . . . . . . : '%s'", 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 3844bd184..f5d487e53 100644
--- a/src/gui/gui-bar.h
+++ b/src/gui/gui-bar.h
@@ -26,6 +26,7 @@ struct t_gui_window;
enum t_gui_bar_type
{
GUI_BAR_TYPE_ROOT = 0,
+ GUI_BAR_TYPE_WINDOW,
GUI_BAR_TYPE_WINDOW_ACTIVE,
GUI_BAR_TYPE_WINDOW_INACTIVE,
/* number of bar types */
@@ -45,22 +46,23 @@ enum t_gui_bar_position
struct t_gui_bar
{
/* user choices */
- struct t_weechat_plugin *plugin; /* plugin */
- int number; /* bar number */
- char *name; /* bar name */
- int type; /* type (root or window) */
- int position; /* position (bottom, top, left, right) */
- int size; /* size of bar (in chars) */
- int separator; /* 1 if separator (line) displayed */
- char *items; /* bar items */
+ struct t_weechat_plugin *plugin; /* plugin */
+ int number; /* bar number */
+ char *name; /* bar name */
+ int type; /* type (root or window) */
+ enum t_gui_bar_position position; /* bottom, top, left, right */
+ int size; /* size of bar (in chars, 0 = auto) */
+ int separator; /* 1 if separator (line) displayed */
+ char *items; /* bar items */
/* internal vars */
- int items_count; /* number of bar items */
- char **items_array; /* exploded bar items */
+ int current_size; /* current bar size (strictly > 0) */
+ int items_count; /* number of bar items */
+ char **items_array; /* exploded bar items */
struct t_gui_bar_window *bar_window; /* pointer to bar window */
- /* (for type root only) */
- struct t_gui_bar *prev_bar; /* link to previous bar */
- struct t_gui_bar *next_bar; /* link to next bar */
+ /* (for type root only) */
+ struct t_gui_bar *prev_bar; /* link to previous bar */
+ struct t_gui_bar *next_bar; /* link to next bar */
};
/* variables */
@@ -72,11 +74,15 @@ extern struct t_gui_bar *last_gui_bar;
/* functions */
-extern int gui_bar_root_get_size (struct t_gui_bar *bar, int position);
+extern int gui_bar_get_type (char *type);
+extern int gui_bar_get_position (char *position);
+extern int gui_bar_root_get_size (struct t_gui_bar *bar,
+ enum t_gui_bar_position position);
extern struct t_gui_bar *gui_bar_search (char *name);
extern struct t_gui_bar *gui_bar_new (struct t_weechat_plugin *plugin,
char *name, char *type, char *position,
int size, int separator, char *items);
+extern void gui_bar_set (struct t_gui_bar *bar, char *property, char *value);
extern void gui_bar_update (char *name);
extern void gui_bar_free (struct t_gui_bar *bar);
extern void gui_bar_free_all ();
@@ -86,10 +92,14 @@ extern void gui_bar_print_log ();
/* functions (GUI dependent) */
extern int gui_bar_window_get_size (struct t_gui_bar *bar,
- struct t_gui_window *window, int position);
+ struct t_gui_window *window,
+ enum t_gui_bar_position position);
+extern int gui_bar_check_size_add (struct t_gui_bar *bar, int add_size);
extern int gui_bar_window_new (struct t_gui_bar *bar,
struct t_gui_window *window);
-extern void gui_bar_window_free (struct t_gui_bar_window *bar_window);
+extern void gui_bar_window_free (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window);
+extern void gui_bar_free_bar_windows (struct t_gui_bar *bar);
extern void gui_bar_draw (struct t_gui_bar *bar);
extern void gui_bar_window_print_log (struct t_gui_bar_window *bar_window);
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 229a832f7..8bd38dc04 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -289,11 +289,12 @@ gui_buffer_set_name (struct t_gui_buffer *buffer, char *name)
if (buffer->name)
free (buffer->name);
buffer->name = strdup (name);
+
+ gui_status_refresh_needed = 1;
+
+ hook_signal_send ("buffer_renamed",
+ WEECHAT_HOOK_SIGNAL_POINTER, buffer);
}
- gui_status_refresh_needed = 1;
-
- hook_signal_send ("buffer_renamed",
- WEECHAT_HOOK_SIGNAL_POINTER, buffer);
}
/*
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index 75e723a2a..45ccf0760 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -39,6 +39,9 @@
#include "gui-color.h"
+struct t_gui_color *gui_color[GUI_COLOR_NUM_COLORS]; /* GUI colors */
+
+
/*
* gui_color_search_config: search a color with configuration option name
* return color found (number >= 0), -1 if not found
diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h
index a8c1f671f..83de11aa7 100644
--- a/src/gui/gui-color.h
+++ b/src/gui/gui-color.h
@@ -103,7 +103,8 @@ enum t_gui_color_enum
GUI_COLOR_INFO_FAILED,
GUI_COLOR_INFO_ABORTED,
- GUI_NUM_COLORS,
+ /* number of colors */
+ GUI_COLOR_NUM_COLORS,
};
/* WeeChat internal color attributes (should never be in protocol messages) */
@@ -141,7 +142,7 @@ struct t_gui_color
/* color variables */
-extern struct t_gui_color *gui_color[GUI_NUM_COLORS];
+extern struct t_gui_color *gui_color[];
/* color functions */
diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c
index e505838f2..e0d9ce8eb 100644
--- a/src/gui/gui-completion.c
+++ b/src/gui/gui-completion.c
@@ -40,6 +40,7 @@
#include "../plugins/plugin.h"
#include "../plugins/plugin-config.h"
#include "gui-completion.h"
+#include "gui-bar.h"
#include "gui-buffer.h"
#include "gui-color.h"
#include "gui-keyboard.h"
@@ -245,6 +246,22 @@ gui_completion_list_add (struct t_gui_completion *completion, char *word,
}
/*
+ * gui_completion_list_add_bars_names: add buffers names to completion list
+ */
+
+void
+gui_completion_list_add_bars_names (struct t_gui_completion *completion)
+{
+ struct t_gui_bar *ptr_bar;
+
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ gui_completion_list_add (completion, ptr_bar->name,
+ 0, WEECHAT_LIST_POS_SORT);
+ }
+}
+
+/*
* gui_completion_list_add_buffers_names: add buffers names to completion list
*/
@@ -785,6 +802,9 @@ gui_completion_build_list_template (struct t_gui_completion *completion,
case 'q': /* quit message */
gui_completion_list_add_quit (completion);
break;
+ case 'r': /* bar names */
+ gui_completion_list_add_bars_names (completion);
+ break;
case 'v': /* value of config option */
gui_completion_list_add_option_value (completion);
break;
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index 1655a37c7..b7c49e946 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -37,6 +37,7 @@
#include "../core/wee-log.h"
#include "../core/wee-utf8.h"
#include "gui-window.h"
+#include "gui-bar.h"
#include "gui-buffer.h"
#include "gui-chat.h"
#include "gui-filter.h"
@@ -129,6 +130,7 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
{
struct t_gui_window *new_window;
struct t_gui_window_tree *ptr_tree, *child1, *child2, *ptr_leaf;
+ struct t_gui_bar *ptr_bar;
#ifdef DEBUG
log_printf ("Creating new window (x:%d, y:%d, width:%d, height:%d)",
@@ -188,11 +190,13 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
if ((new_window = (malloc (sizeof (*new_window)))))
{
+ /* create window objects */
if (!gui_window_objects_init (new_window))
{
free (new_window);
return NULL;
}
+
new_window->win_x = x;
new_window->win_y = y;
new_window->win_width = width;
@@ -241,6 +245,8 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
new_window->win_input_height = 0;
new_window->win_input_cursor_x = 0;
+ new_window->refresh_needed = 0;
+
new_window->dcc_first = NULL;
new_window->dcc_selected = NULL;
new_window->dcc_last_displayed = NULL;
@@ -263,6 +269,13 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
gui_windows = new_window;
last_gui_window = new_window;
new_window->next_window = NULL;
+
+ /* create bar windows */
+ 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, new_window);
+ }
}
else
return NULL;
@@ -283,7 +296,7 @@ gui_window_free (struct t_gui_window *window)
/* free data */
if (window->gui_objects)
{
- gui_window_objects_free (window, 1);
+ gui_window_objects_free (window, 1, 1);
free (window->gui_objects);
}
@@ -381,12 +394,8 @@ gui_window_switch_previous (struct t_gui_window *window)
if (!gui_ok)
return;
- /* if only one window then return */
- if (gui_windows == last_gui_window)
- return;
-
- gui_current_window = (window->prev_window) ? window->prev_window : last_gui_window;
- gui_window_redraw_buffer (gui_current_window->buffer);
+ gui_window_switch ((window->prev_window) ?
+ window->prev_window : last_gui_window);
}
/*
@@ -399,12 +408,8 @@ gui_window_switch_next (struct t_gui_window *window)
if (!gui_ok)
return;
- /* if only one window then return */
- if (gui_windows == last_gui_window)
- return;
-
- gui_current_window = (window->next_window) ? window->next_window : gui_windows;
- gui_window_redraw_buffer (gui_current_window->buffer);
+ gui_window_switch ((window->next_window) ?
+ window->next_window : gui_windows);
}
/*
@@ -424,8 +429,7 @@ gui_window_switch_by_buffer (struct t_gui_window *window, int buffer_number)
{
if (ptr_win->buffer->number == buffer_number)
{
- gui_current_window = ptr_win;
- gui_window_redraw_buffer (gui_current_window->buffer);
+ gui_window_switch (ptr_win);
return;
}
ptr_win = (ptr_win->next_window) ? ptr_win->next_window : gui_windows;
@@ -836,7 +840,6 @@ gui_window_print_log ()
log_printf (" win_input_width . . : %d", ptr_window->win_input_width);
log_printf (" win_input_height. . : %d", ptr_window->win_input_height);
log_printf (" win_input_cursor_x. : %d", ptr_window->win_input_cursor_x);
- gui_window_objects_print_log (ptr_window);
log_printf (" dcc_first . . . . . : 0x%x", ptr_window->dcc_first);
log_printf (" dcc_selected. . . . : 0x%x", ptr_window->dcc_selected);
log_printf (" dcc_last_displayed. : 0x%x", ptr_window->dcc_last_displayed);
@@ -846,5 +849,6 @@ gui_window_print_log ()
log_printf (" start_line_pos. . . : %d", ptr_window->start_line_pos);
log_printf (" prev_window . . . . : 0x%x", ptr_window->prev_window);
log_printf (" next_window . . . . : 0x%x", ptr_window->next_window);
+ gui_window_objects_print_log (ptr_window);
}
}
diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h
index 567975a33..cedb0d2a2 100644
--- a/src/gui/gui-window.h
+++ b/src/gui/gui-window.h
@@ -77,6 +77,9 @@ struct t_gui_window
int win_input_height; /* height of input window */
int win_input_cursor_x; /* position of cursor in input win */
+ /* refresh */
+ int refresh_needed; /* 1 if refresh needed for window */
+
/* GUI specific objects */
void *gui_objects; /* pointer to a GUI specific struct */
@@ -146,11 +149,13 @@ extern int gui_window_get_width ();
extern int gui_window_get_height ();
extern int gui_window_objects_init (struct t_gui_window *window);
extern void gui_window_objects_free (struct t_gui_window *window,
- int free_separator);
+ int free_separator,
+ int free_bar_windows);
extern int gui_window_calculate_pos_size (struct t_gui_window *window,
int force_calculate);
extern void gui_window_redraw_buffer (struct t_gui_buffer *buffer);
extern void gui_window_redraw_all_buffers ();
+extern void gui_window_switch (struct t_gui_window *window);
extern void gui_window_switch_to_buffer (struct t_gui_window *window,
struct t_gui_buffer *buffer);
extern void gui_window_page_up (struct t_gui_window *window);