From e0a3bf121f8ffdede7cd3a4885acf8eedd49bc1e Mon Sep 17 00:00:00 2001 From: Angel Ortega Date: Wed, 11 Jan 2012 10:02:42 +0100 Subject: [PATCH] Fixed ncurses window resize (Closes: #1170). --- TODO | 6 +++--- mpv_curses.c | 37 ++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index 9defd5c..47bc747 100644 --- a/TODO +++ b/TODO @@ -11,8 +11,6 @@ Open Bugs --------- * 1150: The GTK menu is not rebuilt when calling mp.update_ui(). - * 1170: The curses driver doesn't redraw when the terminal window - is resized. * 1176: Add interface to set the undo levels. * 1189: mp.drv.form() cannot be used from the command line in win32. * 1199: On GTK, the default font (Mono 12, seemingly an alias to an @@ -54,7 +52,7 @@ Pending Enhancements to be formed by just the executable with all MPSL code embedded (mainly aimed towards MS Windows). * 1284: Add version control support (git, svn, etc). - * 1293: Add a mp.plumber() game. + * 1293: Add a mp.pipes() game. Closed ------ @@ -364,5 +362,7 @@ Closed (Thu, 10 Nov 2011 13:34:55 +0100). * 1292: Insert new documents after the current one (Wed, 21 Dec 2011 16:09:50 +0100). + * 1170: The curses driver doesn't redraw when the terminal window + is resized (Wed, 11 Jan 2012 10:01:52 +0100). Email bugs to angel@triptico.com diff --git a/mpv_curses.c b/mpv_curses.c index 1a84a9a..704b101 100644 --- a/mpv_curses.c +++ b/mpv_curses.c @@ -4,7 +4,7 @@ Curses driver. - Copyright (C) 1991-2010 Angel Ortega + Copyright (C) 1991-2012 Angel Ortega This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -77,29 +77,13 @@ static void set_attr(void) } +#ifndef NCURSES_VERSION + static void nc_sigwinch(int s) /* SIGWINCH signal handler */ { mpdm_t v; -#ifdef NCURSES_VERSION - /* Make sure that window size changes... */ - struct winsize ws; - - int fd = open("/dev/tty", O_RDWR); - - if (fd == -1) - return; /* This should never have to happen! */ - - if (ioctl(fd, TIOCGWINSZ, &ws) == 0) - resizeterm(ws.ws_row, ws.ws_col); - - close(fd); -#else - /* restart curses */ - /* ... */ -#endif - /* invalidate main window */ clearok(stdscr, 1); refresh(); @@ -113,6 +97,8 @@ static void nc_sigwinch(int s) signal(SIGWINCH, nc_sigwinch); } +#endif + #ifdef CONFOPT_WGET_WCH int wget_wch(WINDOW * w, wint_t * ch); @@ -500,6 +486,17 @@ static mpdm_t nc_getkey(mpdm_t args, mpdm_t ctxt) case ctrl('z'): f = L"ctrl-z"; break; + case KEY_RESIZE: + + /* handle ncurses resizing */ + f = NULL; + { + mpdm_t v = mpdm_hget_s(mp, L"window"); + mpdm_hset_s(v, L"tx", MPDM_I(COLS)); + mpdm_hset_s(v, L"ty", MPDM_I(LINES)); + } + + break; case L'\e': shift = 1; f = NULL; @@ -830,7 +827,9 @@ static mpdm_t ncursesw_drv_startup(mpdm_t a) mpdm_hset_s(v, L"tx", MPDM_I(COLS)); mpdm_hset_s(v, L"ty", MPDM_I(LINES)); +#ifndef NCURSES_VERSION signal(SIGWINCH, nc_sigwinch); +#endif cw = stdscr; -- 2.11.4.GIT