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.
This commit is contained in:
Jean-Marc Lasgouttes 2020-11-12 12:09:36 +01:00
parent 21ca33745e
commit 222a317dd2
3 changed files with 47 additions and 19 deletions

View File

@ -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

View File

@ -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;

View File

@ -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());