#include "systemtray.h"
SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
- : AbstractNotificationBackend(parent)
+ : AbstractNotificationBackend(parent),
+ _blockActivation(false)
{
NotificationSettings notificationSettings;
_showBubble = notificationSettings.value("Systray/ShowBubble", true).toBool();
connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked()), SLOT(notificationActivated()));
connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
SLOT(notificationActivated(SystemTray::ActivationReason)));
+
+ QApplication::instance()->installEventFilter(this);
}
void SystrayNotificationBackend::notify(const Notification ¬ification) {
}
void SystrayNotificationBackend::notificationActivated() {
- if(QtUi::mainWindow()->systemTray()->isAlerted()) {
- QtUi::mainWindow()->systemTray()->setInhibitActivation();
- uint id = _notifications.count()? _notifications.last().notificationId : 0;
- emit activated(id);
+ if(!_blockActivation) {
+ if(QtUi::mainWindow()->systemTray()->isAlerted()) {
+ _blockActivation = true; // prevent double activation because both tray icon and bubble might send a signal
+ uint id = _notifications.count()? _notifications.last().notificationId : 0;
+ emit activated(id);
+ } else
+ GraphicalUi::toggleMainWidget();
}
}
}
}
+// moving the mouse or releasing the button means that we're not dealing with a double activation
+bool SystrayNotificationBackend::eventFilter(QObject *obj, QEvent *event) {
+ if(event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonRelease) {
+ _blockActivation = false;
+ }
+ return AbstractNotificationBackend::eventFilter(obj, event);
+}
+
void SystrayNotificationBackend::showBubbleChanged(const QVariant &v) {
_showBubble = v.toBool();
}