changeset 25735:c7ea6c3cd8de

maint: Merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Thu, 02 Aug 2018 23:52:45 +0200
parents bf89eea6652e (current diff) c799c0dbe0b5 (diff)
children d3aa89a5b152
files libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp
diffstat 1 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp	Thu Aug 02 10:51:15 2018 -0700
+++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp	Thu Aug 02 23:52:45 2018 +0200
@@ -239,6 +239,7 @@
   QSize m_charSize;
   QSize m_bufferSize;
   QRect m_consoleRect;
+  bool m_auto_scroll;
   QPoint m_cursorPos;
   bool m_cursorBlinking;
   bool m_hasBlinkingCursor;
@@ -278,7 +279,7 @@
 //////////////////////////////////////////////////////////////////////////////
 
 QConsolePrivate::QConsolePrivate (QWinTerminalImpl* parent, const QString& cmd)
-  : q (parent), m_command (cmd), m_cursorBlinking (false),
+  : q (parent), m_command (cmd), m_auto_scroll (true), m_cursorBlinking (false),
     m_hasBlinkingCursor (true), m_cursorType (BlockCursor),
     m_beginSelection (0, 0), m_endSelection (0, 0), m_settingSelection (false),
     m_process (NULL), m_inWheelEvent (false)
@@ -1125,6 +1126,7 @@
   r.Right  = m_consoleRect.right ();
   r.Bottom = m_consoleRect.bottom ();
 
+  log ("ReadConsoleOutput (%d,%d) -> (%d,%d)\n", r.Left, r.Top, r.Right, r.Bottom);
   if (! ReadConsoleOutput (m_stdOut, (buf ? buf : m_buffer), bs, bc, &r))
     qCritical ("cannot read console output");
 }
@@ -1217,6 +1219,16 @@
   if (SetConsoleWindowInfo (hStdOut, TRUE, &r))
     {
       m_consoleRect.moveTop (value);
+
+      CONSOLE_SCREEN_BUFFER_INFO sbi;
+      if (GetConsoleScreenBufferInfo (hStdOut, &sbi))
+        {
+          if (sbi.dwCursorPosition.Y > m_consoleRect.bottom ())
+            m_auto_scroll = false;
+          else
+            m_auto_scroll = true;
+        }
+
       updateConsoleView ();
     }
 }
@@ -1279,10 +1291,12 @@
 
       if (m_consoleRect.left () != sbi.srWindow.Left
           || m_consoleRect.right () != sbi.srWindow.Right
-          || m_consoleRect.top () != sbi.srWindow.Top
-          || m_consoleRect.bottom () != sbi.srWindow.Bottom)
+          || (m_auto_scroll &&
+              (m_consoleRect.top () != sbi.srWindow.Top
+               || m_consoleRect.bottom () != sbi.srWindow.Bottom)))
         {
           // Console window changed
+          log ("--> Console window changed\n");
           m_consoleRect = QRect (sbi.srWindow.Left, sbi.srWindow.Top,
                                  sbi.srWindow.Right - sbi.srWindow.Left + 1,
                                  sbi.srWindow.Bottom - sbi.srWindow.Top + 1);
@@ -1357,6 +1371,8 @@
 
   // clear any selection on inserting text
   clearSelection();
+  // enable auto-scrolling
+  m_auto_scroll = true;
 
   int len = s.length ();
   INPUT_RECORD events[TEXT_CHUNK_SIZE];