1 /**
2 * @file
3 * GUI handle the resizing of the screen
4 *
5 * @authors
6 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
7 * Copyright (C) 2018 Ivan J. <parazyd@dyne.org>
8 *
9 * @copyright
10 * This program is free software: you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License as published by the Free Software
12 * Foundation, either version 2 of the License, or (at your option) any later
13 * version.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 /**
25 * @page neo_resize GUI handle the resizing of the screen
26 *
27 * GUI handle the resizing of the screen
28 */
29
30 #include "config.h"
31 #include <stddef.h>
32 #include <fcntl.h>
33 #include <unistd.h>
34 #include "mutt/lib.h"
35 #include "gui/lib.h"
36 #ifdef HAVE_TERMIOS_H
37 #include <termios.h>
38 #endif
39 #ifndef HAVE_TCGETWINSIZE
40 #ifdef HAVE_SYS_IOCTL_H
41 #include <sys/ioctl.h>
42 #else
43 #ifdef HAVE_IOCTL_H
44 #include <ioctl.h>
45 #endif
46 #endif
47 #endif /* HAVE_TCGETWINSIZE */
48
49 /**
50 * mutt_get_winsize - Get the window size
51 * @retval obj Window size
52 */
mutt_get_winsize(void)53 static struct winsize mutt_get_winsize(void)
54 {
55 struct winsize w = { 0 };
56
57 int fd = open("/dev/tty", O_RDONLY);
58 if (fd != -1)
59 {
60 #ifdef HAVE_TCGETWINSIZE
61 tcgetwinsize(fd, &w);
62 #else
63 ioctl(fd, TIOCGWINSZ, &w);
64 #endif
65 close(fd);
66 }
67 return w;
68 }
69
70 /**
71 * mutt_resize_screen - Update NeoMutt's opinion about the window size (CURSES)
72 */
mutt_resize_screen(void)73 void mutt_resize_screen(void)
74 {
75 struct winsize w = mutt_get_winsize();
76
77 int screenrows = w.ws_row;
78 int screencols = w.ws_col;
79
80 if (screenrows <= 0)
81 {
82 const char *cp = mutt_str_getenv("LINES");
83 if (cp && (mutt_str_atoi(cp, &screenrows) < 0))
84 screenrows = 24;
85 }
86
87 if (screencols <= 0)
88 {
89 const char *cp = mutt_str_getenv("COLUMNS");
90 if (cp && (mutt_str_atoi(cp, &screencols) < 0))
91 screencols = 80;
92 }
93
94 resizeterm(screenrows, screencols);
95 rootwin_set_size(screencols, screenrows);
96 window_notify_all(NULL);
97 }
98