1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-08 02:33:12 +02:00

Fix too many refreshs for bars (build content of items when bar is displayed)

This commit is contained in:
Sebastien Helleu
2008-12-19 16:47:24 +01:00
parent 896f509861
commit 7f15535a5c
4 changed files with 61 additions and 37 deletions
+1 -1
View File
@@ -377,7 +377,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
filling = gui_bar_get_filling (bar_window->bar);
content = gui_bar_window_content_get_with_filling (bar_window);
content = gui_bar_window_content_get_with_filling (bar_window, window);
if (content)
{
items = string_explode (content, "\n", 0, 0, &items_count);
+2 -8
View File
@@ -453,10 +453,7 @@ gui_bar_item_update (const char *item_name)
{
if (ptr_bar->bar_window)
{
gui_bar_window_content_build_item (ptr_bar->bar_window,
NULL,
index_item,
index_subitem);
ptr_bar->bar_window->items_refresh_needed[index_item][index_subitem] = 1;
}
else
{
@@ -469,10 +466,7 @@ gui_bar_item_update (const char *item_name)
{
if (ptr_bar_window->bar == ptr_bar)
{
gui_bar_window_content_build_item (ptr_bar_window,
ptr_window,
index_item,
index_subitem);
ptr_bar_window->items_refresh_needed[index_item][index_subitem] = 1;
}
}
}
+55 -24
View File
@@ -246,6 +246,8 @@ gui_bar_window_content_alloc (struct t_gui_bar_window *bar_window)
sizeof (*bar_window->items_subcount));
bar_window->items_content = malloc ((bar_window->items_count) *
sizeof (*bar_window->items_content));
bar_window->items_refresh_needed = malloc (bar_window->items_count *
sizeof (*bar_window->items_refresh_needed));
if (bar_window->items_content)
{
for (i = 0; i < bar_window->items_count; i++)
@@ -253,12 +255,14 @@ gui_bar_window_content_alloc (struct t_gui_bar_window *bar_window)
bar_window->items_subcount[i] = bar_window->bar->items_subcount[i];
bar_window->items_content[i] = malloc (bar_window->items_subcount[i] *
sizeof (**bar_window->items_content));
if (bar_window->items_content[i])
bar_window->items_refresh_needed[i] = malloc (bar_window->items_subcount[i] *
sizeof (**bar_window->items_refresh_needed));
for (j = 0; j < bar_window->items_subcount[i]; j++)
{
for (j = 0; j < bar_window->items_subcount[i]; j++)
{
if (bar_window->items_content[i])
bar_window->items_content[i][j] = NULL;
}
if (bar_window->items_refresh_needed[i])
bar_window->items_refresh_needed[i][j] = 1;
}
}
}
@@ -277,18 +281,21 @@ gui_bar_window_content_free (struct t_gui_bar_window *bar_window)
{
for (i = 0; i < bar_window->items_count; i++)
{
if (bar_window->items_content[i])
for (j = 0; j < bar_window->items_subcount[i]; j++)
{
for (j = 0; j < bar_window->items_subcount[i]; j++)
if (bar_window->items_content[i]
&& bar_window->items_content[i][j])
{
if (bar_window->items_content[i][j])
free (bar_window->items_content[i][j]);
free (bar_window->items_content[i][j]);
}
free (bar_window->items_content[i]);
}
free (bar_window->items_content[i]);
free (bar_window->items_refresh_needed[i]);
}
free (bar_window->items_content);
bar_window->items_content = NULL;
free (bar_window->items_refresh_needed);
bar_window->items_refresh_needed = NULL;
}
}
@@ -317,6 +324,7 @@ gui_bar_window_content_build_item (struct t_gui_bar_window *bar_window,
bar_window->items_content[index_item][index_subitem] =
gui_bar_item_get_value (bar_window->bar->items_array[index_item][index_subitem],
bar_window->bar, window);
bar_window->items_refresh_needed[index_item][index_subitem] = 0;
}
}
@@ -344,6 +352,27 @@ gui_bar_window_content_build (struct t_gui_bar_window *bar_window,
}
}
/*
* gui_bar_window_content_get: get item or subitem content (first rebuild
* content if refresh is needed)
*/
char *
gui_bar_window_content_get (struct t_gui_bar_window *bar_window,
struct t_gui_window *window,
int index_item, int index_subitem)
{
/* rebuild content if refresh is needed */
if (bar_window->items_refresh_needed[index_item][index_subitem])
{
gui_bar_window_content_build_item (bar_window, window,
index_item, index_subitem);
}
/* return content */
return bar_window->items_content[index_item][index_subitem];
}
/*
* gui_bar_window_content_get_with_filling: get content of a bar window,
* formated for display, according
@@ -351,14 +380,15 @@ gui_bar_window_content_build (struct t_gui_bar_window *bar_window,
*/
char *
gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window)
gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
struct t_gui_window *window)
{
enum t_gui_bar_filling filling;
char *content, reinit_color[32], reinit_color_space[32], *item_value;
char *ptr_content, *content, reinit_color[32], reinit_color_space[32];
char *item_value, ****splitted_items, **linear_items;
int index_content, content_length, i, sub, j, k, index;
int length_reinit_color, length_reinit_color_space;
int length, max_length, max_length_screen, total_items, columns, lines;
char ****splitted_items, **linear_items;
snprintf (reinit_color, sizeof (reinit_color),
"%c%c%02d,%02d",
@@ -387,13 +417,13 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window)
{
for (sub = 0; sub < bar_window->items_subcount[i]; sub++)
{
if (bar_window->items_content[i][sub]
&& bar_window->items_content[i][sub][0])
ptr_content = gui_bar_window_content_get (bar_window, window,
i, sub);
if (ptr_content && ptr_content[0])
{
if (gui_bar_get_filling (bar_window->bar) == GUI_BAR_FILLING_HORIZONTAL)
{
item_value = string_replace (bar_window->items_content[i][sub],
"\n",
item_value = string_replace (ptr_content, "\n",
reinit_color_space);
}
else
@@ -401,14 +431,13 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window)
if (!content)
{
content_length += strlen ((item_value) ?
item_value : bar_window->items_content[i][sub]);
content = strdup ((item_value) ?
item_value : bar_window->items_content[i][sub]);
item_value : ptr_content);
content = strdup ((item_value) ? item_value : ptr_content);
}
else
{
content_length += length_reinit_color_space +
strlen ((item_value) ? item_value : bar_window->items_content[i][sub]);
strlen ((item_value) ? item_value : ptr_content);
content = realloc (content, content_length);
if (sub == 0)
{
@@ -423,7 +452,7 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window)
strcat (content, reinit_color);
}
strcat (content,
(item_value) ? item_value : bar_window->items_content[i][sub]);
(item_value) ? item_value : ptr_content);
}
if (item_value)
free (item_value);
@@ -444,10 +473,11 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window)
splitted_items[i] = malloc (bar_window->items_subcount[i] * sizeof (**splitted_items));
for (sub = 0; sub < bar_window->items_subcount[i]; sub++)
{
if (bar_window->items_content[i][sub]
&& bar_window->items_content[i][sub][0])
ptr_content = gui_bar_window_content_get (bar_window, window,
i, sub);
if (ptr_content && ptr_content[0])
{
splitted_items[i][sub] = string_explode (bar_window->items_content[i][sub],
splitted_items[i][sub] = string_explode (ptr_content,
"\n", 0, 0, NULL);
for (j = 0; splitted_items[i][sub][j]; j++)
{
@@ -647,6 +677,7 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
new_bar_window->items_count = 0;
new_bar_window->items_subcount = NULL;
new_bar_window->items_content = NULL;
new_bar_window->items_refresh_needed = NULL;
gui_bar_window_objects_init (new_bar_window);
gui_bar_window_content_build (new_bar_window, window);
+3 -4
View File
@@ -35,6 +35,7 @@ struct t_gui_bar_window
int items_count; /* number of bar items */
int *items_subcount; /* number of sub items */
char ***items_content; /* content for each item/sub item of bar*/
int **items_refresh_needed; /* refresh needed for (sub)item? */
void *gui_objects; /* pointer to a GUI specific struct */
struct t_gui_bar_window *prev_bar_window; /* link to previous bar win */
/* (only for non-root bars) */
@@ -47,12 +48,10 @@ struct t_gui_bar_window
extern int gui_bar_window_valid (struct t_gui_bar_window *bar_window);
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_content_build_item (struct t_gui_bar_window *bar_window,
struct t_gui_window *window,
int index_item, int index_subitem);
extern void gui_bar_window_content_build (struct t_gui_bar_window *bar_window,
struct t_gui_window *window);
extern char *gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window);
extern char *gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
struct t_gui_window *window);
extern struct t_gui_bar_window *gui_bar_window_search_bar (struct t_gui_window *window,
struct t_gui_bar *bar);
extern int gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window);