diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 925feb336..c1880c0c7 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1,8 +1,10 @@ #include "mainwindow.h" +#include #include #include #include +#include #include #include #include @@ -14,6 +16,19 @@ static QString DefaultWindowTitle() noexcept return "Neovim"; } +static void SetDefaultWindowSize(QWidget *widget) +{ + QPoint widget_position = widget->mapToGlobal(QPoint{ widget->width() / 2, 0 }); + QScreen *screen = qApp->screenAt(widget_position); + QRect geometry{ screen->availableGeometry() }; + if (screen->orientation() == Qt::LandscapeOrientation) { + widget->resize(geometry.width() / 2, geometry.height()); + } + else { + widget->resize(geometry.width(), geometry.height() / 2); + } +} + MainWindow::MainWindow(NeovimConnector* c, QWidget* parent) noexcept : QMainWindow{ parent } , m_tabline{ *c, this } @@ -331,10 +346,20 @@ void MainWindow::restoreWindowGeometry() QSettings settings("nvim-qt", "window-geometry"); if (!settings.value("restore_window_geometry", true).toBool()) { + SetDefaultWindowSize(this); return; } - restoreGeometry(settings.value("window_geometry").toByteArray()); - restoreState(settings.value("window_state").toByteArray()); + QVariant geometry{ settings.value("window_geometry") }; + if (geometry.isValid()) { + restoreGeometry(geometry.toByteArray()); + } + else { + SetDefaultWindowSize(this); + } + QVariant state{ settings.value("window_state") }; + if (state.isValid()) { + restoreState(state.toByteArray()); + } } void MainWindow::setGuiAdaptiveColorEnabled(bool isEnabled)