]> granicus.if.org Git - neomutt/commitdiff
window: prepare for reflow
authorRichard Russon <rich@flatcap.org>
Fri, 26 Jul 2019 14:33:25 +0000 (15:33 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 27 Oct 2019 03:29:27 +0000 (03:29 +0000)
mutt_window.c
pager.c

index 091be624f4d054bb24547f536c1e9e4d042c6995..914751a134244034c5a745d10940edef9925c0bd 100644 (file)
@@ -35,6 +35,7 @@
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "options.h"
+#include "pager.h"
 
 struct MuttWindow *RootWindow = NULL; ///< Parent of all Windows
 
@@ -326,6 +327,90 @@ void mutt_window_copy_size(const struct MuttWindow *win_src, struct MuttWindow *
   win_dst->col_offset = win_src->col_offset;
 }
 
+/**
+ * mutt_window_reflow_prep - Prepare the Windows for reflowing
+ *
+ * This bit of business logic is temporary.
+ * Eventually, it will be split into the handlers for various Windows.
+ *
+ * The Window layout is affected by whether the Pager is visible and these
+ * config variables:
+ * - C_Help
+ * - C_PagerIndexLines
+ * - C_SidebarOnRight
+ * - C_SidebarVisible
+ * - C_SidebarWidth
+ * - C_StatusOnTop
+ */
+void mutt_window_reflow_prep(void)
+{
+  MuttHelpWindow->visible = C_Help;
+  MuttSidebarWindow->visible = C_SidebarVisible;
+  MuttSidebarWindow->cols = C_SidebarWidth;
+
+  struct MuttWindow *parent = MuttSidebarWindow->parent;
+  struct MuttWindow *first = TAILQ_FIRST(&parent->children);
+
+  if ((C_SidebarOnRight && (first == MuttSidebarWindow)) ||
+      (!C_SidebarOnRight && (first != MuttSidebarWindow)))
+  {
+    // Swap the Sidebar and the Container of the Index/Pager
+    TAILQ_REMOVE(&parent->children, first, entries);
+    TAILQ_INSERT_TAIL(&parent->children, first, entries);
+  }
+
+  parent = MuttHelpWindow->parent;
+  first = TAILQ_FIRST(&parent->children);
+
+  if ((C_StatusOnTop && (first == MuttHelpWindow)) ||
+      (!C_StatusOnTop && (first != MuttHelpWindow)))
+  {
+    // Swap the HelpLine and the Container of the Sidebar/Index/Pager
+    TAILQ_REMOVE(&parent->children, first, entries);
+    TAILQ_INSERT_TAIL(&parent->children, first, entries);
+  }
+
+  parent = MuttIndexWindow->parent;
+  first = TAILQ_FIRST(&parent->children);
+
+  if ((C_StatusOnTop && (first == MuttIndexWindow)) ||
+      (!C_StatusOnTop && (first != MuttIndexWindow)))
+  {
+    // Swap the Index and the Status Windows
+    TAILQ_REMOVE(&parent->children, first, entries);
+    TAILQ_INSERT_TAIL(&parent->children, first, entries);
+  }
+
+  parent = MuttPagerWindow->parent;
+  first = TAILQ_FIRST(&parent->children);
+
+  if ((C_StatusOnTop && (first == MuttPagerWindow)) ||
+      (!C_StatusOnTop && (first != MuttPagerWindow)))
+  {
+    // Swap the Pager and Pager Bar Windows
+    TAILQ_REMOVE(&parent->children, first, entries);
+    TAILQ_INSERT_TAIL(&parent->children, first, entries);
+  }
+
+  parent = MuttPagerWindow->parent;
+  if (parent->visible)
+  {
+    MuttIndexWindow->rows = C_PagerIndexLines;
+    MuttIndexWindow->size = MUTT_WIN_SIZE_FIXED;
+    parent = MuttIndexWindow->parent;
+    parent->size = MUTT_WIN_SIZE_MINIMISE;
+    parent->visible = (C_PagerIndexLines != 0);
+  }
+  else
+  {
+    MuttIndexWindow->rows = MUTT_WIN_SIZE_UNLIMITED;
+    MuttIndexWindow->size = MUTT_WIN_SIZE_MAXIMISE;
+    parent = MuttIndexWindow->parent;
+    parent->size = MUTT_WIN_SIZE_MAXIMISE;
+    parent->visible = true;
+  }
+}
+
 /**
  * mutt_window_reflow - Resize the Windows to fit the screen
  */
@@ -335,6 +420,7 @@ void mutt_window_reflow(void)
     return;
 
   mutt_debug(LL_DEBUG2, "entering\n");
+  mutt_window_reflow_prep();
 
   MuttStatusWindow->rows = 1;
   MuttStatusWindow->cols = COLS;
diff --git a/pager.c b/pager.c
index f9a43d67f8442e45de53928bf8b9f7263f0b372a..d8b49ef350cab1e7dc8e8814454ef7ff0571d062 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2283,6 +2283,9 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
   }
   unlink(fname);
 
+  MuttPagerWindow->parent->visible = true;
+  mutt_window_reflow();
+
   /* Initialize variables */
 
   if (Context && IsEmail(extra) && !extra->email->read)
@@ -3586,5 +3589,8 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
 
   mutt_buffer_dealloc(&helpstr);
 
+  MuttPagerWindow->parent->visible = false;
+  mutt_window_reflow();
+
   return (rc != -1) ? rc : 0;
 }