mutt stable branch with some hacks
1/*
2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#if HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include "mutt.h"
24#include "mutt_curses.h"
25
26#include <stdlib.h>
27#include <unistd.h>
28#include <fcntl.h>
29#include <termios.h>
30
31#ifdef HAVE_SYS_IOCTL_H
32#include <sys/ioctl.h>
33#else
34# ifdef HAVE_IOCTL_H
35# include <ioctl.h>
36# endif
37#endif
38
39/* this routine should be called after receiving SIGWINCH */
40void mutt_resize_screen (void)
41{
42 char *cp;
43 int fd;
44 struct winsize w;
45#ifdef HAVE_RESIZETERM
46 int SLtt_Screen_Rows, SLtt_Screen_Cols;
47#endif
48
49 SLtt_Screen_Rows = -1;
50 SLtt_Screen_Cols = -1;
51 if ((fd = open ("/dev/tty", O_RDONLY)) != -1)
52 {
53 if (ioctl (fd, TIOCGWINSZ, &w) != -1)
54 {
55 SLtt_Screen_Rows = w.ws_row;
56 SLtt_Screen_Cols = w.ws_col;
57 }
58 close (fd);
59 }
60 if (SLtt_Screen_Rows <= 0)
61 {
62 if ((cp = getenv ("LINES")) != NULL && mutt_atoi (cp, &SLtt_Screen_Rows) < 0)
63 SLtt_Screen_Rows = 24;
64 }
65 if (SLtt_Screen_Cols <= 0)
66 {
67 if ((cp = getenv ("COLUMNS")) != NULL && mutt_atoi (cp, &SLtt_Screen_Cols) < 0)
68 SLtt_Screen_Cols = 80;
69 }
70#ifdef USE_SLANG_CURSES
71 delwin (stdscr);
72 SLsmg_reset_smg ();
73 SLsmg_init_smg ();
74 stdscr = newwin (0, 0, 0, 0);
75 keypad (stdscr, TRUE);
76#else
77 resizeterm (SLtt_Screen_Rows, SLtt_Screen_Cols);
78#endif
79 mutt_reflow_windows ();
80}