diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-03 15:54:21 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-03 15:54:21 +0200 |
commit | 8509f777b43f0a44414ddcb7e8fc0b7c240bd1f9 (patch) | |
tree | 2c51be47c506c7b7aabe624a01289b7584b7e7a6 /src | |
parent | ad199b41aea0fba54287512e248bb4b29c935abb (diff) | |
download | weechat-8509f777b43f0a44414ddcb7e8fc0b7c240bd1f9.zip |
New features and bug fixes with bars
Diffstat (limited to 'src')
32 files changed, 1800 insertions, 738 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 5948720b5..923d5bee7 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -63,7 +63,7 @@ int command_bar (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - int i, type, position, size, separator; + int type, position, size, separator; long number; char *error; struct t_gui_bar *ptr_bar; @@ -86,7 +86,7 @@ command_bar (void *data, struct t_gui_buffer *buffer, ptr_bar = ptr_bar->next_bar) { gui_chat_printf (NULL, - _(" %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)"), + _(" %d. %s: %s, %s, %s: %s%s%d%s, items: %s%s (plugin: %s)"), ptr_bar->number, ptr_bar->name, gui_bar_type_str[ptr_bar->type], @@ -94,7 +94,10 @@ command_bar (void *data, struct t_gui_buffer *buffer, ((ptr_bar->position == GUI_BAR_POSITION_BOTTOM) || (ptr_bar->position == GUI_BAR_POSITION_TOP)) ? _("height") : _("width"), - ptr_bar->size, + (ptr_bar->size == 0) ? _("auto") : "", + (ptr_bar->size == 0) ? " (" : "", + ptr_bar->current_size, + (ptr_bar->size == 0) ? ")" : "", (ptr_bar->items) ? ptr_bar->items : "-", (ptr_bar->separator) ? _(", with separator") : "", @@ -120,99 +123,138 @@ command_bar (void *data, struct t_gui_buffer *buffer, } else gui_chat_printf (NULL, _("No bar item defined")); + + return WEECHAT_RC_OK; } - else + + /* add a new bar */ + if (string_strcasecmp (argv[1], "add") == 0) { - /* add a new bar */ - if (string_strcasecmp (argv[1], "add") == 0) + if (argc < 8) { - if (argc < 8) - { - gui_chat_printf (NULL, - _("%sError: missing arguments for \"%s\" " - "command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "bar"); - return WEECHAT_RC_ERROR; - } - type = -1; - for (i = 0; i < GUI_BAR_NUM_TYPES; i++) - { - if (string_strcasecmp (argv[3], gui_bar_type_str[i]) == 0) - { - type = i; - break; - } - } - if (type < 0) - { - gui_chat_printf (NULL, - _("%sError: wrong type \"%s\" for bar " - "\"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[3], argv[2]); - return WEECHAT_RC_ERROR; - } - position = -1; - for (i = 0; i < GUI_BAR_NUM_POSITIONS; i++) - { - if (string_strcasecmp (argv[4], gui_bar_position_str[i]) == 0) - { - position = i; - break; - } - } - if (position < 0) - { - gui_chat_printf (NULL, - _("%sError: wrong position \"%s\" for bar " - "\"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[4], argv[2]); - return WEECHAT_RC_ERROR; - } - error = NULL; - number = strtol (argv[5], &error, 10); - if (error && !error[0]) + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "bar"); + return WEECHAT_RC_ERROR; + } + type = gui_bar_get_type (argv[3]); + if (type < 0) + { + gui_chat_printf (NULL, + _("%sError: wrong type \"%s\" for bar " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[3], argv[2]); + return WEECHAT_RC_ERROR; + } + position = gui_bar_get_position (argv[4]); + if (position < 0) + { + gui_chat_printf (NULL, + _("%sError: wrong position \"%s\" for bar " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[4], argv[2]); + return WEECHAT_RC_ERROR; + } + error = NULL; + number = strtol (argv[5], &error, 10); + if (error && !error[0]) + { + size = number; + separator = 0; + if (strcmp (argv[6], "0") != 0) + separator = 1; + + /* create bar */ + if (gui_bar_new (NULL, argv[2], argv[3], argv[4], size, + separator, argv[7])) { - size = number; - separator = 0; - if (strcmp (argv[6], "0") != 0) - separator = 1; - - /* create bar */ - if (gui_bar_new (NULL, argv[2], argv[3], argv[4], size, - separator, argv[7])) - { - gui_chat_printf (NULL, _("%sBar \"%s\" created"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - argv[2]); - } - else - { - gui_chat_printf (NULL, _("%sError: failed to create bar " - "\"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[2]); - } + gui_chat_printf (NULL, _("Bar \"%s\" created"), + argv[2]); } else { - gui_chat_printf (NULL, - _("%sError: wrong size \"%s\" for bar " - "\"%s\""), + gui_chat_printf (NULL, _("%sError: failed to create bar " + "\"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[5], argv[2]); - return WEECHAT_RC_ERROR; + argv[2]); } } else { - /* TODO: remove/change bars... */ + gui_chat_printf (NULL, + _("%sError: wrong size \"%s\" for bar " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[5], argv[2]); + return WEECHAT_RC_ERROR; } + + return WEECHAT_RC_OK; } - return WEECHAT_RC_OK; + /* delete a bar */ + if (string_strcasecmp (argv[1], "del") == 0) + { + if (argc < 3) + { + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "bar"); + return WEECHAT_RC_ERROR; + } + ptr_bar = gui_bar_search (argv[2]); + if (!ptr_bar) + { + gui_chat_printf (NULL, + _("%sError: unknown bar \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + return WEECHAT_RC_ERROR; + } + gui_bar_free (ptr_bar); + gui_chat_printf (NULL, _("Bar deleted")); + + return WEECHAT_RC_OK; + } + + /* set a bar property */ + if (string_strcasecmp (argv[1], "set") == 0) + { + if (argc < 5) + { + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "bar"); + return WEECHAT_RC_ERROR; + } + ptr_bar = gui_bar_search (argv[2]); + if (!ptr_bar) + { + gui_chat_printf (NULL, + _("%sError: unknown bar \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + return WEECHAT_RC_ERROR; + } + gui_bar_set (ptr_bar, argv[3], argv_eol[4]); + + return WEECHAT_RC_OK; + } + + gui_chat_printf (NULL, + _("%sError: unknown option for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "bar"); + return WEECHAT_RC_ERROR; } /* @@ -253,250 +295,265 @@ command_buffer (void *data, struct t_gui_buffer *buffer, ptr_buffer->category, ptr_buffer->name); } + + return WEECHAT_RC_OK; } - else + + /* clear content of buffer */ + if (string_strcasecmp (argv[1], "clear") == 0) { - if (string_strcasecmp (argv[1], "clear") == 0) + if (argc > 2) { - /* clear content of buffer */ - if (argc > 2) + if (string_strcasecmp (argv[2], "-all") == 0) + gui_buffer_clear_all (); + else { - if (string_strcasecmp (argv[2], "-all") == 0) - gui_buffer_clear_all (); - else + for (i = 2; i < argc; i++) { - for (i = 2; i < argc; i++) + error = NULL; + number = strtol (argv[i], &error, 10); + if (error && !error[0]) { - error = NULL; - number = strtol (argv[i], &error, 10); - if (error && !error[0]) - { - ptr_buffer = gui_buffer_search_by_number (number); - if (ptr_buffer) - gui_buffer_clear (ptr_buffer); - } + ptr_buffer = gui_buffer_search_by_number (number); + if (ptr_buffer) + gui_buffer_clear (ptr_buffer); } } } - else - gui_buffer_clear (buffer); } - else if (string_strcasecmp (argv[1], "move") == 0) + else + gui_buffer_clear (buffer); + + return WEECHAT_RC_OK; + } + + /* move buffer to another number in the list */ + if (string_strcasecmp (argv[1], "move") == 0) + { + if (argc < 3) { - /* move buffer to another number in the list */ - if (argc < 3) - { - gui_chat_printf (NULL, - _("%sError: missing arguments for \"%s\" " - "command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "buffer"); - return WEECHAT_RC_ERROR; - } - - error = NULL; - number = strtol (((argv[2][0] == '+') || (argv[2][0] == '-')) ? - argv[2] + 1 : argv[2], - &error, 10); - if (error && !error[0]) - { - if (argv[2][0] == '+') - gui_buffer_move_to_number (buffer, - buffer->number + ((int) number)); - else if (argv[2][0] == '-') - gui_buffer_move_to_number (buffer, - buffer->number - ((int) number)); - else - gui_buffer_move_to_number (buffer, (int) number); - } + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "buffer"); + return WEECHAT_RC_ERROR; + } + + error = NULL; + number = strtol (((argv[2][0] == '+') || (argv[2][0] == '-')) ? + argv[2] + 1 : argv[2], + &error, 10); + if (error && !error[0]) + { + if (argv[2][0] == '+') + gui_buffer_move_to_number (buffer, + buffer->number + ((int) number)); + else if (argv[2][0] == '-') + gui_buffer_move_to_number (buffer, + buffer->number - ((int) number)); else - { - /* invalid number */ - gui_chat_printf (NULL, - _("%sError: incorrect buffer number"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); - return WEECHAT_RC_ERROR; - } + gui_buffer_move_to_number (buffer, (int) number); + } + else + { + /* invalid number */ + gui_chat_printf (NULL, + _("%sError: incorrect buffer number"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); + return WEECHAT_RC_ERROR; + } + + return WEECHAT_RC_OK; + } + + /* close buffer */ + if (string_strcasecmp (argv[1], "close") == 0) + { + if (!buffer->plugin) + { + gui_chat_printf (NULL, + _("%sError: WeeChat main buffer can't be " + "closed"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); + return WEECHAT_RC_ERROR; } - else if (string_strcasecmp (argv[1], "close") == 0) + gui_buffer_close (buffer, 1); + gui_status_refresh_needed = 1; + gui_current_window->buffer->input_refresh_needed = 1; + + return WEECHAT_RC_OK; + } + + /* display/change buffer notify */ + if (string_strcasecmp (argv[1], "notify") == 0) + { + if (argc < 3) { - if (!buffer->plugin) + /* display notify level for all buffers */ + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Notify levels:")); + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) { gui_chat_printf (NULL, - _("%sError: WeeChat main buffer can't be " - "closed"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); - return WEECHAT_RC_ERROR; + " %d.%s: %d", + ptr_buffer->number, + ptr_buffer->name, + ptr_buffer->notify_level); } - gui_buffer_close (buffer, 1); - gui_status_refresh_needed = 1; - gui_current_window->buffer->input_refresh_needed = 1; + gui_chat_printf (NULL, ""); } - else if (string_strcasecmp (argv[1], "notify") == 0) + else { - if (argc < 3) - { - /* display notify level for all buffers */ - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, _("Notify levels:")); - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - gui_chat_printf (NULL, - " %d.%s: %d", - ptr_buffer->number, - ptr_buffer->name, - ptr_buffer->notify_level); - } - gui_chat_printf (NULL, ""); - } - else + /* set notify level for buffer */ + error = NULL; + number = strtol (argv[2], &error, 10); + if (error && !error[0]) { - /* set notify level for buffer */ - error = NULL; - number = strtol (argv[2], &error, 10); - if (error && !error[0]) - { - if ((number < GUI_BUFFER_NOTIFY_LEVEL_MIN) - || (number > GUI_BUFFER_NOTIFY_LEVEL_MAX)) - { - /* invalid highlight level */ - gui_chat_printf (NULL, - _("%sError: incorrect notify level " - "(must be between %d and %d)"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - GUI_BUFFER_NOTIFY_LEVEL_MIN, - GUI_BUFFER_NOTIFY_LEVEL_MAX); - return WEECHAT_RC_ERROR; - } - gui_chat_printf (NULL, - _("%sNew notify level for %s%s%s: " - "%d %s"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - buffer->name, - GUI_COLOR(GUI_COLOR_CHAT), - number, - GUI_COLOR(GUI_COLOR_CHAT)); - switch (number) - { - case 0: - gui_chat_printf (NULL, - _("(hotlist: never)")); - break; - case 1: - gui_chat_printf (NULL, - _("(hotlist: highlights)")); - break; - case 2: - gui_chat_printf (NULL, - _("(hotlist: highlights + " - "messages)")); - break; - case 3: - gui_chat_printf (NULL, - _("(hotlist: highlights + " - "messages + join/part " - "(all))")); - break; - default: - gui_chat_printf (NULL, ""); - break; - } - } - else + if ((number < GUI_BUFFER_NOTIFY_LEVEL_MIN) + || (number > GUI_BUFFER_NOTIFY_LEVEL_MAX)) { - /* invalid number */ + /* invalid highlight level */ gui_chat_printf (NULL, - _("%sError: incorrect notify level (must " - "be between %d and %d)"), + _("%sError: incorrect notify level " + "(must be between %d and %d)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], GUI_BUFFER_NOTIFY_LEVEL_MIN, GUI_BUFFER_NOTIFY_LEVEL_MAX); return WEECHAT_RC_ERROR; } + gui_chat_printf (NULL, + _("%sNew notify level for %s%s%s: " + "%d %s"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + buffer->name, + GUI_COLOR(GUI_COLOR_CHAT), + number, + GUI_COLOR(GUI_COLOR_CHAT)); + switch (number) + { + case 0: + gui_chat_printf (NULL, + _("(hotlist: never)")); + break; + case 1: + gui_chat_printf (NULL, + _("(hotlist: highlights)")); + break; + case 2: + gui_chat_printf (NULL, + _("(hotlist: highlights + " + "messages)")); + break; + case 3: + gui_chat_printf (NULL, + _("(hotlist: highlights + " + "messages + join/part " + "(all))")); + break; + default: + gui_chat_printf (NULL, ""); + break; + } } - } - else if (string_strcasecmp (argv[1], "set") == 0) - { - /* set a property on buffer */ - if (argc < 4) + else { + /* invalid number */ gui_chat_printf (NULL, - _("%sError: missing arguments for \"%s\" " - "command"), + _("%sError: incorrect notify level (must " + "be between %d and %d)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "buffer"); + GUI_BUFFER_NOTIFY_LEVEL_MIN, + GUI_BUFFER_NOTIFY_LEVEL_MAX); return WEECHAT_RC_ERROR; } - value = string_remove_quotes (argv_eol[3], "'\""); - gui_buffer_set (buffer, argv[2], (value) ? value : argv_eol[3]); - if (value) - free (value); } + + return WEECHAT_RC_OK; + } + + /* set a property on buffer */ + if (string_strcasecmp (argv[1], "set") == 0) + { + if (argc < 4) + { + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "buffer"); + return WEECHAT_RC_ERROR; + } + value = string_remove_quotes (argv_eol[3], "'\""); + gui_buffer_set (buffer, argv[2], (value) ? value : argv_eol[3]); + if (value) + free (value); + + return WEECHAT_RC_OK; + } + + /* relative jump '-' */ + if (argv[1][0] == '-') + { + error = NULL; + number = strtol (argv[1] + 1, &error, 10); + if (error && !error[0]) + { + target_buffer = buffer->number - (int) number; + if (target_buffer < 1) + target_buffer = (last_gui_buffer) ? + last_gui_buffer->number + target_buffer : 1; + gui_buffer_switch_by_number (gui_current_window, + target_buffer); + } + + return WEECHAT_RC_OK; + } + + /* relative jump '+' */ + if (argv[1][0] == '+') + { + error = NULL; + number = strtol (argv[1] + 1, &error, 10); + if (error && !error[0]) + { + target_buffer = buffer->number + (int) number; + if (last_gui_buffer && target_buffer > last_gui_buffer->number) + target_buffer -= last_gui_buffer->number; + gui_buffer_switch_by_number (gui_current_window, + target_buffer); + } + + return WEECHAT_RC_OK; + } + + /* jump to buffer by number or server/channel name */ + error = NULL; + number = strtol (argv[1], &error, 10); + if (error && !error[0]) + gui_buffer_switch_by_number (gui_current_window, + (int) number); + else + { + ptr_buffer = NULL; + if (argc > 2) + ptr_buffer = gui_buffer_search_by_category_name (argv[1], + argv[2]); else { - /* jump to buffer by number or server/channel name */ - if (argv[1][0] == '-') - { - /* relative jump '-' */ - error = NULL; - number = strtol (argv[1] + 1, &error, 10); - if (error && !error[0]) - { - target_buffer = buffer->number - (int) number; - if (target_buffer < 1) - target_buffer = (last_gui_buffer) ? - last_gui_buffer->number + target_buffer : 1; - gui_buffer_switch_by_number (gui_current_window, - target_buffer); - } - } - else if (argv[1][0] == '+') - { - /* relative jump '+' */ - error = NULL; - number = strtol (argv[1] + 1, &error, 10); - if (error && !error[0]) - { - target_buffer = buffer->number + (int) number; - if (last_gui_buffer && target_buffer > last_gui_buffer->number) - target_buffer -= last_gui_buffer->number; - gui_buffer_switch_by_number (gui_current_window, - target_buffer); - } - } - else - { - /* absolute jump by number, or by category/name */ - error = NULL; - number = strtol (argv[1], &error, 10); - if (error && !error[0]) - gui_buffer_switch_by_number (gui_current_window, - (int) number); - else - { - ptr_buffer = NULL; - if (argc > 2) - ptr_buffer = gui_buffer_search_by_category_name (argv[1], - argv[2]); - else - { - ptr_buffer = gui_buffer_search_by_category_name (argv[1], - NULL); - if (!ptr_buffer) - ptr_buffer = gui_buffer_search_by_category_name (NULL, - argv[1]); - } - if (ptr_buffer) - { - gui_window_switch_to_buffer (gui_current_window, - ptr_buffer); - gui_window_redraw_buffer (ptr_buffer); - } - } - } - + ptr_buffer = gui_buffer_search_by_category_name (argv[1], + NULL); + if (!ptr_buffer) + ptr_buffer = gui_buffer_search_by_category_name (NULL, + argv[1]); + } + if (ptr_buffer) + { + gui_window_switch_to_buffer (gui_current_window, + ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); } } @@ -697,9 +754,17 @@ command_filter (void *data, struct t_gui_buffer *buffer, gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_ERROR; } + + return WEECHAT_RC_OK; } - return WEECHAT_RC_OK; + gui_chat_printf (NULL, + _("%sError: unknown option for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "filter"); + return WEECHAT_RC_ERROR; + } /* @@ -717,120 +782,120 @@ command_help (void *data, struct t_gui_buffer *buffer, (void) buffer; (void) argv_eol; - switch (argc) + /* display help for all commands */ + if (argc == 1) { - case 1: - /* display help for all commands */ - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, - /* TRANSLATORS: %s is "WeeChat" */ - _("%s internal commands:"), - PACKAGE_NAME); - for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; - ptr_hook = ptr_hook->next_hook) + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, + /* TRANSLATORS: %s is "WeeChat" */ + _("%s internal commands:"), + PACKAGE_NAME); + for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; + ptr_hook = ptr_hook->next_hook) + { + if (!ptr_hook->deleted + && !ptr_hook->plugin + && HOOK_COMMAND(ptr_hook, command) + && HOOK_COMMAND(ptr_hook, command)[0]) { - if (!ptr_hook->deleted - && !ptr_hook->plugin - && HOOK_COMMAND(ptr_hook, command) - && HOOK_COMMAND(ptr_hook, command)[0]) - { - gui_chat_printf (NULL, " %s%s%s%s%s%s%s%s", - GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - (HOOK_COMMAND(ptr_hook, level) > 0) ? - "(" : "", - HOOK_COMMAND(ptr_hook, command), - (HOOK_COMMAND(ptr_hook, level) > 0) ? - ")" : "", - GUI_COLOR(GUI_COLOR_CHAT), - (HOOK_COMMAND(ptr_hook, description) - && HOOK_COMMAND(ptr_hook, description)[0]) ? - " - " : "", - (HOOK_COMMAND(ptr_hook, description) - && HOOK_COMMAND(ptr_hook, description)[0]) ? - _(HOOK_COMMAND(ptr_hook, description)) : "", - (HOOK_COMMAND(ptr_hook, level) > 0) ? - _(" (used by a plugin)") : ""); - } + gui_chat_printf (NULL, " %s%s%s%s%s%s%s%s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + (HOOK_COMMAND(ptr_hook, level) > 0) ? + "(" : "", + HOOK_COMMAND(ptr_hook, command), + (HOOK_COMMAND(ptr_hook, level) > 0) ? + ")" : "", + GUI_COLOR(GUI_COLOR_CHAT), + (HOOK_COMMAND(ptr_hook, description) + && HOOK_COMMAND(ptr_hook, description)[0]) ? + " - " : "", + (HOOK_COMMAND(ptr_hook, description) + && HOOK_COMMAND(ptr_hook, description)[0]) ? + _(HOOK_COMMAND(ptr_hook, description)) : "", + (HOOK_COMMAND(ptr_hook, level) > 0) ? + _(" (used by a plugin)") : ""); + } + } + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Other commands:")); + for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; + ptr_hook = ptr_hook->next_hook) + { + if (!ptr_hook->deleted + && ptr_hook->plugin + && HOOK_COMMAND(ptr_hook, command) + && HOOK_COMMAND(ptr_hook, command)[0]) + { + gui_chat_printf (NULL, " %s%s%s%s%s%s%s%s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + (HOOK_COMMAND(ptr_hook, level) > 0) ? + "(" : "", + HOOK_COMMAND(ptr_hook, command), + (HOOK_COMMAND(ptr_hook, level) > 0) ? + ")" : "", + GUI_COLOR(GUI_COLOR_CHAT), + (HOOK_COMMAND(ptr_hook, description) + && HOOK_COMMAND(ptr_hook, description)[0]) ? + " - " : "", + (HOOK_COMMAND(ptr_hook, description) + && HOOK_COMMAND(ptr_hook, description)[0]) ? + _(HOOK_COMMAND(ptr_hook, description)) : "", + (HOOK_COMMAND(ptr_hook, level) > 0) ? + _(" (masked by a plugin)") : ""); } + } + + return WEECHAT_RC_OK; + } + + /* display help about a command */ + for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; + ptr_hook = ptr_hook->next_hook) + { + if (!ptr_hook->deleted + && HOOK_COMMAND(ptr_hook, command) + && HOOK_COMMAND(ptr_hook, command)[0] + && (HOOK_COMMAND(ptr_hook, level) == 0) + && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), + argv[1]) == 0)) + { gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, _("Other commands:")); - for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; - ptr_hook = ptr_hook->next_hook) + gui_chat_printf (NULL, + "[%s%s] %s/%s %s%s", + (ptr_hook->plugin) ? + _("plugin:") : "weechat", + (ptr_hook->plugin) ? + ptr_hook->plugin->name : "", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + HOOK_COMMAND(ptr_hook, command), + GUI_COLOR(GUI_COLOR_CHAT), + (HOOK_COMMAND(ptr_hook, args) + && HOOK_COMMAND(ptr_hook, args)[0]) ? + _(HOOK_COMMAND(ptr_hook, args)) : ""); + if (HOOK_COMMAND(ptr_hook, description) + && HOOK_COMMAND(ptr_hook, description)[0]) { - if (!ptr_hook->deleted - && ptr_hook->plugin - && HOOK_COMMAND(ptr_hook, command) - && HOOK_COMMAND(ptr_hook, command)[0]) - { - gui_chat_printf (NULL, " %s%s%s%s%s%s%s%s", - GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - (HOOK_COMMAND(ptr_hook, level) > 0) ? - "(" : "", - HOOK_COMMAND(ptr_hook, command), - (HOOK_COMMAND(ptr_hook, level) > 0) ? - ")" : "", - GUI_COLOR(GUI_COLOR_CHAT), - (HOOK_COMMAND(ptr_hook, description) - && HOOK_COMMAND(ptr_hook, description)[0]) ? - " - " : "", - (HOOK_COMMAND(ptr_hook, description) - && HOOK_COMMAND(ptr_hook, description)[0]) ? - _(HOOK_COMMAND(ptr_hook, description)) : "", - (HOOK_COMMAND(ptr_hook, level) > 0) ? - _(" (masked by a plugin)") : ""); - } + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "%s", + _(HOOK_COMMAND(ptr_hook, description))); } - break; - case 2: - /* display help about a command */ - for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; - ptr_hook = ptr_hook->next_hook) + if (HOOK_COMMAND(ptr_hook, args_description) + && HOOK_COMMAND(ptr_hook, args_description)[0]) { - if (!ptr_hook->deleted - && HOOK_COMMAND(ptr_hook, command) - && HOOK_COMMAND(ptr_hook, command)[0] - && (HOOK_COMMAND(ptr_hook, level) == 0) - && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), - argv[1]) == 0)) - { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, - "[%s%s] %s/%s %s%s", - (ptr_hook->plugin) ? - _("plugin:") : "weechat", - (ptr_hook->plugin) ? - ptr_hook->plugin->name : "", - GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - HOOK_COMMAND(ptr_hook, command), - GUI_COLOR(GUI_COLOR_CHAT), - (HOOK_COMMAND(ptr_hook, args) - && HOOK_COMMAND(ptr_hook, args)[0]) ? - _(HOOK_COMMAND(ptr_hook, args)) : ""); - if (HOOK_COMMAND(ptr_hook, description) - && HOOK_COMMAND(ptr_hook, description)[0]) - { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, "%s", - _(HOOK_COMMAND(ptr_hook, description))); - } - if (HOOK_COMMAND(ptr_hook, args_description) - && HOOK_COMMAND(ptr_hook, args_description)[0]) - { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, "%s", - _(HOOK_COMMAND(ptr_hook, args_description))); - } - return WEECHAT_RC_OK; - } + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "%s", + _(HOOK_COMMAND(ptr_hook, args_description))); } - gui_chat_printf (NULL, - _("%sNo help available, \"%s\" is an " - "unknown command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[1]); - break; + return WEECHAT_RC_OK; + } } + gui_chat_printf (NULL, + _("%sNo help available, \"%s\" is an " + "unknown command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[1]); + return WEECHAT_RC_OK; } @@ -946,9 +1011,9 @@ command_key (void *data, struct t_gui_buffer *buffer, (void) data; (void) buffer; + /* display all key bindings */ if (argc == 1) { - /* display all key bindings */ gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Key bindings:")); for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key) @@ -958,9 +1023,9 @@ command_key (void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } + /* display key functions */ if (string_strcasecmp (argv[1], "functions") == 0) { - /* display key functions */ gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Internal key functions:")); i = 0; @@ -974,10 +1039,10 @@ command_key (void *data, struct t_gui_buffer *buffer, } return WEECHAT_RC_OK; } - + + /* reset keys (only with "-yes", for security reason) */ if (string_strcasecmp (argv[1], "reset") == 0) { - /* reset keys (only with "-yes", for security reason) */ if ((argc >= 3) && (string_strcasecmp (argv[2], "-yes") == 0)) { gui_keyboard_free_all (); @@ -996,10 +1061,10 @@ command_key (void *data, struct t_gui_buffer *buffer, } return WEECHAT_RC_OK; } - + + /* unbind a key */ if (string_strcasecmp (argv[1], "unbind") == 0) { - /* unbind a key */ if (argc >= 3) { if (gui_keyboard_unbind (argv[2])) @@ -1021,9 +1086,9 @@ command_key (void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } + /* call a key function */ if (string_strcasecmp (argv[1], "call") == 0) { - /* call a key function */ if (argc >= 3) { ptr_function = gui_keyboard_function_search_by_name (argv[2]); @@ -1051,9 +1116,9 @@ command_key (void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } + /* display a key */ if (argc == 2) { - /* display a key */ ptr_key = NULL; internal_code = gui_keyboard_get_internal_code (argv[1]); if (internal_code) @@ -2102,112 +2167,122 @@ command_window (void *data, struct t_gui_buffer *buffer, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); i++; } + + return WEECHAT_RC_OK; } - else + + /* split window horizontally */ + if (string_strcasecmp (argv[1], "splith") == 0) { - if (string_strcasecmp (argv[1], "splith") == 0) + if (argc > 2) { - /* split window horizontally */ - if (argc > 2) - { - error = NULL; - number = strtol (argv[2], &error, 10); - if (error && !error[0] - && (number > 0) && (number < 100)) - gui_window_split_horiz (gui_current_window, number); - } - else - gui_window_split_horiz (gui_current_window, 50); + error = NULL; + number = strtol (argv[2], &error, 10); + if (error && !error[0] + && (number > 0) && (number < 100)) + gui_window_split_horiz (gui_current_window, number); } - else if (string_strcasecmp (argv[1], "splitv") == 0) + else + gui_window_split_horiz (gui_current_window, 50); + + return WEECHAT_RC_OK; + } + + /* split window vertically */ + if (string_strcasecmp (argv[1], "splitv") == 0) + { + if (argc > 2) { - /* split window vertically */ - if (argc > 2) - { - error = NULL; - number = strtol (argv[2], &error, 10); - if (error && !error[0] - && (number > 0) && (number < 100)) - gui_window_split_vertic (gui_current_window, number); - } - else - gui_window_split_vertic (gui_current_window, 50); + error = NULL; + number = strtol (argv[2], &error, 10); + if (error && !error[0] + && (number > 0) && (number < 100)) + gui_window_split_vertic (gui_current_window, number); } - else if (string_strcasecmp (argv[1], "resize") == 0) + else + gui_window_split_vertic (gui_current_window, 50); + + return WEECHAT_RC_OK; + } + + /* resize window */ + if (string_strcasecmp (argv[1], "resize") == 0) + { + if (argc > 2) { - /* resize window */ - if (argc > 2) - { - error = NULL; - number = strtol (argv[2], &error, 10); - if (error && !error[0] - && (number > 0) && (number < 100)) - gui_window_resize (gui_current_window, number); - } + error = NULL; + number = strtol (argv[2], &error, 10); + if (error && !error[0] + && (number > 0) && (number < 100)) + gui_window_resize (gui_current_window, number); } - else if (string_strcasecmp (argv[1], "merge") == 0) + return WEECHAT_RC_OK; + } + + /* merge windows */ + if (string_strcasecmp (argv[1], "merge") == 0) + { + if (argc > 2) { - /* merge windows */ - if (argc > 2) - { - if (string_strcasecmp (argv[2], "all") == 0) - gui_window_merge_all (gui_current_window); - else - { - gui_chat_printf (NULL, - _("%sError: unknown option for \"%s\" " - "command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "window merge"); - return WEECHAT_RC_ERROR; - } - } + if (string_strcasecmp (argv[2], "all") == 0) + gui_window_merge_all (gui_current_window); else { - if (!gui_window_merge (gui_current_window)) - { - gui_chat_printf (NULL, - _("%sError: can not merge windows, " - "there's no other window with same " - "size near current one"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); - return WEECHAT_RC_ERROR; - } + gui_chat_printf (NULL, + _("%sError: unknown option for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "window merge"); + return WEECHAT_RC_ERROR; } } - else if (string_strncasecmp (argv[1], "b", 1) == 0) - { - /* jump to window by buffer number */ - error = NULL; - number = strtol (argv[1] + 1, &error, 10); - if (error && !error[0]) - gui_window_switch_by_buffer (gui_current_window, number); - } - else if (string_strcasecmp (argv[1], "-1") == 0) - gui_window_switch_previous (gui_current_window); - else if (string_strcasecmp (argv[1], "+1") == 0) - gui_window_switch_next (gui_current_window); - else if (string_strcasecmp (argv[1], "up") == 0) - gui_window_switch_up (gui_current_window); - else if (string_strcasecmp (argv[1], "down") == 0) - gui_window_switch_down (gui_current_window); - else if (string_strcasecmp (argv[1], "left") == 0) - gui_window_switch_left (gui_current_window); - else if (string_strcasecmp (argv[1], "right") == 0) - gui_window_switch_right (gui_current_window); - else if (string_strcasecmp (argv[1], "scroll") == 0) - { - if (argc > 2) - gui_window_scroll (gui_current_window, argv[2]); - } else { - gui_chat_printf (NULL, - _("%sError: unknown option for \"%s\" command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "window"); - return WEECHAT_RC_ERROR; + if (!gui_window_merge (gui_current_window)) + { + gui_chat_printf (NULL, + _("%sError: can not merge windows, " + "there's no other window with same " + "size near current one"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); + return WEECHAT_RC_ERROR; + } } + return WEECHAT_RC_OK; + } + + /* jump to window by buffer number */ + if (string_strncasecmp (argv[1], "b", 1) == 0) + { + error = NULL; + number = strtol (argv[1] + 1, &error, 10); + if (error && !error[0]) + gui_window_switch_by_buffer (gui_current_window, number); + } + else if (string_strcasecmp (argv[1], "-1") == 0) + gui_window_switch_previous (gui_current_window); + else if (string_strcasecmp (argv[1], "+1") == 0) + gui_window_switch_next (gui_current_window); + else if (string_strcasecmp (argv[1], "up") == 0) + gui_window_switch_up (gui_current_window); + else if (string_strcasecmp (argv[1], "down") == 0) + gui_window_switch_down (gui_current_window); + else if (string_strcasecmp (argv[1], "left") == 0) + gui_window_switch_left (gui_current_window); + else if (string_strcasecmp (argv[1], "right") == 0) + gui_window_switch_right (gui_current_window); + else if (string_strcasecmp (argv[1], "scroll") == 0) + { + if (argc > 2) + gui_window_scroll (gui_current_window, argv[2]); + } + else + { + gui_chat_printf (NULL, + _("%sError: unknown option for \"%s\" command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "window"); + return WEECHAT_RC_ERROR; } return WEECHAT_RC_OK; @@ -2222,10 +2297,11 @@ command_init () { hook_command (NULL, "bar", N_("manage bars"), - N_("[add name type position size separator item1,item2,...] " - "| [list]"), + N_("[add barname type position size separator item1,item2,...] " + "| [del barname] | [set barname name|type|position|size|" + "separator|items value] | [list]"), N_(" add: add a new bar\n" - " name: name of bar (must be unique)\n" + " barname: name of bar (must be unique)\n" " type: \"root\" (outside windows), \"window_active\" " "(inside active window), or \"window_inactive\" (inside " "each inactive window)\n" @@ -2234,8 +2310,11 @@ command_init () "separator: 1 for using separator (line), 0 or nothing " "means no separator\n" "item1,...: items for this bar\n" + " del: delete a bar\n" + " set: set a value for a bar property\n" " list: list all bars"), - "list", + "add|del|set|list %r name|type|position|size|separator|" + "items", &command_bar, NULL); hook_command (NULL, "buffer", N_("manage buffers"), @@ -2301,7 +2380,7 @@ command_init () " tags: comma separated list of tags, for " "example: \"irc_join,irc_part,irc_quit\"\n" " regex: regular expression to search in " - "line (use \t to separate prefix from message)"), + "line (use \\t to separate prefix from message)"), "list|enable|disable|toggle|add|del", &command_filter, NULL); hook_command (NULL, "help", diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 5b5c7c2e4..ec3e9c833 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -878,6 +878,10 @@ config_file_write_internal (struct t_config_file *config_file, return -1; } + log_printf (_("Writing configuration file %s %s"), + config_file->filename, + (default_options) ? _("(default options)") : ""); + /* write header with version and date */ current_time = time (NULL); string_iconv_fprintf (config_file->file, @@ -951,14 +955,15 @@ config_file_write (struct t_config_file *config_file) } /* - * config_file_read: read a configuration file - * return: 0 = successful - * -1 = config file file not found - * -2 = error in config file + * config_file_read_internal: read a configuration file + * (should not be called directly) + * return: 0 = successful + * -1 = config file file not found + * -2 = error in config file */ int -config_file_read (struct t_config_file *config_file) +config_file_read_internal (struct t_config_file *config_file, int reload) { int filename_length, line_number, rc; char *filename; @@ -992,6 +997,9 @@ config_file_read (struct t_config_file *config_file) } } + if (!reload) + log_printf (_("Reading configuration file %s"), config_file->filename); + /* read all lines */ ptr_section = NULL; line_number = 0; @@ -1178,6 +1186,19 @@ config_file_read (struct t_config_file *config_file) } /* + * config_file_read: read a configuration file + * return: 0 = successful + * -1 = config file file not found + * -2 = error in config file + */ + +int +config_file_read (struct t_config_file *config_file) +{ + return config_file_read_internal (config_file, 0); +} + +/* * config_file_reload: reload a configuration file * return: 0 = successful * -1 = config file file not found @@ -1194,6 +1215,8 @@ config_file_reload (struct t_config_file *config_file) if (!config_file) return -1; + log_printf (_("Reloading configuration file %s"), config_file->filename); + /* init "loaded" flag for all options */ for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) @@ -1209,7 +1232,7 @@ config_file_reload (struct t_config_file *config_file) } /* read configuration file */ - rc = config_file_read (config_file); + rc = config_file_read_internal (config_file, 1); /* reset options not found in configuration file */ for (ptr_section = config_file->sections; ptr_section; diff --git a/src/core/wee-config.c b/src/core/wee-config.c index a6abd624c..5b67ccfb5 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -1533,7 +1533,5 @@ config_weechat_read () int config_weechat_write () { - log_printf (_("Saving WeeChat configuration to disk (%s)"), - weechat_config_file->filename); return config_file_write (weechat_config_file); } diff --git a/src/core/wee-log.c b/src/core/wee-log.c index 65027ca40..e5cd098d7 100644 --- a/src/core/wee-log.c +++ b/src/core/wee-log.c @@ -108,6 +108,8 @@ log_init () "with another home using \"--dir\" command line option.\n")); exit (1); } + log_printf ("%s (%s %s %s)", + PACKAGE_STRING, _("compiled on"), __DATE__, __TIME__); } /* diff --git a/src/core/weechat.c b/src/core/weechat.c index 92cd724b8..893a752de 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -451,9 +451,6 @@ weechat_welcome_message () gui_chat_printf (NULL, "%s-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-", GUI_COLOR(GUI_COLOR_CHAT_NICK)); - - log_printf ("%s (%s %s %s)", - PACKAGE_STRING, _("compiled on"), __DATE__, __TIME__); } /* 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); diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c index 759c5cefd..73a49d80c 100644 --- a/src/plugins/plugin-config.c +++ b/src/plugins/plugin-config.c @@ -391,7 +391,6 @@ plugin_config_read () int plugin_config_write () { - log_printf (_("Saving plugins configuration to disk")); return config_file_write (plugin_config); } diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 64039dcab..07968b405 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -382,6 +382,7 @@ plugin_load (char *filename) new_plugin->bar_item_remove = &gui_bar_item_free; new_plugin->bar_search = &gui_bar_search; new_plugin->bar_new = &gui_bar_new; + new_plugin->bar_set = &gui_bar_set; new_plugin->bar_update = &gui_bar_update; new_plugin->bar_remove = &gui_bar_free; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index cb41daa2c..1e8b6770d 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -3793,6 +3793,47 @@ weechat_lua_api_bar_new (lua_State *L) } /* + * weechat_lua_api_bar_set: set a bar property + */ + +static int +weechat_lua_api_bar_set (lua_State *L) +{ + const char *bar, *property, *value; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_set"); + LUA_RETURN_ERROR; + } + + bar = NULL; + property = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_set"); + LUA_RETURN_ERROR; + } + + bar = lua_tostring (lua_current_interpreter, -3); + property = lua_tostring (lua_current_interpreter, -2); + value = lua_tostring (lua_current_interpreter, -1); + + weechat_buffer_set (script_str2ptr ((char *)bar), + (char *)property, + (char *)value); + + LUA_RETURN_OK; +} + +/* * weechat_lua_api_bar_update: update a bar on screen */ @@ -4494,6 +4535,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "bar_item_remove", &weechat_lua_api_bar_item_remove }, { "bar_search", &weechat_lua_api_bar_search }, { "bar_new", &weechat_lua_api_bar_new }, + { "bar_set", &weechat_lua_api_bar_set }, { "bar_update", &weechat_lua_api_bar_update }, { "bar_remove", &weechat_lua_api_bar_remove }, { "command", &weechat_lua_api_command }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 2b2064bab..b68577825 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -3139,6 +3139,38 @@ static XS (XS_weechat_bar_new) } /* + * weechat::bar_set: set a bar property + */ + +static XS (XS_weechat_bar_set) +{ + char *bar, *property, *value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_set"); + PERL_RETURN_ERROR; + } + + if (items < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_set"); + PERL_RETURN_ERROR; + } + + bar = SvPV (ST (0), PL_na); + property = SvPV (ST (1), PL_na); + value = SvPV (ST (2), PL_na); + weechat_bar_set (script_str2ptr (bar), property, value); + + PERL_RETURN_OK; +} + +/* * weechat::bar_update: update a bar on screen */ @@ -3621,6 +3653,7 @@ weechat_perl_api_init (pTHX) newXS ("weechat::bar_item_remove", XS_weechat_bar_item_remove, "weechat"); newXS ("weechat::bar_search", XS_weechat_bar_search, "weechat"); newXS ("weechat::bar_new", XS_weechat_bar_new, "weechat"); + newXS ("weechat::bar_set", XS_weechat_bar_set, "weechat"); newXS ("weechat::bar_update", XS_weechat_bar_update, "weechat"); newXS ("weechat::bar_remove", XS_weechat_bar_remove, "weechat"); newXS ("weechat::command", XS_weechat_command, "weechat"); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 39691c1e9..33992d6b9 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -3343,6 +3343,41 @@ weechat_python_api_bar_new (PyObject *self, PyObject *args) } /* + * weechat_python_api_bar_set: set a bar property + */ + +static PyObject * +weechat_python_api_bar_set (PyObject *self, PyObject *args) +{ + char *bar, *property, *value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_set"); + PYTHON_RETURN_ERROR; + } + + bar = NULL; + property = NULL; + value = NULL; + + if (!PyArg_ParseTuple (args, "sss", &bar, &property, &value)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_set"); + PYTHON_RETURN_ERROR; + } + + weechat_buffer_set (script_str2ptr (bar), + property, + value); + + PYTHON_RETURN_OK; +} + +/* * weechat_python_api_bar_update: update a bar on screen */ @@ -3850,6 +3885,7 @@ PyMethodDef weechat_python_funcs[] = { "bar_item_remove", &weechat_python_api_bar_item_remove, METH_VARARGS, "" }, { "bar_search", &weechat_python_api_bar_search, METH_VARARGS, "" }, { "bar_new", &weechat_python_api_bar_new, METH_VARARGS, "" }, + { "bar_set", &weechat_python_api_bar_set, METH_VARARGS, "" }, { "bar_update", &weechat_python_api_bar_update, METH_VARARGS, "" }, { "bar_remove", &weechat_python_api_bar_remove, METH_VARARGS, "" }, { "command", &weechat_python_api_command, METH_VARARGS, "" }, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index d9ecbb013..52108c980 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -3856,6 +3856,45 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE type, VALUE position, } /* + * weechat_ruby_api_bar_set: set a bar property + */ + +static VALUE +weechat_ruby_api_bar_set (VALUE class, VALUE bar, VALUE property, VALUE value) +{ + char *c_bar, *c_property, *c_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_set"); + RUBY_RETURN_ERROR; + } + + if (NIL_P (bar) || NIL_P (property) || NIL_P (value)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_set"); + RUBY_RETURN_ERROR; + } + + Check_Type (bar, T_STRING); + Check_Type (property, T_STRING); + Check_Type (value, T_STRING); + + c_bar = STR2CSTR (bar); + c_property = STR2CSTR (property); + c_value = STR2CSTR (value); + + weechat_buffer_set (script_str2ptr (c_bar), + c_property, + c_value); + + RUBY_RETURN_OK; +} + +/* * weechat_ruby_api_bar_update: update a bar on screen */ @@ -4403,6 +4442,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "bar_item_remove", &weechat_ruby_api_bar_item_remove, 1); rb_define_module_function (ruby_mWeechat, "bar_search", &weechat_ruby_api_bar_search, 1); rb_define_module_function (ruby_mWeechat, "bar_new", &weechat_ruby_api_bar_new, 6); + rb_define_module_function (ruby_mWeechat, "bar_set", &weechat_ruby_api_bar_set, 3); rb_define_module_function (ruby_mWeechat, "bar_update", &weechat_ruby_api_bar_update, 1); rb_define_module_function (ruby_mWeechat, "bar_remove", &weechat_ruby_api_bar_remove, 1); rb_define_module_function (ruby_mWeechat, "command", &weechat_ruby_api_command, 2); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 6a5c039da..9a4f658b4 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -341,6 +341,7 @@ struct t_weechat_plugin struct t_gui_bar *(*bar_new) (struct t_weechat_plugin *plugin, char *name, char *type, char *position, int size, int separator, char *items); + void (*bar_set) (struct t_gui_bar *bar, char *property, char *value); void (*bar_update) (char *name); void (*bar_remove) (struct t_gui_bar *bar); @@ -694,6 +695,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __separator, __items) \ weechat_plugin->bar_new(weechat_plugin, __name, __type, __position, \ __size, __separator, __items) +#define weechat_bar_set(__bar, __property, __value) \ + weechat_plugin->bar_set(__bar, __property, __value) #define weechat_bar_update(__name) \ weechat_plugin->bar_update(__name) #define weechat_bar_remove(__bar) \ |