aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Keshav Bhatt <keshavnrj@gmail.com>2022-06-16 18:15:59 +0530
committerLibravatar Keshav Bhatt <keshavnrj@gmail.com>2022-06-16 18:15:59 +0530
commitff99a5f79874622b3ca02f46903c7390dd948259 (patch)
tree5981ce63e61d49fbc56336c02fd08e0781b974da /src
parent3dae93a104b59d3721bd236e0e3b254e3ab0740c (diff)
downloadwhatsie-ff99a5f79874622b3ca02f46903c7390dd948259.tar.gz
whatsie-ff99a5f79874622b3ca02f46903c7390dd948259.zip
fix: show notifications on correct screen
- show notification on screen where the main instance is running - closes #41
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp11
-rw-r--r--src/notificationpopup.h34
2 files changed, 21 insertions, 24 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 8b00d80..13b01eb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -190,9 +190,7 @@ void MainWindow::updateWindowTheme() {
}
QList<QWidget *> widgets = this->findChildren<QWidget *>();
- foreach (QWidget *w, widgets) {
- w->setPalette(qApp->palette());
- }
+ foreach (QWidget *w, widgets) { w->setPalette(qApp->palette()); }
setNotificationPresenter(webEngine->page()->profile());
if (lockWidget != nullptr) {
@@ -505,7 +503,9 @@ void MainWindow::notify(QString title, QString message) {
popup->style()->polish(qApp);
popup->setMinimumWidth(300);
popup->adjustSize();
- popup->present(title, message, QPixmap(":/icons/app/icon-64.png"));
+ int screenNumber = qApp->desktop()->screenNumber(this);
+ popup->present(screenNumber < 0 ? 0 : screenNumber, title, message,
+ QPixmap(":/icons/app/icon-64.png"));
}
}
@@ -844,7 +844,8 @@ void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) {
} else {
popup->setMinimumWidth(300);
- popup->present(notification);
+ int screenNumber = qApp->desktop()->screenNumber(this);
+ popup->present(screenNumber, notification);
}
});
}
diff --git a/src/notificationpopup.h b/src/notificationpopup.h
index 07a63f1..81d4d7b 100644
--- a/src/notificationpopup.h
+++ b/src/notificationpopup.h
@@ -12,6 +12,7 @@
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QPushButton>
+#include <QScreen>
#include <QSettings>
#include <QSpacerItem>
#include <QTimer>
@@ -52,27 +53,25 @@ public:
adjustSize();
}
- void present(QString title, QString message, const QPixmap image) {
+ void present(int screenNumber, QString title, QString message,
+ const QPixmap image) {
m_title.setText("<b>" + title + "</b>");
m_message.setText(message);
m_icon.setPixmap(
image.scaledToHeight(m_icon.height(), Qt::SmoothTransformation));
- this->adjustSize();
- qApp->processEvents();
-
- int x = QApplication::desktop()->geometry().width() - (this->width() + 10);
- int y = 40;
-
- this->update();
QTimer::singleShot(settings.value("notificationTimeOut", 9000).toInt(),
this, [=]() { onClosed(); });
+ this->adjustSize();
+ QRect screenRect = QGuiApplication::screens().at(screenNumber)->geometry();
+ int x = (screenRect.x() + screenRect.width() - 30) - this->width();
+ int y = 40;
+
QPropertyAnimation *a = new QPropertyAnimation(this, "pos");
a->setDuration(200);
- a->setStartValue(
- QApplication::desktop()->mapToGlobal(QPoint(x + this->width(), y)));
+ a->setStartValue(QApplication::desktop()->mapToGlobal(QPoint(x - 20, y)));
a->setEndValue(QApplication::desktop()->mapToGlobal(QPoint(x, y)));
a->setEasingCurve(QEasingCurve::Linear);
a->start(QPropertyAnimation::DeleteWhenStopped);
@@ -80,7 +79,8 @@ public:
this->show();
}
- void present(std::unique_ptr<QWebEngineNotification> &newNotification) {
+ void present(int screenNumber,
+ std::unique_ptr<QWebEngineNotification> &newNotification) {
if (notification) {
notification->close();
notification.reset();
@@ -99,22 +99,18 @@ public:
&NotificationPopup::onClosed);
QTimer::singleShot(settings.value("notificationTimeOut", 9000).toInt(),
notification.get(), [&]() { onClosed(); });
-
this->adjustSize();
- qApp->processEvents();
-
- int x = QApplication::desktop()->geometry().width() - (this->width() + 10);
+ QRect screenRect = QGuiApplication::screens().at(screenNumber)->geometry();
+ int x = (screenRect.x() + screenRect.width() - 30) - this->width();
int y = 40;
- this->update();
-
QPropertyAnimation *a = new QPropertyAnimation(this, "pos");
a->setDuration(200);
- a->setStartValue(
- QApplication::desktop()->mapToGlobal(QPoint(x + this->width(), y)));
+ a->setStartValue(QApplication::desktop()->mapToGlobal(QPoint(x - 20, y)));
a->setEndValue(QApplication::desktop()->mapToGlobal(QPoint(x, y)));
a->setEasingCurve(QEasingCurve::Linear);
a->start(QPropertyAnimation::DeleteWhenStopped);
+
this->show();
}