Skip to content

Commit

Permalink
Set a default size on first launch
Browse files Browse the repository at this point in the history
When `~/.config/nvim-qt/window-geometry.conf` does not exist then
restoreGeometry() will initialize a window that is tiny and must be
resized in order to be usable in some environments.

Resize the window to half the screen when launched for the first time.
Do not restore window state when it is invalid or missing.
  • Loading branch information
davvid committed Mar 7, 2024
1 parent ef1bec6 commit f602849
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 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 Down Expand Up @@ -329,12 +331,32 @@ void MainWindow::restoreWindowGeometry()
qRegisterMetaTypeStreamOperators<QList<int>>("QList<int>");
#endif

QSettings settings("nvim-qt", "window-geometry");
const QSettings settings("nvim-qt", "window-geometry");
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 {
const QPoint local_position{ width() / 2, 0 };
const QPoint global_position = mapToGlobal(local_position);
const QScreen* screen{ qApp->screenAt(global_position) };
if (screen) {
const QRect geometry{ screen->availableGeometry() };
if (screen->orientation() == Qt::LandscapeOrientation) {
resize(geometry.width() / 2, geometry.height());
}
else {
resize(geometry.width(), geometry.height() / 2);
}
}
}
QVariant state{ settings.value("window_state") };
if (state.isValid()) {
restoreState(state.toByteArray());
}
}

void MainWindow::setGuiAdaptiveColorEnabled(bool isEnabled)
Expand Down

0 comments on commit f602849

Please sign in to comment.