rationnalize includes a lot:
[apps/madmutt.git] / lib-ui / resize.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 #include <lib-lib/lib-lib.h>
11
12 #if defined(USE_SLANG_CURSES) || defined(HAVE_RESIZETERM)
13
14 #include <termios.h>
15 #ifdef HAVE_SYS_IOCTL_H
16 #  include <sys/ioctl.h>
17 #elif defined(HAVE_IOCTL_H)
18 #  include <ioctl.h>
19 #endif
20
21 #include <lib-ui/curses.h>
22 #include "mutt.h"
23
24 /* this routine should be called after receiving SIGWINCH */
25 void mutt_resize_screen (void)
26 {
27   char *cp;
28   int fd;
29   struct winsize w;
30
31 #ifdef HAVE_RESIZETERM
32   int SLtt_Screen_Rows, SLtt_Screen_Cols;
33 #endif
34
35   SLtt_Screen_Rows = -1;
36   SLtt_Screen_Cols = -1;
37   if ((fd = open ("/dev/tty", O_RDONLY)) != -1) {
38     if (ioctl (fd, TIOCGWINSZ, &w) != -1) {
39       SLtt_Screen_Rows = w.ws_row;
40       SLtt_Screen_Cols = w.ws_col;
41     }
42     close (fd);
43   }
44   if (SLtt_Screen_Rows <= 0) {
45     if ((cp = getenv ("LINES")) != NULL) {
46       SLtt_Screen_Rows = atoi (cp);
47     }
48     else
49       SLtt_Screen_Rows = 24;
50   }
51   if (SLtt_Screen_Cols <= 0) {
52     if ((cp = getenv ("COLUMNS")) != NULL)
53       SLtt_Screen_Cols = atoi (cp);
54     else
55       SLtt_Screen_Cols = 80;
56   }
57 #ifdef USE_SLANG_CURSES
58   delwin (stdscr);
59   SLsmg_reset_smg ();
60   SLsmg_init_smg ();
61   stdscr = newwin (0, 0, 0, 0);
62   keypad (stdscr, TRUE);
63 #else
64   resizeterm (SLtt_Screen_Rows, SLtt_Screen_Cols);
65 #endif
66 }
67
68 #endif /* defined(USE_SLANG_CURSES) || defined(HAVE_RESIZETERM) */