diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-02-25 16:34:41 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-02-25 16:34:41 +0100 |
commit | 613e9743e590b82db35d6c9a5686fb84a1ef8f9c (patch) | |
tree | d5f90d037710a1a1c20770ef3007d472cbcfd0f9 /src | |
parent | 4f9efe14e3fd74b9ec07bd3beb004d198b07a959 (diff) | |
download | weechat-613e9743e590b82db35d6c9a5686fb84a1ef8f9c.zip |
Fix bug with terminal resize: on some systems, weechat failed to read new terminal size
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/curses/gui-curses-main.c | 43 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 14 | ||||
-rw-r--r-- | src/gui/curses/gui-curses.h | 1 |
3 files changed, 41 insertions, 17 deletions
diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index e5f6dc283..3736ed272 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -28,6 +28,7 @@ #include <unistd.h> #include <string.h> #include <signal.h> +#include <sys/ioctl.h> #include "../../core/weechat.h" #include "../../core/wee-command.h" @@ -55,7 +56,8 @@ int gui_reload_config = 0; - +int gui_term_cols = 0; +int gui_term_lines = 0; /* * gui_main_pre_init: pre-initialize GUI (called before gui_init) @@ -85,6 +87,7 @@ gui_main_init () struct t_gui_buffer *ptr_buffer; struct t_gui_bar *ptr_bar; struct t_gui_bar_window *ptr_bar_win; + struct winsize size; initscr (); @@ -98,11 +101,21 @@ gui_main_init () /* build prefixes according to config */ gui_chat_prefix_build (); - gui_ok = ((COLS >= GUI_WINDOW_MIN_WIDTH) - && (LINES >= GUI_WINDOW_MIN_HEIGHT)); - refresh (); + gui_term_cols = COLS; + gui_term_lines = LINES; + + if (ioctl (fileno (stdout), TIOCGWINSZ, &size) == 0) + { + resizeterm(size.ws_row, size.ws_col); + gui_term_cols = size.ws_col; + gui_term_lines = size.ws_row; + } + + gui_ok = ((gui_term_cols >= GUI_WINDOW_MIN_WIDTH) + && (gui_term_lines >= GUI_WINDOW_MIN_HEIGHT)); + /* init clipboard buffer */ gui_input_clipboard = NULL; @@ -126,7 +139,8 @@ gui_main_init () " - " WEECHAT_WEBSITE); /* create main window (using full space) */ - if (gui_window_new (NULL, ptr_buffer, 0, 0, COLS, LINES, 100, 100)) + if (gui_window_new (NULL, ptr_buffer, 0, 0, + gui_term_cols, gui_term_lines, 100, 100)) { gui_current_window = gui_windows; @@ -201,6 +215,25 @@ gui_main_signal_sighup () void gui_main_signal_sigwinch () { + struct winsize size; + int new_width, new_height; + + if (ioctl (fileno (stdout), TIOCGWINSZ, &size) == 0) + { + resizeterm (size.ws_row, size.ws_col); + gui_term_cols = size.ws_col; + gui_term_lines = size.ws_row; + gui_ok = ((gui_term_cols >= GUI_WINDOW_MIN_WIDTH) + && (gui_term_lines >= GUI_WINDOW_MIN_HEIGHT)); + wrefresh (curscr); + } + else + { + getmaxyx (stdscr, new_height, new_width); + gui_term_cols = new_width; + gui_term_lines = new_height; + } + gui_window_refresh_needed = 1; } diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index a939facf2..6d7dc0080 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -59,7 +59,7 @@ int window_current_color_attr; /* attr sum of last color(s) used */ int gui_window_get_width () { - return COLS; + return gui_term_cols; } /* @@ -69,7 +69,7 @@ gui_window_get_width () int gui_window_get_height () { - return LINES; + return gui_term_lines; } /* @@ -1328,16 +1328,6 @@ gui_window_switch_right (struct t_gui_window *window) void gui_window_refresh_screen () { - int new_height, new_width; - - endwin (); - refresh (); - - getmaxyx (stdscr, new_height, new_width); - - gui_ok = ((new_width >= GUI_WINDOW_MIN_WIDTH) - && (new_height >= GUI_WINDOW_MIN_HEIGHT)); - if (gui_ok) { refresh (); diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index 5b13cf490..fef46369a 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -51,6 +51,7 @@ struct t_gui_bar_window_curses_objects WINDOW *win_separator; /* separator (optional) */ }; +extern int gui_term_cols, gui_term_lines; extern struct t_gui_color gui_weechat_colors[]; /* color functions */ |