diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-bar-window.c | 3 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-chat.c | 147 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-key.c | 1 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-main.c | 33 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 104 | ||||
-rw-r--r-- | src/gui/curses/gui-curses.h | 1 | ||||
-rw-r--r-- | src/gui/gui-input.c | 30 | ||||
-rw-r--r-- | src/gui/gui-key.c | 3 | ||||
-rw-r--r-- | src/gui/gui-window.c | 4 | ||||
-rw-r--r-- | src/gui/gui-window.h | 3 |
10 files changed, 279 insertions, 50 deletions
diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c index 3571d8e8b..b75dab8cf 100644 --- a/src/gui/curses/gui-curses-bar-window.c +++ b/src/gui/curses/gui-curses-bar-window.c @@ -411,6 +411,9 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, if (!gui_init_ok) return; + if (gui_window_bare_display) + return; + if ((bar_window->x < 0) || (bar_window->y < 0)) return; diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 464518bd2..b84a61341 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -24,6 +24,7 @@ #endif #include <stdlib.h> +#include <stdio.h> #include <string.h> #include <time.h> @@ -1844,6 +1845,144 @@ gui_chat_draw_free_buffer (struct t_gui_window *window, int clear_chat) } /* + * Gets line content in bare display. + */ + +char * +gui_chat_get_bare_line (struct t_gui_line *line) +{ + char *prefix, *message, str_time[256], *str_line; + const char *tag_prefix_nick; + struct tm *local_time; + int length; + + prefix = NULL; + message = NULL; + str_line = NULL; + + prefix = (line->data->prefix) ? + gui_color_decode (line->data->prefix, NULL) : strdup (""); + if (!prefix) + goto end; + message = (line->data->message) ? + gui_color_decode (line->data->message, NULL) : strdup (""); + if (!message) + goto end; + + str_time[0] = '\0'; + if ((line->data->date > 0) + && CONFIG_STRING(config_look_bare_display_time_format) + && CONFIG_STRING(config_look_bare_display_time_format)[0]) + { + local_time = localtime (&line->data->date); + strftime (str_time, sizeof (str_time), + CONFIG_STRING(config_look_bare_display_time_format), + local_time); + } + tag_prefix_nick = gui_line_search_tag_starting_with (line, "prefix_nick_"); + + length = strlen (str_time) + 1 + 1 + strlen (prefix) + 1 + 1 + + strlen (message) + 1; + str_line = malloc (length); + if (str_line) + { + snprintf (str_line, length, + "%s%s%s%s%s%s%s", + str_time, + (str_time[0]) ? " " : "", + (prefix[0] && tag_prefix_nick) ? "<" : "", + prefix, + (prefix[0] && tag_prefix_nick) ? ">" : "", + (prefix[0]) ? " " : "", + message); + } + +end: + if (prefix) + free (prefix); + if (message) + free (message); + + return str_line; +} + +/* + * Draws a buffer in bare display (not ncurses). + */ + +void +gui_chat_draw_bare (struct t_gui_window *window) +{ + struct t_gui_line *ptr_line; + char *line; + int y, length, num_lines; + + /* in bare display, we display ONLY the current window/buffer */ + if (window != gui_current_window) + return; + + /* clear screen */ + printf ("\033[2J"); + + /* display lines */ + if ((window->buffer->type == GUI_BUFFER_TYPE_FREE) + || window->scroll->start_line) + { + /* display from top to bottom (starting with "start_line") */ + y = 0; + ptr_line = (window->scroll->start_line) ? + window->scroll->start_line : gui_line_get_first_displayed (window->buffer); + while (ptr_line && (y < gui_term_lines)) + { + line = gui_chat_get_bare_line (ptr_line); + if (!line) + break; + length = utf8_strlen_screen (line); + num_lines = length / gui_term_cols; + if (length % gui_term_cols != 0) + num_lines++; + if (y + num_lines <= gui_term_lines) + printf ("\033[%d;1H%s", y + 1, line); + free (line); + y += num_lines; + ptr_line = gui_line_get_next_displayed (ptr_line); + } + } + else + { + /* display from bottom to top (starting with last line of buffer) */ + y = gui_term_lines; + ptr_line = gui_line_get_last_displayed (window->buffer); + while (ptr_line && (y >= 0)) + { + line = gui_chat_get_bare_line (ptr_line); + if (!line) + break; + length = utf8_strlen_screen (line); + num_lines = length / gui_term_cols; + if (length % gui_term_cols != 0) + num_lines++; + y -= num_lines; + if (y >= 0) + printf ("\033[%d;1H%s", y + 1, line); + free (line); + ptr_line = gui_line_get_prev_displayed (ptr_line); + } + } + + /* + * move cursor to top/left or bottom/right, according to type of buffer and + * whether we are scrolling or not + */ + printf ("\033[%d;1H", + (window->buffer->type == GUI_BUFFER_TYPE_FREE) ? + ((window->scroll->start_line) ? gui_term_lines : 1) : + ((window->scroll->start_line) ? 1 : gui_term_lines)); + + fflush (stdout); +} + +/* * Draws chat window for a buffer. */ @@ -1858,6 +1997,13 @@ gui_chat_draw (struct t_gui_buffer *buffer, int clear_chat) if (!gui_init_ok) return; + if (gui_window_bare_display) + { + if (gui_current_window && (gui_current_window->buffer == buffer)) + gui_chat_draw_bare (gui_current_window); + goto end; + } + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { if ((ptr_win->buffer->number == buffer->number) @@ -1914,5 +2060,6 @@ gui_chat_draw (struct t_gui_buffer *buffer, int clear_chat) } } +end: buffer->chat_refresh_needed = 0; } diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c index fe8b6b7a8..c28ae8f8c 100644 --- a/src/gui/curses/gui-curses-key.c +++ b/src/gui/curses/gui-curses-key.c @@ -214,6 +214,7 @@ gui_key_default_bindings (int context) BIND(/* m-m */ "meta-m", "/mute mouse toggle"); BIND(/* start paste */ "meta2-200~", "/input paste_start"); BIND(/* end paste */ "meta2-201~", "/input paste_stop"); + BIND(/* bare display*/ "meta-!", "/window bare"); /* bind meta-j + {01..99} to switch to buffers # > 10 */ for (i = 1; i < 100; i++) diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index 92801af54..3a0f27435 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -59,10 +59,10 @@ #include "gui-curses.h" -int gui_reload_config = 0; -int gui_signal_sigwinch_received = 0; -int gui_term_cols = 0; -int gui_term_lines = 0; +int gui_reload_config = 0; /* 1 if config must be reloaded */ +int gui_signal_sigwinch_received = 0; /* sigwinch signal (term resized) */ +int gui_term_cols = 0; /* number of columns in terminal */ +int gui_term_lines = 0; /* number of lines in terminal */ /* @@ -375,9 +375,7 @@ gui_main_refreshs () for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { if (ptr_bar->bar_refresh_needed) - { gui_bar_draw (ptr_bar); - } } /* refresh window if needed (if asked during refresh of bars) */ @@ -393,7 +391,7 @@ gui_main_refreshs () if (ptr_win->refresh_needed) { gui_window_switch_to_buffer (ptr_win, ptr_win->buffer, 0); - gui_window_redraw_buffer (ptr_win->buffer); + gui_chat_draw (ptr_win->buffer, 1); ptr_win->refresh_needed = 0; } } @@ -409,18 +407,21 @@ gui_main_refreshs () } } - /* refresh bars if needed */ - for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + if (!gui_window_bare_display) { - if (ptr_bar->bar_refresh_needed) + /* refresh bars if needed */ + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { - gui_bar_draw (ptr_bar); + if (ptr_bar->bar_refresh_needed) + { + gui_bar_draw (ptr_bar); + } } - } - /* move cursor (for cursor mode) */ - if (gui_cursor_mode) - gui_window_move_cursor (); + /* move cursor (for cursor mode) */ + if (gui_cursor_mode) + gui_window_move_cursor (); + } } /* @@ -476,7 +477,7 @@ gui_main_loop () } gui_main_refreshs (); - if (gui_window_refresh_needed) + if (gui_window_refresh_needed && !gui_window_bare_display) gui_main_refreshs (); if (gui_signal_sigwinch_received) diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index da1ed2bf3..b30c2e796 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -53,6 +53,7 @@ #include "../gui-layout.h" #include "../gui-line.h" #include "../gui-main.h" +#include "../gui-mouse.h" #include "../gui-nicklist.h" #include "gui-curses.h" @@ -1162,38 +1163,6 @@ gui_window_draw_separators (struct t_gui_window *window) } /* - * Redraws a buffer. - */ - -void -gui_window_redraw_buffer (struct t_gui_buffer *buffer) -{ - if (!gui_init_ok) - return; - - gui_chat_draw (buffer, 1); -} - -/* - * Redraws all buffers. - */ - -void -gui_window_redraw_all_buffers () -{ - struct t_gui_buffer *ptr_buffer; - - if (!gui_init_ok) - return; - - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - gui_window_redraw_buffer (ptr_buffer); - } -} - -/* * Switches to another buffer in a window. */ @@ -2380,6 +2349,77 @@ gui_window_refresh_screen (int full_refresh) } /* + * Callback for bare display timer. + */ + +int +gui_window_bare_display_timer_cb (void *data, int remaining_calls) +{ + /* make C compiler happy */ + (void) data; + + if (gui_window_bare_display) + gui_window_bare_display_toggle (NULL); + + if (remaining_calls == 0) + gui_window_bare_display_timer = NULL; + + return WEECHAT_RC_OK; +} + +/* + * Toggles bare display. + */ + +void +gui_window_bare_display_toggle (const char *delay) +{ + long milliseconds; + char *error; + + gui_window_bare_display ^= 1; + + if (gui_window_bare_display) + { + /* temporarily disable ncurses */ + endwin (); + if (gui_mouse_enabled) + gui_mouse_disable (); + if (delay) + { + error = NULL; + milliseconds = strtol (delay, &error, 10); + if (error && !error[0] && (milliseconds >= 0)) + { + if (gui_window_bare_display_timer) + { + unhook (gui_window_bare_display_timer); + gui_window_bare_display_timer = NULL; + } + gui_window_bare_display_timer = hook_timer ( + NULL, + milliseconds, 0, 1, + &gui_window_bare_display_timer_cb, NULL); + } + } + } + else + { + /* come back to standard display (with ncurses) */ + refresh (); + if (gui_window_bare_display_timer) + { + unhook (gui_window_bare_display_timer); + gui_window_bare_display_timer = NULL; + } + if (CONFIG_BOOLEAN(config_look_mouse)) + gui_mouse_enable (); + } + + gui_window_ask_refresh (2); +} + +/* * Sets terminal title. * * Note: the content of "title" (if not NULL) is evaluated, so variables like diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index 4b85c53e4..35c4b9b20 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -99,7 +99,6 @@ extern int gui_key_read_cb (void *data, int fd); /* window functions */ extern void gui_window_read_terminal_size (); -extern void gui_window_redraw_buffer (struct t_gui_buffer *buffer); extern void gui_window_clear (WINDOW *window, int fg, int bg); extern void gui_window_clrtoeol (WINDOW *window); extern void gui_window_save_style (WINDOW *window); diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index 8836d957e..47412201d 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -123,6 +123,12 @@ gui_input_replace_input (struct t_gui_buffer *buffer, const char *new_input) void gui_input_paste_pending_signal () { + if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input) + && gui_window_bare_display) + { + gui_window_bare_display_toggle (NULL); + } + (void) hook_signal_send ("input_paste_pending", WEECHAT_HOOK_SIGNAL_STRING, NULL); } @@ -138,6 +144,12 @@ gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer, { char str_buffer[128], *new_input; + if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input) + && gui_window_bare_display) + { + gui_window_bare_display_toggle (NULL); + } + if (!gui_cursor_mode) { if (save_undo) @@ -178,6 +190,12 @@ gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer, void gui_input_text_cursor_moved_signal (struct t_gui_buffer *buffer) { + if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input) + && gui_window_bare_display) + { + gui_window_bare_display_toggle (NULL); + } + (void) hook_signal_send ("input_text_cursor_moved", WEECHAT_HOOK_SIGNAL_POINTER, buffer); } @@ -189,6 +207,12 @@ gui_input_text_cursor_moved_signal (struct t_gui_buffer *buffer) void gui_input_search_signal (struct t_gui_buffer *buffer) { + if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input) + && gui_window_bare_display) + { + gui_window_bare_display_toggle (NULL); + } + (void) hook_signal_send ("input_search", WEECHAT_HOOK_SIGNAL_POINTER, buffer); } @@ -385,6 +409,12 @@ gui_input_return (struct t_gui_buffer *buffer) struct t_gui_window *window; char *command; + if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input) + && gui_window_bare_display) + { + gui_window_bare_display_toggle (NULL); + } + window = gui_window_search_with_buffer (buffer); if (window && window->buffer->input && (window->buffer->input_buffer_size > 0)) diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 0b77179c9..0c9a1a02a 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -1278,7 +1278,8 @@ gui_key_pressed (const char *key_str) if (pos) { pos[0] = '\0'; - gui_mouse_event_end (); + if (!gui_window_bare_display) + gui_mouse_event_end (); gui_mouse_event_init (); } return 0; diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 7e9bc0619..ca059e541 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -67,6 +67,10 @@ struct t_gui_window_tree *gui_windows_tree = NULL; /* windows tree */ int gui_window_cursor_x = 0; /* cursor pos on screen */ int gui_window_cursor_y = 0; /* cursor pos on screen */ +int gui_window_bare_display = 0; /* 1 for bare disp. (disable ncurses)*/ +struct t_hook *gui_window_bare_display_timer = NULL; + /* timer for bare display */ + /* * Searches for a window by number. diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h index 8b3b41a0b..0c17cbb73 100644 --- a/src/gui/gui-window.h +++ b/src/gui/gui-window.h @@ -124,6 +124,8 @@ extern struct t_gui_window *gui_current_window; extern struct t_gui_window_tree *gui_windows_tree; extern int gui_window_cursor_x; extern int gui_window_cursor_y; +extern int gui_window_bare_display; +extern struct t_hook *gui_window_bare_display_timer; /* window functions */ @@ -229,6 +231,7 @@ extern void gui_window_switch_right (struct t_gui_window *window); extern int gui_window_balance (struct t_gui_window_tree *tree); extern void gui_window_swap (struct t_gui_window *window, int direction); extern void gui_window_refresh_screen (int full_refresh); +extern void gui_window_bare_display_toggle (const char *delay); extern void gui_window_set_title (const char *title); extern void gui_window_send_clipboard (const char *storage_unit, const char *text); |