Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions quickshell/Common/SettingsData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
});
Expand Down
2 changes: 1 addition & 1 deletion quickshell/Common/SettingsTabs.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
]
},
Expand Down
75 changes: 28 additions & 47 deletions quickshell/Modules/Notifications/Center/NotificationCard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -150,7 +138,6 @@ Item {
}
root.invokeAction(contextActions.defaultAction(notificationData));
}
onContextMenuRequested: (x, y) => root.openContextMenu(collapsedCard, collapsedCard.notificationData)
}

Loader {
Expand Down Expand Up @@ -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()
Expand All @@ -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 || "")
}
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
}
}
91 changes: 6 additions & 85 deletions quickshell/Modules/Notifications/NotificationActions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<br\s*\/?>/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;
}

Expand All @@ -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();
}
}
}
Loading
Loading