changeset 29148:d9ac99164c18

maint: merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Sun, 06 Dec 2020 14:56:04 +0100
parents 3000414c60eb (current diff) 5d7a651bf0bb (diff)
children e3e887d5f631
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/settings-dialog.cc m4/acinclude.m4
diffstat 7 files changed, 205 insertions(+), 193 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/default-qt-settings.in	Fri Dec 04 15:47:48 2020 -0800
+++ b/libgui/default-qt-settings.in	Sun Dec 06 14:56:04 2020 +0100
@@ -15,32 +15,6 @@
 fontName=__default_font__
 cursorType=ibeam
 
-[DockWidgets]
-TerminalDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\x1j\0\0\0 \0\0\x4\x3\0\0\x2\x9e\0\0\x1j\0\0\0 \0\0\x4\x3\0\0\x2\x9e\0\0\0\0\0\0)
-TerminalDockWidgetFloating=false
-TerminalDockWidgetVisible=true
-WorkspaceView=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\0\0\0\x1+\0\0\x1\x63\0\0\x2\0\0\0\0\0\0\0\x1+\0\0\x1\x63\0\0\x2\0\0\0\0\0\0\0)
-WorkspaceViewFloating=false
-WorkspaceViewVisible=true
-HistoryDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\0\0\0\x2\a\0\0\x1\x63\0\0\x2\xba\0\0\0\0\0\0\x2\a\0\0\x1\x63\0\0\x2\xba\0\0\0\0\0\0)
-HistoryDockWidgetFloating=false
-HistoryDockWidgetVisible=true
-FilesDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\0\0\0\0 \0\0\x1\x63\0\0\x1$\0\0\0\0\0\0\0 \0\0\x1\x63\0\0\x1$\0\0\0\0\0\0)
-FilesDockWidgetFloating=false
-FilesDockWidgetVisible=true
-DocumentationDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\xff\xff\xfbr\xff\xff\xfb\x8d\xff\xff\xfe\v\xff\xff\xfe\v\xff\xff\xfbr\xff\xff\xfb\x8d\xff\xff\xfe\v\xff\xff\xfe\v\0\0\0\0\0\0)
-DocumentationDockWidgetFloating=false
-DocumentationDockWidgetVisible=true
-FileEditor=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\xff\xff\xfbr\xff\xff\xfb\x8d\xff\xff\xfe\v\xff\xff\xfe\v\xff\xff\xfbr\xff\xff\xfb\x8d\xff\xff\xfe\v\xff\xff\xfe\v\0\0\0\0\0\0)
-FileEditorFloating=false
-FileEditorVisible=true
-NewsDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\x2\"\0\0\0@\0\0\x4\xb3\0\0\x1\x1a\0\0\x2\"\0\0\0@\0\0\x4\xb3\0\0\x1\x1a\0\0\0\0\0\0)
-NewsDockWidgetFloating=false
-NewsDockWidgetVisible=true
-VariableEditor=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\0\xff\xff\xfb\x65\xff\xff\xfb\xac\xff\xff\xfe\v\xff\xff\xfe\v\xff\xff\xfb\x65\xff\xff\xfb\xac\xff\xff\xfe\v\xff\xff\xfe\v\xff\xff\xff\xff\0\0\0\0\x5\0)
-VariableEditorFloating=false
-VariableEditorVisible=true
-
 [workspaceview]
 local_collapsed=false
 global_collapsed=false
--- a/libgui/src/gui-preferences-mw.h	Fri Dec 04 15:47:48 2020 -0800
+++ b/libgui/src/gui-preferences-mw.h	Sun Dec 06 14:56:04 2020 +0100
@@ -30,65 +30,13 @@
 
 // Main window preferences
 
-const unsigned char ba_geometry_data[] =
-{
-  0x01,0xd9,0xd0,0xcb,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-  0x00,0x1b,0x00,0x00,0x03,0xaf,0x00,0x00,0x02,0xb8,0x00,0x00,0x00,0x00,
-  0x00,0x00,0x00,0x39,0x00,0x00,0x03,0xaf,0x00,0x00,0x02,0xb8,0x00,0x00,
-  0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00
-};
-
-// FIXME: use the following version when Qt4 support is dropped
-// QVariant (QByteArrayLiteral ("\x1\xd9\xd0\xcb\0\x2\0\0\0\0\0\0\0\0\0\x1b\0\0\x3\xaf\0\0\x2\xb8\0\0\0\0\0\0\0\x39\0\0\x3\xaf\0\0\x2\xb8\0\0\0\0\0\0\0\0\x5\0")));
+// Geometry wihtout default since default layout is built programmatically
 const gui_pref
-mw_geometry ("MainWindow/geometry",
-             QVariant (QByteArray (reinterpret_cast<const char*> (ba_geometry_data),
-                                   sizeof (ba_geometry_data))));
+mw_geometry ("MainWindow/geometry", QVariant (QByteArray ()));
 
-const unsigned char ba_state_data[] =
-{
-  '\0','\0','\0',0xff,'\0','\0','\0','\0',0xfd,'\0','\0','\0',0x2,'\0','\0',
-  '\0','\0','\0','\0',0x1,'&','\0','\0',0x2,'+',0xfc,0x2,'\0','\0','\0',0x3,
-  0xfb,'\0','\0','\0',0x1e,'\0','F','\0','i','\0','l','\0','e','\0','s','\0',
-  'D','\0','o','\0','c','\0','k','\0','W','\0','i','\0','d','\0','g','\0','e',
-  '\0','t',0x1,'\0','\0','\0','?','\0','\0','\0',0xac,'\0','\0','\0',0x88,
-  '\0',0xff,0xff,0xff,0xfb,'\0','\0','\0',0x1a,'\0','W','\0','o','\0','r',
-  '\0','k','\0','s','\0','p','\0','a','\0','c','\0','e','\0','V','\0','i',
-  '\0','e','\0','w',0x1,'\0','\0','\0',0xf1,'\0','\0','\0',0xca,'\0','\0',
-  '\0',0x82,'\0',0xff,0xff,0xff,0xfb,'\0','\0','\0','\"','\0','H','\0','i',
-  '\0','s','\0','t','\0','o','\0','r','\0','y','\0','D','\0','o','\0','c',
-  '\0','k','\0','W','\0','i','\0','d','\0','g','\0','e','\0','t',0x1,'\0',
-  '\0',0x1,0xc1,'\0','\0','\0',0xa9,'\0','\0','\0',0x82,'\0',0xff,0xff,0xff,
-  '\0','\0','\0',0x1,'\0','\0',0x2,0x84,'\0','\0',0x2,'+',0xfc,0x2,'\0','\0',
-  '\0',0x1,0xfc,'\0','\0','\0','?','\0','\0',0x2,'+','\0','\0','\0',0xeb,0x1,
-  '\0','\0',0x1b,0xfa,'\0','\0','\0','\0',0x2,'\0','\0','\0',0x4,0xfb,'\0',
-  '\0','\0','$','\0','T','\0','e','\0','r','\0','m','\0','i','\0','n','\0',
-  'a','\0','l','\0','D','\0','o','\0','c','\0','k','\0','W','\0','i','\0',
-  'd','\0','g','\0','e','\0','t',0x1,'\0','\0','\0','\0',0xff,0xff,0xff,0xff,
-  '\0','\0','\0',0x46,'\0',0xff,0xff,0xff,0xfb,'\0','\0','\0','.','\0','D','\0',
-  'o','\0','c','\0','u','\0','m','\0','e','\0','n','\0','t','\0','a','\0','t',
-  '\0','i','\0','o','\0','n','\0','D','\0','o','\0','c','\0','k','\0','W',
-  '\0','i','\0','d','\0','g','\0','e','\0','t',0x1,'\0','\0','\0','\0',0xff,
-  0xff,0xff,0xff,'\0','\0','\0',0xcf,'\0',0xff,0xff,0xff,0xfb,'\0','\0','\0',
-  0x14,'\0','F','\0','i','\0','l','\0','e','\0','E','\0','d','\0','i','\0',
-  't','\0','o','\0','r',0x1,'\0','\0','\0','\0',0xff,0xff,0xff,0xff,'\0',
-  '\0','\0',0x62,'\0',0xff,0xff,0xff,0xfb,'\0','\0','\0',0x1c,'\0','V','\0',
-  'a','\0','r','\0','i','\0','a','\0','b','\0','l','\0','e','\0','E','\0',
-  'D','\0','i','\0','t','\0','o','\0','r',0x1,'\0','\0','\0','\0',0xff,0xff,
-  0xff,0xff,'\0','\0','\0',';','\0',0xff,0xff,0xff,'\0','\0','\0','\0','\0',
-  '\0',0x2,'+','\0','\0','\0',0x4,'\0','\0','\0',0x4,'\0','\0','\0','\b',
-  '\0','\0','\0','\b',0xfc,'\0','\0','\0',0x1,'\0','\0','\0',0x2,'\0','\0',
-  '\0',0x1,'\0','\0','\0',0x16,'\0','M','\0','a','\0','i','\0','n','\0','T',
-  '\0','o','\0','o','\0','l','\0','b','\0','a','\0','r',0x1,'\0','\0','\0',
-  '\0',0xff,0xff,0xff,0xff,'\0','\0','\0','\0','\0','\0','\0','\0'
-};
-
-// FIXME: use the following version when Qt4 support is dropped
-// QVariant (QByteArrayLiteral ("\0\0\0\xff\0\0\0\0\xfd\0\0\0\x2\0\0\0\0\0\0\x1&\0\0\x2+\xfc\x2\0\0\0\x3\xfb\0\0\0\x1e\0\x46\0i\0l\0\x65\0s\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\0?\0\0\0\xac\0\0\0\x88\0\xff\xff\xff\xfb\0\0\0\x1a\0W\0o\0r\0k\0s\0p\0\x61\0\x63\0\x65\0V\0i\0\x65\0w\x1\0\0\0\xf1\0\0\0\xca\0\0\0\x82\0\xff\xff\xff\xfb\0\0\0\"\0H\0i\0s\0t\0o\0r\0y\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\x1\xc1\0\0\0\xa9\0\0\0\x82\0\xff\xff\xff\0\0\0\x1\0\0\x2\x84\0\0\x2+\xfc\x2\0\0\0\x1\xfc\0\0\0?\0\0\x2+\0\0\0\xeb\x1\0\0\x1b\xfa\0\0\0\0\x2\0\0\0\x4\xfb\0\0\0$\0T\0\x65\0r\0m\0i\0n\0\x61\0l\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\x46\0\xff\xff\xff\xfb\0\0\0.\0\x44\0o\0\x63\0u\0m\0\x65\0n\0t\0\x61\0t\0i\0o\0n\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\xcf\0\xff\xff\xff\xfb\0\0\0\x14\0\x46\0i\0l\0\x65\0\x45\0\x64\0i\0t\0o\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\x62\0\xff\xff\xff\xfb\0\0\0\x1c\0V\0\x61\0r\0i\0\x61\0\x62\0l\0\x65\0\x45\0\x64\0i\0t\0o\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0;\0\xff\xff\xff\0\0\0\0\0\0\x2+\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x1\0\0\0\x16\0M\0\x61\0i\0n\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0")));
+// State wihtout default since default layout is built programmatically
 const gui_pref
-mw_state ("MainWindow/windowState",
-          QVariant (QByteArray (reinterpret_cast<const char*> (ba_state_data),
-                                sizeof (ba_state_data))));
+mw_state ("MainWindow/windowState", QVariant (QByteArray ()));
 
 const gui_pref
 mw_dir_list ("MainWindow/current_directory_list", QVariant (QStringList ()));
--- a/libgui/src/main-window.cc	Fri Dec 04 15:47:48 2020 -0800
+++ b/libgui/src/main-window.cc	Sun Dec 06 14:56:04 2020 +0100
@@ -710,18 +710,11 @@
 
         browser->document ()->adjustSize ();
 
-        // center the window on the screen where octave is running
-        QDesktopWidget *m_desktop = QApplication::desktop ();
-        QRect screen_geo = m_desktop->availableGeometry (this);
-
-        int win_x = screen_geo.width ();        // width of the screen
-        int win_y = screen_geo.height ();       // height of the screen
-
-        int reln_x = win_x*2/5;  // desired width of release notes
-        int reln_y = win_y*2/3;  // desired height of release notes
-
-        m_release_notes_window->resize (reln_x, reln_y);  // set size
-        m_release_notes_window->move (20, 20);     // move to the top left corner
+        int win_x, win_y;
+        get_screen_geometry (&win_x, &win_y);
+
+        m_release_notes_window->resize (win_x*2/5, win_y*2/3);
+        m_release_notes_window->move (20, 20);  // move to the top left corner
       }
 
     if (! m_release_notes_window->isVisible ())
@@ -794,17 +787,10 @@
         m_community_news_window->setLayout (vlayout);
         m_community_news_window->setWindowTitle (tr ("Octave Community News"));
 
-        // center the window on the screen where octave is running
-        QDesktopWidget *m_desktop = QApplication::desktop ();
-        QRect screen_geo = m_desktop->availableGeometry (this);
-
-        int win_x = screen_geo.width ();        // width of the screen
-        int win_y = screen_geo.height ();       // height of the screen
-
-        int news_x = win_x/2;  // desired width of news window
-        int news_y = win_y/2;  // desired height of news window
-
-        m_community_news_window->resize (news_x, news_y);  // set size and center
+        int win_x, win_y;
+        get_screen_geometry (&win_x, &win_y);
+
+        m_community_news_window->resize (win_x/2, win_y/2);
         m_community_news_window->move ((win_x - m_community_news_window->width ())/2,
                                        (win_y - m_community_news_window->height ())/2);
       }
@@ -1027,14 +1013,6 @@
     m_previous_dock->activate ();
   }
 
-  void main_window::reset_windows (void)
-  {
-    hide ();
-    set_window_layout (nullptr);  // do not use the settings file
-    showNormal ();  // make sure main window is not minimized
-    focus_command_window ();
-  }
-
   void main_window::update_octave_directory (const QString& dir)
   {
     // Remove existing entry, if any, then add new directory at top and
@@ -1537,14 +1515,22 @@
   void main_window::set_window_layout (gui_settings *settings)
   {
     // Restore main window state and geometry from settings file or, in case
-    // of an error, from the default layout.
-    if (settings)
+    // of an error (no pref values yet), from the default layout.
+    if (! restoreGeometry (settings->value (mw_geometry).toByteArray ()))
       {
-        if (! restoreState (settings->value (mw_state).toByteArray ()))
-          restoreState (mw_state.def.toByteArray ());
-
-        if (! restoreGeometry (settings->value (mw_geometry).toByteArray ()))
-          restoreGeometry (mw_geometry.def.toByteArray ());
+        do_reset_windows (true);
+        return;
+      }
+
+    if (isMaximized())
+      {
+        setGeometry( QApplication::desktop ()->availableGeometry (this));
+      }
+
+    if (! restoreState (settings->value (mw_state).toByteArray ()))
+      {
+        do_reset_windows (true);
+        return;
       }
 
     // Restore the geometry of all dock-widgets
@@ -1556,13 +1542,11 @@
           {
             bool floating = false;
             bool visible = true;
-            if (settings)
-              {
-                floating = settings->value
-                  (dw_is_floating.key.arg (name), dw_is_floating.def).toBool ();
-                visible = settings->value
-                  (dw_is_visible.key.arg (name), dw_is_visible.def).toBool ();
-              }
+
+            floating = settings->value
+                (dw_is_floating.key.arg (name), dw_is_floating.def).toBool ();
+            visible = settings->value
+                (dw_is_visible.key.arg (name), dw_is_visible.def).toBool ();
 
             // If floating, make window from widget.
             if (floating)
@@ -1571,9 +1555,8 @@
 
                 if (visible)
                   {
-                    if (settings
-                        && settings->value (dw_is_minimized.key.arg (name),
-                                            dw_is_minimized.def).toBool ())
+                    if (settings->value (dw_is_minimized.key.arg (name),
+                                         dw_is_minimized.def).toBool ())
                       widget->showMinimized ();
                     else
                       widget->setVisible (true);
@@ -1590,20 +1573,6 @@
           }
       }
 
-    if (! settings)
-      {
-        restoreGeometry (mw_geometry.def.toByteArray ());
-        restoreState (mw_state.def.toByteArray ());
-
-        QDesktopWidget *m_desktop = QApplication::desktop ();
-        QRect screen_geo = m_desktop->availableGeometry (this);
-
-        int win_x = screen_geo.width ();        // width of the screen
-        int win_y = screen_geo.height ();       // height of the screen
-
-        resize (std::max (width (), 2*win_x/3), std::max (height (), 7*win_y/8));
-      }
-
     show ();
   }
 
@@ -2083,7 +2052,7 @@
     QWidget *dummyWidget = new QWidget ();
     dummyWidget->setObjectName ("CentralDummyWidget");
     dummyWidget->resize (10, 10);
-    dummyWidget->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum);
+    dummyWidget->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
     dummyWidget->hide ();
     setCentralWidget (dummyWidget);
   }
@@ -2189,46 +2158,8 @@
     connect (this, SIGNAL (warning_function_not_found_signal (const QString&)),
              this, SLOT (warning_function_not_found (const QString&)));
 
-    // Build the window with widgets
-
     setWindowTitle ("Octave");
 
-    // See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357
-#if (QT_VERSION < 0x050601) || (QT_VERSION >= 0x050701)
-    setDockOptions (QMainWindow::AnimatedDocks
-                    | QMainWindow::AllowNestedDocks
-                    | QMainWindow::AllowTabbedDocks);
-#else
-    setDockNestingEnabled (true);
-#endif
-
-    addDockWidget (Qt::RightDockWidgetArea, m_command_window);
-    addDockWidget (Qt::RightDockWidgetArea, m_doc_browser_window);
-    tabifyDockWidget (m_command_window, m_doc_browser_window);
-
-#if defined (HAVE_QSCINTILLA)
-    addDockWidget (Qt::RightDockWidgetArea, m_editor_window);
-    tabifyDockWidget (m_command_window, m_editor_window);
-#endif
-    addDockWidget (Qt::RightDockWidgetArea, m_variable_editor_window);
-    tabifyDockWidget (m_command_window, m_variable_editor_window);
-
-    addDockWidget (Qt::LeftDockWidgetArea, m_file_browser_window);
-    addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window);
-    addDockWidget (Qt::LeftDockWidgetArea, m_history_window);
-
-    int win_x = QApplication::desktop ()->width ();
-    int win_y = QApplication::desktop ()->height ();
-
-    if (win_x > 960)
-      win_x = 960;
-
-    if (win_y > 720)
-      win_y = 720;
-
-    setGeometry (0, 0, win_x, win_y);   // excluding frame geometry
-    move (0, 0);                        // including frame geometry
-
     setStatusBar (m_status_bar);
 
 #if defined (HAVE_QSCINTILLA)
@@ -3005,4 +2936,120 @@
          F__mfile_encoding__ (interp, ovl (mfile_encoding));
        });
   }
+
+  // Get size of screen where the main window is located
+  void main_window::get_screen_geometry (int *width, int *height)
+  {
+    QRect screen_geometry
+        = QApplication::desktop ()->availableGeometry (this);
+
+    *width = screen_geometry.width ();
+    *height = screen_geometry.height ();
+  }
+
+  void main_window::resize_dock (QDockWidget *dw, int width, int height)
+  {
+#if defined (HAVE_QMAINWINDOW_RESIZEDOCKS)
+    // resizeDockWidget was added to Qt in Qt 5.6
+    if (width >= 0)
+      resizeDocks ({dw},{width},Qt::Horizontal);
+    if (height >= 0)
+      resizeDocks ({dw},{height},Qt::Vertical);
+#else
+    // This replacement of resizeDockWidget is not very reliable.
+    // But even if Qt4 is not yet
+    QSize s = dw->widget ()->size ();
+    if (width >= 0)
+      s.setWidth (width);
+    if (height >= 0)
+      s.setHeight (height);
+    dw->widget ()->resize (s);
+    dw->adjustSize ();
+#endif
+  }
+
+  // The default main window size relative to the desktop size
+  void main_window::set_default_geometry ()
+  {
+    int win_x, win_y;
+    get_screen_geometry (&win_x, &win_y);
+
+    move (0, 0);
+    resize (2*win_x/3, 7*win_y/8);
+  }
+
+  void main_window::reset_windows (void)
+  {
+    // Slot for resetting the window layout to the default one
+    hide ();
+    showNormal ();              // Unmaximize
+    do_reset_windows (false);   // Add all widgets
+    // Re-add after giving time: This seems to be a reliable way to
+    // reset the main window's layout
+    QTimer::singleShot (250, this, SLOT (do_reset_windows (void)));
+  }
+
+  // Create the default layout of the main window. Do not use
+  // restoreState () and restoreGeometry () with default values since
+  // this might lead to problems when the Qt version changes
+  void main_window::do_reset_windows (bool show_it)
+  {
+    // Set main window default geometry and store its width for
+    // later resizing the command window
+    set_default_geometry ();
+    int win_x = geometry ().width ();
+
+    // Resize command window, the important one in the default layout
+    resize_dock (m_command_window, 7*win_x/8, -1);
+
+    // See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357
+#if (QT_VERSION < 0x050601) || (QT_VERSION >= 0x050701)
+    setDockOptions (QMainWindow::AnimatedDocks
+                    | QMainWindow::AllowNestedDocks
+                    | QMainWindow::AllowTabbedDocks);
+#else
+    setDockNestingEnabled (true);
+#endif
+
+    // Add the dock widgets and show them
+    addDockWidget (Qt::LeftDockWidgetArea, m_file_browser_window);
+    addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window);
+    addDockWidget (Qt::LeftDockWidgetArea, m_history_window);
+
+    addDockWidget (Qt::RightDockWidgetArea, m_command_window);
+
+    addDockWidget (Qt::RightDockWidgetArea, m_doc_browser_window);
+    tabifyDockWidget (m_command_window, m_doc_browser_window);
+
+    addDockWidget (Qt::RightDockWidgetArea, m_variable_editor_window);
+    tabifyDockWidget (m_command_window, m_variable_editor_window);
+
+#if defined (HAVE_QSCINTILLA)
+    addDockWidget (Qt::RightDockWidgetArea, m_editor_window);
+    tabifyDockWidget (m_command_window, m_editor_window);
+#endif
+
+    // Resize command window, the important one in the default layout
+    resize_dock (m_command_window, 2*win_x/3, -1);
+
+    // Show main wibdow, save state and geometry of main window and
+    // all dock widgets
+    if (show_it)
+      {
+        // Show all dock widgets
+        for (auto *widget : dock_widget_list ())
+          widget->show ();
+
+        // Show main window and store size and state
+        showNormal ();
+
+        resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
+        gui_settings *settings = rmgr.get_settings ();
+
+        settings->setValue (mw_geometry.key, saveGeometry ());
+        settings->setValue (mw_state.key, saveState ());
+
+        focus_command_window ();
+      }
+  }
 }
--- a/libgui/src/main-window.h	Fri Dec 04 15:47:48 2020 -0800
+++ b/libgui/src/main-window.h	Sun Dec 06 14:56:04 2020 +0100
@@ -164,6 +164,7 @@
     void prepare_to_exit (void);
     void go_to_previous_widget (void);
     void reset_windows (void);
+    void do_reset_windows (bool show_it = true);
 
     void update_octave_directory (const QString& dir);
     void browse_for_directory (void);
@@ -307,6 +308,10 @@
 
     void update_default_encoding (const QString& default_encoding);
 
+    void get_screen_geometry (int *width, int *height);
+    void set_default_geometry (void);
+    void resize_dock (QDockWidget *dw, int width, int height);
+
     base_qobject& m_octave_qobj;
 
     workspace_model *m_workspace_model;
--- a/libgui/src/octave-dock-widget.cc	Fri Dec 04 15:47:48 2020 -0800
+++ b/libgui/src/octave-dock-widget.cc	Sun Dec 06 14:56:04 2020 +0100
@@ -109,6 +109,7 @@
              this, SLOT (pasteClipboard ()));
     connect (p, SIGNAL (selectAll_signal ()),
              this, SLOT (selectAll ()));
+
     // undo handling
     connect (p, SIGNAL (undo_signal ()), this, SLOT (do_undo ()));
   }
@@ -355,9 +356,9 @@
     // recover old window states, hide and re-show new added widget
     m_parent->restoreState (settings->value (mw_state.key).toByteArray ());
     setFloating (false);
-     // restore size using setGeometry instead of restoreGeometry following
-     // this post:
-     // https://forum.qt.io/topic/79326/qdockwidget-restoregeometry-not-working-correctly-when-qmainwindow-is-maximized/5
+    // restore size using setGeometry instead of restoreGeometry following
+    // this post:
+    // https://forum.qt.io/topic/79326/qdockwidget-restoregeometry-not-working-correctly-when-qmainwindow-is-maximized/5
     setGeometry (m_recent_dock_geom);
 
     // adjust the (un)dock icon
@@ -484,26 +485,28 @@
       m_icon_color_active = "";
 
     QRect available_size = QApplication::desktop ()->availableGeometry (m_parent);
-    int x1, y1, x2, y2;
-    available_size.getCoords (&x1, &y1, &x2, &y2);
-    QRect default_size = QRect (x1+16, y1+32, x2/3, 2*y2/3);
+    int x, y, w, h;
+    available_size.getRect (&x, &y, &w, &h);
+    QRect default_floating_size = QRect (x+16, y+32, w/3, h/2);
+    m_parent->geometry ().getRect (&x, &y, &w, &h);
+    QRect default_dock_size = QRect (x+16, y+32, w/3, h/3);
 
     m_recent_float_geom
       = settings->value (dw_float_geometry.key.arg (objectName ()),
-                         default_size).toRect ();
+                         default_floating_size).toRect ();
 
     QWidget dummy;
     dummy.setGeometry (m_recent_float_geom);
 
     if (QApplication::desktop ()->screenNumber (&dummy) == -1)
-      m_recent_float_geom = default_size;
+      m_recent_float_geom = default_floating_size;
 
     // The following is required for ensure smooth transition from old
     // saveGeomety to new QRect setting (see comment for restoring size
     // of docked widgets)
     QVariant dock_geom
       = settings->value (dw_dock_geometry.key.arg (objectName ()),
-                         dw_dock_geometry.def);
+                         default_dock_size);
     if (dock_geom.canConvert (QMetaType::QRect))
       m_recent_dock_geom = dock_geom.toRect ();
     else
--- a/libgui/src/settings-dialog.cc	Fri Dec 04 15:47:48 2020 -0800
+++ b/libgui/src/settings-dialog.cc	Sun Dec 06 14:56:04 2020 +0100
@@ -999,7 +999,7 @@
     settings->setValue (global_proxy_user.key, proxy_username->text ());
     settings->setValue (global_proxy_pass.key, proxy_password->text ());
     settings->setValue (cs_cursor_use_fgcol.key, terminal_cursorUseForegroundColor->isChecked ());
-    settings->setValue (mw_dir_list.key, terminal_focus_command->isChecked ());
+    settings->setValue (cs_focus_cmd.key, terminal_focus_command->isChecked ());
     settings->setValue (cs_dbg_location.key, terminal_print_dbg_location->isChecked ());
     settings->setValue (cs_hist_buffer.key, terminal_history_buffer->value ());
 
--- a/m4/acinclude.m4	Fri Dec 04 15:47:48 2020 -0800
+++ b/m4/acinclude.m4	Sun Dec 06 14:56:04 2020 +0100
@@ -463,6 +463,40 @@
   fi
 ])
 dnl
+dnl Check whether the Qt class QMainWindow has the resizeDocks member function.
+dnl This member function was introduced in Qt 5.6.
+dnl
+dnl FIXME: remove this test when we drop support for Qt older than 5.6
+dnl
+AC_DEFUN([OCTAVE_CHECK_FUNC_QMAINWINDOW_RESIZEDOCKS], [
+  AC_CACHE_CHECK([for QMainWindow::resizeDocks in <QMainWindow>],
+    [octave_cv_func_mainwindow_resizedocks],
+    [AC_LANG_PUSH(C++)
+    ac_octave_save_CPPFLAGS="$CPPFLAGS"
+    ac_octave_save_CXXFLAGS="$CXXFLAGS"
+    CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS"
+    CXXFLAGS="$CXXPICFLAG $CXXFLAGS"
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #include <QMainWindow>
+        #include <QDockWidget>
+        ]], [[
+        QMainWindow *mw = new QMainWindow ();
+        QDockWidget *dw = new QDockWidget (mw);
+        mw->addDockWidget (Qt::LeftDockWidgetArea, dw);
+        mw->resizeDocks ({dw},{20},Qt::Horizontal);
+        ]])],
+      octave_cv_func_mainwindow_resizedocks=yes,
+      octave_cv_func_mainwindow_resizedocks=no)
+    CPPFLAGS="$ac_octave_save_CPPFLAGS"
+    CXXFLAGS="$ac_octave_save_CXXFLAGS"
+    AC_LANG_POP(C++)
+  ])
+  if test $octave_cv_func_mainwindow_resizedocks = yes; then
+    AC_DEFINE(HAVE_QMAINWINDOW_RESIZEDOCKS, 1,
+      [Define to 1 if you have the 'QMainWindow::resizeDocks' member function.])
+  fi
+])
+dnl
 dnl Check whether the Qt class QScreen has the devicePixelRatio member function.
 dnl This member function was introduced in Qt 5.5.
 dnl
@@ -2024,6 +2058,7 @@
     OCTAVE_CHECK_FUNC_QHELPSEARCHQUERYWIDGET_SEARCHINPUT
     OCTAVE_CHECK_NEW_QHELPINDEXWIDGET_API
     OCTAVE_CHECK_FUNC_QLIST_ITERATOR_CONSTRUCTOR
+    OCTAVE_CHECK_FUNC_QMAINWINDOW_RESIZEDOCKS
     OCTAVE_CHECK_FUNC_QSCREEN_DEVICEPIXELRATIO
     OCTAVE_CHECK_FUNC_QHELPENGINE_DOCUMENTSFORIDENTIFIER
     OCTAVE_CHECK_FUNC_QWHEELEVENT_ANGLEDELTA