diff libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp @ 19270:efccb2a65b9a

preserve text on Windows terminal resize (bug #41893; patch #8532) * QWinTerminalImpl.h, QWinTerminalImpl.cpp (QConsolePrivate::updateConsoleSize): Don't shrink the size of the console buffer. Store the terminal size in the environment. Force the command line editor (usually readline) to notice the change in screen size as soon as possible. (QWinTerminalImpl::QWinTerminalImpl): Connect set_screen_size_signal with parent set_screen_size slot. (QWinTerminalImpl::set_screen_size_signal): New signal. * main-window.h, main-window.cc (main_window::int_pair): New typedef. (main_window::set_screen_size_callback): New callback function. (main_window::set_screen_size): New slot. * sysdep.cc (w32_init): New function. Tell command_editor to prefer environment variables for window size. (MINGW_init, MSVC_init): Call w32_init. (QWinTerminalImpl::setSize): Emit set_screen_size_signal.
author John W. Eaton <jwe@octave.org>
date Thu, 09 Oct 2014 19:20:56 -0400
parents 8b9e99c061f9
children c6615ca0a11d
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp	Sun Oct 19 08:42:58 2014 -0400
+++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp	Thu Oct 09 19:20:56 2014 -0400
@@ -969,9 +969,30 @@
   m_consoleRect.setWidth (winSize.width () / fm.averageCharWidth ());
   m_consoleRect.setHeight (winSize.height () / fm.lineSpacing ());
 
-  m_bufferSize.rwidth () = m_consoleRect.width ();
-  m_bufferSize.rheight () = qMax (m_bufferSize.height (),
-                                  m_consoleRect.height ());
+  // Don't shrink the size of the buffer.  That way wide lines won't be
+  // truncated and will reappear if the window is enlarged again later.
+
+  if (m_consoleRect.width () > m_bufferSize.width ())
+    m_bufferSize.rwidth () = m_consoleRect.width ();
+
+  if (qMax (m_bufferSize.height (), m_consoleRect.height ())
+      > m_bufferSize.height ())
+    m_bufferSize.rheight () = qMax (m_bufferSize.height (),
+                                    m_consoleRect.height ());
+
+  // Store the terminal size in the environment.  When Octave is
+  // initialized, we ask the command editor (usually readline) to prefer
+  // using these values rather than querying the terminal so that the
+  // buffer size can be larger than the size of the window that the
+  // command editor will actually use.
+
+  qputenv ("LINES", QByteArray::number (m_consoleRect.height ()));
+  qputenv ("COLUMNS", QByteArray::number (m_consoleRect.width ())); 
+
+  // Force the command line editor (usually readline) to notice the
+  // change in screen size as soon as possible.
+
+  q->setSize (m_consoleRect.height (), m_consoleRect.width ());
 
   m_consoleRect.moveLeft (0);
   if (m_consoleRect.bottom () >= m_bufferSize.height ())
@@ -1333,6 +1354,9 @@
     connect (this, SIGNAL (set_global_shortcuts_signal (bool)),
            parent, SLOT (set_global_shortcuts (bool)));
 
+    connect (this, SIGNAL (set_screen_size_signal (int, int)),
+             parent, SLOT (set_screen_size (int, int)));
+
     setAcceptDrops (true);
 }
 
@@ -1644,8 +1668,9 @@
 
 void QWinTerminalImpl::setSize (int columns, int lines)
 {
-  Q_UNUSED (columns);
-  Q_UNUSED (lines);
+  d->log ("emit set_screen_size_signal (%d, %d)\n", columns, lines);
+
+  emit set_screen_size_signal (columns, lines);
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -1726,4 +1751,3 @@
       sendText (dropText);
     }
 }
-