[LyX/master] Store correctly the window position with Wayland

Jean-Marc Lasgouttes lasgouttes at lyx.org
Sat Nov 14 16:27:54 UTC 2020


commit 222a317dd243fb18f01bfa6e994902fee06ae3db
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Thu Nov 12 12:09:36 2020 +0100

    Store correctly the window position with Wayland
    
    To do this, hard-coded test for xcb had to be replaced with a call to
    platformName(). Since this method does not exist in Qt4, we emulate
    it.
    
    Note that Qt5 uses xcb bindings for X11 system, while Qt4 relies on
    older X11 bindings. We return platorm == "qt4x11" in this case.
    
    Fixes bug #11746.
---
 src/frontends/qt/GuiApplication.cpp |   23 +++++++++++++++++++++
 src/frontends/qt/GuiApplication.h   |    5 ++++
 src/frontends/qt/GuiView.cpp        |   38 +++++++++++++++++-----------------
 3 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 3c007be..9fa8d94 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -1089,6 +1089,29 @@ GuiApplication * theGuiApp()
 }
 
 
+#if QT_VERSION < 0x050000
+// Emulate platformName() for Qt4
+
+// FIXME: when ditching this method, remove all tests
+//     platformName() == "qt4x11"
+// in the code
+QString GuiApplication::platformName() const
+{
+# if defined(Q_WS_X11)
+	// Note that this one does not really exist
+	return "qt4x11";
+# elif defined(Q_OS_MAC)
+	return "cocoa";
+# elif defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
+	return "windows";
+# else
+	LYXERR0("Unknown platform!");
+	return "unknown";
+# endif
+}
+#endif
+
+
 double GuiApplication::pixelRatio() const
 {
 #if QT_VERSION >= 0x050000
diff --git a/src/frontends/qt/GuiApplication.h b/src/frontends/qt/GuiApplication.h
index 0959762..2235fbc 100644
--- a/src/frontends/qt/GuiApplication.h
+++ b/src/frontends/qt/GuiApplication.h
@@ -160,6 +160,11 @@ public:
 	///
 	GuiView & view(int id) const;
 
+#if (QT_VERSION < 0x050000)
+	/// Emulate platformName() for Qt4
+	QString platformName() const;
+#endif
+
 	/// Current ratio between physical pixels and device-independent pixels
 	double pixelRatio() const;
 
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index 907f151..0b3999d 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -816,12 +816,11 @@ void GuiView::saveLayout() const
 	settings.setValue("devel_mode", devel_mode_);
 	settings.beginGroup("views");
 	settings.beginGroup(QString::number(id_));
-#if defined(Q_WS_X11) || defined(QPA_XCB)
-	settings.setValue("pos", pos());
-	settings.setValue("size", size());
-#else
-	settings.setValue("geometry", saveGeometry());
-#endif
+	if (guiApp->platformName() == "qt4x11" || guiApp->platformName() == "xcb") {
+		settings.setValue("pos", pos());
+		settings.setValue("size", size());
+	} else
+		settings.setValue("geometry", saveGeometry());
 	settings.setValue("layout", saveState(0));
 	settings.setValue("icon_size", toqstr(d.iconSize(iconSize())));
 }
@@ -861,19 +860,20 @@ bool GuiView::restoreLayout()
 	//code below is skipped when when ~/.config/LyX is (re)created
 	setIconSize(d.iconSize(settings.value(icon_key).toString()));
 
-#if defined(Q_WS_X11) || defined(QPA_XCB)
-	QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
-	QSize size = settings.value("size", QSize(690, 510)).toSize();
-	resize(size);
-	move(pos);
-#else
-	// Work-around for bug #6034: the window ends up in an undetermined
-	// state when trying to restore a maximized window when it is
-	// already maximized.
-	if (!(windowState() & Qt::WindowMaximized))
-		if (!restoreGeometry(settings.value("geometry").toByteArray()))
-			setGeometry(50, 50, 690, 510);
-#endif
+	if (guiApp->platformName() == "qt4x11" || guiApp->platformName() == "xcb") {
+		QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
+		QSize size = settings.value("size", QSize(690, 510)).toSize();
+		resize(size);
+		move(pos);
+	} else {
+		// Work-around for bug #6034: the window ends up in an undetermined
+		// state when trying to restore a maximized window when it is
+		// already maximized.
+		if (!(windowState() & Qt::WindowMaximized))
+			if (!restoreGeometry(settings.value("geometry").toByteArray()))
+				setGeometry(50, 50, 690, 510);
+	}
+
 	// Make sure layout is correctly oriented.
 	setLayoutDirection(qApp->layoutDirection());
 


More information about the lyx-cvs mailing list