Optimization of SIGWINCH handling.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-10-15 16:03:04 +04:00
parent 9cfff5ccbf
commit ea2c57dbd6
4 changed files with 55 additions and 64 deletions

View File

@ -34,6 +34,10 @@
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#include <termios.h>
#include "lib/global.h"
#include "lib/strutil.h" /* str_term_form */
@ -224,6 +228,36 @@ tty_shutdown (void)
/* --------------------------------------------------------------------------------------------- */
void
tty_change_screen_size (void)
{
#if defined(TIOCGWINSZ) && NCURSES_VERSION_MAJOR >= 4
struct winsize winsz;
winsz.ws_col = winsz.ws_row = 0;
#ifndef NCURSES_VERSION
tty_noraw_mode ();
tty_reset_screen ();
#endif
/* Ioctl on the STDIN_FILENO */
ioctl (fileno (stdout), TIOCGWINSZ, &winsz);
if (winsz.ws_col != 0 && winsz.ws_row != 0)
{
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
resizeterm (winsz.ws_row, winsz.ws_col);
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
#else
COLS = winsz.ws_col;
LINES = winsz.ws_row;
#endif
}
#endif /* defined(TIOCGWINSZ) || NCURSES_VERSION_MAJOR >= 4 */
}
/* --------------------------------------------------------------------------------------------- */
void
tty_reset_prog_mode (void)
{

View File

@ -34,10 +34,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <sys/types.h> /* size_t */
#include <unistd.h>
#include <signal.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#include <termios.h>
#include "lib/global.h"
#include "lib/strutil.h" /* str_term_form */
@ -153,7 +156,6 @@ sigwinch_handler (int dummy)
{
(void) dummy;
tty_change_screen_size ();
mc_global.tty.winch_flag = TRUE;
}
@ -372,6 +374,19 @@ tty_shutdown (void)
}
}
/* --------------------------------------------------------------------------------------------- */
void
tty_change_screen_size (void)
{
SLtt_get_screen_size ();
SLsmg_reinit_smg ();
do_enter_ca_mode ();
tty_keypad (TRUE);
tty_nodelay (FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/* Done each time we come back from done mode */

View File

@ -252,38 +252,6 @@ tty_resize (int fd)
/* --------------------------------------------------------------------------------------------- */
void
tty_change_screen_size (void)
{
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
#if defined TIOCGWINSZ
struct winsize winsz;
winsz.ws_col = winsz.ws_row = 0;
/* Ioctl on the STDIN_FILENO */
ioctl (0, TIOCGWINSZ, &winsz);
if (winsz.ws_col && winsz.ws_row)
{
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
resizeterm (winsz.ws_row, winsz.ws_col);
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
#else
COLS = winsz.ws_col;
LINES = winsz.ws_row;
#endif
#ifdef HAVE_SUBSHELL_SUPPORT
if (!mc_global.tty.use_subshell)
return;
tty_resize (mc_global.tty.subshell_pty);
#endif
}
#endif /* TIOCGWINSZ */
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
}
/* --------------------------------------------------------------------------------------------- */
void
tty_init_xterm_support (gboolean is_xterm)
{

View File

@ -32,16 +32,8 @@
#include <config.h>
/* If TIOCGWINSZ supported, make it available here, because window resizing code
* depends on it... */
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#include <termios.h>
#include "lib/global.h"
#include "lib/tty/tty.h" /* LINES, COLS */
#include "lib/tty/win.h" /* do_enter_ca_mode() */
#include "lib/tty/color.h" /* tty_set_normal_attrs() */
#include "lib/widget.h"
#include "lib/event.h"
@ -121,7 +113,6 @@ dialog_switch_goto (GList * dlg)
/* --------------------------------------------------------------------------------------------- */
#if defined TIOCGWINSZ
static void
dlg_resize_cb (void *data, void *user_data)
{
@ -133,7 +124,6 @@ dlg_resize_cb (void *data, void *user_data)
else
d->winch_pending = TRUE;
}
#endif
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
@ -374,25 +364,12 @@ void
dialog_change_screen_size (void)
{
mc_global.tty.winch_flag = FALSE;
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
#if defined TIOCGWINSZ
#ifndef NCURSES_VERSION
tty_noraw_mode ();
tty_reset_screen ();
#endif
tty_change_screen_size ();
#ifdef HAVE_SLANG
/* XSI Curses spec states that portable applications shall not invoke
* initscr() more than once. This kludge could be done within the scope
* of the specification by using endwin followed by a refresh (in fact,
* more than one curses implementation does this); it is guaranteed to work
* only with slang.
*/
SLsmg_init_smg ();
do_enter_ca_mode ();
tty_keypad (TRUE);
tty_nodelay (FALSE);
#ifdef HAVE_SUBSHELL_SUPPORT
if (mc_global.tty.use_subshell)
tty_resize (mc_global.tty.subshell_pty);
#endif
/* Inform all suspending dialogs */
@ -402,9 +379,6 @@ dialog_change_screen_size (void)
/* Now, force the redraw */
repaint_screen ();
#endif /* TIOCGWINSZ */
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
}
/* --------------------------------------------------------------------------------------------- */