mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
Toast: reworked the display and logic to make it more robust.
+ some bluetooth logic debouncing to avoid extra toast when adapter comes back to life after suspend.
This commit is contained in:
@@ -15,14 +15,12 @@ Rectangle {
|
||||
|
||||
signal hidden
|
||||
|
||||
width: Math.min(500 * scaling, parent.width * 0.8)
|
||||
height: Math.max(60 * scaling, contentLayout.implicitHeight + Style.marginL * 2 * scaling)
|
||||
width: parent.width
|
||||
height: Math.round(contentLayout.implicitHeight + Style.marginL * 2 * scaling)
|
||||
radius: Style.radiusL * scaling
|
||||
visible: false
|
||||
opacity: 0
|
||||
scale: initialScale
|
||||
|
||||
// Clean surface background like NToast
|
||||
color: Color.mSurface
|
||||
|
||||
// Colored border based on type
|
||||
@@ -67,6 +65,12 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup on destruction
|
||||
Component.onDestruction: {
|
||||
hideTimer.stop()
|
||||
hideAnimation.stop()
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: contentLayout
|
||||
anchors.fill: parent
|
||||
@@ -125,24 +129,9 @@ Rectangle {
|
||||
visible: text.length > 0
|
||||
}
|
||||
}
|
||||
|
||||
// Close button
|
||||
NIconButton {
|
||||
id: closeButton
|
||||
icon: "close"
|
||||
|
||||
colorBg: Color.mSurfaceVariant
|
||||
colorFg: Color.mOnSurface
|
||||
colorBorder: Color.transparent
|
||||
colorBorderHover: Color.mOutline
|
||||
|
||||
baseSize: Style.baseWidgetSize * 0.8
|
||||
Layout.alignment: Qt.AlignTop
|
||||
|
||||
onClicked: root.hide()
|
||||
}
|
||||
}
|
||||
|
||||
// Click anywhere dismiss the toast
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.LeftButton
|
||||
@@ -151,6 +140,10 @@ Rectangle {
|
||||
}
|
||||
|
||||
function show(msg, desc, msgType, msgDuration) {
|
||||
// Stop all timers first
|
||||
hideTimer.stop()
|
||||
hideAnimation.stop()
|
||||
|
||||
message = msg
|
||||
description = desc || ""
|
||||
type = msgType || "notice"
|
||||
@@ -167,10 +160,12 @@ Rectangle {
|
||||
hideTimer.stop()
|
||||
opacity = 0
|
||||
scale = initialScale
|
||||
hideAnimation.start()
|
||||
hideAnimation.restart()
|
||||
}
|
||||
|
||||
function hideImmediately() {
|
||||
hideTimer.stop()
|
||||
hideAnimation.stop()
|
||||
opacity = 0
|
||||
scale = initialScale
|
||||
root.visible = false
|
||||
|
||||
@@ -6,12 +6,12 @@ import qs.Commons
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
Loader {
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property ShellScreen screen
|
||||
required property real scaling
|
||||
required property bool active
|
||||
property bool active: false
|
||||
|
||||
// Local queue for this screen only
|
||||
property var messageQueue: []
|
||||
@@ -44,16 +44,26 @@ Loader {
|
||||
}
|
||||
}
|
||||
|
||||
// Clear queue on component destruction to prevent orphaned toasts
|
||||
Component.onDestruction: {
|
||||
messageQueue = []
|
||||
isShowingToast = false
|
||||
hideTimer.stop()
|
||||
quickSwitchTimer.stop()
|
||||
}
|
||||
|
||||
function enqueueToast(toastData) {
|
||||
Logger.log("ToastScreen", "Queuing:", toastData.message, toastData.description, toastData.type)
|
||||
|
||||
if (replaceOnNew && isShowingToast) {
|
||||
// Cancel current toast and clear queue for latest toast
|
||||
messageQueue = [] // Clear existing queue
|
||||
messageQueue.push(toastData)
|
||||
|
||||
// Hide current toast immediately
|
||||
if (item) {
|
||||
if (windowLoader.item) {
|
||||
hideTimer.stop()
|
||||
item.hideToast() // Need to add this method to PanelWindow
|
||||
windowLoader.item.hideToast()
|
||||
}
|
||||
|
||||
// Process new toast after a brief delay
|
||||
@@ -73,20 +83,30 @@ Loader {
|
||||
}
|
||||
|
||||
function processQueue() {
|
||||
if (!active || !item || messageQueue.length === 0 || isShowingToast) {
|
||||
if (!active || messageQueue.length === 0 || isShowingToast) {
|
||||
return
|
||||
}
|
||||
|
||||
var data = messageQueue.shift()
|
||||
isShowingToast = true
|
||||
|
||||
// Show the toast
|
||||
item.showToast(data.message, data.description, data.type, data.duration)
|
||||
// Activate the loader and show toast
|
||||
windowLoader.active = true
|
||||
// Need a small delay to ensure the window is created
|
||||
Qt.callLater(function () {
|
||||
if (windowLoader.item) {
|
||||
windowLoader.item.showToast(data.message, data.description, data.type, data.duration)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function onToastHidden() {
|
||||
isShowingToast = false
|
||||
// Small delay before next toast
|
||||
|
||||
// Deactivate the loader to completely remove the window
|
||||
windowLoader.active = false
|
||||
|
||||
// Small delay before processing next toast
|
||||
hideTimer.restart()
|
||||
}
|
||||
|
||||
@@ -96,48 +116,55 @@ Loader {
|
||||
onTriggered: root.processQueue()
|
||||
}
|
||||
|
||||
sourceComponent: PanelWindow {
|
||||
id: panel
|
||||
// The loader that creates/destroys the PanelWindow as needed
|
||||
Loader {
|
||||
id: windowLoader
|
||||
active: false // Only active when showing a toast
|
||||
|
||||
screen: root.screen
|
||||
sourceComponent: PanelWindow {
|
||||
id: panel
|
||||
|
||||
anchors {
|
||||
top: true
|
||||
}
|
||||
property alias toastItem: toastItem
|
||||
|
||||
implicitWidth: 500 * root.scaling
|
||||
implicitHeight: Math.round(toastItem.visible ? toastItem.height + Style.marginM * root.scaling : 1)
|
||||
screen: root.screen
|
||||
|
||||
// Set margins based on bar position
|
||||
margins.top: {
|
||||
switch (Settings.data.bar.position) {
|
||||
case "top":
|
||||
return (Style.barHeight + Style.marginS) * scaling + (Settings.data.bar.floating ? Settings.data.bar.marginVertical * Style.marginXL * scaling : 0)
|
||||
default:
|
||||
return Style.marginL * scaling
|
||||
anchors {
|
||||
top: true
|
||||
}
|
||||
}
|
||||
|
||||
color: Color.transparent
|
||||
implicitWidth: 420 * root.scaling
|
||||
implicitHeight: toastItem.height
|
||||
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
|
||||
exclusionMode: PanelWindow.ExclusionMode.Ignore
|
||||
// Set margins based on bar position
|
||||
margins.top: {
|
||||
switch (Settings.data.bar.position) {
|
||||
case "top":
|
||||
return (Style.barHeight + Style.marginS) * scaling + (Settings.data.bar.floating ? Settings.data.bar.marginVertical * Style.marginXL * scaling : 0)
|
||||
default:
|
||||
return Style.marginL * scaling
|
||||
}
|
||||
}
|
||||
|
||||
function showToast(message, description, type, duration) {
|
||||
toastItem.show(message, description, type, duration)
|
||||
}
|
||||
color: Color.transparent
|
||||
|
||||
// Add method to immediately hide toast
|
||||
function hideToast() {
|
||||
toastItem.hideImmediately()
|
||||
}
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
|
||||
exclusionMode: PanelWindow.ExclusionMode.Ignore
|
||||
|
||||
SimpleToast {
|
||||
id: toastItem
|
||||
function showToast(message, description, type, duration) {
|
||||
toastItem.show(message, description, type, duration)
|
||||
}
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
onHidden: root.onToastHidden()
|
||||
function hideToast() {
|
||||
toastItem.hideImmediately()
|
||||
}
|
||||
|
||||
SimpleToast {
|
||||
id: toastItem
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
onHidden: root.onToastHidden()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user