*
* @authors
* Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 2018 Ivan J. <parazyd@dyne.org>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
#endif
#endif
-/**
- * mutt_resize_screen - Called after receiving SIGWINCH
- */
-void mutt_resize_screen(void)
+struct winsize mutt_get_winsize(void)
{
- const char *cp = NULL;
- int fd;
- struct winsize w;
-#if !defined(USE_SLANG_CURSES)
- int SLtt_Screen_Rows, SLtt_Screen_Cols;
-#endif
-
- SLtt_Screen_Rows = -1;
- SLtt_Screen_Cols = -1;
- fd = open("/dev/tty", O_RDONLY);
+ struct winsize w = { 0 };
+ int fd = open("/dev/tty", O_RDONLY);
if (fd != -1)
{
- if (ioctl(fd, TIOCGWINSZ, &w) != -1)
- {
- SLtt_Screen_Rows = w.ws_row;
- SLtt_Screen_Cols = w.ws_col;
- }
+ ioctl(fd, TIOCGWINSZ, &w);
close(fd);
}
+ return w;
+}
+
+#ifdef USE_SLANG_CURSES
+void mutt_resize_screen(void)
+{
+ struct winsize w = mutt_get_winsize();
+
+ /* The following two variables are global to slang */
+ SLtt_Screen_Rows = w.ws_row;
+ SLtt_Screen_Cols = w.ws_col;
+
if (SLtt_Screen_Rows <= 0)
{
- cp = mutt_str_getenv("LINES");
+ const char *cp = mutt_str_getenv("LINES");
if (cp && (mutt_str_atoi(cp, &SLtt_Screen_Rows) < 0))
SLtt_Screen_Rows = 24;
}
+
if (SLtt_Screen_Cols <= 0)
{
- cp = mutt_str_getenv("COLUMNS");
+ const char *cp = mutt_str_getenv("COLUMNS");
if (cp && (mutt_str_atoi(cp, &SLtt_Screen_Cols) < 0))
SLtt_Screen_Cols = 80;
}
-#ifdef USE_SLANG_CURSES
+
delwin(stdscr);
SLsmg_reset_smg();
SLsmg_init_smg();
stdscr = newwin(0, 0, 0, 0);
keypad(stdscr, true);
+ mutt_window_reflow();
+}
#else
- resizeterm(SLtt_Screen_Rows, SLtt_Screen_Cols);
-#endif
+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(cp, &screenrows) < 0))
+ screenrows = 24;
+ }
+
+ if (screencols <= 0)
+ {
+ const char *cp = mutt_str_getenv("LINES");
+ if (cp && (mutt_str_atoi(cp, &screencols) < 0))
+ screencols = 80;
+ }
+
+ resizeterm(screenrows, screencols);
mutt_window_reflow();
}
+#endif