changeset 30639:6ad5bb8f6a6d stable

fix masimized start on systems with two monitors (bug #61172) * main-window.cc: include QWindow and QScreen; (set_window_layout): in maximized mode, only set geometry on systems with one monitor and if total and available geometry differ, otherwise reduce the geometry by a few pixels
author Torsten Lilge <ttl-octave@mailbox.org>
date Fri, 14 Jan 2022 07:09:34 +0100
parents 3c4e851e0220
children d162766886ce
files libgui/src/main-window.cc
diffstat 1 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Thu Jan 13 07:28:18 2022 -0800
+++ b/libgui/src/main-window.cc	Fri Jan 14 07:09:34 2022 +0100
@@ -44,6 +44,7 @@
 #include <QMenu>
 #include <QMenuBar>
 #include <QMessageBox>
+#include <QScreen>
 #include <QStyle>
 #include <QStyleFactory>
 #include <QTextBrowser>
@@ -51,6 +52,7 @@
 #include <QThread>
 #include <QTimer>
 #include <QToolBar>
+#include <QWindow>
 
 // QTerminal includes
 #include "QTerminal.h"
@@ -1543,7 +1545,29 @@
 
     if (isMaximized())
       {
-        setGeometry( QApplication::desktop ()->availableGeometry (this));
+        // If the window state is restored to maximized layout, the
+        // horizontal layout is not preserved. This cann be avoided by
+        // setting the geometry to the max. available geometry. However, on
+        // X11, the available geometry (excluding task bar etc.) is equal to
+        // the total geometry leading to a full screen mode without window
+        // decorations. This in turn can be avoided by reducing the max.
+        // size by a few pixels.
+
+        QScreen *s = windowHandle ()->screen ();  // Get current screen
+        QRect av_geom = s->availableGeometry ();  // Get available and total
+        QRect geom = s->geometry ();              // screen geometry
+
+        QList<QScreen *> screen_list = QGuiApplication::screens ();
+        if ((screen_list.length () > 1) && (av_geom == geom))
+          {
+            // If we have more than one monitor and available and total
+            // geometry are the same, reduce this too large geometry
+            QRect new_geom (av_geom.x () + 1, av_geom.y () + 1,
+                            av_geom.width ()-2, av_geom.height ()-2);
+            setGeometry (new_geom);
+          }
+        else
+          setGeometry (av_geom);  // Set (correct) available geometry
       }
 
     if (! restoreState (settings->value (mw_state).toByteArray ()))