From 949c216964b87c1ae265854ef1886b5b4990fd0d Mon Sep 17 00:00:00 2001 From: purian23 Date: Sat, 14 Feb 2026 19:59:38 -0500 Subject: [PATCH] Right-Click to set Rules on Notifications directly --- quickshell/Common/SettingsData.qml | 24 +++++++++++++++ .../Notifications/Center/NotificationCard.qml | 27 ++++++++++++++++- .../Notifications/Popup/NotificationPopup.qml | 30 ++++++++++++++++++- .../Modules/Settings/NotificationsTab.qml | 9 ++++++ 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/quickshell/Common/SettingsData.qml b/quickshell/Common/SettingsData.qml index f21244b7..d0969d6a 100644 --- a/quickshell/Common/SettingsData.qml +++ b/quickshell/Common/SettingsData.qml @@ -2140,6 +2140,9 @@ Singleton { saveSettings(); } + property bool _pendingExpandNotificationRules: false + property int _pendingNotificationRuleIndex: -1 + function addNotificationRule() { var rules = JSON.parse(JSON.stringify(notificationRules || [])); rules.push({ @@ -2154,6 +2157,27 @@ Singleton { saveSettings(); } + function addNotificationRuleForNotification(appName, desktopEntry) { + var rules = JSON.parse(JSON.stringify(notificationRules || [])); + var pattern = (desktopEntry && desktopEntry !== "") ? desktopEntry : (appName || ""); + var field = (desktopEntry && desktopEntry !== "") ? "desktopEntry" : "appName"; + var rule = { + enabled: true, + field: pattern ? field : "appName", + pattern: pattern || "", + matchType: pattern ? "exact" : "contains", + action: "default", + urgency: "default" + }; + rules.push(rule); + notificationRules = rules; + saveSettings(); + var index = rules.length - 1; + _pendingExpandNotificationRules = true; + _pendingNotificationRuleIndex = index; + return index; + } + function addMuteRuleForApp(appName, desktopEntry) { var rules = JSON.parse(JSON.stringify(notificationRules || [])); var pattern = (desktopEntry && desktopEntry !== "") ? desktopEntry : (appName || ""); diff --git a/quickshell/Modules/Notifications/Center/NotificationCard.qml b/quickshell/Modules/Notifications/Center/NotificationCard.qml index 7c4cab21..62b594c7 100644 --- a/quickshell/Modules/Notifications/Center/NotificationCard.qml +++ b/quickshell/Modules/Notifications/Center/NotificationCard.qml @@ -873,7 +873,7 @@ Rectangle { Menu { id: notificationCardContextMenu - width: 300 + width: 220 closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside background: Rectangle { @@ -883,6 +883,31 @@ Rectangle { border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12) } + MenuItem { + id: setNotificationRulesItem + text: I18n.tr("Set notification rules") + + contentItem: StyledText { + text: parent.text + font.pixelSize: Theme.fontSizeSmall + color: Theme.surfaceText + leftPadding: Theme.spacingS + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + color: parent.hovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : "transparent" + radius: Theme.cornerRadius / 2 + } + + onTriggered: { + const appName = notificationGroup?.appName || ""; + const desktopEntry = notificationGroup?.latestNotification?.desktopEntry || ""; + SettingsData.addNotificationRuleForNotification(appName, desktopEntry); + PopoutService.openSettingsWithTab("notifications"); + } + } + MenuItem { id: muteUnmuteItem readonly property bool isMuted: SettingsData.isAppMuted(notificationGroup?.appName || "", notificationGroup?.latestNotification?.desktopEntry || "") diff --git a/quickshell/Modules/Notifications/Popup/NotificationPopup.qml b/quickshell/Modules/Notifications/Popup/NotificationPopup.qml index c2ea2871..b76e05e2 100644 --- a/quickshell/Modules/Notifications/Popup/NotificationPopup.qml +++ b/quickshell/Modules/Notifications/Popup/NotificationPopup.qml @@ -835,7 +835,10 @@ PanelWindow { Menu { id: popupContextMenu - width: 300 + width: 220 + contentHeight: 130 + margins: -1 + popupType: Popup.Window closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside background: Rectangle { @@ -845,6 +848,31 @@ PanelWindow { border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12) } + MenuItem { + id: setNotificationRulesItem + text: I18n.tr("Set notification rules") + + contentItem: StyledText { + text: parent.text + font.pixelSize: Theme.fontSizeSmall + color: Theme.surfaceText + leftPadding: Theme.spacingS + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + color: parent.hovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : "transparent" + radius: Theme.cornerRadius / 2 + } + + onTriggered: { + const appName = notificationData?.appName || ""; + const desktopEntry = notificationData?.desktopEntry || ""; + SettingsData.addNotificationRuleForNotification(appName, desktopEntry); + PopoutService.openSettingsWithTab("notifications"); + } + } + MenuItem { id: muteUnmuteItem readonly property bool isMuted: SettingsData.isAppMuted(notificationData?.appName || "", notificationData?.desktopEntry || "") diff --git a/quickshell/Modules/Settings/NotificationsTab.qml b/quickshell/Modules/Settings/NotificationsTab.qml index c57a9f29..e38be3bc 100644 --- a/quickshell/Modules/Settings/NotificationsTab.qml +++ b/quickshell/Modules/Settings/NotificationsTab.qml @@ -6,6 +6,15 @@ import qs.Modules.Settings.Widgets Item { id: root + Component.onCompleted: { + if (SettingsData._pendingExpandNotificationRules) { + SettingsData._pendingExpandNotificationRules = false; + notificationRulesCard.userToggledCollapse = true; + notificationRulesCard.expanded = true; + SettingsData._pendingNotificationRuleIndex = -1; + } + } + readonly property var mutedRules: { var rules = SettingsData.notificationRules || []; var out = [];