NeoMutt  2020-06-26-30-g76c339
Teaching an old dog new tricks
DOXYGEN
resize.c
Go to the documentation of this file.
1 
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 USE_SLANG_CURSES
37 #include <stdbool.h>
38 #endif
39 #ifdef HAVE_SYS_IOCTL_H
40 #include <sys/ioctl.h>
41 #else
42 #ifdef HAVE_IOCTL_H
43 #include <ioctl.h>
44 #endif
45 #endif
46 
51 static struct winsize mutt_get_winsize(void)
52 {
53  struct winsize w = { 0 };
54  int fd = open("/dev/tty", O_RDONLY);
55  if (fd != -1)
56  {
57  ioctl(fd, TIOCGWINSZ, &w);
58  close(fd);
59  }
60  return w;
61 }
62 
63 #ifdef USE_SLANG_CURSES
64 
67 void mutt_resize_screen(void)
68 {
69  struct winsize w = mutt_get_winsize();
70 
71  /* The following two variables are global to slang */
72  SLtt_Screen_Rows = w.ws_row;
73  SLtt_Screen_Cols = w.ws_col;
74 
75  if (SLtt_Screen_Rows <= 0)
76  {
77  const char *cp = mutt_str_getenv("LINES");
78  if (cp && (mutt_str_atoi(cp, &SLtt_Screen_Rows) < 0))
79  SLtt_Screen_Rows = 24;
80  }
81 
82  if (SLtt_Screen_Cols <= 0)
83  {
84  const char *cp = mutt_str_getenv("COLUMNS");
85  if (cp && (mutt_str_atoi(cp, &SLtt_Screen_Cols) < 0))
86  SLtt_Screen_Cols = 80;
87  }
88 
89  delwin(stdscr);
90  SLsmg_reset_smg();
91  SLsmg_init_smg();
92  stdscr = newwin(0, 0, 0, 0);
93  keypad(stdscr, true);
94  mutt_window_set_root(SLtt_Screen_Cols, SLtt_Screen_Rows);
95  window_notify_all(NULL);
96 }
97 #else
98 
102 {
103  struct winsize w = mutt_get_winsize();
104 
105  int screenrows = w.ws_row;
106  int screencols = w.ws_col;
107 
108  if (screenrows <= 0)
109  {
110  const char *cp = mutt_str_getenv("LINES");
111  if (cp && (mutt_str_atoi(cp, &screenrows) < 0))
112  screenrows = 24;
113  }
114 
115  if (screencols <= 0)
116  {
117  const char *cp = mutt_str_getenv("COLUMNS");
118  if (cp && (mutt_str_atoi(cp, &screencols) < 0))
119  screencols = 80;
120  }
121 
122  resizeterm(screenrows, screencols);
123  mutt_window_set_root(screencols, screenrows);
124  window_notify_all(NULL);
125 }
126 #endif
Convenience wrapper for the gui headers.
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:257
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:999
static struct winsize mutt_get_winsize(void)
Use an ioctl to get the window size.
Definition: resize.c:51
void mutt_window_set_root(int cols, int rows)
Set the dimensions of the Root Window.
Definition: mutt_window.c:597
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:89
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:101
Convenience wrapper for the library headers.