core: shell state manager
This commit is contained in:
52
Shell/ShellStateManager.qml
Normal file
52
Shell/ShellStateManager.qml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
pragma Singleton
|
||||||
|
import QtQuick
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
id: manager
|
||||||
|
|
||||||
|
property bool shellOpen: false
|
||||||
|
property var windowRequests: ({})
|
||||||
|
property var globals: ({})
|
||||||
|
|
||||||
|
signal shellOpened
|
||||||
|
signal shellClosed
|
||||||
|
signal windowRequested(string name, var payload)
|
||||||
|
|
||||||
|
function openShell() {
|
||||||
|
if (!shellOpen) {
|
||||||
|
console.log("ShellStateManager: openShell");
|
||||||
|
shellOpen = true;
|
||||||
|
shellOpened();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeShell() {
|
||||||
|
if (shellOpen) {
|
||||||
|
console.log("ShellStateManager: closeShell");
|
||||||
|
shellOpen = false;
|
||||||
|
shellClosed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleShell() {
|
||||||
|
console.log("ShellStateManager: toggleShell (isOpen " + shellOpen + ")");
|
||||||
|
shellOpen ? closeShell() : openShell();
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestWindow(name, payload) {
|
||||||
|
console.log("ShellStateManager: requestWindow", name, payload);
|
||||||
|
windowRequests[name] = {
|
||||||
|
payload: payload,
|
||||||
|
timestamp: Date.now()
|
||||||
|
};
|
||||||
|
windowRequested(name, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setGlobal(key, value) {
|
||||||
|
globals[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function global(key, defaultValue) {
|
||||||
|
return globals.hasOwnProperty(key) ? globals[key] : defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
10
shell.qml
10
shell.qml
@@ -5,7 +5,9 @@ import "Shell"
|
|||||||
|
|
||||||
ShellRoot {
|
ShellRoot {
|
||||||
id: baseShell
|
id: baseShell
|
||||||
property bool isOpen: false
|
|
||||||
|
// Use the singleton directly; it controls the shell state globally.
|
||||||
|
property bool isOpen: ShellStateManager.shellOpen
|
||||||
|
|
||||||
WLRLayerTopbar {
|
WLRLayerTopbar {
|
||||||
visible: baseShell.isOpen
|
visible: baseShell.isOpen
|
||||||
@@ -20,7 +22,7 @@ ShellRoot {
|
|||||||
triggerDescription: "Toggle the menu"
|
triggerDescription: "Toggle the menu"
|
||||||
name: "shell_toggle"
|
name: "shell_toggle"
|
||||||
onReleased: {
|
onReleased: {
|
||||||
baseShell.isOpen = !baseShell.isOpen;
|
ShellStateManager.toggleShell()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,10 +30,10 @@ ShellRoot {
|
|||||||
target: "deltarune.shell"
|
target: "deltarune.shell"
|
||||||
enabled: true
|
enabled: true
|
||||||
function open(): void {
|
function open(): void {
|
||||||
baseShell.isOpen = true;
|
ShellStateManager.openShell()
|
||||||
}
|
}
|
||||||
function close(): void {
|
function close(): void {
|
||||||
baseShell.isOpen = false;
|
ShellStateManager.closeShell()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user