move and add menu

This commit is contained in:
Benjamin Palko 2025-08-02 21:08:18 -04:00
parent 87e9941e0a
commit 3e3275a84d
4 changed files with 128 additions and 10 deletions

View file

@ -5,6 +5,7 @@ import Quickshell
import "components" import "components"
import "components/bluetooth" import "components/bluetooth"
import "components/hyprland" import "components/hyprland"
import "components/notifications"
import "components/tray" import "components/tray"
Scope { Scope {

View file

@ -0,0 +1,95 @@
pragma ComponentBehavior: Bound
import qs.config
import qs.services
import qs.widgets
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import Quickshell.Widgets
StyledPopupWindow {
id: root
backgroundColor: Theme.palette.base300
margins: 16
radius: 8
content: ColumnLayout {
spacing: 16
RowLayout {
Layout.fillWidth: true
StyledText {
text: "Enabled"
}
Switch {
checked: Notifications.enabled
onClicked: Notifications.enabled = checked
}
StyledButton {
id: clearButton
Layout.alignment: Qt.AlignRight
onClicked: Notifications.clear()
content: StyledText {
text: "Clear"
color: clearButton.containsMouse ? Theme.palette.base300 : Theme.palette.basecontent
}
}
}
StyledLabel {
color: Theme.palette.base200
StyledListView {
id: notifications
spacing: 8
implicitHeight: 300
implicitWidth: 300
clip: true
header: WrapperRectangle {
margin: 8
color: 'transparent'
StyledText {
text: "Notifications"
font.bold: true
font.pixelSize: 16
}
}
model: Notifications.list
delegate: StyledLabel {
required property var modelData
margin: 16
anchors.left: parent.left
anchors.right: parent.right
RowLayout {
ClippingRectangle {
implicitWidth: icon.implicitSize
implicitHeight: icon.implicitSize
IconImage {
id: icon
implicitSize: 20
source: modelData.image == "" ? Quickshell.iconPath(modelData.appIcon, "device-support-unknown-symbolic") : modelData.image
}
}
ColumnLayout {
StyledText {
font.bold: true
font.pixelSize: 12
text: modelData.summary ?? modelData.appName
}
StyledText {
text: modelData.body
}
}
}
}
}
}
}
}

View file

@ -5,10 +5,10 @@ import qs.widgets
import QtQuick import QtQuick
StyledButton { StyledButton {
id: clickable id: root
onClicked: { onClicked: {
Notifications.clear(); menu.toggle();
} }
content: StyledText { content: StyledText {
@ -19,16 +19,24 @@ StyledButton {
font.bold: true font.bold: true
text: Icons.bell text: Icons.bell
color: clickable.containsMouse ? Theme.palette.base300 : Theme.palette.basecontent color: root.containsMouse ? Theme.palette.base300 : Theme.palette.basecontent
states: State { states: State {
when: Notifications.hasNotifications when: Notifications.hasNotifications
PropertyChanges { PropertyChanges {
text { text {
text: Icons.bellRing text: Icons.bellRing
color: clickable.containsMouse ? Theme.palette.base300 : Theme.palette.secondary color: root.containsMouse ? Theme.palette.base300 : Theme.palette.secondary
} }
} }
} }
} }
NotificationMenu {
id: menu
anchor.item: root
anchor.rect.x: root.width / 2 - width / 2
anchor.rect.y: root.height + 8
}
} }

View file

@ -6,20 +6,34 @@ import Quickshell.Services.Notifications
Singleton { Singleton {
id: root id: root
property bool hasNotifications: notifications.length > 0 property bool enabled: true
property list<Notification> notifications: [] property bool hasNotifications: list.length > 0
property list<Notification> list: []
function clear() { function clear() {
notifications.forEach(notification => { list.forEach(notification => {
notification.dismiss(); notification?.dismiss();
}); });
notifications = []; list = [];
} }
NotificationServer { NotificationServer {
id: server
keepOnReload: false
actionsSupported: true
bodyHyperlinksSupported: true
bodyImagesSupported: true
bodyMarkupSupported: true
imageSupported: true
onNotification: event => { onNotification: event => {
if (!root.enabled) {
return;
}
event.tracked = true; event.tracked = true;
root.notifications.push(event); root.list = root.list.filter(item => item.id != event.id);
root.list.push(event);
} }
} }
} }