diff libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp @ 25731:c799c0dbe0b5 stable

Fix scrolling command window in Windows 10 (bug #52496). * QWinTerminalImpl.cpp: Disable auto-scroll when manually scrolling up.
author Markus Mützel <markus.muetzel@gmx.de>
date Thu, 02 Aug 2018 23:46:48 +0200
parents 6652d3823428
children c7ea6c3cd8de
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp	Sun Jul 22 15:37:57 2018 -0700
+++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp	Thu Aug 02 23:46:48 2018 +0200
@@ -240,6 +240,7 @@
   QSize m_charSize;
   QSize m_bufferSize;
   QRect m_consoleRect;
+  bool m_auto_scroll;
   QPoint m_cursorPos;
   bool m_cursorBlinking;
   bool m_hasBlinkingCursor;
@@ -279,7 +280,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)
@@ -1126,6 +1127,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");
 }
@@ -1218,6 +1220,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 ();
     }
 }
@@ -1280,10 +1292,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);
@@ -1358,6 +1372,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];