changeset 19336:37159a873c96 gui-release

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 d6240c099a02
children c6615ca0a11d
files libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h libgui/src/main-window.cc libgui/src/main-window.h libinterp/corefcn/sysdep.cc liboctave/util/cmd-edit.cc
diffstat 6 files changed, 66 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp	Mon Nov 03 22:39:49 2014 -0800
+++ 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);
     }
 }
-
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h	Mon Nov 03 22:39:49 2014 -0800
+++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h	Thu Oct 09 19:20:56 2014 -0400
@@ -76,6 +76,7 @@
   void terminated (void);
   void titleChanged (const QString&);
   void set_global_shortcuts_signal (bool);
+  void set_screen_size_signal (int, int);
 
 protected:
   void viewPaintEvent (QConsoleView*, QPaintEvent*);
--- a/libgui/src/main-window.cc	Mon Nov 03 22:39:49 2014 -0800
+++ b/libgui/src/main-window.cc	Thu Oct 09 19:20:56 2014 -0400
@@ -2103,6 +2103,12 @@
 }
 
 void
+main_window::set_screen_size_callback (const int_pair& sz)
+{
+  command_editor::set_screen_size (sz.first, sz.second);
+}
+
+void
 main_window::clear_history_callback (void)
 {
   Fhistory (ovl ("-c"));
@@ -2389,6 +2395,13 @@
 }
 
 void
+main_window::set_screen_size (int ht, int wd)
+{
+  octave_link::post_event (this, &main_window::set_screen_size_callback,
+                           int_pair (ht, wd));
+}
+
+void
 main_window::handle_show_doc (const QString& file)
 {
   doc_browser_window->setVisible (true);
--- a/libgui/src/main-window.h	Mon Nov 03 22:39:49 2014 -0800
+++ b/libgui/src/main-window.h	Thu Oct 09 19:20:56 2014 -0400
@@ -69,6 +69,7 @@
 public:
 
   typedef std::pair <std::string, std::string> name_pair;
+  typedef std::pair <int, int> int_pair;
 
   main_window (QWidget *parent = 0);
 
@@ -196,6 +197,8 @@
   void set_global_shortcuts (bool enable);
   void set_global_edit_shortcuts (bool enable);
 
+  void set_screen_size (int ht, int wd);
+
   // handling the clipboard
   void clipboard_has_changed (QClipboard::Mode);
   void clear_clipboard ();
@@ -252,6 +255,8 @@
 
   void resize_command_window_callback (void);
 
+  void set_screen_size_callback (const int_pair&);
+
   void clear_workspace_callback (void);
 
   void clear_history_callback (void);
--- a/libinterp/corefcn/sysdep.cc	Mon Nov 03 22:39:49 2014 -0800
+++ b/libinterp/corefcn/sysdep.cc	Thu Oct 09 19:20:56 2014 -0400
@@ -169,13 +169,21 @@
 {
   w32_set_quiet_shutdown ();
 }
+
+static void
+w32_init (void)
+{
+  w32_set_octave_home ();
+
+  command_editor::prefer_env_winsize (true);
+}
 #endif
 
 #if defined (__MINGW32__)
 static void
 MINGW_init (void)
 {
-  w32_set_octave_home ();
+  w32_init ();
 }
 #endif
 
@@ -183,7 +191,7 @@
 static void
 MSVC_init (void)
 {
-  w32_set_octave_home ();
+  w32_init ();
 }
 #endif
 
--- a/liboctave/util/cmd-edit.cc	Mon Nov 03 22:39:49 2014 -0800
+++ b/liboctave/util/cmd-edit.cc	Thu Oct 09 19:20:56 2014 -0400
@@ -1447,6 +1447,13 @@
 }
 
 bool
+command_editor::prefer_env_winsize (bool arg)
+{
+  return (instance_ok ())
+         ? instance->do_prefer_env_winsize (arg) : false;
+}
+
+bool
 command_editor::interrupt (bool arg)
 {
   bool retval;