diff --git a/app/globalsettings.cpp b/app/globalsettings.cpp index 90e0b4cba..4ecfb872c 100644 --- a/app/globalsettings.cpp +++ b/app/globalsettings.cpp @@ -107,11 +107,18 @@ void GlobalSettings::showWidgetsExplorer() void GlobalSettings::enableAltSession(bool enabled) { - if (enabled) { - m_corona->loadLatteLayout(QString(i18n("Alternative"))); - } else { - m_corona->loadLatteLayout(QString(i18n("My Layout"))); - } + //! this code must be called asynchronously because it is called + //! also from qml (Tasks plasmoid). This change fixes a very important + //! crash when switching sessions through the Tasks plasmoid Context menu + //! Latte was unstable and was crashing very often during changing + //! sessions + QTimer::singleShot(200, [this, enabled]() { + if (enabled) { + m_corona->loadLatteLayout(QString(i18n("Alternative"))); + } else { + m_corona->loadLatteLayout(QString(i18n("My Layout"))); + } + }); } bool GlobalSettings::exposeAltSession() const diff --git a/plasmoid/package/contents/ui/ContextMenu.qml b/plasmoid/package/contents/ui/ContextMenu.qml index 9356ef1cc..c06788219 100644 --- a/plasmoid/package/contents/ui/ContextMenu.qml +++ b/plasmoid/package/contents/ui/ContextMenu.qml @@ -34,6 +34,8 @@ import "../code/activitiesTools.js" as ActivitiesTools PlasmaComponents.ContextMenu { id: menu + property bool changingLayout: false + property QtObject mpris2Source property QtObject backend @@ -264,13 +266,15 @@ PlasmaComponents.ContextMenu { Component.onDestruction: { - windowsPreviewDlg.contextMenu = false; - root.contextMenu = null; - backend.ungrabMouse(visualParent); - root.signalActionsBlockHiding(-1); - //root.signalDraggingState(false); - root.disableRestoreZoom = false; - checkListHovered.startDuration(100); + if (!changingLayout) { + windowsPreviewDlg.contextMenu = false; + root.contextMenu = null; + backend.ungrabMouse(visualParent); + root.signalActionsBlockHiding(-1); + //root.signalDraggingState(false); + root.disableRestoreZoom = false; + checkListHovered.startDuration(100); + } } /// Sub Items @@ -800,6 +804,7 @@ PlasmaComponents.ContextMenu { onClicked: { //fix a crash that when going to Alternative Session through Context Menu, //animations are played during the destruction and because of that Latte.IconItem is crashing + menu.changingLayout = true; root.disableRestoreZoom = false; root.clearZoom(); if (latteDock) diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index 5c31bcd8f..09955dcfb 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -495,6 +495,10 @@ Item { //this is the animation time needed in order for tasks to restore their zoom first interval: 7 * (root.durationTime * units.shortDuration) onTriggered: { + if (root.contextMenu) { + root.contextMenu.destroy(); + root.contextMenu = null; + } if (root.altSessionAction) root.altSessionAction.trigger(); }