mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08: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:
@@ -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