aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorLibravatar Keshav Bhatt <keshavnrj@gmail.com>2022-06-16 21:38:32 +0530
committerLibravatar Keshav Bhatt <keshavnrj@gmail.com>2022-06-16 21:38:32 +0530
commit3a08d5d5801c7e902620e45305da838904bda1ab (patch)
tree4b23b7e3087ecbc2fe0f34c542eaaa09164c4f2e /src/mainwindow.cpp
parent5c2764f71ba3ee51305ff6129bdea0650f10ba21 (diff)
downloadwhatsie-3a08d5d5801c7e902620e45305da838904bda1ab.tar.gz
whatsie-3a08d5d5801c7e902620e45305da838904bda1ab.zip
chore: improve window geo restore
- show window on screen where the cursor is located - default window size if saved geometry is not valid
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 13b01eb..7ab2216 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -23,7 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
setWindowIcon(QIcon(":/icons/app/icon-128.png"));
setMinimumWidth(525);
setMinimumHeight(448);
- restoreGeometry(settings.value("geometry").toByteArray());
+ restoreMainWindow();
initThemes();
createActions();
createTrayIcon();
@@ -35,6 +35,21 @@ MainWindow::MainWindow(QWidget *parent)
initAutoLock();
}
+void MainWindow::restoreMainWindow() {
+ if (settings.value("geometry").isValid()) {
+ restoreGeometry(settings.value("geometry").toByteArray());
+ QPoint pos = QCursor::pos();
+ for (QScreen *screen : QGuiApplication::screens()) {
+ QRect screenRect = screen->geometry();
+ if (screenRect.contains(pos)) {
+ this->move(screenRect.center() - this->rect().center());
+ }
+ }
+ }else{
+ this->resize(636, 760);
+ }
+}
+
void MainWindow::initAutoLock() {
autoLockEventFilter = new AutoLockEventFilter(
settings.value("autoLockDuration", defaultAppAutoLockDuration).toInt() *
@@ -252,9 +267,10 @@ void MainWindow::tryLogOut() {
}
void MainWindow::init_settingWidget() {
+ int screenNumber = qApp->desktop()->screenNumber(this);
if (settingsWidget == nullptr) {
settingsWidget = new SettingsWidget(
- this, webEngine->page()->profile()->cachePath(),
+ this, screenNumber, webEngine->page()->profile()->cachePath(),
webEngine->page()->profile()->persistentStoragePath());
settingsWidget->setWindowTitle(QApplication::applicationName() +
" | Settings");
@@ -414,12 +430,18 @@ void MainWindow::showSettings() {
if (webEngine == nullptr) {
QMessageBox::critical(
this, QApplication::applicationName() + "| Error",
- "Unable to initialize settings module.\nIs webengine initialized?");
+ "Unable to initialize settings module.\nWebengine is not initialized.");
return;
}
if (!settingsWidget->isVisible()) {
this->updateSettingsUserAgentWidget();
settingsWidget->refresh();
+ int screenNumber = qApp->desktop()->screenNumber(this);
+ QRect screenRect = QGuiApplication::screens().at(screenNumber)->geometry();
+ if (!screenRect.contains(settingsWidget->pos())) {
+ settingsWidget->move(screenRect.center() -
+ settingsWidget->rect().center());
+ }
settingsWidget->show();
}
}