From 4fdcac3dd0b5748f1b45769f9429062c63aaf7c4 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 17 Aug 2025 13:30:04 +0800 Subject: feat: standalone also toggle instead of only spawning --- shell.qml | 71 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/shell.qml b/shell.qml index 10cf88b..7e17826 100644 --- a/shell.qml +++ b/shell.qml @@ -24,50 +24,53 @@ Scope { } IpcHandler { target: "launcher" + property var standaloneObj: null function toggle() { launcherLoader.active = !launcherLoader.active; } function standalone(component: string): void { - // NOTE: 'component' must be a QML type name (e.g., 'Calc'), not a 'Component { ... }' block. - // Passing a full Component block will cause a QML error. - Qt.createQmlObject(` - import Quickshell - import QtQuick - import "launcher" - import "launcher/components" + if (standaloneObj) { + standaloneObj.active = !standaloneObj.active; + return; + } + standaloneObj = Qt.createQmlObject(` + import Quickshell + import QtQuick + import "launcher" + import "launcher/components" - LazyLoader { - property QtObject selectionState: QtObject { - property Item selected: null - property string input: "" - property int cursorPosition: 0 - property var priorities: [] - property int selectedPriority: 0 - property int previousSelectedPriority: 0 - property var widgets: [] - } - readonly property list widgets: [ - Component { - Loader { - sourceComponent: Qt.createComponent("launcher/components/" + "${component}.qml") - onLoaded: { - item.standalone = true - item.state = selectionState; + LazyLoader { + property QtObject selectionState: QtObject { + property Item selected: null + property string input: "" + property int cursorPosition: 0 + property var priorities: [] + property int selectedPriority: 0 + property int previousSelectedPriority: 0 + property var widgets: [] + } + readonly property list widgets: [ + Component { + Loader { + sourceComponent: Qt.createComponent("launcher/components/" + "${component}.qml") + onLoaded: { + item.standalone = true + item.state = selectionState; + } + } } + ] + id: root + active: true + component: Launcher { + widgetItems: widgets + state: selectionState + parentLoader: root } } - ] - id: root - active: true - component: Launcher { - widgetItems: widgets - state: selectionState - parentLoader: root - } - } - `, root); + `, root); } } -- cgit v1.2.3