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