Move notificationswapper to common, change defaul wrap mode

This commit is contained in:
2025-10-10 20:24:51 -03:00
parent 92a3907b8f
commit f69518aec4
5 changed files with 90 additions and 69 deletions

View File

@@ -33,7 +33,7 @@ BackgroundRectangle {
// implicitHeight: Math.max(notifLayout.implicitHeight, 100) // implicitHeight: Math.max(notifLayout.implicitHeight, 100)
Component.onCompleted: { Component.onCompleted: {
notificationWrapper.implicitHeight = targetHeight notificationWrapper.implicitHeight = targetHeight;
} }
clip: true clip: true
@@ -45,8 +45,10 @@ BackgroundRectangle {
} }
ScriptAction { ScriptAction {
script: { script: {
if(clicked) notificationWrapper.dismissed() if (clicked)
if(notificationWrapper.implicitHeight === 0) notificationWrapper.timedout() notificationWrapper.dismissed();
if (notificationWrapper.implicitHeight === 0)
notificationWrapper.timedout();
} }
} }
} }
@@ -55,8 +57,8 @@ BackgroundRectangle {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
notificationWrapper.clicked = true notificationWrapper.clicked = true;
notificationWrapper.implicitHeight = 0 notificationWrapper.implicitHeight = 0;
} }
} }
@@ -83,10 +85,10 @@ BackgroundRectangle {
IconImage { IconImage {
id: iconImage id: iconImage
Layout.alignment: Qt.AlignLeft| Qt.AlignVCenter Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
Layout.leftMargin: 10 Layout.leftMargin: 10
implicitSize: 80 implicitSize: 80
visible: notificationWrapper.image? true: false visible: notificationWrapper.image ? true : false
source: notificationWrapper.image source: notificationWrapper.image
} }
@@ -103,6 +105,9 @@ BackgroundRectangle {
id: summaryRectangle id: summaryRectangle
Layout.fillWidth: true Layout.fillWidth: true
MarginWrapperManager {
margin: 10
}
implicitHeight: summaryText.implicitHeight + 10 implicitHeight: summaryText.implicitHeight + 10
@@ -113,7 +118,7 @@ BackgroundRectangle {
anchors.fill: parent anchors.fill: parent
text: notificationWrapper.notification? notificationWrapper.notification.summary : "" text: notificationWrapper.notification ? notificationWrapper.notification.summary : ""
} }
} }
@@ -127,12 +132,15 @@ BackgroundRectangle {
visible: bodyText.text ? true : false visible: bodyText.text ? true : false
MarginWrapperManager {
margin: 15
}
StyledText { StyledText {
id: bodyText id: bodyText
anchors.fill: parent anchors.fill: parent
text: notificationWrapper.notification? notificationWrapper.notification.body : "" text: notificationWrapper.notification ? notificationWrapper.notification.body : ""
} }
} }
} }

View File

@@ -7,7 +7,7 @@ Text {
anchors.margins: 5 anchors.margins: 5
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap wrapMode: Text.Wrap
textFormat: Text.MarkdownText textFormat: Text.MarkdownText
font.bold: true font.bold: true
font.pixelSize: Theme.pixelSize font.pixelSize: Theme.pixelSize

View File

@@ -4,9 +4,10 @@ import Quickshell
import Quickshell.Hyprland import Quickshell.Hyprland
import Quickshell.Wayland import Quickshell.Wayland
import Quickshell.Io import Quickshell.Io
import qs.Common
Singleton { Singleton {
id:root id: root
readonly property string hyprlandSignature: Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE") readonly property string hyprlandSignature: Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE")
@@ -93,32 +94,32 @@ Singleton {
return workspaceDesktopEntries; return workspaceDesktopEntries;
} }
Socket { Socket {
path: `${Quickshell.env("XDG_RUNTIME_DIR")}/hypr/${Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE")}/.socket2.sock` path: `${Quickshell.env("XDG_RUNTIME_DIR")}/hypr/${Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE")}/.socket2.sock`
connected: true connected: true
parser: SplitParser { parser: SplitParser {
property var fullscreenRegex: new RegExp("fullscreen>>."); property var fullscreenRegex: new RegExp("fullscreen>>.")
property var screencastRegex: new RegExp("screencast>>.*") property var screencastRegex: new RegExp("screencast>>.*")
onRead: msg => { onRead: msg => {
let match = fullscreenRegex.exec(msg); let match = fullscreenRegex.exec(msg);
if (match != null) { if (match != null) {
if(msg.split(">>")[1] === "1") { if (msg.split(">>")[1] === "1") {
root.hasFullscreen = true root.hasFullscreen = true;
} else { } else {
root.hasFullscreen = false root.hasFullscreen = false;
} }
} }
match = screencastRegex.exec(msg); match = screencastRegex.exec(msg);
if (match != null) { if (match != null) {
if(msg.split(">>")[1].split(',')[0] === "1") { if (msg.split(">>")[1].split(',')[0] === "1") {
root.isScreencasting = true root.isScreencasting = true;
} else { } else {
root.isScreencasting = false root.isScreencasting = false;
} }
} }
} }
} }
} }
} }

View File

@@ -4,7 +4,7 @@ pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import Quickshell import Quickshell
import Quickshell.Services.Notifications import Quickshell.Services.Notifications
import qs.Widgets import qs.Common
import qs.Services import qs.Services
Singleton { Singleton {
@@ -27,21 +27,21 @@ Singleton {
Connections { Connections {
target: notificationServer target: notificationServer
function onNotification(notif) { function onNotification(notif) {
if(notif.transient || notif.body === "MediaOngoingActivity") if (notif.transient || notif.body === "MediaOngoingActivity")
return; return;
notif.tracked = true; notif.tracked = true;
root.addNotification(trackedNotifications, notif); root.addNotification(trackedNotifications, notif);
if (notif.lastGeneration) if (notif.lastGeneration)
return; return;
// Use the refactored helper // Use the refactored helper
if(notificationList.count < root.maxShown && !root.receivingLock ) { if (notificationList.count < root.maxShown && !root.receivingLock) {
root.addNotification(notificationList, notif) root.addNotification(notificationList, notif);
} else { } else {
root.receivingLock = true root.receivingLock = true;
root.addNotification(pendingList, notif) root.addNotification(pendingList, notif);
} }
} }
} }
@@ -58,7 +58,6 @@ Singleton {
* @param {var} targetNotif * @param {var} targetNotif
*/ */
function removeNotification(model, targetNotif) { function removeNotification(model, targetNotif) {
if (!model || typeof model.remove !== "function") { if (!model || typeof model.remove !== "function") {
console.warn("removeNotification(): invalid model"); console.warn("removeNotification(): invalid model");
return; return;
@@ -85,7 +84,7 @@ Singleton {
// Avoid duplicates // Avoid duplicates
for (let i = 0; i < model.count; i++) { for (let i = 0; i < model.count; i++) {
if (model.get(i).notif === notif) if (model.get(i).notif === notif)
return; return;
} }
model.append({ model.append({
@@ -98,48 +97,47 @@ Singleton {
} }
function notificationDismiss(notif) { function notificationDismiss(notif) {
let pendingIdx = -1 let pendingIdx = -1;
for (let i = 0; i < pendingList.count; i++) { for (let i = 0; i < pendingList.count; i++) {
if (pendingList.get(i).notif === notif) { if (pendingList.get(i).notif === notif) {
pendingIdx = i pendingIdx = i;
break break;
} }
} }
if (pendingIdx >= 0) { if (pendingIdx >= 0) {
pendingList.remove(pendingIdx, 1) pendingList.remove(pendingIdx, 1);
} else { } else {
removeNotification(notificationList, notif) removeNotification(notificationList, notif);
} }
removeNotification(trackedNotifications, notif) removeNotification(trackedNotifications, notif);
if (notif && typeof notif.dismiss === "function") if (notif && typeof notif.dismiss === "function")
notif.dismiss() notif.dismiss();
tryShowNext() tryShowNext();
} }
function timeoutNotification(notif) { function timeoutNotification(notif) {
removeNotification(notificationList, notif);
removeNotification(notificationList, notif) tryShowNext();
tryShowNext()
} }
function tryShowNext() { function tryShowNext() {
let filled = false let filled = false;
while (notificationList.count < root.maxShown && pendingList.count > 0) { while (notificationList.count < root.maxShown && pendingList.count > 0) {
const nextNotif = pendingList.get(0).notif const nextNotif = pendingList.get(0).notif;
pendingList.remove(0, 1) pendingList.remove(0, 1);
addNotification(notificationList, nextNotif) addNotification(notificationList, nextNotif);
filled = true filled = true;
} }
// Only lock if there are still more pending than fit onscreen // Only lock if there are still more pending than fit onscreen
root.receivingLock = pendingList.count > 0 root.receivingLock = pendingList.count > 0;
} }
LazyLoader { LazyLoader {
@@ -157,7 +155,9 @@ Singleton {
implicitWidth: 400 implicitWidth: 400
implicitHeight: screen.height implicitHeight: screen.height
color: "transparent" color: "transparent"
mask: Region { item: listView } mask: Region {
item: listView
}
ListView { ListView {
id: listView id: listView
@@ -176,17 +176,16 @@ Singleton {
notification: modelData notification: modelData
implicitWidth: listView.width implicitWidth: listView.width
startTimer: NotificationUrgency.toString(notification?.urgency) === "Critical" ? false : true
startTimer: NotificationUrgency.toString(notification?.urgency) === "Critical"? false: true
timerDuration: 5000 timerDuration: 5000
onDismissed: { onDismissed: {
if (notification && typeof notification.dismiss === "function") if (notification && typeof notification.dismiss === "function")
root.notificationDismiss(notification); root.notificationDismiss(notification);
} }
onTimedout: { onTimedout: {
root.timeoutNotification(notification) root.timeoutNotification(notification);
} }
} }

View File

@@ -8,12 +8,18 @@ import qs.Services
import qs.Widgets import qs.Widgets
import qs.Common.Styled import qs.Common.Styled
import qs.Common import qs.Common
import QtQuick.Window import Quickshell.Wayland
PopupWindow { PanelWindow {
id: notificationRoot id: notificationRoot
anchor.item: root anchors {
left: true
bottom: true
right: true
top: true
}
implicitWidth: screen.width implicitWidth: screen.width
// implicitWidth: 400 // implicitWidth: 400
implicitHeight: screen.height implicitHeight: screen.height
@@ -21,6 +27,14 @@ PopupWindow {
visible: true visible: true
signal clear signal clear
WlrLayershell.keyboardFocus: WlrKeyboardFocus.OnDemand
contentItem {
focus: true
Keys.onPressed: event => {
if (event.key == Qt.Key_Escape) notificationRoot.clear();
}
}
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: notificationRoot.clear() onClicked: notificationRoot.clear()
@@ -32,7 +46,6 @@ PopupWindow {
anchors{ anchors{
top: parent.top top: parent.top
left: parent.left left: parent.left
topMargin: 40
} }
border.width: 1 border.width: 1
color: Theme.color2 color: Theme.color2
@@ -60,7 +73,7 @@ PopupWindow {
} }
} }
StyledText { StyledText {
anchors.centerIn: parent anchors.fill: parent
text: "NOTIFICAÇÕES" text: "NOTIFICAÇÕES"
} }
} }