Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a default size on first launch #1100

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "mainwindow.h"

#include <QApplication>
#include <QCloseEvent>
#include <QEventLoop>
#include <QLayout>
#include <QScreen>
#include <QSettings>
#include <QStyleFactory>
#include <QToolBar>
Expand All @@ -14,6 +16,23 @@ static QString DefaultWindowTitle() noexcept
return "Neovim";
}

static void SetDefaultWindowSize(QWidget& widget) noexcept
{
const QPoint local_position{ widget.width() / 2, 0 };
const QPoint global_position{ widget.mapToGlobal(local_position) };
const QScreen* screen{ qApp->screenAt(global_position) };
if (!screen) {
return;
}
const 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 }
Expand Down Expand Up @@ -333,8 +352,17 @@ void MainWindow::restoreWindowGeometry()
if (!settings.value("restore_window_geometry", true).toBool()) {
return;
}
restoreGeometry(settings.value("window_geometry").toByteArray());
restoreState(settings.value("window_state").toByteArray());
const QVariant geometry{ settings.value("window_geometry") };
if (geometry.isValid()) {
restoreGeometry(geometry.toByteArray());
}
else {
SetDefaultWindowSize(*this);
}
const QVariant state{ settings.value("window_state") };
if (state.isValid()) {
restoreState(state.toByteArray());
}
}

void MainWindow::setGuiAdaptiveColorEnabled(bool isEnabled)
Expand Down
Loading