Coverage Report

Created: 2023-09-25 07:17

/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) 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 gui_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 <fcntl.h>
32
#include <unistd.h>
33
#include "mutt/lib.h"
34
#include "mutt_curses.h"
35
#include "mutt_window.h"
36
#include "rootwin.h"
37
#ifdef HAVE_TERMIOS_H
38
#include <termios.h> // IWYU pragma: keep
39
#endif
40
#ifndef HAVE_TCGETWINSIZE
41
#ifdef HAVE_SYS_IOCTL_H
42
#include <sys/ioctl.h>
43
#else
44
#ifdef HAVE_IOCTL_H
45
#include <ioctl.h>
46
#endif
47
#endif
48
#endif /* HAVE_TCGETWINSIZE */
49
50
/**
51
 * mutt_get_winsize - Get the window size
52
 * @retval obj Window size
53
 */
54
static struct winsize mutt_get_winsize(void)
55
0
{
56
0
  struct winsize w = { 0 };
57
58
0
  int fd = open("/dev/tty", O_RDONLY);
59
0
  if (fd != -1)
60
0
  {
61
#ifdef HAVE_TCGETWINSIZE
62
    tcgetwinsize(fd, &w);
63
#else
64
0
    ioctl(fd, TIOCGWINSZ, &w);
65
0
#endif
66
0
    close(fd);
67
0
  }
68
0
  return w;
69
0
}
70
71
/**
72
 * mutt_resize_screen - Update NeoMutt's opinion about the window size
73
 */
74
void mutt_resize_screen(void)
75
0
{
76
0
  struct winsize w = mutt_get_winsize();
77
78
0
  int screenrows = w.ws_row;
79
0
  int screencols = w.ws_col;
80
81
0
  if (screenrows <= 0)
82
0
  {
83
0
    const char *cp = mutt_str_getenv("LINES");
84
0
    if (cp && !mutt_str_atoi_full(cp, &screenrows))
85
0
      screenrows = 24;
86
0
  }
87
88
0
  if (screencols <= 0)
89
0
  {
90
0
    const char *cp = mutt_str_getenv("COLUMNS");
91
0
    if (cp && !mutt_str_atoi_full(cp, &screencols))
92
0
      screencols = 80;
93
0
  }
94
95
0
  resizeterm(screenrows, screencols);
96
0
  rootwin_set_size(screencols, screenrows);
97
0
  window_notify_all(NULL);
98
0
}