diff --git a/notificationd/notificationsmodel.cpp b/notificationd/notificationsmodel.cpp index 1a621e7..24a7a10 100644 --- a/notificationd/notificationsmodel.cpp +++ b/notificationd/notificationsmodel.cpp @@ -54,6 +54,8 @@ QVariant NotificationsModel::data(const QModelIndex &index, int role) const return notification.body; case NotificationsModel::IconNameRole: return notification.appIcon; + case NotificationsModel::HasDefaultActionRole: + return notification.actions.contains("default"); default: break; } @@ -111,6 +113,22 @@ void NotificationsModel::close(uint id) } } +void NotificationsModel::invokeDefaultAction(uint notificationId) +{ + const int row = rowOfNotification(notificationId); + + if (row == -1) { + return; + } + + const Notification ¬ification = m_notifications.at(row); + if (!notification.actions.contains("default")) { + return; + } + + NotificationServer::self()->InvokeAction(notificationId, "default"); +} + int NotificationsModel::rowOfNotification(uint id) const { auto it = std::find_if(m_notifications.constBegin(), m_notifications.constEnd(), [id](const Notification &item) { diff --git a/notificationd/notificationsmodel.h b/notificationd/notificationsmodel.h index 61ce050..58e2a25 100644 --- a/notificationd/notificationsmodel.h +++ b/notificationd/notificationsmodel.h @@ -27,6 +27,7 @@ public: UpdatedRole, BodyRole, IconNameRole, + HasDefaultActionRole }; Q_ENUM(Roles) @@ -38,6 +39,7 @@ public: QHash roleNames() const override; Q_INVOKABLE void close(uint id); + Q_INVOKABLE void invokeDefaultAction(uint id); int rowOfNotification(uint id) const; void removeRows(const QVector &rows); diff --git a/notificationd/qml/NotificationPopup.qml b/notificationd/qml/NotificationPopup.qml index 000fa3d..0ce132e 100644 --- a/notificationd/qml/NotificationPopup.qml +++ b/notificationd/qml/NotificationPopup.qml @@ -60,10 +60,17 @@ Window { id: _mouseArea z: 999 anchors.fill: parent - onClicked: notificationsModel.close(model.notificationId) hoverEnabled: true onEntered: timer.stop() onExited: timer.restart() + + onClicked: { + if (model.hasDefaultAction) { + notificationsModel.invokeDefaultAction(model.notificationId) + } + + notificationsModel.close(model.notificationId) + } } RowLayout { @@ -125,7 +132,29 @@ Window { height: 24 source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark" : "light") + "/close.svg" sourceSize: Qt.size(width, height) - visible: _mouseArea.containsMouse + visible: _mouseArea.containsMouse || _closeBtnArea.containsMouse + z: 9999 + + Rectangle { + property color hoveredColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 2) + : Qt.darker(FishUI.Theme.backgroundColor, 1.2) + property color pressedColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 1.5) + : Qt.darker(FishUI.Theme.backgroundColor, 1.3) + + z: -1 + anchors.fill: parent + color: _closeBtnArea.pressed ? pressedColor : _closeBtnArea.containsMouse ? hoveredColor : "transparent" + radius: height / 2 + } + + MouseArea { + id: _closeBtnArea + anchors.fill: parent + hoverEnabled: true + onClicked: { + notificationsModel.close(model.notificationId) + } + } } Timer {