diff --git a/quickshell/Common/SettingsData.qml b/quickshell/Common/SettingsData.qml index 7d93adf0f..8babd82d9 100644 --- a/quickshell/Common/SettingsData.qml +++ b/quickshell/Common/SettingsData.qml @@ -4027,14 +4027,28 @@ Singleton { return true; } + // Header actions keep one single-purpose rule each and never edit a rule built in the editor. + function isOwnAppRule(rule, action, bypassDnd) { + const matchType = (rule.matchType || "contains").toString().toLowerCase(); + const senderless = matchType === "regex" && rule.pattern === "^$" && (!rule.field || rule.field === "appName"); + if (!senderless && (matchType !== "exact" || !rule.pattern) || (rule.conditions || []).length > 0) + return false; + if (rule.field && rule.field !== "appName" && rule.field !== "desktopEntry") + return false; + return (rule.action || "default").toString().toLowerCase() === action && (rule.urgency || "default").toString().toLowerCase() === "default" && _isDndBypassRule(rule) === bypassDnd; + } + + function hasOwnAppRule(appName, desktopEntry, action, bypassDnd, nowMs) { + return _appRuleIndex(notificationRules || [], appName, desktopEntry, rule => rule.enabled !== false && isOwnAppRule(rule, action, bypassDnd) && !isNotificationRuleExpired(rule, nowMs)) !== -1; + } + + // Appended: the policy takes action and urgency from the first matching rule, mute is read from any rule. function addMuteRuleForApp(appName, desktopEntry, expiresAt) { - // Re-muting edits the app's existing no-action or mute rule (including an - // expired one not yet swept) so duplicates never accumulate. const changes = { action: "mute", expiresAt: expiresAt || 0 }; - if (!_updateAppRule(appName, desktopEntry, rule => _hasNoAction(rule) || _isMuteRule(rule), changes)) + if (!_updateAppRule(appName, desktopEntry, rule => isOwnAppRule(rule, "mute", false), changes)) _addAppRule(appName, desktopEntry, changes); } @@ -4076,28 +4090,37 @@ Singleton { } function removeMuteRuleForApp(appName, desktopEntry) { - _updateAppRule(appName, desktopEntry, _isMuteRule, { + _updateAppRule(appName, desktopEntry, rule => isOwnAppRule(rule, "mute", false), { action: "default", expiresAt: 0 }); } + // Kept first: the policy acts on the first matching rule only, so an ignore further down can be shadowed. + function addIgnoreRuleForApp(appName, desktopEntry) { + var rules = JSON.parse(JSON.stringify(notificationRules || [])); + const index = _appRuleIndex(rules, appName, desktopEntry, rule => rule.enabled !== false && isOwnAppRule(rule, "ignore", false)); + if (index === 0) + return; + rules.unshift(index === -1 ? _newNotificationRule(Object.assign(_appRuleKey(appName, desktopEntry), { + action: "ignore" + })) : rules.splice(index, 1)[0]); + notificationRules = rules; + saveSettings(); + } + function isAppDndBypassed(appName, desktopEntry) { return _appRuleIndex(notificationRules || [], appName, desktopEntry, rule => rule.enabled !== false && _isDndBypassRule(rule)) !== -1; } function setAppDndBypass(appName, desktopEntry, enabled) { if (!enabled) { - _updateAppRule(appName, desktopEntry, _isDndBypassRule, { + _updateAppRule(appName, desktopEntry, rule => isOwnAppRule(rule, "default", true), { bypassDnd: false }); return; } - if (isAppDndBypassed(appName, desktopEntry)) - return; - if (!_updateAppRule(appName, desktopEntry, () => true, { - bypassDnd: true - })) + if (!isAppDndBypassed(appName, desktopEntry)) _addAppRule(appName, desktopEntry, { bypassDnd: true }); diff --git a/quickshell/Common/SettingsTabs.qml b/quickshell/Common/SettingsTabs.qml index 33fc5afd2..74f640bc6 100644 --- a/quickshell/Common/SettingsTabs.qml +++ b/quickshell/Common/SettingsTabs.qml @@ -298,7 +298,7 @@ Singleton { "text": I18n.tr("Rules"), "icon": "rule_settings", "tabIndex": 55, - "hint": I18n.tr("Mute, ignore and priority rules per app") + "hint": I18n.tr("Mute, block and priority rules per app") } ] }, diff --git a/quickshell/Modules/Notifications/Center/NotificationCard.qml b/quickshell/Modules/Notifications/Center/NotificationCard.qml index abd12294d..6ea81738c 100644 --- a/quickshell/Modules/Notifications/Center/NotificationCard.qml +++ b/quickshell/Modules/Notifications/Center/NotificationCard.qml @@ -65,13 +65,6 @@ Item { PopoutService.closeNotificationCenter(); } - function openContextMenu(item, notification) { - contextActions.notification = notification; - contextMenuLoader.active = true; - contextMenuLoader.item.popupAnchorItem = item; - contextMenuLoader.item.showDropdownMenu(); - } - // positioners size on polish, so lay out once the width is known or the card is measured at its minimum height function settleLayout() { if (_laidOut || width <= 0) @@ -93,20 +86,11 @@ Item { settleLayout(); ready = true; } - Component.onDestruction: transientSurfaceTracker?.unregister(root) NotificationSwipeGroup { id: rowSwipe } - Connections { - target: root.transientSurfaceTracker - ignoreUnknownSignals: true - function onCloseRequested() { - contextMenuLoader.item?.closeDropdownMenu(); - } - } - Behavior on height { enabled: root.resizing && root.animateExpansion && NotificationMetrics.animationsEnabled NumberAnimation { @@ -138,10 +122,14 @@ Item { keyboardSelected: root.keyboardNavigationActive && root.isGroupSelected keyboardHints: keyboardSelected animateHeight: false + showDismiss: false + showClose: true + transientSurfaceTracker: root.transientSurfaceTracker + closeTooltip: I18n.tr("Close (keep in history)") onDescriptionExpandedChanged: root.animateResize() onExpandRequested: NotificationService.toggleMessageExpansion((notificationData?.notification?.id || "") + "_desc") onGroupToggleRequested: root.toggleGroup() - onDismissRequested: NotificationService.dismissGroup(root.notificationGroup?.key || "") + onCloseRequested: NotificationService.dismissGroup(root.notificationGroup?.key || "") onActionRequested: action => root.invokeAction(action) onBodyClicked: { if (groupCount > 1) { @@ -150,7 +138,6 @@ Item { } root.invokeAction(contextActions.defaultAction(notificationData)); } - onContextMenuRequested: (x, y) => root.openContextMenu(collapsedCard, collapsedCard.notificationData) } Loader { @@ -198,14 +185,6 @@ Item { anchors.rightMargin: NotificationMetrics.cardPadding anchors.verticalCenter: parent.verticalCenter spacing: Theme.spacingXS - DButton { - anchors.verticalCenter: parent.verticalCenter - text: I18n.tr("Dismiss") - buttonHeight: NotificationMetrics.controlSize - horizontalPadding: NotificationMetrics.actionPadding - variant: "text" - onClicked: NotificationService.dismissGroup(root.notificationGroup?.key || "") - } DButton { anchors.verticalCenter: parent.verticalCenter text: (root.notificationGroup?.count || 0).toString() @@ -217,6 +196,24 @@ Item { Accessible.name: I18n.tr("Collapse") onClicked: root.toggleGroup() } + DActionButton { + id: groupMenuButton + anchors.verticalCenter: parent.verticalCenter + iconName: "more_horiz" + buttonSize: NotificationMetrics.controlSize + iconSize: Theme.iconSizeSmall + tooltipText: I18n.tr("More") + // The hidden collapsed card carries the group's latest notification and closes the whole group. + onClicked: collapsedCard.openMenu(groupMenuButton) + } + DActionButton { + anchors.verticalCenter: parent.verticalCenter + iconName: "close" + buttonSize: NotificationMetrics.controlSize + iconSize: Theme.iconSizeSmall + tooltipText: I18n.tr("Close all", "notification group header button, dismisses every notification in the group") + onClicked: NotificationService.dismissGroup(root.notificationGroup?.key || "") + } } } @@ -265,12 +262,15 @@ Item { keyboardSelected: root.keyboardNavigationActive && root.selectedNotificationIndex === row.index keyboardHints: keyboardSelected descriptionExpanded: NotificationService.expandedMessages[(notificationData?.notification?.id || "") + "_desc"] || false + showDismiss: false + showClose: true + transientSurfaceTracker: root.transientSurfaceTracker + closeTooltip: I18n.tr("Close (keep in history)") onDescriptionExpandedChanged: root.animateResize() onExpandRequested: NotificationService.toggleMessageExpansion((notificationData?.notification?.id || "") + "_desc") - onDismissRequested: NotificationService.dismissNotification(row.modelData) + onCloseRequested: NotificationService.dismissNotification(row.modelData) onActionRequested: action => root.invokeAction(action) onBodyClicked: root.invokeAction(contextActions.defaultAction(notificationData)) - onContextMenuRequested: (x, y) => root.openContextMenu(message, row.modelData) } SequentialAnimation { @@ -300,24 +300,5 @@ Item { NotificationActions { id: contextActions - onDismissRequested: NotificationService.dismissGroup(root.notificationGroup?.key || "") - onAppMuted: NotificationService.dismissGroup(root.notificationGroup?.key || "") - } - - Loader { - id: contextMenuLoader - active: false - - sourceComponent: DDropdown { - showTrigger: false - popupWidth: NotificationMetrics.menuWidth - transientSurfaceTracker: root.transientSurfaceTracker - options: contextActions.items.map(item => item.label) - onValueChanged: value => { - const item = contextActions.items.find(item => item.label === value); - if (item) - contextActions.trigger(item.action); - } - } } } diff --git a/quickshell/Modules/Notifications/NotificationActions.qml b/quickshell/Modules/Notifications/NotificationActions.qml index 3a27cde92..b273ad836 100644 --- a/quickshell/Modules/Notifications/NotificationActions.qml +++ b/quickshell/Modules/Notifications/NotificationActions.qml @@ -6,84 +6,27 @@ import "../../Common/htmlElide.js" as HtmlElide QtObject { id: root - property string dismissText: I18n.tr("Dismiss") // null once the clicked notification closes; rule actions drop out with it property var notification: null - readonly property string appName: notification?.appName ?? "" readonly property string ruleAppName: notification?.ruleAppName ?? "" readonly property string desktopEntry: notification?.desktopEntry ?? "" readonly property string copyText: [notification?.summary, notification?.body].map(text => HtmlElide.stripHtmlTags((text || "").replace(//gi, "\n")).trim()).filter(text => text).join("\n") - // nowMs comes from NotificationService's ticking clock so these - // bindings refresh every minute and flip the moment a timed mute lapses - // (a raw Date.now() in a binding is not reactive and would freeze). - readonly property bool isMuted: !!notification && SettingsData.isAppMuted(ruleAppName, desktopEntry, NotificationService.notificationRuleNowMs) - // double, not int: epoch milliseconds exceed the 32-bit QML int range - readonly property double muteExpiresAt: notification ? SettingsData.muteExpiresAt(ruleAppName, desktopEntry, NotificationService.notificationRuleNowMs) : 0 - readonly property bool isDndBypassed: !!notification && SettingsData.isAppDndBypassed(ruleAppName, desktopEntry) - signal dismissRequested - signal appMuted - - readonly property string muteRemainingSuffix: { - if (!isMuted || muteExpiresAt <= 0) - return ""; - const remainingText = NotificationService.formatRuleRemaining(muteExpiresAt); - return remainingText ? I18n.tr(" (%1 left)", "notification menu, %1 = remaining time until a timed mute expires").arg(remainingText) : ""; - } readonly property var items: { - const list = notification ? _ruleItems() : []; - if (root.copyText) { - list.push({ - icon: "content_copy", - label: I18n.tr("Copy"), - action: "copy" - }); - } - list.push({ - icon: "close", - label: root.dismissText, - action: "dismiss" - }); - return list; - } - - function _ruleItems() { - const list = [ + const list = notification ? [ { icon: "tune", label: I18n.tr("Set notification rules"), action: "rules" } - ]; - if (isMuted) { - list.push({ - icon: "notifications", - label: I18n.tr("Unmute popups for %1", "notification menu action, %1 is the app name").arg(appName || I18n.tr("this app")) + muteRemainingSuffix, - action: "mute" - }); - } else { - const muteLabel = I18n.tr("Mute popups for %1", "notification menu action, %1 is the app name").arg(appName || I18n.tr("this app")); - list.push({ - icon: "notifications_off", - label: muteLabel + " (" + I18n.duration(3600) + ")", - action: "mute_1h" - }); - list.push({ - icon: "notifications_off", - label: muteLabel + " (" + I18n.duration(14400) + ")", - action: "mute_4h" - }); + ] : []; + if (root.copyText) { list.push({ - icon: "notifications_off", - label: muteLabel, - action: "mute" + icon: "content_copy", + label: I18n.tr("Copy"), + action: "copy" }); } - list.push({ - icon: isDndBypassed ? "do_not_disturb_on" : "do_not_disturb_off", - label: isDndBypassed ? I18n.tr("Block %1 in Do Not Disturb", "notification menu action, %1 is the app name").arg(appName || I18n.tr("this app")) : I18n.tr("Allow %1 in Do Not Disturb", "notification menu action, %1 is the app name").arg(appName || I18n.tr("this app")), - action: "dnd" - }); return list; } @@ -98,31 +41,9 @@ QtObject { SettingsData.requestNotificationRuleForNotification(ruleAppName, desktopEntry); PopoutService.openSettingsWithTab("notification_rules"); return; - case "mute": - if (isMuted) { - SettingsData.removeMuteRuleForApp(ruleAppName, desktopEntry); - return; - } - SettingsData.addMuteRuleForApp(ruleAppName, desktopEntry); - appMuted(); - return; - case "mute_1h": - SettingsData.addMuteRuleForApp(ruleAppName, desktopEntry, Date.now() + 60 * 60 * 1000); - appMuted(); - return; - case "mute_4h": - SettingsData.addMuteRuleForApp(ruleAppName, desktopEntry, Date.now() + 4 * 60 * 60 * 1000); - appMuted(); - return; - case "dnd": - SettingsData.setAppDndBypass(ruleAppName, desktopEntry, !isDndBypassed); - return; case "copy": Quickshell.execDetached([Proc.dmsBin, "cl", "copy", copyText]); ToastService.showInfo(I18n.tr("Copied to clipboard")); - return; - case "dismiss": - dismissRequested(); } } } diff --git a/quickshell/Modules/Notifications/NotificationCard.qml b/quickshell/Modules/Notifications/NotificationCard.qml index 1c31274a4..d1e73b2ce 100644 --- a/quickshell/Modules/Notifications/NotificationCard.qml +++ b/quickshell/Modules/Notifications/NotificationCard.qml @@ -1,4 +1,5 @@ import QtQuick +import QtQuick.Shapes import Quickshell.Widgets import Quickshell.Services.Notifications import qs.Common @@ -16,10 +17,13 @@ Rectangle { property bool descriptionExpanded: false property bool privacyMode: false property bool showActions: true + property bool reserveActionRow: false property bool showDismiss: true property bool showClose: false + property var transientSurfaceTracker: null + property var popupSurface: null + property string closeTooltip: I18n.tr("Close") property bool revealControls: true - property string dismissText: I18n.tr("Dismiss") property bool showTime: true property bool bodyInvokesAction: false property bool persistImage: false @@ -56,7 +60,11 @@ Rectangle { signal expandRequested signal groupToggleRequested signal bodyClicked - signal contextMenuRequested(real x, real y) + + function openMenu(anchor, x, y) { + menuLoader.active = true; + menuLoader.item.openAt(anchor, root.popupSurface, x, y); + } function forceLayout() { messageText.forceLayout(); @@ -154,7 +162,8 @@ Rectangle { cursorShape: Qt.PointingHandCursor onClicked: mouse => { if (mouse.button === Qt.RightButton) { - root.contextMenuRequested(mouse.x, mouse.y); + if (root.transientSurfaceTracker !== null) + root.openMenu(root, mouse.x, mouse.y); return; } root.bodyClicked(); @@ -297,6 +306,63 @@ Rectangle { } } + Loader { + active: root.interactive && root.transientSurfaceTracker !== null + visible: active + + sourceComponent: DActionButton { + id: menuButton + iconName: "more_horiz" + buttonSize: NotificationMetrics.controlSize + iconSize: Theme.iconSizeSmall + tooltipText: I18n.tr("More") + onClicked: root.openMenu(menuButton) + } + } + + Loader { + active: root.interactive && root.showDismiss && root.transientSurfaceTracker === null + visible: active + + sourceComponent: DActionButton { + id: dismissButton + buttonSize: NotificationMetrics.controlSize + iconSize: Theme.iconSizeSmall + tooltipText: I18n.tr("Clear from history") + onClicked: root.dismissRequested() + + Shape { + x: (dismissButton.width - dismissButton.iconSize) / 2 + y: (dismissButton.height - dismissButton.iconSize) / 2 + width: 24 + height: 24 + scale: dismissButton.iconSize / 24 + transformOrigin: Item.TopLeft + preferredRendererType: Shape.CurveRenderer + + ShapePath { + strokeColor: dismissButton.iconColor + strokeWidth: 2.8 + fillColor: "transparent" + capStyle: ShapePath.RoundCap + + PathSvg { + path: "M21.5 2.5 L13.4 10.6" + } + } + + ShapePath { + strokeColor: "transparent" + fillColor: dismissButton.iconColor + + PathSvg { + path: "M12.62 10 C8.94 9.65 5.72 10.92 3.42 12.99 L2.04 13.22 L3.54 14.6 L1.93 15.29 L3.88 16.44 L2.96 17.59 L4.8 17.93 L4.8 19.55 L6.41 19.08 L6.99 20.81 L8.25 19.66 L9.52 21.73 L10.32 20.35 C12.74 17.93 14.23 14.83 14 11.38 Z" + } + } + } + } + } + Loader { active: root.interactive && root.showClose visible: active @@ -305,7 +371,7 @@ Rectangle { iconName: "close" buttonSize: NotificationMetrics.controlSize iconSize: Theme.iconSizeSmall - Accessible.name: I18n.tr("Dismiss") + tooltipText: root.closeTooltip onClicked: root.closeRequested() } } @@ -416,8 +482,8 @@ Rectangle { Item { width: parent.width - height: actions.implicitHeight - visible: root.interactive && !root.headerOnly && (root.showActions || root.showDismiss) + height: actions.implicitHeight || (root.reserveActionRow ? NotificationMetrics.reservedActionRowHeight : 0) + visible: root.interactive && !root.headerOnly && root.showActions && (actionRepeater.count > 0 || root.reserveActionRow) Flow { id: actions @@ -427,6 +493,7 @@ Rectangle { spacing: Theme.spacingXS Repeater { + id: actionRepeater model: root.showActions ? (root.notificationData?.actions || []) : [] DButton { required property var modelData @@ -441,19 +508,21 @@ Rectangle { onClicked: root.actionRequested(modelData) } } - - DButton { - visible: root.showDismiss - text: root.dismissText - maximumWidth: actions.width - wrapText: true - buttonHeight: NotificationMetrics.actionHeight - horizontalPadding: NotificationMetrics.actionPadding - minimumWidth: 0 - variant: "text" - onClicked: root.dismissRequested() - } } } } + + Loader { + id: menuLoader + active: false + visible: false + + sourceComponent: NotificationMuteMenu { + transientSurfaceTracker: root.transientSurfaceTracker + notification: root.notificationData + canClear: root.showDismiss + onMuted: root.closeRequested() + onClearRequested: root.dismissRequested() + } + } } diff --git a/quickshell/Modules/Notifications/NotificationContextMenu.qml b/quickshell/Modules/Notifications/NotificationContextMenu.qml deleted file mode 100644 index b70472dfe..000000000 --- a/quickshell/Modules/Notifications/NotificationContextMenu.qml +++ /dev/null @@ -1,49 +0,0 @@ -import QtQuick -import qs.Common -import qs.Modules.Notifications -import qs.Services -import qs.Widgets - -DContextMenu { - id: root - - property alias dismissText: actions.dismissText - property alias notification: actions.notification - - signal dismissRequested - signal appMuted - - layerNamespace: "dms:notification-context-menu" - minMenuWidth: NotificationMetrics.menuWidth - menuItems: actions.items.map(item => ({ - type: "item", - icon: item.icon, - text: item.label, - action: () => { - actions.trigger(item.action); - hide(); - } - })) - - function showAt(x, y, targetScreen) { - open(targetScreen ?? root.targetScreen, x, y, false); - } - - function closeMenu() { - hide(); - } - - NotificationActions { - id: actions - onDismissRequested: root.dismissRequested() - onAppMuted: root.appMuted() - } - - Connections { - target: PopoutManager - - function onPopoutOpening() { - root.hide(); - } - } -} diff --git a/quickshell/Modules/Notifications/NotificationMetrics.qml b/quickshell/Modules/Notifications/NotificationMetrics.qml index 0dd3685f9..6b850220b 100644 --- a/quickshell/Modules/Notifications/NotificationMetrics.qml +++ b/quickshell/Modules/Notifications/NotificationMetrics.qml @@ -18,6 +18,7 @@ Singleton { readonly property real imageMaxHeight: Theme.listItemHeight * 4 readonly property real imageDecodeSize: popupWidth * 2 readonly property real actionHeight: compact ? Theme.buttonHeightXS : Theme.buttonHeightS + readonly property real reservedActionRowHeight: (actionHeight - contentSpacing) / 2 readonly property real actionPadding: Theme.spacingS readonly property real controlSize: compact ? Theme.buttonHeightXXS : Theme.buttonHeightXS readonly property real railHeight: Theme.spacingXS diff --git a/quickshell/Modules/Notifications/NotificationMuteMenu.qml b/quickshell/Modules/Notifications/NotificationMuteMenu.qml new file mode 100644 index 000000000..0f495afb5 --- /dev/null +++ b/quickshell/Modules/Notifications/NotificationMuteMenu.qml @@ -0,0 +1,289 @@ +import QtQuick +import Quickshell +import qs.Common +import qs.Services +import qs.DCommon.Widgets +import qs.Widgets +import "../../Common/QmlUtils.js" as QmlUtils + +DContextMenu { + id: root + + property alias notification: actions.notification + readonly property string appName: notification?.appName ?? "" + readonly property string ruleAppName: notification?.ruleAppName ?? "" + readonly property string desktopEntry: notification?.desktopEntry ?? "" + property bool canClear: false + property bool blockArmed: false + + signal muted + signal clearRequested + + minMenuWidth: NotificationMetrics.menuWidth + onOpenStateChanged: { + if (!openState) { + blockArmed = false; + durations.hide(); + } + } + menuItems: { + const label = appName || I18n.tr("this app"); + const nowMs = NotificationService.notificationRuleNowMs; + // Header actions only undo their own rules; a state set in the editor is changed there. + const rulesItem = { + type: "item", + icon: "tune", + text: I18n.tr("Set by a notification rule", "notification menu item, opens the rule that mutes or allows this app"), + action: () => PopoutService.openSettingsWithTab("notification_rules") + }; + const muteItems = SettingsData.hasOwnAppRule(ruleAppName, desktopEntry, "mute", false, nowMs) ? [ + { + type: "item", + icon: "notifications", + text: I18n.tr("Unmute popups for %1", "notification menu action, %1 is the app name").arg(label), + action: () => SettingsData.removeMuteRuleForApp(ruleAppName, desktopEntry) + } + ] : SettingsData.isAppMuted(ruleAppName, desktopEntry, nowMs) ? [rulesItem] : [ + { + type: "item", + icon: "notifications_off", + text: I18n.tr("Mute Popups", "notification rule action option"), + trailingIcon: I18n.isRtl ? "chevron_left" : "chevron_right", + keepOpen: true, + action: () => openDurations() + } + ]; + const ownDnd = SettingsData.hasOwnAppRule(ruleAppName, desktopEntry, "default", true, nowMs); + const dndItem = !ownDnd && SettingsData.isAppDndBypassed(ruleAppName, desktopEntry) ? rulesItem : { + type: "item", + icon: "bedtime", + text: ownDnd ? I18n.tr("Stop allowing %1 during Do Not Disturb", "notification menu action, %1 is the app name").arg(label) : I18n.tr("Allow %1 during Do Not Disturb", "notification menu action, %1 is the app name").arg(label), + action: () => SettingsData.setAppDndBypass(ruleAppName, desktopEntry, !ownDnd) + }; + return [ + ...muteItems, + { + type: "item", + icon: "block", + text: blockArmed ? I18n.tr("Click again to block %1", "notification header button, %1 is the app name").arg(label) : I18n.tr("Block %1", "notification header button, %1 is the app name").arg(label) + "…", + keepOpen: !blockArmed, + action: () => { + if (!blockArmed) { + blockArmed = true; + return; + } + SettingsData.addIgnoreRuleForApp(ruleAppName, desktopEntry); + hide(); + muted(); + } + }, + { + type: "item", + hidden: !canClear, + icon: "cleaning_services", + text: I18n.tr("Clear from history"), + action: () => { + hide(); + clearRequested(); + } + }, + ...(muteItems[0] === rulesItem && dndItem === rulesItem ? [] : [dndItem]), + { + type: "separator" + }, + ...actions.items.map(item => ({ + type: "item", + icon: item.icon, + text: item.label, + action: () => actions.trigger(item.action) + })) + ]; + } + + function openAt(anchor, popupSurface, x, y) { + const window = anchor.QsWindow.window; + const atPoint = x !== undefined; + const px = atPoint ? x : 0; + const py = atPoint ? y : anchor.height; + // The popup band can be centred, anchored to neither edge, which screenPointOf reads as x = 0 + const local = popupSurface ? anchor.mapToItem(null, px, py) : null; + const pos = local ? Qt.point(local.x + popupSurface.bandX, local.y + popupSurface.bandY) : QmlUtils.screenPointOf(window, anchor, px, py); + if (!pos) + return; + open(window.screen, atPoint || I18n.isRtl ? pos.x : pos.x + anchor.width - effectiveMenuWidth, pos.y, false); + } + + // Mirrors DContextMenu's on-screen clamp; the mute row is the first row, so the submenu shares the menu's top. + function openDurations() { + const x = Math.max(menuMargin, Math.min(contextWindow.width - effectiveMenuWidth - menuMargin, anchorX)); + const y = Math.max(menuMargin, Math.min(contextWindow.height - effectiveMenuHeight - menuMargin, anchorY)); + const fitsRight = x + effectiveMenuWidth + durations.effectiveMenuWidth <= contextWindow.width - menuMargin; + const fitsLeft = x - durations.effectiveMenuWidth >= menuMargin; + const toRight = I18n.isRtl ? fitsRight && !fitsLeft : fitsRight || !fitsLeft; + durations.open(targetScreen, toRight ? x + effectiveMenuWidth : x - durations.effectiveMenuWidth, y, keyboardNavigation); + } + + function mute(minutes) { + SettingsData.addMuteRuleForApp(ruleAppName, desktopEntry, minutes > 0 ? Date.now() + minutes * 60 * 1000 : 0); + hide(); + muted(); + } + + DContextMenu { + id: durations + + property bool customOpen: false + readonly property var customUnits: [ + { + label: I18n.tr("D", "custom mute duration field, days", true), + minutes: 24 * 60 + }, + { + label: I18n.tr("H", "custom mute duration field, hours", true), + minutes: 60 + }, + { + label: I18n.tr("M", "custom mute duration field, minutes", true), + minutes: 1 + } + ] + + transientSurfaceTracker: root.transientSurfaceTracker + minMenuWidth: NotificationMetrics.menuWidth + // Keyboard focus only while the custom fields are open, so the plain menu never steals it. + keyboardNavigable: customOpen + // Its fullscreen backdrop covers the main menu, so any dismissal closes both. + onOpenStateChanged: { + if (!openState) { + customOpen = false; + root.hide(); + } + } + menuItems: [ + { + type: "item", + icon: "schedule", + text: I18n.tr("For 1 hour", "timed preset menu option"), + action: () => root.mute(60) + }, + { + type: "item", + icon: "schedule", + text: I18n.tr("For %1", "timed preset menu option, %1 is a duration such as 15 minutes").arg(I18n.duration(14400)), + action: () => root.mute(4 * 60) + }, + { + type: "item", + icon: "notifications_off", + text: I18n.tr("Forever"), + action: () => root.mute(0) + }, + { + type: "separator" + }, + { + type: "item", + icon: "tune", + text: I18n.tr("Custom") + "…", + keepOpen: true, + action: () => durations.customOpen = true + }, + { + type: "component", + hidden: !durations.customOpen, + height: Theme.fieldHeight, + component: customFields + } + ] + + Component { + id: customFields + + // Takes clicks on labels and gaps, and keys the fields leave unhandled, before the menu backdrop and key + // handler see them: Enter would activate the hovered row, Left would close, Up/Down move the highlight. + MouseArea { + id: fields + // customOpen rebuilds menuItems, so the row is created already shown; focus once the menu's own + // focus binding has settled on its key handler. + Component.onCompleted: { + if (durations.customOpen) + Qt.callLater(() => units.itemAt(0)?.field.forceActiveFocus()); + } + Keys.onPressed: event => { + if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) + apply(); + event.accepted = [Qt.Key_Return, Qt.Key_Enter, Qt.Key_Left, Qt.Key_Up, Qt.Key_Down].includes(event.key); + } + + function apply() { + let minutes = 0; + for (let i = 0; i < units.count; i++) + minutes += units.itemAt(i).minutes; + if (minutes > 0) + root.mute(minutes); + } + + Row { + spacing: Theme.spacingXS + leftPadding: Theme.spacingS + + Repeater { + id: units + model: durations.customUnits + + Row { + id: unit + required property var modelData + readonly property alias field: input + readonly property int minutes: (parseInt(input.text) || 0) * modelData.minutes + spacing: Theme.spacingXXS + + DTextField { + id: input + width: Theme.buttonHeightS + validator: IntValidator { + bottom: 0 + top: 999 + } + } + + StyledText { + anchors.verticalCenter: parent.verticalCenter + text: unit.modelData.label + font.pixelSize: Theme.fontSizeSmall + color: Theme.onSurfaceVariant + } + } + } + + DButton { + anchors.verticalCenter: parent.verticalCenter + text: I18n.tr("OK") + variant: "text" + minimumWidth: 0 + horizontalPadding: NotificationMetrics.actionPadding + onClicked: fields.apply() + } + } + } + } + } + + NotificationActions { + id: actions + } + + Timer { + interval: 3000 + running: root.blockArmed + onTriggered: root.blockArmed = false + } + + Connections { + target: PopoutManager + + function onPopoutOpening() { + root.hide(); + } + } +} diff --git a/quickshell/Modules/Notifications/Popup/NotificationPopup.qml b/quickshell/Modules/Notifications/Popup/NotificationPopup.qml index c9a902797..69a71b7fb 100644 --- a/quickshell/Modules/Notifications/Popup/NotificationPopup.qml +++ b/quickshell/Modules/Notifications/Popup/NotificationPopup.qml @@ -212,7 +212,6 @@ Item { function closeTransientUi() { transientSurfaces.closeAll(); - popupContextMenuLoader.active = false; } NotificationActions { @@ -706,10 +705,12 @@ Item { privacyMode: SettingsData.notificationPopupPrivacyMode bodyInvokesAction: win.bodyClickInvokesAction persistImage: true + reserveActionRow: true showClose: true + transientSurfaceTracker: transientSurfaces + popupSurface: win.surface revealControls: win.hovered || win.contextMenuActive contentOpacity: swipe.contentOpacity - dismissText: I18n.tr("Clear") animateHeight: false outerRadius: win.connectedFrameMode ? Theme.connectedSurfaceRadius : NotificationMetrics.popupRadius color: "transparent" @@ -743,14 +744,6 @@ Item { } win.dismissPopupReliably(); } - onContextMenuRequested: (x, y) => { - popupContextMenuLoader.active = true; - const menu = popupContextMenuLoader.item; - if (!menu) - return; - const point = mapToItem(null, x, y); - menu.showAt(point.x + (win.surface?.bandX ?? 0), point.y + (win.surface?.bandY ?? 0), win.screen); - } } } } @@ -948,18 +941,13 @@ Item { } } - Connections { - target: popupContextMenuLoader.item - ignoreUnknownSignals: true - - function onVisibleChanged() { - if (!notificationData?.timer || exiting || _isDestroying) - return; - if (win.contextMenuActive) { - notificationData.timer.stop(); - } else if (!cardHoverHandler.hovered && notificationData.popup) { - notificationData.timer.restart(); - } + onContextMenuActiveChanged: { + if (!notificationData?.timer || exiting || _isDestroying) + return; + if (contextMenuActive) { + notificationData.timer.stop(); + } else if (!cardHoverHandler.hovered && notificationData.popup) { + notificationData.timer.restart(); } } @@ -970,23 +958,4 @@ Item { repeat: false onTriggered: finalizeExit("watchdog") } - - Loader { - id: popupContextMenuLoader - active: false - - sourceComponent: NotificationContextMenu { - transientSurfaceTracker: transientSurfaces - dismissText: notificationCard.dismissText - notification: notificationData - onAppMuted: { - if (notificationData && !win.exiting) - NotificationService.dismissNotification(notificationData); - } - onDismissRequested: { - if (notificationData && !win.exiting) - NotificationService.permanentlyDismissNotification(notificationData); - } - } - } } diff --git a/quickshell/Modules/Notifications/Popup/NotificationPopupManager.qml b/quickshell/Modules/Notifications/Popup/NotificationPopupManager.qml index 697deea18..7be6a5869 100644 --- a/quickshell/Modules/Notifications/Popup/NotificationPopupManager.qml +++ b/quickshell/Modules/Notifications/Popup/NotificationPopupManager.qml @@ -20,7 +20,13 @@ DIdleSurface { return Qt.rect(0, 0, 0, 0); return Qt.rect(p.alignedX, p.alignedY, p.alignedWidth, p.alignedHeight); } - readonly property bool overlayWanted: popupWindows.some(p => p?.wantsOverlay ?? false) + // Frozen while a card menu is open: a layer change remaps the surface above the menu. + property bool overlayWanted: false + Binding on overlayWanted { + when: !manager.popupWindows.some(p => p?.contextMenuActive) + value: manager.popupWindows.some(p => p?.wantsOverlay ?? false) + restoreMode: Binding.RestoreNone + } readonly property list blurRegions: popupWindows.map(p => p?.blurRegion ?? null).filter(r => r !== null) // A stack growing from the bottom would move the surface origin under visible cards, so it keeps the band. readonly property bool fitsStack: boundsSupported && _stackAnchorsTop() diff --git a/quickshell/Modules/Settings/NotificationRulesTab.qml b/quickshell/Modules/Settings/NotificationRulesTab.qml index 9b66668a5..551d7d236 100644 --- a/quickshell/Modules/Settings/NotificationRulesTab.qml +++ b/quickshell/Modules/Settings/NotificationRulesTab.qml @@ -22,7 +22,9 @@ Item { // Expired timed mutes drop out of the list the minute they lapse // (notificationRuleNowMs ticks), without waiting for the sweep. - readonly property var mutedRules: indexedRules(rule => (rule.action || "").toString().toLowerCase() === "mute" && !SettingsData.isNotificationRuleExpired(rule, NotificationService.notificationRuleNowMs)) + // Only the header's own rules: Unmute/Unblock delete the whole rule, so manual rules stay in the main list. + readonly property var mutedRules: indexedRules(rule => SettingsData.isOwnAppRule(rule, "mute", false) && !SettingsData.isNotificationRuleExpired(rule, NotificationService.notificationRuleNowMs)) + readonly property var blockedRules: indexedRules(rule => SettingsData.isOwnAppRule(rule, "ignore", false)) readonly property var notificationRuleFieldOptions: [ { @@ -69,7 +71,7 @@ Item { }, { value: "ignore", - label: I18n.tr("Ignore Completely", "notification rule action option") + label: I18n.tr("Block", "notification rule action option") }, { value: "popup_only", @@ -203,7 +205,7 @@ Item { } SettingsRow { - subtitle: I18n.tr("Mute, ignore and priority rules per app") + subtitle: I18n.tr("Mute, block and priority rules per app") } Repeater { @@ -267,13 +269,13 @@ Item { SettingsDeferred { SettingsCard { - iconName: "volume_off" + iconName: "notifications_off" title: I18n.tr("Muted apps") settingKey: "mutedApps" tags: ["notification", "mute", "unmute", "popup"] SettingsRow { - subtitle: root.mutedRules.length > 0 ? I18n.tr("Apps with notification popups muted. Unmute or delete to remove.") : I18n.tr("No apps muted. Right-click a notification and choose \"Mute popups\" to add one here.") + subtitle: root.mutedRules.length > 0 ? I18n.tr("Apps with notification popups muted. Unmute or delete to remove.") : I18n.tr("No apps muted. Use the mute button on a notification to add one here.") } Repeater { @@ -296,6 +298,36 @@ Item { } } + SettingsDeferred { + SettingsCard { + iconName: "block" + title: I18n.tr("Blocked apps") + settingKey: "blockedApps" + tags: ["notification", "block", "unblock", "ignore"] + + SettingsRow { + subtitle: root.blockedRules.length > 0 ? I18n.tr("Apps whose notifications are dropped entirely. Unblock to remove.") : I18n.tr("No apps blocked. Use the block button on a notification to add one here.") + } + + Repeater { + model: root.blockedRules + + delegate: SettingsRow { + required property var modelData + + title: modelData.rule?.pattern || I18n.tr("Unknown") + singleLineTitle: true + + DButton { + text: I18n.tr("Unblock") + variant: "text" + onClicked: SettingsData.removeNotificationRule(modelData.index) + } + } + } + } + } + SettingsFabBar { DFab { text: I18n.tr("Add rule", "notification rule dialog title and button") diff --git a/quickshell/tests/notification-menu-rules.test.mjs b/quickshell/tests/notification-menu-rules.test.mjs index c2141efe0..bf09e4d88 100644 --- a/quickshell/tests/notification-menu-rules.test.mjs +++ b/quickshell/tests/notification-menu-rules.test.mjs @@ -32,21 +32,7 @@ function policy(rules, notif) { const rule = overrides => ({ enabled: true, field: "appName", pattern: "firefox", matchType: "exact", action: "default", urgency: "default", bypassDnd: false, ...overrides }); const plain = value => JSON.parse(JSON.stringify(value)); -test("unmute keeps a rule that also bypasses DND", () => { - const s = settings([rule({ action: "mute", bypassDnd: true })]); - s.removeMuteRuleForApp("Firefox", ""); - assert.deepEqual(plain(s.notificationRules), [rule({ bypassDnd: true })]); - assert.equal(s.isAppMuted("Firefox", ""), false); - assert.equal(s.isAppDndBypassed("Firefox", ""), true); -}); - -test("block in DND keeps a rule with an action", () => { - const s = settings([rule({ action: "no_history", bypassDnd: true })]); - s.setAppDndBypass("Firefox", "", false); - assert.deepEqual(plain(s.notificationRules), [rule({ action: "no_history" })]); -}); - -test("rule is removed only when nothing meaningful is left", () => { +test("unmute and stop allowing in DND remove the app's own rule", () => { let s = settings([rule({ action: "mute" })]); s.removeMuteRuleForApp("Firefox", ""); assert.deepEqual(plain(s.notificationRules), []); @@ -54,10 +40,49 @@ test("rule is removed only when nothing meaningful is left", () => { s = settings([rule({ bypassDnd: true })]); s.setAppDndBypass("Firefox", "", false); assert.deepEqual(plain(s.notificationRules), []); +}); - s = settings([rule({ action: "mute", urgency: "critical" })]); +test("header actions never edit a rule built in the editor", () => { + const manual = [rule({ action: "mute", bypassDnd: true }), rule({ action: "no_history", bypassDnd: true }), rule({ action: "mute", urgency: "critical" })]; + const s = settings(plain(manual)); s.removeMuteRuleForApp("Firefox", ""); - assert.deepEqual(plain(s.notificationRules), [rule({ urgency: "critical" })]); + s.setAppDndBypass("Firefox", "", false); + assert.deepEqual(plain(s.notificationRules), manual); + assert.equal(s.isAppMuted("Firefox", ""), true); + assert.equal(s.hasOwnAppRule("Firefox", "", "mute", false), false); + assert.equal(s.isAppDndBypassed("Firefox", ""), true); + assert.equal(s.hasOwnAppRule("Firefox", "", "default", true), false); + assert.equal(settings([rule({ action: "mute", expiresAt: 1 })]).hasOwnAppRule("Firefox", "", "mute", false), false); + assert.deepEqual([rule({ action: "ignore" }), rule({ action: "ignore", bypassDnd: true }), rule({ action: "ignore", matchType: "contains" }), rule({ action: "ignore", conditions: [rule()] }), rule({ action: "ignore", field: "summary" })].map(r => s.isOwnAppRule(r, "ignore", false)), [true, false, false, false, false]); + + const critical = rule({ urgency: "critical" }); + const later = Date.now() + 60000; + const t = settings([critical]); + t.addMuteRuleForApp("Firefox", "", later); + assert.deepEqual(plain(t.notificationRules), [critical, rule({ pattern: "Firefox", action: "mute", expiresAt: later })]); + t.addMuteRuleForApp("Firefox", ""); + assert.deepEqual(plain(t.notificationRules), [critical, rule({ pattern: "Firefox", action: "mute" })]); +}); + +test("block, mute and DND each own a rule, ordered so none shadows a manual rule", () => { + const manual = rule({ pattern: "fire", matchType: "contains", urgency: "low" }); + const notif = { appName: "Firefox", summary: "", body: "" }; + const s = settings([manual]); + s.addMuteRuleForApp("Firefox", ""); + s.setAppDndBypass("Firefox", "", true); + s.addIgnoreRuleForApp("Firefox", ""); + const mute = rule({ pattern: "Firefox", action: "mute" }); + const dnd = rule({ pattern: "Firefox", bypassDnd: true }); + assert.deepEqual(plain(s.notificationRules), [rule({ pattern: "Firefox", action: "ignore" }), manual, mute, dnd]); + + s.removeNotificationRule(0); + assert.deepEqual(plain(s.notificationRules), [manual, mute, dnd]); + assert.equal(s.hasOwnAppRule("Firefox", "", "mute", false), true); + assert.equal(s.hasOwnAppRule("Firefox", "", "default", true), true); + const p = policy(plain(s.notificationRules), notif); + assert.equal(p.urgency, 0); + assert.equal(p.disablePopup, true); + assert.equal(p.bypassDnd, true); }); test("disabled rules are never edited or deleted", () => { @@ -71,16 +96,6 @@ test("disabled rules are never edited or deleted", () => { assert.deepEqual(plain(s.notificationRules), [disabled, rule({ pattern: "Firefox", action: "mute" })]); }); -test("mute and DND bypass share one rule instead of shadowing each other", () => { - const s = settings([rule({ bypassDnd: true })]); - s.addMuteRuleForApp("Firefox", ""); - assert.deepEqual(plain(s.notificationRules), [rule({ action: "mute", bypassDnd: true })]); - - const t = settings([rule({ action: "no_history" })]); - t.setAppDndBypass("Firefox", "", true); - assert.deepEqual(plain(t.notificationRules), [rule({ action: "no_history", bypassDnd: true })]); -}); - test("mute next to an exact no_history rule appends a mute rule and unmute removes only it", () => { const noHistory = rule({ action: "no_history" }); const s = settings([noHistory]); @@ -155,4 +170,24 @@ test("a sender with no app name or desktop entry can be muted without muting nam s.removeMuteRuleForApp("", ""); assert.deepEqual(plain(s.notificationRules), []); + + s.addIgnoreRuleForApp("", ""); + s.addIgnoreRuleForApp("", ""); + assert.equal(s.notificationRules.length, 1); + assert.equal(s.isOwnAppRule(s.notificationRules[0], "ignore", false), true); +}); + +test("block drops the app even behind an earlier matching rule and is added once", () => { + const broad = rule({ pattern: "fire", matchType: "contains", urgency: "low" }); + const s = settings([broad]); + s.addIgnoreRuleForApp("Firefox", ""); + s.addIgnoreRuleForApp("Firefox", ""); + assert.deepEqual(plain(s.notificationRules), [rule({ pattern: "Firefox", action: "ignore" }), broad]); + assert.equal(policy(plain(s.notificationRules), { appName: "Firefox", summary: "", body: "" }).drop, true); + + const ignore = rule({ action: "ignore" }); + const t = settings([broad, ignore]); + t.addIgnoreRuleForApp("Firefox", ""); + assert.deepEqual(plain(t.notificationRules), [ignore, broad]); + assert.equal(policy(plain(t.notificationRules), { appName: "Firefox", summary: "", body: "" }).drop, true); }); diff --git a/quickshell/translations/settings_search_index.json b/quickshell/translations/settings_search_index.json index ad47b9f71..02ecfe0b8 100644 --- a/quickshell/translations/settings_search_index.json +++ b/quickshell/translations/settings_search_index.json @@ -18908,6 +18908,30 @@ "parentLabel": "Bar", "icon": "SettingsUiState.selectedWidgetIcon" }, + { + "section": "blockedApps", + "label": "Blocked apps", + "tabIndex": 55, + "category": "Rules", + "keywords": [ + "alert", + "alerts", + "apps", + "block", + "blocked", + "ignore", + "messages", + "notif", + "notification", + "notifications", + "notifs", + "rules", + "toast", + "unblock" + ], + "parentLabel": "Notifications", + "icon": "block" + }, { "section": "mutedApps", "label": "Muted apps", @@ -18930,7 +18954,7 @@ "unmute" ], "parentLabel": "Notifications", - "icon": "volume_off" + "icon": "notifications_off" }, { "section": "notificationRules", @@ -18964,7 +18988,7 @@ "keywords": [ "alert", "alerts", - "ignore", + "block", "messages", "mute", "notif", @@ -18976,7 +19000,7 @@ ], "icon": "rule_settings", "parentLabel": "Notifications", - "description": "Mute, ignore and priority rules per app" + "description": "Mute, block and priority rules per app" }, { "section": "useAutoLocation",