From d7fbe8c2226de7cd96fcad9dc3b1995b7f4c963a Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 28 Feb 2021 10:53:19 -0400 Subject: [PATCH] Add keybinds to control global notifications Alt+M: toggle "mute all notifications except highlights" Alt+Shift+M: toggle "mute all notifications" The Keys.Rooms.(previous/next)_highlight keybinds, previously bound to Alt+(Shift+)M (stood for "mention") now defaults to Alt+(Shift+)H. The NotificationLevel enum and notificationLevel property had to be moved from Window to UI due to QML having a global "Window" object that causes conflicts when trying to access the enum as "Window.NotificationLevel" from UI.qml. --- docs/TODO.md | 1 - src/config/settings.py | 11 ++++++++-- src/gui/MainPane/TopBar.qml | 30 ++++++++++++-------------- src/gui/PythonBridge/EventHandlers.qml | 6 +++--- src/gui/UI.qml | 29 +++++++++++++++++++++++++ src/gui/Window.qml | 9 -------- 6 files changed, 55 insertions(+), 31 deletions(-) diff --git a/docs/TODO.md b/docs/TODO.md index 31d88b51..4036e6bc 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -6,7 +6,6 @@ - explain pattern - fix spinbox buttons - HMenuItem checkbox styling -- config & keybind for global rule disabling - quick settings - import/export/json edit rules? - fix flickable popups can't be flicked by keyboard diff --git a/src/config/settings.py b/src/config/settings.py index f2b0b77c..ce69ea17 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -236,6 +236,13 @@ class Keys: # Switch to the last opened page/chat, similar to Alt+Tab on most desktops. last_page = ["Ctrl+Tab"] + # Toggle muting all notifications in the running client, + # except highlights (e.g. replies or keywords) + notifications_highlights_only = ["Alt+M"] + + # Toggle muting all notifications in the running client + notifications_mute = ["Alt+Shift+M"] + # Toggle the QML developer console. Type ". help" inside it for more info. qml_console = ["F1"] @@ -321,8 +328,8 @@ class Keys: # list. What causes a highlight is controlled by push rules # (editable in GUI account settings): by default, this includes # when your name is mentioned, replied to, or messages with keywords. - previous_highlight = ["Alt+Shift+M"] - next_highlight = ["Alt+M"] + previous_highlight = ["Alt+Shift+H"] + next_highlight = ["Alt+H"] class AtIndex: # Switch to room number X in the current account. diff --git a/src/gui/MainPane/TopBar.qml b/src/gui/MainPane/TopBar.qml index 1b233d51..e9ed3a17 100644 --- a/src/gui/MainPane/TopBar.qml +++ b/src/gui/MainPane/TopBar.qml @@ -67,19 +67,19 @@ Rectangle { backgroundColor: "transparent" icon.name: - window.notificationLevel === Window.NotificationLevel.Enable ? + mainUI.notificationLevel === UI.NotificationLevel.Enable ? "notifications-all" : - window.notificationLevel === Window.NotificationLevel.Mute ? + mainUI.notificationLevel === UI.NotificationLevel.Mute ? "notifications-none" : "notifications-mentions-keywords" icon.color: - window.notificationLevel === Window.NotificationLevel.Enable ? + mainUI.notificationLevel === UI.NotificationLevel.Enable ? theme.icons.colorize : - window.notificationLevel === Window.NotificationLevel.Mute ? + mainUI.notificationLevel === UI.NotificationLevel.Mute ? theme.colors.negativeBackground : theme.colors.middleBackground @@ -95,31 +95,29 @@ Rectangle { HMenuItem { text: qsTr("Enable notifications") checked: - window.notificationLevel === - Window.NotificationLevel.Enable + mainUI.notificationLevel === + UI.NotificationLevel.Enable onTriggered: - window.notificationLevel = - Window.NotificationLevel.Enable + mainUI.notificationLevel = + UI.NotificationLevel.Enable } HMenuItem { text: qsTr("Highlights only (replies, keywords...)") checked: - window.notificationLevel === - Window.NotificationLevel.HighlightsOnly + mainUI.notificationLevel === + UI.NotificationLevel.HighlightsOnly onTriggered: - window.notificationLevel = - Window.NotificationLevel.HighlightsOnly + mainUI.notificationLevel = + UI.NotificationLevel.HighlightsOnly } HMenuItem { text: qsTr("Mute all notifications") checked: - window.notificationLevel === - Window.NotificationLevel.Mute + mainUI.notificationLevel === UI.NotificationLevel.Mute onTriggered: - window.notificationLevel = - Window.NotificationLevel.Mute + mainUI.notificationLevel = UI.NotificationLevel.Mute } } } diff --git a/src/gui/PythonBridge/EventHandlers.qml b/src/gui/PythonBridge/EventHandlers.qml index 07c55b78..626aafd7 100644 --- a/src/gui/PythonBridge/EventHandlers.qml +++ b/src/gui/PythonBridge/EventHandlers.qml @@ -11,10 +11,10 @@ QtObject { function onNotificationRequested( id, critical, bubble, sound, urgencyHint, title, body, image, ) { - const level = window.notificationLevel + const level = window.mainUI.notificationLevel - if (level === Window.NotificationLevel.Mute) return - if (level === Window.HighlightsOnly && ! critical) return + if (level === UI.NotificationLevel.Mute) return + if (level === UI.NotificationLevel.HighlightsOnly && ! critical) return if (window.notifiedIds.has(id)) return window.notifiedIds.add(id) diff --git a/src/gui/UI.qml b/src/gui/UI.qml index 89c794cb..8d824214 100644 --- a/src/gui/UI.qml +++ b/src/gui/UI.qml @@ -6,12 +6,22 @@ import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import QtGraphicalEffects 1.12 +import "." import "Base" import "MainPane" Item { id: mainUI + enum NotificationLevel { Mute, HighlightsOnly, Enable } + + property int notificationLevel: + settings.Notifications.start_level === "highlights_only" ? + UI.NotificationLevel.HighlightsOnly : + settings.Notifications.start_level === "mute" ? + UI.NotificationLevel.Mute : + UI.NotificationLevel.Enable + property bool accountsPresent: ModelStore.get("accounts").count > 0 || py.startupAnyAccountsSaved @@ -78,6 +88,25 @@ Item { } } + HShortcut { + sequences: window.settings.Keys.notifications_highlights_only + onActivated: + mainUI.notificationLevel = + mainUI.notificationLevel === + UI.NotificationLevel.HighlightsOnly ? + UI.NotificationLevel.Enable : + UI.NotificationLevel.HighlightsOnly + } + + HShortcut { + sequences: window.settings.Keys.notifications_mute + onActivated: + mainUI.notificationLevel = + mainUI.notificationLevel === UI.NotificationLevel.Mute ? + UI.NotificationLevel.Enable : + UI.NotificationLevel.Mute + } + FontMetrics { id: fontMetrics font.family: theme.fontFamily.sans diff --git a/src/gui/Window.qml b/src/gui/Window.qml index a61379ba..8c92198b 100644 --- a/src/gui/Window.qml +++ b/src/gui/Window.qml @@ -10,8 +10,6 @@ import "PythonBridge" ApplicationWindow { id: window - enum NotificationLevel { Mute, HighlightsOnly, Enable } - // FIXME: Qt 5.13.1 bug, this randomly stops updating after the cursor // leaves the window until it's clicked again. @@ -21,13 +19,6 @@ ApplicationWindow { window.visibility === window.Minimized || window.visibility === window.Hidden - property int notificationLevel: - py.ready && settings.Notifications.start_level === "highlights_only" ? - Window.NotificationLevel.HighlightsOnly : - py.ready && settings.Notifications.start_level === "mute" ? - Window.NotificationLevel.Mute : - Window.NotificationLevel.Enable - property var notifiedIds: new Set() property var mainUI: null