mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 15:53:12 +02:00
Added conditions for bar display and bar max size
This commit is contained in:
@@ -304,15 +304,8 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
|
||||
|
||||
if (window)
|
||||
{
|
||||
/* bar is type "window_active" and window is not active */
|
||||
if ((CONFIG_INTEGER(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 ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
|
||||
&& (!gui_current_window || (gui_current_window == window)))
|
||||
if ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_WINDOW)
|
||||
&& (!gui_bar_check_conditions_for_window (bar, window)))
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -488,10 +481,8 @@ gui_bar_window_remove_unused_bars (struct t_gui_window *window)
|
||||
{
|
||||
next_bar_win = ptr_bar_win->next_bar_window;
|
||||
|
||||
if (((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
|
||||
&& (window != gui_current_window))
|
||||
|| ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
|
||||
&& (window == gui_current_window)))
|
||||
if ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW)
|
||||
&& (!gui_bar_check_conditions_for_window (ptr_bar_win->bar, window)))
|
||||
{
|
||||
gui_bar_window_free (ptr_bar_win, window);
|
||||
rc = 1;
|
||||
@@ -519,10 +510,8 @@ gui_bar_window_add_missing_bars (struct t_gui_window *window)
|
||||
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
if (((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
|
||||
&& (window == gui_current_window))
|
||||
|| ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
|
||||
&& (window != gui_current_window)))
|
||||
if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW)
|
||||
&& gui_bar_check_conditions_for_window (ptr_bar, window))
|
||||
{
|
||||
if (!gui_bar_window_search_bar (window, ptr_bar))
|
||||
{
|
||||
|
||||
@@ -317,6 +317,8 @@ gui_chat_draw_title (struct t_gui_buffer *buffer, int erase)
|
||||
|
||||
if (title_decoded)
|
||||
free (title_decoded);
|
||||
|
||||
buffer->title_refresh_needed = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1276,6 +1278,8 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
|
||||
ptr_line->refresh_needed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
buffer->chat_refresh_needed = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -423,4 +423,6 @@ gui_input_draw (struct t_gui_buffer *buffer, int erase)
|
||||
refresh ();
|
||||
}
|
||||
}
|
||||
|
||||
buffer->input_refresh_needed = 0;
|
||||
}
|
||||
|
||||
@@ -206,14 +206,11 @@ gui_main_loop ()
|
||||
|
||||
/* refresh window if needed */
|
||||
if (gui_window_refresh_needed)
|
||||
gui_window_refresh_screen (0);
|
||||
gui_window_refresh_screen ();
|
||||
|
||||
/* refresh status bar if needed */
|
||||
if (gui_status_refresh_needed)
|
||||
{
|
||||
gui_status_draw (1);
|
||||
gui_status_refresh_needed = 0;
|
||||
}
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
@@ -230,29 +227,22 @@ gui_main_loop ()
|
||||
{
|
||||
/* refresh title if needed */
|
||||
if (ptr_buffer->title_refresh_needed)
|
||||
{
|
||||
gui_chat_draw_title (ptr_buffer, 1);
|
||||
ptr_buffer->title_refresh_needed = 0;
|
||||
}
|
||||
|
||||
/* refresh chat if needed */
|
||||
if (ptr_buffer->chat_refresh_needed)
|
||||
{
|
||||
gui_chat_draw (ptr_buffer,
|
||||
(ptr_buffer->chat_refresh_needed) > 1 ? 1 : 0);
|
||||
ptr_buffer->chat_refresh_needed = 0;
|
||||
}
|
||||
|
||||
/* refresh nicklist if needed */
|
||||
if (ptr_buffer->nicklist_refresh_needed)
|
||||
{
|
||||
gui_nicklist_draw (ptr_buffer, 1);
|
||||
ptr_buffer->nicklist_refresh_needed = 0;
|
||||
}
|
||||
|
||||
/* refresh input if needed */
|
||||
if (ptr_buffer->input_refresh_needed)
|
||||
{
|
||||
gui_input_draw (ptr_buffer, 1);
|
||||
ptr_buffer->input_refresh_needed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* wait for keyboard or network activity */
|
||||
|
||||
@@ -316,4 +316,6 @@ gui_nicklist_draw (struct t_gui_buffer *buffer, int erase)
|
||||
refresh ();
|
||||
}
|
||||
}
|
||||
|
||||
buffer->nicklist_refresh_needed = 0;
|
||||
}
|
||||
|
||||
@@ -249,4 +249,6 @@ gui_status_draw (int erase)
|
||||
wnoutrefresh (GUI_CURSES(ptr_win)->win_status);
|
||||
refresh ();
|
||||
}
|
||||
|
||||
gui_status_refresh_needed = 0;
|
||||
}
|
||||
|
||||
@@ -501,40 +501,6 @@ gui_window_redraw_all_buffers ()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@@ -544,6 +510,7 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
|
||||
struct t_gui_buffer *buffer)
|
||||
{
|
||||
struct t_gui_bar_window *ptr_bar_win;
|
||||
struct t_gui_buffer *old_buffer;
|
||||
|
||||
if (!gui_ok)
|
||||
return;
|
||||
@@ -551,6 +518,8 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
|
||||
if (window->buffer->num_displayed > 0)
|
||||
window->buffer->num_displayed--;
|
||||
|
||||
old_buffer = window->buffer;
|
||||
|
||||
if (window->buffer != buffer)
|
||||
{
|
||||
window->start_line = NULL;
|
||||
@@ -565,8 +534,14 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
|
||||
window->win_title_start = 0;
|
||||
window->win_nick_start = 0;
|
||||
|
||||
if (old_buffer == buffer)
|
||||
{
|
||||
gui_bar_window_remove_unused_bars (window);
|
||||
gui_bar_window_add_missing_bars (window);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -624,6 +599,12 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
|
||||
buffer->num_displayed++;
|
||||
|
||||
gui_hotlist_remove_buffer (buffer);
|
||||
|
||||
if (buffer != old_buffer)
|
||||
{
|
||||
gui_bar_window_remove_unused_bars (window);
|
||||
gui_bar_window_add_missing_bars (window);
|
||||
}
|
||||
|
||||
/* redraw bars in window */
|
||||
for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
|
||||
@@ -636,6 +617,38 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
|
||||
WEECHAT_HOOK_SIGNAL_POINTER, 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_window_switch_to_buffer (gui_current_window,
|
||||
gui_current_window->buffer);
|
||||
|
||||
gui_window_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_page_up: display previous page on buffer
|
||||
*/
|
||||
@@ -1548,29 +1561,25 @@ gui_window_switch_right (struct t_gui_window *window)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_refresh_screen (int force)
|
||||
gui_window_refresh_screen ()
|
||||
{
|
||||
int new_height, new_width;
|
||||
|
||||
if (force || (gui_window_refresh_needed == 1))
|
||||
endwin ();
|
||||
refresh ();
|
||||
|
||||
getmaxyx (stdscr, new_height, new_width);
|
||||
|
||||
gui_ok = ((new_width >= GUI_WINDOW_MIN_WIDTH)
|
||||
&& (new_height >= GUI_WINDOW_MIN_HEIGHT));
|
||||
|
||||
if (gui_ok)
|
||||
{
|
||||
endwin ();
|
||||
refresh ();
|
||||
|
||||
getmaxyx (stdscr, new_height, new_width);
|
||||
|
||||
gui_ok = ((new_width >= GUI_WINDOW_MIN_WIDTH)
|
||||
&& (new_height >= GUI_WINDOW_MIN_HEIGHT));
|
||||
|
||||
if (gui_ok)
|
||||
{
|
||||
refresh ();
|
||||
gui_window_refresh_windows ();
|
||||
}
|
||||
gui_window_refresh_windows ();
|
||||
}
|
||||
|
||||
if (gui_window_refresh_needed > 0)
|
||||
gui_window_refresh_needed = 0;
|
||||
gui_window_refresh_needed = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1581,7 +1590,6 @@ void
|
||||
gui_window_refresh_screen_sigwinch ()
|
||||
{
|
||||
gui_window_refresh_needed = 1;
|
||||
//gui_window_refresh_screen (0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -208,11 +208,9 @@ gui_bar_window_remove_unused_bars (struct t_gui_window *window)
|
||||
while (ptr_bar_win)
|
||||
{
|
||||
next_bar_win = ptr_bar_win->next_bar_window;
|
||||
|
||||
if (((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
|
||||
&& (window != gui_current_window))
|
||||
|| ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
|
||||
&& (window == gui_current_window)))
|
||||
|
||||
if ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW)
|
||||
&& (!gui_bar_check_conditions_for_window (ptr_bar_win->bar, window)))
|
||||
{
|
||||
gui_bar_window_free (ptr_bar_win, window);
|
||||
rc = 1;
|
||||
@@ -240,10 +238,8 @@ gui_bar_window_add_missing_bars (struct t_gui_window *window)
|
||||
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
if (((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
|
||||
&& (window == gui_current_window))
|
||||
|| ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
|
||||
&& (window != gui_current_window)))
|
||||
if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW)
|
||||
&& gui_bar_check_conditions_for_window (ptr_bar, window))
|
||||
{
|
||||
if (!gui_bar_window_search_bar (window, ptr_bar))
|
||||
{
|
||||
|
||||
+256
-29
@@ -32,14 +32,15 @@
|
||||
#include "../core/wee-log.h"
|
||||
#include "../core/wee-string.h"
|
||||
#include "gui-bar.h"
|
||||
#include "gui-buffer.h"
|
||||
#include "gui-chat.h"
|
||||
#include "gui-window.h"
|
||||
|
||||
|
||||
char *gui_bar_option_str[GUI_BAR_NUM_OPTIONS] =
|
||||
{ "type", "position", "size", "separator", "items" };
|
||||
{ "type", "conditions", "position", "size", "size_max", "separator", "items" };
|
||||
char *gui_bar_type_str[GUI_BAR_NUM_TYPES] =
|
||||
{ "root", "window", "window_active", "window_inactive" };
|
||||
{ "root", "window" };
|
||||
char *gui_bar_position_str[GUI_BAR_NUM_POSITIONS] =
|
||||
{ "bottom", "top", "left", "right" };
|
||||
|
||||
@@ -114,6 +115,40 @@ gui_bar_search_position (char *position)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_check_conditions_for_window: return 1 if bar should be displayed in
|
||||
* this window, according to condition(s)
|
||||
* on bar
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_check_conditions_for_window (struct t_gui_bar *bar,
|
||||
struct t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < bar->conditions_count; i++)
|
||||
{
|
||||
if (string_strcasecmp (bar->conditions_array[i], "active") == 0)
|
||||
{
|
||||
if (gui_current_window && (gui_current_window != window))
|
||||
return 0;
|
||||
}
|
||||
else if (string_strcasecmp (bar->conditions_array[i], "inactive") == 0)
|
||||
{
|
||||
if (!gui_current_window || (gui_current_window == window))
|
||||
return 0;
|
||||
}
|
||||
else if (string_strcasecmp (bar->conditions_array[i], "nicklist") == 0)
|
||||
{
|
||||
if (window->buffer && !window->buffer->nicklist)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_root_get_size: get total bar size ("root" type) for a position
|
||||
*/
|
||||
@@ -254,6 +289,40 @@ gui_bar_config_check_type (void *data, struct t_config_option *option,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_config_change_conditions: callback when conditions is changed
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_config_change_conditions (void *data, struct t_config_option *option)
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
ptr_bar = gui_bar_search_with_option_name (option->name);
|
||||
if (ptr_bar)
|
||||
{
|
||||
if (ptr_bar->conditions_array)
|
||||
string_free_exploded (ptr_bar->conditions_array);
|
||||
|
||||
if (CONFIG_STRING(ptr_bar->conditions) && CONFIG_STRING(ptr_bar->conditions)[0])
|
||||
{
|
||||
ptr_bar->conditions_array = string_explode (CONFIG_STRING(ptr_bar->conditions),
|
||||
",", 0, 0,
|
||||
&ptr_bar->conditions_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr_bar->conditions_count = 0;
|
||||
ptr_bar->conditions_array = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
gui_window_refresh_needed = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_config_change_position: callback when position is changed
|
||||
*/
|
||||
@@ -306,7 +375,6 @@ gui_bar_config_check_size (void *data, struct t_config_option *option,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* gui_bar_config_change_size: callback when size is changed
|
||||
*/
|
||||
@@ -328,6 +396,31 @@ gui_bar_config_change_size (void *data, struct t_config_option *option)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_config_change_size_max: callback when max size is changed
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_config_change_size_max (void *data, struct t_config_option *option)
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
ptr_bar = gui_bar_search_with_option_name (option->name);
|
||||
if (ptr_bar)
|
||||
{
|
||||
if ((CONFIG_INTEGER(ptr_bar->size_max) > 0)
|
||||
&& (ptr_bar->current_size > CONFIG_INTEGER(ptr_bar->size_max)))
|
||||
{
|
||||
gui_bar_set_current_size (ptr_bar,
|
||||
CONFIG_INTEGER(ptr_bar->size_max));
|
||||
}
|
||||
gui_window_refresh_needed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_config_change_separator: callback when separator is changed
|
||||
*/
|
||||
@@ -398,10 +491,14 @@ gui_bar_set_name (struct t_gui_bar *bar, char *name)
|
||||
{
|
||||
snprintf (option_name, length, "%s.type", name);
|
||||
config_file_option_rename (bar->type, option_name);
|
||||
snprintf (option_name, length, "%s.conditions", name);
|
||||
config_file_option_rename (bar->conditions, option_name);
|
||||
snprintf (option_name, length, "%s.position", name);
|
||||
config_file_option_rename (bar->position, option_name);
|
||||
snprintf (option_name, length, "%s.size", name);
|
||||
config_file_option_rename (bar->size, option_name);
|
||||
snprintf (option_name, length, "%s.size_max", name);
|
||||
config_file_option_rename (bar->size_max, option_name);
|
||||
snprintf (option_name, length, "%s.separator", name);
|
||||
config_file_option_rename (bar->separator, option_name);
|
||||
snprintf (option_name, length, "%s.items", name);
|
||||
@@ -535,6 +632,10 @@ gui_bar_set_current_size (struct t_gui_bar *bar, int current_size)
|
||||
if (current_size == 0)
|
||||
current_size = 1;
|
||||
|
||||
if ((CONFIG_INTEGER(bar->size_max) > 0)
|
||||
&& (current_size > CONFIG_INTEGER(bar->size_max)))
|
||||
current_size = CONFIG_INTEGER(bar->size_max);
|
||||
|
||||
/* check if new size is ok if it's more than before */
|
||||
if (current_size > bar->current_size
|
||||
&& !gui_bar_check_size_add (bar, current_size - bar->current_size))
|
||||
@@ -584,48 +685,50 @@ gui_bar_set_size (struct t_gui_bar *bar, char *size)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_set_items: set items for a bar
|
||||
* gui_bar_set_size_max: set max size for a bar
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_set_items (struct t_gui_bar *bar, char *items)
|
||||
gui_bar_set_size_max (struct t_gui_bar *bar, char *size)
|
||||
{
|
||||
config_file_option_set (bar->items, items, 1);
|
||||
long number;
|
||||
char *error, value[32];
|
||||
|
||||
if (bar->items_array)
|
||||
string_free_exploded (bar->items_array);
|
||||
|
||||
if (CONFIG_STRING(bar->items) && CONFIG_STRING(bar->items)[0])
|
||||
error = NULL;
|
||||
number = strtol (size, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
bar->items_array = string_explode (CONFIG_STRING(bar->items),
|
||||
",", 0, 0,
|
||||
&bar->items_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
bar->items_count = 0;
|
||||
bar->items_array = NULL;
|
||||
if (number < 0)
|
||||
return;
|
||||
|
||||
snprintf (value, sizeof (value), "%ld", number);
|
||||
config_file_option_set (bar->size_max, value, 1);
|
||||
|
||||
if ((number > 0) && (number < bar->current_size))
|
||||
gui_bar_set_size (bar, value);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_set: set a property for bar
|
||||
* return: 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
void
|
||||
int
|
||||
gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
|
||||
{
|
||||
long number;
|
||||
char *error;
|
||||
|
||||
if (!bar || !property || !value)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
if (string_strcasecmp (property, "name") == 0)
|
||||
{
|
||||
gui_bar_set_name (bar, value);
|
||||
return 1;
|
||||
}
|
||||
if (string_strcasecmp (property, "number") == 0)
|
||||
else if (string_strcasecmp (property, "number") == 0)
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (value, &error, 10);
|
||||
@@ -634,16 +737,31 @@ gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
|
||||
gui_bar_set_number (bar, number);
|
||||
gui_window_refresh_needed = 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if (string_strcasecmp (property, "conditions") == 0)
|
||||
{
|
||||
config_file_option_set (bar->conditions, value, 1);
|
||||
gui_window_refresh_needed = 1;
|
||||
return 1;
|
||||
}
|
||||
else if (string_strcasecmp (property, "position") == 0)
|
||||
{
|
||||
gui_bar_set_position (bar, value);
|
||||
gui_bar_refresh (bar);
|
||||
return 1;
|
||||
}
|
||||
else if (string_strcasecmp (property, "size") == 0)
|
||||
{
|
||||
gui_bar_set_size (bar, value);
|
||||
gui_bar_refresh (bar);
|
||||
return 1;
|
||||
}
|
||||
else if (string_strcasecmp (property, "size_max") == 0)
|
||||
{
|
||||
gui_bar_set_size_max (bar, value);
|
||||
gui_bar_refresh (bar);
|
||||
return 1;
|
||||
}
|
||||
else if (string_strcasecmp (property, "separator") == 0)
|
||||
{
|
||||
@@ -651,12 +769,16 @@ gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
|
||||
(strcmp (value, "1") == 0) ? "on" : "off",
|
||||
1);
|
||||
gui_bar_refresh (bar);
|
||||
return 1;
|
||||
}
|
||||
else if (string_strcasecmp (property, "items") == 0)
|
||||
{
|
||||
gui_bar_set_items (bar, value);
|
||||
config_file_option_set (bar->items, value, 1);
|
||||
gui_bar_draw (bar);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -675,11 +797,15 @@ gui_bar_alloc (char *name)
|
||||
new_bar->number = 0;
|
||||
new_bar->name = strdup (name);
|
||||
new_bar->type = NULL;
|
||||
new_bar->conditions = NULL;
|
||||
new_bar->position = NULL;
|
||||
new_bar->size = NULL;
|
||||
new_bar->size_max = NULL;
|
||||
new_bar->separator = NULL;
|
||||
new_bar->items = NULL;
|
||||
new_bar->current_size = 1;
|
||||
new_bar->conditions_count = 0;
|
||||
new_bar->conditions_array = NULL;
|
||||
new_bar->items_count = 0;
|
||||
new_bar->items_array = NULL;
|
||||
new_bar->bar_window = NULL;
|
||||
@@ -720,6 +846,15 @@ gui_bar_create_option (char *bar_name, int index_option, char *value)
|
||||
"root|window|window_active|window_inactive", 0, 0, value,
|
||||
&gui_bar_config_check_type, NULL, NULL, NULL, NULL, NULL);
|
||||
break;
|
||||
case GUI_BAR_OPTION_CONDITIONS:
|
||||
ptr_option = config_file_new_option (
|
||||
weechat_config_file, weechat_config_section_bar,
|
||||
option_name, "string",
|
||||
N_("condition(s) for displaying bar (for bars of type "
|
||||
"\"window\")"),
|
||||
NULL, 0, 0, value,
|
||||
NULL, NULL, &gui_bar_config_change_conditions, NULL, NULL, NULL);
|
||||
break;
|
||||
case GUI_BAR_OPTION_POSITION:
|
||||
ptr_option = config_file_new_option (
|
||||
weechat_config_file, weechat_config_section_bar,
|
||||
@@ -738,6 +873,16 @@ gui_bar_create_option (char *bar_name, int index_option, char *value)
|
||||
&gui_bar_config_change_size, NULL,
|
||||
NULL, NULL);
|
||||
break;
|
||||
case GUI_BAR_OPTION_SIZE_MAX:
|
||||
ptr_option = config_file_new_option (
|
||||
weechat_config_file, weechat_config_section_bar,
|
||||
option_name, "integer",
|
||||
N_("max bar size in chars (0 = no limit)"),
|
||||
NULL, 0, INT_MAX, value,
|
||||
NULL, NULL,
|
||||
&gui_bar_config_change_size_max, NULL,
|
||||
NULL, NULL);
|
||||
break;
|
||||
case GUI_BAR_OPTION_SEPARATOR:
|
||||
ptr_option = config_file_new_option (
|
||||
weechat_config_file, weechat_config_section_bar,
|
||||
@@ -769,8 +914,10 @@ gui_bar_create_option (char *bar_name, int index_option, char *value)
|
||||
struct t_gui_bar *
|
||||
gui_bar_new_with_options (struct t_weechat_plugin *plugin, char *name,
|
||||
struct t_config_option *type,
|
||||
struct t_config_option *conditions,
|
||||
struct t_config_option *position,
|
||||
struct t_config_option *size,
|
||||
struct t_config_option *size_max,
|
||||
struct t_config_option *separator,
|
||||
struct t_config_option *items)
|
||||
{
|
||||
@@ -784,10 +931,23 @@ gui_bar_new_with_options (struct t_weechat_plugin *plugin, char *name,
|
||||
new_bar->plugin = plugin;
|
||||
new_bar->number = (last_gui_bar) ? last_gui_bar->number + 1 : 1;
|
||||
new_bar->type = type;
|
||||
new_bar->conditions = conditions;
|
||||
if (CONFIG_STRING(conditions) && CONFIG_STRING(conditions)[0])
|
||||
{
|
||||
new_bar->conditions_array = string_explode (CONFIG_STRING(conditions),
|
||||
",", 0, 0,
|
||||
&new_bar->conditions_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
new_bar->conditions_count = 0;
|
||||
new_bar->conditions_array = NULL;
|
||||
}
|
||||
new_bar->position = position;
|
||||
new_bar->size = size;
|
||||
new_bar->current_size = (CONFIG_INTEGER(size) == 0) ?
|
||||
1 : CONFIG_INTEGER(size);
|
||||
new_bar->size_max = size_max;
|
||||
new_bar->separator = separator;
|
||||
new_bar->items = items;
|
||||
if (CONFIG_STRING(items) && CONFIG_STRING(items)[0])
|
||||
@@ -839,11 +999,12 @@ gui_bar_new_with_options (struct t_weechat_plugin *plugin, char *name,
|
||||
|
||||
struct t_gui_bar *
|
||||
gui_bar_new (struct t_weechat_plugin *plugin, char *name,
|
||||
char *type, char *position, char *size, char *separators,
|
||||
char *items)
|
||||
char *type, char *conditions, char *position, char *size,
|
||||
char *size_max, char *separators, char *items)
|
||||
{
|
||||
struct t_config_option *option_type, *option_position, *option_size;
|
||||
struct t_config_option *option_separator, *option_items;
|
||||
struct t_config_option *option_type, *option_conditions, *option_position;
|
||||
struct t_config_option *option_size, *option_size_max, *option_separator;
|
||||
struct t_config_option *option_items;
|
||||
struct t_gui_bar *new_bar;
|
||||
|
||||
if (!name || !name[0])
|
||||
@@ -863,26 +1024,35 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name,
|
||||
|
||||
option_type = gui_bar_create_option (name, GUI_BAR_OPTION_TYPE,
|
||||
type);
|
||||
option_conditions = gui_bar_create_option (name, GUI_BAR_OPTION_CONDITIONS,
|
||||
conditions);
|
||||
option_position = gui_bar_create_option (name, GUI_BAR_OPTION_POSITION,
|
||||
position);
|
||||
option_size = gui_bar_create_option (name, GUI_BAR_OPTION_SIZE,
|
||||
size);
|
||||
option_size_max = gui_bar_create_option (name, GUI_BAR_OPTION_SIZE_MAX,
|
||||
size_max);
|
||||
option_separator = gui_bar_create_option (name, GUI_BAR_OPTION_SEPARATOR,
|
||||
(config_file_string_to_boolean (separators)) ?
|
||||
"on" : "off");
|
||||
option_items = gui_bar_create_option (name, GUI_BAR_OPTION_ITEMS,
|
||||
items);
|
||||
new_bar = gui_bar_new_with_options (plugin, name, option_type,
|
||||
option_position, option_size,
|
||||
option_conditions, option_position,
|
||||
option_size, option_size_max,
|
||||
option_separator, option_items);
|
||||
if (!new_bar)
|
||||
{
|
||||
if (option_type)
|
||||
config_file_option_free (option_type);
|
||||
if (option_conditions)
|
||||
config_file_option_free (option_conditions);
|
||||
if (option_position)
|
||||
config_file_option_free (option_position);
|
||||
if (option_size)
|
||||
config_file_option_free (option_size);
|
||||
if (option_size_max)
|
||||
config_file_option_free (option_size_max);
|
||||
if (option_separator)
|
||||
config_file_option_free (option_separator);
|
||||
if (option_items)
|
||||
@@ -904,14 +1074,51 @@ gui_bar_use_temp_bars ()
|
||||
for (ptr_temp_bar = gui_temp_bars; ptr_temp_bar;
|
||||
ptr_temp_bar = ptr_temp_bar->next_bar)
|
||||
{
|
||||
if (ptr_temp_bar->type && ptr_temp_bar->position
|
||||
&& ptr_temp_bar->size && ptr_temp_bar->separator
|
||||
if (!ptr_temp_bar->type)
|
||||
ptr_temp_bar->type = gui_bar_create_option (ptr_temp_bar->name,
|
||||
GUI_BAR_OPTION_TYPE,
|
||||
"0");
|
||||
if (!ptr_temp_bar->conditions)
|
||||
ptr_temp_bar->conditions = gui_bar_create_option (ptr_temp_bar->name,
|
||||
GUI_BAR_OPTION_CONDITIONS,
|
||||
"");
|
||||
|
||||
if (!ptr_temp_bar->position)
|
||||
ptr_temp_bar->position = gui_bar_create_option (ptr_temp_bar->name,
|
||||
GUI_BAR_OPTION_POSITION,
|
||||
"top");
|
||||
|
||||
if (!ptr_temp_bar->size)
|
||||
ptr_temp_bar->size = gui_bar_create_option (ptr_temp_bar->name,
|
||||
GUI_BAR_OPTION_SIZE,
|
||||
"0");
|
||||
|
||||
if (!ptr_temp_bar->size_max)
|
||||
ptr_temp_bar->size_max = gui_bar_create_option (ptr_temp_bar->name,
|
||||
GUI_BAR_OPTION_SIZE_MAX,
|
||||
"0");
|
||||
|
||||
if (!ptr_temp_bar->separator)
|
||||
ptr_temp_bar->separator = gui_bar_create_option (ptr_temp_bar->name,
|
||||
GUI_BAR_OPTION_SEPARATOR,
|
||||
"off");
|
||||
|
||||
if (!ptr_temp_bar->items)
|
||||
ptr_temp_bar->items = gui_bar_create_option (ptr_temp_bar->name,
|
||||
GUI_BAR_OPTION_ITEMS,
|
||||
"");
|
||||
|
||||
if (ptr_temp_bar->type && ptr_temp_bar->conditions
|
||||
&& ptr_temp_bar->position && ptr_temp_bar->size
|
||||
&& ptr_temp_bar->size_max && ptr_temp_bar->separator
|
||||
&& ptr_temp_bar->items)
|
||||
{
|
||||
gui_bar_new_with_options (NULL, ptr_temp_bar->name,
|
||||
ptr_temp_bar->type,
|
||||
ptr_temp_bar->conditions,
|
||||
ptr_temp_bar->position,
|
||||
ptr_temp_bar->size,
|
||||
ptr_temp_bar->size_max,
|
||||
ptr_temp_bar->separator,
|
||||
ptr_temp_bar->items);
|
||||
}
|
||||
@@ -922,6 +1129,11 @@ gui_bar_use_temp_bars ()
|
||||
config_file_option_free (ptr_temp_bar->type);
|
||||
ptr_temp_bar->type = NULL;
|
||||
}
|
||||
if (ptr_temp_bar->conditions)
|
||||
{
|
||||
config_file_option_free (ptr_temp_bar->conditions);
|
||||
ptr_temp_bar->conditions = NULL;
|
||||
}
|
||||
if (ptr_temp_bar->position)
|
||||
{
|
||||
config_file_option_free (ptr_temp_bar->position);
|
||||
@@ -932,6 +1144,11 @@ gui_bar_use_temp_bars ()
|
||||
config_file_option_free (ptr_temp_bar->size);
|
||||
ptr_temp_bar->size = NULL;
|
||||
}
|
||||
if (ptr_temp_bar->size_max)
|
||||
{
|
||||
config_file_option_free (ptr_temp_bar->size_max);
|
||||
ptr_temp_bar->size_max = NULL;
|
||||
}
|
||||
if (ptr_temp_bar->separator)
|
||||
{
|
||||
config_file_option_free (ptr_temp_bar->separator);
|
||||
@@ -1006,14 +1223,20 @@ gui_bar_free (struct t_gui_bar *bar)
|
||||
free (bar->name);
|
||||
if (bar->type)
|
||||
config_file_option_free (bar->type);
|
||||
if (bar->conditions)
|
||||
config_file_option_free (bar->conditions);
|
||||
if (bar->position)
|
||||
config_file_option_free (bar->position);
|
||||
if (bar->size)
|
||||
config_file_option_free (bar->size);
|
||||
if (bar->size_max)
|
||||
config_file_option_free (bar->size_max);
|
||||
if (bar->separator)
|
||||
config_file_option_free (bar->separator);
|
||||
if (bar->items)
|
||||
config_file_option_free (bar->items);
|
||||
if (bar->conditions_array)
|
||||
string_free_exploded (bar->conditions_array);
|
||||
if (bar->items_array)
|
||||
string_free_exploded (bar->items_array);
|
||||
|
||||
@@ -1073,10 +1296,14 @@ gui_bar_print_log ()
|
||||
log_printf (" type . . . . . . . . . : %d (%s)",
|
||||
CONFIG_INTEGER(ptr_bar->type),
|
||||
gui_bar_type_str[CONFIG_INTEGER(ptr_bar->type)]);
|
||||
log_printf (" conditions . . . . . . : '%s'", CONFIG_STRING(ptr_bar->conditions));
|
||||
log_printf (" conditions_count . . . : %d", ptr_bar->conditions_count);
|
||||
log_printf (" conditions_array . . . : 0x%x", ptr_bar->conditions_array);
|
||||
log_printf (" position . . . . . . . : %d (%s)",
|
||||
CONFIG_INTEGER(ptr_bar->position),
|
||||
gui_bar_position_str[CONFIG_INTEGER(ptr_bar->position)]);
|
||||
log_printf (" size . . . . . . . . . : %d", CONFIG_INTEGER(ptr_bar->size));
|
||||
log_printf (" size_max . . . . . . . : %d", CONFIG_INTEGER(ptr_bar->size_max));
|
||||
log_printf (" current_size . . . . . : %d", ptr_bar->current_size);
|
||||
log_printf (" separator. . . . . . . : %d", CONFIG_INTEGER(ptr_bar->separator));
|
||||
log_printf (" items. . . . . . . . . : '%s'", CONFIG_STRING(ptr_bar->items));
|
||||
|
||||
+21
-13
@@ -26,8 +26,10 @@ struct t_gui_window;
|
||||
enum t_gui_bar_option
|
||||
{
|
||||
GUI_BAR_OPTION_TYPE = 0,
|
||||
GUI_BAR_OPTION_CONDITIONS,
|
||||
GUI_BAR_OPTION_POSITION,
|
||||
GUI_BAR_OPTION_SIZE,
|
||||
GUI_BAR_OPTION_SIZE_MAX,
|
||||
GUI_BAR_OPTION_SEPARATOR,
|
||||
GUI_BAR_OPTION_ITEMS,
|
||||
/* number of bar types */
|
||||
@@ -38,8 +40,6 @@ 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 */
|
||||
GUI_BAR_NUM_TYPES,
|
||||
};
|
||||
@@ -57,17 +57,21 @@ 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 */
|
||||
struct t_config_option *type; /* type (root or window) */
|
||||
struct t_config_option *position; /* bottom, top, left, right */
|
||||
struct t_config_option *size; /* size of bar (in chars, 0 = auto) */
|
||||
struct t_config_option *separator; /* true if separator line displayed */
|
||||
struct t_config_option *items; /* bar items */
|
||||
struct t_weechat_plugin *plugin; /* plugin */
|
||||
int number; /* bar number */
|
||||
char *name; /* bar name */
|
||||
struct t_config_option *type; /* type (root or window) */
|
||||
struct t_config_option *conditions; /* conditions for display */
|
||||
struct t_config_option *position; /* bottom, top, left, right */
|
||||
struct t_config_option *size; /* size of bar (in chars, 0 = auto) */
|
||||
struct t_config_option *size_max; /* max size of bar (0 = no limit) */
|
||||
struct t_config_option *separator; /* true if separator line displayed */
|
||||
struct t_config_option *items; /* bar items */
|
||||
|
||||
/* internal vars */
|
||||
int current_size; /* current bar size (strictly > 0) */
|
||||
int conditions_count; /* number of conditions */
|
||||
char **conditions_array; /* exploded bar conditions */
|
||||
int items_count; /* number of bar items */
|
||||
char **items_array; /* exploded bar items */
|
||||
struct t_gui_bar_window *bar_window; /* pointer to bar window */
|
||||
@@ -90,18 +94,22 @@ extern struct t_gui_bar *last_gui_temp_bar;
|
||||
extern int gui_bar_search_option (char *option_name);
|
||||
extern int gui_bar_search_type (char *type);
|
||||
extern int gui_bar_search_position (char *position);
|
||||
extern int gui_bar_check_conditions_for_window (struct t_gui_bar *bar,
|
||||
struct t_gui_window *window);
|
||||
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 void gui_bar_set_current_size (struct t_gui_bar *bar, int current_size);
|
||||
extern void gui_bar_set (struct t_gui_bar *bar, char *property, char *value);
|
||||
extern int gui_bar_set (struct t_gui_bar *bar, char *property, char *value);
|
||||
extern struct t_gui_bar *gui_bar_alloc (char *name);
|
||||
extern struct t_config_option *gui_bar_create_option (char *bar_name,
|
||||
int index_option,
|
||||
char *value);
|
||||
extern struct t_gui_bar *gui_bar_new (struct t_weechat_plugin *plugin,
|
||||
char *name, char *type, char *position,
|
||||
char *size, char *separator, char *items);
|
||||
char *name, char *type, char *conditions,
|
||||
char *position, char *size,
|
||||
char *size_max, char *separator,
|
||||
char *items);
|
||||
extern void gui_bar_use_temp_bars ();
|
||||
extern void gui_bar_update (char *name);
|
||||
extern void gui_bar_free (struct t_gui_bar *bar);
|
||||
|
||||
@@ -158,9 +158,9 @@ 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_switch (struct t_gui_window *window);
|
||||
extern void gui_window_page_up (struct t_gui_window *window);
|
||||
extern void gui_window_page_down (struct t_gui_window *window);
|
||||
extern void gui_window_scroll_up (struct t_gui_window *window);
|
||||
|
||||
Reference in New Issue
Block a user