Andreas Krennmair:
[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 #include "mutt.h"
20 #include "mutt_curses.h"
21
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <termios.h>
26
27 #ifdef HAVE_SYS_IOCTL_H
28 #include <sys/ioctl.h>
29 #else
30 # ifdef HAVE_IOCTL_H
31 # include <ioctl.h>
32 # endif
33 #endif
34
35 /* this routine should be called after receiving SIGWINCH */
36 void mutt_resize_screen (void)
37 {
38   char *cp;
39   int fd;
40   struct winsize w;
41 #ifdef HAVE_RESIZETERM
42   int SLtt_Screen_Rows, SLtt_Screen_Cols;
43 #endif
44
45   SLtt_Screen_Rows = -1;
46   SLtt_Screen_Cols = -1;
47   if ((fd = open ("/dev/tty", O_RDONLY)) != -1)
48   {
49     if (ioctl (fd, TIOCGWINSZ, &w) != -1)
50     {
51       SLtt_Screen_Rows = w.ws_row;
52       SLtt_Screen_Cols = w.ws_col;
53     }
54     close (fd);
55   }
56   if (SLtt_Screen_Rows <= 0)
57   {
58     if ((cp = getenv ("LINES")) != NULL)
59     {
60       SLtt_Screen_Rows = atoi (cp);
61     }
62     else
63       SLtt_Screen_Rows = 24;
64   }
65   if (SLtt_Screen_Cols <= 0)
66   {
67     if ((cp = getenv ("COLUMNS")) != NULL)
68       SLtt_Screen_Cols = atoi (cp);
69     else
70       SLtt_Screen_Cols = 80;
71   }
72 #ifdef USE_SLANG_CURSES
73   delwin (stdscr);
74   SLsmg_reset_smg ();
75   SLsmg_init_smg ();
76   stdscr = newwin (0, 0, 0, 0);
77   keypad (stdscr, TRUE);
78 #else
79   resizeterm (SLtt_Screen_Rows, SLtt_Screen_Cols);
80 #endif
81 }