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