diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2005-02-06 03:13:33 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2005-02-06 03:13:33 +0000 |
commit | 0c695733b35e02254821e80d894e7f21d1bd3c10 (patch) | |
tree | 87190b3a70f1767ba084f12bf953b336c71c11ba /src | |
parent | df4ed3eebae586b2587732c36447f27a7f415808 (diff) | |
download | weechat-0c695733b35e02254821e80d894e7f21d1bd3c10.zip |
Improved /window command: now split and merge are ok, fixed crash when resizing terminal to small size
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 136 | ||||
-rw-r--r-- | src/common/completion.c | 53 | ||||
-rw-r--r-- | src/gui/curses/gui-display.c | 297 | ||||
-rw-r--r-- | src/gui/gui.h | 11 |
4 files changed, 392 insertions, 105 deletions
diff --git a/src/common/command.c b/src/common/command.c index 7b7cb68ba..e6cf37ad5 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -99,13 +99,13 @@ t_weechat_command weechat_commands[] = N_("alias_name"), N_("alias_name: name of alias to remove"), 1, 1, NULL, weechat_cmd_unalias }, { "window", N_("manage windows"), - N_("[action]"), - N_("action: action to do:\n" - " close close current window (under development!)\n" - " list list opened windows (no parameter implies this list)\n" - " splith split current window horizontally\n" - " splitv split current window vertically"), - 0, MAX_ARGS, weechat_cmd_window, NULL }, + N_("[list | splith | splitv | [merge [down | up | left | right | all]]]"), + N_( + " list list opened windows (no parameter implies this list)\n" + "splith split current window horizontally\n" + "splitv split current window vertically\n" + " merge merge window with another"), + 0, 2, weechat_cmd_window, NULL }, { NULL, NULL, NULL, NULL, 0, 0, NULL, NULL } }; @@ -788,6 +788,43 @@ weechat_cmd_alias (char *arguments) } /* + * weechat_cmd_buffer_display_info: display info about a buffer + */ + +void +weechat_cmd_buffer_display_info (t_gui_buffer *buffer) +{ + if (buffer->dcc) + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, "DCC\n"); + else if (BUFFER_IS_SERVER (buffer)) + { + gui_printf (NULL, _("Server: ")); + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, + "%s\n", SERVER(buffer)->name); + } + else if (BUFFER_IS_CHANNEL (buffer)) + { + gui_printf (NULL, _("Channel: ")); + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, + "%s", CHANNEL(buffer)->name); + gui_printf (NULL, _(" (server: ")); + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, + "%s", SERVER(buffer)->name); + gui_printf (NULL, ")\n"); + } + else if (BUFFER_IS_PRIVATE (buffer)) + { + gui_printf (NULL, _("Private with: ")); + gui_printf_color (NULL, COLOR_WIN_CHAT_NICK, + "%s", CHANNEL(buffer)->name); + gui_printf (NULL, _(" (server: ")); + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, + "%s", SERVER(buffer)->name); + gui_printf (NULL, ")\n"); + } +} + +/* * weechat_cmd_buffer: manage buffers */ @@ -813,34 +850,7 @@ weechat_cmd_buffer (int argc, char **argv) gui_printf (NULL, "%d", ptr_buffer->number); gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "] "); - if (ptr_buffer->dcc) - gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, "DCC\n"); - else if (BUFFER_IS_SERVER (ptr_buffer)) - { - gui_printf (NULL, _("Server: ")); - gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, - "%s\n", SERVER(ptr_buffer)->name); - } - else if (BUFFER_IS_CHANNEL (ptr_buffer)) - { - gui_printf (NULL, _("Channel: ")); - gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, - "%s", CHANNEL(ptr_buffer)->name); - gui_printf (NULL, _(" (server: ")); - gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, - "%s", SERVER(ptr_buffer)->name); - gui_printf (NULL, ")\n"); - } - else if (BUFFER_IS_PRIVATE (ptr_buffer)) - { - gui_printf (NULL, _("Private with: ")); - gui_printf_color (NULL, COLOR_WIN_CHAT_NICK, - "%s", CHANNEL(ptr_buffer)->name); - gui_printf (NULL, _(" (server: ")); - gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, - "%s", SERVER(ptr_buffer)->name); - gui_printf (NULL, ")\n"); - } + weechat_cmd_buffer_display_info (ptr_buffer); } } else @@ -1966,11 +1976,36 @@ weechat_cmd_unalias (char *arguments) int weechat_cmd_window (int argc, char **argv) { + t_gui_window *ptr_win; + int i; + if ((argc == 0) || ((argc == 1) && (strcasecmp (argv[0], "list") == 0))) { /* list opened windows */ - irc_display_prefix (NULL, PREFIX_ERROR); - gui_printf (NULL, "window list -- NOT DEVELOPED!\n"); + + irc_display_prefix (NULL, PREFIX_INFO); + gui_printf (NULL, _("Opened windows:\n")); + + i = 1; + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + irc_display_prefix (NULL, PREFIX_INFO); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "["); + gui_printf (NULL, "%d", i); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "] ("); + gui_printf (NULL, "%d", ptr_win->win_x); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, ":"); + gui_printf (NULL, "%d", ptr_win->win_y); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, ";"); + gui_printf (NULL, "%d", ptr_win->win_width); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "x"); + gui_printf (NULL, "%d", ptr_win->win_height); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, ") "); + + weechat_cmd_buffer_display_info (ptr_win->buffer); + + i++; + } } else { @@ -1984,12 +2019,39 @@ weechat_cmd_window (int argc, char **argv) /* split window vertically */ gui_window_split_vertic (gui_current_window); } + else if (strcasecmp (argv[0], "merge") == 0) + { + if (argc >= 2) + { + if (strcasecmp (argv[1], "down") == 0) + gui_window_merge_down (gui_current_window); + else if (strcasecmp (argv[1], "up") == 0) + gui_window_merge_up (gui_current_window); + else if (strcasecmp (argv[1], "left") == 0) + gui_window_merge_left (gui_current_window); + else if (strcasecmp (argv[1], "right") == 0) + gui_window_merge_right (gui_current_window); + else if (strcasecmp (argv[1], "all") == 0) + gui_window_merge_all (gui_current_window); + else + { + irc_display_prefix (NULL, PREFIX_ERROR); + gui_printf (NULL, + _("%s unknown option for \"%s\" command\n"), + WEECHAT_ERROR, "window merge"); + return -1; + } + } + else + gui_window_merge_auto (gui_current_window); + } else { irc_display_prefix (NULL, PREFIX_ERROR); gui_printf (NULL, _("%s unknown option for \"%s\" command\n"), WEECHAT_ERROR, "window"); + return -1; } } return 0; diff --git a/src/common/completion.c b/src/common/completion.c index 1ca4ad225..f0aea7cd1 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -233,21 +233,46 @@ completion_build_list (t_completion *completion, void *channel) } return; } - if ((strcasecmp (completion->base_command, "window") == 0) - && (completion->base_command_arg == 2)) + if (strcasecmp (completion->base_command, "window") == 0) { - weelist_add (&completion->completion_list, - &completion->last_completion, - "close"); - weelist_add (&completion->completion_list, - &completion->last_completion, - "list"); - weelist_add (&completion->completion_list, - &completion->last_completion, - "splith"); - weelist_add (&completion->completion_list, - &completion->last_completion, - "splitv"); + if (completion->base_command_arg == 1) + { + weelist_add (&completion->completion_list, + &completion->last_completion, + "list"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "splith"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "splitv"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "merge"); + return; + } + + if (completion->base_command_arg == 2) + { + weelist_add (&completion->completion_list, + &completion->last_completion, + "down"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "up"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "left"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "right"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "all"); + return; + } + + completion_stop (completion); return; } diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c index 1fe7ea1e9..591cccecb 100644 --- a/src/gui/curses/gui-display.c +++ b/src/gui/curses/gui-display.c @@ -299,6 +299,29 @@ gui_curses_window_clear (WINDOW *window) } /* + * gui_draw_window_separator: draw window separation + */ + +void +gui_draw_window_separator (t_gui_window *window) +{ + if (window->win_separator) + delwin (window->win_separator); + + if (window->win_x > 0) + { + window->win_separator = newwin (window->win_height, + 1, + window->win_y, + window->win_x - 1); + gui_window_set_color (window->win_separator, COLOR_WIN_TITLE); + wborder (window->win_separator, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + wrefresh (window->win_separator); + refresh (); + } +} + +/* * gui_draw_buffer_title: draw title window for a buffer */ @@ -419,6 +442,8 @@ gui_display_end_of_line (t_gui_window *window, t_gui_line *line, int count) { num_displayed = window->win_chat_width - window->win_chat_cursor_x; + if (num_displayed < 0) + return; saved_char = ptr_message->message[offset + num_displayed]; ptr_message->message[offset + num_displayed] = '\0'; if (lines_displayed >= num_lines - count) @@ -1583,49 +1608,6 @@ gui_move_page_down (t_gui_window *window) } /* - * gui_curses_resize_handler: called when term size is modified - */ - -void -gui_curses_resize_handler () -{ - t_gui_window *ptr_win, *old_current_window; - int old_width, old_height; - int new_width, new_height; - - getmaxyx (stdscr, old_height, old_width); - - endwin (); - refresh (); - - getmaxyx (stdscr, new_height, new_width); - - old_current_window = gui_current_window; - - /* TODO: manage when some windows are outside new term size */ - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - ptr_win->dcc_first = NULL; - ptr_win->dcc_selected = NULL; - if (ptr_win->win_x + ptr_win->win_width == old_width) - ptr_win->win_width = new_width - ptr_win->win_x; - if (ptr_win->win_y + ptr_win->win_height == old_height) - ptr_win->win_height = new_height - ptr_win->win_y; - gui_switch_to_buffer (ptr_win, ptr_win->buffer); - } - - gui_current_window = old_current_window; - if ((new_width > 5) && (new_height > 5)) - { - gui_ok = 1; - gui_calculate_pos_size (gui_current_window); - gui_redraw_buffer (gui_current_window->buffer); - } - else - gui_ok = 0; -} - -/* * gui_window_init_subviews: init subviews for a WeeChat window */ @@ -1703,16 +1685,227 @@ gui_window_split_vertic (t_gui_window *window) gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); gui_redraw_buffer (gui_current_window->buffer); - /* create & draw separator if window is not on the left */ - gui_current_window->win_separator = newwin (gui_current_window->win_height, - 1, - gui_current_window->win_y, - gui_current_window->win_x - 1); - gui_window_set_color (gui_current_window->win_separator, COLOR_WIN_TITLE); - wborder (gui_current_window->win_separator, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); - wrefresh (gui_current_window->win_separator); - refresh (); + /* create & draw separator */ + gui_draw_window_separator (gui_current_window); + } +} + +/* + * gui_window_merge_down: merge window, direction down + */ + +int +gui_window_merge_down (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win != window) + { + if ((ptr_win->win_y == window->win_y + window->win_height) + && (ptr_win->win_x == window->win_x) + && (ptr_win->win_width == window->win_width)) + { + window->win_height += ptr_win->win_height; + gui_window_free (ptr_win); + gui_switch_to_buffer (window, window->buffer); + gui_redraw_buffer (window->buffer); + return 0; + } + } + } + + /* no window found below current window */ + return -1; +} + +/* + * gui_window_merge_up: merge window, direction up + */ + +int +gui_window_merge_up (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win != window) + { + if ((ptr_win->win_y + ptr_win->win_height == window->win_y) + && (ptr_win->win_x == window->win_x) + && (ptr_win->win_width == window->win_width)) + { + window->win_height += ptr_win->win_height; + window->win_y -= ptr_win->win_height; + gui_window_free (ptr_win); + gui_switch_to_buffer (window, window->buffer); + gui_redraw_buffer (window->buffer); + return 0; + } + } + } + + /* no window found above current window */ + return -1; +} + +/* + * gui_window_merge_left: merge window, direction left + */ + +int +gui_window_merge_left (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win != window) + { + if ((ptr_win->win_x + ptr_win->win_width + 1 == window->win_x) + && (ptr_win->win_y == window->win_y) + && (ptr_win->win_height == window->win_height)) + { + window->win_width += ptr_win->win_width + 1; + window->win_x -= ptr_win->win_width + 1; + gui_window_free (ptr_win); + gui_switch_to_buffer (window, window->buffer); + gui_redraw_buffer (window->buffer); + return 0; + } + } } + + /* no window found on the left of current window */ + return -1; +} + +/* + * gui_window_merge_right: merge window, direction right + */ + +int +gui_window_merge_right (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win != window) + { + if ((ptr_win->win_x == window->win_x + window->win_width + 1) + && (ptr_win->win_y == window->win_y) + && (ptr_win->win_height == window->win_height)) + { + window->win_width += ptr_win->win_width + 1; + gui_window_free (ptr_win); + gui_switch_to_buffer (window, window->buffer); + gui_redraw_buffer (window->buffer); + return 0; + } + } + } + + /* no window found on the right of current window */ + return -1; +} + +/* + * gui_window_merge: merge a window, direction auto + */ + +void +gui_window_merge_auto (t_gui_window *window) +{ + if (gui_window_merge_down (window) == 0) + return; + if (gui_window_merge_up (window) == 0) + return; + if (gui_window_merge_left (window) == 0) + return; + if (gui_window_merge_right (window) == 0) + return; +} + +/* + * gui_window_merge_all: merge all windows + */ + +void +gui_window_merge_all (t_gui_window *window) +{ + while (gui_windows->next_window) + { + gui_window_free ((gui_windows == window) ? gui_windows->next_window : gui_windows); + } + window->win_x = 0; + window->win_y = 0; + window->win_width = COLS; + window->win_height = LINES; + gui_switch_to_buffer (window, window->buffer); + gui_redraw_buffer (window->buffer); +} + +/* + * gui_curses_resize_handler: called when term size is modified + */ + +void +gui_curses_resize_handler () +{ + t_gui_window *ptr_win, *old_current_window; + int old_width, old_height; + int new_width, new_height; + int merge_all_windows; + + getmaxyx (stdscr, old_height, old_width); + + endwin (); + refresh (); + + getmaxyx (stdscr, new_height, new_width); + + old_current_window = gui_current_window; + + gui_ok = ((new_width > 5) && (new_height > 5)); + + merge_all_windows = 0; + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + ptr_win->dcc_first = NULL; + ptr_win->dcc_selected = NULL; + + if (!merge_all_windows) + { + if ((ptr_win->win_x > new_width - 5) + || (ptr_win->win_y > new_height - 5)) + merge_all_windows = 1; + else + { + if (ptr_win->win_x + ptr_win->win_width == old_width) + ptr_win->win_width = new_width - ptr_win->win_x; + if (ptr_win->win_y + ptr_win->win_height == old_height) + ptr_win->win_height = new_height - ptr_win->win_y; + if ((ptr_win->win_width < 5) || (ptr_win->win_height < 5)) + merge_all_windows = 1; + } + } + } + + if (merge_all_windows) + gui_window_merge_all (gui_current_window); + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + gui_calculate_pos_size (ptr_win); + gui_switch_to_buffer (ptr_win, ptr_win->buffer); + gui_draw_window_separator (ptr_win); + } + + gui_current_window = old_current_window; + gui_redraw_buffer (gui_current_window->buffer); } /* diff --git a/src/gui/gui.h b/src/gui/gui.h index 756a807a4..1056ce1f6 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -247,9 +247,8 @@ extern t_gui_buffer *last_gui_buffer; extern t_gui_buffer *buffer_before_dcc; extern t_gui_infobar *gui_infobar; -/* prototypes */ - /* GUI independent functions */ + extern t_gui_window *gui_window_new (int, int, int, int); extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int); extern void gui_buffer_clear (t_gui_buffer *); @@ -267,7 +266,9 @@ extern void gui_move_next_word (t_gui_buffer *); extern void gui_buffer_insert_string (t_gui_buffer *, char *, int); extern t_gui_buffer *gui_switch_to_buffer_by_number (t_gui_window *, int); extern void gui_move_buffer_to_number (t_gui_window *, int); + /* GUI dependant functions */ + extern int gui_assign_color (int *, char *); extern int gui_get_color_by_name (char *); extern char *gui_get_color_by_value (int); @@ -292,6 +293,12 @@ extern void gui_curses_resize_handler (); extern void gui_window_init_subwindows (t_gui_window *); extern void gui_window_split_horiz (t_gui_window *); extern void gui_window_split_vertic (t_gui_window *); +extern int gui_window_merge_up (t_gui_window *); +extern int gui_window_merge_down (t_gui_window *); +extern int gui_window_merge_left (t_gui_window *); +extern int gui_window_merge_right (t_gui_window *); +extern void gui_window_merge_auto (t_gui_window *); +extern void gui_window_merge_all (t_gui_window *); extern void gui_pre_init (int *, char **[]); extern void gui_init_colors (); extern void gui_set_window_title (); |