forked from Shinonome/dots-hyprland
Unread notification count on bar (#2153)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import qs.modules.common
|
|
||||||
import qs
|
import qs
|
||||||
|
import qs.modules.common
|
||||||
|
import qs.services
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
@@ -44,6 +45,13 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSidebarRightOpenChanged: {
|
||||||
|
if (GlobalStates.sidebarRightOpen) {
|
||||||
|
Notifications.timeoutAll();
|
||||||
|
Notifications.markAllRead();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
property real screenZoom: 1
|
property real screenZoom: 1
|
||||||
onScreenZoomChanged: {
|
onScreenZoomChanged: {
|
||||||
Quickshell.execDetached(["hyprctl", "keyword", "cursor:zoom_factor", root.screenZoom.toString()]);
|
Quickshell.execDetached(["hyprctl", "keyword", "cursor:zoom_factor", root.screenZoom.toString()]);
|
||||||
|
|||||||
@@ -295,6 +295,48 @@ Item { // Bar content region
|
|||||||
Layout.rightMargin: indicatorsRowLayout.realSpacing
|
Layout.rightMargin: indicatorsRowLayout.realSpacing
|
||||||
color: rightSidebarButton.colText
|
color: rightSidebarButton.colText
|
||||||
}
|
}
|
||||||
|
Revealer {
|
||||||
|
reveal: Notifications.silent || Notifications.unread > 0
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.rightMargin: reveal ? indicatorsRowLayout.realSpacing : 0
|
||||||
|
implicitHeight: reveal ? notificationIcon.implicitHeight : 0
|
||||||
|
implicitWidth: reveal ? notificationIcon.implicitWidth : 0
|
||||||
|
Behavior on Layout.rightMargin {
|
||||||
|
animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this)
|
||||||
|
}
|
||||||
|
Rectangle {
|
||||||
|
id: notifPing
|
||||||
|
visible: !Notifications.silent && Notifications.unread > 0
|
||||||
|
property bool showUnreadCount: Config.options.bar.indicators.notifications.showUnreadCount
|
||||||
|
anchors {
|
||||||
|
right: parent.right
|
||||||
|
top: parent.top
|
||||||
|
rightMargin: showUnreadCount ? 0 : 1
|
||||||
|
topMargin: showUnreadCount ? 0 : 3
|
||||||
|
}
|
||||||
|
radius: Appearance.rounding.full
|
||||||
|
color: Appearance.colors.colOnLayer0
|
||||||
|
z: 1
|
||||||
|
|
||||||
|
implicitHeight: showUnreadCount ? Math.max(notificationCounterText.implicitWidth, notificationCounterText.implicitHeight) : 8
|
||||||
|
implicitWidth: implicitHeight
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
id: notificationCounterText
|
||||||
|
visible: notifPing.showUnreadCount
|
||||||
|
anchors.centerIn: parent
|
||||||
|
font.pixelSize: Appearance.font.pixelSize.smallest
|
||||||
|
color: Appearance.colors.colLayer0
|
||||||
|
text: Notifications.unread
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaterialSymbol {
|
||||||
|
id: notificationIcon
|
||||||
|
text: Notifications.silent ? "notifications_paused" : "notifications"
|
||||||
|
iconSize: Appearance.font.pixelSize.larger
|
||||||
|
color: rightSidebarButton.colText
|
||||||
|
}
|
||||||
|
}
|
||||||
MaterialSymbol {
|
MaterialSymbol {
|
||||||
Layout.rightMargin: indicatorsRowLayout.realSpacing
|
Layout.rightMargin: indicatorsRowLayout.realSpacing
|
||||||
text: Network.materialSymbol
|
text: Network.materialSymbol
|
||||||
|
|||||||
@@ -212,6 +212,11 @@ Singleton {
|
|||||||
property bool useUSCS: false // Instead of metric (SI) units
|
property bool useUSCS: false // Instead of metric (SI) units
|
||||||
property int fetchInterval: 10 // minutes
|
property int fetchInterval: 10 // minutes
|
||||||
}
|
}
|
||||||
|
property JsonObject indicators: JsonObject {
|
||||||
|
property JsonObject notifications: JsonObject {
|
||||||
|
property bool showUnreadCount: false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property JsonObject battery: JsonObject {
|
property JsonObject battery: JsonObject {
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ Scope {
|
|||||||
|
|
||||||
function toggle(): void {
|
function toggle(): void {
|
||||||
GlobalStates.sidebarRightOpen = !GlobalStates.sidebarRightOpen;
|
GlobalStates.sidebarRightOpen = !GlobalStates.sidebarRightOpen;
|
||||||
if(GlobalStates.sidebarRightOpen) Notifications.timeoutAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function close(): void {
|
function close(): void {
|
||||||
@@ -79,7 +78,6 @@ Scope {
|
|||||||
|
|
||||||
function open(): void {
|
function open(): void {
|
||||||
GlobalStates.sidebarRightOpen = true;
|
GlobalStates.sidebarRightOpen = true;
|
||||||
Notifications.timeoutAll();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +87,6 @@ Scope {
|
|||||||
|
|
||||||
onPressed: {
|
onPressed: {
|
||||||
GlobalStates.sidebarRightOpen = !GlobalStates.sidebarRightOpen;
|
GlobalStates.sidebarRightOpen = !GlobalStates.sidebarRightOpen;
|
||||||
if(GlobalStates.sidebarRightOpen) Notifications.timeoutAll();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalShortcut {
|
GlobalShortcut {
|
||||||
@@ -98,7 +95,6 @@ Scope {
|
|||||||
|
|
||||||
onPressed: {
|
onPressed: {
|
||||||
GlobalStates.sidebarRightOpen = true;
|
GlobalStates.sidebarRightOpen = true;
|
||||||
Notifications.timeoutAll();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalShortcut {
|
GlobalShortcut {
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
property bool silent: false
|
property bool silent: false
|
||||||
|
property int unread: 0
|
||||||
property var filePath: Directories.notificationsPath
|
property var filePath: Directories.notificationsPath
|
||||||
property list<Notif> list: []
|
property list<Notif> list: []
|
||||||
property var popupList: list.filter((notif) => notif.popup);
|
property var popupList: list.filter((notif) => notif.popup);
|
||||||
@@ -173,12 +174,17 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root.unread++;
|
||||||
root.notify(newNotifObject);
|
root.notify(newNotifObject);
|
||||||
// console.log(notifToString(newNotifObject));
|
// console.log(notifToString(newNotifObject));
|
||||||
notifFileView.setText(stringifyList(root.list));
|
notifFileView.setText(stringifyList(root.list));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function markAllRead() {
|
||||||
|
root.unread = 0;
|
||||||
|
}
|
||||||
|
|
||||||
function discardNotification(id) {
|
function discardNotification(id) {
|
||||||
console.log("[Notifications] Discarding notification with ID: " + id);
|
console.log("[Notifications] Discarding notification with ID: " + id);
|
||||||
const index = root.list.findIndex((notif) => notif.notificationId === id);
|
const index = root.list.findIndex((notif) => notif.notificationId === id);
|
||||||
|
|||||||
Reference in New Issue
Block a user