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