Nico Golde:
[apps/madmutt.git] / resize.c
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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 */
40 void 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)
63     {
64       SLtt_Screen_Rows = atoi (cp);
65     }
66     else
67       SLtt_Screen_Rows = 24;
68   }
69   if (SLtt_Screen_Cols <= 0)
70   {
71     if ((cp = getenv ("COLUMNS")) != NULL)
72       SLtt_Screen_Cols = atoi (cp);
73     else
74       SLtt_Screen_Cols = 80;
75   }
76 #ifdef USE_SLANG_CURSES
77   delwin (stdscr);
78   SLsmg_reset_smg ();
79   SLsmg_init_smg ();
80   stdscr = newwin (0, 0, 0, 0);
81   keypad (stdscr, TRUE);
82 #else
83   resizeterm (SLtt_Screen_Rows, SLtt_Screen_Cols);
84 #endif
85 }