diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2014-10-15 00:51:05 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2014-11-19 03:31:47 +0100 |
commit | b8dc6bb3cc2554f0fbadf37b0178f22e0766df2d (patch) | |
tree | 00a9f8a2b2dc2dbdbdc8b1f3fc06b94fb4599123 /src/utils.c | |
parent | b352a0fc8d49536322ffffa3b2d16d135d9a7996 (diff) | |
download | tdv-b8dc6bb3cc2554f0fbadf37b0178f22e0766df2d.tar.gz tdv-b8dc6bb3cc2554f0fbadf37b0178f22e0766df2d.tar.xz tdv-b8dc6bb3cc2554f0fbadf37b0178f22e0766df2d.zip |
Avoid flicker while resizing
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index 8636778..ebbd4a9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -20,7 +20,16 @@ #include <glib.h> #include <gio/gio.h> +#include <stdlib.h> +#include <errno.h> +#include <curses.h> +#include <termios.h> +#ifndef TIOCGWINSZ +#include <sys/ioctl.h> +#endif // ! TIOCGWINSZ + +#include "config.h" #include "utils.h" @@ -61,3 +70,34 @@ stream_read_string (GDataInputStream *dis, GError **error) return s; } + +static bool +xstrtoul (unsigned long *out, const char *s, int base) +{ + char *end; + errno = 0; + *out = strtoul (s, &end, base); + return errno == 0 && !*end && end != s; +} + +// Didn't want to have this ugly piece of code in the main source file; +// the standard endwin/refresh sequence makes the terminal flicker. +void +update_curses_terminal_size (void) +{ +#if defined (HAVE_RESIZE_TERM) && defined (TIOCGWINSZ) + struct winsize size; + if (!ioctl (STDOUT_FILENO, TIOCGWINSZ, (char *) &size)) + { + char *row = getenv ("LINES"); + char *col = getenv ("COLUMNS"); + unsigned long tmp; + resize_term ( + (row && xstrtoul (&tmp, row, 10)) ? tmp : size.ws_row, + (col && xstrtoul (&tmp, col, 10)) ? tmp : size.ws_col); + } +#else // HAVE_RESIZE_TERM && TIOCGWINSZ + endwin (); + refresh (); +#endif // HAVE_RESIZE_TERM && TIOCGWINSZ +} |