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